Ticket #594: magma_gfq.patch

File magma_gfq.patch, 7.1 KB (added by malb, 14 years ago)
  • sage/interfaces/magma.py

    # HG changeset patch
    # User 'Martin Albrecht <malb@informatik.uni-bremen.de>'
    # Date 1189002374 -3600
    # Node ID 7a7978220d6bc1a2685a09e068565f4cacababa4
    # Parent  1eb99b8dd81a3a0e18f039da1a2566395e44c3bf
    merge
    
    diff -r 1eb99b8dd81a -r 7a7978220d6b sage/interfaces/magma.py
    a b class Magma(Expect): 
    260260        x = str(x).rstrip()
    261261        if len(x) == 0 or x[len(x) - 1] != ';':
    262262            x += ';'
     263        print "INPUT",x
    263264        ans = Expect.eval(self, x).replace('\\\n','')
    264265        if 'Runtime error' in ans or 'User error' in ans:
    265266            raise RuntimeError, "Error evaluation Magma code.\nIN:%s\nOUT:%s"%(x, ans)
    class Magma(Expect): 
    313314            Lexicographical Order
    314315            Variables: x, y, z
    315316        """
     317        print "INPUT",x
    316318        if gens is None:
    317319            return Expect.__call__(self, x)
    318320        return self.objgens(x, gens)
    class Magma(Expect): 
    416418            raise TypeError, "Error executing Magma code:\n%s"%out
    417419        return ans
    418420
    419    
    420            
    421421    #def new(self, x):
    422422    #    if isinstance(x, MagmaElement) and x.parent() == self:
    423423    #        return x
    class Magma(Expect): 
    510510            self.__trait_names = N
    511511            return N
    512512
     513    def ideal(self, L):
     514        """
     515        """
     516        P = iter(L).next().parent()
     517        Pn = P._magma_().name()
     518        k = P.base_ring()
     519        if k.degree() > 1:
     520            i = str(k.gen())
     521            o = k._magma_().name() + ".1"
     522            self.eval("%s := %s"%(i,o))
     523        mlist = self(L)
     524        return self("ideal<%s|%s>"%(Pn,mlist.name()))
    513525
    514526class MagmaFunctionElement(FunctionElement):
    515527    def __call__(self, *args, **kwds):
  • sage/rings/polynomial/multi_polynomial_ideal.py

    diff -r 1eb99b8dd81a -r 7a7978220d6b sage/rings/polynomial/multi_polynomial_ideal.py
    a b class MPolynomialIdeal_magma_repr: 
    155155        if magma == None:
    156156            import sage.interfaces.magma
    157157            magma = sage.interfaces.magma.magma
    158         mlist = magma(self.gens())
    159         return magma("ideal<%s|%s>"%(self.ring()._magma_().name(),mlist.name()))
     158        return magma.ideal(self.gens())
    160159
    161160    def _magma_groebner_basis(self):
    162161        """
  • sage/rings/ring.pyx

    diff -r 1eb99b8dd81a -r 7a7978220d6b sage/rings/ring.pyx
    a b cdef class FiniteField(Field): 
    10261026        return 'GF(%s)'%self.order()
    10271027
    10281028    def _magma_init_(self):
    1029         return 'GF(%s)'%self.order()
     1029        """
     1030        Return string representation of self that MAGMA can
     1031        understand.
     1032        """
     1033        if self.degree() == 1:
     1034            return 'GF(%s)'%self.order()
     1035        B = self.base_ring()
     1036        p = self.polynomial()
     1037        return "ext< %s | %s >"%(B._magma_init_(),p._magma_init_())
    10301038   
    10311039    def __cmp__(self, other):
    10321040        """
  • sage/interfaces/magma.py

    # HG changeset patch
    # User 'Martin Albrecht <malb@informatik.uni-bremen.de>'
    # Date 1189008402 -3600
    # Node ID b4eeb4c6f0dd0ffbb0384332aac99834d6125fcf
    # Parent  7a7978220d6bc1a2685a09e068565f4cacababa4
    several fixes to teach the MAGMA interface GF(q) conversion
    
    diff -r 7a7978220d6b -r b4eeb4c6f0dd sage/interfaces/magma.py
    a b class Magma(Expect): 
    260260        x = str(x).rstrip()
    261261        if len(x) == 0 or x[len(x) - 1] != ';':
    262262            x += ';'
    263         print "INPUT",x
    264263        ans = Expect.eval(self, x).replace('\\\n','')
    265264        if 'Runtime error' in ans or 'User error' in ans:
    266265            raise RuntimeError, "Error evaluation Magma code.\nIN:%s\nOUT:%s"%(x, ans)
    class Magma(Expect): 
    314313            Lexicographical Order
    315314            Variables: x, y, z
    316315        """
    317         print "INPUT",x
    318316        if gens is None:
    319317            return Expect.__call__(self, x)
    320318        return self.objgens(x, gens)
    class Magma(Expect): 
    518516        k = P.base_ring()
    519517        if k.degree() > 1:
    520518            i = str(k.gen())
    521             o = k._magma_().name() + ".1"
     519            o = self("BaseRing(%s).1"%Pn).name()
    522520            self.eval("%s := %s"%(i,o))
    523521        mlist = self(L)
    524522        return self("ideal<%s|%s>"%(Pn,mlist.name()))
  • sage/rings/polynomial/multi_polynomial_ideal.py

    diff -r 7a7978220d6b -r b4eeb4c6f0dd sage/rings/polynomial/multi_polynomial_ideal.py
    a b class MPolynomialIdeal_magma_repr: 
    174174            pass
    175175        R = self.ring()
    176176        mgb = self._magma_().GroebnerBasis()
    177         B = Sequence([R(str(mgb[i+1])) for i in range(len(mgb))], R,
    178                         check=False, immutable=True)
     177        mgb = [str(mgb[i+1]) for i in range(len(mgb))]
     178        if R.base_ring().degree() > 1:
     179            a = str(R.base_ring().gen())
     180            mgb = [e.replace("$.1",a) for e in mgb]
     181        B = Sequence([R(e) for e in mgb], R, check=False, immutable=True)
    179182        self.__magma_groebner_basis = B
    180183        return B
    181184         
  • sage/rings/polynomial/multi_polynomial_ring_generic.pyx

    diff -r 7a7978220d6b -r b4eeb4c6f0dd sage/rings/polynomial/multi_polynomial_ring_generic.pyx
    a b cdef class MPolynomialRing_generic(sage. 
    254254            return R
    255255
    256256    def _magma_init_(self):
    257         B = self.base_ring()._magma_init_()
     257        """
     258        Return a string representation of self MAGMA can understand.
     259        """
     260        try: # we need that for GF(q) arithmetic
     261            B = self.base_ring()._magma_().name()
     262        except (RuntimeError,TypeError):
     263            B = self.base_ring()._magma_init_()
    258264        R = 'PolynomialRing(%s, %s, %s)'%(B, self.ngens(),self.term_order().magma_str())
    259265        return R
    260266   
  • sage/rings/ring.pxd

    diff -r 7a7978220d6b -r b4eeb4c6f0dd sage/rings/ring.pxd
    a b cdef class FiniteField(Field): 
    3131    cdef public object __multiplicative_generator
    3232    cdef public object __polynomial_ring
    3333    cdef public object __vector_space
     34    cdef public object __interface
    3435
    3536cdef class Algebra(Ring):
    3637    pass
  • sage/structure/sage_object.pyx

    diff -r 7a7978220d6b -r b4eeb4c6f0dd sage/structure/sage_object.pyx
    a b cdef class SageObject: 
    229229                X = self.__interface[I]
    230230                X._check_valid()
    231231                return X
    232             except AttributeError:
     232            except (AttributeError, TypeError):
    233233                try:
    234234                    self.__interface = {}
    235235                except AttributeError: