Fields - Category Framework

Skip to content
Back to top
View this page
Edit this page

# Fields

class sage.categories.fields.Fields(base_category)

  Bases: `CategoryWithAxiom_singleton`

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

  EXAMPLES:

  Sage

      sage: K = Fields()
      sage: K
      Category of fields
      sage: Fields().super_categories()
      [Category of euclidean domains,
       Category of division rings,
       Category of noetherian 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())                                                            # needs sage.rings.real_mpfr
      Real Field with 53 bits of precision

  Python

      >>> from sage.all import *
      >>> K = Fields()
      >>> K
      Category of fields
      >>> Fields().super_categories()
      [Category of euclidean domains,
       Category of division rings,
       Category of noetherian rings]

      >>> K(IntegerRing())
      Rational Field
      >>> K(PolynomialRing(GF(Integer(3)), 'x'))
      Fraction Field of Univariate Polynomial Ring in x over
      Finite Field of size 3
      >>> K(RealField())                                                            # needs sage.rings.real_mpfr
      Real Field with 53 bits of precision

  class ElementMethods

    Bases: `object`

    euclidean_degree()

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

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

      EXAMPLES:

      Sage

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

      Python

          >>> from sage.all import *
          >>> 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

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

      Python

          >>> from sage.all import *
          >>> x = GF(Integer(7))(Integer(5))
          >>> x.factor()
          5
          >>> RR(Integer(0)).factor()                                                    # needs sage.rings.real_mpfr
          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

          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

      Python

          >>> from sage.all import *
          >>> K = GF(Integer(5))
          >>> K(Integer(2)).gcd(K(Integer(1)))
          1
          >>> K(Integer(0)).gcd(K(Integer(0)))
          0
          >>> all(x.gcd(y) == (Integer(0) if x == Integer(0) and y == Integer(0) else Integer(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

          sage: gcd(15.0,12.0)                                                    # needs sage.rings.real_mpfr
          3.00000000000000

      [Python]

          >>> from sage.all import *
          >>> gcd(RealNumber('15.0'),RealNumber('12.0'))                                                    # needs sage.rings.real_mpfr
          3.00000000000000

      But for other floating point numbers, the gcd is just \(0.0\) or \(1.0\):

      Sage

          sage: gcd(3.2, 2.18)                                                    # needs sage.rings.real_mpfr
          1.00000000000000

          sage: gcd(0.0, 0.0)                                                     # needs sage.rings.real_mpfr
          0.000000000000000

      Python

          >>> from sage.all import *
          >>> gcd(RealNumber('3.2'), RealNumber('2.18'))                                                    # needs sage.rings.real_mpfr
          1.00000000000000

          >>> gcd(RealNumber('0.0'), RealNumber('0.0'))                                                     # needs sage.rings.real_mpfr
          0.000000000000000

      AUTHOR:

      - Simon King (2011-02) – Issue #10771

      - Vincent Delecroix (2015) – Issue #17671

    inverse_of_unit()

      Return the inverse of this element.

      EXAMPLES:

      Sage

          sage: x = polygen(ZZ, 'x')
          sage: NumberField(x^7 + 2, 'a')(2).inverse_of_unit()                    # needs sage.rings.number_field
          1/2

      Python

          >>> from sage.all import *
          >>> x = polygen(ZZ, 'x')
          >>> NumberField(x**Integer(7) + Integer(2), 'a')(Integer(2)).inverse_of_unit()                    # needs sage.rings.number_field
          1/2

      Trying to invert the zero element typically raises a `ZeroDivisionError`:

      Sage

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

      [Python]

          >>> from sage.all import *
          >>> QQ(Integer(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

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

      Python

          >>> from sage.all import *
          >>> try:
          ...    QQ(Integer(0)).inverse_of_unit()
          ... except ArithmeticError:
          ...    pass

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

      Sage

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

      [Python]

          >>> from sage.all import *
          >>> RR(Integer(0)).inverse_of_unit()
          +infinity

    is_unit()

      Return `True` if `self` has a multiplicative inverse.

      EXAMPLES:

      Sage

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

      Python

          >>> from sage.all import *
          >>> QQ(Integer(2)).is_unit()
          True
          >>> QQ(Integer(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

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

      Python

          >>> from sage.all import *
          >>> GF(Integer(2))(Integer(1)).lcm(GF(Integer(2))(Integer(0)))
          0
          >>> GF(Integer(2))(Integer(1)).lcm(GF(Integer(2))(Integer(1)))
          1

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

      Sage

          sage: lcm(15.0, 12.0)                                                   # needs sage.rings.real_mpfr
          60.0000000000000

      [Python]

          >>> from sage.all import *
          >>> lcm(RealNumber('15.0'), RealNumber('12.0'))                                                   # needs sage.rings.real_mpfr
          60.0000000000000

      But for others floating point numbers, it is just \(0.0\) or \(1.0\):

      Sage

          sage: lcm(3.2, 2.18)                                                    # needs sage.rings.real_mpfr
          1.00000000000000

          sage: lcm(0.0, 0.0)                                                     # needs sage.rings.real_mpfr
          0.000000000000000

      Python

          >>> from sage.all import *
          >>> lcm(RealNumber('3.2'), RealNumber('2.18'))                                                    # needs sage.rings.real_mpfr
          1.00000000000000

          >>> lcm(RealNumber('0.0'), RealNumber('0.0'))                                                     # needs sage.rings.real_mpfr
          0.000000000000000

      AUTHOR:

      - Simon King (2011-02) – Issue #10771

      - Vincent Delecroix (2015) – Issue #17671

    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

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

      Python

          >>> from sage.all import *
          >>> f,g = QQ(Integer(1)), QQ(Integer(2))
          >>> 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:

      - Julian Rueth (2012-10-19): moved here from `sage.structure.element.FieldElement`

      EXAMPLES:

      Sage

          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)

      Python

          >>> from sage.all import *
          >>> K = GF(Integer(5))
          >>> K(Integer(2)).xgcd(K(Integer(1)))
          (1, 3, 0)
          >>> K(Integer(0)).xgcd(K(Integer(4)))
          (1, 0, 4)
          >>> K(Integer(1)).xgcd(K(Integer(1)))
          (1, 1, 0)
          >>> GF(Integer(5))(Integer(0)).xgcd(GF(Integer(5))(Integer(0)))
          (0, 0, 0)

      The xgcd of nonzero 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

          sage: xgcd(12.0, 8.0)                                                   # needs sage.rings.real_mpfr
          (4.00000000000000, 1.00000000000000, -1.00000000000000)

          sage: xgcd(3.1, 2.98714)                                                # needs sage.rings.real_mpfr
          (1.00000000000000, 0.322580645161290, 0.000000000000000)

          sage: xgcd(0.0, 1.1)                                                    # needs sage.rings.real_mpfr
          (1.00000000000000, 0.000000000000000, 0.909090909090909)

      [Python]

          >>> from sage.all import *
          >>> xgcd(RealNumber('12.0'), RealNumber('8.0'))                                                   # needs sage.rings.real_mpfr
          (4.00000000000000, 1.00000000000000, -1.00000000000000)

          >>> xgcd(RealNumber('3.1'), RealNumber('2.98714'))                                                # needs sage.rings.real_mpfr
          (1.00000000000000, 0.322580645161290, 0.000000000000000)

          >>> xgcd(RealNumber('0.0'), RealNumber('1.1'))                                                    # needs sage.rings.real_mpfr
          (1.00000000000000, 0.000000000000000, 0.909090909090909)

  Finite

    alias of `FiniteFields`

  class ParentMethods

    Bases: `object`

    algebraic_closure()

      Return the algebraic closure of `self`.

      Note

      This is only implemented for certain classes of field.

      EXAMPLES:

      Sage

          sage: K = PolynomialRing(QQ,'x').fraction_field(); K
          Fraction Field of Univariate Polynomial Ring in x over Rational Field
          sage: K.algebraic_closure()
          Traceback (most recent call last):
          ...
          NotImplementedError: algebraic closures of general fields not implemented

      Python

          >>> from sage.all import *
          >>> K = PolynomialRing(QQ,'x').fraction_field(); K
          Fraction Field of Univariate Polynomial Ring in x over Rational Field
          >>> K.algebraic_closure()
          Traceback (most recent call last):
          ...
          NotImplementedError: algebraic closures of general fields not implemented

    an_embedding(K)

      Return some embedding of this field into another field \(K\), and raise a `ValueError` if none exists.

      EXAMPLES:

      Sage

          sage: GF(2).an_embedding(GF(4))
          Ring morphism:
            From: Finite Field of size 2
            To:   Finite Field in z2 of size 2^2
            Defn: 1 |--> 1
          sage: GF(4).an_embedding(GF(8))
          Traceback (most recent call last):
          ...
          ValueError: no embedding from Finite Field in z2 of size 2^2 to Finite Field in z3 of size 2^3
          sage: GF(4).an_embedding(GF(16))
          Ring morphism:
            From: Finite Field in z2 of size 2^2
            To:   Finite Field in z4 of size 2^4
            Defn: z2 |--> z4^2 + z4

      Python

          >>> from sage.all import *
          >>> GF(Integer(2)).an_embedding(GF(Integer(4)))
          Ring morphism:
            From: Finite Field of size 2
            To:   Finite Field in z2 of size 2^2
            Defn: 1 |--> 1
          >>> GF(Integer(4)).an_embedding(GF(Integer(8)))
          Traceback (most recent call last):
          ...
          ValueError: no embedding from Finite Field in z2 of size 2^2 to Finite Field in z3 of size 2^3
          >>> GF(Integer(4)).an_embedding(GF(Integer(16)))
          Ring morphism:
            From: Finite Field in z2 of size 2^2
            To:   Finite Field in z4 of size 2^4
            Defn: z2 |--> z4^2 + z4

      Sage

          sage: CyclotomicField(5).an_embedding(QQbar)
          Coercion map:
            From: Cyclotomic Field of order 5 and degree 4
            To:   Algebraic Field
          sage: CyclotomicField(3).an_embedding(CyclotomicField(7))
          Traceback (most recent call last):
          ...
          ValueError: no embedding from Cyclotomic Field of order 3 and degree 2 to Cyclotomic Field of order 7 and degree 6
          sage: CyclotomicField(3).an_embedding(CyclotomicField(6))
          Generic morphism:
            From: Cyclotomic Field of order 3 and degree 2
            To:   Cyclotomic Field of order 6 and degree 2
            Defn: zeta3 -> zeta6 - 1

      [Python]

          >>> from sage.all import *
          >>> CyclotomicField(Integer(5)).an_embedding(QQbar)
          Coercion map:
            From: Cyclotomic Field of order 5 and degree 4
            To:   Algebraic Field
          >>> CyclotomicField(Integer(3)).an_embedding(CyclotomicField(Integer(7)))
          Traceback (most recent call last):
          ...
          ValueError: no embedding from Cyclotomic Field of order 3 and degree 2 to Cyclotomic Field of order 7 and degree 6
          >>> CyclotomicField(Integer(3)).an_embedding(CyclotomicField(Integer(6)))
          Generic morphism:
            From: Cyclotomic Field of order 3 and degree 2
            To:   Cyclotomic Field of order 6 and degree 2
            Defn: zeta3 -> zeta6 - 1

    divides(x, y, coerce=True)

      Return `True` if `x` divides `y` in this field.

      This is usually `True` in a field!.

      If `coerce` is `True` (the default), first coerce `x` and `y` into `self`.

      EXAMPLES:

      Sage

          sage: QQ.divides(2, 3/4)
          True
          sage: QQ.divides(0, 5)
          False

      Python

          >>> from sage.all import *
          >>> QQ.divides(Integer(2), Integer(3)/Integer(4))
          True
          >>> QQ.divides(Integer(0), Integer(5))
          False

    fraction_field()

      Return the fraction field of `self`, which is `self`.

      EXAMPLES:

      Since fields are their own field of fractions, we simply get the original field in return:

      Sage

          sage: QQ.fraction_field()
          Rational Field
          sage: RR.fraction_field()                                                   # needs sage.rings.real_mpfr
          Real Field with 53 bits of precision
          sage: CC.fraction_field()                                                   # needs sage.rings.real_mpfr
          Complex Field with 53 bits of precision

          sage: x = polygen(ZZ, 'x')
          sage: F = NumberField(x^2 + 1, 'i')                                         # needs sage.rings.number_field
          sage: F.fraction_field()                                                    # needs sage.rings.number_field
          Number Field in i with defining polynomial x^2 + 1

      Python

          >>> from sage.all import *
          >>> QQ.fraction_field()
          Rational Field
          >>> RR.fraction_field()                                                   # needs sage.rings.real_mpfr
          Real Field with 53 bits of precision
          >>> CC.fraction_field()                                                   # needs sage.rings.real_mpfr
          Complex Field with 53 bits of precision

          >>> x = polygen(ZZ, 'x')
          >>> F = NumberField(x**Integer(2) + Integer(1), 'i')                                         # needs sage.rings.number_field
          >>> F.fraction_field()                                                    # needs sage.rings.number_field
          Number Field in i with defining polynomial x^2 + 1

    ideal(*gens, **kwds)

      Return the ideal generated by `gens`.

      INPUT:

      - an element or a list/tuple/sequence of elements, the generators

      Any named arguments are ignored.

      EXAMPLES:

      Sage

          sage: QQ.ideal(2)
          Principal ideal (1) of Rational Field
          sage: QQ.ideal(0)
          Principal ideal (0) of Rational Field

      Python

          >>> from sage.all import *
          >>> QQ.ideal(Integer(2))
          Principal ideal (1) of Rational Field
          >>> QQ.ideal(Integer(0))
          Principal ideal (0) of Rational Field

    integral_closure()

      Return this field, since fields are integrally closed in their fraction field.

      EXAMPLES:

      Sage

          sage: QQ.integral_closure()
          Rational Field
          sage: Frac(ZZ['x,y']).integral_closure()
          Fraction Field of Multivariate Polynomial Ring in x, y
          over Integer Ring

      Python

          >>> from sage.all import *
          >>> QQ.integral_closure()
          Rational Field
          >>> Frac(ZZ['x,y']).integral_closure()
          Fraction Field of Multivariate Polynomial Ring in x, y
          over Integer Ring

    is_field(proof=True)

      Return `True` as `self` is a field.

      EXAMPLES:

      Sage

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

          sage: Frac(ZZ['x,y']).is_field()
          True

      Python

          >>> from sage.all import *
          >>> QQ.is_field()
          True
          >>> Parent(QQ,category=Fields()).is_field()
          True

          >>> Frac(ZZ['x,y']).is_field()
          True

    is_integrally_closed()

      Return whether `self` is integrally closed.

      For every field \(F\), \(F\) is its own field of fractions. Therefore every element of \(F\) is integral over \(F\).

      EXAMPLES:

      Sage

          sage: QQ.is_integrally_closed()
          True
          sage: QQbar.is_integrally_closed()                                      # needs sage.rings.number_field
          True
          sage: Z5 = GF(5); Z5
          Finite Field of size 5
          sage: Z5.is_integrally_closed()
          True
          sage: Frac(ZZ['x,y']).is_integrally_closed()
          True

      Python

          >>> from sage.all import *
          >>> QQ.is_integrally_closed()
          True
          >>> QQbar.is_integrally_closed()                                      # needs sage.rings.number_field
          True
          >>> Z5 = GF(Integer(5)); Z5
          Finite Field of size 5
          >>> Z5.is_integrally_closed()
          True
          >>> Frac(ZZ['x,y']).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

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

      Python

          >>> from sage.all import *
          >>> QQ.is_perfect()
          True
          >>> GF(Integer(2)).is_perfect()
          True
          >>> FunctionField(GF(Integer(2)), 'x').is_perfect()
          False

    krull_dimension()

      Return the Krull dimension of this field, which is 0.

      EXAMPLES:

      Sage

          sage: QQ.krull_dimension()
          0
          sage: Frac(QQ['x,y']).krull_dimension()
          0

      Python

          >>> from sage.all import *
          >>> QQ.krull_dimension()
          0
          >>> Frac(QQ['x,y']).krull_dimension()
          0

    prime_subfield()

      Return the prime subfield of `self`.

      EXAMPLES:

      Sage

          sage: k = GF(9, 'a')                                                        # needs sage.rings.finite_rings
          sage: k.prime_subfield()                                                    # needs sage.rings.finite_rings
          Finite Field of size 3

      Python

          >>> from sage.all import *
          >>> k = GF(Integer(9), 'a')                                                        # needs sage.rings.finite_rings
          >>> k.prime_subfield()                                                    # needs sage.rings.finite_rings
          Finite Field of size 3

    vector_space(*args, **kwds)

      Give 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

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

      Python

          >>> from sage.all import *
          >>> # needs sage.rings.padics
          >>> K = Qq(Integer(125), names=('a',)); (a,) = K._first_ngens(1)
          >>> V, fr, to = K.vector_space()
          >>> v = V([Integer(1), Integer(2), Integer(3)])
          >>> fr(v, Integer(7))
          (3*a^2 + 2*a + 1) + O(5^7)

  extra_super_categories()

    EXAMPLES:

    Sage

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

    Python

        >>> from sage.all import *
        >>> Fields().extra_super_categories()
        [Category of euclidean domains, Category of noetherian rings]