Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" Relative finite field extensions
Considering a *absolute field* `F_{q^m}` and a *relative_field* `F_q`, with `q = p^s`, `p` being a prime and `s, m` being integers, this file contains a class to take care of the representation of `F_{q^m}`-elements as `F_q`-elements.
.. WARNING::
As this code is experimental, a warning is thrown when a relative finite field extension is created for the first time in a session (see :class:`sage.misc.superseded.experimental`).
TESTS::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: RelativeFiniteFieldExtension(Fqm, Fq) doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See http://trac.sagemath.org/20284 for details. Relative field extension between Finite Field in aa of size 2^4 and Finite Field in a of size 2^2 """
#***************************************************************************** # Copyright (C) 2016 David Lucas <david.lucas@inria.fr> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #*****************************************************************************
r""" Considering `p` a prime number, n an integer and three finite fields `F_p`, `F_q` and `F_{q^m}`, this class contains a set of methods to manage the representation of elements of the relative extension `F_{q^m}` over `F_q`.
INPUT:
- ``absolute_field``, ``relative_field`` -- two finite fields, ``relative_field`` being a subfield of ``absolute_field``
- ``embedding`` -- (default: ``None``) an homomorphism from ``relative_field`` to ``absolute_field``. If ``None`` is provided, it will default to the first homomorphism of the list of homomorphisms Sage can build.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: RelativeFiniteFieldExtension(Fqm, Fq) Relative field extension between Finite Field in aa of size 2^4 and Finite Field in a of size 2^2
It is possible to specify the embedding to use from ``relative_field`` to ``absolute_field``::
sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq, embedding=Hom(Fq, Fqm)[1]) sage: FE.embedding() == Hom(Fq, Fqm)[1] True """
r""" TESTS:
If ``absolute_field`` is not a finite field, an error is raised::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm = RR sage: Fq.<a> = GF(4) sage: RelativeFiniteFieldExtension(Fqm, Fq) Traceback (most recent call last): ... ValueError: absolute_field has to be a finite field
Same for ``relative_field``::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq = RR sage: RelativeFiniteFieldExtension(Fqm, Fq) Traceback (most recent call last): ... ValueError: relative_field has to be a finite field
If ``relative_field`` is not a subfield of ``absolute_field``, an exception is raised::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(8) sage: RelativeFiniteFieldExtension(Fqm, Fq) Traceback (most recent call last): ... ValueError: relative_field has to be a subfield of absolute_field """ raise ValueError("embedding has to be an embedding from relative_field to absolute_field") else:
r""" Returns a string representation of ``self``.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: RelativeFiniteFieldExtension(Fqm, Fq) Relative field extension between Finite Field in aa of size 2^4 and Finite Field in a of size 2^2 """
r""" Returns a latex representation of ``self``.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: latex(RelativeFiniteFieldExtension(Fqm, Fq)) \textnormal{Relative field extension between \Bold{F}_{2^{4}} and \Bold{F}_{2^{2}}} """ self.relative_field()._latex_())
r""" Tests equality between embeddings.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fq = GF(4) sage: FQ = GF(4**3) sage: H = Hom(Fq, FQ) sage: E1 = RelativeFiniteFieldExtension(FQ, Fq) sage: E2 = RelativeFiniteFieldExtension(FQ, Fq, H[0]) sage: E3 = RelativeFiniteFieldExtension(FQ, Fq, H[1]) sage: E1 == E2 True sage: E1 == E3 False """ and self.embedding() == other.embedding()
def _representation_matrix(self): r""" Returns the matrix used to represents elements of the absolute field as vectors in the basis of the relative field over the prime field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE._representation_matrix() [1 0 0 0] [0 0 1 1] [0 1 1 1] [0 0 0 1] """ for i in range(m) for j in range(s)])
r""" Returns a vector representation of ``b`` in the basis of the relative field over the prime field.
INPUT:
- ``b`` -- an element of the absolute field
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: b = aa^3 + aa^2 + aa + 1 sage: FE._flattened_relative_field_representation(b) (1, 0, 1, 1) """ raise ValueError("The input has to be an element of the absolute field")
r""" Returns a vector representation of the field element ``b`` in the basis of the absolute field over the relative field.
INPUT:
- ``b`` -- an element of the absolute field
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: b = aa^3 + aa^2 + aa + 1 sage: FE.relative_field_representation(b) (1, a + 1) """ raise ValueError("The input has to be an element of the absolute field") else:
r""" Returns an absolute field representation of the relative field vector ``a``.
INPUT:
- ``a`` -- a vector in the relative extension field
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: b = aa^3 + aa^2 + aa + 1 sage: rel = FE.relative_field_representation(b) sage: FE.absolute_field_representation(rel) == b True """ raise ValueError("The input has to be a vector with length equal to the order of the absolute field") raise ValueError("The input has to be over the prime field")
r""" Returns ``True`` if ``b`` is in the relative field.
INPUT:
- ``b`` -- an element of the absolute field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.is_in_relative_field(aa^2 + aa) True sage: FE.is_in_relative_field(aa^3) False """
r""" Casts an absolute field element into the relative field (if possible). This is the inverse function of the field embedding.
INPUT:
- ``b`` -- an element of the absolute field which also lies in the relative field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: phi = FE.embedding() sage: b = aa^2 + aa sage: FE.is_in_relative_field(b) True sage: FE.cast_into_relative_field(b) a sage: phi(FE.cast_into_relative_field(b)) == b True """
r""" Returns the embedding which is used to go from the relative field to the absolute field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.embedding() Ring morphism: From: Finite Field in a of size 2^2 To: Finite Field in aa of size 2^4 Defn: a |--> aa^2 + aa """
r""" Returns a basis of the relative field over the prime field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.relative_field_basis() [1, a] """
r""" Returns a basis of the absolute field over the prime field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.absolute_field_basis() [1, aa, aa^2, aa^3] """
r""" Let `F_p` be the base field of our relative field `F_q`. Returns `s` where `p^s = q`
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.relative_field_degree() 2 """
r""" Let `F_p` be the base field of our absolute field `F_{q^m}`. Returns `sm` where `p^{sm} = q^{m}`
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.absolute_field_degree() 4 """
r""" Return `m`, the extension degree of the absiolute field over the relative field.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(64) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.extension_degree() 3 """
r""" Returns the base field of our absolute and relative fields.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.prime_field() Finite Field of size 2 """
r""" Returns the relative field of ``self``.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.relative_field() Finite Field in a of size 2^2 """
r""" Returns the absolute field of ``self``.
EXAMPLES::
sage: from sage.coding.relative_finite_field_extension import * sage: Fqm.<aa> = GF(16) sage: Fq.<a> = GF(4) sage: FE = RelativeFiniteFieldExtension(Fqm, Fq) sage: FE.absolute_field() Finite Field in aa of size 2^4 """ |