# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1252418006 14400
# Node ID d8ea9591840748adf3616654ae1367f16514bd78
# Parent 81cbc5d22a61e09a1bcc15f2d198b3d8861f79ab
Exposes Maxima functionality of simplifying factorials and binomials, trac 6636
diff -r 81cbc5d22a61 -r d8ea95918407 sage/symbolic/expression.pyx
|
a
|
b
|
|
| 5059 | 5059 | .. seealso:: |
| 5060 | 5060 | |
| 5061 | 5061 | :meth:`simplify_full`, :meth:`simplify_trig`, |
| 5062 | | :meth:`simplify_rational`, :meth:`simplify_radical` |
| | 5062 | :meth:`simplify_rational`, :meth:`simplify_radical`, |
| | 5063 | :meth:`simplify_factorial` |
| 5063 | 5064 | |
| 5064 | 5065 | EXAMPLES:: |
| 5065 | 5066 | |
| … |
… |
|
| 5072 | 5073 | |
| 5073 | 5074 | def simplify_full(self): |
| 5074 | 5075 | """ |
| 5075 | | Applies simplify_trig, simplify_rational, and simplify_radical |
| | 5076 | Applies simplify_factorial, simplify_trig, simplify_rational, and simplify_radical |
| 5076 | 5077 | to self (in that order). |
| 5077 | 5078 | |
| 5078 | 5079 | ALIAS: simplify_full and full_simplify are the same. |
| … |
… |
|
| 5094 | 5095 | sage: f = sin(x/(x^2 + x)) |
| 5095 | 5096 | sage: f.simplify_full() |
| 5096 | 5097 | sin(1/(x + 1)) |
| | 5098 | |
| | 5099 | :: |
| | 5100 | |
| | 5101 | sage: var('n,k') |
| | 5102 | (n, k) |
| | 5103 | sage: f = binomial(n,k)*factorial(k)*factorial(n-k) |
| | 5104 | sage: f.simplify_full() |
| | 5105 | factorial(n) |
| 5097 | 5106 | """ |
| 5098 | 5107 | x = self |
| | 5108 | x = x.simplify_factorial() |
| 5099 | 5109 | x = x.simplify_trig() |
| 5100 | 5110 | x = x.simplify_rational() |
| 5101 | 5111 | x = x.simplify_radical() |
| … |
… |
|
| 5155 | 5165 | # TODO: come up with a way to intelligently wrap Maxima's way of |
| 5156 | 5166 | # fine-tuning all simplificationsrational |
| 5157 | 5167 | |
| | 5168 | def simplify_factorial(self): |
| | 5169 | """ |
| | 5170 | Simplify by combining expressions with factorials, and by |
| | 5171 | expanding binomials into factorials. |
| | 5172 | |
| | 5173 | ALIAS: factorial_simplify and simplify_factorial are the same |
| | 5174 | |
| | 5175 | EXAMPLES: |
| | 5176 | |
| | 5177 | Some examples are relatively clear:: |
| | 5178 | |
| | 5179 | sage: var('n,k') |
| | 5180 | (n, k) |
| | 5181 | sage: f = factorial(n+1)/factorial(n); f |
| | 5182 | factorial(n + 1)/factorial(n) |
| | 5183 | sage: f.simplify_factorial() |
| | 5184 | n + 1 |
| | 5185 | |
| | 5186 | :: |
| | 5187 | sage: f = factorial(n)*(n+1); f |
| | 5188 | (n + 1)*factorial(n) |
| | 5189 | sage: simplify(f) |
| | 5190 | (n + 1)*factorial(n) |
| | 5191 | sage: f.simplify_factorial() |
| | 5192 | factorial(n + 1) |
| | 5193 | |
| | 5194 | :: |
| | 5195 | |
| | 5196 | sage: f = binomial(n,k)*factorial(k)*factorial(n-k); f |
| | 5197 | factorial(-k + n)*factorial(k)*binomial(n,k) |
| | 5198 | sage: f.simplify_factorial() |
| | 5199 | factorial(n) |
| | 5200 | |
| | 5201 | A more complicated example, which needs further processing:: |
| | 5202 | |
| | 5203 | sage: f = factorial(x)/factorial(x-2)/2 + factorial(x+1)/factorial(x)/2; f |
| | 5204 | 1/2*factorial(x)/factorial(x - 2) + 1/2*factorial(x + 1)/factorial(x) |
| | 5205 | sage: g = f.simplify_factorial(); g |
| | 5206 | 1/2*(x - 1)*x + 1/2*x + 1/2 |
| | 5207 | sage: g.simplify_rational() |
| | 5208 | 1/2*x^2 + 1/2 |
| | 5209 | """ |
| | 5210 | return self.parent()(self._maxima_().makefact().factcomb().minfactorial()) |
| | 5211 | |
| | 5212 | factorial_simplify = simplify_factorial |
| | 5213 | |
| 5158 | 5214 | def simplify_radical(self): |
| 5159 | 5215 | r""" |
| 5160 | 5216 | Simplifies this symbolic expression, which can contain logs, |