diff --git a/src/sage/arith/functions.pyx b/src/sage/arith/functions.pyx index 2fe15bbb974..0f2c07d247a 100644 --- a/src/sage/arith/functions.pyx +++ b/src/sage/arith/functions.pyx @@ -72,25 +72,25 @@ def lcm(a, b=None): Make sure we try `\QQ` and not merely `\ZZ` (:trac:`13014`):: - sage: bool(lcm(2/5, 3/7) == lcm(SR(2/5), SR(3/7))) + sage: bool(lcm(2/5, 3/7) == lcm(SR(2/5), SR(3/7))) # optional - sage.symbolic True Make sure that the lcm of Expressions stays symbolic:: sage: parent(lcm(2, 4)) Integer Ring - sage: parent(lcm(SR(2), 4)) + sage: parent(lcm(SR(2), 4)) # optional - sage.symbolic Symbolic Ring - sage: parent(lcm(2, SR(4))) + sage: parent(lcm(2, SR(4))) # optional - sage.symbolic Symbolic Ring - sage: parent(lcm(SR(2), SR(4))) + sage: parent(lcm(SR(2), SR(4))) # optional - sage.symbolic Symbolic Ring Verify that objects without lcm methods but which can't be coerced to `\ZZ` or `\QQ` raise an error:: - sage: F. = FreeMonoid(2) - sage: lcm(x,y) + sage: F. = FreeMonoid(2) # optional - sage.groups + sage: lcm(x,y) # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to find lcm of x and y diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py index d3b5d164054..7cdd54cb54c 100644 --- a/src/sage/arith/misc.py +++ b/src/sage/arith/misc.py @@ -82,26 +82,26 @@ def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, EXAMPLES:: - sage: algdep(1.888888888888888, 1) + sage: algdep(1.888888888888888, 1) # optional - sage.libs.pari 9*x - 17 - sage: algdep(0.12121212121212,1) + sage: algdep(0.12121212121212, 1) # optional - sage.libs.pari 33*x - 4 - sage: algdep(sqrt(2),2) + sage: algdep(sqrt(2), 2) # optional - sage.libs.pari sage.symbolic x^2 - 2 This example involves a complex number:: - sage: z = (1/2)*(1 + RDF(sqrt(3)) *CC.0); z + sage: z = (1/2) * (1 + RDF(sqrt(3)) * CC.0); z # optional - sage.symbolic 0.500000000000000 + 0.866025403784439*I - sage: algdep(z, 6) + sage: algdep(z, 6) # optional - sage.symbolic x^2 - x + 1 This example involves a `p`-adic number:: - sage: K = Qp(3, print_mode = 'series') - sage: a = K(7/19); a + sage: K = Qp(3, print_mode='series') # optional - sage.rings.padics + sage: a = K(7/19); a # optional - sage.rings.padics 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) - sage: algdep(a, 1) + sage: algdep(a, 1) # optional - sage.rings.padics 19*x - 7 These examples show the importance of proper precision control. We @@ -109,82 +109,82 @@ def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, 33'rd bit:: sage: z = sqrt(RealField(200)(2)) + (1/2)^33 - sage: p = algdep(z, 4); p + sage: p = algdep(z, 4); p # optional - sage.libs.pari 227004321085*x^4 - 216947902586*x^3 - 99411220986*x^2 + 82234881648*x - 211871195088 - sage: factor(p) + sage: factor(p) # optional - sage.libs.pari 227004321085*x^4 - 216947902586*x^3 - 99411220986*x^2 + 82234881648*x - 211871195088 - sage: algdep(z, 4, known_bits=32) + sage: algdep(z, 4, known_bits=32) # optional - sage.libs.pari x^2 - 2 - sage: algdep(z, 4, known_digits=10) + sage: algdep(z, 4, known_digits=10) # optional - sage.libs.pari x^2 - 2 - sage: algdep(z, 4, use_bits=25) + sage: algdep(z, 4, use_bits=25) # optional - sage.libs.pari x^2 - 2 - sage: algdep(z, 4, use_digits=8) + sage: algdep(z, 4, use_digits=8) # optional - sage.libs.pari x^2 - 2 Using the ``height_bound`` and ``proof`` parameters, we can see that `pi` is not the root of an integer polynomial of degree at most 5 and coefficients bounded above by 10:: - sage: algdep(pi.n(), 5, height_bound=10, proof=True) is None + sage: algdep(pi.n(), 5, height_bound=10, proof=True) is None # optional - sage.libs.pari sage.symbolic True For stronger results, we need more precision:: - sage: algdep(pi.n(), 5, height_bound=100, proof=True) is None + sage: algdep(pi.n(), 5, height_bound=100, proof=True) is None # optional - sage.libs.pari sage.symbolic Traceback (most recent call last): ... ValueError: insufficient precision for non-existence proof - sage: algdep(pi.n(200), 5, height_bound=100, proof=True) is None + sage: algdep(pi.n(200), 5, height_bound=100, proof=True) is None # optional - sage.libs.pari sage.symbolic True - sage: algdep(pi.n(), 10, height_bound=10, proof=True) is None + sage: algdep(pi.n(), 10, height_bound=10, proof=True) is None # optional - sage.libs.pari sage.symbolic Traceback (most recent call last): ... ValueError: insufficient precision for non-existence proof - sage: algdep(pi.n(200), 10, height_bound=10, proof=True) is None + sage: algdep(pi.n(200), 10, height_bound=10, proof=True) is None # optional - sage.libs.pari sage.symbolic True We can also use ``proof=True`` to get positive results:: - sage: a = sqrt(2) + sqrt(3) + sqrt(5) - sage: algdep(a.n(), 8, height_bound=1000, proof=True) + sage: a = sqrt(2) + sqrt(3) + sqrt(5) # optional - sage.libs.pari sage.symbolic + sage: algdep(a.n(), 8, height_bound=1000, proof=True) # optional - sage.libs.pari sage.symbolic Traceback (most recent call last): ... ValueError: insufficient precision for uniqueness proof - sage: f = algdep(a.n(1000), 8, height_bound=1000, proof=True); f + sage: f = algdep(a.n(1000), 8, height_bound=1000, proof=True); f # optional - sage.libs.pari sage.symbolic x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576 - sage: f(a).expand() + sage: f(a).expand() # optional - sage.libs.pari sage.symbolic 0 TESTS:: - sage: algdep(complex("1+2j"), 4) + sage: algdep(complex("1+2j"), 4) # optional - sage.libs.pari x^2 - 2*x + 5 We get an irreducible polynomial even if PARI returns a reducible one:: sage: z = CDF(1, RR(3).sqrt())/2 - sage: pari(z).algdep(5) + sage: pari(z).algdep(5) # optional - sage.libs.pari x^5 + x^2 - sage: algdep(z, 5) + sage: algdep(z, 5) # optional - sage.libs.pari x^2 - x + 1 Check that cases where a constant polynomial might look better get handled correctly:: - sage: z=CC(-1)**(1/3) - sage: algdep(z,1) + sage: z = CC(-1)**(1/3) + sage: algdep(z, 1) # optional - sage.libs.pari x Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8, float64 - sage: algdep(float64(1.888888888888888), int8(1)) + sage: from numpy import int8, float64 # optional - numpy + sage: algdep(float64(1.888888888888888), int8(1)) # optional - numpy sage.libs.pari 9*x - 17 sage: from gmpy2 import mpz, mpfr - sage: algdep(mpfr(1.888888888888888), mpz(1)) + sage: algdep(mpfr(1.888888888888888), mpz(1)) # optional - sage.libs.pari 9*x - 17 """ if proof and not height_bound: @@ -303,47 +303,54 @@ def bernoulli(n, algorithm='default', num_threads=1): EXAMPLES:: - sage: bernoulli(12) + sage: bernoulli(12) # optional - sage.libs.flint -691/2730 - sage: bernoulli(50) + sage: bernoulli(50) # optional - sage.libs.flint 495057205241079648212477525/66 We demonstrate each of the alternative algorithms:: - sage: bernoulli(12, algorithm='arb') + sage: bernoulli(12, algorithm='arb') # optional - sage.libs.flint -691/2730 - sage: bernoulli(12, algorithm='flint') + sage: bernoulli(12, algorithm='flint') # optional - sage.libs.flint -691/2730 - sage: bernoulli(12, algorithm='gap') + sage: bernoulli(12, algorithm='gap') # optional - sage.libs.gap -691/2730 - sage: bernoulli(12, algorithm='gp') + sage: bernoulli(12, algorithm='gp') # optional - sage.libs.pari -691/2730 sage: bernoulli(12, algorithm='magma') # optional - magma -691/2730 - sage: bernoulli(12, algorithm='pari') + sage: bernoulli(12, algorithm='pari') # optional - sage.libs.pari -691/2730 - sage: bernoulli(12, algorithm='bernmm') + sage: bernoulli(12, algorithm='bernmm') # optional - sage.libs.ntl -691/2730 - sage: bernoulli(12, algorithm='bernmm', num_threads=4) + sage: bernoulli(12, algorithm='bernmm', num_threads=4) # optional - sage.libs.ntl -691/2730 TESTS:: - sage: algs = ['arb', 'gap', 'gp', 'pari', 'bernmm', 'flint'] + sage: algs = [] + sage: algs += ['arb'] # optional - sage.libs.flint + sage: algs += ['gap'] # optional - sage.libs.gap + sage: algs += ['gp', 'pari'] # optional - sage.libs.pari + sage: algs += ['bernmm'] # optional - sage.libs.ntl + sage: algs += ['flint'] # optional - sage.libs.flint sage: test_list = [ZZ.random_element(2, 2255) for _ in range(500)] sage: vals = [[bernoulli(i, algorithm=j) for j in algs] for i in test_list] # long time (up to 21s on sage.math, 2011) - sage: all(len(set(x))==1 for x in vals) # long time (depends on previous line) + sage: all(len(set(x)) == 1 for x in vals) # long time (depends on previous line) True - sage: algs = ['gp', 'pari', 'bernmm'] + sage: algs = [] + sage: algs += ['gp', 'pari'] # optional - sage.libs.pari + sage: algs += ['bernmm'] # optional - sage.libs.ntl sage: test_list = [ZZ.random_element(2256, 5000) for _ in range(500)] sage: vals = [[bernoulli(i, algorithm=j) for j in algs] for i in test_list] # long time (up to 30s on sage.math, 2011) sage: all(len(set(x))==1 for x in vals) # long time (depends on previous line) True - sage: from numpy import int8 - sage: bernoulli(int8(12)) + sage: from numpy import int8 # optional - numpy + sage: bernoulli(int8(12)) # optional - numpy sage.libs.flint -691/2730 sage: from gmpy2 import mpz - sage: bernoulli(mpz(12)) + sage: bernoulli(mpz(12)) # optional - sage.libs.flint -691/2730 AUTHOR: @@ -433,8 +440,8 @@ def factorial(n, algorithm='gmp'): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: factorial(int8(4)) + sage: from numpy import int8 # optional - numpy + sage: factorial(int8(4)) # optional - numpy 24 sage: from gmpy2 import mpz sage: factorial(mpz(4)) @@ -519,7 +526,7 @@ def is_prime(n): sage: a = 2**2048 + 981 sage: is_prime(a) # not tested - takes ~ 1min sage: proof.arithmetic(False) - sage: is_prime(a) # instantaneous! + sage: is_prime(a) # instantaneous! # optional - sage.libs.pari True sage: proof.arithmetic(True) @@ -586,19 +593,19 @@ def is_pseudoprime(n): EXAMPLES:: - sage: is_pseudoprime(389) + sage: is_pseudoprime(389) # optional - sage.libs.pari True - sage: is_pseudoprime(2000) + sage: is_pseudoprime(2000) # optional - sage.libs.pari False - sage: is_pseudoprime(2) + sage: is_pseudoprime(2) # optional - sage.libs.pari True - sage: is_pseudoprime(-1) + sage: is_pseudoprime(-1) # optional - sage.libs.pari False sage: factor(-6) -1 * 2 * 3 - sage: is_pseudoprime(1) + sage: is_pseudoprime(1) # optional - sage.libs.pari False - sage: is_pseudoprime(-2) + sage: is_pseudoprime(-2) # optional - sage.libs.pari False """ return ZZ(n).is_pseudoprime() @@ -621,51 +628,51 @@ def is_prime_power(n, get_data=False): EXAMPLES:: - sage: is_prime_power(389) + sage: is_prime_power(389) # optional - sage.libs.pari True - sage: is_prime_power(2000) + sage: is_prime_power(2000) # optional - sage.libs.pari False - sage: is_prime_power(2) + sage: is_prime_power(2) # optional - sage.libs.pari True - sage: is_prime_power(1024) + sage: is_prime_power(1024) # optional - sage.libs.pari True - sage: is_prime_power(1024, get_data=True) + sage: is_prime_power(1024, get_data=True) # optional - sage.libs.pari (2, 10) The same results can be obtained with:: - sage: 389.is_prime_power() + sage: 389.is_prime_power() # optional - sage.libs.pari True - sage: 2000.is_prime_power() + sage: 2000.is_prime_power() # optional - sage.libs.pari False - sage: 2.is_prime_power() + sage: 2.is_prime_power() # optional - sage.libs.pari True - sage: 1024.is_prime_power() + sage: 1024.is_prime_power() # optional - sage.libs.pari True - sage: 1024.is_prime_power(get_data=True) + sage: 1024.is_prime_power(get_data=True) # optional - sage.libs.pari (2, 10) TESTS:: - sage: is_prime_power(-1) + sage: is_prime_power(-1) # optional - sage.libs.pari False - sage: is_prime_power(1) + sage: is_prime_power(1) # optional - sage.libs.pari False - sage: is_prime_power(QQ(997^100)) + sage: is_prime_power(QQ(997^100)) # optional - sage.libs.pari True - sage: is_prime_power(1/2197) + sage: is_prime_power(1/2197) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: no conversion of this rational to integer - sage: is_prime_power("foo") + sage: is_prime_power("foo") # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: unable to convert 'foo' to an integer sage: from gmpy2 import mpz - sage: is_prime_power(mpz(389)) + sage: is_prime_power(mpz(389)) # optional - sage.libs.pari True - sage: from numpy import int16 - sage: is_prime_power(int16(389)) + sage: from numpy import int16 # optional - numpy + sage: is_prime_power(int16(389)) # optional - numpy sage.libs.pari True """ return ZZ(n).is_prime_power(get_data=get_data) @@ -688,39 +695,39 @@ def is_pseudoprime_power(n, get_data=False): EXAMPLES:: - sage: is_pseudoprime_power(389) + sage: is_pseudoprime_power(389) # optional - sage.libs.pari True - sage: is_pseudoprime_power(2000) + sage: is_pseudoprime_power(2000) # optional - sage.libs.pari False - sage: is_pseudoprime_power(2) + sage: is_pseudoprime_power(2) # optional - sage.libs.pari True - sage: is_pseudoprime_power(1024) + sage: is_pseudoprime_power(1024) # optional - sage.libs.pari True - sage: is_pseudoprime_power(-1) + sage: is_pseudoprime_power(-1) # optional - sage.libs.pari False - sage: is_pseudoprime_power(1) + sage: is_pseudoprime_power(1) # optional - sage.libs.pari False - sage: is_pseudoprime_power(997^100) + sage: is_pseudoprime_power(997^100) # optional - sage.libs.pari True Use of the get_data keyword:: - sage: is_pseudoprime_power(3^1024, get_data=True) + sage: is_pseudoprime_power(3^1024, get_data=True) # optional - sage.libs.pari (3, 1024) - sage: is_pseudoprime_power(2^256, get_data=True) + sage: is_pseudoprime_power(2^256, get_data=True) # optional - sage.libs.pari (2, 256) - sage: is_pseudoprime_power(31, get_data=True) + sage: is_pseudoprime_power(31, get_data=True) # optional - sage.libs.pari (31, 1) - sage: is_pseudoprime_power(15, get_data=True) + sage: is_pseudoprime_power(15, get_data=True) # optional - sage.libs.pari (15, 0) Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: is_pseudoprime_power(int16(1024)) + sage: from numpy import int16 # optional - numpy + sage: is_pseudoprime_power(int16(1024)) # optional - numpy sage.libs.pari True sage: from gmpy2 import mpz - sage: is_pseudoprime_power(mpz(1024)) + sage: is_pseudoprime_power(mpz(1024)) # optional - sage.libs.pari True """ return ZZ(n).is_prime_power(proof=False, get_data=get_data) @@ -784,8 +791,8 @@ def valuation(m, *args, **kwds): Traceback (most recent call last): ... ValueError: You can only compute the valuation with respect to a integer larger than 1. - sage: from numpy import int16 - sage: valuation(int16(512), int16(2)) + sage: from numpy import int16 # optional - numpy + sage: valuation(int16(512), int16(2)) # optional - numpy 9 sage: from gmpy2 import mpz sage: valuation(mpz(512), mpz(2)) @@ -822,49 +829,49 @@ def prime_powers(start, stop=None): EXAMPLES:: - sage: prime_powers(20) + sage: prime_powers(20) # optional - sage.libs.pari [2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19] - sage: len(prime_powers(1000)) + sage: len(prime_powers(1000)) # optional - sage.libs.pari 193 - sage: len(prime_range(1000)) + sage: len(prime_range(1000)) # optional - sage.libs.pari 168 - sage: a = [z for z in range(95,1234) if is_prime_power(z)] - sage: b = prime_powers(95,1234) - sage: len(b) + sage: a = [z for z in range(95, 1234) if is_prime_power(z)] # optional - sage.libs.pari + sage: b = prime_powers(95, 1234) # optional - sage.libs.pari + sage: len(b) # optional - sage.libs.pari 194 - sage: len(a) + sage: len(a) # optional - sage.libs.pari 194 - sage: a[:10] + sage: a[:10] # optional - sage.libs.pari [97, 101, 103, 107, 109, 113, 121, 125, 127, 128] - sage: b[:10] + sage: b[:10] # optional - sage.libs.pari [97, 101, 103, 107, 109, 113, 121, 125, 127, 128] - sage: a == b + sage: a == b # optional - sage.libs.pari True - sage: prime_powers(100) == [i for i in range(100) if is_prime_power(i)] + sage: prime_powers(100) == [i for i in range(100) if is_prime_power(i)] # optional - sage.libs.pari True - sage: prime_powers(10,7) + sage: prime_powers(10, 7) # optional - sage.libs.pari [] - sage: prime_powers(-5) + sage: prime_powers(-5) # optional - sage.libs.pari [] - sage: prime_powers(-1,3) + sage: prime_powers(-1, 3) # optional - sage.libs.pari [2] TESTS: Check that output are always Sage integers (:trac:`922`):: - sage: v = prime_powers(10) - sage: type(v[0]) + sage: v = prime_powers(10) # optional - sage.libs.pari + sage: type(v[0]) # optional - sage.libs.pari - sage: prime_powers(0,1) + sage: prime_powers(0, 1) # optional - sage.libs.pari [] - sage: prime_powers(2) + sage: prime_powers(2) # optional - sage.libs.pari [] - sage: prime_powers(3) + sage: prime_powers(3) # optional - sage.libs.pari [2] sage: prime_powers("foo") @@ -879,18 +886,18 @@ def prime_powers(start, stop=None): Check that long input are accepted (:trac:`17852`):: - sage: prime_powers(6l) + sage: prime_powers(6l) # optional - sage.libs.pari [2, 3, 4, 5] - sage: prime_powers(6l,10l) + sage: prime_powers(6l, 10l) # optional - sage.libs.pari [7, 8, 9] Check numpy and gmpy2 support:: - sage: from numpy import int8 - sage: prime_powers(int8(20)) + sage: from numpy import int8 # optional - numpy + sage: prime_powers(int8(20)) # optional - numpy sage.libs.pari [2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19] sage: from gmpy2 import mpz - sage: prime_powers(mpz(20)) + sage: prime_powers(mpz(20)) # optional - sage.libs.pari [2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19] """ start = ZZ(start) @@ -932,11 +939,11 @@ def primes_first_n(n, leave_pari=False): EXAMPLES:: - sage: primes_first_n(10) + sage: primes_first_n(10) # optional - sage.libs.pari [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] - sage: len(primes_first_n(1000)) + sage: len(primes_first_n(1000)) # optional - sage.libs.pari 1000 - sage: primes_first_n(0) + sage: primes_first_n(0) # optional - sage.libs.pari [] """ if n < 0: @@ -974,13 +981,13 @@ def eratosthenes(n): [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] sage: len(eratosthenes(100)) 25 - sage: eratosthenes(213) == prime_range(213) + sage: eratosthenes(213) == prime_range(213) # optional - sage.libs.pari True TESTS:: - sage: from numpy import int8 - sage: eratosthenes(int8(3)) + sage: from numpy import int8 # optional - numpy + sage: eratosthenes(int8(3)) # optional - numpy [2, 3] sage: from gmpy2 import mpz sage: eratosthenes(mpz(3)) @@ -1013,75 +1020,74 @@ def eratosthenes(n): def primes(start=2, stop=None, proof=None): r""" - Return an iterator over all primes between start and stop-1, - inclusive. This is much slower than ``prime_range``, but + Return an iterator over all primes between ``start`` and ``stop-1``, + inclusive. This is much slower than :func:`prime_range`, but potentially uses less memory. As with :func:`next_prime`, the optional - argument proof controls whether the numbers returned are + argument ``proof`` controls whether the numbers returned are guaranteed to be prime or not. - This command is like the Python 3 ``range`` command, except it only iterates - over primes. In some cases it is better to use primes than - ``prime_range``, because primes does not build a list of all primes in - the range in memory all at once. However, it is potentially much - slower since it simply calls the :func:`next_prime` function - repeatedly, and :func:`next_prime` is slow. + This command is like the Python 3 :func:`range` command, except it only + iterates over primes. In some cases it is better to use :func:`primes` than + :func:`prime_range`, because :func:`primes` does not build a list of all + primes in the range in memory all at once. However, it is potentially much + slower since it simply calls the :func:`next_prime` function repeatedly, and + :func:`next_prime` is slow. INPUT: - - ``start`` - an integer (default: 2) optional argument - - giving lower bound for the primes + - ``start`` -- an integer (optional, default: 2) lower bound for the primes - - ``stop`` - an integer (or infinity) - giving upper (open) bound for the + - ``stop`` -- an integer (or infinity) upper (open) bound for the primes - - ``proof`` - bool or None (default: None) If True, the function - yields only proven primes. If False, the function uses a - pseudo-primality test, which is much faster for really big - numbers but does not provide a proof of primality. If None, - uses the global default (see :mod:`sage.structure.proof.proof`) + - ``proof`` -- bool or ``None`` (default: ``None``) If ``True``, the + function yields only proven primes. If ``False``, the function uses a + pseudo-primality test, which is much faster for really big numbers but + does not provide a proof of primality. If ``None``, uses the global + default (see :mod:`sage.structure.proof.proof`) OUTPUT: - - an iterator over primes from start to stop-1, inclusive + - an iterator over primes from ``start`` to ``stop-1``, inclusive EXAMPLES:: - sage: for p in primes(5,10): + sage: for p in primes(5, 10): # optional - sage.libs.pari ....: print(p) 5 7 - sage: list(primes(13)) + sage: list(primes(13)) # optional - sage.libs.pari [2, 3, 5, 7, 11] - sage: list(primes(10000000000, 10000000100)) + sage: list(primes(10000000000, 10000000100)) # optional - sage.libs.pari [10000000019, 10000000033, 10000000061, 10000000069, 10000000097] - sage: max(primes(10^100, 10^100+10^4, proof=False)) + sage: max(primes(10^100, 10^100+10^4, proof=False)) # optional - sage.libs.pari 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009631 - sage: next(p for p in primes(10^20, infinity) if is_prime(2*p+1)) + sage: next(p for p in primes(10^20, infinity) if is_prime(2*p+1)) # optional - sage.libs.pari 100000000000000001243 TESTS:: - sage: for a in range(-10, 50): + sage: for a in range(-10, 50): # optional - sage.libs.pari ....: for b in range(-10, 50): ....: assert list(primes(a,b)) == list(filter(is_prime, range(a,b))) - sage: sum(primes(-10, 9973, proof=False)) == sum(filter(is_prime, range(-10, 9973))) + sage: sum(primes(-10, 9973, proof=False)) == sum(filter(is_prime, range(-10, 9973))) # optional - sage.libs.pari True - sage: for p in primes(10, infinity): + sage: for p in primes(10, infinity): # optional - sage.libs.pari ....: if p > 20: break ....: print(p) 11 13 17 19 - sage: next(p for p in primes(10,oo)) # checks alternate infinity notation + sage: next(p for p in primes(10,oo)) # checks alternate infinity notation # optional - sage.libs.pari 11 - sage: from numpy import int8 - sage: list(primes(int8(13))) + sage: from numpy import int8 # optional - numpy + sage: list(primes(int8(13))) # optional - numpy sage.libs.pari [2, 3, 5, 7, 11] sage: from gmpy2 import mpz - sage: list(primes(mpz(13))) + sage: list(primes(mpz(13))) # optional - sage.libs.pari [2, 3, 5, 7, 11] """ from sage.rings.infinity import infinity @@ -1121,40 +1127,40 @@ def next_prime_power(n): EXAMPLES:: - sage: next_prime_power(1) + sage: next_prime_power(1) # optional - sage.libs.pari 2 - sage: next_prime_power(2) + sage: next_prime_power(2) # optional - sage.libs.pari 3 - sage: next_prime_power(10) + sage: next_prime_power(10) # optional - sage.libs.pari 11 - sage: next_prime_power(7) + sage: next_prime_power(7) # optional - sage.libs.pari 8 - sage: next_prime_power(99) + sage: next_prime_power(99) # optional - sage.libs.pari 101 The same results can be obtained with:: - sage: 1.next_prime_power() + sage: 1.next_prime_power() # optional - sage.libs.pari 2 - sage: 2.next_prime_power() + sage: 2.next_prime_power() # optional - sage.libs.pari 3 - sage: 10.next_prime_power() + sage: 10.next_prime_power() # optional - sage.libs.pari 11 Note that `2` is the smallest prime power:: - sage: next_prime_power(-10) + sage: next_prime_power(-10) # optional - sage.libs.pari 2 - sage: next_prime_power(0) + sage: next_prime_power(0) # optional - sage.libs.pari 2 TESTS:: - sage: from numpy import int8 - sage: next_prime_power(int8(10)) + sage: from numpy import int8 # optional - numpy + sage: next_prime_power(int8(10)) # optional - numpy sage.libs.pari 11 sage: from gmpy2 import mpz - sage: next_prime_power(mpz(10)) + sage: next_prime_power(mpz(10)) # optional - sage.libs.pari 11 """ return ZZ(n).next_prime_power() @@ -1172,22 +1178,22 @@ def next_probable_prime(n): EXAMPLES:: - sage: next_probable_prime(-100) + sage: next_probable_prime(-100) # optional - sage.libs.pari 2 - sage: next_probable_prime(19) + sage: next_probable_prime(19) # optional - sage.libs.pari 23 - sage: next_probable_prime(int(999999999)) + sage: next_probable_prime(int(999999999)) # optional - sage.libs.pari 1000000007 - sage: next_probable_prime(2^768) + sage: next_probable_prime(2^768) # optional - sage.libs.pari 1552518092300708935148979488462502555256886017116696611139052038026050952686376886330878408828646477950487730697131073206171580044114814391444287275041181139204454976020849905550265285631598444825262999193716468750892846853816058039 TESTS:: - sage: from numpy import int8 - sage: next_probable_prime(int8(19)) + sage: from numpy import int8 # optional - numpy + sage: next_probable_prime(int8(19)) # optional - numpy sage.libs.pari 23 sage: from gmpy2 import mpz - sage: next_probable_prime(mpz(19)) + sage: next_probable_prime(mpz(19)) # optional - sage.libs.pari 23 """ return ZZ(n).next_probable_prime() @@ -1211,33 +1217,33 @@ def next_prime(n, proof=None): EXAMPLES:: - sage: next_prime(-100) + sage: next_prime(-100) # optional - sage.libs.pari 2 - sage: next_prime(1) + sage: next_prime(1) # optional - sage.libs.pari 2 - sage: next_prime(2) + sage: next_prime(2) # optional - sage.libs.pari 3 - sage: next_prime(3) + sage: next_prime(3) # optional - sage.libs.pari 5 - sage: next_prime(4) + sage: next_prime(4) # optional - sage.libs.pari 5 Notice that the next_prime(5) is not 5 but 7. :: - sage: next_prime(5) + sage: next_prime(5) # optional - sage.libs.pari 7 - sage: next_prime(2004) + sage: next_prime(2004) # optional - sage.libs.pari 2011 TESTS:: - sage: from numpy import int8 - sage: next_prime(int8(3)) + sage: from numpy import int8 # optional - numpy + sage: next_prime(int8(3)) # optional - numpy sage.libs.pari 5 sage: from gmpy2 import mpz - sage: next_probable_prime(mpz(3)) + sage: next_probable_prime(mpz(3)) # optional - sage.libs.pari 5 """ return ZZ(n).next_prime(proof) @@ -1250,38 +1256,38 @@ def previous_prime(n): EXAMPLES:: - sage: previous_prime(10) + sage: previous_prime(10) # optional - sage.libs.pari 7 - sage: previous_prime(7) + sage: previous_prime(7) # optional - sage.libs.pari 5 - sage: previous_prime(8) + sage: previous_prime(8) # optional - sage.libs.pari 7 - sage: previous_prime(7) + sage: previous_prime(7) # optional - sage.libs.pari 5 - sage: previous_prime(5) + sage: previous_prime(5) # optional - sage.libs.pari 3 - sage: previous_prime(3) + sage: previous_prime(3) # optional - sage.libs.pari 2 - sage: previous_prime(2) + sage: previous_prime(2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no previous prime - sage: previous_prime(1) + sage: previous_prime(1) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no previous prime - sage: previous_prime(-20) + sage: previous_prime(-20) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no previous prime TESTS:: - sage: from numpy import int8 - sage: previous_prime(int8(7)) + sage: from numpy import int8 # optional - numpy + sage: previous_prime(int8(7)) # optional - numpy sage.libs.pari 5 sage: from gmpy2 import mpz - sage: previous_prime(mpz(7)) + sage: previous_prime(mpz(7)) # optional - sage.libs.pari 5 """ n = ZZ(n) - 1 @@ -1316,52 +1322,52 @@ def previous_prime_power(n): EXAMPLES:: - sage: previous_prime_power(3) + sage: previous_prime_power(3) # optional - sage.libs.pari 2 - sage: previous_prime_power(10) + sage: previous_prime_power(10) # optional - sage.libs.pari 9 - sage: previous_prime_power(7) + sage: previous_prime_power(7) # optional - sage.libs.pari 5 - sage: previous_prime_power(127) + sage: previous_prime_power(127) # optional - sage.libs.pari 125 The same results can be obtained with:: - sage: 3.previous_prime_power() + sage: 3.previous_prime_power() # optional - sage.libs.pari 2 - sage: 10.previous_prime_power() + sage: 10.previous_prime_power() # optional - sage.libs.pari 9 - sage: 7.previous_prime_power() + sage: 7.previous_prime_power() # optional - sage.libs.pari 5 - sage: 127.previous_prime_power() + sage: 127.previous_prime_power() # optional - sage.libs.pari 125 Input less than or equal to `2` raises errors:: - sage: previous_prime_power(2) + sage: previous_prime_power(2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no prime power less than 2 - sage: previous_prime_power(-10) + sage: previous_prime_power(-10) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no prime power less than 2 :: - sage: n = previous_prime_power(2^16 - 1) - sage: while is_prime(n): + sage: n = previous_prime_power(2^16 - 1) # optional - sage.libs.pari + sage: while is_prime(n): # optional - sage.libs.pari ....: n = previous_prime_power(n) - sage: factor(n) + sage: factor(n) # optional - sage.libs.pari 251^2 TESTS:: - sage: from numpy import int8 - sage: previous_prime_power(int8(10)) + sage: from numpy import int8 # optional - numpy + sage: previous_prime_power(int8(10)) # optional - numpy sage.libs.pari 9 sage: from gmpy2 import mpz - sage: previous_prime_power(mpz(10)) + sage: previous_prime_power(mpz(10)) # optional - sage.libs.pari 9 """ return ZZ(n).previous_prime_power() @@ -1378,53 +1384,53 @@ def random_prime(n, proof=None, lbound=2): INPUT: - - ``n`` - an integer >= 2. + - ``n`` - an integer `\geq 2`. - - ``proof`` - bool or None (default: None) If False, the function uses a + - ``proof`` - bool or ``None`` (default: ``None``) If ``False``, the function uses a pseudo-primality test, which is much faster for really big numbers but - does not provide a proof of primality. If None, uses the global default + does not provide a proof of primality. If ``None``, uses the global default (see :mod:`sage.structure.proof.proof`) - - ``lbound`` - an integer >= 2, lower bound for the chosen primes + - ``lbound`` - an integer `\geq 2`, lower bound for the chosen primes EXAMPLES:: - sage: p = random_prime(100000) - sage: p.is_prime() + sage: p = random_prime(100000) # optional - sage.libs.pari + sage: p.is_prime() # optional - sage.libs.pari True - sage: p <= 100000 + sage: p <= 100000 # optional - sage.libs.pari True - sage: random_prime(2) + sage: random_prime(2) # optional - sage.libs.pari 2 Here we generate a random prime between 100 and 200:: - sage: p = random_prime(200, lbound=100) - sage: p.is_prime() + sage: p = random_prime(200, lbound=100) # optional - sage.libs.pari + sage: p.is_prime() # optional - sage.libs.pari True - sage: 100 <= p <= 200 + sage: 100 <= p <= 200 # optional - sage.libs.pari True If all we care about is finding a pseudo prime, then we can pass in ``proof=False`` :: - sage: p = random_prime(200, proof=False, lbound=100) - sage: p.is_pseudoprime() + sage: p = random_prime(200, proof=False, lbound=100) # optional - sage.libs.pari + sage: p.is_pseudoprime() # optional - sage.libs.pari True - sage: 100 <= p <= 200 + sage: 100 <= p <= 200 # optional - sage.libs.pari True TESTS:: - sage: type(random_prime(2)) + sage: type(random_prime(2)) # optional - sage.libs.pari - sage: type(random_prime(100)) + sage: type(random_prime(100)) # optional - sage.libs.pari - sage: random_prime(1, lbound=-2) #caused Sage hang #10112 + sage: random_prime(1, lbound=-2) #caused Sage hang #10112 # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: n must be greater than or equal to 2 - sage: random_prime(126, lbound=114) + sage: random_prime(126, lbound=114) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: there are no primes between 114 and 126 (inclusive) @@ -1516,22 +1522,22 @@ def divisors(n): This function works whenever one has unique factorization:: - sage: K. = QuadraticField(7) - sage: divisors(K.ideal(7)) + sage: K. = QuadraticField(7) # optional - sage.rings.number_field + sage: divisors(K.ideal(7)) # optional - sage.rings.number_field [Fractional ideal (1), Fractional ideal (a), Fractional ideal (7)] - sage: divisors(K.ideal(3)) + sage: divisors(K.ideal(3)) # optional - sage.rings.number_field [Fractional ideal (1), Fractional ideal (3), - Fractional ideal (a - 2), Fractional ideal (a + 2)] - sage: divisors(K.ideal(35)) + Fractional ideal (a - 2), Fractional ideal (a + 2)] + sage: divisors(K.ideal(35)) # optional - sage.rings.number_field [Fractional ideal (1), Fractional ideal (5), Fractional ideal (a), - Fractional ideal (7), Fractional ideal (5*a), Fractional ideal (35)] + Fractional ideal (7), Fractional ideal (5*a), Fractional ideal (35)] TESTS:: sage: divisors(int(300)) [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 25, 30, 50, 60, 75, 100, 150, 300] - sage: import numpy - sage: divisors(numpy.int8(100)) + sage: import numpy # optional - numpy + sage: divisors(numpy.int8(100)) # optional - numpy [1, 2, 4, 5, 10, 20, 25, 50, 100] sage: import gmpy2 sage: divisors(gmpy2.mpz(100)) @@ -1593,13 +1599,13 @@ class Sigma: :: - sage: P = plot(sigma, 1, 100) + sage: P = plot(sigma, 1, 100) # optional - sage.plot This method also works with k-th powers. :: - sage: P = plot(sigma, 1, 100, k=2) + sage: P = plot(sigma, 1, 100, k=2) # optional - sage.plot AUTHORS: @@ -1611,21 +1617,21 @@ class Sigma: sage: sigma(100,4) 106811523 - sage: sigma(factorial(100),3).mod(144169) + sage: sigma(factorial(100), 3).mod(144169) # optional - sage.libs.pari 3672 - sage: sigma(factorial(150),12).mod(691) + sage: sigma(factorial(150), 12).mod(691) # optional - sage.libs.pari 176 - sage: RR(sigma(factorial(133),20)) + sage: RR(sigma(factorial(133),20)) # optional - sage.libs.pari 2.80414775675747e4523 - sage: sigma(factorial(100),0) + sage: sigma(factorial(100),0) # optional - sage.libs.pari 39001250856960000 - sage: sigma(factorial(41),1) + sage: sigma(factorial(41),1) # optional - sage.libs.pari 229199532273029988767733858700732906511758707916800 - sage: from numpy import int8 - sage: sigma(int8(100),int8(4)) + sage: from numpy import int8 # optional - numpy + sage: sigma(int8(100), int8(4)) # optional - numpy sage.libs.pari 106811523 sage: from gmpy2 import mpz - sage: sigma(mpz(100),mpz(4)) + sage: sigma(mpz(100), mpz(4)) # optional - sage.libs.pari 106811523 """ def __repr__(self): @@ -1649,9 +1655,9 @@ def __call__(self, n, k=1): sage: from sage.arith.misc import Sigma sage: q = Sigma() - sage: q(10) + sage: q(10) # optional - sage.libs.pari 18 - sage: q(10,2) + sage: q(10,2) # optional - sage.libs.pari 130 """ n = ZZ(n) @@ -1693,8 +1699,8 @@ def plot(self, xmin=1, xmax=50, k=1, pointsize=30, rgbcolor=(0,0,1), join=True, EXAMPLES:: sage: from sage.arith.misc import Sigma - sage: p = Sigma().plot() - sage: p.ymax() + sage: p = Sigma().plot() # optional - sage.libs.pari sage.plot + sage: p.ymax() # optional - sage.libs.pari sage.plot 124.0 """ v = [(n, sigma(n, k)) for n in range(xmin, xmax + 1)] @@ -1784,33 +1790,33 @@ def gcd(a, b=None, **kwargs): Make sure we try QQ and not merely ZZ (:trac:`13014`):: - sage: bool(gcd(2/5, 3/7) == gcd(SR(2/5), SR(3/7))) + sage: bool(gcd(2/5, 3/7) == gcd(SR(2/5), SR(3/7))) # optional - sage.symbolic True Make sure that the gcd of Expressions stays symbolic:: sage: parent(gcd(2, 4)) Integer Ring - sage: parent(gcd(SR(2), 4)) + sage: parent(gcd(SR(2), 4)) # optional - sage.symbolic Symbolic Ring - sage: parent(gcd(2, SR(4))) + sage: parent(gcd(2, SR(4))) # optional - sage.symbolic Symbolic Ring - sage: parent(gcd(SR(2), SR(4))) + sage: parent(gcd(SR(2), SR(4))) # optional - sage.symbolic Symbolic Ring Verify that objects without gcd methods but which cannot be coerced to ZZ or QQ raise an error:: - sage: F. = FreeMonoid(2) - sage: gcd(a,b) + sage: F. = FreeMonoid(2) # optional - sage.groups + sage: gcd(a, b) # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to call gcd with a Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: GCD(int8(97),int8(100)) + sage: from numpy import int8 # optional - numpy + sage: GCD(int8(97), int8(100)) # optional - numpy 1 sage: from gmpy2 import mpq, mpz sage: GCD(mpq(2/3), mpq(4/5)) @@ -1909,8 +1915,8 @@ def xlcm(m, n): TESTS:: - sage: from numpy import int16 - sage: xlcm(int16(120), int16(36)) + sage: from numpy import int16 # optional - numpy + sage: xlcm(int16(120), int16(36)) # optional - numpy (360, 40, 9) sage: from gmpy2 import mpz sage: xlcm(mpz(120), mpz(36)) @@ -1975,15 +1981,15 @@ def xgcd(a, b): sage: xgcd(x^3 - 1, x^2 - 1) (x - 1, 1, -x) - sage: K. = NumberField(x^2-3) - sage: g.xgcd(g+2) + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: g.xgcd(g + 2) # optional - sage.rings.number_field (1, 1/3*g, 0) - sage: R. = K[] - sage: S. = R.fraction_field()[] - sage: xgcd(y^2, a*y+b) + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.fraction_field()[] # optional - sage.rings.number_field + sage: xgcd(y^2, a*y + b) # optional - sage.rings.number_field (1, a^2/b^2, ((-a)/b^2)*y + 1/b) - sage: xgcd((b+g)*y^2, (a+g)*y+b) + sage: xgcd((b+g)*y^2, (a+g)*y + b) # optional - sage.rings.number_field (1, (a^2 + (2*g)*a + 3)/(b^3 + g*b^2), ((-a + (-g))/b^2)*y + 1/b) Here is an example of a xgcd for two polynomials over the integers, where the linear @@ -1999,10 +2005,10 @@ def xgcd(a, b): Tests with numpy and gmpy2 types:: - sage: from numpy import int8 - sage: xgcd(4,int8(8)) + sage: from numpy import int8 # optional - numpy + sage: xgcd(4, int8(8)) # optional - numpy (4, 1, 0) - sage: xgcd(int8(4),int8(8)) + sage: xgcd(int8(4), int8(8)) # optional - numpy (4, 1, 0) sage: from gmpy2 import mpz sage: xgcd(mpz(4), mpz(8)) @@ -2014,10 +2020,10 @@ def xgcd(a, b): We check that :trac:`3330` has been fixed:: - sage: R. = NumberField(x^2-3,'g').extension(x^2-7,'h')[] - sage: h = R.base_ring().gen() - sage: S. = R.fraction_field()[] - sage: xgcd(y^2, a*h*y+b) + sage: R. = NumberField(x^2 - 3, 'g').extension(x^2 - 7, 'h')[] # optional - sage.rings.number_field + sage: h = R.base_ring().gen() # optional - sage.rings.number_field + sage: S. = R.fraction_field()[] # optional - sage.rings.number_field + sage: xgcd(y^2, a*h*y + b) # optional - sage.rings.number_field (1, 7*a^2/b^2, (((-h)*a)/b^2)*y + 1/b) """ try: @@ -2132,20 +2138,20 @@ def inverse_mod(a, m): :: - sage: inverse_mod(7,1) + sage: inverse_mod(7, 1) 0 - sage: inverse_mod(5,14) + sage: inverse_mod(5, 14) 3 - sage: inverse_mod(3,-5) + sage: inverse_mod(3, -5) 2 Tests with numpy and mpz numbers:: - sage: from numpy import int8 - sage: inverse_mod(int8(5),int8(14)) + sage: from numpy import int8 # optional - numpy + sage: inverse_mod(int8(5), int8(14)) # optional - numpy 3 sage: from gmpy2 import mpz - sage: inverse_mod(mpz(5),mpz(14)) + sage: inverse_mod(mpz(5), mpz(14)) 3 """ try: @@ -2222,13 +2228,13 @@ def power_mod(a, n, m): EXAMPLES:: - sage: power_mod(2,388,389) + sage: power_mod(2, 388, 389) 1 - sage: power_mod(2,390,391) + sage: power_mod(2, 390, 391) 285 - sage: power_mod(2,-1,7) + sage: power_mod(2, -1, 7) 4 - sage: power_mod(11,1,7) + sage: power_mod(11, 1, 7) 4 This function works for fairly general rings:: @@ -2236,7 +2242,7 @@ def power_mod(a, n, m): sage: R. = ZZ[] sage: power_mod(3*x, 10, 7) 4*x^10 - sage: power_mod(-3*x^2+4, 7, 2*x^3-5) + sage: power_mod(-3*x^2 + 4, 7, 2*x^3 - 5) x^14 + x^8 + x^6 + x^3 + 962509*x^2 - 791910*x - 698281 TESTS:: @@ -2250,11 +2256,11 @@ def power_mod(a, n, m): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int32 - sage: power_mod(int32(2),int32(390),int32(391)) + sage: from numpy import int32 # optional - numpy + sage: power_mod(int32(2), int32(390), int32(391)) # optional - numpy 285 sage: from gmpy2 import mpz - sage: power_mod(mpz(2),mpz(390),mpz(391)) + sage: power_mod(mpz(2), mpz(390), mpz(391)) mpz(285) """ if not m: @@ -2373,8 +2379,8 @@ def rational_reconstruction(a, m, algorithm='fast'): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int32 - sage: rational_reconstruction(int32(3), int32(292393)) + sage: from numpy import int32 # optional - numpy + sage: rational_reconstruction(int32(3), int32(292393)) # optional - numpy 3 sage: from gmpy2 import mpz sage: rational_reconstruction(mpz(3), mpz(292393)) @@ -2408,16 +2414,16 @@ def mqrr_rational_reconstruction(u, m, T): EXAMPLES:: - sage: mqrr_rational_reconstruction(21,3100,13) + sage: mqrr_rational_reconstruction(21, 3100, 13) (21, 1) Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: mqrr_rational_reconstruction(int16(21),int16(3100),int16(13)) + sage: from numpy import int16 # optional - numpy + sage: mqrr_rational_reconstruction(int16(21), int16(3100), int16(13)) # optional - numpy (21, 1) sage: from gmpy2 import mpz - sage: mqrr_rational_reconstruction(mpz(21),mpz(3100),mpz(13)) + sage: mqrr_rational_reconstruction(mpz(21), mpz(3100), mpz(13)) (21, 1) """ u = py_scalar_to_element(u) @@ -2481,8 +2487,8 @@ def trial_division(n, bound=None): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: trial_division(int8(91)) + sage: from numpy import int8 # optional - numpy + sage: trial_division(int8(91)) # optional - numpy 7 sage: from gmpy2 import mpz sage: trial_division(mpz(91)) @@ -2500,69 +2506,67 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): type of ``n``. If ``n`` is an integer, returns the factorization as an object - of type ``Factorization``. + of type :class:`Factorization`. - If n is not an integer, ``n.factor(proof=proof, **kwds)`` gets called. + If ``n`` is not an integer, ``n.factor(proof=proof, **kwds)`` gets called. See ``n.factor??`` for more documentation in this case. .. warning:: - This means that applying ``factor`` to an integer result of + This means that applying :func:`factor` to an integer result of a symbolic computation will not factor the integer, because it is considered as an element of a larger symbolic ring. EXAMPLES:: - sage: f(n)=n^2 - sage: is_prime(f(3)) + sage: f(n) = n^2 # optional - sage.symbolic + sage: is_prime(f(3)) # optional - sage.symbolic False - sage: factor(f(3)) + sage: factor(f(3)) # optional - sage.symbolic 9 INPUT: - - ``n`` - an nonzero integer + - ``n`` -- a nonzero integer - - ``proof`` - bool or None (default: None) + - ``proof`` -- bool or ``None`` (default: ``None``) - - ``int_`` - bool (default: False) whether to return + - ``int_`` -- bool (default: ``False``) whether to return answers as Python ints - - ``algorithm`` - string + - ``algorithm`` -- string - - ``'pari'`` - (default) use the PARI c library + - ``'pari'`` -- (default) use the PARI c library - - ``'flint'`` - use the FLINT library - - - ``'kash'`` - use KASH computer algebra system (requires that + - ``'kash'`` -- use KASH computer algebra system (requires that kash be installed) - - ``'magma'`` - use Magma (requires magma be installed) + - ``'magma'`` -- use Magma (requires magma be installed) - - ``verbose`` - integer (default: 0); PARI's debug + - ``verbose`` -- integer (default: 0); PARI's debug variable is set to this; e.g., set to 4 or 8 to see lots of output during factorization. OUTPUT: - - factorization of n + - factorization of `n` The qsieve and ecm commands give access to highly optimized implementations of algorithms for doing certain integer factorization problems. These implementations are not used by the - generic factor command, which currently just calls PARI (note that + generic :func:`factor` command, which currently just calls PARI (note that PARI also implements sieve and ecm algorithms, but they are not as optimized). Thus you might consider using them instead for certain numbers. The factorization returned is an element of the class - :class:`~sage.structure.factorization.Factorization`; see Factorization?? - for more details, and examples below for usage. A Factorization contains - both the unit factor (+1 or -1) and a sorted list of (prime, exponent) + :class:`~sage.structure.factorization.Factorization`; use ``Factorization??`` + to see more details, and examples below for usage. A :class:`~sage.structure.factorization.Factorization` contains + both the unit factor (`+1` or `-1`) and a sorted list of ``(prime, exponent)`` pairs. The factorization displays in pretty-print format but it is easy to - obtain access to the (prime,exponent) pairs and the unit, to + obtain access to the ``(prime, exponent)`` pairs and the unit, to recover the number from its factorization, and even to multiply two factorizations. See examples below. @@ -2579,12 +2583,12 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): -1 sage: f.value() -20 - sage: factor( -next_prime(10^2) * next_prime(10^7) ) + sage: factor(-next_prime(10^2) * next_prime(10^7)) # optional - sage.libs.pari -1 * 101 * 10000019 :: - sage: factor(293292629867846432923017396246429, algorithm='flint') + sage: factor(293292629867846432923017396246429, algorithm='flint') # optional - sage.libs.flint 3 * 4852301647696687 * 20148007492971089 :: @@ -2607,52 +2611,52 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): 1 sage: factor(-1) -1 - sage: factor(2^(2^7)+1) + sage: factor(2^(2^7) + 1) # optional - sage.libs.pari 59649589127497217 * 5704689200685129054721 - Sage calls PARI's factor, which has proof False by default. - Sage has a global proof flag, set to True by default (see - :mod:`sage.structure.proof.proof`, or proof.[tab]). To override - the default, call this function with proof=False. + Sage calls PARI's :pari:`factor`, which has ``proof=False`` by default. + Sage has a global proof flag, set to ``True`` by default (see + :mod:`sage.structure.proof.proof`, or use ``proof.[tab]``). To override + the default, call this function with ``proof=False``. :: - sage: factor(3^89-1, proof=False) + sage: factor(3^89 - 1, proof=False) # optional - sage.libs.pari 2 * 179 * 1611479891519807 * 5042939439565996049162197 :: - sage: factor(2^197 + 1) # long time (2s) + sage: factor(2^197 + 1) # long time (2s) # optional - sage.libs.pari 3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843 Any object which has a factor method can be factored like this:: - sage: K. = QuadraticField(-1) - sage: factor(122 - 454*i) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: factor(122 - 454*i) # optional - sage.rings.number_field (-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4) To access the data in a factorization:: - sage: f = factor(420); f + sage: f = factor(420); f # optional - sage.libs.pari 2^2 * 3 * 5 * 7 - sage: [x for x in f] + sage: [x for x in f] # optional - sage.libs.pari [(2, 2), (3, 1), (5, 1), (7, 1)] - sage: [p for p,e in f] + sage: [p for p,e in f] # optional - sage.libs.pari [2, 3, 5, 7] - sage: [e for p,e in f] + sage: [e for p,e in f] # optional - sage.libs.pari [2, 1, 1, 1] - sage: [p^e for p,e in f] + sage: [p^e for p,e in f] # optional - sage.libs.pari [4, 3, 5, 7] We can factor Python, numpy and gmpy2 numbers:: sage: factor(math.pi) 3.141592653589793 - sage: import numpy - sage: factor(numpy.int8(30)) + sage: import numpy # optional - numpy + sage: factor(numpy.int8(30)) # optional - numpy sage.libs.pari 2 * 3 * 5 sage: import gmpy2 - sage: factor(gmpy2.mpz(30)) + sage: factor(gmpy2.mpz(30)) # optional - sage.libs.pari 2 * 3 * 5 TESTS:: @@ -2704,14 +2708,14 @@ def radical(n, *args, **kwds): Traceback (most recent call last): ... ArithmeticError: radical of 0 is not defined - sage: K. = QuadraticField(-1) - sage: radical(K(2)) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: radical(K(2)) # optional - sage.rings.number_field i + 1 Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: radical(int8(50)) + sage: from numpy import int8 # optional - numpy + sage: radical(int8(50)) # optional - numpy 10 sage: from gmpy2 import mpz sage: radical(mpz(50)) @@ -2764,13 +2768,13 @@ def prime_divisors(n): For polynomials we get all irreducible factors:: sage: R. = PolynomialRing(QQ) - sage: prime_divisors(x^12 - 1) + sage: prime_divisors(x^12 - 1) # optional - sage.libs.pari [x - 1, x + 1, x^2 - x + 1, x^2 + 1, x^2 + x + 1, x^4 - x^2 + 1] Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: prime_divisors(int8(-100)) + sage: from numpy import int8 # optional - numpy + sage: prime_divisors(int8(-100)) # optional - numpy [2, 5] sage: from gmpy2 import mpz sage: prime_divisors(mpz(-100)) @@ -2802,8 +2806,8 @@ def odd_part(n): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: odd_part(int8(5)) + sage: from numpy import int8 # optional - numpy + sage: odd_part(int8(5)) # optional - numpy 5 sage: from gmpy2 import mpz sage: odd_part(mpz(5)) @@ -2846,8 +2850,8 @@ def prime_to_m_part(n, m): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: prime_to_m_part(int16(240), int16(2)) + sage: from numpy import int16 # optional - numpy + sage: prime_to_m_part(int16(240), int16(2)) # optional - numpy 15 sage: from gmpy2 import mpz sage: prime_to_m_part(mpz(240), mpz(2)) @@ -2889,7 +2893,7 @@ def is_square(n, root=False): False sage: is_square(CDF(-2.2)) True - sage: is_square((x-1)^2) + sage: is_square((x-1)^2) # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError: is_square() not implemented for @@ -2902,8 +2906,8 @@ def is_square(n, root=False): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: is_square(int8(4)) + sage: from numpy import int8 # optional - numpy + sage: is_square(int8(4)) # optional - numpy True sage: from gmpy2 import mpz sage: is_square(mpz(4)) @@ -2912,7 +2916,7 @@ def is_square(n, root=False): Tests with Polynomial:: sage: R. = LaurentPolynomialRing(QQ, 'v') - sage: H = IwahoriHeckeAlgebra('A3', v**2) + sage: H = IwahoriHeckeAlgebra('A3', v**2) # optional - sage.combinat sage.modules sage: R. = QQ[] sage: p = a*b + c*d*a*d*a + 5 sage: is_square(p**2) @@ -2941,47 +2945,47 @@ def is_squarefree(n): EXAMPLES:: - sage: is_squarefree(100) + sage: is_squarefree(100) # optional - sage.libs.pari False - sage: is_squarefree(101) + sage: is_squarefree(101) # optional - sage.libs.pari True sage: R = ZZ['x'] sage: x = R.gen() - sage: is_squarefree((x^2+x+1) * (x-2)) + sage: is_squarefree((x^2+x+1) * (x-2)) # optional - sage.libs.pari True - sage: is_squarefree((x-1)**2 * (x-3)) + sage: is_squarefree((x-1)**2 * (x-3)) # optional - sage.libs.pari False - sage: O = ZZ[sqrt(-1)] - sage: I = O.gen(1) - sage: is_squarefree(I+1) + sage: O = ZZ[sqrt(-1)] # optional - sage.rings.number_field sage.symbolic + sage: I = O.gen(1) # optional - sage.rings.number_field sage.symbolic + sage: is_squarefree(I + 1) # optional - sage.rings.number_field sage.symbolic True - sage: is_squarefree(O(2)) + sage: is_squarefree(O(2)) # optional - sage.rings.number_field sage.symbolic False - sage: O(2).factor() + sage: O(2).factor() # optional - sage.rings.number_field sage.symbolic (-I) * (I + 1)^2 This method fails on domains which are not Unique Factorization Domains:: - sage: O = ZZ[sqrt(-5)] - sage: a = O.gen(1) - sage: is_squarefree(a - 3) + sage: O = ZZ[sqrt(-5)] # optional - sage.rings.number_field sage.symbolic + sage: a = O.gen(1) # optional - sage.rings.number_field sage.symbolic + sage: is_squarefree(a - 3) # optional - sage.rings.number_field sage.symbolic Traceback (most recent call last): ... ArithmeticError: non-principal ideal in factorization Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: is_squarefree(int8(100)) + sage: from numpy import int8 # optional - numpy + sage: is_squarefree(int8(100)) # optional - numpy sage.libs.pari False - sage: is_squarefree(int8(101)) + sage: is_squarefree(int8(101)) # optional - numpy sage.libs.pari True sage: from gmpy2 import mpz - sage: is_squarefree(mpz(100)) + sage: is_squarefree(mpz(100)) # optional - sage.libs.pari False - sage: is_squarefree(mpz(101)) + sage: is_squarefree(mpz(101)) # optional - sage.libs.pari True """ e = py_scalar_to_element(n) @@ -3018,11 +3022,11 @@ class Euler_Phi: 1 sage: euler_phi(2) 1 - sage: euler_phi(3) + sage: euler_phi(3) # optional - sage.libs.pari 2 - sage: euler_phi(12) + sage: euler_phi(12) # optional - sage.libs.pari 4 - sage: euler_phi(37) + sage: euler_phi(37) # optional - sage.libs.pari 36 Notice that euler_phi is defined to be 0 on negative numbers and @@ -3041,7 +3045,7 @@ class Euler_Phi: :: - sage: euler_phi(21) + sage: euler_phi(21) # optional - sage.libs.pari 12 sage: [i for i in range(21) if gcd(21,i) == 1] [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] @@ -3051,22 +3055,22 @@ class Euler_Phi: :: - sage: len([i for i in range(21) if gcd(21,i) == 1]) == euler_phi(21) + sage: len([i for i in range(21) if gcd(21,i) == 1]) == euler_phi(21) # optional - sage.libs.pari True The phi function also has a special plotting method. :: - sage: P = plot(euler_phi, -3, 71) + sage: P = plot(euler_phi, -3, 71) # optional - sage.libs.pari sage.plot Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: euler_phi(int8(37)) + sage: from numpy import int8 # optional - numpy + sage: euler_phi(int8(37)) # optional - numpy sage.libs.pari sage.plot 36 sage: from gmpy2 import mpz - sage: euler_phi(mpz(37)) + sage: euler_phi(mpz(37)) # optional - sage.libs.pari sage.plot 36 AUTHORS: @@ -3094,9 +3098,9 @@ def __call__(self, n): EXAMPLES:: sage: from sage.arith.misc import Euler_Phi - sage: Euler_Phi()(10) + sage: Euler_Phi()(10) # optional - sage.libs.pari 4 - sage: Euler_Phi()(720) + sage: Euler_Phi()(720) # optional - sage.libs.pari 192 """ if n <= 0: @@ -3130,8 +3134,8 @@ def plot(self, xmin=1, xmax=50, pointsize=30, rgbcolor=(0, 0, 1), EXAMPLES:: sage: from sage.arith.misc import Euler_Phi - sage: p = Euler_Phi().plot() - sage: p.ymax() + sage: p = Euler_Phi().plot() # optional - sage.plot + sage: p.ymax() # optional - sage.plot 46.0 """ v = [(n, euler_phi(n)) for n in range(xmin, xmax + 1)] @@ -3187,7 +3191,7 @@ def carmichael_lambda(n): The Carmichael function of the first ten primes:: - sage: list(map(carmichael_lambda, primes_first_n(10))) + sage: list(map(carmichael_lambda, primes_first_n(10))) # optional - sage.libs.pari [1, 2, 4, 6, 10, 12, 16, 18, 22, 28] Cases where the Carmichael function is equivalent to the Euler phi @@ -3195,19 +3199,19 @@ def carmichael_lambda(n): sage: carmichael_lambda(2) == euler_phi(2) True - sage: carmichael_lambda(4) == euler_phi(4) + sage: carmichael_lambda(4) == euler_phi(4) # optional - sage.libs.pari True - sage: p = random_prime(1000, lbound=3, proof=True) + sage: p = random_prime(1000, lbound=3, proof=True) # optional - sage.libs.pari sage: k = randint(1, 1000) - sage: carmichael_lambda(p^k) == euler_phi(p^k) + sage: carmichael_lambda(p^k) == euler_phi(p^k) # optional - sage.libs.pari True A case where `\lambda(n) \neq \varphi(n)`:: sage: k = randint(3, 1000) - sage: carmichael_lambda(2^k) == 2^(k - 2) + sage: carmichael_lambda(2^k) == 2^(k - 2) # optional - sage.libs.pari True - sage: carmichael_lambda(2^k) == 2^(k - 2) == euler_phi(2^k) + sage: carmichael_lambda(2^k) == 2^(k - 2) == euler_phi(2^k) # optional - sage.libs.pari False Verifying the current implementation of the Carmichael function using @@ -3217,7 +3221,7 @@ def carmichael_lambda(n): sage: from sage.arith.misc import carmichael_lambda sage: n = randint(1, 500) - sage: c = carmichael_lambda(n) + sage: c = carmichael_lambda(n) # optional - sage.libs.pari sage: def coprime(n): ....: return [i for i in range(n) if gcd(i, n) == 1] sage: def znpower(n, k): @@ -3232,7 +3236,7 @@ def carmichael_lambda(n): ....: T = [L[i] == ones[i] for i in range(len(L))] ....: if all(T): ....: return k - sage: c == my_carmichael(n) + sage: c == my_carmichael(n) # optional - sage.libs.pari True Carmichael's theorem states that `a^{\lambda(n)} \equiv 1 \pmod{n}` @@ -3241,12 +3245,12 @@ def carmichael_lambda(n): sage: from sage.arith.misc import carmichael_lambda sage: n = randint(2, 1000) - sage: c = carmichael_lambda(n) + sage: c = carmichael_lambda(n) # optional - sage.libs.pari sage: ZnZ = IntegerModRing(n) sage: M = ZnZ.list_of_elements_of_multiplicative_group() sage: ones = [1] * len(M) - sage: P = [power_mod(a, c, n) for a in M] - sage: P == ones + sage: P = [power_mod(a, c, n) for a in M] # optional - sage.libs.pari + sage: P == ones # optional - sage.libs.pari True TESTS: @@ -3266,7 +3270,7 @@ def carmichael_lambda(n): Bug reported in :trac:`8283`:: sage: from sage.arith.misc import carmichael_lambda - sage: type(carmichael_lambda(16)) + sage: type(carmichael_lambda(16)) # optional - sage.libs.pari REFERENCES: @@ -3354,44 +3358,48 @@ def crt(a, b, m=None, n=None): sage: g = y^3 - 5 # optional - sage.rings.number_field sage: CRT(1, 3, f, g) # optional - sage.rings.number_field -3/26*y^4 + 5/26*y^3 + 15/26*y + 53/26 - sage: CRT(1,a,f,g) + sage: CRT(1, a, f, g) # optional - sage.rings.number_field (-3/52*a + 3/52)*y^4 + (5/52*a - 5/52)*y^3 + (15/52*a - 15/52)*y + 27/52*a + 25/52 You can also do this for any number of moduli:: - sage: K. = NumberField(x^3 - 7) - sage: R. = K[] - sage: CRT([], []) + sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: CRT([], []) # optional - sage.rings.number_field 0 - sage: CRT([a], [x]) + sage: CRT([a], [x]) # optional - sage.rings.number_field a - sage: f = x^2 + 3 - sage: g = x^3 - 5 - sage: h = x^5 + x^2 - 9 - sage: k = CRT([1, a, 3], [f, g, h]); k - (127/26988*a - 5807/386828)*x^9 + (45/8996*a - 33677/1160484)*x^8 + (2/173*a - 6/173)*x^7 + (133/6747*a - 5373/96707)*x^6 + (-6/2249*a + 18584/290121)*x^5 + (-277/8996*a + 38847/386828)*x^4 + (-135/4498*a + 42673/193414)*x^3 + (-1005/8996*a + 470245/1160484)*x^2 + (-1215/8996*a + 141165/386828)*x + 621/8996*a + 836445/386828 - sage: k.mod(f) + sage: f = x^2 + 3 # optional - sage.rings.number_field + sage: g = x^3 - 5 # optional - sage.rings.number_field + sage: h = x^5 + x^2 - 9 # optional - sage.rings.number_field + sage: k = CRT([1, a, 3], [f, g, h]); k # optional - sage.rings.number_field + (127/26988*a - 5807/386828)*x^9 + (45/8996*a - 33677/1160484)*x^8 + + (2/173*a - 6/173)*x^7 + (133/6747*a - 5373/96707)*x^6 + + (-6/2249*a + 18584/290121)*x^5 + (-277/8996*a + 38847/386828)*x^4 + + (-135/4498*a + 42673/193414)*x^3 + (-1005/8996*a + 470245/1160484)*x^2 + + (-1215/8996*a + 141165/386828)*x + 621/8996*a + 836445/386828 + sage: k.mod(f) # optional - sage.rings.number_field 1 - sage: k.mod(g) + sage: k.mod(g) # optional - sage.rings.number_field a - sage: k.mod(h) + sage: k.mod(h) # optional - sage.rings.number_field 3 If the moduli are not coprime, a solution may not exist:: - sage: crt(4,8,8,12) + sage: crt(4, 8, 8, 12) 20 - sage: crt(4,6,8,12) + sage: crt(4, 6, 8, 12) Traceback (most recent call last): ... ValueError: no solution to crt problem since gcd(8,12) does not divide 4-6 sage: x = polygen(QQ) - sage: crt(2,3,x-1,x+1) + sage: crt(2, 3, x - 1, x + 1) -1/2*x + 5/2 - sage: crt(2,x,x^2-1,x^2+1) + sage: crt(2, x, x^2 - 1, x^2 + 1) -1/2*x^3 + x^2 + 1/2*x + 1 - sage: crt(2,x,x^2-1,x^3-1) + sage: crt(2, x, x^2 - 1, x^3 - 1) Traceback (most recent call last): ... ValueError: no solution to crt problem since gcd(x^2 - 1,x^3 - 1) does not divide 2-x @@ -3401,13 +3409,13 @@ def crt(a, b, m=None, n=None): crt also work with numpy and gmpy2 numbers:: - sage: import numpy - sage: crt(numpy.int8(2), numpy.int8(3), numpy.int8(7), numpy.int8(11)) + sage: import numpy # optional - numpy + sage: crt(numpy.int8(2), numpy.int8(3), numpy.int8(7), numpy.int8(11)) # optional - numpy 58 sage: from gmpy2 import mpz sage: crt(mpz(2), mpz(3), mpz(7), mpz(11)) 58 - sage: crt(mpz(2), 3, mpz(7), numpy.int8(11)) + sage: crt(mpz(2), 3, mpz(7), numpy.int8(11)) # optional - numpy 58 """ if isinstance(a, list): @@ -3494,8 +3502,8 @@ def CRT_list(values, moduli): sage: CRT([32r,2r,2r],[60r,90r,150r]) 452 - sage: from numpy import int8 - sage: CRT_list([int8(2),int8(3),int8(2)], [int8(3),int8(5),int8(7)]) + sage: from numpy import int8 # optional - numpy + sage: CRT_list([int8(2), int8(3), int8(2)], [int8(3), int8(5), int8(7)]) # optional - numpy 23 sage: from gmpy2 import mpz sage: CRT_list([mpz(2),mpz(3),mpz(2)], [mpz(3),mpz(5),mpz(7)]) @@ -3599,7 +3607,7 @@ def CRT_vectors(X, moduli): sage: CRT_vectors([[3,5,7],[3,5,11]], [2,3]) [3, 5, 5] - sage: CRT_vectors([vector(ZZ, [2,3,1]), Sequence([1,7,8],ZZ)], [8,9]) + sage: CRT_vectors([vector(ZZ, [2,3,1]), Sequence([1,7,8], ZZ)], [8,9]) # optional - sage.modules [10, 43, 17] """ # First find the CRT basis: @@ -3641,15 +3649,15 @@ def binomial(x, m, **kwds): EXAMPLES:: sage: from sage.arith.misc import binomial - sage: binomial(5,2) + sage: binomial(5, 2) 10 - sage: binomial(2,0) + sage: binomial(2, 0) 1 - sage: binomial(1/2, 0) + sage: binomial(1/2, 0) # optional - sage.libs.pari 1 - sage: binomial(3,-1) + sage: binomial(3, -1) 0 - sage: binomial(20,10) + sage: binomial(20, 10) 184756 sage: binomial(-2, 5) -6 @@ -3657,11 +3665,11 @@ def binomial(x, m, **kwds): 0 sage: binomial(RealField()('2.5'), 2) 1.87500000000000 - sage: n=var('n'); binomial(n,2) + sage: n = var('n'); binomial(n, 2) # optional - sage.symbolic 1/2*(n - 1)*n - sage: n=var('n'); binomial(n,n) + sage: n = var('n'); binomial(n, n) # optional - sage.symbolic 1 - sage: n=var('n'); binomial(n,n-1) + sage: n = var('n'); binomial(n, n - 1) # optional - sage.symbolic n sage: binomial(2^100, 2^100) 1 @@ -3669,7 +3677,7 @@ def binomial(x, m, **kwds): sage: x = polygen(ZZ) sage: binomial(x, 3) 1/6*x^3 - 1/2*x^2 + 1/3*x - sage: binomial(x, x-3) + sage: binomial(x, x - 3) 1/6*x^3 - 1/2*x^2 + 1/3*x If `x \in \ZZ`, there is an optional 'algorithm' parameter, which @@ -3690,21 +3698,21 @@ def binomial(x, m, **kwds): We test conversion of arguments to Integers -- see :trac:`6870`:: - sage: binomial(1/2,1/1) + sage: binomial(1/2, 1/1) 1/2 - sage: binomial(10^20+1/1,10^20) + sage: binomial(10^20 + 1/1, 10^20) 100000000000000000001 - sage: binomial(SR(10**7),10**7) + sage: binomial(SR(10**7), 10**7) # optional - sage.symbolic 1 - sage: binomial(3/2,SR(1/1)) + sage: binomial(3/2, SR(1/1)) # optional - sage.symbolic 3/2 Some floating point cases -- see :trac:`7562`, :trac:`9633`, and :trac:`12448`:: - sage: binomial(1.,3) + sage: binomial(1., 3) 0.000000000000000 - sage: binomial(-2.,3) + sage: binomial(-2., 3) -4.00000000000000 sage: binomial(0.5r, 5) 0.02734375 @@ -3749,8 +3757,8 @@ def binomial(x, m, **kwds): sage: binomial(y,3).parent() Multivariate Polynomial Ring in x, y over Ring of integers modulo 7 - sage: n = var('n') - sage: binomial(n,2) + sage: n = var('n') # optional - sage.symbolic + sage: binomial(n,2) # optional - sage.symbolic 1/2*(n - 1)*n Invalid inputs:: @@ -3761,8 +3769,8 @@ def binomial(x, m, **kwds): ... TypeError: either m or x-m must be an integer - sage: k, i = var('k,i') - sage: binomial(k,i) + sage: k, i = var('k,i') # optional - sage.symbolic + sage: binomial(k,i) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: either m or x-m must be an integer @@ -3799,15 +3807,15 @@ def binomial(x, m, **kwds): :func:`~sage.functions.other.binomial` from the module :mod:`sage.functions.other`:: - sage: from sage.functions.other import binomial - sage: binomial(k, i) + sage: from sage.functions.other import binomial # optional - sage.symbolic + sage: binomial(k, i) # optional - sage.symbolic binomial(k, i) binomial support numpy and gmpy2 parameters:: sage: from sage.arith.misc import binomial - sage: import numpy - sage: binomial(numpy.int32(20), numpy.int32(10)) + sage: import numpy # optional - numpy + sage: binomial(numpy.int32(20), numpy.int32(10)) # optional - numpy 184756 sage: import gmpy2 sage: binomial(gmpy2.mpz(20), gmpy2.mpz(10)) @@ -3888,17 +3896,17 @@ def multinomial(*ks): 618970023101454657175683075 sage: multinomial([2^30, 2, 1]) 618970023101454657175683075 - sage: multinomial(Composition([1, 3])) + sage: multinomial(Composition([1, 3])) # optional - sage.combinat 4 - sage: multinomial(Partition([4, 2])) + sage: multinomial(Partition([4, 2])) # optional - sage.combinat 15 TESTS: Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: multinomial(int8(3), int8(2)) + sage: from numpy import int8 # optional - numpy + sage: multinomial(int8(3), int8(2)) # optional - numpy 10 sage: from gmpy2 import mpz sage: multinomial(mpz(3), mpz(2)) @@ -3954,8 +3962,8 @@ def binomial_coefficients(n): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: sorted(binomial_coefficients(int8(3)).items()) + sage: from numpy import int8 # optional - numpy + sage: sorted(binomial_coefficients(int8(3)).items()) # optional - numpy [((0, 3), 1), ((1, 2), 3), ((2, 1), 3), ((3, 0), 1)] sage: from gmpy2 import mpz sage: sorted(binomial_coefficients(mpz(3)).items()) @@ -4031,8 +4039,8 @@ def multinomial_coefficients(m, n): {(): 1} sage: multinomial_coefficients(0, 3) {} - sage: from numpy import int8 - sage: sorted(multinomial_coefficients(int8(2), int8(5)).items()) + sage: from numpy import int8 # optional - numpy + sage: sorted(multinomial_coefficients(int8(2), int8(5)).items()) # optional - numpy [((0, 5), 1), ((1, 4), 5), ((2, 3), 10), ((3, 2), 10), ((4, 1), 5), ((5, 0), 1)] sage: from gmpy2 import mpz sage: sorted(multinomial_coefficients(mpz(2), mpz(5)).items()) @@ -4120,8 +4128,8 @@ def kronecker_symbol(x,y): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: kronecker_symbol(int8(13),int8(21)) + sage: from numpy import int8 # optional - numpy + sage: kronecker_symbol(int8(13),int8(21)) # optional - numpy -1 sage: from gmpy2 import mpz sage: kronecker_symbol(mpz(13),mpz(21)) @@ -4172,8 +4180,8 @@ def legendre_symbol(x, p): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: legendre_symbol(int8(2),int8(3)) + sage: from numpy import int8 # optional - numpy + sage: legendre_symbol(int8(2), int8(3)) # optional - numpy -1 sage: from gmpy2 import mpz sage: legendre_symbol(mpz(2),mpz(3)) @@ -4228,8 +4236,8 @@ def jacobi_symbol(a, b): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: jacobi_symbol(int16(10),int16(777)) + sage: from numpy import int16 # optional - numpy + sage: jacobi_symbol(int16(10), int16(777)) # optional - numpy -1 sage: from gmpy2 import mpz sage: jacobi_symbol(mpz(10),mpz(777)) @@ -4264,15 +4272,15 @@ def primitive_root(n, check=True): EXAMPLES:: - sage: primitive_root(23) + sage: primitive_root(23) # optional - sage.libs.pari 5 - sage: primitive_root(-46) + sage: primitive_root(-46) # optional - sage.libs.pari 5 - sage: primitive_root(25) + sage: primitive_root(25) # optional - sage.libs.pari 2 - sage: print([primitive_root(p) for p in primes(100)]) + sage: print([primitive_root(p) for p in primes(100)]) # optional - sage.libs.pari [1, 2, 2, 3, 2, 2, 3, 2, 5, 2, 3, 2, 6, 3, 5, 2, 2, 2, 2, 7, 5, 3, 2, 3, 5] - sage: primitive_root(8) + sage: primitive_root(8) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no primitive root @@ -4288,57 +4296,57 @@ def primitive_root(n, check=True): :: sage: n = 10^50 + 151 # a prime - sage: primitive_root(n) + sage: primitive_root(n) # optional - sage.libs.pari 11 - sage: primitive_root(n, check=False) + sage: primitive_root(n, check=False) # optional - sage.libs.pari 11 TESTS: Various special cases:: - sage: primitive_root(-1) + sage: primitive_root(-1) # optional - sage.libs.pari 0 - sage: primitive_root(0) + sage: primitive_root(0) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no primitive root - sage: primitive_root(1) + sage: primitive_root(1) # optional - sage.libs.pari 0 - sage: primitive_root(2) + sage: primitive_root(2) # optional - sage.libs.pari 1 - sage: primitive_root(3) + sage: primitive_root(3) # optional - sage.libs.pari 2 - sage: primitive_root(4) + sage: primitive_root(4) # optional - sage.libs.pari 3 We test that various numbers without primitive roots give an error - see :trac:`10836`:: - sage: primitive_root(15) + sage: primitive_root(15) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no primitive root - sage: primitive_root(16) + sage: primitive_root(16) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no primitive root - sage: primitive_root(1729) + sage: primitive_root(1729) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no primitive root - sage: primitive_root(4*7^8) + sage: primitive_root(4*7^8) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no primitive root Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: primitive_root(int8(-46)) + sage: from numpy import int8 # optional - numpy + sage: primitive_root(int8(-46)) # optional - numpy sage.libs.pari 5 sage: from gmpy2 import mpz - sage: primitive_root(mpz(-46)) + sage: primitive_root(mpz(-46)) # optional - sage.libs.pari 5 """ from sage.libs.pari.all import pari @@ -4374,29 +4382,29 @@ def nth_prime(n): EXAMPLES:: - sage: nth_prime(3) + sage: nth_prime(3) # optional - sage.libs.pari 5 - sage: nth_prime(10) + sage: nth_prime(10) # optional - sage.libs.pari 29 - sage: nth_prime(10^7) + sage: nth_prime(10^7) # optional - sage.libs.pari 179424673 :: - sage: nth_prime(0) + sage: nth_prime(0) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: nth prime meaningless for non-positive n (=0) TESTS:: - sage: all(prime_pi(nth_prime(j)) == j for j in range(1, 1000, 10)) + sage: all(prime_pi(nth_prime(j)) == j for j in range(1, 1000, 10)) # optional - sage.libs.pari True - sage: from numpy import int8 - sage: nth_prime(int8(10)) + sage: from numpy import int8 # optional - numpy + sage: nth_prime(int8(10)) # optional - numpy sage.libs.pari 29 sage: from gmpy2 import mpz - sage: nth_prime(mpz(10)) + sage: nth_prime(mpz(10)) # optional - sage.libs.pari 29 """ if n <= 0: @@ -4427,8 +4435,8 @@ def quadratic_residues(n): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: quadratic_residues(int8(11)) + sage: from numpy import int8 # optional - numpy + sage: quadratic_residues(int8(11)) # optional - numpy [0, 1, 3, 4, 5, 9] sage: from gmpy2 import mpz sage: quadratic_residues(mpz(11)) @@ -4462,39 +4470,39 @@ class Moebius: EXAMPLES:: - sage: moebius(-5) + sage: moebius(-5) # optional - sage.libs.pari -1 - sage: moebius(9) + sage: moebius(9) # optional - sage.libs.pari 0 - sage: moebius(12) + sage: moebius(12) # optional - sage.libs.pari 0 - sage: moebius(-35) + sage: moebius(-35) # optional - sage.libs.pari 1 - sage: moebius(-1) + sage: moebius(-1) # optional - sage.libs.pari 1 - sage: moebius(7) + sage: moebius(7) # optional - sage.libs.pari -1 :: - sage: moebius(0) # potentially nonstandard! + sage: moebius(0) # potentially nonstandard! # optional - sage.libs.pari 0 The moebius function even makes sense for non-integer inputs. :: - sage: x = GF(7)['x'].0 - sage: moebius(x+2) + sage: x = GF(7)['x'].0 # optional - sage.libs.pari + sage: moebius(x + 2) # optional - sage.libs.pari -1 Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: moebius(int8(-5)) + sage: from numpy import int8 # optional - numpy + sage: moebius(int8(-5)) # optional - numpy sage.libs.pari -1 sage: from gmpy2 import mpz - sage: moebius(mpz(-5)) + sage: moebius(mpz(-5)) # optional - sage.libs.pari -1 """ def __call__(self, n): @@ -4502,7 +4510,7 @@ def __call__(self, n): EXAMPLES:: sage: from sage.arith.misc import Moebius - sage: Moebius().__call__(7) + sage: Moebius().__call__(7) # optional - sage.libs.pari -1 """ n = py_scalar_to_element(n) @@ -4560,8 +4568,8 @@ def plot(self, xmin=0, xmax=50, pointsize=30, rgbcolor=(0,0,1), join=True, EXAMPLES:: sage: from sage.arith.misc import Moebius - sage: p = Moebius().plot() - sage: p.ymax() + sage: p = Moebius().plot() # optional - sage.plot + sage: p.ymax() # optional - sage.plot 1.0 """ values = self.range(xmin, xmax + 1) @@ -4583,12 +4591,12 @@ def range(self, start, stop=None, step=None): EXAMPLES:: - sage: v = moebius.range(-10,10); v + sage: v = moebius.range(-10, 10); v # optional - sage.libs.pari [1, 0, 0, -1, 1, -1, 0, -1, -1, 1, 0, 1, -1, -1, 0, -1, 1, -1, 0, 0] - sage: v == [moebius(n) for n in range(-10,10)] + sage: v == [moebius(n) for n in range(-10, 10)] # optional - sage.libs.pari True - sage: v = moebius.range(-1000, 2000, 4) - sage: v == [moebius(n) for n in range(-1000,2000, 4)] + sage: v = moebius.range(-1000, 2000, 4) # optional - sage.libs.pari + sage: v == [moebius(n) for n in range(-1000, 2000, 4)] # optional - sage.libs.pari True """ if stop is None: @@ -4652,14 +4660,15 @@ def continuant(v, n=None): sage: q = continuant([1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10]) sage: p/q 517656/190435 - sage: continued_fraction([2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10]).convergent(14) + sage: F = continued_fraction([2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10]) + sage: F.convergent(14) # optional - sage.libs.pari 517656/190435 - sage: x = PolynomialRing(RationalField(),'x',5).gens() + sage: x = PolynomialRing(RationalField(), 'x', 5).gens() sage: continuant(x) x0*x1*x2*x3*x4 + x0*x1*x2 + x0*x1*x4 + x0*x3*x4 + x2*x3*x4 + x0 + x2 + x4 sage: continuant(x, 3) x0*x1*x2 + x0 + x2 - sage: continuant(x,2) + sage: continuant(x, 2) x0*x1 + 1 We verify the identity @@ -4671,7 +4680,7 @@ def continuant(v, n=None): for `n = 6` using polynomial arithmetic:: sage: z = QQ['z'].0 - sage: continuant((z,z,z,z,z,z,z,z,z,z,z,z,z,z,z),6) + sage: continuant((z,z,z,z,z,z,z,z,z,z,z,z,z,z,z), 6) z^6 + 5*z^4 + 6*z^2 + 1 sage: continuant(9) @@ -4681,11 +4690,11 @@ def continuant(v, n=None): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: continuant([int8(1),int8(2),int8(3)]) + sage: from numpy import int8 # optional - numpy + sage: continuant([int8(1), int8(2), int8(3)]) # optional - numpy 10 sage: from gmpy2 import mpz - sage: continuant([mpz(1),mpz(2),mpz(3)]) + sage: continuant([mpz(1), mpz(2), mpz(3)]) mpz(10) AUTHORS: @@ -4719,18 +4728,18 @@ def number_of_divisors(n): EXAMPLES:: - sage: number_of_divisors(100) + sage: number_of_divisors(100) # optional - sage.libs.pari 9 - sage: number_of_divisors(-720) + sage: number_of_divisors(-720) # optional - sage.libs.pari 30 Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: number_of_divisors(int8(100)) + sage: from numpy import int8 # optional - numpy + sage: number_of_divisors(int8(100)) # optional - numpy sage.libs.pari 9 sage: from gmpy2 import mpz - sage: number_of_divisors(mpz(100)) + sage: number_of_divisors(mpz(100)) # optional - sage.libs.pari 9 """ m = ZZ(n) @@ -4768,33 +4777,33 @@ def hilbert_symbol(a, b, p, algorithm="pari"): EXAMPLES:: - sage: hilbert_symbol (-1, -1, -1, algorithm='all') + sage: hilbert_symbol(-1, -1, -1, algorithm='all') # optional - sage.libs.pari -1 - sage: hilbert_symbol (2,3, 5, algorithm='all') + sage: hilbert_symbol(2, 3, 5, algorithm='all') # optional - sage.libs.pari 1 - sage: hilbert_symbol (4, 3, 5, algorithm='all') + sage: hilbert_symbol(4, 3, 5, algorithm='all') # optional - sage.libs.pari 1 - sage: hilbert_symbol (0, 3, 5, algorithm='all') + sage: hilbert_symbol(0, 3, 5, algorithm='all') # optional - sage.libs.pari 0 - sage: hilbert_symbol (-1, -1, 2, algorithm='all') + sage: hilbert_symbol(-1, -1, 2, algorithm='all') # optional - sage.libs.pari -1 - sage: hilbert_symbol (1, -1, 2, algorithm='all') + sage: hilbert_symbol(1, -1, 2, algorithm='all') # optional - sage.libs.pari 1 - sage: hilbert_symbol (3, -1, 2, algorithm='all') + sage: hilbert_symbol(3, -1, 2, algorithm='all') # optional - sage.libs.pari -1 - sage: hilbert_symbol(QQ(-1)/QQ(4), -1, 2) == -1 + sage: hilbert_symbol(QQ(-1)/QQ(4), -1, 2) == -1 # optional - sage.libs.pari True - sage: hilbert_symbol(QQ(-1)/QQ(4), -1, 3) == 1 + sage: hilbert_symbol(QQ(-1)/QQ(4), -1, 3) == 1 # optional - sage.libs.pari True Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: hilbert_symbol(int8(2),int8(3),int8(5),algorithm='all') + sage: from numpy import int8 # optional - numpy + sage: hilbert_symbol(int8(2), int8(3), int8(5), algorithm='all') # optional - numpy sage.libs.pari 1 sage: from gmpy2 import mpz - sage: hilbert_symbol(mpz(2),mpz(3),mpz(5),algorithm='all') + sage: hilbert_symbol(mpz(2), mpz(3), mpz(5), algorithm='all') # optional - sage.libs.pari 1 AUTHORS: @@ -4873,22 +4882,22 @@ def hilbert_conductor(a, b): EXAMPLES:: - sage: hilbert_conductor(-1, -1) + sage: hilbert_conductor(-1, -1) # optional - sage.libs.pari 2 - sage: hilbert_conductor(-1, -11) + sage: hilbert_conductor(-1, -11) # optional - sage.libs.pari 11 - sage: hilbert_conductor(-2, -5) + sage: hilbert_conductor(-2, -5) # optional - sage.libs.pari 5 - sage: hilbert_conductor(-3, -17) + sage: hilbert_conductor(-3, -17) # optional - sage.libs.pari 17 Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: hilbert_conductor(int8(-3), int8(-17)) + sage: from numpy import int8 # optional - numpy + sage: hilbert_conductor(int8(-3), int8(-17)) # optional - numpy sage.libs.pari 17 sage: from gmpy2 import mpz - sage: hilbert_conductor(mpz(-3), mpz(-17)) + sage: hilbert_conductor(mpz(-3), mpz(-17)) # optional - sage.libs.pari 17 AUTHOR: @@ -4916,19 +4925,19 @@ def hilbert_conductor_inverse(d): EXAMPLES:: - sage: hilbert_conductor_inverse(2) + sage: hilbert_conductor_inverse(2) # optional - sage.libs.pari (-1, -1) - sage: hilbert_conductor_inverse(3) + sage: hilbert_conductor_inverse(3) # optional - sage.libs.pari (-1, -3) - sage: hilbert_conductor_inverse(6) + sage: hilbert_conductor_inverse(6) # optional - sage.libs.pari (-1, 3) - sage: hilbert_conductor_inverse(30) + sage: hilbert_conductor_inverse(30) # optional - sage.libs.pari (-3, -10) - sage: hilbert_conductor_inverse(4) + sage: hilbert_conductor_inverse(4) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: d needs to be squarefree - sage: hilbert_conductor_inverse(-1) + sage: hilbert_conductor_inverse(-1) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: d needs to be positive @@ -4939,18 +4948,18 @@ def hilbert_conductor_inverse(d): TESTS:: - sage: for i in range(100): + sage: for i in range(100): # optional - sage.libs.pari ....: d = ZZ.random_element(2**32).squarefree_part() ....: if hilbert_conductor(*hilbert_conductor_inverse(d)) != d: ....: print("hilbert_conductor_inverse failed for d = {}".format(d)) Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: hilbert_conductor_inverse(int8(30)) + sage: from numpy import int8 # optional - numpy + sage: hilbert_conductor_inverse(int8(30)) # optional - numpy sage.libs.pari (-3, -10) sage: from gmpy2 import mpz - sage: hilbert_conductor_inverse(mpz(30)) + sage: hilbert_conductor_inverse(mpz(30)) # optional - sage.libs.pari (-3, -10) """ Z = ZZ @@ -5026,25 +5035,25 @@ def falling_factorial(x, a): sage: falling_factorial(10, 3) 720 - sage: falling_factorial(10, RR('3.0')) + sage: falling_factorial(10, RR('3.0')) # optional - sage.symbolic 720.000000000000 - sage: falling_factorial(10, RR('3.3')) + sage: falling_factorial(10, RR('3.3')) # optional - sage.symbolic 1310.11633396601 sage: falling_factorial(10, 10) 3628800 sage: factorial(10) 3628800 - sage: a = falling_factorial(1+I, I); a + sage: a = falling_factorial(1 + I, I); a # optional - sage.symbolic gamma(I + 2) - sage: CC(a) + sage: CC(a) # optional - sage.symbolic 0.652965496420167 + 0.343065839816545*I - sage: falling_factorial(1+I, 4) + sage: falling_factorial(1 + I, 4) 4*I + 2 sage: falling_factorial(I, 4) -10 sage: M = MatrixSpace(ZZ, 4, 4) - sage: A = M([1,0,1,0,1,0,1,0,1,0,10,10,1,0,1,1]) + sage: A = M([1,0,1,0, 1,0,1,0, 1,0,10,10, 1,0,1,1]) sage: falling_factorial(A, 2) # A(A - I) [ 1 0 10 10] [ 1 0 10 10] @@ -5059,13 +5068,13 @@ def falling_factorial(x, a): Check that :trac:`14858` is fixed:: - sage: falling_factorial(-4, SR(2)) + sage: falling_factorial(-4, SR(2)) # optional - sage.symbolic 20 Check that :trac:`16770` is fixed:: - sage: d = var('d') - sage: parent(falling_factorial(d, 0)) + sage: d = var('d') # optional - sage.symbolic + sage: parent(falling_factorial(d, 0)) # optional - sage.symbolic Symbolic Ring Check that :trac:`20075` is fixed:: @@ -5075,8 +5084,8 @@ def falling_factorial(x, a): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: falling_factorial(int8(10), int8(3)) + sage: from numpy import int8 # optional - numpy + sage: falling_factorial(int8(10), int8(3)) # optional - numpy 720 sage: from gmpy2 import mpz sage: falling_factorial(mpz(10), mpz(3)) @@ -5151,15 +5160,15 @@ def rising_factorial(x, a): Check that :trac:`14858` is fixed:: - sage: bool(rising_factorial(-4, 2) == + sage: bool(rising_factorial(-4, 2) == # optional - sage.symbolic ....: rising_factorial(-4, SR(2)) == ....: rising_factorial(SR(-4), SR(2))) True Check that :trac:`16770` is fixed:: - sage: d = var('d') - sage: parent(rising_factorial(d, 0)) + sage: d = var('d') # optional - sage.symbolic + sage: parent(rising_factorial(d, 0)) # optional - sage.symbolic Symbolic Ring Check that :trac:`20075` is fixed:: @@ -5169,8 +5178,8 @@ def rising_factorial(x, a): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: rising_factorial(int8(10), int8(3)) + sage: from numpy import int8 # optional - numpy + sage: rising_factorial(int8(10), int8(3)) # optional - numpy 1320 sage: from gmpy2 import mpz sage: rising_factorial(mpz(10), mpz(3)) @@ -5199,15 +5208,15 @@ def integer_ceil(x): sage: integer_ceil(5.4) 6 - sage: integer_ceil(x) + sage: integer_ceil(x) # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError: computation of ceil of x not implemented Tests with numpy and gmpy2 numbers:: - sage: from numpy import float32 - sage: integer_ceil(float32(5.4)) + sage: from numpy import float32 # optional - numpy + sage: integer_ceil(float32(5.4)) # optional - numpy 6 sage: from gmpy2 import mpfr sage: integer_ceil(mpfr(5.4)) @@ -5245,15 +5254,15 @@ def integer_floor(x): sage: integer_floor(RDF(-5/2)) -3 - sage: integer_floor(x) + sage: integer_floor(x) # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError: computation of floor of x not implemented Tests with numpy and gmpy2 numbers:: - sage: from numpy import float32 - sage: integer_floor(float32(5.4)) + sage: from numpy import float32 # optional - numpy + sage: integer_floor(float32(5.4)) # optional - numpy 5 sage: from gmpy2 import mpfr sage: integer_floor(mpfr(5.4)) @@ -5309,11 +5318,11 @@ def two_squares(n): ValueError: 21 is not a sum of 2 squares sage: two_squares(21^2) (0, 21) - sage: a,b = two_squares(100000000000000000129); a,b + sage: a, b = two_squares(100000000000000000129); a, b # optional - sage.libs.pari (4418521500, 8970878873) - sage: a^2 + b^2 + sage: a^2 + b^2 # optional - sage.libs.pari 100000000000000000129 - sage: two_squares(2^222+1) + sage: two_squares(2^222 + 1) # optional - sage.libs.pari (253801659504708621991421712450521, 2583712713213354898490304645018692) sage: two_squares(0) (0, 0) @@ -5324,17 +5333,17 @@ def two_squares(n): TESTS:: - sage: for _ in range(100): + sage: for _ in range(100): # optional - sage.libs.pari ....: a = ZZ.random_element(2**16, 2**20) ....: b = ZZ.random_element(2**16, 2**20) ....: n = a**2 + b**2 - ....: aa,bb = two_squares(n) + ....: aa, bb = two_squares(n) ....: assert aa**2 + bb**2 == n Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: two_squares(int16(389)) + sage: from numpy import int16 # optional - numpy + sage: two_squares(int16(389)) # optional - numpy (10, 17) sage: from gmpy2 import mpz sage: two_squares(mpz(389)) @@ -5431,11 +5440,11 @@ def three_squares(n): (3, 24, 49) sage: three_squares(7^100) (0, 0, 1798465042647412146620280340569649349251249) - sage: three_squares(11^111-1) + sage: three_squares(11^111 - 1) # optional - sage.libs.pari (616274160655975340150706442680, 901582938385735143295060746161, 6270382387635744140394001363065311967964099981788593947233) - sage: three_squares(7 * 2^41) + sage: three_squares(7 * 2^41) # optional - sage.libs.pari (1048576, 2097152, 3145728) - sage: three_squares(7 * 2^42) + sage: three_squares(7 * 2^42) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: 30786325577728 is not a sum of 3 squares @@ -5448,18 +5457,18 @@ def three_squares(n): TESTS:: - sage: for _ in range(100): + sage: for _ in range(100): # optional - sage.libs.pari ....: a = ZZ.random_element(2**16, 2**20) ....: b = ZZ.random_element(2**16, 2**20) ....: c = ZZ.random_element(2**16, 2**20) ....: n = a**2 + b**2 + c**2 - ....: aa,bb,cc = three_squares(n) + ....: aa, bb, cc = three_squares(n) ....: assert aa**2 + bb**2 + cc**2 == n Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: three_squares(int16(389)) + sage: from numpy import int16 # optional - numpy + sage: three_squares(int16(389)) # optional - numpy (1, 8, 18) sage: from gmpy2 import mpz sage: three_squares(mpz(389)) @@ -5575,23 +5584,23 @@ def four_squares(n): (0, 0, 3, 11) sage: four_squares(1101011011004) (90, 102, 1220, 1049290) - sage: four_squares(10^100-1) + sage: four_squares(10^100 - 1) # optional - sage.libs.pari (155024616290, 2612183768627, 14142135623730950488016887, 99999999999999999999999999999999999999999999999999) - sage: for i in range(2^129, 2^129+10000): # long time + sage: for i in range(2^129, 2^129+10000): # long time # optional - sage.libs.pari ....: S = four_squares(i) ....: assert sum(x^2 for x in S) == i TESTS:: - sage: for _ in range(100): - ....: n = ZZ.random_element(2**32,2**34) - ....: aa,bb,cc,dd = four_squares(n) + sage: for _ in range(100): # optional - sage.libs.pari + ....: n = ZZ.random_element(2**32, 2**34) + ....: aa, bb, cc, dd = four_squares(n) ....: assert aa**2 + bb**2 + cc**2 + dd**2 == n Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: four_squares(int16(389)) + sage: from numpy import int16 # optional - numpy + sage: four_squares(int16(389)) # optional - numpy (0, 1, 8, 18) sage: from gmpy2 import mpz sage: four_squares(mpz(389)) @@ -5652,7 +5661,7 @@ def sum_of_k_squares(k, n): (1, 2, 5, 98) sage: sum_of_k_squares(5, 9634) (0, 1, 2, 5, 98) - sage: sum_of_k_squares(6, 11^1111-1) + sage: sum_of_k_squares(6, 11^1111 - 1) # optional - sage.libs.pari (19215400822645944253860920437586326284, 37204645194585992174252915693267578306, 3473654819477394665857484221256136567800161086815834297092488779216863122, 5860191799617673633547572610351797996721850737768032876360978911074629287841061578270832330322236796556721252602860754789786937515870682024273948, 20457423294558182494001919812379023992538802203730791019728543439765347851316366537094696896669915675685581905102118246887673397020172285247862426612188418787649371716686651256443143210952163970564228423098202682066311189439731080552623884051737264415984619097656479060977602722566383385989, 311628095411678159849237738619458396497534696043580912225334269371611836910345930320700816649653412141574887113710604828156159177769285115652741014638785285820578943010943846225597311231847997461959204894255074229895666356909071243390280307709880906261008237873840245959883405303580405277298513108957483306488193844321589356441983980532251051786704380984788999660195252373574924026139168936921591652831237741973242604363696352878914129671292072201700073286987126265965322808664802662993006926302359371379531571194266134916767573373504566621665949840469229781956838744551367172353) sage: sum_of_k_squares(7, 0) (0, 0, 0, 0, 0, 0, 0) @@ -5685,8 +5694,8 @@ def sum_of_k_squares(k, n): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int16 - sage: sum_of_k_squares(int16(2), int16(9634)) + sage: from numpy import int16 # optional - numpy + sage: sum_of_k_squares(int16(2), int16(9634)) # optional - numpy (15, 97) sage: from gmpy2 import mpz sage: sum_of_k_squares(mpz(2), mpz(9634)) @@ -5757,8 +5766,8 @@ def subfactorial(n): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: subfactorial(int8(8)) + sage: from numpy import int8 # optional - numpy + sage: subfactorial(int8(8)) # optional - numpy 14833 sage: from gmpy2 import mpz sage: subfactorial(mpz(8)) @@ -5798,10 +5807,10 @@ def is_power_of_two(n): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: is_power_of_two(int8(16)) + sage: from numpy import int8 # optional - numpy + sage: is_power_of_two(int8(16)) # optional - numpy True - sage: is_power_of_two(int8(24)) + sage: is_power_of_two(int8(24)) # optional - numpy False sage: from gmpy2 import mpz sage: is_power_of_two(mpz(16)) @@ -5818,7 +5827,7 @@ def differences(lis, n=1): EXAMPLES:: - sage: differences(prime_range(50)) + sage: differences(prime_range(50)) # optional - sage.libs.pari [1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4] sage: differences([i^2 for i in range(1,11)]) [3, 5, 7, 9, 11, 13, 15, 17, 19] @@ -5826,16 +5835,16 @@ def differences(lis, n=1): [10, 22, 40, 64, 94, 130, 172, 220, 274, 334, 400, 472, 550, 634, 724, 820, 922, 1030, 1144] sage: differences([i^3 - i^2 for i in range(1,21)], 2) [10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 100, 106, 112] - sage: differences([p - i^2 for i, p in enumerate(prime_range(50))], 3) + sage: differences([p - i^2 for i, p in enumerate(prime_range(50))], 3) # optional - sage.libs.pari [-1, 2, -4, 4, -4, 4, 0, -6, 8, -6, 0, 4] Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: differences([int8(1),int8(4),int8(6),int8(19)]) + sage: from numpy import int8 # optional - numpy + sage: differences([int8(1), int8(4), int8(6), int8(19)]) # optional - numpy [3, 2, 13] sage: from gmpy2 import mpz - sage: differences([mpz(1),mpz(4),mpz(6),mpz(19)]) + sage: differences([mpz(1), mpz(4), mpz(6), mpz(19)]) [mpz(3), mpz(2), mpz(13)] AUTHORS: @@ -5977,8 +5986,8 @@ def fundamental_discriminant(D): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: fundamental_discriminant(int8(102)) + sage: from numpy import int8 # optional - numpy + sage: fundamental_discriminant(int8(102)) # optional - numpy 408 sage: from gmpy2 import mpz sage: fundamental_discriminant(mpz(102)) @@ -6035,8 +6044,8 @@ def squarefree_divisors(x): Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: list(squarefree_divisors(int8(12))) + sage: from numpy import int8 # optional - numpy + sage: list(squarefree_divisors(int8(12))) # optional - numpy [1, 2, 3, 6] sage: from gmpy2 import mpz sage: list(squarefree_divisors(mpz(12))) @@ -6086,7 +6095,7 @@ def dedekind_sum(p, q, algorithm='default'): Several small values:: - sage: for q in range(10): print([dedekind_sum(p,q) for p in range(q+1)]) + sage: for q in range(10): print([dedekind_sum(p,q) for p in range(q+1)]) # optional - sage.libs.flint [0] [0, 0] [0, 0, 0] @@ -6100,44 +6109,44 @@ def dedekind_sum(p, q, algorithm='default'): Check relations for restricted arguments:: - sage: q = 23; dedekind_sum(1, q); (q-1)*(q-2)/(12*q) + sage: q = 23; dedekind_sum(1, q); (q-1)*(q-2)/(12*q) # optional - sage.libs.flint 77/46 77/46 sage: p, q = 100, 723 # must be coprime - sage: dedekind_sum(p, q) + dedekind_sum(q, p) + sage: dedekind_sum(p, q) + dedekind_sum(q, p) # optional - sage.libs.flint 31583/86760 - sage: -1/4 + (p/q + q/p + 1/(p*q))/12 + sage: -1/4 + (p/q + q/p + 1/(p*q))/12 # optional - sage.libs.flint 31583/86760 We check that evaluation works with large input:: - sage: dedekind_sum(3^54 - 1, 2^93 + 1) + sage: dedekind_sum(3^54 - 1, 2^93 + 1) # optional - sage.libs.flint 459340694971839990630374299870/29710560942849126597578981379 - sage: dedekind_sum(3^54 - 1, 2^93 + 1, algorithm='pari') + sage: dedekind_sum(3^54 - 1, 2^93 + 1, algorithm='pari') # optional - sage.libs.pari 459340694971839990630374299870/29710560942849126597578981379 We check consistency of the results:: - sage: dedekind_sum(5, 7, algorithm='default') + sage: dedekind_sum(5, 7, algorithm='default') # optional - sage.libs.flint -1/14 - sage: dedekind_sum(5, 7, algorithm='flint') + sage: dedekind_sum(5, 7, algorithm='flint') # optional - sage.libs.flint -1/14 - sage: dedekind_sum(5, 7, algorithm='pari') + sage: dedekind_sum(5, 7, algorithm='pari') # optional - sage.libs.pari -1/14 - sage: dedekind_sum(6, 8, algorithm='default') + sage: dedekind_sum(6, 8, algorithm='default') # optional - sage.libs.flint -1/8 - sage: dedekind_sum(6, 8, algorithm='flint') + sage: dedekind_sum(6, 8, algorithm='flint') # optional - sage.libs.flint -1/8 - sage: dedekind_sum(6, 8, algorithm='pari') + sage: dedekind_sum(6, 8, algorithm='pari') # optional - sage.libs.pari -1/8 Tests with numpy and gmpy2 numbers:: - sage: from numpy import int8 - sage: dedekind_sum(int8(5), int8(7), algorithm='default') + sage: from numpy import int8 # optional - numpy + sage: dedekind_sum(int8(5), int8(7), algorithm='default') # optional - numpy sage.libs.flint -1/14 sage: from gmpy2 import mpz - sage: dedekind_sum(mpz(5), mpz(7), algorithm='default') + sage: dedekind_sum(mpz(5), mpz(7), algorithm='default') # optional - sage.libs.flint -1/14 REFERENCES: @@ -6196,45 +6205,45 @@ def gauss_sum(char_value, finite_field): EXAMPLES:: sage: from sage.arith.misc import gauss_sum - sage: F = GF(5); q = 5 - sage: zq = UniversalCyclotomicField().zeta(q-1) - sage: L = [gauss_sum(zq**i,F) for i in range(5)]; L + sage: F = GF(5); q = 5 # optional - sage.libs.pari + sage: zq = UniversalCyclotomicField().zeta(q - 1) # optional - sage.libs.pari + sage: L = [gauss_sum(zq**i, F) for i in range(5)]; L # optional - sage.libs.pari [-1, E(20)^4 + E(20)^13 - E(20)^16 - E(20)^17, E(5) - E(5)^2 - E(5)^3 + E(5)^4, E(20)^4 - E(20)^13 - E(20)^16 + E(20)^17, -1] - sage: [g*g.conjugate() for g in L] + sage: [g*g.conjugate() for g in L] # optional - sage.libs.pari [1, 5, 5, 5, 1] - sage: F = GF(11**2); q = 11**2 - sage: zq = UniversalCyclotomicField().zeta(q-1) - sage: g = gauss_sum(zq**4,F) - sage: g*g.conjugate() + sage: F = GF(11**2); q = 11**2 # optional - sage.libs.pari + sage: zq = UniversalCyclotomicField().zeta(q - 1) # optional - sage.libs.pari + sage: g = gauss_sum(zq**4, F) # optional - sage.libs.pari + sage: g*g.conjugate() # optional - sage.libs.pari 121 TESTS:: - sage: F = GF(11); q = 11 - sage: zq = UniversalCyclotomicField().zeta(q-1) - sage: gauss_sum(zq**2,F).n(60) + sage: F = GF(11); q = 11 # optional - sage.libs.pari sage.rings.number_field + sage: zq = UniversalCyclotomicField().zeta(q - 1) # optional - sage.libs.pari sage.rings.number_field + sage: gauss_sum(zq**2, F).n(60) # optional - sage.libs.pari sage.rings.number_field 2.6361055643248352 + 2.0126965627574471*I - sage: zq = QQbar.zeta(q-1) - sage: gauss_sum(zq**2,F) + sage: zq = QQbar.zeta(q - 1) # optional - sage.libs.pari sage.rings.number_field + sage: gauss_sum(zq**2, F) # optional - sage.libs.pari sage.rings.number_field 2.636105564324836? + 2.012696562757447?*I - sage: zq = ComplexField(60).zeta(q-1) - sage: gauss_sum(zq**2,F) + sage: zq = ComplexField(60).zeta(q - 1) # optional - sage.libs.pari sage.rings.number_field + sage: gauss_sum(zq**2, F) # optional - sage.libs.pari sage.rings.number_field 2.6361055643248352 + 2.0126965627574471*I - sage: F = GF(7); q = 7 - sage: zq = QQbar.zeta(q-1) - sage: D = DirichletGroup(7, QQbar) - sage: all(D[i].gauss_sum()==gauss_sum(zq**i,F) for i in range(6)) + sage: F = GF(7); q = 7 # optional - sage.libs.pari sage.rings.number_field + sage: zq = QQbar.zeta(q - 1) # optional - sage.libs.pari sage.rings.number_field + sage: D = DirichletGroup(7, QQbar) # optional - sage.libs.pari sage.rings.number_field + sage: all(D[i].gauss_sum() == gauss_sum(zq**i, F) for i in range(6)) # optional - sage.libs.pari sage.rings.number_field True - sage: gauss_sum(1,QQ) + sage: gauss_sum(1, QQ) Traceback (most recent call last): ... ValueError: second input must be a finite field diff --git a/src/sage/arith/multi_modular.pyx b/src/sage/arith/multi_modular.pyx index 766c9923404..17505583fca 100644 --- a/src/sage/arith/multi_modular.pyx +++ b/src/sage/arith/multi_modular.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - primecountpy """ Utility classes for multi-modular algorithms """ diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index b90d97e0f02..4637e239dce 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -432,16 +432,16 @@ cdef class PrecomposedAction(Action): We demonstrate that an example discussed on :trac:`14711` did not become a problem:: - sage: E = ModularSymbols(11).2 - sage: s = E.modular_symbol_rep() - sage: del E,s - sage: import gc - sage: _ = gc.collect() - sage: E = ModularSymbols(11).2 - sage: v = E.manin_symbol_rep() - sage: c,x = v[0] - sage: y = x.modular_symbol_rep() - sage: coercion_model.get_action(QQ, parent(y), op=operator.mul) + sage: E = ModularSymbols(11).2 # optional - sage.modular + sage: s = E.modular_symbol_rep() # optional - sage.modular + sage: del E,s # optional - sage.modular + sage: import gc # optional - sage.modular + sage: _ = gc.collect() # optional - sage.modular + sage: E = ModularSymbols(11).2 # optional - sage.modular + sage: v = E.manin_symbol_rep() # optional - sage.modular + sage: c,x = v[0] # optional - sage.modular + sage: y = x.modular_symbol_rep() # optional - sage.modular + sage: coercion_model.get_action(QQ, parent(y), op=operator.mul) # optional - sage.modular Left scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field with precomposition on right by Coercion map: @@ -483,12 +483,12 @@ cdef class PrecomposedAction(Action): Check that this action can be pickled (:trac:`29031`):: - sage: E = ModularSymbols(11).2 - sage: v = E.manin_symbol_rep() - sage: c,x = v[0] - sage: y = x.modular_symbol_rep() - sage: act = coercion_model.get_action(QQ, parent(y), op=operator.mul) - sage: loads(dumps(act)) is not None + sage: E = ModularSymbols(11).2 # optional - sage.modular + sage: v = E.manin_symbol_rep() # optional - sage.modular + sage: c,x = v[0] # optional - sage.modular + sage: y = x.modular_symbol_rep() # optional - sage.modular + sage: act = coercion_model.get_action(QQ, parent(y), op=operator.mul) # optional - sage.modular + sage: loads(dumps(act)) is not None # optional - sage.modular True """ return (type(self), (self._action, self.G_precomposition, self.S_precomposition)) diff --git a/src/sage/categories/hecke_modules.py b/src/sage/categories/hecke_modules.py index 9372e88c54b..ae3d638b06b 100644 --- a/src/sage/categories/hecke_modules.py +++ b/src/sage/categories/hecke_modules.py @@ -103,7 +103,7 @@ class ParentMethods: def _Hom_(self, Y, category): r""" - Returns the homset from ``self`` to ``Y`` in the category ``category`` + Return the homset from ``self`` to ``Y`` in the category ``category`` INPUT: @@ -121,15 +121,15 @@ def _Hom_(self, Y, category): EXAMPLES:: - sage: M = ModularForms(Gamma0(7), 4) - sage: H = M._Hom_(M, category = HeckeModules(QQ)); H + sage: M = ModularForms(Gamma0(7), 4) # optional - sage.modular + sage: H = M._Hom_(M, category=HeckeModules(QQ)); H # optional - sage.modular Set of Morphisms from Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) of weight 4 over Rational Field to Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(7) of weight 4 over Rational Field in Category of Hecke modules over Rational Field - sage: H.__class__ + sage: H.__class__ # optional - sage.modular - sage: TestSuite(H).run(skip=["_test_elements", "_test_an_element", "_test_elements_eq", + sage: TestSuite(H).run(skip=["_test_elements", "_test_an_element", "_test_elements_eq", # optional - sage.modular ....: "_test_elements_eq_reflexive", "_test_elements_eq_transitive", ....: "_test_elements_eq_symmetric", "_test_elements_neq", "_test_some_elements", ....: "_test_zero", "_test_additive_associativity", @@ -142,7 +142,7 @@ def _Hom_(self, Y, category): TESTS:: - sage: H = M._Hom_(M, category = HeckeModules(GF(5))); H + sage: H = M._Hom_(M, category=HeckeModules(GF(5))); H # optional - sage.modular sage.rings.finite_rings Traceback (most recent call last): ... TypeError: Category of Hecke modules over Finite Field of size 5 diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 6554c895ff4..eba755da300 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -592,15 +592,15 @@ class Homset(Set_generic): Conversely, homsets of non-unique parents are non-unique:: - sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) - sage: H = End(P11) - sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) + sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes + sage: H = End(P11) # optional - sage.schemes + sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes False - sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) + sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) # optional - sage.schemes True - sage: loads(dumps(H)) is H + sage: loads(dumps(H)) is H # optional - sage.schemes False - sage: loads(dumps(H)) == H + sage: loads(dumps(H)) == H # optional - sage.schemes True """ def __init__(self, X, Y, category=None, base=None, check=True): diff --git a/src/sage/categories/modules_with_basis.py b/src/sage/categories/modules_with_basis.py index 9f31917cf22..85a0d50239a 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -165,7 +165,7 @@ def _call_(self, x): If ``x`` itself is not a module with basis, but there is a canonical one associated to it, the latter is returned:: - sage: CQ(AbelianVariety(Gamma0(37))) # indirect doctest # optional - sage.modules + sage: CQ(AbelianVariety(Gamma0(37))) # indirect doctest # optional - sage.modular sage.modules Vector space of dimension 4 over Rational Field """ try: diff --git a/src/sage/features/sagemath.py b/src/sage/features/sagemath.py index 7e545404de2..969747b34e8 100644 --- a/src/sage/features/sagemath.py +++ b/src/sage/features/sagemath.py @@ -63,9 +63,11 @@ def __init__(self): """ # sage.combinat will be a namespace package. # Testing whether sage.combinat itself can be imported is meaningless. + # Some modules providing basic combinatorics are already included in sagemath-categories. # Hence, we test a Python module within the package. JoinFeature.__init__(self, 'sage.combinat', - [PythonModule('sage.combinat.combination')]) + [PythonModule('sage.combinat.tableau')], + spkg='sagemath_combinat') class sage__geometry__polyhedron(PythonModule): @@ -87,7 +89,8 @@ def __init__(self): sage: isinstance(sage__geometry__polyhedron(), sage__geometry__polyhedron) True """ - PythonModule.__init__(self, 'sage.geometry.polyhedron') + PythonModule.__init__(self, 'sage.geometry.polyhedron', + spkg='sagemath_polyhedra') class sage__graphs(JoinFeature): @@ -109,7 +112,31 @@ def __init__(self): True """ JoinFeature.__init__(self, 'sage.graphs', - [PythonModule('sage.graphs.graph')]) + [PythonModule('sage.graphs.graph')], + spkg='sagemath_graphs') + + +class sage__modular(JoinFeature): + r""" + A :class:`~sage.features.Feature` describing the presence of :mod:`sage.modular`. + + EXAMPLES:: + + sage: from sage.features.sagemath import sage__modular + sage: sage__modular().is_present() # optional - sage.modular + FeatureTestResult('sage.modular', True) + """ + def __init__(self): + r""" + TESTS:: + + sage: from sage.features.sagemath import sage__modular + sage: isinstance(sage__modular(), sage__modular) + True + """ + JoinFeature.__init__(self, 'sage.modular', + [PythonModule('sage.modular.modform.eisenstein_submodule')], + spkg='sagemath_schemes') class sage__groups(JoinFeature): @@ -134,6 +161,55 @@ def __init__(self): [PythonModule('sage.groups.perm_gps.permgroup')]) +class sage__libs__flint(JoinFeature): + r""" + A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.flint` + and other modules depending on FLINT and arb. + + EXAMPLES:: + + sage: from sage.features.sagemath import sage__libs__flint + sage: sage__libs__flint().is_present() # optional - sage.libs.flint + FeatureTestResult('sage.libs.flint', True) + """ + def __init__(self): + r""" + TESTS:: + + sage: from sage.features.sagemath import sage__libs__flint + sage: isinstance(sage__libs__flint(), sage__libs__flint) + True + """ + JoinFeature.__init__(self, 'sage.libs.flint', + [PythonModule('sage.libs.flint.flint'), + PythonModule('sage.libs.arb.arith')], + spkg='sagemath_flint') + + +class sage__libs__ntl(JoinFeature): + r""" + A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.ntl` + and other modules depending on NTL and arb. + + EXAMPLES:: + + sage: from sage.features.sagemath import sage__libs__ntl + sage: sage__libs__ntl().is_present() # optional - sage.libs.ntl + FeatureTestResult('sage.libs.ntl', True) + """ + def __init__(self): + r""" + TESTS:: + + sage: from sage.features.sagemath import sage__libs__ntl + sage: isinstance(sage__libs__ntl(), sage__libs__ntl) + True + """ + JoinFeature.__init__(self, 'sage.libs.ntl', + [PythonModule('sage.libs.ntl.convert')], + spkg='sagemath_ntl') + + class sage__libs__pari(JoinFeature): r""" A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.pari`. @@ -153,7 +229,8 @@ def __init__(self): True """ JoinFeature.__init__(self, 'sage.libs.pari', - [PythonModule('sage.libs.pari.convert_sage')]) + [PythonModule('sage.libs.pari.convert_sage')], + spkg='sagemath_pari') class sage__modules(JoinFeature): @@ -175,7 +252,8 @@ def __init__(self): True """ JoinFeature.__init__(self, 'sage.modules', - [PythonModule('sage.modules.free_module')]) + [PythonModule('sage.modules.free_module')], + spkg='sagemath_modules') class sage__plot(JoinFeature): @@ -197,7 +275,8 @@ def __init__(self): True """ JoinFeature.__init__(self, 'sage.plot', - [PythonModule('sage.plot.plot')]) + [PythonModule('sage.plot.plot')], + spkg='sagemath_symbolics') class sage__rings__finite_rings(JoinFeature): @@ -290,6 +369,29 @@ def __init__(self): [PythonModule('sage.rings.padics.factory')]) +class sage__rings__polynomial__pbori(JoinFeature): + r""" + A :class:`sage.features.Feature` describing the presence of :mod:`sage.rings.polynomial.pbori`. + + EXAMPLES:: + + sage: from sage.features.sagemath import sage__rings__polynomial__pbori + sage: sage__rings__polynomial__pbori().is_present() # optional - sage.rings.polynomial.pbori + FeatureTestResult('sage.rings.polynomial.pbori', True) + """ + def __init__(self): + r""" + TESTS:: + + sage: from sage.features.sagemath import sage__rings__polynomial__pbori + sage: isinstance(sage__rings__polynomial__pbori(), sage__rings__polynomial__pbori) + True + """ + JoinFeature.__init__(self, 'sage.rings.polynomial.pbori', + [PythonModule('sage.rings.polynomial.pbori.pbori')], + spkg='sagemath_brial') + + class sage__rings__real_double(PythonModule): r""" A :class:`~sage.features.Feature` describing the presence of :mod:`sage.rings.real_double`. @@ -329,7 +431,31 @@ def __init__(self): sage: isinstance(sage__rings__real_mpfr(), sage__rings__real_mpfr) True """ - PythonModule.__init__(self, 'sage.rings.real_mpfr') + PythonModule.__init__(self, 'sage.rings.real_mpfr', + spkg='sagemath_modules') + + +class sage__schemes(JoinFeature): + r""" + A :class:`~sage.features.Feature` describing the presence of :mod:`sage.schemes`. + + EXAMPLES:: + + sage: from sage.features.sagemath import sage__schemes + sage: sage__schemes().is_present() # optional - sage.schemes + FeatureTestResult('sage.schemes', True) + """ + def __init__(self): + r""" + TESTS:: + + sage: from sage.features.sagemath import sage__schemes + sage: isinstance(sage__schemes(), sage__schemes) + True + """ + JoinFeature.__init__(self, 'sage.schemes', + [PythonModule('sage.schemes.elliptic_curves.ell_generic')], + spkg="sagemath_schemes") class sage__symbolic(JoinFeature): @@ -382,13 +508,18 @@ def all_features(): sage__geometry__polyhedron(), sage__graphs(), sage__groups(), + sage__libs__flint(), + sage__libs__ntl(), sage__libs__pari(), + sage__modular(), sage__modules(), sage__plot(), sage__rings__finite_rings(), sage__rings__function_field(), sage__rings__number_field(), sage__rings__padics(), + sage__rings__polynomial__pbori(), sage__rings__real_double(), sage__rings__real_mpfr(), + sage__schemes(), sage__symbolic()] diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index bf6aafdc2a7..6693a5be8b4 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -3707,8 +3707,9 @@ class disk_cached_function: sage: dir = tmp_dir() sage: @disk_cached_function(dir) ....: def foo(x): return ModularSymbols(x) - sage: foo(389) - Modular Symbols space of dimension 65 for Gamma_0(389) of weight 2 with sign 0 over Rational Field + sage: foo(389) # optional - sage.modular + Modular Symbols space of dimension 65 for Gamma_0(389) of weight 2 + with sign 0 over Rational Field """ return DiskCachedFunction(f, self._dir, memory_cache=self._memory_cache, key=self._key) diff --git a/src/sage/misc/functional.py b/src/sage/misc/functional.py index 9407f588848..12817b97fb2 100644 --- a/src/sage/misc/functional.py +++ b/src/sage/misc/functional.py @@ -1915,25 +1915,25 @@ def sqrt(x, *args, **kwds): EXAMPLES:: - sage: sqrt(-1) + sage: sqrt(-1) # optional - sage.symbolic I - sage: sqrt(2) + sage: sqrt(2) # optional - sage.symbolic sqrt(2) - sage: sqrt(2)^2 + sage: sqrt(2)^2 # optional - sage.symbolic 2 sage: sqrt(4) 2 - sage: sqrt(4,all=True) + sage: sqrt(4, all=True) [2, -2] - sage: sqrt(x^2) + sage: sqrt(x^2) # optional - sage.symbolic sqrt(x^2) For a non-symbolic square root, there are a few options. The best is to numerically approximate afterward:: - sage: sqrt(2).n() + sage: sqrt(2).n() # optional - sage.symbolic 1.41421356237310 - sage: sqrt(2).n(prec=100) + sage: sqrt(2).n(prec=100) # optional - sage.symbolic 1.4142135623730950488016887242 Or one can input a numerical type:: @@ -1948,9 +1948,9 @@ def sqrt(x, *args, **kwds): To prevent automatic evaluation, one can use the ``hold`` parameter after coercing to the symbolic ring:: - sage: sqrt(SR(4),hold=True) + sage: sqrt(SR(4), hold=True) # optional - sage.symbolic sqrt(4) - sage: sqrt(4,hold=True) + sage: sqrt(4, hold=True) Traceback (most recent call last): ... TypeError: ..._do_sqrt() got an unexpected keyword argument 'hold' diff --git a/src/sage/misc/latex.py b/src/sage/misc/latex.py index c915ae00e2f..e4ada89f9e8 100644 --- a/src/sage/misc/latex.py +++ b/src/sage/misc/latex.py @@ -2068,9 +2068,9 @@ def repr_lincomb(symbols, coeffs): Verify that :trac:`17299` (latex representation of modular symbols) is fixed:: - sage: x = EllipticCurve('64a1').modular_symbol_space(sign=1).basis()[0] + sage: x = EllipticCurve('64a1').modular_symbol_space(sign=1).basis()[0] # optional - sage.schemes sage: from sage.misc.latex import repr_lincomb - sage: latex(x.modular_symbol_rep()) + sage: latex(x.modular_symbol_rep()) # optional - sage.schemes \left\{\frac{-3}{11}, \frac{-1}{4}\right\} - \left\{\frac{3}{13}, \frac{1}{4}\right\} Verify that it works when the symbols are numbers:: diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index d4a6c12ed5a..ada787afa22 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -1150,7 +1150,7 @@ def get_star_imports(module_name): sage: from sage.misc.lazy_import import get_star_imports sage: 'get_star_imports' in get_star_imports('sage.misc.lazy_import') True - sage: 'EllipticCurve' in get_star_imports('sage.schemes.all') + sage: 'EllipticCurve' in get_star_imports('sage.schemes.all') # optional - sage.schemes True TESTS:: @@ -1164,7 +1164,7 @@ def get_star_imports(module_name): sage: import sage.misc.lazy_import_cache as cache sage: cache.get_cache_file = (lambda: cache_file) sage: lazy.star_imports = None - sage: lazy.get_star_imports('sage.schemes.all') + sage: lazy.get_star_imports('sage.schemes.all') # optional - sage.schemes doctest:...: UserWarning: star_imports cache is corrupted [...] sage: os.remove(cache_file) diff --git a/src/sage/misc/lazy_list.pyx b/src/sage/misc/lazy_list.pyx index 4e25ee39299..fb192443494 100644 --- a/src/sage/misc/lazy_list.pyx +++ b/src/sage/misc/lazy_list.pyx @@ -415,8 +415,9 @@ cdef class lazy_list_generic(): sage: from sage.misc.lazy_list import lazy_list sage: P = lazy_list(Primes()) - sage: P[2:143:5].list() - [5, 19, 41, 61, 83, 107, 137, 163, 191, 223, 241, 271, 307, 337, 367, 397, 431, 457, 487, 521, 563, 593, 617, 647, 677, 719, 751, 787, 823] + sage: P[2:143:5].list() # optional - sage.libs.pari + [5, 19, 41, 61, 83, 107, 137, 163, 191, 223, 241, 271, 307, 337, 367, + 397, 431, 457, 487, 521, 563, 593, 617, 647, 677, 719, 751, 787, 823] sage: P = lazy_list(iter([1,2,3])) sage: P.list() [1, 2, 3] @@ -453,9 +454,9 @@ cdef class lazy_list_generic(): start 10 stop 21474838 step 4 - sage: P[0] + sage: P[0] # optional - sage.libs.pari 31 - sage: P._info() + sage: P._info() # optional - sage.libs.pari cache length 11 start 10 stop 21474838 @@ -858,9 +859,9 @@ cdef class lazy_list_generic(): sage: from sage.misc.lazy_list import lazy_list sage: L = lazy_list(Primes())[2:] - sage: L._update_cache_up_to(4) + sage: L._update_cache_up_to(4) # optional - sage.libs.pari 0 - sage: L._info() + sage: L._info() # optional - sage.libs.pari cache length 5 start 2 stop 9223372036854775807 # 64-bit @@ -885,9 +886,9 @@ cdef class lazy_list_generic(): TESTS:: sage: from sage.misc.lazy_list import lazy_list - sage: L = lazy_list(Primes()); L + sage: L = lazy_list(Primes()); L # optional - sage.libs.pari lazy list [2, 3, 5, ...] - sage: L._get_cache_() + sage: L._get_cache_() # optional - sage.libs.pari [2, 3, 5, 7] """ return self.cache @@ -964,9 +965,9 @@ cdef class lazy_list_from_iterator(lazy_list_generic): sage: from sage.misc.lazy_list import lazy_list sage: L = lazy_list(iter(Primes()))[2:] - sage: L._update_cache_up_to(4) + sage: L._update_cache_up_to(4) # optional - sage.libs.pari 0 - sage: L._info() + sage: L._info() # optional - sage.libs.pari cache length 5 start 2 stop 9223372036854775807 # 64-bit @@ -1015,9 +1016,9 @@ cdef class lazy_list_from_function(lazy_list_generic): EXAMPLES:: sage: from sage.misc.lazy_list import lazy_list_from_function - sage: lazy_list_from_function(euler_phi) + sage: lazy_list_from_function(euler_phi) # optional - sage.libs.pari lazy list [0, 1, 1, ...] - sage: lazy_list_from_function(divisors, [None]) + sage: lazy_list_from_function(divisors, [None]) # optional - sage.libs.pari lazy list [None, [1], [1, 2], ...] TESTS:: @@ -1064,9 +1065,9 @@ cdef class lazy_list_from_function(lazy_list_generic): TESTS:: sage: from sage.misc.lazy_list import lazy_list_from_function - sage: loads(dumps(lazy_list_from_function(euler_phi))) + sage: loads(dumps(lazy_list_from_function(euler_phi))) # optional - sage.libs.pari lazy list [0, 1, 1, ...] - sage: loads(dumps(lazy_list_from_function(divisors, [None]))) + sage: loads(dumps(lazy_list_from_function(divisors, [None]))) # optional - sage.libs.pari lazy list [None, [1], [1, 2], ...] """ if self.start != 0 or self.step != 1: diff --git a/src/sage/misc/prandom.py b/src/sage/misc/prandom.py index 751d5b35129..19662a47adb 100644 --- a/src/sage/misc/prandom.py +++ b/src/sage/misc/prandom.py @@ -142,9 +142,9 @@ def choice(seq): EXAMPLES:: - sage: s = [choice(list(primes(10, 100))) for i in range(5)]; s # random + sage: s = [choice(list(primes(10, 100))) for i in range(5)]; s # random # optional - sage.libs.pari [17, 47, 11, 31, 47] - sage: all(t in primes(10, 100) for t in s) + sage: all(t in primes(10, 100) for t in s) # optional - sage.libs.pari True """ return _pyrand().choice(seq) @@ -227,9 +227,9 @@ def uniform(a, b): sage: 0.0 <= s <= 1.0 True - sage: s = uniform(e, pi); s # random + sage: s = uniform(e, pi); s # random # optional - sage.symbolic 0.5143475134191677*pi + 0.48565248658083227*e - sage: bool(e <= s <= pi) + sage: bool(e <= s <= pi) # optional - sage.symbolic True """ return _pyrand().uniform(a, b) diff --git a/src/sage/misc/randstate.pyx b/src/sage/misc/randstate.pyx index e9f3db46753..f2f55bc5c2c 100644 --- a/src/sage/misc/randstate.pyx +++ b/src/sage/misc/randstate.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups sage.libs.gap sage.libs.ntl sage.libs.pari r""" Random Number States @@ -678,8 +679,8 @@ cdef class randstate: seed the generator itself. However, we put the call in to make the coverage tester happy. :: - sage: current_randstate().set_seed_ntl(False) - sage: ntl.ZZ_random(10^40) + sage: current_randstate().set_seed_ntl(False) # optional - sage.libs.ntl + sage: ntl.ZZ_random(10^40) # optional - sage.libs.ntl 1495283511775355459459209288047895196007 """ global _ntl_seed_randstate @@ -698,10 +699,10 @@ cdef class randstate: EXAMPLES:: sage: set_random_seed(99900000999) - sage: current_randstate().set_seed_gap() - sage: gap.Random(1, 10^50) + sage: current_randstate().set_seed_gap() # optional - sage.libs.gap + sage: gap.Random(1, 10^50) # optional - sage.libs.gap 1496738263332555434474532297768680634540939580077 - sage: gap(35).SCRRandomString() + sage: gap(35).SCRRandomString() # optional - sage.libs.gap [ 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1 ] """ @@ -736,8 +737,8 @@ cdef class randstate: EXAMPLES:: sage: set_random_seed(987654321) - sage: current_randstate().set_seed_gp() - sage: gp.random() + sage: current_randstate().set_seed_gp() # optional - sage.libs.pari + sage: gp.random() # optional - sage.libs.pari 23289294 """ if gp is None: @@ -783,8 +784,8 @@ cdef class randstate: EXAMPLES:: sage: set_random_seed(5551212) - sage: current_randstate().set_seed_pari() - sage: pari.getrand().type() + sage: current_randstate().set_seed_pari() # optional - sage.libs.pari + sage: pari.getrand().type() # optional - sage.libs.pari 't_INT' """ global _pari_seed_randstate diff --git a/src/sage/misc/table.py b/src/sage/misc/table.py index cbd8b083a6b..978a29f65ec 100644 --- a/src/sage/misc/table.py +++ b/src/sage/misc/table.py @@ -170,7 +170,7 @@ class table(SageObject): To generate HTML you should use ``html(table(...))``:: - sage: data = [["$x$", r"$\sin(x)$"]] + [(x,n(sin(x), digits=2)) for x in [0..3]] + sage: data = [["$x$", r"$\sin(x)$"]] + [(x, n(sin(x), digits=2)) for x in [0..3]] # optional - sage.symbolic sage: output = html(table(data, header_row=True, frame=True)) sage: type(output) diff --git a/src/sage/modules/module.pyx b/src/sage/modules/module.pyx index 180222b8b18..20c51d19079 100644 --- a/src/sage/modules/module.pyx +++ b/src/sage/modules/module.pyx @@ -186,7 +186,9 @@ cdef class Module(Parent): EXAMPLES:: - sage: sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], QQ).change_ring(GF(7)) + sage: from sage.modular.modform.space import ModularFormsSpace # optional - sage.modular + sage: ModularFormsSpace(Gamma0(11), 2, # optional - sage.modular sage.rings.finite_rings + ....: DirichletGroup(1)[0], QQ).change_ring(GF(7)) Traceback (most recent call last): ... NotImplementedError: the method change_ring() has not yet been implemented @@ -216,26 +218,31 @@ cdef class Module(Parent): TESTS:: - sage: N = ModularForms(6, 4) - sage: N.base_extend(CyclotomicField(7)) - Modular Forms space of dimension 5 for Congruence Subgroup Gamma0(6) of weight 4 over Cyclotomic Field of order 7 and degree 6 - - sage: m = ModularForms(DirichletGroup(13).0^2,2); m - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 - sage: m.base_extend(CyclotomicField(12)) - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 12 and degree 4 - - sage: chi = DirichletGroup(109, CyclotomicField(3)).0 - sage: S3 = CuspForms(chi, 2) - sage: S9 = S3.base_extend(CyclotomicField(9)) - sage: S9 - Cuspidal subspace of dimension 8 of Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 9 and degree 6 - sage: S9.has_coerce_map_from(S3) # not implemented + sage: N = ModularForms(6, 4) # optional - sage.modular + sage: N.base_extend(CyclotomicField(7)) # optional - sage.modular sage.rings.number_field + Modular Forms space of dimension 5 for Congruence Subgroup Gamma0(6) + of weight 4 over Cyclotomic Field of order 7 and degree 6 + + sage: m = ModularForms(DirichletGroup(13).0^2,2); m # optional - sage.modular sage.rings.number_field + Modular Forms space of dimension 3, character [zeta6] and weight 2 + over Cyclotomic Field of order 6 and degree 2 + sage: m.base_extend(CyclotomicField(12)) # optional - sage.modular sage.rings.number_field + Modular Forms space of dimension 3, character [zeta6] and weight 2 + over Cyclotomic Field of order 12 and degree 4 + + sage: chi = DirichletGroup(109, CyclotomicField(3)).0 # optional - sage.modular sage.rings.number_field + sage: S3 = CuspForms(chi, 2) # optional - sage.modular sage.rings.number_field + sage: S9 = S3.base_extend(CyclotomicField(9)); S9 # optional - sage.modular sage.rings.number_field + Cuspidal subspace of dimension 8 of + Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 + over Cyclotomic Field of order 9 and degree 6 + sage: S9.has_coerce_map_from(S3) # not implemented # optional - sage.modular sage.rings.number_field True - sage: S9.base_extend(CyclotomicField(3)) + sage: S9.base_extend(CyclotomicField(3)) # optional - sage.modular sage.rings.number_field Traceback (most recent call last): ... - TypeError: Base extension of self (over 'Cyclotomic Field of order 9 and degree 6') to ring 'Cyclotomic Field of order 3 and degree 2' not defined. + TypeError: Base extension of self (over 'Cyclotomic Field of order 9 and degree 6') + to ring 'Cyclotomic Field of order 3 and degree 2' not defined. """ if R.has_coerce_map_from(self.base_ring()): @@ -252,7 +259,10 @@ cdef class Module(Parent): sage: from sage.modules.module import Module sage: M = Module(ZZ) sage: M.endomorphism_ring() - Set of Morphisms from to in Category of modules over Integer Ring + Set of Morphisms + from + to + in Category of modules over Integer Ring """ from sage.categories.homset import End return End(self) diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index f20e3fcf884..8f5edb766e9 100644 --- a/src/sage/structure/category_object.pyx +++ b/src/sage/structure/category_object.pyx @@ -36,14 +36,14 @@ This example illustrates generators for a free module over `\ZZ`. :: - sage: M = FreeModule(ZZ, 4) - sage: M + sage: M = FreeModule(ZZ, 4) # optional - sage.modules + sage: M # optional - sage.modules Ambient free module of rank 4 over the principal ideal domain Integer Ring - sage: M.ngens() + sage: M.ngens() # optional - sage.modules 4 - sage: M.gen(0) + sage: M.gen(0) # optional - sage.modules (1, 0, 0, 0) - sage: M.gens() + sage: M.gens() # optional - sage.modules ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) """ @@ -270,8 +270,8 @@ cdef class CategoryObject(SageObject): EXAMPLES:: - sage: B. = BooleanPolynomialRing() - sage: B.gens_dict() + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: B.gens_dict() # optional - sage.rings.polynomial.pbori {'a': a, 'b': b, 'c': c, 'd': d} TESTS:: @@ -351,16 +351,16 @@ cdef class CategoryObject(SageObject): For orders, we correctly use the ring generator, see :trac:`15348`:: - sage: A. = ZZ.extension(x^2 + 1) - sage: i + sage: A. = ZZ.extension(x^2 + 1) # optional - sage.rings.number_field + sage: i # optional - sage.rings.number_field i - sage: parent(i) + sage: parent(i) # optional - sage.rings.number_field Order in Number Field in i with defining polynomial x^2 + 1 :: - sage: B. = EquationOrder(x^2 + 3) - sage: z.minpoly() + sage: B. = EquationOrder(x^2 + 3) # optional - sage.rings.number_field + sage: z.minpoly() # optional - sage.rings.number_field x^2 + 3 """ return self._defining_names()[:n] @@ -388,18 +388,18 @@ cdef class CategoryObject(SageObject): For orders, we correctly use the ring generator, see :trac:`15348`:: - sage: B. = EquationOrder(x^2 + 3) - sage: B._defining_names() + sage: B. = EquationOrder(x^2 + 3) # optional - sage.rings.number_field + sage: B._defining_names() # optional - sage.rings.number_field (z,) For vector spaces and free modules, we get a basis (which can be different from the given generators):: - sage: V = ZZ^3 - sage: V._defining_names() + sage: V = ZZ^3 # optional - sage.modules + sage: V._defining_names() # optional - sage.modules ((1, 0, 0), (0, 1, 0), (0, 0, 1)) - sage: W = V.span([(0, 1, 0), (1/2, 1, 0)]) - sage: W._defining_names() + sage: W = V.span([(0, 1, 0), (1/2, 1, 0)]) # optional - sage.modules + sage: W._defining_names() # optional - sage.modules ((1/2, 0, 0), (0, 1, 0)) """ return self.gens() @@ -500,10 +500,10 @@ cdef class CategoryObject(SageObject): wants to print elements of the quotient of such an "unnamed" ring, an error resulted. That was fixed in :trac:`11068`:: - sage: MS = MatrixSpace(GF(5),2,2) - sage: I = MS*[MS.0*MS.1,MS.2+MS.3]*MS - sage: Q. = MS.quo(I) - sage: a #indirect doctest + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.rings.finite_rings sage.modules + sage: I = MS * [MS.0*MS.1, MS.2 + MS.3] * MS # optional - sage.rings.finite_rings sage.modules + sage: Q. = MS.quo(I) # optional - sage.rings.finite_rings sage.modules + sage: a #indirect doctest # optional - sage.rings.finite_rings sage.modules [1 0] [0 0] @@ -562,42 +562,42 @@ cdef class CategoryObject(SageObject): EXAMPLES:: - sage: from sage.modules.module import Module - sage: Module(ZZ).base_ring() + sage: from sage.modules.module import Module # optional - sage.modules + sage: Module(ZZ).base_ring() # optional - sage.modules Integer Ring - sage: F = FreeModule(ZZ,3) - sage: F.base_ring() + sage: F = FreeModule(ZZ, 3) # optional - sage.modules + sage: F.base_ring() # optional - sage.modules Integer Ring - sage: F.__class__.base_ring + sage: F.__class__.base_ring # optional - sage.modules Note that the coordinates of the elements of a module can lie in a bigger ring, the ``coordinate_ring``:: - sage: M = (ZZ^2) * (1/2) - sage: v = M([1/2, 0]) - sage: v.base_ring() + sage: M = (ZZ^2) * (1/2) # optional - sage.modules + sage: v = M([1/2, 0]) # optional - sage.modules + sage: v.base_ring() # optional - sage.modules Integer Ring - sage: parent(v[0]) + sage: parent(v[0]) # optional - sage.modules Rational Field - sage: v.coordinate_ring() + sage: v.coordinate_ring() # optional - sage.modules Rational Field More examples:: - sage: F = FreeAlgebra(QQ, 'x') - sage: F.base_ring() + sage: F = FreeAlgebra(QQ, 'x') # optional - sage.combinat sage.modules + sage: F.base_ring() # optional - sage.combinat sage.modules Rational Field - sage: F.__class__.base_ring + sage: F.__class__.base_ring # optional - sage.combinat sage.modules - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) - sage: H = Hom(E, F) - sage: H.base_ring() + sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) # optional - sage.modules + sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) # optional - sage.modules + sage: H = Hom(E, F) # optional - sage.modules + sage: H.base_ring() # optional - sage.modules Integer Ring - sage: H.__class__.base_ring + sage: H.__class__.base_ring # optional - sage.modules .. TODO:: @@ -626,7 +626,9 @@ cdef class CategoryObject(SageObject): sage: R. = PolynomialRing(QQ, 2) sage: R.Hom(QQ) - Set of Homomorphisms from Multivariate Polynomial Ring in x, y over Rational Field to Rational Field + Set of Homomorphisms + from Multivariate Polynomial Ring in x, y over Rational Field + to Rational Field Homspaces are defined for very general Sage objects, even elements of familiar rings. @@ -634,7 +636,7 @@ cdef class CategoryObject(SageObject): sage: n = 5; Hom(n,7) Set of Morphisms from 5 to 7 in Category of elements of Integer Ring - sage: z=(2/3); Hom(z,8/1) + sage: z = 2/3; Hom(z, 8/1) Set of Morphisms from 2/3 to 8 in Category of elements of Rational Field This example illustrates the optional third argument:: @@ -662,7 +664,8 @@ cdef class CategoryObject(SageObject): sage: x (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) sage: R.latex_variable_names () - ['x_{0}', 'x_{1}', 'x_{2}', 'x_{3}', 'x_{4}', 'x_{5}', 'x_{6}', 'x_{7}', 'x_{8}', 'x_{9}', 'x_{10}', 'x_{11}'] + ['x_{0}', 'x_{1}', 'x_{2}', 'x_{3}', 'x_{4}', 'x_{5}', 'x_{6}', + 'x_{7}', 'x_{8}', 'x_{9}', 'x_{10}', 'x_{11}'] sage: f = x[0]^3 + 15/3 * x[1]^10 sage: print(latex(f)) 5 x_{1}^{10} + x_{0}^{3} @@ -890,8 +893,8 @@ cdef class CategoryObject(SageObject): _test_some_elements _test_zero _test_zero_divisors - sage: F = GF(9,'a') - sage: dir(F) + sage: F = GF(9,'a') # optional - sage.rings.finite_rings + sage: dir(F) # optional - sage.rings.finite_rings [..., '__class__', ..., '_test_pickling', ..., 'extension', ...] """ diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index d5b4c12aaae..b3081701b44 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -21,9 +21,9 @@ there. For example:: Rational Field sage: b = ZZ['x'].gen(); b.parent() Univariate Polynomial Ring in x over Integer Ring - sage: a+b + sage: a + b x + 1/2 - sage: (a+b).parent() + sage: (a + b).parent() Univariate Polynomial Ring in x over Rational Field If there is a coercion (see below) from one of the parents to the other, @@ -35,9 +35,9 @@ On failure, a TypeError is always raised. Some arithmetic operations (such as multiplication) can indicate an action rather than arithmetic in a common parent. For example:: - sage: E = EllipticCurve('37a') - sage: P = E(0,0) - sage: 5*P + sage: E = EllipticCurve('37a') # optional - sage.schemes + sage: P = E(0,0) # optional - sage.schemes + sage: 5*P # optional - sage.schemes (1/4 : -5/8 : 1) where there is action of `\ZZ` on the points of `E` given by the additive @@ -254,8 +254,8 @@ cpdef py_scalar_to_element(x): ....: numpy.int64('-3'), numpy.uint64('552'), ....: numpy.float16('-1.23'), numpy.float32('-2.22'), ....: numpy.float64('-3.412'), numpy.complex64(1.2+I), - ....: numpy.complex128(-2+I)] - sage: for x in elt: + ....: numpy.complex128(-2+I)] + sage: for x in elt: # optional - numpy ....: assert py_scalar_parent(type(x)) == py_scalar_to_element(x).parent() sage: elt = [gmpy2.mpz(42), gmpy2.mpq('3/4'), @@ -364,12 +364,17 @@ def parent_is_numerical(P): EXAMPLES:: sage: from sage.structure.coerce import parent_is_numerical - sage: import gmpy2, numpy - sage: [parent_is_numerical(R) for R in [RR, CC, QQ, QuadraticField(-1), - ....: int, complex, gmpy2.mpc, numpy.complexfloating]] - [True, True, True, True, True, True, True, True] - sage: [parent_is_numerical(R) for R in [SR, QQ['x'], QQ[['x']], str]] - [False, False, False, False] + sage: import gmpy2 + sage: [parent_is_numerical(R) for R in [RR, CC, QQ, int, complex, gmpy2.mpc]] + [True, True, True, True, True, True] + sage: parent_is_numerical(QuadraticField(-1)) # optional - sage.rings.number_field + True + sage: import numpy; parent_is_numerical(numpy.complexfloating) # optional - numpy + True + sage: parent_is_numerical(SR) # optional - sage.symbolic + False + sage: [parent_is_numerical(R) for R in [QQ['x'], QQ[['x']], str]] + [False, False, False] sage: [parent_is_numerical(R) for R in [RIF, RBF, CIF, CBF]] [False, False, False, False] """ @@ -387,15 +392,22 @@ def parent_is_real_numerical(P): EXAMPLES:: sage: from sage.structure.coerce import parent_is_real_numerical - sage: import gmpy2, numpy - sage: [parent_is_real_numerical(R) for R in [RR, QQ, ZZ, RLF, - ....: QuadraticField(2), int, float, gmpy2.mpq, numpy.integer]] - [True, True, True, True, True, True, True, True, True] - sage: [parent_is_real_numerical(R) for R in [CC, QuadraticField(-1), - ....: complex, gmpy2.mpc, numpy.complexfloating]] - [False, False, False, False, False] - sage: [parent_is_real_numerical(R) for R in [SR, QQ['x'], QQ[['x']], str]] + sage: import gmpy2 + sage: [parent_is_real_numerical(R) for R in [RR, QQ, ZZ, RLF, int, float, gmpy2.mpq]] + [True, True, True, True, True, True, True] + sage: parent_is_real_numerical(QuadraticField(2)) # optional - sage.rings.number_field + True + sage: import numpy; parent_is_real_numerical(numpy.integer) # optional - numpy + True + sage: parent_is_real_numerical(QuadraticField(-1)) # optional - sage.rings.number_field + False + sage: [parent_is_real_numerical(R) + ....: for R in [CC, complex, gmpy2.mpc, numpy.complexfloating]] [False, False, False, False] + sage: [parent_is_real_numerical(R) for R in [QQ['x'], QQ[['x']], str]] + [False, False, False] + sage: parent_is_real_numerical(SR) # optional - sage.symbolic + False sage: [parent_is_real_numerical(R) for R in [RIF, RBF, CIF, CBF]] [False, False, False, False] """ @@ -427,7 +439,7 @@ cpdef bint is_numpy_type(t): False sage: is_numpy_type(Integer) False - sage: is_numpy_type(Sudoku) + sage: is_numpy_type(Sudoku) # optional - sage.combinat False sage: is_numpy_type(None) False @@ -482,10 +494,11 @@ cdef class CoercionModel: EXAMPLES:: - sage: f = ZZ['t','x'].0 + QQ['x'].0 + CyclotomicField(13).gen(); f + sage: f = ZZ['t', 'x'].0 + QQ['x'].0 + CyclotomicField(13).gen(); f # optional - sage.rings.number_field t + x + zeta13 - sage: f.parent() - Multivariate Polynomial Ring in t, x over Cyclotomic Field of order 13 and degree 12 + sage: f.parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in t, x + over Cyclotomic Field of order 13 and degree 12 sage: ZZ['x','y'].0 + ~Frac(QQ['y']).0 (x*y + 1)/y sage: MatrixSpace(ZZ['x'], 2, 2)(2) + ~Frac(QQ['x']).0 @@ -591,7 +604,7 @@ cdef class CoercionModel: EXAMPLES:: sage: cm = sage.structure.element.get_coercion_model() - sage: cm.canonical_coercion(1,2/3) + sage: cm.canonical_coercion(1, 2/3) (1, 2/3) sage: maps, actions = cm.get_cache() @@ -635,7 +648,8 @@ cdef class CoercionModel: 1/2*x sage: maps, actions = cm.get_cache() sage: act = actions[QQ, R, operator.mul]; act - Left scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring + Left scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring sage: act.actor() Rational Field sage: act.domain() @@ -685,7 +699,7 @@ cdef class CoercionModel: sage: cm = sage.structure.element.get_coercion_model() sage: cm.record_exceptions() - sage: 1+1/2+2 # make sure there aren't any errors hanging around + sage: 1 + 1/2 + 2 # make sure there aren't any errors hanging around 7/2 sage: cm.exception_stack() [] @@ -747,29 +761,32 @@ cdef class CoercionModel: 5/2 sage: cm.exception_stack() [] - sage: 1/2 + GF(3)(2) + sage: 1/2 + GF(3)(2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Rational Field' and 'Finite Field of size 3' + TypeError: unsupported operand parent(s) for +: + 'Rational Field' and 'Finite Field of size 3' Now see what the actual problem was:: sage: import traceback - sage: cm.exception_stack() + sage: cm.exception_stack() # optional - sage.rings.finite_rings ['Traceback (most recent call last):...', 'Traceback (most recent call last):...'] - sage: print(cm.exception_stack()[-1]) + sage: print(cm.exception_stack()[-1]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 3' + TypeError: no common canonical parent for objects with parents: + 'Rational Field' and 'Finite Field of size 3' This is typically accessed via the :func:`coercion_traceback` function. :: - sage: coercion_traceback() + sage: coercion_traceback() # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 3' + TypeError: no common canonical parent for objects with parents: + 'Rational Field' and 'Finite Field of size 3' """ if not self._exceptions_cleared: self._exception_stack = [] @@ -805,7 +822,8 @@ cdef class CoercionModel: sage: R = ZZ['x'] sage: cm.explain(R, QQ) Action discovered. - Right scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring + Right scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring Result lives in Univariate Polynomial Ring in x over Rational Field Univariate Polynomial Ring in x over Rational Field @@ -874,7 +892,8 @@ cdef class CoercionModel: sage: cm.explain(ZZx, ZZ, operator.truediv) Action discovered. - Right inverse action by Rational Field on Univariate Polynomial Ring in x over Integer Ring + Right inverse action by Rational Field + on Univariate Polynomial Ring in x over Integer Ring with precomposition on right by Natural morphism: From: Integer Ring To: Rational Field @@ -914,17 +933,17 @@ cdef class CoercionModel: EXAMPLES:: sage: cm = sage.structure.element.get_coercion_model() - sage: GF7 = GF(7) - sage: steps, res = cm.analyse(GF7, ZZ) - sage: steps + sage: GF7 = GF(7) # optional - sage.rings.finite_rings + sage: steps, res = cm.analyse(GF7, ZZ) # optional - sage.rings.finite_rings + sage: steps # optional - sage.rings.finite_rings ['Coercion on right operand via', Natural morphism: From: Integer Ring To: Finite Field of size 7, 'Arithmetic performed after coercions.'] - sage: res + sage: res # optional - sage.rings.finite_rings Finite Field of size 7 - sage: f = steps[1]; type(f) + sage: f = steps[1]; type(f) # optional - sage.rings.finite_rings - sage: f(100) + sage: f(100) # optional - sage.rings.finite_rings 2 """ self._exceptions_cleared = False @@ -1044,7 +1063,9 @@ cdef class CoercionModel: sage: cm.common_parent(QQxy, QQzt, QQyz) Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Multivariate Polynomial Ring in x, y over Rational Field' and 'Multivariate Polynomial Ring in z, t over Rational Field' + TypeError: no common canonical parent for objects with parents: + 'Multivariate Polynomial Ring in x, y over Rational Field' and + 'Multivariate Polynomial Ring in z, t over Rational Field' """ base = None for x in args: @@ -1079,8 +1100,8 @@ cdef class CoercionModel: sage: ZZx = ZZ['x'] sage: cm.division_parent(ZZx) Fraction Field of Univariate Polynomial Ring in x over Integer Ring - sage: K = GF(41) - sage: cm.division_parent(K) + sage: K = GF(41) # optional - sage.rings.finite_rings + sage: cm.division_parent(K) # optional - sage.rings.finite_rings Finite Field of size 41 sage: Zmod100 = Integers(100) sage: cm.division_parent(Zmod100) @@ -1130,14 +1151,14 @@ cdef class CoercionModel: The operator can be any callable:: sage: R. = ZZ['x'] - sage: cm.bin_op(x^2-1, x+1, gcd) + sage: cm.bin_op(x^2 - 1, x + 1, gcd) x + 1 Actions are detected and performed:: - sage: M = matrix(ZZ, 2, 2, range(4)) - sage: V = vector(ZZ, [5,7]) - sage: cm.bin_op(M, V, operator.mul) + sage: M = matrix(ZZ, 2, 2, range(4)) # optional - sage.modules + sage: V = vector(ZZ, [5,7]) # optional - sage.modules + sage: cm.bin_op(M, V, operator.mul) # optional - sage.modules (7, 31) TESTS:: @@ -1261,14 +1282,14 @@ cdef class CoercionModel: sage: cm = sage.structure.element.get_coercion_model() sage: cm.canonical_coercion(mod(2, 10), 17) (2, 7) - sage: x, y = cm.canonical_coercion(1/2, matrix(ZZ, 2, 2, range(4))) - sage: x + sage: x, y = cm.canonical_coercion(1/2, matrix(ZZ, 2, 2, range(4))) # optional - sage.modules + sage: x # optional - sage.modules [1/2 0] [ 0 1/2] - sage: y + sage: y # optional - sage.modules [0 1] [2 3] - sage: parent(x) is parent(y) + sage: parent(x) is parent(y) # optional - sage.modules True There is some support for non-Sage datatypes as well:: @@ -1293,9 +1314,9 @@ cdef class CoercionModel: We also make an exception for 0, even if `\ZZ` does not map in:: - sage: canonical_coercion(vector([1, 2, 3]), 0) + sage: canonical_coercion(vector([1, 2, 3]), 0) # optional - sage.modules ((1, 2, 3), (0, 0, 0)) - sage: canonical_coercion(GF(5)(0), float(0)) + sage: canonical_coercion(GF(5)(0), float(0)) # optional - sage.rings.finite_rings (0, 0) """ xp = parent(x) @@ -1436,8 +1457,8 @@ cdef class CoercionModel: From: Rational Field To: Univariate Polynomial Ring in x over Rational Field - sage: K = GF(7) - sage: cm.coercion_maps(QQ, K) is None + sage: K = GF(7) # optional - sage.rings.finite_rings + sage: cm.coercion_maps(QQ, K) is None # optional - sage.rings.finite_rings True Note that to break symmetry, if there is a coercion map in both @@ -1473,19 +1494,19 @@ cdef class CoercionModel: garbage collection after being involved in binary operations:: sage: import gc - sage: T=type(GF(2)) + sage: T = type(GF(2)) # optional - sage.rings.finite_rings sage: gc.collect() #random 852 - sage: N0=len(list(o for o in gc.get_objects() if type(o) is T)) - sage: L=[ZZ(1)+GF(p)(1) for p in prime_range(2,50)] - sage: N1=len(list(o for o in gc.get_objects() if type(o) is T)) - sage: N1 > N0 + sage: N0 = len(list(o for o in gc.get_objects() if type(o) is T)) # optional - sage.rings.finite_rings + sage: L = [ZZ(1) + GF(p)(1) for p in prime_range(2, 50)] # optional - sage.rings.finite_rings + sage: N1 = len(list(o for o in gc.get_objects() if type(o) is T)) # optional - sage.rings.finite_rings + sage: N1 > N0 # optional - sage.rings.finite_rings True - sage: del L + sage: del L # optional - sage.rings.finite_rings sage: gc.collect() #random 3939 - sage: N2=len(list(o for o in gc.get_objects() if type(o) is T)) - sage: N2-N0 + sage: N2 = len(list(o for o in gc.get_objects() if type(o) is T)) # optional - sage.rings.finite_rings + sage: N2 - N0 # optional - sage.rings.finite_rings 0 """ @@ -1553,9 +1574,11 @@ cdef class CoercionModel: sage: cm.verify_coercion_maps(ZZ, QQ, homs) == homs Traceback (most recent call last): ... - RuntimeError: ('BUG in coercion model, codomains must be identical', Natural morphism: + RuntimeError: ('BUG in coercion model, codomains must be identical', + Natural morphism: From: Integer Ring - To: Rational Field, Generic map: + To: Rational Field, + Generic map: From: Rational Field To: Real Field with 53 bits of precision) """ @@ -1616,7 +1639,7 @@ cdef class CoercionModel: If R is S, then two identity morphisms suffice:: - sage: cm.discover_coercion(SR, SR) + sage: cm.discover_coercion(SR, SR) # optional - sage.symbolic (None, None) If there is a coercion map either direction, use that:: @@ -1693,18 +1716,22 @@ cdef class CoercionModel: sage: cm = sage.structure.element.get_coercion_model() sage: ZZx = ZZ['x'] sage: cm.get_action(ZZx, ZZ, operator.mul) - Right scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring + Right scalar multiplication by Integer Ring + on Univariate Polynomial Ring in x over Integer Ring sage: cm.get_action(ZZx, QQ, operator.mul) - Right scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring + Right scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring sage: QQx = QQ['x'] sage: cm.get_action(QQx, int, operator.mul) - Right scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Rational Field + Right scalar multiplication by Integer Ring + on Univariate Polynomial Ring in x over Rational Field with precomposition on right by Native morphism: From: Set of Python objects of class 'int' To: Integer Ring sage: A = cm.get_action(QQx, ZZ, operator.truediv); A - Right inverse action by Rational Field on Univariate Polynomial Ring in x over Rational Field + Right inverse action by Rational Field + on Univariate Polynomial Ring in x over Rational Field with precomposition on right by Natural morphism: From: Integer Ring To: Rational Field @@ -1733,7 +1760,8 @@ cdef class CoercionModel: sage: R. = ZZ['x'] sage: cm = sage.structure.element.get_coercion_model() sage: cm.verify_action(R.get_action(QQ), R, QQ, operator.mul) - Right scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring + Right scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring sage: cm.verify_action(R.get_action(QQ), RDF, R, operator.mul) Traceback (most recent call last): ... @@ -1742,8 +1770,9 @@ cdef class CoercionModel: R = Real Double Field S = Univariate Polynomial Ring in x over Integer Ring (should be Univariate Polynomial Ring in x over Integer Ring, Rational Field) - action = Right scalar multiplication by Rational Field on - Univariate Polynomial Ring in x over Integer Ring () + action = Right scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring + () """ if action is None: return action @@ -1826,13 +1855,14 @@ cdef class CoercionModel: Check that :trac:`17740` is fixed:: - sage: R = GF(5)['x'] - sage: cm.discover_action(R, ZZ, operator.truediv) - Right inverse action by Finite Field of size 5 on Univariate Polynomial Ring in x over Finite Field of size 5 + sage: R = GF(5)['x'] # optional - sage.rings.finite_rings + sage: cm.discover_action(R, ZZ, operator.truediv) # optional - sage.rings.finite_rings + Right inverse action by Finite Field of size 5 + on Univariate Polynomial Ring in x over Finite Field of size 5 with precomposition on right by Natural morphism: From: Integer Ring To: Finite Field of size 5 - sage: cm.bin_op(R.gen(), 7, operator.truediv).parent() + sage: cm.bin_op(R.gen(), 7, operator.truediv).parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 Check that :trac:`18221` is fixed:: @@ -1932,15 +1962,16 @@ cdef class CoercionModel: If there is no coercion, we only support ``==`` and ``!=``:: - sage: x = QQ.one(); y = GF(2).one() - sage: richcmp(x, y, op_EQ) + sage: x = QQ.one(); y = GF(2).one() # optional - sage.rings.finite_rings + sage: richcmp(x, y, op_EQ) # optional - sage.rings.finite_rings False - sage: richcmp(x, y, op_NE) + sage: richcmp(x, y, op_NE) # optional - sage.rings.finite_rings True - sage: richcmp(x, y, op_GT) + sage: richcmp(x, y, op_GT) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for >: 'Rational Field' and 'Finite Field of size 2' + TypeError: unsupported operand parent(s) for >: + 'Rational Field' and 'Finite Field of size 2' We support non-Sage types with the usual Python convention:: diff --git a/src/sage/structure/coerce_actions.pyx b/src/sage/structure/coerce_actions.pyx index 3096282f068..146c41379b7 100644 --- a/src/sage/structure/coerce_actions.pyx +++ b/src/sage/structure/coerce_actions.pyx @@ -55,9 +55,11 @@ cdef class GenericAction(Action): for otherwise they could be garbage collected, giving rise to random errors (see :trac:`18157`). :: - sage: M = MatrixSpace(ZZ,2) - sage: sage.structure.coerce_actions.ActedUponAction(M, Cusps, True) - Left action by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring on Set P^1(QQ) of all cusps + sage: M = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: sage.structure.coerce_actions.ActedUponAction(M, Cusps, True) # optional - sage.modular sage.modules + Left action + by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring + on Set P^1(QQ) of all cusps sage: Z6 = Zmod(6) sage: sage.structure.coerce_actions.GenericAction(QQ, Z6, True) @@ -92,9 +94,9 @@ cdef class GenericAction(Action): errors (see :trac:`18157`). :: - sage: M = MatrixSpace(ZZ,2) - sage: A = sage.structure.coerce_actions.ActedUponAction(M, Cusps, True) - sage: A.codomain() + sage: M = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: A = sage.structure.coerce_actions.ActedUponAction(M, Cusps, True) # optional - sage.modular sage.modules + sage: A.codomain() # optional - sage.modular sage.modules Set P^1(QQ) of all cusps sage: S3 = SymmetricGroup(3) # optional - sage.groups @@ -140,14 +142,14 @@ cdef class ActedUponAction(GenericAction): """ TESTS:: - sage: M = MatrixSpace(ZZ,2) - sage: A = sage.structure.coerce_actions.ActedUponAction(M, Cusps, True) - sage: A.act(matrix(ZZ, 2, [1,0,2,-1]), Cusp(1,2)) + sage: M = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: A = sage.structure.coerce_actions.ActedUponAction(M, Cusps, True) # optional - sage.modular sage.modules + sage: A.act(matrix(ZZ, 2, [1,0,2,-1]), Cusp(1,2)) # optional - sage.modular sage.modules Infinity - sage: A(matrix(ZZ, 2, [1,0,2,-1]), Cusp(1,2)) + sage: A(matrix(ZZ, 2, [1,0,2,-1]), Cusp(1,2)) # optional - sage.modular sage.modules Infinity - sage: type(A) + sage: type(A) # optional - sage.modular sage.modules <... 'sage.structure.coerce_actions.ActedUponAction'> """ return (x)._acted_upon_(g, not self._is_left) @@ -170,10 +172,12 @@ def detect_element_action(Parent X, Y, bint X_on_left, X_el=None, Y_el=None): sage: detect_element_action(ZZx, ZZ, False) Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring sage: detect_element_action(ZZx, QQ, True) - Right scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring - sage: detect_element_action(Cusps, M, False) - Left action by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring on Set P^1(QQ) of all cusps - sage: detect_element_action(Cusps, M, True), + Right scalar multiplication by Rational Field + on Univariate Polynomial Ring in x over Integer Ring + sage: detect_element_action(Cusps, M, False) # optional - sage.modular sage.modules + Left action by Full MatrixSpace of 2 by 2 dense matrices over Integer Ring + on Set P^1(QQ) of all cusps + sage: detect_element_action(Cusps, M, True), # optional - sage.modular sage.modules (None,) sage: detect_element_action(ZZ, QQ, True), (None,) diff --git a/src/sage/structure/coerce_dict.pyx b/src/sage/structure/coerce_dict.pyx index 440993aadd6..d38997d807c 100644 --- a/src/sage/structure/coerce_dict.pyx +++ b/src/sage/structure/coerce_dict.pyx @@ -35,18 +35,18 @@ coerce maps. In previous versions of Sage, the cache was by strong references and resulted in a memory leak in the following example. However, this leak was fixed by :trac:`715`, using weak references:: - sage: K. = GF(2^55) - sage: for i in range(20): + sage: K. = GF(2^55) # optional - sage.rings.finite_rings sage.combinat + sage: for i in range(50): # optional - sage.rings.finite_rings sage.combinat ....: a = K.random_element() ....: E = EllipticCurve(j=a) ....: P = E.random_point() ....: Q = 2*P - sage: L = [Partitions(n) for n in range(200)] # purge strong cache in CachedRepresentation + sage: L = [Partitions(n) for n in range(200)] # purge strong cache in CachedRepresentation # optional - sage.rings.finite_rings sage.combinat sage: import gc sage: n = gc.collect() - sage: from sage.schemes.elliptic_curves.ell_finite_field import EllipticCurve_finite_field - sage: LE = [x for x in gc.get_objects() if isinstance(x, EllipticCurve_finite_field)] - sage: len(LE) + sage: from sage.schemes.elliptic_curves.ell_finite_field import EllipticCurve_finite_field # optional - sage.rings.finite_rings sage.combinat + sage: LE = [x for x in gc.get_objects() if isinstance(x, EllipticCurve_finite_field)] # optional - sage.rings.finite_rings sage.combinat + sage: len(LE) # optional - sage.rings.finite_rings sage.combinat 1 """ diff --git a/src/sage/structure/coerce_maps.pyx b/src/sage/structure/coerce_maps.pyx index 3b4649edead..e40f9ddb5db 100644 --- a/src/sage/structure/coerce_maps.pyx +++ b/src/sage/structure/coerce_maps.pyx @@ -32,16 +32,19 @@ cdef class DefaultConvertMap(Map): Maps of this type are morphisms in the category of sets with partial maps (see :trac:`15618`):: - sage: f = GF(11).convert_map_from(GF(7)); f + sage: f = GF(11).convert_map_from(GF(7)); f # optional - sage.rings.finite_rings Conversion map: From: Finite Field of size 7 To: Finite Field of size 11 - sage: f.parent() - Set of Morphisms from Finite Field of size 7 to Finite Field of size 11 in Category of sets with partial maps + sage: f.parent() # optional - sage.rings.finite_rings + Set of Morphisms + from Finite Field of size 7 + to Finite Field of size 11 + in Category of sets with partial maps Test that :trac:`23211` is resolved:: - sage: f._is_coercion + sage: f._is_coercion # optional - sage.rings.finite_rings False sage: QQ[['x']].coerce_map_from(QQ)._is_coercion True @@ -50,7 +53,8 @@ cdef class DefaultConvertMap(Map): sage: from sage.structure.coerce_maps import DefaultConvertMap sage: DefaultConvertMap(ZZ, ZZ) - doctest:...: DeprecationWarning: DefaultConvertMap is deprecated, use DefaultConvertMap_unique instead. This probably means that _element_constructor_ should be a method and not some other kind of callable + doctest:...: DeprecationWarning: DefaultConvertMap is deprecated, use DefaultConvertMap_unique instead. + This probably means that _element_constructor_ should be a method and not some other kind of callable See https://github.com/sagemath/sage/issues/26879 for details. Conversion map: From: Integer Ring @@ -81,8 +85,8 @@ cdef class DefaultConvertMap(Map): EXAMPLES:: - sage: f = GF(11).convert_map_from(GF(7)) - sage: f._repr_type() + sage: f = GF(11).convert_map_from(GF(7)) # optional - sage.rings.finite_rings + sage: f._repr_type() # optional - sage.rings.finite_rings 'Conversion' """ return self._repr_type_str or ("Coercion" if self._is_coercion else "Conversion") @@ -191,13 +195,13 @@ cdef class NamedConvertMap(Map): EXAMPLES:: sage: from sage.structure.coerce_maps import NamedConvertMap - sage: var('t') + sage: var('t') # optional - sage.symbolic t - sage: mor = NamedConvertMap(SR, QQ['t'], '_polynomial_') - sage: mor(t^2/4+1) + sage: mor = NamedConvertMap(SR, QQ['t'], '_polynomial_') # optional - sage.symbolic + sage: mor(t^2/4 + 1) # optional - sage.symbolic 1/4*t^2 + 1 - sage: mor = NamedConvertMap(SR, GF(7)[['t']], '_polynomial_') - sage: mor(t^2/4+1) + sage: mor = NamedConvertMap(SR, GF(7)[['t']], '_polynomial_') # optional - sage.symbolic + sage: mor(t^2/4 + 1) # optional - sage.symbolic 1 + 2*t^2 """ if isinstance(domain, type): @@ -214,19 +218,19 @@ cdef class NamedConvertMap(Map): EXAMPLES:: sage: from sage.structure.coerce_maps import NamedConvertMap - sage: var('t') + sage: var('t') # optional - sage.symbolic t - sage: phi = NamedConvertMap(SR, QQ['t'], '_polynomial_') - sage: psi = copy(phi) # indirect doctest - sage: psi + sage: phi = NamedConvertMap(SR, QQ['t'], '_polynomial_') # optional - sage.symbolic + sage: psi = copy(phi) # indirect doctest # optional - sage.symbolic + sage: psi # optional - sage.symbolic Conversion via _polynomial_ method map: From: Symbolic Ring To: Univariate Polynomial Ring in t over Rational Field - sage: phi == psi # todo: comparison not implemented + sage: phi == psi # todo: comparison not implemented # optional - sage.symbolic True - sage: psi(t^2/4+1) + sage: psi(t^2/4 + 1) # optional - sage.symbolic 1/4*t^2 + 1 - sage: psi(t^2/4+1) == phi(t^2/4+1) + sage: psi(t^2/4 + 1) == phi(t^2/4 + 1) # optional - sage.symbolic True """ slots = Map._extra_slots(self) @@ -240,19 +244,19 @@ cdef class NamedConvertMap(Map): EXAMPLES:: sage: from sage.structure.coerce_maps import NamedConvertMap - sage: var('t') + sage: var('t') # optional - sage.symbolic t - sage: phi = NamedConvertMap(SR, QQ['t'], '_polynomial_') - sage: psi = copy(phi) # indirect doctest - sage: psi + sage: phi = NamedConvertMap(SR, QQ['t'], '_polynomial_') # optional - sage.symbolic + sage: psi = copy(phi) # indirect doctest # optional - sage.symbolic + sage: psi # optional - sage.symbolic Conversion via _polynomial_ method map: From: Symbolic Ring To: Univariate Polynomial Ring in t over Rational Field - sage: phi == psi # todo: comparison not implemented + sage: phi == psi # todo: comparison not implemented # optional - sage.symbolic True - sage: psi(t^2/4+1) + sage: psi(t^2/4 + 1) # optional - sage.symbolic 1/4*t^2 + 1 - sage: psi(t^2/4+1) == phi(t^2/4+1) + sage: psi(t^2/4 + 1) == phi(t^2/4 + 1) # optional - sage.symbolic True """ self.method_name = _slots['method_name'] @@ -263,13 +267,13 @@ cdef class NamedConvertMap(Map): EXAMPLES:: sage: from sage.structure.coerce_maps import NamedConvertMap - sage: f = NamedConvertMap(GF(5), QQ, '_integer_'); f + sage: f = NamedConvertMap(GF(5), QQ, '_integer_'); f # optional - sage.rings.finite_rings Conversion via _integer_ method map: From: Finite Field of size 5 To: Rational Field - sage: f(19) + sage: f(19) # optional - sage.rings.finite_rings 4 - sage: f(19).parent() + sage: f(19).parent() # optional - sage.rings.finite_rings Rational Field """ cdef Parent C = self._codomain @@ -297,8 +301,8 @@ cdef class NamedConvertMap(Map): EXAMPLES:: sage: from sage.structure.coerce_maps import NamedConvertMap - sage: f = NamedConvertMap(SR, ZZ['x'], '_polynomial_') - sage: f(x^2+1, check=True) + sage: f = NamedConvertMap(SR, ZZ['x'], '_polynomial_') # optional - sage.symbolic + sage: f(x^2 + 1, check=True) # optional - sage.symbolic x^2 + 1 """ cdef Parent C = self._codomain @@ -331,12 +335,12 @@ cdef class CallableConvertMap(Map): :: - sage: f = CallableConvertMap(RR, RR, exp, parent_as_first_arg=False) - sage: f(0) + sage: f = CallableConvertMap(RR, RR, exp, parent_as_first_arg=False) # optional - sage.symbolic + sage: f(0) # optional - sage.symbolic 1.00000000000000 - sage: f(1) + sage: f(1) # optional - sage.symbolic 2.71828182845905 - sage: f(-3) + sage: f(-3) # optional - sage.symbolic 0.0497870683678639 """ if isinstance(domain, type): diff --git a/src/sage/structure/element.pxd b/src/sage/structure/element.pxd index 5c6e295a4b8..4403ddd685a 100644 --- a/src/sage/structure/element.pxd +++ b/src/sage/structure/element.pxd @@ -132,12 +132,12 @@ cpdef inline bint have_same_parent(left, right): These have different types but the same parent:: sage: a = RLF(2) - sage: b = exp(a) - sage: type(a) + sage: b = exp(a) # optional - sage.symbolic + sage: type(a) # optional - sage.symbolic <... 'sage.rings.real_lazy.LazyWrapper'> - sage: type(b) + sage: type(b) # optional - sage.symbolic <... 'sage.rings.real_lazy.LazyNamedUnop'> - sage: have_same_parent(a, b) + sage: have_same_parent(a, b) # optional - sage.symbolic True """ return HAVE_SAME_PARENT(classify_elements(left, right)) diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 026991c25d8..82031af875a 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -354,7 +354,7 @@ def is_Element(x): sage: from sage.structure.element import is_Element sage: is_Element(2/3) True - sage: is_Element(QQ^3) + sage: is_Element(QQ^3) # optional - sage.modules False """ return isinstance(x, Element) @@ -648,7 +648,7 @@ cdef class Element(SageObject): sage: QQ.base_ring() Rational Field - sage: identity_matrix(3).base_ring() + sage: identity_matrix(3).base_ring() # optional - sage.modules Integer Ring """ return self._parent.base_ring() @@ -893,13 +893,13 @@ cdef class Element(SageObject): sage: mp.dps = 30 sage: 25._mpmath_(53) mpf('25.0') - sage: mpmathify(3+4*I) + sage: mpmathify(3 + 4*I) # optional - mpmath mpc(real='3.0', imag='4.0') - sage: mpmathify(1+pi) + sage: mpmathify(1 + pi) # optional - mpmath mpf('4.14159265358979323846264338327933') - sage: (1+pi)._mpmath_(10) + sage: (1 + pi)._mpmath_(10) # optional - mpmath mpf('4.140625') - sage: (1+pi)._mpmath_(mp.prec) + sage: (1 + pi)._mpmath_(mp.prec) # optional - mpmath mpf('4.14159265358979323846264338327933') """ return self.n(prec)._mpmath_(prec=prec) @@ -920,11 +920,11 @@ cdef class Element(SageObject): EXAMPLES:: - sage: x, y = PolynomialRing(ZZ,2,'xy').gens() + sage: x, y = PolynomialRing(ZZ, 2, 'xy').gens() sage: f = x^2 + y + x^2*y^2 + 5 sage: f((5,y)) 25*y^2 + y + 30 - sage: f.substitute({x:5}) + sage: f.substitute({x: 5}) 25*y^2 + y + 30 sage: f.substitute(x=5) 25*y^2 + y + 30 @@ -1024,13 +1024,13 @@ cdef class Element(SageObject): Verify that :trac:`5185` is fixed:: - sage: v = vector({1: 1, 3: -1}) - sage: w = vector({1: -1, 3: 1}) - sage: v + w + sage: v = vector({1: 1, 3: -1}) # optional - sage.modules + sage: w = vector({1: -1, 3: 1}) # optional - sage.modules + sage: v + w # optional - sage.modules (0, 0, 0, 0) - sage: (v+w).is_zero() + sage: (v + w).is_zero() # optional - sage.modules True - sage: bool(v+w) + sage: bool(v + w) # optional - sage.modules False """ @@ -1130,7 +1130,7 @@ cdef class Element(SageObject): We now create an ``Element`` class where we define ``_richcmp_`` and check that comparison works:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.structure.richcmp cimport rich_to_bool ....: from sage.structure.element cimport Element @@ -1143,9 +1143,9 @@ cdef class Element(SageObject): ....: cdef float x2 = (other).x ....: return rich_to_bool(op, (x1 > x2) - (x1 < x2)) ....: ''') - sage: a = FloatCmp(1) # optional - sage.misc.cython - sage: b = FloatCmp(2) # optional - sage.misc.cython - sage: a <= b, b <= a # optional - sage.misc.cython + sage: a = FloatCmp(1) # optional - sage.misc.cython + sage: b = FloatCmp(2) # optional - sage.misc.cython + sage: a <= b, b <= a # optional - sage.misc.cython (True, False) """ # Obvious case @@ -1280,16 +1280,16 @@ cdef class Element(SageObject): EXAMPLES:: - sage: cython( # long time # optional - sage.misc.cython + sage: cython( # long time # optional - sage.misc.cython ....: ''' ....: from sage.structure.element cimport Element ....: cdef class MyElement(Element): ....: cdef _add_long(self, long n): ....: return n ....: ''') - sage: e = MyElement(Parent()) # long time # optional - sage.misc.cython - sage: i = int(42) # optional - sage.misc.cython - sage: i + e, e + i # long time # optional - sage.misc.cython + sage: e = MyElement(Parent()) # long time # optional - sage.misc.cython + sage: i = int(42) # optional - sage.misc.cython + sage: i + e, e + i # long time # optional - sage.misc.cython (42, 42) """ return coercion_model.bin_op(self, n, add) @@ -1490,13 +1490,13 @@ cdef class Element(SageObject): :: - sage: A = AlgebrasWithBasis(QQ).example(); A + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: x = A.an_element() - sage: x + sage: x = A.an_element() # optional - sage.combinat sage.modules + sage: x # optional - sage.combinat sage.modules B[word: ] + 2*B[word: a] + 3*B[word: b] + B[word: bab] - sage: x.__mul__(x) + sage: x.__mul__(x) # optional - sage.combinat sage.modules B[word: ] + 4*B[word: a] + 4*B[word: aa] + 6*B[word: ab] + 2*B[word: abab] + 6*B[word: b] + 6*B[word: ba] + 2*B[word: bab] + 2*B[word: baba] + 3*B[word: babb] @@ -1558,16 +1558,16 @@ cdef class Element(SageObject): EXAMPLES:: - sage: cython( # long time # optional - sage.misc.cython + sage: cython( # long time # optional - sage.misc.cython ....: ''' ....: from sage.structure.element cimport Element ....: cdef class MyElement(Element): ....: cdef _mul_long(self, long n): ....: return n ....: ''') - sage: e = MyElement(Parent()) # long time # optional - sage.misc.cython - sage: i = int(42) # optional - sage.misc.cython - sage: i * e, e * i # long time # optional - sage.misc.cython + sage: e = MyElement(Parent()) # long time # optional - sage.misc.cython + sage: i = int(42) # optional - sage.misc.cython + sage: i * e, e * i # long time # optional - sage.misc.cython (42, 42) """ return coercion_model.bin_op(self, n, mul) @@ -1675,11 +1675,11 @@ cdef class Element(SageObject): sage: operator.truediv(2, 3) 2/3 - sage: operator.truediv(pi, 3) + sage: operator.truediv(pi, 3) # optional - sage.symbolic 1/3*pi sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^2 + 1) - sage: operator.truediv(2, K.ideal(i+1)) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: operator.truediv(2, K.ideal(i + 1)) # optional - sage.rings.number_field Fractional ideal (-i + 1) :: @@ -1994,15 +1994,15 @@ cdef class Element(SageObject): :: - sage: (2/3)^I + sage: (2/3)^I # optional - sage.symbolic (2/3)^I - sage: (2/3)^sqrt(2) + sage: (2/3)^sqrt(2) # optional - sage.symbolic (2/3)^sqrt(2) - sage: var('x,y,z,n') + sage: var('x,y,z,n') # optional - sage.symbolic (x, y, z, n) - sage: (2/3)^(x^n + y^n + z^n) + sage: (2/3)^(x^n + y^n + z^n) # optional - sage.symbolic (2/3)^(x^n + y^n + z^n) - sage: (-7/11)^(tan(x)+exp(x)) + sage: (-7/11)^(tan(x)+exp(x)) # optional - sage.symbolic (-7/11)^(e^x + tan(x)) sage: float(1.2)**(1/2) 1.0954451150103321 @@ -2140,7 +2140,7 @@ def is_ModuleElement(x): sage: from sage.structure.element import is_ModuleElement sage: is_ModuleElement(2/3) True - sage: is_ModuleElement((QQ^3).0) + sage: is_ModuleElement((QQ^3).0) # optional - sage.modules True sage: is_ModuleElement('a') False @@ -2219,7 +2219,7 @@ cdef class ElementWithCachedMethod(Element): ....: "from sage.structure.parent cimport Parent", ....: "cdef class MyParent(Parent):", ....: " Element = MyElement"] - sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython + sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython sage: cython_code = ["from sage.misc.cachefunc import cached_method", ....: "from sage.misc.cachefunc import cached_in_parent_method", ....: "from sage.categories.category import Category", @@ -2242,21 +2242,21 @@ cdef class ElementWithCachedMethod(Element): ....: " @cached_method", ....: " def invert(self, x):", ....: " return -x"] - sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython - sage: C = MyCategory() # optional - sage.misc.cython - sage: P = MyParent(category=C) # optional - sage.misc.cython - sage: ebroken = MyBrokenElement(P, 5) # optional - sage.misc.cython - sage: e = MyElement(P, 5) # optional - sage.misc.cython + sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython + sage: C = MyCategory() # optional - sage.misc.cython + sage: P = MyParent(category=C) # optional - sage.misc.cython + sage: ebroken = MyBrokenElement(P, 5) # optional - sage.misc.cython + sage: e = MyElement(P, 5) # optional - sage.misc.cython The cached methods inherited by ``MyElement`` works:: - sage: e.element_cache_test() # optional - sage.misc.cython + sage: e.element_cache_test() # optional - sage.misc.cython <-5> - sage: e.element_cache_test() is e.element_cache_test() # optional - sage.misc.cython + sage: e.element_cache_test() is e.element_cache_test() # optional - sage.misc.cython True - sage: e.element_via_parent_test() # optional - sage.misc.cython + sage: e.element_via_parent_test() # optional - sage.misc.cython <-5> - sage: e.element_via_parent_test() is e.element_via_parent_test() # optional - sage.misc.cython + sage: e.element_via_parent_test() is e.element_via_parent_test() # optional - sage.misc.cython True The other element class can only inherit a @@ -2264,36 +2264,36 @@ cdef class ElementWithCachedMethod(Element): parent. In fact, equal elements share the cache, even if they are of different types:: - sage: e == ebroken # optional - sage.misc.cython + sage: e == ebroken # optional - sage.misc.cython True - sage: type(e) == type(ebroken) # optional - sage.misc.cython + sage: type(e) == type(ebroken) # optional - sage.misc.cython False - sage: ebroken.element_via_parent_test() is e.element_via_parent_test() # optional - sage.misc.cython + sage: ebroken.element_via_parent_test() is e.element_via_parent_test() # optional - sage.misc.cython True However, the cache of the other inherited method breaks, although the method as such works:: - sage: ebroken.element_cache_test() # optional - sage.misc.cython + sage: ebroken.element_cache_test() # optional - sage.misc.cython <-5> - sage: ebroken.element_cache_test() is ebroken.element_cache_test() # optional - sage.misc.cython + sage: ebroken.element_cache_test() is ebroken.element_cache_test() # optional - sage.misc.cython False Since ``e`` and ``ebroken`` share the cache, when we empty it for one element it is empty for the other as well:: - sage: b = ebroken.element_via_parent_test() # optional - sage.misc.cython - sage: e.element_via_parent_test.clear_cache() # optional - sage.misc.cython - sage: b is ebroken.element_via_parent_test() # optional - sage.misc.cython + sage: b = ebroken.element_via_parent_test() # optional - sage.misc.cython + sage: e.element_via_parent_test.clear_cache() # optional - sage.misc.cython + sage: b is ebroken.element_via_parent_test() # optional - sage.misc.cython False Note that the cache only breaks for elements that do no allow attribute assignment. A Python version of ``MyBrokenElement`` therefore allows for cached methods:: - sage: epython = MyPythonElement(P, 5) # optional - sage.misc.cython - sage: epython.element_cache_test() # optional - sage.misc.cython + sage: epython = MyPythonElement(P, 5) # optional - sage.misc.cython + sage: epython.element_cache_test() # optional - sage.misc.cython <-5> - sage: epython.element_cache_test() is epython.element_cache_test() # optional - sage.misc.cython + sage: epython.element_cache_test() is epython.element_cache_test() # optional - sage.misc.cython True """ @@ -2310,7 +2310,7 @@ cdef class ElementWithCachedMethod(Element): EXAMPLES:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.structure.element cimport ElementWithCachedMethod ....: cdef class MyElement(ElementWithCachedMethod): @@ -2336,12 +2336,12 @@ cdef class ElementWithCachedMethod(Element): ....: def my_lazy_attr(self): ....: return 'lazy attribute of <%s>'%self.x ....: ''') - sage: C = MyCategory() # optional - sage.misc.cython - sage: P = MyParent(category=C) # optional - sage.misc.cython - sage: e = MyElement(P, 5) # optional - sage.misc.cython - sage: e.my_lazy_attr # optional - sage.misc.cython + sage: C = MyCategory() # optional - sage.misc.cython + sage: P = MyParent(category=C) # optional - sage.misc.cython + sage: e = MyElement(P, 5) # optional - sage.misc.cython + sage: e.my_lazy_attr # optional - sage.misc.cython 'lazy attribute of <5>' - sage: e.my_lazy_attr is e.my_lazy_attr # optional - sage.misc.cython + sage: e.my_lazy_attr is e.my_lazy_attr # optional - sage.misc.cython True """ try: @@ -2453,8 +2453,8 @@ cdef class ModuleElementWithMutability(ModuleElement): """ EXAMPLES:: - sage: v = sage.modules.free_module_element.FreeModuleElement(QQ^3) - sage: type(v) + sage: v = sage.modules.free_module_element.FreeModuleElement(QQ^3) # optional - sage.modules + sage: type(v) # optional - sage.modules """ self._parent = parent @@ -2466,11 +2466,11 @@ cdef class ModuleElementWithMutability(ModuleElement): EXAMPLES:: - sage: v = vector([1..5]); v + sage: v = vector([1..5]); v # optional - sage.modules (1, 2, 3, 4, 5) - sage: v[1] = 10 - sage: v.set_immutable() - sage: v[1] = 10 + sage: v[1] = 10 # optional - sage.modules + sage: v.set_immutable() # optional - sage.modules + sage: v[1] = 10 # optional - sage.modules Traceback (most recent call last): ... ValueError: vector is immutable; please change a copy instead (use copy()) @@ -2484,10 +2484,10 @@ cdef class ModuleElementWithMutability(ModuleElement): EXAMPLES:: - sage: v = vector(QQ['x,y'], [1..5]); v.is_mutable() + sage: v = vector(QQ['x,y'], [1..5]); v.is_mutable() # optional - sage.modules True - sage: v.set_immutable() - sage: v.is_mutable() + sage: v.set_immutable() # optional - sage.modules + sage: v.is_mutable() # optional - sage.modules False """ return not self._is_immutable @@ -2499,10 +2499,10 @@ cdef class ModuleElementWithMutability(ModuleElement): EXAMPLES:: - sage: v = vector(QQ['x,y'], [1..5]); v.is_immutable() + sage: v = vector(QQ['x,y'], [1..5]); v.is_immutable() # optional - sage.modules False - sage: v.set_immutable() - sage: v.is_immutable() + sage: v.set_immutable() # optional - sage.modules + sage: v.is_immutable() # optional - sage.modules True """ return self._is_immutable @@ -2550,9 +2550,9 @@ cdef class MonoidElement(Element): EXAMPLES:: - sage: G = SymmetricGroup(4) # optional - sage.groups - sage: g = G([2, 3, 4, 1]) # optional - sage.groups - sage: g.powers(4) # optional - sage.groups + sage: G = SymmetricGroup(4) # optional - sage.groups + sage: g = G([2, 3, 4, 1]) # optional - sage.groups + sage: g.powers(4) # optional - sage.groups [(), (1,2,3,4), (1,3)(2,4), (1,4,3,2)] """ if n < 0: @@ -2681,22 +2681,22 @@ cdef class RingElement(ModuleElement): True sage: p(a,200) * p(a,-64) == p(a,136) True - sage: p(2, 1/2) + sage: p(2, 1/2) # optional - sage.symbolic sqrt(2) TESTS: These are not testing this code, but they are probably good to have around:: - sage: 2r**(SR(2)-1-1r) + sage: 2r**(SR(2)-1-1r) # optional - sage.symbolic 1 - sage: 2r^(1/2) + sage: 2r^(1/2) # optional - sage.symbolic sqrt(2) Exponent overflow should throw an OverflowError (:trac:`2956`):: - sage: K. = AA[] - sage: x^(2^64 + 12345) + sage: K. = AA[] # optional - sage.rings.number_field + sage: x^(2^64 + 12345) # optional - sage.rings.number_field Traceback (most recent call last): ... OverflowError: exponent overflow (2147483648) @@ -2793,8 +2793,8 @@ cdef class RingElement(ModuleElement): :: - sage: R. = GF(7)[] - sage: divmod(x^2, x-1) + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: divmod(x^2, x - 1) # optional - sage.rings.finite_rings (x + 1, 1) :: @@ -2839,8 +2839,8 @@ cdef class RingElement(ModuleElement): sage: a = QQ(0) sage: a.is_nilpotent() True - sage: m = matrix(QQ,3,[[3,2,3],[9,0,3],[-9,0,-3]]) - sage: m.is_nilpotent() + sage: m = matrix(QQ, 3, [[3,2,3], [9,0,3], [-9,0,-3]]) # optional - sage.modules + sage: m.is_nilpotent() # optional - sage.modules Traceback (most recent call last): ... AttributeError: ... object has no attribute 'is_nilpotent' @@ -2884,30 +2884,30 @@ cdef class RingElement(ModuleElement): For polynomial rings, prime is the same as irreducible:: sage: R. = QQ[] - sage: x.is_prime() + sage: x.is_prime() # optional - sage.libs.singular True - sage: (x^2 + y^3).is_prime() + sage: (x^2 + y^3).is_prime() # optional - sage.libs.singular True - sage: (x^2 - y^2).is_prime() + sage: (x^2 - y^2).is_prime() # optional - sage.libs.singular False - sage: R(0).is_prime() + sage: R(0).is_prime() # optional - sage.libs.singular False - sage: R(2).is_prime() + sage: R(2).is_prime() # optional - sage.libs.singular False For the Gaussian integers:: - sage: K. = QuadraticField(-1) - sage: ZI = K.ring_of_integers() - sage: ZI(3).is_prime() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: ZI = K.ring_of_integers() # optional - sage.rings.number_field + sage: ZI(3).is_prime() # optional - sage.rings.number_field True - sage: ZI(5).is_prime() + sage: ZI(5).is_prime() # optional - sage.rings.number_field False - sage: ZI(2+i).is_prime() + sage: ZI(2 + i).is_prime() # optional - sage.rings.number_field True - sage: ZI(0).is_prime() + sage: ZI(0).is_prime() # optional - sage.rings.number_field False - sage: ZI(1).is_prime() + sage: ZI(1).is_prime() # optional - sage.rings.number_field False In fields, an element is never prime:: @@ -2930,13 +2930,13 @@ cdef class RingElement(ModuleElement): redefines :meth:`is_prime` to determine primality in the ring of integers:: - sage: (1+i).is_prime() + sage: (1 + i).is_prime() # optional - sage.rings.number_field True - sage: K(5).is_prime() + sage: K(5).is_prime() # optional - sage.rings.number_field False - sage: K(7).is_prime() + sage: K(7).is_prime() # optional - sage.rings.number_field True - sage: K(7/13).is_prime() + sage: K(7/13).is_prime() # optional - sage.rings.number_field False However, for rationals, :meth:`is_prime` *does* follow the @@ -2980,16 +2980,16 @@ cdef class CommutativeRingElement(RingElement): EXAMPLES:: - sage: F = GF(25) - sage: x = F.gen() - sage: z = F.zero() - sage: x.inverse_mod(F.ideal(z)) + sage: F = GF(25) # optional - sage.rings.finite_rings + sage: x = F.gen() # optional - sage.rings.finite_rings + sage: z = F.zero() # optional - sage.rings.finite_rings + sage: x.inverse_mod(F.ideal(z)) # optional - sage.rings.finite_rings 2*z2 + 3 - sage: x.inverse_mod(F.ideal(1)) + sage: x.inverse_mod(F.ideal(1)) # optional - sage.rings.finite_rings 1 - sage: z.inverse_mod(F.ideal(1)) + sage: z.inverse_mod(F.ideal(1)) # optional - sage.rings.finite_rings 1 - sage: z.inverse_mod(F.ideal(z)) + sage: z.inverse_mod(F.ideal(z)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: an element of a proper ideal does not have an inverse modulo that ideal @@ -3012,24 +3012,24 @@ cdef class CommutativeRingElement(RingElement): sage: P. = PolynomialRing(QQ) sage: x.divides(x^2) True - sage: x.divides(x^2+2) + sage: x.divides(x^2 + 2) False - sage: (x^2+2).divides(x) + sage: (x^2 + 2).divides(x) False sage: P. = PolynomialRing(ZZ) sage: x.divides(x^2) True - sage: x.divides(x^2+2) + sage: x.divides(x^2 + 2) False - sage: (x^2+2).divides(x) + sage: (x^2 + 2).divides(x) False :trac:`5347` has been fixed:: - sage: K = GF(7) - sage: K(3).divides(1) + sage: K = GF(7) # optional - sage.rings.finite_rings + sage: K(3).divides(1) # optional - sage.rings.finite_rings True - sage: K(3).divides(K(1)) + sage: K(3).divides(K(1)) # optional - sage.rings.finite_rings True :: @@ -3059,7 +3059,8 @@ cdef class CommutativeRingElement(RingElement): sage: Zmod(5)(1).divides(Zmod(2)(1)) Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Ring of integers modulo 5' and 'Ring of integers modulo 2' + TypeError: no common canonical parent for objects with parents: + 'Ring of integers modulo 5' and 'Ring of integers modulo 2' sage: Zmod(35)(4).divides(Zmod(7)(1)) True sage: Zmod(35)(7).divides(Zmod(7)(1)) @@ -3360,7 +3361,7 @@ cdef class Expression(CommutativeRingElement): EXAMPLES:: - sage: isinstance(SR.var('y'), sage.structure.element.Expression) # optional - sage.symbolic + sage: isinstance(SR.var('y'), sage.structure.element.Expression) # optional - sage.symbolic True By design, there is a unique direct subclass:: @@ -3606,14 +3607,14 @@ cdef class Vector(ModuleElementWithMutability): TESTS:: - sage: A = matrix([[1, 2], [0, 3]]) - sage: b = vector([0, 1]) - sage: x = b / A; x + sage: A = matrix([[1, 2], [0, 3]]) # optional - sage.modules + sage: b = vector([0, 1]) # optional - sage.modules + sage: x = b / A; x # optional - sage.modules (0, 1/3) - sage: x == b * ~A + sage: x == b * ~A # optional - sage.modules True - sage: A = matrix([[1, 2], [0, 3], [1, 5]]) - sage: (b / A) * A == b + sage: A = matrix([[1, 2], [0, 3], [1, 5]]) # optional - sage.modules + sage: (b / A) * A == b # optional - sage.modules True """ right = py_scalar_to_element(right) @@ -3640,32 +3641,33 @@ cdef class Vector(ModuleElementWithMutability): EXAMPLES:: - sage: v = vector([1,2,3]) - sage: v._magma_init_(magma) # optional - magma + sage: v = vector([1,2,3]) # optional - sage.modules + sage: v._magma_init_(magma) # optional - magma # optional - sage.modules '_sage_[...]![1,2,3]' - sage: mv = magma(v); mv # optional - magma + sage: mv = magma(v); mv # optional - magma # optional - sage.modules (1 2 3) - sage: mv.Type() # optional - magma + sage: mv.Type() # optional - magma # optional - sage.modules ModTupRngElt - sage: mv.Parent() # optional - magma + sage: mv.Parent() # optional - magma # optional - sage.modules Full RSpace of degree 3 over Integer Ring - sage: v = vector(QQ, [1/2, 3/4, 5/6]) - sage: mv = magma(v); mv # optional - magma + sage: v = vector(QQ, [1/2, 3/4, 5/6]) # optional - sage.modules + sage: mv = magma(v); mv # optional - magma # optional - sage.modules (1/2 3/4 5/6) - sage: mv.Type() # optional - magma + sage: mv.Type() # optional - magma # optional - sage.modules ModTupFldElt - sage: mv.Parent() # optional - magma + sage: mv.Parent() # optional - magma # optional - sage.modules Full Vector space of degree 3 over Rational Field A more demanding example:: sage: R. = QQ[] - sage: v = vector([x^3, y, 2/3*z + x/y]) - sage: magma(v) # optional - magma + sage: v = vector([x^3, y, 2/3*z + x/y]) # optional - sage.modules + sage: magma(v) # optional - magma # optional - sage.modules ( x^3 y (2/3*y*z + x)/y) - sage: magma(v).Parent() # optional - magma - Full Vector space of degree 3 over Multivariate rational function field of rank 3 over Rational Field + sage: magma(v).Parent() # optional - magma # optional - sage.modules + Full Vector space of degree 3 + over Multivariate rational function field of rank 3 over Rational Field """ V = magma(self._parent) v = [x._magma_init_(magma) for x in self.list()] @@ -3752,7 +3754,8 @@ cdef class Matrix(ModuleElement): sage: A*B Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 3 by 2 dense matrices over Rational Field' and 'Full MatrixSpace of 3 by 2 dense matrices over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 3 by 2 dense matrices over Rational Field' and 'Full MatrixSpace of 3 by 2 dense matrices over Rational Field' Here we test (matrix * vector) multiplication:: @@ -3800,7 +3803,9 @@ cdef class Matrix(ModuleElement): sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*vector(QQ['y'],[1,2])) Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' Here we test (matrix * scalar) multiplication:: @@ -3954,32 +3959,32 @@ cdef class Matrix(ModuleElement): EXAMPLES:: - sage: a = matrix(ZZ, 2, range(4)) - sage: operator.truediv(a, 5) + sage: a = matrix(ZZ, 2, range(4)) # optional - sage.modules + sage: operator.truediv(a, 5) # optional - sage.modules [ 0 1/5] [2/5 3/5] - sage: a = matrix(ZZ, 2, range(4)) - sage: b = matrix(ZZ, 2, [1,1,0,5]) - sage: operator.truediv(a, b) + sage: a = matrix(ZZ, 2, range(4)) # optional - sage.modules + sage: b = matrix(ZZ, 2, [1,1,0,5]) # optional - sage.modules + sage: operator.truediv(a, b) # optional - sage.modules [ 0 1/5] [ 2 1/5] - sage: c = matrix(QQ, 2, [3,2,5,7]) - sage: operator.truediv(c, a) + sage: c = matrix(QQ, 2, [3,2,5,7]) # optional - sage.modules + sage: operator.truediv(c, a) # optional - sage.modules [-5/2 3/2] [-1/2 5/2] TESTS:: - sage: a = matrix(ZZ, [[1, 2], [0, 3]]) - sage: b = matrix(ZZ, 3, 2, range(6)) - sage: x = b / a; x + sage: a = matrix(ZZ, [[1, 2], [0, 3]]) # optional - sage.modules + sage: b = matrix(ZZ, 3, 2, range(6)) # optional - sage.modules + sage: x = b / a; x # optional - sage.modules [ 0 1/3] [ 2 -1/3] [ 4 -1] - sage: x == b * ~a + sage: x == b * ~a # optional - sage.modules True - sage: a = matrix(ZZ, [[1, 2], [0, 3], [1, 5]]) - sage: (b / a) * a == b + sage: a = matrix(ZZ, [[1, 2], [0, 3], [1, 5]]) # optional - sage.modules + sage: (b / a) * a == b # optional - sage.modules True """ if is_Matrix(right): @@ -4035,14 +4040,14 @@ cdef class PrincipalIdealDomainElement(DedekindDomainElement): :trac:`30849`:: - sage: 2.gcd(pari(3)) + sage: 2.gcd(pari(3)) # optional - sage.libs.pari 1 - sage: type(2.gcd(pari(3))) + sage: type(2.gcd(pari(3))) # optional - sage.libs.pari - sage: 2.gcd(pari('1/3')) + sage: 2.gcd(pari('1/3')) # optional - sage.libs.pari 1/3 - sage: type(2.gcd(pari('1/3'))) + sage: type(2.gcd(pari('1/3'))) # optional - sage.libs.pari sage: import gmpy2 @@ -4053,7 +4058,7 @@ cdef class PrincipalIdealDomainElement(DedekindDomainElement): sage: 2.gcd(gmpy2.mpq(1,3)) 1/3 - sage: type(2.gcd(pari('1/3'))) + sage: type(2.gcd(pari('1/3'))) # optional - sage.libs.pari """ # NOTE: in order to handle nicely pari or gmpy2 integers we do not rely only on coercion @@ -4074,14 +4079,14 @@ cdef class PrincipalIdealDomainElement(DedekindDomainElement): :trac:`30849`:: - sage: 2.lcm(pari(3)) + sage: 2.lcm(pari(3)) # optional - sage.libs.pari 6 - sage: type(2.lcm(pari(3))) + sage: type(2.lcm(pari(3))) # optional - sage.libs.pari - sage: 2.lcm(pari('1/3')) + sage: 2.lcm(pari('1/3')) # optional - sage.libs.pari 2 - sage: type(2.lcm(pari('1/3'))) + sage: type(2.lcm(pari('1/3'))) # optional - sage.libs.pari sage: import gmpy2 @@ -4131,15 +4136,15 @@ cdef class EuclideanDomainElement(PrincipalIdealDomainElement): EXAMPLES:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.structure.element cimport EuclideanDomainElement ....: cdef class MyElt(EuclideanDomainElement): ....: def quo_rem(self, other): ....: return self._parent.var('quo,rem') ....: ''') - sage: e = MyElt(SR) # optional - sage.misc.cython - sage: e // e # optional - sage.misc.cython + sage: e = MyElt(SR) # optional - sage.misc.cython + sage: e // e # optional - sage.misc.cython quo """ Q, _ = self.quo_rem(right) @@ -4162,15 +4167,15 @@ cdef class EuclideanDomainElement(PrincipalIdealDomainElement): :: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.structure.element cimport EuclideanDomainElement ....: cdef class MyElt(EuclideanDomainElement): ....: def quo_rem(self, other): ....: return self._parent.var('quo,rem') ....: ''') - sage: e = MyElt(SR) # optional - sage.misc.cython - sage: e % e # optional - sage.misc.cython + sage: e = MyElt(SR) # optional - sage.misc.cython + sage: e % e # optional - sage.misc.cython rem """ _, R = self.quo_rem(other) @@ -4195,9 +4200,9 @@ cdef class FieldElement(CommutativeRingElement): sage: K. = NumberField(x^4 + x^2 + 2/3) # optional - sage.rings.number_field sage: c = (1+b) // (1-b); c # optional - sage.rings.number_field 3/4*b^3 + 3/4*b^2 + 3/2*b + 1/2 - sage: (1+b) / (1-b) == c + sage: (1+b) / (1-b) == c # optional - sage.rings.number_field True - sage: c * (1-b) + sage: c * (1-b) # optional - sage.rings.number_field b + 1 """ return self._div_(right) @@ -4266,14 +4271,14 @@ cdef class FieldElement(CommutativeRingElement): EXAMPLES:: - sage: K. = QQ[sqrt(3)] - sage: K(0).divides(rt3) + sage: K. = QQ[sqrt(3)] # optional - sage.rings.number_field sage.symbolic + sage: K(0).divides(rt3) # optional - sage.rings.number_field sage.symbolic False - sage: rt3.divides(K(17)) + sage: rt3.divides(K(17)) # optional - sage.rings.number_field sage.symbolic True - sage: K(0).divides(K(0)) + sage: K(0).divides(K(0)) # optional - sage.rings.number_field sage.symbolic True - sage: rt3.divides(K(0)) + sage: rt3.divides(K(0)) # optional - sage.rings.number_field sage.symbolic True """ if not (other._parent is self._parent): @@ -4288,8 +4293,8 @@ def is_AlgebraElement(x): TESTS:: sage: from sage.structure.element import is_AlgebraElement - sage: R. = FreeAlgebra(QQ,2) - sage: is_AlgebraElement(x*y) + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: is_AlgebraElement(x * y) # optional - sage.combinat sage.modules True sage: is_AlgebraElement(1) @@ -4347,8 +4352,8 @@ cpdef canonical_coercion(x, y): EXAMPLES:: - sage: A = Matrix([[0, 1], [1, 0]]) - sage: canonical_coercion(A, 1) + sage: A = Matrix([[0, 1], [1, 0]]) # optional - sage.modules + sage: canonical_coercion(A, 1) # optional - sage.modules ( [0 1] [1 0] [1 0], [0 1] @@ -4398,14 +4403,16 @@ def coercion_traceback(dump=True): sage: 1 + 1/5 6/5 sage: coercion_traceback() # Should be empty, as all went well. - sage: 1/5 + GF(5).gen() + sage: 1/5 + GF(5).gen() # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Rational Field' and 'Finite Field of size 5' - sage: coercion_traceback() + TypeError: unsupported operand parent(s) for +: + 'Rational Field' and 'Finite Field of size 5' + sage: coercion_traceback() # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Rational Field' and 'Finite Field of size 5' + TypeError: no common canonical parent for objects with parents: + 'Rational Field' and 'Finite Field of size 5' """ if dump: for traceback in coercion_model.exception_stack(): @@ -4438,7 +4445,7 @@ def coerce_binop(method): Sparse polynomial rings uses `@coerce_binop` on `gcd`:: - sage: S. = PolynomialRing(ZZ,sparse=True) + sage: S. = PolynomialRing(ZZ, sparse=True) sage: f = x^2 sage: g = x sage: f.gcd(g) #indirect doctest @@ -4459,15 +4466,15 @@ def coerce_binop(method): sage: h = R2(1) sage: f.gcd(g) 1 - sage: f.gcd(g,algorithm='modular') + sage: f.gcd(g, algorithm='modular') 1 sage: f.gcd(h) 1 - sage: f.gcd(h,algorithm='modular') + sage: f.gcd(h, algorithm='modular') 1 sage: h.gcd(f) 1 - sage: h.gcd(f,'modular') + sage: h.gcd(f, 'modular') 1 We demonstrate a small class using `@coerce_binop` on a method:: diff --git a/src/sage/structure/element_wrapper.pyx b/src/sage/structure/element_wrapper.pyx index f77bcce6ea5..44aa88ea530 100644 --- a/src/sage/structure/element_wrapper.pyx +++ b/src/sage/structure/element_wrapper.pyx @@ -209,8 +209,8 @@ cdef class ElementWrapper(Element): sage: from sage.structure.element_wrapper import DummyParent sage: ElementWrapper(DummyParent("A parent"), 1)._ascii_art_() 1 - sage: x = var('x') - sage: ElementWrapper(DummyParent("A parent"), x^2 + x)._ascii_art_() + sage: x = var('x') # optional - sage.symbolic + sage: ElementWrapper(DummyParent("A parent"), x^2 + x)._ascii_art_() # optional - sage.symbolic 2 x + x """ @@ -226,8 +226,8 @@ cdef class ElementWrapper(Element): sage: from sage.structure.element_wrapper import DummyParent sage: ElementWrapper(DummyParent("A parent"), 1)._ascii_art_() 1 - sage: x = var('x') - sage: ElementWrapper(DummyParent("A parent"), x^2 + x)._unicode_art_() + sage: x = var('x') # optional - sage.symbolic + sage: ElementWrapper(DummyParent("A parent"), x^2 + x)._unicode_art_() # optional - sage.symbolic 2 x + x """ @@ -561,8 +561,8 @@ cdef class ElementWrapperCheckWrappedClass(ElementWrapper): :: sage: A = cartesian_product([ZZ, ZZ]) - sage: B = cartesian_product([GF(3), GF(5)]) - sage: A((3,5)) == B((0,0)) + sage: B = cartesian_product([GF(3), GF(5)]) # optional - sage.rings.finite_rings + sage: A((3,5)) == B((0,0)) # optional - sage.rings.finite_rings True """ if type(self) is type(right): diff --git a/src/sage/structure/factorization.py b/src/sage/structure/factorization.py index 8fa56d6bf75..a547bee0820 100644 --- a/src/sage/structure/factorization.py +++ b/src/sage/structure/factorization.py @@ -70,22 +70,22 @@ sage: f = -5*(x-2)*(x-3) sage: f -5*x^2 + 25*x - 30 - sage: F = f.factor(); F + sage: F = f.factor(); F # optional - sage.libs.pari (-5) * (x - 3) * (x - 2) - sage: F.unit() + sage: F.unit() # optional - sage.libs.pari -5 - sage: F.value() + sage: F.value() # optional - sage.libs.pari -5*x^2 + 25*x - 30 The underlying list is the list of pairs `(p_i, e_i)`, where each `p_i` is a 'prime' and each `e_i` is an integer. The unit part is discarded by the list:: - sage: list(F) + sage: list(F) # optional - sage.libs.pari [(x - 3, 1), (x - 2, 1)] - sage: len(F) + sage: len(F) # optional - sage.libs.pari 2 - sage: F[1] + sage: F[1] # optional - sage.libs.pari (x - 2, 1) In the ring `\ZZ[x]`, the integer `-5` is not a unit, so the @@ -95,56 +95,58 @@ sage: f = -5*(x-2)*(x-3) sage: f -5*x^2 + 25*x - 30 - sage: F = f.factor(); F + sage: F = f.factor(); F # optional - sage.libs.pari (-1) * 5 * (x - 3) * (x - 2) - sage: F.universe() + sage: F.universe() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring - sage: F.unit() + sage: F.unit() # optional - sage.libs.pari -1 - sage: list(F) + sage: list(F) # optional - sage.libs.pari [(5, 1), (x - 3, 1), (x - 2, 1)] - sage: F.value() + sage: F.value() # optional - sage.libs.pari -5*x^2 + 25*x - 30 - sage: len(F) + sage: len(F) # optional - sage.libs.pari 3 On the other hand, -1 is a unit in `\ZZ`, so it is included in the unit:: sage: x = ZZ['x'].0 - sage: f = -1*(x-2)*(x-3) - sage: F = f.factor(); F + sage: f = -1*(x-2)*(x-3) # optional - sage.libs.pari + sage: F = f.factor(); F # optional - sage.libs.pari (-1) * (x - 3) * (x - 2) - sage: F.unit() + sage: F.unit() # optional - sage.libs.pari -1 - sage: list(F) + sage: list(F) # optional - sage.libs.pari [(x - 3, 1), (x - 2, 1)] Factorizations can involve fairly abstract mathematical objects:: - sage: F = ModularSymbols(11,4).factorization() - sage: F - (Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 6 for Gamma_0(11) of weight 4 with sign 0 over Rational Field) * - (Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 6 for Gamma_0(11) of weight 4 with sign 0 over Rational Field) * - (Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 6 for Gamma_0(11) of weight 4 with sign 0 over Rational Field) - sage: type(F) + sage: F = ModularSymbols(11,4).factorization(); F # optional - sage.modular + (Modular Symbols subspace of dimension 2 of Modular Symbols space + of dimension 6 for Gamma_0(11) of weight 4 with sign 0 over Rational Field) * + (Modular Symbols subspace of dimension 2 of Modular Symbols space + of dimension 6 for Gamma_0(11) of weight 4 with sign 0 over Rational Field) * + (Modular Symbols subspace of dimension 2 of Modular Symbols space + of dimension 6 for Gamma_0(11) of weight 4 with sign 0 over Rational Field) + sage: type(F) # optional - sage.modular - sage: K. = NumberField(x^2 + 3); K + sage: K. = NumberField(x^2 + 3); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 + 3 - sage: f = K.factor(15); f + sage: f = K.factor(15); f # optional - sage.rings.number_field (Fractional ideal (1/2*a + 3/2))^2 * (Fractional ideal (5)) - sage: f.universe() + sage: f.universe() # optional - sage.rings.number_field Monoid of ideals of Number Field in a with defining polynomial x^2 + 3 - sage: f.unit() + sage: f.unit() # optional - sage.rings.number_field Fractional ideal (1) - sage: g=K.factor(9); g + sage: g = K.factor(9); g # optional - sage.rings.number_field (Fractional ideal (1/2*a + 3/2))^4 - sage: f.lcm(g) + sage: f.lcm(g) # optional - sage.rings.number_field (Fractional ideal (1/2*a + 3/2))^4 * (Fractional ideal (5)) - sage: f.gcd(g) + sage: f.gcd(g) # optional - sage.rings.number_field (Fractional ideal (1/2*a + 3/2))^2 - sage: f.is_integral() + sage: f.is_integral() # optional - sage.rings.number_field True TESTS:: @@ -206,7 +208,7 @@ class Factorization(SageObject): -1 sage: loads(F.dumps()) == F True - sage: F = Factorization([(x,1/3)]) + sage: F = Factorization([(x, 1/3)]) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: no conversion of this rational to integer @@ -281,13 +283,13 @@ def __init__(self, x, unit=None, cr=False, sort=True, simplify=True): sage: Factorization([(2, 7), (5,2), (2, 5)]) 2^12 * 5^2 - sage: R. = FreeAlgebra(QQ,2) - sage: Factorization([(a,1),(b,1),(a,2)]) + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: Factorization([(a,1), (b,1), (a,2)]) # optional - sage.combinat sage.modules a * b * a^2 Autosorting (the default) swaps around the factors below:: - sage: F = Factorization([(ZZ^3, 2), (ZZ^2, 5)], cr=True); F + sage: F = Factorization([(ZZ^3, 2), (ZZ^2, 5)], cr=True); F # optional - sage.modules (Ambient free module of rank 2 over the principal ideal domain Integer Ring)^5 * (Ambient free module of rank 3 over the principal ideal domain Integer Ring)^2 """ @@ -413,7 +415,7 @@ def __richcmp__(self, other, op): sage: x = polygen(QQ) sage: x^2 - 1 > x^2 - 4 True - sage: factor(x^2 - 1) > factor(x^2 - 4) + sage: factor(x^2 - 1) > factor(x^2 - 4) # optional - sage.libs.pari True """ if not isinstance(other, Factorization): @@ -520,13 +522,13 @@ def universe(self): sage: F.universe() Integer Ring - sage: R. = FreeAlgebra(QQ, 3) - sage: F = Factorization([(z, 2)], 3) - sage: (F*F^-1).universe() + sage: R. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: F = Factorization([(z, 2)], 3) # optional - sage.combinat sage.modules + sage: (F*F^-1).universe() # optional - sage.combinat sage.modules Free Algebra on 3 generators (x, y, z) over Rational Field - sage: F = ModularSymbols(11,4).factorization() - sage: F.universe() + sage: F = ModularSymbols(11,4).factorization() # optional - sage.modular + sage: F.universe() # optional - sage.modular """ try: return self.__universe @@ -551,11 +553,11 @@ def base_change(self, U): possible:: sage: g = x^2 - 1 - sage: F = factor(g); F + sage: F = factor(g); F # optional - sage.libs.pari (x - 1) * (x + 1) - sage: F.universe() + sage: F.universe() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring - sage: F.base_change(ZZ) + sage: F.base_change(ZZ) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Impossible to coerce the factors of (x - 1) * (x + 1) into Integer Ring @@ -576,15 +578,15 @@ def is_commutative(self): sage: F = factor(2006) sage: F.is_commutative() True - sage: K = QuadraticField(23, 'a') - sage: F = K.factor(13) - sage: F.is_commutative() + sage: K = QuadraticField(23, 'a') # optional - sage.rings.number_field + sage: F = K.factor(13) # optional - sage.rings.number_field + sage: F.is_commutative() # optional - sage.rings.number_field True - sage: R. = FreeAlgebra(QQ, 3) - sage: F = Factorization([(z, 2)], 3) - sage: F.is_commutative() + sage: R. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: F = Factorization([(z, 2)], 3) # optional - sage.combinat sage.modules + sage: F.is_commutative() # optional - sage.combinat sage.modules False - sage: (F*F^-1).is_commutative() + sage: (F*F^-1).is_commutative() # optional - sage.combinat sage.modules False """ try: @@ -602,14 +604,14 @@ def _set_cr(self, cr): EXAMPLES:: sage: x = polygen(QQ,'x') - sage: F = factor(x^6 - 1); F + sage: F = factor(x^6 - 1); F # optional - sage.libs.pari (x - 1) * (x + 1) * (x^2 - x + 1) * (x^2 + x + 1) - sage: F._set_cr(True); F + sage: F._set_cr(True); F # optional - sage.libs.pari (x - 1) * (x + 1) * (x^2 - x + 1) * (x^2 + x + 1) - sage: F._set_cr(False); F + sage: F._set_cr(False); F # optional - sage.libs.pari (x - 1) * (x + 1) * (x^2 - x + 1) * (x^2 + x + 1) """ self.__cr = bool(cr) @@ -620,12 +622,12 @@ def simplify(self): TESTS:: - sage: R. = FreeAlgebra(ZZ, 2) - sage: F = Factorization([(x,3), (y, 2), (y,2)], simplify=False); F + sage: R. = FreeAlgebra(ZZ, 2) # optional - sage.combinat sage.modules + sage: F = Factorization([(x,3), (y, 2), (y,2)], simplify=False); F # optional - sage.combinat sage.modules x^3 * y^2 * y^2 - sage: F.simplify(); F + sage: F.simplify(); F # optional - sage.combinat sage.modules x^3 * y^4 - sage: F * Factorization([(y, -2)], 2) + sage: F * Factorization([(y, -2)], 2) # optional - sage.combinat sage.modules (2) * x^3 * y^2 """ repeat = False @@ -679,8 +681,8 @@ def sort(self, key=None): We sort it by decreasing degree:: - sage: F.sort(key=lambda x:(-x[0].degree(), x)) - sage: F + sage: F.sort(key=lambda x: (-x[0].degree(), x)) # optional - sage.libs.pari + sage: F # optional - sage.libs.pari (x^2 - x + 1) * (x + 1) """ if len(self) == 0: @@ -769,7 +771,7 @@ def _cr(self): Next we factor a modular symbols space:: - sage: F = ModularSymbols(11).factor(); F + sage: F = ModularSymbols(11).factor(); F # optional - sage.modular (Modular Symbols subspace of dimension 1 of ...) * (Modular Symbols subspace of dimension 1 of ...) * (Modular Symbols subspace of dimension 1 of ...) @@ -861,7 +863,7 @@ def _latex_(self): -1 \cdot 2^{2} \cdot 5^{2} sage: f._latex_() '-1 \\cdot 2^{2} \\cdot 5^{2}' - sage: x = AA['x'].0; factor(x^2 + x + 1)._latex_() # trac 12178 + sage: x = AA['x'].0; factor(x^2 + x + 1)._latex_() # trac 12178 # optional - sage.rings.number_field '(x^{2} + x + 1.000000000000000?)' """ if len(self) == 0: @@ -898,12 +900,12 @@ def __pari__(self): EXAMPLES:: sage: f = factor(-24) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari [-1, 1; 2, 3; 3, 1] sage: R. = QQ[] - sage: g = factor(x^10 - 1) - sage: pari(g) + sage: g = factor(x^10 - 1) # optional - sage.libs.pari + sage: pari(g) # optional - sage.libs.pari [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1] """ @@ -1003,12 +1005,12 @@ def __rmul__(self, left): -2 * 3 * 5 sage: a * -2 -2 * 3 * 5 - sage: R. = FreeAlgebra(QQ,2) - sage: f = Factorization([(x,2),(y,3)]); f + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: f = Factorization([(x,2), (y,3)]); f # optional - sage.combinat sage.modules x^2 * y^3 - sage: x * f + sage: x * f # optional - sage.combinat sage.modules x^3 * y^3 - sage: f * x + sage: f * x # optional - sage.combinat sage.modules x^2 * y^3 * x Note that this does not automatically factor ``left``:: @@ -1035,12 +1037,12 @@ def __mul__(self, other): sage: factor(-10) * factor(16) -1 * 2^5 * 5 - sage: R. = FreeAlgebra(ZZ, 2) - sage: F = Factorization([(x,3), (y, 2), (x,1)]); F + sage: R. = FreeAlgebra(ZZ, 2) # optional - sage.combinat sage.modules + sage: F = Factorization([(x,3), (y, 2), (x,1)]); F # optional - sage.combinat sage.modules x^3 * y^2 * x - sage: F*F + sage: F*F # optional - sage.combinat sage.modules x^3 * y^2 * x^4 * y^2 * x - sage: -1 * F + sage: -1 * F # optional - sage.combinat sage.modules (-1) * x^3 * y^2 * x sage: P. = ZZ[] @@ -1101,13 +1103,13 @@ def __pow__(self, n): sage: K. = NumberField(x^3 - 39*x - 91) # optional - sage.rings.number_field sage: F = K.factor(7); F # optional - sage.rings.number_field (Fractional ideal (7, a)) * (Fractional ideal (7, a + 2)) * (Fractional ideal (7, a - 2)) - sage: F^9 + sage: F^9 # optional - sage.rings.number_field (Fractional ideal (7, a))^9 * (Fractional ideal (7, a + 2))^9 * (Fractional ideal (7, a - 2))^9 - sage: R. = FreeAlgebra(ZZ, 2) - sage: F = Factorization([(x,3), (y, 2), (x,1)]); F + sage: R. = FreeAlgebra(ZZ, 2) # optional - sage.combinat sage.modules + sage: F = Factorization([(x,3), (y, 2), (x,1)]); F # optional - sage.combinat sage.modules x^3 * y^2 * x - sage: F**2 + sage: F**2 # optional - sage.combinat sage.modules x^3 * y^2 * x^4 * y^2 * x """ from sage.rings.integer import Integer @@ -1139,10 +1141,10 @@ def __invert__(self): sage: F^-1 2^-1 * 17^-1 * 59^-1 - sage: R. = FreeAlgebra(QQ, 2) - sage: F = Factorization([(x,3), (y, 2), (x,1)], 2); F + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: F = Factorization([(x,3), (y, 2), (x,1)], 2); F # optional - sage.combinat sage.modules (2) * x^3 * y^2 * x - sage: F^-1 + sage: F^-1 # optional - sage.combinat sage.modules (1/2) * x^-1 * y^-2 * x^-3 """ return Factorization([(p,-e) for p,e in reversed(self)], @@ -1160,12 +1162,12 @@ def __truediv__(self, other): sage: factor(-10) / factor(16) -1 * 2^-3 * 5 - sage: R. = FreeAlgebra(QQ, 2) - sage: F = Factorization([(x,3), (y, 2), (x,1)]); F + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: F = Factorization([(x,3), (y, 2), (x,1)]); F # optional - sage.combinat sage.modules x^3 * y^2 * x - sage: G = Factorization([(y, 1), (x,1)],1); G + sage: G = Factorization([(y, 1), (x,1)],1); G # optional - sage.combinat sage.modules y * x - sage: F / G + sage: F / G # optional - sage.combinat sage.modules x^3 * y """ if not isinstance(other, Factorization): @@ -1183,10 +1185,10 @@ def value(self): sage: F.value() -2006 - sage: R. = FreeAlgebra(ZZ, 2) - sage: F = Factorization([(x,3), (y, 2), (x,1)]); F + sage: R. = FreeAlgebra(ZZ, 2) # optional - sage.combinat sage.modules + sage: F = Factorization([(x,3), (y, 2), (x,1)]); F # optional - sage.combinat sage.modules x^3 * y^2 * x - sage: F.value() + sage: F.value() # optional - sage.combinat sage.modules x^3*y^2*x """ from sage.misc.misc_c import prod @@ -1212,7 +1214,7 @@ def gcd(self, other): 2 * 5 sage: R. = ZZ[] - sage: (factor(-20).gcd(factor(5*x+10))).universe() + sage: (factor(-20).gcd(factor(5*x+10))).universe() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring """ if not isinstance(other, Factorization): @@ -1254,7 +1256,7 @@ def lcm(self, other): 2^4 * 5 sage: R. = ZZ[] - sage: (factor(-20).lcm(factor(5*x+10))).universe() + sage: (factor(-20).lcm(factor(5*x + 10))).universe() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring """ if not isinstance(other, Factorization): diff --git a/src/sage/structure/factory.pyx b/src/sage/structure/factory.pyx index a1a28a0da7a..f47f0ea96fa 100644 --- a/src/sage/structure/factory.pyx +++ b/src/sage/structure/factory.pyx @@ -196,7 +196,7 @@ cdef class UniqueFactory(SageObject): :class:`object`. The third allows attribute assignment and is derived from :class:`object`. :: - sage: cython("cdef class C: pass") # optional - sage.misc.cython + sage: cython("cdef class C: pass") # optional - sage.misc.cython sage: class D: ....: def __init__(self, *args): ....: self.t = args @@ -214,7 +214,7 @@ cdef class UniqueFactory(SageObject): It is impossible to create an instance of ``C`` with our factory, since it does not allow weak references:: - sage: F(1, impl='C') # optional - sage.misc.cython + sage: F(1, impl='C') # optional - sage.misc.cython Traceback (most recent call last): ... TypeError: cannot create weak reference to '....C' object @@ -222,14 +222,14 @@ cdef class UniqueFactory(SageObject): Let us try again, with a Cython class that does allow weak references. Now, creation of an instance using the factory works:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: cdef class C: ....: cdef __weakref__ ....: ''') ....: - sage: c = F(1, impl='C') # optional - sage.misc.cython - sage: isinstance(c, C) # optional - sage.misc.cython + sage: c = F(1, impl='C') # optional - sage.misc.cython + sage: isinstance(c, C) # optional - sage.misc.cython True The cache is used when calling the factory again---even if it is suggested @@ -237,16 +237,16 @@ cdef class UniqueFactory(SageObject): only considered an "extra argument" that does not count for the key. :: - sage: c is F(1, impl='C') is F(1, impl="D") is F(1) # optional - sage.misc.cython + sage: c is F(1, impl='C') is F(1, impl="D") is F(1) # optional - sage.misc.cython True However, pickling and unpickling does not use the cache. This is because the factory has tried to assign an attribute to the instance that provides information on the key used to create the instance, but failed:: - sage: loads(dumps(c)) is c # optional - sage.misc.cython + sage: loads(dumps(c)) is c # optional - sage.misc.cython False - sage: hasattr(c, '_factory_data') # optional - sage.misc.cython + sage: hasattr(c, '_factory_data') # optional - sage.misc.cython False We have already seen that our factory will only take the requested @@ -302,7 +302,7 @@ cdef class UniqueFactory(SageObject): sage: fake_factory = UniqueFactory('ZZ') sage: loads(dumps(fake_factory)) Integer Ring - sage: fake_factory = UniqueFactory('sage.rings.all.QQ') + sage: fake_factory = UniqueFactory('sage.rings.rational_field.QQ') sage: loads(dumps(fake_factory)) Rational Field """ @@ -313,17 +313,17 @@ cdef class UniqueFactory(SageObject): """ EXAMPLES:: - sage: A = FiniteField(127) - sage: A is loads(dumps(A)) # indirect doctest + sage: A = FiniteField(127) # optional - sage.rings.finite_rings + sage: A is loads(dumps(A)) # indirect doctest # optional - sage.rings.finite_rings True - sage: B = FiniteField(3^3,'b') - sage: B is loads(dumps(B)) + sage: B = FiniteField(3^3,'b') # optional - sage.rings.finite_rings + sage: B is loads(dumps(B)) # optional - sage.rings.finite_rings True - sage: C = FiniteField(2^16,'c') - sage: C is loads(dumps(C)) + sage: C = FiniteField(2^16,'c') # optional - sage.rings.finite_rings + sage: C is loads(dumps(C)) # optional - sage.rings.finite_rings True - sage: D = FiniteField(3^20,'d') - sage: D is loads(dumps(D)) + sage: D = FiniteField(3^20,'d') # optional - sage.rings.finite_rings + sage: D is loads(dumps(D)) # optional - sage.rings.finite_rings True TESTS:: @@ -396,10 +396,10 @@ cdef class UniqueFactory(SageObject): Check that :trac:`16317` has been fixed, i.e., caching works for unhashable objects:: - sage: K. = Qq(4) - sage: d = test_factory.get_object(3.0, (K(1), 'c'), {}) # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: d = test_factory.get_object(3.0, (K(1), 'c'), {}) # optional - sage.rings.padics Making object (1 + O(2^20), 'c') - sage: d is test_factory.get_object(3.0, (K(1), 'c'), {}) # optional - sage.rings.padics + sage: d is test_factory.get_object(3.0, (K(1), 'c'), {}) # optional - sage.rings.padics True """ @@ -468,7 +468,7 @@ cdef class UniqueFactory(SageObject): sage: from sage.structure.test_factory import test_factory sage: test_factory.create_key_and_extra_args(1, 2, key=5) ((1, 2), {}) - sage: GF.create_key_and_extra_args(3) + sage: GF.create_key_and_extra_args(3) # optional - sage.rings.finite_rings ((3, ('x',), None, 'modn', 3, 1, True, None, None, None, True, False), {}) """ return self.create_key(*args, **kwds), {} @@ -518,15 +518,15 @@ cdef class UniqueFactory(SageObject): The ``GF`` factory used to have a custom :meth:`other_keys` method, but this was removed in :trac:`16934`:: - sage: key, _ = GF.create_key_and_extra_args(27, 'k'); key + sage: key, _ = GF.create_key_and_extra_args(27, 'k'); key # optional - sage.rings.finite_rings (27, ('k',), x^3 + 2*x + 1, 'givaro', 3, 3, True, None, 'poly', True, True, True) - sage: K = GF.create_object(0, key); K + sage: K = GF.create_object(0, key); K # optional - sage.rings.finite_rings Finite Field in k of size 3^3 - sage: GF.other_keys(key, K) + sage: GF.other_keys(key, K) # optional - sage.rings.finite_rings [] - sage: K = GF(7^40, 'a') - sage: loads(dumps(K)) is K + sage: K = GF(7^40, 'a') # optional - sage.rings.finite_rings + sage: loads(dumps(K)) is K # optional - sage.rings.finite_rings True """ return [] @@ -540,12 +540,12 @@ cdef class UniqueFactory(SageObject): EXAMPLES:: - sage: from sage.modules.free_module import FreeModuleFactory_with_standard_basis as F - sage: V = F(ZZ, 5) - sage: factory, data = F.reduce_data(V) - sage: factory(*data) + sage: from sage.modules.free_module import FreeModuleFactory_with_standard_basis as F # optional - sage.modules + sage: V = F(ZZ, 5) # optional - sage.modules + sage: factory, data = F.reduce_data(V) # optional - sage.modules + sage: factory(*data) # optional - sage.modules Ambient free module of rank 5 over the principal ideal domain Integer Ring - sage: factory(*data) is V + sage: factory(*data) is V # optional - sage.modules True sage: from sage.structure.test_factory import test_factory @@ -638,12 +638,12 @@ def generic_factory_unpickle(factory, *args): EXAMPLES:: - sage: from sage.modules.free_module import FreeModuleFactory_with_standard_basis as F - sage: V = F(ZZ, 5) - sage: func, data = F.reduce_data(V) - sage: func is sage.structure.factory.generic_factory_unpickle + sage: from sage.modules.free_module import FreeModuleFactory_with_standard_basis as F # optional - sage.modules + sage: V = F(ZZ, 5) # optional - sage.modules + sage: func, data = F.reduce_data(V) # optional - sage.modules + sage: func is sage.structure.factory.generic_factory_unpickle # optional - sage.modules True - sage: sage.structure.factory.generic_factory_unpickle(*data) is V + sage: sage.structure.factory.generic_factory_unpickle(*data) is V # optional - sage.modules True TESTS: @@ -730,8 +730,8 @@ def generic_factory_reduce(self, proto): EXAMPLES:: - sage: V = QQ^6 - sage: sage.structure.factory.generic_factory_reduce(V, 1) == V.__reduce_ex__(1) + sage: V = QQ^6 # optional - sage.modules + sage: sage.structure.factory.generic_factory_reduce(V, 1) == V.__reduce_ex__(1) # optional - sage.modules True """ if self._factory_data is None: diff --git a/src/sage/structure/formal_sum.py b/src/sage/structure/formal_sum.py index 7a788c3994f..835d8c040d9 100644 --- a/src/sage/structure/formal_sum.py +++ b/src/sage/structure/formal_sum.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules """ Formal sums @@ -103,24 +104,25 @@ def __init__(self, x, parent=None, check=True, reduce=True): sage: a.reduce() sage: a 4*2/3 - 5*7 - sage: FormalSum([(1,2/3), (3,2/3), (-5, 7)], parent=FormalSums(GF(5))) + sage: FormalSum([(1, 2/3), (3, 2/3), (-5, 7)], parent=FormalSums(GF(5))) # optional - sage.rings.finite_rings 4*2/3 Notice below that the coefficient 5 doesn't get reduced modulo 5:: - sage: FormalSum([(1,2/3), (3,2/3), (-5, 7)], parent=FormalSums(GF(5)), check=False) + sage: FormalSum([(1, 2/3), (3, 2/3), (-5, 7)], parent=FormalSums(GF(5)), # optional - sage.rings.finite_rings + ....: check=False) 4*2/3 - 5*7 Make sure we first reduce before checking coefficient types:: - sage: x,y = var('x, y') - sage: FormalSum([(1/2,x), (2,y)], FormalSums(QQ)) + sage: x,y = var('x, y') # optional - sage.symbolic + sage: FormalSum([(1/2,x), (2,y)], FormalSums(QQ)) # optional - sage.symbolic 1/2*x + 2*y - sage: FormalSum([(1/2,x), (2,y)], FormalSums(ZZ)) + sage: FormalSum([(1/2,x), (2,y)], FormalSums(ZZ)) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: no conversion of this rational to integer - sage: FormalSum([(1/2,x), (1/2,x), (2,y)], FormalSums(ZZ)) + sage: FormalSum([(1/2,x), (1/2,x), (2,y)], FormalSums(ZZ)) # optional - sage.symbolic x + 2*y """ if x == 0: @@ -309,11 +311,12 @@ class FormalSums(UniqueRepresentation, Module): Abelian Group of all Formal Finite Sums over Integer Ring sage: FormalSums(ZZ) Abelian Group of all Formal Finite Sums over Integer Ring - sage: FormalSums(GF(7)) + sage: FormalSums(GF(7)) # optional - sage.rings.finite_rings Abelian Group of all Formal Finite Sums over Finite Field of size 7 - sage: FormalSums(ZZ[sqrt(2)]) - Abelian Group of all Formal Finite Sums over Order in Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? - sage: FormalSums(GF(9,'a')) + sage: FormalSums(ZZ[sqrt(2)]) # optional - sage.symbolic sage.rings.number_field + Abelian Group of all Formal Finite Sums over Order in Number Field in sqrt2 + with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? + sage: FormalSums(GF(9,'a')) # optional - sage.rings.finite_rings Abelian Group of all Formal Finite Sums over Finite Field in a of size 3^2 TESTS:: @@ -338,9 +341,9 @@ def _repr_(self): """ EXAMPLES:: - sage: FormalSums(GF(7)) + sage: FormalSums(GF(7)) # optional - sage.rings.finite_rings Abelian Group of all Formal Finite Sums over Finite Field of size 7 - sage: FormalSums(GF(7))._repr_() + sage: FormalSums(GF(7))._repr_() # optional - sage.rings.finite_rings 'Abelian Group of all Formal Finite Sums over Finite Field of size 7' """ return "Abelian Group of all Formal Finite Sums over %s"%self.base_ring() @@ -400,12 +403,12 @@ def base_extend(self, R): """ EXAMPLES:: - sage: F7 = FormalSums(ZZ).base_extend(GF(7)); F7 + sage: F7 = FormalSums(ZZ).base_extend(GF(7)); F7 # optional - sage.rings.finite_rings Abelian Group of all Formal Finite Sums over Finite Field of size 7 The following tests against a bug that was fixed at :trac:`18795`:: - sage: isinstance(F7, F7.category().parent_class) + sage: isinstance(F7, F7.category().parent_class) # optional - sage.rings.finite_rings True """ if self.base_ring().has_coerce_map_from(R): @@ -418,7 +421,8 @@ def _get_action_(self, other, op, self_is_left): EXAMPLES:: sage: A = FormalSums(RR); A.get_action(RR) # indirect doctest - Right scalar multiplication by Real Field with 53 bits of precision on Abelian Group of all Formal Finite Sums over Real Field with 53 bits of precision + Right scalar multiplication by Real Field with 53 bits of precision + on Abelian Group of all Formal Finite Sums over Real Field with 53 bits of precision sage: A = FormalSums(ZZ); A.get_action(QQ) Right scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field diff --git a/src/sage/structure/global_options.py b/src/sage/structure/global_options.py index c97cee38b3f..b202d7e7871 100644 --- a/src/sage/structure/global_options.py +++ b/src/sage/structure/global_options.py @@ -387,7 +387,7 @@ class options(GlobalOptions): Here is an example to test the pickling of a :class:`GlobalOptions` instance:: - sage: TestSuite(Partitions.options).run() + sage: TestSuite(Partitions.options).run() # optional - sage.combinat TESTS: @@ -526,15 +526,15 @@ class Option(): EXAMPLES:: - sage: Partitions.options.display + sage: Partitions.options.display # optional - sage.combinat list - sage: Partitions.options.display='compact' - sage: Partitions.options.display('list') - sage: Partitions.options._reset() + sage: Partitions.options.display = 'compact' # optional - sage.combinat + sage: Partitions.options.display('list') # optional - sage.combinat + sage: Partitions.options._reset() # optional - sage.combinat TESTS:: - sage: TestSuite(Partitions.options.display).run() + sage: TestSuite(Partitions.options.display).run() # optional - sage.combinat """ __name__ = 'Option class' @@ -545,7 +545,7 @@ def __init__(self, options, name): EXAMPLES:: - sage: type(Partitions.options.display) # indirect doctest + sage: type(Partitions.options.display) # indirect doctest # optional - sage.combinat """ self._name = name @@ -559,7 +559,7 @@ def __repr__(self): EXAMPLES:: - sage: Partitions.options.display # indirect doctest + sage: Partitions.options.display # indirect doctest # optional - sage.combinat list """ # NOTE: we intentionally use str() instead of repr() @@ -572,7 +572,7 @@ def __add__(self, other): EXAMPLES:: - sage: Tableaux.options.convention +' is good' + sage: Tableaux.options.convention + ' is good' # optional - sage.combinat 'English is good' """ return self._options[self._name] + other @@ -584,7 +584,7 @@ def __radd__(self, other): EXAMPLES:: - sage: 'Good '+Tableaux.options.convention + sage: 'Good ' + Tableaux.options.convention # optional - sage.combinat 'Good English' """ return other + self._options[self._name] @@ -596,7 +596,7 @@ def __mul__(self, other): EXAMPLES:: - sage: Tableaux.options.convention +' is good' + sage: Tableaux.options.convention + ' is good' # optional - sage.combinat 'English is good' """ return self._options[self._name] * other @@ -608,7 +608,7 @@ def __rmul__(self, other): EXAMPLES:: - sage: 'Good '+Tableaux.options.convention + sage: 'Good ' + Tableaux.options.convention # optional - sage.combinat 'Good English' """ return other * self._options[self._name] @@ -619,14 +619,14 @@ def __bool__(self) -> bool: EXAMPLES:: - sage: RiggedConfigurations.options.half_width_boxes_type_B + sage: RiggedConfigurations.options.half_width_boxes_type_B # optional - sage.combinat True - sage: 'yes' if RiggedConfigurations.options.half_width_boxes_type_B else 'no' + sage: 'yes' if RiggedConfigurations.options.half_width_boxes_type_B else 'no' # optional - sage.combinat 'yes' - sage: RiggedConfigurations.options.half_width_boxes_type_B=False - sage: 'yes' if RiggedConfigurations.options.half_width_boxes_type_B else 'no' + sage: RiggedConfigurations.options.half_width_boxes_type_B = False # optional - sage.combinat + sage: 'yes' if RiggedConfigurations.options.half_width_boxes_type_B else 'no' # optional - sage.combinat 'no' - sage: RiggedConfigurations.options._reset() + sage: RiggedConfigurations.options._reset() # optional - sage.combinat """ return bool(self._options[self._name]) @@ -636,12 +636,12 @@ def __call__(self, *args, **kwds): EXAMPLES:: - sage: Partitions.options.display() # indirect doctest + sage: Partitions.options.display() # indirect doctest # optional - sage.combinat 'list' - sage: Partitions.options.display('exp') # indirect doctest - sage: Partitions.options.display() # indirect doctest + sage: Partitions.options.display('exp') # indirect doctest # optional - sage.combinat + sage: Partitions.options.display() # indirect doctest # optional - sage.combinat 'exp_low' - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat TESTS: @@ -696,11 +696,11 @@ def __eq__(self, other): EXAMPLES:: - sage: Tableaux.options.convention + sage: Tableaux.options.convention # optional - sage.combinat English - sage: Tableaux.options.convention == "English" + sage: Tableaux.options.convention == "English" # optional - sage.combinat True - sage: Tableaux.options.convention == "French" + sage: Tableaux.options.convention == "French" # optional - sage.combinat False """ return self._options[self._name] == other @@ -712,11 +712,11 @@ def __ne__(self, other): EXAMPLES:: - sage: Tableaux.options.convention + sage: Tableaux.options.convention # optional - sage.combinat English - sage: Tableaux.options.convention != "English" + sage: Tableaux.options.convention != "English" # optional - sage.combinat False - sage: Tableaux.options.convention != "French" + sage: Tableaux.options.convention != "French" # optional - sage.combinat True """ return self._options[self._name] != other @@ -728,7 +728,7 @@ def __hash__(self): EXAMPLES:: - sage: hash(Tableaux.options.convention) == hash(Tableaux.options('convention')) + sage: hash(Tableaux.options.convention) == hash(Tableaux.options('convention')) # optional - sage.combinat True """ return hash(self._options[self._name]) @@ -740,7 +740,7 @@ def __str__(self): EXAMPLES:: - sage: str(Tableaux.options.convention) + sage: str(Tableaux.options.convention) # optional - sage.combinat 'English' """ return str(self._options[self._name]) @@ -1232,7 +1232,7 @@ def _instancedoc_(self): EXAMPLES:: - sage: print(Partitions.options.__doc__) + sage: print(Partitions.options.__doc__) # optional - sage.combinat Sets and displays the global options for elements of the partition, skew partition, and partition tuple classes. If no parameters are @@ -1273,12 +1273,12 @@ def __setattr__(self, name, value=None): EXAMPLES:: - sage: Partitions.options.display = 'exp' - sage: Partitions.options.dispplay = 'list' + sage: Partitions.options.display = 'exp' # optional - sage.combinat + sage: Partitions.options.dispplay = 'list' # optional - sage.combinat Traceback (most recent call last): ... ValueError: dispplay is not an option for Partitions - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat """ # Underscore, and "special", attributes are set using type.__setattr__ if name[0] == '_' or name in ['reset', 'dispatch', 'default_value']: @@ -1298,24 +1298,24 @@ def __setstate__(self, state): EXAMPLES:: - sage: Partitions.options() + sage: Partitions.options() # optional - sage.combinat Current options for Partitions - convention: English - diagram_str: * - display: list - latex: young_diagram - latex_diagram_str: \ast - sage: Partitions.options.convention="French" - sage: pickle = dumps(Partitions.options) - sage: Partitions.options._reset() # reset options - sage: loads(pickle) # indirect doctest + sage: Partitions.options.convention = "French" # optional - sage.combinat + sage: pickle = dumps(Partitions.options) # optional - sage.combinat + sage: Partitions.options._reset() # reset options # optional - sage.combinat + sage: loads(pickle) # indirect doctest # optional - sage.combinat Current options for Partitions - convention: French - diagram_str: * - display: list - latex: young_diagram - latex_diagram_str: \ast - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat """ # open the options for the corresponding "parent" and copy all of # the data from its options class into unpickle @@ -1350,8 +1350,8 @@ def __getstate__(self): EXAMPLES:: - sage: Partitions.options._reset() - sage: Partitions.options.__getstate__() + sage: Partitions.options._reset() # optional - sage.combinat + sage: Partitions.options.__getstate__() # optional - sage.combinat {'convention': 'English', 'option_class': 'Partitions', 'options_module': 'sage.combinat.partition'} @@ -1385,9 +1385,9 @@ def __eq__(self, other): EXAMPLES:: - sage: Partitions.options == PartitionsGreatestLE.options # indirect doctest + sage: Partitions.options == PartitionsGreatestLE.options # indirect doctest # optional - sage.combinat True - sage: Partitions.options == Tableaux.options + sage: Partitions.options == Tableaux.options # optional - sage.combinat False """ return isinstance(other, GlobalOptions) and self.__getstate__() == other.__getstate__() diff --git a/src/sage/structure/indexed_generators.py b/src/sage/structure/indexed_generators.py index 4cf80c3522d..5573ff60834 100644 --- a/src/sage/structure/indexed_generators.py +++ b/src/sage/structure/indexed_generators.py @@ -174,8 +174,8 @@ def indices(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.indices() + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.indices() # optional - sage.modules {'a', 'b', 'c'} """ return self._indices @@ -186,14 +186,14 @@ def prefix(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.prefix() + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.prefix() # optional - sage.modules 'B' :: - sage: X = SchubertPolynomialRing(QQ) - sage: X.prefix() + sage: X = SchubertPolynomialRing(QQ) # optional - sage.combinat + sage: X.prefix() # optional - sage.combinat 'X' """ return self._print_options['prefix'] @@ -229,16 +229,16 @@ def print_options(self, **kwds): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [1,2,3], prefix='x') - sage: F.print_options() + sage: F = CombinatorialFreeModule(ZZ, [1,2,3], prefix='x') # optional - sage.modules + sage: F.print_options() # optional - sage.modules {...'prefix': 'x'...} - sage: F.print_options(bracket='(') - sage: F.print_options() + sage: F.print_options(bracket='(') # optional - sage.modules + sage: F.print_options() # optional - sage.modules {...'bracket': '('...} TESTS:: - sage: sorted(F.print_options().items()) + sage: sorted(F.print_options().items()) # optional - sage.modules [('bracket', '('), ('iterate_key', False), ('latex_bracket', False), ('latex_names', None), ('latex_prefix', None), ('latex_scalar_mult', None), @@ -247,7 +247,7 @@ def print_options(self, **kwds): ('sorting_key', at ...>), ('sorting_reverse', False), ('string_quotes', True), ('tensor_symbol', None)] - sage: F.print_options(bracket='[') # reset + sage: F.print_options(bracket='[') # reset # optional - sage.modules """ # don't just use kwds.get(...) because I want to distinguish # between an argument like "option=None" and the option not @@ -270,33 +270,33 @@ def _parse_names(self, m, use_latex): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [1,2,3], names='a,b,c', + sage: F = CombinatorialFreeModule(ZZ, [1,2,3], names='a,b,c', # optional - sage.modules ....: latex_names='x,y,z') - sage: F._parse_names(1, False) + sage: F._parse_names(1, False) # optional - sage.modules 'a' - sage: F._parse_names(1, True) + sage: F._parse_names(1, True) # optional - sage.modules 'x' - sage: F.print_options(latex_names=None) - sage: F._parse_names(1, True) + sage: F.print_options(latex_names=None) # optional - sage.modules + sage: F._parse_names(1, True) # optional - sage.modules 'a' - sage: F.print_options(latex_names={1:'x', 2:'y'}, names=None) - sage: F._parse_names(1, False) is None + sage: F.print_options(latex_names={1:'x', 2:'y'}, names=None) # optional - sage.modules + sage: F._parse_names(1, False) is None # optional - sage.modules True - sage: F._parse_names(1, True) + sage: F._parse_names(1, True) # optional - sage.modules 'x' - sage: F._parse_names(3, True) is None + sage: F._parse_names(3, True) is None # optional - sage.modules True - sage: F.print_options(names={1:'a', 3:'c'}, latex_names=None) - sage: F._parse_names(1, False) + sage: F.print_options(names={1:'a', 3:'c'}, latex_names=None) # optional - sage.modules + sage: F._parse_names(1, False) # optional - sage.modules 'a' - sage: F._parse_names(1, True) + sage: F._parse_names(1, True) # optional - sage.modules 'a' - sage: F._parse_names(2, False) is None + sage: F._parse_names(2, False) is None # optional - sage.modules True - sage: F._parse_names(2, True) is None + sage: F._parse_names(2, True) is None # optional - sage.modules True """ names = self._print_options.get('names', None) @@ -349,69 +349,69 @@ def _repr_generator(self, m): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: e = F.basis() - sage: e['a'] + 2*e['b'] # indirect doctest + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: e['a'] + 2*e['b'] # indirect doctest # optional - sage.modules B['a'] + 2*B['b'] - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'], prefix="F") - sage: e = F.basis() - sage: e['a'] + 2*e['b'] # indirect doctest + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'], prefix="F") # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: e['a'] + 2*e['b'] # indirect doctest # optional - sage.modules F['a'] + 2*F['b'] - sage: F.print_options(string_quotes=False) - sage: e['a'] + 2*e['b'] + sage: F.print_options(string_quotes=False) # optional - sage.modules + sage: e['a'] + 2*e['b'] # optional - sage.modules F[a] + 2*F[b] - sage: F = CombinatorialFreeModule(QQ, ['aa', 'bb', 'cc'], prefix="F") - sage: e = F.basis() - sage: F.print_options(iterate_key=True) - sage: e['aa'] + 2*e['bb'] + sage: F = CombinatorialFreeModule(QQ, ['aa', 'bb', 'cc'], prefix="F") # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: F.print_options(iterate_key=True) # optional - sage.modules + sage: e['aa'] + 2*e['bb'] # optional - sage.modules F['a', 'a'] + 2*F['b', 'b'] - sage: F.print_options(string_quotes=False) - sage: e['aa'] + 2*e['bb'] + sage: F.print_options(string_quotes=False) # optional - sage.modules + sage: e['aa'] + 2*e['bb'] # optional - sage.modules F[a, a] + 2*F[b, b] - sage: QS3 = CombinatorialFreeModule(QQ, Permutations(3), prefix="") - sage: original_print_options = QS3.print_options() - sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) - sage: a # indirect doctest + sage: QS3 = CombinatorialFreeModule(QQ, Permutations(3), prefix="") # optional - sage.combinat sage.modules + sage: original_print_options = QS3.print_options() # optional - sage.combinat sage.modules + sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) # optional - sage.combinat sage.modules + sage: a # indirect doctest # optional - sage.combinat sage.modules 2*[[1, 2, 3]] + 4*[[3, 2, 1]] - sage: QS3.print_options(bracket = False) - sage: a # indirect doctest + sage: QS3.print_options(bracket = False) # optional - sage.combinat sage.modules + sage: a # indirect doctest # optional - sage.combinat sage.modules 2*[1, 2, 3] + 4*[3, 2, 1] - sage: QS3.print_options(prefix='') - sage: a # indirect doctest + sage: QS3.print_options(prefix='') # optional - sage.combinat sage.modules + sage: a # indirect doctest # optional - sage.combinat sage.modules 2*[1, 2, 3] + 4*[3, 2, 1] - sage: QS3.print_options(bracket="|", scalar_mult=" *@* ") - sage: a # indirect doctest + sage: QS3.print_options(bracket="|", scalar_mult=" *@* ") # optional - sage.combinat sage.modules + sage: a # indirect doctest # optional - sage.combinat sage.modules 2 *@* |[1, 2, 3]| + 4 *@* |[3, 2, 1]| - sage: QS3.print_options(bracket="|", scalar_mult="*", iterate_key=True) - sage: a # indirect doctest + sage: QS3.print_options(bracket="|", scalar_mult="*", iterate_key=True) # optional - sage.combinat sage.modules + sage: a # indirect doctest # optional - sage.combinat sage.modules 2*|1, 2, 3| + 4*|3, 2, 1| - sage: QS3.print_options(**original_print_options) # reset + sage: QS3.print_options(**original_print_options) # reset # optional - sage.combinat sage.modules TESTS:: - sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), ('c','d')]) - sage: e = F.basis() - sage: e[('a','b')] + 2*e[('c','d')] # indirect doctest + sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), ('c','d')]) # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: e[('a','b')] + 2*e[('c','d')] # indirect doctest # optional - sage.modules B[('a', 'b')] + 2*B[('c', 'd')] - sage: F. = CombinatorialFreeModule(QQ) - sage: a + 2*b + sage: F. = CombinatorialFreeModule(QQ) # optional - sage.modules + sage: a + 2*b # optional - sage.modules a + 2*b - sage: F = CombinatorialFreeModule(QQ, ZZ) - sage: e = F.basis() - sage: 3*e[1] + 2*e[-2] + sage: F = CombinatorialFreeModule(QQ, ZZ) # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: 3*e[1] + 2*e[-2] # optional - sage.modules 2*B[-2] + 3*B[1] - sage: F.print_options(iterate_key=True) - sage: 3*e[1] + 2*e[-2] + sage: F.print_options(iterate_key=True) # optional - sage.modules + sage: 3*e[1] + 2*e[-2] # optional - sage.modules 2*B[-2] + 3*B[1] """ ret = self._parse_names(m, False) @@ -457,24 +457,24 @@ def _ascii_art_generator(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: ascii_art(R[1,2,2,4]) + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: ascii_art(R[1,2,2,4]) # optional - sage.combinat R **** ** ** * - sage: Partitions.options(diagram_str="#", convention="french") - sage: ascii_art(R[1,2,2,4]) + sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat + sage: ascii_art(R[1,2,2,4]) # optional - sage.combinat R # ## ## #### - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat - sage: F. = CombinatorialFreeModule(QQ) - sage: ascii_art(a + 2*b) + sage: F. = CombinatorialFreeModule(QQ) # optional - sage.modules + sage: ascii_art(a + 2*b) # optional - sage.modules a + 2*b """ from sage.typeset.ascii_art import AsciiArt, ascii_art @@ -493,26 +493,26 @@ def _unicode_art_generator(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: unicode_art(R[1,2,2,4]) + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: unicode_art(R[1,2,2,4]) # optional - sage.combinat R ┌┬┬┬┐ ┌┼┼┴┴┘ ┌┼┼┘ ├┼┘ └┘ - sage: Partitions.options.convention="french" - sage: unicode_art(R[1,2,2,4]) + sage: Partitions.options.convention="french" # optional - sage.combinat + sage: unicode_art(R[1,2,2,4]) # optional - sage.combinat R ┌┐ ├┼┐ └┼┼┐ └┼┼┬┬┐ └┴┴┴┘ - sage: Partitions.options._reset() + sage: Partitions.options._reset() # optional - sage.combinat - sage: F. = CombinatorialFreeModule(QQ) - sage: unicode_art(a + 2*b) + sage: F. = CombinatorialFreeModule(QQ) # optional - sage.modules + sage: unicode_art(a + 2*b) # optional - sage.modules a + 2*b """ from sage.typeset.unicode_art import UnicodeArt, unicode_art @@ -546,47 +546,49 @@ def _latex_generator(self, m): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: e = F.basis() - sage: latex(e['a'] + 2*e['b']) # indirect doctest + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: latex(e['a'] + 2*e['b']) # indirect doctest # optional - sage.modules B_{a} + 2 B_{b} - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'], prefix="C") - sage: e = F.basis() - sage: latex(e['a'] + 2*e['b']) # indirect doctest + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c'], prefix="C") # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: latex(e['a'] + 2*e['b']) # indirect doctest # optional - sage.modules C_{a} + 2 C_{b} - sage: QS3 = CombinatorialFreeModule(QQ, Permutations(3), prefix="", scalar_mult="*") - sage: original_print_options = QS3.print_options() - sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) - sage: latex(a) # indirect doctest + sage: QS3 = CombinatorialFreeModule(QQ, Permutations(3), # optional - sage.combinat sage.modules + ....: prefix="", scalar_mult="*") + sage: original_print_options = QS3.print_options() # optional - sage.combinat sage.modules + sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) # optional - sage.combinat sage.modules + sage: latex(a) # indirect doctest # optional - sage.combinat sage.modules 2 [1, 2, 3] + 4 [3, 2, 1] - sage: QS3.print_options(latex_bracket=True) - sage: latex(a) # indirect doctest + sage: QS3.print_options(latex_bracket=True) # optional - sage.combinat sage.modules + sage: latex(a) # indirect doctest # optional - sage.combinat sage.modules 2 \left[ [1, 2, 3] \right] + 4 \left[ [3, 2, 1] \right] - sage: QS3.print_options(latex_bracket="(") - sage: latex(a) # indirect doctest + sage: QS3.print_options(latex_bracket="(") # optional - sage.combinat sage.modules + sage: latex(a) # indirect doctest # optional - sage.combinat sage.modules 2 \left( [1, 2, 3] \right) + 4 \left( [3, 2, 1] \right) - sage: QS3.print_options(latex_bracket=('\\myleftbracket', '\\myrightbracket')) - sage: latex(a) # indirect doctest + sage: QS3.print_options(latex_bracket=('\\myleftbracket', # optional - sage.combinat sage.modules + ....: '\\myrightbracket')) + sage: latex(a) # indirect doctest # optional - sage.combinat sage.modules 2 \myleftbracket [1, 2, 3] \myrightbracket + 4 \myleftbracket [3, 2, 1] \myrightbracket - sage: QS3.print_options(**original_print_options) # reset + sage: QS3.print_options(**original_print_options) # reset # optional - sage.combinat sage.modules TESTS:: - sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), (0,1,2)]) - sage: e = F.basis() - sage: latex(e[('a','b')]) # indirect doctest + sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), (0,1,2)]) # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: latex(e[('a','b')]) # indirect doctest # optional - sage.modules B_{('a', 'b')} - sage: latex(2*e[(0,1,2)]) # indirect doctest + sage: latex(2*e[(0,1,2)]) # indirect doctest # optional - sage.modules 2 B_{\left(0, 1, 2\right)} - sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), (0,1,2)], prefix="") - sage: e = F.basis() - sage: latex(2*e[(0,1,2)]) # indirect doctest + sage: F = CombinatorialFreeModule(QQ, [('a', 'b'), (0,1,2)], prefix="") # optional - sage.modules + sage: e = F.basis() # optional - sage.modules + sage: latex(2*e[(0,1,2)]) # indirect doctest # optional - sage.modules 2 \left(0, 1, 2\right) - sage: F. = CombinatorialFreeModule(QQ, latex_names='x,y,z') - sage: latex(a + 2*b) + sage: F. = CombinatorialFreeModule(QQ, latex_names='x,y,z') # optional - sage.modules + sage: latex(a + 2*b) # optional - sage.modules x + 2 y """ from sage.misc.latex import latex diff --git a/src/sage/structure/nonexact.py b/src/sage/structure/nonexact.py index ffb39e5f579..f5894af43ac 100644 --- a/src/sage/structure/nonexact.py +++ b/src/sage/structure/nonexact.py @@ -9,7 +9,7 @@ sage: R. = PowerSeriesRing(QQ) sage: R.default_prec() 20 - sage: cos(x) + sage: cos(x) # optional - sage.symbolic 1 - 1/2*x^2 + 1/24*x^4 - 1/720*x^6 + 1/40320*x^8 - 1/3628800*x^10 + 1/479001600*x^12 - 1/87178291200*x^14 + 1/20922789888000*x^16 - 1/6402373705728000*x^18 + O(x^20) diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 564368806c0..f8b4dc2c9c7 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -86,7 +86,7 @@ TESTS: This came up in some subtle bug once:: - sage: gp(2) + gap(3) + sage: gp(2) + gap(3) # optional - sage.libs.pari 5 """ # **************************************************************************** @@ -361,16 +361,22 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) + sage: Q = P.quotient(x^2 + 2) sage: Q.category() - Join of Category of commutative rings and Category of subquotients of monoids and Category of quotients of semigroups + Join of + Category of commutative rings and + Category of subquotients of monoids and + Category of quotients of semigroups sage: first_class = Q.__class__ sage: Q._refine_category_(Fields()) sage: Q.category() - Join of Category of fields and Category of subquotients of monoids and Category of quotients of semigroups + Join of + Category of fields and + Category of subquotients of monoids and + Category of quotients of semigroups sage: first_class == Q.__class__ False - sage: TestSuite(Q).run() + sage: TestSuite(Q).run() # optional - sage.libs.singular TESTS: @@ -584,8 +590,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: k = GF(5) - sage: k._set_element_constructor() + sage: k = GF(5) # optional - sage.rings.finite_rings + sage: k._set_element_constructor() # optional - sage.rings.finite_rings """ try: _element_constructor_ = self._element_constructor_ @@ -823,7 +829,7 @@ cdef class Parent(sage.structure.category_object.CategoryObject): sage: ZZ._repr_option('ascii_art') False - sage: MatrixSpace(ZZ, 2)._repr_option('element_ascii_art') + sage: MatrixSpace(ZZ, 2)._repr_option('element_ascii_art') # optional - sage.modules True """ if not isinstance(key, basestring): @@ -909,36 +915,36 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules This matrix space is in fact an algebra, and in particular it is a ring, from the point of view of categories:: - sage: MS.category() + sage: MS.category() # optional - sage.modules Category of infinite finite dimensional algebras with basis over (number fields and quotient fields and metric spaces) - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True However, its class does not inherit from the base class ``Ring``:: - sage: isinstance(MS,Ring) + sage: isinstance(MS, Ring) # optional - sage.modules False Its ``_mul_`` method is inherited from the category, and can be used to create a left or right ideal:: - sage: MS._mul_.__module__ + sage: MS._mul_.__module__ # optional - sage.modules 'sage.categories.rings' - sage: MS*MS.1 # indirect doctest + sage: MS * MS.1 # indirect doctest # optional - sage.modules Left Ideal ( [0 1] [0 0] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: MS*[MS.1,2] + sage: MS * [MS.1, 2] # optional - sage.modules Left Ideal ( [0 1] @@ -948,14 +954,14 @@ cdef class Parent(sage.structure.category_object.CategoryObject): [0 2] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: MS.1*MS + sage: MS.1 * MS # optional - sage.modules Right Ideal ( [0 1] [0 0] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: [MS.1,2]*MS + sage: [MS.1, 2] * MS # optional - sage.modules Right Ideal ( [0 1] @@ -1004,22 +1010,22 @@ cdef class Parent(sage.structure.category_object.CategoryObject): TESTS:: - sage: ZZ^3 + sage: ZZ^3 # optional - sage.modules Ambient free module of rank 3 over the principal ideal domain Integer Ring - sage: QQ^3 + sage: QQ^3 # optional - sage.modules Vector space of dimension 3 over Rational Field - sage: QQ[x]^3 + sage: QQ['x']^3 # optional - sage.modules Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: IntegerModRing(6)^3 + sage: IntegerModRing(6)^3 # optional - sage.modules Ambient free module of rank 3 over Ring of integers modulo 6 sage: 3^ZZ Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for ^: 'Integer Ring' and '' - sage: Partitions(3)^3 + sage: Partitions(3)^3 # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: unsupported operand type(s) for ** or pow(): 'Partitions_n_with_category' and 'int' @@ -1077,21 +1083,21 @@ cdef class Parent(sage.structure.category_object.CategoryObject): True sage: I in RR False - sage: SR(2) in ZZ + sage: SR(2) in ZZ # optional - sage.symbolic True sage: RIF(1, 2) in RIF True - sage: pi in RIF # there is no element of RIF equal to pi + sage: pi in RIF # there is no element of RIF equal to pi # optional - sage.symbolic False - sage: sqrt(2) in CC + sage: sqrt(2) in CC # optional - sage.symbolic True - sage: pi in RR + sage: pi in RR # optional - sage.symbolic True - sage: pi in CC + sage: pi in CC # optional - sage.symbolic True - sage: pi in RDF + sage: pi in RDF # optional - sage.symbolic True - sage: pi in CDF + sage: pi in CDF # optional - sage.symbolic True Note that we have @@ -1129,9 +1135,9 @@ cdef class Parent(sage.structure.category_object.CategoryObject): Check that :trac:`13824` is fixed:: - sage: 4/3 in GF(3) + sage: 4/3 in GF(3) # optional - sage.rings.finite_rings False - sage: 15/50 in GF(25, 'a') + sage: 15/50 in GF(25, 'a') # optional - sage.rings.finite_rings False sage: 7/4 in Integers(4) False @@ -1148,9 +1154,9 @@ cdef class Parent(sage.structure.category_object.CategoryObject): Check that :trac:`24209` is fixed:: - sage: I in QQbar + sage: I in QQbar # optional - sage.rings.number_field True - sage: sqrt(-1) in QQbar + sage: sqrt(-1) in QQbar # optional - sage.rings.number_field sage.symbolic True """ P = parent(x) @@ -1194,8 +1200,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): We make an exception for zero:: - sage: V = GF(7)^7 - sage: V.coerce(0) + sage: V = GF(7)^7 # optional - sage.modules sage.rings.finite_rings + sage: V.coerce(0) # optional - sage.modules sage.rings.finite_rings (0, 0, 0, 0, 0, 0, 0) """ cdef R = parent(x) @@ -1233,7 +1239,7 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: VectorSpace(GF(7), 3)[:10] + sage: VectorSpace(GF(7), 3)[:10] # optional - sage.rings.finite_rings [(0, 0, 0), (1, 0, 0), (2, 0, 0), @@ -1370,29 +1376,30 @@ cdef class Parent(sage.structure.category_object.CategoryObject): 6 sage: R. = PolynomialRing(QQ) - sage: f = R.hom([5], GF(7)) + sage: f = R.hom([5], GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators - sage: R. = PolynomialRing(GF(7)) - sage: f = R.hom([3], GF(49,'a')) - sage: f + sage: R. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: f = R.hom([3], GF(49,'a')) # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Finite Field of size 7 To: Finite Field in a of size 7^2 Defn: x |--> 3 - sage: f(x+6) + sage: f(x + 6) # optional - sage.rings.finite_rings 2 - sage: f(x^2+1) + sage: f(x^2 + 1) # optional - sage.rings.finite_rings 3 Natural morphism:: - sage: f = ZZ.hom(GF(5)) - sage: f(7) + sage: f = ZZ.hom(GF(5)) # optional - sage.rings.finite_rings + sage: f(7) # optional - sage.rings.finite_rings 2 - sage: f + sage: f # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 5 @@ -1677,30 +1684,30 @@ cdef class Parent(sage.structure.category_object.CategoryObject): ....: return a.parent()(D) sage: R. = QQ['x, y, z'] - sage: G = SymmetricGroup(3) - sage: act = SymmetricGroupAction(G, R) + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: act = SymmetricGroupAction(G, R) # optional - sage.groups sage: t = x + 2*y + 3*z - sage: act(G((1, 2)), t) + sage: act(G((1, 2)), t) # optional - sage.groups 2*x + y + 3*z - sage: act(G((2, 3)), t) + sage: act(G((2, 3)), t) # optional - sage.groups x + 3*y + 2*z - sage: act(G((1, 2, 3)), t) + sage: act(G((1, 2, 3)), t) # optional - sage.groups 3*x + y + 2*z This should fail, since we have not registered the left action:: - sage: G((1,2)) * t + sage: G((1,2)) * t # optional - sage.groups Traceback (most recent call last): ... TypeError: ... Now let's make it work:: - sage: R._unset_coercions_used() - sage: R.register_action(act) - sage: G((1, 2)) * t + sage: R._unset_coercions_used() # optional - sage.groups + sage: R.register_action(act) # optional - sage.groups + sage: G((1, 2)) * t # optional - sage.groups 2*x + y + 3*z """ if self._coercions_used: @@ -1761,35 +1768,35 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: S3 = AlternatingGroup(3) - sage: G = SL(3, QQ) - sage: p = S3[2]; p.matrix() + sage: S3 = AlternatingGroup(3) # optional - sage.groups + sage: G = SL(3, QQ) # optional - sage.groups + sage: p = S3[2]; p.matrix() # optional - sage.groups [0 0 1] [1 0 0] [0 1 0] In general one cannot mix matrices and permutations:: - sage: G(p) + sage: G(p) # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to convert (1,3,2) to a rational - sage: phi = S3.hom(lambda p: G(p.matrix()), codomain = G) - sage: phi(p) + sage: phi = S3.hom(lambda p: G(p.matrix()), codomain=G) # optional - sage.groups + sage: phi(p) # optional - sage.groups [0 0 1] [1 0 0] [0 1 0] - sage: S3._unset_coercions_used() - sage: S3.register_embedding(phi) + sage: S3._unset_coercions_used() # optional - sage.groups + sage: S3.register_embedding(phi) # optional - sage.groups By :trac:`14711`, coerce maps should be copied when using outside of the coercion system:: - sage: phi = copy(S3.coerce_embedding()); phi + sage: phi = copy(S3.coerce_embedding()); phi # optional - sage.groups Generic morphism: From: Alternating group of order 3!/2 as a permutation group To: Special Linear Group of degree 3 over Rational Field - sage: phi(p) + sage: phi(p) # optional - sage.groups [0 0 1] [1 0 0] [0 1 0] @@ -1797,11 +1804,11 @@ cdef class Parent(sage.structure.category_object.CategoryObject): This does not work since matrix groups are still old-style parents (see :trac:`14014`):: - sage: G(p) # todo: not implemented + sage: G(p) # todo: not implemented # optional - sage.groups Though one can have a permutation act on the rows of a matrix:: - sage: G(1) * p + sage: G(1) * p # optional - sage.groups [0 0 1] [1 0 0] [0 1 0] @@ -1810,29 +1817,30 @@ cdef class Parent(sage.structure.category_object.CategoryObject): sage: x = QQ['x'].0 sage: t = abs(ZZ.random_element(10^6)) - sage: K = NumberField(x^2 + 2*3*7*11, "a"+str(t)) - sage: a = K.gen() - sage: K_into_MS = K.hom([a.matrix()]) - sage: K._unset_coercions_used() - sage: K.register_embedding(K_into_MS) - - sage: L = NumberField(x^2 + 2*3*7*11*19*31, "b"+str(abs(ZZ.random_element(10^6)))) - sage: b = L.gen() - sage: L_into_MS = L.hom([b.matrix()]) - sage: L._unset_coercions_used() - sage: L.register_embedding(L_into_MS) - - sage: K.coerce_embedding()(a) + sage: K = NumberField(x^2 + 2*3*7*11, "a"+str(t)) # optional - sage.rings.number_field + sage: a = K.gen() # optional - sage.rings.number_field + sage: K_into_MS = K.hom([a.matrix()]) # optional - sage.rings.number_field + sage: K._unset_coercions_used() # optional - sage.rings.number_field + sage: K.register_embedding(K_into_MS) # optional - sage.rings.number_field + + sage: L = NumberField(x^2 + 2*3*7*11*19*31, # optional - sage.rings.number_field + ....: "b" + str(abs(ZZ.random_element(10^6)))) + sage: b = L.gen() # optional - sage.rings.number_field + sage: L_into_MS = L.hom([b.matrix()]) # optional - sage.rings.number_field + sage: L._unset_coercions_used() # optional - sage.rings.number_field + sage: L.register_embedding(L_into_MS) # optional - sage.rings.number_field + + sage: K.coerce_embedding()(a) # optional - sage.rings.number_field [ 0 1] [-462 0] - sage: L.coerce_embedding()(b) + sage: L.coerce_embedding()(b) # optional - sage.rings.number_field [ 0 1] [-272118 0] - sage: a.matrix() * b.matrix() + sage: a.matrix() * b.matrix() # optional - sage.rings.number_field [-272118 0] [ 0 -462] - sage: a.matrix() * b.matrix() + sage: a.matrix() * b.matrix() # optional - sage.rings.number_field [-272118 0] [ 0 -462] """ @@ -1865,13 +1873,15 @@ cdef class Parent(sage.structure.category_object.CategoryObject): sage: K. = NumberField(x^3 + x^2 + 1, embedding=1) # optional - sage.rings.number_field sage: K.coerce_embedding() # optional - sage.rings.number_field Generic morphism: - From: Number Field in a with defining polynomial x^3 + x^2 + 1 with a = -1.465571231876768? + From: Number Field in a with defining polynomial x^3 + x^2 + 1 + with a = -1.465571231876768? To: Real Lazy Field Defn: a -> -1.465571231876768? - sage: K.=NumberField(x^3+x^2+1,embedding=CC.gen()) - sage: K.coerce_embedding() + sage: K. = NumberField(x^3 + x^2 + 1, embedding=CC.gen()) # optional - sage.rings.number_field + sage: K.coerce_embedding() # optional - sage.rings.number_field Generic morphism: - From: Number Field in a with defining polynomial x^3 + x^2 + 1 with a = 0.2327856159383841? + 0.7925519925154479?*I + From: Number Field in a with defining polynomial x^3 + x^2 + 1 + with a = 0.2327856159383841? + 0.7925519925154479?*I To: Complex Lazy Field Defn: a -> 0.2327856159383841? + 0.7925519925154479?*I """ @@ -1922,11 +1932,11 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: QQ['x']._generic_convert_map(SR) + sage: QQ['x']._generic_convert_map(SR) # optional - sage.symbolic Conversion via _polynomial_ method map: From: Symbolic Ring To: Univariate Polynomial Ring in x over Rational Field - sage: GF(11)._generic_convert_map(GF(7)) + sage: GF(11)._generic_convert_map(GF(7)) # optional - sage.rings.finite_rings Conversion map: From: Finite Field of size 7 To: Finite Field of size 11 @@ -2045,8 +2055,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): cpdef bint has_coerce_map_from(self, S) except -2: """ - Return True if there is a natural map from S to self. - Otherwise, return False. + Return ``True`` if there is a natural map from ``S`` to ``self``. + Otherwise, return ``False``. EXAMPLES:: @@ -2098,13 +2108,13 @@ cdef class Parent(sage.structure.category_object.CategoryObject): sage: import gc sage: _ = gc.collect() - sage: K = GF(1<<55,'t') - sage: for i in range(50): + sage: K = GF(1<<55,'t') # optional - sage.rings.finite_rings + sage: for i in range(50): # optional - sage.rings.finite_rings sage.schemes ....: a = K.random_element() ....: E = EllipticCurve(j=a) ....: b = K.has_coerce_map_from(E) sage: _ = gc.collect() - sage: len([x for x in gc.get_objects() if isinstance(x,type(E))]) + sage: len([x for x in gc.get_objects() if isinstance(x, type(E))]) # optional - sage.rings.finite_rings sage.schemes 1 TESTS: @@ -2112,12 +2122,12 @@ cdef class Parent(sage.structure.category_object.CategoryObject): The following was fixed in :trac:`12969`:: sage: R = QQ['q,t'].fraction_field() - sage: Sym = sage.combinat.sf.sf.SymmetricFunctions(R) - sage: H = Sym.macdonald().H() - sage: P = Sym.macdonald().P() - sage: m = Sym.monomial() - sage: Ht = Sym.macdonald().Ht() - sage: phi = m.coerce_map_from(P) + sage: Sym = sage.combinat.sf.sf.SymmetricFunctions(R) # optional - sage.combinat sage.modules + sage: H = Sym.macdonald().H() # optional - sage.combinat sage.modules + sage: P = Sym.macdonald().P() # optional - sage.combinat sage.modules + sage: m = Sym.monomial() # optional - sage.combinat sage.modules + sage: Ht = Sym.macdonald().Ht() # optional - sage.combinat sage.modules + sage: phi = m.coerce_map_from(P) # optional - sage.combinat sage.modules """ return copy(self._internal_coerce_map_from(S)) @@ -2148,15 +2158,15 @@ cdef class Parent(sage.structure.category_object.CategoryObject): To: Rational Field sage: R = QQ['q,t'].fraction_field() - sage: Sym = sage.combinat.sf.sf.SymmetricFunctions(R) - sage: P = Sym.macdonald().P() - sage: Ht = Sym.macdonald().Ht() - sage: Ht._internal_coerce_map_from(P) + sage: Sym = sage.combinat.sf.sf.SymmetricFunctions(R) # optional - sage.combinat + sage: P = Sym.macdonald().P() # optional - sage.combinat + sage: Ht = Sym.macdonald().Ht() # optional - sage.combinat + sage: Ht._internal_coerce_map_from(P) # optional - sage.combinat (map internal to coercion system -- copy before use) Composite map: From: Symmetric Functions over Fraction Field of Multivariate Polynomial Ring in q, t over Rational Field in the Macdonald P basis To: Symmetric Functions over Fraction Field of Multivariate Polynomial Ring in q, t over Rational Field in the Macdonald Ht basis - sage: copy(Ht._internal_coerce_map_from(P)) + sage: copy(Ht._internal_coerce_map_from(P)) # optional - sage.combinat Composite map: From: Symmetric Functions over Fraction Field of Multivariate Polynomial Ring in q, t over Rational Field in the Macdonald P basis To: Symmetric Functions over Fraction Field of Multivariate Polynomial Ring in q, t over Rational Field in the Macdonald Ht basis @@ -2174,8 +2184,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): The following was fixed in :trac:`4740`:: - sage: F = GF(13) - sage: F._internal_coerce_map_from(F) is F._internal_coerce_map_from(F) + sage: F = GF(13) # optional - sage.rings.finite_rings + sage: F._internal_coerce_map_from(F) is F._internal_coerce_map_from(F) # optional - sage.rings.finite_rings True """ if not good_as_coerce_domain(S): @@ -2295,9 +2305,9 @@ cdef class Parent(sage.structure.category_object.CategoryObject): sage: p = QQ.random_element() # optional - sage.rings.number_field sage: c = phi(p) - p; c # optional - sage.rings.number_field 0 - sage: c.parent() is M + sage: c.parent() is M # optional - sage.rings.number_field True - sage: K.coerce_map_from(QQ) + sage: K.coerce_map_from(QQ) # optional - sage.rings.number_field Coercion map: From: Rational Field To: Number Field in a with defining polynomial x^2 - 2 over its base field @@ -2319,16 +2329,18 @@ cdef class Parent(sage.structure.category_object.CategoryObject): Check that :trac:`14982` is fixed, and more generally that we discover sensible coercion paths in the presence of embeddings:: - sage: K. = NumberField(x^2+1/2, embedding=CC(0,1)) - sage: L = NumberField(x^2+2, 'b', embedding=1/a) - sage: PolynomialRing(L, 'x').coerce_map_from(L) + sage: K. = NumberField(x^2 + 1/2, embedding=CC(0, 1)) # optional - sage.rings.number_field + sage: L = NumberField(x^2 + 2, 'b', embedding=1/a) # optional - sage.rings.number_field + sage: PolynomialRing(L, 'x').coerce_map_from(L) # optional - sage.rings.number_field Polynomial base injection morphism: From: Number Field in b with defining polynomial x^2 + 2 with b = -2*a - To: Univariate Polynomial Ring in x over Number Field in b with defining polynomial x^2 + 2 with b = -2*a - sage: PolynomialRing(K, 'x').coerce_map_from(L) + To: Univariate Polynomial Ring in x over Number Field in b + with defining polynomial x^2 + 2 with b = -2*a + sage: PolynomialRing(K, 'x').coerce_map_from(L) # optional - sage.rings.number_field Composite map: From: Number Field in b with defining polynomial x^2 + 2 with b = -2*a - To: Univariate Polynomial Ring in x over Number Field in a with defining polynomial x^2 + 1/2 with a = 0.7071067811865475?*I + To: Univariate Polynomial Ring in x over Number Field in a + with defining polynomial x^2 + 1/2 with a = 0.7071067811865475?*I Defn: Generic morphism: From: Number Field in b with defining polynomial x^2 + 2 with b = -2*a To: Number Field in a with defining polynomial x^2 + 1/2 with a = 0.7071067811865475?*I @@ -2336,15 +2348,18 @@ cdef class Parent(sage.structure.category_object.CategoryObject): then Polynomial base injection morphism: From: Number Field in a with defining polynomial x^2 + 1/2 with a = 0.7071067811865475?*I - To: Univariate Polynomial Ring in x over Number Field in a with defining polynomial x^2 + 1/2 with a = 0.7071067811865475?*I - sage: MatrixSpace(L, 2, 2).coerce_map_from(L) + To: Univariate Polynomial Ring in x over Number Field in a + with defining polynomial x^2 + 1/2 with a = 0.7071067811865475?*I + sage: MatrixSpace(L, 2, 2).coerce_map_from(L) # optional - sage.rings.number_field Coercion map: From: Number Field in b with defining polynomial x^2 + 2 with b = -2*a - To: Full MatrixSpace of 2 by 2 dense matrices over Number Field in b with defining polynomial x^2 + 2 with b = -2*a - sage: PowerSeriesRing(L, 'x').coerce_map_from(L) + To: Full MatrixSpace of 2 by 2 dense matrices over Number Field in b + with defining polynomial x^2 + 2 with b = -2*a + sage: PowerSeriesRing(L, 'x').coerce_map_from(L) # optional - sage.rings.number_field Coercion map: From: Number Field in b with defining polynomial x^2 + 2 with b = -2*a - To: Power Series Ring in x over Number Field in b with defining polynomial x^2 + 2 with b = -2*a + To: Power Series Ring in x over Number Field in b + with defining polynomial x^2 + 2 with b = -2*a """ if isinstance(S, Parent) and (S)._embedding is not None: if (S)._embedding.codomain() is self: @@ -2540,10 +2555,14 @@ cdef class Parent(sage.structure.category_object.CategoryObject): TESTS:: - sage: M = QQ['y']^3 - sage: M.get_action(ZZ['x']['y']) - Right scalar multiplication by Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring on Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field - sage: print(M.get_action(ZZ['x'])) + sage: M = QQ['y']^3 # optional - sage.modules + sage: M.get_action(ZZ['x']['y']) # optional - sage.modules + Right scalar multiplication + by Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Integer Ring + on Ambient free module of rank 3 over the principal ideal domain + Univariate Polynomial Ring in y over Rational Field + sage: print(M.get_action(ZZ['x'])) # optional - sage.modules None """ action = self._get_action_(S, op, self_on_left) @@ -2562,33 +2581,40 @@ cdef class Parent(sage.structure.category_object.CategoryObject): """ TESTS:: - sage: E = EllipticCurve([1,0]) - sage: coercion_model.get_action(E, ZZ, operator.mul) - Right Integer Multiplication by Integer Ring on Elliptic Curve defined by y^2 = x^3 + x over Rational Field - sage: coercion_model.get_action(ZZ, E, operator.mul) - Left Integer Multiplication by Integer Ring on Elliptic Curve defined by y^2 = x^3 + x over Rational Field - sage: coercion_model.get_action(E, int, operator.mul) - Right Integer Multiplication by Set of Python objects of class 'int' on Elliptic Curve defined by y^2 = x^3 + x over Rational Field - sage: coercion_model.get_action(int, E, operator.mul) - Left Integer Multiplication by Set of Python objects of class 'int' on Elliptic Curve defined by y^2 = x^3 + x over Rational Field + sage: E = EllipticCurve([1,0]) # optional - sage.schemes + sage: coercion_model.get_action(E, ZZ, operator.mul) # optional - sage.schemes + Right Integer Multiplication by Integer Ring + on Elliptic Curve defined by y^2 = x^3 + x over Rational Field + sage: coercion_model.get_action(ZZ, E, operator.mul) # optional - sage.schemes + Left Integer Multiplication by Integer Ring + on Elliptic Curve defined by y^2 = x^3 + x over Rational Field + sage: coercion_model.get_action(E, int, operator.mul) # optional - sage.schemes + Right Integer Multiplication by Set of Python objects of class 'int' + on Elliptic Curve defined by y^2 = x^3 + x over Rational Field + sage: coercion_model.get_action(int, E, operator.mul) # optional - sage.schemes + Left Integer Multiplication by Set of Python objects of class 'int' + on Elliptic Curve defined by y^2 = x^3 + x over Rational Field :: sage: R. = CDF[] sage: coercion_model.get_action(R, ZZ, operator.pow) - Right Integer Powering by Integer Ring on Univariate Polynomial Ring in x over Complex Double Field + Right Integer Powering by Integer Ring + on Univariate Polynomial Ring in x over Complex Double Field sage: print(coercion_model.get_action(ZZ, R, operator.pow)) None sage: coercion_model.get_action(R, int, operator.pow) - Right Integer Powering by Set of Python objects of class 'int' on Univariate Polynomial Ring in x over Complex Double Field + Right Integer Powering by Set of Python objects of class 'int' + on Univariate Polynomial Ring in x over Complex Double Field sage: print(coercion_model.get_action(int, R, operator.pow)) None sage: coercion_model.get_action(R, IntegerModRing(7), operator.pow) - Right Integer Powering by Ring of integers modulo 7 on Univariate Polynomial Ring in x over Complex Double Field + Right Integer Powering by Ring of integers modulo 7 + on Univariate Polynomial Ring in x over Complex Double Field :: - sage: print(coercion_model.get_action(E, ZZ, operator.pow)) + sage: print(coercion_model.get_action(E, ZZ, operator.pow)) # optional - sage.schemes None """ # G acts on S, G -> G', R -> S => G' acts on R (?) @@ -2791,9 +2817,9 @@ cdef class Parent(sage.structure.category_object.CategoryObject): True sage: ZZ.is_exact() True - sage: Qp(7).is_exact() + sage: Qp(7).is_exact() # optional - sage.rings.padics False - sage: Zp(7, type='capped-abs').is_exact() + sage: Zp(7, type='capped-abs').is_exact() # optional - sage.rings.padics False """ return True @@ -2806,12 +2832,18 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: [R._is_numerical() for R in [RR, CC, QQ, QuadraticField(-1)]] - [True, True, True, True] - sage: [R._is_numerical() for R in [SR, QQ['x'], QQ[['x']]]] - [False, False, False] - sage: [R._is_numerical() for R in [RIF, RBF, CIF, CBF]] - [False, False, False, False] + sage: QuadraticField(-1)._is_numerical() # optional - sage.rings.number_field + True + sage: [R._is_numerical() for R in [RR, CC, QQ]] + [True, True, True] + sage: SR._is_numerical() # optional - sage.symbolic + False + sage: [R._is_numerical() for R in [QQ['x'], QQ[['x']]]] + [False, False] + sage: [R._is_numerical() for R in [RBF, CBF]] # optional - sage.libs.flint + [False, False] + sage: [R._is_numerical() for R in [RIF, CIF]] + [False, False] """ try: from sage.rings.complex_mpfr import ComplexField @@ -2832,14 +2864,22 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: [R._is_real_numerical() for R in [RR, QQ, ZZ, RLF, QuadraticField(2)]] - [True, True, True, True, True] - sage: [R._is_real_numerical() for R in [CC, QuadraticField(-1)]] + sage: QuadraticField(2)._is_real_numerical() # optional - sage.rings.number_field + True + sage: [R._is_real_numerical() for R in [RR, QQ, ZZ, RLF]] + [True, True, True, True] + sage: QuadraticField(-1)._is_real_numerical() # optional - sage.rings.number_field + False + sage: CC._is_real_numerical() + False + sage: SR._is_real_numerical() # optional - sage.symbolic + False + sage: [R._is_real_numerical() for R in [QQ['x'], QQ[['x']]]] + [False, False] + sage: [R._is_real_numerical() for R in [RBF, CBF]] # optional - sage.libs.flint + [False, False] + sage: [R._is_real_numerical() for R in [RIF, CIF]] # optional - sage.libs.flint [False, False] - sage: [R._is_real_numerical() for R in [SR, QQ['x'], QQ[['x']]]] - [False, False, False] - sage: [R._is_real_numerical() for R in [RIF, RBF, CIF, CBF]] - [False, False, False, False] """ try: from sage.rings.real_mpfr import RealField, mpfr_prec_min @@ -2885,7 +2925,7 @@ cdef class Set_generic(Parent): sage: bool(Set(QQ)) True - sage: bool(Set(GF(3))) + sage: bool(Set(GF(3))) # optional - sage.rings.finite_rings True """ return not (self.is_finite() and len(self) == 0) @@ -2926,9 +2966,9 @@ cdef class EltPair: Verify that :trac:`16341` has been resolved:: - sage: K. = Qq(9) # optional - sage.rings.padics - sage: E = EllipticCurve_from_j(0).base_extend(K) # optional - sage.rings.padics - sage: E.get_action(ZZ) # optional - sage.rings.padics + sage: K. = Qq(9) # optional - sage.rings.padics + sage: E = EllipticCurve_from_j(0).base_extend(K) # optional - sage.rings.padics + sage: E.get_action(ZZ) # optional - sage.rings.padics Right Integer Multiplication by Integer Ring on Elliptic Curve defined by y^2 + (1+O(3^20))*y = x^3 diff --git a/src/sage/structure/parent_gens.pyx b/src/sage/structure/parent_gens.pyx index 332ec274a42..43540c75254 100644 --- a/src/sage/structure/parent_gens.pyx +++ b/src/sage/structure/parent_gens.pyx @@ -47,14 +47,14 @@ This example illustrates generators for a free module over `\ZZ`. :: - sage: M = FreeModule(ZZ, 4) - sage: M + sage: M = FreeModule(ZZ, 4) # optional - sage.modules + sage: M # optional - sage.modules Ambient free module of rank 4 over the principal ideal domain Integer Ring - sage: M.ngens() + sage: M.ngens() # optional - sage.modules 4 - sage: M.gen(0) + sage: M.gen(0) # optional - sage.modules (1, 0, 0, 0) - sage: M.gens() + sage: M.gens() # optional - sage.modules ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) """ @@ -240,31 +240,31 @@ cdef class ParentWithGens(ParentWithBase): 6 sage: R. = PolynomialRing(QQ) - sage: f = R.hom([5], GF(7)) + sage: f = R.hom([5], GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: relations do not all (canonically) map to 0 under map determined by images of generators - sage: R. = PolynomialRing(GF(7)) - sage: f = R.hom([3], GF(49,'a')) - sage: f + sage: R. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: f = R.hom([3], GF(49, 'a')) # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Finite Field of size 7 To: Finite Field in a of size 7^2 Defn: x |--> 3 - sage: f(x+6) + sage: f(x + 6) # optional - sage.rings.finite_rings 2 - sage: f(x^2+1) + sage: f(x^2 + 1) # optional - sage.rings.finite_rings 3 EXAMPLES: Natural morphism :: - sage: f = ZZ.hom(GF(5)) - sage: f(7) + sage: f = ZZ.hom(GF(5)) # optional - sage.rings.finite_rings + sage: f(7) # optional - sage.rings.finite_rings 2 - sage: f + sage: f # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 5 @@ -280,13 +280,13 @@ cdef class ParentWithGens(ParentWithBase): You can specify a map on the base ring:: - sage: k = GF(2) - sage: R. = k[] - sage: l. = k.extension(a^3 + a^2 + 1) - sage: R. = l[] - sage: m. = l.extension(b^2 + b + a) - sage: n. = GF(2^6) - sage: m.hom([z^4 + z^3 + 1], base_map=l.hom([z^5 + z^4 + z^2])) + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: l. = k.extension(a^3 + a^2 + 1) # optional - sage.rings.finite_rings + sage: R. = l[] # optional - sage.rings.finite_rings + sage: m. = l.extension(b^2 + b + a) # optional - sage.rings.finite_rings + sage: n. = GF(2^6) # optional - sage.rings.finite_rings + sage: m.hom([z^4 + z^3 + 1], base_map=l.hom([z^5 + z^4 + z^2])) # optional - sage.rings.finite_rings Ring morphism: From: Univariate Quotient Polynomial Ring in b over Finite Field in a of size 2^3 with modulus b^2 + b + a To: Finite Field in z of size 2^6 @@ -335,7 +335,7 @@ cdef class localvars: EXAMPLES:: - sage: R. = PolynomialRing(QQ,2) + sage: R. = PolynomialRing(QQ, 2) sage: with localvars(R, 'z,w'): ....: print(x^3 + y^3 - x*y) z^3 + w^3 - z*w diff --git a/src/sage/structure/parent_old.pyx b/src/sage/structure/parent_old.pyx index 097acdd55de..adb70af2b98 100644 --- a/src/sage/structure/parent_old.pyx +++ b/src/sage/structure/parent_old.pyx @@ -13,7 +13,7 @@ TESTS: This came up in some subtle bug once:: - sage: gp(2) + gap(3) + sage: gp(2) + gap(3) # optional - sage.libs.gap sage.libs.pari 5 """ @@ -46,19 +46,19 @@ cdef class Parent(parent.Parent): TESTS:: - sage: V = VectorSpace(GF(2,'a'),2) - sage: V.list() + sage: V = VectorSpace(GF(2,'a'), 2) # optional - sage.modules sage.rings.finite_rings + sage: V.list() # optional - sage.modules sage.rings.finite_rings [(0, 0), (1, 0), (0, 1), (1, 1)] - sage: MatrixSpace(GF(3), 1, 1).list() + sage: MatrixSpace(GF(3), 1, 1).list() # optional - sage.modules sage.rings.finite_rings [[0], [1], [2]] - sage: DirichletGroup(3).list() + sage: DirichletGroup(3).list() # optional - sage.groups [Dirichlet character modulo 3 of conductor 1 mapping 2 |--> 1, - Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1] - sage: K = GF(7^6,'a') - sage: K.list()[:10] # long time + Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1] + sage: K = GF(7^6,'a') # optional - sage.rings.finite_rings + sage: K.list()[:10] # long time # optional - sage.rings.finite_rings [0, 1, 2, 3, 4, 5, 6, a, a + 1, a + 2] - sage: K. = GF(4) - sage: K.list() + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: K.list() # optional - sage.rings.finite_rings [0, a, a + 1, 1] """ diff --git a/src/sage/structure/proof/proof.py b/src/sage/structure/proof/proof.py index a5a931f5675..b232225da33 100644 --- a/src/sage/structure/proof/proof.py +++ b/src/sage/structure/proof/proof.py @@ -196,10 +196,12 @@ class WithProof(): systems for a block of code, with a guarantee that it will be set back to how it was before after the block is done, even if there is an error. - EXAMPLES:: + EXAMPLES: + + This would hang "forever" if attempted with ``proof=True``:: sage: proof.arithmetic(True) - sage: with proof.WithProof('arithmetic',False): # this would hang "forever" if attempted with proof=True + sage: with proof.WithProof('arithmetic', False): # optional - sage.libs.pari ....: print((10^1000 + 453).is_prime()) ....: print(1/0) Traceback (most recent call last): diff --git a/src/sage/structure/sequence.py b/src/sage/structure/sequence.py index 45ca7765e3d..1286d6a1114 100644 --- a/src/sage/structure/sequence.py +++ b/src/sage/structure/sequence.py @@ -45,8 +45,8 @@ special parent. This is what should happen, e.g., with finite field elements of different characteristics:: - sage: v = Sequence([GF(3)(1), GF(7)(1)]) - sage: v.universe() + sage: v = Sequence([GF(3)(1), GF(7)(1)]) # optional - sage.rings.finite_rings + sage: v.universe() # optional - sage.rings.finite_rings Category of objects You can make a list immutable with ``v.freeze()``. Assignment is @@ -201,9 +201,9 @@ def Sequence(x, universe=None, check=True, immutable=False, cr=False, cr_str=Non This example illustrates how every element of a list is taken into account when constructing a sequence.:: - sage: v = Sequence([1,7,6,GF(5)(3)]); v + sage: v = Sequence([1, 7, 6, GF(5)(3)]); v # optional - sage.rings.finite_rings [1, 2, 1, 3] - sage: v.universe() + sage: v.universe() # optional - sage.rings.finite_rings Finite Field of size 5 TESTS:: @@ -397,9 +397,9 @@ class Sequence_generic(sage.structure.sage_object.SageObject, list): :: - sage: v = Sequence([1,7,6,GF(5)(3)]); v + sage: v = Sequence([1, 7, 6, GF(5)(3)]); v # optional - sage.rings.finite_rings [1, 2, 1, 3] - sage: v.universe() + sage: v.universe() # optional - sage.rings.finite_rings Finite Field of size 5 """ @@ -674,11 +674,11 @@ def _latex_(self): r""" TESTS:: - sage: t= Sequence([sqrt(x), exp(x), x^(x-1)], universe=SR); t + sage: t= Sequence([sqrt(x), exp(x), x^(x-1)], universe=SR); t # optional - sage.symbolic [sqrt(x), e^x, x^(x - 1)] - sage: t._latex_() + sage: t._latex_() # optional - sage.symbolic '\\left[\\sqrt{x}, e^{x}, x^{x - 1}\\right]' - sage: latex(t) + sage: latex(t) # optional - sage.symbolic \left[\sqrt{x}, e^{x}, x^{x - 1}\right] """ from sage.misc.latex import list_function as list_latex_function @@ -710,9 +710,9 @@ def universe(self): EXAMPLES:: - sage: Sequence([1,2/3,-2/5]).universe() + sage: Sequence([1, 2/3, -2/5]).universe() Rational Field - sage: Sequence([1,2/3,'-2/5']).universe() + sage: Sequence([1, 2/3, '-2/5']).universe() Category of objects """ return self.__universe @@ -738,7 +738,7 @@ def set_immutable(self): EXAMPLES:: - sage: v = Sequence([1,2,3,4/5]) + sage: v = Sequence([1, 2, 3, 4/5]) sage: v[0] = 5 sage: v [5, 2, 3, 4/5] @@ -759,7 +759,7 @@ def is_immutable(self): EXAMPLES:: - sage: v = Sequence([1,2,3,4/5]) + sage: v = Sequence([1, 2, 3, 4/5]) sage: v[0] = 5 sage: v [5, 2, 3, 4/5] @@ -778,7 +778,7 @@ def is_mutable(self): """ EXAMPLES:: - sage: a = Sequence([1,2/3,-2/5]) + sage: a = Sequence([1, 2/3, -2/5]) sage: a.is_mutable() True sage: a[0] = 100 diff --git a/src/sage/structure/unique_representation.py b/src/sage/structure/unique_representation.py index 7d30c39d66c..c6ffa9cb739 100644 --- a/src/sage/structure/unique_representation.py +++ b/src/sage/structure/unique_representation.py @@ -21,13 +21,13 @@ instances constructed with the same arguments share the same memory representation. For example, calling twice:: - sage: G = SymmetricGroup(6) - sage: H = SymmetricGroup(6) + sage: G = SymmetricGroup(6) # optional - sage.groups + sage: H = SymmetricGroup(6) # optional - sage.groups to create the symmetric group on six elements gives back the same object:: - sage: G is H + sage: G is H # optional - sage.groups True This is a standard design pattern. Besides saving memory, it allows for @@ -100,9 +100,9 @@ class will by default also be used as keys for the cache:: since ``C(1)`` already is in the cache, and since the unit elements in different finite fields are all equal to the integer one, we find:: - sage: GF(5)(1) == 1 == GF(3)(1) + sage: GF(5)(1) == 1 == GF(3)(1) # optional - sage.rings.finite_rings True - sage: C(1) is C(GF(3)(1)) is C(GF(5)(1)) + sage: C(1) is C(GF(3)(1)) is C(GF(5)(1)) # optional - sage.rings.finite_rings True But ``C(2)`` is not in the cache, and the number two is not equal in different @@ -112,9 +112,9 @@ class will by default also be used as keys for the cache:: when comparing elements of *distinct* algebraic structures!!). Hence, we have:: - sage: GF(5)(2) == GF(3)(2) + sage: GF(5)(2) == GF(3)(2) # optional - sage.rings.finite_rings False - sage: C(GF(3)(2)) is C(GF(5)(2)) + sage: C(GF(3)(2)) is C(GF(5)(2)) # optional - sage.rings.finite_rings False Normalising the arguments @@ -424,10 +424,10 @@ class is directly created, then the cache is not used:: Using :class:`CachedRepresentation` has the advantage that one has a class and creates cached instances of this class by the usual Python syntax:: - sage: G = SymmetricGroup(6) - sage: issubclass(SymmetricGroup, sage.structure.unique_representation.CachedRepresentation) + sage: G = SymmetricGroup(6) # optional - sage.groups + sage: issubclass(SymmetricGroup, sage.structure.unique_representation.CachedRepresentation) # optional - sage.groups True - sage: isinstance(G, SymmetricGroup) + sage: isinstance(G, SymmetricGroup) # optional - sage.groups True In contrast, a factory is just a callable object that returns something that @@ -436,14 +436,14 @@ class is directly created, then the cache is not used:: sage: isinstance(GF, sage.structure.factory.UniqueFactory) True - sage: K5 = GF(5) - sage: type(K5) + sage: K5 = GF(5) # optional - sage.rings.finite_rings + sage: type(K5) # optional - sage.rings.finite_rings - sage: K25 = GF(25, 'x') - sage: type(K25) + sage: K25 = GF(25, 'x') # optional - sage.rings.finite_rings + sage: type(K25) # optional - sage.rings.finite_rings - sage: Kp = GF(next_prime_power(1000000)^2, 'x') - sage: type(Kp) + sage: Kp = GF(next_prime_power(1000000)^2, 'x') # optional - sage.rings.finite_rings + sage: type(Kp) # optional - sage.rings.finite_rings This can be confusing to the user. Namely, the user might determine the class @@ -498,13 +498,13 @@ class :class:`~sage.misc.fast_methods.WithEqualityById`, which provides since they are equal to groups created in a totally different way, namely to subgroups:: - sage: G = SymmetricGroup(6) - sage: G3 = G.subgroup([G((1,2,3,4,5,6)),G((1,2))]) - sage: G is G3 + sage: G = SymmetricGroup(6) # optional - sage.groups + sage: G3 = G.subgroup([G((1,2,3,4,5,6)), G((1,2))]) # optional - sage.groups + sage: G is G3 # optional - sage.groups False - sage: type(G) == type(G3) + sage: type(G) == type(G3) # optional - sage.groups False - sage: G == G3 + sage: G == G3 # optional - sage.groups True The unique representation behaviour can conveniently be implemented with a @@ -517,9 +517,9 @@ class that inherits from :class:`UniqueRepresentation`: By adding ring. Thus, it is reasonable to use :class:`UniqueRepresentation` in this case:: - sage: isinstance(SymmetricFunctions(CC), SymmetricFunctions) + sage: isinstance(SymmetricFunctions(CC), SymmetricFunctions) # optional - sage.combinat True - sage: issubclass(SymmetricFunctions, UniqueRepresentation) + sage: issubclass(SymmetricFunctions, UniqueRepresentation) # optional - sage.combinat True :class:`UniqueRepresentation` differs from :class:`CachedRepresentation` only @@ -1188,15 +1188,15 @@ class UniqueRepresentation(CachedRepresentation, WithEqualityById): the same memory representation), if and only if they were created using equal arguments. For example, calling twice:: - sage: f = SymmetricFunctions(QQ) - sage: g = SymmetricFunctions(QQ) + sage: f = SymmetricFunctions(QQ) # optional - sage.combinat sage.modules + sage: g = SymmetricFunctions(QQ) # optional - sage.combinat sage.modules to create the symmetric function algebra over `\QQ` actually gives back the same object:: - sage: f == g + sage: f == g # optional - sage.combinat sage.modules True - sage: f is g + sage: f is g # optional - sage.combinat sage.modules True This is a standard design pattern. It allows for sharing cached data (say @@ -1211,19 +1211,19 @@ class UniqueRepresentation(CachedRepresentation, WithEqualityById): derive from it, or make sure some of its super classes does. Also, it groups together the class and the factory in a single gadget:: - sage: isinstance(SymmetricFunctions(CC), SymmetricFunctions) + sage: isinstance(SymmetricFunctions(CC), SymmetricFunctions) # optional - sage.combinat sage.modules True - sage: issubclass(SymmetricFunctions, UniqueRepresentation) + sage: issubclass(SymmetricFunctions, UniqueRepresentation) # optional - sage.combinat sage.modules True This nice behaviour is not available when one just uses a factory:: - sage: isinstance(GF(7), GF) + sage: isinstance(GF(7), GF) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: isinstance() arg 2 must be a type... - sage: isinstance(GF, sage.structure.factory.UniqueFactory) + sage: isinstance(GF, sage.structure.factory.UniqueFactory) # optional - sage.rings.finite_rings True In addition, :class:`~sage.structure.factory.UniqueFactory` only provides