Hi,
On 20 August 2014 21:28, Ondřej Čertík <
ondrej...@gmail.com> wrote:
> Hi Clemens,
>
> On Wed, Aug 20, 2014 at 5:15 AM, clemens novak <
clen...@gmail.com> wrote:
>> I have a question regarding the apart function. I want to obtain the partial
>> fractions for eq = z / (z**2-z-1) .
>>
>> The denominator has real roots solve(denom(eq)) yields [1/2 + sqrt(5)/2 ,
>> 1/2- sqrt(5)/2], but apart does not return the partial fractions; i,e.
>> apart(eq, z) = z/(z**2 - z - 1) .
>>
>> Using apart(eq, z, full=True) yields RootSum(_w**2 - _w - 1, Lambda(_a,
>> (_a/5 + 2/5)/(-_a + z))) which doesn't seem to be of much help (at least for
>> me).
>>
>> Using apart with a fraction with "simpler" roots produces the desired
>> partial fractions; e.g. apart (z / (z**2+z-2), z) yields 2/(3*(z + 2)) +
>> 1/(3*(z - 1))
>>
>> Are there any additional options I can provide to apart to obtain the
>> desired result?
>
> Good point. I checked Mathematica and it produces the same result as SymPy.
> However, clearly this can be decomposed, so I don't quite understand
> if this is a bug in Mathematica as well,
> or whether perhaps there is some reason not to do the decomposition
> for this case.
There is no bug in this case. apart() uses polynomial factorization
routines to "decompose" the denominator. By default, sympy (but also
many other computer algebra systems) work over the rationals and z**2
- z - 1 doesn't have rational zeros. If you invoke apart(f, z), then
you will get partial fraction decomposition over rationals. To get the
expected result, you have set the domain of computation properly, e.g.
apart(f, z, extension=sqrt(5)) is helpful in this case. apart()
accepts all options that factor() and other polynomial manipulation
functions accept.
In [1]: apart(z/(z**2 - z - 1), z, extension=sqrt(5))
Out[1]:
___ ___
╲╱ 5 + 5 -5 + ╲╱ 5
─────────────────── - ───────────────────
⎛ ___ ⎞ ⎛ ___⎞
5⋅⎝2⋅z - ╲╱ 5 - 1⎠ 5⋅⎝2⋅z - 1 + ╲╱ 5 ⎠
In [2]: simplify(_)
Out[2]:
z
──────────
2
z - z - 1
Another option is to use full=True (no need for extension, because
this method doesn't use factorization at all). The result seems
useless at first but you can use .doit() on the resulting RootSum to
get more familiar result:
In [1]: apart(z/(z**2 - z - 1), z, full=True)
Out[1]:
⎛ a 2 ⎞
⎜ ─ + ─ ⎟
⎜ 2 5 5 ⎟
RootSum⎜w - w - 1, a ↦ ──────⎟
⎝ -a + z⎠
In [2]: _.doit()
Out[2]:
___ ___
╲╱ 5 1 ╲╱ 5 1
───── + ─ - ───── + ─
10 2 10 2
───────────── + ─────────────
___ ___
╲╱ 5 1 1 ╲╱ 5
z - ───── - ─ z - ─ + ─────
2 2 2 2
In [3]: simplify(_)
Out[3]:
z
──────────
2
z - z - 1
It would be good to document this in apart()'s docstring (the current
one is pretty weak), because it's a common misconception that apart()
uses either roots() or solve() to decompose the denominator.
Mateusz
> To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CADDwiVA8P6izbs%2Ba2QtGm9ntFNzxO%2ByVMSROmuvuG5iqetvLMg%40mail.gmail.com.