# Fields#

class sage.categories.fields.Fields(base_category)#

The category of (commutative) fields, i.e. commutative rings where all non-zero elements have multiplicative inverses

EXAMPLES:

sage: K = Fields()
sage: K
Category of fields
sage: Fields().super_categories()
[Category of euclidean domains, Category of division rings]

sage: K(IntegerRing())
Rational Field
sage: K(PolynomialRing(GF(3), 'x'))
Fraction Field of Univariate Polynomial Ring in x over
Finite Field of size 3
sage: K(RealField())
Real Field with 53 bits of precision

class ElementMethods#

Bases: object

euclidean_degree()#

Return the degree of this element as an element of an Euclidean domain.

In a field, this returns 0 for all but the zero element (for which it is undefined).

EXAMPLES:

sage: QQ.one().euclidean_degree()
0

factor()#

Return a factorization of self.

Since self is either a unit or zero, this function is trivial.

EXAMPLES:

sage: x = GF(7)(5)
sage: x.factor()
5
sage: RR(0).factor()
Traceback (most recent call last):
...
ArithmeticError: factorization of 0.000000000000000 is not defined

gcd(other)#

Greatest common divisor.

Note

Since we are in a field and the greatest common divisor is only determined up to a unit, it is correct to either return zero or one. Note that fraction fields of unique factorization domains provide a more sophisticated gcd.

EXAMPLES:

sage: K = GF(5)
sage: K(2).gcd(K(1))
1
sage: K(0).gcd(K(0))
0
sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) for x in K for y in K)
True


For field of characteristic zero, the gcd of integers is considered as if they were elements of the integer ring:

sage: gcd(15.0,12.0)
3.00000000000000


But for other floating point numbers, the gcd is just $$0.0$$ or $$1.0$$:

sage: gcd(3.2, 2.18)
1.00000000000000

sage: gcd(0.0, 0.0)
0.000000000000000


AUTHOR:

inverse_of_unit()#

Return the inverse of this element.

EXAMPLES:

sage: NumberField(x^7+2,'a')(2).inverse_of_unit()
1/2


Trying to invert the zero element typically raises a ZeroDivisionError:

sage: QQ(0).inverse_of_unit()
Traceback (most recent call last):
...
ZeroDivisionError: rational division by zero


To catch that exception in a way that also works for non-units in more general rings, use something like:

sage: try:
....:    QQ(0).inverse_of_unit()
....: except ArithmeticError:
....:    pass


Also note that some “fields” allow one to invert the zero element:

sage: RR(0).inverse_of_unit()
+infinity

is_unit()#

Returns True if self has a multiplicative inverse.

EXAMPLES:

sage: QQ(2).is_unit()
True
sage: QQ(0).is_unit()
False

lcm(other)#

Least common multiple.

Note

Since we are in a field and the least common multiple is only determined up to a unit, it is correct to either return zero or one. Note that fraction fields of unique factorization domains provide a more sophisticated lcm.

EXAMPLES:

sage: GF(2)(1).lcm(GF(2)(0))
0
sage: GF(2)(1).lcm(GF(2)(1))
1


For field of characteristic zero, the lcm of integers is considered as if they were elements of the integer ring:

sage: lcm(15.0,12.0)
60.0000000000000


But for others floating point numbers, it is just $$0.0$$ or $$1.0$$:

sage: lcm(3.2, 2.18)
1.00000000000000

sage: lcm(0.0, 0.0)
0.000000000000000


AUTHOR:

quo_rem(other)#

Return the quotient with remainder of the division of this element by other.

INPUT:

• other – an element of the field

EXAMPLES:

sage: f,g = QQ(1), QQ(2)
sage: f.quo_rem(g)
(1/2, 0)

xgcd(other)#

Compute the extended gcd of self and other.

INPUT:

• other – an element with the same parent as self

OUTPUT:

A tuple (r, s, t) of elements in the parent of self such that r = s * self + t * other. Since the computations are done over a field, r is zero if self and other are zero, and one otherwise.

AUTHORS:

EXAMPLES:

sage: K = GF(5)
sage: K(2).xgcd(K(1))
(1, 3, 0)
sage: K(0).xgcd(K(4))
(1, 0, 4)
sage: K(1).xgcd(K(1))
(1, 1, 0)
sage: GF(5)(0).xgcd(GF(5)(0))
(0, 0, 0)


The xgcd of non-zero floating point numbers will be a triple of floating points. But if the input are two integral floating points the result is a floating point version of the standard gcd on $$\ZZ$$:

sage: xgcd(12.0, 8.0)
(4.00000000000000, 1.00000000000000, -1.00000000000000)

sage: xgcd(3.1, 2.98714)
(1.00000000000000, 0.322580645161290, 0.000000000000000)

sage: xgcd(0.0, 1.1)
(1.00000000000000, 0.000000000000000, 0.909090909090909)

Finite#

alias of FiniteFields

class ParentMethods#

Bases: object

fraction_field()#

Returns the fraction field of self, which is self.

EXAMPLES:

sage: QQ.fraction_field() is QQ
True

is_field(proof=True)#

Returns True as self is a field.

EXAMPLES:

sage: QQ.is_field()
True
sage: Parent(QQ,category=Fields()).is_field()
True

is_integrally_closed()#

Return True, as per IntegralDomain.is_integrally_closed(): for every field $$F$$, $$F$$ is its own field of fractions, hence every element of $$F$$ is integral over $$F$$.

EXAMPLES:

sage: QQ.is_integrally_closed()
True
sage: QQbar.is_integrally_closed()
True
sage: Z5 = GF(5); Z5
Finite Field of size 5
sage: Z5.is_integrally_closed()
True

is_perfect()#

Return whether this field is perfect, i.e., its characteristic is $$p=0$$ or every element has a $$p$$-th root.

EXAMPLES:

sage: QQ.is_perfect()
True
sage: GF(2).is_perfect()
True
sage: FunctionField(GF(2), 'x').is_perfect()
False

vector_space(*args, **kwds)#

Gives an isomorphism of this field with a vector space over a subfield.

This method is an alias for free_module, which may have more documentation.

INPUT:

• base – a subfield or morphism into this field (defaults to the base field)

• basis – a basis of the field as a vector space over the subfield; if not given, one is chosen automatically

• map – whether to return maps from and to the vector space

OUTPUT:

• V – a vector space over base

• from_V – an isomorphism from V to this field

• to_V – the inverse isomorphism from this field to V

EXAMPLES:

sage: K.<a> = Qq(125)                                   # optional - sage.rings.padics
sage: V, fr, to = K.vector_space()                      # optional - sage.rings.padics
sage: v = V([1, 2, 3])                                  # optional - sage.rings.padics
sage: fr(v, 7)                                          # optional - sage.rings.padics
(3*a^2 + 2*a + 1) + O(5^7)

extra_super_categories()#

EXAMPLES:

sage: Fields().extra_super_categories()
[Category of euclidean domains]