Ticket #1810: finite_field_refactor_doc.2.patch

File finite_field_refactor_doc.2.patch, 38.0 KB (added by Martin Albrecht, 15 years ago)

rebased against 2.10.2

  • sage/coding/guava.py

    # HG changeset patch
    # User Martin Albrecht <malb@informatik.uni-bremen.de>
    # Date 1204137744 0
    # Node ID a1755ae00b9c6505540e269dd3512e0ec743a4a6
    # Parent  59538ebc8f3bc9e36d8e847c5c15a8cad5a90791
    Finite Fields documentation cleanup (#1810)
    this involves refactoring such that minor stuff doesn't show up in the reference manual
    
    diff -r 59538ebc8f3b -r a1755ae00b9c 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
    2728from sage.groups.perm_gps.permgroup import *
    2829from sage.misc.sage_eval import sage_eval
    2930from sage.misc.misc import prod, add
    def HammingCode(r,F): 
    7778    gap.eval("G:=GeneratorMat(C)")
    7879    k = eval(gap.eval("Length(G)"))
    7980    n = eval(gap.eval("Length(G[1])"))
    80     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)]
     81    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)]
    8182    MS = MatrixSpace(F,k,n)
    8283    return LinearCode(MS(G))
    8384   
    def QuadraticResidueCode(n,F): 
    111112    gap.eval("G:=GeneratorMat(C)")
    112113    k = eval(gap.eval("Length(G)"))
    113114    n = eval(gap.eval("Length(G[1])"))
    114     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)]
     115    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)]
    115116    MS = MatrixSpace(F,k,n)
    116117    return LinearCode(MS(G))
    117118
    def ExtendedQuadraticResidueCode(n,F): 
    146147    gap.eval("G:=GeneratorMat(XC)")
    147148    k = eval(gap.eval("Length(G)"))
    148149    n = eval(gap.eval("Length(G[1])"))
    149     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)]
     150    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)]
    150151    MS = MatrixSpace(F,k,n)
    151152    return LinearCode(MS(G))
    152153
    def QuasiQuadraticResidueCode(p): 
    184185    gap.eval("G:=GeneratorMat(C)")
    185186    k = eval(gap.eval("Length(G)"))
    186187    n = eval(gap.eval("Length(G[1])"))
    187     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)]
     188    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)]
    188189    MS = MatrixSpace(F,k,n)
    189190    return LinearCode(MS(G))
    190191
    def BinaryReedMullerCode(r,k): 
    229230    gap.eval("G:=GeneratorMat(C)")
    230231    k = eval(gap.eval("Length(G)"))
    231232    n = eval(gap.eval("Length(G[1])"))
    232     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)]
     233    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)]
    233234    MS = MatrixSpace(F,k,n)
    234235    return LinearCode(MS(G))
    235236
    def RandomLinearCodeGuava(n,k,F): 
    261262    gap.eval("G:=GeneratorMat(C)")
    262263    k = eval(gap.eval("Length(G)"))
    263264    n = eval(gap.eval("Length(G[1])"))
    264     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)]
     265    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)]
    265266    MS = MatrixSpace(F,k,n)
    266267    return LinearCode(MS(G))
    267268
    def CyclicCode(g,n,F): 
    291292    gap.eval("G:=GeneratorMat(C)")
    292293    k = eval(gap.eval("Length(G)"))
    293294    n1 = eval(gap.eval("Length(G[1])"))
    294     G = [[gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n1+1)] for i in range(1,k+1)]
     295    G = [[gfq_gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n1+1)] for i in range(1,k+1)]
    295296    MS = MatrixSpace(F,k,n1)
    296297    return LinearCode(MS(G))
  • sage/coding/linear_code.py

    diff -r 59538ebc8f3b -r a1755ae00b9c sage/coding/linear_code.py
    a b import sage.modules.module as module 
    176176import sage.modules.module as module
    177177import sage.modules.free_module_element as fme
    178178from sage.interfaces.all import gap
    179 from sage.rings.finite_field import GF
     179from sage.rings.finite_field import FiniteField as GF
    180180from sage.groups.perm_gps.permgroup import PermutationGroup
    181181from sage.matrix.matrix_space import MatrixSpace
    182182from sage.rings.arith import GCD, rising_factorial, binomial
    def min_wt_vec(Gmat,F): 
    259259
    260260    AUTHOR: David Joyner (11-2005)
    261261    """
    262     from sage.rings.finite_field import gap_to_sage
     262    from sage.interfaces.gap import gfq_gap_to_sage
    263263    gap.eval("G:="+Gmat)
    264264    k = int(gap.eval("Length(G)"))
    265265    q = F.order()
    def min_wt_vec(Gmat,F): 
    267267    C = gap(Gmat).GeneratorMatCode(F)
    268268    n = int(C.WordLength())
    269269    cg = C.MinimumDistanceCodeword()
    270     c = [gap_to_sage(cg[j],F) for j in range(1,n+1)]
     270    c = [gfq_gap_to_sage(cg[j],F) for j in range(1,n+1)]
    271271    V = VectorSpace(F,n)
    272272    return V(c)
    273273    ## this older code returns more info but may be slower:
    class LinearCode(module.Module): 
    495495            False
    496496
    497497        """
    498         from sage.rings.finite_field import gap_to_sage
     498        from sage.interfaces.gap import gfq_gap_to_sage
    499499        F = self.base_ring()
    500500        q = F.order()
    501501        G = self.gen_mat()
    502502        n = len(G.columns())
    503503        Cg = gap(G).GeneratorMatCode(F)
    504504        c = Cg.Random()
    505         ans = [gap_to_sage(c[i],F) for i in range(1,n+1)]
     505        ans = [gfq_gap_to_sage(c[i],F) for i in range(1,n+1)]
    506506        V = VectorSpace(F,n)
    507507        return V(ans)
    508508   
    class LinearCode(module.Module): 
    718718
    719719        Does not work for very long codes since the syndrome table grows too large.
    720720        """
    721         from sage.rings.finite_field import gap_to_sage
     721        from sage.interfaces.gap import gfq_gap_to_sage
    722722        F = self.base_ring()
    723723        q = F.order()
    724724        G = self.gen_mat()
    class LinearCode(module.Module): 
    734734            vstr = vstr[1:-1]     # added by William Stein so const.tex works 2006-10-01
    735735        gap.eval("C:=GeneratorMatCode("+Gstr+",GF("+str(q)+"))")
    736736        gap.eval("c:=VectorCodeword(Decodeword( C, Codeword( "+vstr+" )))") # v->vstr, 8-27-2006
    737         ans = [gap_to_sage(gap.eval("c["+str(i)+"]"),F) for i in range(1,n+1)]
     737        ans = [gfq_gap_to_sage(gap.eval("c["+str(i)+"]"),F) for i in range(1,n+1)]
    738738        V = VectorSpace(F,n)
    739739        return V(ans)
    740740
  • sage/crypto/mq/mpolynomialsystem.py

    diff -r 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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
    85 
    86 from sage.structure.parent_gens import normalize_names, ParentWithGens
    87139
    88140import sage.interfaces.gap
    89141import sage.databases.conway
    def FiniteField(order, name=None, modulu 
    152204        sage: F.<x> = GF(5)[]
    153205        sage: K.<a> = GF(5**2, name='a', modulus=x^2 + 2, check_irreducible=False)
    154206
    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.
     207    For example, you may print finite field elements as integers. This
     208    currently only works if the order of field is $<2^{16}$, though.
    158209
    159210        sage: k.<a> = GF(2^8,repr='int')
    160211        sage: a
    161212        2
    162213
    163214    The order of a finite field must be a prime power:
     215   
    164216        sage: GF(100)
    165217        Traceback (most recent call last):
    166218        ...
    def FiniteField(order, name=None, modulu 
    179231        if not K is None:
    180232            return K
    181233    if arith.is_prime(order):
     234        from finite_field_prime_modn import FiniteField_prime_modn
    182235        K = FiniteField_prime_modn(order,*args,**kwds)
    183236    else:
    184237        if not arith.is_prime_power(order):
    def FiniteField(order, name=None, modulu 
    195248            # DO *NOT* use for prime subfield, since that would lead to
    196249            # a circular reference in the call to ParentWithGens in the
    197250            # __init__ method.
     251            from finite_field_givaro import FiniteField_givaro
    198252            K = FiniteField_givaro(order, name, modulus, cache=elem_cache, *args,**kwds)
    199253        else:
    200254            if integer.Integer(order).factor()[0][0] == 2:
    def FiniteField(order, name=None, modulu 
    210264
    211265def is_PrimeFiniteField(x):
    212266    """
    213     Returns True if x is a prime finite field (which is a specific
    214     data type).
     267    Returns True if x is a prime finite field.
    215268
    216269    EXAMPLES:
    217270        sage: is_PrimeFiniteField(QQ)
    def is_PrimeFiniteField(x): 
    223276        sage: is_PrimeFiniteField(GF(next_prime(10^90,proof=False)))
    224277        True
    225278    """
    226     return isinstance(x, FiniteField_prime_modn)
     279    from finite_field_prime_modn import FiniteField_prime_modn
     280    from ring import FiniteField as FiniteField_generic
     281
     282    return isinstance(x, FiniteField_prime_modn) or \
     283           (isinstance(x, FiniteField_generic) and x.degree() == 1)
    227284   
    228 GF = FiniteField
    229 
    230285##################################################################
    231286   
    232287def conway_polynomial(p, n):
    233     """
     288    r"""
    234289    Return the Conway polynomial of degree n over GF(p), which is
    235290    loaded from a table.
    236291
    def conway_polynomial(p, n): 
    248303    disk, which takes a fraction of a second.  Subsequent calls do not
    249304    require reloading the table.
    250305
    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
     306    See also the \code{ConwayPolynomials()} object, which is a table of
     307    Conway polynomials.   For example, if \code{c=ConwayPolynomials}, then
     308    \code{c.primes()} is a list of all primes for which the polynomials are
     309    known, and for a given prime $p$,  \code{c.degree(p)} is a list of all
    255310    degrees for which the Conway polynomials are known.
    256311
    257312    EXAMPLES:
    def conway_polynomial(p, n): 
    265320        RuntimeError: requested conway polynomial not in database.
    266321    """
    267322    (p,n)=(int(p),int(n))
    268     R = polynomial_ring.PolynomialRing(GF(p), 'x')
     323    R = polynomial_ring.PolynomialRing(FiniteField(p), 'x')
    269324    try:
    270325        return R(sage.databases.conway.ConwayPolynomials()[p][n])
    271326    except KeyError:
    272327        raise RuntimeError, "requested conway polynomial not in database."
    273328
    274329def exists_conway_polynomial(p, n):
    275     """
    276     Return True if the Conway polynomial over F_p of degree n is in the
     330    r"""
     331    Return True if the Conway polynomial over $F_p$ of degree $n$ is in the
    277332    database and False otherwise.
    278333
    279334    If the Conway polynomial is in the database, to obtain it use the
    280     command conway_polynomial(p,n).
     335    command \code{conway_polynomial(p,n)}.
    281336
    282337    EXAMPLES:
    283338        sage: exists_conway_polynomial(2,3)
    def exists_conway_polynomial(p, n): 
    291346    """
    292347    return sage.databases.conway.ConwayPolynomials().has_polynomial(p,n)
    293348
    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
    452349
    453350zech_log_bound = 2**16
  • sage/rings/finite_field_ext_pari.py

    diff -r 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c sage/rings/integer_mod_ring.py
    a b def IntegerModRing(order=0): 
    9999    if _objsIntegerModRing.has_key(order):
    100100        x = _objsIntegerModRing[order]()
    101101        if not x is None: return x
    102     #if check_prime and arith.is_prime(order):
    103     #    R = sage.rings.finite_field.FiniteField_prime_modn(order)
    104     #else:
    105102    R = IntegerModRing_generic(order)
    106103    _objsIntegerModRing[order] = weakref.ref(R)
    107104    return R
    class IntegerModRing_generic(quotient_ri 
    580577            return TypeError, "error coercing to finite field"
    581578        except TypeError:
    582579            if sage.interfaces.all.is_GapElement(x):
    583                 import finite_field
     580                from sage.interfaces.gap import gfq_gap_to_sage
    584581                try:
    585                     return finite_field.gap_to_sage(x, self)
     582                    return gfq_gap_to_sage(x, self)
    586583                except (ValueError, IndexError, TypeError), msg:
    587584                    raise TypeError, "%s\nerror coercing to finite field"%msg
    588585            else:
  • sage/rings/padics/factory.py

    diff -r 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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 59538ebc8f3b -r a1755ae00b9c 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