Ticket #9948: 9948_padic_pari_gp.patch

File 9948_padic_pari_gp.patch, 3.8 KB (added by jdemeyer, 11 years ago)
  • sage/rings/padics/padic_base_generic_element.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1321046401 -3600
    # Node ID a32c647f42f3367c3283b6561468a19acebd084a
    # Parent  ffd0a4aeb77c44b0e1d528e323f87ecffcd86930
    Fix conversion of p-adics between Sage and PARI/GP
    
    diff --git a/sage/rings/padics/padic_base_generic_element.pyx b/sage/rings/padics/padic_base_generic_element.pyx
    a b  
    1010"""
    1111
    1212from sage.rings.integer import Integer
     13from sage.rings.infinity import infinity
    1314
    1415cdef class pAdicBaseGenericElement(pAdicGenericElement):
    1516    def __init__(self, parent):
     
    3132
    3233    def _pari_init_(self):
    3334        """
    34         A string that when input into pari will yield the pari version
     35        A string that when input into PARI will yield the PARI version
    3536        of this element.
    3637
    3738        EXAMPLES::
    3839
    39             sage: R = ZpCA(5)
    40             sage: pari(R(1777)) #indirect doctest
     40            sage: gp(ZpCA(5)(1777))
    4141            2 + 5^2 + 4*5^3 + 2*5^4 + O(5^20)
     42            sage: gp(Qp(5)(1/25))
     43            5^-2 + O(5^18)
     44            sage: gp(ZpCR(5)(0))   # absolute precision is +Infinity
     45            0
     46            sage: gp(ZpCA(5)(0))   # absolute precision is 20
     47            O(5^20)
    4248        """
    43         return "%s + O(%s^%s)" % (self.lift(), self.parent().prime(), self.precision_absolute())
     49        if self.precision_absolute() is infinity:
     50            return "%s" % self.lift()
     51        else:
     52            return "%s+O(%s^%s)" % (self.lift(), self.parent().prime(), self.precision_absolute())
    4453
    4554    def _integer_(self, Z=None):
    4655        """
  • sage/rings/padics/padic_capped_absolute_element.pyx

    diff --git a/sage/rings/padics/padic_capped_absolute_element.pyx b/sage/rings/padics/padic_capped_absolute_element.pyx
    a b  
    7272            2 + 2*3 + O(3^2)
    7373            sage: R(3 + O(3^2))
    7474            3 + O(3^2)
     75            sage: R(pari(9))
     76            3^2 + O(3^5)
     77            sage: R(gp(9))
     78            3^2 + O(3^5)
    7579        """
    7680        mpz_init(self.value)
    7781        pAdicBaseGenericElement.__init__(self,parent)
     
    111115            return
    112116        elif isinstance(x, (int, long)):
    113117            x = Integer(x)
    114         elif isinstance(x, pari_gen):
     118        elif isinstance(x, pari_gen) or isinstance(x, sage.interfaces.gp.GpElement):
    115119            if x.type() == "t_PADIC":
    116120                if x.variable() != self.prime_pow.prime:
    117121                    raise TypeError, "Cannot coerce a pari p-adic with the wrong prime."
  • sage/rings/padics/padic_capped_relative_element.pyx

    diff --git a/sage/rings/padics/padic_capped_relative_element.pyx b/sage/rings/padics/padic_capped_relative_element.pyx
    a b  
    19061906            O(5^5)
    19071907        """
    19081908        if mpz_sgn(self.unit) == -1:
    1909             return P.new_gen_from_int(0)
     1909            return P.PARI_ZERO
    19101910        else:
    19111911            return P.new_gen_from_padic(self.ordp, self.relprec,
    19121912                                        self.prime_pow.prime.value,
  • sage/rings/padics/padic_generic_element.pyx

    diff --git a/sage/rings/padics/padic_generic_element.pyx b/sage/rings/padics/padic_generic_element.pyx
    a b  
    174174    cdef bint _set_prec_both(self, long absprec, long relprec) except -1:
    175175        return 0
    176176   
    177     #def _pari_(self):
    178     #    """
    179     #    Returns a pari version of this element.
    180 
    181     #    EXAMPLES::
    182 
    183     #        sage: R = Zp(5)
    184     #        sage: pari(R(1777))
    185     #        2 + 5^2 + 4*5^3 + 2*5^4 + O(5^20)
    186     #    """
    187     #    return pari(self._pari_init_())
    188 
    189177    def __floordiv__(self, right):
    190178        """
    191179        Divides self by right and throws away the nonintegral part if