Ticket #1963: padic_capped_absolute_element.diff

File padic_capped_absolute_element.diff, 13.4 KB (added by robertwb, 5 years ago)
  • sage/rings/padics/padic_capped_absolute_element.pxd

    # 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 
    1515    cdef ModuleElement _neg_c_impl(self) 
    1616    cdef pAdicCappedAbsoluteElement _lshift_c(pAdicCappedAbsoluteElement self, long shift) 
    1717    cdef pAdicCappedAbsoluteElement _rshift_c(pAdicCappedAbsoluteElement self, long shift) 
    18     cdef Integer lift_c(pAdicCappedAbsoluteElement self) 
    1918    cdef object teichmuller_list(pAdicCappedAbsoluteElement self) 
    20     cdef pAdicCappedAbsoluteElement unit_part_c(pAdicCappedAbsoluteElement self) 
     19    cpdef pAdicCappedAbsoluteElement unit_part(pAdicCappedAbsoluteElement self) 
    2120    cdef long valuation_c(self) 
    22     cdef val_unit_c(self) 
     21    cpdef val_unit(self) 
     22    cpdef Integer lift(self) 
  • sage/rings/padics/padic_capped_absolute_element.pyx

    diff -r 3c0f4cb8844e -r 67574d49fcaa sage/rings/padics/padic_capped_absolute_element.pyx
    a b PariError = sage.libs.pari.gen.PariError 
    4747 
    4848cdef class pAdicCappedAbsoluteElement(pAdicBaseGenericElement): 
    4949    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        """ 
    5072        mpz_init(self.value) 
    5173        pAdicBaseGenericElement.__init__(self,parent) 
    5274        if empty: 
    cdef class pAdicCappedAbsoluteElement(pA 
    264286        return x 
    265287 
    266288    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        """ 
    267297        return mpz_sgn(self.value) == 0 
    268298 
    269299    def __richcmp__(left, right, op): 
    270300        return (<Element>left)._richcmp(right, op) 
    271301 
    272302    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        """ 
    273313        return self._invert_c_impl() 
    274314 
    275315    cdef RingElement _invert_c_impl(self): 
    cdef class pAdicCappedAbsoluteElement(pA 
    299339        return ans 
    300340 
    301341    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        """ 
    302354        if not self and not right: 
    303355            raise ArithmeticError, "0^0 is undefined." 
    304         cdef Integer new, val, absprec 
     356        cdef Integer new, absprec 
     357        cdef long val 
    305358        new = Integer(right) #Need to make sure that this works for p-adic exponents 
    306359        val = self.valuation_c() 
    307360        if (val > 0) and isinstance(right, pAdicBaseGenericElement): 
    cdef class pAdicCappedAbsoluteElement(pA 
    329382        return ans 
    330383 
    331384    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        """ 
    332393        cdef pAdicCappedAbsoluteElement ans 
    333394        cdef pAdicCappedAbsoluteElement right = <pAdicCappedAbsoluteElement> _right 
    334395        ans = self._new_c() 
    cdef class pAdicCappedAbsoluteElement(pA 
    487548        return ans 
    488549 
    489550    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        """ 
    490559        cdef pAdicCappedAbsoluteElement ans 
    491560        cdef pAdicCappedAbsoluteElement right = <pAdicCappedAbsoluteElement> _right 
    492561        ans = self._new_c() 
    cdef class pAdicCappedAbsoluteElement(pA 
    560629        mpz_set(ans.value, self.value) 
    561630        return ans 
    562631 
    563     def exp_artin_hasse(self): 
    564         raise NotImplementedError                 
    565  
    566     def gamma(self): 
    567         raise NotImplementedError                         
    568  
    569632    def is_zero(self, absprec = None): 
    570633        r""" 
    571634        Returns whether self is zero modulo $p^{\mbox{absprec}}$. 
    cdef class pAdicCappedAbsoluteElement(pA 
    576639        OUTPUT: 
    577640            boolean -- whether self is zero 
    578641           
     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 
    579650        """ 
    580651        if absprec is None: 
    581652            return mpz_sgn(self.value) == 0 
    cdef class pAdicCappedAbsoluteElement(pA 
    598669            mpz_clear(tmp) 
    599670            return False 
    600671 
    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 
    602673        r""" 
    603674        Returns whether self is equal to right modulo $p^{\mbox{absprec}}$. 
    604675 
    cdef class pAdicCappedAbsoluteElement(pA 
    609680        OUTPUT: 
    610681            boolean -- whether self is equal to right 
    611682           
     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 
    612693        """ 
    613694        cdef unsigned long aprec 
    614695        if absprec is None: 
    cdef class pAdicCappedAbsoluteElement(pA 
    631712        mpz_init(tmp1) 
    632713        mpz_init(tmp2) 
    633714        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]) 
    635716        if mpz_cmp(tmp1, tmp2) == 0: 
    636717            mpz_clear(tmp1) 
    637718            mpz_clear(tmp2) 
    cdef class pAdicCappedAbsoluteElement(pA 
    641722            mpz_clear(tmp2) 
    642723            return False 
    643724 
    644     def lift(self): 
     725    cpdef Integer lift(self): 
    645726        """ 
    646727        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 
    647735        """ 
    648         return self.lift_c() 
    649  
    650     cdef Integer lift_c(pAdicCappedAbsoluteElement self): 
    651736        cdef Integer ans 
    652737        ans = PY_NEW(Integer) 
    653738        mpz_set(ans.value, self.value) 
    654739        return ans 
    655740 
    656741    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        """ 
    657755        cdef pAdicCappedAbsoluteElement ans 
    658756        cdef unsigned long prec_cap 
    659757        cdef unsigned long dest_prec 
    cdef class pAdicCappedAbsoluteElement(pA 
    706804            raise ValueError 
    707805 
    708806    cdef object teichmuller_list(pAdicCappedAbsoluteElement self): 
     807         
    709808        # May eventually want to add a dict to store teichmuller lifts already seen, if p small enough 
    710809        cdef unsigned long curpower 
    711810        cdef mpz_t tmp, tmp2 
    cdef class pAdicCappedAbsoluteElement(pA 
    735834        self.teichmuller_set_c(self.value, tmp) 
    736835        mpz_clear(tmp) 
    737836 
    738     def log_artin_hasse(self): 
    739         raise NotImplementedError                                 
    740  
    741837    def multiplicative_order(self): 
    742838        r""" 
    743839        Returns the minimum possible multiplicative order of self. 
    cdef class pAdicCappedAbsoluteElement(pA 
    746842            self -- a p-adic element 
    747843        OUTPUT: 
    748844            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 
    749860        """ 
    750         cdef mpz_t tmp 
     861        cdef mpz_t ppow_minus_one 
    751862        cdef Integer ans 
    752863        if mpz_divisible_p(self.value, self.prime_pow.prime.value): 
    753864            return infinity 
    cdef class pAdicCappedAbsoluteElement(pA 
    755866            ans = PY_NEW(Integer) 
    756867            mpz_set_ui(ans.value, 1) 
    757868            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) 
    760871        if mpz_cmp(self.value, tmp) == 0: 
    761872            ans = PY_NEW(Integer) 
    762873            mpz_set_ui(ans.value, 2) 
    763             mpz_clear(tmp) 
     874            mpz_clear(ppow_minus_one) 
    764875            return ans 
    765876        # 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) 
    769880            return self.residue(1).multiplicative_order() 
    770881        else: 
    771             mpz_clear(tmp) 
     882            mpz_clear(ppow_minus_one) 
    772883            return infinity 
    773884 
    774885    def padded_list(self, n, list_mode = 'simple'): 
    cdef class pAdicCappedAbsoluteElement(pA 
    8951006    #    except PariError: 
    8961007    #        raise ValueError, "element is not a square" # should eventually change to return an element of an extension field 
    8971008 
    898     def unit_part(self): 
     1009    cpdef pAdicCappedAbsoluteElement unit_part(self): 
    8991010        r""" 
    9001011        Returns the unit part of self. 
    9011012 
    cdef class pAdicCappedAbsoluteElement(pA 
    9111022            sage: type(a) 
    9121023                <type 'sage.rings.padics.padic_capped_absolute_element.pAdicCappedAbsoluteElement'> 
    9131024        """ 
    914         return self.unit_part_c() 
    915  
    916     cdef pAdicCappedAbsoluteElement unit_part_c(pAdicCappedAbsoluteElement self): 
    9171025        cdef pAdicCappedAbsoluteElement ans 
    9181026        cdef unsigned long v 
    9191027        if mpz_sgn(self.value) == 0: 
    cdef class pAdicCappedAbsoluteElement(pA 
    9551063        mpz_clear(tmp) 
    9561064        return ans 
    9571065 
    958     def val_unit(self): 
     1066    cpdef val_unit(self): 
    9591067        """ 
    9601068        Returns a 2-tuple, the first element set to the valuation of self, and the second to the unit part of self. 
    9611069 
    cdef class pAdicCappedAbsoluteElement(pA 
    9691077        sage: b.val_unit() 
    9701078        (6, O(5^0)) 
    9711079        """ 
    972         return self.val_unit_c() 
    973  
    974     cdef val_unit_c(self): 
    9751080        cdef pAdicCappedAbsoluteElement unit 
    9761081        cdef Integer val 
    9771082        cdef unsigned long v 
    cdef class pAdicCappedAbsoluteElement(pA 
    9931098            return (val, self) 
    9941099 
    9951100    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()) 
    9971108 
    9981109def make_pAdicCappedAbsoluteElement(parent, x, absprec): 
    9991110    return parent(x, absprec=absprec)