diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 2d68e3080ca..3b7a4725582 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -202,9 +202,9 @@ cpdef factor_aurifeuillian(n, check=True): def factor_cunningham(m, proof=None): r""" - Return factorization of self obtained using trial division + Return factorization of ``self`` obtained using trial division for all primes in the so called Cunningham table. This is - efficient if self has some factors of type `b^n+1` or `b^n-1`, + efficient if ``self`` has some factors of type `b^n+1` or `b^n-1`, with `b` in `\{2,3,5,6,7,10,11,12\}`. You need to install an optional package to use this method, @@ -245,12 +245,12 @@ def factor_cunningham(m, proof=None): cpdef factor_trial_division(m, long limit=LONG_MAX): r""" - Return partial factorization of self obtained using trial division - for all primes up to limit, where limit must fit in a C signed long. + Return partial factorization of ``self`` obtained using trial division + for all primes up to ``limit``, where ``limit`` must fit in a C ``signed long``. INPUT: - - ``limit`` -- integer (default: ``LONG_MAX``) that fits in a C signed long + - ``limit`` -- integer (default: ``LONG_MAX``) that fits in a C ``signed long`` EXAMPLES:: @@ -294,7 +294,7 @@ def factor_using_pari(n, int_=False, debug_level=0, proof=None): r""" Factor this integer using PARI. - This function returns a list of pairs, not a ``Factorization`` + This function returns a list of pairs, not a :class:`Factorization` object. The first element of each pair is the factor, of type ``Integer`` if ``int_`` is ``False`` or ``int`` otherwise, the second element is the positive exponent, of type ``int``. diff --git a/src/sage/rings/fast_arith.pyx b/src/sage/rings/fast_arith.pyx index 88f2ca583e4..dfaa7782962 100644 --- a/src/sage/rings/fast_arith.pyx +++ b/src/sage/rings/fast_arith.pyx @@ -59,16 +59,16 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False): - ``algorithm`` -- optional string (default: ``None``), one of: - - ``None``: Use algorithm ``"pari_primes"`` if ``stop`` <= 436273009 - (approximately 4.36E8). Otherwise use algorithm ``"pari_isprime"``. + - ``None``: Use algorithm ``"pari_primes"`` if ``stop`` <= 436273009 + (approximately 4.36E8). Otherwise use algorithm ``"pari_isprime"``. - - ``"pari_primes"``: Use PARI's :pari:`primes` function to generate all - primes from 2 to stop. This is fast but may crash if there is - insufficient memory. Raises an error if ``stop`` > 436273009. + - ``"pari_primes"``: Use PARI's :pari:`primes` function to generate all + primes from 2 to stop. This is fast but may crash if there is + insufficient memory. Raises an error if ``stop`` > 436273009. - - ``"pari_isprime"``: Wrapper for ``list(primes(start, stop))``. Each (odd) - integer in the specified range is tested for primality by applying PARI's - :pari:`isprime` function. This is slower but will work for much larger input. + - ``"pari_isprime"``: Wrapper for ``list(primes(start, stop))``. Each (odd) + integer in the specified range is tested for primality by applying PARI's + :pari:`isprime` function. This is slower but will work for much larger input. - ``py_ints`` -- optional boolean (default ``False``), return Python ints rather than Sage Integers (faster). Ignored unless algorithm ``"pari_primes"`` is being diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 10a94aa156d..e27ceda40ac 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -25,7 +25,7 @@ Add an integer and a rational number:: Add an integer and a complex number:: sage: b = ComplexField().0 + 1.5 - sage: loads((a+b).dumps()) == a+b + sage: loads((a + b).dumps()) == a + b True sage: z = 32 @@ -354,7 +354,7 @@ cdef class IntegerWrapper(Integer): ``Integers`` (with initialized ``parent`` and ``mpz_t`` fields) into a pool on "deallocation" and then pull them out whenever a new one is needed. Because ``Integers`` are so common, this is - actually a significant savings. However , this does cause issues + actually a significant savings. However, this does cause issues with subclassing a Python class directly from ``Integer`` (but that's ok for a Cython class). @@ -762,7 +762,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _im_gens_(self, codomain, im_gens, base_map=None): """ - Return the image of self under the map that sends the generators of + Return the image of ``self`` under the map that sends the generators of the parent to im_gens. Since ZZ maps canonically in the category of rings, this is just the natural coercion. @@ -1077,7 +1077,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: two=Integer(2) + sage: two = Integer(2) sage: two.str(1) Traceback (most recent call last): ... @@ -1364,7 +1364,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Return a list of digits for ``self`` in the given base in little endian order. - The returned value is unspecified if self is a negative number + The returned value is unspecified if ``self`` is a negative number and the digits are given. INPUT: @@ -1695,7 +1695,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ndigits(self, base=10): """ - Return the number of digits of self expressed in the given base. + Return the number of digits of ``self`` expressed in the given base. INPUT: @@ -2316,25 +2316,25 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def nth_root(self, int n, bint truncate_mode=0): r""" - Returns the (possibly truncated) n'th root of self. + Returns the (possibly truncated) ``n``-th root of ``self``. INPUT: - - ``n`` - integer >= 1 (must fit in C int type). + - ``n`` - integer >= 1 (must fit in the C ``int`` type). - ``truncate_mode`` - boolean, whether to allow truncation if - self is not an n'th power. + ``self`` is not an n'th power. OUTPUT: - If truncate_mode is 0 (default), then returns the exact n'th root - if self is an n'th power, or raises a ValueError if it is not. + If ``truncate_mode`` is 0 (default), then returns the exact n'th root + if ``self`` is an n'th power, or raises a ValueError if it is not. - If truncate_mode is 1, then if either n is odd or self is - positive, returns a pair (root, exact_flag) where root is the - truncated nth root (rounded towards zero) and exact_flag is a + If ``truncate_mode`` is 1, then if either n is odd or ``self`` is + positive, returns a pair ``(root, exact_flag)`` where ``root`` is the + truncated ``n``-th root (rounded towards zero) and ``exact_flag`` is a boolean indicating whether the root extraction was exact; - otherwise raises a ValueError. + otherwise raises a :class:`ValueError`. AUTHORS: @@ -2643,11 +2643,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: # The following are very very fast. sage: # Note that for base m a perfect power of 2, we get the exact log by counting bits. - sage: n=2983579823750185701375109835; m=32 + sage: n = 2983579823750185701375109835; m = 32 sage: n.exact_log(m) 18 sage: # The next is a favorite of mine. The log2 approximate is exact and immediately provable. - sage: n=90153710570912709517902579010793251709257901270941709247901209742124;m=213509721309572 + sage: n = 90153710570912709517902579010793251709257901270941709247901209742124 + sage: m = 213509721309572 sage: n.exact_log(m) 4 @@ -2663,9 +2664,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: x.exact_log(3) 100000 - sage: (x+1).exact_log(3) + sage: (x + 1).exact_log(3) 100000 - sage: (x-1).exact_log(3) + sage: (x - 1).exact_log(3) 99999 :: @@ -2751,19 +2752,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def log(self, m=None, prec=None): r""" Returns symbolic log by default, unless the logarithm is exact (for - an integer argument). When precision is given, the RealField + an integer argument). When ``prec`` is given, the :class:`RealField` approximation to that bit precision is used. This function is provided primarily so that Sage integers may be treated in the same manner as real numbers when convenient. Direct - use of exact_log is probably best for arithmetic log computation. + use of :meth:`exact_log` is probably best for arithmetic log computation. INPUT: - ``m`` - default: natural log base e - - ``prec`` - integer (default: None): if None, returns - symbolic, else to given bits of precision as in RealField + - ``prec`` - integer (default: ``None``): if ``None``, returns + symbolic, else to given bits of precision as in :class:`RealField` EXAMPLES:: @@ -2784,8 +2785,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: log(x, 3) 100000 - With the new Pynac symbolic backend, log(x) also - works in a reasonable amount of time for this x:: + Also ``log(x)``, giving a symbolic output, + works in a reasonable amount of time for this ``x``:: sage: x = 3^100000 sage: log(x) @@ -2794,20 +2795,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): But approximations are probably more useful in this case, and work to as high a precision as we desire:: - sage: x.log(3,53) # default precision for RealField + sage: x.log(3, 53) # default precision for RealField 100000.000000000 - sage: (x+1).log(3,53) + sage: (x +1 ).log(3, 53) 100000.000000000 - sage: (x+1).log(3,1000) + sage: (x + 1).log(3, 1000) 100000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 We can use non-integer bases, with default e:: - sage: x.log(2.5,prec=53) + sage: x.log(2.5, prec=53) 119897.784671579 We also get logarithms of negative integers, via the - symbolic ring, using the branch from `-pi` to `pi`:: + symbolic ring, using the branch from `-\pi` to `\pi`:: sage: log(-1) I*pi @@ -2872,7 +2873,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def exp(self, prec=None): r""" - Returns the exponential function of self as a real number. + Returns the exponential function of ``self`` as a real number. This function is provided only so that Sage integers may be treated in the same manner as real numbers when convenient. @@ -2911,7 +2912,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def prime_to_m_part(self, m): """ - Returns the prime-to-m part of self, i.e., the largest divisor of + Returns the prime-to-m part of ``self``, i.e., the largest divisor of ``self`` that is coprime to ``m``. INPUT: @@ -3394,7 +3395,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def quo_rem(Integer self, other): """ - Returns the quotient and the remainder of self divided by other. + Returns the quotient and the remainder of ``self`` divided by other. Note that the remainder returned is always either zero or of the same sign as other. @@ -3484,7 +3485,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def powermod(self, exp, mod): r""" - Compute self\*\*exp modulo mod. + Compute ``self**exp`` modulo ``mod``. EXAMPLES:: @@ -3518,10 +3519,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def rational_reconstruction(self, Integer m): """ - Return the rational reconstruction of this integer modulo m, i.e., - the unique (if it exists) rational number that reduces to self + Return the rational reconstruction of this integer modulo `m`, i.e., + the unique (if it exists) rational number that reduces to ``self`` modulo m and whose numerator and denominator is bounded by - sqrt(m/2). + `\sqrt{m/2}`. INPUT: @@ -3687,17 +3688,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trial_division(self, long bound=LONG_MAX, long start=2): """ - Return smallest prime divisor of self up to bound, beginning - checking at start, or abs(self) if no such divisor is found. + Return smallest prime divisor of ``self`` up to bound, beginning + checking at ``start``, or ``abs(self)`` if no such divisor is found. INPUT: - - ``bound`` -- a positive integer that fits in a C signed long - - ``start`` -- a positive integer that fits in a C signed long + - ``bound`` -- a positive integer that fits in a C ``signed long`` + - ``start`` -- a positive integer that fits in a C ``signed long`` - OUTPUT: - - - a positive integer + OUTPUT: A positive integer EXAMPLES:: @@ -3885,7 +3884,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: dict(f)[3] 6 - We use proof=False, which doesn't prove correctness of the primes + We use ``proof=False``, which doesn't prove correctness of the primes that appear in the factorization:: sage: n = 920384092842390423848290348203948092384082349082 @@ -4154,7 +4153,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cpdef RingElement _valuation(Integer self, Integer p): r""" - Return the p-adic valuation of self. + Return the p-adic valuation of ``self``. We do not require that p be prime, but it must be at least 2. For more documentation see ``valuation`` @@ -4179,8 +4178,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef object _val_unit(Integer self, Integer p): r""" - Returns a pair: the p-adic valuation of self, and the p-adic unit - of self. + Returns a pair: the p-adic valuation of ``self``, and the p-adic unit + of ``self``. We do not require the p be prime, but it must be at least 2. For more documentation see ``val_unit`` @@ -4204,7 +4203,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def valuation(self, p): """ - Return the p-adic valuation of self. + Return the p-adic valuation of ``self``. INPUT: @@ -4265,8 +4264,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def val_unit(self, p): r""" - Returns a pair: the p-adic valuation of self, and the p-adic unit - of self. + Returns a pair: the p-adic valuation of ``self``, and the p-adic unit + of ``self``. INPUT: @@ -4301,10 +4300,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): IMPLEMENTATION: - Currently returns 0 when self is 0. This behaviour is fairly arbitrary, + Currently returns 0 when ``self`` is 0. This behaviour is fairly arbitrary, and in Sage 4.6 this special case was not handled at all, eventually propagating a TypeError. The caller should not rely on the behaviour - in case self is 0. + in case ``self`` is 0. EXAMPLES:: @@ -4328,10 +4327,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef Integer _divide_knowing_divisible_by(Integer self, Integer right): r""" - Returns the integer self / right when self is divisible by right. + Returns the integer ``self`` / ``right`` when ``self`` is divisible by right. - If self is not divisible by right, the return value is undefined, - and may not even be close to self/right. For more documentation see + If ``self`` is not divisible by right, the return value is undefined, + and may not even be close to ``self`` / ``right``. For more documentation see ``divide_knowing_divisible_by`` AUTHORS: @@ -4354,10 +4353,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def divide_knowing_divisible_by(self, right): r""" - Returns the integer self / right when self is divisible by right. + Returns the integer ``self`` / ``right`` when ``self`` is divisible by ``right``. - If self is not divisible by right, the return value is undefined, - and may not even be close to self/right for multi-word integers. + If ``self`` is not divisible by right, the return value is undefined, + and may not even be close to ``self`` / ``right`` for multi-word integers. EXAMPLES:: @@ -4384,7 +4383,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _lcm(self, Integer n): """ - Returns the least common multiple of self and `n`. + Returns the least common multiple of ``self`` and `n`. EXAMPLES:: @@ -4400,7 +4399,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _gcd(self, Integer n): """ - Return the greatest common divisor of self and `n`. + Return the greatest common divisor of ``self`` and `n`. EXAMPLES:: @@ -4517,7 +4516,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def multifactorial(self, long k): r""" - Compute the k-th factorial `n!^{(k)}` of self. + Compute the k-th factorial `n!^{(k)}` of ``self``. The multifactorial number `n!^{(k)}` is defined for non-negative integers `n` as follows. For `k=1` this is the standard factorial, @@ -4619,7 +4618,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def floor(self): """ - Return the floor of self, which is just self since self is an + Return the floor of ``self``, which is just self since ``self`` is an integer. EXAMPLES:: @@ -4632,7 +4631,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ceil(self): """ - Return the ceiling of self, which is self since self is an + Return the ceiling of ``self``, which is ``self`` since ``self`` is an integer. EXAMPLES:: @@ -4645,8 +4644,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trunc(self): """ - Round this number to the nearest integer, which is self since - self is an integer. + Round this number to the nearest integer, which is ``self`` since + ``self`` is an integer. EXAMPLES:: @@ -4658,8 +4657,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def round(Integer self, mode="away"): """ - Returns the nearest integer to ``self``, which is self since - self is an integer. + Returns the nearest integer to ``self``, which is ``self`` since + ``self`` is an integer. EXAMPLES: @@ -4673,7 +4672,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def real(self): """ - Returns the real part of self, which is self. + Returns the real part of ``self``, which is ``self``. EXAMPLES:: @@ -4684,7 +4683,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def imag(self): """ - Returns the imaginary part of self, which is zero. + Returns the imaginary part of ``self``, which is zero. EXAMPLES:: @@ -4771,7 +4770,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_square(self): r""" - Returns ``True`` if self is a perfect square. + Returns ``True`` if ``self`` is a perfect square. EXAMPLES:: @@ -5022,8 +5021,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): .. NOTE:: - For large integers self, is_power_of() is faster than - is_perfect_power(). The following examples gives some indication of + For large integers ``self``, :meth:`is_power_of` is faster than + :meth:`is_perfect_power`. The following examples give some indication of how much faster. :: @@ -5031,15 +5030,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: b = lcm(range(1,10000)) sage: b.exact_log(2) 14446 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_perfect_power() sage: cputime(t) # random 0.53203299999999976 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_power_of(2) sage: cputime(t) # random 0.0 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_power_of(3) sage: cputime(t) # random 0.032002000000000308 @@ -5049,19 +5048,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: b = lcm(range(1, 1000)) sage: b.exact_log(2) 1437 - sage: t=cputime() - sage: for a in range(2, 10000): k = b.is_perfect_power() # note that we change the range from the example above + sage: t = cputime() + sage: for a in range(2, 10000): # note that we change the range from the example above + ....: k = b.is_perfect_power() sage: cputime(t) # random 0.17201100000000036 - sage: t=cputime(); TWO=int(2) + sage: t = cputime(); TWO = int(2) sage: for a in range(2, 10000): k = b.is_power_of(TWO) sage: cputime(t) # random 0.0040000000000000036 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 10000): k = b.is_power_of(3) sage: cputime(t) # random 0.040003000000000011 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 10000): k = b.is_power_of(a) sage: cputime(t) # random 0.02800199999999986 @@ -5140,7 +5140,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari (10000000000000000016800000000000000005031, 0) - The method works for large entries when `proof=False`:: + The method works for large entries when ``proof=False``:: sage: proof.arithmetic(False) sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari @@ -5262,7 +5262,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - Calls the PARI ``isprime`` function. + Calls the PARI function :pari:`isprime`. TESTS: @@ -5331,7 +5331,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_irreducible(self): r""" - Returns ``True`` if self is irreducible, i.e. +/- + Returns ``True`` if ``self`` is irreducible, i.e. +/- prime EXAMPLES:: @@ -5358,7 +5358,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): This uses PARI's Baillie-PSW probabilistic primality test. Currently, there are no known pseudoprimes for - Baillie-PSW that are not actually prime. However it is + Baillie-PSW that are not actually prime. However, it is conjectured that there are infinitely many. See :wikipedia:`Baillie-PSW_primality_test` @@ -5423,7 +5423,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - :meth:`perfect_power`: Finds the minimal base for which this integer is a perfect power. - - :meth:`is_power_of`: If you know the base already this method is + - :meth:`is_power_of`: If you know the base already, this method is the fastest option. - :meth:`is_prime_power`: Checks whether the base is prime. @@ -5515,7 +5515,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def jacobi(self, b): r""" - Calculate the Jacobi symbol `\left(\frac{self}{b}\right)`. + Calculate the Jacobi symbol `\left(\frac{\text{self}}{b}\right)`. EXAMPLES:: @@ -5552,9 +5552,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def kronecker(self, b): r""" - Calculate the Kronecker symbol `\left(\frac{self}{b}\right)` - with the Kronecker extension `(self/2)=(2/self)` when `self` is odd, - or `(self/2)=0` when `self` is even. + Calculate the Kronecker symbol `\left(\frac{\text{self}}{b}\right)` + with the Kronecker extension `(\text{self}/2)=(2/\text{self})` when ``self`` is odd, + or `(\text{self}/2)=0` when ``self`` is even. EXAMPLES:: @@ -5589,7 +5589,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - ``proof`` (boolean, default ``True``) -- if ``False`` then for negative discriminants a faster algorithm is used by the PARI library which is known to give incorrect results - when the class group has many cyclic factors. However the + when the class group has many cyclic factors. However, the results are correct for discriminants `D` with `|D|\le 2\cdot10^{10}`. OUTPUT: @@ -5662,7 +5662,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Use ``self.radical()`` for the product of the primes that divide self. - If self is 0, just returns 0. + If ``self`` is 0, just returns 0. EXAMPLES:: @@ -5738,7 +5738,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_probable_prime(self): """ - Return the next probable prime after self, as determined by PARI. + Return the next probable prime after ``self``, as determined by PARI. EXAMPLES:: @@ -5759,9 +5759,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_prime(self, proof=None): r""" - Return the next prime after self. + Return the next prime after ``self``. - This method calls the PARI ``nextprime`` function. + This method calls the PARI function :pari:`nextprime`. INPUT: @@ -5798,9 +5798,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def previous_prime(self, proof=None): r""" - Returns the previous prime before self. + Returns the previous prime before ``self``. - This method calls the PARI ``precprime`` function. + This method calls the PARI function :pari:`precprime`. INPUT: @@ -5846,7 +5846,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_prime_power(self, proof=None): r""" - Return the next prime power after self. + Return the next prime power after ``self``. INPUT: @@ -5858,7 +5858,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - The algorithm is naive. It computes the next power of 2 and go through + The algorithm is naive. It computes the next power of 2 and goes through the odd numbers calling :meth:`is_prime_power`. .. SEEALSO:: @@ -5912,7 +5912,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def previous_prime_power(self, proof=None): r""" - Return the previous prime power before self. + Return the previous prime power before ``self``. INPUT: @@ -5924,7 +5924,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - The algorithm is naive. It computes the previous power of 2 and go + The algorithm is naive. It computes the previous power of 2 and goes through the odd numbers calling the method :meth:`is_prime_power`. .. SEEALSO:: @@ -5983,7 +5983,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def additive_order(self): """ - Return the additive order of self. + Return the additive order of ``self``. EXAMPLES:: @@ -5999,7 +5999,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def multiplicative_order(self): r""" - Return the multiplicative order of self. + Return the multiplicative order of ``self``. EXAMPLES:: @@ -6242,9 +6242,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def sqrtrem(self): r""" - Return (s, r) where s is the integer square root of self and + Return (s, r) where s is the integer square root of ``self`` and r is the remainder such that `\text{self} = s^2 + r`. - Raises ``ValueError`` if self is negative. + Raises ``ValueError`` if ``self`` is negative. EXAMPLES:: @@ -6272,8 +6272,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def isqrt(self): r""" - Returns the integer floor of the square root of self, or raises an - ``ValueError`` if self is negative. + Returns the integer floor of the square root of ``self``, or raises an + ``ValueError`` if ``self`` is negative. EXAMPLES:: @@ -6315,7 +6315,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): is not None. - ``all`` - bool (default: False); if True, return all - square roots of self (a list of length 0, 1 or 2). + square roots of ``self`` (a list of length 0, 1 or 2). EXAMPLES:: @@ -6752,7 +6752,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def __invert__(self): """ - Return the multiplicative inverse of self, as a rational number. + Return the multiplicative inverse of ``self``, as a rational number. EXAMPLES:: @@ -6778,8 +6778,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def inverse_of_unit(self): """ - Return inverse of self if self is a unit in the integers, i.e., - self is -1 or 1. Otherwise, raise a ZeroDivisionError. + Return inverse of ``self`` if ``self`` is a unit in the integers, i.e., + ``self`` is -1 or 1. Otherwise, raise a :class:`ZeroDivisionError`. EXAMPLES:: @@ -6803,7 +6803,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def inverse_mod(self, n): r""" - Return the inverse of self modulo `n`, if this inverse exists. + Return the inverse of ``self`` modulo `n`, if this inverse exists. Otherwise, raises a ``ZeroDivisionError`` exception. @@ -7271,7 +7271,7 @@ def GCD_list(v): @cython.binding(True) def make_integer(s): """ - Create a Sage integer from the base-32 Python *string* s. This is + Create a Sage integer from the base-32 Python *string* ``s``. This is used in unpickling integers. EXAMPLES:: diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 515338982e2..136b380d2ab 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -152,7 +152,8 @@ cpdef is_Polynomial(f): sage: from sage.rings.polynomial.polynomial_element import is_Polynomial sage: R. = ZZ[] sage: is_Polynomial(x^3 + x + 1) - doctest:...: DeprecationWarning: the function is_Polynomial is deprecated; use isinstance(x, sage.structure.element.Polynomial) instead + doctest:...: DeprecationWarning: the function is_Polynomial is deprecated; + use isinstance(x, sage.structure.element.Polynomial) instead See https://github.com/sagemath/sage/issues/32709 for details. True sage: S. = R[] @@ -313,7 +314,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = QQ[] - sage: (x-3).is_one() + sage: (x - 3).is_one() False sage: R(1).is_one() True @@ -412,9 +413,9 @@ cdef class Polynomial(CommutativePolynomial): def subs(self, *x, **kwds): r""" - Identical to self(\*x). + Identical to ``self(*x)``. - See the docstring for ``self.__call__``. + See the docstring for :meth:`__call__`. EXAMPLES:: @@ -1526,10 +1527,11 @@ cdef class Polynomial(CommutativePolynomial): def inverse_mod(a, m): """ - Inverts the polynomial a with respect to m, or raises a ValueError - if no such inverse exists. The parameter m may be either a single - polynomial or an ideal (for consistency with inverse_mod in other - rings). + Invert the polynomial ``a`` with respect to ``m``, or raise a :class:`ValueError` + if no such inverse exists. + + The parameter ``m`` may be either a single polynomial or an ideal + (for consistency with :meth:`inverse_mod` in other rings). .. SEEALSO:: @@ -1576,11 +1578,11 @@ cdef class Polynomial(CommutativePolynomial): ....: for c in poly.coefficients(sparse=False)]) 1.0000000000000004 - ALGORITHM: Solve the system as + mt = 1, returning s as the inverse - of a mod m. + ALGORITHM: Solve the system `as + mt = 1`, returning `s` as the inverse + of `a` mod `m`. Uses the Euclidean algorithm for exact rings, and solves a linear - system for the coefficients of s and t for inexact rings (as the + system for the coefficients of `s` and `t` for inexact rings (as the Euclidean algorithm may not converge in that case). AUTHORS: @@ -2871,7 +2873,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _floordiv_(self, right): r""" - Quotient of division of self by other. This is denoted //. + Quotient of division of ``self`` by ``other``. This is denoted //. If self = quotient \* right + remainder, this function returns quotient. @@ -2894,7 +2896,7 @@ cdef class Polynomial(CommutativePolynomial): def __mod__(self, other): """ - Remainder of division of self by other. + Remainder of division of ``self`` by ``other``. EXAMPLES:: @@ -2909,7 +2911,7 @@ cdef class Polynomial(CommutativePolynomial): def mod(self, other): """ - Remainder of division of self by other. + Remainder of division of ``self`` by ``other``. EXAMPLES:: @@ -2954,7 +2956,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _mul_generic(self, right): """ - Compute the product of self and right using the classical quadratic + Compute the product of ``self`` and ``right`` using the classical quadratic algorithm. This method is the default for inexact rings. For two polynomials of degree n and m this method needs @@ -3114,7 +3116,7 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``self`` - Polynomial - - ``right`` - Polynomial (over same base ring as self) + - ``right`` - Polynomial (over same base ring as ``self``) - ``K_threshold`` - (optional) Integer. A threshold to fall back to schoolbook algorithm. In the recursion, if one of the polynomials is of degree less that K_threshold then the classic quadratic @@ -3300,22 +3302,22 @@ cdef class Polynomial(CommutativePolynomial): def base_ring(self): """ - Return the base ring of the parent of self. + Return the base ring of the parent of ``self``. EXAMPLES:: sage: R. = ZZ[] sage: x.base_ring() Integer Ring - sage: (2*x+3).base_ring() + sage: (2*x + 3).base_ring() Integer Ring """ return self._parent.base_ring() cpdef base_extend(self, R): """ - Return a copy of this polynomial but with coefficients in R, if - there is a natural map from coefficient ring of self to R. + Return a copy of this polynomial but with coefficients in ``R``, if + there is a natural map from the coefficient ring of ``self`` to ``R``. EXAMPLES:: @@ -3458,8 +3460,9 @@ cdef class Polynomial(CommutativePolynomial): def __copy__(self): """ - Return a "copy" of self. This is just self, since in Sage - polynomials are immutable this just returns self again. + Return a "copy" of ``self``. + + This is just ``self``, since in Sage polynomials are immutable. EXAMPLES: @@ -3537,20 +3540,20 @@ cdef class Polynomial(CommutativePolynomial): def denominator(self): """ - Return a denominator of self. + Return a denominator of ``self``. - First, the lcm of the denominators of the entries of self + First, the lcm of the denominators of the entries of ``self`` is computed and returned. If this computation fails, the - unit of the parent of self is returned. + unit of the parent of ``self`` is returned. Note that some subclasses may implement their own - denominator function. For example, see + :meth:`denominator` method. For example, see :class:`sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint` .. warning:: This is not the denominator of the rational function - defined by self, which would always be 1 since self is a + defined by ``self``, which would always be 1 since ``self`` is a polynomial. EXAMPLES: @@ -3578,7 +3581,7 @@ cdef class Polynomial(CommutativePolynomial): Finally, we try to compute the denominator of a polynomial with coefficients in the real numbers, which is a ring whose elements do - not have a denominator method. + not have a :meth:`denominator` method. :: @@ -3589,7 +3592,7 @@ cdef class Polynomial(CommutativePolynomial): 1.00000000000000 Check that the denominator is an element over the base whenever the base - has no denominator function. This closes :trac:`9063`. :: + has no :meth:`denominator` method. This closes :trac:`9063`. :: sage: R. = GF(5)[] # optional - sage.rings.finite_rings sage: x = R(0) # optional - sage.rings.finite_rings @@ -3625,7 +3628,7 @@ cdef class Polynomial(CommutativePolynomial): def numerator(self): """ - Return a numerator of self computed as self * self.denominator() + Return a numerator of ``self``, computed as ``self * self.denominator()`` Note that some subclasses may implement its own numerator function. For example, see @@ -3634,13 +3637,13 @@ cdef class Polynomial(CommutativePolynomial): .. warning:: This is not the numerator of the rational function - defined by self, which would always be self since self is a + defined by ``self``, which would always be ``self`` since ``self`` is a polynomial. EXAMPLES: First we compute the numerator of a polynomial with - integer coefficients, which is of course self. + integer coefficients, which is of course ``self``. :: @@ -3676,8 +3679,8 @@ cdef class Polynomial(CommutativePolynomial): sage: f.numerator() x + 0.300000000000000 - We check that the computation the numerator and denominator - are valid + We check that the computation of the numerator and denominator + are valid. :: @@ -3695,10 +3698,10 @@ cdef class Polynomial(CommutativePolynomial): def derivative(self, *args): r""" The formal derivative of this polynomial, with respect to variables - supplied in args. + supplied in ``args``. Multiple variables and iteration counts may be supplied; see - documentation for the global derivative() function for more + documentation for the global :func:`derivative` function for more details. .. SEEALSO:: @@ -3962,7 +3965,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: t = PolynomialRing(R,'t').gen() - sage: f = x*t +5*t^2 + sage: f = x*t + 5*t^2 sage: f.integral(x) 5*x*t^2 + 1/2*x^2*t @@ -4108,11 +4111,14 @@ cdef class Polynomial(CommutativePolynomial): sage: (x^2).factor() # optional - sage.libs.ntl Traceback (most recent call last): ... - NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented - sage: R.base_ring()._factor_univariate_polynomial = lambda f: f.change_ring(ZZ).factor() - sage: (x^2).factor() # optional - sage.libs.pari + NotImplementedError: factorization of polynomials over rings with + composite characteristic is not implemented + sage: def my_factor(f): + ....: return f.change_ring(ZZ).factor() + sage: R.base_ring()._factor_univariate_polynomial = my_factor # optional - sage.libs.ntl + sage: (x^2).factor() # optional - sage.libs.ntl sage.libs.pari x^2 - sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl + sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl Arbitrary precision real and complex factorization:: @@ -4187,9 +4193,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = (x^2 + 2*R(I))^3 sage: F = f.factor() sage: F # abs tol 3e-5 - (x - 1.0000138879287663 + 1.0000013435286879*I) * (x - 0.9999942196864997 + 0.9999873009803959*I) * (x - 0.9999918923847313 + 1.0000113554909125*I) * (x + 0.9999908759550227 - 1.0000069659624138*I) * (x + 0.9999985293216753 - 0.9999886153831807*I) * (x + 1.0000105947233 - 1.0000044186544053*I) + (x - 1.0000138879287663 + 1.0000013435286879*I) * (x - 0.9999942196864997 + 0.9999873009803959*I) * (x - 0.9999918923847313 + 1.0000113554909125*I) + * (x + 0.9999908759550227 - 1.0000069659624138*I) * (x + 0.9999985293216753 - 0.9999886153831807*I) * (x + 1.0000105947233 - 1.0000044186544053*I) sage: [f(t[0][0]).abs() for t in F] # abs tol 1e-13 - [1.979365054e-14, 1.97936298566e-14, 1.97936990747e-14, 3.6812407475e-14, 3.65211563729e-14, 3.65220890052e-14] + [1.979365054e-14, 1.97936298566e-14, 1.97936990747e-14, + 3.6812407475e-14, 3.65211563729e-14, 3.65220890052e-14] Factoring polynomials over `\ZZ/n\ZZ` for composite `n` is not implemented:: @@ -4878,7 +4886,7 @@ cdef class Polynomial(CommutativePolynomial): The actual algorithm for computing greatest common divisors depends on the base ring underlying the polynomial ring. If the base ring - defines a method ``_gcd_univariate_polynomial``, then this method + defines a method :meth:`_gcd_univariate_polynomial`, then this method will be called (see examples below). EXAMPLES:: @@ -5007,7 +5015,7 @@ cdef class Polynomial(CommutativePolynomial): - (ring theory) A polynomial over a ring is primitive if its coefficients generate the unit ideal. - Calling `is_primitive` on a polynomial over an infinite field will + Calling :meth:`is_primitive` on a polynomial over an infinite field will raise an error. The additional inputs to this function are to speed up computation for @@ -5015,29 +5023,29 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - - ``n`` (default: ``None``) - if provided, should equal - `q-1` where ``self.parent()`` is the field with `q` - elements; otherwise it will be computed. + - ``n`` (default: ``None``) - if provided, should equal + `q-1` where ``self.parent()`` is the field with `q` + elements; otherwise it will be computed. - - ``n_prime_divs`` (default: ``None``) - if provided, should - be a list of the prime divisors of ``n``; otherwise it - will be computed. + - ``n_prime_divs`` (default: ``None``) - if provided, should + be a list of the prime divisors of ``n``; otherwise it + will be computed. .. NOTE:: Computation of the prime divisors of ``n`` can dominate the running time of this method, so performing this computation externally - (e.g. ``pdivs=n.prime_divisors()``) is a good idea for repeated calls + (e.g., ``pdivs = n.prime_divisors()``) is a good idea for repeated calls to is_primitive for polynomials of the same degree. Results may be incorrect if the wrong ``n`` and/or factorization are provided. - EXAMPLES:: + EXAMPLES: - Field semantics examples. + Field semantics examples. - :: + :: sage: R. = GF(2)['x'] # optional - sage.rings.finite_rings sage: f = x^4+x^3+x^2+x+1 # optional - sage.rings.finite_rings @@ -5066,9 +5074,9 @@ cdef class Polynomial(CommutativePolynomial): ... NotImplementedError: is_primitive() not defined for polynomials over infinite fields. - Ring semantics examples. + Ring semantics examples. - :: + :: sage: x=polygen(ZZ) sage: f = 5*x^2+2 @@ -5171,14 +5179,14 @@ cdef class Polynomial(CommutativePolynomial): def is_monomial(self): """ - Return True if self is a monomial, i.e., a power of the generator. + Return True if ``self`` is a monomial, i.e., a power of the generator. EXAMPLES:: sage: R. = QQ[] sage: x.is_monomial() True - sage: (x+1).is_monomial() + sage: (x + 1).is_monomial() False sage: (x^2).is_monomial() True @@ -5219,7 +5227,7 @@ cdef class Polynomial(CommutativePolynomial): True sage: (3*x^5).is_term() True - sage: (1+3*x^5).is_term() + sage: (1 + 3*x^5).is_term() False To require that the coefficient is 1, use :meth:`is_monomial()` @@ -5233,7 +5241,7 @@ cdef class Polynomial(CommutativePolynomial): def root_field(self, names, check_irreducible=True): """ Return the field generated by the roots of the irreducible - polynomial self. The output is either a number field, relative + polynomial ``self``. The output is either a number field, relative number field, a quotient of a polynomial ring over a field, or the fraction field of the base ring. @@ -5317,15 +5325,15 @@ cdef class Polynomial(CommutativePolynomial): def sylvester_matrix(self, right, variable = None): """ - Return the Sylvester matrix of self and right. + Return the Sylvester matrix of ``self`` and ``right``. Note that the Sylvester matrix is not defined if one of the polynomials is zero. INPUT: - - right: a polynomial in the same ring as self. - - variable: optional, included for compatibility with the multivariate + - ``right``: a polynomial in the same ring as ``self``. + - ``variable``: optional, included for compatibility with the multivariate case only. The variable of the polynomials. EXAMPLES:: @@ -5349,7 +5357,7 @@ cdef class Polynomial(CommutativePolynomial): sage: M.determinant() # optional - sage.modules 0 - If self and right are polynomials of positive degree, the determinant + If ``self`` and ``right`` are polynomials of positive degree, the determinant of the Sylvester matrix is the resultant of the polynomials.:: sage: h1 = R._random_nonzero_element() @@ -5359,7 +5367,7 @@ cdef class Polynomial(CommutativePolynomial): True The rank of the Sylvester matrix is related to the degree of the - gcd of self and right:: + gcd of ``self`` and ``right``:: sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() # optional - sage.modules True @@ -5636,8 +5644,8 @@ cdef class Polynomial(CommutativePolynomial): sage: R(x).is_gen() True - Important - this function doesn't return True if self equals the - generator; it returns True if self *is* the generator. + Important - this function doesn't return True if ``self`` equals the + generator; it returns True if ``self`` *is* the generator. :: @@ -5808,7 +5816,7 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -5894,7 +5902,7 @@ cdef class Polynomial(CommutativePolynomial): - ``v`` -- a prime or prime ideal of the base ring. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -5946,7 +5954,7 @@ cdef class Polynomial(CommutativePolynomial): - ``i`` -- an integer. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -6020,7 +6028,7 @@ cdef class Polynomial(CommutativePolynomial): sage: v = f.list(); v [-1/3, 2, 0, -2/5] - Note that v is a list, it is mutable, and each call to the list + Note that ``v`` is a list, it is mutable, and each call to the :meth:`list` method returns a new list:: sage: type(v) @@ -6202,7 +6210,7 @@ cdef class Polynomial(CommutativePolynomial): polynomial, computed using the Newton-Raphson method. The Newton-Raphson method is an iterative root-finding algorithm. - For f(x) a polynomial, as is the case here, this is essentially the + For `f(x)` a polynomial, as is the case here, this is essentially the same as Horner's method. INPUT: @@ -6214,10 +6222,10 @@ cdef class Polynomial(CommutativePolynomial): OUTPUT: A list of numbers hopefully approximating a root of - f(x)=0. + `f(x)=0`. - If one of the iterates is a critical point of f then a - ZeroDivisionError exception is raised. + If one of the iterates is a critical point of `f`, a + :class:`ZeroDivisionError` exception is raised. EXAMPLES:: @@ -6270,13 +6278,13 @@ cdef class Polynomial(CommutativePolynomial): def newton_slopes(self, p, lengths=False): """ - Return the `p`-adic slopes of the Newton polygon of self, + Return the `p`-adic slopes of the Newton polygon of ``self``, when this makes sense. OUTPUT: - If `lengths` is `False`, a list of rational numbers. If `lengths` is - `True`, a list of couples `(s,l)` where `s` is the slope and `l` the + If ``lengths`` is False, a list of rational numbers. If ``lengths`` is + True, a list of couples `(s,l)` where `s` is the slope and `l` the length of the corresponding segment in the Newton polygon. EXAMPLES:: @@ -6294,7 +6302,7 @@ cdef class Polynomial(CommutativePolynomial): sage: (x^2^100 + 27).newton_slopes(3, lengths=True) [(3/1267650600228229401496703205376, 1267650600228229401496703205376)] - ALGORITHM: Uses PARI if `lengths` is `False`. + ALGORITHM: Uses PARI if ``lengths`` is ``False``. """ if not lengths: f = self.__pari__() @@ -6688,7 +6696,7 @@ cdef class Polynomial(CommutativePolynomial): ALGORITHM: - Uses PARI's ``polresultant`` function. For base rings that + Uses PARI's function :pari:`polresultant`. For base rings that are not supported by PARI, the resultant is computed as the determinant of the Sylvester matrix. @@ -6886,8 +6894,8 @@ cdef class Polynomial(CommutativePolynomial): where the roots `a` and `b` are to be considered in the algebraic closure of the fraction field of the coefficients and counted with multiplicities. If the polynomials are not monic this quantity is - multiplied by `\\alpha_1^{deg(p_2)} \\alpha_2^{deg(p_1)}` where - `\\alpha_1` and `\\alpha_2` are the leading coefficients of `p_1` and + multiplied by `\alpha_1^{deg(p_2)} \alpha_2^{deg(p_1)}` where + `\alpha_1` and `\alpha_2` are the leading coefficients of `p_1` and `p_2` respectively. INPUT: @@ -6898,7 +6906,7 @@ cdef class Polynomial(CommutativePolynomial): - ``op`` -- ``operator.OP`` where ``OP=add`` or ``sub`` or ``mul`` or ``truediv``. - - ``algorithm`` -- can be "resultant" or "BFSS"; + - ``algorithm`` -- can be ``"resultant"`` or ``"BFSS"``; by default the former is used when the polynomials have few nonzero coefficients and small degrees or if the base ring is not `\ZZ` or `\QQ`. Otherwise the latter is used. @@ -6910,7 +6918,7 @@ cdef class Polynomial(CommutativePolynomial): ALGORITHM: The computation is straightforward using resultants. Indeed for the - composed sum it would be `Res_y(p1(x-y), p2(y))`. However, the method + composed sum it would be `Res_y(p_1(x-y), p_2(y))`. However, the method from [BFSS2006]_ using series expansions is asymptotically much faster. Note that the algorithm ``BFSS`` with polynomials with coefficients in @@ -7321,8 +7329,8 @@ cdef class Polynomial(CommutativePolynomial): R_n := a_n^{2 n-2} \prod_{1 = QQ[] sage: g = -27*u^14 - 32*u^9 sage: g.roots(CDF, multiplicities=False) # abs tol 2e-15 - [-1.0345637159435719, 0.0, -0.3196977699902601 - 0.9839285635706636*I, -0.3196977699902601 + 0.9839285635706636*I, 0.8369796279620465 - 0.6081012947885318*I, 0.8369796279620465 + 0.6081012947885318*I] + [-1.0345637159435719, 0.0, -0.3196977699902601 - 0.9839285635706636*I, -0.3196977699902601 + 0.9839285635706636*I, + 0.8369796279620465 - 0.6081012947885318*I, 0.8369796279620465 + 0.6081012947885318*I] sage: g.roots(CDF) # abs tol 2e-15 - [(-1.0345637159435719, 1), (0.0, 9), (-0.3196977699902601 - 0.9839285635706636*I, 1), (-0.3196977699902601 + 0.9839285635706636*I, 1), (0.8369796279620465 - 0.6081012947885318*I, 1), (0.8369796279620465 + 0.6081012947885318*I, 1)] + [(-1.0345637159435719, 1), (0.0, 9), (-0.3196977699902601 - 0.9839285635706636*I, 1), (-0.3196977699902601 + 0.9839285635706636*I, 1), + (0.8369796279620465 - 0.6081012947885318*I, 1), (0.8369796279620465 + 0.6081012947885318*I, 1)] This shows that the issue at :trac:`2418` is fixed:: @@ -8538,7 +8580,7 @@ cdef class Polynomial(CommutativePolynomial): Return the complex roots of this polynomial, without multiplicities. - Calls self.roots(ring=CC), unless this is a polynomial with + Calls ``self.roots(ring=CC)``, unless this is a polynomial with floating-point coefficients, in which case it is uses the appropriate precision from the input coefficients. @@ -8582,16 +8624,16 @@ cdef class Polynomial(CommutativePolynomial): def number_of_roots_in_interval(self, a=None, b=None): r""" Return the number of roots of this polynomial in the interval - [a,b], counted without multiplicity. The endpoints a, b default to - -Infinity, Infinity (which are also valid input values). + `[a,b]`, counted without multiplicity. The endpoints `a`, `b` default to + ``-Infinity``, ``Infinity`` (which are also valid input values). Calls the PARI routine :pari:`polsturm`. Note that as of version 2.8, PARI includes the left endpoint of the interval (and no longer uses Sturm's algorithm on exact - inputs). polsturm requires a polynomial with real + inputs). :pari:`polsturm` requires a polynomial with real coefficients; in case PARI returns an error, we try again - after taking the GCD of `self` with its complex conjugate. + after taking the GCD of ``self`` with its complex conjugate. EXAMPLES:: @@ -8856,8 +8898,8 @@ cdef class Polynomial(CommutativePolynomial): - ``self`` -- polynomial with rational or integer coefficients - ``return_q`` -- (default ``False``) if ``True``, return a second value `q` - which is the prime power with respect to which this is `q`-Weil, - or 0 if there is no such value. + which is the prime power with respect to which this is `q`-Weil, + or 0 if there is no such value. EXAMPLES:: @@ -8878,7 +8920,7 @@ cdef class Polynomial(CommutativePolynomial): .. SEEALSO:: - Polynomial rings have a method `weil_polynomials` to compute sets of Weil + Polynomial rings have a method :meth:`weil_polynomials` to compute sets of Weil polynomials. This computation uses the iterator :class:`sage.rings.polynomial.weil.weil_polynomials.WeilPolynomials`. @@ -9004,7 +9046,7 @@ cdef class Polynomial(CommutativePolynomial): The actual algorithm for computing the extended gcd depends on the base ring underlying the polynomial ring. If the base ring defines - a method ``_xgcd_univariate_polynomial``, then this method will be + a method :meth:`_xgcd_univariate_polynomial`, then this method will be called (see examples below). EXAMPLES:: @@ -9018,7 +9060,7 @@ cdef class Polynomial(CommutativePolynomial): x One can easily add xgcd functionality to new rings by providing a - method ``_xgcd_univariate_polynomial``:: + method :meth:`_xgcd_univariate_polynomial`:: sage: R. = QQ[] sage: S. = R[] @@ -9027,12 +9069,13 @@ cdef class Polynomial(CommutativePolynomial): sage: h1.xgcd(h2) Traceback (most recent call last): ... - NotImplementedError: Univariate Polynomial Ring in x over Rational Field does not provide an xgcd implementation for univariate polynomials + NotImplementedError: Univariate Polynomial Ring in x over Rational Field + does not provide an xgcd implementation for univariate polynomials sage: T. = QQ[] - sage: def poor_xgcd(f,g): + sage: def poor_xgcd(f, g): ....: ret = S(T(f).gcd(g)) - ....: if ret == f: return ret,S.one(),S.zero() - ....: if ret == g: return ret,S.zero(),S.one() + ....: if ret == f: return ret, S.one(), S.zero() + ....: if ret == g: return ret, S.zero(), S.one() ....: raise NotImplementedError sage: R._xgcd_univariate_polynomial = poor_xgcd sage: h1.xgcd(h2) @@ -9070,10 +9113,10 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PolynomialRing(QQ, 'z').gen() sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1 sage: m = z**21 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) - (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: n, d = p.rational_reconstruction(m); n, d + (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, + z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) + sage: ((p*d - n) % m).is_zero() True Over `\ZZ[z]`:: @@ -9081,10 +9124,10 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PolynomialRing(ZZ, 'z').gen() sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1 sage: m = z**21 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) - (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: n, d = p.rational_reconstruction(m); n, d + (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, + z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) + sage: ((p*d - n) % m).is_zero() True Over an integral domain ``d`` might not be monic:: @@ -9093,15 +9136,13 @@ cdef class Polynomial(CommutativePolynomial): sage: x = P.gen() sage: p = 7*x^5 - 10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256 sage: m = x^5 - sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 3, 2); n, d (-32*x^3 + 384*x^2 + 2304*x + 2048, 5*x + 8) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True - sage: n, d = p.rational_reconstruction(m, 4, 0) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 4, 0); n, d (-10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256, 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True Over `\QQ(t)[z]`:: @@ -9113,8 +9154,7 @@ cdef class Polynomial(CommutativePolynomial): sage: # p = (1 + t^2*z + z^4) / (1 - t*z) sage: p = (1 + t^2*z + z^4)*(1 - t*z).inverse_mod(z^9) sage: m = z^9 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m); n, d (-1/t*z^4 - t*z - 1/t, z - 1/t) sage: print(((p*d - n) % m ).is_zero()) True @@ -9122,8 +9162,9 @@ cdef class Polynomial(CommutativePolynomial): sage: n = -10*t^2*z^4 + (-t^2 + t - 1)*z^3 + (-t - 8)*z^2 + z + 2*t^2 - t sage: d = z^4 + (2*t + 4)*z^3 + (-t + 5)*z^2 + (t^2 + 2)*z + t^2 + 2*t + 1 sage: prec = 9 - sage: nc, dc = Pz((n.subs(z = w)/d.subs(z = w) + O(w^prec)).list()).rational_reconstruction(z^prec) - sage: print( (nc, dc) == (n, d) ) + sage: x = n.subs(z=w)/d.subs(z=w) + O(w^prec) + sage: nc, dc = Pz(x.list()).rational_reconstruction(z^prec) + sage: (nc, dc) == (n, d) True Over `\QQ[t][z]`:: @@ -9308,9 +9349,9 @@ cdef class Polynomial(CommutativePolynomial): `\infty`. If a prime (or non-prime) `p` is given, then the valuation - is the largest power of `p` which divides self. + is the largest power of `p` which divides ``self``. - The valuation at `\infty` is -self.degree(). + The valuation at `\infty` is ``-self.degree()``. EXAMPLES:: @@ -9555,13 +9596,13 @@ cdef class Polynomial(CommutativePolynomial): cpdef Polynomial truncate(self, long n): r""" - Return the polynomial of degree ` < n` which is equivalent + Return the polynomial of degree `< n` which is equivalent to self modulo `x^n`. EXAMPLES:: sage: R. = ZZ[]; S. = PolynomialRing(R, sparse=True) - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: f.truncate(2) x*y - 3*x @@ -9624,13 +9665,13 @@ cdef class Polynomial(CommutativePolynomial): sage: K. = FunctionField(GF(3)) # optional - sage.rings.finite_rings sage: R. = K[] # optional - sage.rings.finite_rings - sage: (x^3-x).is_squarefree() # optional - sage.rings.finite_rings + sage: (x^3 - x).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3-1).is_squarefree() # optional - sage.rings.finite_rings + sage: (x^3 - 1).is_squarefree() # optional - sage.rings.finite_rings False - sage: (x^3+t).is_squarefree() # optional - sage.rings.finite_rings + sage: (x^3 + t).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3+t^3).is_squarefree() # optional - sage.rings.finite_rings + sage: (x^3 + t^3).is_squarefree() # optional - sage.rings.finite_rings False In the following example, `t^2` is a unit in the base field:: @@ -9743,12 +9784,12 @@ cdef class Polynomial(CommutativePolynomial): def radical(self): """ - Return the radical of self. + Return the radical of ``self``. Over a field, this is the product of - the distinct irreducible factors of self. (This is also sometimes + the distinct irreducible factors of ``self``. (This is also sometimes called the "square-free part" of self, but that term is ambiguous; - it is sometimes used to mean the quotient of self by its maximal + it is sometimes used to mean the quotient of ``self`` by its maximal square factor.) EXAMPLES:: @@ -9996,9 +10037,9 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``certificate`` -- boolean, default to ``False``. Only works with - ``algorithm`` set to "pari". + ``algorithm`` set to ``"pari"``. - - ``algorithm`` -- either "pari" or "sage" (default is "pari") + - ``algorithm`` -- either ``"pari"`` or ``"sage"`` (default is ``"pari"``) ALGORITHM: @@ -10282,7 +10323,7 @@ cdef class Polynomial(CommutativePolynomial): The algorithm assumes that the polynomial has rational coefficients. If the polynomial is known to be irreducible, it may be slightly more - efficient to call `is_cyclotomic` instead. + efficient to call :meth:`is_cyclotomic` instead. .. SEEALSO:: @@ -10447,7 +10488,7 @@ cdef class Polynomial(CommutativePolynomial): series. This method works only when the base ring is an integral domain. Moreover, for polynomial whose coefficient of lower degree is different from 1, the elements of the base - ring should have a method ``nth_root`` implemented. + ring should have a method :meth:`nth_root` implemented. EXAMPLES:: @@ -10757,7 +10798,7 @@ cdef class Polynomial(CommutativePolynomial): @coerce_binop def divides(self, p): r""" - Return `True` if this polynomial divides `p`. + Return ``True`` if this polynomial divides `p`. This method is only implemented for polynomials over an integral domain. @@ -10841,7 +10882,7 @@ cdef class Polynomial(CommutativePolynomial): - ``D`` -- dictionary (optional) - - ``phi`` -- SpecializationMorphism (optional) + - ``phi`` -- :class:`SpecializationMorphism` (optional) OUTPUT: a new polynomial @@ -11411,7 +11452,7 @@ cdef class Polynomial_generic_dense(Polynomial): True sage: (3*x^5).is_term() # optional - sage.symbolic True - sage: (1+3*x^5).is_term() # optional - sage.symbolic + sage: (1 + 3*x^5).is_term() # optional - sage.symbolic False """ if not self.__coeffs: @@ -11651,8 +11692,7 @@ cdef class Polynomial_generic_dense(Polynomial): """ Return the constant coefficient of this polynomial. - OUTPUT: - element of base ring + OUTPUT: element of base ring EXAMPLES:: @@ -11753,8 +11793,8 @@ cdef class Polynomial_generic_dense(Polynomial): Return the quotient and remainder of the Euclidean division of ``self`` and ``other``. - Raises a ``ZerodivisionError`` if ``other`` is zero. Raises an - ``ArithmeticError`` if the division is not exact. + Raises a :class:`ZerodivisionError` if ``other`` is zero. Raises an + :class:`ArithmeticError` if the division is not exact. EXAMPLES:: @@ -11854,7 +11894,7 @@ cdef class Polynomial_generic_dense(Polynomial): cpdef Polynomial truncate(self, long n): r""" - Return the polynomial of degree ` < n` which is equivalent + Return the polynomial of degree `< n` which is equivalent to self modulo `x^n`. EXAMPLES:: @@ -12167,7 +12207,7 @@ cdef class ConstantPolynomialSection(Map): """ This class is used for conversion from a polynomial ring to its base ring. - Since :trac:`9944`, it calls the ``constant_coefficient`` method, + Since :trac:`9944`, it calls the :meth:`constant_coefficient` method, which can be optimized for a particular polynomial type. EXAMPLES:: @@ -12222,12 +12262,12 @@ cdef class PolynomialBaseringInjection(Morphism): This class is used for conversion from a ring to a polynomial over that ring. - It calls the _new_constant_poly method on the generator, + It calls the :meth:`_new_constant_poly` method on the generator, which should be optimized for a particular polynomial type. Technically, it should be a method of the polynomial ring, but - few polynomial rings are cython classes, and so, as a method - of a cython polynomial class, it is faster. + few polynomial rings are Cython classes, and so, as a method + of a Cython polynomial class, it is faster. EXAMPLES: @@ -12240,12 +12280,14 @@ cdef class PolynomialBaseringInjection(Morphism): sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics Polynomial base injection morphism: From: 3-adic Field with capped relative precision 20 - To: Univariate Polynomial Ring in x over 3-adic Field with capped relative precision 20 + To: Univariate Polynomial Ring in x over + 3-adic Field with capped relative precision 20 sage: R. = Qp(3)[] # optional - sage.rings.padics sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics Polynomial base injection morphism: From: 3-adic Field with capped relative precision 20 - To: Multivariate Polynomial Ring in x, y over 3-adic Field with capped relative precision 20 + To: Multivariate Polynomial Ring in x, y over + 3-adic Field with capped relative precision 20 sage: R. = QQ[] sage: R.coerce_map_from(R.base_ring()) Polynomial base injection morphism: diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index 4f7f7d4a04b..19d225cace4 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -791,9 +791,9 @@ def quo_rem(self, other): Returns the quotient and remainder of the Euclidean division of ``self`` and ``other``. - Raises ZerodivisionError if ``other`` is zero. + Raises :class:`ZerodivisionError` if ``other`` is zero. - Raises ArithmeticError if ``other`` has a nonunit leading coefficient + Raises :class:`ArithmeticError` if ``other`` has a nonunit leading coefficient and this causes the Euclidean division to fail. EXAMPLES:: @@ -811,7 +811,8 @@ def quo_rem(self, other): sage: f.quo_rem(g) Traceback (most recent call last): ... - ArithmeticError: Division non exact (consider coercing to polynomials over the fraction field) + ArithmeticError: Division non exact + (consider coercing to polynomials over the fraction field) sage: g = 0 sage: f.quo_rem(g) Traceback (most recent call last): @@ -974,7 +975,7 @@ def reverse(self, degree=None): """ Return this polynomial but with the coefficients reversed. - If an optional degree argument is given the coefficient list will be + If an optional degree argument is given, the coefficient list will be truncated or zero padded as necessary and the reverse polynomial will have the specified degree. @@ -996,7 +997,7 @@ def reverse(self, degree=None): def truncate(self, n): """ - Return the polynomial of degree `< n` equal to `self` modulo `x^n`. + Return the polynomial of degree `< n` equal to ``self`` modulo `x^n`. EXAMPLES:: @@ -1061,8 +1062,8 @@ class Polynomial_generic_field(Polynomial_singular_repr, @coerce_binop def quo_rem(self, other): """ - Returns a tuple (quotient, remainder) where - self = quotient * other + remainder. + Returns a tuple ``(quotient, remainder)`` where + ``self = quotient * other + remainder``. EXAMPLES:: diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index db99b06f53f..5367ba96603 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -63,7 +63,7 @@ :trac:`9944` introduced some changes related with coercion. Previously, a dense and a sparse polynomial ring with the same variable name over the same base ring evaluated equal, but of -course they were not identical.Coercion maps are cached - but if a +course they were not identical. Coercion maps are cached - but if a coercion to a dense ring is requested and a coercion to a sparse ring is returned instead (since the cache keys are equal!), all hell breaks loose. @@ -79,9 +79,9 @@ True sage: R.has_coerce_map_from(S) False - sage: (R.0+S.0).parent() + sage: (R.0 + S.0).parent() Univariate Polynomial Ring in x over Rational Field - sage: (S.0+R.0).parent() + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Rational Field It may be that one has rings of dense or sparse polynomials over @@ -107,9 +107,9 @@ sage: R. = PolynomialRing(ZZ, implementation='NTL') # optional - sage.libs.ntl sage: S. = PolynomialRing(ZZ, implementation='FLINT') # optional - sage.libs.flint - sage: (S.0+R.0).parent() is S # optional - sage.libs.flint sage.libs.ntl + sage: (S.0 + R.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True - sage: (R.0+S.0).parent() is S # optional - sage.libs.flint sage.libs.ntl + sage: (R.0 + S.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True TESTS:: @@ -603,7 +603,8 @@ def flattening_morphism(self): sage: QQ['a','b']['x'].flattening_morphism() Flattening morphism: - From: Univariate Polynomial Ring in x over Multivariate Polynomial Ring in a, b over Rational Field + From: Univariate Polynomial Ring in x over + Multivariate Polynomial Ring in a, b over Rational Field To: Multivariate Polynomial Ring in a, b, x over Rational Field sage: QQ['x'].flattening_morphism() @@ -732,9 +733,9 @@ def _coerce_map_from_(self, P): sage: R. = PolynomialRing(QQ, sparse=True) sage: S. = QQ[] - sage: (R.0+S.0).parent() + sage: (R.0 + S.0).parent() Univariate Polynomial Ring in x over Rational Field - sage: (S.0+R.0).parent() + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Rational Field Here we test a feature that was implemented in :trac:`813`:: @@ -743,7 +744,7 @@ def _coerce_map_from_(self, P): sage: Q = Frac(QQ['x'])['y'] sage: Q.has_coerce_map_from(P) True - sage: P.0+Q.0 + sage: P.0 + Q.0 y + x In order to avoid bidirectional coercions (which are generally @@ -1068,8 +1069,8 @@ def change_var(self, var): def extend_variables(self, added_names, order = 'degrevlex'): r""" - Returns a multivariate polynomial ring with the same base ring but - with added_names as additional variables. + Return a multivariate polynomial ring with the same base ring but + with ``added_names`` as additional variables. EXAMPLES:: @@ -1362,7 +1363,7 @@ def random_element(self, degree=(-1,2), *args, **kwds): sage: R.random_element(6).degree() 6 - If a tuple of two integers is given for the degree argument, a degree + If a tuple of two integers is given for the ``degree`` argument, a degree is first uniformly chosen, then a polynomial of that degree is given:: sage: R.random_element(degree=(0, 8)).degree() in range(0, 9) @@ -1374,7 +1375,7 @@ def random_element(self, degree=(-1,2), *args, **kwds): Note that the zero polynomial has degree ``-1``, so if you want to consider it set the minimum degree to ``-1``:: - sage: while R.random_element(degree=(-1,2),x=-1,y=1) != R.zero(): + sage: while R.random_element(degree=(-1,2), x=-1, y=1) != R.zero(): ....: pass TESTS:: @@ -1561,10 +1562,10 @@ def polynomials( self, of_degree = None, max_degree = None ): - ``max_degree`` - an int; the iterator will generate all polynomials which have degree less than or equal to - max_degree + ``max_degree`` - ``of_degree`` - an int; the iterator will generate - all polynomials which have degree of_degree + all polynomials which have degree ``of_degree`` OUTPUT: an iterator @@ -1875,16 +1876,16 @@ def weil_polynomials(self, d, q, sign=1, lead=1): - ``sign`` -- integer (default `1`), the sign `s` of the functional equation - ``lead`` -- integer, list of integers or list of pairs of integers (default `1`), - constraints on the leading few coefficients of the generated polynomials. - If pairs `(a, b)` of integers are given, they are treated as a constraint - of the form `\equiv a \pmod{b}`; the moduli must be in decreasing order by - divisibility, and the modulus of the leading coefficient must be 0. + constraints on the leading few coefficients of the generated polynomials. + If pairs `(a, b)` of integers are given, they are treated as a constraint + of the form `\equiv a \pmod{b}`; the moduli must be in decreasing order by + divisibility, and the modulus of the leading coefficient must be 0. .. SEEALSO:: More documentation and additional options are available using the iterator :class:`sage.rings.polynomial.weil.weil_polynomials.WeilPolynomials` - directly. In addition, polynomials have a method `is_weil_polynomial` to + directly. In addition, polynomials have a method :meth:`is_weil_polynomial` to test whether or not the given polynomial is a Weil polynomial. EXAMPLES:: @@ -1904,9 +1905,9 @@ def weil_polynomials(self, d, q, sign=1, lead=1): sage: l = R.weil_polynomials(4, 2, lead=((1,0), (2,4), (1,2))) # optional - sage.libs.flint sage: l # optional - sage.libs.flint [T^4 + 2*T^3 + 5*T^2 + 4*T + 4, - T^4 + 2*T^3 + 3*T^2 + 4*T + 4, - T^4 - 2*T^3 + 5*T^2 - 4*T + 4, - T^4 - 2*T^3 + 3*T^2 - 4*T + 4] + T^4 + 2*T^3 + 3*T^2 + 4*T + 4, + T^4 - 2*T^3 + 5*T^2 - 4*T + 4, + T^4 - 2*T^3 + 3*T^2 - 4*T + 4] We do not require Weil polynomials to be monic. This example generates Weil polynomials associated to K3 surfaces over `GF(2)` of Picard number at least 12:: @@ -2113,7 +2114,7 @@ def divided_difference(self, points, full_table=False): - ``points`` -- a list of pairs `(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)` of elements of the base ring of ``self``, where `x_i - x_j` is invertible for `i \neq j`. This method - converts the `x_i` and `y_i` into the base ring of `self`. + converts the `x_i` and `y_i` into the base ring of ``self``. - ``full_table`` -- boolean (default: ``False``): If ``True``, return the full divided-difference table. If ``False``, @@ -2200,7 +2201,7 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r - ``points`` -- a list of pairs `(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)` of elements of the base ring of ``self``, where `x_i - x_j` is invertible for `i \neq j`. This method - converts the `x_i` and `y_i` into the base ring of `self`. + converts the `x_i` and `y_i` into the base ring of ``self``. - ``algorithm`` -- (default: ``'divided_difference'``): one of the following: @@ -2551,10 +2552,11 @@ def irreducible_element(self, n, algorithm=None): 2 sage: f.is_irreducible() # optional - sage.rings.finite_rings True - sage: GF(19)['x'].irreducible_element(21, algorithm="first_lexicographic") # optional - sage.rings.finite_rings + sage: R = GF(19)['x'] # optional - sage.rings.finite_rings + sage: R.irreducible_element(21, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^21 + x + 5 - sage: GF(5**2, 'a')['x'].irreducible_element(17, # optional - sage.rings.finite_rings - ....: algorithm="first_lexicographic") + sage: R = GF(5**2, 'a')['x'] # optional - sage.rings.finite_rings + sage: R.irreducible_element(17, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^17 + a*x + 4*a + 3 AUTHORS: @@ -3372,13 +3374,13 @@ def irreducible_element(self, n, algorithm=None): Currently available options are: - ``'adleman-lenstra'``: a variant of the Adleman--Lenstra - algorithm as implemented in PARI. + algorithm as implemented in PARI. - ``'conway'``: look up the Conway polynomial of degree `n` over the field of `p` elements in the database; raise a ``RuntimeError`` if it is not found. - - ``'ffprimroot'``: use the ``ffprimroot()`` function from + - ``'ffprimroot'``: use the :pari:`ffprimroot` function from PARI. - ``'first_lexicographic'``: return the lexicographically @@ -3391,7 +3393,7 @@ def irreducible_element(self, n, algorithm=None): - ``'primitive'``: return a polynomial `f` such that a root of `f` generates the multiplicative group of the finite field extension defined by `f`. This uses the Conway polynomial if - possible, otherwise it uses ``ffprimroot``. + possible, otherwise it uses ``'ffprimroot'``. - ``'random'``: try random polynomials until an irreducible one is found. @@ -3399,7 +3401,7 @@ def irreducible_element(self, n, algorithm=None): If ``algorithm`` is ``None``, use `x - 1` in degree 1. In degree > 1, the Conway polynomial is used if it is found in the database. Otherwise, the algorithm ``minimal_weight`` - is used if `p = 2`, and the algorithm ``adleman-lenstra`` if + is used if `p = 2`, and the algorithm ``'adleman-lenstra'`` if `p > 2`. OUTPUT: @@ -3505,9 +3507,9 @@ def polygen(ring_or_element, name="x"): INPUT: - - polygen(base_ring, name="x") + - ``polygen(base_ring, name="x")`` - - polygen(ring_element, name="x") + - ``polygen(ring_element, name="x")`` If the first input is a ring, return a polynomial generator over that ring. If it is a ring element, return a polynomial generator @@ -3523,9 +3525,9 @@ def polygen(ring_or_element, name="x"): .. note:: - If you give a list or comma separated string to polygen, you'll + If you give a list or comma-separated string to :func:`polygen`, you'll get a tuple of indeterminates, exactly as if you called - polygens. + :func:`polygens`. """ if is_RingElement(ring_or_element): base_ring = ring_or_element.parent() @@ -3552,7 +3554,7 @@ def polygens(base_ring, names="x", *args): x^2 + 2*x*y + y^2 + 2*x*z + 2*y*z + z^2 sage: parent(x) Multivariate Polynomial Ring in x, y, z over Rational Field - sage: t = polygens(QQ,['x','yz','abc']) + sage: t = polygens(QQ, ['x','yz','abc']) sage: t (x, yz, abc) diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 2be981c7ea0..08eda1849a0 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -1116,7 +1116,7 @@ cdef class Rational(sage.structure.element.FieldElement): def content(self, other): """ - Return the content of ``self`` and ``other``, i.e. the unique positive + Return the content of ``self`` and ``other``, i.e., the unique positive rational number `c` such that ``self/c`` and ``other/c`` are coprime integers. @@ -1193,7 +1193,7 @@ cdef class Rational(sage.structure.element.FieldElement): - ``p`` -- a prime number - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1230,7 +1230,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1266,7 +1266,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1309,7 +1309,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1404,11 +1404,11 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - - ``L`` -- a number field - - ``element`` -- (default: ``False``) boolean whether to also output - an element of which ``self`` is a norm - - proof -- If ``True``, then the output is correct unconditionally. - If ``False``, then the output assumes GRH. + - ``L`` -- a number field + - ``element`` -- (default: ``False``) boolean whether to also output + an element of which ``self`` is a norm + - ``proof`` -- If ``True``, then the output is correct unconditionally. + If ``False``, then the output assumes GRH. OUTPUT: @@ -1420,7 +1420,7 @@ cdef class Rational(sage.structure.element.FieldElement): ALGORITHM: - Uses PARI's bnfisnorm. See ``_bnfisnorm()``. + Uses the PARI function :pari:`bnfisnorm`. See :meth:`_bnfisnorm()`. EXAMPLES:: @@ -1612,9 +1612,9 @@ cdef class Rational(sage.structure.element.FieldElement): This test makes sure we workaround a bug in GMP (see :trac:`4612`):: - sage: [ -a for a in srange(100) if not QQ(-a^3).is_perfect_power() ] + sage: [-a for a in srange(100) if not QQ(-a^3).is_perfect_power()] [] - sage: [ -a for a in srange(100) if not QQ(-a^3).is_perfect_power(True) ] + sage: [-a for a in srange(100) if not QQ(-a^3).is_perfect_power(True)] [] """ cdef int s @@ -2971,7 +2971,7 @@ cdef class Rational(sage.structure.element.FieldElement): def numerator(self): """ Return the numerator of this rational number. - numer is an alias of numerator. + ``numer`` is an alias of ``numerator``. EXAMPLES:: @@ -3021,7 +3021,7 @@ cdef class Rational(sage.structure.element.FieldElement): def denominator(self): """ Return the denominator of this rational number. - denom is an alias of denominator. + ``denom`` is an alias of ``denominator``. EXAMPLES:: @@ -3344,7 +3344,7 @@ cdef class Rational(sage.structure.element.FieldElement): def round(Rational self, mode="away"): """ Return the nearest integer to ``self``, rounding away from 0 by - default, for consistency with the builtin Python round. + default, for consistency with the builtin Python :func:`round`. INPUT: @@ -3557,7 +3557,7 @@ cdef class Rational(sage.structure.element.FieldElement): def is_integral(self): r""" - Determine if a rational number is integral (i.e is in + Determine if a rational number is integral (i.e., is in `\ZZ`). OUTPUT: bool diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index a76e648f6db..5ef6b7522a0 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -11,7 +11,7 @@ Rational Field Values of various types can be converted to rational numbers by using the -``__call__`` method of ``RationalField`` (that is, by treating ``QQ`` as a +:meth:`__call__` method of :class:`RationalField` (that is, by treating ``QQ`` as a function). :: @@ -304,7 +304,7 @@ def __len__(self): def construction(self): r""" - Returns a pair ``(functor, parent)`` such that ``functor(parent)`` + Return a pair ``(functor, parent)`` such that ``functor(parent)`` returns ``self``. This is the construction of `\QQ` as the fraction field of `\ZZ`. @@ -460,7 +460,7 @@ def range_by_height(self, start, end=None): Returns a Python generator for the list of rational numbers with heights in ``range(start, end)``. Follows the same - convention as Python range, see ``range?`` for details. + convention as Python :func:`range`, type ``range?`` for details. See also ``__iter__()``. @@ -741,7 +741,7 @@ def residue_field(self, p, check=True): def hilbert_symbol_negative_at_S(self, S, b, check=True): r""" - Returns an integer that has a negative Hilbert symbol with respect + Return an integer that has a negative Hilbert symbol with respect to a given rational number and a given set of primes (or places). The function is algorithm 3.4.1 in [Kir2016]_. It finds an integer `a` @@ -915,7 +915,7 @@ def phi(x): def gens(self): r""" - Return a tuple of generators of `\QQ` which is only ``(1,)``. + Return a tuple of generators of `\QQ`, which is only ``(1,)``. EXAMPLES:: @@ -928,7 +928,7 @@ def gen(self, n=0): r""" Return the ``n``-th generator of `\QQ`. - There is only the 0-th generator which is 1. + There is only the 0-th generator, which is 1. EXAMPLES:: @@ -942,7 +942,7 @@ def gen(self, n=0): def degree(self): r""" - Return the degree of `\QQ` which is 1. + Return the degree of `\QQ`, which is 1. EXAMPLES:: @@ -953,7 +953,7 @@ def degree(self): def absolute_degree(self): r""" - Return the absolute degree of `\QQ` which is 1. + Return the absolute degree of `\QQ`, which is 1. EXAMPLES:: @@ -964,7 +964,7 @@ def absolute_degree(self): def ngens(self): r""" - Return the number of generators of `\QQ` which is 1. + Return the number of generators of `\QQ`, which is 1. EXAMPLES:: @@ -1087,7 +1087,7 @@ def algebraic_closure(self): def order(self): r""" - Return the order of `\QQ` which is `\infty`. + Return the order of `\QQ`, which is `\infty`. EXAMPLES:: diff --git a/src/sage/rings/sum_of_squares.pyx b/src/sage/rings/sum_of_squares.pyx index 235446af376..7e19380441e 100644 --- a/src/sage/rings/sum_of_squares.pyx +++ b/src/sage/rings/sum_of_squares.pyx @@ -140,7 +140,7 @@ def two_squares_pyx(uint32_t n): .. SEEALSO:: - :func:`~sage.arith.all.two_squares` is much more suited for large inputs + :func:`~sage.arith.misc.two_squares` is much more suited for large inputs EXAMPLES:: @@ -278,7 +278,7 @@ def four_squares_pyx(uint32_t n): .. SEEALSO:: - :func:`~sage.arith.all.four_squares` is much more suited for large input + :func:`~sage.arith.misc.four_squares` is much more suited for large input EXAMPLES::