Sympy apart() with complex variables

519 views
Skip to first unread message

s5s

unread,
Apr 12, 2021, 9:13:57 AM4/12/21
to sympy
Hi,

I am trying to do partial fractions involving a complex variable. I was wondering if one can do this with sympy apart function. Below is the code to attempt this but it does not return a decomposed expression.


from sympy import *
x, y, z = symbols('x, y, z')
s= symbols('s', complex=True, real=False)
num = s - 1
den = s**2 + 4*s + 13
apart(num/den)

The function (s**2 + 4*s+13) can be decomposed into 2 partial fractions with denominators (s + 2 - j3) and (s + 2 + j3) where j is the sqrt(-1).

I am not sure if this functionality is not available or if I've missed out a constraint or a step. I've certainly used sympy to do partial fractions many times but the variables were real unlike this time.

Regards

Oscar Benjamin

unread,
Apr 12, 2021, 9:49:43 AM4/12/21
to sympy
Whether or not the variables are real does not matter. The question is
what domain sympy can use to factor the denominator. By default it
only tries to factor over the rationals. In this case it factors in
the Gaussian integers which are given by the extension ZZ[I] where ZZ
is the ring of integers and I is sqrt(-1):

>>> apart(num/den, extension=I)
(1/2 - I/2)/(s + 2 + 3*I) + (1/2 + I/2)/(s + 2 - 3*I)

More generally the extension needs to generate a field over which the
denominator factors so you need to pass the roots of the denominator:

>>> apart(num/den, extension=roots(den, s, multiple=True))
(1/2 - I/2)/(s + 2 + 3*I) + (1/2 + I/2)/(s + 2 - 3*I)

We should probably make it so that extension=True or something can
compute this automatically.


Oscar
Reply all
Reply to author
Forward
0 new messages