Ticket #10596: trac_10596_remove_trailing_whitespaces.patch

File trac_10596_remove_trailing_whitespaces.patch, 19.2 KB (added by aapitzsch, 9 years ago)
  • sage/rings/integer.pyx

    # HG changeset patch
    # User André Apitzsch <andre.apitzsch@st.ovgu.de>
    # Date 1322318859 -3600
    # Node ID dc1960b07588c78aab331fc674dd7c90adb8d1f4
    # Parent  8040305b41cbf03a9c8ef3393883cccfc0b6da9f
    trac 10596: integer.pyx remove trailing whitespaces
    
    diff --git a/sage/rings/integer.pyx b/sage/rings/integer.pyx
    a b  
    217217
    218218cdef _digits_naive(mpz_t v,l,int offset,Integer base,digits):
    219219    """
    220     This method fills in digit entries in the list, l, using the most 
     220    This method fills in digit entries in the list, l, using the most
    221221    basic digit algorithm -- repeat division by base.
    222222
    223223    INPUT:
     
    339339cdef Integer zero = the_integer_ring._zero_element
    340340cdef Integer one = the_integer_ring._one_element
    341341
    342 # The documentation for the ispseudoprime() function in the PARI 
    343 # manual states that its result is always prime up to this 10^13. 
     342# The documentation for the ispseudoprime() function in the PARI
     343# manual states that its result is always prime up to this 10^13.
    344344cdef mpz_t PARI_PSEUDOPRIME_LIMIT
    345345mpz_init(PARI_PSEUDOPRIME_LIMIT)
    346346mpz_set_str(PARI_PSEUDOPRIME_LIMIT, "10000000000000", 10)
     
    596596            sage: ZZ(pari("Mod(x, x^3+x+1)"))   # Note error message refers to lifted element
    597597            Traceback (most recent call last):
    598598            ...
    599             TypeError: Unable to coerce PARI x to an Integer       
     599            TypeError: Unable to coerce PARI x to an Integer
    600600        """
    601601        # TODO: All the code below should somehow be in an external
    602602        # cdef'd function.  Then e.g., if a matrix or vector or
     
    795795            sage: n.__xor__(m)
    796796            1
    797797        """
    798         if PY_TYPE_CHECK(x, Integer) and PY_TYPE_CHECK(y, Integer):       
     798        if PY_TYPE_CHECK(x, Integer) and PY_TYPE_CHECK(y, Integer):
    799799            return (<Integer>x)._xor(y)
    800800        return bin_op(x, y, operator.xor)
    801        
     801
    802802    def __richcmp__(left, right, int op):
    803803        """
    804804        cmp for integers
     
    10251025        ::
    10261026       
    10271027            sage: big = 10^5000000
    1028             sage: s = big.str()                 # long time (> 20 seconds)
    1029             sage: len(s)                        # long time (depends on above defn of s)
     1028            sage: s = big.str()       # long time (> 20 seconds)
     1029            sage: len(s)              # long time (depends on above defn of s)
    10301030            5000001
    1031             sage: s[:10]                        # long time (depends on above defn of s)
     1031            sage: s[:10]              # long time (depends on above defn of s)
    10321032            '1000000000'
    10331033        """
    10341034        if base < 2 or base > 36:
     
    11191119            sage: print hex(long(16938402384092843092843098243))
    11201120            0x36bb1e3929d1a8fe2802f083L
    11211121        """
    1122         return self.str(16) 
     1122        return self.str(16)
    11231123       
    11241124    def __oct__(self):
    11251125        r"""
     
    19201920           self is not an n'th power.
    19211921       
    19221922        OUTPUT:
    1923        
     1923
    19241924        If truncate_mode is 0 (default), then returns the exact n'th root
    19251925        if self is an n'th power, or raises a ValueError if it is not.
    19261926       
     
    22022202        r"""
    22032203        Returns the largest integer `k` such that `m^k \leq \text{self}`,
    22042204        i.e., the floor of `\log_m(\text{self})`.
    2205        
     2205
    22062206        This is guaranteed to return the correct answer even when the usual
    22072207        log function doesn't have sufficient precision.
    22082208       
     
    22942294        if mpz_divisible_2exp_p(_m.value,m_log2):
    22952295            # Here, m is a power of 2 and the correct answer is found
    22962296            # by a log 2 approximation.
    2297             guess = n_log2/m_log2 # truncating division
     2297            guess = n_log2/m_log2  # truncating division
    22982298        elif n_log2/(m_log2+1) == n_log2/m_log2:
    22992299            # In this case, we have an upper bound and lower bound which
    23002300            # give the same answer, thus, the correct answer.
    23012301            guess = n_log2/m_log2
    2302         elif m_log2 < 8: # i.e. m<256
     2302        elif m_log2 < 8:  # i.e. m<256
    23032303            # if the base m is at most 256, we can use mpz_sizeinbase
    23042304            # to get the following guess which is either the exact
    23052305            # log, or 1+ the exact log
     
    23082308            # we've already excluded the case when m is an exact power of 2
    23092309
    23102310            if n_log2/m_log2 > 8000:
    2311                 # If we have a very large number of digits, it can be a nice 
     2311                # If we have a very large number of digits, it can be a nice
    23122312                # shortcut to test the guess using interval arithmetic.
    23132313                # (suggested by David Harvey and Carl Witty)
    23142314                # "for randomly distributed integers, the chance of this
     
    23212321                    guess_filled = 1
    23222322                    guess =  guess - 1
    23232323            if not guess_filled:
    2324                 # At this point, either 
     2324                # At this point, either
    23252325                #  1)  self is close enough to a perfect power of m that we
    23262326                #      need an exact comparison, or
    23272327                #  2)  the numbers are small enough that converting to the
     
    25852585        prev_c = ptr + (2*divisor_count)
    25862586
    25872587        # These are used to keep track of whether or not we are able to
    2588         # perform the operations in machine words. A factor of two safety 
    2589         # margin is added to cover any floating-point rounding issues. 
     2588        # perform the operations in machine words. A factor of two safety
     2589        # margin is added to cover any floating-point rounding issues.
    25902590        cdef bint fits_c = True
    25912591        cdef double cur_max = 1
    25922592        cdef double fits_max = 2.0**(sizeof(long long)*8-2)
     
    26812681            sage_free(ptr)
    26822682       
    26832683        return sorted
    2684        
    2685                          
     2684
     2685
    26862686    def __pos__(self):
    26872687        """
    26882688        EXAMPLES::
     
    30823082
    30833083    def trial_division(self, long bound=LONG_MAX):
    30843084        """
    3085         Return smallest prime divisor of self up to bound, 
     3085        Return smallest prime divisor of self up to bound,
    30863086        or abs(self) if no such divisor is found.
    30873087
    30883088        INPUT:
     
    31213121            sage: (-n).trial_division(bound=10^4)
    31223122            1000030000000000000000000000000000000012100363
    31233123            sage: (-n).trial_division()
    3124             100003           
     3124            100003
    31253125            sage: n = 2 * next_prime(10^40); n.trial_division()
    31263126            2
    31273127            sage: n = 3 * next_prime(10^40); n.trial_division()
    31283128            3
    3129             sage: n = 5 * next_prime(10^40); n.trial_division()           
     3129            sage: n = 5 * next_prime(10^40); n.trial_division()
    31303130            5
    31313131            sage: n = 2 * next_prime(10^4); n.trial_division()
    31323132            2
    31333133            sage: n = 3 * next_prime(10^4); n.trial_division()
    31343134            3
    3135             sage: n = 5 * next_prime(10^4); n.trial_division()           
     3135            sage: n = 5 * next_prime(10^4); n.trial_division()
    31363136            5
    31373137        """
    31383138        if bound <= 0:
     
    31913191            sig_off()
    31923192            return x
    31933193
    3194     def factor(self, algorithm='pari', proof=None, limit=None, int_=False, 
     3194    def factor(self, algorithm='pari', proof=None, limit=None, int_=False,
    31953195                     verbose=0):
    31963196        """
    31973197        Return the prime factorization of this integer as a list of pairs
     
    32593259            mpz_set_si(unit.value, -1)
    32603260
    32613261        if mpz_cmpabs_ui(n.value, 1) == 0:
    3262             return IntegerFactorization([], unit=unit, unsafe=True, 
     3262            return IntegerFactorization([], unit=unit, unsafe=True,
    32633263                                            sort=False, simplify=False)
    32643264
    32653265        if limit is not None:
     
    32733273            z_factor(&f, mpz_get_ui(n.value), proof)
    32743274            F = [(Integer(f.p[i]), int(f.exp[i])) for i from 0 <= i < f.num]
    32753275            F.sort()
    3276             return IntegerFactorization(F, unit=unit, unsafe=True, 
     3276            return IntegerFactorization(F, unit=unit, unsafe=True,
    32773277                                           sort=False, simplify=False)
    32783278
    32793279        if mpz_sizeinbase(n.value, 2) < 40:
     
    34213421
    34223422        - David Roe (2007-03-31)
    34233423        """
    3424         cdef Integer v, u       
     3424        cdef Integer v, u
    34253425        if mpz_cmp_ui(p.value, 2) < 0:
    34263426            raise ValueError, "You can only compute the valuation with respect to a integer larger than 1."
    34273427        if self == 0:
     
    35093509        and in Sage 4.6 this special case was not handled at all, eventually
    35103510        propagating a TypeError.  The caller should not rely on the behaviour
    35113511        in case self is 0.
    3512        
     3512
    35133513        EXAMPLES::
    35143514       
    35153515            sage: odd_part(5)
     
    37433743        cdef int tip = 0
    37443744        for i from 1 <= i <= n//k:
    37453745            mpz_set_ui(sub_prods[tip], k*i + residue)
    3746             # for the i-th terms we use the bits of i to calculate how many 
     3746            # for the i-th terms we use the bits of i to calculate how many
    37473747            # times we need to multiply "up" the stack of sub-products
    37483748            for j from 0 <= j < 32:
    37493749                if i & (1 << j):
     
    37653765        sage_free(sub_prods)
    37663766
    37673767        return z
    3768 
     3768       
    37693769    def gamma(self):
    37703770        r"""
    37713771        The gamma function on integers is the factorial function (shifted by
     
    38163816   
    38173817    def real(self):
    38183818        """
    3819         Returns the real part of self, which is self. 
     3819        Returns the real part of self, which is self.
    38203820       
    38213821        EXAMPLES::
    38223822       
     
    39753975                if mpz_popcount(nabs) == 1: # |n| = 2^k for k >= 2.  We special case this for speed
    39763976                    mpz_init(sabs)
    39773977                    mpz_abs(sabs, self.value)
    3978                     if mpz_popcount(sabs) == 1: # |self| = 2^L for some L >= 0. 
     3978                    if mpz_popcount(sabs) == 1: # |self| = 2^L for some L >= 0.
    39793979                        b = mpz_scan1(sabs, 0) # the bit that self is set at
    39803980                        c = mpz_scan1(nabs, 0) # the bit that n is set at
    39813981                        # Having obtained b and c, we're done with nabs and sabs (on this branch anyway)
    39823982                        mpz_clear(nabs)
    3983                         mpz_clear(sabs) 
     3983                        mpz_clear(sabs)
    39843984                        if b % c == 0: # Now we know that |self| is a power of |n|
    39853985                            b = (b // c) % 2 # Whether b // c is even or odd determines whether (-2^c)^(b // c) is positive or negative
    39863986                            a = mpz_cmp_ui(self.value, 0)
     
    43314331       
    43324332        EXAMPLES::
    43334333       
    4334             sage: 3._bnfisnorm(QuadraticField(-1, 'i')) 
     4334            sage: 3._bnfisnorm(QuadraticField(-1, 'i'))
    43354335            (1, 3)
    43364336            sage: 7._bnfisnorm(CyclotomicField(7))
    43374337            (-zeta7 + 1, 1)            # 64-bit
     
    44074407
    44084408    def radical(self, *args, **kwds):
    44094409        r"""
    4410         Return the product of the prime divisors of self.  Computing
     4410        Return the product of the prime divisors of self. Computing
    44114411        the radical of zero gives an error.
    44124412       
    44134413        EXAMPLES::
     
    45164516            sage: (100).next_probable_prime()
    45174517            101
    45184518            sage: (2^512).next_probable_prime()
    4519             13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171       
     4519            13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171
    45204520            sage: 0.next_probable_prime()
    45214521            2
    45224522            sage: 126.next_probable_prime()
     
    49414941           compute minimal cofactors (see below)
    49424942       
    49434943        OUTPUT:
    4944        
     4944
    49454945        A triple (g, s, t), where `g` is the non-negative gcd of self
    49464946        and `n`, and `s` and `t` are cofactors satisfying the Bezout identity
    49474947       
     
    50935093            sage: n._shift_helper(1, -1)
    50945094            617
    50955095            sage: n._shift_helper(100, 1)
    5096             1564280840681635081446931755433984           
     5096            1564280840681635081446931755433984
    50975097            sage: n._shift_helper(100, -1)
    50985098            0
    50995099            sage: n._shift_helper(-100, 1)
    51005100            0
    51015101            sage: n._shift_helper(-100, -1)
    5102             1564280840681635081446931755433984           
     5102            1564280840681635081446931755433984
    51035103        """
    51045104        cdef long n
    51055105
     
    52115211    def __and__(x, y):
    52125212        """
    52135213        Return the bitwise and two integers.
    5214        
     5214
    52155215        EXAMPLES::
    5216        
     5216
    52175217            sage: n = Integer(6);  m = Integer(2)
    52185218            sage: n & m
    52195219            2
     
    52325232    def __or__(x, y):
    52335233        """
    52345234        Return the bitwise or of the integers x and y.
    5235        
     5235
    52365236        EXAMPLES::
    5237        
     5237
    52385238            sage: n = 8; m = 4
    52395239            sage: n.__or__(m)
    52405240            12
     
    52465246    def __invert__(self):
    52475247        """
    52485248        Return the multiplicative inverse of self, as a rational number.
    5249        
     5249
    52505250        EXAMPLE::
    5251        
     5251
    52525252            sage: n = 10
    52535253            sage: 1/n
    52545254            1/10
     
    52565256            1/10
    52575257        """
    52585258        return one / self
    5259        
     5259
    52605260    def inverse_of_unit(self):
    52615261        """
    52625262        Return inverse of self if self is a unit in the integers, i.e.,
     
    54715471
    54725472        INPUT:
    54735473
    5474             - ``m`` -- an integer 
     5474            - ``m`` -- an integer
    54755475
    54765476            - ``algorithm`` -- ``'mpir'`` (default) or ``'pari'``; ``'mpir'`` is
    54775477              faster for small ``m``, and ``'pari'`` tends to be faster for
     
    56805680
    56815681############### INTEGER CREATION CODE #####################
    56825682
    5683 # We need a couple of internal GMP datatypes. 
     5683# We need a couple of internal GMP datatypes.
    56845684
    56855685# This may be potentially very dangerous as it reaches
    56865686# deeply into the internal structure of GMP which may not
    56875687# be consistent across future versions of GMP.
    5688 # See extensive note in the fast_tp_new() function below. 
    5689 
    5690 include "../ext/python_rich_object.pxi" 
     5688# See extensive note in the fast_tp_new() function below.
     5689
     5690include "../ext/python_rich_object.pxi"
    56915691cdef extern from "gmp.h":
    56925692    ctypedef long mp_limb_t
    56935693    ctypedef mp_limb_t* mp_ptr #"mp_ptr"
    56945694
    5695     # We allocate _mp_d directly (mpz_t is typedef of this in GMP) 
     5695    # We allocate _mp_d directly (mpz_t is typedef of this in GMP)
    56965696    ctypedef struct __mpz_struct "__mpz_struct":
    56975697        int _mp_alloc
    56985698        int _mp_size
     
    57245724# To avoid this we calculate the byte offset of the value member and
    57255725# remember it in this variable.
    57265726#
    5727 # Eventually this may be rendered obsolete by a change in Cython allowing 
     5727# Eventually this may be rendered obsolete by a change in Cython allowing
    57285728# non-reference counted extension types.
    57295729cdef long mpz_t_offset
    57305730mpz_t_offset_python = None
    57315731
    57325732
    5733 # stores the GMP alloc function 
     5733# stores the GMP alloc function
    57345734cdef void * (* mpz_alloc)(size_t)
    57355735
    57365736# stores the GMP free function
    57375737cdef void (* mpz_free)(void *, size_t)
    57385738
    5739 # A global  pool for performance when integers are rapidly created and destroyed. 
     5739# A global  pool for performance when integers are rapidly created and destroyed.
    57405740# It operates on the following principles:
    57415741#
    5742 # - The pool starts out empty. 
    5743 # - When an new integer is needed, one from the pool is returned 
     5742# - The pool starts out empty.
     5743# - When an new integer is needed, one from the pool is returned
    57445744#   if available, otherwise a new Integer object is created
    5745 # - When an integer is collected, it will add it to the pool 
    5746 #   if there is room, otherwise it will be deallocated. 
    5747    
     5745# - When an integer is collected, it will add it to the pool
     5746#   if there is room, otherwise it will be deallocated.
     5747
    57485748
    57495749cdef int integer_pool_size = 100
    57505750   
     
    57565756cdef int use_pool = 0
    57575757
    57585758# The signature of tp_new is
    5759 # PyObject* tp_new(RichPyTypeObject *t, PyObject *a, PyObject *k). 
     5759# PyObject* tp_new(RichPyTypeObject *t, PyObject *a, PyObject *k).
    57605760# However we only use t in this implementation.
    57615761#
    57625762# t in this case is the Integer TypeObject.
     
    57705770    # for profiling pool usage
    57715771    # total_alloc += 1
    57725772   
    5773     # If there is a ready integer in the pool, we will 
    5774     # decrement the counter and return that. 
     5773    # If there is a ready integer in the pool, we will
     5774    # decrement the counter and return that.
    57755775
    57765776    if integer_pool_count > 0:
    57775777   
     
    57815781        integer_pool_count -= 1
    57825782        new = <RichPyObject *> integer_pool[integer_pool_count]
    57835783     
    5784     # Otherwise, we have to create one. 
     5784    # Otherwise, we have to create one.
    57855785
    57865786    else:
    57875787
    57885788        # allocate enough room for the Integer, sizeof_Integer is
    57895789        # sizeof(Integer). The use of PyObject_MALLOC directly
    5790         # assumes that Integers are not garbage collected, i.e. 
     5790        # assumes that Integers are not garbage collected, i.e.
    57915791        # they do not possess references to other Python
    5792         # objects (as indicated by the Py_TPFLAGS_HAVE_GC flag). 
     5792        # objects (as indicated by the Py_TPFLAGS_HAVE_GC flag).
    57935793        # See below for a more detailed description.
    57945794        new = PyObject_MALLOC( sizeof_Integer )
    57955795
     
    58275827        #
    58285828        # The clean version of the following line is:
    58295829        #
    5830         #  mpz_init( <mpz_t>(<char *>new + mpz_t_offset) ) 
     5830        #  mpz_init( <mpz_t>(<char *>new + mpz_t_offset) )
    58315831        #
    5832         # We save time both by avoiding an extra function call and 
    5833         # because the rest of the mpz struct was already initialized 
     5832        # We save time both by avoiding an extra function call and
     5833        # because the rest of the mpz struct was already initialized
    58345834        # fully using the memcpy above.
    58355835
    58365836        (<__mpz_struct *>( <char *>new + mpz_t_offset) )._mp_d = <mp_ptr>mpz_alloc(__GMP_BITS_PER_MP_LIMB >> 3)
     
    58425842    # one reference in that case.
    58435843   
    58445844    # Objects from the pool have reference count zero, so this
    5845     # needs to be set in this case. 
     5845    # needs to be set in this case.
    58465846
    58475847    new.ob_refcnt = 1
    58485848
     
    58505850
    58515851cdef void fast_tp_dealloc(PyObject* o):
    58525852
    5853     # If there is room in the pool for a used integer object, 
    5854     # then put it in rather than deallocating it. 
     5853    # If there is room in the pool for a used integer object,
     5854    # then put it in rather than deallocating it.
    58555855
    58565856    global integer_pool, integer_pool_count
    58575857   
     
    58655865        # It's cheap to zero out an integer, so do it here.
    58665866        (<__mpz_struct *>( <char *>o + mpz_t_offset))._mp_size = 0
    58675867       
    5868         # And add it to the pool. 
     5868        # And add it to the pool.
    58695869        integer_pool[integer_pool_count] = o
    58705870        integer_pool_count += 1
    58715871        return
     
    59005900    # an Integer which includes reference counting. Reference counting
    59015901    # is bad in constructors and destructors as it potentially calls
    59025902    # the destructor.
    5903     # Eventually this may be rendered obsolete by a change in Cython allowing 
     5903    # Eventually this may be rendered obsolete by a change in Cython allowing
    59045904    # non-reference counted extension types.
    59055905    mpz_t_offset = <char *>(&global_dummy_Integer.value) - <char *>o
    59065906    global mpz_t_offset_python