# Revision history [back]

In the given case, working over the rationals already work:

sage: var('s');
sage: L = 2*(s + 3)/(3*s^2 + 13*s + 10)
sage: L.partial_fraction()
2/7/(3*s + 10) + 4/7/(s + 1)
sage: version()
'SageMath version 7.5.1, Release Date: 2017-01-15'


There is no need to pass to more complicated rings.

Note that above L in an instance for the class

sage: L.__class__
<type 'sage.symbolic.expression.Expression'>
sage: L.parent()
Symbolic Ring


and generally, if a class provides a method with the "right name", than it also does the "right job". A similar method name, but for an other class is also working:

sage: R.<s> = PolynomialRing(QQ)
sage: L = 2*(s + 3)/(3*s^2 + 13*s + 10)
sage: L.parent()
Fraction Field of Univariate Polynomial Ring in s over Rational Field
sage: L.partial_fraction_decomposition()
(0, [4/7/(s + 1), 2/21/(s + 10/3)])


(After L was defined, i typed in the sage interpreter only L.part followed by [TABULATOR]. The method came automatically.)

To see where the explicit declaration of the coefficients fiels is / may be important, i will use an other examle: \begin{align} F &= \frac 1{x^4+4}\\ G &= \frac 1{x^4+1} . \end{align} In this case we try first symbolically...

sage: var( 'x' );
sage: F = 1/(x^4 + 4)
sage: G = 1/(x^4 + 1)
sage: F.partial_fraction()
1/8*(x + 2)/(x^2 + 2*x + 2) - 1/8*(x - 2)/(x^2 - 2*x + 2)
sage: G.partial_fraction()
1/(x^4 + 1)


We have to tell sage somehow something about the field to work in. We consider only G. The possibilities are:

• Work over the inexact field CC.
• over $\mathbb Q(\sqrt 2)$
• over $\mathbb Q(i)$
• over $\mathbb Q(\zeta_8)$

and the sample code is:

sage: K1.<a> = QuadraticField(2)
sage: K3.<c> = CyclotomicField(8)
sage: for K in (K1, K2, K3, CC):
....:     print "Field", K
....:     Kx = FractionField( PolynomialRing(K, names='x') )
....:     pprint.pprint( Kx(G).partial_fraction_decomposition() )
....:     print
....:
Field Number Field in a with defining polynomial x^2 - 2
(0, [(-1/4*a*x + 1/2)/(x^2 - a*x + 1), (1/4*a*x + 1/2)/(x^2 + a*x + 1)])

Field Number Field in b with defining polynomial x^2 + 1
(0, [(-1/2*b)/(x^2 - b), 1/2*b/(x^2 + b)])

Field Cyclotomic Field of order 8 and degree 4
(0, [(-1/4*c)/(x - c), 1/4*c/(x + c), (-1/4*c^3)/(x - c^3), 1/4*c^3/(x + c^3)])

Field Complex Field with 53 bits of precision
(0,
[(-0.176776695296637 - 0.176776695296637*I)/(x - 0.707106781186548 - 0.707106781186548*I),
(-0.176776695296637 + 0.176776695296637*I)/(x - 0.707106781186548 + 0.707106781186548*I),
(0.176776695296637 - 0.176776695296637*I)/(x + 0.707106781186548 - 0.707106781186548*I),
(0.176776695296637 + 0.176776695296637*I)/(x + 0.707106781186548 + 0.707106781186548*I)])


I hope the idea is clear.

In the given case, working over the rationals already work:works:

sage: var('s');
sage: L = 2*(s + 3)/(3*s^2 + 13*s + 10)
sage: L.partial_fraction()
2/7/(3*s + 10) + 4/7/(s + 1)
sage: version()
'SageMath version 7.5.1, Release Date: 2017-01-15'


There is no need to pass to more complicated rings.

Note that above L in an instance for the class

sage: L.__class__
<type 'sage.symbolic.expression.Expression'>
sage: L.parent()
Symbolic Ring


and generally, if a class provides a method with the "right name", than it also does the "right job". A similar method name, but for an other class is also working:

sage: R.<s> = PolynomialRing(QQ)
sage: L = 2*(s + 3)/(3*s^2 + 13*s + 10)
sage: L.parent()
Fraction Field of Univariate Polynomial Ring in s over Rational Field
sage: L.partial_fraction_decomposition()
(0, [4/7/(s + 1), 2/21/(s + 10/3)])


(After L was defined, i typed in the sage interpreter only L.part followed by [TABULATOR]. The method came automatically.)

To see where the explicit declaration of the coefficients fiels is / may be important, i will use an other examle: \begin{align} F &= \frac 1{x^4+4}\\ G &= \frac 1{x^4+1} . \end{align} In this case we try first symbolically...

sage: var( 'x' );
sage: F = 1/(x^4 + 4)
sage: G = 1/(x^4 + 1)
sage: F.partial_fraction()
1/8*(x + 2)/(x^2 + 2*x + 2) - 1/8*(x - 2)/(x^2 - 2*x + 2)
sage: G.partial_fraction()
1/(x^4 + 1)


We have to tell sage somehow something about the field to work in. We consider only G. The possibilities are:

• Work over the inexact field CC.
• over $\mathbb Q(\sqrt 2)$
• over $\mathbb Q(i)$
• over $\mathbb Q(\zeta_8)$

and etc.

And the sample code is:

sage: K1.<a> = QuadraticField(2)
sage: K3.<c> = CyclotomicField(8)
sage: for K in (K1, K2, K3, CC):
CC, QQbar, AA):
....:     print "Field", K
....:     Kx = FractionField( PolynomialRing(K, names='x') )
....:     pprint.pprint( Kx(G).partial_fraction_decomposition() )
....:     print
....:
Field ....:
Number Field in a with defining polynomial x^2 - 2
(0, [(-1/4*a*x + 1/2)/(x^2 - a*x + 1), (1/4*a*x + 1/2)/(x^2 + a*x + 1)])

Field Number Field in b with defining polynomial x^2 + 1
(0, [(-1/2*b)/(x^2 - b), 1/2*b/(x^2 + b)])

Field Cyclotomic Field of order 8 and degree 4
(0, [(-1/4*c)/(x - c), 1/4*c/(x + c), (-1/4*c^3)/(x - c^3), 1/4*c^3/(x + c^3)])

Field Complex Field with 53 bits of precision
(0,
[(-0.176776695296637 - 0.176776695296637*I)/(x - 0.707106781186548 - 0.707106781186548*I),
(-0.176776695296637 + 0.176776695296637*I)/(x - 0.707106781186548 + 0.707106781186548*I),
(0.176776695296637 - 0.176776695296637*I)/(x + 0.707106781186548 - 0.707106781186548*I),
(0.176776695296637 + 0.176776695296637*I)/(x + 0.707106781186548 + 0.707106781186548*I)])

Algebraic Field
(0,
[(-0.1767766952966369? - 0.1767766952966369?*I)/(x - 0.7071067811865475? - 0.7071067811865475?*I),
(-0.1767766952966369? + 0.1767766952966369?*I)/(x - 0.7071067811865475? + 0.7071067811865475?*I),
(0.1767766952966369? - 0.1767766952966369?*I)/(x + 0.7071067811865475? - 0.7071067811865475?*I),
(0.1767766952966369? + 0.1767766952966369?*I)/(x + 0.7071067811865475? + 0.7071067811865475?*I)])

Algebraic Real Field
(0,
[(-0.3535533905932738?*x + 1/2)/(x^2 - 1.414213562373095?*x + 1),
(0.3535533905932738?*x + 1/2)/(x^2 + 1.414213562373095?*x + 1)])

sage:


I hope the idea is clear.

(My preference is always to work over exact fields, if possible.)

In the given case, working over the rationals already works:

sage: var('s');
sage: L = 2*(s + 3)/(3*s^2 + 13*s + 10)
sage: L.partial_fraction()
2/7/(3*s + 10) + 4/7/(s + 1)
sage: version()
'SageMath version 7.5.1, Release Date: 2017-01-15'


There is no need to pass to more complicated rings.

Note that above L in an instance for the class

sage: L.__class__
<type 'sage.symbolic.expression.Expression'>
sage: L.parent()
Symbolic Ring


and generally, if a class provides a method with the "right name", than it also does the "right job". A similar method name, but for an other class is also working:

sage: R.<s> = PolynomialRing(QQ)
sage: L = 2*(s + 3)/(3*s^2 + 13*s + 10)
sage: L.parent()
Fraction Field of Univariate Polynomial Ring in s over Rational Field
sage: L.partial_fraction_decomposition()
(0, [4/7/(s + 1), 2/21/(s + 10/3)])


(After L was defined, i typed in the sage interpreter only L.part followed by [TABULATOR]. The method came automatically.)

To see where the explicit declaration of the coefficients fiels is / may be important, i will use an other examle: \begin{align} F &= \frac 1{x^4+4}\\ G &= \frac 1{x^4+1} . \end{align} In this case we try first symbolically...

sage: var( 'x' );
sage: F = 1/(x^4 + 4)
sage: G = 1/(x^4 + 1)
sage: F.partial_fraction()
1/8*(x + 2)/(x^2 + 2*x + 2) - 1/8*(x - 2)/(x^2 - 2*x + 2)
sage: G.partial_fraction()
1/(x^4 + 1)


We have to tell sage somehow something about the field to work in. We consider only G. The possibilities are:

• Work over the inexact field CC.
• over $\mathbb Q(\sqrt 2)$
• over $\mathbb Q(i)$
• over $\mathbb Q(\zeta_8)$

etc.

And the sample code is:

sage: K1.<a> = QuadraticField(2)
sage: K3.<c> = CyclotomicField(8)
sage: for K in (K1, K2, K3, CC, QQbar, AA):
....:     print K
....:     Kx = FractionField( PolynomialRing(K, names='x') )
....:     pprint.pprint( Kx(G).partial_fraction_decomposition() )
....:     print
....:
....:
Number Field in a with defining polynomial x^2 - 2
(0, [(-1/4*a*x + 1/2)/(x^2 - a*x + 1), (1/4*a*x + 1/2)/(x^2 + a*x + 1)])

Number Field in b with defining polynomial x^2 + 1
(0, [(-1/2*b)/(x^2 - b), 1/2*b/(x^2 + b)])

Cyclotomic Field of order 8 and degree 4
(0, [(-1/4*c)/(x - c), 1/4*c/(x + c), (-1/4*c^3)/(x - c^3), 1/4*c^3/(x + c^3)])

Complex Field with 53 bits of precision
(0,
[(-0.176776695296637 - 0.176776695296637*I)/(x - 0.707106781186548 - 0.707106781186548*I),
(-0.176776695296637 + 0.176776695296637*I)/(x - 0.707106781186548 + 0.707106781186548*I),
(0.176776695296637 - 0.176776695296637*I)/(x + 0.707106781186548 - 0.707106781186548*I),
(0.176776695296637 + 0.176776695296637*I)/(x + 0.707106781186548 + 0.707106781186548*I)])

Algebraic Field
(0,
[(-0.1767766952966369? - 0.1767766952966369?*I)/(x - 0.7071067811865475? - 0.7071067811865475?*I),
(-0.1767766952966369? + 0.1767766952966369?*I)/(x - 0.7071067811865475? + 0.7071067811865475?*I),
(0.1767766952966369? - 0.1767766952966369?*I)/(x + 0.7071067811865475? - 0.7071067811865475?*I),
(0.1767766952966369? + 0.1767766952966369?*I)/(x + 0.7071067811865475? + 0.7071067811865475?*I)])

Algebraic Real Field
(0,
[(-0.3535533905932738?*x + 1/2)/(x^2 - 1.414213562373095?*x + 1),
(0.3535533905932738?*x + 1/2)/(x^2 + 1.414213562373095?*x + 1)])

sage:


I hope the idea is clear.

(My preference is always to work over exact fields, if possible.)