Ticket #1810: finite_field_refactor_doc.3.patch

File finite_field_refactor_doc.3.patch, 36.9 KB (added by Martin Albrecht, 15 years ago)

rebased against 2.10.3.alpha3

  • sage/coding/code_constructions.py

    # HG changeset patch
    # User 'Martin Albrecht <malb@informatik.uni-bremen.de>'
    # Date 1204143565 28800
    # Node ID 1691c70f15a5dcb8357a20c5e3eb31fb3926860d
    # Parent  3b0d22a6661d3303d10d5e43f910e36fb791c5a6
    Finite Field documentation (rebasing #1810 again)
    
    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/coding/code_constructions.py
    a b from sage.interfaces.all import gap 
    1414from sage.interfaces.all import gap
    1515#from sage.misc.preparser import *
    1616from sage.matrix.matrix_space import MatrixSpace
    17 from sage.rings.finite_field import GF
     17from sage.rings.finite_field import FiniteField as GF
    1818#from sage.groups.perm_gps.permgroup import *
    1919from sage.groups.perm_gps.permgroup_named import SymmetricGroup
    2020from sage.misc.sage_eval import sage_eval
  • sage/coding/guava.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/coding/guava.py
    a b from sage.interfaces.all import gap 
    2323from sage.interfaces.all import gap
    2424from sage.misc.preparser import *
    2525from sage.matrix.matrix_space import MatrixSpace
    26 from sage.rings.finite_field import *
     26from sage.rings.finite_field import FiniteField as GF
     27from sage.interfaces.gap import gfq_gap_to_sage as gap_to_sage
    2728from sage.groups.perm_gps.permgroup import *
    2829from sage.misc.sage_eval import sage_eval
    2930from sage.misc.misc import prod, add
    def QuadraticResidueCode(n,F): 
    6263    gap.eval("G:=GeneratorMat(C)")
    6364    k = eval(gap.eval("Length(G)"))
    6465    n = eval(gap.eval("Length(G[1])"))
    65     G = [[gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
     66    G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
    6667    MS = MatrixSpace(F,k,n)
    6768    return LinearCode(MS(G))
    6869
    def QuasiQuadraticResidueCode(p): 
    135136    gap.eval("G:=GeneratorMat(C)")
    136137    k = eval(gap.eval("Length(G)"))
    137138    n = eval(gap.eval("Length(G[1])"))
    138     G = [[gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
     139    G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
    139140    MS = MatrixSpace(F,k,n)
    140141    return LinearCode(MS(G))
    141142
    def BinaryReedMullerCode(r,k): 
    180181    gap.eval("G:=GeneratorMat(C)")
    181182    k = eval(gap.eval("Length(G)"))
    182183    n = eval(gap.eval("Length(G[1])"))
    183     G = [[gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
     184    G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
    184185    MS = MatrixSpace(F,k,n)
    185186    return LinearCode(MS(G))
    186187
    def RandomLinearCodeGuava(n,k,F): 
    212213    gap.eval("G:=GeneratorMat(C)")
    213214    k = eval(gap.eval("Length(G)"))
    214215    n = eval(gap.eval("Length(G[1])"))
    215     G = [[gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
     216    G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,k+1)]
    216217    MS = MatrixSpace(F,k,n)
    217218    return LinearCode(MS(G))
    218219
  • sage/coding/linear_code.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/coding/linear_code.py
    a b import sage.modules.module as module 
    177177import sage.modules.module as module
    178178import sage.modules.free_module_element as fme
    179179from sage.interfaces.all import gap
    180 from sage.rings.finite_field import GF
     180from sage.rings.finite_field import FiniteField as GF
    181181from sage.groups.perm_gps.permgroup import PermutationGroup
    182182from sage.matrix.matrix_space import MatrixSpace
    183183from sage.rings.arith import GCD, rising_factorial, binomial
    def min_wt_vec(Gmat,F): 
    260260
    261261    AUTHOR: David Joyner (11-2005)
    262262    """
    263     from sage.rings.finite_field import gap_to_sage
     263    from sage.interfaces.gap import gfq_gap_to_sage
    264264    gap.eval("G:="+Gmat)
    265265    k = int(gap.eval("Length(G)"))
    266266    q = F.order()
    def min_wt_vec(Gmat,F): 
    268268    C = gap(Gmat).GeneratorMatCode(F)
    269269    n = int(C.WordLength())
    270270    cg = C.MinimumDistanceCodeword()
    271     c = [gap_to_sage(cg[j],F) for j in range(1,n+1)]
     271    c = [gfq_gap_to_sage(cg[j],F) for j in range(1,n+1)]
    272272    V = VectorSpace(F,n)
    273273    return V(c)
    274274    ## this older code returns more info but may be slower:
    class LinearCode(module.Module): 
    474474            False
    475475
    476476        """
    477         from sage.rings.finite_field import gap_to_sage
     477        from sage.interfaces.gap import gfq_gap_to_sage
    478478        F = self.base_ring()
    479479        q = F.order()
    480480        G = self.gen_mat()
    481481        n = len(G.columns())
    482482        Cg = gap(G).GeneratorMatCode(F)
    483483        c = Cg.Random()
    484         ans = [gap_to_sage(c[i],F) for i in range(1,n+1)]
     484        ans = [gfq_gap_to_sage(c[i],F) for i in range(1,n+1)]
    485485        V = VectorSpace(F,n)
    486486        return V(ans)
    487487   
    class LinearCode(module.Module): 
    691691
    692692        Does not work for very long codes since the syndrome table grows too large.
    693693        """
    694         from sage.rings.finite_field import gap_to_sage
     694        from sage.interfaces.gap import gfq_gap_to_sage
    695695        F = self.base_ring()
    696696        q = F.order()
    697697        G = self.gen_mat()
    class LinearCode(module.Module): 
    707707            vstr = vstr[1:-1]     # added by William Stein so const.tex works 2006-10-01
    708708        gap.eval("C:=GeneratorMatCode("+Gstr+",GF("+str(q)+"))")
    709709        gap.eval("c:=VectorCodeword(Decodeword( C, Codeword( "+vstr+" )))") # v->vstr, 8-27-2006
    710         ans = [gap_to_sage(gap.eval("c["+str(i)+"]"),F) for i in range(1,n+1)]
     710        ans = [gfq_gap_to_sage(gap.eval("c["+str(i)+"]"),F) for i in range(1,n+1)]
    711711        V = VectorSpace(F,n)
    712712        return V(ans)
    713713
  • sage/crypto/mq/mpolynomialsystem.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/crypto/mq/mpolynomialsystem.py
    a b from sage.structure.sage_object import S 
    3232from sage.structure.sage_object import SageObject
    3333
    3434from sage.rings.integer_ring import ZZ
    35 from sage.rings.finite_field import GF
     35from sage.rings.finite_field import FiniteField as GF
    3636
    3737from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
    3838from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal
  • sage/crypto/mq/sr.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/crypto/mq/sr.py
    a b REFERENCES: 
    7777   Advanced Encryption Standard; Springer 2006; 
    7878"""
    7979
    80 from sage.rings.finite_field import GF
     80from sage.rings.finite_field import FiniteField as GF
    8181from sage.rings.integer_ring import ZZ
    8282from sage.rings.polynomial.polynomial_ring import PolynomialRing
    8383
  • sage/groups/perm_gps/cubegroup.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/groups/perm_gps/cubegroup.py
    a b from sage.interfaces.all import gap, is_ 
    7474from sage.interfaces.all import gap, is_GapElement, is_ExpectElement
    7575from sage.groups.perm_gps.permgroup_element import PermutationGroupElement
    7676import sage.structure.coerce as coerce
    77 from sage.rings.finite_field import GF
     77from sage.rings.finite_field import FiniteField as GF
    7878from sage.rings.arith import factor
    7979from sage.groups.abelian_gps.abelian_group import AbelianGroup
    8080from sage.plot.plot import PolygonFactory, TextFactory
  • sage/groups/perm_gps/permgroup.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/groups/perm_gps/permgroup.py
    a b from sage.interfaces.all import gap, is_ 
    9191from sage.interfaces.all import gap, is_GapElement, is_ExpectElement
    9292from sage.groups.perm_gps.permgroup_element import PermutationGroupElement
    9393import sage.structure.coerce as coerce
    94 from sage.rings.finite_field import GF
     94from sage.rings.finite_field import FiniteField as GF
    9595from sage.rings.arith import factor
    9696from sage.groups.abelian_gps.abelian_group import AbelianGroup
    9797from sage.misc.functional import is_even, log
  • sage/groups/perm_gps/permgroup_named.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/groups/perm_gps/permgroup_named.py
    a b from sage.rings.all import Rational 
    7070from sage.rings.all      import RationalField, Integer
    7171from sage.interfaces.all import gap, is_GapElement, is_ExpectElement
    7272import sage.structure.coerce as coerce
    73 from sage.rings.finite_field import GF
     73from sage.rings.finite_field import FiniteField as GF
    7474from sage.rings.arith import factor
    7575from sage.groups.abelian_gps.abelian_group import AbelianGroup
    7676from sage.misc.functional import is_even, log
  • sage/interfaces/gap.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/interfaces/gap.py
    a b def is_GapElement(x): 
    736736def is_GapElement(x):
    737737    return isinstance(x, GapElement)
    738738
    739 ###########
     739def gfq_gap_to_sage(x, F):
     740    """
     741    INPUT:
     742        x -- gap finite field element
     743        F -- SAGE finite field
     744    OUTPUT:
     745        element of F
     746
     747    EXAMPLES:
     748        sage: x = gap('Z(13)')
     749        sage: F = GF(13, 'a')
     750        sage: F(x)
     751        2
     752        sage: F(gap('0*Z(13)'))
     753        0
     754        sage: F = GF(13^2, 'a')
     755        sage: x = gap('Z(13)')
     756        sage: F(x)
     757        2
     758        sage: x = gap('Z(13^2)^3')
     759        sage: F(x)
     760        12*a + 11
     761        sage: F.multiplicative_generator()^3
     762        12*a + 11
     763
     764    AUTHOR:
     765        -- David Joyner and William Stein
     766    """
     767    from sage.rings.finite_field import FiniteField
     768   
     769    s = str(x)
     770    if s[:2] == '0*':
     771        return F(0)
     772    i1 = s.index("(")
     773    i2 = s.index(")")
     774    q  = eval(s[i1+1:i2].replace('^','**'))
     775    if q == F.order():
     776        K = F
     777    else:
     778        K = FiniteField(q, F.variable_name())
     779    if s.find(')^') == -1:
     780        e = 1
     781    else:
     782        e = int(s[i2+2:])
     783    if F.degree() == 1:
     784        g = int(gap.eval('Int(Z(%s))'%q))
     785    else:
     786        g = K.multiplicative_generator()
     787    return F(K(g**e))
    740788
    741789#############
    742790
  • sage/libs/singular/singular.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/libs/singular/singular.pyx
    a b cdef extern from "limits.h": 
    2121    long INT_MIN
    2222
    2323from sage.rings.rational_field import RationalField
    24 from sage.rings.finite_field import FiniteField_prime_modn
     24from sage.rings.finite_field_prime_modn import FiniteField_prime_modn
    2525from sage.rings.finite_field_ext_pari import FiniteField_ext_pari
    2626from sage.libs.pari.all import pari
    2727
  • sage/matrix/matrix_rational_dense.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/matrix/matrix_rational_dense.pyx
    a b from sage.rings.integer cimport Integer 
    6464from sage.rings.integer cimport Integer
    6565from sage.rings.ring import is_Ring
    6666from sage.rings.integer_ring import ZZ, is_IntegerRing
    67 from sage.rings.finite_field import GF
     67from sage.rings.finite_field import FiniteField as GF
    6868from sage.rings.integer_mod_ring import is_IntegerModRing
    6969from sage.rings.rational_field import QQ
    7070from sage.rings.arith import gcd
  • sage/misc/flatten.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/misc/flatten.py
    a b def flatten(in_list, ltypes=(list, tuple 
    4040       [0, 1, 2, 3, 4]
    4141       sage: flatten([GF(5)])
    4242       [Finite Field of size 5]
    43        sage: flatten([GF(5)], ltypes = (list, tuple, sage.rings.finite_field.FiniteField_prime_modn))
     43       sage: flatten([GF(5)], ltypes = (list, tuple, sage.rings.finite_field_prime_modn.FiniteField_prime_modn))
    4444       [0, 1, 2, 3, 4]
    4545
    4646   Degenerate cases:
  • sage/rings/all.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/all.py
    a b Integers = IntegerModRing 
    6565
    6666# Finite fields
    6767from finite_field import (FiniteField, is_FiniteField, is_PrimeFiniteField,
    68                           GF, conway_polynomial, exists_conway_polynomial)
     68                          conway_polynomial, exists_conway_polynomial)
     69GF = FiniteField
     70
    6971from finite_field_element import FiniteFieldElement, is_FiniteFieldElement
    7072
    7173# Number field
  • sage/rings/finite_field.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/finite_field.py
    a b  
    1 """
     1r"""
    22Finite Fields
    33
     4\SAGE supports arithmetic in finite prime and extension fields.
     5Several implementation for prime fields are implemented natively in
     6\SAGE for several sizes of primes $p$. These implementations are
     7\begin{itemize}
     8\item \code{sage.rings.integer_mod.IntegerMod_int},
     9\item \code{sage.rings.integer_mod.IntegerMod_int64}, and
     10\item \code{sage.rings.integer_mod.IntegerMod_gmp}.
     11\end{itemize}
     12Small extension fields
     13of cardinality $< 2^{16}$ are implemented using tables of Zech logs
     14via the Givaro C++ library
     15(\code{sage.rings.finite_field_givaro.FiniteField_givaro}). While this
     16representation is very fast it is limited to finite fields of small
     17cardinality. Larger finite extension fields of order $q >= 2^{16}$ are
     18internally represented as polynomials over a smaller finite prime
     19fields. If the characteristic of such a field is 2 then NTL is used
     20internally to represent the field
     21(\code{sage.rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e}). In all
     22other case the PARI C library is used
     23(\code{sage.rings.finite_field_ext_pari.FiniteField_ext_pari}).
     24
     25However, this distinction is internal only and the user usually does
     26not have to worry about it because consistency across all
     27implementations is aimed for. In all extension field implementations
     28the user may either specify a minimal polynomial or leave the choice
     29to \SAGE.
     30 
     31For small finite fields the default choice are Conway polynomials.
     32
     33The Conway polynomial $C_n$ is the lexicographically first monic
     34irreducible, primitive polynomial of degree $n$ over $GF(p)$ with the
     35property that for a root $\alpha$ of $C_n$ we have that $\beta=
     36\alpha^{(p^n - 1)/(p^m - 1)}$ is a root of $C_m$ for all $m$ dividing
     37$n$. \SAGE contains a database of conway polynomials which also can be
     38queried independendtly of finite field construction.
     39
     40While \SAGE supports basic arithmetic in finite fields some more
     41advanced features for computing with finite fields are still not
     42implemented. For instance, \SAGE does not calculate embeddings of
     43finite fields yet.
    444
    545EXAMPLES:
     46    sage: k = GF(5); type(k)
     47    <class 'sage.rings.finite_field_prime_modn.FiniteField_prime_modn'>
     48   
     49    sage: k = GF(5^2,'c'); type(k)
     50    <type 'sage.rings.finite_field_givaro.FiniteField_givaro'>
     51   
     52    sage: k = GF(2^16,'c'); type(k)
     53    <type 'sage.rings.finite_field_ntl_gf2e.FiniteField_ntl_gf2e'>
     54   
     55    sage: k = GF(3^16,'c'); type(k)
     56    <class 'sage.rings.finite_field_ext_pari.FiniteField_ext_pari'>
     57
    658Finite Fields support iteration, starting with 0.
     59
    760    sage: k = GF(9, 'a')
    861    sage: for i,x in enumerate(k):  print i,x
    962    0 0
    Finite Fields support iteration, startin 
    2477    4
    2578
    2679We output the base rings of several finite fields.
     80
    2781    sage: k = GF(3); type(k)
    28     <class 'sage.rings.finite_field.FiniteField_prime_modn'>
     82    <class 'sage.rings.finite_field_prime_modn.FiniteField_prime_modn'>
    2983    sage: k.base_ring()
    3084    Finite Field of size 3
    3185
    Further examples: 
    48102    True
    49103    sage: GF(8,'a').is_field()
    50104    True
     105
     106AUTHORS:
     107     -- William Stein: initial version
     108     -- Robert Bradshaw: prime field implementation
     109     -- Martin Albrecht: Givaro and ntl.GF2E implementations
    51110"""
    52111
    53112#*****************************************************************************
    import random 
    68127import random
    69128import weakref
    70129
     130from ring import is_FiniteField
     131from sage.structure.parent_gens import normalize_names
     132
    71133import arith
    72 
    73134import integer
    74 import rational
    75 import integer_mod
    76 
    77 import integer_mod_ring
    78 from ring import is_FiniteField
    79 from ring import FiniteField as FiniteField_generic
    80 from finite_field_givaro import FiniteField_givaro
    81135
    82136import polynomial.polynomial_ring as polynomial_ring
    83137import polynomial.polynomial_element as polynomial_element
    84138import polynomial.multi_polynomial_element as multi_polynomial_element
    85139
    86 from sage.structure.parent_gens import normalize_names, ParentWithGens
     140# We don't late import this because this means trouble with the Givaro library
     141# TODO: figure out why
     142from finite_field_givaro import FiniteField_givaro
    87143
    88144import sage.interfaces.gap
    89145import sage.databases.conway
    def FiniteField(order, name=None, modulu 
    152208        sage: F.<x> = GF(5)[]
    153209        sage: K.<a> = GF(5**2, name='a', modulus=x^2 + 2, check_irreducible=False)
    154210
    155     For example, you may print finite field elements as integers via
    156     the Givaro implementation. But the constructor parameter to allow
    157     this is not passed to the actual implementation so far.
     211    For example, you may print finite field elements as integers. This
     212    currently only works if the order of field is $<2^{16}$, though.
    158213
    159214        sage: k.<a> = GF(2^8,repr='int')
    160215        sage: a
    161216        2
    162217
    163218    The order of a finite field must be a prime power:
     219   
    164220        sage: GF(100)
    165221        Traceback (most recent call last):
    166222        ...
    def FiniteField(order, name=None, modulu 
    179235        if not K is None:
    180236            return K
    181237    if arith.is_prime(order):
     238        from finite_field_prime_modn import FiniteField_prime_modn
    182239        K = FiniteField_prime_modn(order,*args,**kwds)
    183240    else:
    184241        if not arith.is_prime_power(order):
    def FiniteField(order, name=None, modulu 
    210267
    211268def is_PrimeFiniteField(x):
    212269    """
    213     Returns True if x is a prime finite field (which is a specific
    214     data type).
     270    Returns True if x is a prime finite field.
    215271
    216272    EXAMPLES:
    217273        sage: is_PrimeFiniteField(QQ)
    def is_PrimeFiniteField(x): 
    223279        sage: is_PrimeFiniteField(GF(next_prime(10^90,proof=False)))
    224280        True
    225281    """
    226     return isinstance(x, FiniteField_prime_modn)
     282    from finite_field_prime_modn import FiniteField_prime_modn
     283    from ring import FiniteField as FiniteField_generic
     284
     285    return isinstance(x, FiniteField_prime_modn) or \
     286           (isinstance(x, FiniteField_generic) and x.degree() == 1)
    227287   
    228 GF = FiniteField
    229 
    230288##################################################################
    231289   
    232290def conway_polynomial(p, n):
    233     """
     291    r"""
    234292    Return the Conway polynomial of degree n over GF(p), which is
    235293    loaded from a table.
    236294
    def conway_polynomial(p, n): 
    248306    disk, which takes a fraction of a second.  Subsequent calls do not
    249307    require reloading the table.
    250308
    251     See also the ConwayPolynomials() object, which is a table of
    252     Conway polynomials.   For example, if c=ConwayPolynomials, then
    253     c.primes() is a list of all primes for which the polynomials are
    254     known, and for a given prime p,  c.degree(p) is a list of all
     309    See also the \code{ConwayPolynomials()} object, which is a table of
     310    Conway polynomials.   For example, if \code{c=ConwayPolynomials}, then
     311    \code{c.primes()} is a list of all primes for which the polynomials are
     312    known, and for a given prime $p$,  \code{c.degree(p)} is a list of all
    255313    degrees for which the Conway polynomials are known.
    256314
    257315    EXAMPLES:
    def conway_polynomial(p, n): 
    265323        RuntimeError: requested conway polynomial not in database.
    266324    """
    267325    (p,n)=(int(p),int(n))
    268     R = polynomial_ring.PolynomialRing(GF(p), 'x')
     326    R = polynomial_ring.PolynomialRing(FiniteField(p), 'x')
    269327    try:
    270328        return R(sage.databases.conway.ConwayPolynomials()[p][n])
    271329    except KeyError:
    272330        raise RuntimeError, "requested conway polynomial not in database."
    273331
    274332def exists_conway_polynomial(p, n):
    275     """
    276     Return True if the Conway polynomial over F_p of degree n is in the
     333    r"""
     334    Return True if the Conway polynomial over $F_p$ of degree $n$ is in the
    277335    database and False otherwise.
    278336
    279337    If the Conway polynomial is in the database, to obtain it use the
    280     command conway_polynomial(p,n).
     338    command \code{conway_polynomial(p,n)}.
    281339
    282340    EXAMPLES:
    283341        sage: exists_conway_polynomial(2,3)
    def exists_conway_polynomial(p, n): 
    291349    """
    292350    return sage.databases.conway.ConwayPolynomials().has_polynomial(p,n)
    293351
    294 def gap_to_sage(x, F):
    295     """
    296     INPUT:
    297         x -- gap finite field element
    298         F -- SAGE finite field
    299     OUTPUT:
    300         element of F
    301 
    302     EXAMPLES:
    303         sage: x = gap('Z(13)')
    304         sage: F = GF(13, 'a')
    305         sage: F(x)
    306         2
    307         sage: F(gap('0*Z(13)'))
    308         0
    309         sage: F = GF(13^2, 'a')
    310         sage: x = gap('Z(13)')
    311         sage: F(x)
    312         2
    313         sage: x = gap('Z(13^2)^3')
    314         sage: F(x)
    315         12*a + 11
    316         sage: F.multiplicative_generator()^3
    317         12*a + 11
    318 
    319     AUTHOR:
    320         -- David Joyner and William Stein
    321     """
    322     s = str(x)
    323     if s[:2] == '0*':
    324         return F(0)
    325     i1 = s.index("(")
    326     i2 = s.index(")")
    327     q  = eval(s[i1+1:i2].replace('^','**'))
    328     if q == F.order():
    329         K = F
    330     else:
    331         K = FiniteField(q, F.variable_name())
    332     if s.find(')^') == -1:
    333         e = 1
    334     else:
    335         e = int(s[i2+2:])
    336     if F.degree() == 1:
    337         g = int(sage.interfaces.gap.gap.eval('Int(Z(%s))'%q))
    338     else:
    339         g = K.multiplicative_generator()
    340     return F(K(g**e))
    341 
    342 
    343 class FiniteField_prime_modn(FiniteField_generic, integer_mod_ring.IntegerModRing_generic):
    344     def __init__(self, p, name=None):
    345         p = integer.Integer(p)
    346         if not arith.is_prime(p):
    347             raise ArithmeticError, "p must be prime"
    348         integer_mod_ring.IntegerModRing_generic.__init__(self, p)
    349         self._kwargs = {}
    350         self.__char = p
    351         self.__gen = self(1)  # self(int(pari.pari(p).znprimroot().lift()))
    352         ParentWithGens.__init__(self, self, ('x',), normalize=False)
    353 
    354     def __cmp__(self, other):
    355         if not isinstance(other, FiniteField_prime_modn):
    356             return cmp(type(self), type(other))
    357         return cmp(self.__char, other.__char)
    358 
    359     def _is_valid_homomorphism_(self, codomain, im_gens):
    360         """
    361         This is called implicitly by the hom constructor.
    362        
    363         EXAMPLES:
    364             sage: k = GF(73^2,'a')
    365             sage: f = k.modulus()
    366             sage: r = f.change_ring(k).roots()
    367             sage: k.hom([r[0][0]])
    368             Ring endomorphism of Finite Field in a of size 73^2
    369               Defn: a |--> 72*a + 3
    370         """
    371         try:
    372             return im_gens[0] == codomain._coerce_(self.gen(0))
    373         except TypeError:
    374             return False
    375 
    376     def _coerce_impl(self, x):
    377         if isinstance(x, (int, long, integer.Integer)):
    378             return self(x)
    379         if isinstance(x, integer_mod.IntegerMod_abstract) and \
    380                x.parent().characteristic() == self.characteristic():
    381             return self(x)
    382         raise TypeError, "no canonical coercion of x"
    383 
    384     def characteristic(self):
    385         return self.__char
    386 
    387     def modulus(self):
    388         try:
    389             return self.__modulus
    390         except AttributeError:
    391             x = polynomial_ring.PolynomialRing(self, 'x').gen()
    392             self.__modulus = x - 1
    393         return self.__modulus
    394 
    395     def is_prime_field(self):
    396         return True
    397        
    398     def is_prime(self):
    399         return True
    400 
    401     def polynomial(self, name=None):
    402         if name is None:
    403             name = self.variable_name()
    404         try:
    405             return self.__polynomial[name]
    406         except  AttributeError:
    407             R = polynomial_ring.PolynomialRing(FiniteField(self.characteristic()), name)
    408             f = polynomial_ring.PolynomialRing(self, name)([0,1])
    409             try:
    410                 self.__polynomial[name] = f
    411             except (KeyError, AttributeError):
    412                 self.__polynomial = {}
    413                 self.__polynomial[name] = f
    414             return f
    415 
    416     def order(self):
    417         return self.__char
    418 
    419     def gen(self, n=0):
    420         """
    421         Return generator of this finite field.
    422        
    423         EXAMPLES:
    424             sage: k = GF(13)
    425             sage: k.gen()
    426             1
    427             sage: k.gen(1)
    428             Traceback (most recent call last):
    429             ...
    430             IndexError: only one generator
    431         """
    432         if n != 0:
    433             raise IndexError, "only one generator"
    434         return self.__gen
    435 
    436     def __iter__(self):
    437         for i in xrange(self.order()):
    438             yield self(i)
    439 
    440     def degree(self):
    441         """
    442         Returns the degree of the finite field, which is a positive
    443         integer.
    444 
    445         EXAMPLES:
    446             sage: FiniteField(3).degree()
    447             1
    448             sage: FiniteField(3^20, 'a').degree()
    449             20
    450         """
    451         return 1
    452352
    453353zech_log_bound = 2**16
  • sage/rings/finite_field_ext_pari.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/finite_field_ext_pari.py
    a b class FiniteField_ext_pari(FiniteField_g 
    181181            raise ArithmeticError, "q must be a prime power"
    182182
    183183        if F[0][1] > 1:
    184             from finite_field import GF
     184            from finite_field import FiniteField as GF
    185185            base_ring = GF(F[0][0])
    186186        else:
    187187            raise ValueError, "The size of the finite field must not be prime."
    class FiniteField_ext_pari(FiniteField_g 
    207207                #     self.__pari_modulus = pari.pari.finitefield_init(self.__char, self.__degree, self.variable_name())
    208208                # So instead we iterate through random polys until we find an irreducible one.
    209209
    210                 from finite_field import GF
     210                from finite_field import FiniteField as GF
    211211                R = polynomial_ring.PolynomialRing(GF(self.__char), 'x')
    212212                while True:
    213213                    modulus = R.random_element(self.__degree)
    class FiniteField_ext_pari(FiniteField_g 
    433433                raise TypeError, "no coercion defined"
    434434
    435435        elif sage.interfaces.gap.is_GapElement(x):
    436             from finite_field import gap_to_sage
     436            from sage.interfaces.gap import gfq_gap_to_sage
    437437            try:
    438                 return gap_to_sage(x, self)
     438                return gfq_gap_to_sage(x, self)
    439439            except (ValueError, IndexError, TypeError):
    440440                raise TypeError, "no coercion defined"
    441441           
    class FiniteField_ext_pari(FiniteField_g 
    569569        try:
    570570            return self.__polynomial[name]
    571571        except (AttributeError, KeyError):
    572             from finite_field import GF
     572            from finite_field import FiniteField as GF
    573573            R = polynomial_ring.PolynomialRing(GF(self.characteristic()), name)
    574574            f = R(self._pari_modulus())
    575575            try:
  • sage/rings/finite_field_givaro.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/finite_field_givaro.pyx
    a b r""" 
    11r"""
    2 Finite Non-prime Fields of cardinality up to $2^{16}$
     2Finite Extension Fields of cardinality up to $2^{16}$
    33
    44SAGE includes the Givaro finite field library, for highly optimized
    55arithmetic in finite fields.
    using the PARI implementation. 
    1414
    1515EXAMPLES:
    1616    sage: k = GF(5); type(k)
    17     <class 'sage.rings.finite_field.FiniteField_prime_modn'>
     17    <class 'sage.rings.finite_field_prime_modn.FiniteField_prime_modn'>
    1818    sage: k = GF(5^2,'c'); type(k)
    1919    <type 'sage.rings.finite_field_givaro.FiniteField_givaro'>
    2020    sage: k = GF(2^16,'c'); type(k)
    cdef class FiniteField_givaro(FiniteFiel 
    516516            e = e._pari_()
    517517
    518518        elif sage.interfaces.gap.is_GapElement(e):
    519             from sage.rings.finite_field import gap_to_sage
    520             return gap_to_sage(e, self)
     519            from sage.interfaces.gap import gfq_gap_to_sage
     520            return gfq_gap_to_sage(e, self)
    521521
    522522        else:
    523523            raise TypeError, "unable to coerce"
    cdef class FiniteField_givaro(FiniteFiel 
    608608            sage: S.prime_subfield()
    609609            Finite Field of size 5
    610610            sage: type(S.prime_subfield())
    611             <class 'sage.rings.finite_field.FiniteField_prime_modn'>           
     611            <class 'sage.rings.finite_field_prime_modn.FiniteField_prime_modn'>           
    612612        """
    613613        return self.prime_subfield_C()
    614614
  • sage/rings/finite_field_ntl_gf2e.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/finite_field_ntl_gf2e.pyx
    a b cdef void late_import(): 
    115115    FreeModuleElement = sage.modules.free_module_element.FreeModuleElement
    116116
    117117    import sage.rings.finite_field
    118     GF = sage.rings.finite_field.GF
     118    GF = sage.rings.finite_field.FiniteField
    119119
    120120cdef extern from "arpa/inet.h":
    121121    unsigned int htonl(unsigned int)
    cdef class FiniteField_ntl_gf2e(FiniteFi 
    364364            e = e._pari_()
    365365
    366366        elif is_GapElement(e):
    367             from finite_field import gap_to_sage
    368             return gap_to_sage(e, self)
     367            from sage.interfaces.gap import gfq_gap_to_sage
     368            return gfq_gap_to_sage(e, self)
    369369        else:
    370370            raise TypeError, "unable to coerce"
    371371
  • sage/rings/integer_mod_ring.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/integer_mod_ring.py
    a b def IntegerModRing(order=0): 
    103103    if _objsIntegerModRing.has_key(order):
    104104        x = _objsIntegerModRing[order]()
    105105        if not x is None: return x
    106     #if check_prime and arith.is_prime(order):
    107     #    R = sage.rings.finite_field.FiniteField_prime_modn(order)
    108     #else:
    109106    R = IntegerModRing_generic(order)
    110107    _objsIntegerModRing[order] = weakref.ref(R)
    111108    return R
    class IntegerModRing_generic(quotient_ri 
    584581            return TypeError, "error coercing to finite field"
    585582        except TypeError:
    586583            if sage.interfaces.all.is_GapElement(x):
    587                 import finite_field
     584                from sage.interfaces.gap import gfq_gap_to_sage
    588585                try:
    589                     return finite_field.gap_to_sage(x, self)
     586                    return gfq_gap_to_sage(x, self)
    590587                except (ValueError, IndexError, TypeError), msg:
    591588                    raise TypeError, "%s\nerror coercing to finite field"%msg
    592589            else:
  • sage/rings/padics/factory.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/padics/factory.py
    a b def Qq(q, prec = 20, type = 'capped-rel' 
    169169        return Qp(q, prec, type, print_mode, halt, names, check)
    170170    base = Qp(F[0][0], prec, type, print_mode, halt, qp_name, check = False)
    171171    if modulus is None:
    172         from sage.rings.finite_field import GF
     172        from sage.rings.finite_field import FiniteField as GF
    173173        from sage.rings.integer_ring import ZZ
    174174        from sage.rings.polynomial.polynomial_ring import PolynomialRing
    175175        if qp_name is None:
    def Zq(q, prec = 20, type = 'capped-abs' 
    417417        return Zp(q, prec, type, print_mode, halt, names, check)
    418418    base = Zp(F[0][0], prec, type, print_mode, halt, zp_name, check = False)
    419419    if modulus is None:
    420         from sage.rings.finite_field import GF
     420        from sage.rings.finite_field import FiniteField as GF
    421421        if zp_name is None:
    422422            zp_name = (str(F[0][0]),)
    423423        modulus = PolynomialRing(base, 'x')(GF(q, names).modulus().change_ring(ZZ))
  • sage/rings/padics/padic_generic.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/padics/padic_generic.py
    a b class pAdicGeneric(sage.rings.ring.Princ 
    254254            sage: k
    255255                Finite Field of size 3
    256256        """
    257         return sage.rings.finite_field.GF(self.prime())
     257        return sage.rings.finite_field.FiniteField(self.prime())
    258258
    259259    residue_field = residue_class_field
    260260
    class pAdicGeneric(sage.rings.ring.Princ 
    491491            else:
    492492                raise ValueError, "No, %sth root of unity in self"%n
    493493        else:
    494             return self.teichmuller(sage.rings.finite_field.GF(self.prime()).zeta(n).lift())
     494            return self.teichmuller(sage.rings.finite_field.FiniteField(self.prime()).zeta(n).lift())
    495495
    496496    def zeta_order(self):
    497497        """
  • sage/rings/padics/unramified_extension_generic.py

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/padics/unramified_extension_generic.py
    a b pAdicExtensionGeneric = padic_extension_ 
    1717pAdicExtensionGeneric = padic_extension_generic.pAdicExtensionGeneric
    1818#UnramifiedExtensionGenericElement = sage.rings.padics.unramified_extension_generic_element.UnramifiedExtensionGenericElement
    1919PolynomialRing = sage.rings.polynomial.polynomial_ring.PolynomialRing
    20 GF = sage.rings.finite_field.GF
     20GF = sage.rings.ring.FiniteField
    2121#pAdicGeneric = sage.rings.padics.padic_generic.pAdicGeneric
    2222
    2323class UnramifiedExtensionGeneric(pAdicExtensionGeneric):
  • sage/rings/polynomial/multi_polynomial_libsingular.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/polynomial/multi_polynomial_libsingular.pyx
    a b from sage.rings.polynomial.pbori import  
    5050
    5151# base ring imports
    5252from sage.rings.rational_field import RationalField
    53 from sage.rings.finite_field import FiniteField_prime_modn
    54 from sage.rings.finite_field import FiniteField_generic
     53from sage.rings.finite_field_prime_modn import FiniteField_prime_modn
     54from sage.rings.ring import FiniteField as FiniteField_generic
    5555from sage.rings.finite_field_givaro cimport FiniteField_givaroElement
    5656from sage.rings.finite_field_givaro cimport FiniteField_givaro
    5757from sage.rings.number_field.number_field import NumberField_generic
  • sage/rings/polynomial/pbori.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/polynomial/pbori.pyx
    a b from sage.rings.polynomial.polynomial_el 
    3131
    3232from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal
    3333from sage.rings.polynomial.term_order import TermOrder
    34 from sage.rings.finite_field import GF
     34from sage.rings.finite_field import FiniteField as GF
    3535from sage.monoids.monoid import Monoid_class
    3636
    3737from sage.structure.sequence import Sequence
  • sage/rings/residue_field.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/residue_field.pyx
    a b from sage.rings.all import ZZ, QQ, Integ 
    6565from sage.rings.all import ZZ, QQ, Integers
    6666from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal
    6767import weakref
     68from sage.rings.finite_field import FiniteField as GF
    6869from sage.rings.finite_field_givaro import FiniteField_givaro
    69 from sage.rings.finite_field import FiniteField_prime_modn, GF
     70from sage.rings.finite_field_prime_modn import FiniteField_prime_modn
    7071from sage.rings.finite_field_ext_pari import FiniteField_ext_pari
    7172from sage.structure.parent_base import ParentWithBase
    7273
  • sage/rings/ring.pyx

    diff -r 3b0d22a6661d -r 1691c70f15a5 sage/rings/ring.pyx
    a b cdef class FiniteFieldIterator: 
    11201120        return self.parent(self.iter.next())
    11211121
    11221122cdef class FiniteField(Field):
    1123     """
    1124     """
    1125    
    11261123    def __init__(self):
    11271124        """
    11281125        EXAMPLES:
    cdef class FiniteField(Field): 
    15141511            Univariate Polynomial Ring in alpha over Finite Field of size 3
    15151512        """
    15161513        from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    1517         from sage.rings.finite_field import GF
     1514        from sage.rings.finite_field import FiniteField as GF
    15181515       
    15191516        if variable_name is None and self.__polynomial_ring is not None:
    15201517            return self.__polynomial_ring