Ticket #11873: 11873.patch

File 11873.patch, 4.8 KB (added by Jeroen Demeyer, 11 years ago)
  • sage/rings/padics/padic_base_generic_element.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1317730265 -7200
    # Node ID 9a8537346d18bebae0872dd1c23c2f97da0b4468
    # Parent  f128679a5afc7f985064a99e5d413d7486139bdb
    Fix abs() of zero p-adics
    
    diff --git a/sage/rings/padics/padic_base_generic_element.pyx b/sage/rings/padics/padic_base_generic_element.pyx
    a b  
    7777        else:
    7878            return 1
    7979
    80     cpdef abs(self, prec=None):
    81         """
    82         Returns the `p`-adic absolute value of ``self``.
    83 
    84         This is normalized so that the absolute value of `p` is `1/p`.
    85 
    86         INPUT:
    87        
    88         - ``prec`` -- Integer.  The precision of the real field in
    89           which the answer is returned.  If ``None``, returns a
    90           rational for absolutely unramified fields, or a real with 53
    91           bits of precision if ramified.
    92 
    93         EXAMPLES:
    94         sage: a = Qp(5)(15); a.abs()
    95         1/5
    96         sage: a.abs(53)
    97         0.200000000000000
    98         """
    99         if prec is None:
    100             return self.prime_pow.prime**(-self.valuation())
    101         from sage.rings.real_mpfr import RealField
    102         return RealField(prec)(self.prime_pow.prime**(-self.valuation()))
    103 
    10480    def exp(self):
    10581        r"""
    10682        Compute the `p`-adic exponential of any element of
  • sage/rings/padics/padic_ext_element.pyx

    diff --git a/sage/rings/padics/padic_ext_element.pyx b/sage/rings/padics/padic_ext_element.pyx
    a b  
    309309            [1, 0, -1, 0, 2, 1, 2, 0, 1]
    310310        """
    311311        return self.ext_p_list(pos)       
    312 
    313     cpdef abs(self, prec=None):
    314         """
    315         Returns the p-adic absolute value of self.
    316 
    317         This is normalized so that the absolute value of p is 1/p.
    318 
    319         INPUT --
    320         prec - Integer.  The precision of the real field in which the answer is returned.  If None, returns a rational for absolutely unramified fields, or a real with 53 bits of precision if ramified.
    321 
    322         EXAMPLES:
    323         sage: R = Zp(5,5)
    324         sage: S.<x> = ZZ[]
    325         sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5
    326         sage: W.<w> = R.ext(f)
    327         sage: w.abs()
    328         0.724779663677696
    329         """
    330         if prec is None:
    331             if self.parent().e() == 1:
    332                 return self.parent().prime()**(-self.valuation())
    333             else:
    334                 prec = 53
    335         from sage.rings.real_mpfr import RealField
    336         return RealField(prec)(self.parent().prime())**(-self.ordp())
  • 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  
    10281028
    10291029    cpdef abs(self, prec=None):
    10301030        """
    1031         Returns the p-adic absolute value of self.
     1031        Return the `p`-adic absolute value of ``self``.
    10321032
    1033         This is normalized so that the absolute value of p is 1/p.
     1033        This is normalized so that the absolute value of `p` is `1/p`.
    10341034
    1035         INPUT::
     1035        INPUT:
    10361036       
    1037             - prec -- Integer.  The precision of the real field in
    1038               which the answer is returned.  If None, returns a
    1039               rational for absolutely unramified fields, or a real
    1040               with 53 bits of precision if ramified.
     1037        - ``prec`` -- Integer.  The precision of the real field in which
     1038          the answer is returned.  If ``None``, returns a rational for
     1039          absolutely unramified fields, or a real with 53 bits of
     1040          precision for ramified fields.
    10411041
    10421042        EXAMPLES::
    1043        
     1043
    10441044            sage: a = Qp(5)(15); a.abs()
    10451045            1/5
    10461046            sage: a.abs(53)
    10471047            0.200000000000000
     1048            sage: Qp(7)(0).abs()
     1049            0
     1050            sage: Qp(7)(0).abs(prec=20)
     1051            0.00000
     1052
     1053        An unramified extension::
     1054
     1055            sage: R = Zp(5,5)
     1056            sage: P.<x> = PolynomialRing(R)
     1057            sage: Z25.<u> = R.ext(x^2 - 3)
     1058            sage: u.abs()
     1059            1
     1060            sage: (u^24-1).abs()
     1061            1/5
     1062
     1063        A ramified extension::
     1064
     1065            sage: W.<w> = R.ext(x^5 + 75*x^3 - 15*x^2 + 125*x - 5)
     1066            sage: w.abs()
     1067            0.724779663677696
     1068            sage: W(0).abs()
     1069            0.000000000000000
    10481070        """
    1049         raise NotImplementedError
     1071        K = self.parent()
     1072        if not prec and K.e() > 1:
     1073            prec = 53
     1074        if prec:
     1075            from sage.rings.real_mpfr import RealField
     1076            if self.is_zero():
     1077                return RealField(prec).zero()
     1078            return RealField(prec)(K.prime())**(-self.ordp())
     1079        else:
     1080            if self.is_zero():
     1081                return Rational(0)
     1082            return Rational(K.prime())**(-self.valuation())
     1083