# Ticket #6636: trac_6636-factorial-simplify.patch

File trac_6636-factorial-simplify.patch, 3.3 KB (added by kcrisman, 4 years ago)

Needs #6197

• ## sage/symbolic/expression.pyx

```# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1252418006 14400
# Parent  81cbc5d22a61e09a1bcc15f2d198b3d8861f79ab
Exposes Maxima functionality of simplifying factorials and binomials, trac 6636

diff -r 81cbc5d22a61 -r d8ea95918407 sage/symbolic/expression.pyx```
 a .. seealso:: :meth:`simplify_full`, :meth:`simplify_trig`, :meth:`simplify_rational`, :meth:`simplify_radical` :meth:`simplify_rational`, :meth:`simplify_radical`, :meth:`simplify_factorial` EXAMPLES:: def simplify_full(self): """ Applies simplify_trig, simplify_rational, and simplify_radical Applies simplify_factorial, simplify_trig, simplify_rational, and simplify_radical to self (in that order). ALIAS: simplify_full and full_simplify are the same. sage: f = sin(x/(x^2 + x)) sage: f.simplify_full() sin(1/(x + 1)) :: sage: var('n,k') (n, k) sage: f = binomial(n,k)*factorial(k)*factorial(n-k) sage: f.simplify_full() factorial(n) """ x = self x = x.simplify_factorial() x = x.simplify_trig() x = x.simplify_rational() x = x.simplify_radical() # TODO: come up with a way to intelligently wrap Maxima's way of # fine-tuning all simplificationsrational def simplify_factorial(self): """ Simplify by combining expressions with factorials, and by expanding binomials into factorials. ALIAS: factorial_simplify and simplify_factorial are the same EXAMPLES: Some examples are relatively clear:: sage: var('n,k') (n, k) sage: f = factorial(n+1)/factorial(n); f factorial(n + 1)/factorial(n) sage: f.simplify_factorial() n + 1 :: sage: f = factorial(n)*(n+1); f (n + 1)*factorial(n) sage: simplify(f) (n + 1)*factorial(n) sage: f.simplify_factorial() factorial(n + 1) :: sage: f = binomial(n,k)*factorial(k)*factorial(n-k); f factorial(-k + n)*factorial(k)*binomial(n,k) sage: f.simplify_factorial() factorial(n) A more complicated example, which needs further processing:: sage: f = factorial(x)/factorial(x-2)/2 + factorial(x+1)/factorial(x)/2; f 1/2*factorial(x)/factorial(x - 2) + 1/2*factorial(x + 1)/factorial(x) sage: g = f.simplify_factorial(); g 1/2*(x - 1)*x + 1/2*x + 1/2 sage: g.simplify_rational() 1/2*x^2 + 1/2 """ return self.parent()(self._maxima_().makefact().factcomb().minfactorial()) factorial_simplify = simplify_factorial def simplify_radical(self): r""" Simplifies this symbolic expression, which can contain logs,