def __init__(self, q, names="a", modulus=None, repr="poly"): """ Initialize ``self``. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: no such algorithm for finding an irreducible polynomial: strangeinput sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3.<a> = GF(2^16, impl="pari_ffelt") sage: k1 == k3 False sage: TestSuite(k).run() sage: k.<a> = GF(2^64) sage: k._repr_option('element_is_atomic') False sage: P.<x> = PolynomialRing(k) sage: (a+1)*x # indirect doctest (a + 1)*x """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") FiniteField.__init__(self, GF2, names, normalize=True) self._kwargs = {'repr': repr} from sage.rings.polynomial.polynomial_element import is_Polynomial if not is_Polynomial(modulus): from sage.misc.superseded import deprecation deprecation( 16983, "constructing a FiniteField_ntl_gf2e without giving a polynomial as modulus is deprecated, use the more general FiniteField constructor instead" ) R = GF2['x'] if modulus is None or isinstance(modulus, str): modulus = R.irreducible_element(k, algorithm=modulus) else: modulus = R(modulus) self._cache = Cache_ntl_gf2e(self, k, modulus) self._modulus = modulus
def __init__(self, q, names="a", modulus=None, repr="poly"): """ Initialize ``self``. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: Modulus parameter not understood sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3 = k1._finite_field_ext_pari_() sage: k1 == k3 False sage: TestSuite(k).run() sage: k.<a> = GF(2^64) sage: k._repr_option('element_is_atomic') False sage: P.<x> = PolynomialRing(k) sage: (a+1)*x # indirect doctest (a + 1)*x """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") p = Integer(2) FiniteField.__init__(self, GF(p), names, normalize=True) self._kwargs = {'repr': repr} self._is_conway = False if modulus is None or modulus == 'default': if exists_conway_polynomial(p, k): modulus = "conway" else: modulus = "minimal_weight" if modulus == "conway": modulus = conway_polynomial(p, k) self._is_conway = True if is_Polynomial(modulus): modulus = modulus.list() self._cache = Cache_ntl_gf2e(self, k, modulus) self._polynomial = {}
def __init__(self, q, names="a", modulus=None, repr="poly"): """ Initialize ``self``. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: Modulus parameter not understood sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3 = k1._finite_field_ext_pari_() sage: k1 == k3 False sage: TestSuite(k).run() sage: k.<a> = GF(2^64) sage: k._repr_option('element_is_atomic') False sage: P.<x> = PolynomialRing(k) sage: (a+1)*x # indirect doctest (a + 1)*x """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") p = Integer(2) FiniteField.__init__(self, GF(p), names, normalize=True) self._kwargs = {'repr':repr} self._is_conway = False if modulus is None or modulus == 'default': if exists_conway_polynomial(p, k): modulus = "conway" else: modulus = "minimal_weight" if modulus == "conway": modulus = conway_polynomial(p, k) self._is_conway = True if is_Polynomial(modulus): modulus = modulus.list() self._cache = Cache_ntl_gf2e(self, k, modulus) self._polynomial = {}
def __init__(self, q, names="a", modulus=None, repr="poly"): """ Initialize ``self``. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: no such algorithm for finding an irreducible polynomial: strangeinput sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3.<a> = GF(2^16, impl="pari_ffelt") sage: k1 == k3 False sage: TestSuite(k).run() sage: k.<a> = GF(2^64) sage: k._repr_option('element_is_atomic') False sage: P.<x> = PolynomialRing(k) sage: (a+1)*x # indirect doctest (a + 1)*x """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") FiniteField.__init__(self, GF2, names, normalize=True) self._kwargs = {'repr':repr} from sage.rings.polynomial.polynomial_element import is_Polynomial if not is_Polynomial(modulus): from sage.misc.superseded import deprecation deprecation(16983, "constructing a FiniteField_ntl_gf2e without giving a polynomial as modulus is deprecated, use the more general FiniteField constructor instead") R = GF2['x'] if modulus is None or isinstance(modulus, str): modulus = R.irreducible_element(k, algorithm=modulus) else: modulus = R(modulus) self._cache = Cache_ntl_gf2e(self, k, modulus) self._modulus = modulus
def __init__(self, q, names="a", modulus=None, repr="poly"): """ Initialize ``self``. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: no such algorithm for finding an irreducible polynomial: strangeinput sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3.<a> = GF(2^16, impl="pari_ffelt") sage: k1 == k3 False sage: TestSuite(k).run() sage: k.<a> = GF(2^64) sage: k._repr_option('element_is_atomic') False sage: P.<x> = PolynomialRing(k) sage: (a+1)*x # indirect doctest (a + 1)*x """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") FiniteField.__init__(self, GF2, names, normalize=True) from sage.rings.polynomial.polynomial_element import is_Polynomial if not is_Polynomial(modulus): raise TypeError("modulus must be a polynomial") self._cache = Cache_ntl_gf2e(self, k, modulus) self._modulus = modulus
def xi_degrees(n, p=2, reverse=True): r""" Decreasing list of degrees of the xi_i's, starting in degree n. INPUT: - `n` - integer - `p` - prime number, optional (default 2) - ``reverse`` - bool, optional (default True) OUTPUT: ``list`` - list of integers When `p=2`: decreasing list of the degrees of the `\xi_i`'s with degree at most n. At odd primes: decreasing list of these degrees, each divided by `2(p-1)`. If ``reverse`` is False, then return an increasing list rather than a decreasing one. EXAMPLES:: sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(17) [15, 7, 3, 1] sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(17, reverse=False) [1, 3, 7, 15] sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(17,p=3) [13, 4, 1] sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(400,p=17) [307, 18, 1] """ from sage.rings.integer import Integer if n <= 0: return [] N = Integer(n * (p - 1) + 1) l = [(p**d - 1) // (p - 1) for d in range(1, N.exact_log(p) + 1)] if reverse: l.reverse() return l
def __init__(self, q, names="a", modulus=None, repr="poly"): """ Finite Field for characteristic 2 and order >= 2. INPUT: q -- 2^n (must be 2 power) names -- variable used for poly_repr (default: 'a') modulus -- you may provide a polynomial to use for reduction or a string: 'conway': force the use of a Conway polynomial, will raise a RuntimeError if none is found in the database; 'minimal_weight': use a minimal weight polynomial, should result in faster arithmetic; 'random': use a random irreducible polynomial. 'default':a Conway polynomial is used if found. Otherwise a sparse polynomial is used. repr -- controls the way elements are printed to the user: (default: 'poly') 'poly': polynomial representation OUTPUT: Finite field with characteristic 2 and cardinality 2^n. EXAMPLES:: sage: k.<a> = GF(2^16) sage: type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: k.<a> = GF(2^1024) sage: k.modulus() x^1024 + x^19 + x^6 + x + 1 sage: set_random_seed(0) sage: k.<a> = GF(2^17, modulus='random') sage: k.modulus() x^17 + x^16 + x^15 + x^10 + x^8 + x^6 + x^4 + x^3 + x^2 + x + 1 sage: k.modulus().is_irreducible() True sage: k.<a> = GF(2^211, modulus='minimal_weight') sage: k.modulus() x^211 + x^11 + x^10 + x^8 + 1 sage: k.<a> = GF(2^211, modulus='conway') sage: k.modulus() x^211 + x^9 + x^6 + x^5 + x^3 + x + 1 sage: k.<a> = GF(2^411, modulus='conway') Traceback (most recent call last): ... RuntimeError: requested conway polynomial not in database. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: Modulus parameter not understood sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3 = k1._finite_field_ext_pari_() sage: k1 == k3 False """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") p = Integer(2) FiniteField.__init__(self, GF(p), names, normalize=True) self._kwargs = {'repr': repr} self._is_conway = False if modulus is None or modulus == 'default': if exists_conway_polynomial(p, k): modulus = "conway" else: modulus = "minimal_weight" if modulus == "conway": modulus = conway_polynomial(p, k) self._is_conway = True if is_Polynomial(modulus): modulus = modulus.list() self._cache = Cache_ntl_gf2e(self, k, modulus) self._polynomial = {}
def __init__(self, q, names="a", modulus=None, repr="poly"): """ Finite Field for characteristic 2 and order >= 2. INPUT: q -- 2^n (must be 2 power) names -- variable used for poly_repr (default: 'a') modulus -- you may provide a polynomial to use for reduction or a string: 'conway': force the use of a Conway polynomial, will raise a RuntimeError if none is found in the database; 'minimal_weight': use a minimal weight polynomial, should result in faster arithmetic; 'random': use a random irreducible polynomial. 'default':a Conway polynomial is used if found. Otherwise a sparse polynomial is used. repr -- controls the way elements are printed to the user: (default: 'poly') 'poly': polynomial representation OUTPUT: Finite field with characteristic 2 and cardinality 2^n. EXAMPLES:: sage: k.<a> = GF(2^16) sage: type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: k.<a> = GF(2^1024) sage: k.modulus() x^1024 + x^19 + x^6 + x + 1 sage: set_random_seed(0) sage: k.<a> = GF(2^17, modulus='random') sage: k.modulus() x^17 + x^16 + x^15 + x^10 + x^8 + x^6 + x^4 + x^3 + x^2 + x + 1 sage: k.modulus().is_irreducible() True sage: k.<a> = GF(2^211, modulus='minimal_weight') sage: k.modulus() x^211 + x^11 + x^10 + x^8 + 1 sage: k.<a> = GF(2^211, modulus='conway') sage: k.modulus() x^211 + x^9 + x^6 + x^5 + x^3 + x + 1 sage: k.<a> = GF(2^411, modulus='conway') Traceback (most recent call last): ... RuntimeError: requested conway polynomial not in database. TESTS:: sage: k.<a> = GF(2^100, modulus='strangeinput') Traceback (most recent call last): ... ValueError: Modulus parameter not understood sage: k.<a> = GF(2^20) ; type(k) <class 'sage.rings.finite_rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e_with_category'> sage: loads(dumps(k)) is k True sage: k1.<a> = GF(2^16) sage: k2.<a> = GF(2^17) sage: k1 == k2 False sage: k3 = k1._finite_field_ext_pari_() sage: k1 == k3 False """ late_import() q = Integer(q) if q < 2: raise ValueError("q must be a 2-power") k = q.exact_log(2) if q != 1 << k: raise ValueError("q must be a 2-power") p = Integer(2) FiniteField.__init__(self, GF(p), names, normalize=True) self._kwargs = {'repr':repr} self._is_conway = False if modulus is None or modulus == 'default': if exists_conway_polynomial(p, k): modulus = "conway" else: modulus = "minimal_weight" if modulus == "conway": modulus = conway_polynomial(p, k) self._is_conway = True if is_Polynomial(modulus): modulus = modulus.list() self._cache = Cache_ntl_gf2e(self, k, modulus) self._polynomial = {}