Fraction Field Elements

AUTHORS:

  • William Stein (input from David Joyner, David Kohel, and Joe Wetherell)
class sage.rings.fraction_field_element.FractionFieldElement

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)
__abs__()

EXAMPLES:

sage: from sage.rings.fraction_field_element import FractionFieldElement
sage: abs(FractionFieldElement(QQ, -2, 3, coerce=False))
2/3
__call__()

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
__copy__()

EXAMPLES:

sage: R.<x,y> = ZZ[]
sage: f = x/y+1; f
(x + y)/y
sage: copy(f)
(x + y)/y
__eq__()
x.__eq__(y) <==> x==y
__float__()

EXAMPLES:

sage: K.<x,y> = Frac(ZZ['x,y'])
sage: float(x/x + y/y)
2.0
__ge__()
x.__ge__(y) <==> x>=y
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__int__()

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
__invert__()

EXAMPLES:

sage: K.<t> = Frac(GF(7)['t'])
sage: f = (t^2+5)/(t-1)
sage: ~f
(t + 6)/(t^2 + 5)
__le__()
x.__le__(y) <==> x<=y
__long__()

EXAMPLES:

sage: K.<x> = Frac(QQ['x'])
sage: long(K(3))
3L
sage: long(K(3/5))
0L
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
__neg__()

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)
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__nonzero__()
x.__nonzero__() <==> x != 0
__pow__()
x.__pow__(y[, z]) <==> pow(x, y[, z])
__reduce__()

EXAMPLES:

sage: F = ZZ['x,y'].fraction_field()
sage: f = F.random_element()
sage: loads(f.dumps()) == f
True
__rpow__()
y.__rpow__(x[, z]) <==> pow(x, y[, z])
_add_()

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
_derivative()

Return the derivative of this rational function with respect to the variable var.

See also

derivative()

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)
_div_()

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)
_im_gens_()

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
_integer_()

EXAMPLES:

sage: K = Frac(ZZ['x'])
sage: K(5)._integer_()
5
sage: K.<x> = Frac(RR['x'])
sage: ZZ(2*x/x)
2
_is_atomic()

EXAMPLES:

sage: K.<x> = Frac(ZZ['x'])
sage: x._is_atomic()
True
sage: f = 1/(x+1)
sage: f._is_atomic()
False
_latex_()

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
_magma_init_()

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
_mul_()

EXAMPLES:

sage: K.<t> = Frac(GF(7)['t'])
sage: a = t/(1+t)
sage: b = 3/t
sage: a*b
3/(t + 1)
_rational_()

EXAMPLES:

sage: K.<x> = Frac(QQ['x'])
sage: K(1/2)._rational_()
1/2
sage: K(1/2 + x/x)._rational_()
3/2
_repr_()

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'
_sub_()

EXAMPLES:

sage: K.<t> = Frac(GF(7)['t'])
sage: t - 1/t
(t^2 + 6)/t
denominator()

EXAMPLES:

sage: R.<x,y> = ZZ[]
sage: f = x/y+1; f
(x + y)/y
sage: f.denominator()
y
derivative()

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

_derivative()

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)
factor()

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)
is_one()

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
is_zero()

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
numerator()

EXAMPLES:

sage: R.<x,y> = ZZ[]
sage: f = x/y+1; f
(x + y)/y
sage: f.numerator()
x + y
partial_fraction_decomposition()

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:

  • Robert Bradshaw (2007-05-31)

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)])
reduce()

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
valuation()

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
sage.rings.fraction_field_element.is_FractionFieldElement()

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
sage.rings.fraction_field_element.make_element()

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)
sage.rings.fraction_field_element.make_element_old()

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)

Previous topic

Fraction Field of Integral Domains

Next topic

Quotient Rings

This Page