Fields¶
- class sage.categories.fields.Fields(base_category)[source]¶
- Bases: - CategoryWithAxiom_singleton- The category of (commutative) fields, i.e. commutative rings where all nonzero 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, 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 - >>> 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[source]¶
- Bases: - object- euclidean_degree()[source]¶
- 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: QQ.one().euclidean_degree() 0 - >>> from sage.all import * >>> QQ.one().euclidean_degree() 0 
 - factor()[source]¶
- Return a factorization of - self.- Since - selfis either a unit or zero, this function is trivial.- EXAMPLES: - 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 - >>> 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)[source]¶
- 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 - >>> 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: gcd(15.0,12.0) # needs sage.rings.real_mpfr 3.00000000000000 - >>> 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: 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 - >>> 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()[source]¶
- Return the inverse of this element. - EXAMPLES: - sage: x = polygen(ZZ, 'x') sage: NumberField(x^7 + 2, 'a')(2).inverse_of_unit() # needs sage.rings.number_field 1/2 - >>> 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: QQ(0).inverse_of_unit() Traceback (most recent call last): ... ZeroDivisionError: rational division by zero - >>> 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: try: ....: QQ(0).inverse_of_unit() ....: except ArithmeticError: ....: pass - >>> 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: RR(0).inverse_of_unit() +infinity - >>> from sage.all import * >>> RR(Integer(0)).inverse_of_unit() +infinity 
 - is_unit()[source]¶
- Return - Trueif- selfhas a multiplicative inverse.- EXAMPLES: - sage: QQ(2).is_unit() True sage: QQ(0).is_unit() False - >>> from sage.all import * >>> QQ(Integer(2)).is_unit() True >>> QQ(Integer(0)).is_unit() False 
 - lcm(other)[source]¶
- 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 - >>> 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: lcm(15.0, 12.0) # needs sage.rings.real_mpfr 60.0000000000000 - >>> 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: 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 - >>> 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)[source]¶
- 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) - >>> from sage.all import * >>> f,g = QQ(Integer(1)), QQ(Integer(2)) >>> f.quo_rem(g) (1/2, 0) 
 - xgcd(other)[source]¶
- Compute the extended gcd of - selfand- other.- INPUT: - other– an element with the same parent as- self
 - OUTPUT: - A tuple - (r, s, t)of elements in the parent of- selfsuch that- r = s * self + t * other. Since the computations are done over a field,- ris zero if- selfand- otherare zero, and one otherwise.- AUTHORS: - Julian Rueth (2012-10-19): moved here from - sage.structure.element.FieldElement
 - 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) - >>> 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: 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) - >>> 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[source]¶
- alias of - FiniteFields
 - class ParentMethods[source]¶
- Bases: - object- divides(x, y, coerce=True)[source]¶
- Return - Trueif- xdivides- yin this field.- This is usually - Truein a field!.- If - coerceis- True(the default), first coerce- xand- yinto- self.- EXAMPLES: - sage: QQ.divides(2, 3/4) True sage: QQ.divides(0, 5) False - >>> from sage.all import * >>> QQ.divides(Integer(2), Integer(3)/Integer(4)) True >>> QQ.divides(Integer(0), Integer(5)) False 
 - fraction_field()[source]¶
- Return the fraction field of - self, which is- self.- EXAMPLES: - sage: QQ.fraction_field() is QQ True - >>> from sage.all import * >>> QQ.fraction_field() is QQ True 
 - ideal(*gens, **kwds)[source]¶
- 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: QQ.ideal(2) Principal ideal (1) of Rational Field sage: QQ.ideal(0) Principal ideal (0) of Rational Field - >>> 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()[source]¶
- Return this field, since fields are integrally closed in their fraction field. - EXAMPLES: - 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 - >>> 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)[source]¶
- Return - Trueas- selfis a field.- EXAMPLES: - sage: QQ.is_field() True sage: Parent(QQ,category=Fields()).is_field() True - >>> from sage.all import * >>> QQ.is_field() True >>> Parent(QQ,category=Fields()).is_field() True 
 - is_integrally_closed()[source]¶
- Return whether - selfis integrally closed.- For every field \(F\), \(F\) is its own field of fractions. Therefore every element of \(F\) is integral over \(F\). - EXAMPLES: - 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 - >>> 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()[source]¶
- 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 - >>> from sage.all import * >>> QQ.is_perfect() True >>> GF(Integer(2)).is_perfect() True >>> FunctionField(GF(Integer(2)), 'x').is_perfect() False 
 - krull_dimension()[source]¶
- Return the Krull dimension of this field, which is 0. - EXAMPLES: - sage: QQ.krull_dimension() 0 sage: Frac(QQ['x,y']).krull_dimension() 0 - >>> from sage.all import * >>> QQ.krull_dimension() 0 >>> Frac(QQ['x,y']).krull_dimension() 0 
 - prime_subfield()[source]¶
- Return the prime subfield of - self.- EXAMPLES: - sage: k = GF(9, 'a') # needs sage.rings.finite_rings sage: k.prime_subfield() # needs sage.rings.finite_rings Finite Field of size 3 - >>> 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)[source]¶
- 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- Vto this field
- to_V– the inverse isomorphism from this field to- V
 - EXAMPLES: - 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) - >>> 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)