Base Classes for Finite Fields
TESTS:
sage: K.<a> = NumberField(x^2 + 1)
sage: F = K.factor(3)[0][0].residue_field()
sage: loads(dumps(F)) == F
True
AUTHORS:
Bases: sage.rings.ring.Field
Abstract base class for finite fields.
Return an algebraic closure of self.
INPUT:
OUTPUT:
An algebraic closure of self. Note that mathematically speaking, this is only unique up to non-unique isomorphism. To obtain canonically defined algebraic closures, one needs an algorithm that also provides a canonical isomorphism between any two algebraic closures constructed using the algorithm.
This non-uniqueness problem can in principle be solved by using Conway polynomials; see for example [CP]. These have the drawback that computing them takes a long time. Therefore Sage implements a variant called pseudo-Conway polynomials, which are easier to compute but do not determine an algebraic closure up to unique isomorphism.
The output of this method is cached, so that within the same Sage session, calling it multiple times will return the same algebraic closure (i.e. the same Sage object). Despite this, the non-uniqueness of the current implementation means that coercion and pickling cannot work as one might expect. See below for an example.
EXAMPLE:
sage: F = GF(5).algebraic_closure()
sage: F
Algebraic closure of Finite Field of size 5
sage: F.gen(3)
z3
The default name is ‘z’ but you can change it through the option name:
sage: Ft = GF(5).algebraic_closure('t')
sage: Ft.gen(3)
t3
Because Sage currently only implements algebraic closures using a non-unique definition (see above), it is currently impossible to implement pickling in such a way that a pickled and unpickled element compares equal to the original:
sage: F = GF(7).algebraic_closure()
sage: x = F.gen(2)
sage: loads(dumps(x)) == x
False
Note
This is currently only implemented for prime fields.
REFERENCE:
[CP] | Wikipedia entry on Conway polynomials, Wikipedia article Conway_polynomial_(finite_fields) |
TEST:
sage: GF(5).algebraic_closure() is GF(5).algebraic_closure()
True
Return the cardinality of self.
Same as order().
EXAMPLES:
sage: GF(997).cardinality()
997
Return the construction of this finite field, as a ConstructionFunctor and the base field.
EXAMPLES:
sage: v = GF(3^3, conway=True, prefix='z').construction(); v
(AlgebraicExtensionFunctor, Finite Field of size 3)
sage: v[0].polys[0]
3
sage: v = GF(2^1000, 'a').construction(); v[0].polys[0]
a^1000 + a^5 + a^4 + a^3 + 1
Return an extension of this finite field.
INPUT:
OUTPUT:
An extension of the given modulus, or pseudo-Conway of the given degree if modulus is an integer.
EXAMPLES:
sage: k = GF(2)
sage: R.<x> = k[]
sage: k.extension(x^1000 + x^5 + x^4 + x^3 + 1, 'a')
Finite Field in a of size 2^1000
sage: k = GF(3^4, conway=True, prefix='z')
sage: R.<x> = k[]
sage: k.extension(3, conway=True, prefix='z')
Finite Field in z12 of size 3^12
An example using the map argument:
sage: F = GF(5)
sage: E, f = F.extension(2, 'b', map=True)
sage: E
Finite Field in b of size 5^2
sage: f
Ring morphism:
From: Finite Field of size 5
To: Finite Field in b of size 5^2
Defn: 1 |--> 1
sage: f.parent()
Set of field embeddings from Finite Field of size 5 to Finite Field in b of size 5^2
Extensions of non-prime finite fields by polynomials are not yet supported: we fall back to generic code:
sage: k.extension(x^5 + x^2 + x - 1)
Univariate Quotient Polynomial Ring in x over Finite Field in z4 of size 3^4 with modulus x^5 + x^2 + x + 2
Returns the factored order of this field. For compatibility with integer_mod_ring.
EXAMPLES:
sage: GF(7^2,'a').factored_order()
7^2
Returns the factorization of self.order()-1, as a 1-element list.
The format is for compatibility with integer_mod_ring.
EXAMPLES:
sage: GF(7^2,'a').factored_unit_order()
[2^4 * 3]
INPUT:
OUTPUT:
The \(n\)-th power of the absolute arithmetic Frobenius endomorphism on this finite field.
EXAMPLES:
sage: k.<t> = GF(3^5)
sage: Frob = k.frobenius_endomorphism(); Frob
Frobenius endomorphism t |--> t^3 on Finite Field in t of size 3^5
sage: a = k.random_element()
sage: Frob(a) == a^3
True
We can specify a power:
sage: k.frobenius_endomorphism(2)
Frobenius endomorphism t |--> t^(3^2) on Finite Field in t of size 3^5
The result is simplified if possible:
sage: k.frobenius_endomorphism(6)
Frobenius endomorphism t |--> t^3 on Finite Field in t of size 3^5
sage: k.frobenius_endomorphism(5)
Identity endomorphism of Finite Field in t of size 3^5
Comparisons work:
sage: k.frobenius_endomorphism(6) == Frob
True
sage: from sage.categories.morphism import IdentityMorphism
sage: k.frobenius_endomorphism(5) == IdentityMorphism(k)
True
AUTHOR:
Return a generator of this field (over its prime field). As this is an abstract base class, this just raises a NotImplementedError.
EXAMPLES:
sage: K = GF(17)
sage: sage.rings.finite_rings.finite_field_base.FiniteField.gen(K)
Traceback (most recent call last):
...
NotImplementedError
Return True if self is defined by a Conway polynomial.
EXAMPLES:
sage: GF(5^3, ‘a’).is_conway() True sage: GF(5^3, ‘a’, modulus=’adleman-lenstra’).is_conway() False sage: GF(next_prime(2^16, 2), ‘a’).is_conway() False
Returns whether or not the finite field is a field, i.e., always returns True.
EXAMPLES:
sage: k.<a> = FiniteField(3^4)
sage: k.is_field()
True
Return True since a finite field is finite.
EXAMPLES:
sage: GF(997).is_finite()
True
Return whether this field is perfect, i.e., every element has a \(p\)-th root. Always returns True since finite fields are perfect.
EXAMPLES:
sage: GF(2).is_perfect()
True
Return True if self is a prime field, i.e., has degree 1.
EXAMPLES:
sage: GF(3^7, 'a').is_prime_field()
False
sage: GF(3, 'a').is_prime_field()
True
Return the minimal polynomial of the generator of self (over an appropriate base field).
The minimal polynomial of an element \(a\) in a field is the unique irreducible polynomial of smallest degree with coefficients in the base field that has \(a\) as a root. In finite field extensions, \(\GF{p^n}\), the base field is \(\GF{p}\). Here are several examples:
sage: F.<a> = GF(7^2, 'a'); F
Finite Field in a of size 7^2
sage: F.polynomial_ring()
Univariate Polynomial Ring in a over Finite Field of size 7
sage: f = F.modulus(); f
x^2 + 6*x + 3
sage: f(a)
0
Although \(f\) is irreducible over the base field, we can double-check whether or not \(f\) factors in \(F\) as follows. The command F[x](f) coerces \(f\) as a polynomial with coefficients in \(F\). (Instead of a polynomial with coefficients over the base field.)
sage: f.factor()
x^2 + 6*x + 3
sage: F[x](f).factor()
(x + a + 6) * (x + 6*a)
Here is an example with a degree 3 extension:
sage: G.<b> = GF(7^3, 'b'); G
Finite Field in b of size 7^3
sage: g = G.modulus(); g
x^3 + 6*x^2 + 4
sage: g.degree(); G.degree()
3
3
Return a primitive element of this finite field, i.e. a generator of the multiplicative group.
You can use multiplicative_generator() or primitive_element(), these mean the same thing.
Warning
This generator might change from one version of Sage to another.
EXAMPLES:
sage: k = GF(997)
sage: k.multiplicative_generator()
7
sage: k.<a> = GF(11^3)
sage: k.primitive_element()
a
sage: k.<b> = GF(19^32)
sage: k.multiplicative_generator()
b + 4
TESTS:
Check that large characteristics work (trac ticket #11946):
sage: p = 10^20 + 39
sage: x = polygen(GF(p))
sage: K.<a> = GF(p^2, modulus=x^2+1)
sage: K.multiplicative_generator()
a + 12
The number of generators of the finite field. Always 1.
EXAMPLES:
sage: k = FiniteField(3^4, 'b')
sage: k.ngens()
1
Return the order of this finite field.
EXAMPLES:
sage: GF(997).order()
997
Return the defining polynomial of this finite field.
EXAMPLES:
sage: f = GF(27,'a').polynomial(); f
a^3 + 2*a + 1
sage: parent(f)
Univariate Polynomial Ring in a over Finite Field of size 3
Returns the polynomial ring over the prime subfield in the same variable as this finite field.
EXAMPLES:
sage: k.<alpha> = FiniteField(3^4)
sage: k.polynomial_ring()
Univariate Polynomial Ring in alpha over Finite Field of size 3
Return a primitive element of this finite field, i.e. a generator of the multiplicative group.
You can use multiplicative_generator() or primitive_element(), these mean the same thing.
Warning
This generator might change from one version of Sage to another.
EXAMPLES:
sage: k = GF(997)
sage: k.multiplicative_generator()
7
sage: k.<a> = GF(11^3)
sage: k.primitive_element()
a
sage: k.<b> = GF(19^32)
sage: k.multiplicative_generator()
b + 4
TESTS:
Check that large characteristics work (trac ticket #11946):
sage: p = 10^20 + 39
sage: x = polygen(GF(p))
sage: K.<a> = GF(p^2, modulus=x^2+1)
sage: K.multiplicative_generator()
a + 12
A random element of the finite field. Passes arguments to random_element() function of underlying vector space.
EXAMPLES:
sage: k = GF(19^4, 'a')
sage: k.random_element()
a^3 + 3*a^2 + 6*a + 9
Passes extra positional or keyword arguments through:
sage: k.random_element(prob=0)
0
Returns a collection of elements of this finite field for use in unit testing.
EXAMPLES:
sage: k = GF(2^8,'a')
sage: k.some_elements() # random output
[a^4 + a^3 + 1, a^6 + a^4 + a^3, a^5 + a^4 + a, a^2 + a]
Return all subfields of self of the given degree, or all possible degrees if degree is \(0\).
The subfields are returned as absolute fields together with an embedding into self.
INPUT:
OUTPUT:
A list of pairs (K, e), where K ranges over the subfields of this field and e gives an embedding of K into self.
EXAMPLES:
sage: k.<a> = GF(2^21, conway=True, prefix='z')
sage: k.subfields()
[(Finite Field of size 2,
Ring morphism:
From: Finite Field of size 2
To: Finite Field in a of size 2^21
Defn: 1 |--> 1),
(Finite Field in z3 of size 2^3,
Ring morphism:
From: Finite Field in z3 of size 2^3
To: Finite Field in a of size 2^21
Defn: z3 |--> a^20 + a^19 + a^17 + a^15 + a^11 + a^9 + a^8 + a^6 + a^2),
(Finite Field in z7 of size 2^7,
Ring morphism:
From: Finite Field in z7 of size 2^7
To: Finite Field in a of size 2^21
Defn: z7 |--> a^20 + a^19 + a^17 + a^15 + a^14 + a^6 + a^4 + a^3 + a),
(Finite Field in z21 of size 2^21,
Ring morphism:
From: Finite Field in z21 of size 2^21
To: Finite Field in a of size 2^21
Defn: z21 |--> a)]
The exponent of the unit group of the finite field. For a finite field, this is always the order minus 1.
EXAMPLES:
sage: k = GF(2^10, 'a')
sage: k.order()
1024
sage: k.unit_group_exponent()
1023
Return the vector space over the prime subfield isomorphic to this finite field as a vector space.
EXAMPLES:
sage: GF(27,'a').vector_space()
Vector space of dimension 3 over Finite Field of size 3
Returns an element of multiplicative order n in this finite field, if there is one. Raises a ValueError if there is not.
EXAMPLES:
sage: k = GF(7)
sage: k.zeta()
3
sage: k.zeta().multiplicative_order()
6
sage: k.zeta(3)
2
sage: k.zeta(3).multiplicative_order()
3
sage: k = GF(49, 'a')
sage: k.zeta().multiplicative_order()
48
sage: k.zeta(6)
3
Even more examples:
sage: GF(9,'a').zeta_order()
8
sage: GF(9,'a').zeta()
a
sage: GF(9,'a').zeta(4)
a + 1
sage: GF(9,'a').zeta()^2
a + 1
Return the order of the distinguished root of unity in self.
EXAMPLES:
sage: GF(9,'a').zeta_order()
8
sage: GF(9,'a').zeta()
a
sage: GF(9,'a').zeta().multiplicative_order()
8
Bases: object
An iterator over a finite field. This should only be used when the field is an extension of a smaller field which already has a separate iterator function.
x.next() -> the next value, or raise StopIteration
Return True if x is of type finite field, and False otherwise.
EXAMPLES:
sage: from sage.rings.finite_rings.finite_field_base import is_FiniteField
sage: is_FiniteField(GF(9,'a'))
True
sage: is_FiniteField(GF(next_prime(10^10)))
True
Note that the integers modulo n are not of type finite field, so this function returns False:
sage: is_FiniteField(Integers(7))
False
Used to unpickle extensions of finite fields. Now superseded (hence no doctest), but kept around for backward compatibility.
EXAMPLES:
sage: # not tested
Used to unpickle finite prime fields. Now superseded (hence no doctest), but kept around for backward compatibility.
EXAMPLE:
sage: # not tested