AUTHORS:
EXAMPLES:
sage: K, x = FractionField(PolynomialRing(QQ, 'x')).objgen()
sage: K
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: loads(K.dumps()) == K
True
sage: f = (x^3 + x)/(17 - x^19); f
(x^3 + x)/(-x^19 + 17)
sage: loads(f.dumps()) == f
True
TESTS:
Test if #5451 is fixed:
sage: A = FiniteField(9,'theta')['t']
sage: K.<t> = FractionField(A)
sage: f= 2/(t^2+2*t); g =t^9/(t^18 + t^10 + t^2);f+g
(2*t^15 + 2*t^14 + 2*t^13 + 2*t^12 + 2*t^11 + 2*t^10 + 2*t^9 + t^7 + t^6 + t^5 + t^4 + t^3 + t^2 + t + 1)/(t^17 + t^9 + t)
EXAMPLES:
sage: from sage.rings.fraction_field_element import FractionFieldElement
sage: abs(FractionFieldElement(QQ, -2, 3, coerce=False))
2/3
Evaluate the fraction at the given arguments. This assumes that a call function is defined for the numerator and denominator.
EXAMPLES:
sage: x = PolynomialRing(RationalField(),'x',3).gens()
sage: f = x[0] + x[1] - 2*x[1]*x[2]
sage: f
-2*x1*x2 + x0 + x1
sage: f(1,2,5)
-17
sage: h = f /(x[1] + x[2])
sage: h
(-2*x1*x2 + x0 + x1)/(x1 + x2)
sage: h(1,2,5)
-17/7
EXAMPLES:
sage: R.<x,y> = ZZ[]
sage: f = x/y+1; f
(x + y)/y
sage: copy(f)
(x + y)/y
EXAMPLES:
sage: K.<x,y> = Frac(ZZ['x,y'])
sage: float(x/x + y/y)
2.0
EXAMPLES:
sage: K = Frac(ZZ['x'])
sage: int(K(-3))
-3
sage: K.<x> = Frac(RR['x'])
sage: x/x
1.00000000000000*x/(1.00000000000000*x)
sage: int(x/x)
1
sage: int(K(.5))
0
EXAMPLES:
sage: K.<t> = Frac(GF(7)['t'])
sage: f = (t^2+5)/(t-1)
sage: ~f
(t + 6)/(t^2 + 5)
EXAMPLES:
sage: K.<x> = Frac(QQ['x'])
sage: long(K(3))
3L
sage: long(K(3/5))
0L
EXAMPLES:
sage: K.<t> = Frac(GF(5)['t'])
sage: f = (t^2+t)/(t+2); f
(t^2 + t)/(t + 2)
sage: -f
(4*t^2 + 4*t)/(t + 2)
EXAMPLES:
sage: F = ZZ['x,y'].fraction_field()
sage: f = F.random_element()
sage: loads(f.dumps()) == f
True
EXAMPLES:
sage: K.<x,y> = Frac(ZZ['x,y'])
sage: x+y
x + y
sage: 1/x + 1/y
(x + y)/(x*y)
sage: 1/x + 1/(x*y)
(y + 1)/(x*y)
sage: Frac(CDF['x']).gen() + 3
1.0*x + 3.0
Return the derivative of this rational function with respect to the variable var.
See also
EXAMPLES:
sage: F = FractionField(PolynomialRing(RationalField(),'x'))
sage: x = F.gen()
sage: t = 1/x^2
sage: t._derivative(x)
-2/x^3
sage: t.derivative()
-2/x^3
sage: F = FractionField(PolynomialRing(RationalField(),'x,y'))
sage: x,y = F.gens()
sage: t = (x*y/(x+y))
sage: t._derivative(x)
y^2/(x^2 + 2*x*y + y^2)
sage: t._derivative(y)
x^2/(x^2 + 2*x*y + y^2)
EXAMPLES:
sage: K.<x,y,z> = Frac(ZZ['x,y,z'])
sage: a = (x+1)*(x+y)/(z-3)
sage: b = (x+y)/(z-1)
sage: a/b
(x*z - x + z - 1)/(z - 3)
EXAMPLES:
sage: F = ZZ['x,y'].fraction_field()
sage: x,y = F.gens()
sage: K = GF(7)['a,b'].fraction_field()
sage: a,b = K.gens()
sage: phi = F.hom([a+b, a*b], K)
sage: phi(x+y) # indirect doctest
a*b + a + b
sage: (x^2/y)._im_gens_(K, [a+b, a*b])
(a^2 + 2*a*b + b^2)/(a*b)
sage: (x^2/y)._im_gens_(K, [a, a*b])
a/b
EXAMPLES:
sage: K = Frac(ZZ['x'])
sage: K(5)._integer_()
5
sage: K.<x> = Frac(RR['x'])
sage: ZZ(2*x/x)
2
EXAMPLES:
sage: K.<x> = Frac(ZZ['x'])
sage: x._is_atomic()
True
sage: f = 1/(x+1)
sage: f._is_atomic()
False
Return a latex representation of this rational function.
EXAMPLES:
sage: R = PolynomialRing(QQ, 'x')
sage: F = R.fraction_field()
sage: x = F.gen()
sage: a = x^2 / 1
sage: latex(a)
x^{2}
sage: latex(x^2/(x^2+1))
\frac{x^{2}}{x^{2} + 1}
sage: a = 1/x
sage: latex(a)
\frac{1}{x}
TESTS:
sage: from sage.rings.fraction_field_element import FractionFieldElement
sage: z = FractionFieldElement(F, 0, R.gen(), coerce=False)
sage: z.numerator() == 0
True
sage: z.denominator() == R.gen()
True
sage: latex(z)
0
Return a string representation of self Magma can understand.
EXAMPLES:
sage: R.<x> = ZZ[]
sage: magma((x^2 + x + 1)/(x + 1)) # optional - magma
(x^2 + x + 1)/(x + 1)
sage: R.<x,y> = QQ[]
sage: magma((x+y)/x) # optional - magma
(x + y)/x
EXAMPLES:
sage: K.<t> = Frac(GF(7)['t'])
sage: a = t/(1+t)
sage: b = 3/t
sage: a*b
3/(t + 1)
EXAMPLES:
sage: K.<x> = Frac(QQ['x'])
sage: K(1/2)._rational_()
1/2
sage: K(1/2 + x/x)._rational_()
3/2
EXAMPLES:
sage: K.<x> = Frac(ZZ['x'])
sage: repr(x+1)
'x + 1'
sage: repr((x+1)/(x-1))
'(x + 1)/(x - 1)'
sage: repr(1/(x-1))
'1/(x - 1)'
sage: repr(1/x)
'1/x'
EXAMPLES:
sage: K.<t> = Frac(GF(7)['t'])
sage: t - 1/t
(t^2 + 6)/t
EXAMPLES:
sage: R.<x,y> = ZZ[]
sage: f = x/y+1; f
(x + y)/y
sage: f.denominator()
y
The derivative of this rational function, with respect to variables supplied in args.
Multiple variables and iteration counts may be supplied; see documentation for the global derivative() function for more details.
See also
EXAMPLES:
sage: F = FractionField(PolynomialRing(RationalField(),'x'))
sage: x = F.gen()
sage: (1/x).derivative()
-1/x^2
sage: (x+1/x).derivative(x, 2)
2/x^3
sage: F = FractionField(PolynomialRing(RationalField(),'x,y'))
sage: x,y = F.gens()
sage: (1/(x+y)).derivative(x,y)
2/(x^3 + 3*x^2*y + 3*x*y^2 + y^3)
Return the factorization of self over the base ring
EXAMPLES:
sage: K.<x> = QQ[]
sage: f = (x^3+x)/(x-3)
sage: f.factor()
(x - 3)^-1 * x * (x^2 + 1)
Returns True if this element is equal to one.
EXAMPLES:
sage: F = ZZ['x,y'].fraction_field()
sage: x,y = F.gens()
sage: (x/x).is_one()
True
sage: (x/y).is_one()
False
Returns True if this element is equal to zero.
EXAMPLES:
sage: F = ZZ['x,y'].fraction_field()
sage: x,y = F.gens()
sage: t = F(0)/x
sage: t.is_zero()
True
sage: u = 1/x - 1/x
sage: u.is_zero()
True
sage: u.parent() is F
True
EXAMPLES:
sage: R.<x,y> = ZZ[]
sage: f = x/y+1; f
(x + y)/y
sage: f.numerator()
x + y
Decomposes fraction field element into a whole part and a list of fraction field elements over prime power denominators.
The sum will be equal to the original fraction.
AUTHORS:
EXAMPLES:
sage: S.<t> = QQ[]
sage: q = 1/(t+1) + 2/(t+2) + 3/(t-3); q
(6*t^2 + 4*t - 6)/(t^3 - 7*t - 6)
sage: whole, parts = q.partial_fraction_decomposition(); parts
[3/(t - 3), 1/(t + 1), 2/(t + 2)]
sage: sum(parts) == q
True
sage: q = 1/(t^3+1) + 2/(t^2+2) + 3/(t-3)^5
sage: whole, parts = q.partial_fraction_decomposition(); parts
[1/3/(t + 1), 3/(t^5 - 15*t^4 + 90*t^3 - 270*t^2 + 405*t - 243), (-1/3*t + 2/3)/(t^2 - t + 1), 2/(t^2 + 2)]
sage: sum(parts) == q
True
We do the best we can over in-exact fields:
sage: R.<x> = RealField(20)[]
sage: q = 1/(x^2 + 2)^2 + 1/(x-1); q
(1.0000*x^4 + 4.0000*x^2 + 1.0000*x + 3.0000)/(1.0000*x^5 - 1.0000*x^4 + 4.0000*x^3 - 4.0000*x^2 + 4.0000*x - 4.0000)
sage: whole, parts = q.partial_fraction_decomposition(); parts
[1.0000/(1.0000*x - 1.0000), 1.0000/(1.0000*x^4 + 4.0000*x^2 + 4.0000)]
sage: sum(parts)
(1.0000*x^4 + 4.0000*x^2 + 1.0000*x + 3.0000)/(1.0000*x^5 - 1.0000*x^4 + 4.0000*x^3 - 4.0000*x^2 + 4.0000*x - 4.0000)
TESTS:
We test partial fraction for irreducible denominators:
sage: R.<x> = ZZ[]
sage: q = x^2/(x-1)
sage: q.partial_fraction_decomposition()
(x + 1, [1/(x - 1)])
sage: q = x^10/(x-1)^5
sage: whole, parts = q.partial_fraction_decomposition()
sage: whole + sum(parts) == q
True
And also over finite fields (see trac #6052):
sage: R.<x> = GF(2)[]
sage: q = (x+1)/(x^3+x+1)
sage: q.partial_fraction_decomposition()
(0, [(x + 1)/(x^3 + x + 1)])
Divides out the gcd of the numerator and denominator.
Automatically called for exact rings, but because it may be numerically unstable for inexact rings it must be called manually in that case.
EXAMPLES:
sage: R.<x> = RealField(10)[]
sage: f = (x^2+2*x+1)/(x+1); f
(1.0*x^2 + 2.0*x + 1.0)/(1.0*x + 1.0)
sage: f.reduce(); f
1.0*x + 1.0
Return the valuation of self, assuming that the numerator and denominator have valuation functions defined on them.
EXAMPLES:
sage: x = PolynomialRing(RationalField(),'x').gen()
sage: f = (x**3 + x)/(x**2 - 2*x**3)
sage: f
(x^2 + 1)/(-2*x^2 + x)
sage: f.valuation()
-1
Returns whether or not x is of type FractionFieldElement
EXAMPLES:
sage: from sage.rings.fraction_field_element import is_FractionFieldElement
sage: R.<x> = ZZ[]
sage: is_FractionFieldElement(x/2)
False
sage: is_FractionFieldElement(2/x)
True
sage: is_FractionFieldElement(1/3)
False
Used for unpickling FractionFieldElement objects (and subclasses).
EXAMPLES:
sage: from sage.rings.fraction_field_element import make_element
sage: R = ZZ['x,y']
sage: x,y = R.gens()
sage: F = R.fraction_field()
sage: make_element(F, 1+x, 1+y)
(x + 1)/(y + 1)
Used for unpickling old FractionFieldElement pickles.
EXAMPLES:
sage: from sage.rings.fraction_field_element import make_element_old
sage: R.<x,y> = ZZ[]
sage: F = R.fraction_field()
sage: make_element_old(F, {'_FractionFieldElement__numerator':x+y,'_FractionFieldElement__denominator':x-y})
(x + y)/(x - y)