# Casting and Partial Fractions for symbolic generating function?

This is probably a silly question, but I can't seem to find an answer anywhere. It seems odd to me that Sage should allow us to get a series expansion for a generating function, but won't allow us to use a partial fraction decomposition...

sage: version()
'SageMath version 8.9, Release Date: 2019-09-29'
sage: F, z = SR.var('F z')
sage: system = [(F - z)/z^2 == F + F/z]
sage: sols = solve(system, F, solution_dict=True)
sage: sols
[{F: -z/(z^2 + z - 1)}]
sage: F = sols[F]
sage: F
-z/(z^2 + z - 1)
sage: F.series(z, 11)
1*z + 1*z^2 + 2*z^3 + 3*z^4 + 5*z^5 + 8*z^6
+ 13*z^7 + 21*z^8 + 34*z^9 + 55*z^10 + Order(z^11)
sage: F.partial_fraction(z)
-z/(z^2 + z - 1)


Sage is (correctly) working with $$F$$ over a symbolic ring, and I'm not sure how to make it do a partial fraction decomposition over $$\mathbb{C}$$.

Any tips on best practices for this would be amazing! Ideally, I wouldn't have to convert to rational functions over $$\mathbb{C}$$ and back, since I might want to keep manipulating it symbolically afterwards, but at this point I don't even know how to convert it.

To work over the field of rational functions in z with coefficients in QQbar, define it as follows:

sage: R = PolynomialRing(QQbar, 'z').fraction_field()


then get F as an element of that ring:

sage: FF = R(F)
sage: FF
(-z)/(z^2 + z - 1)


and use the partial_fraction_decomposition method:

sage: FF.partial_fraction_decomposition()
(0,
[(-0.2763932022500211?)/(z - 0.618033988749895?),
(-0.7236067977499790?)/(z + 1.618033988749895?)])


Note that the coefficients are now elements in QQbar.

If you need their radical expressions:

sage: for pf in pfd:
....:     num, den = pf.numerator(), pf.denominator()
....:     print("* partial fraction: {}".format(pf))
....:     print("  where {} = {}".format(num, num.radical_expression()))
....:     print("  and {} = {}".format(den, den.radical_expression()))
....:
* partial fraction: (-0.2763932022500211?)/(z - 0.618033988749895?)
where -0.2763932022500211? = 1/2*sqrt(1/5) - 1/2
and -0.618033988749895? = -1/2*sqrt(5) + 1/2
* partial fraction: (-0.7236067977499790?)/(z + 1.618033988749895?)
where -0.7236067977499790? = -1/2*sqrt(1/5) - 1/2
and 1.618033988749895? = 1/2*sqrt(5) + 1/2

• Thank you! If I want to continue manipulating FF symbolically, is that still possible, or would I need to cast back? And if you don't mind, what are the differences between using symbolic functions and using "actual" functions? Sorry for so many questions! – HallaSurvivor Jan 27 at 23:30
• nevermind - it seems SR is the appropriate ring. Thanks again! ^_^ – HallaSurvivor Jan 28 at 0:11