# 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
|
|
23 | 23 | cpdef _ntl_rep_abs(self) |
24 | 24 | cpdef ntl_ZZ_pX _ntl_rep(self) |
25 | 25 | |
26 | | cpdef pAdicZZpXCAElement lift_to_precision(self, absprec) |
27 | | No newline at end of file |
| 26 | cpdef pAdicZZpXCAElement lift_to_precision(self, absprec=*) |
diff --git a/sage/rings/padics/padic_ZZ_pX_CA_element.pyx b/sage/rings/padics/padic_ZZ_pX_CA_element.pyx
a
|
b
|
|
1754 | 1754 | |
1755 | 1755 | # raise NotImplementedError |
1756 | 1756 | |
1757 | | cpdef pAdicZZpXCAElement lift_to_precision(self, absprec): |
| 1757 | cpdef pAdicZZpXCAElement lift_to_precision(self, absprec=None): |
1758 | 1758 | """ |
1759 | 1759 | 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``. |
1762 | 1761 | |
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. |
1764 | 1774 | |
1765 | 1775 | EXAMPLES:: |
1766 | | |
| 1776 | |
1767 | 1777 | sage: R = ZpCA(5,5) |
1768 | 1778 | sage: S.<x> = ZZ[] |
1769 | 1779 | sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 |
… |
… |
|
1780 | 1790 | [345] |
1781 | 1791 | sage: c._ntl_rep() |
1782 | 1792 | [345] |
| 1793 | sage: a.lift_to_precision().precision_absolute() == W.precision_cap() |
| 1794 | True |
1783 | 1795 | """ |
1784 | 1796 | cdef pAdicZZpXCAElement ans |
1785 | 1797 | 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): |
1787 | 1799 | 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: |
1789 | 1803 | if mpz_sgn((<Integer>absprec).value) < 0: |
1790 | 1804 | return self |
1791 | 1805 | else: |
1792 | | aprec = self.prime_pow.ram_prec_cap |
| 1806 | raise PrecisionError("Precision higher than allowed by the precision cap.") |
1793 | 1807 | else: |
1794 | 1808 | 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.") |
1795 | 1811 | if aprec <= self.absprec: |
1796 | 1812 | return self |
1797 | 1813 | ans = self._new_c(aprec) # restores context |
diff --git a/sage/rings/padics/padic_ZZ_pX_CR_element.pxd b/sage/rings/padics/padic_ZZ_pX_CR_element.pxd
a
|
b
|
|
31 | 31 | cpdef _ntl_rep_abs(self) |
32 | 32 | cpdef ntl_ZZ_pX _ntl_rep(self) |
33 | 33 | |
34 | | cpdef pAdicZZpXCRElement lift_to_precision(self, absprec) |
35 | | No newline at end of file |
| 34 | cpdef pAdicZZpXCRElement lift_to_precision(self, absprec=*) |
diff --git a/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/sage/rings/padics/padic_ZZ_pX_CR_element.pyx
a
|
b
|
|
2541 | 2541 | # """ |
2542 | 2542 | # raise NotImplementedError |
2543 | 2543 | |
2544 | | cpdef pAdicZZpXCRElement lift_to_precision(self, absprec): |
| 2544 | cpdef pAdicZZpXCRElement lift_to_precision(self, absprec=None): |
2545 | 2545 | """ |
2546 | 2546 | 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``. |
2551 | 2548 | |
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. |
2553 | 2563 | |
2554 | 2564 | EXAMPLES:: |
2555 | | |
| 2565 | |
2556 | 2566 | sage: R = Zp(5,5) |
2557 | 2567 | sage: S.<x> = R[] |
2558 | 2568 | sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 |
… |
… |
|
2569 | 2579 | [19 35 118 60 121] |
2570 | 2580 | sage: c._ntl_rep() |
2571 | 2581 | [19 35 118 60 121] |
| 2582 | sage: a.lift_to_precision().precision_relative() == W.precision_cap() |
| 2583 | True |
2572 | 2584 | """ |
2573 | 2585 | cdef pAdicZZpXCRElement ans |
2574 | 2586 | cdef long aprec, rprec |
2575 | 2587 | self._normalize() |
2576 | 2588 | if self._is_exact_zero(): |
2577 | 2589 | return self |
2578 | | if not PY_TYPE_CHECK(absprec, Integer): |
| 2590 | if absprec is not None and not PY_TYPE_CHECK(absprec, Integer): |
2579 | 2591 | 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: |
2581 | 2600 | if mpz_sgn((<Integer>absprec).value) < 0 or self.relprec == self.prime_pow.ram_prec_cap: |
2582 | 2601 | return self |
2583 | 2602 | else: |
2584 | 2603 | 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) |
2591 | 2609 | if aprec <= self.ordp + self.relprec: |
2592 | 2610 | return self |
2593 | 2611 | if self.relprec == 0: |
2594 | 2612 | if self.ordp >= aprec: |
2595 | 2613 | return self |
2596 | 2614 | elif aprec >= maxordp: |
2597 | | raise ValueError, "absprec larger than maximum allowable valuation" |
| 2615 | raise ValueError("absprec larger than maximum allowable valuation") |
2598 | 2616 | else: |
2599 | 2617 | ans = self._new_c(0) |
2600 | 2618 | ans._set_inexact_zero(aprec) |
… |
… |
|
2602 | 2620 | # Now we're done handling all the special cases. |
2603 | 2621 | rprec = aprec - self.ordp |
2604 | 2622 | 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.") |
2606 | 2624 | ans = self._new_c(rprec) |
2607 | 2625 | ans.ordp = self.ordp |
2608 | 2626 | ZZ_pX_conv_modulus(ans.unit, self.unit, self.prime_pow.get_context_capdiv(rprec).x) |
diff --git a/sage/rings/padics/padic_ZZ_pX_FM_element.pyx b/sage/rings/padics/padic_ZZ_pX_FM_element.pyx
a
|
b
|
|
1547 | 1547 | # """ |
1548 | 1548 | # raise NotImplementedError |
1549 | 1549 | |
1550 | | def lift_to_precision(self, absprec): |
| 1550 | def lift_to_precision(self, absprec=None): |
1551 | 1551 | """ |
1552 | 1552 | Returns ``self``. |
1553 | 1553 | |
diff --git a/sage/rings/padics/padic_capped_absolute_element.pyx b/sage/rings/padics/padic_capped_absolute_element.pyx
a
|
b
|
|
964 | 964 | mpz_set(ans.value, self.value) |
965 | 965 | return ans |
966 | 966 | |
967 | | def lift_to_precision(self, absprec): |
| 967 | def lift_to_precision(self, absprec = None): |
968 | 968 | """ |
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. |
971 | 972 | |
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 | |
976 | 984 | EXAMPLES:: |
977 | | |
| 985 | |
978 | 986 | sage: R = ZpCA(17) |
979 | 987 | sage: R(-1,2).lift_to_precision(10) |
980 | 988 | 16 + 16*17 + O(17^10) |
… |
… |
|
984 | 992 | Traceback (most recent call last): |
985 | 993 | ... |
986 | 994 | PrecisionError: Precision higher than allowed by the precision cap. |
| 995 | sage: R(-1,2).lift_to_precision().precision_absolute() == R.precision_cap() |
| 996 | True |
987 | 997 | """ |
988 | 998 | cdef pAdicCappedAbsoluteElement ans |
989 | 999 | cdef unsigned long prec_cap |
990 | 1000 | cdef unsigned long dest_prec |
991 | 1001 | 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): |
993 | 1003 | 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.") |
998 | 1011 | else: |
999 | 1012 | dest_prec = mpz_get_ui((<Integer>absprec).value) |
1000 | 1013 | 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) |
1008 | 1021 | return ans |
1009 | 1022 | |
1010 | 1023 | def list(pAdicCappedAbsoluteElement self, lift_mode = 'simple'): |
diff --git a/sage/rings/padics/padic_capped_relative_element.pyx b/sage/rings/padics/padic_capped_relative_element.pyx
a
|
b
|
|
1864 | 1864 | mpz_mul(ans.value, self.unit, self.prime_pow.pow_mpz_t_tmp(self.ordp)[0]) |
1865 | 1865 | return ans |
1866 | 1866 | |
1867 | | def lift_to_precision(self, absprec): |
| 1867 | def lift_to_precision(self, absprec = None): |
1868 | 1868 | """ |
1869 | 1869 | 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. |
1872 | 1872 | |
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. |
1876 | 1885 | |
1877 | 1886 | EXAMPLES:: |
1878 | 1887 | |
… |
… |
|
1893 | 1902 | Traceback (most recent call last): |
1894 | 1903 | ... |
1895 | 1904 | PrecisionError: Precision higher than allowed by the precision cap. |
| 1905 | sage: c.lift_to_precision().precision_relative() == R.precision_cap() |
| 1906 | True |
1896 | 1907 | """ |
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): |
1898 | 1916 | absprec = Integer(absprec) |
1899 | 1917 | return self.lift_to_precision_c(mpz_get_si((<Integer>absprec).value)) |
1900 | 1918 | |
diff --git a/sage/rings/padics/padic_fixed_mod_element.pyx b/sage/rings/padics/padic_fixed_mod_element.pyx
a
|
b
|
|
821 | 821 | mpz_set(ans.value, self.value) |
822 | 822 | return ans |
823 | 823 | |
824 | | def lift_to_precision(self, absprec): |
| 824 | def lift_to_precision(self, absprec=None): |
825 | 825 | """ |
826 | 826 | Returns self. |
827 | 827 | |