Base class for finite field elements
AUTHORS:
- David Roe (2010-1-14) -- factored out of sage.structure.element
Bases: sage.rings.finite_rings.element_base.FiniteRingElement
Elements represented as polynomials modulo a given ideal.
TESTS:
sage: k.<a> = GF(64)
sage: TestSuite(a).run()
Return the additive order of this finite field element.
EXAMPLES:
sage: k.<a> = FiniteField(2^12, 'a')
sage: b = a^3 + a + 1
sage: b.additive_order()
2
sage: k(0).additive_order()
1
Return the characteristic polynomial of self as a polynomial with given variable.
INPUT:
The result is not cached.
EXAMPLES:
sage: k.<a> = GF(19^2)
sage: parent(a)
Finite Field in a of size 19^2
sage: a.charpoly('X')
X^2 + 18*X + 2
sage: a^2 + 18*a + 2
0
sage: a.charpoly('X', algorithm='pari')
X^2 + 18*X + 2
Return the power of self, where
is the
characteristic of the field.
INPUT:
Note that if is negative, then this computes the appropriate root.
EXAMPLES:
sage: F.<a> = GF(29^2)
sage: z = a^2 + 5*a + 1
sage: z.pth_power()
19*a + 20
sage: z.pth_power(10)
10*a + 28
sage: z.pth_power(-10) == z
True
sage: F.<b> = GF(2^12)
sage: y = b^3 + b + 1
sage: y == (y.pth_power(-3))^(2^3)
True
sage: y.pth_power(2)
b^7 + b^6 + b^5 + b^4 + b^3 + b
Returns True if and only if this element is a perfect square.
EXAMPLES:
sage: k.<a> = FiniteField(9, impl='givaro', modulus='primitive')
sage: a.is_square()
False
sage: (a**2).is_square()
True
sage: k.<a> = FiniteField(4, impl='ntl', modulus='primitive')
sage: (a**2).is_square()
True
sage: k.<a> = FiniteField(17^5, impl='pari_ffelt', modulus='primitive')
sage: a.is_square()
False
sage: (a**2).is_square()
True
sage: k(0).is_square()
True
Returns the minimal polynomial of this element (over the corresponding prime subfield).
EXAMPLES:
sage: k.<a> = FiniteField(3^4)
sage: parent(a)
Finite Field in a of size 3^4
sage: b=a**20;p=charpoly(b,"y");p
y^4 + 2*y^2 + 1
sage: factor(p)
(y^2 + 1)^2
sage: b.minimal_polynomial('y')
y^2 + 1
Returns the minimal polynomial of this element (over the corresponding prime subfield).
EXAMPLES:
sage: k.<a> = FiniteField(19^2)
sage: parent(a)
Finite Field in a of size 19^2
sage: b=a**20;p=b.charpoly("x");p
x^2 + 15*x + 4
sage: factor(p)
(x + 17)^2
sage: b.minpoly('x')
x + 17
Return the multiplicative order of this field element.
EXAMPLE:
sage: S.<a> = GF(5^3); S
Finite Field in a of size 5^3
sage: a.multiplicative_order()
124
sage: (a^8).multiplicative_order()
31
sage: S(0).multiplicative_order()
Traceback (most recent call last):
...
ArithmeticError: Multiplicative order of 0 not defined.
Return the norm of self down to the prime subfield.
This is the product of the Galois conjugates of self.
EXAMPLES:
sage: S.<b> = GF(5^2); S
Finite Field in b of size 5^2
sage: b.norm()
2
sage: b.charpoly('t')
t^2 + 4*t + 2
Next we consider a cubic extension:
sage: S.<a> = GF(5^3); S
Finite Field in a of size 5^3
sage: a.norm()
2
sage: a.charpoly('t')
t^3 + 3*t + 3
sage: a * a^5 * (a^25)
2
Returns an th root of self.
INPUT:
OUTPUT:
If self has an th root, returns one (if all is False) or a
list of all of them (if all is True).
Otherwise, raises a ValueError (if extend is False)
or a NotImplementedError (if extend is True).
Warning
The extend option is not implemented (yet).
EXAMPLES:
sage: K = GF(31)
sage: a = K(22)
sage: K(22).nth_root(7)
13
sage: K(25).nth_root(5)
5
sage: K(23).nth_root(3)
29
sage: K.<a> = GF(625)
sage: (3*a^2+a+1).nth_root(13)**13
3*a^2 + a + 1
sage: k.<a> = GF(29^2)
sage: b = a^2 + 5*a + 1
sage: b.nth_root(11)
3*a + 20
sage: b.nth_root(5)
Traceback (most recent call last):
...
ValueError: no nth root
sage: b.nth_root(5, all = True)
[]
sage: b.nth_root(3, all = True)
[14*a + 18, 10*a + 13, 5*a + 27]
sage: k.<a> = GF(29^5)
sage: b = a^2 + 5*a + 1
sage: b.nth_root(5)
19*a^4 + 2*a^3 + 2*a^2 + 16*a + 3
sage: b.nth_root(7)
Traceback (most recent call last):
...
ValueError: no nth root
sage: b.nth_root(4, all=True)
[]
TESTS:
sage: for p in [2,3,5,7,11]: # long time, random because of PARI warnings
....: for n in [2,5,10]:
....: q = p^n
....: K.<a> = GF(q)
....: for r in (q-1).divisors():
....: if r == 1: continue
....: x = K.random_element()
....: y = x^r
....: assert y.nth_root(r)^r == y
....: assert (y^41).nth_root(41*r)^(41*r) == y^41
....: assert (y^307).nth_root(307*r)^(307*r) == y^307
sage: k.<a> = GF(4)
sage: a.nth_root(0,all=True)
[]
sage: k(1).nth_root(0,all=True)
[a, a + 1, 1]
ALGORITHMS:
Johnston, Anna M. A generalized qth root algorithm. Proceedings of the tenth annual ACM-SIAM symposium on Discrete algorithms. Baltimore, 1999: pp 929-930.
AUTHOR:
Return the power of self, where
is the
characteristic of the field.
INPUT:
Note that if is negative, then this computes the appropriate root.
EXAMPLES:
sage: F.<a> = GF(29^2)
sage: z = a^2 + 5*a + 1
sage: z.pth_power()
19*a + 20
sage: z.pth_power(10)
10*a + 28
sage: z.pth_power(-10) == z
True
sage: F.<b> = GF(2^12)
sage: y = b^3 + b + 1
sage: y == (y.pth_power(-3))^(2^3)
True
sage: y.pth_power(2)
b^7 + b^6 + b^5 + b^4 + b^3 + b
Return the root of self, where
is the characteristic
of the field.
INPUT:
Note that if is negative, then this computes the appropriate power.
EXAMPLES:
sage: F.<b> = GF(2^12)
sage: y = b^3 + b + 1
sage: y == (y.pth_root(3))^(2^3)
True
sage: y.pth_root(2)
b^11 + b^10 + b^9 + b^7 + b^5 + b^4 + b^2 + b
See :meth:square_root().
EXAMPLES:
sage: k.<a> = GF(3^17)
sage: (a^3 - a - 1).sqrt()
a^16 + 2*a^15 + a^13 + 2*a^12 + a^10 + 2*a^9 + 2*a^8 + a^7 + a^6 + 2*a^5 + a^4 + 2*a^2 + 2*a + 2
The square root function.
INPUT:
extend – bool (default: True); if True, return a square root in an extension ring, if necessary. Otherwise, raise a ValueError if the root is not in the base ring.
Warning
This option is not implemented!
all - bool (default: False); if True, return all square roots of self, instead of just one.
Warning
The 'extend' option is not implemented (yet).
EXAMPLES:
sage: F = FiniteField(7^2, 'a')
sage: F(2).square_root()
4
sage: F(3).square_root()
2*a + 6
sage: F(3).square_root()**2
3
sage: F(4).square_root()
2
sage: K = FiniteField(7^3, 'alpha', impl='pari_ffelt')
sage: K(3).square_root()
Traceback (most recent call last):
...
ValueError: must be a perfect square.
Return the trace of this element, which is the sum of the Galois conjugates.
EXAMPLES:
sage: S.<a> = GF(5^3); S
Finite Field in a of size 5^3
sage: a.trace()
0
sage: a.charpoly('t')
t^3 + 3*t + 3
sage: a + a^5 + a^25
0
sage: z = a^2 + a + 1
sage: z.trace()
2
sage: z.charpoly('t')
t^3 + 3*t^2 + 2*t + 2
sage: z + z^5 + z^25
2
Bases: sage.structure.element.CommutativeRingElement
INPUT:
Returns if x is a finite field element.
EXAMPLE:
sage: from sage.rings.finite_rings.element_base import is_FiniteFieldElement
sage: is_FiniteFieldElement(1)
False
sage: is_FiniteFieldElement(IntegerRing())
False
sage: is_FiniteFieldElement(GF(5)(2))
True