# HG changeset patch
# User Robert Bradshaw <robertwb@math.washington.edu>
# Date 1202290095 28800
# Node ID 67574d49fcaa756f80775f15e150933a4c2f2ad5
# Parent 3c0f4cb8844ed4bf3c4bd8fdab2a97e4fac69e5e
padic capped absolute doctests
diff -r 3c0f4cb8844e -r 67574d49fcaa sage/rings/padics/padic_capped_absolute_element.pxd
|
a
|
b
|
cdef class pAdicCappedAbsoluteElement(pA |
| 15 | 15 | cdef ModuleElement _neg_c_impl(self) |
| 16 | 16 | cdef pAdicCappedAbsoluteElement _lshift_c(pAdicCappedAbsoluteElement self, long shift) |
| 17 | 17 | cdef pAdicCappedAbsoluteElement _rshift_c(pAdicCappedAbsoluteElement self, long shift) |
| 18 | | cdef Integer lift_c(pAdicCappedAbsoluteElement self) |
| 19 | 18 | cdef object teichmuller_list(pAdicCappedAbsoluteElement self) |
| 20 | | cdef pAdicCappedAbsoluteElement unit_part_c(pAdicCappedAbsoluteElement self) |
| | 19 | cpdef pAdicCappedAbsoluteElement unit_part(pAdicCappedAbsoluteElement self) |
| 21 | 20 | cdef long valuation_c(self) |
| 22 | | cdef val_unit_c(self) |
| | 21 | cpdef val_unit(self) |
| | 22 | cpdef Integer lift(self) |
diff -r 3c0f4cb8844e -r 67574d49fcaa sage/rings/padics/padic_capped_absolute_element.pyx
|
a
|
b
|
PariError = sage.libs.pari.gen.PariError |
| 47 | 47 | |
| 48 | 48 | cdef class pAdicCappedAbsoluteElement(pAdicBaseGenericElement): |
| 49 | 49 | def __init__(pAdicCappedAbsoluteElement self, parent, x, absprec=infinity, relprec = infinity, empty=False): |
| | 50 | """ |
| | 51 | EXAMPLES: |
| | 52 | sage: R = ZpCA(3, 5) |
| | 53 | sage: R(2) |
| | 54 | 2 + O(3^5) |
| | 55 | sage: R(2, absprec=2) |
| | 56 | 2 + O(3^2) |
| | 57 | sage: R(3, relprec=2) |
| | 58 | 3 + O(3^3) |
| | 59 | sage: R(Qp(3)(10)) |
| | 60 | 1 + 3^2 + O(3^5) |
| | 61 | sage: R(pari(6)) |
| | 62 | 2*3 + O(3^5) |
| | 63 | sage: R(pari(1/2)) |
| | 64 | 2 + 3 + 3^2 + 3^3 + 3^4 + O(3^5) |
| | 65 | sage: R(1/2) |
| | 66 | 2 + 3 + 3^2 + 3^3 + 3^4 + O(3^5) |
| | 67 | sage: R(mod(-1, 3^7)) |
| | 68 | 2 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + O(3^5) |
| | 69 | sage: R(mod(-1, 3^2)) |
| | 70 | 2 + 2*3 + O(3^2) |
| | 71 | """ |
| 50 | 72 | mpz_init(self.value) |
| 51 | 73 | pAdicBaseGenericElement.__init__(self,parent) |
| 52 | 74 | if empty: |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 264 | 286 | return x |
| 265 | 287 | |
| 266 | 288 | cpdef bint _is_inexact_zero(self): |
| | 289 | """ |
| | 290 | EXAMPLES: |
| | 291 | sage: R = ZpCA(7, 5) |
| | 292 | sage: R(7^5)._is_inexact_zero() |
| | 293 | True |
| | 294 | sage: R(0)._is_inexact_zero() |
| | 295 | True |
| | 296 | """ |
| 267 | 297 | return mpz_sgn(self.value) == 0 |
| 268 | 298 | |
| 269 | 299 | def __richcmp__(left, right, op): |
| 270 | 300 | return (<Element>left)._richcmp(right, op) |
| 271 | 301 | |
| 272 | 302 | def __invert__(self): |
| | 303 | """ |
| | 304 | EXAMPLES: |
| | 305 | sage: R = ZpCA(17) |
| | 306 | sage: ~R(-1) == R(-1) |
| | 307 | True |
| | 308 | sage: ~R(5) * 5 |
| | 309 | 1 + O(17^20) |
| | 310 | sage: ~R(5) |
| | 311 | 7 + 3*17 + 10*17^2 + 13*17^3 + 6*17^4 + 3*17^5 + 10*17^6 + 13*17^7 + 6*17^8 + 3*17^9 + 10*17^10 + 13*17^11 + 6*17^12 + 3*17^13 + 10*17^14 + 13*17^15 + 6*17^16 + 3*17^17 + 10*17^18 + 13*17^19 + O(17^20) |
| | 312 | """ |
| 273 | 313 | return self._invert_c_impl() |
| 274 | 314 | |
| 275 | 315 | cdef RingElement _invert_c_impl(self): |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 299 | 339 | return ans |
| 300 | 340 | |
| 301 | 341 | def __pow__(pAdicCappedAbsoluteElement self, right, dummy): |
| | 342 | """ |
| | 343 | EXAMPLES: |
| | 344 | sage: R = ZpCA(11, 5) |
| | 345 | sage: R(1/2)^5 |
| | 346 | 10 + 7*11 + 11^2 + 5*11^3 + 4*11^4 + O(11^5) |
| | 347 | sage: R(1/32) |
| | 348 | 10 + 7*11 + 11^2 + 5*11^3 + 4*11^4 + O(11^5) |
| | 349 | sage: R(1/2)^5 == R(1/32) |
| | 350 | True |
| | 351 | sage: R(3)^1000 |
| | 352 | 1 + 4*11^2 + 3*11^3 + 7*11^4 + O(11^5) |
| | 353 | """ |
| 302 | 354 | if not self and not right: |
| 303 | 355 | raise ArithmeticError, "0^0 is undefined." |
| 304 | | cdef Integer new, val, absprec |
| | 356 | cdef Integer new, absprec |
| | 357 | cdef long val |
| 305 | 358 | new = Integer(right) #Need to make sure that this works for p-adic exponents |
| 306 | 359 | val = self.valuation_c() |
| 307 | 360 | if (val > 0) and isinstance(right, pAdicBaseGenericElement): |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 329 | 382 | return ans |
| 330 | 383 | |
| 331 | 384 | cdef ModuleElement _add_c_impl(self, ModuleElement _right): |
| | 385 | """ |
| | 386 | EXAMPLES: |
| | 387 | sage: R = ZpCA(13, 4) |
| | 388 | sage: R(2) + R(3) |
| | 389 | 5 + O(13^4) |
| | 390 | sage: R(12) + R(1) |
| | 391 | 13 + O(13^4) |
| | 392 | """ |
| 332 | 393 | cdef pAdicCappedAbsoluteElement ans |
| 333 | 394 | cdef pAdicCappedAbsoluteElement right = <pAdicCappedAbsoluteElement> _right |
| 334 | 395 | ans = self._new_c() |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 487 | 548 | return ans |
| 488 | 549 | |
| 489 | 550 | cdef ModuleElement _sub_c_impl(self, ModuleElement _right): |
| | 551 | """ |
| | 552 | EXAMPLES: |
| | 553 | sage: R = ZpCA(13, 4) |
| | 554 | sage: R(10) - R(10) |
| | 555 | O(13^4) |
| | 556 | sage: R(10) - R(11) |
| | 557 | 12 + 12*13 + 12*13^2 + 12*13^3 + O(13^4) |
| | 558 | """ |
| 490 | 559 | cdef pAdicCappedAbsoluteElement ans |
| 491 | 560 | cdef pAdicCappedAbsoluteElement right = <pAdicCappedAbsoluteElement> _right |
| 492 | 561 | ans = self._new_c() |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 560 | 629 | mpz_set(ans.value, self.value) |
| 561 | 630 | return ans |
| 562 | 631 | |
| 563 | | def exp_artin_hasse(self): |
| 564 | | raise NotImplementedError |
| 565 | | |
| 566 | | def gamma(self): |
| 567 | | raise NotImplementedError |
| 568 | | |
| 569 | 632 | def is_zero(self, absprec = None): |
| 570 | 633 | r""" |
| 571 | 634 | Returns whether self is zero modulo $p^{\mbox{absprec}}$. |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 576 | 639 | OUTPUT: |
| 577 | 640 | boolean -- whether self is zero |
| 578 | 641 | |
| | 642 | EXAMPLES: |
| | 643 | sage: R = ZpCA(17, 6) |
| | 644 | sage: R(0).is_zero() |
| | 645 | True |
| | 646 | sage: R(17^6).is_zero() |
| | 647 | True |
| | 648 | sage: R(17^2).is_zero(absprec=2) |
| | 649 | True |
| 579 | 650 | """ |
| 580 | 651 | if absprec is None: |
| 581 | 652 | return mpz_sgn(self.value) == 0 |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 598 | 669 | mpz_clear(tmp) |
| 599 | 670 | return False |
| 600 | 671 | |
| 601 | | def is_equal_to(self, right, absprec = None): #assumes they have the same parent |
| | 672 | def is_equal_to(pAdicCappedAbsoluteElement self, pAdicCappedAbsoluteElement right, absprec = None): #assumes they have the same parent |
| 602 | 673 | r""" |
| 603 | 674 | Returns whether self is equal to right modulo $p^{\mbox{absprec}}$. |
| 604 | 675 | |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 609 | 680 | OUTPUT: |
| 610 | 681 | boolean -- whether self is equal to right |
| 611 | 682 | |
| | 683 | EXAMPLES: |
| | 684 | sage: R = ZpCA(2, 6) |
| | 685 | sage: R(13).is_equal_to(R(13)) |
| | 686 | True |
| | 687 | sage: R(13).is_equal_to(R(13+2^10)) |
| | 688 | True |
| | 689 | sage: R(13).is_equal_to(R(17), 2) |
| | 690 | True |
| | 691 | sage: R(13).is_equal_to(R(17), 5) |
| | 692 | False |
| 612 | 693 | """ |
| 613 | 694 | cdef unsigned long aprec |
| 614 | 695 | if absprec is None: |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 631 | 712 | mpz_init(tmp1) |
| 632 | 713 | mpz_init(tmp2) |
| 633 | 714 | mpz_mod(tmp1, self.value, self.prime_pow.pow_mpz_t_tmp(aprec)[0]) |
| 634 | | mpz_mod(tmp2, (<pAdicCappedAbsoluteElement>right).value, self.prime_pow.pow_mpz_t_tmp(aprec)[0]) |
| | 715 | mpz_mod(tmp2, (right).value, self.prime_pow.pow_mpz_t_tmp(aprec)[0]) |
| 635 | 716 | if mpz_cmp(tmp1, tmp2) == 0: |
| 636 | 717 | mpz_clear(tmp1) |
| 637 | 718 | mpz_clear(tmp2) |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 641 | 722 | mpz_clear(tmp2) |
| 642 | 723 | return False |
| 643 | 724 | |
| 644 | | def lift(self): |
| | 725 | cpdef Integer lift(self): |
| 645 | 726 | """ |
| 646 | 727 | Returns an integer congruent to this p-adic element modulo p^self.absprec(). |
| | 728 | |
| | 729 | EXAMPLES: |
| | 730 | sage: R = ZpCA(3) |
| | 731 | sage: R(10).lift() |
| | 732 | 10 |
| | 733 | sage: R(-1).lift() |
| | 734 | 3486784400 |
| 647 | 735 | """ |
| 648 | | return self.lift_c() |
| 649 | | |
| 650 | | cdef Integer lift_c(pAdicCappedAbsoluteElement self): |
| 651 | 736 | cdef Integer ans |
| 652 | 737 | ans = PY_NEW(Integer) |
| 653 | 738 | mpz_set(ans.value, self.value) |
| 654 | 739 | return ans |
| 655 | 740 | |
| 656 | 741 | def lift_to_precision(self, absprec): |
| | 742 | """ |
| | 743 | Returns a p-adic integer congruent to this p-adic element modulo p^absprec |
| | 744 | with precision at least absprec. |
| | 745 | |
| | 746 | EXAMPLES: |
| | 747 | sage: R = ZpCA(17, 6) |
| | 748 | sage: (1+O(2^5)).lift_to_precision(10) |
| | 749 | 1 + O(2^10) |
| | 750 | sage: (1+O(2^15)).lift_to_precision(10) |
| | 751 | 1 + O(2^15) |
| | 752 | sage: (1+O(2^15)).lift_to_precision(30) |
| | 753 | 1 + O(2^30) |
| | 754 | """ |
| 657 | 755 | cdef pAdicCappedAbsoluteElement ans |
| 658 | 756 | cdef unsigned long prec_cap |
| 659 | 757 | cdef unsigned long dest_prec |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 706 | 804 | raise ValueError |
| 707 | 805 | |
| 708 | 806 | cdef object teichmuller_list(pAdicCappedAbsoluteElement self): |
| | 807 | |
| 709 | 808 | # May eventually want to add a dict to store teichmuller lifts already seen, if p small enough |
| 710 | 809 | cdef unsigned long curpower |
| 711 | 810 | cdef mpz_t tmp, tmp2 |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 735 | 834 | self.teichmuller_set_c(self.value, tmp) |
| 736 | 835 | mpz_clear(tmp) |
| 737 | 836 | |
| 738 | | def log_artin_hasse(self): |
| 739 | | raise NotImplementedError |
| 740 | | |
| 741 | 837 | def multiplicative_order(self): |
| 742 | 838 | r""" |
| 743 | 839 | Returns the minimum possible multiplicative order of self. |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 746 | 842 | self -- a p-adic element |
| 747 | 843 | OUTPUT: |
| 748 | 844 | integer -- the multiplicative order of self. This is the minimum multiplicative order of all elements of Z_p lifting self to infinite precision. |
| | 845 | |
| | 846 | EXAMPLES: |
| | 847 | sage: R = ZpCA(7, 6) |
| | 848 | sage: R(1/3) |
| | 849 | 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + 4*7^5 + O(7^6) |
| | 850 | sage: R(1/3).multiplicative_order() |
| | 851 | +Infinity |
| | 852 | sage: R(7).multiplicative_order() |
| | 853 | +Infinity |
| | 854 | sage: R(1).multiplicative_order() |
| | 855 | 1 |
| | 856 | sage: R(-1).multiplicative_order() |
| | 857 | 2 |
| | 858 | sage: R.teichmuller(3).multiplicative_order() |
| | 859 | 6 |
| 749 | 860 | """ |
| 750 | | cdef mpz_t tmp |
| | 861 | cdef mpz_t ppow_minus_one |
| 751 | 862 | cdef Integer ans |
| 752 | 863 | if mpz_divisible_p(self.value, self.prime_pow.prime.value): |
| 753 | 864 | return infinity |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 755 | 866 | ans = PY_NEW(Integer) |
| 756 | 867 | mpz_set_ui(ans.value, 1) |
| 757 | 868 | return ans |
| 758 | | mpz_init(tmp) |
| 759 | | mpz_sub_ui(tmp, self.prime_pow.pow_mpz_t_tmp(self.absprec)[0], 1) |
| | 869 | mpz_init(ppow_minus_one) |
| | 870 | mpz_sub_ui(ppow_minus_one, self.prime_pow.pow_mpz_t_tmp(self.absprec)[0], 1) |
| 760 | 871 | if mpz_cmp(self.value, tmp) == 0: |
| 761 | 872 | ans = PY_NEW(Integer) |
| 762 | 873 | mpz_set_ui(ans.value, 2) |
| 763 | | mpz_clear(tmp) |
| | 874 | mpz_clear(ppow_minus_one) |
| 764 | 875 | return ans |
| 765 | 876 | # check if self is an approximation to a teichmuller lift: |
| 766 | | mpz_powm(tmp, self.value, self.prime_pow.prime.value, self.prime_pow.pow_mpz_t_tmp(self.absprec)[0]) |
| 767 | | if mpz_cmp(tmp, self.value) == 0: |
| 768 | | mpz_clear(tmp) |
| | 877 | mpz_powm(ppow_minus_one, self.value, self.prime_pow.prime.value, self.prime_pow.pow_mpz_t_tmp(self.absprec)[0]) |
| | 878 | if mpz_cmp(ppow_minus_one, self.value) == 0: |
| | 879 | mpz_clear(ppow_minus_one) |
| 769 | 880 | return self.residue(1).multiplicative_order() |
| 770 | 881 | else: |
| 771 | | mpz_clear(tmp) |
| | 882 | mpz_clear(ppow_minus_one) |
| 772 | 883 | return infinity |
| 773 | 884 | |
| 774 | 885 | def padded_list(self, n, list_mode = 'simple'): |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 895 | 1006 | # except PariError: |
| 896 | 1007 | # raise ValueError, "element is not a square" # should eventually change to return an element of an extension field |
| 897 | 1008 | |
| 898 | | def unit_part(self): |
| | 1009 | cpdef pAdicCappedAbsoluteElement unit_part(self): |
| 899 | 1010 | r""" |
| 900 | 1011 | Returns the unit part of self. |
| 901 | 1012 | |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 911 | 1022 | sage: type(a) |
| 912 | 1023 | <type 'sage.rings.padics.padic_capped_absolute_element.pAdicCappedAbsoluteElement'> |
| 913 | 1024 | """ |
| 914 | | return self.unit_part_c() |
| 915 | | |
| 916 | | cdef pAdicCappedAbsoluteElement unit_part_c(pAdicCappedAbsoluteElement self): |
| 917 | 1025 | cdef pAdicCappedAbsoluteElement ans |
| 918 | 1026 | cdef unsigned long v |
| 919 | 1027 | if mpz_sgn(self.value) == 0: |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 955 | 1063 | mpz_clear(tmp) |
| 956 | 1064 | return ans |
| 957 | 1065 | |
| 958 | | def val_unit(self): |
| | 1066 | cpdef val_unit(self): |
| 959 | 1067 | """ |
| 960 | 1068 | Returns a 2-tuple, the first element set to the valuation of self, and the second to the unit part of self. |
| 961 | 1069 | |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 969 | 1077 | sage: b.val_unit() |
| 970 | 1078 | (6, O(5^0)) |
| 971 | 1079 | """ |
| 972 | | return self.val_unit_c() |
| 973 | | |
| 974 | | cdef val_unit_c(self): |
| 975 | 1080 | cdef pAdicCappedAbsoluteElement unit |
| 976 | 1081 | cdef Integer val |
| 977 | 1082 | cdef unsigned long v |
| … |
… |
cdef class pAdicCappedAbsoluteElement(pA |
| 993 | 1098 | return (val, self) |
| 994 | 1099 | |
| 995 | 1100 | def __hash__(self): |
| 996 | | return hash(self.lift_c()) |
| | 1101 | """ |
| | 1102 | EXAMPLES: |
| | 1103 | sage: R = ZpCA(11, 5) |
| | 1104 | sage: hash(R(3)) == hash(3) |
| | 1105 | True |
| | 1106 | """ |
| | 1107 | return hash(self.lift()) |
| 997 | 1108 | |
| 998 | 1109 | def make_pAdicCappedAbsoluteElement(parent, x, absprec): |
| 999 | 1110 | return parent(x, absprec=absprec) |