Ticket #14294: 14294.patch

File 14294.patch, 14.0 KB (added by roed, 9 years ago)
  • sage/rings/padics/padic_ZZ_pX_CA_element.pxd

    # HG changeset patch
    # User David Roe <roed.math@gmail.com>
    # Date 1363601306 21600
    # Node ID c88cd4c60e6cdc9350b66c5fb75cf23c3fb418a2
    # Parent  790eb8c53dd40f50d99b9e1afe0e725707996cf1
    #14294: make absprec argument of lift_to_precision optional
    
    diff --git a/sage/rings/padics/padic_ZZ_pX_CA_element.pxd b/sage/rings/padics/padic_ZZ_pX_CA_element.pxd
    a b  
    2323    cpdef _ntl_rep_abs(self)
    2424    cpdef ntl_ZZ_pX _ntl_rep(self)
    2525
    26     cpdef pAdicZZpXCAElement lift_to_precision(self, absprec)
    27  No newline at end of file
     26    cpdef pAdicZZpXCAElement lift_to_precision(self, absprec=*)
  • sage/rings/padics/padic_ZZ_pX_CA_element.pyx

    diff --git a/sage/rings/padics/padic_ZZ_pX_CA_element.pyx b/sage/rings/padics/padic_ZZ_pX_CA_element.pyx
    a b  
    17541754
    17551755#         raise NotImplementedError
    17561756
    1757     cpdef pAdicZZpXCAElement lift_to_precision(self, absprec):
     1757    cpdef pAdicZZpXCAElement lift_to_precision(self, absprec=None):
    17581758        """
    17591759        Returns a ``pAdicZZpXCAElement`` congruent to ``self`` but with
    1760         absolute precision at least ``absprec``.  If setting ``absprec`` that
    1761         high would violate the precision cap, raises a precision error.
     1760        absolute precision at least ``absprec``.
    17621761
    1763         Note that the new digits will not necessarily be zero.
     1762        INPUT:
     1763
     1764        - ``absprec`` -- (default ``None``) the absolute precision of
     1765          the result.  If ``None``, lifts to the maximum precision
     1766          allowed.
     1767
     1768        .. NOTE::
     1769
     1770            If setting ``absprec`` that high would violate the
     1771            precision cap, raises a precision error.
     1772
     1773            Note that the new digits will not necessarily be zero.
    17641774
    17651775        EXAMPLES::
    1766        
     1776
    17671777            sage: R = ZpCA(5,5)
    17681778            sage: S.<x> = ZZ[]
    17691779            sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5
     
    17801790            [345]
    17811791            sage: c._ntl_rep()
    17821792            [345]
     1793            sage: a.lift_to_precision().precision_absolute() == W.precision_cap()
     1794            True
    17831795        """
    17841796        cdef pAdicZZpXCAElement ans
    17851797        cdef long aprec, rprec
    1786         if not PY_TYPE_CHECK(absprec, Integer):
     1798        if absprec is not None and not PY_TYPE_CHECK(absprec, Integer):
    17871799            absprec = Integer(absprec)
    1788         if mpz_fits_slong_p((<Integer>absprec).value) == 0:
     1800        if absprec is None:
     1801            aprec = self.prime_pow.ram_prec_cap
     1802        elif mpz_fits_slong_p((<Integer>absprec).value) == 0:
    17891803            if mpz_sgn((<Integer>absprec).value) < 0:
    17901804                return self
    17911805            else:
    1792                 aprec = self.prime_pow.ram_prec_cap
     1806                raise PrecisionError("Precision higher than allowed by the precision cap.")
    17931807        else:
    17941808            aprec = mpz_get_si((<Integer>absprec).value)
     1809            if aprec > self.prime_pow.ram_prec_cap:
     1810                raise PrecisionError("Precision higher than allowed by the precision cap.")
    17951811        if aprec <= self.absprec:
    17961812            return self
    17971813        ans = self._new_c(aprec) # restores context
  • sage/rings/padics/padic_ZZ_pX_CR_element.pxd

    diff --git a/sage/rings/padics/padic_ZZ_pX_CR_element.pxd b/sage/rings/padics/padic_ZZ_pX_CR_element.pxd
    a b  
    3131    cpdef _ntl_rep_abs(self)
    3232    cpdef ntl_ZZ_pX _ntl_rep(self)
    3333
    34     cpdef pAdicZZpXCRElement lift_to_precision(self, absprec)
    35  No newline at end of file
     34    cpdef pAdicZZpXCRElement lift_to_precision(self, absprec=*)
  • sage/rings/padics/padic_ZZ_pX_CR_element.pyx

    diff --git a/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/sage/rings/padics/padic_ZZ_pX_CR_element.pyx
    a b  
    25412541#        """
    25422542#        raise NotImplementedError
    25432543
    2544     cpdef pAdicZZpXCRElement lift_to_precision(self, absprec):
     2544    cpdef pAdicZZpXCRElement lift_to_precision(self, absprec=None):
    25452545        """
    25462546        Returns a ``pAdicZZpXCRElement`` congruent to ``self`` but with
    2547         absolute precision at least ``absprec``.  If setting ``absprec`` that
    2548         high would violate the precision cap, raises a precision
    2549         error.  If self is an inexact zero and ``absprec`` is greater than
    2550         the maximum allowed valuation, raises an error.
     2547        absolute precision at least ``absprec``.
    25512548
    2552         Note that the new digits will not necessarily be zero.
     2549        INPUT:
     2550
     2551        - ``absprec`` -- (default ``None``) the absolute precision of
     2552          the result.  If ``None``, lifts to the maximum precision
     2553          allowed.
     2554
     2555        .. NOTE::
     2556
     2557            If setting ``absprec`` that high would violate the
     2558            precision cap, raises a precision error.  If self is an
     2559            inexact zero and ``absprec`` is greater than the maximum
     2560            allowed valuation, raises an error.
     2561
     2562            Note that the new digits will not necessarily be zero.
    25532563
    25542564        EXAMPLES::
    2555        
     2565
    25562566            sage: R = Zp(5,5)
    25572567            sage: S.<x> = R[]
    25582568            sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5
     
    25692579            [19 35 118 60 121]
    25702580            sage: c._ntl_rep()
    25712581            [19 35 118 60 121]
     2582            sage: a.lift_to_precision().precision_relative() == W.precision_cap()
     2583            True
    25722584        """
    25732585        cdef pAdicZZpXCRElement ans
    25742586        cdef long aprec, rprec
    25752587        self._normalize()
    25762588        if self._is_exact_zero():
    25772589            return self
    2578         if not PY_TYPE_CHECK(absprec, Integer):
     2590        if absprec is not None and not PY_TYPE_CHECK(absprec, Integer):
    25792591            absprec = Integer(absprec)
    2580         if mpz_fits_slong_p((<Integer>absprec).value) == 0:
     2592        if absprec is None:
     2593            if self.relprec == 0:
     2594                # return an exact zero
     2595                ans = self._new_c(0)
     2596                ans._set_exact_zero()
     2597                return ans
     2598            aprec = self.prime_pow.ram_prec_cap + self.ordp
     2599        elif mpz_fits_slong_p((<Integer>absprec).value) == 0:
    25812600            if mpz_sgn((<Integer>absprec).value) < 0 or self.relprec == self.prime_pow.ram_prec_cap:
    25822601                return self
    25832602            else:
    25842603                if self.relprec == 0:
    2585                     raise ValueError, "absprec larger than maximum allowable valuation"
    2586                 ans = self._new_c(self.prime_pow.ram_prec_cap)
    2587                 ans.ordp = self.ordp
    2588                 ZZ_pX_conv_modulus(ans.unit, self.unit, self.prime_pow.get_top_context().x)
    2589                 return ans
    2590         aprec = mpz_get_si((<Integer>absprec).value)
     2604                    raise ValueError("absprec larger than maximum allowable valuation")
     2605                else:
     2606                    raise PrecisionError("Precision higher than allowed by the precision cap.")
     2607        else:
     2608            aprec = mpz_get_si((<Integer>absprec).value)
    25912609        if aprec <= self.ordp + self.relprec:
    25922610            return self
    25932611        if self.relprec == 0:
    25942612            if self.ordp >= aprec:
    25952613                return self
    25962614            elif aprec >= maxordp:
    2597                 raise ValueError, "absprec larger than maximum allowable valuation"
     2615                raise ValueError("absprec larger than maximum allowable valuation")
    25982616            else:
    25992617                ans = self._new_c(0)
    26002618                ans._set_inexact_zero(aprec)
     
    26022620        # Now we're done handling all the special cases.
    26032621        rprec = aprec - self.ordp
    26042622        if rprec > self.prime_pow.ram_prec_cap:
    2605             raise PrecisionError, "Precision higher than allowed by the precision cap."
     2623            raise PrecisionError("Precision higher than allowed by the precision cap.")
    26062624        ans = self._new_c(rprec)
    26072625        ans.ordp = self.ordp
    26082626        ZZ_pX_conv_modulus(ans.unit, self.unit, self.prime_pow.get_context_capdiv(rprec).x)
  • sage/rings/padics/padic_ZZ_pX_FM_element.pyx

    diff --git a/sage/rings/padics/padic_ZZ_pX_FM_element.pyx b/sage/rings/padics/padic_ZZ_pX_FM_element.pyx
    a b  
    15471547#        """
    15481548#        raise NotImplementedError
    15491549
    1550     def lift_to_precision(self, absprec):
     1550    def lift_to_precision(self, absprec=None):
    15511551        """
    15521552        Returns ``self``.
    15531553
  • 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  
    964964        mpz_set(ans.value, self.value)
    965965        return ans
    966966
    967     def lift_to_precision(self, absprec):
     967    def lift_to_precision(self, absprec = None):
    968968        """
    969         Returns a `p`-adic integer congruent to this `p`-adic element
    970         modulo ``p^absprec`` with precision at least ``absprec``.
     969        Returns another element of the same parent, with absolute
     970        precision at least absprec, congruent to this one modulo the
     971        known precision.
    971972
    972         If such lifting would yield an element with precision greater
    973         than allowed by the precision cap of ``self``'s parent, an
    974         error is raised.
    975        
     973        INPUT:
     974
     975        - ``absprec`` -- (default ``None``) the absolute precision of
     976          the result.  If ``None``, lifts to the maximum precision
     977          allowed.
     978
     979        .. NOTE::
     980
     981            If setting ``absprec`` that high would violate the
     982            precision cap, raises a precision error.
     983
    976984        EXAMPLES::
    977        
     985
    978986            sage: R = ZpCA(17)
    979987            sage: R(-1,2).lift_to_precision(10)
    980988            16 + 16*17 + O(17^10)
     
    984992            Traceback (most recent call last):
    985993            ...
    986994            PrecisionError: Precision higher than allowed by the precision cap.
     995            sage: R(-1,2).lift_to_precision().precision_absolute() == R.precision_cap()
     996            True
    987997        """
    988998        cdef pAdicCappedAbsoluteElement ans
    989999        cdef unsigned long prec_cap
    9901000        cdef unsigned long dest_prec
    9911001        prec_cap = self.prime_pow.prec_cap
    992         if not PY_TYPE_CHECK(absprec, Integer):
     1002        if absprec is not None and not PY_TYPE_CHECK(absprec, Integer):
    9931003            absprec = Integer(absprec)
    994         if mpz_fits_ulong_p((<Integer>absprec).value) == 0:
    995             ans = self._new_c()
    996             ans._set_prec_abs(prec_cap)
    997             mpz_set(ans.value, self.value)
     1004        if absprec is None:
     1005            dest_prec = prec_cap
     1006        elif mpz_fits_slong_p((<Integer>absprec).value) == 0:
     1007            if mpz_sgn((<Integer>absprec).value) < 0:
     1008                return self
     1009            else:
     1010                raise PrecisionError("Precision higher than allowed by the precision cap.")
    9981011        else:
    9991012            dest_prec = mpz_get_ui((<Integer>absprec).value)
    10001013            if prec_cap < dest_prec:
    1001                 raise PrecisionError, "Precision higher than allowed by the precision cap."
    1002             if dest_prec <= self.absprec:
    1003                 return self
    1004             else:
    1005                 ans = self._new_c()
    1006                 ans._set_prec_abs(dest_prec)
    1007                 mpz_set(ans.value, self.value)
     1014                raise PrecisionError("Precision higher than allowed by the precision cap.")
     1015        if dest_prec <= self.absprec:
     1016            return self
     1017        else:
     1018            ans = self._new_c()
     1019            ans._set_prec_abs(dest_prec)
     1020            mpz_set(ans.value, self.value)
    10081021        return ans
    10091022
    10101023    def list(pAdicCappedAbsoluteElement self, lift_mode = 'simple'):
  • 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  
    18641864            mpz_mul(ans.value, self.unit, self.prime_pow.pow_mpz_t_tmp(self.ordp)[0])
    18651865            return ans
    18661866
    1867     def lift_to_precision(self, absprec):
     1867    def lift_to_precision(self, absprec = None):
    18681868        """
    18691869        Returns another element of the same parent, with absolute
    1870         precision at least absprec, congruent to self modulo self's
    1871         precision.
     1870        precision at least absprec, congruent to this one modulo the
     1871        known precision.
    18721872
    1873         If such lifting would yield an element with precision greater
    1874         than allowed by the precision cap of self's parent, an error
    1875         is raised.
     1873        INPUT:
     1874
     1875        - ``absprec`` -- (default ``None``) the absolute precision of
     1876          the result.  If ``None``, lifts to the maximum precision
     1877          allowed.
     1878
     1879        .. NOTE::
     1880
     1881            If setting ``absprec`` that high would violate the
     1882            precision cap, raises a precision error.  If self is an
     1883            inexact zero and ``absprec`` is greater than the maximum
     1884            allowed valuation, raises an error.
    18761885
    18771886        EXAMPLES::
    18781887
     
    18931902            Traceback (most recent call last):
    18941903            ...
    18951904            PrecisionError: Precision higher than allowed by the precision cap.
     1905            sage: c.lift_to_precision().precision_relative() == R.precision_cap()
     1906            True
    18961907        """
    1897         if not PY_TYPE_CHECK(absprec, Integer):
     1908        cdef pAdicCappedRelativeElement ans
     1909        if absprec is None:
     1910            if self.relprec == 0:
     1911                ans = self._new_c()
     1912                ans._set_exact_zero()
     1913                return ans
     1914            return self.lift_to_precision_c(self.ordp + self.prime_pow.prec_cap)
     1915        elif not PY_TYPE_CHECK(absprec, Integer):
    18981916            absprec = Integer(absprec)
    18991917        return self.lift_to_precision_c(mpz_get_si((<Integer>absprec).value))
    19001918
  • sage/rings/padics/padic_fixed_mod_element.pyx

    diff --git a/sage/rings/padics/padic_fixed_mod_element.pyx b/sage/rings/padics/padic_fixed_mod_element.pyx
    a b  
    821821        mpz_set(ans.value, self.value)
    822822        return ans
    823823
    824     def lift_to_precision(self, absprec):
     824    def lift_to_precision(self, absprec=None):
    825825        """
    826826        Returns self.
    827827