diff --git a/src/sage/arith/functions.pyx b/src/sage/arith/functions.pyx index 2fe15bbb974..58a1fc91bd9 100644 --- a/src/sage/arith/functions.pyx +++ b/src/sage/arith/functions.pyx @@ -39,17 +39,17 @@ def lcm(a, b=None): EXAMPLES:: - sage: lcm(97,100) + sage: lcm(97, 100) 9700 - sage: LCM(97,100) + sage: LCM(97, 100) 9700 - sage: LCM(0,2) + sage: LCM(0, 2) 0 - sage: LCM(-3,-5) + sage: LCM(-3, -5) 15 sage: LCM([1,2,3,4,5]) 60 - sage: v = LCM(range(1,10000)) # *very* fast! + sage: v = LCM(range(1, 10000)) # *very* fast! sage: len(str(v)) 4349 @@ -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 9c671105c5a..1bcf0545f7d 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) @@ -543,8 +550,9 @@ def is_prime(n): However, number fields redefine ``.is_prime()`` in an incompatible fashion (cf. :trac:`32340`) and we should not warn:: - sage: K. = NumberField(x^2+1) - sage: is_prime(1+i) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: is_prime(1 + i) # optional - sage.rings.number_field True """ try: @@ -585,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() @@ -620,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) @@ -687,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) @@ -783,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)) @@ -821,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") @@ -878,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) @@ -931,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: @@ -973,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)) @@ -1046,41 +1054,41 @@ def primes(start=2, stop=None, proof=None): 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 @@ -1120,40 +1128,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() @@ -1171,22 +1179,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() @@ -1210,33 +1218,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) @@ -1249,38 +1257,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 @@ -1315,52 +1323,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() @@ -1388,42 +1396,42 @@ def random_prime(n, proof=None, lbound=2): 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) @@ -1515,22 +1523,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)) @@ -1592,13 +1600,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: @@ -1610,21 +1618,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): @@ -1648,9 +1656,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) @@ -1692,8 +1700,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)] @@ -1783,33 +1791,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)) @@ -1908,8 +1916,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)) @@ -1974,15 +1982,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 @@ -1998,10 +2006,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)) @@ -2013,10 +2021,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: @@ -2131,20 +2139,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: @@ -2221,13 +2229,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:: @@ -2235,7 +2243,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:: @@ -2249,11 +2257,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: @@ -2372,8 +2380,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)) @@ -2407,16 +2415,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) @@ -2480,8 +2488,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)) @@ -2512,10 +2520,10 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): 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: @@ -2578,7 +2586,7 @@ 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 :: @@ -2606,7 +2614,7 @@ 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. @@ -2616,42 +2624,42 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): :: - 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:: @@ -2703,14 +2711,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)) @@ -2763,13 +2771,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)) @@ -2801,8 +2809,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)) @@ -2845,8 +2853,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)) @@ -2901,8 +2909,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)) @@ -2940,47 +2948,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) @@ -3017,11 +3025,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 @@ -3040,7 +3048,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] @@ -3050,22 +3058,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: @@ -3093,9 +3101,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: @@ -3129,8 +3137,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)] @@ -3186,7 +3194,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 @@ -3194,19 +3202,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: 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 @@ -3216,7 +3224,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): @@ -3231,7 +3239,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}` @@ -3240,12 +3248,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: @@ -3265,7 +3273,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: @@ -3346,50 +3354,55 @@ def crt(a, b, m=None, n=None): Note that this also works for polynomial rings:: - sage: K. = NumberField(x^3 - 7) - sage: R. = K[] - sage: f = y^2 + 3 - sage: g = y^3 - 5 - sage: CRT(1,3,f,g) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = y^2 + 3 # optional - sage.rings.number_field + 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 @@ -3399,13 +3412,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): @@ -3492,8 +3505,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)]) @@ -3597,7 +3610,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: @@ -3639,15 +3652,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 @@ -3655,11 +3668,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 @@ -3667,7 +3680,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 @@ -3688,21 +3701,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 @@ -3759,8 +3772,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 @@ -3797,15 +3810,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)) @@ -3886,17 +3899,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)) @@ -3952,8 +3965,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()) @@ -4029,8 +4042,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()) @@ -4118,8 +4131,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)) @@ -4170,8 +4183,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)) @@ -4226,8 +4239,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)) @@ -4262,15 +4275,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 @@ -4286,57 +4299,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 @@ -4372,29 +4385,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: @@ -4425,8 +4438,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)) @@ -4460,39 +4473,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): @@ -4500,7 +4513,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) @@ -4558,8 +4571,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) @@ -4581,12 +4594,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: @@ -4650,14 +4663,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 @@ -4669,7 +4683,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) @@ -4679,11 +4693,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: @@ -4717,18 +4731,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) @@ -4766,33 +4780,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: @@ -4871,22 +4885,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: @@ -4914,19 +4928,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 @@ -4937,18 +4951,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 @@ -5024,25 +5038,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] @@ -5057,13 +5071,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:: @@ -5073,8 +5087,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)) @@ -5149,7 +5163,7 @@ 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 @@ -5167,8 +5181,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)) @@ -5197,15 +5211,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)) @@ -5243,15 +5257,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)) @@ -5307,11 +5321,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) @@ -5322,17 +5336,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)) @@ -5429,11 +5443,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 @@ -5446,18 +5460,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)) @@ -5573,23 +5587,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)) @@ -5650,7 +5664,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) @@ -5683,8 +5697,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)) @@ -5755,8 +5769,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)) @@ -5796,10 +5810,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)) @@ -5816,7 +5830,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] @@ -5824,16 +5838,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: @@ -5975,8 +5989,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)) @@ -6033,8 +6047,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))) @@ -6084,7 +6098,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] @@ -6098,44 +6112,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: @@ -6194,45 +6208,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/calculus/riemann.pyx b/src/sage/calculus/riemann.pyx index 4dc18b964f2..b7969a8c4c2 100644 --- a/src/sage/calculus/riemann.pyx +++ b/src/sage/calculus/riemann.pyx @@ -1190,10 +1190,11 @@ cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values, EXAMPLES:: sage: from sage.calculus.riemann import complex_to_spiderweb - sage: import numpy - sage: zval = numpy.array([[0, 1, 1000],[.2+.3j,1,-.3j],[0,0,0]],dtype = numpy.complex128) - sage: deriv = numpy.array([[.1]],dtype = numpy.float64) - sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,False,0.001) + sage: import numpy # optional - numpy + sage: zval = numpy.array([[0,1,1000], [.2+.3j,1,-.3j], [0,0,0]], # optional - numpy + ....: dtype=numpy.complex128) + sage: deriv = numpy.array([[.1]],dtype = numpy.float64) # optional - numpy + sage: complex_to_spiderweb(zval, deriv, deriv, 4, 4, [0,0,0], 1, False, 0.001) # optional - numpy array([[[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]], @@ -1206,7 +1207,7 @@ cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values, [1., 1., 1.], [1., 1., 1.]]]) - sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,True,0.001) + sage: complex_to_spiderweb(zval, deriv, deriv, 4, 4, [0,0,0], 1, True, 0.001) # optional - numpy array([[[1. , 1. , 1. ], [1. , 0.05558355, 0.05558355], [0.17301243, 0. , 0. ]], @@ -1280,13 +1281,13 @@ cpdef complex_to_rgb(np.ndarray[COMPLEX_T, ndim = 2] z_values): EXAMPLES:: sage: from sage.calculus.riemann import complex_to_rgb - sage: import numpy - sage: complex_to_rgb(numpy.array([[0, 1, 1000]], dtype = numpy.complex128)) + sage: import numpy # optional - numpy + sage: complex_to_rgb(numpy.array([[0, 1, 1000]], dtype=numpy.complex128)) # optional - numpy array([[[1. , 1. , 1. ], [1. , 0.05558355, 0.05558355], [0.17301243, 0. , 0. ]]]) - sage: complex_to_rgb(numpy.array([[0, 1j, 1000j]], dtype = numpy.complex128)) + sage: complex_to_rgb(numpy.array([[0, 1j, 1000j]], dtype=numpy.complex128)) # optional - numpy array([[[1. , 1. , 1. ], [0.52779177, 1. , 0.05558355], [0.08650622, 0.17301243, 0. ]]]) diff --git a/src/sage/calculus/test_sympy.py b/src/sage/calculus/test_sympy.py index 927e6ee4fb6..a1db950bf10 100644 --- a/src/sage/calculus/test_sympy.py +++ b/src/sage/calculus/test_sympy.py @@ -102,98 +102,98 @@ And here are some actual tests of sympy:: - sage: from sympy import Symbol, cos, sympify, pprint - sage: from sympy.abc import x + sage: from sympy import Symbol, cos, sympify, pprint # optional - sympy + sage: from sympy.abc import x # optional - sympy :: - sage: e = (1/cos(x)^3)._sympy_(); e + sage: e = (1/cos(x)^3)._sympy_(); e # optional - sympy cos(x)**(-3) - sage: f = e.series(x, 0, int(10)); f + sage: f = e.series(x, 0, int(10)); f # optional - sympy 1 + 3*x**2/2 + 11*x**4/8 + 241*x**6/240 + 8651*x**8/13440 + O(x**10) And the pretty-printer. Since unicode characters are not working on some architectures, we disable it:: - sage: from sympy.printing import pprint_use_unicode - sage: prev_use = pprint_use_unicode(False) - sage: pprint(e) + sage: from sympy.printing import pprint_use_unicode # optional - sympy + sage: prev_use = pprint_use_unicode(False) # optional - sympy + sage: pprint(e) # optional - sympy 1 ------- 3 cos (x) - sage: pprint(f) + sage: pprint(f) # optional - sympy 2 4 6 8 3*x 11*x 241*x 8651*x / 10\ 1 + ---- + ----- + ------ + ------- + O\x / 2 8 240 13440 - sage: pprint_use_unicode(prev_use) + sage: pprint_use_unicode(prev_use) # optional - sympy False And the functionality to convert from sympy format to Sage format:: - sage: e._sage_() + sage: e._sage_() # optional - sympy cos(x)^(-3) - sage: e._sage_().taylor(x._sage_(), 0, 8) + sage: e._sage_().taylor(x._sage_(), 0, 8) # optional - sympy 8651/13440*x^8 + 241/240*x^6 + 11/8*x^4 + 3/2*x^2 + 1 - sage: f._sage_() + sage: f._sage_() # optional - sympy 8651/13440*x^8 + 241/240*x^6 + 11/8*x^4 + 3/2*x^2 + Order(x^10) + 1 Mixing SymPy with Sage:: - sage: import sympy - sage: var("x")._sympy_() + var("y")._sympy_() + sage: import sympy # optional - sympy + sage: var("x")._sympy_() + var("y")._sympy_() # optional - sympy x + y - sage: o = var("omega") - sage: s = sympy.Symbol("x") - sage: t1 = s + o - sage: t2 = o + s - sage: type(t1) + sage: o = var("omega") # optional - sympy + sage: s = sympy.Symbol("x") # optional - sympy + sage: t1 = s + o # optional - sympy + sage: t2 = o + s # optional - sympy + sage: type(t1) # optional - sympy - sage: type(t2) + sage: type(t2) # optional - sympy - sage: t1, t2 + sage: t1, t2 # optional - sympy (omega + x, omega + x) - sage: e=sympy.sin(var("y"))+sage.all.cos(sympy.Symbol("x")) - sage: type(e) + sage: e = sympy.sin(var("y"))+sage.all.cos(sympy.Symbol("x")) # optional - sympy + sage: type(e) # optional - sympy - sage: e + sage: e # optional - sympy sin(y) + cos(x) - sage: e=e._sage_() - sage: type(e) + sage: e=e._sage_() # optional - sympy + sage: type(e) # optional - sympy - sage: e + sage: e # optional - sympy cos(x) + sin(y) - sage: e = sage.all.cos(var("y")**3)**4+var("x")**2 - sage: e = e._sympy_() - sage: e + sage: e = sage.all.cos(var("y")**3)**4+var("x")**2 # optional - sympy + sage: e = e._sympy_() # optional - sympy + sage: e # optional - sympy x**2 + cos(y**3)**4 :: - sage: a = sympy.Matrix([1, 2, 3]) - sage: a[1] + sage: a = sympy.Matrix([1, 2, 3]) # optional - sympy + sage: a[1] # optional - sympy 2 :: - sage: sympify(1.5) + sage: sympify(1.5) # optional - sympy 1.50000000000000 - sage: sympify(2) + sage: sympify(2) # optional - sympy 2 - sage: sympify(-2) + sage: sympify(-2) # optional - sympy -2 TESTS: This was fixed in Sympy, see :trac:`14437`:: - sage: from sympy import Function, Symbol, rsolve - sage: u = Function('u') - sage: n = Symbol('n', integer=True) - sage: f = u(n+2) - u(n+1) + u(n)/4 - sage: expand(2**n * rsolve(f,u(n))) + sage: from sympy import Function, Symbol, rsolve # optional - sympy + sage: u = Function('u') # optional - sympy + sage: n = Symbol('n', integer=True) # optional - sympy + sage: f = u(n+2) - u(n+1) + u(n)/4 # optional - sympy + sage: expand(2**n * rsolve(f,u(n))) # optional - sympy 2*C1*n + C0 """ diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 0c82d6cfe08..b90d97e0f02 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -21,7 +21,8 @@ A group action `G \times S \rightarrow S` is a functor from `G` to Sets. sage: import gc sage: _ = gc.collect() sage: A - ) failed: RuntimeError: This action acted on a set that became garbage collected> + ) failed: + RuntimeError: This action acted on a set that became garbage collected> To avoid garbage collection of the underlying set, it is sufficient to create a strong reference to it before the action is created. @@ -265,15 +266,17 @@ cdef class Action(Functor): sage: R = (ZZ['x'])['y'] sage: A = R.get_action(P,operator.mul,True) sage: A # indirect doctest - Right scalar multiplication by Univariate Polynomial Ring in x over - Rational Field on Univariate Polynomial Ring in y over Univariate - Polynomial Ring in x over Integer Ring + Right scalar multiplication + by Univariate Polynomial Ring in x over Rational Field + on Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Integer Ring In this example, the underlying set is the ring ``R``. This is the same as the left domain, which is different from the codomain of the action:: sage: A.codomain() - Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field sage: A.codomain() == R False sage: A.left_domain() is R @@ -294,7 +297,8 @@ cdef class Action(Functor): sage: import gc sage: _ = gc.collect() sage: A - ) failed: RuntimeError: This action acted on a set that became garbage collected> + ) failed: + RuntimeError: This action acted on a set that became garbage collected> """ S = self.US() if S is None: @@ -329,24 +333,28 @@ cdef class InverseAction(Action): EXAMPLES:: - sage: V = QQ^3 - sage: v = V((1, 2, 3)) + sage: V = QQ^3 # optional - sage.modules + sage: v = V((1, 2, 3)) # optional - sage.modules sage: cm = get_coercion_model() - sage: a = cm.get_action(V, QQ, operator.mul) - sage: a - Right scalar multiplication by Rational Field on Vector space of dimension 3 over Rational Field - sage: ~a - Right inverse action by Rational Field on Vector space of dimension 3 over Rational Field - sage: (~a)(v, 1/3) + sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules + sage: a # optional - sage.modules + Right scalar multiplication by Rational Field + on Vector space of dimension 3 over Rational Field + sage: ~a # optional - sage.modules + Right inverse action by Rational Field + on Vector space of dimension 3 over Rational Field + sage: (~a)(v, 1/3) # optional - sage.modules (3, 6, 9) - sage: b = cm.get_action(QQ, V, operator.mul) - sage: b - Left scalar multiplication by Rational Field on Vector space of dimension 3 over Rational Field - sage: ~b - Left inverse action by Rational Field on Vector space of dimension 3 over Rational Field - sage: (~b)(1/3, v) + sage: b = cm.get_action(QQ, V, operator.mul) # optional - sage.modules + sage: b # optional - sage.modules + Left scalar multiplication by Rational Field + on Vector space of dimension 3 over Rational Field + sage: ~b # optional - sage.modules + Left inverse action by Rational Field + on Vector space of dimension 3 over Rational Field + sage: (~b)(1/3, v) # optional - sage.modules (3, 6, 9) sage: c = cm.get_action(ZZ, list, operator.mul) @@ -390,11 +398,11 @@ cdef class InverseAction(Action): Check that this action can be pickled (:trac:`29031`):: - sage: V = QQ^3 - sage: v = V((1, 2, 3)) - sage: cm = get_coercion_model() - sage: a = cm.get_action(V, QQ, operator.mul) - sage: loads(dumps(~a)) is not None + sage: V = QQ^3 # optional - sage.modules + sage: v = V((1, 2, 3)) # optional - sage.modules + sage: cm = get_coercion_model() # optional - sage.modules + sage: a = cm.get_action(V, QQ, operator.mul) # optional - sage.modules + sage: loads(dumps(~a)) is not None # optional - sage.modules True """ return (type(self), (self._action,)) @@ -434,8 +442,9 @@ cdef class PrecomposedAction(Action): sage: c,x = v[0] sage: y = x.modular_symbol_rep() sage: coercion_model.get_action(QQ, parent(y), op=operator.mul) - Left scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field - with precomposition on right by Coercion map: + Left scalar multiplication by Rational Field + on Abelian Group of all Formal Finite Sums over Rational Field + with precomposition on right by Coercion map: From: Abelian Group of all Formal Finite Sums over Integer Ring To: Abelian Group of all Formal Finite Sums over Rational Field """ @@ -542,8 +551,8 @@ cdef class ActionEndomorphism(Morphism): sage: A = ZZ['x'].get_action(QQ, self_on_left=False, op=operator.mul) sage: A - 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: A(1/2) Action of 1/2 on Univariate Polynomial Ring in x over Integer Ring under Left scalar multiplication by Rational Field on Univariate diff --git a/src/sage/categories/additive_magmas.py b/src/sage/categories/additive_magmas.py index 8d2c46d0771..91c2eef94f9 100644 --- a/src/sage/categories/additive_magmas.py +++ b/src/sage/categories/additive_magmas.py @@ -33,7 +33,10 @@ class AdditiveMagmas(Category_singleton): sage: AdditiveMagmas().super_categories() [Category of sets] sage: AdditiveMagmas().all_super_categories() - [Category of additive magmas, Category of sets, Category of sets with partial maps, Category of objects] + [Category of additive magmas, + Category of sets, + Category of sets with partial maps, + Category of objects] The following axioms are defined by this category:: @@ -45,11 +48,11 @@ class AdditiveMagmas(Category_singleton): Category of additive commutative additive magmas sage: AdditiveMagmas().AdditiveUnital().AdditiveInverse() Category of additive inverse additive unital additive magmas - sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative() + sage: C = AdditiveMagmas().AdditiveAssociative().AdditiveCommutative(); C Category of commutative additive semigroups - sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative().AdditiveUnital() + sage: C.AdditiveUnital() Category of commutative additive monoids - sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().AdditiveInverse() + sage: C.AdditiveUnital().AdditiveInverse() Category of commutative additive groups TESTS:: @@ -112,9 +115,10 @@ def AdditiveCommutative(self): sage: AdditiveMagmas().AdditiveCommutative() Category of additive commutative additive magmas - sage: AdditiveMagmas().AdditiveAssociative().AdditiveUnital().AdditiveCommutative() + sage: C = AdditiveMagmas().AdditiveAssociative().AdditiveUnital() + sage: C.AdditiveCommutative() Category of commutative additive monoids - sage: _ is CommutativeAdditiveMonoids() + sage: C.AdditiveCommutative() is CommutativeAdditiveMonoids() True TESTS:: @@ -279,7 +283,7 @@ def addition_table(self, names='letters', elements=None): elements as lowercase ASCII letters. :: sage: R = IntegerModRing(5) - sage: R.addition_table() + sage: R.addition_table() # optional - sage.modules + a b c d e +---------- a| a b c d e @@ -294,8 +298,7 @@ def addition_table(self, names='letters', elements=None): ``digits`` will include leading zeros as padding. :: sage: R = IntegerModRing(11) - sage: P = R.addition_table(names='elements') - sage: P + sage: P = R.addition_table(names='elements'); P # optional - sage.modules + 0 1 2 3 4 5 6 7 8 9 10 +--------------------------------- 0| 0 1 2 3 4 5 6 7 8 9 10 @@ -310,8 +313,7 @@ def addition_table(self, names='letters', elements=None): 9| 9 10 0 1 2 3 4 5 6 7 8 10| 10 0 1 2 3 4 5 6 7 8 9 - sage: T = R.addition_table(names='digits') - sage: T + sage: T = R.addition_table(names='digits'); T # optional - sage.modules + 00 01 02 03 04 05 06 07 08 09 10 +--------------------------------- 00| 00 01 02 03 04 05 06 07 08 09 10 @@ -331,7 +333,7 @@ def addition_table(self, names='letters', elements=None): sage: S = IntegerModRing(7) sage: elts = [0, 3, 6, 2, 5, 1, 4] - sage: S.addition_table(elements=elts) + sage: S.addition_table(elements=elts) # optional - sage.modules + a b c d e f g +-------------- a| a b c d e f g @@ -351,8 +353,8 @@ def addition_table(self, names='letters', elements=None): representation. :: sage: T = IntegerModRing(12) - sage: elts=[0, 3, 6, 9] - sage: T.addition_table(names='elements', elements=elts) + sage: elts = [0, 3, 6, 9] + sage: T.addition_table(names='elements', elements=elts) # optional - sage.modules + 0 3 6 9 +-------- 0| 0 3 6 9 @@ -366,15 +368,15 @@ def addition_table(self, names='letters', elements=None): comprehensive documentation. :: sage: R = IntegerModRing(3) - sage: T = R.addition_table() - sage: T.column_keys() + sage: T = R.addition_table() # optional - sage.modules + sage: T.column_keys() # optional - sage.modules (0, 1, 2) - sage: sorted(T.translation().items()) + sage: sorted(T.translation().items()) # optional - sage.modules [('a', 0), ('b', 1), ('c', 2)] - sage: T.change_names(['x', 'y', 'z']) - sage: sorted(T.translation().items()) + sage: T.change_names(['x', 'y', 'z']) # optional - sage.modules + sage: sorted(T.translation().items()) # optional - sage.modules [('x', 0), ('y', 1), ('z', 2)] - sage: T + sage: T # optional - sage.modules + x y z +------ x| x y z @@ -471,16 +473,16 @@ def _add_(self, right): r""" EXAMPLES:: - sage: G5=GF(5); G8=GF(4,'x'); GG = G5.cartesian_product(G8) - sage: e = GG((G5(1),G8.primitive_element())); e + sage: G5 = GF(5); G8 = GF(4, 'x'); GG = G5.cartesian_product(G8) # optional - sage.rings.finite_rings + sage: e = GG((G5(1), G8.primitive_element())); e # optional - sage.rings.finite_rings (1, x) - sage: e+e + sage: e + e # optional - sage.rings.finite_rings (2, 0) - sage: e = groups.misc.AdditiveCyclic(8) - sage: x = e.cartesian_product(e)((e(1),e(2))) - sage: x + sage: e = groups.misc.AdditiveCyclic(8) # optional - sage.rings.finite_rings + sage: x = e.cartesian_product(e)((e(1), e(2))) # optional - sage.rings.finite_rings + sage: x # optional - sage.rings.finite_rings (1, 2) - sage: 4*x + sage: 4 * x # optional - sage.rings.finite_rings (4, 0) """ return self.parent()._cartesian_product_of_elements( @@ -497,7 +499,8 @@ def extra_super_categories(self): [Category of magmatic algebras with basis over Rational Field] sage: AdditiveMagmas().Algebras(QQ).super_categories() - [Category of magmatic algebras with basis over Rational Field, Category of set algebras over Rational Field] + [Category of magmatic algebras with basis over Rational Field, + Category of set algebras over Rational Field] """ from sage.categories.magmatic_algebras import MagmaticAlgebras return [MagmaticAlgebras(self.base_ring()).WithBasis()] @@ -516,9 +519,10 @@ def algebra_generators(self): EXAMPLES:: sage: S = CommutativeAdditiveSemigroups().example(); S - An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) - sage: A.algebra_generators() + An example of a commutative semigroup: + the free commutative semigroup generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ) # optional - sage.modules + sage: A.algebra_generators() # optional - sage.modules Family (B[a], B[b], B[c], B[d]) .. TODO:: @@ -541,10 +545,11 @@ def product_on_basis(self, g1, g2): EXAMPLES:: sage: S = CommutativeAdditiveSemigroups().example(); S - An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) - sage: a,b,c,d = A.algebra_generators() - sage: a * d * b + An example of a commutative semigroup: + the free commutative semigroup generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ) # optional - sage.modules + sage: a, b, c, d = A.algebra_generators() # optional - sage.modules + sage: a * d * b # optional - sage.modules B[a + b + d] .. TODO:: @@ -580,10 +585,11 @@ def extra_super_categories(self): EXAMPLES:: - sage: AdditiveMagmas().AdditiveCommutative().Algebras(QQ).extra_super_categories() + sage: C = AdditiveMagmas().AdditiveCommutative().Algebras(QQ) + sage: C.extra_super_categories() [Category of commutative magmas] - sage: AdditiveMagmas().AdditiveCommutative().Algebras(QQ).super_categories() + sage: C.super_categories() [Category of additive magma algebras over Rational Field, Category of commutative magmas] """ @@ -718,10 +724,10 @@ def is_empty(self): EXAMPLES:: - sage: A = AdditiveAbelianGroup([3,3]) - sage: A in AdditiveMagmas() + sage: A = AdditiveAbelianGroup([3, 3]) # optional - sage.groups + sage: A in AdditiveMagmas() # optional - sage.groups True - sage: A.is_empty() + sage: A.is_empty() # optional - sage.groups False sage: B = CommutativeAdditiveMonoids().example() @@ -733,7 +739,7 @@ def is_empty(self): We check that the method ``is_empty`` is inherited from this category in both examples above:: - sage: A.is_empty.__module__ + sage: A.is_empty.__module__ # optional - sage.groups 'sage.categories.additive_magmas' sage: B.is_empty.__module__ 'sage.categories.additive_magmas' @@ -801,17 +807,17 @@ def _sub_(left, right): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b']) - sage: a,b = F.basis() - sage: a - b + sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # optional - sage.modules + sage: a, b = F.basis() # optional - sage.modules + sage: a - b # optional - sage.modules B['a'] - B['b'] TESTS: Check that :trac:`18275` is fixed:: - sage: C = GF(5).cartesian_product(GF(5)) - sage: C.one() - C.one() + sage: C = GF(5).cartesian_product(GF(5)) # optional - sage.rings.finite_rings + sage: C.one() - C.one() # optional - sage.rings.finite_rings (0, 0) """ return left + (-right) @@ -827,21 +833,21 @@ def __neg__(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b']) - sage: a,b = F.basis() - sage: - b + sage: F = CombinatorialFreeModule(QQ, ['a', 'b']) # optional - sage.modules + sage: a, b = F.basis() # optional - sage.modules + sage: -b # optional - sage.modules -B['b'] TESTS:: - sage: F = CombinatorialFreeModule(ZZ, ['a','b']) - sage: a,b = F.gens() - sage: FF = cartesian_product((F,F)) - sage: x = cartesian_product([a,2*a-3*b]) ; x + sage: F = CombinatorialFreeModule(ZZ, ['a', 'b']) # optional - sage.modules + sage: a, b = F.gens() # optional - sage.modules + sage: FF = cartesian_product((F, F)) # optional - sage.modules + sage: x = cartesian_product([a, 2*a-3*b]); x # optional - sage.modules B[(0, 'a')] + 2*B[(1, 'a')] - 3*B[(1, 'b')] - sage: x.parent() is FF + sage: x.parent() is FF # optional - sage.modules True - sage: -x + sage: -x # optional - sage.modules -B[(0, 'a')] - 2*B[(1, 'a')] + 3*B[(1, 'b')] """ return self._neg_() @@ -911,14 +917,14 @@ def _neg_(self): EXAMPLES:: - sage: x = cartesian_product((GF(7)(2),17)) ; x + sage: x = cartesian_product((GF(7)(2), 17)); x # optional - sage.rings.finite_rings (2, 17) - sage: -x + sage: -x # optional - sage.rings.finite_rings (5, -17) TESTS:: - sage: x.parent() in AdditiveMagmas().AdditiveUnital().AdditiveInverse().CartesianProducts() + sage: x.parent() in AdditiveMagmas().AdditiveUnital().AdditiveInverse().CartesianProducts() # optional - sage.rings.finite_rings True """ return self.parent()._cartesian_product_of_elements( @@ -947,7 +953,7 @@ def zero(self): EXAMPLES:: - sage: GF(8,'x').cartesian_product(GF(5)).zero() + sage: GF(8, 'x').cartesian_product(GF(5)).zero() # optional - sage.rings.finite_rings (0, 0) """ return self._cartesian_product_of_elements( @@ -964,7 +970,8 @@ def extra_super_categories(self): [Category of unital magmas] sage: C.super_categories() - [Category of unital algebras with basis over Rational Field, Category of additive magma algebras over Rational Field] + [Category of unital algebras with basis over Rational Field, + Category of additive magma algebras over Rational Field] """ from sage.categories.magmas import Magmas return [Magmas().Unital()] @@ -982,13 +989,14 @@ def one_basis(self): EXAMPLES:: sage: S = CommutativeAdditiveMonoids().example(); S - An example of a commutative monoid: the free commutative monoid generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(ZZ) - sage: A.one_basis() + An example of a commutative monoid: + the free commutative monoid generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(ZZ) # optional - sage.modules + sage: A.one_basis() # optional - sage.modules 0 - sage: A.one() + sage: A.one() # optional - sage.modules B[0] - sage: A(3) + sage: A(3) # optional - sage.modules 3*B[0] """ return self.basis().keys().zero() @@ -1007,17 +1015,17 @@ def zero(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat The subset algebra of {1, 2, 3} over Rational Field - sage: A.zero.__module__ + sage: A.zero.__module__ # optional - sage.combinat 'sage.categories.additive_magmas' - sage: A.zero() + sage: A.zero() # optional - sage.combinat 0 TESTS:: - sage: A.zero() is A.a_realization().zero() + sage: A.zero() is A.a_realization().zero() # optional - sage.combinat True - sage: A._test_zero() + sage: A._test_zero() # optional - sage.combinat """ return self.a_realization().zero() diff --git a/src/sage/categories/additive_semigroups.py b/src/sage/categories/additive_semigroups.py index 0527867154b..667e27eb1e9 100644 --- a/src/sage/categories/additive_semigroups.py +++ b/src/sage/categories/additive_semigroups.py @@ -150,9 +150,10 @@ def algebra_generators(self): EXAMPLES:: sage: S = CommutativeAdditiveSemigroups().example(); S - An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) - sage: A.algebra_generators() + An example of a commutative semigroup: + the free commutative semigroup generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ) # optional - sage.modules + sage: A.algebra_generators() # optional - sage.modules Family (B[a], B[b], B[c], B[d]) """ return self.basis().keys().additive_semigroup_generators().map(self.monomial) @@ -169,10 +170,11 @@ def product_on_basis(self, g1, g2): EXAMPLES:: sage: S = CommutativeAdditiveSemigroups().example(); S - An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) - sage: a,b,c,d = A.algebra_generators() - sage: b * d * c + An example of a commutative semigroup: + the free commutative semigroup generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ) # optional - sage.modules + sage: a, b, c, d = A.algebra_generators() # optional - sage.modules + sage: b * d * c # optional - sage.modules B[b + c + d] """ return self.monomial(g1 + g2) diff --git a/src/sage/categories/affine_weyl_groups.py b/src/sage/categories/affine_weyl_groups.py index 6bc26562b8e..3df85b07415 100644 --- a/src/sage/categories/affine_weyl_groups.py +++ b/src/sage/categories/affine_weyl_groups.py @@ -34,9 +34,9 @@ class AffineWeylGroups(Category_singleton): sage: C.example() NotImplemented - sage: W = WeylGroup(["A",4,1]); W + sage: W = WeylGroup(["A", 4, 1]); W # optional - sage.combinat sage.groups Weyl Group of type ['A', 4, 1] (as a matrix group acting on the root space) - sage: W.category() + sage: W.category() # optional - sage.combinat sage.groups Category of irreducible affine weyl groups TESTS:: @@ -81,8 +81,8 @@ def special_node(self): EXAMPLES:: - sage: W = WeylGroup(['A',3,1]) - sage: W.special_node() + sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups + sage: W.special_node() # optional - sage.combinat sage.groups 0 """ return self.cartan_type().special_node() @@ -95,8 +95,9 @@ def affine_grassmannian_elements_of_given_length(self, k): EXAMPLES:: - sage: W = WeylGroup(['A',3,1]) - sage: [x.reduced_word() for x in W.affine_grassmannian_elements_of_given_length(3)] + sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() # optional - sage.combinat sage.groups + ....: for x in W.affine_grassmannian_elements_of_given_length(3)] [[2, 1, 0], [3, 1, 0], [2, 3, 0]] .. SEEALSO:: @@ -136,14 +137,14 @@ def is_affine_grassmannian(self): EXAMPLES:: - sage: W = WeylGroup(['A',3,1]) - sage: w = W.from_reduced_word([2,1,0]) - sage: w.is_affine_grassmannian() + sage: W = WeylGroup(['A', 3, 1]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([2,1,0]) # optional - sage.combinat sage.groups + sage: w.is_affine_grassmannian() # optional - sage.combinat sage.groups True - sage: w = W.from_reduced_word([2,0]) - sage: w.is_affine_grassmannian() + sage: w = W.from_reduced_word([2,0]) # optional - sage.combinat sage.groups + sage: w.is_affine_grassmannian() # optional - sage.combinat sage.groups False - sage: W.one().is_affine_grassmannian() + sage: W.one().is_affine_grassmannian() # optional - sage.combinat sage.groups True """ D = self.descents() @@ -168,17 +169,17 @@ def affine_grassmannian_to_core(self): EXAMPLES:: - sage: W = WeylGroup(['A',2,1]) - sage: w = W.from_reduced_word([0,2,1,0]) - sage: la = w.affine_grassmannian_to_core(); la + sage: W = WeylGroup(['A', 2, 1]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([0,2,1,0]) # optional - sage.combinat sage.groups + sage: la = w.affine_grassmannian_to_core(); la # optional - sage.combinat sage.groups [4, 2] - sage: type(la) + sage: type(la) # optional - sage.combinat sage.groups - sage: la.to_grassmannian() == w + sage: la.to_grassmannian() == w # optional - sage.combinat sage.groups True - sage: w = W.from_reduced_word([0,2,1]) - sage: w.affine_grassmannian_to_core() + sage: w = W.from_reduced_word([0,2,1]) # optional - sage.combinat sage.groups + sage: w.affine_grassmannian_to_core() # optional - sage.combinat sage.groups Traceback (most recent call last): ... ValueError: this only works on type 'A' affine Grassmannian elements @@ -214,11 +215,11 @@ def affine_grassmannian_to_partition(self): EXAMPLES:: sage: k = 2 - sage: W = WeylGroup(['A',k,1]) - sage: w = W.from_reduced_word([0,2,1,0]) - sage: la = w.affine_grassmannian_to_partition(); la + sage: W = WeylGroup(['A', k, 1]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([0,2,1,0]) # optional - sage.combinat sage.groups + sage: la = w.affine_grassmannian_to_partition(); la # optional - sage.combinat sage.groups [2, 2] - sage: la.from_kbounded_to_grassmannian(k) == w + sage: la.from_kbounded_to_grassmannian(k) == w # optional - sage.combinat sage.groups True """ return self.affine_grassmannian_to_core().to_bounded_partition() diff --git a/src/sage/categories/algebra_functor.py b/src/sage/categories/algebra_functor.py index d2c64474d8e..9142a9b6e38 100644 --- a/src/sage/categories/algebra_functor.py +++ b/src/sage/categories/algebra_functor.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.groups r""" Group algebras and beyond: the Algebra functorial construction diff --git a/src/sage/categories/algebra_ideals.py b/src/sage/categories/algebra_ideals.py index 2beecea2ee4..3bea4f66f91 100644 --- a/src/sage/categories/algebra_ideals.py +++ b/src/sage/categories/algebra_ideals.py @@ -79,9 +79,10 @@ def super_categories(self): EXAMPLES:: sage: AlgebraIdeals(QQ['x']).super_categories() - [Category of algebra modules over Univariate Polynomial Ring in x over Rational Field] - sage: C = AlgebraIdeals(FreeAlgebra(QQ,2,'a,b')) - sage: C.super_categories() + [Category of algebra modules + over Univariate Polynomial Ring in x over Rational Field] + sage: C = AlgebraIdeals(FreeAlgebra(QQ, 2, 'a,b')) # optional - sage.combinat sage.modules + sage: C.super_categories() # optional - sage.combinat sage.modules [] """ diff --git a/src/sage/categories/algebra_modules.py b/src/sage/categories/algebra_modules.py index 46698060095..387efec77e2 100644 --- a/src/sage/categories/algebra_modules.py +++ b/src/sage/categories/algebra_modules.py @@ -39,7 +39,7 @@ def __init__(self, A): sage: AlgebraModules(QQ['a']) Category of algebra modules over Univariate Polynomial Ring in a over Rational Field sage: AlgebraModules(QQ['a,b']) # todo: not implemented (QQ['a,b'] should be in Algebras(QQ)) - sage: AlgebraModules(FreeAlgebra(QQ,2,'a,b')) + sage: AlgebraModules(FreeAlgebra(QQ, 2, 'a,b')) # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: A (=Free Algebra on 2 generators (a, b) over Rational Field) must be a commutative algebra diff --git a/src/sage/categories/algebras.py b/src/sage/categories/algebras.py index 253d64a2819..79e99aab325 100644 --- a/src/sage/categories/algebras.py +++ b/src/sage/categories/algebras.py @@ -68,7 +68,7 @@ def __contains__(self, x): sage: QQ['x'] in Algebras(QQ) True - sage: QQ^3 in Algebras(QQ) + sage: QQ^3 in Algebras(QQ) # optional - sage.modules False sage: QQ['x'] in Algebras(CDF) False @@ -154,15 +154,15 @@ def _div_(self, y): EXAMPLES:: - sage: C = AlgebrasWithBasis(QQ).example() - sage: x = C(2); x + sage: C = AlgebrasWithBasis(QQ).example() # optional - sage.combinat + sage: x = C(2); x # optional - sage.combinat 2*B[word: ] - sage: y = C.algebra_generators().first(); y + sage: y = C.algebra_generators().first(); y # optional - sage.combinat B[word: a] - sage: y._div_(x) + sage: y._div_(x) # optional - sage.combinat 1/2*B[word: a] - sage: x._div_(y) + sage: x._div_(y) # optional - sage.combinat Traceback (most recent call last): ... ValueError: cannot invert self (= B[word: a]) diff --git a/src/sage/categories/algebras_with_basis.py b/src/sage/categories/algebras_with_basis.py index d2296873b59..e7762b50f24 100644 --- a/src/sage/categories/algebras_with_basis.py +++ b/src/sage/categories/algebras_with_basis.py @@ -33,35 +33,37 @@ class AlgebrasWithBasis(CategoryWithAxiom_over_base_ring): We construct a typical parent in this category, and do some computations with it:: - sage: A = C.example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field + sage: A = C.example(); A # optional - sage.combinat + An example of an algebra with basis: + the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.category() + sage: A.category() # optional - sage.combinat Category of algebras with basis over Rational Field - sage: A.one_basis() + sage: A.one_basis() # optional - sage.combinat word: - sage: A.one() + sage: A.one() # optional - sage.combinat B[word: ] - sage: A.base_ring() + sage: A.base_ring() # optional - sage.combinat Rational Field - sage: A.basis().keys() + sage: A.basis().keys() # optional - sage.combinat Finite words over {'a', 'b', 'c'} - sage: (a,b,c) = A.algebra_generators() - sage: a^3, b^2 + sage: (a,b,c) = A.algebra_generators() # optional - sage.combinat + sage: a^3, b^2 # optional - sage.combinat (B[word: aaa], B[word: bb]) - sage: a*c*b + sage: a * c * b # optional - sage.combinat B[word: acb] - sage: A.product + sage: A.product # optional - sage.combinat - sage: A.product(a*b,b) + An example of an algebra with basis: + the free algebra on the generators ('a', 'b', 'c') over Rational Field> + sage: A.product(a * b, b) # optional - sage.combinat B[word: abb] - sage: TestSuite(A).run(verbose=True) + sage: TestSuite(A).run(verbose=True) # optional - sage.combinat running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_associativity() . . . pass @@ -91,9 +93,9 @@ class AlgebrasWithBasis(CategoryWithAxiom_over_base_ring): running ._test_prod() . . . pass running ._test_some_elements() . . . pass running ._test_zero() . . . pass - sage: A.__class__ + sage: A.__class__ # optional - sage.combinat - sage: A.element_class + sage: A.element_class # optional - sage.combinat Please see the source code of `A` (with ``A??``) for how to @@ -110,13 +112,15 @@ def example(self, alphabet=('a','b','c')): EXAMPLES:: - sage: AlgebrasWithBasis(QQ).example() - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field + sage: AlgebrasWithBasis(QQ).example() # optional - sage.combinat + An example of an algebra with basis: + the free algebra on the generators ('a', 'b', 'c') over Rational Field An other set of generators can be specified as optional argument:: - sage: AlgebrasWithBasis(QQ).example((1,2,3)) - An example of an algebra with basis: the free algebra on the generators (1, 2, 3) over Rational Field + sage: AlgebrasWithBasis(QQ).example((1,2,3)) # optional - sage.combinat + An example of an algebra with basis: + the free algebra on the generators (1, 2, 3) over Rational Field """ from sage.categories.examples.algebras_with_basis import Example return Example(self.base_ring(), alphabet) @@ -143,12 +147,12 @@ def hochschild_complex(self, M): EXAMPLES:: sage: R. = QQ[] - sage: A = algebras.DifferentialWeyl(R) - sage: H = A.hochschild_complex(A) + sage: A = algebras.DifferentialWeyl(R) # optional - sage.combinat + sage: H = A.hochschild_complex(A) # optional - sage.combinat - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: T = SGA.trivial_representation() - sage: H = SGA.hochschild_complex(T) + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat + sage: T = SGA.trivial_representation() # optional - sage.combinat + sage: H = SGA.hochschild_complex(T) # optional - sage.combinat """ from sage.homology.hochschild_complex import HochschildComplex return HochschildComplex(self, M) @@ -176,14 +180,14 @@ def __invert__(self): EXAMPLES:: - sage: C = AlgebrasWithBasis(QQ).example() - sage: x = C(2); x + sage: C = AlgebrasWithBasis(QQ).example() # optional - sage.combinat + sage: x = C(2); x # optional - sage.combinat 2*B[word: ] - sage: ~x + sage: ~x # optional - sage.combinat 1/2*B[word: ] - sage: a = C.algebra_generators().first(); a + sage: a = C.algebra_generators().first(); a # optional - sage.combinat B[word: a] - sage: ~a + sage: ~a # optional - sage.combinat Traceback (most recent call last): ... ValueError: cannot invert self (= B[word: a]) @@ -237,18 +241,20 @@ def one_from_cartesian_product_of_one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + An example of an algebra with basis: the free algebra + on the generators ('a', 'b', 'c') over Rational Field + sage: A.one_basis() # optional - sage.combinat word: - sage: B = cartesian_product((A, A, A)) - sage: B.one_from_cartesian_product_of_one_basis() + sage: B = cartesian_product((A, A, A)) # optional - sage.combinat + sage: B.one_from_cartesian_product_of_one_basis() # optional - sage.combinat B[(0, word: )] + B[(1, word: )] + B[(2, word: )] - sage: B.one() + sage: B.one() # optional - sage.combinat B[(0, word: )] + B[(1, word: )] + B[(2, word: )] - sage: cartesian_product([SymmetricGroupAlgebra(QQ, 3), SymmetricGroupAlgebra(QQ, 4)]).one() + sage: cartesian_product([SymmetricGroupAlgebra(QQ, 3), # optional - sage.combinat + ....: SymmetricGroupAlgebra(QQ, 4)]).one() B[(0, [1, 2, 3])] + B[(1, [1, 2, 3, 4])] """ return self.sum_of_monomials( zip( self._sets_keys(), (set.one_basis() for set in self._sets)) ) @@ -258,10 +264,11 @@ def one(self): """ TESTS:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: B = cartesian_product((A, A, A)) - sage: B.one() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + An example of an algebra with basis: the free algebra + on the generators ('a', 'b', 'c') over Rational Field + sage: B = cartesian_product((A, A, A)) # optional - sage.combinat + sage: B.one() # optional - sage.combinat B[(0, word: )] + B[(1, word: )] + B[(2, word: )] """ if all(hasattr(module, "one_basis") for module in self._sets): @@ -310,14 +317,15 @@ def one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + An example of an algebra with basis: the free algebra + on the generators ('a', 'b', 'c') over Rational Field + sage: A.one_basis() # optional - sage.combinat word: - sage: B = tensor((A, A, A)) - sage: B.one_basis() + sage: B = tensor((A, A, A)) # optional - sage.combinat + sage: B.one_basis() # optional - sage.combinat (word: , word: , word: ) - sage: B.one() + sage: B.one() # optional - sage.combinat B[word: ] # B[word: ] # B[word: ] """ # FIXME: this method should be conditionally defined, @@ -335,23 +343,25 @@ def product_on_basis(self, t1, t2): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: (a,b,c) = A.algebra_generators() + sage: A = AlgebrasWithBasis(QQ).example(); A # optional - sage.combinat + An example of an algebra with basis: the free algebra + on the generators ('a', 'b', 'c') over Rational Field + sage: (a,b,c) = A.algebra_generators() # optional - sage.combinat - sage: x = tensor( (a, b, c) ); x + sage: x = tensor((a, b, c)); x # optional - sage.combinat B[word: a] # B[word: b] # B[word: c] - sage: y = tensor( (c, b, a) ); y + sage: y = tensor((c, b, a)); y # optional - sage.combinat B[word: c] # B[word: b] # B[word: a] - sage: x*y + sage: x * y # optional - sage.combinat B[word: ac] # B[word: bb] # B[word: ca] - sage: x = tensor( ((a+2*b), c) ) ; x + sage: x = tensor(((a + 2*b), c)); x # optional - sage.combinat B[word: a] # B[word: c] + 2*B[word: b] # B[word: c] - sage: y = tensor( (c, a) ) + 1; y + sage: y = tensor((c, a)) + 1; y # optional - sage.combinat B[word: ] # B[word: ] + B[word: c] # B[word: a] - sage: x*y - B[word: a] # B[word: c] + B[word: ac] # B[word: ca] + 2*B[word: b] # B[word: c] + 2*B[word: bc] # B[word: ca] + sage: x * y # optional - sage.combinat + B[word: a] # B[word: c] + B[word: ac] # B[word: ca] + + 2*B[word: b] # B[word: c] + 2*B[word: bc] # B[word: ca] TODO: optimize this implementation! diff --git a/src/sage/categories/bialgebras.py b/src/sage/categories/bialgebras.py index 441d924c964..fa6a7a1a507 100644 --- a/src/sage/categories/bialgebras.py +++ b/src/sage/categories/bialgebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Bialgebras """ diff --git a/src/sage/categories/bialgebras_with_basis.py b/src/sage/categories/bialgebras_with_basis.py index 831bab3f068..067d0b35b8e 100644 --- a/src/sage/categories/bialgebras_with_basis.py +++ b/src/sage/categories/bialgebras_with_basis.py @@ -92,32 +92,33 @@ def convolution_product(self, *maps): with the projection ``Proj2`` on the Hopf algebra of non-commutative symmetric functions:: - sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() - sage: T = R.convolution_product([Id, Id]) - sage: [T(R(comp)) for comp in Compositions(3)] + sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() # optional - sage.combinat + sage: T = R.convolution_product([Id, Id]) # optional - sage.combinat + sage: [T(R(comp)) for comp in Compositions(3)] # optional - sage.combinat [4*R[1, 1, 1] + R[1, 2] + R[2, 1], 2*R[1, 1, 1] + 4*R[1, 2] + 2*R[2, 1] + 2*R[3], 2*R[1, 1, 1] + 2*R[1, 2] + 4*R[2, 1] + 2*R[3], R[1, 2] + R[2, 1] + 4*R[3]] - sage: T = R.convolution_product(Proj2, Id) - sage: [T(R([i])) for i in range(1, 5)] + sage: T = R.convolution_product(Proj2, Id) # optional - sage.combinat + sage: [T(R([i])) for i in range(1, 5)] # optional - sage.combinat [0, R[2], R[2, 1] + R[3], R[2, 2] + R[4]] Compute the convolution product of no maps on the Hopf algebra of symmetric functions in non-commuting variables. This is the composition of the counit with the unit:: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() - sage: T = m.convolution_product() - sage: [T(m(lam)) for lam in SetPartitions(0).list() + SetPartitions(2).list()] + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: T = m.convolution_product() # optional - sage.combinat + sage: [T(m(lam)) # optional - sage.combinat + ....: for lam in SetPartitions(0).list() + SetPartitions(2).list()] [m{}, 0, 0] Compute the convolution product of the projection ``Proj2`` with the identity on the Hopf algebra of symmetric functions in non-commuting variables:: - sage: T = m.convolution_product(Proj2, Id) - sage: [T(m(lam)) for lam in SetPartitions(3)] + sage: T = m.convolution_product(Proj2, Id) # optional - sage.combinat + sage: [T(m(lam)) for lam in SetPartitions(3)] # optional - sage.combinat [0, m{{1, 2}, {3}} + m{{1, 2, 3}}, m{{1, 2}, {3}} + m{{1, 2, 3}}, @@ -127,12 +128,15 @@ def convolution_product(self, *maps): Compute the convolution product of the antipode with itself and the identity map on group algebra of the symmetric group:: - sage: G = SymmetricGroup(3) - sage: QG = GroupAlgebra(G, QQ) - sage: x = QG.sum_of_terms([(p,p.number_of_peaks() + p.number_of_inversions()) for p in Permutations(3)]); x + sage: G = SymmetricGroup(3) # optional - sage.groups sage.combinat + sage: QG = GroupAlgebra(G, QQ) # optional - sage.groups sage.combinat + sage: x = QG.sum_of_terms( # optional - sage.groups sage.combinat + ....: [(p, p.number_of_peaks() + p.number_of_inversions()) + ....: for p in Permutations(3)] + ....: ); x 2*[1, 3, 2] + [2, 1, 3] + 3*[2, 3, 1] + 2*[3, 1, 2] + 3*[3, 2, 1] - sage: T = QG.convolution_product(Antipode, Antipode, Id) - sage: T(x) + sage: T = QG.convolution_product(Antipode, Antipode, Id) # optional - sage.groups sage.combinat + sage: T(x) # optional - sage.groups sage.combinat 2*[1, 3, 2] + [2, 1, 3] + 2*[2, 3, 1] + 3*[3, 1, 2] + 3*[3, 2, 1] """ onbasis = lambda x: self.term(x).convolution_product(*maps) @@ -168,31 +172,32 @@ def adams_operator(self, n): EXAMPLES:: - sage: h = SymmetricFunctions(QQ).h() - sage: h[5].adams_operator(2) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: h[5].adams_operator(2) # optional - sage.combinat 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h[5].plethysm(2*h[1]) + sage: h[5].plethysm(2*h[1]) # optional - sage.combinat 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h([]).adams_operator(0) + sage: h([]).adams_operator(0) # optional - sage.combinat h[] - sage: h([]).adams_operator(1) + sage: h([]).adams_operator(1) # optional - sage.combinat h[] - sage: h[3,2].adams_operator(0) + sage: h[3,2].adams_operator(0) # optional - sage.combinat 0 - sage: h[3,2].adams_operator(1) + sage: h[3,2].adams_operator(1) # optional - sage.combinat h[3, 2] :: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S[4].adams_operator(5) - 5*S[1, 1, 1, 1] + 10*S[1, 1, 2] + 10*S[1, 2, 1] + 10*S[1, 3] + 10*S[2, 1, 1] + 10*S[2, 2] + 10*S[3, 1] + 5*S[4] + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: S[4].adams_operator(5) # optional - sage.combinat + 5*S[1, 1, 1, 1] + 10*S[1, 1, 2] + 10*S[1, 2, 1] + + 10*S[1, 3] + 10*S[2, 1, 1] + 10*S[2, 2] + 10*S[3, 1] + 5*S[4] :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() - sage: m[[1,3],[2]].adams_operator(-2) + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: m[[1,3],[2]].adams_operator(-2) # optional - sage.combinat 3*m{{1}, {2, 3}} + 3*m{{1, 2}, {3}} + 6*m{{1, 2, 3}} - 2*m{{1, 3}, {2}} """ if n < 0: @@ -254,18 +259,18 @@ def convolution_product(self, *maps): sage: Id = lambda x: x sage: Antipode = lambda x: x.antipode() - sage: s = SymmetricFunctions(QQ).schur() - sage: s[3].convolution_product(Id, Id) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s[3].convolution_product(Id, Id) # optional - sage.combinat 2*s[2, 1] + 4*s[3] - sage: s[3,2].convolution_product(Id) == s[3,2] + sage: s[3,2].convolution_product(Id) == s[3,2] # optional - sage.combinat True The method accepts multiple arguments, or a single argument consisting of a list of maps:: - sage: s[3,2].convolution_product(Id, Id) + sage: s[3,2].convolution_product(Id, Id) # optional - sage.combinat 2*s[2, 1, 1, 1] + 6*s[2, 2, 1] + 6*s[3, 1, 1] + 12*s[3, 2] + 6*s[4, 1] + 2*s[5] - sage: s[3,2].convolution_product([Id, Id]) + sage: s[3,2].convolution_product([Id, Id]) # optional - sage.combinat 2*s[2, 1, 1, 1] + 6*s[2, 2, 1] + 6*s[3, 1, 1] + 12*s[3, 2] + 6*s[4, 1] + 2*s[5] We test the defining property of the antipode morphism; namely, @@ -273,28 +278,31 @@ def convolution_product(self, *maps): convolution algebra whose identity element is the composition of the counit and unit:: - sage: s[3,2].convolution_product() == s[3,2].convolution_product(Antipode, Id) == s[3,2].convolution_product(Id, Antipode) + sage: (s[3,2].convolution_product() # optional - sage.combinat + ....: == s[3,2].convolution_product(Antipode, Id) + ....: == s[3,2].convolution_product(Id, Antipode)) True :: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() - sage: Psi[2,1].convolution_product(Id, Id, Id) + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat + sage: Psi[2,1].convolution_product(Id, Id, Id) # optional - sage.combinat 3*Psi[1, 2] + 6*Psi[2, 1] - sage: (Psi[5,1] - Psi[1,5]).convolution_product(Id, Id, Id) + sage: (Psi[5,1] - Psi[1,5]).convolution_product(Id, Id, Id) # optional - sage.combinat -3*Psi[1, 5] + 3*Psi[5, 1] :: - sage: G = SymmetricGroup(3) - sage: QG = GroupAlgebra(G,QQ) - sage: x = QG.sum_of_terms([(p,p.length()) for p in Permutations(3)]); x + sage: G = SymmetricGroup(3) # optional - sage.combinat + sage: QG = GroupAlgebra(G, QQ) # optional - sage.combinat + sage: x = QG.sum_of_terms([(p, p.length()) # optional - sage.combinat + ....: for p in Permutations(3)]); x [1, 3, 2] + [2, 1, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] + 3*[3, 2, 1] - sage: x.convolution_product(Id, Id) + sage: x.convolution_product(Id, Id) # optional - sage.combinat 5*[1, 2, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] - sage: x.convolution_product(Id, Id, Id) + sage: x.convolution_product(Id, Id, Id) # optional - sage.combinat 4*[1, 2, 3] + [1, 3, 2] + [2, 1, 3] + 3*[3, 2, 1] - sage: x.convolution_product([Id]*6) + sage: x.convolution_product([Id] * 6) # optional - sage.combinat 9*[1, 2, 3] TESTS:: @@ -304,57 +312,60 @@ def convolution_product(self, *maps): :: - sage: h = SymmetricFunctions(QQ).h() - sage: h[5].convolution_product([Id, Id]) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: h[5].convolution_product([Id, Id]) # optional - sage.combinat 2*h[3, 2] + 2*h[4, 1] + 2*h[5] - sage: h.one().convolution_product([Id, Antipode]) + sage: h.one().convolution_product([Id, Antipode]) # optional - sage.combinat h[] - sage: h[3,2].convolution_product([Id, Antipode]) + sage: h[3,2].convolution_product([Id, Antipode]) # optional - sage.combinat 0 - sage: h.one().convolution_product([Id, Antipode]) == h.one().convolution_product() + sage: (h.one().convolution_product([Id, Antipode]) # optional - sage.combinat + ....: == h.one().convolution_product()) True :: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S[4].convolution_product([Id]*5) + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: S[4].convolution_product([Id] * 5) # optional - sage.combinat 5*S[1, 1, 1, 1] + 10*S[1, 1, 2] + 10*S[1, 2, 1] + 10*S[1, 3] + 10*S[2, 1, 1] + 10*S[2, 2] + 10*S[3, 1] + 5*S[4] :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() - sage: m[[1,3],[2]].convolution_product([Antipode, Antipode]) + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: m[[1,3],[2]].convolution_product([Antipode, Antipode]) # optional - sage.combinat 3*m{{1}, {2, 3}} + 3*m{{1, 2}, {3}} + 6*m{{1, 2, 3}} - 2*m{{1, 3}, {2}} - sage: m[[]].convolution_product([]) + sage: m[[]].convolution_product([]) # optional - sage.combinat m{} - sage: m[[1,3],[2]].convolution_product([]) + sage: m[[1,3],[2]].convolution_product([]) # optional - sage.combinat 0 :: - sage: QS = SymmetricGroupAlgebra(QQ, 5) - sage: x = QS.sum_of_terms(zip(Permutations(5)[3:6],[1,2,3])); x + sage: QS = SymmetricGroupAlgebra(QQ, 5) # optional - sage.combinat + sage: x = QS.sum_of_terms(zip(Permutations(5)[3:6], [1,2,3])); x # optional - sage.combinat [1, 2, 4, 5, 3] + 2*[1, 2, 5, 3, 4] + 3*[1, 2, 5, 4, 3] - sage: x.convolution_product([Antipode, Id]) + sage: x.convolution_product([Antipode, Id]) # optional - sage.combinat 6*[1, 2, 3, 4, 5] - sage: x.convolution_product(Id, Antipode, Antipode, Antipode) + sage: x.convolution_product(Id, Antipode, Antipode, Antipode) # optional - sage.combinat 3*[1, 2, 3, 4, 5] + [1, 2, 4, 5, 3] + 2*[1, 2, 5, 3, 4] :: - sage: G = SymmetricGroup(3) - sage: QG = GroupAlgebra(G,QQ) - sage: x = QG.sum_of_terms([(p,p.length()) for p in Permutations(3)]); x + sage: G = SymmetricGroup(3) # optional - sage.combinat + sage: QG = GroupAlgebra(G, QQ) # optional - sage.combinat + sage: x = QG.sum_of_terms([(p, p.length()) # optional - sage.combinat + ....: for p in Permutations(3)]); x [1, 3, 2] + [2, 1, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] + 3*[3, 2, 1] - sage: x.convolution_product(Antipode, Id) + sage: x.convolution_product(Antipode, Id) # optional - sage.combinat 9*[1, 2, 3] - sage: x.convolution_product([Id, Antipode, Antipode, Antipode]) + sage: x.convolution_product([Id, Antipode, Antipode, Antipode]) # optional - sage.combinat 5*[1, 2, 3] + 2*[2, 3, 1] + 2*[3, 1, 2] :: - sage: s[3,2].counit().parent() == s[3,2].convolution_product().parent() + sage: (s[3,2].counit().parent() # optional - sage.combinat + ....: == s[3,2].convolution_product().parent()) False """ # Be flexible on how the maps are entered: accept a list/tuple of diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index fe5e22cffd9..2cce9fae52a 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -22,48 +22,49 @@ sage: Sets() Category of sets - sage: GSets(AbelianGroup([2,4,9])) + sage: GSets(AbelianGroup([2, 4, 9])) # optional - sage.groups Category of G-sets for Multiplicative Abelian group isomorphic to C2 x C4 x C9 sage: Semigroups() Category of semigroups - sage: VectorSpaces(FiniteField(11)) + sage: VectorSpaces(FiniteField(11)) # optional - sage.libs.pari Category of vector spaces over Finite Field of size 11 sage: Ideals(IntegerRing()) Category of ring ideals in Integer Ring Let's request the category of some objects:: - sage: V = VectorSpace(RationalField(), 3) - sage: V.category() + sage: V = VectorSpace(RationalField(), 3) # optional - sage.modules + sage: V.category() # optional - sage.modules Category of finite dimensional vector spaces with basis over (number fields and quotient fields and metric spaces) - sage: G = SymmetricGroup(9) - sage: G.category() - Join of Category of finite enumerated permutation groups and - Category of finite weyl groups and - Category of well generated finite irreducible complex reflection groups + sage: G = SymmetricGroup(9) # optional - sage.groups + sage: G.category() # optional - sage.groups + Join of + Category of finite enumerated permutation groups and + Category of finite weyl groups and + Category of well generated finite irreducible complex reflection groups - sage: P = PerfectMatchings(3) - sage: P.category() + sage: P = PerfectMatchings(3) # optional - sage.combinat sage.graphs + sage: P.category() # optional - sage.combinat sage.graphs Category of finite enumerated sets Let's check some memberships:: - sage: V in VectorSpaces(QQ) + sage: V in VectorSpaces(QQ) # optional - sage.modules True - sage: V in VectorSpaces(FiniteField(11)) + sage: V in VectorSpaces(FiniteField(11)) # optional - sage.modules sage.libs.pari False - sage: G in Monoids() + sage: G in Monoids() # optional - sage.groups True - sage: P in Rings() + sage: P in Rings() # optional - sage.combinat sage.graphs False For parametrized categories one can use the following shorthand:: - sage: V in VectorSpaces + sage: V in VectorSpaces # optional - sage.modules True - sage: G in VectorSpaces + sage: G in VectorSpaces # optional - sage.groups False A parent ``P`` is in a category ``C`` if ``P.category()`` is a subcategory of @@ -83,11 +84,11 @@ True By default, the category of an element `x` of a parent `P` is the category - of all objects of `P` (this is dubious an may be deprecated):: + of all objects of `P` (this is dubious and may be deprecated):: - sage: V = VectorSpace(RationalField(), 3) - sage: v = V.gen(1) - sage: v.category() + sage: V = VectorSpace(RationalField(), 3) # optional - sage.modules + sage: v = V.gen(1) # optional - sage.modules + sage: v.category() # optional - sage.modules Category of elements of Vector space of dimension 3 over Rational Field """ @@ -308,7 +309,8 @@ class inheritance from ``C.parent_class``. sage: Ds().parent_class.__bases__ (, ) sage: Ds().parent_class.mro() - [, , , , <... 'object'>] + [, , + , , <... 'object'>] Note that two categories in the same class need not have the same ``super_categories``. For example, ``Algebras(QQ)`` has @@ -325,7 +327,7 @@ class inheritance from ``C.parent_class``. On the other hand, identical hierarchies of classes are, preferably, built only once (e.g. for categories over a base ring):: - sage: Algebras(GF(5)).parent_class is Algebras(GF(7)).parent_class + sage: Algebras(GF(5)).parent_class is Algebras(GF(7)).parent_class # optional - sage.rings.finite_rings True sage: F = FractionField(ZZ['t']) sage: Coalgebras(F).parent_class is Coalgebras(FractionField(F['x'])).parent_class @@ -565,9 +567,11 @@ def an_instance(cls): sage: Algebras.an_instance() Category of algebras over Rational Field sage: Bimodules.an_instance() - Category of bimodules over Rational Field on the left and Real Field with 53 bits of precision on the right + Category of bimodules over Rational Field on the left + and Real Field with 53 bits of precision on the right sage: AlgebraIdeals.an_instance() - Category of algebra ideals in Univariate Polynomial Ring in x over Rational Field + Category of algebra ideals + in Univariate Polynomial Ring in x over Rational Field """ return cls() @@ -724,15 +728,15 @@ def __classcontains__(cls, x): This method makes it easy to test if an object is, say, a vector space, without having to specify the base ring:: - sage: F = FreeModule(QQ,3) - sage: F in VectorSpaces + sage: F = FreeModule(QQ, 3) # optional - sage.modules + sage: F in VectorSpaces # optional - sage.modules True - sage: F = FreeModule(ZZ,3) - sage: F in VectorSpaces + sage: F = FreeModule(ZZ, 3) # optional - sage.modules + sage: F in VectorSpaces # optional - sage.modules False - sage: F in Algebras + sage: F in Algebras # optional - sage.modules False TESTS: @@ -798,14 +802,14 @@ def category_graph(self): EXAMPLES:: sage: C = Algebras(QQ) - sage: G = C.category_graph() - sage: G.is_directed_acyclic() + sage: G = C.category_graph() # optional - sage.graphs + sage: G.is_directed_acyclic() # optional - sage.graphs True The girth of a directed acyclic graph is infinite, however, the girth of the underlying undirected graph is 4 in this case:: - sage: Graph(G).girth() + sage: Graph(G).girth() # optional - sage.graphs 4 """ return category_graph([self]) @@ -928,8 +932,8 @@ def _set_of_super_categories(self): TESTS:: - sage: C = HopfAlgebrasWithBasis(GF(7)) - sage: C._set_of_super_categories == frozenset(C._all_super_categories_proper) + sage: C = HopfAlgebrasWithBasis(GF(7)) # optional - sage.libs.pari + sage: C._set_of_super_categories == frozenset(C._all_super_categories_proper) # optional - sage.libs.pari True """ return frozenset(self._all_super_categories_proper) @@ -1669,7 +1673,7 @@ def parent_class(self): the category of algebras over a finite field versus algebras over a non-field:: - sage: Algebras(GF(7)).parent_class is Algebras(GF(5)).parent_class + sage: Algebras(GF(7)).parent_class is Algebras(GF(5)).parent_class # optional - sage.rings.finite_rings True sage: Algebras(QQ).parent_class is Algebras(ZZ).parent_class False @@ -1714,7 +1718,7 @@ def element_class(self): category of algebras over a field versus algebras over a non-field:: - sage: Algebras(GF(5)).element_class is Algebras(GF(3)).element_class + sage: Algebras(GF(5)).element_class is Algebras(GF(3)).element_class # optional - sage.rings.finite_rings True sage: Algebras(QQ).element_class is Algebras(ZZ).element_class False @@ -1788,9 +1792,9 @@ def is_subcategory(self, c): :: - sage: M3 = VectorSpaces(FiniteField(3)) - sage: M9 = VectorSpaces(FiniteField(9, 'a')) - sage: M3.is_subcategory(M9) + sage: M3 = VectorSpaces(FiniteField(3)) # optional - sage.libs.pari sage.modules + sage: M9 = VectorSpaces(FiniteField(9, 'a')) # optional - sage.libs.pari sage.modules + sage: M3.is_subcategory(M9) # optional - sage.libs.pari sage.modules False Join categories are properly handled:: @@ -1801,16 +1805,16 @@ def is_subcategory(self, c): :: - sage: V3 = VectorSpaces(FiniteField(3)) + sage: V3 = VectorSpaces(FiniteField(3)) # optional - sage.libs.pari sage: POSet = PartiallyOrderedSets() - sage: PoV3 = Category.join((V3, POSet)) - sage: A3 = AlgebrasWithBasis(FiniteField(3)) - sage: PoA3 = Category.join((A3, POSet)) - sage: PoA3.is_subcategory(PoV3) + sage: PoV3 = Category.join((V3, POSet)) # optional - sage.libs.pari + sage: A3 = AlgebrasWithBasis(FiniteField(3)) # optional - sage.libs.pari + sage: PoA3 = Category.join((A3, POSet)) # optional - sage.libs.pari + sage: PoA3.is_subcategory(PoV3) # optional - sage.libs.pari True - sage: PoV3.is_subcategory(PoV3) + sage: PoV3.is_subcategory(PoV3) # optional - sage.libs.pari True - sage: PoV3.is_subcategory(PoA3) + sage: PoV3.is_subcategory(PoA3) # optional - sage.libs.pari False """ if c is self: @@ -1852,7 +1856,8 @@ def or_subcategory(self, category=None, join=False): sage: Monoids().or_subcategory(EnumeratedSets()) Traceback (most recent call last): ... - ValueError: Subcategory of `Category of monoids` required; got `Category of enumerated sets` + ValueError: Subcategory of `Category of monoids` required; + got `Category of enumerated sets` Otherwise, the two categories are joined together:: @@ -2077,7 +2082,8 @@ def _with_axiom(self, axiom): sage: Magmas().Finite().Commutative().super_categories() [Category of commutative magmas, Category of finite sets] - sage: Algebras(QQ).WithBasis().Commutative() is Algebras(QQ).Commutative().WithBasis() + sage: C = Algebras(QQ).WithBasis().Commutative() + sage: C is Algebras(QQ).Commutative().WithBasis() True When ``axiom`` is not defined for ``self``, ``self`` is returned:: @@ -2252,7 +2258,9 @@ def _sort(categories): Category of commutative magmas, Category of finite sets, Category of facade sets) - sage: Category._sort(Category._flatten_categories([Sets().Finite(), Algebras(QQ).WithBasis(), Semigroups().Finite(), Sets().Facade(),Algebras(QQ).Commutative(), Algebras(QQ).Graded().WithBasis()], sage.categories.category.JoinCategory)) + sage: Category._sort(Category._flatten_categories([Sets().Finite(), Algebras(QQ).WithBasis(), Semigroups().Finite(), + ....: Sets().Facade(), Algebras(QQ).Commutative(), Algebras(QQ).Graded().WithBasis()], + ....: sage.categories.category.JoinCategory)) (Category of algebras with basis over Rational Field, Category of algebras with basis over Rational Field, Category of graded algebras over Rational Field, @@ -2597,7 +2605,7 @@ def category_sample(): EXAMPLES:: sage: from sage.categories.category import category_sample - sage: sorted(category_sample(), key=str) + sage: sorted(category_sample(), key=str) # optional - sage.groups [Category of G-sets for Symmetric group of order 8! as a permutation group, Category of Hecke modules over Rational Field, Category of Lie algebras over Rational Field, @@ -2636,14 +2644,14 @@ def category_graph(categories=None): EXAMPLES:: - sage: G = sage.categories.category.category_graph(categories = [Groups()]) - sage: G.vertices(sort=True) + sage: G = sage.categories.category.category_graph(categories=[Groups()]) # optional - sage.graphs + sage: G.vertices(sort=True) # optional - sage.graphs ['groups', 'inverse unital magmas', 'magmas', 'monoids', 'objects', 'semigroups', 'sets', 'sets with partial maps', 'unital magmas'] - sage: G.plot() + sage: G.plot() # optional - sage.graphs sage.plot Graphics object consisting of 20 graphics primitives - sage: sage.categories.category.category_graph().plot() + sage: sage.categories.category.category_graph().plot() # optional - sage.graphs sage.plot Graphics object consisting of ... graphics primitives """ from sage import graphs @@ -2691,15 +2699,15 @@ class CategoryWithParameters(Category): EXAMPLES:: - sage: C1 = Algebras(GF(5)) - sage: C2 = Algebras(GF(3)) + sage: C1 = Algebras(GF(5)) # optional - sage.rings.finite_rings + sage: C2 = Algebras(GF(3)) # optional - sage.rings.finite_rings sage: C3 = Algebras(ZZ) sage: from sage.categories.category import CategoryWithParameters - sage: isinstance(C1, CategoryWithParameters) + sage: isinstance(C1, CategoryWithParameters) # optional - sage.rings.finite_rings True - sage: C1.parent_class is C2.parent_class + sage: C1.parent_class is C2.parent_class # optional - sage.rings.finite_rings True - sage: C1.parent_class is C3.parent_class + sage: C1.parent_class is C3.parent_class # optional - sage.rings.finite_rings False .. automethod:: Category._make_named_class @@ -2744,7 +2752,7 @@ def _make_named_class(self, name, method_provider, cache=False, **options): The categories of bimodules over the fields ``CC`` or ``RR`` provide the same methods to their parents and elements:: - sage: Bimodules(ZZ,RR).parent_class is Bimodules(ZZ,RDF).parent_class #indirect doctest + sage: Bimodules(ZZ,RR).parent_class is Bimodules(ZZ,RDF).parent_class # indirect doctest True sage: Bimodules(CC,ZZ).element_class is Bimodules(RR,ZZ).element_class True @@ -2918,12 +2926,12 @@ class JoinCategory(CategoryWithParameters): the underlying implementation is the same for all finite fields, we have:: - sage: G = SymmetricGroup(10) - sage: A3 = G.algebra(GF(3)) - sage: A5 = G.algebra(GF(5)) - sage: type(A3.category()) + sage: G = SymmetricGroup(10) # optional - sage.groups sage.rings.finite_rings + sage: A3 = G.algebra(GF(3)) # optional - sage.groups sage.rings.finite_rings + sage: A5 = G.algebra(GF(5)) # optional - sage.groups sage.rings.finite_rings + sage: type(A3.category()) # optional - sage.groups sage.rings.finite_rings - sage: type(A3) is type(A5) + sage: type(A3) is type(A5) # optional - sage.groups sage.rings.finite_rings True .. automethod:: Category._repr_object_names diff --git a/src/sage/categories/category_types.py b/src/sage/categories/category_types.py index 4469a57a996..2c18e308a3e 100644 --- a/src/sage/categories/category_types.py +++ b/src/sage/categories/category_types.py @@ -72,14 +72,14 @@ def _call_(self, x): """ EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: x = V.0 - sage: C = x.category() - sage: C + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: x = V.0 # optional - sage.modules + sage: C = x.category() # optional - sage.modules + sage: C # optional - sage.modules Category of elements of Vector space of dimension 3 over Rational Field - sage: w = C([1,2,3]); w # indirect doctest + sage: w = C([1, 2, 3]); w # indirect doctest # optional - sage.modules (1, 2, 3) - sage: w.category() + sage: w.category() # optional - sage.modules Category of elements of Vector space of dimension 3 over Rational Field """ return self.__object(x) @@ -129,9 +129,9 @@ def _latex_(self): r""" EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: x = V.0 - sage: latex(x.category()) # indirect doctest + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: x = V.0 # optional - sage.modules + sage: latex(x.category()) # indirect doctest # optional - sage.modules \mathbf{Elt}_{\Bold{Q}^{3}} """ return "\\mathbf{Elt}_{%s}"%latex(self.__object) @@ -153,11 +153,11 @@ class Category_over_base(CategoryWithParameters): EXAMPLES:: - sage: Algebras(GF(2)).element_class is Algebras(GF(3)).element_class + sage: Algebras(GF(2)).element_class is Algebras(GF(3)).element_class # optional - sage.rings.finite_rings True - sage: C = GF(2).category() - sage: Algebras(GF(2)).parent_class is Algebras(C).parent_class + sage: C = GF(2).category() # optional - sage.rings.finite_rings + sage: Algebras(GF(2)).parent_class is Algebras(C).parent_class # optional - sage.rings.finite_rings True sage: C = ZZ.category() @@ -278,7 +278,7 @@ def _repr_object_names(self): 'algebras over Rational Field' sage: Algebras(Fields())._repr_object_names() 'algebras over fields' - sage: Algebras(GF(2).category())._repr_object_names() + sage: Algebras(GF(2).category())._repr_object_names() # optional - sage.rings.finite_rings 'algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups)' """ base = self.__base @@ -338,9 +338,9 @@ def __init__(self, base, name=None): EXAMPLES:: - sage: C = Algebras(GF(2)); C + sage: C = Algebras(GF(2)); C # optional - sage.rings.finite_rings Category of algebras over Finite Field of size 2 - sage: TestSuite(C).run() + sage: TestSuite(C).run() # optional - sage.rings.finite_rings """ from sage.categories.rings import Rings if not (base in Rings() or @@ -355,8 +355,8 @@ def base_ring(self): EXAMPLES:: - sage: C = Algebras(GF(2)) - sage: C.base_ring() + sage: C = Algebras(GF(2)) # optional - sage.rings.finite_rings + sage: C.base_ring() # optional - sage.rings.finite_rings Finite Field of size 2 """ return self.base() @@ -399,11 +399,11 @@ def _subcategory_hook_(self, C): sage: VectorSpaces(QQ)._subcategory_hook_(VectorSpaces(QQ) & Rings()) Unknown - sage: Sym = SymmetricFunctions(QQ) - sage: from sage.combinat.sf.sfa import SymmetricFunctionsBases - sage: Modules(QQ)._subcategory_hook_(SymmetricFunctionsBases(Sym)) + sage: Sym = SymmetricFunctions(QQ) # optional - sage.combinat + sage: from sage.combinat.sf.sfa import SymmetricFunctionsBases # optional - sage.combinat + sage: Modules(QQ)._subcategory_hook_(SymmetricFunctionsBases(Sym)) # optional - sage.combinat Unknown - sage: SymmetricFunctionsBases(Sym).is_subcategory(Modules(QQ)) + sage: SymmetricFunctionsBases(Sym).is_subcategory(Modules(QQ)) # optional - sage.combinat True Case 1: the two bases are categories; then the base of ``C`` @@ -411,7 +411,7 @@ def _subcategory_hook_(self, C): sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(Fields())) True - sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(Fields().Finite())) # todo: not implemented + sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(Fields().Finite())) # todo: not implemented True sage: VectorSpaces(Fields().Finite())._subcategory_hook_(Algebras(Fields())) False @@ -419,7 +419,7 @@ def _subcategory_hook_(self, C): Case 2: the base of ``self`` is a category; then the base of ``C`` shall be a parent in this category:: - sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(QQ)) # todo: not implemented + sage: VectorSpaces(Fields())._subcategory_hook_(Algebras(QQ)) # todo: not implemented True sage: VectorSpaces(Fields().Finite())._subcategory_hook_(Algebras(QQ)) False @@ -430,15 +430,17 @@ def _subcategory_hook_(self, C): True sage: VectorSpaces(CC)._subcategory_hook_(Algebras(QQ)) # base ring in different categories False - sage: VectorSpaces(GF(2))._subcategory_hook_(Algebras(GF(3))) # base ring in the same category + sage: VectorSpaces(GF(2))._subcategory_hook_(Algebras(GF(3))) # base ring in the same category # optional - sage.rings.finite_rings False Note; we need both previous tests since the distinction is made respectively using the parent class or the base ring:: - sage: issubclass(Algebras(QQ).parent_class, VectorSpaces(CC).parent_class) + sage: issubclass(Algebras(QQ).parent_class, # optional - sage.modules + ....: VectorSpaces(CC).parent_class) False - sage: issubclass(Algebras(GF(2)).parent_class, VectorSpaces(GF(3)).parent_class) + sage: issubclass(Algebras(GF(2)).parent_class, # optional - sage.modules sage.rings.finite_rings + ....: VectorSpaces(GF(3)).parent_class) True Check that :trac:`16618` is fixed: this `_subcategory_hook_` diff --git a/src/sage/categories/category_with_axiom.py b/src/sage/categories/category_with_axiom.py index 1c92e587456..a304ff996cd 100644 --- a/src/sage/categories/category_with_axiom.py +++ b/src/sage/categories/category_with_axiom.py @@ -182,7 +182,8 @@ class ``Semigroups.Infinite`` inheriting from :class:`CategoryWithAxiom`. :trac:`15648`), one should pass the option ``as_name`` to :class:`~sage.misc.lazy_import.LazyImport`:: - Finite = LazyImport('sage.categories.finite_groups', 'FiniteGroups', as_name='Finite') + Finite = LazyImport('sage.categories.finite_groups', 'FiniteGroups', + as_name='Finite') in order to prevent ``Groups.Finite`` to keep on reimporting ``FiniteGroups``. @@ -1730,7 +1731,8 @@ def base_category_class_and_axiom(cls): (, 'Finite') sage: base_category_class_and_axiom(FiniteDimensionalHopfAlgebrasWithBasis) - (, 'FiniteDimensional') + (, + 'FiniteDimensional') sage: base_category_class_and_axiom(HopfAlgebrasWithBasis) (, 'WithBasis') @@ -1742,7 +1744,9 @@ def base_category_class_and_axiom(cls): sage: base_category_class_and_axiom(FacadeSemigroups) Traceback (most recent call last): ... - AssertionError: Missing (lazy import) link for to for axiom Facade? + AssertionError: Missing (lazy import) link + for + to for axiom Facade? sage: Semigroups.Facade = FacadeSemigroups sage: base_category_class_and_axiom(FacadeSemigroups) @@ -1760,7 +1764,8 @@ def base_category_class_and_axiom(cls): sage: base_category_class_and_axiom(Sets.Infinite) Traceback (most recent call last): ... - TypeError: Could not retrieve the base category class and axiom for . + TypeError: Could not retrieve the base category class and axiom + for . ... """ if "." in cls.__name__: @@ -1812,7 +1817,8 @@ def axiom_of_nested_class(cls, nested_cls): sage: from sage.categories.category_with_axiom import TestObjects, axiom_of_nested_class sage: axiom_of_nested_class(TestObjects, TestObjects.FiniteDimensional) 'FiniteDimensional' - sage: axiom_of_nested_class(TestObjects.FiniteDimensional, TestObjects.FiniteDimensional.Finite) + sage: axiom_of_nested_class(TestObjects.FiniteDimensional, + ....: TestObjects.FiniteDimensional.Finite) 'Finite' sage: axiom_of_nested_class(Sets, FiniteSets) 'Finite' @@ -2456,9 +2462,9 @@ def axioms(self): sage: C.axioms() frozenset({'Finite'}) - sage: C = Modules(GF(5)).FiniteDimensional(); C + sage: C = Modules(GF(5)).FiniteDimensional(); C # optional - sage.rings.finite_rings Category of finite dimensional vector spaces over Finite Field of size 5 - sage: sorted(C.axioms()) + sage: sorted(C.axioms()) # optional - sage.rings.finite_rings ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Finite', 'FiniteDimensional'] @@ -2466,7 +2472,7 @@ def axioms(self): ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'FiniteDimensional', 'Unital', 'WithBasis'] - sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms()) + sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms()) # optional - sage.rings.finite_rings ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'Finite', 'FiniteDimensional', 'Unital', 'WithBasis'] @@ -2543,7 +2549,8 @@ class CategoryWithAxiom_singleton(Category_singleton, CategoryWithAxiom):#, Cate sage: isinstance(C, Category_over_base_ring) # todo: not implemented True sage: C.FiniteDimensional() - Category of finite dimensional connected test objects over base ring over Ring of integers modulo 2 + Category of finite dimensional connected test objects + over base ring over Ring of integers modulo 2 sage: C.Connected() Category of connected test objects over base ring over Ring of integers modulo 2 """ @@ -2790,7 +2797,8 @@ def super_categories(self): Category of unital test objects over base ring over Rational Field sage: TestObjectsOverBaseRing.FiniteDimensional.Unital.an_instance() Category of finite dimensional unital test objects over base ring over Rational Field - sage: TestSuite(TestObjectsOverBaseRing(QQ).FiniteDimensional().Unital().Commutative()).run() + sage: C = TestObjectsOverBaseRing(QQ).FiniteDimensional().Unital().Commutative() + sage: TestSuite(C).run() """ return [TestObjects()] diff --git a/src/sage/categories/chain_complexes.py b/src/sage/categories/chain_complexes.py index b1d8c578e60..8ce3e6145bc 100644 --- a/src/sage/categories/chain_complexes.py +++ b/src/sage/categories/chain_complexes.py @@ -67,27 +67,27 @@ def homology(self, n=None): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: C.homology(0) + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules + sage: C.homology(0) # optional - sage.modules Z x Z - sage: C.homology(1) + sage: C.homology(1) # optional - sage.modules Z x C3 - sage: C.homology(2) + sage: C.homology(2) # optional - sage.modules 0 :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) - sage: C = A.cdg_algebra({z: x*y}) - sage: C.homology(0) + sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # optional - sage.combinat sage.modules + sage: C = A.cdg_algebra({z: x*y}) # optional - sage.combinat sage.modules + sage: C.homology(0) # optional - sage.combinat sage.modules Free module generated by {[1]} over Rational Field - sage: C.homology(1) + sage: C.homology(1) # optional - sage.combinat sage.modules Free module generated by {} over Rational Field - sage: C.homology(2) + sage: C.homology(2) # optional - sage.combinat sage.modules Free module generated by {[x], [y]} over Rational Field - sage: C.homology(3) + sage: C.homology(3) # optional - sage.combinat sage.modules Free module generated by {} over Rational Field - sage: C.homology(4) + sage: C.homology(4) # optional - sage.combinat sage.modules Free module generated by {[x^2], [y^2]} over Rational Field """ @@ -99,17 +99,18 @@ def differential(self, *args, **kwargs): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: C.differential(0) + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules + sage: C.differential(0) # optional - sage.modules [3 0 0] [0 0 0] :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) - sage: C = A.cdg_algebra({z: x*y}) - sage: C.differential() - Differential of Commutative Differential Graded Algebra with generators ('x', 'y', 'z') in degrees (2, 2, 3) over Rational Field + sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # optional - sage.combinat sage.modules + sage: C = A.cdg_algebra({z: x*y}) # optional - sage.combinat sage.modules + sage: C.differential() # optional - sage.combinat sage.modules + Differential of Commutative Differential Graded Algebra with + generators ('x', 'y', 'z') in degrees (2, 2, 3) over Rational Field Defn: x --> 0 y --> 0 z --> x*y @@ -123,10 +124,10 @@ def lift_from_homology(self, x): EXAMPLES:: - sage: E3 = EuclideanSpace(3) # optional - sage.symbolic - sage: C = E3.de_rham_complex() # optional - sage.symbolic - sage: one = C.homology().one() # optional - sage.symbolic - sage: C.lift_from_homology(one) # optional - sage.symbolic + sage: E3 = EuclideanSpace(3) # optional - sage.symbolic + sage: C = E3.de_rham_complex() # optional - sage.symbolic + sage: one = C.homology().one() # optional - sage.symbolic + sage: C.lift_from_homology(one) # optional - sage.symbolic Mixed differential form one on the Euclidean space E^3 """ @@ -143,10 +144,10 @@ def reduce_to_homology(self, x, n=None): EXAMPLES:: - sage: E3 = EuclideanSpace(3) # optional - sage.symbolic - sage: C = E3.de_rham_complex() # optional - sage.symbolic - sage: one = C.one() # optional - sage.symbolic - sage: C.reduce_to_homology(one) # optional - sage.symbolic + sage: E3 = EuclideanSpace(3) # optional - sage.symbolic + sage: C = E3.de_rham_complex() # optional - sage.symbolic + sage: one = C.one() # optional - sage.symbolic + sage: C.reduce_to_homology(one) # optional - sage.symbolic [one] """ try: @@ -168,35 +169,35 @@ class HomologyFunctor(Functor): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) - sage: H(C) + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules + sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) # optional - sage.modules + sage: H(C) # optional - sage.modules Z x C3 :: - sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) - sage: C = A.cdg_algebra({z: x*y}) - sage: H = HomologyFunctor(ChainComplexes(QQ), 2) - sage: H(C) + sage: A. = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # optional - sage.combinat sage.modules + sage: C = A.cdg_algebra({z: x*y}) # optional - sage.combinat sage.modules + sage: H = HomologyFunctor(ChainComplexes(QQ), 2) # optional - sage.combinat sage.modules + sage: H(C) # optional - sage.combinat sage.modules Free module generated by {[x], [y]} over Rational Field Applying to a chain map:: - sage: S = simplicial_complexes.Sphere(1); S + sage: S = simplicial_complexes.Sphere(1); S # optional - sage.graphs Minimal triangulation of the 1-sphere - sage: C = S.chain_complex() - sage: C.differential() + sage: C = S.chain_complex() # optional - sage.graphs sage.modules + sage: C.differential() # optional - sage.graphs sage.modules {0: [], 1: [-1 -1 0] [ 1 0 -1] [ 0 1 1], 2: []} - sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)} - sage: G = Hom(C,C) - sage: x = G(f) - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) - sage: H(C) + sage: f = {0: zero_matrix(ZZ,3,3), 1: zero_matrix(ZZ,3,3)} # optional - sage.modules + sage: G = Hom(C, C) # optional - sage.graphs sage.modules + sage: x = G(f) # optional - sage.graphs sage.modules + sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) # optional - sage.graphs sage.modules + sage: H(C) # optional - sage.graphs sage.modules Z - sage: H(x) + sage: H(x) # optional - sage.graphs sage.modules Generic morphism: From: Z To: Z @@ -225,9 +226,9 @@ def _apply_functor(self, x): TESTS:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) - sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) - sage: H._apply_functor(C) + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) # optional - sage.modules + sage: H = HomologyFunctor(ChainComplexes(ZZ), 1) # optional - sage.modules + sage: H._apply_functor(C) # optional - sage.modules Z x C3 """ @@ -239,15 +240,15 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: E3 = EuclideanSpace(3) # optional - sage.symbolic - sage: C = E3.de_rham_complex() # optional - sage.symbolic - sage: id = Hom(C, C).identity() # optional - sage.symbolic - sage: H = HomologyFunctor(ChainComplexes(SR)) # optional - sage.symbolic - sage: id_star = H(id); id_star # optional - sage.symbolic + sage: E3 = EuclideanSpace(3) # optional - sage.symbolic + sage: C = E3.de_rham_complex() # optional - sage.symbolic + sage: id = Hom(C, C).identity() # optional - sage.symbolic + sage: H = HomologyFunctor(ChainComplexes(SR)) # optional - sage.symbolic + sage: id_star = H(id); id_star # optional - sage.symbolic Generic endomorphism of De Rham cohomology ring on the Euclidean space E^3 - sage: one = H(C).one() # optional - sage.symbolic - sage: id_star(one) # optional - sage.symbolic + sage: one = H(C).one() # optional - sage.symbolic + sage: id_star(one) # optional - sage.symbolic [one] """ from .morphism import SetMorphism diff --git a/src/sage/categories/classical_crystals.py b/src/sage/categories/classical_crystals.py index 9650dae15a2..373d07378d9 100644 --- a/src/sage/categories/classical_crystals.py +++ b/src/sage/categories/classical_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Classical Crystals """ diff --git a/src/sage/categories/coalgebras.py b/src/sage/categories/coalgebras.py index ecbf5d15baf..870315dc644 100644 --- a/src/sage/categories/coalgebras.py +++ b/src/sage/categories/coalgebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Coalgebras """ diff --git a/src/sage/categories/coalgebras_with_basis.py b/src/sage/categories/coalgebras_with_basis.py index 5518804d649..844f5e5a294 100644 --- a/src/sage/categories/coalgebras_with_basis.py +++ b/src/sage/categories/coalgebras_with_basis.py @@ -61,10 +61,12 @@ def coproduct_on_basis(self, i): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: (a, b) = A._group.gens() - sage: A.coproduct_on_basis(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + An example of Hopf algebra with basis: + the group algebra of the Dihedral group of order 6 + as a permutation group over Rational Field + sage: (a, b) = A._group.gens() # optional - sage.groups sage.modules + sage: A.coproduct_on_basis(a) # optional - sage.groups sage.modules B[(1,2,3)] # B[(1,2,3)] """ @@ -79,12 +81,14 @@ def coproduct(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: [a,b] = A.algebra_generators() - sage: a, A.coproduct(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + An example of Hopf algebra with basis: + the group algebra of the Dihedral group of order 6 + as a permutation group over Rational Field + sage: a, b = A.algebra_generators() # optional - sage.groups sage.modules + sage: a, A.coproduct(a) # optional - sage.groups sage.modules (B[(1,2,3)], B[(1,2,3)] # B[(1,2,3)]) - sage: b, A.coproduct(b) + sage: b, A.coproduct(b) # optional - sage.groups sage.modules (B[(1,3)], B[(1,3)] # B[(1,3)]) """ @@ -111,10 +115,12 @@ def counit_on_basis(self, i): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: (a, b) = A._group.gens() - sage: A.counit_on_basis(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + An example of Hopf algebra with basis: + the group algebra of the Dihedral group of order 6 + as a permutation group over Rational Field + sage: (a, b) = A._group.gens() # optional - sage.groups sage.modules + sage: A.counit_on_basis(a) # optional - sage.groups sage.modules 1 """ @@ -127,12 +133,14 @@ def counit(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: [a,b] = A.algebra_generators() - sage: a, A.counit(a) + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups sage.modules + An example of Hopf algebra with basis: + the group algebra of the Dihedral group of order 6 + as a permutation group over Rational Field + sage: a, b = A.algebra_generators() # optional - sage.groups sage.modules + sage: a, A.counit(a) # optional - sage.groups sage.modules (B[(1,2,3)], 1) - sage: b, A.counit(b) + sage: b, A.counit(b) # optional - sage.groups sage.modules (B[(1,3)], 1) """ @@ -152,29 +160,29 @@ def coproduct_iterated(self, n=1): EXAMPLES:: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() - sage: Psi[2,2].coproduct_iterated(0) + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat + sage: Psi[2,2].coproduct_iterated(0) # optional - sage.combinat Psi[2, 2] - sage: Psi[2,2].coproduct_iterated(2) + sage: Psi[2,2].coproduct_iterated(2) # optional - sage.combinat Psi[] # Psi[] # Psi[2, 2] + 2*Psi[] # Psi[2] # Psi[2] + Psi[] # Psi[2, 2] # Psi[] + 2*Psi[2] # Psi[] # Psi[2] + 2*Psi[2] # Psi[2] # Psi[] + Psi[2, 2] # Psi[] # Psi[] TESTS:: - sage: p = SymmetricFunctions(QQ).p() - sage: p[5,2,2].coproduct_iterated() + sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat + sage: p[5,2,2].coproduct_iterated() # optional - sage.combinat p[] # p[5, 2, 2] + 2*p[2] # p[5, 2] + p[2, 2] # p[5] + p[5] # p[2, 2] + 2*p[5, 2] # p[2] + p[5, 2, 2] # p[] - sage: p([]).coproduct_iterated(3) + sage: p([]).coproduct_iterated(3) # optional - sage.combinat p[] # p[] # p[] # p[] :: - sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() - sage: Psi[2,2].coproduct_iterated(0) + sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() # optional - sage.combinat + sage: Psi[2,2].coproduct_iterated(0) # optional - sage.combinat Psi[2, 2] - sage: Psi[2,2].coproduct_iterated(3) + sage: Psi[2,2].coproduct_iterated(3) # optional - sage.combinat Psi[] # Psi[] # Psi[] # Psi[2, 2] + 2*Psi[] # Psi[] # Psi[2] # Psi[2] + Psi[] # Psi[] # Psi[2, 2] # Psi[] + 2*Psi[] # Psi[2] # Psi[] # Psi[2] + 2*Psi[] # Psi[2] # Psi[2] # Psi[] + Psi[] # Psi[2, 2] # Psi[] # Psi[] @@ -183,14 +191,14 @@ def coproduct_iterated(self, n=1): :: - sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() - sage: m[[1,3],[2]].coproduct_iterated(2) + sage: m = SymmetricFunctionsNonCommutingVariables(QQ).m() # optional - sage.combinat + sage: m[[1,3],[2]].coproduct_iterated(2) # optional - sage.combinat m{} # m{} # m{{1, 3}, {2}} + m{} # m{{1}} # m{{1, 2}} + m{} # m{{1, 2}} # m{{1}} + m{} # m{{1, 3}, {2}} # m{} + m{{1}} # m{} # m{{1, 2}} + m{{1}} # m{{1, 2}} # m{} + m{{1, 2}} # m{} # m{{1}} + m{{1, 2}} # m{{1}} # m{} + m{{1, 3}, {2}} # m{} # m{} - sage: m[[]].coproduct_iterated(3), m[[1,3],[2]].coproduct_iterated(0) + sage: m[[]].coproduct_iterated(3), m[[1,3],[2]].coproduct_iterated(0) # optional - sage.combinat (m{} # m{} # m{} # m{}, m{{1, 3}, {2}}) """ if n < 0: diff --git a/src/sage/categories/commutative_additive_groups.py b/src/sage/categories/commutative_additive_groups.py index c1383022833..9300f4d6db5 100644 --- a/src/sage/categories/commutative_additive_groups.py +++ b/src/sage/categories/commutative_additive_groups.py @@ -79,10 +79,11 @@ def additive_order(self): sage: G((0,1)).additive_order() +Infinity - sage: K = GF(9) - sage: H = cartesian_product([cartesian_product([Zmod(2),Zmod(9)]), K]) - sage: z = H(((1,2), K.gen())) - sage: z.additive_order() + sage: K = GF(9) # optional - sage.rings.finite_rings + sage: H = cartesian_product([ # optional - sage.rings.finite_rings + ....: cartesian_product([Zmod(2), Zmod(9)]), K]) + sage: z = H(((1,2), K.gen())) # optional - sage.rings.finite_rings + sage: z.additive_order() # optional - sage.rings.finite_rings 18 """ from sage.rings.infinity import Infinity diff --git a/src/sage/categories/commutative_algebra_ideals.py b/src/sage/categories/commutative_algebra_ideals.py index 15824e09644..e0835848e91 100644 --- a/src/sage/categories/commutative_algebra_ideals.py +++ b/src/sage/categories/commutative_algebra_ideals.py @@ -24,14 +24,16 @@ class CommutativeAlgebraIdeals(Category_ideal): sage: C = CommutativeAlgebraIdeals(QQ['x']) sage: C - Category of commutative algebra ideals in Univariate Polynomial Ring in x over Rational Field + Category of commutative algebra ideals in + Univariate Polynomial Ring in x over Rational Field """ def __init__(self, A): """ EXAMPLES:: sage: CommutativeAlgebraIdeals(ZZ['x']) - Category of commutative algebra ideals in Univariate Polynomial Ring in x over Integer Ring + Category of commutative algebra ideals in + Univariate Polynomial Ring in x over Integer Ring sage: CommutativeAlgebraIdeals(ZZ) Traceback (most recent call last): @@ -43,7 +45,7 @@ def __init__(self, A): ... TypeError: A (=Ring of integers modulo 4) must be a commutative algebra - sage: CommutativeAlgebraIdeals(Partitions(4)) + sage: CommutativeAlgebraIdeals(Partitions(4)) # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: A (=Partitions of the integer 4) must be a commutative algebra diff --git a/src/sage/categories/commutative_algebras.py b/src/sage/categories/commutative_algebras.py index cff24e1298a..bdff573db87 100644 --- a/src/sage/categories/commutative_algebras.py +++ b/src/sage/categories/commutative_algebras.py @@ -22,8 +22,8 @@ class CommutativeAlgebras(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: M = CommutativeAlgebras(GF(19)) - sage: M + sage: M = CommutativeAlgebras(GF(19)) # optional - sage.rings.finite_rings + sage: M # optional - sage.rings.finite_rings Category of commutative algebras over Finite Field of size 19 sage: CommutativeAlgebras(QQ).super_categories() [Category of algebras over Rational Field, Category of commutative rings] @@ -53,7 +53,7 @@ def __contains__(self, A): True sage: QQ['a,b'] in CommutativeAlgebras(QQ) True - sage: FreeAlgebra(QQ,2,'a,b') in CommutativeAlgebras(QQ) + sage: FreeAlgebra(QQ, 2, 'a,b') in CommutativeAlgebras(QQ) # optional - sage.combinat False TODO: get rid of this method once all commutative algebras in @@ -80,12 +80,12 @@ def extra_super_categories(self): TESTS:: - sage: X = algebras.Shuffle(QQ, 'ab') - sage: Y = algebras.Shuffle(QQ, 'bc') - sage: X in Algebras(QQ).Commutative() + sage: X = algebras.Shuffle(QQ, 'ab') # optional - sage.combinat + sage: Y = algebras.Shuffle(QQ, 'bc') # optional - sage.combinat + sage: X in Algebras(QQ).Commutative() # optional - sage.combinat True - sage: T = tensor([X, Y]) - sage: T in CommutativeRings() + sage: T = tensor([X, Y]) # optional - sage.combinat + sage: T in CommutativeRings() # optional - sage.combinat True """ return [CommutativeRings()] diff --git a/src/sage/categories/commutative_ring_ideals.py b/src/sage/categories/commutative_ring_ideals.py index 115b79afb80..837f1edf944 100644 --- a/src/sage/categories/commutative_ring_ideals.py +++ b/src/sage/categories/commutative_ring_ideals.py @@ -35,7 +35,7 @@ def __init__(self, R): TESTS:: - sage: CommutativeRingIdeals(Partitions(4)) + sage: CommutativeRingIdeals(Partitions(4)) # optional - sage.combinat Traceback (most recent call last): ... TypeError: R (=Partitions of the integer 4) must be a commutative ring diff --git a/src/sage/categories/commutative_rings.py b/src/sage/categories/commutative_rings.py index 71e08a5070d..6219c1070bb 100644 --- a/src/sage/categories/commutative_rings.py +++ b/src/sage/categories/commutative_rings.py @@ -35,14 +35,14 @@ class CommutativeRings(CategoryWithAxiom): sage: QQ['x,y,z'] in CommutativeRings() True - sage: GroupAlgebra(DihedralGroup(3), QQ) in CommutativeRings() + sage: GroupAlgebra(DihedralGroup(3), QQ) in CommutativeRings() # optional - sage.groups sage.modules False - sage: MatrixSpace(QQ,2,2) in CommutativeRings() + sage: MatrixSpace(QQ, 2, 2) in CommutativeRings() # optional - sage.modules False GroupAlgebra should be fixed:: - sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # todo: not implemented + sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # todo: not implemented # optional - sage.groups sage.modules True """ @@ -110,92 +110,98 @@ def over(self, base=None, gen=None, gens=None, name=None, names=None): We construct an extension of finite fields:: - sage: F = GF(5^2) - sage: k = GF(5^4) - sage: z4 = k.gen() + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: k = GF(5^4) # optional - sage.rings.finite_rings + sage: z4 = k.gen() # optional - sage.rings.finite_rings - sage: K = k.over(F) - sage: K - Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base + sage: K = k.over(F) # optional - sage.rings.finite_rings + sage: K # optional - sage.rings.finite_rings + Field in z4 with defining polynomial + x^2 + (4*z2 + 3)*x + z2 over its base If not explicitly given, the default generator of the top ring (here k) is used and the same name is kept:: - sage: K.gen() + sage: K.gen() # optional - sage.rings.finite_rings z4 - sage: K(z4) + sage: K(z4) # optional - sage.rings.finite_rings z4 However, it is possible to specify another generator and/or another name. For example:: - sage: Ka = k.over(F, name='a') - sage: Ka - Field in a with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: Ka.gen() + sage: Ka = k.over(F, name='a') # optional - sage.rings.finite_rings + sage: Ka # optional - sage.rings.finite_rings + Field in a with defining polynomial + x^2 + (4*z2 + 3)*x + z2 over its base + sage: Ka.gen() # optional - sage.rings.finite_rings a - sage: Ka(z4) + sage: Ka(z4) # optional - sage.rings.finite_rings a - sage: Kb = k.over(F, gen=-z4+1, name='b') - sage: Kb + sage: Kb = k.over(F, gen=-z4+1, name='b') # optional - sage.rings.finite_rings + sage: Kb # optional - sage.rings.finite_rings Field in b with defining polynomial x^2 + z2*x + 4 over its base - sage: Kb.gen() + sage: Kb.gen() # optional - sage.rings.finite_rings b - sage: Kb(-z4+1) + sage: Kb(-z4+1) # optional - sage.rings.finite_rings b Note that the shortcut ``K.`` is also available:: - sage: KKa. = k.over(F) - sage: KKa is Ka + sage: KKa. = k.over(F) # optional - sage.rings.finite_rings + sage: KKa is Ka # optional - sage.rings.finite_rings True Building an extension on top of another extension is allowed:: - sage: L = GF(5^12).over(K) - sage: L - Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base - sage: L.base_ring() - Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings + Field in z12 with defining polynomial + x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base + sage: L.base_ring() # optional - sage.rings.finite_rings + Field in z4 with defining polynomial + x^2 + (4*z2 + 3)*x + z2 over its base The successive bases of an extension are accessible via the method :meth:`sage.rings.ring_extension.RingExtension_generic.bases`:: - sage: L.bases() - [Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, - Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base, + sage: L.bases() # optional - sage.rings.finite_rings + [Field in z12 with defining polynomial + x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, + Field in z4 with defining polynomial + x^2 + (4*z2 + 3)*x + z2 over its base, Finite Field in z2 of size 5^2] When ``base`` is omitted, the canonical base of the ring is used:: sage: S. = QQ[] - sage: E = S.over() - sage: E + sage: E = S.over() # optional - sage.modules + sage: E # optional - sage.modules Univariate Polynomial Ring in x over Rational Field over its base - sage: E.base_ring() + sage: E.base_ring() # optional - sage.modules Rational Field Here is an example where ``base`` is a defining morphism:: - sage: k. = QQ.extension(x^2 - 2) - sage: l. = QQ.extension(x^4 - 2) - sage: f = k.hom([b^2]) - sage: L = l.over(f) - sage: L + sage: k. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: l. = QQ.extension(x^4 - 2) # optional - sage.rings.number_field + sage: f = k.hom([b^2]) # optional - sage.rings.number_field + sage: L = l.over(f) # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field Field in b with defining polynomial x^2 - a over its base - sage: L.base_ring() + sage: L.base_ring() # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 - 2 Similarly, one can create a tower of extensions:: - sage: K = k.over() - sage: L = l.over(Hom(K,l)(f)) - sage: L + sage: K = k.over() # optional - sage.rings.number_field + sage: L = l.over(Hom(K, l)(f)) # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field Field in b with defining polynomial x^2 - a over its base - sage: L.base_ring() + sage: L.base_ring() # optional - sage.rings.number_field Field in a with defining polynomial x^2 - 2 over its base - sage: L.bases() + sage: L.bases() # optional - sage.rings.number_field [Field in b with defining polynomial x^2 - a over its base, Field in a with defining polynomial x^2 - 2 over its base, Rational Field] @@ -221,7 +227,8 @@ class Finite(CategoryWithAxiom): EXAMPLES:: - sage: cartesian_product([Zmod(34), GF(5)]) in Rings().Commutative().Finite() + sage: cartesian_product([Zmod(34), # optional - sage.rings.finite_rings + ....: GF(5)]) in Rings().Commutative().Finite() True """ class ParentMethods: @@ -278,34 +285,34 @@ def cyclotomic_cosets(self, q, cosets=None): cyclic, the set of squares is a particular case of cyclotomic coset:: - sage: K = GF(25,'z') - sage: a = K.multiplicative_generator() - sage: K.cyclotomic_cosets(a**2,cosets=[1]) + sage: K = GF(25, 'z') # optional - sage.rings.finite_rings + sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings + sage: K.cyclotomic_cosets(a**2, cosets=[1]) # optional - sage.rings.finite_rings [[1, 2, 3, 4, z + 1, z + 3, 2*z + 1, 2*z + 2, 3*z + 3, 3*z + 4, 4*z + 2, 4*z + 4]] - sage: sorted(b for b in K if not b.is_zero() and b.is_square()) + sage: sorted(b for b in K if not b.is_zero() and b.is_square()) # optional - sage.rings.finite_rings [1, 2, 3, 4, z + 1, z + 3, 2*z + 1, 2*z + 2, 3*z + 3, 3*z + 4, 4*z + 2, 4*z + 4] We compute some examples of minimal polynomials:: - sage: K = GF(27,'z') - sage: a = K.multiplicative_generator() - sage: R. = PolynomialRing(K, 'X') - sage: a.minimal_polynomial('X') + sage: K = GF(27, 'z') # optional - sage.rings.finite_rings + sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(K, 'X') # optional - sage.rings.finite_rings + sage: a.minimal_polynomial('X') # optional - sage.rings.finite_rings X^3 + 2*X + 1 - sage: cyc3 = Zmod(26).cyclotomic_cosets(3,cosets=[1]); cyc3 + sage: cyc3 = Zmod(26).cyclotomic_cosets(3, cosets=[1]); cyc3 # optional - sage.rings.finite_rings [[1, 3, 9]] - sage: prod(X - a**i for i in cyc3[0]) + sage: prod(X - a**i for i in cyc3[0]) # optional - sage.rings.finite_rings X^3 + 2*X + 1 - sage: (a**7).minimal_polynomial('X') + sage: (a**7).minimal_polynomial('X') # optional - sage.rings.finite_rings X^3 + X^2 + 2*X + 1 - sage: cyc7 = Zmod(26).cyclotomic_cosets(3,cosets=[7]); cyc7 + sage: cyc7 = Zmod(26).cyclotomic_cosets(3, cosets=[7]); cyc7 # optional - sage.rings.finite_rings [[7, 11, 21]] - sage: prod(X - a**i for i in cyc7[0]) + sage: prod(X - a**i for i in cyc7[0]) # optional - sage.rings.finite_rings X^3 + X^2 + 2*X + 1 Cyclotomic cosets of fields are useful in combinatorial design @@ -314,26 +321,26 @@ def cyclotomic_cosets(self, q, cosets=None): :mod:`~sage.combinat.designs.difference_family`). This is illustrated on the following examples:: - sage: K = GF(5) - sage: a = K.multiplicative_generator() - sage: H = K.cyclotomic_cosets(a**2, cosets=[1,2]); H + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings + sage: H = K.cyclotomic_cosets(a**2, cosets=[1, 2]); H # optional - sage.rings.finite_rings [[1, 4], [2, 3]] - sage: sorted(x-y for D in H for x in D for y in D if x != y) + sage: sorted(x - y for D in H for x in D for y in D if x != y) # optional - sage.rings.finite_rings [1, 2, 3, 4] - sage: K = GF(37) - sage: a = K.multiplicative_generator() - sage: H = K.cyclotomic_cosets(a**4, cosets=[1]); H + sage: K = GF(37) # optional - sage.rings.finite_rings + sage: a = K.multiplicative_generator() # optional - sage.rings.finite_rings + sage: H = K.cyclotomic_cosets(a**4, cosets=[1]); H # optional - sage.rings.finite_rings [[1, 7, 9, 10, 12, 16, 26, 33, 34]] - sage: sorted(x-y for D in H for x in D for y in D if x != y) + sage: sorted(x - y for D in H for x in D for y in D if x != y) # optional - sage.rings.finite_rings [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ..., 33, 34, 34, 35, 35, 36, 36] The method ``cyclotomic_cosets`` works on any finite commutative ring:: - sage: R = cartesian_product([GF(7), Zmod(14)]) - sage: a = R((3,5)) - sage: R.cyclotomic_cosets((3,5), [(1,1)]) + sage: R = cartesian_product([GF(7), Zmod(14)]) # optional - sage.rings.finite_rings + sage: a = R((3,5)) # optional - sage.rings.finite_rings + sage: R.cyclotomic_cosets((3,5), [(1,1)]) # optional - sage.rings.finite_rings [[(1, 1), (2, 11), (3, 5), (4, 9), (5, 3), (6, 13)]] """ q = self(q) @@ -373,7 +380,8 @@ def extra_super_categories(self): sage: CommutativeRings().Commutative().CartesianProducts().extra_super_categories() [Category of commutative rings] - sage: cartesian_product([ZZ, Zmod(34), QQ, GF(5)]) in CommutativeRings() + sage: cartesian_product([ZZ, Zmod(34), # optional - sage.rings.finite_rings + ....: QQ, GF(5)]) in CommutativeRings() True """ return [CommutativeRings()] diff --git a/src/sage/categories/complete_discrete_valuation.py b/src/sage/categories/complete_discrete_valuation.py index e7bc01ddd28..71c7ec57015 100644 --- a/src/sage/categories/complete_discrete_valuation.py +++ b/src/sage/categories/complete_discrete_valuation.py @@ -22,13 +22,13 @@ class CompleteDiscreteValuationRings(Category_singleton): EXAMPLES:: - sage: Zp(7) in CompleteDiscreteValuationRings() + sage: Zp(7) in CompleteDiscreteValuationRings() # optional - sage.rings.padics True sage: QQ in CompleteDiscreteValuationRings() False sage: QQ[['u']] in CompleteDiscreteValuationRings() True - sage: Qp(7) in CompleteDiscreteValuationRings() + sage: Qp(7) in CompleteDiscreteValuationRings() # optional - sage.rings.padics False sage: TestSuite(CompleteDiscreteValuationRings()).run() """ @@ -49,10 +49,10 @@ def valuation(self): EXAMPLES:: - sage: R = Zp(7) - sage: x = R(7); x + sage: R = Zp(7) # optional - sage.rings.padics + sage: x = R(7); x # optional - sage.rings.padics 7 + O(7^21) - sage: x.valuation() + sage: x.valuation() # optional - sage.rings.padics 1 """ @@ -63,32 +63,32 @@ def denominator(self): EXAMPLES:: - sage: K = Qp(7) - sage: x = K(1/21) - sage: x.denominator() + sage: K = Qp(7) # optional - sage.rings.padics + sage: x = K(1/21) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 7 + O(7^21) - sage: x = K(7) - sage: x.denominator() + sage: x = K(7) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) Note that the denominator lives in the ring of integers:: - sage: x.denominator().parent() + sage: x.denominator().parent() # optional - sage.rings.padics 7-adic Ring with capped relative precision 20 When the denominator is indistinguishable from 0 and the precision on the input is `O(p^n)`, the return value is `1` if `n` is nonnegative and `p^(-n)` otherwise:: - sage: x = K(0,5); x + sage: x = K(0, 5); x # optional - sage.rings.padics O(7^5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^25) """ return self.parent()(1) @@ -101,26 +101,26 @@ def numerator(self): EXAMPLES:: - sage: K = Qp(7, 5) - sage: x = K(1/21) - sage: x.numerator() + sage: K = Qp(7, 5) # optional - sage.rings.padics + sage: x = K(1/21) # optional - sage.rings.padics + sage: x.numerator() # optional - sage.rings.padics 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + O(7^5) - sage: x == x.numerator() / x.denominator() + sage: x == x.numerator() / x.denominator() # optional - sage.rings.padics True Note that the numerator lives in the ring of integers:: - sage: x.numerator().parent() + sage: x.numerator().parent() # optional - sage.rings.padics 7-adic Ring with capped relative precision 5 TESTS:: - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.numerator() + sage: x.numerator() # optional - sage.rings.padics O(7^0) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^10) """ return self @@ -146,21 +146,22 @@ def lift_to_precision(self, absprec=None): EXAMPLES:: - sage: R = ZpCA(17) - sage: R(-1,2).lift_to_precision(10) + sage: R = ZpCA(17) # optional - sage.rings.padics + sage: R(-1, 2).lift_to_precision(10) # optional - sage.rings.padics 16 + 16*17 + O(17^10) - sage: R(1,15).lift_to_precision(10) + sage: R(1, 15).lift_to_precision(10) # optional - sage.rings.padics 1 + O(17^15) - sage: R(1,15).lift_to_precision(30) + sage: R(1, 15).lift_to_precision(30) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: precision higher than allowed by the precision cap - sage: R(-1,2).lift_to_precision().precision_absolute() == R.precision_cap() + sage: (R(-1, 2).lift_to_precision().precision_absolute() # optional - sage.rings.padics + ....: == R.precision_cap()) True - sage: R = Zp(5); c = R(17,3); c.lift_to_precision(8) + sage: R = Zp(5); c = R(17, 3); c.lift_to_precision(8) # optional - sage.rings.padics 2 + 3*5 + O(5^8) - sage: c.lift_to_precision().precision_relative() == R.precision_cap() + sage: c.lift_to_precision().precision_relative() == R.precision_cap() # optional - sage.rings.padics True """ @@ -171,13 +172,13 @@ class CompleteDiscreteValuationFields(Category_singleton): EXAMPLES:: - sage: Zp(7) in CompleteDiscreteValuationFields() + sage: Zp(7) in CompleteDiscreteValuationFields() # optional - sage.rings.padics False sage: QQ in CompleteDiscreteValuationFields() False - sage: LaurentSeriesRing(QQ,'u') in CompleteDiscreteValuationFields() + sage: LaurentSeriesRing(QQ, 'u') in CompleteDiscreteValuationFields() True - sage: Qp(7) in CompleteDiscreteValuationFields() + sage: Qp(7) in CompleteDiscreteValuationFields() # optional - sage.rings.padics True sage: TestSuite(CompleteDiscreteValuationFields()).run() """ @@ -199,10 +200,10 @@ def valuation(self): EXAMPLES:: - sage: K = Qp(7) - sage: x = K(7); x + sage: K = Qp(7) # optional - sage.rings.padics + sage: x = K(7); x # optional - sage.rings.padics 7 + O(7^21) - sage: x.valuation() + sage: x.valuation() # optional - sage.rings.padics 1 """ @@ -213,32 +214,32 @@ def denominator(self): EXAMPLES:: - sage: K = Qp(7) - sage: x = K(1/21) - sage: x.denominator() + sage: K = Qp(7) # optional - sage.rings.padics + sage: x = K(1/21) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 7 + O(7^21) - sage: x = K(7) - sage: x.denominator() + sage: x = K(7) # optional - sage.rings.padics + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) Note that the denominator lives in the ring of integers:: - sage: x.denominator().parent() + sage: x.denominator().parent() # optional - sage.rings.padics 7-adic Ring with capped relative precision 20 When the denominator is indistinguishable from 0 and the precision on the input is `O(p^n)`, the return value is `1` if `n` is nonnegative and `p^(-n)` otherwise:: - sage: x = K(0,5); x + sage: x = K(0, 5); x # optional - sage.rings.padics O(7^5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 1 + O(7^20) - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^25) """ val = self.valuation() @@ -256,26 +257,26 @@ def numerator(self): EXAMPLES:: - sage: K = Qp(7, 5) - sage: x = K(1/21) - sage: x.numerator() + sage: K = Qp(7, 5) # optional - sage.rings.padics + sage: x = K(1/21) # optional - sage.rings.padics + sage: x.numerator() # optional - sage.rings.padics 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + O(7^5) - sage: x == x.numerator() / x.denominator() + sage: x == x.numerator() / x.denominator() # optional - sage.rings.padics True Note that the numerator lives in the ring of integers:: - sage: x.numerator().parent() + sage: x.numerator().parent() # optional - sage.rings.padics 7-adic Ring with capped relative precision 5 TESTS:: - sage: x = K(0,-5); x + sage: x = K(0, -5); x # optional - sage.rings.padics O(7^-5) - sage: x.numerator() + sage: x.numerator() # optional - sage.rings.padics O(7^0) - sage: x.denominator() + sage: x.denominator() # optional - sage.rings.padics 7^5 + O(7^10) """ R = self.parent().integer_ring() diff --git a/src/sage/categories/complex_reflection_groups.py b/src/sage/categories/complex_reflection_groups.py index 5b23c448a96..e55b16eb6a0 100644 --- a/src/sage/categories/complex_reflection_groups.py +++ b/src/sage/categories/complex_reflection_groups.py @@ -64,18 +64,18 @@ class ComplexReflectionGroups(Category_singleton): An example of a reflection group:: - sage: W = ComplexReflectionGroups().example(); W + sage: W = ComplexReflectionGroups().example(); W # optional - sage.combinat sage.groups 5-colored permutations of size 3 ``W`` is in the category of complex reflection groups:: - sage: W in ComplexReflectionGroups() + sage: W in ComplexReflectionGroups() # optional - sage.combinat sage.groups True TESTS:: - sage: TestSuite(W).run() - sage: TestSuite(ComplexReflectionGroups()).run() + sage: TestSuite(W).run() # optional - sage.combinat sage.groups + sage: TestSuite(ComplexReflectionGroups()).run() # optional - sage.combinat sage.groups """ @cached_method @@ -115,7 +115,7 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().example() + sage: ComplexReflectionGroups().example() # optional - sage.combinat sage.groups 5-colored permutations of size 3 """ from sage.combinat.colored_permutations import ColoredPermutations @@ -133,9 +133,9 @@ def rank(self): EXAMPLES:: - sage: W = CoxeterGroups().example(); W + sage: W = CoxeterGroups().example(); W # optional - sage.groups The symmetric group on {0, ..., 3} - sage: W.rank() + sage: W.rank() # optional - sage.groups 3 """ diff --git a/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py b/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py index b75cbcb3e5d..3bbe54cefc0 100644 --- a/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py +++ b/src/sage/categories/complex_reflection_or_generalized_coxeter_groups.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.groups r""" Common category for Generalized Coxeter Groups or Complex Reflection Groups """ diff --git a/src/sage/categories/covariant_functorial_construction.py b/src/sage/categories/covariant_functorial_construction.py index ad402bfe09d..90a1c42b1cc 100644 --- a/src/sage/categories/covariant_functorial_construction.py +++ b/src/sage/categories/covariant_functorial_construction.py @@ -134,9 +134,10 @@ def category_from_parents(self, parents): EXAMPLES:: - sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]) - sage: tensor.category_from_parents((E, E, E)) - Category of tensor products of finite dimensional vector spaces with basis over Rational Field + sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]) # optional - sage.modules + sage: tensor.category_from_parents((E, E, E)) # optional - sage.modules + Category of tensor products of + finite dimensional vector spaces with basis over Rational Field """ from sage.structure.parent import Parent assert all(isinstance(parent, Parent) for parent in parents) @@ -213,8 +214,8 @@ def __call__(self, args, **kwargs): EXAMPLES:: - sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]); E.rename("E") - sage: tensor((E, E, E)) + sage: E = CombinatorialFreeModule(QQ, ["a", "b", "c"]); E.rename("E") # optional - sage.modules + sage: tensor((E, E, E)) # optional - sage.modules E # E # E """ args = tuple(args) # a bit brute force; let's see if this becomes a bottleneck later @@ -399,10 +400,12 @@ def category_of(cls, category, *args): EXAMPLES:: - sage: sage.categories.tensor.TensorProductsCategory.category_of(ModulesWithBasis(QQ)) + sage: C = sage.categories.tensor.TensorProductsCategory + sage: C.category_of(ModulesWithBasis(QQ)) Category of tensor products of vector spaces with basis over Rational Field - sage: sage.categories.algebra_functor.AlgebrasCategory.category_of(FiniteMonoids(), QQ) + sage: C = sage.categories.algebra_functor.AlgebrasCategory + sage: C.category_of(FiniteMonoids(), QQ) Join of Category of finite dimensional algebras with basis over Rational Field and Category of monoid algebras over Rational Field and Category of finite set algebras over Rational Field @@ -540,7 +543,8 @@ def default_super_categories(cls, category, *args): Bialgebras are both algebras and coalgebras:: sage: Bialgebras(QQ).super_categories() - [Category of algebras over Rational Field, Category of coalgebras over Rational Field] + [Category of algebras over Rational Field, + Category of coalgebras over Rational Field] Hence tensor products of bialgebras are tensor products of algebras and tensor products of coalgebras:: @@ -551,8 +555,10 @@ def default_super_categories(cls, category, *args): Here is how :meth:`default_super_categories` was called internally:: - sage: sage.categories.tensor.TensorProductsCategory.default_super_categories(Bialgebras(QQ)) - Join of Category of tensor products of algebras over Rational Field and Category of tensor products of coalgebras over Rational Field + sage: C = sage.categories.tensor.TensorProductsCategory + sage: C.default_super_categories(Bialgebras(QQ)) + Join of Category of tensor products of algebras over Rational Field + and Category of tensor products of coalgebras over Rational Field We now show a similar example, with the ``Algebra`` functor which takes a parameter `\QQ`:: @@ -570,7 +576,8 @@ def default_super_categories(cls, category, *args): Here is how :meth:`default_super_categories` was called internally:: - sage: sage.categories.algebra_functor.AlgebrasCategory.default_super_categories(FiniteMonoids(), QQ) + sage: C = sage.categories.algebra_functor.AlgebrasCategory + sage: C.default_super_categories(FiniteMonoids(), QQ) Join of Category of finite dimensional algebras with basis over Rational Field and Category of monoid algebras over Rational Field and Category of finite set algebras over Rational Field @@ -609,7 +616,8 @@ def is_construction_defined_by_base(self): sage: Bialgebras(QQ).Graded().is_construction_defined_by_base() Traceback (most recent call last): ... - AttributeError: 'JoinCategory_with_category' object has no attribute 'is_construction_defined_by_base' + AttributeError: 'JoinCategory_with_category' object has + no attribute 'is_construction_defined_by_base' """ base = self.base_category() f = self._functor_category diff --git a/src/sage/categories/coxeter_group_algebras.py b/src/sage/categories/coxeter_group_algebras.py index c8a3d935f05..623b1078e60 100644 --- a/src/sage/categories/coxeter_group_algebras.py +++ b/src/sage/categories/coxeter_group_algebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat, sage.groups r""" Coxeter Group Algebras """ diff --git a/src/sage/categories/coxeter_groups.py b/src/sage/categories/coxeter_groups.py index 98fe35a0ab3..6be88fffae2 100644 --- a/src/sage/categories/coxeter_groups.py +++ b/src/sage/categories/coxeter_groups.py @@ -53,21 +53,21 @@ class CoxeterGroups(Category_singleton): Here are some further examples:: - sage: FiniteCoxeterGroups().example() + sage: FiniteCoxeterGroups().example() # optional - sage.combinat sage.groups The 5-th dihedral group of order 10 - sage: FiniteWeylGroups().example() + sage: FiniteWeylGroups().example() # optional - sage.combinat sage.groups The symmetric group on {0, ..., 3} - sage: WeylGroup(["B", 3]) + sage: WeylGroup(["B", 3]) # optional - sage.combinat sage.groups Weyl Group of type ['B', 3] (as a matrix group acting on the ambient space) - sage: S4 = SymmetricGroup(4); S4 + sage: S4 = SymmetricGroup(4); S4 # optional - sage.groups Symmetric group of order 4! as a permutation group - sage: S4 in CoxeterGroups().Finite() + sage: S4 in CoxeterGroups().Finite() # optional - sage.groups True Those will eventually be also in this category:: - sage: DihedralGroup(5) + sage: DihedralGroup(5) # optional - sage.groups Dihedral group of order 10 as a permutation group .. TODO:: add a demo of usual computations on Coxeter groups. @@ -97,7 +97,7 @@ class CoxeterGroups(Category_singleton): TESTS:: sage: W = CoxeterGroups().example() - sage: TestSuite(W).run() + sage: TestSuite(W).run() # optional - sage.combinat """ def super_categories(self): @@ -136,8 +136,8 @@ def coxeter_matrix(self): EXAMPLES:: - sage: G = WeylGroup(['A',3]) - sage: G.coxeter_matrix() + sage: G = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: G.coxeter_matrix() # optional - sage.combinat sage.groups [1 3 2] [3 1 3] [2 3 1] @@ -150,14 +150,14 @@ def index_set(self): EXAMPLES:: - sage: W = CoxeterGroup([[1,3],[3,1]]) - sage: W.index_set() + sage: W = CoxeterGroup([[1,3],[3,1]]) # optional - sage.combinat sage.groups + sage: W.index_set() # optional - sage.combinat sage.groups (1, 2) - sage: W = CoxeterGroup([[1,3],[3,1]], index_set=['x', 'y']) - sage: W.index_set() + sage: W = CoxeterGroup([[1,3],[3,1]], index_set=['x', 'y']) # optional - sage.combinat sage.groups + sage: W.index_set() # optional - sage.combinat sage.groups ('x', 'y') - sage: W = CoxeterGroup(['H',3]) - sage: W.index_set() + sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups + sage: W.index_set() # optional - sage.combinat sage.groups (1, 2, 3) """ return self.coxeter_matrix().index_set() @@ -168,18 +168,18 @@ def coxeter_diagram(self): EXAMPLES:: - sage: W = CoxeterGroup(['H',3], implementation="reflection") - sage: G = W.coxeter_diagram(); G + sage: W = CoxeterGroup(['H', 3], implementation="reflection") # optional - sage.combinat sage.groups + sage: G = W.coxeter_diagram(); G # optional - sage.combinat sage.groups sage.graphs Graph on 3 vertices - sage: G.edges(sort=True) + sage: G.edges(sort=True) # optional - sage.combinat sage.groups sage.graphs [(1, 2, 3), (2, 3, 5)] - sage: CoxeterGroup(G) is W + sage: CoxeterGroup(G) is W # optional - sage.combinat sage.groups sage.graphs True - sage: G = Graph([(0, 1, 3), (1, 2, oo)]) - sage: W = CoxeterGroup(G) - sage: W.coxeter_diagram() == G + sage: G = Graph([(0, 1, 3), (1, 2, oo)]) # optional - sage.combinat sage.groups sage.graphs + sage: W = CoxeterGroup(G) # optional - sage.combinat sage.groups sage.graphs + sage: W.coxeter_diagram() == G # optional - sage.combinat sage.groups sage.graphs True - sage: CoxeterGroup(W.coxeter_diagram()) is W + sage: CoxeterGroup(W.coxeter_diagram()) is W # optional - sage.combinat sage.groups sage.graphs True """ return self.coxeter_matrix().coxeter_graph() @@ -190,8 +190,8 @@ def coxeter_type(self): EXAMPLES:: - sage: W = CoxeterGroup(['H',3]) - sage: W.coxeter_type() + sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups + sage: W.coxeter_type() # optional - sage.combinat sage.groups Coxeter type of ['H', 3] """ return self.coxeter_matrix().coxeter_type() @@ -203,12 +203,12 @@ def braid_relations(self): EXAMPLES:: - sage: W = WeylGroup(["A",2]) - sage: W.braid_relations() + sage: W = WeylGroup(["A", 2]) # optional - sage.combinat sage.groups + sage: W.braid_relations() # optional - sage.combinat sage.groups [[[1, 2, 1], [2, 1, 2]]] - sage: W = WeylGroup(["B",3]) - sage: W.braid_relations() + sage: W = WeylGroup(["B", 3]) # optional - sage.combinat sage.groups + sage: W.braid_relations() # optional - sage.combinat sage.groups [[[1, 2, 1], [2, 1, 2]], [[1, 3], [3, 1]], [[2, 3, 2, 3], [3, 2, 3, 2]]] """ rels = [] @@ -228,16 +228,16 @@ def braid_group_as_finitely_presented_group(self): EXAMPLES:: - sage: W = CoxeterGroup(['A',2]) - sage: W.braid_group_as_finitely_presented_group() + sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: W.braid_group_as_finitely_presented_group() # optional - sage.combinat sage.groups Finitely presented group < S1, S2 | S1*S2*S1*S2^-1*S1^-1*S2^-1 > - sage: W = WeylGroup(['B',2]) - sage: W.braid_group_as_finitely_presented_group() + sage: W = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups + sage: W.braid_group_as_finitely_presented_group() # optional - sage.combinat sage.groups Finitely presented group < S1, S2 | (S1*S2)^2*(S1^-1*S2^-1)^2 > sage: W = ReflectionGroup(['B',3], index_set=["AA","BB","5"]) # optional - gap3 - sage: W.braid_group_as_finitely_presented_group() # optional - gap3 + sage: W.braid_group_as_finitely_presented_group() # optional - gap3 Finitely presented group < SAA, SBB, S5 | (SAA*SBB)^2*(SAA^-1*SBB^-1)^2, SAA*S5*SAA^-1*S5^-1, SBB*S5*SBB*S5^-1*SBB^-1*S5^-1 > @@ -279,10 +279,10 @@ def braid_orbit(self, word): sage: word = w.reduced_word(); word [0, 1, 2, 1] - sage: sorted(W.braid_orbit(word)) + sage: sorted(W.braid_orbit(word)) # optional - sage.combinat sage.groups [[0, 1, 2, 1], [0, 2, 1, 2], [2, 0, 1, 2]] - sage: sorted(W.braid_orbit([2,1,1,2,1])) + sage: sorted(W.braid_orbit([2,1,1,2,1])) # optional - sage.combinat sage.groups [[1, 2, 1, 1, 2], [2, 1, 1, 2, 1], [2, 1, 2, 1, 2], [2, 2, 1, 2, 2]] sage: W = ReflectionGroup(['A',3], index_set=["AA","BB","5"]) # optional - gap3 @@ -354,17 +354,17 @@ def __iter__(self): (2, 1, 2), (2, 1, 2, 1)] - sage: W = WeylGroup(["A",2,1]) - sage: g = iter(W) - sage: next(g) + sage: W = WeylGroup(["A", 2, 1]) # optional - sage.combinat sage.groups + sage: g = iter(W) # optional - sage.combinat sage.groups + sage: next(g) # optional - sage.combinat sage.groups [1 0 0] [0 1 0] [0 0 1] - sage: next(g) + sage: next(g) # optional - sage.combinat sage.groups [-1 1 1] [ 0 1 0] [ 0 0 1] - sage: next(g) + sage: next(g) # optional - sage.combinat sage.groups [ 1 0 0] [ 1 -1 1] [ 0 0 1] @@ -377,19 +377,19 @@ def _element_constructor_(self, x, **args): EXAMPLES:: - sage: W1 = WeylGroup("G2",prefix="s") - sage: W2 = CoxeterGroup("G2") - sage: W3 = CoxeterGroup("G2", implementation="permutation") - sage: W1(W2.an_element()) + sage: W1 = WeylGroup("G2", prefix="s") # optional - sage.combinat sage.groups + sage: W2 = CoxeterGroup("G2") # optional - sage.combinat sage.groups + sage: W3 = CoxeterGroup("G2", implementation="permutation") # optional - sage.combinat sage.groups + sage: W1(W2.an_element()) # optional - sage.combinat sage.groups s1*s2 - sage: W2(W1.an_element()) + sage: W2(W1.an_element()) # optional - sage.combinat sage.groups [ 2 -a] [ a -1] - sage: W1(W3.an_element()) + sage: W1(W3.an_element()) # optional - sage.combinat sage.groups s1*s2 - sage: s1,s2 = W1.simple_reflections() - sage: W = CoxeterGroup("A1") - sage: W(s1*s2) + sage: s1, s2 = W1.simple_reflections() # optional - sage.combinat sage.groups + sage: W = CoxeterGroup("A1") # optional - sage.combinat sage.groups + sage: W(s1 * s2) # optional - sage.combinat sage.groups Traceback (most recent call last): ... ValueError: inconsistent number of rows: should be 1 but got 3 @@ -419,7 +419,7 @@ def weak_order_ideal(self, predicate, side="right", category=None): EXAMPLES:: sage: D6 = FiniteCoxeterGroups().example(5) - sage: I = D6.weak_order_ideal(predicate = lambda w: w.length() <= 3) + sage: I = D6.weak_order_ideal(predicate=lambda w: w.length() <= 3) sage: I.cardinality() 7 sage: list(I) @@ -511,17 +511,17 @@ def coxeter_element(self): EXAMPLES:: - sage: CoxeterGroup(['A', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['A', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: CoxeterGroup(['B', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['B', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: CoxeterGroup(['D', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['D', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 4, 3] - sage: CoxeterGroup(['F', 4]).coxeter_element().reduced_word() + sage: CoxeterGroup(['F', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: CoxeterGroup(['E', 8]).coxeter_element().reduced_word() + sage: CoxeterGroup(['E', 8]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 3, 2, 4, 5, 6, 7, 8] - sage: CoxeterGroup(['H', 3]).coxeter_element().reduced_word() + sage: CoxeterGroup(['H', 3]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3] This method is also used for well generated finite complex @@ -545,9 +545,9 @@ def coxeter_element(self): TESTS:: - sage: WeylGroup(['A', 4]).coxeter_element().reduced_word() + sage: WeylGroup(['A', 4]).coxeter_element().reduced_word() # optional - sage.combinat sage.groups [1, 2, 3, 4] - sage: SymmetricGroup(3).coxeter_element() + sage: SymmetricGroup(3).coxeter_element() # optional - sage.combinat sage.groups (1,3,2) """ return self.prod(self.simple_reflections()) @@ -575,24 +575,24 @@ class is not unique and we only obtain one such class. TESTS:: - sage: W = SymmetricGroup(3) - sage: sorted(W.standard_coxeter_elements()) + sage: W = SymmetricGroup(3) # optional - sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups [(1,2,3), (1,3,2)] - sage: W = Permutations(3) - sage: sorted(W.standard_coxeter_elements()) + sage: W = Permutations(3) # optional - sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups [[2, 3, 1], [3, 1, 2]] - sage: W = CoxeterGroup(['D',3]) - sage: sorted(W.standard_coxeter_elements()) + sage: W = CoxeterGroup(['D', 3]) # optional - sage.combinat sage.groups + sage: sorted(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups [ [-1 1 1] [ 0 -1 1] [ 0 1 -1] [ 1 -1 -1] [-1 0 1] [ 1 -1 0] [ 0 0 -1] [ 1 -1 0] [-1 1 0], [ 0 -1 0], [ 1 0 -1], [ 1 0 -1] ] - sage: W = ColoredPermutations(3,2) - sage: len(W.standard_coxeter_elements()) + sage: W = ColoredPermutations(3,2) # optional - sage.combinat sage.groups + sage: len(W.standard_coxeter_elements()) # optional - sage.combinat sage.groups 2 """ if not self.is_irreducible() or not self.is_well_generated(): @@ -642,8 +642,9 @@ def fully_commutative_elements(self): EXAMPLES:: - sage: CoxeterGroup(['A', 3]).fully_commutative_elements() - Fully commutative elements of Finite Coxeter group over Integer Ring with Coxeter matrix: + sage: CoxeterGroup(['A', 3]).fully_commutative_elements() # optional - sage.combinat sage.groups + Fully commutative elements of + Finite Coxeter group over Integer Ring with Coxeter matrix: [1 3 2] [3 1 3] [2 3 1] @@ -689,7 +690,7 @@ def simple_projection(self, i, side='right', length_increasing=True): sage: sigma (1, 2, 3, 0) sage: u0 = W.simple_projection(0) - sage: d0 = W.simple_projection(0,length_increasing=False) + sage: d0 = W.simple_projection(0, length_increasing=False) sage: sigma.length() 3 sage: pi=sigma*s[0] @@ -738,9 +739,9 @@ def kazhdan_lusztig_cells(self, side='left'): representation of elements in the output cells but not the method used for the cell computation:: - sage: W = CoxeterGroup('A2') - sage: KL_cells = W.kazhdan_lusztig_cells(side='right') - sage: set([tuple(sorted(C, key=lambda w: w.reduced_word())) + sage: W = CoxeterGroup('A2') # optional - sage.combinat sage.groups + sage: KL_cells = W.kazhdan_lusztig_cells(side='right') # optional - sage.combinat sage.groups + sage: set([tuple(sorted(C, key=lambda w: w.reduced_word())) # optional - sage.combinat sage.groups ....: for C in KL_cells]) {( [-1 1] [ 0 -1] @@ -758,11 +759,11 @@ def kazhdan_lusztig_cells(self, side='left'): [ 1 0] [-1 1] [ 1 -1], [-1 0] )} - sage: len(KL_cells) + sage: len(KL_cells) # optional - sage.combinat sage.groups 4 - sage: W = CoxeterGroup('A2', implementation='permutation') - sage: len(W.kazhdan_lusztig_cells(side='right')) + sage: W = CoxeterGroup('A2', implementation='permutation') # optional - sage.combinat sage.groups + sage: len(W.kazhdan_lusztig_cells(side='right')) # optional - sage.combinat sage.groups 4 We compute the left cells in the Coxeter group of type `A_3` @@ -792,11 +793,12 @@ def kazhdan_lusztig_cells(self, side='left'): Computing the two sided cells in `B_3`:: - sage: W = CoxeterGroup('B3', implementation='coxeter3') # optional - coxeter3 - sage: b3_cells = W.kazhdan_lusztig_cells('two-sided') # optional - coxeter3 - sage: len(b3_cells) # optional - coxeter3 + sage: W = CoxeterGroup('B3', implementation='coxeter3') # optional - coxeter3 + sage: b3_cells = W.kazhdan_lusztig_cells('two-sided') # optional - coxeter3 + sage: len(b3_cells) # optional - coxeter3 6 - sage: set([tuple(sorted(C)) for C in W.kazhdan_lusztig_cells()]) # optional - coxeter3 + sage: set([tuple(sorted(C)) # optional - coxeter3 + ....: for C in W.kazhdan_lusztig_cells()]) {([],), ([1], [1, 2, 3, 2, 1], [2, 1], [2, 3, 2, 1], [3, 2, 1]), ([1, 2], [1, 2, 3, 2], [2], [2, 3, 2], [3, 2]), @@ -825,8 +827,8 @@ def kazhdan_lusztig_cells(self, side='left'): TESTS:: - sage: W = CoxeterGroup(['A', 2, 1]) - sage: W.kazhdan_lusztig_cells() + sage: W = CoxeterGroup(['A', 2, 1]) # optional - sage.combinat sage.groups + sage: W.kazhdan_lusztig_cells() # optional - sage.combinat sage.groups Traceback (most recent call last): ... ValueError: the Coxeter group must be finite to compute Kazhdan--Lusztig cells @@ -887,7 +889,9 @@ def simple_projections(self, side='right', length_increasing=True): sage: sigma = W.an_element(); sigma (1, 2, 3, 0) sage: pi = W.simple_projections(); pi - Finite family {0: at ...>, 1: at ...>, 2: ...>} + Finite family {0: at ...>, + 1: at ...>, + 2: ...>} sage: pi[1](sigma) (1, 3, 2, 0) sage: W.simple_projection(1)(sigma) @@ -907,9 +911,11 @@ def sign_representation(self, base_ring=None, side="twosided"): EXAMPLES:: - sage: W = WeylGroup(["A", 1, 1]) - sage: W.sign_representation() - Sign representation of Weyl Group of type ['A', 1, 1] (as a matrix group acting on the root space) over Integer Ring + sage: W = WeylGroup(["A", 1, 1]) # optional - sage.combinat sage.groups + sage: W.sign_representation() # optional - sage.combinat sage.groups + Sign representation of + Weyl Group of type ['A', 1, 1] (as a matrix group acting on the root space) + over Integer Ring """ if base_ring is None: @@ -933,18 +939,18 @@ def demazure_product(self, Q): EXAMPLES:: - sage: W = WeylGroup(['A',2]) - sage: w = W.demazure_product([2,2,1]) - sage: w.reduced_word() + sage: W = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: w = W.demazure_product([2,2,1]) # optional - sage.combinat sage.groups + sage: w.reduced_word() # optional - sage.combinat sage.groups [2, 1] - sage: w = W.demazure_product([2,1,2,1,2]) - sage: w.reduced_word() + sage: w = W.demazure_product([2,1,2,1,2]) # optional - sage.combinat sage.groups + sage: w.reduced_word() # optional - sage.combinat sage.groups [1, 2, 1] - sage: W = WeylGroup(['B',2]) - sage: w = W.demazure_product([2,1,2,1,2]) - sage: w.reduced_word() + sage: W = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups + sage: w = W.demazure_product([2,1,2,1,2]) # optional - sage.combinat sage.groups + sage: w.reduced_word() # optional - sage.combinat sage.groups [2, 1, 2, 1] """ return self.one().apply_demazure_product(Q) @@ -955,16 +961,16 @@ def bruhat_interval(self, x, y): EXAMPLES:: - sage: W = WeylGroup("A3", prefix="s") - sage: [s1,s2,s3] = W.simple_reflections() - sage: W.bruhat_interval(s2,s1*s3*s2*s1*s3) + sage: W = WeylGroup("A3", prefix="s") # optional - sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups + sage: W.bruhat_interval(s2, s1*s3*s2*s1*s3) # optional - sage.combinat sage.groups [s1*s2*s3*s2*s1, s2*s3*s2*s1, s3*s1*s2*s1, s1*s2*s3*s1, s1*s2*s3*s2, s3*s2*s1, s2*s3*s1, s2*s3*s2, s1*s2*s1, s3*s1*s2, s1*s2*s3, s2*s1, s3*s2, s2*s3, s1*s2, s2] - sage: W = WeylGroup(['A',2,1], prefix="s") - sage: [s0,s1,s2] = W.simple_reflections() - sage: W.bruhat_interval(1,s0*s1*s2) + sage: W = WeylGroup(['A', 2, 1], prefix="s") # optional - sage.combinat sage.groups + sage: s0, s1, s2 = W.simple_reflections() # optional - sage.combinat sage.groups + sage: W.bruhat_interval(1, s0*s1*s2) # optional - sage.combinat sage.groups [s0*s1*s2, s1*s2, s0*s2, s0*s1, s2, s1, s0, 1] """ if x == 1: @@ -994,19 +1000,19 @@ def bruhat_interval_poset(self, x, y, facade=False): EXAMPLES:: - sage: W = WeylGroup("A3", prefix="s") - sage: s1,s2,s3 = W.simple_reflections() - sage: W.bruhat_interval_poset(s2, s1*s3*s2*s1*s3) + sage: W = WeylGroup("A3", prefix="s") # optional - sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups + sage: W.bruhat_interval_poset(s2, s1*s3*s2*s1*s3) # optional - sage.combinat sage.groups Finite poset containing 16 elements - sage: W = WeylGroup(['A',2,1], prefix="s") - sage: s0,s1,s2 = W.simple_reflections() - sage: W.bruhat_interval_poset(1, s0*s1*s2) + sage: W = WeylGroup(['A', 2, 1], prefix="s") # optional - sage.combinat sage.groups + sage: s0, s1, s2 = W.simple_reflections() # optional - sage.combinat sage.groups + sage: W.bruhat_interval_poset(1, s0*s1*s2) # optional - sage.combinat sage.groups Finite poset containing 8 elements TESTS:: - sage: W.bruhat_interval_poset(s0*s1*s2, s0*s1*s2) + sage: W.bruhat_interval_poset(s0*s1*s2, s0*s1*s2) # optional - sage.combinat sage.groups Finite poset containing 1 elements """ if x == 1: @@ -1061,27 +1067,27 @@ def bruhat_graph(self, x=None, y=None, edge_labels=False): EXAMPLES:: - sage: W = CoxeterGroup(['H',3]) - sage: G = W.bruhat_graph(); G + sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups sage.graphs + sage: G = W.bruhat_graph(); G # optional - sage.combinat sage.groups sage.graphs Digraph on 120 vertices - sage: W = CoxeterGroup(['A',2,1]) - sage: s1, s2, s3 = W.simple_reflections() - sage: W.bruhat_graph(s1, s1*s3*s2*s3) + sage: W = CoxeterGroup(['A', 2, 1]) # optional - sage.combinat sage.groups sage.graphs + sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups sage.graphs + sage: W.bruhat_graph(s1, s1*s3*s2*s3) # optional - sage.combinat sage.groups sage.graphs Digraph on 6 vertices - sage: W.bruhat_graph(s1, s3*s2*s3) + sage: W.bruhat_graph(s1, s3*s2*s3) # optional - sage.combinat sage.groups sage.graphs Digraph on 0 vertices - sage: W = WeylGroup("A3", prefix="s") - sage: s1, s2, s3 = W.simple_reflections() - sage: G = W.bruhat_graph(s1*s3, s1*s2*s3*s2*s1); G + sage: W = WeylGroup("A3", prefix="s") # optional - sage.combinat sage.groups sage.graphs + sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups sage.graphs + sage: G = W.bruhat_graph(s1*s3, s1*s2*s3*s2*s1); G # optional - sage.combinat sage.groups sage.graphs Digraph on 10 vertices Check that the graph has the correct number of edges (see :trac:`17744`):: - sage: len(G.edges(sort=False)) + sage: len(G.edges(sort=False)) # optional - sage.combinat sage.groups sage.graphs 16 """ if x is None or x == 1: @@ -1129,8 +1135,8 @@ def canonical_representation(self): EXAMPLES:: - sage: W = WeylGroup("A3") - sage: W.canonical_representation() + sage: W = WeylGroup("A3") # optional - sage.combinat sage.groups + sage: W.canonical_representation() # optional - sage.combinat sage.groups Finite Coxeter group over Integer Ring with Coxeter matrix: [1 3 2] [3 1 3] @@ -1146,16 +1152,16 @@ def elements_of_length(self, n): EXAMPLES:: - sage: A = AffinePermutationGroup(['A',2,1]) - sage: [len(list(A.elements_of_length(i))) for i in [0..5]] + sage: A = AffinePermutationGroup(['A', 2, 1]) # optional - sage.combinat sage.groups + sage: [len(list(A.elements_of_length(i))) for i in [0..5]] # optional - sage.combinat sage.groups [1, 3, 6, 9, 12, 15] - sage: W = CoxeterGroup(['H',3]) - sage: [len(list(W.elements_of_length(i))) for i in range(4)] + sage: W = CoxeterGroup(['H', 3]) # optional - sage.combinat sage.groups + sage: [len(list(W.elements_of_length(i))) for i in range(4)] # optional - sage.combinat sage.groups [1, 3, 5, 7] - sage: W = CoxeterGroup(['A',2]) - sage: [len(list(W.elements_of_length(i))) for i in range(6)] + sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: [len(list(W.elements_of_length(i))) for i in range(6)] # optional - sage.combinat sage.groups [1, 2, 2, 1, 0, 0] """ I = self.weak_order_ideal(ConstantFunction(True), side='right') @@ -1173,18 +1179,18 @@ def random_element_of_length(self, n): EXAMPLES:: - sage: A = AffinePermutationGroup(['A', 7, 1]) - sage: p = A.random_element_of_length(10) - sage: p in A + sage: A = AffinePermutationGroup(['A', 7, 1]) # optional - sage.combinat sage.groups + sage: p = A.random_element_of_length(10) # optional - sage.combinat sage.groups + sage: p in A # optional - sage.combinat sage.groups True - sage: p.length() == 10 + sage: p.length() == 10 # optional - sage.combinat sage.groups True - sage: W = CoxeterGroup(['A', 4]) - sage: p = W.random_element_of_length(5) - sage: p in W + sage: W = CoxeterGroup(['A', 4]) # optional - sage.combinat sage.groups + sage: p = W.random_element_of_length(5) # optional - sage.combinat sage.groups + sage: p in W # optional - sage.combinat sage.groups True - sage: p.length() == 5 + sage: p.length() == 5 # optional - sage.combinat sage.groups True """ from sage.misc.prandom import randint @@ -1236,14 +1242,14 @@ def _test_has_descent(self, **options): sage: W = CoxeterGroups().example() sage: W._test_has_descent() - sage: W = Permutations(4) - sage: W._test_has_descent() - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" - sage: W._test_has_descent() - sage: sage.combinat.permutation.Permutations.options._reset() + sage: W = Permutations(4) # optional - sage.combinat sage.groups + sage: W._test_has_descent() # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups + sage: W._test_has_descent() # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups - sage: W = SignedPermutations(3) - sage: W._test_has_descent() + sage: W = SignedPermutations(3) # optional - sage.combinat sage.groups + sage: W._test_has_descent() # optional - sage.combinat sage.groups """ tester = self._tester(**options) s = self.simple_reflections() @@ -1300,21 +1306,21 @@ def _test_coxeter_relations(self, **options): TESTS:: - sage: A = AffinePermutationGroup(['A',7,1]) - sage: A._test_coxeter_relations() + sage: A = AffinePermutationGroup(['A', 7, 1]) # optional - sage.combinat sage.groups + sage: A._test_coxeter_relations() # optional - sage.combinat sage.groups - sage: cm = CartanMatrix([[2,-5,0],[-2,2,-1],[0,-1,2]]) - sage: W = WeylGroup(cm) - sage: W._test_coxeter_relations() + sage: cm = CartanMatrix([[2,-5,0], [-2,2,-1], [0,-1,2]]) # optional - sage.combinat sage.groups + sage: W = WeylGroup(cm) # optional - sage.combinat sage.groups + sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups - sage: W = Permutations(4) - sage: W._test_coxeter_relations() - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" - sage: W._test_coxeter_relations() - sage: sage.combinat.permutation.Permutations.options._reset() + sage: W = Permutations(4) # optional - sage.combinat sage.groups + sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups + sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups + sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups - sage: W = SignedPermutations(3) - sage: W._test_coxeter_relations() + sage: W = SignedPermutations(3) # optional - sage.combinat sage.groups + sage: W._test_coxeter_relations() # optional - sage.combinat sage.groups """ tester = self._tester(**options) s = self.simple_reflections() @@ -1347,7 +1353,7 @@ def has_descent(self, i, side='right', positive=False): sage: w = s[0] * s[1] * s[2] sage: w.has_descent(2) True - sage: [ w.has_descent(i) for i in [0,1,2] ] + sage: [ w.has_descent(i) for i in [0,1,2] ] [False, False, True] sage: [ w.has_descent(i, side='left') for i in [0,1,2] ] [True, False, False] @@ -1600,17 +1606,18 @@ def reduced_words(self): sage: W = CoxeterGroups().example() sage: s = W.simple_reflections() sage: w = s[0] * s[2] - sage: sorted(w.reduced_words()) + sage: sorted(w.reduced_words()) # optional - sage.combinat [[0, 2], [2, 0]] - sage: W = WeylGroup(['E',6]) - sage: w = W.from_reduced_word([2,3,4,2]) - sage: sorted(w.reduced_words()) + sage: W = WeylGroup(['E', 6]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([2,3,4,2]) # optional - sage.combinat sage.groups + sage: sorted(w.reduced_words()) # optional - sage.combinat sage.groups [[2, 3, 4, 2], [3, 2, 4, 2], [3, 4, 2, 4]] - sage: W = ReflectionGroup(['A',3], index_set=["AA","BB","5"]) # optional - gap3 - sage: w = W.long_element() # optional - gap3 - sage: w.reduced_words() # optional - gap3 + sage: W = ReflectionGroup(['A',3], # optional - gap3 + ....: index_set=["AA","BB","5"]) + sage: w = W.long_element() # optional - gap3 + sage: w.reduced_words() # optional - gap3 [['BB', '5', 'AA', 'BB', '5', 'AA'], ['5', 'BB', '5', 'AA', 'BB', '5'], ['BB', 'AA', 'BB', '5', 'BB', 'AA'], @@ -1693,32 +1700,32 @@ def reduced_word_graph(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix='s') - sage: w0 = W.long_element() - sage: G = w0.reduced_word_graph() - sage: G.num_verts() + sage: W = WeylGroup(['A', 3], prefix='s') # optional - sage.combinat sage.groups + sage: w0 = W.long_element() # optional - sage.combinat sage.groups + sage: G = w0.reduced_word_graph() # optional - sage.combinat sage.groups sage.graphs + sage: G.num_verts() # optional - sage.combinat sage.groups sage.graphs 16 - sage: len(w0.reduced_words()) + sage: len(w0.reduced_words()) # optional - sage.combinat sage.groups sage.graphs 16 - sage: G.num_edges() + sage: G.num_edges() # optional - sage.combinat sage.groups sage.graphs 18 - sage: len([e for e in G.edges(sort=False) if e[2] == 2]) + sage: len([e for e in G.edges(sort=False) if e[2] == 2]) # optional - sage.combinat sage.groups sage.graphs 10 - sage: len([e for e in G.edges(sort=False) if e[2] == 3]) + sage: len([e for e in G.edges(sort=False) if e[2] == 3]) # optional - sage.combinat sage.groups sage.graphs 8 TESTS:: - sage: p = Permutation([3,2,4,1]) - sage: pp = WeylGroup(['A',3]).from_reduced_word(p.reduced_word()) - sage: pp.reduced_word_graph() + sage: p = Permutation([3,2,4,1]) # optional - sage.combinat + sage: pp = WeylGroup(['A',3]).from_reduced_word(p.reduced_word()) # optional - sage.combinat sage.groups + sage: pp.reduced_word_graph() # optional - sage.combinat sage.groups sage.graphs Graph on 3 vertices - sage: w1 = W.one() - sage: G = w1.reduced_word_graph() - sage: G.num_verts() + sage: w1 = W.one() # optional - sage.combinat sage.groups + sage: G = w1.reduced_word_graph() # optional - sage.combinat sage.groups sage.graphs + sage: G.num_verts() # optional - sage.combinat sage.groups sage.graphs 1 - sage: G.num_edges() + sage: G.num_edges() # optional - sage.combinat sage.groups sage.graphs 0 .. SEEALSO:: @@ -1814,14 +1821,14 @@ def reflection_length(self): EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: s = W.simple_reflections() - sage: (s[1]*s[2]*s[3]).reflection_length() + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: (s[1]*s[2]*s[3]).reflection_length() # optional - sage.combinat sage.groups 3 - sage: W = SymmetricGroup(4) - sage: s = W.simple_reflections() - sage: (s[3]*s[2]*s[3]).reflection_length() + sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: (s[3]*s[2]*s[3]).reflection_length() # optional - sage.combinat sage.groups 1 """ @@ -1844,14 +1851,14 @@ def absolute_length(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) - sage: s = W.simple_reflections() - sage: (s[1]*s[2]*s[3]).absolute_length() + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: (s[1]*s[2]*s[3]).absolute_length() # optional - sage.combinat sage.groups 3 - sage: W = SymmetricGroup(4) - sage: s = W.simple_reflections() - sage: (s[3]*s[2]*s[1]).absolute_length() + sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: (s[3]*s[2]*s[1]).absolute_length() # optional - sage.combinat sage.groups 3 """ M = self.canonical_matrix() @@ -1876,40 +1883,40 @@ def absolute_le(self, other): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) - sage: s = W.simple_reflections() - sage: w0 = s[1] - sage: w1 = s[1]*s[2]*s[3] - sage: w0.absolute_le(w1) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: w0 = s[1] # optional - sage.combinat sage.groups + sage: w1 = s[1]*s[2]*s[3] # optional - sage.combinat sage.groups + sage: w0.absolute_le(w1) # optional - sage.combinat sage.groups True - sage: w1.absolute_le(w0) + sage: w1.absolute_le(w0) # optional - sage.combinat sage.groups False - sage: w1.absolute_le(w1) + sage: w1.absolute_le(w1) # optional - sage.combinat sage.groups True TESTS: Check that this is independent of the implementation of the group, see :trac:`34799`:: - sage: W1 = WeylGroup(['A',2]) - sage: W2 = Permutations(3) + sage: W1 = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: W2 = Permutations(3) # optional - sage.combinat sage.groups sage: P = lambda pi: W2(list(pi.to_permutation())) - sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 if w1.absolute_le(w2)) - sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d2 + sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 if w1.absolute_le(w2)) # optional - sage.combinat sage.groups + sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) # optional - sage.combinat sage.groups + sage: d1 == d2 # optional - sage.combinat sage.groups True - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" - sage: d3 = set((w1, w2) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d3 + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups + sage: d3 = set((w1, w2) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) # optional - sage.combinat sage.groups + sage: d1 == d3 # optional - sage.combinat sage.groups True - sage: sage.combinat.permutation.Permutations.options._reset() - - sage: W1 = WeylGroup(['B',2]) - sage: W2 = SignedPermutations(2) - sage: P = lambda pi: W2(list(pi.to_permutation())) - sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 if w1.absolute_le(w2)) - sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) - sage: d1 == d2 + sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups + + sage: W1 = WeylGroup(['B', 2]) # optional - sage.combinat sage.groups + sage: W2 = SignedPermutations(2) # optional - sage.combinat sage.groups + sage: P = lambda pi: W2(list(pi.to_permutation())) # optional - sage.combinat sage.groups + sage: d1 = set((P(w1), P(w2)) for w1 in W1 for w2 in W1 if w1.absolute_le(w2)) # optional - sage.combinat sage.groups + sage: d2 = set((w1, w2) for w1 in W2 for w2 in W2 if w1.absolute_le(w2)) # optional - sage.combinat sage.groups + sage: d1 == d2 # optional - sage.combinat sage.groups True """ if self == other: @@ -1928,11 +1935,11 @@ def absolute_covers(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) - sage: s = W.simple_reflections() - sage: w0 = s[1] - sage: w1 = s[1]*s[2]*s[3] - sage: w0.absolute_covers() + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: w0 = s[1] # optional - sage.combinat sage.groups + sage: w1 = s[1]*s[2]*s[3] # optional - sage.combinat sage.groups + sage: w0.absolute_covers() # optional - sage.combinat sage.groups [ [0 0 1 0] [0 1 0 0] [0 1 0 0] [0 0 0 1] [0 1 0 0] [1 0 0 0] [1 0 0 0] [0 0 1 0] [1 0 0 0] [0 0 0 1] @@ -1956,9 +1963,9 @@ def canonical_matrix(self): EXAMPLES:: - sage: W = WeylGroup(["A", 3]) - sage: s = W.simple_reflections() - sage: (s[1]*s[2]*s[3]).canonical_matrix() + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: (s[1]*s[2]*s[3]).canonical_matrix() # optional - sage.combinat sage.groups [ 0 0 -1] [ 1 0 -1] [ 0 1 -1] @@ -1988,11 +1995,11 @@ def coset_representative(self, index_set, side='right'): [2, 3] sage: w.coset_representative([1,2]).reduced_word() [2, 3] - sage: w.coset_representative([1,3] ).reduced_word() + sage: w.coset_representative([1,3] ).reduced_word() [2] - sage: w.coset_representative([2,3] ).reduced_word() + sage: w.coset_representative([2,3] ).reduced_word() [2, 1] - sage: w.coset_representative([1,2,3] ).reduced_word() + sage: w.coset_representative([1,2,3] ).reduced_word() [] sage: w.coset_representative([], side='left').reduced_word() [2, 3, 1] @@ -2039,15 +2046,15 @@ def apply_simple_projection(self, i, side='right', length_increasing=True): (1, 2, 3, 0) sage: w.apply_simple_projection(2, length_increasing=False) (1, 2, 0, 3) - sage: W = WeylGroup(['C',4],prefix="s") - sage: v = W.from_reduced_word([1,2,3,4,3,1]) - sage: v + sage: W = WeylGroup(['C', 4], prefix="s") # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([1,2,3,4,3,1]) # optional - sage.combinat sage.groups + sage: v # optional - sage.combinat sage.groups s1*s2*s3*s4*s3*s1 - sage: v.apply_simple_projection(2) + sage: v.apply_simple_projection(2) # optional - sage.combinat sage.groups s1*s2*s3*s4*s3*s1*s2 - sage: v.apply_simple_projection(2, side='left') + sage: v.apply_simple_projection(2, side='left') # optional - sage.combinat sage.groups s1*s2*s3*s4*s3*s1 - sage: v.apply_simple_projection(1, length_increasing = False) + sage: v.apply_simple_projection(1, length_increasing=False) # optional - sage.combinat sage.groups s1*s2*s3*s4*s3 """ @@ -2075,44 +2082,48 @@ def binary_factorizations(self, predicate=ConstantFunction(True)): We construct the set of all factorizations of the maximal element of the group:: - sage: W = WeylGroup(['A',3]) - sage: s = W.simple_reflections() - sage: w0 = W.from_reduced_word([1,2,3,1,2,1]) - sage: w0.binary_factorizations().cardinality() + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: w0 = W.from_reduced_word([1,2,3,1,2,1]) # optional - sage.combinat sage.groups + sage: w0.binary_factorizations().cardinality() # optional - sage.combinat sage.groups 24 The same number of factorizations, by bounded length:: - sage: [w0.binary_factorizations(lambda u: u.length() <= l).cardinality() for l in [-1,0,1,2,3,4,5,6]] + sage: [w0.binary_factorizations( # optional - sage.combinat sage.groups + ....: lambda u: u.length() <= l + ....: ).cardinality() + ....: for l in [-1,0,1,2,3,4,5,6]] [0, 1, 4, 9, 15, 20, 23, 24] The number of factorizations of the elements just below the maximal element:: - sage: [(s[i]*w0).binary_factorizations().cardinality() for i in [1,2,3]] + sage: [(s[i]*w0).binary_factorizations().cardinality() # optional - sage.combinat sage.groups + ....: for i in [1,2,3]] [12, 12, 12] - sage: w0.binary_factorizations(lambda u: False).cardinality() + sage: w0.binary_factorizations(lambda u: False).cardinality() # optional - sage.combinat sage.groups 0 TESTS:: - sage: w0.binary_factorizations().category() + sage: w0.binary_factorizations().category() # optional - sage.combinat sage.groups Category of finite enumerated sets Check that this is independent of the implementation of the group, see :trac:`34799`:: - sage: W1 = WeylGroup(['A',3]) - sage: W2 = Permutations(4) - sage: P = lambda pi: W2(list(pi.to_permutation())) - sage: d1 = {P(pi): set((P(w[0]), P(w[1])) for w in pi.binary_factorizations()) for pi in W1} - sage: d2 = {pi: set(pi.binary_factorizations()) for pi in W2} - sage: d1 == d2 + sage: W1 = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: W2 = Permutations(4) # optional - sage.combinat sage.groups + sage: P = lambda pi: W2(list(pi.to_permutation())) # optional - sage.combinat sage.groups + sage: d1 = {P(pi): set((P(w[0]), P(w[1])) for w in pi.binary_factorizations()) for pi in W1} # optional - sage.combinat sage.groups + sage: d2 = {pi: set(pi.binary_factorizations()) for pi in W2} # optional - sage.combinat sage.groups + sage: d1 == d2 # optional - sage.combinat sage.groups True - sage: sage.combinat.permutation.Permutations.options.mult = "r2l" - sage: d3 = {pi: set(pi.binary_factorizations()) for pi in W2} - sage: d1 == d3 + sage: sage.combinat.permutation.Permutations.options.mult = "r2l" # optional - sage.combinat sage.groups + sage: d3 = {pi: set(pi.binary_factorizations()) for pi in W2} # optional - sage.combinat sage.groups + sage: d1 == d3 # optional - sage.combinat sage.groups True - sage: sage.combinat.permutation.Permutations.options._reset() + sage: sage.combinat.permutation.Permutations.options._reset() # optional - sage.combinat sage.groups """ from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest W = self.parent() @@ -2142,35 +2153,38 @@ def bruhat_lower_covers(self): EXAMPLES:: - sage: W = WeylGroup(["A",3]) - sage: w = W.from_reduced_word([3,2,3]) - sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,3]) # optional - sage.combinat sage.groups + sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) # optional - sage.combinat sage.groups [[3, 2], [2, 3]] - sage: W = WeylGroup(["A",3]) - sage: print([v.reduced_word() for v in W.simple_reflection(1).bruhat_lower_covers()]) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: print([v.reduced_word() # optional - sage.combinat sage.groups + ....: for v in W.simple_reflection(1).bruhat_lower_covers()]) [[]] - sage: print([v.reduced_word() for v in W.one().bruhat_lower_covers()]) + sage: print([v.reduced_word() # optional - sage.combinat sage.groups + ....: for v in W.one().bruhat_lower_covers()]) [] - sage: W = WeylGroup(["B",4,1]) - sage: w = W.from_reduced_word([0,2]) - sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) + sage: W = WeylGroup(["B", 4, 1]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([0,2]) # optional - sage.combinat sage.groups + sage: print([v.reduced_word() for v in w.bruhat_lower_covers()]) # optional - sage.combinat sage.groups [[2], [0]] - sage: W = WeylGroup("A3",prefix="s",implementation="permutation") - sage: [s1,s2,s3]=W.simple_reflections() - sage: (s1*s2*s3*s1).bruhat_lower_covers() + sage: W = WeylGroup("A3", prefix="s", implementation="permutation") # optional - sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups + sage: (s1*s2*s3*s1).bruhat_lower_covers() # optional - sage.combinat sage.groups [s2*s1*s3, s1*s2*s1, s1*s2*s3] We now show how to construct the Bruhat poset:: - sage: W = WeylGroup(["A",3]) - sage: covers = tuple([u, v] for v in W for u in v.bruhat_lower_covers() ) - sage: P = Poset((W, covers), cover_relations = True) - sage: P.show() + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: covers = tuple([u, v] # optional - sage.combinat sage.groups + ....: for v in W for u in v.bruhat_lower_covers()) + sage: P = Poset((W, covers), cover_relations = True) # optional - sage.combinat sage.groups sage.graphs + sage: P.show() # optional - sage.combinat sage.groups sage.graphs Alternatively, one can just use:: - sage: P = W.bruhat_poset() + sage: P = W.bruhat_poset() # optional - sage.combinat sage.groups sage.graphs The algorithm is taken from Stembridge's 'coxeter/weyl' package for Maple. """ @@ -2193,21 +2207,21 @@ def bruhat_upper_covers(self): EXAMPLES:: - sage: W = WeylGroup(['A',3,1], prefix="s") - sage: w = W.from_reduced_word([1,2,1]) - sage: w.bruhat_upper_covers() + sage: W = WeylGroup(['A', 3, 1], prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([1,2,1]) # optional - sage.combinat sage.groups + sage: w.bruhat_upper_covers() # optional - sage.combinat sage.groups [s1*s2*s1*s0, s1*s2*s0*s1, s0*s1*s2*s1, s3*s1*s2*s1, s2*s3*s1*s2, s1*s2*s3*s1] - sage: W = WeylGroup(['A',3]) - sage: w = W.long_element() - sage: w.bruhat_upper_covers() + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: w = W.long_element() # optional - sage.combinat sage.groups + sage: w.bruhat_upper_covers() # optional - sage.combinat sage.groups [] - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([1,2,1]) - sage: S = [v for v in W if w in v.bruhat_lower_covers()] - sage: C = w.bruhat_upper_covers() - sage: set(S) == set(C) + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([1,2,1]) # optional - sage.combinat sage.groups + sage: S = [v for v in W if w in v.bruhat_lower_covers()] # optional - sage.combinat sage.groups + sage: C = w.bruhat_upper_covers() # optional - sage.combinat sage.groups + sage: set(S) == set(C) # optional - sage.combinat sage.groups True """ Covers = set() @@ -2231,17 +2245,17 @@ def bruhat_lower_covers_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.bruhat_lower_covers_reflections() + sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups + sage: w.bruhat_lower_covers_reflections() # optional - sage.combinat sage.groups [(s1*s2*s1, s1*s2*s3*s2*s1), (s3*s2*s1, s2), (s3*s1*s2, s1)] TESTS: Check bug discovered in :trac:`32669` is fixed:: - sage: W = CoxeterGroup(['A',3], implementation='permutation') - sage: W.w0.bruhat_lower_covers_reflections() + sage: W = CoxeterGroup(['A', 3], implementation='permutation') # optional - sage.combinat sage.groups + sage: W.w0.bruhat_lower_covers_reflections() # optional - sage.combinat sage.groups [((1,3,7,9)(2,11,6,10)(4,8,5,12), (2,5)(3,9)(4,6)(8,11)(10,12)), ((1,11)(3,10)(4,9)(5,7)(6,12), (1,4)(2,8)(3,5)(7,10)(9,11)), ((1,9,7,3)(2,10,6,11)(4,12,5,8), (1,7)(2,4)(5,6)(8,10)(11,12))] @@ -2264,11 +2278,11 @@ def lower_cover_reflections(self, side='right'): EXAMPLES:: - sage: W = WeylGroup(['A',3],prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.lower_cover_reflections() + sage: W = WeylGroup(['A', 3],prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups + sage: w.lower_cover_reflections() # optional - sage.combinat sage.groups [s1*s2*s3*s2*s1, s2, s1] - sage: w.lower_cover_reflections(side='left') + sage: w.lower_cover_reflections(side='left') # optional - sage.combinat sage.groups [s2*s3*s2, s3, s1] """ @@ -2287,10 +2301,11 @@ def bruhat_upper_covers_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',4], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.bruhat_upper_covers_reflections() - [(s1*s2*s3*s2*s1, s3), (s2*s3*s1*s2*s1, s2*s3*s2), (s3*s4*s1*s2*s1, s4), (s4*s3*s1*s2*s1, s1*s2*s3*s4*s3*s2*s1)] + sage: W = WeylGroup(['A', 4], prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups + sage: w.bruhat_upper_covers_reflections() # optional - sage.combinat sage.groups + [(s1*s2*s3*s2*s1, s3), (s2*s3*s1*s2*s1, s2*s3*s2), + (s3*s4*s1*s2*s1, s4), (s4*s3*s1*s2*s1, s1*s2*s3*s4*s3*s2*s1)] """ Covers = set() for i in self.parent().index_set(): @@ -2310,11 +2325,11 @@ def cover_reflections(self, side='right'): EXAMPLES:: - sage: W = WeylGroup(['A',4], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.cover_reflections() + sage: W = WeylGroup(['A', 4], prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups + sage: w.cover_reflections() # optional - sage.combinat sage.groups [s3, s2*s3*s2, s4, s1*s2*s3*s4*s3*s2*s1] - sage: w.cover_reflections(side='left') + sage: w.cover_reflections(side='left') # optional - sage.combinat sage.groups [s4, s2, s1*s2*s1, s3*s4*s3] """ @@ -2335,19 +2350,19 @@ def bruhat_le(self, other): EXAMPLES:: - sage: W = WeylGroup(["A",3]) - sage: u = W.from_reduced_word([1,2,1]) - sage: v = W.from_reduced_word([1,2,3,2,1]) - sage: u.bruhat_le(u) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: u = W.from_reduced_word([1,2,1]) # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([1,2,3,2,1]) # optional - sage.combinat sage.groups + sage: u.bruhat_le(u) # optional - sage.combinat sage.groups True - sage: u.bruhat_le(v) + sage: u.bruhat_le(v) # optional - sage.combinat sage.groups True - sage: v.bruhat_le(u) + sage: v.bruhat_le(u) # optional - sage.combinat sage.groups False - sage: v.bruhat_le(v) + sage: v.bruhat_le(v) # optional - sage.combinat sage.groups True - sage: s = W.simple_reflections() - sage: s[1].bruhat_le(W.one()) + sage: s = W.simple_reflections() # optional - sage.combinat sage.groups + sage: s[1].bruhat_le(W.one()) # optional - sage.combinat sage.groups False The implementation uses the equivalent condition that any @@ -2368,19 +2383,19 @@ def bruhat_le(self, other): We now run consistency tests with permutations and :meth:`bruhat_lower_covers`:: - sage: W = WeylGroup(["A",3]) - sage: P4 = Permutations(4) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: P4 = Permutations(4) # optional - sage.combinat sage.groups sage: def P4toW(w): return W.from_reduced_word(w.reduced_word()) - sage: for u in P4: + sage: for u in P4: # optional - sage.combinat sage.groups ....: for v in P4: ....: assert u.bruhat_lequal(v) == P4toW(u).bruhat_le(P4toW(v)) - sage: W = WeylGroup(["B",3]) - sage: P = W.bruhat_poset() # This is built from bruhat_lower_covers - sage: Q = Poset((W, attrcall("bruhat_le"))) # long time (10s) - sage: all( u.bruhat_le(v) == P.is_lequal(u,v) for u in W for v in W ) # long time (7s) + sage: W = WeylGroup(["B", 3]) # optional - sage.combinat sage.groups + sage: P = W.bruhat_poset() # This is built from bruhat_lower_covers # optional - sage.combinat sage.groups sage.graphs + sage: Q = Poset((W, attrcall("bruhat_le"))) # long time (10s) # optional - sage.combinat sage.groups sage.graphs + sage: all(u.bruhat_le(v) == P.is_lequal(u,v) for u in W for v in W) # long time (7s) # optional - sage.combinat sage.groups sage.graphs True - sage: all( P.is_lequal(u,v) == Q.is_lequal(u,v) for u in W for v in W) # long time (9s) + sage: all(P.is_lequal(u,v) == Q.is_lequal(u,v) for u in W for v in W) # long time (9s) # optional - sage.combinat sage.groups sage.graphs True """ if not have_same_parent(self, other): @@ -2409,21 +2424,21 @@ def weak_le(self, other, side='right'): EXAMPLES:: - sage: W = WeylGroup(["A",3]) - sage: u = W.from_reduced_word([1,2]) - sage: v = W.from_reduced_word([1,2,3,2]) - sage: u.weak_le(u) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: u = W.from_reduced_word([1,2]) # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([1,2,3,2]) # optional - sage.combinat sage.groups + sage: u.weak_le(u) # optional - sage.combinat sage.groups True - sage: u.weak_le(v) + sage: u.weak_le(v) # optional - sage.combinat sage.groups True - sage: v.weak_le(u) + sage: v.weak_le(u) # optional - sage.combinat sage.groups False - sage: v.weak_le(v) + sage: v.weak_le(v) # optional - sage.combinat sage.groups True Comparison for left weak order is achieved with the option ``side``:: - sage: u.weak_le(v, side='left') + sage: u.weak_le(v, side='left') # optional - sage.combinat sage.groups False The implementation uses the equivalent condition that any @@ -2439,10 +2454,10 @@ def weak_le(self, other, side='right'): We now run consistency tests with permutations:: - sage: W = WeylGroup(["A",3]) - sage: P4 = Permutations(4) - sage: def P4toW(w): return W.from_reduced_word(w.reduced_word()) - sage: for u in P4: # long time (5s on sage.math, 2011) + sage: W = WeylGroup(["A", 3]) # optional - sage.combinat sage.groups + sage: P4 = Permutations(4) # optional - sage.combinat sage.groups + sage: def P4toW(w): return W.from_reduced_word(w.reduced_word()) # optional - sage.combinat sage.groups + sage: for u in P4: # long time (5s on sage.math, 2011) # optional - sage.combinat sage.groups ....: for v in P4: ....: assert u.permutohedron_lequal(v) == P4toW(u).weak_le(P4toW(v)) ....: assert u.permutohedron_lequal(v, side='left') == P4toW(u).weak_le(P4toW(v), side='left') @@ -2475,29 +2490,29 @@ def weak_covers(self, side='right', index_set=None, positive=False): EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([3,2,1]) - sage: [x.reduced_word() for x in w.weak_covers()] + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,1]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers()] # optional - sage.combinat sage.groups [[3, 2]] To obtain instead elements that cover self, set ``positive=True``:: - sage: [x.reduced_word() for x in w.weak_covers(positive=True)] + sage: [x.reduced_word() for x in w.weak_covers(positive=True)] # optional - sage.combinat sage.groups [[3, 1, 2, 1], [2, 3, 2, 1]] To obtain covers for left weak order, set the option side to 'left':: - sage: [x.reduced_word() for x in w.weak_covers(side='left')] + sage: [x.reduced_word() for x in w.weak_covers(side='left')] # optional - sage.combinat sage.groups [[2, 1]] - sage: w = W.from_reduced_word([3,2,3,1]) - sage: [x.reduced_word() for x in w.weak_covers()] + sage: w = W.from_reduced_word([3,2,3,1]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.weak_covers()] # optional - sage.combinat sage.groups [[2, 3, 2], [3, 2, 1]] - sage: [x.reduced_word() for x in w.weak_covers(side='left')] + sage: [x.reduced_word() for x in w.weak_covers(side='left')] # optional - sage.combinat sage.groups [[3, 2, 1], [2, 3, 1]] Covers w.r.t. a parabolic subgroup are obtained with the option ``index_set``:: - sage: [x.reduced_word() for x in w.weak_covers(index_set = [1,2])] + sage: [x.reduced_word() for x in w.weak_covers(index_set=[1,2])] # optional - sage.combinat sage.groups [[2, 3, 2]] """ return [self.apply_simple_reflection(i, side=side) @@ -2580,16 +2595,20 @@ def is_coxeter_sortable(self, c, sorting_word=None): [2, 0, 1, 2, 0] sage: w.is_coxeter_sortable(c) True - sage: W = CoxeterGroup(['A',3]) - sage: c = W.from_reduced_word([1,2,3]) - sage: len([w for w in W if w.is_coxeter_sortable(c)]) # number of c-sortable elements in A_3 (Catalan number) + + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: c = W.from_reduced_word([1,2,3]) # optional - sage.combinat sage.groups + + Number of `c`-sortable elements in `A_3` (Catalan number):: + + sage: len([w for w in W if w.is_coxeter_sortable(c)]) # optional - sage.combinat sage.groups 14 TESTS:: - sage: W = SymmetricGroup(3) - sage: c = Permutation((1,2,3)) - sage: sorted(w for w in W if w.is_coxeter_sortable(c)) + sage: W = SymmetricGroup(3) # optional - sage.combinat sage.groups + sage: c = Permutation((1,2,3)) # optional - sage.combinat sage.groups + sage: sorted(w for w in W if w.is_coxeter_sortable(c)) # optional - sage.combinat sage.groups [(), (2,3), (1,2), (1,3,2), (1,3)] """ if hasattr(c, "reduced_word"): @@ -2640,15 +2659,15 @@ def apply_demazure_product(self, element, side='right', EXAMPLES:: - sage: W = WeylGroup(['C',4],prefix="s") - sage: v = W.from_reduced_word([1,2,3,4,3,1]) - sage: v.apply_demazure_product([1,3,4,3,3]) + sage: W = WeylGroup(['C', 4], prefix="s") # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([1,2,3,4,3,1]) # optional - sage.combinat sage.groups + sage: v.apply_demazure_product([1,3,4,3,3]) # optional - sage.combinat sage.groups s4*s1*s2*s3*s4*s3*s1 - sage: v.apply_demazure_product([1,3,4,3],side='left') + sage: v.apply_demazure_product([1,3,4,3], side='left') # optional - sage.combinat sage.groups s3*s4*s1*s2*s3*s4*s2*s3*s1 - sage: v.apply_demazure_product((1,3,4,3),side='left') + sage: v.apply_demazure_product((1,3,4,3), side='left') # optional - sage.combinat sage.groups s3*s4*s1*s2*s3*s4*s2*s3*s1 - sage: v.apply_demazure_product(v) + sage: v.apply_demazure_product(v) # optional - sage.combinat sage.groups s2*s3*s4*s1*s2*s3*s4*s2*s3*s2*s1 """ @@ -2683,14 +2702,14 @@ def min_demazure_product_greater(self, element): EXAMPLES:: - sage: W = WeylGroup(['A',4],prefix="s") - sage: v = W.from_reduced_word([2,3,4,1,2]) - sage: u = W.from_reduced_word([2,3,2,1]) - sage: v.min_demazure_product_greater(u) + sage: W = WeylGroup(['A', 4], prefix="s") # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([2,3,4,1,2]) # optional - sage.combinat sage.groups + sage: u = W.from_reduced_word([2,3,2,1]) # optional - sage.combinat sage.groups + sage: v.min_demazure_product_greater(u) # optional - sage.combinat sage.groups s4*s2 - sage: v.min_demazure_product_greater([2,3,2,1]) + sage: v.min_demazure_product_greater([2,3,2,1]) # optional - sage.combinat sage.groups s4*s2 - sage: v.min_demazure_product_greater((2,3,2,1)) + sage: v.min_demazure_product_greater((2,3,2,1)) # optional - sage.combinat sage.groups s4*s2 """ @@ -2730,14 +2749,14 @@ def deodhar_factor_element(self, w, index_set): EXAMPLES:: - sage: W = WeylGroup(['A',5],prefix="s") - sage: v = W.from_reduced_word([5]) - sage: w = W.from_reduced_word([4,5,2,3,1,2]) - sage: v.deodhar_factor_element(w,[1,3,4]) + sage: W = WeylGroup(['A', 5], prefix="s") # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([5]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([4,5,2,3,1,2]) # optional - sage.combinat sage.groups + sage: v.deodhar_factor_element(w, [1,3,4]) # optional - sage.combinat sage.groups s3*s1 - sage: W = WeylGroup(['C',2]) - sage: w = W.from_reduced_word([2,1]) - sage: w.deodhar_factor_element(W.from_reduced_word([2]),[1]) + sage: W = WeylGroup(['C', 2]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([2,1]) # optional - sage.combinat sage.groups + sage: w.deodhar_factor_element(W.from_reduced_word([2]),[1]) # optional - sage.combinat sage.groups Traceback (most recent call last): ... ValueError: [2, 1] is not of minimum length in its coset for the parabolic subgroup with index set [1] @@ -2785,10 +2804,10 @@ def deodhar_lift_up(self, w, index_set): EXAMPLES:: - sage: W = WeylGroup(['A',3],prefix="s") - sage: v = W.from_reduced_word([1,2,3]) - sage: w = W.from_reduced_word([1,3,2]) - sage: v.deodhar_lift_up(w, [3]) + sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([1,2,3]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([1,3,2]) # optional - sage.combinat sage.groups + sage: v.deodhar_lift_up(w, [3]) # optional - sage.combinat sage.groups s1*s2*s3*s2 """ vmin = self.coset_representative(index_set) @@ -2819,10 +2838,10 @@ def deodhar_lift_down(self, w, index_set): EXAMPLES:: - sage: W = WeylGroup(['A',3],prefix="s") - sage: v = W.from_reduced_word([1,2,3,2]) - sage: w = W.from_reduced_word([3,2]) - sage: v.deodhar_lift_down(w, [3]) + sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups + sage: v = W.from_reduced_word([1,2,3,2]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2]) # optional - sage.combinat sage.groups + sage: v.deodhar_lift_down(w, [3]) # optional - sage.combinat sage.groups s2*s3*s2 """ @@ -2842,9 +2861,9 @@ def inversions_as_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.inversions_as_reflections() + sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups + sage: w.inversions_as_reflections() # optional - sage.combinat sage.groups [s1, s1*s2*s1, s2, s1*s2*s3*s2*s1] """ i = self.first_descent() @@ -2859,9 +2878,9 @@ def left_inversions_as_reflections(self): EXAMPLES:: - sage: W = WeylGroup(['A',3], prefix="s") - sage: w = W.from_reduced_word([3,1,2,1]) - sage: w.left_inversions_as_reflections() + sage: W = WeylGroup(['A', 3], prefix="s") # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,1,2,1]) # optional - sage.combinat sage.groups + sage: w.left_inversions_as_reflections() # optional - sage.combinat sage.groups [s1, s3, s1*s2*s3*s2*s1, s2*s3*s2] """ return self.inverse().inversions_as_reflections() @@ -2872,31 +2891,31 @@ def lower_covers(self, side='right', index_set=None): INPUT: - - side -- 'left' or 'right' (default: 'right') - - index_set -- a list of indices or ``None`` + - ``side`` -- ``'left'`` or ``'right'`` (default: ``'right'``) + - ``index_set`` -- a list of indices or ``None`` OUTPUT: a list EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([3,2,1]) - sage: [x.reduced_word() for x in w.lower_covers()] + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([3,2,1]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers()] # optional - sage.combinat sage.groups [[3, 2]] To obtain covers for left weak order, set the option side to 'left':: - sage: [x.reduced_word() for x in w.lower_covers(side='left')] + sage: [x.reduced_word() for x in w.lower_covers(side='left')] # optional - sage.combinat sage.groups [[2, 1]] - sage: w = W.from_reduced_word([3,2,3,1]) - sage: [x.reduced_word() for x in w.lower_covers()] + sage: w = W.from_reduced_word([3,2,3,1]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.lower_covers()] # optional - sage.combinat sage.groups [[2, 3, 2], [3, 2, 1]] Covers w.r.t. a parabolic subgroup are obtained with the option ``index_set``:: - sage: [x.reduced_word() for x in w.lower_covers(index_set = [1,2])] + sage: [x.reduced_word() for x in w.lower_covers(index_set=[1,2])] # optional - sage.combinat sage.groups [[2, 3, 2]] - sage: [x.reduced_word() for x in w.lower_covers(side='left')] + sage: [x.reduced_word() for x in w.lower_covers(side='left')] # optional - sage.combinat sage.groups [[3, 2, 1], [2, 3, 1]] """ return self.weak_covers(side=side, index_set=index_set, @@ -2908,28 +2927,29 @@ def upper_covers(self, side='right', index_set=None): INPUT: - - side -- 'left' or 'right' (default: 'right') - - index_set -- a list of indices or None + - ``side`` -- ``'left'`` or ``'right'`` (default: ``'right'``) + - ``index_set`` -- a list of indices or ``None`` OUTPUT: a list EXAMPLES:: - sage: W = WeylGroup(['A',3]) - sage: w = W.from_reduced_word([2,3]) - sage: [x.reduced_word() for x in w.upper_covers()] + sage: W = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: w = W.from_reduced_word([2,3]) # optional - sage.combinat sage.groups + sage: [x.reduced_word() for x in w.upper_covers()] # optional - sage.combinat sage.groups [[2, 3, 1], [2, 3, 2]] To obtain covers for left weak order, set the option ``side`` to 'left':: - sage: [x.reduced_word() for x in w.upper_covers(side='left')] + sage: [x.reduced_word() for x in w.upper_covers(side='left')] # optional - sage.combinat sage.groups [[1, 2, 3], [2, 3, 2]] Covers w.r.t. a parabolic subgroup are obtained with the option ``index_set``:: - sage: [x.reduced_word() for x in w.upper_covers(index_set = [1])] + sage: [x.reduced_word() for x in w.upper_covers(index_set=[1])] # optional - sage.combinat sage.groups [[2, 3, 1]] - sage: [x.reduced_word() for x in w.upper_covers(side='left', index_set = [1])] + sage: [x.reduced_word() # optional - sage.combinat sage.groups + ....: for x in w.upper_covers(side='left', index_set=[1])] [[1, 2, 3]] """ return self.weak_covers(side=side, index_set=index_set, @@ -2972,9 +2992,9 @@ def kazhdan_lusztig_cell(self, side='left'): choice of implementation affects the representation of elements in the output cell but not the method used for the cell computation:: - sage: W = CoxeterGroup('A3', implementation='permutation') - sage: s1,s2,s3 = W.simple_reflections() - sage: s1.kazhdan_lusztig_cell() + sage: W = CoxeterGroup('A3', implementation='permutation') # optional - sage.combinat sage.groups + sage: s1, s2, s3 = W.simple_reflections() # optional - sage.combinat sage.groups + sage: s1.kazhdan_lusztig_cell() # optional - sage.combinat sage.groups {(1,2,3,12)(4,5,10,11)(6,7,8,9), (1,2,10)(3,6,5)(4,7,8)(9,12,11), (1,7)(2,4)(5,6)(8,10)(11,12)} diff --git a/src/sage/categories/crystals.py b/src/sage/categories/crystals.py index f74340cf25d..3ceb16529d6 100644 --- a/src/sage/categories/crystals.py +++ b/src/sage/categories/crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs sage.combinat r""" Crystals diff --git a/src/sage/categories/discrete_valuation.py b/src/sage/categories/discrete_valuation.py index 5b68f8b6c12..42829732859 100644 --- a/src/sage/categories/discrete_valuation.py +++ b/src/sage/categories/discrete_valuation.py @@ -20,7 +20,7 @@ class DiscreteValuationRings(Category_singleton): EXAMPLES:: - sage: GF(7)[['x']] in DiscreteValuationRings() + sage: GF(7)[['x']] in DiscreteValuationRings() # optional - sage.rings.finite_rings True sage: TestSuite(DiscreteValuationRings()).run() """ @@ -41,7 +41,7 @@ def uniformizer(self): EXAMPLES:: - sage: Zp(5).uniformizer() + sage: Zp(5).uniformizer() # optional - sage.rings.padics 5 + O(5^21) sage: K. = QQ[[]] @@ -56,7 +56,7 @@ def residue_field(self): EXAMPLES:: - sage: Zp(5).residue_field() + sage: Zp(5).residue_field() # optional - sage.rings.padics Finite Field of size 5 sage: K. = QQ[[]] @@ -70,38 +70,38 @@ def _matrix_charpoly(self, M, var): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)) - sage: M = matrix(4, 4, [ (t^(i+j)).add_bigoh(10) - ....: for i in range(4) for j in range(4) ]) - sage: M + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: M = matrix(4, 4, [(t^(i+j)).add_bigoh(10) # optional - sage.rings.finite_rings + ....: for i in range(4) for j in range(4)]) + sage: M # optional - sage.rings.finite_rings [ 1 + O(t^10) t + O(t^10) t^2 + O(t^10) t^3 + O(t^10)] [ t + O(t^10) t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10)] [t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10)] [t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10) t^6 + O(t^10)] - sage: M.charpoly() # indirect doctest + sage: M.charpoly() # indirect doctest # optional - sage.rings.finite_rings x^4 + (4 + 4*t^2 + 4*t^4 + 4*t^6 + O(t^10))*x^3 Note that this function uses a Hessenberg-like algorithm that performs divisions. Hence, truncations may show up even if the input matrix is exact:: - sage: M = matrix(3, 3, [ 1, t, t^2, 1+t, t^2, t^3, t^2, t^3, t^4 ]) - sage: M + sage: M = matrix(3, 3, [ 1, t, t^2, 1+t, t^2, t^3, t^2, t^3, t^4 ]) # optional - sage.rings.finite_rings + sage: M # optional - sage.rings.finite_rings [ 1 t t^2] [1 + t t^2 t^3] [ t^2 t^3 t^4] - sage: M.charpoly() + sage: M.charpoly() # optional - sage.rings.finite_rings x^3 + (4 + 4*t^2 + 4*t^4 + O(t^25))*x^2 + (4*t + O(t^24))*x Another example over the p-adics:: - sage: R = Zp(5, print_mode="digits", prec=5) - sage: M = matrix(R, 3, 3, range(9)) - sage: M + sage: R = Zp(5, print_mode="digits", prec=5) # optional - sage.rings.padics + sage: M = matrix(R, 3, 3, range(9)) # optional - sage.rings.padics + sage: M # optional - sage.rings.padics [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: M.charpoly() + sage: M.charpoly() # optional - sage.rings.padics ...00001*x^3 + ...44423*x^2 + ...44412*x + ...00000 """ return M._charpoly_hessenberg(var) @@ -114,8 +114,8 @@ def valuation(self): EXAMPLES:: - sage: x = Zp(5)(50) - sage: x.valuation() + sage: x = Zp(5)(50) # optional - sage.rings.padics + sage: x.valuation() # optional - sage.rings.padics 2 """ @@ -125,10 +125,10 @@ def euclidean_degree(self): TESTS:: - sage: R. = GF(5)[[]] - sage: (q^3).euclidean_degree() + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: (q^3).euclidean_degree() # optional - sage.rings.finite_rings 3 - sage: R(0).euclidean_degree() + sage: R(0).euclidean_degree() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: Euclidean degree of the zero element not defined @@ -145,12 +145,12 @@ def quo_rem(self, other): TESTS:: - sage: R. = GF(5)[[]] - sage: (q^2 + q).quo_rem(q) + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: (q^2 + q).quo_rem(q) # optional - sage.rings.finite_rings (1 + q, 0) - sage: (q + 1).quo_rem(q^2) + sage: (q + 1).quo_rem(q^2) # optional - sage.rings.finite_rings (0, 1 + q) - sage: q.quo_rem(0) + sage: q.quo_rem(0) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: Euclidean division by the zero element not defined @@ -170,12 +170,12 @@ def is_unit(self): EXAMPLES:: - sage: x = Zp(5)(50) - sage: x.is_unit() + sage: x = Zp(5)(50) # optional - sage.rings.padics + sage: x.is_unit() # optional - sage.rings.padics False - sage: x = Zp(7)(50) - sage: x.is_unit() + sage: x = Zp(7)(50) # optional - sage.rings.padics + sage: x.is_unit() # optional - sage.rings.padics True """ return self.valuation() == 0 @@ -213,7 +213,7 @@ class DiscreteValuationFields(Category_singleton): EXAMPLES:: - sage: Qp(7) in DiscreteValuationFields() + sage: Qp(7) in DiscreteValuationFields() # optional - sage.rings.padics True sage: TestSuite(DiscreteValuationFields()).run() """ @@ -235,7 +235,7 @@ def uniformizer(self): EXAMPLES:: - sage: Qp(5).uniformizer() + sage: Qp(5).uniformizer() # optional - sage.rings.padics 5 + O(5^21) """ @@ -247,7 +247,7 @@ def residue_field(self): EXAMPLES:: - sage: Qp(5).residue_field() + sage: Qp(5).residue_field() # optional - sage.rings.padics Finite Field of size 5 sage: K. = LaurentSeriesRing(QQ) @@ -261,17 +261,17 @@ def _matrix_hessenbergize(self, H): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)) - sage: K = R.fraction_field() - sage: H = matrix(K, 4, 4, [ (t^(i+j)).add_bigoh(10) - ....: for i in range(4) for j in range(4) ]) - sage: H + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: H = matrix(K, 4, 4, [(t^(i+j)).add_bigoh(10) # optional - sage.rings.finite_rings + ....: for i in range(4) for j in range(4)]) + sage: H # optional - sage.rings.finite_rings [ 1 + O(t^10) t + O(t^10) t^2 + O(t^10) t^3 + O(t^10)] [ t + O(t^10) t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10)] [t^2 + O(t^10) t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10)] [t^3 + O(t^10) t^4 + O(t^10) t^5 + O(t^10) t^6 + O(t^10)] - sage: H.hessenbergize() - sage: H + sage: H.hessenbergize() # optional - sage.rings.finite_rings + sage: H # optional - sage.rings.finite_rings [ 1 + O(t^10) t + t^3 + t^5 + O(t^10) t^2 + O(t^10) t^3 + O(t^10)] [ t + O(t^10) t^2 + t^4 + t^6 + O(t^10) t^3 + O(t^10) t^4 + O(t^10)] [ O(t^10) O(t^10) O(t^10) O(t^10)] @@ -279,14 +279,14 @@ def _matrix_hessenbergize(self, H): Another example over the p-adics:: - sage: K = Qp(5, print_mode="digits", prec=5) - sage: H = matrix(K, 3, 3, range(9)) - sage: H + sage: K = Qp(5, print_mode="digits", prec=5) # optional - sage.rings.padics + sage: H = matrix(K, 3, 3, range(9)) # optional - sage.rings.padics + sage: H # optional - sage.rings.padics [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: H.hessenbergize() - sage: H + sage: H.hessenbergize() # optional - sage.rings.padics + sage: H # optional - sage.rings.padics [ 0 ...00010 ...00002] [ ...00003 ...00024 ...000010] [ ...00000 ...44440 ...44443] @@ -302,7 +302,7 @@ def valuation(self): EXAMPLES:: - sage: x = Qp(5)(50) - sage: x.valuation() + sage: x = Qp(5)(50) # optional - sage.rings.padics + sage: x.valuation() # optional - sage.rings.padics 2 """ diff --git a/src/sage/categories/domains.py b/src/sage/categories/domains.py index c40f95ba880..02062390a02 100644 --- a/src/sage/categories/domains.py +++ b/src/sage/categories/domains.py @@ -59,21 +59,21 @@ def _test_zero_divisors(self, **options): not have them in theory. For such inexact rings, these tests are not performed:: - sage: R = ZpFM(5); R + sage: R = ZpFM(5); R # optional - sage.rings.padics 5-adic Ring of fixed modulus 5^20 - sage: R.is_exact() + sage: R.is_exact() # optional - sage.rings.padics False - sage: a = R(5^19) - sage: a.is_zero() + sage: a = R(5^19) # optional - sage.rings.padics + sage: a.is_zero() # optional - sage.rings.padics False - sage: (a*a).is_zero() + sage: (a * a).is_zero() # optional - sage.rings.padics True - sage: R._test_zero_divisors() + sage: R._test_zero_divisors() # optional - sage.rings.padics EXAMPLES:: sage: ZZ._test_zero_divisors() - sage: ZpFM(5)._test_zero_divisors() + sage: ZpFM(5)._test_zero_divisors() # optional - sage.rings.padics """ if not self.is_exact(): diff --git a/src/sage/categories/drinfeld_modules.py b/src/sage/categories/drinfeld_modules.py index 4a4f193bf1c..2ae9eb54173 100644 --- a/src/sage/categories/drinfeld_modules.py +++ b/src/sage/categories/drinfeld_modules.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld modules over a base diff --git a/src/sage/categories/enumerated_sets.py b/src/sage/categories/enumerated_sets.py index 1097a04412a..b58cb646aba 100644 --- a/src/sage/categories/enumerated_sets.py +++ b/src/sage/categories/enumerated_sets.py @@ -85,7 +85,8 @@ class EnumeratedSets(CategoryWithAxiom): sage: EnumeratedSets().super_categories() [Category of sets] sage: EnumeratedSets().all_super_categories() - [Category of enumerated sets, Category of sets, Category of sets with partial maps, Category of objects] + [Category of enumerated sets, Category of sets, + Category of sets with partial maps, Category of objects] TESTS:: @@ -277,33 +278,33 @@ def iterator_range(self, start=None, stop=None, step=None): EXAMPLES:: - sage: P = Partitions() - sage: list(P.iterator_range(stop=5)) + sage: P = Partitions() # optional - sage.combinat + sage: list(P.iterator_range(stop=5)) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: list(P.iterator_range(0, 5)) + sage: list(P.iterator_range(0, 5)) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: list(P.iterator_range(3, 5)) + sage: list(P.iterator_range(3, 5)) # optional - sage.combinat [[1, 1], [3]] - sage: list(P.iterator_range(3, 10)) + sage: list(P.iterator_range(3, 10)) # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: list(P.iterator_range(3, 10, 2)) + sage: list(P.iterator_range(3, 10, 2)) # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2]] - sage: it = P.iterator_range(3) - sage: [next(it) for x in range(10)] + sage: it = P.iterator_range(3) # optional - sage.combinat + sage: [next(it) for x in range(10)] # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1], [5]] - sage: it = P.iterator_range(3, step=2) - sage: [next(it) for x in range(5)] + sage: it = P.iterator_range(3, step=2) # optional - sage.combinat + sage: [next(it) for x in range(5)] # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2], [1, 1, 1, 1]] - sage: next(P.iterator_range(stop=-3)) + sage: next(P.iterator_range(stop=-3)) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: next(P.iterator_range(start=-3)) + sage: next(P.iterator_range(start=-3)) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -356,26 +357,26 @@ def unrank_range(self, start=None, stop=None, step=None): EXAMPLES:: - sage: P = Partitions() - sage: P.unrank_range(stop=5) + sage: P = Partitions() # optional - sage.combinat + sage: P.unrank_range(stop=5) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P.unrank_range(0, 5) + sage: P.unrank_range(0, 5) # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P.unrank_range(3, 5) + sage: P.unrank_range(3, 5) # optional - sage.combinat [[1, 1], [3]] - sage: P.unrank_range(3, 10) + sage: P.unrank_range(3, 10) # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: P.unrank_range(3, 10, 2) + sage: P.unrank_range(3, 10, 2) # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2]] - sage: P.unrank_range(3) + sage: P.unrank_range(3) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P.unrank_range(stop=-3) + sage: P.unrank_range(stop=-3) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P.unrank_range(start=-3) + sage: P.unrank_range(start=-3) # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -409,24 +410,24 @@ def __getitem__(self, i): EXAMPLES:: - sage: P = Partitions() - sage: P[:5] + sage: P = Partitions() # optional - sage.combinat + sage: P[:5] # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P[0:5] + sage: P[0:5] # optional - sage.combinat [[], [1], [2], [1, 1], [3]] - sage: P[3:5] + sage: P[3:5] # optional - sage.combinat [[1, 1], [3]] - sage: P[3:10] + sage: P[3:10] # optional - sage.combinat [[1, 1], [3], [2, 1], [1, 1, 1], [4], [3, 1], [2, 2]] - sage: P[3:10:2] + sage: P[3:10:2] # optional - sage.combinat [[1, 1], [2, 1], [4], [2, 2]] - sage: P[3:] + sage: P[3:] # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set - sage: P[3] + sage: P[3] # optional - sage.combinat [1, 1] - sage: P[-1] + sage: P[-1] # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set @@ -467,9 +468,9 @@ def __len__(self): EXAMPLES:: - sage: len(GF(5)) + sage: len(GF(5)) # optional - sage.libs.pari 5 - sage: len(MatrixSpace(GF(2), 3, 3)) + sage: len(MatrixSpace(GF(2), 3, 3)) # optional - sage.libs.pari sage.modules 512 """ from sage.rings.infinity import Infinity @@ -494,7 +495,7 @@ def tuple(self): EXAMPLES:: - sage: (GF(3)^2).tuple() + sage: (GF(3)^2).tuple() # optional - sage.libs.pari ((0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)) sage: R = Integers(11) sage: l = R.tuple(); l @@ -575,7 +576,7 @@ def list(self): EXAMPLES:: - sage: (GF(3)^2).list() + sage: (GF(3)^2).list() # optional - sage.libs.pari [(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)] sage: R = Integers(11) sage: R.list() @@ -603,7 +604,7 @@ def _list_from_iterator(self): Trying to list an infinite vector space raises an error instead of running forever (see :trac:`10470`):: - sage: (QQ^2).list() # indirect test + sage: (QQ^2).list() # indirect test # optional - sage.modules Traceback (most recent call last): ... AttributeError: 'FreeModule_ambient_field_with_category' object has no attribute 'list' @@ -958,16 +959,16 @@ def map(self, f, name=None, *, is_injective=True): EXAMPLES:: - sage: R = Compositions(4).map(attrcall('partial_sums')); R + sage: R = Compositions(4).map(attrcall('partial_sums')); R # optional - sage.combinat Image of Compositions of 4 by The map *.partial_sums() from Compositions of 4 - sage: R.cardinality() + sage: R.cardinality() # optional - sage.combinat 8 - sage: R.list() + sage: R.list() # optional - sage.combinat [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4], [1, 4], [2, 3, 4], [2, 4], [3, 4], [4]] - sage: [r for r in R] + sage: [r for r in R] # optional - sage.combinat [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4], [1, 4], [2, 3, 4], [2, 4], [3, 4], [4]] - sage: R.category() + sage: R.category() # optional - sage.combinat Category of finite enumerated subobjects of sets .. WARNING:: @@ -975,20 +976,20 @@ def map(self, f, name=None, *, is_injective=True): If the function is not injective, then there may be repeated elements:: - sage: P = Compositions(4) - sage: P.list() + sage: P = Compositions(4) # optional - sage.combinat + sage: P.list() # optional - sage.combinat [[1, 1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 3], [2, 1, 1], [2, 2], [3, 1], [4]] - sage: P.map(attrcall('major_index')).list() + sage: P.map(attrcall('major_index')).list() # optional - sage.combinat [6, 3, 4, 1, 5, 2, 3, 0] Pass ``is_injective=False`` to get a correct result in this case:: - sage: P.map(attrcall('major_index'), is_injective=False).list() + sage: P.map(attrcall('major_index'), is_injective=False).list() # optional - sage.combinat [6, 3, 4, 1, 5, 2, 0] TESTS:: - sage: TestSuite(R).run(skip=['_test_an_element', + sage: TestSuite(R).run(skip=['_test_an_element', # optional - sage.combinat ....: '_test_enumerated_set_contains', ....: '_test_some_elements']) """ diff --git a/src/sage/categories/examples/algebras_with_basis.py b/src/sage/categories/examples/algebras_with_basis.py index f1d05839e2a..ccbc3a3a9c0 100644 --- a/src/sage/categories/examples/algebras_with_basis.py +++ b/src/sage/categories/examples/algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Examples of algebras with basis """ diff --git a/src/sage/categories/examples/crystals.py b/src/sage/categories/examples/crystals.py index 02121cd3c02..c38117b3b70 100644 --- a/src/sage/categories/examples/crystals.py +++ b/src/sage/categories/examples/crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Example of a crystal """ diff --git a/src/sage/categories/examples/filtered_modules_with_basis.py b/src/sage/categories/examples/filtered_modules_with_basis.py index 0b5e9b475eb..3cf9db3f57c 100644 --- a/src/sage/categories/examples/filtered_modules_with_basis.py +++ b/src/sage/categories/examples/filtered_modules_with_basis.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.combinat r""" Examples of filtered modules with basis """ diff --git a/src/sage/categories/examples/finite_coxeter_groups.py b/src/sage/categories/examples/finite_coxeter_groups.py index c7937688ef8..57ada2a0c2b 100644 --- a/src/sage/categories/examples/finite_coxeter_groups.py +++ b/src/sage/categories/examples/finite_coxeter_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.groups r""" Examples of finite Coxeter groups """ diff --git a/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py b/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py index f51b66c49dd..ac18f69b6ec 100644 --- a/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/examples/finite_dimensional_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Example of a finite dimensional algebra with basis """ diff --git a/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py index a975d902e14..db28f48dff7 100644 --- a/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of a finite dimensional Lie algebra with basis """ diff --git a/src/sage/categories/examples/finite_semigroups.py b/src/sage/categories/examples/finite_semigroups.py index e21a9713815..bf00b415b58 100644 --- a/src/sage/categories/examples/finite_semigroups.py +++ b/src/sage/categories/examples/finite_semigroups.py @@ -25,7 +25,8 @@ class LeftRegularBand(UniqueRepresentation, Parent): EXAMPLES:: sage: S = FiniteSemigroups().example(); S - An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd') + An example of a finite semigroup: + the left regular band generated by ('a', 'b', 'c', 'd') This is the semigroup generated by:: @@ -69,9 +70,9 @@ class LeftRegularBand(UniqueRepresentation, Parent): Now, let us look at the structure of the semigroup:: sage: S = FiniteSemigroups().example(alphabet = ('a','b','c')) - sage: S.cayley_graph(side="left", simple=True).plot() + sage: S.cayley_graph(side="left", simple=True).plot() # optional - sage.graphs Graphics object consisting of 60 graphics primitives - sage: S.j_transversal_of_idempotents() # random (arbitrary choice) + sage: S.j_transversal_of_idempotents() # random (arbitrary choice) # optional - sage.graphs ['acb', 'ac', 'ab', 'bc', 'a', 'c', 'b'] We conclude by running systematic tests on this semigroup:: diff --git a/src/sage/categories/examples/finite_weyl_groups.py b/src/sage/categories/examples/finite_weyl_groups.py index 535d5101101..b4d6c05a233 100644 --- a/src/sage/categories/examples/finite_weyl_groups.py +++ b/src/sage/categories/examples/finite_weyl_groups.py @@ -59,7 +59,7 @@ class SymmetricGroup(UniqueRepresentation, Parent): 24 sage: S.long_element() (3, 2, 1, 0) - sage: S.cayley_graph(side = "left").plot() + sage: S.cayley_graph(side="left").plot() # optional - sage.graphs sage.plot Graphics object consisting of 120 graphics primitives Alternatively, one could have implemented @@ -69,7 +69,7 @@ class SymmetricGroup(UniqueRepresentation, Parent): TESTS:: - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.combinat """ def __init__(self, n=4): @@ -135,7 +135,7 @@ def cartan_type(self): EXAMPLES:: - sage: FiniteWeylGroups().example().cartan_type() + sage: FiniteWeylGroups().example().cartan_type() # optional - sage.combinat ['A', 3] relabelled by {1: 0, 2: 1, 3: 2} """ from sage.combinat.root_system.cartan_type import CartanType diff --git a/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py b/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py index b67e01a4b02..2d2a0f71f4b 100644 --- a/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py +++ b/src/sage/categories/examples/graded_connected_hopf_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of graded connected Hopf algebras with basis """ diff --git a/src/sage/categories/examples/graded_modules_with_basis.py b/src/sage/categories/examples/graded_modules_with_basis.py index 0be39623fa3..86aa957c404 100644 --- a/src/sage/categories/examples/graded_modules_with_basis.py +++ b/src/sage/categories/examples/graded_modules_with_basis.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.combinat r""" Examples of graded modules with basis """ diff --git a/src/sage/categories/examples/hopf_algebras_with_basis.py b/src/sage/categories/examples/hopf_algebras_with_basis.py index 35b61f3c085..265ab46836f 100644 --- a/src/sage/categories/examples/hopf_algebras_with_basis.py +++ b/src/sage/categories/examples/hopf_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of Hopf algebras with basis """ diff --git a/src/sage/categories/examples/lie_algebras.py b/src/sage/categories/examples/lie_algebras.py index 135a665cfa3..81c7f8457ab 100644 --- a/src/sage/categories/examples/lie_algebras.py +++ b/src/sage/categories/examples/lie_algebras.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of a Lie algebra """ @@ -68,11 +69,11 @@ def __classcall_private__(cls, gens): EXAMPLES:: - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: L1 = LieAlgebras(QQ).example() - sage: gens = list(S3.algebra_generators()) - sage: L2 = LieAlgebras(QQ).example(gens) - sage: L1 is L2 + sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat + sage: L1 = LieAlgebras(QQ).example() # optional - sage.combinat + sage: gens = list(S3.algebra_generators()) # optional - sage.combinat + sage: L2 = LieAlgebras(QQ).example(gens) # optional - sage.combinat + sage: L1 is L2 # optional - sage.combinat True """ return super().__classcall__(cls, tuple(gens)) @@ -81,8 +82,8 @@ def __init__(self, gens): """ EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: TestSuite(L).run() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat + sage: TestSuite(L).run() # optional - sage.combinat """ if not gens: raise ValueError("need at least one generator") @@ -95,7 +96,7 @@ def _repr_(self): """ EXAMPLES:: - sage: LieAlgebras(QQ).example() + sage: LieAlgebras(QQ).example() # optional - sage.combinat sage.groups An example of a Lie algebra: the Lie algebra from the associative algebra Symmetric group algebra of order 3 over Rational Field generated by ([2, 1, 3], [2, 3, 1]) @@ -110,10 +111,10 @@ def _element_constructor_(self, value): EXAMPLES:: - sage: S3 = SymmetricGroupAlgebra(ZZ, 3) - sage: gens = S3.algebra_generators() - sage: L = LieAlgebras(QQ).example() - sage: L(3*gens[0] + gens[1]) + sage: S3 = SymmetricGroupAlgebra(ZZ, 3) # optional - sage.combinat sage.groups + sage: gens = S3.algebra_generators() # optional - sage.combinat sage.groups + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: L(3*gens[0] + gens[1]) # optional - sage.combinat sage.groups 3*[2, 1, 3] + [2, 3, 1] """ return self.element_class(self, self._A(value)) @@ -124,8 +125,8 @@ def zero(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.zero() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: L.zero() # optional - sage.combinat sage.groups 0 """ return self.element_class(self, self._A.zero()) @@ -136,8 +137,8 @@ def lie_algebra_generators(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.lie_algebra_generators() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: L.lie_algebra_generators() # optional - sage.combinat sage.groups Family ([2, 1, 3], [2, 3, 1]) """ return Family([self.element_class(self, g) for g in self._gens]) @@ -157,17 +158,17 @@ def __eq__(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x == x + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: x == x # optional - sage.combinat sage.groups True - sage: x.bracket(y) == -y.bracket(x) + sage: x.bracket(y) == -y.bracket(x) # optional - sage.combinat sage.groups True - sage: x == y + sage: x == y # optional - sage.combinat sage.groups False - sage: x.bracket(x) == L.zero() + sage: x.bracket(x) == L.zero() # optional - sage.combinat sage.groups True - sage: x.bracket(x) == 0 + sage: x.bracket(x) == 0 # optional - sage.combinat sage.groups True """ if not isinstance(rhs, LieAlgebraFromAssociative.Element): @@ -180,15 +181,15 @@ def __ne__(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x != y + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: x != y # optional - sage.combinat sage.groups True - sage: x != 0 + sage: x != 0 # optional - sage.combinat sage.groups True - sage: x != x + sage: x != x # optional - sage.combinat sage.groups False - sage: x.bracket(y) != -y.bracket(x) + sage: x.bracket(y) != -y.bracket(x) # optional - sage.combinat sage.groups False """ return not self.__eq__(rhs) @@ -199,10 +200,10 @@ def __bool__(self) -> bool: EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: bool(sum(L.lie_algebra_generators())) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: bool(sum(L.lie_algebra_generators())) # optional - sage.combinat sage.groups True - sage: bool(L.zero()) + sage: bool(L.zero()) # optional - sage.combinat sage.groups False """ return bool(self.value) @@ -213,9 +214,9 @@ def _add_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x + y + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: x + y # optional - sage.combinat sage.groups [2, 1, 3] + [2, 3, 1] """ return self.__class__(self.parent(), self.value + rhs.value) @@ -226,9 +227,9 @@ def _sub_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x - y + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: x - y # optional - sage.combinat sage.groups [2, 1, 3] - [2, 3, 1] """ return self.__class__(self.parent(), self.value - rhs.value) @@ -239,9 +240,9 @@ def _acted_upon_(self, scalar, self_on_left=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: 3 * x + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: 3 * x # optional - sage.combinat sage.groups 3*[2, 1, 3] """ # This was copied, but IDK if it still applies: @@ -265,9 +266,9 @@ def __truediv__(self, x, self_on_left=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: y / 4 + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: y / 4 # optional - sage.combinat sage.groups 1/4*[2, 3, 1] """ if self_on_left: @@ -280,9 +281,9 @@ def __neg__(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: -x + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: -x # optional - sage.combinat sage.groups -[2, 1, 3] """ return self.__class__(self.parent(), -self.value) @@ -313,15 +314,15 @@ def _bracket_(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: elt = 2*x - y - sage: elt.bracket(elt) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.groups + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.groups + sage: elt = 2*x - y # optional - sage.combinat sage.groups + sage: elt.bracket(elt) # optional - sage.combinat sage.groups 0 - sage: elt.bracket(x) + sage: elt.bracket(x) # optional - sage.combinat sage.groups -[1, 3, 2] + [3, 2, 1] - sage: elt2 = x.bracket(y) + x - sage: elt.bracket(elt2) + sage: elt2 = x.bracket(y) + x # optional - sage.combinat sage.groups + sage: elt.bracket(elt2) # optional - sage.combinat sage.groups -2*[2, 1, 3] + 4*[2, 3, 1] - 4*[3, 1, 2] + 2*[3, 2, 1] """ return self.__class__(self.parent(), self.value * rhs.value - rhs.value * self.value) diff --git a/src/sage/categories/examples/lie_algebras_with_basis.py b/src/sage/categories/examples/lie_algebras_with_basis.py index 484e0eee918..e69711ddf03 100644 --- a/src/sage/categories/examples/lie_algebras_with_basis.py +++ b/src/sage/categories/examples/lie_algebras_with_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules r""" Examples of a Lie algebra with basis """ diff --git a/src/sage/categories/examples/sets_cat.py b/src/sage/categories/examples/sets_cat.py index 19b1ef29ade..6f358929a72 100644 --- a/src/sage/categories/examples/sets_cat.py +++ b/src/sage/categories/examples/sets_cat.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari """ Examples of sets """ diff --git a/src/sage/categories/examples/with_realizations.py b/src/sage/categories/examples/with_realizations.py index 7bc940dd289..627bd2a07c3 100644 --- a/src/sage/categories/examples/with_realizations.py +++ b/src/sage/categories/examples/with_realizations.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.modules r""" Examples of parents endowed with multiple realizations """ diff --git a/src/sage/categories/fields.py b/src/sage/categories/fields.py index 4bbbd08ae95..28a93a314b5 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -38,7 +38,7 @@ class Fields(CategoryWithAxiom): sage: K(IntegerRing()) Rational Field - sage: K(PolynomialRing(GF(3), 'x')) + sage: K(PolynomialRing(GF(3), 'x')) # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 3 sage: K(RealField()) @@ -64,7 +64,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in Fields() + sage: GF(4, "a") in Fields() # optional - sage.rings.finite_rings True sage: QQ in Fields() True @@ -81,15 +81,15 @@ def __contains__(self, x): Caveat: this should eventually be fixed:: - sage: gap.Rationals in Fields() + sage: gap.Rationals in Fields() # optional - sage.libs.gap False typically by implementing the method :meth:`category` appropriately for Gap objects:: - sage: GR = gap.Rationals - sage: GR.category = lambda : Fields() - sage: GR in Fields() + sage: GR = gap.Rationals # optional - sage.libs.gap + sage: GR.category = lambda: Fields() # optional - sage.libs.gap + sage: GR in Fields() # optional - sage.libs.gap True The following tests against a memory leak fixed in :trac:`13370`. In order @@ -101,7 +101,7 @@ def __contains__(self, x): sage: _ = gc.collect() sage: permstore = [X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)] sage: n = len(permstore) - sage: for i in prime_range(100): + sage: for i in prime_range(100): # optional - sage.libs.pari ....: R = ZZ.quotient(i) ....: t = R in Fields() @@ -140,16 +140,16 @@ def _contains_helper(cls): TESTS:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.category() + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.category() # optional - sage.libs.pari Category of commutative no zero divisors quotients of algebras over (number fields and quotient fields and metric spaces) sage: F = Fields() - sage: F._contains_helper(Q) + sage: F._contains_helper(Q) # optional - sage.libs.pari False - sage: Q in F # This changes the category! + sage: Q in F # This changes the category! # optional - sage.libs.pari True - sage: F._contains_helper(Q) + sage: F._contains_helper(Q) # optional - sage.libs.pari True """ @@ -169,7 +169,7 @@ def _call_(self, x): sage: K(IntegerRing()) # indirect doctest Rational Field - sage: K(PolynomialRing(GF(3), 'x')) # indirect doctest + sage: K(PolynomialRing(GF(3), 'x')) # indirect doctest # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 3 sage: K(RealField()) @@ -207,11 +207,11 @@ def is_integrally_closed(self): sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() + sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field True - sage: Z5 = GF(5); Z5 + sage: Z5 = GF(5); Z5 # optional - sage.rings.finite_rings Finite Field of size 5 - sage: Z5.is_integrally_closed() + sage: Z5.is_integrally_closed() # optional - sage.rings.finite_rings True """ return True @@ -231,13 +231,15 @@ def _gcd_univariate_polynomial(self, a, b): EXAMPLES:: - sage: R. = QQbar[] - sage: QQbar._gcd_univariate_polynomial(2*x, 2*x^2) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: QQbar._gcd_univariate_polynomial(2*x, 2*x^2) # optional - sage.rings.number_field x TESTS:: - sage: for A in (RR, CC, QQbar): + sage: fields = [RR, CC] + sage: fields.append(QQbar) # optional - sage.rings.number_field + sage: for A in fields: ....: g = A._gcd_univariate_polynomial ....: R. = A[] ....: z = R.zero() @@ -330,7 +332,9 @@ def _xgcd_univariate_polynomial(self, a, b): TESTS:: - sage: for A in (RR, CC, QQbar): + sage: fields = [RR, CC] + sage: fields.append(QQbar) # optional - sage.rings.number_field + sage: for A in fields: ....: g = A._xgcd_univariate_polynomial ....: R. = A[] ....: z, h = R(0), R(1/2) @@ -388,9 +392,9 @@ def is_perfect(self): sage: QQ.is_perfect() True - sage: GF(2).is_perfect() + sage: GF(2).is_perfect() # optional - sage.rings.finite_rings True - sage: FunctionField(GF(2), 'x').is_perfect() + sage: FunctionField(GF(2), 'x').is_perfect() # optional - sage.rings.finite_rings False """ @@ -464,11 +468,11 @@ def _squarefree_decomposition_univariate_polynomial(self, f): sage: p = 37 * (x-2/3)^2 sage: p.squarefree_decomposition() (37) * (x - 2/3)^2 - sage: x = polygen(GF(3)) - sage: x.squarefree_decomposition() + sage: x = polygen(GF(3)) # optional - sage.rings.finite_rings + sage: x.squarefree_decomposition() # optional - sage.rings.finite_rings x - sage: f = QQbar['x'](1) - sage: f.squarefree_decomposition() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.squarefree_decomposition() # optional - sage.rings.number_field 1 """ from sage.structure.factorization import Factorization @@ -525,10 +529,10 @@ def vector_space(self, *args, **kwds): EXAMPLES:: - sage: K. = Qq(125) # optional - sage.rings.padics - sage: V, fr, to = K.vector_space() # optional - sage.rings.padics - sage: v = V([1, 2, 3]) # optional - sage.rings.padics - sage: fr(v, 7) # optional - sage.rings.padics + sage: K. = Qq(125) # optional - sage.rings.padics + sage: V, fr, to = K.vector_space() # optional - sage.rings.padics + sage: v = V([1, 2, 3]) # optional - sage.rings.padics + sage: fr(v, 7) # optional - sage.rings.padics (3*a^2 + 2*a + 1) + O(5^7) """ return self.free_module(*args, **kwds) @@ -601,12 +605,13 @@ def gcd(self,other): EXAMPLES:: - sage: K = GF(5) - sage: K(2).gcd(K(1)) + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: K(2).gcd(K(1)) # optional - sage.rings.finite_rings 1 - sage: K(0).gcd(K(0)) + sage: K(0).gcd(K(0)) # optional - sage.rings.finite_rings 0 - sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) for x in K for y in K) + sage: all(x.gcd(y) == (0 if x == 0 and y == 0 else 1) # optional - sage.rings.finite_rings + ....: for x in K for y in K) True For field of characteristic zero, the gcd of integers is considered @@ -658,9 +663,9 @@ def lcm(self, other): EXAMPLES:: - sage: GF(2)(1).lcm(GF(2)(0)) + sage: GF(2)(1).lcm(GF(2)(0)) # optional - sage.rings.finite_rings 0 - sage: GF(2)(1).lcm(GF(2)(1)) + sage: GF(2)(1).lcm(GF(2)(1)) # optional - sage.rings.finite_rings 1 For field of characteristic zero, the lcm of integers is considered @@ -721,14 +726,14 @@ def xgcd(self, other): EXAMPLES:: - sage: K = GF(5) - sage: K(2).xgcd(K(1)) + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: K(2).xgcd(K(1)) # optional - sage.rings.finite_rings (1, 3, 0) - sage: K(0).xgcd(K(4)) + sage: K(0).xgcd(K(4)) # optional - sage.rings.finite_rings (1, 0, 4) - sage: K(1).xgcd(K(1)) + sage: K(1).xgcd(K(1)) # optional - sage.rings.finite_rings (1, 1, 0) - sage: GF(5)(0).xgcd(GF(5)(0)) + sage: GF(5)(0).xgcd(GF(5)(0)) # optional - sage.rings.finite_rings (0, 0, 0) The xgcd of non-zero floating point numbers will be a triple of @@ -772,8 +777,8 @@ def factor(self): EXAMPLES:: - sage: x = GF(7)(5) - sage: x.factor() + sage: x = GF(7)(5) # optional - sage.rings.finite_rings + sage: x.factor() # optional - sage.rings.finite_rings 5 sage: RR(0).factor() Traceback (most recent call last): @@ -791,7 +796,8 @@ def inverse_of_unit(self): EXAMPLES:: - sage: NumberField(x^7+2,'a')(2).inverse_of_unit() + sage: x = polygen(ZZ, 'x') + sage: NumberField(x^7+2, 'a')(2).inverse_of_unit() # optional - sage.rings.number_field 1/2 Trying to invert the zero element typically raises a diff --git a/src/sage/categories/filtered_hopf_algebras_with_basis.py b/src/sage/categories/filtered_hopf_algebras_with_basis.py index 08888c78313..ca2dc9ac513 100644 --- a/src/sage/categories/filtered_hopf_algebras_with_basis.py +++ b/src/sage/categories/filtered_hopf_algebras_with_basis.py @@ -88,14 +88,14 @@ def antipode_on_basis(self, index): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.monomial(0).antipode() # indirect doctest + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.combinat + sage: H.monomial(0).antipode() # indirect doctest # optional - sage.combinat P0 - sage: H.monomial(1).antipode() # indirect doctest + sage: H.monomial(1).antipode() # indirect doctest # optional - sage.combinat -P1 - sage: H.monomial(2).antipode() # indirect doctest + sage: H.monomial(2).antipode() # indirect doctest # optional - sage.combinat P2 - sage: H.monomial(3).antipode() # indirect doctest + sage: H.monomial(3).antipode() # indirect doctest # optional - sage.combinat -P3 """ if self.monomial(index) == self.one(): @@ -116,15 +116,15 @@ def antipode(self, elem): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.antipode(H.monomial(14)) + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.combinat + sage: H.antipode(H.monomial(14)) # optional - sage.combinat P14 - sage: H.monomial(0).antipode() + sage: H.monomial(0).antipode() # optional - sage.combinat P0 - sage: H.monomial(2).antipode() + sage: H.monomial(2).antipode() # optional - sage.combinat P2 - sage: (2*H.monomial(1) + 3*H.monomial(4)).antipode() + sage: (2*H.monomial(1) + 3*H.monomial(4)).antipode() # optional - sage.combinat -2*P1 + 3*P4 """ return self.linear_combination( diff --git a/src/sage/categories/filtered_modules_with_basis.py b/src/sage/categories/filtered_modules_with_basis.py index 336c1c326c8..7a9b2684f79 100644 --- a/src/sage/categories/filtered_modules_with_basis.py +++ b/src/sage/categories/filtered_modules_with_basis.py @@ -200,8 +200,10 @@ def homogeneous_component_basis(self, d): sage: A = GradedModulesWithBasis(ZZ).example() sage: A.homogeneous_component_basis(4) - Lazy family (Term map from Partitions to An example of a graded module with basis: - the free module on partitions over Integer Ring(i))_{i in Partitions of the integer 4} + Lazy family (Term map + from Partitions + to An example of a graded module with basis: the free module + on partitions over Integer Ring(i))_{i in Partitions of the integer 4} sage: cat = GradedModulesWithBasis(ZZ) sage: C = CombinatorialFreeModule(ZZ, ['a', 'b'], category=cat) @@ -316,12 +318,12 @@ def to_graded_conversion(self): EXAMPLES:: - sage: A = Modules(QQ).WithBasis().Filtered().example() - sage: p = -2 * A.an_element(); p + sage: A = Modules(QQ).WithBasis().Filtered().example() # optional - sage.combinat + sage: p = -2 * A.an_element(); p # optional - sage.combinat -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.to_graded_conversion()(p); q + sage: q = A.to_graded_conversion()(p); q # optional - sage.combinat -4*Bbar[[]] - 4*Bbar[[1]] - 6*Bbar[[2]] - sage: q.parent() is A.graded_algebra() + sage: q.parent() is A.graded_algebra() # optional - sage.combinat True """ base_one = self.base_ring().one() @@ -344,14 +346,14 @@ def from_graded_conversion(self): EXAMPLES:: - sage: A = Modules(QQ).WithBasis().Filtered().example() - sage: p = -2 * A.an_element(); p + sage: A = Modules(QQ).WithBasis().Filtered().example() # optional - sage.combinat + sage: p = -2 * A.an_element(); p # optional - sage.combinat -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.to_graded_conversion()(p); q + sage: q = A.to_graded_conversion()(p); q # optional - sage.combinat -4*Bbar[[]] - 4*Bbar[[1]] - 6*Bbar[[2]] - sage: A.from_graded_conversion()(q) == p + sage: A.from_graded_conversion()(q) == p # optional - sage.combinat True - sage: q.parent() is A.graded_algebra() + sage: q.parent() is A.graded_algebra() # optional - sage.combinat True """ base_one = self.base_ring().one() @@ -376,14 +378,14 @@ def projection(self, i): EXAMPLES:: - sage: A = Modules(ZZ).WithBasis().Filtered().example() - sage: p = -2 * A.an_element(); p + sage: A = Modules(ZZ).WithBasis().Filtered().example() # optional - sage.combinat + sage: p = -2 * A.an_element(); p # optional - sage.combinat -4*P[] - 4*P[1] - 6*P[2] - sage: q = A.projection(2)(p); q + sage: q = A.projection(2)(p); q # optional - sage.combinat -6*Bbar[[2]] - sage: q.parent() is A.graded_algebra() + sage: q.parent() is A.graded_algebra() # optional - sage.combinat True - sage: A.projection(3)(p) + sage: A.projection(3)(p) # optional - sage.combinat 0 """ base_zero = self.base_ring().zero() @@ -437,50 +439,55 @@ def induced_graded_map(self, other, f): We start with the free `\QQ`-module with basis the set of all partitions:: - sage: A = Modules(QQ).WithBasis().Filtered().example(); A + sage: A = Modules(QQ).WithBasis().Filtered().example(); A # optional - sage.combinat An example of a filtered module with basis: the free module on partitions over Rational Field - sage: M = A.indices(); M + sage: M = A.indices(); M # optional - sage.combinat Partitions - sage: p1, p2, p21, p321 = [A.basis()[Partition(i)] for i in [[1], [2], [2,1], [3,2,1]]] + sage: p1, p2, p21, p321 = [A.basis()[Partition(i)] # optional - sage.combinat + ....: for i in [[1], [2], [2,1], [3,2,1]]] Let us define a map from ``A`` to itself which acts on the basis by sending every partition `\lambda` to the sum of the conjugates of all partitions `\mu` for which `\lambda / \mu` is a horizontal strip:: - sage: def map_on_basis(lam): - ....: return A.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = A.module_morphism(on_basis=map_on_basis, + sage: def map_on_basis(lam): # optional - sage.combinat + ....: def mus(k): + ....: return lam.remove_horizontal_border_strip(k) + ....: return A.sum_of_monomials([Partition(mu).conjugate() + ....: for k in range(sum(lam) + 1) + ....: for mu in mus(k)]) + sage: f = A.module_morphism(on_basis=map_on_basis, # optional - sage.combinat ....: codomain=A) - sage: f(p1) + sage: f(p1) # optional - sage.combinat P[] + P[1] - sage: f(p2) + sage: f(p2) # optional - sage.combinat P[] + P[1] + P[1, 1] - sage: f(p21) + sage: f(p21) # optional - sage.combinat P[1] + P[1, 1] + P[2] + P[2, 1] - sage: f(p21 - p1) + sage: f(p21 - p1) # optional - sage.combinat -P[] + P[1, 1] + P[2] + P[2, 1] - sage: f(p321) + sage: f(p321) # optional - sage.combinat P[2, 1] + P[2, 1, 1] + P[2, 2] + P[2, 2, 1] + P[3, 1] + P[3, 1, 1] + P[3, 2] + P[3, 2, 1] We now compute `\operatorname{gr} f` :: - sage: grA = A.graded_algebra(); grA + sage: grA = A.graded_algebra(); grA # optional - sage.combinat Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field - sage: pp1, pp2, pp21, pp321 = [A.to_graded_conversion()(i) for i in [p1, p2, p21, p321]] - sage: pp2 + 4 * pp21 + sage: pp1, pp2, pp21, pp321 = [A.to_graded_conversion()(i) # optional - sage.combinat + ....: for i in [p1, p2, p21, p321]] + sage: pp2 + 4 * pp21 # optional - sage.combinat Bbar[[2]] + 4*Bbar[[2, 1]] - sage: grf = A.induced_graded_map(A, f); grf - Generic endomorphism of Graded Module of An example of a - filtered module with basis: - the free module on partitions over Rational Field - sage: grf(pp1) + sage: grf = A.induced_graded_map(A, f); grf # optional - sage.combinat + Generic endomorphism of Graded Module of + An example of a filtered module with basis: + the free module on partitions over Rational Field + sage: grf(pp1) # optional - sage.combinat Bbar[[1]] - sage: grf(pp2 + 4 * pp21) + sage: grf(pp2 + 4 * pp21) # optional - sage.combinat Bbar[[1, 1]] + 4*Bbar[[2, 1]] **Example 2.** @@ -490,45 +497,48 @@ def induced_graded_map(self, other, f): `f` will lead into a graded algebra already, namely into the algebra of symmetric functions:: - sage: h = SymmetricFunctions(QQ).h() - sage: def map_on_basis(lam): # redefining map_on_basis - ....: return h.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = A.module_morphism(on_basis=map_on_basis, + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + ....: def mus(k): + ....: return lam.remove_horizontal_border_strip(k) + ....: return h.sum_of_monomials([Partition(mu).conjugate() + ....: for k in range(sum(lam) + 1) + ....: for mu in mus(k)]) + sage: f = A.module_morphism(on_basis=map_on_basis, # optional - sage.combinat ....: codomain=h) # redefining f - sage: f(p1) + sage: f(p1) # optional - sage.combinat h[] + h[1] - sage: f(p2) + sage: f(p2) # optional - sage.combinat h[] + h[1] + h[1, 1] - sage: f(A.zero()) + sage: f(A.zero()) # optional - sage.combinat 0 - sage: f(p2 - 3*p1) + sage: f(p2 - 3*p1) # optional - sage.combinat -2*h[] - 2*h[1] + h[1, 1] The algebra ``h`` of symmetric functions in the `h`-basis is already graded, so its associated graded algebra is implemented as itself:: - sage: grh = h.graded_algebra(); grh is h + sage: grh = h.graded_algebra(); grh is h # optional - sage.combinat True - sage: grf = A.induced_graded_map(h, f); grf + sage: grf = A.induced_graded_map(h, f); grf # optional - sage.combinat Generic morphism: From: Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field To: Symmetric Functions over Rational Field in the homogeneous basis - sage: grf(pp1) + sage: grf(pp1) # optional - sage.combinat h[1] - sage: grf(pp2) + sage: grf(pp2) # optional - sage.combinat h[1, 1] - sage: grf(pp321) + sage: grf(pp321) # optional - sage.combinat h[3, 2, 1] - sage: grf(pp2 - 3*pp1) + sage: grf(pp2 - 3*pp1) # optional - sage.combinat -3*h[1] + h[1, 1] - sage: grf(pp21) + sage: grf(pp21) # optional - sage.combinat h[2, 1] - sage: grf(grA.zero()) + sage: grf(grA.zero()) # optional - sage.combinat 0 **Example 3.** @@ -537,42 +547,45 @@ def induced_graded_map(self, other, f): have one as the domain instead. Our new ``f`` will go from ``h`` to ``A``:: - sage: def map_on_basis(lam): # redefining map_on_basis - ....: return A.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = h.module_morphism(on_basis=map_on_basis, + sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + ....: def mus(k): + ....: return lam.remove_horizontal_border_strip(k) + ....: return A.sum_of_monomials([Partition(mu).conjugate() + ....: for k in range(sum(lam) + 1) + ....: for mu in mus(k)]) + sage: f = h.module_morphism(on_basis=map_on_basis, # optional - sage.combinat ....: codomain=A) # redefining f - sage: f(h[1]) + sage: f(h[1]) # optional - sage.combinat P[] + P[1] - sage: f(h[2]) + sage: f(h[2]) # optional - sage.combinat P[] + P[1] + P[1, 1] - sage: f(h[1, 1]) + sage: f(h[1, 1]) # optional - sage.combinat P[1] + P[2] - sage: f(h[2, 2]) + sage: f(h[2, 2]) # optional - sage.combinat P[1, 1] + P[2, 1] + P[2, 2] - sage: f(h[3, 2, 1]) + sage: f(h[3, 2, 1]) # optional - sage.combinat P[2, 1] + P[2, 1, 1] + P[2, 2] + P[2, 2, 1] + P[3, 1] + P[3, 1, 1] + P[3, 2] + P[3, 2, 1] - sage: f(h.one()) + sage: f(h.one()) # optional - sage.combinat P[] - sage: grf = h.induced_graded_map(A, f); grf + sage: grf = h.induced_graded_map(A, f); grf # optional - sage.combinat Generic morphism: From: Symmetric Functions over Rational Field in the homogeneous basis To: Graded Module of An example of a filtered module with basis: the free module on partitions over Rational Field - sage: grf(h[1]) + sage: grf(h[1]) # optional - sage.combinat Bbar[[1]] - sage: grf(h[2]) + sage: grf(h[2]) # optional - sage.combinat Bbar[[1, 1]] - sage: grf(h[1, 1]) + sage: grf(h[1, 1]) # optional - sage.combinat Bbar[[2]] - sage: grf(h[2, 2]) + sage: grf(h[2, 2]) # optional - sage.combinat Bbar[[2, 2]] - sage: grf(h[3, 2, 1]) + sage: grf(h[3, 2, 1]) # optional - sage.combinat Bbar[[3, 2, 1]] - sage: grf(h.one()) + sage: grf(h.one()) # optional - sage.combinat Bbar[[]] **Example 4.** @@ -580,33 +593,36 @@ def induced_graded_map(self, other, f): The construct `\operatorname{gr} f` also makes sense when `f` is a filtration-preserving map between graded modules. :: - sage: def map_on_basis(lam): # redefining map_on_basis - ....: return h.sum_of_monomials([Partition(mu).conjugate() for k in range(sum(lam) + 1) - ....: for mu in lam.remove_horizontal_border_strip(k)]) - sage: f = h.module_morphism(on_basis=map_on_basis, + sage: def map_on_basis(lam): # redefining map_on_basis # optional - sage.combinat + ....: def mus(k): + ....: return lam.remove_horizontal_border_strip(k) + ....: return h.sum_of_monomials([Partition(mu).conjugate() + ....: for k in range(sum(lam) + 1) + ....: for mu in mus(k)]) + sage: f = h.module_morphism(on_basis=map_on_basis, # optional - sage.combinat ....: codomain=h) # redefining f - sage: f(h[1]) + sage: f(h[1]) # optional - sage.combinat h[] + h[1] - sage: f(h[2]) + sage: f(h[2]) # optional - sage.combinat h[] + h[1] + h[1, 1] - sage: f(h[1, 1]) + sage: f(h[1, 1]) # optional - sage.combinat h[1] + h[2] - sage: f(h[2, 1]) + sage: f(h[2, 1]) # optional - sage.combinat h[1] + h[1, 1] + h[2] + h[2, 1] - sage: f(h.one()) + sage: f(h.one()) # optional - sage.combinat h[] - sage: grf = h.induced_graded_map(h, f); grf - Generic endomorphism of Symmetric Functions over Rational - Field in the homogeneous basis - sage: grf(h[1]) + sage: grf = h.induced_graded_map(h, f); grf # optional - sage.combinat + Generic endomorphism of + Symmetric Functions over Rational Field in the homogeneous basis + sage: grf(h[1]) # optional - sage.combinat h[1] - sage: grf(h[2]) + sage: grf(h[2]) # optional - sage.combinat h[1, 1] - sage: grf(h[1, 1]) + sage: grf(h[1, 1]) # optional - sage.combinat h[2] - sage: grf(h[2, 1]) + sage: grf(h[2, 1]) # optional - sage.combinat h[2, 1] - sage: grf(h.one()) + sage: grf(h.one()) # optional - sage.combinat h[] """ grA = self.graded_algebra() @@ -643,26 +659,26 @@ def is_homogeneous(self): EXAMPLES:: - sage: A = ModulesWithBasis(ZZ).Filtered().example() - sage: x = A(Partition((3,2,1))) - sage: y = A(Partition((4,4,1))) - sage: z = A(Partition((2,2,2))) - sage: (3*x).is_homogeneous() + sage: A = ModulesWithBasis(ZZ).Filtered().example() # optional - sage.combinat + sage: x = A(Partition((3,2,1))) # optional - sage.combinat + sage: y = A(Partition((4,4,1))) # optional - sage.combinat + sage: z = A(Partition((2,2,2))) # optional - sage.combinat + sage: (3*x).is_homogeneous() # optional - sage.combinat True - sage: (x - y).is_homogeneous() + sage: (x - y).is_homogeneous() # optional - sage.combinat False - sage: (x+2*z).is_homogeneous() + sage: (x+2*z).is_homogeneous() # optional - sage.combinat True Here is an example with a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: (x, y) = (S[2], S[3]) - sage: (3*x).is_homogeneous() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: (x, y) = (S[2], S[3]) # optional - sage.combinat + sage: (3*x).is_homogeneous() # optional - sage.combinat True - sage: (x^3 - y^2).is_homogeneous() + sage: (x^3 - y^2).is_homogeneous() # optional - sage.combinat True - sage: ((x + y)^2).is_homogeneous() + sage: ((x + y)^2).is_homogeneous() # optional - sage.combinat False Let us now test a filtered algebra (but remember that the @@ -701,10 +717,10 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: A = GradedModulesWithBasis(QQ).example() - sage: A.degree_on_basis(Partition((2,1))) + sage: A = GradedModulesWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.degree_on_basis(Partition((2,1))) # optional - sage.combinat sage.modules 3 - sage: A.degree_on_basis(Partition((4,2,1,1,1,1))) + sage: A.degree_on_basis(Partition((4,2,1,1,1,1))) # optional - sage.combinat sage.modules 10 """ @@ -722,28 +738,28 @@ def homogeneous_degree(self): EXAMPLES:: - sage: A = ModulesWithBasis(ZZ).Filtered().example() - sage: x = A(Partition((3,2,1))) - sage: y = A(Partition((4,4,1))) - sage: z = A(Partition((2,2,2))) - sage: x.degree() + sage: A = ModulesWithBasis(ZZ).Filtered().example() # optional - sage.combinat sage.modules + sage: x = A(Partition((3,2,1))) # optional - sage.combinat sage.modules + sage: y = A(Partition((4,4,1))) # optional - sage.combinat sage.modules + sage: z = A(Partition((2,2,2))) # optional - sage.combinat sage.modules + sage: x.degree() # optional - sage.combinat sage.modules 6 - sage: (x + 2*z).degree() + sage: (x + 2*z).degree() # optional - sage.combinat sage.modules 6 - sage: (y - x).degree() + sage: (y - x).degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous An example in a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: (x, y) = (S[2], S[3]) - sage: x.homogeneous_degree() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat sage.modules + sage: (x, y) = (S[2], S[3]) # optional - sage.combinat sage.modules + sage: x.homogeneous_degree() # optional - sage.combinat sage.modules 2 - sage: (x^3 + 4*y^2).homogeneous_degree() + sage: (x^3 + 4*y^2).homogeneous_degree() # optional - sage.combinat sage.modules 6 - sage: ((1 + x)^3).homogeneous_degree() + sage: ((1 + x)^3).homogeneous_degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous @@ -765,8 +781,8 @@ def homogeneous_degree(self): TESTS:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S.zero().degree() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat sage.modules + sage: S.zero().degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: the zero element does not have a well-defined degree @@ -793,28 +809,28 @@ def maximal_degree(self): EXAMPLES:: - sage: A = ModulesWithBasis(ZZ).Filtered().example() - sage: x = A(Partition((3,2,1))) - sage: y = A(Partition((4,4,1))) - sage: z = A(Partition((2,2,2))) - sage: x.maximal_degree() + sage: A = ModulesWithBasis(ZZ).Filtered().example() # optional - sage.combinat + sage: x = A(Partition((3,2,1))) # optional - sage.combinat + sage: y = A(Partition((4,4,1))) # optional - sage.combinat + sage: z = A(Partition((2,2,2))) # optional - sage.combinat + sage: x.maximal_degree() # optional - sage.combinat 6 - sage: (x + 2*z).maximal_degree() + sage: (x + 2*z).maximal_degree() # optional - sage.combinat 6 - sage: (y - x).maximal_degree() + sage: (y - x).maximal_degree() # optional - sage.combinat 9 - sage: (3*z).maximal_degree() + sage: (3*z).maximal_degree() # optional - sage.combinat 6 Now, we test this on a graded algebra:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: (x, y) = (S[2], S[3]) - sage: x.maximal_degree() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: (x, y) = (S[2], S[3]) # optional - sage.combinat + sage: x.maximal_degree() # optional - sage.combinat 2 - sage: (x^3 + 4*y^2).maximal_degree() + sage: (x^3 + 4*y^2).maximal_degree() # optional - sage.combinat 6 - sage: ((1 + x)^3).maximal_degree() + sage: ((1 + x)^3).maximal_degree() # optional - sage.combinat 6 Let us now test a filtered algebra:: @@ -836,8 +852,8 @@ def maximal_degree(self): TESTS:: - sage: S = NonCommutativeSymmetricFunctions(QQ).S() - sage: S.zero().degree() + sage: S = NonCommutativeSymmetricFunctions(QQ).S() # optional - sage.combinat + sage: S.zero().degree() # optional - sage.combinat Traceback (most recent call last): ... ValueError: the zero element does not have a well-defined degree @@ -998,16 +1014,16 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: S = E.submodule([x + y, x*y - y*z, y]) - sage: B = S.basis() - sage: [B[0].lift(), B[1].lift(), B[2].lift()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules + sage: B = S.basis() # optional - sage.combinat sage.modules + sage: [B[0].lift(), B[1].lift(), B[2].lift()] # optional - sage.combinat sage.modules [x, y, x*y - y*z] - sage: S.degree_on_basis(0) + sage: S.degree_on_basis(0) # optional - sage.combinat sage.modules 1 - sage: S.degree_on_basis(1) + sage: S.degree_on_basis(1) # optional - sage.combinat sage.modules 1 - sage: S.degree_on_basis(2) + sage: S.degree_on_basis(2) # optional - sage.combinat sage.modules 2 """ return self.basis()[m].lift().degree() @@ -1019,29 +1035,29 @@ def degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: S = E.submodule([x + y, x*y - y*z, y]) - sage: B = S.basis() - sage: [B[0].lift(), B[1].lift(), B[2].lift()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules + sage: B = S.basis() # optional - sage.combinat sage.modules + sage: [B[0].lift(), B[1].lift(), B[2].lift()] # optional - sage.combinat sage.modules [x, y, x*y - y*z] - sage: B[0].degree() + sage: B[0].degree() # optional - sage.combinat sage.modules 1 - sage: B[1].degree() + sage: B[1].degree() # optional - sage.combinat sage.modules 1 - sage: (B[0] + 3*B[1]).degree() + sage: (B[0] + 3*B[1]).degree() # optional - sage.combinat sage.modules 1 The degree of inhomogeneous elements is not defined (following the behavior of the exterior algebra):: - sage: (B[0] + B[2]).degree() + sage: (B[0] + B[2]).degree() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous We can still get the maximal degree:: - sage: (B[0] + B[2]).maximal_degree() + sage: (B[0] + B[2]).maximal_degree() # optional - sage.combinat sage.modules 2 """ return self.lift().degree() @@ -1059,14 +1075,14 @@ def maximal_degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: F = E.submodule([x + 1, x*y - 1]) - sage: B = F.basis() - sage: [B[0].lift(), B[1].lift()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: F = E.submodule([x + 1, x*y - 1]) # optional - sage.combinat sage.modules + sage: B = F.basis() # optional - sage.combinat sage.modules + sage: [B[0].lift(), B[1].lift()] # optional - sage.combinat sage.modules [-x*y + 1, x*y + x] - sage: B[0].maximal_degree() + sage: B[0].maximal_degree() # optional - sage.combinat sage.modules 2 - sage: B[1].maximal_degree() + sage: B[1].maximal_degree() # optional - sage.combinat sage.modules 2 """ return self.lift().maximal_degree() diff --git a/src/sage/categories/finite_complex_reflection_groups.py b/src/sage/categories/finite_complex_reflection_groups.py index 8648f89dbc4..f4ab8a943ce 100644 --- a/src/sage/categories/finite_complex_reflection_groups.py +++ b/src/sage/categories/finite_complex_reflection_groups.py @@ -56,7 +56,7 @@ class FiniteComplexReflectionGroups(CategoryWithAxiom): sage: W = ComplexReflectionGroups().Finite().example(); W # optional - gap3 Reducible real reflection group of rank 4 and type A2 x B2 - sage: W.reflections() # optional - gap3 + sage: W.reflections() # optional - gap3 Finite family {1: (1,8)(2,5)(9,12), 2: (1,5)(2,9)(8,12), 3: (3,10)(4,7)(11,14), 4: (3,6)(4,11)(10,13), 5: (1,9)(2,8)(5,12), 6: (4,14)(6,13)(7,11), @@ -64,7 +64,7 @@ class FiniteComplexReflectionGroups(CategoryWithAxiom): ``W`` is in the category of complex reflection groups:: - sage: W in ComplexReflectionGroups().Finite() # optional - gap3 + sage: W in ComplexReflectionGroups().Finite() # optional - gap3 True """ def example(self): @@ -104,14 +104,14 @@ def WellGenerated(self): Here is an example of a finite well-generated complex reflection group:: - sage: W = C.example(); W # optional - gap3 + sage: W = C.example(); W # optional - gap3 Reducible complex reflection group of rank 4 and type A2 x G(3,1,2) All finite Coxeter groups are well generated:: sage: CoxeterGroups().Finite().is_subcategory(C) True - sage: SymmetricGroup(3) in C + sage: SymmetricGroup(3) in C # optional - sage.groups True .. NOTE:: @@ -124,8 +124,9 @@ def WellGenerated(self): TESTS:: - sage: TestSuite(W).run() # optional - gap3 - sage: TestSuite(ComplexReflectionGroups().Finite().WellGenerated()).run() # optional - gap3 + sage: TestSuite(W).run() # optional - gap3 + sage: C = ComplexReflectionGroups().Finite().WellGenerated() + sage: TestSuite(C).run() # optional - gap3 sage: CoxeterGroups().Finite().WellGenerated.__module__ 'sage.categories.finite_complex_reflection_groups' @@ -148,12 +149,12 @@ def degrees(self): EXAMPLES:: - sage: W = ColoredPermutations(1,4) - sage: W.degrees() + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.degrees() # optional - sage.combinat sage.groups (2, 3, 4) - sage: W = ColoredPermutations(3,3) - sage: W.degrees() + sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups + sage: W.degrees() # optional - sage.combinat sage.groups (3, 6, 9) sage: W = ReflectionGroup(31) # optional - gap3 @@ -170,12 +171,12 @@ def codegrees(self): EXAMPLES:: - sage: W = ColoredPermutations(1,4) - sage: W.codegrees() + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.codegrees() # optional - sage.combinat sage.groups (2, 1, 0) - sage: W = ColoredPermutations(3,3) - sage: W.codegrees() + sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups + sage: W.codegrees() # optional - sage.combinat sage.groups (6, 3, 0) sage: W = ReflectionGroup(31) # optional - gap3 @@ -198,27 +199,27 @@ def _test_degrees(self, **options): Reducible real reflection group of rank 4 and type A2 x B2 sage: W._test_degrees() # optional - gap3 - sage: W = SymmetricGroup(5) - sage: W._test_degrees() + sage: W = SymmetricGroup(5) # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups We now break the implementation of W.degrees and check that this is caught:: - sage: W.degrees = lambda: (1/1,5) - sage: W._test_degrees() + sage: W.degrees = lambda: (1/1,5) # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the degrees should be integers - sage: W.degrees = lambda: (1,2,3) - sage: W._test_degrees() + sage: W.degrees = lambda: (1,2,3) # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the degrees should be larger than 2 We restore W to its normal state:: - sage: del W.degrees - sage: W._test_degrees() + sage: del W.degrees # optional - sage.groups + sage: W._test_degrees() # optional - sage.groups See the documentation for :class:`TestSuite` for more information. """ @@ -253,27 +254,27 @@ def _test_codegrees(self, **options): Reducible real reflection group of rank 4 and type A2 x B2 sage: W._test_codegrees() # optional - gap3 - sage: W = SymmetricGroup(5) - sage: W._test_codegrees() + sage: W = SymmetricGroup(5) # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups We now break the implementation of W.degrees and check that this is caught:: - sage: W.codegrees = lambda: (1/1,5) - sage: W._test_codegrees() + sage: W.codegrees = lambda: (1/1,5) # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the codegrees should be integers - sage: W.codegrees = lambda: (2,1,-1) - sage: W._test_codegrees() + sage: W.codegrees = lambda: (2,1,-1) # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups Traceback (most recent call last): ... AssertionError: the codegrees should be nonnegative We restore W to its normal state:: - sage: del W.codegrees - sage: W._test_codegrees() + sage: del W.codegrees # optional - sage.groups + sage: W._test_codegrees() # optional - sage.groups See the documentation for :class:`TestSuite` for more information. """ @@ -310,14 +311,14 @@ def number_of_reflection_hyperplanes(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.number_of_reflection_hyperplanes() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(2,3) - sage: W.number_of_reflection_hyperplanes() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups 9 - sage: W = ColoredPermutations(4,3) - sage: W.number_of_reflection_hyperplanes() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflection_hyperplanes() # optional - sage.combinat sage.groups 15 sage: W = ReflectionGroup((4,2,3)) # optional - gap3 sage: W.number_of_reflection_hyperplanes() # optional - gap3 @@ -341,20 +342,21 @@ def number_of_reflections(self): EXAMPLES:: - sage: [SymmetricGroup(i).number_of_reflections() for i in range(int(8))] + sage: [SymmetricGroup(i).number_of_reflections() # optional - sage.groups + ....: for i in range(int(8))] [0, 0, 1, 3, 6, 10, 15, 21] - sage: W = ColoredPermutations(1,3) - sage: W.number_of_reflections() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(2,3) - sage: W.number_of_reflections() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - sage.combinat sage.groups 9 - sage: W = ColoredPermutations(4,3) - sage: W.number_of_reflections() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - sage.combinat sage.groups 21 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.number_of_reflections() # optional - gap3 + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.number_of_reflections() # optional - gap3 # optional - sage.combinat sage.groups 15 """ from sage.rings.integer_ring import ZZ @@ -375,17 +377,17 @@ def rank(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.rank() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.rank() # optional - sage.combinat sage.groups 2 - sage: W = ColoredPermutations(2,3) - sage: W.rank() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.rank() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(4,3) - sage: W.rank() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.rank() # optional - sage.combinat sage.groups 3 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.rank() # optional - gap3 + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.rank() # optional - gap3 # optional - sage.combinat sage.groups 3 """ return len(self.degrees()) @@ -399,17 +401,17 @@ def cardinality(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.cardinality() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - sage.combinat sage.groups 6 - sage: W = ColoredPermutations(2,3) - sage: W.cardinality() + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - sage.combinat sage.groups 48 - sage: W = ColoredPermutations(4,3) - sage: W.cardinality() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - sage.combinat sage.groups 384 - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.cardinality() # optional - gap3 + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.cardinality() # optional - gap3 # optional - sage.combinat sage.groups 192 """ from sage.rings.integer_ring import ZZ @@ -437,20 +439,20 @@ def is_well_generated(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.is_well_generated() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.is_well_generated() # optional - sage.combinat sage.groups True - sage: W = ColoredPermutations(4,3) - sage: W.is_well_generated() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.is_well_generated() # optional - sage.combinat sage.groups True - sage: W = ReflectionGroup((4,2,3)) # optional - gap3 - sage: W.is_well_generated() # optional - gap3 + sage: W = ReflectionGroup((4,2,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.is_well_generated() # optional - gap3 # optional - sage.combinat sage.groups False - sage: W = ReflectionGroup((4,4,3)) # optional - gap3 - sage: W.is_well_generated() # optional - gap3 + sage: W = ReflectionGroup((4,4,3)) # optional - gap3 # optional - sage.combinat sage.groups + sage: W.is_well_generated() # optional - gap3 # optional - sage.combinat sage.groups True """ return self.number_of_simple_reflections() == self.rank() @@ -472,12 +474,12 @@ def is_real(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.is_real() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.is_real() # optional - sage.combinat sage.groups True - sage: W = ColoredPermutations(4,3) - sage: W.is_real() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.is_real() # optional - sage.combinat sage.groups False .. TODO:: @@ -501,24 +503,24 @@ def base_change_matrix(self): EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [1 0] [0 1] - sage: W = ReflectionGroup(23) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup(23) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [1 0 0] [0 1 0] [0 0 1] - sage: W = ReflectionGroup((3,1,2)) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup((3,1,2)) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [1 0] [1 1] - sage: W = ReflectionGroup((4,2,2)) # optional - gap3 - sage: W.base_change_matrix() # optional - gap3 + sage: W = ReflectionGroup((4,2,2)) # optional - gap3 + sage: W.base_change_matrix() # optional - gap3 [ 1 0] [E(4) 1] """ @@ -542,8 +544,8 @@ def to_matrix(self): [0 1], [ 0 -1], [ 1 1], [ 1 0], [-1 -1], [-1 0] ] - sage: W = ColoredPermutations(1,3) - sage: [t.to_matrix() for t in W] + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: [t.to_matrix() for t in W] # optional - sage.combinat sage.groups [ [1 0 0] [1 0 0] [0 1 0] [0 0 1] [0 1 0] [0 0 1] [0 1 0] [0 0 1] [1 0 0] [1 0 0] [0 0 1] [0 1 0] @@ -553,8 +555,8 @@ def to_matrix(self): A different representation is given by the colored permutations:: - sage: W = ColoredPermutations(3, 1) - sage: [t.to_matrix() for t in W] + sage: W = ColoredPermutations(3, 1) # optional - sage.combinat sage.groups + sage: [t.to_matrix() for t in W] # optional - sage.combinat sage.groups [[1], [zeta3], [-zeta3 - 1]] """ @@ -580,9 +582,9 @@ def character_value(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3); W + sage: W = ColoredPermutations(1,3); W # optional - sage.combinat sage.groups 1-colored permutations of size 3 - sage: [t.character_value() for t in W] + sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups [3, 1, 1, 0, 0, 1] Note that this could be a different (faithful) @@ -594,14 +596,14 @@ def character_value(self): sage: [t.character_value() for t in W] # optional - gap3 [2, 0, 0, -1, -1, 0] - sage: W = ColoredPermutations(2,2); W + sage: W = ColoredPermutations(2,2); W # optional - sage.combinat sage.groups 2-colored permutations of size 2 - sage: [t.character_value() for t in W] + sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups [2, 0, 0, -2, 0, 0, 0, 0] - sage: W = ColoredPermutations(3,1); W + sage: W = ColoredPermutations(3,1); W # optional - sage.combinat sage.groups 3-colored permutations of size 1 - sage: [t.character_value() for t in W] + sage: [t.character_value() for t in W] # optional - sage.combinat sage.groups [1, zeta3, -zeta3 - 1] """ return self.to_matrix().trace() @@ -622,20 +624,20 @@ def reflection_length(self, in_unitary_group=False): EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 1, 2, 2] - sage: W = ReflectionGroup((2,1,2)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((2,1,2)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 1, 1, 2, 2, 2] - sage: W = ReflectionGroup((2,2,2)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((2,2,2)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 2] - sage: W = ReflectionGroup((3,1,2)) # optional - gap3 - sage: sorted([t.reflection_length() for t in W]) # optional - gap3 + sage: W = ReflectionGroup((3,1,2)) # optional - gap3 + sage: sorted([t.reflection_length() for t in W]) # optional - gap3 [0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] """ W = self.parent() @@ -655,7 +657,8 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().Finite().Irreducible().example() # optional - gap3 + sage: C = ComplexReflectionGroups().Finite().Irreducible() + sage: C.example() # optional - gap3 Irreducible complex reflection group of rank 3 and type G(4,2,3) """ from sage.combinat.root_system.reflection_group_real import ReflectionGroup @@ -733,23 +736,26 @@ def absolute_order_ideal(self, gens=None, EXAMPLES:: - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted( w.reduced_word() for w in W.absolute_order_ideal() ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.absolute_order_ideal()) [[], [1], [1, 2], [1, 2, 1], [2]] - sage: sorted( w.reduced_word() for w in W.absolute_order_ideal(W.from_reduced_word([2,1])) ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.absolute_order_ideal(W.from_reduced_word([2,1]))) [[], [1], [1, 2, 1], [2], [2, 1]] - sage: sorted( w.reduced_word() for w in W.absolute_order_ideal(W.from_reduced_word([2])) ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.absolute_order_ideal(W.from_reduced_word([2]))) [[], [2]] - sage: W = CoxeterGroup(['A', 3]) - sage: len(list(W.absolute_order_ideal())) + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: len(list(W.absolute_order_ideal())) # optional - sage.combinat sage.groups 14 - sage: W = CoxeterGroup(['A', 2]) - sage: for (w, l) in W.absolute_order_ideal(return_lengths=True): + sage: W = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: for (w, l) in W.absolute_order_ideal(return_lengths=True): # optional - sage.combinat sage.groups ....: print(w.reduced_word(), l) [1, 2] 2 [1, 2, 1] 1 @@ -793,9 +799,10 @@ def elements_below_coxeter_element(self, c=None): TESTS:: - sage: W = CoxeterGroup(['A', 3]) - sage: len(list(W.elements_below_coxeter_element())) - doctest:...: DeprecationWarning: The method elements_below_coxeter_element is deprecated. Please use absolute_order_ideal instead. + sage: W = CoxeterGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: len(list(W.elements_below_coxeter_element())) # optional - sage.combinat sage.groups + doctest:...: DeprecationWarning: The method elements_below_coxeter_element + is deprecated. Please use absolute_order_ideal instead. See https://github.com/sagemath/sage/issues/27924 for details. 14 """ @@ -835,23 +842,28 @@ def noncrossing_partition_lattice(self, c=None, L=None, EXAMPLES:: - sage: W = SymmetricGroup(4) - sage: W.noncrossing_partition_lattice() + sage: W = SymmetricGroup(4) # optional - sage.combinat sage.groups + sage: W.noncrossing_partition_lattice() # optional - sage.combinat sage.groups Finite lattice containing 14 elements - sage: W = WeylGroup(['G', 2]) - sage: W.noncrossing_partition_lattice() + sage: W = WeylGroup(['G', 2]) # optional - sage.combinat sage.groups + sage: W.noncrossing_partition_lattice() # optional - sage.combinat sage.groups Finite lattice containing 8 elements - sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted( w.reduced_word() for w in W.noncrossing_partition_lattice() ) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.noncrossing_partition_lattice()) [[], [1], [1, 2], [1, 2, 1], [2]] - sage: sorted( w.reduced_word() for w in W.noncrossing_partition_lattice(W.from_reduced_word([2,1])) ) # optional - gap3 + sage: c21 = W.from_reduced_word([2,1]) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.noncrossing_partition_lattice(c21)) [[], [1], [1, 2, 1], [2], [2, 1]] - sage: sorted( w.reduced_word() for w in W.noncrossing_partition_lattice(W.from_reduced_word([2])) ) # optional - gap3 + sage: c2 = W.from_reduced_word([2]) # optional - gap3 + sage: sorted(w.reduced_word() # optional - gap3 + ....: for w in W.noncrossing_partition_lattice(c2)) [[], [2]] """ from sage.combinat.posets.posets import Poset @@ -899,8 +911,9 @@ def generalized_noncrossing_partitions(self, m, c=None, positive=False): sage: W = ReflectionGroup((1,1,3)) # optional - gap3 + sage: chains = W.generalized_noncrossing_partitions(2) # optional - gap3 sage: sorted([w.reduced_word() for w in chain] # optional - gap3 - ....: for chain in W.generalized_noncrossing_partitions(2)) + ....: for chain in chains) [[[], [], [1, 2]], [[], [1], [2]], [[], [1, 2], []], @@ -914,8 +927,10 @@ def generalized_noncrossing_partitions(self, m, c=None, positive=False): [[2], [], [1, 2, 1]], [[2], [1, 2, 1], []]] + sage: chains = W.generalized_noncrossing_partitions(2, # optional - gap3 + ....: positive=True) sage: sorted([w.reduced_word() for w in chain] # optional - gap3 - ....: for chain in W.generalized_noncrossing_partitions(2, positive=True)) + ....: for chain in chains) [[[], [1, 2], []], [[], [1, 2, 1], [1]], [[1], [2], []], @@ -987,14 +1002,14 @@ def absolute_poset(self, in_unitary_group=False): TESTS:: - sage: W1 = CoxeterGroup(['A',2]) - sage: W2 = WeylGroup(['A',2]) - sage: W3 = SymmetricGroup(3) - sage: W1.absolute_poset() + sage: W1 = CoxeterGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: W2 = WeylGroup(['A', 2]) # optional - sage.combinat sage.groups + sage: W3 = SymmetricGroup(3) # optional - sage.combinat sage.groups + sage: W1.absolute_poset() # optional - sage.combinat sage.groups Finite poset containing 6 elements - sage: W2.absolute_poset() + sage: W2.absolute_poset() # optional - sage.combinat sage.groups Finite poset containing 6 elements - sage: W3.absolute_poset() + sage: W3.absolute_poset() # optional - sage.combinat sage.groups Finite poset containing 6 elements """ return self.noncrossing_partition_lattice(L=tuple(self), in_unitary_group=in_unitary_group) @@ -1008,7 +1023,8 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().Finite().WellGenerated().example() # optional - gap3 + sage: C = ComplexReflectionGroups().Finite().WellGenerated() + sage: C.example() # optional - gap3 Reducible complex reflection group of rank 4 and type A2 x G(3,1,2) """ from sage.combinat.root_system.reflection_group_real import ReflectionGroup @@ -1062,12 +1078,15 @@ def coxeter_elements(self): EXAMPLES:: sage: W = ReflectionGroup((1,1,3)) # optional - gap3 - sage: sorted(c.reduced_word() for c in W.coxeter_elements()) # optional - gap3 + sage: sorted(c.reduced_word() # optional - gap3 + ....: for c in W.coxeter_elements()) [[1, 2], [2, 1]] sage: W = ReflectionGroup((1,1,4)) # optional - gap3 - sage: sorted(c.reduced_word() for c in W.coxeter_elements()) # optional - gap3 - [[1, 2, 1, 3, 2], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 1, 3, 2, 1], [3, 2, 1]] + sage: sorted(c.reduced_word() # optional - gap3 + ....: for c in W.coxeter_elements()) + [[1, 2, 1, 3, 2], [1, 2, 3], [1, 3, 2], + [2, 1, 3], [2, 1, 3, 2, 1], [3, 2, 1]] """ return self.coxeter_element().conjugacy_class() @@ -1084,7 +1103,8 @@ def example(self): EXAMPLES:: sage: from sage.categories.complex_reflection_groups import ComplexReflectionGroups - sage: ComplexReflectionGroups().Finite().WellGenerated().Irreducible().example() + sage: C = ComplexReflectionGroups().Finite().WellGenerated().Irreducible() + sage: C.example() # optional - sage.combinat sage.groups 4-colored permutations of size 3 """ from sage.combinat.colored_permutations import ColoredPermutations @@ -1109,12 +1129,12 @@ def coxeter_number(self): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: W.coxeter_number() + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: W.coxeter_number() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(4,3) - sage: W.coxeter_number() + sage: W = ColoredPermutations(4,3) # optional - sage.combinat sage.groups + sage: W.coxeter_number() # optional - sage.combinat sage.groups 12 sage: W = ReflectionGroup((4,4,3)) # optional - gap3 @@ -1130,20 +1150,20 @@ def number_of_reflections_of_full_support(self): EXAMPLES:: - sage: W = Permutations(4) - sage: W.number_of_reflections_of_full_support() + sage: W = Permutations(4) # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 1 - sage: W = ColoredPermutations(1,4) - sage: W.number_of_reflections_of_full_support() + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 1 - sage: W = CoxeterGroup("B3") - sage: W.number_of_reflections_of_full_support() + sage: W = CoxeterGroup("B3") # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 3 - sage: W = ColoredPermutations(3,3) - sage: W.number_of_reflections_of_full_support() + sage: W = ColoredPermutations(3,3) # optional - sage.combinat sage.groups + sage: W.number_of_reflections_of_full_support() # optional - sage.combinat sage.groups 3 """ n = self.rank() @@ -1175,18 +1195,18 @@ def rational_catalan_number(self, p, polynomial=False): EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: [W.rational_catalan_number(p) for p in [5,7,8]] + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: [W.rational_catalan_number(p) for p in [5,7,8]] # optional - sage.combinat sage.groups [7, 12, 15] - sage: W = ColoredPermutations(2,2) - sage: [W.rational_catalan_number(p) for p in [7,9,11]] + sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups + sage: [W.rational_catalan_number(p) for p in [7,9,11]] # optional - sage.combinat sage.groups [10, 15, 21] TESTS:: - sage: W = ColoredPermutations(1,4) - sage: W.rational_catalan_number(3, polynomial=True) + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: W.rational_catalan_number(3, polynomial=True) # optional - sage.combinat sage.groups q^6 + q^4 + q^3 + q^2 + 1 """ from sage.arith.misc import GCD as gcd @@ -1243,37 +1263,37 @@ def fuss_catalan_number(self, m, positive=False, EXAMPLES:: - sage: W = ColoredPermutations(1,3) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + sage: W = ColoredPermutations(1,3) # optional - sage.combinat sage.groups + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups [5, 12, 22] - sage: W = ColoredPermutations(1,4) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + sage: W = ColoredPermutations(1,4) # optional - sage.combinat sage.groups + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups [14, 55, 140] - sage: W = ColoredPermutations(1,5) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + sage: W = ColoredPermutations(1,5) # optional - sage.combinat sage.groups + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups [42, 273, 969] - sage: W = ColoredPermutations(2,2) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups [6, 15, 28] - sage: W = ColoredPermutations(2,3) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + sage: W = ColoredPermutations(2,3) # optional - sage.combinat sage.groups + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups [20, 84, 220] - sage: W = ColoredPermutations(2,4) - sage: [W.fuss_catalan_number(i) for i in [1,2,3]] + sage: W = ColoredPermutations(2,4) # optional - sage.combinat sage.groups + sage: [W.fuss_catalan_number(i) for i in [1,2,3]] # optional - sage.combinat sage.groups [70, 495, 1820] TESTS:: - sage: W = ColoredPermutations(2,4) - sage: W.fuss_catalan_number(2,positive=True) + sage: W = ColoredPermutations(2,4) # optional - sage.combinat sage.groups + sage: W.fuss_catalan_number(2, positive=True) # optional - sage.combinat sage.groups 330 - sage: W = ColoredPermutations(2,2) - sage: W.fuss_catalan_number(2,polynomial=True) + sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups + sage: W.fuss_catalan_number(2, polynomial=True) # optional - sage.combinat sage.groups q^16 + q^14 + 2*q^12 + 2*q^10 + 3*q^8 + 2*q^6 + 2*q^4 + q^2 + 1 """ @@ -1317,22 +1337,25 @@ def catalan_number(self, positive=False, polynomial=False): EXAMPLES:: - sage: [ColoredPermutations(1,n).catalan_number() for n in [3,4,5]] + sage: [ColoredPermutations(1,n).catalan_number() # optional - sage.combinat sage.groups + ....: for n in [3,4,5]] [5, 14, 42] - sage: [ColoredPermutations(2,n).catalan_number() for n in [3,4,5]] + sage: [ColoredPermutations(2,n).catalan_number() # optional - sage.combinat sage.groups + ....: for n in [3,4,5]] [20, 70, 252] - sage: [ReflectionGroup((2,2,n)).catalan_number() for n in [3,4,5]] # optional - gap3 + sage: [ReflectionGroup((2,2,n)).catalan_number() # optional - gap3 + ....: for n in [3,4,5]] [14, 50, 182] TESTS:: - sage: W = ColoredPermutations(3,6) - sage: W.catalan_number(positive=True) + sage: W = ColoredPermutations(3,6) # optional - sage.combinat sage.groups + sage: W.catalan_number(positive=True) # optional - sage.combinat sage.groups 462 - sage: W = ColoredPermutations(2,2) - sage: W.catalan_number(polynomial=True) + sage: W = ColoredPermutations(2,2) # optional - sage.combinat sage.groups + sage: W.catalan_number(polynomial=True) # optional - sage.combinat sage.groups q^8 + q^6 + 2*q^4 + q^2 + 1 """ return self.fuss_catalan_number(1, positive=positive, diff --git a/src/sage/categories/finite_coxeter_groups.py b/src/sage/categories/finite_coxeter_groups.py index 270341c2262..0ec68ca2b99 100644 --- a/src/sage/categories/finite_coxeter_groups.py +++ b/src/sage/categories/finite_coxeter_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.groups r""" Finite Coxeter Groups """ diff --git a/src/sage/categories/finite_crystals.py b/src/sage/categories/finite_crystals.py index 072df1f9c53..f920da8b877 100644 --- a/src/sage/categories/finite_crystals.py +++ b/src/sage/categories/finite_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Finite Crystals """ diff --git a/src/sage/categories/finite_dimensional_algebras_with_basis.py b/src/sage/categories/finite_dimensional_algebras_with_basis.py index 542cf09d425..cc7c7969b58 100644 --- a/src/sage/categories/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_algebras_with_basis.py @@ -90,29 +90,29 @@ def radical_basis(self): We construct the group algebra of the Klein Four-Group over the rationals:: - sage: A = KleinFourGroup().algebra(QQ) + sage: A = KleinFourGroup().algebra(QQ) # optional - sage.groups sage.modules This algebra belongs to the category of finite dimensional algebras over the rationals:: - sage: A in Algebras(QQ).FiniteDimensional().WithBasis() + sage: A in Algebras(QQ).FiniteDimensional().WithBasis() # optional - sage.groups sage.modules True Since the field has characteristic `0`, Maschke's Theorem tells us that the group algebra is semisimple. So its radical is the zero ideal:: - sage: A in Algebras(QQ).Semisimple() + sage: A in Algebras(QQ).Semisimple() # optional - sage.groups sage.modules True - sage: A.radical_basis() + sage: A.radical_basis() # optional - sage.groups sage.modules () Let's work instead over a field of characteristic `2`:: - sage: A = KleinFourGroup().algebra(GF(2)) - sage: A in Algebras(GF(2)).Semisimple() + sage: A = KleinFourGroup().algebra(GF(2)) # optional - sage.groups sage.rings.finite_rings sage.modules + sage: A in Algebras(GF(2)).Semisimple() # optional - sage.groups sage.rings.finite_rings sage.modules False - sage: A.radical_basis() + sage: A.radical_basis() # optional - sage.groups sage.rings.finite_rings sage.modules (() + (1,2)(3,4), (3,4) + (1,2)(3,4), (1,2) + (1,2)(3,4)) We now implement the algebra `A = K[x] / (x^p-1)`, where `K` @@ -120,7 +120,7 @@ def radical_basis(self): radical; alas, we currently need to wrap `A` to make it a proper :class:`ModulesWithBasis`:: - sage: class AnAlgebra(CombinatorialFreeModule): + sage: class AnAlgebra(CombinatorialFreeModule): # optional - sage.modules ....: def __init__(self, F): ....: R. = PolynomialRing(F) ....: I = R.ideal(x**F.characteristic()-F.one()) @@ -132,24 +132,24 @@ def radical_basis(self): ....: return self.basis()[self.base_ring().one()] ....: def product_on_basis(self, w1, w2): ....: return self.from_vector(vector(w1*w2)) - sage: AnAlgebra(GF(3)).radical_basis() + sage: AnAlgebra(GF(3)).radical_basis() # optional - sage.rings.finite_rings sage.modules (B[1] + 2*B[xbar^2], B[xbar] + 2*B[xbar^2]) - sage: AnAlgebra(GF(16,'a')).radical_basis() + sage: AnAlgebra(GF(16,'a')).radical_basis() # optional - sage.rings.finite_rings sage.modules (B[1] + B[xbar],) - sage: AnAlgebra(GF(49,'a')).radical_basis() + sage: AnAlgebra(GF(49,'a')).radical_basis() # optional - sage.rings.finite_rings sage.modules (B[1] + 6*B[xbar^6], B[xbar] + 6*B[xbar^6], B[xbar^2] + 6*B[xbar^6], B[xbar^3] + 6*B[xbar^6], B[xbar^4] + 6*B[xbar^6], B[xbar^5] + 6*B[xbar^6]) TESTS:: - sage: A = KleinFourGroup().algebra(GF(2)) - sage: A.radical_basis() + sage: A = KleinFourGroup().algebra(GF(2)) # optional - sage.groups sage.rings.finite_rings sage.modules + sage: A.radical_basis() # optional - sage.groups sage.rings.finite_rings sage.modules (() + (1,2)(3,4), (3,4) + (1,2)(3,4), (1,2) + (1,2)(3,4)) - sage: A = KleinFourGroup().algebra(QQ, category=Monoids()) - sage: A.radical_basis.__module__ + sage: A = KleinFourGroup().algebra(QQ, category=Monoids()) # optional - sage.groups sage.modules + sage: A.radical_basis.__module__ # optional - sage.groups sage.modules 'sage.categories.finite_dimensional_algebras_with_basis' - sage: A.radical_basis() + sage: A.radical_basis() # optional - sage.groups sage.modules () """ F = self.base_ring() @@ -292,10 +292,10 @@ def semisimple_quotient(self): descent algebra of the symmetric group is of dimension the number of partitions of `n`:: - sage: [ DescentAlgebra(QQ,n).B().semisimple_quotient().dimension() + sage: [ DescentAlgebra(QQ,n).B().semisimple_quotient().dimension() # optional - sage.combinat ....: for n in range(6) ] [1, 1, 2, 3, 5, 7] - sage: [Partitions(n).cardinality() for n in range(10)] + sage: [Partitions(n).cardinality() for n in range(10)] # optional - sage.combinat [1, 1, 2, 3, 5, 7, 11, 15, 22, 30] .. TODO:: @@ -365,7 +365,8 @@ def center(self): The center of a semisimple algebra is semisimple:: - sage: DihedralGroup(6).algebra(QQ).center() in Algebras(QQ).Semisimple() + sage: A = DihedralGroup(6).algebra(QQ) + sage: A.center() in Algebras(QQ).Semisimple() # optional - sage.groups sage.modules True .. TODO:: @@ -473,7 +474,7 @@ def orthogonal_idempotents_central_mod_radical(self): An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: A.orthogonal_idempotents_central_mod_radical() + sage: A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field (x, y) :: @@ -496,7 +497,8 @@ def orthogonal_idempotents_central_mod_radical(self): True sage: all(e*e == e for e in idempotents) True - sage: all(e*f == 0 and f*e == 0 for e in idempotents for f in idempotents if e != f) + sage: all(e*f == 0 and f*e == 0 + ....: for e in idempotents for f in idempotents if e != f) True This is best tested with:: @@ -645,8 +647,8 @@ def cartan_invariants_matrix(self): in characteristic zero, the Cartan invariants matrix is the identity:: - sage: A3 = SymmetricGroup(3).algebra(QQ) - sage: A3.cartan_invariants_matrix() + sage: A3 = SymmetricGroup(3).algebra(QQ) # optional - sage.groups sage.modules + sage: A3.cartan_invariants_matrix() # optional - sage.groups sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -655,7 +657,7 @@ def cartan_invariants_matrix(self): matrix counts the number of paths between two vertices:: sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example() - sage: A.cartan_invariants_matrix() + sage: A.cartan_invariants_matrix() # optional - sage.modules sage.rings.number_field [1 2] [0 1] @@ -663,8 +665,8 @@ def cartan_invariants_matrix(self): sage: Z12 = Monoids().Finite().example(); Z12 An example of a finite multiplicative monoid: the integers modulo 12 - sage: A = Z12.algebra(QQ) - sage: A.cartan_invariants_matrix() + sage: A = Z12.algebra(QQ) # optional - sage.modules + sage: A.cartan_invariants_matrix() # optional - sage.modules [1 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0] [0 0 2 0 0 0 0 0 0] @@ -677,9 +679,9 @@ def cartan_invariants_matrix(self): With the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) - sage: A.cartan_invariants_matrix() + sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups sage.modules + sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups sage.modules + sage: A.cartan_invariants_matrix() # optional - sage.groups sage.modules [1 0 0 0 0 0 0 0] [0 2 1 0 1 1 0 0] [0 1 1 0 1 0 0 0] @@ -739,10 +741,10 @@ def isotypic_projective_modules(self, side='left'): An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: Q = A.isotypic_projective_modules(side="left"); Q + sage: Q = A.isotypic_projective_modules(side="left"); Q # optional - sage.rings.number_field [Free module generated by {0} over Rational Field, Free module generated by {0, 1, 2} over Rational Field] - sage: [[x.lift() for x in Qi.basis()] + sage: [[x.lift() for x in Qi.basis()] # optional - sage.rings.number_field ....: for Qi in Q] [[x], [y, a, b]] @@ -750,7 +752,7 @@ def isotypic_projective_modules(self, side='left'): We check that the sum of the dimensions of the isotypic projective modules is the dimension of ``self``:: - sage: sum([Qi.dimension() for Qi in Q]) == A.dimension() + sage: sum([Qi.dimension() for Qi in Q]) == A.dimension() # optional - sage.rings.number_field True .. SEEALSO:: @@ -782,19 +784,19 @@ def peirce_summand(self, ei, ej): EXAMPLES:: sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example() - sage: idemp = A.orthogonal_idempotents_central_mod_radical() - sage: A.peirce_summand(idemp[0], idemp[1]) + sage: idemp = A.orthogonal_idempotents_central_mod_radical() # optional - sage.rings.number_field + sage: A.peirce_summand(idemp[0], idemp[1]) # optional - sage.rings.number_field Free module generated by {0, 1} over Rational Field - sage: A.peirce_summand(idemp[1], idemp[0]) + sage: A.peirce_summand(idemp[1], idemp[0]) # optional - sage.rings.number_field Free module generated by {} over Rational Field We recover the `2\times2` block of `\QQ[S_4]` corresponding to the unique simple module of dimension `2` of the symmetric group `S_4`:: - sage: A4 = SymmetricGroup(4).algebra(QQ) - sage: e = A4.central_orthogonal_idempotents()[2] - sage: A4.peirce_summand(e, e) + sage: A4 = SymmetricGroup(4).algebra(QQ) # optional - sage.groups + sage: e = A4.central_orthogonal_idempotents()[2] # optional - sage.groups sage.rings.number_field + sage: A4.peirce_summand(e, e) # optional - sage.groups sage.rings.number_field Free module generated by {0, 1, 2, 3} over Rational Field TESTS: @@ -802,11 +804,11 @@ def peirce_summand(self, ei, ej): We check each idempotent belong to its own Peirce summand (see :trac:`24687`):: - sage: from sage.monoids.hecke_monoid import HeckeMonoid - sage: M = HeckeMonoid(SymmetricGroup(4)) - sage: A = M.algebra(QQ) - sage: Idms = A.orthogonal_idempotents_central_mod_radical() - sage: all(A.peirce_summand(e, e).retract(e) + sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups + sage: M = HeckeMonoid(SymmetricGroup(4)) # optional - sage.groups + sage: A = M.algebra(QQ) # optional - sage.groups + sage: Idms = A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups sage.rings.number_field + sage: all(A.peirce_summand(e, e).retract(e) # optional - sage.groups sage.rings.number_field ....: in A.peirce_summand(e, e) for e in Idms) True """ @@ -863,14 +865,14 @@ def peirce_decomposition(self, idempotents=None, check=True): An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: A.orthogonal_idempotents_central_mod_radical() + sage: A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups (x, y) - sage: decomposition = A.peirce_decomposition(); decomposition + sage: decomposition = A.peirce_decomposition(); decomposition # optional - sage.groups sage.modules sage.rings.number_field [[Free module generated by {0} over Rational Field, Free module generated by {0, 1} over Rational Field], [Free module generated by {} over Rational Field, Free module generated by {0} over Rational Field]] - sage: [ [[x.lift() for x in decomposition[i][j].basis()] + sage: [ [[x.lift() for x in decomposition[i][j].basis()] # optional - sage.groups sage.modules sage.rings.number_field ....: for j in range(2)] ....: for i in range(2)] [[[x], [a, b]], @@ -879,9 +881,9 @@ def peirce_decomposition(self, idempotents=None, check=True): We recover that the group algebra of the symmetric group `S_4` is a block matrix algebra:: - sage: A = SymmetricGroup(4).algebra(QQ) - sage: decomposition = A.peirce_decomposition() # long time - sage: [[decomposition[i][j].dimension() # long time (4s) + sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules + sage: decomposition = A.peirce_decomposition() # long time # optional - sage.groups sage.modules sage.rings.number_field + sage: [[decomposition[i][j].dimension() # long time (4s) # optional - sage.groups sage.modules sage.rings.number_field ....: for j in range(len(decomposition))] ....: for i in range(len(decomposition))] [[9, 0, 0, 0, 0], @@ -894,7 +896,7 @@ def peirce_decomposition(self, idempotents=None, check=True): dimension of the corresponding simple module of `S_4`. The latter are given by:: - sage: [p.standard_tableaux().cardinality() for p in Partitions(4)] + sage: [p.standard_tableaux().cardinality() for p in Partitions(4)] # optional - sage.combinat [1, 3, 2, 3, 1] """ if idempotents is None: @@ -926,9 +928,9 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): sage: A.is_identity_decomposition_into_orthogonal_idempotents([A.one()]) True - sage: A.is_identity_decomposition_into_orthogonal_idempotents([x,y]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([x, y]) True - sage: A.is_identity_decomposition_into_orthogonal_idempotents([x+a, y-a]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([x + a, y - a]) True Here the idempotents do not sum up to `1`:: @@ -938,15 +940,15 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): Here `1+x` and `-x` are neither idempotent nor orthogonal:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents([1+x,-x]) + sage: A.is_identity_decomposition_into_orthogonal_idempotents([1 + x, -x]) False With the algebra of the `0`-Hecke monoid:: - sage: from sage.monoids.hecke_monoid import HeckeMonoid - sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) - sage: idempotents = A.orthogonal_idempotents_central_mod_radical() - sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) + sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups + sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ) # optional - sage.groups sage.modules + sage: idempotents = A.orthogonal_idempotents_central_mod_radical() # optional - sage.groups sage.modules sage.rings.number_field + sage: A.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.groups sage.modules sage.rings.number_field True Here are some more counterexamples: @@ -992,19 +994,19 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l): 2. Some idempotents summing to 1 but not orthogonal:: - sage: R. = PolynomialRing(GF(2)) - sage: A = PQAlgebra(GF(2), x) - sage: a = A.one() - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,)) + sage: R. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: A = PQAlgebra(GF(2), x) # optional - sage.rings.finite_rings + sage: a = A.one() # optional - sage.rings.finite_rings + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,)) # optional - sage.rings.finite_rings True - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, a, a)) + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a, a, a)) # optional - sage.rings.finite_rings False 3. Some orthogonal idempotents not summing to the identity:: - sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,a)) + sage: A.is_identity_decomposition_into_orthogonal_idempotents((a,a)) # optional - sage.rings.finite_rings False - sage: A.is_identity_decomposition_into_orthogonal_idempotents(()) + sage: A.is_identity_decomposition_into_orthogonal_idempotents(()) # optional - sage.rings.finite_rings False """ return (self.sum(l) == self.one() @@ -1019,11 +1021,11 @@ def is_commutative(self): EXAMPLES:: - sage: S4 = SymmetricGroupAlgebra(QQ, 4) - sage: S4.is_commutative() + sage: S4 = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S4.is_commutative() # optional - sage.groups sage.modules False - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S2.is_commutative() + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S2.is_commutative() # optional - sage.groups sage.modules True """ B = list(self.basis()) @@ -1047,23 +1049,23 @@ def to_matrix(self, base_ring=None, action=operator.mul, side='left'): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) - sage: a = QS3([2,1,3]) - sage: a.to_matrix(side='left') + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: a = QS3([2,1,3]) # optional - sage.groups sage.modules + sage: a.to_matrix(side='left') # optional - sage.groups sage.modules [0 0 1 0 0 0] [0 0 0 0 1 0] [1 0 0 0 0 0] [0 0 0 0 0 1] [0 1 0 0 0 0] [0 0 0 1 0 0] - sage: a.to_matrix(side='right') + sage: a.to_matrix(side='right') # optional - sage.groups sage.modules [0 0 1 0 0 0] [0 0 0 1 0 0] [1 0 0 0 0 0] [0 1 0 0 0 0] [0 0 0 0 0 1] [0 0 0 0 1 0] - sage: a.to_matrix(base_ring=RDF, side="left") + sage: a.to_matrix(base_ring=RDF, side="left") # optional - sage.groups sage.modules [0.0 0.0 1.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0 1.0 0.0] [1.0 0.0 0.0 0.0 0.0 0.0] @@ -1100,47 +1102,47 @@ def __invert__(self): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) - sage: P = Permutation - sage: a = 3 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) - sage: b = ~a; b + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: P = Permutation # optional - sage.groups sage.modules + sage: a = 3 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) # optional - sage.groups sage.modules + sage: b = ~a; b # optional - sage.groups sage.modules 9/20*[1, 2, 3] - 7/40*[1, 3, 2] - 7/40*[2, 1, 3] + 3/40*[2, 3, 1] + 3/40*[3, 1, 2] - 1/20*[3, 2, 1] - sage: a * b + sage: a * b # optional - sage.groups sage.modules [1, 2, 3] - sage: ~b == a + sage: ~b == a # optional - sage.groups sage.modules True - sage: a = 3 * QS3.one() - sage: b = ~a - sage: b * a == QS3.one() + sage: a = 3 * QS3.one() # optional - sage.groups sage.modules + sage: b = ~a # optional - sage.groups sage.modules + sage: b * a == QS3.one() # optional - sage.groups sage.modules True - sage: b == 1/3 * QS3.one() + sage: b == 1/3 * QS3.one() # optional - sage.groups sage.modules True - sage: ~b == a + sage: ~b == a # optional - sage.groups sage.modules True sage: R. = QQ[] - sage: RS3 = SymmetricGroupAlgebra(R, 3) - sage: a = RS3(P([1,2,3])) - RS3(P([1,3,2])) + RS3(P([2,1,3])); ~a + sage: RS3 = SymmetricGroupAlgebra(R, 3) # optional - sage.groups sage.modules + sage: a = RS3(P([1,2,3])) - RS3(P([1,3,2])) + RS3(P([2,1,3])); ~a # optional - sage.groups sage.modules -1/2*[1, 3, 2] + 1/2*[2, 1, 3] + 1/2*[2, 3, 1] + 1/2*[3, 1, 2] Some examples on elements that do not have an inverse:: - sage: c = 2 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) - sage: ~c + sage: c = 2 * QS3(P([1,2,3])) + QS3(P([1,3,2])) + QS3(P([2,1,3])) # optional - sage.groups sage.modules + sage: ~c # optional - sage.groups sage.modules Traceback (most recent call last): ... ValueError: cannot invert self (= 2*[1, 2, 3] + [1, 3, 2] + [2, 1, 3]) - sage: ZS3 = SymmetricGroupAlgebra(ZZ, 3) - sage: aZ = 3 * ZS3(P([1,2,3])) + ZS3(P([1,3,2])) + ZS3(P([2,1,3])) - sage: ~aZ + sage: ZS3 = SymmetricGroupAlgebra(ZZ, 3) # optional - sage.groups sage.modules + sage: aZ = 3 * ZS3(P([1,2,3])) + ZS3(P([1,3,2])) + ZS3(P([2,1,3])) # optional - sage.groups sage.modules + sage: ~aZ # optional - sage.groups sage.modules Traceback (most recent call last): ... ValueError: cannot invert self (= 3*[1, 2, 3] + [1, 3, 2] + [2, 1, 3]) - sage: x = 2 * ZS3.one() - sage: ~x + sage: x = 2 * ZS3.one() # optional - sage.groups sage.modules + sage: ~x # optional - sage.groups sage.modules Traceback (most recent call last): ... ValueError: cannot invert self (= 2*[1, 2, 3]) @@ -1149,9 +1151,9 @@ def __invert__(self): An algebra that does not define ``one_basis()``:: - sage: I = DescentAlgebra(QQ, 3).I() - sage: a = 3 * I.one() - sage: ~a == 1/3 * I.one() + sage: I = DescentAlgebra(QQ, 3).I() # optional - sage.combinat sage.modules + sage: a = 3 * I.one() # optional - sage.combinat sage.modules + sage: ~a == 1/3 * I.one() # optional - sage.combinat sage.modules True """ alg = self.parent() @@ -1239,8 +1241,8 @@ def _test_cellular(self, **options): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S._test_cellular() + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: S._test_cellular() # optional - sage.combinat sage.modules """ tester = self._tester(**options) cell_basis = self.cellular_basis() @@ -1273,8 +1275,8 @@ def cell_poset(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: S.cell_poset() + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S.cell_poset() # optional - sage.groups sage.modules Finite poset containing 5 elements """ @@ -1288,8 +1290,8 @@ def cell_module_indices(self, mu): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S.cell_module_indices([2,1]) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S.cell_module_indices([2,1]) # optional - sage.groups sage.modules Standard tableaux of shape [2, 1] """ @@ -1301,8 +1303,8 @@ def _to_cellular_element(self, i): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S._to_cellular_element # no implementation currently uses this + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S._to_cellular_element # no implementation currently uses this # optional - sage.groups sage.modules NotImplemented """ @@ -1314,13 +1316,12 @@ def _from_cellular_index(self, x): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: mu = Partition([2,1]) - sage: s = StandardTableau([[1,2],[3]]) - sage: t = StandardTableau([[1,3],[2]]) - sage: S._from_cellular_index((mu, s, t)) - 1/4*[1, 3, 2] - 1/4*[2, 3, 1] + 1/4*[3, 1, 2] - - 1/4*[3, 2, 1] + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.groups sage.modules + sage: mu = Partition([2,1]) # optional - sage.combinat sage.groups sage.modules + sage: s = StandardTableau([[1,2],[3]]) # optional - sage.combinat sage.groups sage.modules + sage: t = StandardTableau([[1,3],[2]]) # optional - sage.combinat sage.groups sage.modules + sage: S._from_cellular_index((mu, s, t)) # optional - sage.combinat sage.groups sage.modules + 1/4*[1, 3, 2] - 1/4*[2, 3, 1] + 1/4*[3, 1, 2] - 1/4*[3, 2, 1] """ def cellular_involution(self, x): @@ -1329,8 +1330,8 @@ def cellular_involution(self, x): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: for b in S.basis(): b, S.cellular_involution(b) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: for b in S.basis(): b, S.cellular_involution(b) # optional - sage.groups sage.modules ([1, 2, 3], [1, 2, 3]) ([1, 3, 2], 49/48*[1, 3, 2] + 7/48*[2, 3, 1] - 7/48*[3, 1, 2] - 1/48*[3, 2, 1]) @@ -1356,8 +1357,8 @@ def cells(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: dict(S.cells()) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: dict(S.cells()) # optional - sage.groups sage.modules {[1, 1, 1]: Standard tableaux of shape [1, 1, 1], [2, 1]: Standard tableaux of shape [2, 1], [3]: Standard tableaux of shape [3]} @@ -1371,8 +1372,8 @@ def cellular_basis(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S.cellular_basis() + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S.cellular_basis() # optional - sage.groups sage.modules Cellular basis of Symmetric group algebra of order 3 over Rational Field """ @@ -1385,8 +1386,8 @@ def cell_module(self, mu, **kwds): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 3) - sage: S.cell_module(Partition([2,1])) + sage: S = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: S.cell_module(Partition([2,1])) # optional - sage.combinat sage.groups sage.modules Cell module indexed by [2, 1] of Cellular basis of Symmetric group algebra of order 3 over Rational Field """ @@ -1404,8 +1405,8 @@ def simple_module_parameterization(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: S.simple_module_parameterization() + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S.simple_module_parameterization() # optional - sage.groups sage.modules ([4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]) """ return tuple([mu for mu in self.cell_poset() @@ -1418,12 +1419,12 @@ def cellular_involution(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: elt = S([3,1,2,4]) - sage: ci = elt.cellular_involution(); ci + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: elt = S([3,1,2,4]) # optional - sage.groups sage.modules + sage: ci = elt.cellular_involution(); ci # optional - sage.groups sage.modules 7/48*[1, 3, 2, 4] + 49/48*[2, 3, 1, 4] - 1/48*[3, 1, 2, 4] - 7/48*[3, 2, 1, 4] - sage: ci.cellular_involution() + sage: ci.cellular_involution() # optional - sage.groups sage.modules [3, 1, 2, 4] """ return self.parent().cellular_involution(self) @@ -1455,10 +1456,10 @@ def cell_poset(self): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: T.cell_poset() + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: T = S2.tensor(S3) # optional - sage.groups sage.modules + sage: T.cell_poset() # optional - sage.combinat sage.graphs sage.groups sage.modules Finite poset containing 6 elements """ ret = self._sets[0].cell_poset() @@ -1475,10 +1476,10 @@ def cell_module_indices(self, mu): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: T.cell_module_indices(([1,1], [2,1])) + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: T = S2.tensor(S3) # optional - sage.groups sage.modules + sage: T.cell_module_indices(([1,1], [2,1])) # optional - sage.groups sage.modules The Cartesian product of (Standard tableaux of shape [1, 1], Standard tableaux of shape [2, 1]) """ @@ -1494,10 +1495,10 @@ def cellular_involution(self): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: for b in T.basis(): b, T.cellular_involution(b) + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: T = S2.tensor(S3) # optional - sage.groups sage.modules + sage: for b in T.basis(): b, T.cellular_involution(b) # optional - sage.groups sage.modules ([1, 2] # [1, 2, 3], [1, 2] # [1, 2, 3]) ([1, 2] # [1, 3, 2], 49/48*[1, 2] # [1, 3, 2] + 7/48*[1, 2] # [2, 3, 1] @@ -1547,10 +1548,10 @@ def _to_cellular_element(self, i): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: all(T(T._to_cellular_element(k)).leading_support() == k + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: T = S2.tensor(S3) # optional - sage.groups sage.modules + sage: all(T(T._to_cellular_element(k)).leading_support() == k # optional - sage.groups sage.modules ....: for k in T.basis().keys()) True """ @@ -1583,11 +1584,11 @@ def _from_cellular_index(self, x): EXAMPLES:: - sage: S2 = SymmetricGroupAlgebra(QQ, 2) - sage: S3 = SymmetricGroupAlgebra(QQ, 3) - sage: T = S2.tensor(S3) - sage: C = T.cellular_basis() - sage: all(C(T._from_cellular_index(k)).leading_support() == k + sage: S2 = SymmetricGroupAlgebra(QQ, 2) # optional - sage.groups sage.modules + sage: S3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: T = S2.tensor(S3) # optional - sage.groups sage.modules + sage: C = T.cellular_basis() # optional - sage.groups sage.modules + sage: all(C(T._from_cellular_index(k)).leading_support() == k # optional - sage.groups sage.modules ....: for k in C.basis().keys()) True """ diff --git a/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py index 4bbdf0807b1..e10e30a5846 100644 --- a/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py @@ -55,12 +55,12 @@ def _test_grading(self, **options): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # optional - sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L._test_grading() - sage: L = LieAlgebra(QQ, {('x','y'): {'x': 1}}, + sage: L._test_grading() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('x','y'): {'x': 1}}, # optional - sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L._test_grading() + sage: L._test_grading() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: Lie bracket [x, y] has degree 1, not degree 2 @@ -96,9 +96,9 @@ def homogeneous_component_as_submodule(self, d): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, # optional - sage.combinat sage.modules ....: nilpotent=True, category=C) - sage: L.homogeneous_component_as_submodule(2) + sage: L.homogeneous_component_as_submodule(2) # optional - sage.combinat sage.modules Sparse vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [0 0 1] @@ -147,12 +147,12 @@ def _test_generated_by_degree_one(self, **options): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() sage: sc = {('x','y'): {'z': 1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) - sage: L._test_generated_by_degree_one() + sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # optional - sage.combinat sage.modules + sage: L._test_generated_by_degree_one() # optional - sage.combinat sage.modules sage: sc = {('x','y'): {'z': 1}, ('a','b'): {'c':1}, ('z','c'): {'m':1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) - sage: L._test_generated_by_degree_one() + sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # optional - sage.combinat sage.modules + sage: L._test_generated_by_degree_one() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [a, b, x, y] does not generate Nilpotent Lie algebra @@ -199,16 +199,16 @@ def degree_on_basis(self, m): sage: C = LieAlgebras(QQ).WithBasis().Graded() sage: C = C.FiniteDimensional().Stratified().Nilpotent() sage: sc = {('X','Y'): {'Z': 1}} - sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) - sage: L.degree_on_basis(X.leading_support()) + sage: L. = LieAlgebra(QQ, sc, nilpotent=True, category=C) # optional - sage.combinat sage.modules + sage: L.degree_on_basis(X.leading_support()) # optional - sage.combinat sage.modules 1 - sage: X.degree() + sage: X.degree() # optional - sage.combinat sage.modules 1 - sage: Y.degree() + sage: Y.degree() # optional - sage.combinat sage.modules 1 - sage: L[X, Y] + sage: L[X, Y] # optional - sage.combinat sage.modules Z - sage: Z.degree() + sage: Z.degree() # optional - sage.combinat sage.modules 2 """ if not hasattr(self, '_basis_degrees'): diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index 487924b5748..93cbb33a545 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -46,13 +46,13 @@ def example(self, n=3): EXAMPLES:: sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() - sage: C.example() + sage: C.example() # optional - sage.modules An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field Other dimensions can be specified as an optional argument:: - sage: C.example(5) + sage: C.example(5) # optional - sage.modules An example of a finite dimensional Lie algebra with basis: the 5-dimensional abelian Lie algebra over Rational Field """ @@ -70,27 +70,27 @@ def _construct_UEA(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: UEA = L._construct_UEA(); UEA + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules sage.combinat + sage: UEA = L._construct_UEA(); UEA # optional - sage.modules sage.combinat Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} - sage: UEA.relations(add_commutative=True) + sage: UEA.relations(add_commutative=True) # optional - sage.modules sage.combinat {b1*b0: b0*b1, b2*b0: b0*b2, b2*b1: b1*b2} :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'z':1}, ('y','z'):{'x':1}, ('z','x'):{'y':1}}) - sage: UEA = L._construct_UEA(); UEA + sage: L. = LieAlgebra(QQ, {('x','y'):{'z':1}, ('y','z'):{'x':1}, ('z','x'):{'y':1}}) # optional - sage.modules sage.combinat + sage: UEA = L._construct_UEA(); UEA # optional - sage.modules sage.combinat Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: sorted(UEA.relations().items(), key=str) + sage: sorted(UEA.relations().items(), key=str) # optional - sage.modules sage.combinat [(y*x, x*y - z), (z*x, x*z + y), (z*y, y*z - x)] Singular's ``nc_algebra`` does not work over `\ZZ/6\ZZ`, so we fallback to the PBW basis in this case:: - sage: L = lie_algebras.pwitt(Zmod(6), 6) - sage: L._construct_UEA() + sage: L = lie_algebras.pwitt(Zmod(6), 6) # optional - sage.modules sage.combinat + sage: L._construct_UEA() # optional - sage.modules sage.combinat Universal enveloping algebra of The 6-Witt Lie algebra over Ring of integers modulo 6 in the Poincare-Birkhoff-Witt basis @@ -147,8 +147,8 @@ def _basis_ordering(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L._basis_ordering + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules sage.combinat + sage: L._basis_ordering # optional - sage.modules sage.combinat (0, 1, 2) """ return tuple(self.basis().keys()) @@ -161,10 +161,10 @@ def _basis_key_inverse(self): EXAMPLES:: - sage: G = SymmetricGroup(3) - sage: S = GroupAlgebra(G, QQ) - sage: L = LieAlgebra(associative=S) - sage: [L._basis_key_inverse[k] for k in L._basis_ordering] + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: S = GroupAlgebra(G, QQ) # optional - sage.groups sage.modules + sage: L = LieAlgebra(associative=S) # optional - sage.groups sage.modules + sage: [L._basis_key_inverse[k] for k in L._basis_ordering] # optional - sage.groups sage.modules [0, 1, 2, 3, 4, 5] """ return {k: i for i,k in enumerate(self._basis_ordering)} @@ -175,33 +175,33 @@ def _basis_key(self, x): TESTS:: - sage: L = lie_algebras.three_dimensional_by_rank(QQ, 3, names=['E','F','H']) - sage: PBW = L.pbw_basis() - sage: PBW._basis_key('E') < PBW._basis_key('H') + sage: L = lie_algebras.three_dimensional_by_rank(QQ, 3, names=['E','F','H']) # optional - sage.groups sage.modules + sage: PBW = L.pbw_basis() # optional - sage.groups sage.modules + sage: PBW._basis_key('E') < PBW._basis_key('H') # optional - sage.groups sage.modules True :: - sage: L = lie_algebras.sl(QQ, 2) - sage: def neg_key(x): + sage: L = lie_algebras.sl(QQ, 2) # optional - sage.groups sage.modules + sage: def neg_key(x): # optional - sage.groups sage.modules ....: return -L.basis().keys().index(x) - sage: PBW = L.pbw_basis(basis_key=neg_key) - sage: prod(PBW.gens()) # indirect doctest + sage: PBW = L.pbw_basis(basis_key=neg_key) # optional - sage.groups sage.modules + sage: prod(PBW.gens()) # indirect doctest # optional - sage.groups sage.modules PBW[-alpha[1]]*PBW[alphacheck[1]]*PBW[alpha[1]] - 4*PBW[-alpha[1]]*PBW[alpha[1]] + PBW[alphacheck[1]]^2 - 2*PBW[alphacheck[1]] Check that :trac:`23266` is fixed:: - sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix') - sage: sl2.indices() + sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix') # optional - sage.groups sage.modules + sage: sl2.indices() # optional - sage.groups sage.modules {'e1', 'f1', 'h1'} - sage: type(sl2.basis().keys()) + sage: type(sl2.basis().keys()) # optional - sage.groups sage.modules - sage: Usl2 = sl2.pbw_basis() - sage: Usl2._basis_key(2) + sage: Usl2 = sl2.pbw_basis() # optional - sage.groups sage.modules + sage: Usl2._basis_key(2) # optional - sage.groups sage.modules 2 - sage: Usl2._basis_key(3) + sage: Usl2._basis_key(3) # optional - sage.groups sage.modules Traceback (most recent call last): ... KeyError: 3 @@ -214,8 +214,8 @@ def _dense_free_module(self, R=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L._dense_free_module() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L._dense_free_module() # optional - sage.modules Vector space of dimension 3 over Rational Field """ if R is None: @@ -237,10 +237,10 @@ def from_vector(self, v, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.modules (1, 0, 0) - sage: parent(u) is L + sage: parent(u) is L # optional - sage.modules True """ if order is None: @@ -260,17 +260,17 @@ def killing_matrix(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: L.killing_matrix(a, b) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.modules + sage: L.killing_matrix(a, b) # optional - sage.modules [0 0 0] [0 0 0] [0 0 0] :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.killing_matrix(y, x) + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.killing_matrix(y, x) # optional - sage.combinat sage.modules [ 0 -1] [ 0 0] """ @@ -291,9 +291,9 @@ def killing_form(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: L.killing_form(a, b) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.killing_form(a, b) # optional - sage.combinat sage.modules 0 """ return self.killing_matrix(x, y).trace() @@ -309,16 +309,16 @@ def killing_form_matrix(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.killing_form_matrix() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L.killing_form_matrix() # optional - sage.modules [0 0 0] [0 0 0] [0 0 0] - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example(0) - sage: m = L.killing_form_matrix(); m + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example(0) # optional - sage.modules + sage: m = L.killing_form_matrix(); m # optional - sage.modules [] - sage: parent(m) + sage: parent(m) # optional - sage.modules Full MatrixSpace of 0 by 0 dense matrices over Rational Field """ from sage.matrix.constructor import matrix @@ -347,18 +347,18 @@ def structure_coefficients(self, include_zeros=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.structure_coefficients() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L.structure_coefficients() # optional - sage.modules Finite family {} - sage: L.structure_coefficients(True) + sage: L.structure_coefficients(True) # optional - sage.modules Finite family {(0, 1): (0, 0, 0), (0, 2): (0, 0, 0), (1, 2): (0, 0, 0)} :: - sage: G = SymmetricGroup(3) - sage: S = GroupAlgebra(G, QQ) - sage: L = LieAlgebra(associative=S) - sage: L.structure_coefficients() + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: S = GroupAlgebra(G, QQ) # optional - sage.groups sage.modules + sage: L = LieAlgebra(associative=S) # optional - sage.groups sage.modules sage.combinat + sage: L.structure_coefficients() # optional - sage.groups sage.modules sage.combinat Finite family {((2,3), (1,2)): (1,2,3) - (1,3,2), ((2,3), (1,3)): -(1,2,3) + (1,3,2), ((1,2,3), (2,3)): -(1,2) + (1,3), @@ -401,23 +401,23 @@ def centralizer_basis(self, S): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: L.centralizer_basis([a + b, 2*a + c]) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.modules + sage: L.centralizer_basis([a + b, 2*a + c]) # optional - sage.modules [(1, 0, 0), (0, 1, 0), (0, 0, 1)] - sage: H = lie_algebras.Heisenberg(QQ, 2) - sage: H.centralizer_basis(H) + sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules + sage: H.centralizer_basis(H) # optional - sage.combinat sage.modules [z] - sage: D = DescentAlgebra(QQ, 4).D() - sage: L = LieAlgebra(associative=D) - sage: L.centralizer_basis(L) + sage: D = DescentAlgebra(QQ, 4).D() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(associative=D) # optional - sage.combinat sage.modules + sage: L.centralizer_basis(L) # optional - sage.combinat sage.modules [D{}, D{1} + D{1, 2} + D{2, 3} + D{3}, D{1, 2, 3} + D{1, 3} + D{2}] - sage: D.center_basis() + sage: D.center_basis() # optional - sage.combinat sage.modules (D{}, D{1} + D{1, 2} + D{2, 3} + D{3}, D{1, 2, 3} + D{1, 3} + D{2}) @@ -465,12 +465,12 @@ def centralizer(self, S): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: S = L.centralizer([a + b, 2*a + c]); S + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.modules + sage: S = L.centralizer([a + b, 2*a + c]); S # optional - sage.modules An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field - sage: S.basis_matrix() + sage: S.basis_matrix() # optional - sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -483,11 +483,11 @@ def center(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: Z = L.center(); Z + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: Z = L.center(); Z # optional - sage.modules An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field - sage: Z.basis_matrix() + sage: Z.basis_matrix() # optional - sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -514,8 +514,8 @@ def derivations_basis(self): We construct the derivations of the Heisenberg Lie algebra:: - sage: H = lie_algebras.Heisenberg(QQ, 1) - sage: H.derivations_basis() + sage: H = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: H.derivations_basis() # optional - sage.combinat sage.modules ( [1 0 0] [0 1 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [1 0 0] [0 1 0] [0 0 0] [0 0 0] @@ -524,8 +524,8 @@ def derivations_basis(self): We construct the derivations of `\mathfrak{sl}_2`:: - sage: sl2 = lie_algebras.sl(QQ, 2) - sage: sl2.derivations_basis() + sage: sl2 = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules + sage: sl2.derivations_basis() # optional - sage.combinat sage.modules ( [ 1 0 0] [ 0 1 0] [ 0 0 0] [ 0 0 0] [ 0 0 -1/2] [ 1 0 0] @@ -534,9 +534,9 @@ def derivations_basis(self): We verify these are derivations:: - sage: D = [sl2.module_morphism(matrix=M, codomain=sl2) + sage: D = [sl2.module_morphism(matrix=M, codomain=sl2) # optional - sage.combinat sage.modules ....: for M in sl2.derivations_basis()] - sage: all(d(a.bracket(b)) == d(a).bracket(b) + a.bracket(d(b)) + sage: all(d(a.bracket(b)) == d(a).bracket(b) + a.bracket(d(b)) # optional - sage.combinat sage.modules ....: for a in sl2.basis() for b in sl2.basis() for d in D) True @@ -578,8 +578,8 @@ def inner_derivations_basis(self): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 1) - sage: H.inner_derivations_basis() + sage: H = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: H.inner_derivations_basis() # optional - sage.combinat sage.modules ( [0 0 0] [0 0 0] [0 0 0] [0 0 0] @@ -606,24 +606,24 @@ def subalgebra(self, *gens, **kwds): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 2) - sage: p1,p2,q1,q2,z = H.basis() - sage: S = H.subalgebra([p1, q1]) - sage: S.basis().list() + sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules + sage: p1,p2,q1,q2,z = H.basis() # optional - sage.combinat sage.modules + sage: S = H.subalgebra([p1, q1]) # optional - sage.combinat sage.modules + sage: S.basis().list() # optional - sage.combinat sage.modules [p1, q1, z] - sage: S.basis_matrix() + sage: S.basis_matrix() # optional - sage.combinat sage.modules [1 0 0 0 0] [0 0 1 0 0] [0 0 0 0 1] Passing an extra category to a subalgebra:: - sage: L = LieAlgebra(QQ, 3, step=2) - sage: x,y,z = L.homogeneous_component_basis(1) - sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() - sage: C = C.Subobjects().Graded().Stratified() - sage: S = L.subalgebra([x, y], category=C) - sage: S.homogeneous_component_basis(2).list() + sage: L = LieAlgebra(QQ, 3, step=2) # optional - sage.combinat sage.modules + sage: x,y,z = L.homogeneous_component_basis(1) # optional - sage.combinat sage.modules + sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() # optional - sage.combinat sage.modules + sage: C = C.Subobjects().Graded().Stratified() # optional - sage.combinat sage.modules + sage: S = L.subalgebra([x, y], category=C) # optional - sage.combinat sage.modules + sage: S.homogeneous_component_basis(2).list() # optional - sage.combinat sage.modules [X_12] """ from sage.algebras.lie_algebras.subalgebra import LieSubalgebra_finite_dimensional_with_basis @@ -645,21 +645,21 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: H = lie_algebras.Heisenberg(QQ, 2) - sage: p1,p2,q1,q2,z = H.basis() - sage: I = H.ideal([p1-p2, q1-q2]) - sage: I.basis().list() + sage: H = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules + sage: p1,p2,q1,q2,z = H.basis() # optional - sage.combinat sage.modules + sage: I = H.ideal([p1-p2, q1-q2]) # optional - sage.combinat sage.modules + sage: I.basis().list() # optional - sage.combinat sage.modules [-p1 + p2, -q1 + q2, z] - sage: I.reduce(p1 + p2 + q1 + q2 + z) + sage: I.reduce(p1 + p2 + q1 + q2 + z) # optional - sage.combinat sage.modules 2*p1 + 2*q1 Passing an extra category to an ideal:: - sage: L. = LieAlgebra(QQ, abelian=True) - sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() - sage: C = C.Subobjects().Graded().Stratified() - sage: I = L.ideal(x, y, category=C) - sage: I.homogeneous_component_basis(1).list() + sage: L. = LieAlgebra(QQ, abelian=True) # optional - sage.combinat sage.modules + sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() # optional - sage.combinat sage.modules + sage: C = C.Subobjects().Graded().Stratified() # optional - sage.combinat sage.modules + sage: I = L.ideal(x, y, category=C) # optional - sage.combinat sage.modules + sage: I.homogeneous_component_basis(1).list() # optional - sage.combinat sage.modules [x, y] """ from sage.algebras.lie_algebras.subalgebra import LieSubalgebra_finite_dimensional_with_basis @@ -676,18 +676,18 @@ def is_ideal(self, A): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: I = L.ideal([2*a - c, b + c]) - sage: I.is_ideal(L) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: I = L.ideal([2*a - c, b + c]) # optional - sage.combinat sage.modules + sage: I.is_ideal(L) # optional - sage.combinat sage.modules True - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.is_ideal(L) + sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) # optional - sage.combinat sage.modules + sage: L.is_ideal(L) # optional - sage.combinat sage.modules True - sage: F = LieAlgebra(QQ, 'F', representation='polynomial') - sage: L.is_ideal(F) + sage: F = LieAlgebra(QQ, 'F', representation='polynomial') # optional - sage.combinat sage.modules + sage: L.is_ideal(F) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: A must be a finite dimensional Lie algebra @@ -728,26 +728,27 @@ def quotient(self, I, names=None, category=None): The Engel Lie algebra as a quotient of the free nilpotent Lie algebra of step 3 with 2 generators:: - sage: L. = LieAlgebra(QQ, 2, step=3) - sage: E = L.quotient(U); E - Lie algebra quotient L/I of dimension 4 over Rational Field where - L: Free Nilpotent Lie algebra on 5 generators (X, Y, Z, W, U) over Rational Field - I: Ideal (U) - sage: E.basis().list() - [X, Y, Z, W] - sage: E(X).bracket(E(Y)) - Z - sage: Y.bracket(Z) - -U - sage: E(Y).bracket(E(Z)) - 0 - sage: E(U) - 0 + sage: L. = LieAlgebra(QQ, 2, step=3) # optional - sage.combinat sage.modules + sage: E = L.quotient(U); E # optional - sage.combinat sage.modules + Lie algebra quotient L/I of dimension 4 over Rational Field where + L: Free Nilpotent Lie algebra on 5 generators (X, Y, Z, W, U) + over Rational Field + I: Ideal (U) + sage: E.basis().list() # optional - sage.combinat sage.modules + [X, Y, Z, W] + sage: E(X).bracket(E(Y)) # optional - sage.combinat sage.modules + Z + sage: Y.bracket(Z) # optional - sage.combinat sage.modules + -U + sage: E(Y).bracket(E(Z)) # optional - sage.combinat sage.modules + 0 + sage: E(U) # optional - sage.combinat sage.modules + 0 Quotients when the base ring is not a field are not implemented:: - sage: L = lie_algebras.Heisenberg(ZZ, 1) - sage: L.quotient(L.an_element()) + sage: L = lie_algebras.Heisenberg(ZZ, 1) # optional - sage.combinat sage.modules + sage: L.quotient(L.an_element()) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: quotients over non-fields not implemented @@ -769,44 +770,46 @@ def product_space(self, L, submodule=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a,b,c = L.lie_algebra_generators() - sage: X = L.subalgebra([a, b+c]) - sage: L.product_space(X) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a,b,c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: X = L.subalgebra([a, b+c]) # optional - sage.combinat sage.modules + sage: L.product_space(X) # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field - with basis matrix: - [] - sage: Y = L.subalgebra([a, 2*b-c]) - sage: X.product_space(Y) + with basis matrix: [] + sage: Y = L.subalgebra([a, 2*b-c]) # optional - sage.combinat sage.modules + sage: X.product_space(Y) # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: - the 0-dimensional abelian Lie algebra over Rational - Field with basis matrix: - [] + the 0-dimensional abelian Lie algebra over Rational Field + with basis matrix: [] :: - sage: H = lie_algebras.Heisenberg(ZZ, 4) - sage: Hp = H.product_space(H, submodule=True).basis() - sage: [H.from_vector(v) for v in Hp] + sage: H = lie_algebras.Heisenberg(ZZ, 4) # optional - sage.combinat sage.modules + sage: Hp = H.product_space(H, submodule=True).basis() # optional - sage.combinat sage.modules + sage: [H.from_vector(v) for v in Hp] # optional - sage.combinat sage.modules [z] :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: Lp = L.product_space(L) # todo: not implemented - #17416 - sage: Lp # todo: not implemented - #17416 - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,) - sage: Lp.product_space(L) # todo: not implemented - #17416 - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,) - sage: L.product_space(Lp) # todo: not implemented - #17416 - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,) - sage: Lp.product_space(Lp) # todo: not implemented - #17416 - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - () + sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) # optional - sage.combinat sage.modules + sage: Lp = L.product_space(L) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + sage: Lp # todo: not implemented - #17416 # optional - sage.combinat sage.modules + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,) + sage: Lp.product_space(L) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,) + sage: L.product_space(Lp) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,) + sage: Lp.product_space(Lp) # todo: not implemented - #17416 # optional - sage.combinat sage.modules + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: () """ from sage.matrix.constructor import matrix @@ -843,8 +846,8 @@ def derived_subalgebra(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.derived_subalgebra() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.derived_subalgebra() # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -852,10 +855,10 @@ def derived_subalgebra(self): If ``self`` is semisimple, then the derived subalgebra is ``self``:: - sage: sl3 = LieAlgebra(QQ, cartan_type=['A',2]) - sage: sl3.derived_subalgebra() + sage: sl3 = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules + sage: sl3.derived_subalgebra() # optional - sage.combinat sage.modules Lie algebra of ['A', 2] in the Chevalley basis - sage: sl3 is sl3.derived_subalgebra() + sage: sl3 is sl3.derived_subalgebra() # optional - sage.combinat sage.modules True """ @@ -894,24 +897,25 @@ def derived_series(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.derived_series() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.derived_series() # optional - sage.combinat sage.modules (An example of a finite dimensional Lie algebra with basis: the 3-dimensional abelian Lie algebra over Rational Field, An example of a finite dimensional Lie algebra with basis: the 0-dimensional abelian Lie algebra over Rational Field - with basis matrix: - []) + with basis matrix: []) :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.derived_series() # todo: not implemented - #17416 + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.derived_series() # todo: not implemented - #17416 # optional - sage.combinat sage.modules (Lie algebra on 2 generators (x, y) over Rational Field, - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,), - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - ()) + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,), + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: ()) """ L = [self] while L[-1].dimension() > 0: @@ -952,31 +956,30 @@ def lower_central_series(self, submodule=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.derived_series() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.derived_series() # optional - sage.combinat sage.modules (An example of a finite dimensional Lie algebra with basis: - the 3-dimensional abelian Lie algebra over Rational Field, + the 3-dimensional abelian Lie algebra over Rational Field, An example of a finite dimensional Lie algebra with basis: - the 0-dimensional abelian Lie algebra over Rational Field - with basis matrix: - []) + the 0-dimensional abelian Lie algebra over Rational Field + with basis matrix: []) The lower central series as submodules:: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.lower_central_series(submodule=True) + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.lower_central_series(submodule=True) # optional - sage.combinat sage.modules (Sparse vector space of dimension 2 over Rational Field, - Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [1 0]) + Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: [1 0]) :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.lower_central_series() # todo: not implemented - #17416 + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.lower_central_series() # todo: not implemented - #17416 # optional - sage.combinat sage.modules (Lie algebra on 2 generators (x, y) over Rational Field, - Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis: - (x,)) + Subalgebra generated of + Lie algebra on 2 generators (x, y) over Rational Field + with basis: (x,)) """ if submodule: L = [self.module()] @@ -995,14 +998,14 @@ def is_abelian(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_abelian() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) - sage: L.is_abelian() + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules False """ return len(self.structure_coefficients()) == 0 @@ -1018,14 +1021,14 @@ def is_solvable(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_solvable() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_solvable() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: L.is_solvable() # todo: not implemented - #17416 + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.is_solvable() # todo: not implemented - #17416 # optional - sage.combinat sage.modules False """ return not self.derived_series()[-1].dimension() @@ -1039,8 +1042,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_nilpotent() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_nilpotent() # optional - sage.combinat sage.modules True """ return not self.lower_central_series()[-1].dimension() @@ -1055,8 +1058,8 @@ def is_semisimple(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_semisimple() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_semisimple() # optional - sage.combinat sage.modules False """ return not self.killing_form_matrix().is_singular() @@ -1101,24 +1104,24 @@ def chevalley_eilenberg_complex(self, M=None, dual=False, sparse=True, ncpus=Non EXAMPLES:: - sage: L = lie_algebras.sl(ZZ, 2) - sage: C = L.chevalley_eilenberg_complex(); C + sage: L = lie_algebras.sl(ZZ, 2) # optional - sage.combinat sage.modules + sage: C = L.chevalley_eilenberg_complex(); C # optional - sage.combinat sage.modules Chain complex with at most 4 nonzero terms over Integer Ring - sage: ascii_art(C) + sage: ascii_art(C) # optional - sage.combinat sage.modules [ 2 0 0] [0] [ 0 -1 0] [0] [0 0 0] [ 0 0 2] [0] 0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0 - sage: L = LieAlgebra(QQ, cartan_type=['C',2]) - sage: C = L.chevalley_eilenberg_complex() # long time - sage: [C.free_module_rank(i) for i in range(11)] # long time + sage: L = LieAlgebra(QQ, cartan_type=['C',2]) # optional - sage.combinat sage.modules + sage: C = L.chevalley_eilenberg_complex() # long time # optional - sage.combinat sage.modules + sage: [C.free_module_rank(i) for i in range(11)] # long time # optional - sage.combinat sage.modules [1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1] - sage: g = lie_algebras.sl(QQ,2) - sage: E,F,H = g.basis() - sage: n = g.subalgebra([F,H]) - sage: ascii_art(n.chevalley_eilenberg_complex()) + sage: g = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules + sage: E, F, H = g.basis() # optional - sage.combinat sage.modules + sage: n = g.subalgebra([F, H]) # optional - sage.combinat sage.modules + sage: ascii_art(n.chevalley_eilenberg_complex()) # optional - sage.combinat sage.modules [0] [0 0] [2] 0 <-- C_0 <------ C_1 <---- C_2 <-- 0 @@ -1269,15 +1272,15 @@ def homology(self, deg=None, M=None, sparse=True, ncpus=None): EXAMPLES:: - sage: L = lie_algebras.cross_product(QQ) - sage: L.homology() + sage: L = lie_algebras.cross_product(QQ) # optional - sage.combinat sage.modules + sage: L.homology() # optional - sage.combinat sage.modules {0: Vector space of dimension 1 over Rational Field, 1: Vector space of dimension 0 over Rational Field, 2: Vector space of dimension 0 over Rational Field, 3: Vector space of dimension 1 over Rational Field} - sage: L = lie_algebras.pwitt(GF(5), 5) - sage: L.homology() + sage: L = lie_algebras.pwitt(GF(5), 5) # optional - sage.combinat sage.libs.pari sage.modules + sage: L.homology() # optional - sage.combinat sage.libs.pari sage.modules {0: Vector space of dimension 1 over Finite Field of size 5, 1: Vector space of dimension 0 over Finite Field of size 5, 2: Vector space of dimension 1 over Finite Field of size 5, @@ -1285,9 +1288,9 @@ def homology(self, deg=None, M=None, sparse=True, ncpus=None): 4: Vector space of dimension 0 over Finite Field of size 5, 5: Vector space of dimension 1 over Finite Field of size 5} - sage: d = {('x', 'y'): {'y': 2}} - sage: L. = LieAlgebra(ZZ, d) - sage: L.homology() + sage: d = {('x', 'y'): {'y': 2}} # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(ZZ, d) # optional - sage.combinat sage.modules + sage: L.homology() # optional - sage.combinat sage.modules {0: Z, 1: Z x C2, 2: 0} .. SEEALSO:: @@ -1334,8 +1337,8 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 4) - sage: L.cohomology() + sage: L = lie_algebras.so(QQ, 4) # optional - sage.combinat sage.modules + sage: L.cohomology() # optional - sage.combinat sage.modules {0: Vector space of dimension 1 over Rational Field, 1: Vector space of dimension 0 over Rational Field, 2: Vector space of dimension 0 over Rational Field, @@ -1344,8 +1347,8 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): 5: Vector space of dimension 0 over Rational Field, 6: Vector space of dimension 1 over Rational Field} - sage: L = lie_algebras.Heisenberg(QQ, 2) - sage: L.cohomology() + sage: L = lie_algebras.Heisenberg(QQ, 2) # optional - sage.combinat sage.modules + sage: L.cohomology() # optional - sage.combinat sage.modules {0: Vector space of dimension 1 over Rational Field, 1: Vector space of dimension 4 over Rational Field, 2: Vector space of dimension 5 over Rational Field, @@ -1353,9 +1356,9 @@ def cohomology(self, deg=None, M=None, sparse=True, ncpus=None): 4: Vector space of dimension 4 over Rational Field, 5: Vector space of dimension 1 over Rational Field} - sage: d = {('x', 'y'): {'y': 2}} - sage: L. = LieAlgebra(ZZ, d) - sage: L.cohomology() + sage: d = {('x', 'y'): {'y': 2}} # optional - sage.combinat sage.modules + sage: L. = LieAlgebra(ZZ, d) # optional - sage.combinat sage.modules + sage: L.cohomology() # optional - sage.combinat sage.modules {0: Z, 1: Z, 2: C2} .. SEEALSO:: @@ -1376,13 +1379,13 @@ def as_finite_dimensional_algebra(self): EXAMPLES:: - sage: L = lie_algebras.cross_product(QQ) - sage: x,y,z = L.basis() - sage: F = L.as_finite_dimensional_algebra() - sage: X,Y,Z = F.basis() - sage: x.bracket(y) + sage: L = lie_algebras.cross_product(QQ) # optional - sage.combinat sage.modules + sage: x, y, z = L.basis() # optional - sage.combinat sage.modules + sage: F = L.as_finite_dimensional_algebra() # optional - sage.combinat sage.modules + sage: X, Y, Z = F.basis() # optional - sage.combinat sage.modules + sage: x.bracket(y) # optional - sage.combinat sage.modules Z - sage: X * Y + sage: X * Y # optional - sage.combinat sage.modules Z """ from sage.matrix.constructor import matrix @@ -1436,9 +1439,10 @@ def morphism(self, on_generators, codomain=None, base_map=None, check=True): A quotient type Lie algebra morphism :: - sage: L. = LieAlgebra(QQ, {('X','Y'): {'Z':1}, ('X','Z'): {'W':1}}) - sage: K. = LieAlgebra(QQ, abelian=True) - sage: L.morphism({X: A, Y: B}) + sage: L. = LieAlgebra(QQ, {('X','Y'): {'Z': 1}, # optional - sage.combinat sage.modules + ....: ('X','Z'): {'W': 1}}) + sage: K. = LieAlgebra(QQ, abelian=True) # optional - sage.combinat sage.modules + sage: L.morphism({X: A, Y: B}) # optional - sage.combinat sage.modules Lie algebra morphism: From: Lie algebra on 4 generators (X, Y, Z, W) over Rational Field To: Abelian Lie algebra on 2 generators (A, B) over Rational Field @@ -1450,7 +1454,7 @@ def morphism(self, on_generators, codomain=None, base_map=None, check=True): The reverse map `A \mapsto X`, `B \mapsto Y` does not define a Lie algebra morphism, since `[A,B] = 0`, but `[X,Y] \neq 0`:: - sage: K.morphism({A:X, B: Y}) + sage: K.morphism({A:X, B: Y}) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: this does not define a Lie algebra morphism; @@ -1460,15 +1464,16 @@ def morphism(self, on_generators, codomain=None, base_map=None, check=True): on the coefficients, even though it's not a Lie algebra morphism (since it isn't linear):: - sage: R. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: L. = LieAlgebra(K, {('X','Y'): {'Z':1}, ('X','Z'): {'W':1}}) - sage: M. = LieAlgebra(K, abelian=True) - sage: phi = L.morphism({X: A, Y: B}, base_map=cc) - sage: phi(X) + sage: R. = ZZ[] # optional - sage.combinat sage.modules + sage: K. = NumberField(x^2 + 1) # optional - sage.combinat sage.modules sage.rings.number_fields + sage: cc = K.hom([-i]) # optional - sage.combinat sage.modules sage.rings.number_fields + sage: L. = LieAlgebra(K, {('X','Y'): {'Z': 1}, # optional - sage.combinat sage.modules sage.rings.number_fields + ....: ('X','Z'): {'W': 1}}) + sage: M. = LieAlgebra(K, abelian=True) # optional - sage.combinat sage.modules sage.rings.number_fields + sage: phi = L.morphism({X: A, Y: B}, base_map=cc) # optional - sage.combinat sage.modules sage.rings.number_fields + sage: phi(X) # optional - sage.combinat sage.modules sage.rings.number_fields A - sage: phi(i*X) + sage: phi(i*X) # optional - sage.combinat sage.modules sage.rings.number_fields -i*A """ from sage.algebras.lie_algebras.morphism import LieAlgebraMorphism_from_generators @@ -1497,13 +1502,13 @@ def universal_polynomials(self): EXAMPLES:: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) - sage: L.universal_polynomials() + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.universal_polynomials() # optional - sage.combinat sage.modules Finite family {('x', 'x', 'y'): X01*X10 - X00*X11 + X00, ('y', 'x', 'y'): X10} - sage: L = LieAlgebra(QQ, cartan_type=['A',1]) - sage: list(L.universal_polynomials()) + sage: L = LieAlgebra(QQ, cartan_type=['A',1]) # optional - sage.combinat sage.modules + sage: list(L.universal_polynomials()) # optional - sage.combinat sage.modules [-2*X01*X10 + 2*X00*X11 - 2*X00, -2*X02*X10 + 2*X00*X12 + X01, -2*X02*X11 + 2*X01*X12 - 2*X02, @@ -1514,13 +1519,13 @@ def universal_polynomials(self): -2*X12*X20 + 2*X10*X22 + X21, -2*X12*X21 + 2*X11*X22 - 2*X22] - sage: L = LieAlgebra(QQ, cartan_type=['B',2]) - sage: al = RootSystem(['B',2]).root_lattice().simple_roots() - sage: k = list(L.basis().keys())[0] - sage: UP = L.universal_polynomials() # long time - sage: len(UP) # long time + sage: L = LieAlgebra(QQ, cartan_type=['B', 2]) # optional - sage.combinat sage.modules + sage: al = RootSystem(['B', 2]).root_lattice().simple_roots() # optional - sage.combinat sage.modules + sage: k = list(L.basis().keys())[0] # optional - sage.combinat sage.modules + sage: UP = L.universal_polynomials() # long time # optional - sage.combinat sage.modules + sage: len(UP) # long time # optional - sage.combinat sage.modules 450 - sage: UP[al[2],al[1],-al[1]] # long time + sage: UP[al[2], al[1], -al[1]] # long time # optional - sage.combinat sage.modules X0_7*X4_1 - X0_1*X4_7 - 2*X0_7*X5_1 + 2*X0_1*X5_7 + X2_7*X7_1 - X2_1*X7_7 - X3_7*X8_1 + X3_1*X8_7 + X0_4 """ @@ -1574,12 +1579,12 @@ def universal_commutative_algebra(self): EXAMPLES:: - sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) - sage: A = L.universal_commutative_algebra() - sage: a,b,c,d = A.gens() - sage: (a,b,c,d) + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: A = L.universal_commutative_algebra() # optional - sage.combinat sage.modules + sage: a, b, c, d = A.gens() # optional - sage.combinat sage.modules + sage: a, b, c, d # optional - sage.combinat sage.modules (X00bar, X01bar, 0, X11bar) - sage: a*d - a + sage: a*d - a # optional - sage.combinat sage.modules 0 """ P = list(self.universal_polynomials()) @@ -1593,31 +1598,31 @@ def adjoint_matrix(self, sparse=False): # In #11111 (more or less) by using matr EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.an_element().adjoint_matrix() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.an_element().adjoint_matrix() # optional - sage.combinat sage.modules [0 0 0] [0 0 0] [0 0 0] - sage: L.an_element().adjoint_matrix(sparse=True).is_sparse() + sage: L.an_element().adjoint_matrix(sparse=True).is_sparse() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ, {('x','y'):{'x':1}}) - sage: x.adjoint_matrix() + sage: L. = LieAlgebra(QQ, {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: x.adjoint_matrix() # optional - sage.combinat sage.modules [0 1] [0 0] - sage: y.adjoint_matrix() + sage: y.adjoint_matrix() # optional - sage.combinat sage.modules [-1 0] [ 0 0] We verify that this forms a representation:: - sage: sl3 = lie_algebras.sl(QQ, 3) - sage: e1, e2 = sl3.e(1), sl3.e(2) - sage: e12 = e1.bracket(e2) - sage: E1, E2 = e1.adjoint_matrix(), e2.adjoint_matrix() - sage: E1 * E2 - E2 * E1 == e12.adjoint_matrix() + sage: sl3 = lie_algebras.sl(QQ, 3) # optional - sage.combinat sage.modules + sage: e1, e2 = sl3.e(1), sl3.e(2) # optional - sage.combinat sage.modules + sage: e12 = e1.bracket(e2) # optional - sage.combinat sage.modules + sage: E1, E2 = e1.adjoint_matrix(), e2.adjoint_matrix() # optional - sage.combinat sage.modules + sage: E1 * E2 - E2 * E1 == e12.adjoint_matrix() # optional - sage.combinat sage.modules True """ from sage.matrix.constructor import matrix @@ -1640,16 +1645,16 @@ def to_vector(self, order=None, sparse=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.an_element().to_vector() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.an_element().to_vector() # optional - sage.combinat sage.modules (0, 0, 0) - sage: L.an_element().to_vector(sparse=True) + sage: L.an_element().to_vector(sparse=True) # optional - sage.combinat sage.modules (0, 0, 0) - sage: D = DescentAlgebra(QQ, 4).D() - sage: L = LieAlgebra(associative=D) - sage: L.an_element().to_vector() + sage: D = DescentAlgebra(QQ, 4).D() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(associative=D) # optional - sage.combinat sage.modules + sage: L.an_element().to_vector() # optional - sage.combinat sage.modules (1, 1, 1, 1, 1, 1, 1, 1) TESTS: @@ -1657,13 +1662,13 @@ def to_vector(self, order=None, sparse=False): Check that the error raised agrees with the one from ``monomial_coefficients()`` (see :trac:`25007`):: - sage: L = lie_algebras.sp(QQ, 4, representation='matrix') - sage: x = L.an_element() - sage: x.monomial_coefficients() + sage: L = lie_algebras.sp(QQ, 4, representation='matrix') # optional - sage.combinat sage.modules + sage: x = L.an_element() # optional - sage.combinat sage.modules + sage: x.monomial_coefficients() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: the basis is not defined - sage: x.to_vector() + sage: x.to_vector() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: the basis is not defined @@ -1697,10 +1702,11 @@ def ambient(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: S = L.subalgebra([2*a+b, b + c]) - sage: S.ambient() == L + sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() + sage: L = C.example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: S = L.subalgebra([2*a + b, b + c]) # optional - sage.combinat sage.modules + sage: S.ambient() == L # optional - sage.combinat sage.modules True """ @@ -1711,10 +1717,11 @@ def basis_matrix(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: S = L.subalgebra([2*a+b, b + c]) - sage: S.basis_matrix() + sage: C = LieAlgebras(QQ).FiniteDimensional().WithBasis() + sage: L = C.example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: S = L.subalgebra([2*a + b, b + c]) # optional - sage.combinat sage.modules + sage: S.basis_matrix() # optional - sage.combinat sage.modules [ 1 0 -1/2] [ 0 1 1] """ diff --git a/src/sage/categories/finite_dimensional_modules_with_basis.py b/src/sage/categories/finite_dimensional_modules_with_basis.py index 0ebca2f2dde..573aec237a1 100644 --- a/src/sage/categories/finite_dimensional_modules_with_basis.py +++ b/src/sage/categories/finite_dimensional_modules_with_basis.py @@ -46,8 +46,8 @@ def gens(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, ['a', 'b', 'c']) - sage: F.gens() + sage: F = CombinatorialFreeModule(ZZ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.gens() # optional - sage.modules (B['a'], B['b'], B['c']) """ return tuple(self.basis()) @@ -91,35 +91,35 @@ def annihilator(self, S, action=operator.mul, side='right', category=None): EXAMPLES:: - sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F + sage: F = FiniteDimensionalAlgebrasWithBasis(QQ).example(); F # optional - sage.modules An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: x,y,a,b = F.basis() - sage: A = F.annihilator([a + 3*b + 2*y]); A + sage: x, y, a, b = F.basis() # optional - sage.modules + sage: A = F.annihilator([a + 3*b + 2*y]); A # optional - sage.modules Free module generated by {0} over Rational Field - sage: [b.lift() for b in A.basis()] + sage: [b.lift() for b in A.basis()] # optional - sage.modules [-1/2*a - 3/2*b + x] The category can be used to specify other properties of this subspace, like that this is a subalgebra:: - sage: center = F.annihilator(F.basis(), F.bracket, + sage: center = F.annihilator(F.basis(), F.bracket, # optional - sage.modules ....: category=Algebras(QQ).Subobjects()) - sage: (e,) = center.basis() - sage: e.lift() + sage: (e,) = center.basis() # optional - sage.modules + sage: e.lift() # optional - sage.modules x + y - sage: e * e == e + sage: e * e == e # optional - sage.modules True Taking annihilator is order reversing for inclusion:: - sage: A = F.annihilator([]); A .rename("A") - sage: Ax = F.annihilator([x]); Ax .rename("Ax") - sage: Ay = F.annihilator([y]); Ay .rename("Ay") - sage: Axy = F.annihilator([x,y]); Axy.rename("Axy") - sage: P = Poset(([A, Ax, Ay, Axy], attrcall("is_submodule"))) - sage: sorted(P.cover_relations(), key=str) + sage: A = F.annihilator([]); A .rename("A") # optional - sage.modules + sage: Ax = F.annihilator([x]); Ax .rename("Ax") # optional - sage.modules + sage: Ay = F.annihilator([y]); Ay .rename("Ay") # optional - sage.modules + sage: Axy = F.annihilator([x,y]); Axy.rename("Axy") # optional - sage.modules + sage: P = Poset(([A, Ax, Ay, Axy], attrcall("is_submodule"))) # optional - sage.combinat sage.graphs sage.modules + sage: sorted(P.cover_relations(), key=str) # optional - sage.combinat sage.graphs sage.modules [[Ax, A], [Axy, Ax], [Axy, Ay], [Ay, A]] """ return self.submodule(self.annihilator_basis(S, action, side), @@ -204,7 +204,8 @@ def annihilator_basis(self, S, action=operator.mul, side='right'): compute the orthogonal of a subspace:: sage: x,y,a,b = F.basis() - sage: def scalar(u,v): return vector([sum(u[i]*v[i] for i in F.basis().keys())]) + sage: def scalar(u,v): + ....: return vector([sum(u[i]*v[i] for i in F.basis().keys())]) sage: F.annihilator_basis([x+y, a+b], scalar) (x - y, a - b) @@ -251,13 +252,13 @@ def _dense_free_module(self, base_ring=None): EXAMPLES:: - sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']); C + sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']); C # optional - sage.modules Free module generated by {'a', 'b', 'c'} over Univariate Polynomial Ring in x over Rational Field - sage: C._dense_free_module() + sage: C._dense_free_module() # optional - sage.modules Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: C._dense_free_module(QQ['x,y']) + sage: C._dense_free_module(QQ['x,y']) # optional - sage.modules Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x, y over Rational Field """ @@ -272,11 +273,11 @@ def from_vector(self, vector, order=None, coerce=True): EXAMPLES:: - sage: p_mult = matrix([[0,0,0],[0,0,-1],[0,0,0]]) - sage: q_mult = matrix([[0,0,1],[0,0,0],[0,0,0]]) - sage: A = algebras.FiniteDimensional(QQ, [p_mult, q_mult, matrix(QQ,3,3)], - ....: 'p,q,z') - sage: A.from_vector(vector([1,0,2])) + sage: p_mult = matrix([[0,0,0], [0,0,-1], [0,0,0]]) # optional - sage.modules + sage: q_mult = matrix([[0,0,1], [0,0,0], [0,0,0]]) # optional - sage.modules + sage: A = algebras.FiniteDimensional( # optional - sage.combinat sage.modules + ....: QQ, [p_mult, q_mult, matrix(QQ, 3, 3)], 'p,q,z') + sage: A.from_vector(vector([1,0,2])) # optional - sage.combinat sage.modules p + 2*z """ if order is None: @@ -312,42 +313,42 @@ def echelon_form(self, elements, row_reduced=False, order=None): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") - sage: x = X.basis() - sage: V = X.echelon_form([x[0]-x[1], x[0]-x[2],x[1]-x[2]]); V + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: V = X.echelon_form([x[0]-x[1], x[0]-x[2], x[1]-x[2]]); V # optional - sage.modules [x[0] - x[2], x[1] - x[2]] - sage: matrix(list(map(vector, V))) + sage: matrix(list(map(vector, V))) # optional - sage.modules [ 1 0 -1] [ 0 1 -1] :: - sage: F = CombinatorialFreeModule(ZZ, [1,2,3,4]) - sage: B = F.basis() - sage: elements = [B[1]-17*B[2]+6*B[3], B[1]-17*B[2]+B[4]] - sage: F.echelon_form(elements) + sage: F = CombinatorialFreeModule(ZZ, [1,2,3,4]) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: elements = [B[1]-17*B[2]+6*B[3], B[1]-17*B[2]+B[4]] # optional - sage.modules + sage: F.echelon_form(elements) # optional - sage.modules [B[1] - 17*B[2] + B[4], 6*B[3] - B[4]] :: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: a,b,c = F.basis() - sage: F.echelon_form([8*a+b+10*c, -3*a+b-c, a-b-c]) + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: a,b,c = F.basis() # optional - sage.modules + sage: F.echelon_form([8*a+b+10*c, -3*a+b-c, a-b-c]) # optional - sage.modules [B['a'] + B['c'], B['b'] + 2*B['c']] :: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') - sage: x = C.basis() - sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]) + sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # optional - sage.modules + sage: x = C.basis() # optional - sage.modules + sage: C.echelon_form([x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]) # optional - sage.modules [x[0] - x[2], x[1] - x[2]] :: - sage: M = MatrixSpace(QQ, 3, 3) - sage: A = M([[0, 0, 2], [0, 0, 0], [0, 0, 0]]) - sage: M.echelon_form([A, A]) + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([[0, 0, 2], [0, 0, 0], [0, 0, 0]]) # optional - sage.modules + sage: M.echelon_form([A, A]) # optional - sage.modules [ [0 0 1] [0 0 0] @@ -358,8 +359,8 @@ def echelon_form(self, elements, row_reduced=False, order=None): We convert the input elements to ``self``:: - sage: E. = ExteriorAlgebra(QQ) - sage: E.echelon_form([1, x + 2]) + sage: E. = ExteriorAlgebra(QQ) # optional - sage.modules sage.combinat + sage: E.echelon_form([1, x + 2]) # optional - sage.modules sage.combinat [1, x] """ # Make sure elements consists of elements of ``self`` @@ -410,35 +411,37 @@ def invariant_module(self, S, action=operator.mul, action_on_basis=None, We build the invariant module of the permutation representation of the symmetric group:: - sage: G = SymmetricGroup(3); G.rename('S3') - sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') + sage: G = SymmetricGroup(3); G.rename('S3') # optional - sage.groups sage.modules + sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') # optional - sage.groups sage.modules sage: action = lambda g, x: M.term(g(x)) - sage: I = M.invariant_module(G, action_on_basis=action); I + sage: I = M.invariant_module(G, action_on_basis=action); I # optional - sage.groups sage.modules (S3)-invariant submodule of M - sage: I.basis() + sage: I.basis() # optional - sage.groups sage.modules Finite family {0: B[0]} - sage: [I.lift(b) for b in I.basis()] + sage: [I.lift(b) for b in I.basis()] # optional - sage.groups sage.modules [M[1] + M[2] + M[3]] - sage: G.rename(); M.rename() # reset the names + sage: G.rename(); M.rename() # reset the names # optional - sage.groups sage.modules We can construct the invariant module of any module that has an action of ``S``. In this example, we consider the dihedral group `G = D_4` and the subgroup `H < G` of all rotations. We construct the `H`-invariant module of the group algebra `\QQ[G]`:: - sage: G = groups.permutation.Dihedral(4) - sage: H = G.subgroup(G.gen(0)) - sage: H - Subgroup generated by [(1,2,3,4)] of (Dihedral group of order 8 as a permutation group) - sage: H.cardinality() + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: H = G.subgroup(G.gen(0)) # optional - sage.groups + sage: H # optional - sage.groups + Subgroup generated by [(1,2,3,4)] + of (Dihedral group of order 8 as a permutation group) + sage: H.cardinality() # optional - sage.groups 4 - sage: A = G.algebra(QQ) - sage: I = A.invariant_module(H) - sage: [I.lift(b) for b in I.basis()] + sage: A = G.algebra(QQ) # optional - sage.groups sage.modules + sage: I = A.invariant_module(H) # optional - sage.groups sage.modules + sage: [I.lift(b) for b in I.basis()] # optional - sage.groups sage.modules [() + (1,2,3,4) + (1,3)(2,4) + (1,4,3,2), (2,4) + (1,2)(3,4) + (1,3) + (1,4)(2,3)] - sage: all(h * I.lift(b) == I.lift(b) for b in I.basis() for h in H) + sage: all(h * I.lift(b) == I.lift(b) # optional - sage.groups sage.modules + ....: for b in I.basis() for h in H) True """ if action_on_basis is not None: @@ -480,12 +483,13 @@ def twisted_invariant_module(self, G, chi, EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [1,2,3]) - sage: G = SymmetricGroup(3) - sage: def action(g,x): return(M.term(g(x))) # permute coordinates - sage: T = M.twisted_invariant_module(G, [2,0,-1], action_on_basis=action) + sage: M = CombinatorialFreeModule(QQ, [1,2,3]) # optional - sage.groups sage.modules + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: def action(g,x): return(M.term(g(x))) # permute coordinates + sage: T = M.twisted_invariant_module(G, [2,0,-1], # optional - sage.groups sage.modules + ....: action_on_basis=action) sage: import __main__; __main__.action = action - sage: TestSuite(T).run() + sage: TestSuite(T).run() # optional - sage.groups sage.modules """ if action_on_basis is not None: @@ -514,12 +518,12 @@ def dense_coefficient_list(self, order=None): EXAMPLES:: - sage: v = vector([0, -1, -3]) - sage: v.dense_coefficient_list() + sage: v = vector([0, -1, -3]) # optional - sage.modules + sage: v.dense_coefficient_list() # optional - sage.modules [0, -1, -3] - sage: v.dense_coefficient_list([2,1,0]) + sage: v.dense_coefficient_list([2,1,0]) # optional - sage.modules [-3, -1, 0] - sage: sorted(v.coefficients()) + sage: sorted(v.coefficients()) # optional - sage.modules [-3, -1] """ if order is None: @@ -535,11 +539,11 @@ def _vector_(self, order=None): EXAMPLES:: - sage: v = vector([0, -1, -3]) - sage: v._vector_() + sage: v = vector([0, -1, -3]) # optional - sage.modules + sage: v._vector_() # optional - sage.modules (0, -1, -3) - sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']) - sage: C.an_element()._vector_() + sage: C = CombinatorialFreeModule(QQ['x'], ['a','b','c']) # optional - sage.modules + sage: C.an_element()._vector_() # optional - sage.modules (2, 2, 3) """ if order is None: @@ -577,30 +581,31 @@ def matrix(self, base_ring=None, side="left"): EXAMPLES:: - sage: X = CombinatorialFreeModule(ZZ, [1,2]); x = X.basis() - sage: Y = CombinatorialFreeModule(ZZ, [3,4]); y = Y.basis() - sage: phi = X.module_morphism(on_basis = {1: y[3] + 3*y[4], 2: 2*y[3] + 5*y[4]}.__getitem__, - ....: codomain = Y) - sage: phi.matrix() + sage: X = CombinatorialFreeModule(ZZ, [1,2]); x = X.basis() # optional - sage.modules + sage: Y = CombinatorialFreeModule(ZZ, [3,4]); y = Y.basis() # optional - sage.modules + sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], # optional - sage.modules + ....: 2: 2*y[3] + 5*y[4]}.__getitem__, + ....: codomain=Y) + sage: phi.matrix() # optional - sage.modules [1 2] [3 5] - sage: phi.matrix(side="right") + sage: phi.matrix(side="right") # optional - sage.modules [1 3] [2 5] - sage: phi.matrix().parent() + sage: phi.matrix().parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: phi.matrix(QQ).parent() + sage: phi.matrix(QQ).parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field The resulting matrix is immutable:: - sage: phi.matrix().is_mutable() + sage: phi.matrix().is_mutable() # optional - sage.modules False The zero morphism has a zero matrix:: - sage: Hom(X,Y).zero().matrix() + sage: Hom(X, Y).zero().matrix() # optional - sage.modules [0 0] [0 0] @@ -609,10 +614,11 @@ def matrix(self, base_ring=None, side="left"): Add support for morphisms where the codomain has a different base ring than the domain:: - sage: Y = CombinatorialFreeModule(QQ, [3,4]); y = Y.basis() - sage: phi = X.module_morphism(on_basis = {1: y[3] + 3*y[4], 2: 2*y[3] + 5/2*y[4]}.__getitem__, - ....: codomain = Y) - sage: phi.matrix().parent() # todo: not implemented + sage: Y = CombinatorialFreeModule(QQ, [3,4]); y = Y.basis() # optional - sage.modules + sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], # optional - sage.modules + ....: 2: 2*y[3] + 5/2*y[4]}.__getitem__, + ....: codomain=Y) + sage: phi.matrix().parent() # todo: not implemented # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field This currently does not work because, in this case, @@ -620,20 +626,20 @@ def matrix(self, base_ring=None, side="left"): additive groups (i.e. the intersection of the categories of modules over `\ZZ` and over `\QQ`):: - sage: phi.parent().homset_category() + sage: phi.parent().homset_category() # optional - sage.modules Category of commutative additive semigroups - sage: phi.parent().homset_category() # todo: not implemented + sage: phi.parent().homset_category() # todo: not implemented # optional - sage.modules Category of finite dimensional modules with basis over Integer Ring TESTS: Check that :trac:`23216` is fixed:: - sage: X = CombinatorialFreeModule(QQ, []) - sage: Y = CombinatorialFreeModule(QQ, [1,2,3]) - sage: Hom(X,Y).zero().matrix() + sage: X = CombinatorialFreeModule(QQ, []) # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [1,2,3]) # optional - sage.modules + sage: Hom(X, Y).zero().matrix() # optional - sage.modules [] - sage: Hom(X,Y).zero().matrix().parent() + sage: Hom(X, Y).zero().matrix().parent() # optional - sage.modules Full MatrixSpace of 3 by 0 dense matrices over Rational Field """ if base_ring is None: @@ -663,41 +669,41 @@ def __invert__(self): EXAMPLES:: sage: category = FiniteDimensionalModulesWithBasis(ZZ) - sage: X = CombinatorialFreeModule(ZZ, [1,2], category = category); X.rename("X"); x = X.basis() - sage: Y = CombinatorialFreeModule(ZZ, [3,4], category = category); Y.rename("Y"); y = Y.basis() - sage: phi = X.module_morphism(on_basis = {1: y[3] + 3*y[4], 2: 2*y[3] + 5*y[4]}.__getitem__, - ....: codomain = Y, category = category) - sage: psi = ~phi - sage: psi + sage: X = CombinatorialFreeModule(ZZ, [1,2], category=category); X.rename("X"); x = X.basis() # optional - sage.modules + sage: Y = CombinatorialFreeModule(ZZ, [3,4], category=category); Y.rename("Y"); y = Y.basis() # optional - sage.modules + sage: phi = X.module_morphism(on_basis={1: y[3] + 3*y[4], 2: 2*y[3] + 5*y[4]}.__getitem__, # optional - sage.modules + ....: codomain=Y, category=category) + sage: psi = ~phi # optional - sage.modules + sage: psi # optional - sage.modules Generic morphism: From: Y To: X - sage: psi.parent() + sage: psi.parent() # optional - sage.modules Set of Morphisms from Y to X in Category of finite dimensional modules with basis over Integer Ring - sage: psi(y[3]) + sage: psi(y[3]) # optional - sage.modules -5*B[1] + 3*B[2] - sage: psi(y[4]) + sage: psi(y[4]) # optional - sage.modules 2*B[1] - B[2] - sage: psi.matrix() + sage: psi.matrix() # optional - sage.modules [-5 2] [ 3 -1] - sage: psi(phi(x[1])), psi(phi(x[2])) + sage: psi(phi(x[1])), psi(phi(x[2])) # optional - sage.modules (B[1], B[2]) - sage: phi(psi(y[3])), phi(psi(y[4])) + sage: phi(psi(y[3])), phi(psi(y[4])) # optional - sage.modules (B[3], B[4]) We check that this function complains if the morphism is not invertible:: - sage: phi = X.module_morphism(on_basis = {1: y[3] + y[4], 2: y[3] + y[4]}.__getitem__, - ....: codomain = Y, category = category) - sage: ~phi + sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + y[4]}.__getitem__, # optional - sage.modules + ....: codomain=Y, category=category) + sage: ~phi # optional - sage.modules Traceback (most recent call last): ... RuntimeError: morphism is not invertible - sage: phi = X.module_morphism(on_basis = {1: y[3] + y[4], 2: y[3] + 5*y[4]}.__getitem__, - ....: codomain = Y, category = category) - sage: ~phi + sage: phi = X.module_morphism(on_basis={1: y[3] + y[4], 2: y[3] + 5*y[4]}.__getitem__, # optional - sage.modules + ....: codomain=Y, category=category) + sage: ~phi # optional - sage.modules Traceback (most recent call last): ... RuntimeError: morphism is not invertible @@ -717,9 +723,9 @@ def kernel_basis(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: f.kernel_basis() + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules + sage: f.kernel_basis() # optional - sage.groups sage.modules ([1, 2, 3] - [3, 2, 1], [1, 3, 2] - [3, 2, 1], [2, 1, 3] - [3, 2, 1]) """ return tuple(map( self.domain().from_vector, @@ -731,12 +737,12 @@ def kernel(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: K = f.kernel() - sage: K + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules + sage: K = f.kernel() # optional - sage.groups sage.modules + sage: K # optional - sage.groups sage.modules Free module generated by {0, 1, 2} over Rational Field - sage: K.ambient() + sage: K.ambient() # optional - sage.groups sage.modules Symmetric group algebra of order 3 over Rational Field """ D = self.domain() @@ -749,9 +755,9 @@ def image_basis(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: f.image_basis() + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules + sage: f.image_basis() # optional - sage.groups sage.modules ([1, 2, 3], [2, 3, 1], [3, 1, 2]) """ C = self.codomain() @@ -763,9 +769,9 @@ def image(self): EXAMPLES:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) - sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) - sage: f.image() + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups sage.modules + sage: f = SGA.module_morphism(lambda x: SGA(x**2), codomain=SGA) # optional - sage.groups sage.modules + sage: f.image() # optional - sage.groups sage.modules Free module generated by {0, 1, 2} over Rational Field """ C = self.codomain() @@ -781,10 +787,12 @@ def extra_super_categories(self): EXAMPLES:: - sage: ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts().extra_super_categories() + sage: C = ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts() + sage: C.extra_super_categories() [Category of finite dimensional modules with basis over Integer Ring] - sage: ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts().FiniteDimensional() - Category of tensor products of finite dimensional modules with basis over Integer Ring + sage: C.FiniteDimensional() + Category of tensor products of + finite dimensional modules with basis over Integer Ring """ return [self.base_category()] diff --git a/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py index fe0ad9f3d21..8f1300854b3 100644 --- a/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py @@ -60,16 +60,16 @@ def _test_nilpotency(self, **options): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) - sage: L._test_nilpotency() - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, - ....: nilpotent=True, step = 3) - sage: L._test_nilpotency() + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules + sage: L._test_nilpotency() # optional - sage.combinat sage.modules + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, # optional - sage.combinat sage.modules + ....: nilpotent=True, step=3) + sage: L._test_nilpotency() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: claimed nilpotency step 3 does not match the actual nilpotency step 2 - sage: L = LieAlgebra(QQ, {('X','Y'): {'X': 1}}, nilpotent=True) - sage: L._test_nilpotency() + sage: L = LieAlgebra(QQ, {('X','Y'): {'X': 1}}, nilpotent=True) # optional - sage.combinat sage.modules + sage: L._test_nilpotency() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: final term of lower central series is non-zero @@ -100,28 +100,29 @@ def lie_group(self, name='G', **kwds): We define the Heisenberg group:: - sage: L = lie_algebras.Heisenberg(QQ, 1) - sage: G = L.lie_group('G'); G # optional - sage.symbolic + sage: L = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: G = L.lie_group('G'); G # optional - sage.combinat sage.modules sage.symbolic Lie group G of Heisenberg algebra of rank 1 over Rational Field We test multiplying elements of the group:: - sage: p,q,z = L.basis() # optional - sage.symbolic - sage: g = G.exp(p); g # optional - sage.symbolic + sage: p, q, z = L.basis() # optional - sage.combinat sage.modules sage.symbolic + sage: g = G.exp(p); g # optional - sage.combinat sage.modules sage.symbolic exp(p1) - sage: h = G.exp(q); h # optional - sage.symbolic + sage: h = G.exp(q); h # optional - sage.combinat sage.modules sage.symbolic exp(q1) - sage: g*h # optional - sage.symbolic + sage: g * h # optional - sage.combinat sage.modules sage.symbolic exp(p1 + q1 + 1/2*z) We extend an element of the Lie algebra to a left-invariant vector field:: - sage: X = G.left_invariant_extension(2*p + 3*q, name='X'); X # optional - sage.symbolic - Vector field X on the Lie group G of Heisenberg algebra of rank 1 over Rational Field - sage: X.at(G.one()).display() # optional - sage.symbolic + sage: X = G.left_invariant_extension(2*p + 3*q, name='X'); X # optional - sage.combinat sage.modules sage.symbolic + Vector field X on the Lie group G of + Heisenberg algebra of rank 1 over Rational Field + sage: X.at(G.one()).display() # optional - sage.combinat sage.modules sage.symbolic X = 2 ∂/∂x_0 + 3 ∂/∂x_1 - sage: X.display() # optional - sage.symbolic + sage: X.display() # optional - sage.combinat sage.modules sage.symbolic X = 2 ∂/∂x_0 + 3 ∂/∂x_1 + (3/2*x_0 - x_1) ∂/∂x_2 .. SEEALSO:: @@ -137,11 +138,11 @@ def step(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) - sage: L.step() + sage: L = LieAlgebra(QQ, {('X','Y'): {'Z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules + sage: L.step() # optional - sage.combinat sage.modules 2 - sage: sc = {('X','Y'): {'Z': 1}, ('X','Z'): {'W': 1}} - sage: LieAlgebra(QQ, sc, nilpotent=True).step() + sage: sc = {('X','Y'): {'Z': 1}, ('X','Z'): {'W': 1}} # optional - sage.combinat sage.modules + sage: LieAlgebra(QQ, sc, nilpotent=True).step() # optional - sage.combinat sage.modules 3 """ if not hasattr(self, '_step'): @@ -154,8 +155,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, nilpotent=True) - sage: L.is_nilpotent() + sage: L = LieAlgebra(QQ, {('x','y'): {'z': 1}}, nilpotent=True) # optional - sage.combinat sage.modules + sage: L.is_nilpotent() # optional - sage.combinat sage.modules True """ return True diff --git a/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py b/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py index 59ab6a9a8ad..56303fc5eb0 100644 --- a/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_semisimple_algebras_with_basis.py @@ -49,13 +49,13 @@ def radical_basis(self, **keywords): EXAMPLES:: - sage: A = SymmetricGroup(4).algebra(QQ) - sage: A.radical_basis() + sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules + sage: A.radical_basis() # optional - sage.groups sage.modules () TESTS:: - sage: A.radical_basis.__module__ + sage: A.radical_basis.__module__ # optional - sage.groups sage.modules 'sage.categories.finite_dimensional_semisimple_algebras_with_basis' """ return () @@ -81,25 +81,25 @@ def central_orthogonal_idempotents(self): acts on `V_i` as multiplication by the `i`-th power of a cube root of unity:: - sage: R = CyclotomicField(3) - sage: A3 = AlternatingGroup(3).algebra(R) - sage: idempotents = A3.central_orthogonal_idempotents() - sage: idempotents + sage: R = CyclotomicField(3) # optional - sage.rings.number_field + sage: A3 = AlternatingGroup(3).algebra(R) # optional - sage.rings.number_field sage.groups + sage: idempotents = A3.central_orthogonal_idempotents() # optional - sage.rings.number_field sage.groups + sage: idempotents # optional - sage.rings.number_field sage.groups (1/3*() + 1/3*(1,2,3) + 1/3*(1,3,2), 1/3*() - (1/3*zeta3+1/3)*(1,2,3) - (-1/3*zeta3)*(1,3,2), 1/3*() - (-1/3*zeta3)*(1,2,3) - (1/3*zeta3+1/3)*(1,3,2)) - sage: A3.is_identity_decomposition_into_orthogonal_idempotents(idempotents) + sage: A3.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.rings.number_field sage.groups True For the semisimple quotient of a quiver algebra, we recover the vertices of the quiver:: - sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A + sage: A = FiniteDimensionalAlgebrasWithBasis(QQ).example(); A # optional - sage.combinat An example of a finite dimensional algebra with basis: the path algebra of the Kronecker quiver (containing the arrows a:x->y and b:x->y) over Rational Field - sage: Aquo = A.semisimple_quotient() - sage: Aquo.central_orthogonal_idempotents() + sage: Aquo = A.semisimple_quotient() # optional - sage.combinat + sage: Aquo.central_orthogonal_idempotents() # optional - sage.combinat (B['x'], B['y']) """ return tuple([x.lift() @@ -157,8 +157,8 @@ def _orthogonal_decomposition(self, generators=None): center of the algebra of the symmetric group `S_4`:: - sage: Z4 = SymmetricGroup(4).algebra(QQ).center() - sage: Z4._orthogonal_decomposition() + sage: Z4 = SymmetricGroup(4).algebra(QQ).center() # optional - sage.groups sage.modules + sage: Z4._orthogonal_decomposition() # optional - sage.groups sage.modules (B[0] + B[1] + B[2] + B[3] + B[4], B[0] + 1/3*B[1] - 1/3*B[2] - 1/3*B[4], B[0] + B[2] - 1/2*B[3], @@ -219,10 +219,10 @@ def central_orthogonal_idempotents(self): EXAMPLES:: - sage: A4 = SymmetricGroup(4).algebra(QQ) - sage: Z4 = A4.center() - sage: idempotents = Z4.central_orthogonal_idempotents() - sage: idempotents + sage: A4 = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules + sage: Z4 = A4.center() # optional - sage.groups sage.modules + sage: idempotents = Z4.central_orthogonal_idempotents() # optional - sage.groups sage.modules + sage: idempotents # optional - sage.groups sage.modules (1/24*B[0] + 1/24*B[1] + 1/24*B[2] + 1/24*B[3] + 1/24*B[4], 3/8*B[0] + 1/8*B[1] - 1/8*B[2] - 1/8*B[4], 1/6*B[0] + 1/6*B[2] - 1/12*B[3], @@ -233,7 +233,7 @@ def central_orthogonal_idempotents(self): recognize among them the sum and alternating sum of all permutations:: - sage: [e.lift() for e in idempotents] + sage: [e.lift() for e in idempotents] # optional - sage.groups sage.modules [1/24*() + 1/24*(3,4) + 1/24*(2,3) + 1/24*(2,3,4) + 1/24*(2,4,3) + 1/24*(2,4) + 1/24*(1,2) + 1/24*(1,2)(3,4) + 1/24*(1,2,3) + 1/24*(1,2,3,4) + 1/24*(1,2,4,3) + 1/24*(1,2,4) + 1/24*(1,3,2) @@ -251,7 +251,7 @@ def central_orthogonal_idempotents(self): We check that they indeed form a decomposition of the identity of `Z_4` into orthogonal idempotents:: - sage: Z4.is_identity_decomposition_into_orthogonal_idempotents(idempotents) + sage: Z4.is_identity_decomposition_into_orthogonal_idempotents(idempotents) # optional - sage.groups sage.modules True """ return tuple([(e.leading_coefficient()/(e*e).leading_coefficient())*e diff --git a/src/sage/categories/finite_enumerated_sets.py b/src/sage/categories/finite_enumerated_sets.py index 4a872cf2fbf..4d90a3cd3f9 100644 --- a/src/sage/categories/finite_enumerated_sets.py +++ b/src/sage/categories/finite_enumerated_sets.py @@ -59,9 +59,9 @@ def _call_(self, X): EXAMPLES:: - sage: FiniteEnumeratedSets()(GF(3)) + sage: FiniteEnumeratedSets()(GF(3)) # optional - sage.rings.finite_rings Finite Field of size 3 - sage: Partitions(3) + sage: Partitions(3) # optional - sage.combinat Partitions of the integer 3 For now, lists, tuples, sets, Sets are coerced into finite @@ -86,9 +86,9 @@ def __len__(self): EXAMPLES:: - sage: len(GF(5)) + sage: len(GF(5)) # optional - sage.rings.finite_rings 5 - sage: len(MatrixSpace(GF(2), 3, 3)) + sage: len(MatrixSpace(GF(2), 3, 3)) # optional - sage.rings.finite_rings sage.modules 512 """ return int(self.cardinality()) @@ -590,17 +590,17 @@ class ParentMethods: inherit various methods from `Sets.CartesianProducts` and not from :class:`EnumeratedSets.Finite`:: - sage: C = cartesian_product([Partitions(10), Permutations(20)]) - sage: C in EnumeratedSets().Finite() + sage: C = cartesian_product([Partitions(10), Permutations(20)]) # optional - sage.combinat + sage: C in EnumeratedSets().Finite() # optional - sage.combinat True - sage: C.random_element.__module__ + sage: C.random_element.__module__ # optional - sage.combinat 'sage.categories.sets_cat' - sage: C.cardinality.__module__ + sage: C.cardinality.__module__ # optional - sage.combinat 'sage.categories.sets_cat' - sage: C.__iter__.__module__ + sage: C.__iter__.__module__ # optional - sage.combinat 'sage.categories.sets_cat' """ random_element = raw_getattr(Sets.CartesianProducts.ParentMethods, "random_element") @@ -613,8 +613,9 @@ def last(self): EXAMPLES:: - sage: C = cartesian_product([Zmod(42), Partitions(10), IntegerRange(5)]) - sage: C.last() + sage: C = cartesian_product([Zmod(42), Partitions(10), # optional - sage.combinat + ....: IntegerRange(5)]) + sage: C.last() # optional - sage.combinat (41, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 4) """ return self._cartesian_product_of_elements( @@ -635,13 +636,13 @@ def rank(self, x): EXAMPLES:: - sage: C = cartesian_product([GF(2), GF(11), GF(7)]) - sage: C.rank(C((1,2,5))) + sage: C = cartesian_product([GF(2), GF(11), GF(7)]) # optional - sage.rings.finite_rings + sage: C.rank(C((1,2,5))) # optional - sage.rings.finite_rings 96 - sage: C.rank(C((0,0,0))) + sage: C.rank(C((0,0,0))) # optional - sage.rings.finite_rings 0 - sage: for c in C: print(C.rank(c)) + sage: for c in C: print(C.rank(c)) # optional - sage.rings.finite_rings 0 1 2 @@ -656,12 +657,12 @@ def rank(self, x): sage: F1 = FiniteEnumeratedSet('abcdefgh') sage: F2 = IntegerRange(250) - sage: F3 = Partitions(20) - sage: C = cartesian_product([F1, F2, F3]) - sage: c = C(('a', 86, [7,5,4,4])) - sage: C.rank(c) + sage: F3 = Partitions(20) # optional - sage.combinat + sage: C = cartesian_product([F1, F2, F3]) # optional - sage.combinat + sage: c = C(('a', 86, [7,5,4,4])) # optional - sage.combinat + sage: C.rank(c) # optional - sage.combinat 54213 - sage: C.unrank(54213) + sage: C.unrank(54213) # optional - sage.combinat ('a', 86, [7, 5, 4, 4]) """ from builtins import zip @@ -691,18 +692,18 @@ def unrank(self, i): EXAMPLES:: - sage: C = cartesian_product([GF(3), GF(11), GF(7), GF(5)]) - sage: c = C.unrank(123); c + sage: C = cartesian_product([GF(3), GF(11), GF(7), GF(5)]) # optional - sage.rings.finite_rings + sage: c = C.unrank(123); c # optional - sage.rings.finite_rings (0, 3, 3, 3) - sage: C.rank(c) + sage: C.rank(c) # optional - sage.rings.finite_rings 123 - sage: c = C.unrank(857); c + sage: c = C.unrank(857); c # optional - sage.rings.finite_rings (2, 2, 3, 2) - sage: C.rank(c) + sage: C.rank(c) # optional - sage.rings.finite_rings 857 - sage: C.unrank(2500) + sage: C.unrank(2500) # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: index i (=2) is greater than the cardinality diff --git a/src/sage/categories/finite_fields.py b/src/sage/categories/finite_fields.py index 25a93c8b960..b685a249780 100644 --- a/src/sage/categories/finite_fields.py +++ b/src/sage/categories/finite_fields.py @@ -34,7 +34,7 @@ class FiniteFields(CategoryWithAxiom): Some examples of membership testing and coercion:: - sage: FiniteField(17) in K + sage: FiniteField(17) in K # optional - sage.rings.finite_rings True sage: RationalField() in K False @@ -67,7 +67,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in FiniteFields() + sage: GF(4, "a") in FiniteFields() # optional - sage.rings.finite_rings True sage: QQ in FiniteFields() False @@ -82,7 +82,7 @@ def _call_(self, x): """ EXAMPLES:: - sage: FiniteFields()(GF(4, "a")) + sage: FiniteFields()(GF(4, "a")) # optional - sage.rings.finite_rings Finite Field in a of size 2^2 sage: FiniteFields()(RationalField()) # indirect doctest Traceback (most recent call last): diff --git a/src/sage/categories/finite_groups.py b/src/sage/categories/finite_groups.py index 42415233567..1d0e7d72357 100644 --- a/src/sage/categories/finite_groups.py +++ b/src/sage/categories/finite_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups r""" Finite groups """ diff --git a/src/sage/categories/finite_lattice_posets.py b/src/sage/categories/finite_lattice_posets.py index 4b7f0fb9b28..1bb0de98fad 100644 --- a/src/sage/categories/finite_lattice_posets.py +++ b/src/sage/categories/finite_lattice_posets.py @@ -49,8 +49,8 @@ def join_irreducibles(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) - sage: L.join_irreducibles() + sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) # optional - sage.combinat sage.graphs + sage: L.join_irreducibles() # optional - sage.combinat sage.graphs [1, 2, 4] .. SEEALSO:: @@ -71,8 +71,8 @@ def join_irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) - sage: L.join_irreducibles_poset() + sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # optional - sage.combinat sage.graphs + sage: L.join_irreducibles_poset() # optional - sage.combinat sage.graphs Finite poset containing 3 elements .. SEEALSO:: @@ -92,8 +92,8 @@ def meet_irreducibles(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) - sage: L.meet_irreducibles() + sage: L = LatticePoset({0:[1,2],1:[3],2:[3,4],3:[5],4:[5]}) # optional - sage.combinat sage.graphs + sage: L.meet_irreducibles() # optional - sage.combinat sage.graphs [1, 3, 4] .. SEEALSO:: @@ -114,8 +114,8 @@ def meet_irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) - sage: L.join_irreducibles_poset() + sage: L = LatticePoset({0:[1,2,3],1:[4],2:[4],3:[4]}) # optional - sage.combinat sage.graphs + sage: L.join_irreducibles_poset() # optional - sage.combinat sage.graphs Finite poset containing 3 elements .. SEEALSO:: @@ -143,20 +143,20 @@ def irreducibles_poset(self): EXAMPLES:: - sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], + sage: L = LatticePoset({1: [2, 3, 4], 2: [5, 6], 3: [5], # optional - sage.combinat sage.graphs ....: 4: [6], 5: [9, 7], 6: [9, 8], 7: [10], ....: 8: [10], 9: [10], 10: [11]}) - sage: L_ = L.irreducibles_poset() - sage: sorted(L_) + sage: L_ = L.irreducibles_poset() # optional - sage.combinat sage.graphs + sage: sorted(L_) # optional - sage.combinat sage.graphs [2, 3, 4, 7, 8, 9, 10, 11] - sage: L_.completion_by_cuts().is_isomorphic(L) + sage: L_.completion_by_cuts().is_isomorphic(L) # optional - sage.combinat sage.graphs True TESTS:: - sage: LatticePoset().irreducibles_poset() + sage: LatticePoset().irreducibles_poset() # optional - sage.combinat sage.graphs Finite poset containing 0 elements - sage: posets.ChainPoset(1).irreducibles_poset() + sage: posets.ChainPoset(1).irreducibles_poset() # optional - sage.combinat sage.graphs Finite poset containing 1 elements """ if self.cardinality() == 1: @@ -191,35 +191,36 @@ def is_lattice_morphism(self, f, codomain): lattice of divisors of `60`, and check that the map `b \mapsto 5 \prod_{x\in b} x` is a morphism of lattices:: - sage: D = LatticePoset((divisors(60), attrcall("divides"))) - sage: B = LatticePoset((Subsets([2,2,3]), attrcall("issubset"))) - sage: def f(b): return D(5*prod(b)) - sage: B.is_lattice_morphism(f, D) + sage: D = LatticePoset((divisors(60), attrcall("divides"))) # optional - sage.combinat sage.graphs + sage: B = LatticePoset((Subsets([2,2,3]), attrcall("issubset"))) # optional - sage.combinat sage.graphs + sage: def f(b): return D(5*prod(b)) # optional - sage.combinat sage.graphs + sage: B.is_lattice_morphism(f, D) # optional - sage.combinat sage.graphs True We construct the boolean lattice `B_2`:: - sage: B = posets.BooleanLattice(2) - sage: B.cover_relations() + sage: B = posets.BooleanLattice(2) # optional - sage.combinat sage.graphs + sage: B.cover_relations() # optional - sage.combinat sage.graphs [[0, 1], [0, 2], [1, 3], [2, 3]] And the same lattice with new top and bottom elements numbered respectively `-1` and `3`:: - sage: L = LatticePoset(DiGraph({-1:[0], 0:[1,2], 1:[3], 2:[3],3:[4]})) - sage: L.cover_relations() + sage: G = DiGraph({-1:[0], 0:[1,2], 1:[3], 2:[3], 3:[4]}) # optional - sage.graphs + sage: L = LatticePoset(G) # optional - sage.combinat sage.graphs + sage: L.cover_relations() # optional - sage.combinat sage.graphs [[-1, 0], [0, 1], [0, 2], [1, 3], [2, 3], [3, 4]] - sage: f = { B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(3) }.__getitem__ - sage: B.is_lattice_morphism(f, L) + sage: f = {B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(3)}.__getitem__ # optional - sage.combinat sage.graphs + sage: B.is_lattice_morphism(f, L) # optional - sage.combinat sage.graphs True - sage: f = { B(0): L(-1),B(1): L(1), B(2): L(2), B(3): L(3) }.__getitem__ - sage: B.is_lattice_morphism(f, L) + sage: f = {B(0): L(-1),B(1): L(1), B(2): L(2), B(3): L(3)}.__getitem__ # optional - sage.combinat sage.graphs + sage: B.is_lattice_morphism(f, L) # optional - sage.combinat sage.graphs False - sage: f = { B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(4) }.__getitem__ - sage: B.is_lattice_morphism(f, L) + sage: f = {B(0): L(0), B(1): L(1), B(2): L(2), B(3): L(4)}.__getitem__ # optional - sage.combinat sage.graphs + sage: B.is_lattice_morphism(f, L) # optional - sage.combinat sage.graphs False .. SEEALSO:: diff --git a/src/sage/categories/finite_monoids.py b/src/sage/categories/finite_monoids.py index fdf1db47a71..9531b671249 100644 --- a/src/sage/categories/finite_monoids.py +++ b/src/sage/categories/finite_monoids.py @@ -72,9 +72,9 @@ def nerve(self): The nerve (classifying space) of the cyclic group of order 2 is infinite-dimensional real projective space. :: - sage: Sigma2 = groups.permutation.Cyclic(2) - sage: BSigma2 = Sigma2.nerve() - sage: BSigma2.cohomology(4, base_ring=GF(2)) + sage: Sigma2 = groups.permutation.Cyclic(2) # optional - sage.groups + sage: BSigma2 = Sigma2.nerve() # optional - sage.groups + sage: BSigma2.cohomology(4, base_ring=GF(2)) # optional - sage.groups sage.modules sage.rings.finite_rings Vector space of dimension 1 over Finite Field of size 2 The `k`-simplices of the nerve are named after the chains @@ -83,45 +83,45 @@ def nerve(self): element) and ``(1,2)`` in Sage. So the 1-cells and 2-cells in `B\Sigma_2` are:: - sage: BSigma2.n_cells(1) + sage: BSigma2.n_cells(1) # optional - sage.groups [(1,2)] - sage: BSigma2.n_cells(2) + sage: BSigma2.n_cells(2) # optional - sage.groups [(1,2) * (1,2)] Another construction of the group, with different names for its elements:: - sage: C2 = groups.misc.MultiplicativeAbelian([2]) - sage: BC2 = C2.nerve() - sage: BC2.n_cells(0) + sage: C2 = groups.misc.MultiplicativeAbelian([2]) # optional - sage.groups + sage: BC2 = C2.nerve() # optional - sage.groups + sage: BC2.n_cells(0) # optional - sage.groups [1] - sage: BC2.n_cells(1) + sage: BC2.n_cells(1) # optional - sage.groups [f] - sage: BC2.n_cells(2) + sage: BC2.n_cells(2) # optional - sage.groups [f * f] With mod `p` coefficients, `B \Sigma_p` should have its first nonvanishing homology group in dimension `p`:: - sage: Sigma3 = groups.permutation.Symmetric(3) - sage: BSigma3 = Sigma3.nerve() - sage: BSigma3.homology(range(4), base_ring=GF(3)) + sage: Sigma3 = groups.permutation.Symmetric(3) # optional - sage.groups + sage: BSigma3 = Sigma3.nerve() # optional - sage.groups + sage: BSigma3.homology(range(4), base_ring=GF(3)) # optional - sage.groups sage.rings.finite_rings {0: Vector space of dimension 0 over Finite Field of size 3, - 1: Vector space of dimension 0 over Finite Field of size 3, - 2: Vector space of dimension 0 over Finite Field of size 3, - 3: Vector space of dimension 1 over Finite Field of size 3} + 1: Vector space of dimension 0 over Finite Field of size 3, + 2: Vector space of dimension 0 over Finite Field of size 3, + 3: Vector space of dimension 1 over Finite Field of size 3} Note that we can construct the `n`-skeleton for `B\Sigma_2` for relatively large values of `n`, while for `B\Sigma_3`, the complexes get large pretty quickly:: - sage: Sigma2.nerve().n_skeleton(14) + sage: Sigma2.nerve().n_skeleton(14) # optional - sage.groups Simplicial set with 15 non-degenerate simplices - sage: BSigma3 = Sigma3.nerve() - sage: BSigma3.n_skeleton(3) + sage: BSigma3 = Sigma3.nerve() # optional - sage.groups + sage: BSigma3.n_skeleton(3) # optional - sage.groups Simplicial set with 156 non-degenerate simplices - sage: BSigma3.n_skeleton(4) + sage: BSigma3.n_skeleton(4) # optional - sage.groups Simplicial set with 781 non-degenerate simplices Finally, note that the classifying space of the order `p` @@ -129,33 +129,33 @@ def nerve(self): on `p` letters, and its first homology group appears earlier:: - sage: C3 = groups.misc.MultiplicativeAbelian([3]) - sage: list(C3) + sage: C3 = groups.misc.MultiplicativeAbelian([3]) # optional - sage.groups + sage: list(C3) # optional - sage.groups [1, f, f^2] - sage: BC3 = C3.nerve() - sage: BC3.n_cells(1) + sage: BC3 = C3.nerve() # optional - sage.groups + sage: BC3.n_cells(1) # optional - sage.groups [f, f^2] - sage: BC3.n_cells(2) + sage: BC3.n_cells(2) # optional - sage.groups [f * f, f * f^2, f^2 * f, f^2 * f^2] - sage: len(BSigma3.n_cells(2)) + sage: len(BSigma3.n_cells(2)) # optional - sage.groups 25 - sage: len(BC3.n_cells(3)) + sage: len(BC3.n_cells(3)) # optional - sage.groups 8 - sage: len(BSigma3.n_cells(3)) + sage: len(BSigma3.n_cells(3)) # optional - sage.groups 125 - sage: BC3.homology(range(4), base_ring=GF(3)) + sage: BC3.homology(range(4), base_ring=GF(3)) # optional - sage.groups sage.rings.finite_rings {0: Vector space of dimension 0 over Finite Field of size 3, 1: Vector space of dimension 1 over Finite Field of size 3, 2: Vector space of dimension 1 over Finite Field of size 3, 3: Vector space of dimension 1 over Finite Field of size 3} - sage: BC5 = groups.permutation.Cyclic(5).nerve() - sage: BC5.homology(range(4), base_ring=GF(5)) + sage: BC5 = groups.permutation.Cyclic(5).nerve() # optional - sage.groups + sage: BC5.homology(range(4), base_ring=GF(5)) # optional - sage.groups sage.rings.finite_rings {0: Vector space of dimension 0 over Finite Field of size 5, - 1: Vector space of dimension 1 over Finite Field of size 5, - 2: Vector space of dimension 1 over Finite Field of size 5, - 3: Vector space of dimension 1 over Finite Field of size 5} + 1: Vector space of dimension 1 over Finite Field of size 5, + 2: Vector space of dimension 1 over Finite Field of size 5, + 3: Vector space of dimension 1 over Finite Field of size 5} """ from sage.topology.simplicial_set_examples import Nerve return Nerve(self) @@ -179,20 +179,20 @@ def rhodes_radical_congruence(self, base_ring=None): EXAMPLES:: sage: M = Monoids().Finite().example() - sage: M.rhodes_radical_congruence() + sage: M.rhodes_radical_congruence() # optional - sage.groups sage.modules [(0, 6), (2, 8), (4, 10)] - sage: from sage.monoids.hecke_monoid import HeckeMonoid - sage: H3 = HeckeMonoid(SymmetricGroup(3)) - sage: H3.repr_element_method(style="reduced") - sage: H3.rhodes_radical_congruence() + sage: from sage.monoids.hecke_monoid import HeckeMonoid # optional - sage.groups sage.modules + sage: H3 = HeckeMonoid(SymmetricGroup(3)) # optional - sage.groups sage.modules + sage: H3.repr_element_method(style="reduced") # optional - sage.groups sage.modules + sage: H3.rhodes_radical_congruence() # optional - sage.groups sage.modules [([1, 2], [2, 1]), ([1, 2], [1, 2, 1]), ([2, 1], [1, 2, 1])] By Maschke's theorem, every group algebra over `\QQ` is semisimple hence the Rhodes radical of a group must be trivial:: - sage: SymmetricGroup(3).rhodes_radical_congruence() + sage: SymmetricGroup(3).rhodes_radical_congruence() # optional - sage.groups sage.modules [] - sage: DihedralGroup(10).rhodes_radical_congruence() + sage: DihedralGroup(10).rhodes_radical_congruence() # optional - sage.groups sage.modules [] REFERENCES: diff --git a/src/sage/categories/finite_permutation_groups.py b/src/sage/categories/finite_permutation_groups.py index 59c00471e3f..e081d2d4f63 100644 --- a/src/sage/categories/finite_permutation_groups.py +++ b/src/sage/categories/finite_permutation_groups.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.groups r""" Finite Permutation Groups """ diff --git a/src/sage/categories/finite_posets.py b/src/sage/categories/finite_posets.py index b5422adfd4e..263033a2c9b 100644 --- a/src/sage/categories/finite_posets.py +++ b/src/sage/categories/finite_posets.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Finite posets diff --git a/src/sage/categories/finite_semigroups.py b/src/sage/categories/finite_semigroups.py index a7f9b9a20a1..e9c31e1ad62 100644 --- a/src/sage/categories/finite_semigroups.py +++ b/src/sage/categories/finite_semigroups.py @@ -51,7 +51,8 @@ class FiniteSemigroups(CategoryWithAxiom): sage: sorted(C.axioms()) ['Associative', 'Finite'] sage: C.example() - An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd') + An example of a finite semigroup: + the left regular band generated by ('a', 'b', 'c', 'd') TESTS:: @@ -86,8 +87,9 @@ def j_classes(self): EXAMPLES:: sage: S = FiniteSemigroups().example(alphabet=('a','b', 'c')) - sage: sorted(map(sorted, S.j_classes())) - [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] + sage: sorted(map(sorted, S.j_classes())) # optional - sage.graphs + [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], + ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] """ return self.cayley_graph(side="twosided", simple=True).strongly_connected_components() @@ -103,8 +105,9 @@ def j_classes_of_idempotents(self): EXAMPLES:: sage: S = FiniteSemigroups().example(alphabet=('a','b', 'c')) - sage: sorted(map(sorted, S.j_classes_of_idempotents())) - [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] + sage: sorted(map(sorted, S.j_classes_of_idempotents())) # optional - sage.graphs + [['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], + ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']] """ return [l for l in ([x for x in cl if attrcall('is_idempotent')(x)] for cl in self.j_classes()) if len(l) > 0] @@ -120,7 +123,7 @@ def j_transversal_of_idempotents(self): The chosen elements depend on the order of each `J`-class, and that order is random when using Python 3. :: - sage: sorted(S.j_transversal_of_idempotents()) # random + sage: sorted(S.j_transversal_of_idempotents()) # random # optional - sage.graphs ['a', 'ab', 'abc', 'ac', 'b', 'c', 'cb'] """ def first_idempotent(l): diff --git a/src/sage/categories/finite_weyl_groups.py b/src/sage/categories/finite_weyl_groups.py index 4420827c833..1d1d0250c23 100644 --- a/src/sage/categories/finite_weyl_groups.py +++ b/src/sage/categories/finite_weyl_groups.py @@ -27,7 +27,7 @@ class FiniteWeylGroups(CategoryWithAxiom): TESTS:: sage: W = FiniteWeylGroups().example() - sage: TestSuite(W).run() + sage: TestSuite(W).run() # optional - sage.combinat """ class ParentMethods: diff --git a/src/sage/categories/finitely_generated_lambda_bracket_algebras.py b/src/sage/categories/finitely_generated_lambda_bracket_algebras.py index 8877491e33e..f36e4e52738 100644 --- a/src/sage/categories/finitely_generated_lambda_bracket_algebras.py +++ b/src/sage/categories/finitely_generated_lambda_bracket_algebras.py @@ -27,7 +27,7 @@ class FinitelyGeneratedLambdaBracketAlgebras(CategoryWithAxiom_over_base_ring): EXAMPLES:: sage: from sage.categories.lambda_bracket_algebras import LambdaBracketAlgebras - sage: LambdaBracketAlgebras(QQbar).FinitelyGenerated() + sage: LambdaBracketAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field Category of finitely generated lambda bracket algebras over Algebraic Field """ _base_category_class_and_axiom = (LambdaBracketAlgebras, "FinitelyGeneratedAsLambdaBracketAlgebra") @@ -38,12 +38,12 @@ def ngens(self): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) - sage: Vir.ngens() + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: Vir.ngens() # optional - sage.combinat sage.modules 2 - sage: V = lie_conformal_algebras.Affine(QQ, 'A2') - sage: V.ngens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A2') # optional - sage.combinat sage.modules + sage: V.ngens() # optional - sage.combinat sage.modules 9 """ return len(self.gens()) @@ -54,12 +54,12 @@ def gen(self,i): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') - sage: V.gens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: V.gens() # optional - sage.combinat sage.modules (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: V.gen(0) + sage: V.gen(0) # optional - sage.combinat sage.modules B[alpha[1]] - sage: V.1 + sage: V.1 # optional - sage.combinat sage.modules B[alphacheck[1]] """ return self.gens()[i] @@ -73,10 +73,11 @@ def some_elements(self): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) - sage: V.some_elements() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.some_elements() # optional - sage.combinat sage.modules [e, h, f, K, ...] - sage: all(v.parent() is V for v in V.some_elements()) + sage: all(v.parent() is V for v in V.some_elements()) # optional - sage.combinat sage.modules True """ S = list(self.gens()) @@ -91,8 +92,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() - Category of H-graded finitely generated lie conformal algebras over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated lie conformal algebras + over Algebraic Field """ def _repr_object_names(self): """ @@ -100,7 +102,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) diff --git a/src/sage/categories/finitely_generated_lie_conformal_algebras.py b/src/sage/categories/finitely_generated_lie_conformal_algebras.py index 464d1eb7d03..3aaa8264606 100644 --- a/src/sage/categories/finitely_generated_lie_conformal_algebras.py +++ b/src/sage/categories/finitely_generated_lie_conformal_algebras.py @@ -27,7 +27,7 @@ class FinitelyGeneratedLieConformalAlgebras(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated() + sage: LieConformalAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field Category of finitely generated lie conformal algebras over Algebraic Field """ _base_category_class_and_axiom = (LieConformalAlgebras, "FinitelyGeneratedAsLambdaBracketAlgebra") @@ -43,10 +43,11 @@ def some_elements(self): EXAMPLES:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) - sage: V.some_elements() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.some_elements() # optional - sage.combinat sage.modules [e, h, f, K, ...] - sage: all(v.parent() is V for v in V.some_elements()) + sage: all(v.parent() is V for v in V.some_elements()) # optional - sage.combinat sage.modules True """ S = list(self.gens()) @@ -61,8 +62,9 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).FinitelyGenerated().Super() - Category of super finitely generated lie conformal algebras over Algebraic Real Field + sage: LieConformalAlgebras(AA).FinitelyGenerated().Super() # optional - sage.rings.number_field + Category of super finitely generated lie conformal algebras + over Algebraic Real Field """ class Graded(GradedModulesCategory): """ @@ -70,8 +72,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Super().Graded() - Category of H-graded super finitely generated lie conformal algebras over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Super().Graded() # optional - sage.rings.number_field + Category of H-graded super finitely generated lie conformal algebras + over Algebraic Field """ def _repr_object_names(self): """ @@ -79,8 +82,8 @@ def _repr_object_names(self): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).FinitelyGenerated() - sage: C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar).FinitelyGenerated() # optional - sage.rings.number_field + sage: C.Super().Graded() # optional - sage.rings.number_field Category of H-graded super finitely generated lie conformal algebras over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) @@ -91,8 +94,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() - Category of H-graded finitely generated lie conformal algebras over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated lie conformal algebras + over Algebraic Field """ def _repr_object_names(self): """ @@ -100,7 +104,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) diff --git a/src/sage/categories/functor.pyx b/src/sage/categories/functor.pyx index a0e8b42e1bf..4ee9a328634 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -112,12 +112,12 @@ cdef class Functor(SageObject): this behaviour. Here we illustrate the default:: sage: from sage.categories.functor import Functor - sage: F = Functor(Rings(),Fields()) + sage: F = Functor(Rings(), Fields()) sage: F Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) + sage: F(GF(2)) # optional - sage.rings.finite_rings Finite Field of size 2 Functors are not only about the objects of a category, but also about @@ -128,7 +128,7 @@ cdef class Functor(SageObject): sage: R1. = ZZ[] sage: R2. = QQ[] - sage: f = R1.hom([a+b],R2) + sage: f = R1.hom([a + b], R2) sage: f Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring @@ -150,8 +150,10 @@ cdef class Functor(SageObject): Poly[t] sage: F(f) Ring morphism: - From: Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring - To: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field + From: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in x over Integer Ring + To: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in a, b over Rational Field Defn: Induced from base ring by Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring @@ -159,7 +161,8 @@ cdef class Functor(SageObject): Defn: x |--> a + b sage: p = R1['t']('(-x^2 + x)*t^2 + (x^2 - x)*t - 4*x^2 - x + 1') sage: F(f)(p) - (-a^2 - 2*a*b - b^2 + a + b)*t^2 + (a^2 + 2*a*b + b^2 - a - b)*t - 4*a^2 - 8*a*b - 4*b^2 - a - b + 1 + (-a^2 - 2*a*b - b^2 + a + b)*t^2 + (a^2 + 2*a*b + b^2 - a - b)*t + - 4*a^2 - 8*a*b - 4*b^2 - a - b + 1 """ def __init__(self, domain, codomain): @@ -167,12 +170,12 @@ cdef class Functor(SageObject): TESTS:: sage: from sage.categories.functor import Functor - sage: F = Functor(Rings(),Fields()) + sage: F = Functor(Rings(), Fields()) sage: F Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) + sage: F(GF(2)) # optional - sage.rings.finite_rings Finite Field of size 2 """ @@ -228,7 +231,7 @@ cdef class Functor(SageObject): TESTS:: sage: from sage.categories.functor import Functor - sage: F = Functor(FiniteFields(),Fields()) + sage: F = Functor(FiniteFields(), Fields()) sage: F._apply_functor(ZZ) Rational Field @@ -248,20 +251,22 @@ cdef class Functor(SageObject): TESTS:: sage: from sage.categories.functor import Functor - sage: F = Functor(Rings(),Fields()) - sage: k. = GF(25) - sage: f = k.hom([-a-4]) - sage: R. = k[] - sage: fR = R.hom(f,R) - sage: fF = F(fR) # indirect doctest - sage: fF - Ring endomorphism of Fraction Field of Univariate Polynomial Ring in t over Finite Field in a of size 5^2 + sage: F = Functor(Rings(), Fields()) + sage: k. = GF(25) # optional - sage.rings.finite_rings + sage: f = k.hom([-a - 4]) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: fR = R.hom(f, R) # optional - sage.rings.finite_rings + sage: fF = F(fR) # indirect doctest # optional - sage.rings.finite_rings + sage: fF # optional - sage.rings.finite_rings + Ring endomorphism of Fraction Field of + Univariate Polynomial Ring in t over Finite Field in a of size 5^2 Defn: Induced from base ring by - Ring endomorphism of Univariate Polynomial Ring in t over Finite Field in a of size 5^2 + Ring endomorphism of Univariate Polynomial Ring in t + over Finite Field in a of size 5^2 Defn: Induced from base ring by Ring endomorphism of Finite Field in a of size 5^2 Defn: a |--> 4*a + 1 - sage: fF((a^2+a)*t^2/(a*t - a^2)) + sage: fF((a^2+a)*t^2/(a*t - a^2)) # optional - sage.rings.finite_rings ((4*a + 2)*t^2)/(t + a + 4) """ @@ -334,13 +339,13 @@ cdef class Functor(SageObject): Functor from Category of rings to Category of fields sage: F(ZZ) Rational Field - sage: F(GF(2)) + sage: F(GF(2)) # optional - sage.rings.finite_rings Finite Field of size 2 Two subclasses:: - sage: F1 = ForgetfulFunctor(FiniteFields(),Fields()) - sage: F1(GF(5)) #indirect doctest + sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) + sage: F1(GF(5)) # indirect doctest # optional - sage.rings.finite_rings Finite Field of size 5 sage: F1(ZZ) Traceback (most recent call last): @@ -352,7 +357,8 @@ cdef class Functor(SageObject): sage: F2(ZZ['x','y']) Traceback (most recent call last): ... - TypeError: x (=Multivariate Polynomial Ring in x, y over Integer Ring) is not in Category of fields + TypeError: x (=Multivariate Polynomial Ring in x, y over Integer Ring) + is not in Category of fields The last example shows that it is tested whether the result of applying the functor lies in the functor's codomain. Note that @@ -360,20 +366,22 @@ cdef class Functor(SageObject): which was fixed in :trac:`8807`:: sage: class IllFunctor(Functor): - ....: def __init__(self, m,n): + ....: def __init__(self, m, n): ....: self._m = m ....: self._n = n - ....: Functor.__init__(self,Rings(),Rings()) + ....: Functor.__init__(self, Rings(), Rings()) ....: def _apply_functor(self, R): - ....: return MatrixSpace(R,self._m,self._n) - sage: F = IllFunctor(2,2) + ....: return MatrixSpace(R, self._m, self._n) + sage: F = IllFunctor(2, 2) sage: F(QQ) Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: F = IllFunctor(2,3) + sage: F = IllFunctor(2, 3) sage: F(QQ) Traceback (most recent call last): ... - TypeError: Functor from Category of rings to Category of rings is ill-defined, since it sends x (=Rational Field) to something that is not in Category of rings. + TypeError: Functor from Category of rings to Category of rings + is ill-defined, since it sends x (=Rational Field) to something + that is not in Category of rings. """ from sage.categories.morphism import is_Morphism @@ -390,7 +398,7 @@ cdef class Functor(SageObject): EXAMPLES:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) sage: F.domain() Category of finite enumerated fields @@ -403,7 +411,7 @@ cdef class Functor(SageObject): EXAMPLES:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) sage: F.codomain() Category of fields @@ -456,10 +464,12 @@ class ForgetfulFunctor_generic(Functor): EXAMPLES:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) #indirect doctest + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) # indirect doctest sage: F - The forgetful functor from Category of finite enumerated fields to Category of fields - sage: F(GF(3)) + The forgetful functor + from Category of finite enumerated fields + to Category of fields + sage: F(GF(3)) # optional - sage.rings.finite_rings Finite Field of size 3 """ @@ -477,7 +487,7 @@ class ForgetfulFunctor_generic(Functor): """ TESTS:: - sage: F = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F = ForgetfulFunctor(FiniteFields(), Fields()) sage: F #indirect doctest The forgetful functor from Category of finite enumerated fields to Category of fields @@ -497,7 +507,7 @@ class ForgetfulFunctor_generic(Functor): TESTS:: - sage: F1 = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) This is to test against a bug occurring in a previous version (see :trac:`8800`):: @@ -524,7 +534,7 @@ class ForgetfulFunctor_generic(Functor): EXAMPLES:: - sage: F1 = ForgetfulFunctor(FiniteFields(),Fields()) + sage: F1 = ForgetfulFunctor(FiniteFields(), Fields()) sage: F1 != F1 False sage: F1 != QQ @@ -665,14 +675,17 @@ def ForgetfulFunctor(domain, codomain): sage: abgrps = CommutativeAdditiveGroups() sage: F = ForgetfulFunctor(rings, abgrps) sage: F - The forgetful functor from Category of rings to Category of commutative additive groups + The forgetful functor + from Category of rings + to Category of commutative additive groups It would be a mistake to call it in opposite order:: sage: F = ForgetfulFunctor(abgrps, rings) Traceback (most recent call last): ... - ValueError: Forgetful functor not supported for domain Category of commutative additive groups + ValueError: Forgetful functor not supported for domain + Category of commutative additive groups If both categories are equal, the forgetful functor is the same as the identity functor:: diff --git a/src/sage/categories/g_sets.py b/src/sage/categories/g_sets.py index b9447203e42..0f8004ddbf0 100644 --- a/src/sage/categories/g_sets.py +++ b/src/sage/categories/g_sets.py @@ -23,8 +23,8 @@ class GSets(Category): EXAMPLES:: - sage: S = SymmetricGroup(3) - sage: GSets(S) + sage: S = SymmetricGroup(3) # optional - sage.groups + sage: GSets(S) # optional - sage.groups Category of G-sets for Symmetric group of order 3! as a permutation group TODO: should this derive from Category_over_base? @@ -33,8 +33,8 @@ def __init__(self, G): """ TESTS:: - sage: S8 = SymmetricGroup(8) - sage: TestSuite(GSets(S8)).run() + sage: S8 = SymmetricGroup(8) # optional - sage.groups + sage: TestSuite(GSets(S8)).run() # optional - sage.groups """ Category.__init__(self) self.__G = G @@ -43,7 +43,7 @@ def _repr_object_names(self): """ EXAMPLES:: - sage: GSets(SymmetricGroup(8)) # indirect doctests + sage: GSets(SymmetricGroup(8)) # indirect doctests # optional - sage.groups Category of G-sets for Symmetric group of order 8! as a permutation group """ return "G-sets for %s"%self.__G @@ -55,7 +55,7 @@ def super_categories(self): """ EXAMPLES:: - sage: GSets(SymmetricGroup(8)).super_categories() + sage: GSets(SymmetricGroup(8)).super_categories() # optional - sage.groups [Category of sets] """ return [Sets()] @@ -67,7 +67,7 @@ def an_instance(cls): EXAMPLES:: - sage: GSets.an_instance() # indirect doctest + sage: GSets.an_instance() # indirect doctest # optional - sage.groups Category of G-sets for Symmetric group of order 8! as a permutation group """ from sage.groups.perm_gps.permgroup_named import SymmetricGroup diff --git a/src/sage/categories/graded_algebras.py b/src/sage/categories/graded_algebras.py index 54ce5775c9e..efa1a501192 100644 --- a/src/sage/categories/graded_algebras.py +++ b/src/sage/categories/graded_algebras.py @@ -39,8 +39,8 @@ def graded_algebra(self): EXAMPLES:: - sage: m = SymmetricFunctions(QQ).m() - sage: m.graded_algebra() is m + sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat + sage: m.graded_algebra() is m # optional - sage.combinat True """ return self diff --git a/src/sage/categories/graded_algebras_with_basis.py b/src/sage/categories/graded_algebras_with_basis.py index b4df3c3c260..52d80b78b4e 100644 --- a/src/sage/categories/graded_algebras_with_basis.py +++ b/src/sage/categories/graded_algebras_with_basis.py @@ -46,8 +46,8 @@ def graded_algebra(self): EXAMPLES:: - sage: m = SymmetricFunctions(QQ).m() - sage: m.graded_algebra() is m + sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat + sage: m.graded_algebra() is m # optional - sage.combinat sage.modules True TESTS: @@ -57,21 +57,21 @@ def graded_algebra(self): and :meth:`projection` (which form the interface of the associated graded algebra) work correctly here:: - sage: to_gr = m.to_graded_conversion() - sage: from_gr = m.from_graded_conversion() - sage: m[2] == to_gr(m[2]) == from_gr(m[2]) + sage: to_gr = m.to_graded_conversion() # optional - sage.combinat sage.modules + sage: from_gr = m.from_graded_conversion() # optional - sage.combinat sage.modules + sage: m[2] == to_gr(m[2]) == from_gr(m[2]) # optional - sage.combinat sage.modules True - sage: u = 3*m[1] - (1/2)*m[3] - sage: u == to_gr(u) == from_gr(u) + sage: u = 3*m[1] - (1/2)*m[3] # optional - sage.combinat sage.modules + sage: u == to_gr(u) == from_gr(u) # optional - sage.combinat sage.modules True - sage: m.zero() == to_gr(m.zero()) == from_gr(m.zero()) + sage: m.zero() == to_gr(m.zero()) == from_gr(m.zero()) # optional - sage.combinat sage.modules True - sage: p2 = m.projection(2) - sage: p2(m[2] - 4*m[1,1] + 3*m[1] - 2*m[[]]) + sage: p2 = m.projection(2) # optional - sage.combinat sage.modules + sage: p2(m[2] - 4*m[1,1] + 3*m[1] - 2*m[[]]) # optional - sage.combinat sage.modules -4*m[1, 1] + m[2] - sage: p2(4*m[1]) + sage: p2(4*m[1]) # optional - sage.combinat sage.modules 0 - sage: p2(m.zero()) == m.zero() + sage: p2(m.zero()) == m.zero() # optional - sage.combinat sage.modules True """ return self @@ -111,13 +111,13 @@ def free_graded_module(self, generator_degrees, names=None): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) - sage: Cl = CliffordAlgebra(Q) - sage: M = Cl.free_graded_module((0, 2, 3)) - sage: M.gens() + sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6]) # optional - sage.modules + sage: Cl = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: M = Cl.free_graded_module((0, 2, 3)) # optional - sage.combinat sage.modules + sage: M.gens() # optional - sage.combinat sage.modules (g[0], g[2], g[3]) - sage: N. = Cl.free_graded_module((1, 2)) - sage: N.generators() + sage: N. = Cl.free_graded_module((1, 2)) # optional - sage.combinat sage.modules + sage: N.generators() # optional - sage.combinat sage.modules (xy, z) """ try: @@ -134,10 +134,10 @@ def formal_series_ring(self): EXAMPLES:: - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) - sage: S = NCSF.Complete() - sage: L = S.formal_series_ring() - sage: L + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # optional - sage.combinat + sage: S = NCSF.Complete() # optional - sage.combinat + sage: L = S.formal_series_ring() # optional - sage.combinat + sage: L # optional - sage.combinat Lazy completion of Non-Commutative Symmetric Functions over the Rational Field in the Complete basis """ @@ -185,13 +185,13 @@ def one_basis(self): EXAMPLES:: - sage: A. = ExteriorAlgebra(QQ) - sage: A.one_basis() + sage: A. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules 0 - sage: B = tensor((A, A, A)) - sage: B.one_basis() + sage: B = tensor((A, A, A)) # optional - sage.combinat sage.modules + sage: B.one_basis() # optional - sage.combinat sage.modules (0, 0, 0) - sage: B.one() + sage: B.one() # optional - sage.combinat sage.modules 1 # 1 # 1 """ # FIXME: this method should be conditionally defined, @@ -211,10 +211,10 @@ def product_on_basis(self, t0, t1): Test the sign in the super tensor product:: - sage: A = SteenrodAlgebra(3) - sage: x = A.Q(0) - sage: y = x.coproduct() - sage: y^2 + sage: A = SteenrodAlgebra(3) # optional - sage.combinat sage.modules + sage: x = A.Q(0) # optional - sage.combinat sage.modules + sage: y = x.coproduct() # optional - sage.combinat sage.modules + sage: y^2 # optional - sage.combinat sage.modules 0 TODO: optimize this implementation! diff --git a/src/sage/categories/graded_hopf_algebras_with_basis.py b/src/sage/categories/graded_hopf_algebras_with_basis.py index d806597ae0c..204ab23013e 100644 --- a/src/sage/categories/graded_hopf_algebras_with_basis.py +++ b/src/sage/categories/graded_hopf_algebras_with_basis.py @@ -44,7 +44,7 @@ def example(self): TESTS:: - sage: GradedHopfAlgebrasWithBasis(QQ).example() + sage: GradedHopfAlgebrasWithBasis(QQ).example() # optional - sage.modules An example of a graded connected Hopf algebra with basis over Rational Field """ from sage.categories.examples.graded_connected_hopf_algebras_with_basis import \ @@ -85,7 +85,7 @@ def example(self): TESTS:: - sage: GradedHopfAlgebrasWithBasis(QQ).Connected().example() + sage: GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules An example of a graded connected Hopf algebra with basis over Rational Field """ from sage.categories.examples.graded_connected_hopf_algebras_with_basis import \ @@ -114,10 +114,10 @@ def counit_on_basis(self, i): EXAMPLES:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.monomial(4).counit() # indirect doctest + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules + sage: H.monomial(4).counit() # indirect doctest # optional - sage.modules 0 - sage: H.monomial(0).counit() # indirect doctest + sage: H.monomial(0).counit() # indirect doctest # optional - sage.modules 1 """ if i == self.one_basis(): @@ -144,14 +144,14 @@ def antipode_on_basis(self, index): TESTS:: - sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() - sage: H.monomial(0).antipode() # indirect doctest + sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() # optional - sage.modules + sage: H.monomial(0).antipode() # indirect doctest # optional - sage.modules P0 - sage: H.monomial(1).antipode() # indirect doctest + sage: H.monomial(1).antipode() # indirect doctest # optional - sage.modules -P1 - sage: H.monomial(2).antipode() # indirect doctest + sage: H.monomial(2).antipode() # indirect doctest # optional - sage.modules P2 - sage: H.monomial(3).antipode() # indirect doctest + sage: H.monomial(3).antipode() # indirect doctest # optional - sage.modules -P3 """ if self.monomial(index) == self.one(): diff --git a/src/sage/categories/graded_lie_conformal_algebras.py b/src/sage/categories/graded_lie_conformal_algebras.py index 66950ecce53..2650492898d 100644 --- a/src/sage/categories/graded_lie_conformal_algebras.py +++ b/src/sage/categories/graded_lie_conformal_algebras.py @@ -31,11 +31,11 @@ def Super(self, base_ring=None): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) - sage: C.Graded().Super() is C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: C.Graded().Super() is C.Super().Graded() # optional - sage.rings.number_field True - sage: Cp = C.WithBasis() - sage: Cp.Graded().Super() is Cp.Super().Graded() + sage: Cp = C.WithBasis() # optional - sage.rings.number_field + sage: Cp.Graded().Super() is Cp.Super().Graded() # optional - sage.rings.number_field True """ return self.base_category().Super(base_ring).Graded() @@ -46,10 +46,10 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).Graded() + sage: LieConformalAlgebras(QQbar).Graded() # optional - sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) @@ -60,7 +60,7 @@ class GradedLieConformalAlgebras(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).Graded(); C + sage: C = LieConformalAlgebras(QQbar).Graded(); C # optional - sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field sage: CS = LieConformalAlgebras(QQ).Graded().Super(); CS diff --git a/src/sage/categories/graded_modules_with_basis.py b/src/sage/categories/graded_modules_with_basis.py index 1868147bedb..b1185e20352 100644 --- a/src/sage/categories/graded_modules_with_basis.py +++ b/src/sage/categories/graded_modules_with_basis.py @@ -46,17 +46,18 @@ def degree_negation(self, element): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: E.degree_negation((1 + a) * (1 + b)) + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: E.degree_negation((1 + a) * (1 + b)) # optional - sage.combinat sage.modules a*b - a - b + 1 - sage: E.degree_negation(E.zero()) + sage: E.degree_negation(E.zero()) # optional - sage.combinat sage.modules 0 - sage: P = GradedModulesWithBasis(ZZ).example(); P - An example of a graded module with basis: the free module on partitions over Integer Ring - sage: pbp = lambda x: P.basis()[Partition(list(x))] - sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) - sage: P.degree_negation(p) + sage: P = GradedModulesWithBasis(ZZ).example(); P # optional - sage.combinat sage.modules + An example of a graded module with basis: + the free module on partitions over Integer Ring + sage: pbp = lambda x: P.basis()[Partition(list(x))] # optional - sage.combinat sage.modules + sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) # optional - sage.combinat sage.modules + sage: P.degree_negation(p) # optional - sage.combinat sage.modules -4*P[1] - 2*P[2] + P[3, 1] """ base_one = self.base_ring().one() @@ -114,56 +115,63 @@ def submodule(self, gens, check=True, already_echelonized=False, A graded submodule of a graded module generated by homogeneous elements is naturally graded:: - sage: E. = ExteriorAlgebra(QQ) - sage: S = E.submodule([x + y, x*y - y*z]) - sage: S.category() - Join of Category of graded vector spaces with basis over Rational Field - and Category of subobjects of filtered modules with basis over Rational Field - and Category of finite dimensional vector spaces with basis over Rational Field - sage: S.basis()[0].degree() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: S = E.submodule([x + y, x*y - y*z]) # optional - sage.combinat sage.modules + sage: S.category() # optional - sage.combinat sage.modules + Join of + Category of graded vector spaces with basis over Rational Field and + Category of subobjects of filtered modules with basis over Rational Field and + Category of finite dimensional vector spaces with basis over Rational Field + sage: S.basis()[0].degree() # optional - sage.combinat sage.modules 1 - sage: S.basis()[1].degree() + sage: S.basis()[1].degree() # optional - sage.combinat sage.modules 2 We check on the echelonized basis:: - sage: Sp = E.submodule([1, x + y + 5, x*y - y*z + x + y - 2]) - sage: Sp.category() - Join of Category of graded vector spaces with basis over Rational Field - and Category of subobjects of filtered modules with basis over Rational Field - and Category of finite dimensional vector spaces with basis over Rational Field + sage: Sp = E.submodule([1, x + y + 5, x*y - y*z + x + y - 2]) # optional - sage.combinat sage.modules + sage: Sp.category() # optional - sage.combinat sage.modules + Join of + Category of graded vector spaces with basis over Rational Field and + Category of subobjects of filtered modules with basis over Rational Field and + Category of finite dimensional vector spaces with basis over Rational Field If it is generated by inhomogeneous elements, then it is filtered by default:: - sage: F = E.submodule([x + y*z, x*z + y*x]) - sage: F.category() - Join of Category of subobjects of filtered modules with basis over Rational Field - and Category of filtered vector spaces with basis over Rational Field - and Category of finite dimensional vector spaces with basis over Rational Field + sage: F = E.submodule([x + y*z, x*z + y*x]) # optional - sage.combinat sage.modules + sage: F.category() # optional - sage.combinat sage.modules + Join of + Category of subobjects of filtered modules with basis over Rational Field and + Category of filtered vector spaces with basis over Rational Field and + Category of finite dimensional vector spaces with basis over Rational Field If ``category`` is specified, then it does not give any extra structure to the submodule (we can think of this as applying the forgetful functor):: - sage: SM = E.submodule([x + y, x*y - y*z], category=ModulesWithBasis(QQ)) - sage: SM.category() - Join of Category of finite dimensional vector spaces with basis over Rational Field - and Category of subobjects of sets - sage: FM = E.submodule([x + 1, x*y - x*y*z], category=ModulesWithBasis(QQ)) - sage: FM.category() - Join of Category of finite dimensional vector spaces with basis over Rational Field - and Category of subobjects of sets + sage: SM = E.submodule([x + y, x*y - y*z], # optional - sage.combinat sage.modules + ....: category=ModulesWithBasis(QQ)) + sage: SM.category() # optional - sage.combinat sage.modules + Join of + Category of finite dimensional vector spaces with basis over Rational Field and + Category of subobjects of sets + sage: FM = E.submodule([x + 1, x*y - x*y*z], # optional - sage.combinat sage.modules + ....: category=ModulesWithBasis(QQ)) + sage: FM.category() # optional - sage.combinat sage.modules + Join of + Category of finite dimensional vector spaces with basis over Rational Field and + Category of subobjects of sets If we have specified that this is a graded submodule of a graded module, then the echelonized elements must be homogeneous:: sage: Cat = ModulesWithBasis(QQ).Graded().Subobjects() - sage: E.submodule([x + y, x*y - 1], category=Cat) + sage: E.submodule([x + y, x*y - 1], category=Cat) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: all of the generators must be homogeneous - sage: E.submodule([x + y, x*y - x - y], category=Cat) + sage: E.submodule([x + y, x*y - x - y], category=Cat) # optional - sage.combinat sage.modules Free module generated by {0, 1} over Rational Field """ # Make sure gens consists of elements of ``self`` @@ -215,13 +223,14 @@ def quotient_module(self, submodule, check=True, already_echelonized=False, cate EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: S = E.submodule([x + y, x*y - y*z, y]) - sage: Q = E.quotient_module(S) - sage: Q.category() - Join of Category of quotients of graded modules with basis over Rational Field - and Category of graded vector spaces with basis over Rational Field - and Category of finite dimensional vector spaces with basis over Rational Field + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules + sage: Q = E.quotient_module(S) # optional - sage.combinat sage.modules + sage: Q.category() # optional - sage.combinat sage.modules + Join of + Category of quotients of graded modules with basis over Rational Field and + Category of graded vector spaces with basis over Rational Field and + Category of finite dimensional vector spaces with basis over Rational Field .. SEEALSO:: @@ -258,17 +267,18 @@ def degree_negation(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: ((1 + a) * (1 + b)).degree_negation() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: ((1 + a) * (1 + b)).degree_negation() # optional - sage.combinat sage.modules a*b - a - b + 1 - sage: E.zero().degree_negation() + sage: E.zero().degree_negation() # optional - sage.combinat sage.modules 0 - sage: P = GradedModulesWithBasis(ZZ).example(); P - An example of a graded module with basis: the free module on partitions over Integer Ring - sage: pbp = lambda x: P.basis()[Partition(list(x))] - sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) - sage: p.degree_negation() + sage: P = GradedModulesWithBasis(ZZ).example(); P # optional - sage.combinat sage.modules + An example of a graded module with basis: + the free module on partitions over Integer Ring + sage: pbp = lambda x: P.basis()[Partition(list(x))] # optional - sage.combinat sage.modules + sage: p = pbp([3,1]) - 2 * pbp([2]) + 4 * pbp([1]) # optional - sage.combinat sage.modules + sage: p.degree_negation() # optional - sage.combinat sage.modules -4*P[1] - 2*P[2] + P[3, 1] """ return self.parent().degree_negation(self) @@ -282,13 +292,13 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: S = E.submodule([x + y, x*y - y*z, y]) - sage: Q = E.quotient_module(S) - sage: B = Q.basis() - sage: [B[i].lift() for i in Q.indices()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules + sage: Q = E.quotient_module(S) # optional - sage.combinat sage.modules + sage: B = Q.basis() # optional - sage.combinat sage.modules + sage: [B[i].lift() for i in Q.indices()] # optional - sage.combinat sage.modules [1, z, x*z, y*z, x*y*z] - sage: [Q.degree_on_basis(i) for i in Q.indices()] + sage: [Q.degree_on_basis(i) for i in Q.indices()] # optional - sage.combinat sage.modules [0, 1, 2, 2, 3] """ return self.basis()[m].lift().degree() @@ -300,13 +310,13 @@ def degree(self): EXAMPLES:: - sage: E. = ExteriorAlgebra(QQ) - sage: S = E.submodule([x + y, x*y - y*z, y]) - sage: Q = E.quotient_module(S) - sage: B = Q.basis() - sage: [B[i].lift() for i in Q.indices()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: S = E.submodule([x + y, x*y - y*z, y]) # optional - sage.combinat sage.modules + sage: Q = E.quotient_module(S) # optional - sage.combinat sage.modules + sage: B = Q.basis() # optional - sage.combinat sage.modules + sage: [B[i].lift() for i in Q.indices()] # optional - sage.combinat sage.modules [1, z, x*z, y*z, x*y*z] - sage: [B[i].degree() for i in Q.indices()] + sage: [B[i].degree() for i in Q.indices()] # optional - sage.combinat sage.modules [0, 1, 2, 2, 3] """ return self.lift().degree() diff --git a/src/sage/categories/group_algebras.py b/src/sage/categories/group_algebras.py index 0df6bf44165..46e36fd47cf 100644 --- a/src/sage/categories/group_algebras.py +++ b/src/sage/categories/group_algebras.py @@ -50,15 +50,16 @@ class GroupAlgebras(AlgebrasCategory): Here is how to create the group algebra of a group `G`:: - sage: G = DihedralGroup(5) - sage: QG = G.algebra(QQ); QG - Algebra of Dihedral group of order 10 as a permutation group over Rational Field + sage: G = DihedralGroup(5) # optional - sage.groups + sage: QG = G.algebra(QQ); QG # optional - sage.groups sage.modules + Algebra of + Dihedral group of order 10 as a permutation group over Rational Field and an example of computation:: - sage: g = G.an_element(); g + sage: g = G.an_element(); g # optional - sage.groups sage.modules (1,4)(2,3) - sage: (QG.term(g) + 1)**3 + sage: (QG.term(g) + 1)**3 # optional - sage.groups sage.modules 4*() + 4*(1,4)(2,3) .. TODO:: @@ -68,14 +69,14 @@ class GroupAlgebras(AlgebrasCategory): TESTS:: - sage: A = GroupAlgebras(QQ).example(GL(3, GF(11))) - sage: A.one_basis() + sage: A = GroupAlgebras(QQ).example(GL(3, GF(11))) # optional - sage.groups sage.modules sage.rings.finite_rings + sage: A.one_basis() # optional - sage.groups sage.modules sage.rings.finite_rings [1 0 0] [0 1 0] [0 0 1] - sage: A = SymmetricGroupAlgebra(QQ,4) - sage: x = Permutation([4,3,2,1]) - sage: A.product_on_basis(x,x) + sage: A = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules sage.combinat + sage: x = Permutation([4,3,2,1]) # optional - sage.groups sage.modules sage.combinat + sage: A.product_on_basis(x, x) # optional - sage.groups sage.modules sage.combinat [1, 2, 3, 4] sage: C = GroupAlgebras(ZZ) @@ -104,13 +105,15 @@ def example(self, G=None): EXAMPLES:: - sage: GroupAlgebras(QQ['x']).example() - Algebra of Dihedral group of order 8 as a permutation group over Univariate Polynomial Ring in x over Rational Field + sage: GroupAlgebras(QQ['x']).example() # optional - sage.groups sage.modules + Algebra of Dihedral group of order 8 as a permutation group + over Univariate Polynomial Ring in x over Rational Field An other group can be specified as optional argument:: - sage: GroupAlgebras(QQ).example(AlternatingGroup(4)) - Algebra of Alternating group of order 4!/2 as a permutation group over Rational Field + sage: GroupAlgebras(QQ).example(AlternatingGroup(4)) # optional - sage.groups sage.modules + Algebra of + Alternating group of order 4!/2 as a permutation group over Rational Field """ from sage.groups.perm_gps.permgroup_named import DihedralGroup if G is None: @@ -124,19 +127,19 @@ def __init_extra__(self): EXAMPLES:: - sage: A = GroupAlgebra(SymmetricGroup(4), QQ) - sage: B = GroupAlgebra(SymmetricGroup(3), ZZ) - sage: A.has_coerce_map_from(B) + sage: A = GroupAlgebra(SymmetricGroup(4), QQ) # optional - sage.groups sage.modules + sage: B = GroupAlgebra(SymmetricGroup(3), ZZ) # optional - sage.groups sage.modules + sage: A.has_coerce_map_from(B) # optional - sage.groups sage.modules True - sage: B.has_coerce_map_from(A) + sage: B.has_coerce_map_from(A) # optional - sage.groups sage.modules False - sage: A.has_coerce_map_from(ZZ) + sage: A.has_coerce_map_from(ZZ) # optional - sage.groups sage.modules True - sage: A.has_coerce_map_from(CC) + sage: A.has_coerce_map_from(CC) # optional - sage.groups sage.modules False - sage: A.has_coerce_map_from(SymmetricGroup(5)) + sage: A.has_coerce_map_from(SymmetricGroup(5)) # optional - sage.groups sage.modules False - sage: A.has_coerce_map_from(SymmetricGroup(2)) + sage: A.has_coerce_map_from(SymmetricGroup(2)) # optional - sage.groups sage.modules True """ if not self.base_ring().has_coerce_map_from(self.group()): @@ -152,8 +155,8 @@ def _latex_(self): EXAMPLES:: - sage: A = GroupAlgebra(KleinFourGroup(), ZZ) - sage: latex(A) # indirect doctest + sage: A = GroupAlgebra(KleinFourGroup(), ZZ) # optional - sage.groups sage.modules + sage: latex(A) # indirect doctest # optional - sage.groups sage.modules \Bold{Z}[\langle (3,4), (1,2) \rangle] """ from sage.misc.latex import latex @@ -165,9 +168,9 @@ def group(self): EXAMPLES:: - sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() + sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() # optional - sage.groups sage.modules sage.rings.finite_rings General Linear Group of degree 3 over Finite Field of size 11 - sage: SymmetricGroup(10).algebra(QQ).group() + sage: SymmetricGroup(10).algebra(QQ).group() # optional - sage.groups sage.modules Symmetric group of order 10! as a permutation group """ return self.basis().keys() @@ -195,7 +198,7 @@ def center_basis(self): EXAMPLES:: - sage: SymmetricGroup(3).algebra(QQ).center_basis() + sage: SymmetricGroup(3).algebra(QQ).center_basis() # optional - sage.groups sage.modules ((), (2,3) + (1,2) + (1,3), (1,2,3) + (1,3,2)) .. SEEALSO:: @@ -217,15 +220,16 @@ def coproduct_on_basis(self, g): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A - Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: g = CyclicPermutationGroup(6).an_element(); g + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + Algebra of + Cyclic group of order 6 as a permutation group over Integer Ring + sage: g = CyclicPermutationGroup(6).an_element(); g # optional - sage.groups sage.modules (1,2,3,4,5,6) - sage: A.coproduct_on_basis(g) + sage: A.coproduct_on_basis(g) # optional - sage.groups sage.modules (1,2,3,4,5,6) # (1,2,3,4,5,6) - sage: a = A.an_element(); a + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.coproduct() + sage: a.coproduct() # optional - sage.groups sage.modules () # () + 3*(1,2,3,4,5,6) # (1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) # (1,3,5)(2,4,6) """ from sage.categories.tensor import tensor @@ -242,15 +246,16 @@ def antipode_on_basis(self,g): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A - Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: g = CyclicPermutationGroup(6).an_element();g + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + Algebra of + Cyclic group of order 6 as a permutation group over Integer Ring + sage: g = CyclicPermutationGroup(6).an_element(); g # optional - sage.groups sage.modules (1,2,3,4,5,6) - sage: A.antipode_on_basis(g) + sage: A.antipode_on_basis(g) # optional - sage.groups sage.modules (1,6,5,4,3,2) - sage: a = A.an_element(); a + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.antipode() + sage: a.antipode() # optional - sage.groups sage.modules () + 3*(1,5,3)(2,6,4) + 3*(1,6,5,4,3,2) """ return self.term(~g) @@ -265,11 +270,12 @@ def counit_on_basis(self,g): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ);A - Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: g = CyclicPermutationGroup(6).an_element();g + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + Algebra of + Cyclic group of order 6 as a permutation group over Integer Ring + sage: g = CyclicPermutationGroup(6).an_element(); g # optional - sage.groups sage.modules (1,2,3,4,5,6) - sage: A.counit_on_basis(g) + sage: A.counit_on_basis(g) # optional - sage.groups sage.modules 1 """ return self.base_ring().one() @@ -284,11 +290,12 @@ def counit(self,x): EXAMPLES:: - sage: A = CyclicPermutationGroup(6).algebra(ZZ); A - Algebra of Cyclic group of order 6 as a permutation group over Integer Ring - sage: a = A.an_element(); a + sage: A = CyclicPermutationGroup(6).algebra(ZZ); A # optional - sage.groups sage.modules + Algebra of + Cyclic group of order 6 as a permutation group over Integer Ring + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + 3*(1,2,3,4,5,6) + 3*(1,3,5)(2,4,6) - sage: a.counit() + sage: a.counit() # optional - sage.groups sage.modules 7 """ return self.base_ring().sum(x.coefficients()) @@ -305,17 +312,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: - sage: GroupAlgebra(SymmetricGroup(2)).is_integral_domain() + sage: S2 = SymmetricGroup(2) # optional - sage.groups + sage: GroupAlgebra(S2).is_integral_domain() # optional - sage.groups sage.modules False - sage: GroupAlgebra(SymmetricGroup(1)).is_integral_domain() + sage: S1 = SymmetricGroup(1) + sage: GroupAlgebra(S1).is_integral_domain() # optional - sage.groups sage.modules True - sage: GroupAlgebra(SymmetricGroup(1), IntegerModRing(4)).is_integral_domain() + sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain() # optional - sage.groups sage.modules False - sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain() + sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain() # optional - sage.groups sage.modules True - sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain() + sage: GroupAlgebra(AbelianGroup(2, [0,2])).is_integral_domain() # optional - sage.groups sage.modules False - sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented + sage: GroupAlgebra(GL(2, ZZ)).is_integral_domain() # not implemented # optional - sage.groups sage.modules False """ from sage.sets.set import Set @@ -385,22 +394,24 @@ def central_form(self): EXAMPLES:: - sage: QS3 = SymmetricGroup(3).algebra(QQ) - sage: A = QS3([2,3,1]) + QS3([3,1,2]) - sage: A.central_form() + sage: QS3 = SymmetricGroup(3).algebra(QQ) # optional - sage.groups sage.modules + sage: A = QS3([2,3,1]) + QS3([3,1,2]) # optional - sage.groups sage.modules + sage: A.central_form() # optional - sage.groups sage.modules B[(1,2,3)] - sage: QS4 = SymmetricGroup(4).algebra(QQ) - sage: B = sum(len(s.cycle_type())*QS4(s) for s in Permutations(4)) - sage: B.central_form() + sage: QS4 = SymmetricGroup(4).algebra(QQ) # optional - sage.groups sage.modules + sage: B = sum(len(s.cycle_type()) * QS4(s) for s in Permutations(4)) # optional - sage.groups sage.modules + sage: B.central_form() # optional - sage.groups sage.modules 4*B[()] + 3*B[(1,2)] + 2*B[(1,2)(3,4)] + 2*B[(1,2,3)] + B[(1,2,3,4)] The following test fails due to a bug involving combinatorial free modules and the coercion system (see :trac:`28544`):: - sage: QG = GroupAlgebras(QQ).example(PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])) - sage: s = sum(i for i in QG.basis()) - sage: s.central_form() # not tested - B[()] + B[(4,5)] + B[(3,4,5)] + B[(2,3)(4,5)] + B[(2,3,4,5)] + B[(1,2)(3,4,5)] + B[(1,2,3,4,5)] + sage: G = PermutationGroup([[(1,2,3),(4,5)], [(3,4)]]) # optional - sage.groups sage.modules + sage: QG = GroupAlgebras(QQ).example(G) # optional - sage.groups sage.modules + sage: s = sum(i for i in QG.basis()) # optional - sage.groups sage.modules + sage: s.central_form() # not tested # optional - sage.groups sage.modules + B[()] + B[(4,5)] + B[(3,4,5)] + B[(2,3)(4,5)] + + B[(2,3,4,5)] + B[(1,2)(3,4,5)] + B[(1,2,3,4,5)] .. SEEALSO:: diff --git a/src/sage/categories/groupoid.py b/src/sage/categories/groupoid.py index 4c6e3ae6042..9eee3750655 100644 --- a/src/sage/categories/groupoid.py +++ b/src/sage/categories/groupoid.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups r""" Groupoid """ diff --git a/src/sage/categories/groups.py b/src/sage/categories/groups.py index 97d57799f8c..569cfc0d36d 100644 --- a/src/sage/categories/groups.py +++ b/src/sage/categories/groups.py @@ -42,7 +42,7 @@ def example(self): """ EXAMPLES:: - sage: Groups().example() + sage: Groups().example() # optional - sage.groups General Linear Group of degree 4 over Rational Field """ from sage.rings.rational_field import QQ @@ -69,13 +69,13 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Groups.free(index_set=ZZ) + sage: Groups.free(index_set=ZZ) # optional - sage.groups Free group indexed by Integer Ring - sage: Groups().free(ZZ) + sage: Groups().free(ZZ) # optional - sage.groups Free group indexed by Integer Ring - sage: Groups().free(5) + sage: Groups().free(5) # optional - sage.groups Free Group on generators {x0, x1, x2, x3, x4} - sage: F. = Groups().free(); F + sage: F. = Groups().free(); F # optional - sage.groups Free Group on generators {x, y, z} """ from sage.rings.integer_ring import ZZ @@ -99,8 +99,8 @@ def group_generators(self): EXAMPLES:: - sage: A = AlternatingGroup(4) - sage: A.group_generators() + sage: A = AlternatingGroup(4) # optional - sage.groups + sage: A.group_generators() # optional - sage.groups Family ((2,3,4), (1,2,3)) """ from sage.sets.family import Family @@ -120,11 +120,11 @@ def monoid_generators(self): EXAMPLES:: - sage: A = AlternatingGroup(4) - sage: A.monoid_generators() + sage: A = AlternatingGroup(4) # optional - sage.groups + sage: A.monoid_generators() # optional - sage.groups Family ((2,3,4), (1,2,3)) - sage: F. = FreeGroup() - sage: F.monoid_generators() + sage: F. = FreeGroup() # optional - sage.groups + sage: F.monoid_generators() # optional - sage.groups Family (x, y, x^-1, y^-1) """ G = self.group_generators() @@ -142,8 +142,8 @@ def _test_inverse(self, **options): EXAMPLES:: - sage: G = SymmetricGroup(3) - sage: G._test_inverse() + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: G._test_inverse() # optional - sage.groups """ tester = self._tester(**options) for x in tester.some_elements(): @@ -156,11 +156,13 @@ def semidirect_product(self, N, mapping, check=True): EXAMPLES:: - sage: G = Groups().example() - sage: G.semidirect_product(G,Morphism(G,G)) + sage: G = Groups().example() # optional - sage.groups + sage: G.semidirect_product(G, Morphism(G, G)) # optional - sage.groups Traceback (most recent call last): ... - NotImplementedError: semidirect product of General Linear Group of degree 4 over Rational Field and General Linear Group of degree 4 over Rational Field not yet implemented + NotImplementedError: semidirect product of General Linear Group of degree 4 + over Rational Field and General Linear Group of degree 4 over Rational Field + not yet implemented """ raise NotImplementedError("semidirect product of %s and %s not yet implemented" % (self, N)) @@ -176,11 +178,12 @@ def holomorph(self): EXAMPLES:: - sage: G = Groups().example() - sage: G.holomorph() + sage: G = Groups().example() # optional - sage.groups + sage: G.holomorph() # optional - sage.groups Traceback (most recent call last): ... - NotImplementedError: holomorph of General Linear Group of degree 4 over Rational Field not yet implemented + NotImplementedError: holomorph of General Linear Group of degree 4 + over Rational Field not yet implemented """ raise NotImplementedError("holomorph of %s not yet implemented"%self) @@ -243,11 +246,11 @@ def cayley_table(self, names='letters', elements=None): Permutation groups, matrix groups and abelian groups can all compute their multiplication tables. :: - sage: G = DiCyclicGroup(3) - sage: T = G.cayley_table() - sage: T.column_keys() + sage: G = DiCyclicGroup(3) # optional - sage.groups + sage: T = G.cayley_table() # optional - sage.groups + sage: T.column_keys() # optional - sage.groups ((), (5,6,7), ..., (1,4,2,3)(5,7)) - sage: T + sage: T # optional - sage.groups * a b c d e f g h i j k l +------------------------ a| a b c d e f g h i j k l @@ -265,8 +268,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: M = SL(2, 2) - sage: M.cayley_table() + sage: M = SL(2, 2) # optional - sage.groups + sage: M.cayley_table() # optional - sage.groups * a b c d e f +------------ a| a b c d e f @@ -279,8 +282,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: A = AbelianGroup([2, 3]) - sage: A.cayley_table() + sage: A = AbelianGroup([2, 3]) # optional - sage.groups + sage: A.cayley_table() # optional - sage.groups * a b c d e f +------------ a| a b c d e f @@ -298,8 +301,8 @@ def cayley_table(self, names='letters', elements=None): you can choose to just use the string representations of the elements themselves. :: - sage: C = CyclicPermutationGroup(11) - sage: C.cayley_table(names='digits') + sage: C = CyclicPermutationGroup(11) # optional - sage.groups + sage: C.cayley_table(names='digits') # optional - sage.groups * 00 01 02 03 04 05 06 07 08 09 10 +--------------------------------- 00| 00 01 02 03 04 05 06 07 08 09 10 @@ -316,9 +319,9 @@ def cayley_table(self, names='letters', elements=None): :: - sage: G = QuaternionGroup() - sage: names = ['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] - sage: G.cayley_table(names=names) + sage: G = QuaternionGroup() # optional - sage.groups + sage: names = ['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] # optional - sage.groups + sage: G.cayley_table(names=names) # optional - sage.groups * 1 I -1 -I J -K -J K +------------------------ 1| 1 I -1 -I J -K -J K @@ -332,8 +335,8 @@ def cayley_table(self, names='letters', elements=None): :: - sage: A = AbelianGroup([2,2]) - sage: A.cayley_table(names='elements') + sage: A = AbelianGroup([2, 2]) # optional - sage.groups + sage: A.cayley_table(names='elements') # optional - sage.groups * 1 f1 f0 f0*f1 +------------------------ 1| 1 f1 f0 f0*f1 @@ -345,10 +348,10 @@ def cayley_table(self, names='letters', elements=None): routine behaves similarly, but changes an existing table "in-place." :: - sage: G = AlternatingGroup(3) - sage: T = G.cayley_table() - sage: T.change_names('digits') - sage: T + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = G.cayley_table() # optional - sage.groups + sage: T.change_names('digits') # optional - sage.groups + sage: T # optional - sage.groups * 0 1 2 +------ 0| 0 1 2 @@ -360,11 +363,11 @@ def cayley_table(self, names='letters', elements=None): Elements will be coerced into the group as part of setting up the table. :: - sage: G = SL(2,ZZ) - sage: G + sage: G = SL(2,ZZ) # optional - sage.groups + sage: G # optional - sage.groups Special Linear Group of degree 2 over Integer Ring - sage: identity = matrix(ZZ, [[1,0], [0,1]]) - sage: G.cayley_table(elements=[identity, -identity]) + sage: identity = matrix(ZZ, [[1,0], [0,1]]) # optional - sage.groups + sage: G.cayley_table(elements=[identity, -identity]) # optional - sage.groups * a b +---- a| a b @@ -381,11 +384,11 @@ class provides even greater flexibility, including changing confirms that they form a closed subset in the group. :: - sage: from sage.matrix.operation_table import OperationTable - sage: G = DiCyclicGroup(3) - sage: commutator = lambda x, y: x*y*x^-1*y^-1 - sage: T = OperationTable(G, commutator) - sage: T + sage: from sage.matrix.operation_table import OperationTable # optional - sage.groups + sage: G = DiCyclicGroup(3) # optional - sage.groups + sage: commutator = lambda x, y: x*y*x^-1*y^-1 # optional - sage.groups + sage: T = OperationTable(G, commutator) # optional - sage.groups + sage: T # optional - sage.groups . a b c d e f g h i j k l +------------------------ a| a a a a a a a a a a a a @@ -401,12 +404,12 @@ class provides even greater flexibility, including changing k| a b c a b c b a c b a c l| a b c a b c c b a c b a - sage: trans = T.translation() - sage: comm = [trans['a'], trans['b'], trans['c']] - sage: comm + sage: trans = T.translation() # optional - sage.groups + sage: comm = [trans['a'], trans['b'], trans['c']] # optional - sage.groups + sage: comm # optional - sage.groups [(), (5,6,7), (5,7,6)] - sage: P = G.cayley_table(elements=comm) - sage: P + sage: P = G.cayley_table(elements=comm) # optional - sage.groups + sage: P # optional - sage.groups * a b c +------ a| a b c @@ -437,9 +440,9 @@ def conjugacy_class(self, g): EXAMPLES:: - sage: A = AbelianGroup([2,2]) - sage: c = A.conjugacy_class(A.an_element()) - sage: type(c) + sage: A = AbelianGroup([2, 2]) # optional - sage.groups + sage: c = A.conjugacy_class(A.an_element()) # optional - sage.groups + sage: type(c) # optional - sage.groups """ from sage.groups.conjugacy_classes import ConjugacyClass @@ -452,29 +455,32 @@ def conjugacy_class(self): EXAMPLES:: - sage: D = DihedralGroup(5) - sage: g = D((1,3,5,2,4)) - sage: g.conjugacy_class() - Conjugacy class of (1,3,5,2,4) in Dihedral group of order 10 as a permutation group + sage: D = DihedralGroup(5) # optional - sage.groups + sage: g = D((1,3,5,2,4)) # optional - sage.groups + sage: g.conjugacy_class() # optional - sage.groups + Conjugacy class of (1,3,5,2,4) + in Dihedral group of order 10 as a permutation group - sage: H = MatrixGroup([matrix(GF(5),2,[1,2, -1, 1]), matrix(GF(5),2, [1,1, 0,1])]) - sage: h = H(matrix(GF(5),2,[1,2, -1, 1])) - sage: h.conjugacy_class() + sage: H = MatrixGroup([matrix(GF(5), 2, [1,2, -1,1]), # optional - sage.groups sage.rings.finite_rings sage.modules + ....: matrix(GF(5), 2, [1,1, 0,1])]) + sage: h = H(matrix(GF(5), 2, [1,2, -1,1])) # optional - sage.groups sage.rings.finite_rings sage.modules + sage: h.conjugacy_class() # optional - sage.groups sage.rings.finite_rings sage.modules Conjugacy class of [1 2] - [4 1] in Matrix group over Finite Field of size 5 with 2 generators ( + [4 1] + in Matrix group over Finite Field of size 5 with 2 generators ( [1 2] [1 1] [4 1], [0 1] ) - sage: G = SL(2, GF(2)) - sage: g = G.gens()[0] - sage: g.conjugacy_class() + sage: G = SL(2, GF(2)) # optional - sage.groups sage.rings.finite_rings sage.modules + sage: g = G.gens()[0] # optional - sage.groups sage.rings.finite_rings sage.modules + sage: g.conjugacy_class() # optional - sage.groups sage.rings.finite_rings sage.modules Conjugacy class of [1 1] [0 1] in Special Linear Group of degree 2 over Finite Field of size 2 - sage: G = SL(2, QQ) - sage: g = G([[1,1],[0,1]]) - sage: g.conjugacy_class() + sage: G = SL(2, QQ) # optional - sage.groups sage.modules + sage: g = G([[1,1], [0,1]]) # optional - sage.groups sage.modules + sage: g.conjugacy_class() # optional - sage.groups sage.modules Conjugacy class of [1 1] [0 1] in Special Linear Group of degree 2 over Rational Field """ @@ -505,13 +511,13 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Groups.Commutative.free(index_set=ZZ) + sage: Groups.Commutative.free(index_set=ZZ) # optional - sage.groups Free abelian group indexed by Integer Ring - sage: Groups().Commutative().free(ZZ) + sage: Groups().Commutative().free(ZZ) # optional - sage.groups Free abelian group indexed by Integer Ring - sage: Groups().Commutative().free(5) + sage: Groups().Commutative().free(5) # optional - sage.groups Multiplicative Abelian group isomorphic to Z x Z x Z x Z x Z - sage: F. = Groups().Commutative().free(); F + sage: F. = Groups().Commutative().free(); F # optional - sage.groups Multiplicative Abelian group isomorphic to Z x Z x Z """ from sage.rings.integer_ring import ZZ @@ -568,11 +574,11 @@ def group_generators(self): EXAMPLES:: - sage: C5 = CyclicPermutationGroup(5) - sage: C4 = CyclicPermutationGroup(4) - sage: S4 = SymmetricGroup(3) - sage: C = cartesian_product([C5, C4, S4]) - sage: C.group_generators() + sage: C5 = CyclicPermutationGroup(5) # optional - sage.groups + sage: C4 = CyclicPermutationGroup(4) # optional - sage.groups + sage: S4 = SymmetricGroup(3) # optional - sage.groups + sage: C = cartesian_product([C5, C4, S4]) # optional - sage.groups + sage: C.group_generators() # optional - sage.groups Family (((1,2,3,4,5), (), ()), ((), (1,2,3,4), ()), ((), (), (1,2)), @@ -580,16 +586,16 @@ def group_generators(self): We check the other portion of :trac:`16718` is fixed:: - sage: len(C.j_classes()) + sage: len(C.j_classes()) # optional - sage.groups 1 An example with an infinitely generated group (a better output is needed):: - sage: G = Groups.free([1,2]) - sage: H = Groups.free(ZZ) - sage: C = cartesian_product([G, H]) - sage: C.monoid_generators() + sage: G = Groups.free([1,2]) # optional - sage.groups + sage: H = Groups.free(ZZ) # optional - sage.groups + sage: C = cartesian_product([G, H]) # optional - sage.groups + sage: C.monoid_generators() # optional - sage.groups Lazy family (gen(i))_{i in The Cartesian product of (...)} """ F = self.cartesian_factors() @@ -622,13 +628,13 @@ def order(self): EXAMPLES:: - sage: C = cartesian_product([SymmetricGroup(10), SL(2,GF(3))]) - sage: C.order() + sage: C = cartesian_product([SymmetricGroup(10), SL(2, GF(3))]) # optional - sage.groups sage.rings.finite_rings + sage: C.order() # optional - sage.groups sage.rings.finite_rings 87091200 TESTS:: - sage: C.order.__module__ + sage: C.order.__module__ # optional - sage.groups sage.rings.finite_rings 'sage.categories.groups' .. TODO:: diff --git a/src/sage/categories/hecke_modules.py b/src/sage/categories/hecke_modules.py index 6b593d4fb3a..9372e88c54b 100644 --- a/src/sage/categories/hecke_modules.py +++ b/src/sage/categories/hecke_modules.py @@ -46,7 +46,7 @@ class HeckeModules(Category_module): sage: HeckeModules(IntegerRing()) Category of Hecke modules over Integer Ring - sage: HeckeModules(FiniteField(5)) + sage: HeckeModules(FiniteField(5)) # optional - sage.rings.finite_rings Category of Hecke modules over Finite Field of size 5 The base ring doesn't have to be a principal ideal domain:: @@ -64,7 +64,7 @@ def __init__(self, R): sage: TestSuite(HeckeModules(ZZ)).run() - sage: HeckeModules(Partitions(3)).run() + sage: HeckeModules(Partitions(3)).run() # optional - sage.combinat Traceback (most recent call last): ... TypeError: R (=Partitions of the integer 3) must be a commutative ring @@ -123,7 +123,10 @@ def _Hom_(self, Y, category): sage: M = ModularForms(Gamma0(7), 4) sage: H = M._Hom_(M, category = HeckeModules(QQ)); H - 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 + 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: TestSuite(H).run(skip=["_test_elements", "_test_an_element", "_test_elements_eq", @@ -142,7 +145,8 @@ def _Hom_(self, Y, category): sage: H = M._Hom_(M, category = HeckeModules(GF(5))); H Traceback (most recent call last): ... - TypeError: Category of Hecke modules over Finite Field of size 5 is not a subcategory of Category of Hecke modules over Rational Field + TypeError: Category of Hecke modules over Finite Field of size 5 + is not a subcategory of Category of Hecke modules over Rational Field """ # TODO: double check that it's the correct HeckeModules category below: if category is not None and not category.is_subcategory(HeckeModules(self.base_ring())): diff --git a/src/sage/categories/highest_weight_crystals.py b/src/sage/categories/highest_weight_crystals.py index b8afdee2117..226d310eb35 100644 --- a/src/sage/categories/highest_weight_crystals.py +++ b/src/sage/categories/highest_weight_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Highest Weight Crystals """ @@ -128,7 +129,8 @@ def highest_weight_vectors(self): :: sage: C = crystals.Letters(['A',2]) - sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]]) + sage: T = crystals.TensorProduct(C, C, C, generators=[[C(2),C(1),C(1)], + ....: [C(1),C(2),C(1)]]) sage: T.highest_weight_vectors() ([2, 1, 1], [1, 2, 1]) """ @@ -174,7 +176,8 @@ def lowest_weight_vectors(self): :: sage: C = crystals.Letters(['A',2]) - sage: T = crystals.TensorProduct(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]]) + sage: T = crystals.TensorProduct(C, C, C,generators=[[C(2),C(1),C(1)], + ....: [C(1),C(2),C(1)]]) sage: T.lowest_weight_vectors() ([3, 2, 3], [3, 3, 2]) """ diff --git a/src/sage/categories/homset.py b/src/sage/categories/homset.py index 88b162c5845..6554c895ff4 100644 --- a/src/sage/categories/homset.py +++ b/src/sage/categories/homset.py @@ -11,26 +11,26 @@ In the following, the :class:`Hom` object is indeed cached:: - sage: K = GF(17) - sage: H = Hom(ZZ, K) - sage: H + sage: K = GF(17) # optional - sage.rings.finite_rings + sage: H = Hom(ZZ, K) # optional - sage.rings.finite_rings + sage: H # optional - sage.rings.finite_rings Set of Homomorphisms from Integer Ring to Finite Field of size 17 - sage: H is Hom(ZZ, K) + sage: H is Hom(ZZ, K) # optional - sage.rings.finite_rings True Nonetheless, garbage collection occurs when the original references are overwritten:: - sage: for p in prime_range(200): + sage: for p in prime_range(200): # optional - sage.rings.finite_rings ....: K = GF(p) ....: H = Hom(ZZ, K) sage: import gc sage: _ = gc.collect() - sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF - sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] - sage: len(L) + sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF # optional - sage.rings.finite_rings + sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] # optional - sage.rings.finite_rings + sage: len(L) # optional - sage.rings.finite_rings 1 - sage: L + sage: L # optional - sage.rings.finite_rings [Finite Field of size 199] AUTHORS: @@ -104,34 +104,43 @@ def Hom(X, Y, category=None, check=True): EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: Hom(V, V) + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: Hom(V, V) # optional - sage.modules Set of Morphisms (Linear Transformations) from Vector space of dimension 3 over Rational Field to Vector space of dimension 3 over Rational Field - sage: G = AlternatingGroup(3) - sage: Hom(G, G) - Set of Morphisms from Alternating group of order 3!/2 as a permutation group to Alternating group of order 3!/2 as a permutation group in Category of finite enumerated permutation groups - sage: Hom(ZZ, QQ, Sets()) + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: Hom(G, G) # optional - sage.groups + Set of Morphisms + from Alternating group of order 3!/2 as a permutation group + to Alternating group of order 3!/2 as a permutation group + in Category of finite enumerated permutation groups + sage: Hom(ZZ, QQ, Sets()) # optional - sage.groups Set of Morphisms from Integer Ring to Rational Field in Category of sets - sage: Hom(FreeModule(ZZ,1), FreeModule(QQ,1)) - Set of Morphisms from Ambient free module of rank 1 over the principal ideal domain Integer Ring to Vector space of dimension 1 over Rational Field in Category of commutative additive groups - sage: Hom(FreeModule(QQ,1), FreeModule(ZZ,1)) - Set of Morphisms from Vector space of dimension 1 over Rational Field to Ambient free module of rank 1 over the principal ideal domain Integer Ring in Category of commutative additive groups + sage: Hom(FreeModule(ZZ, 1), FreeModule(QQ, 1)) # optional - sage.modules + Set of Morphisms + from Ambient free module of rank 1 over the principal ideal domain Integer Ring + to Vector space of dimension 1 over Rational Field + in Category of commutative additive groups + sage: Hom(FreeModule(QQ, 1), FreeModule(ZZ, 1)) # optional - sage.modules + Set of Morphisms + from Vector space of dimension 1 over Rational Field + to Ambient free module of rank 1 over the principal ideal domain Integer Ring + in Category of commutative additive groups Here, we test against a memory leak that has been fixed at :trac:`11521` by using a weak cache:: - sage: for p in prime_range(10^3): + sage: for p in prime_range(10^3): # optional - sage.rings.finite_rings ....: K = GF(p) ....: a = K(0) sage: import gc sage: gc.collect() # random 624 - sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF - sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] - sage: len(L), L[0] + sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF # optional - sage.rings.finite_rings + sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] # optional - sage.rings.finite_rings + sage: len(L), L[0] # optional - sage.rings.finite_rings (1, Finite Field of size 997) To illustrate the choice of the category, we consider the @@ -139,13 +148,13 @@ def Hom(X, Y, category=None, check=True): sage: X = ZZ; X Integer Ring - sage: Y = SymmetricGroup(3); Y + sage: Y = SymmetricGroup(3); Y # optional - sage.groups Symmetric group of order 3! as a permutation group By default, the smallest category containing both ``X`` and ``Y``, is used:: - sage: Hom(X, Y) + sage: Hom(X, Y) # optional - sage.groups Set of Morphisms from Integer Ring to Symmetric group of order 3! as a permutation group in Category of enumerated monoids @@ -153,10 +162,13 @@ def Hom(X, Y, category=None, check=True): Otherwise, if ``category`` is specified, then ``category`` is used, after checking that ``X`` and ``Y`` are indeed in ``category``:: - sage: Hom(X, Y, Magmas()) - Set of Morphisms from Integer Ring to Symmetric group of order 3! as a permutation group in Category of magmas + sage: Hom(X, Y, Magmas()) # optional - sage.groups + Set of Morphisms + from Integer Ring + to Symmetric group of order 3! as a permutation group + in Category of magmas - sage: Hom(X, Y, Groups()) + sage: Hom(X, Y, Groups()) # optional - sage.groups Traceback (most recent call last): ... ValueError: Integer Ring is not in Category of groups @@ -183,10 +195,10 @@ def Hom(X, Y, category=None, check=True): Homset are unique parents:: - sage: k = GF(5) - sage: H1 = Hom(k,k) - sage: H2 = Hom(k,k) - sage: H1 is H2 + sage: k = GF(5) # optional - sage.rings.finite_rings + sage: H1 = Hom(k, k) # optional - sage.rings.finite_rings + sage: H2 = Hom(k, k) # optional - sage.rings.finite_rings + sage: H1 is H2 # optional - sage.rings.finite_rings True Moreover, if no category is provided, then the result is identical @@ -231,16 +243,16 @@ def Hom(X, Y, category=None, check=True): Variation on the theme:: - sage: U1 = FreeModule(ZZ,2) - sage: U2 = FreeModule(ZZ,2,inner_product_matrix=matrix([[1,0],[0,-1]])) - sage: U1 == U2, U1 is U2 + sage: U1 = FreeModule(ZZ, 2) # optional - sage.modules + sage: U2 = FreeModule(ZZ, 2, inner_product_matrix=matrix([[1,0], [0,-1]])) # optional - sage.modules + sage: U1 == U2, U1 is U2 # optional - sage.modules (False, False) - sage: V = ZZ^3 - sage: H1 = Hom(U1, V); H2 = Hom(U2, V) - sage: H1 == H2, H1 is H2 + sage: V = ZZ^3 # optional - sage.modules + sage: H1 = Hom(U1, V); H2 = Hom(U2, V) # optional - sage.modules + sage: H1 == H2, H1 is H2 # optional - sage.modules (False, False) - sage: H1 = Hom(V, U1); H2 = Hom(V, U2) - sage: H1 == H2, H1 is H2 + sage: H1 = Hom(V, U1); H2 = Hom(V, U2) # optional - sage.modules + sage: H1 == H2, H1 is H2 # optional - sage.modules (False, False) Since :trac:`11900`, the meet of the categories of the given arguments is @@ -249,12 +261,18 @@ def Hom(X, Y, category=None, check=True): sage: PA = Parent(category=Algebras(QQ)) sage: PJ = Parent(category=Rings() & Modules(QQ)) - sage: Hom(PA,PJ) - Set of Homomorphisms from to - sage: Hom(PA,PJ).category() - Category of homsets of unital magmas and right modules over Rational Field and left modules over Rational Field - sage: Hom(PA,PJ, Rngs()) - Set of Morphisms from to in Category of rngs + sage: Hom(PA, PJ) + Set of Homomorphisms + from + to + sage: Hom(PA, PJ).category() + Category of homsets of + unital magmas and right modules over Rational Field + and left modules over Rational Field + sage: Hom(PA, PJ, Rngs()) + Set of Morphisms + from + to in Category of rngs .. TODO:: @@ -280,17 +298,17 @@ def Hom(X, Y, category=None, check=True): Checks that the domain and codomain are in the specified category. Case of a non parent:: - sage: S = SimplicialComplex([[1,2], [1,4]]); S.rename("S") - sage: Hom(S, S, SimplicialComplexes()) + sage: S = SimplicialComplex([[1,2], [1,4]]); S.rename("S") # optional - sage.graphs + sage: Hom(S, S, SimplicialComplexes()) # optional - sage.graphs Set of Morphisms from S to S in Category of finite simplicial complexes - sage: Hom(Set(), S, Sets()) + sage: Hom(Set(), S, Sets()) # optional - sage.graphs Set of Morphisms from {} to S in Category of sets - sage: Hom(S, Set(), Sets()) + sage: Hom(S, Set(), Sets()) # optional - sage.graphs Set of Morphisms from S to {} in Category of sets - sage: H = Hom(S, S, ChainComplexes(QQ)) + sage: H = Hom(S, S, ChainComplexes(QQ)) # optional - sage.graphs Traceback (most recent call last): ... ValueError: S is not in Category of chain complexes over Rational Field @@ -303,11 +321,11 @@ def Hom(X, Y, category=None, check=True): ....: def super_categories(self): return [Objects()] ....: def __contains__(self, X): return True sage: C = PermissiveCategory(); C.rename("Permissive category") - sage: S.category().is_subcategory(C) + sage: S.category().is_subcategory(C) # optional - sage.graphs False - sage: S in C + sage: S in C # optional - sage.graphs True - sage: Hom(S, S, C) + sage: Hom(S, S, C) # optional - sage.graphs Set of Morphisms from S to S in Permissive category With ``check=False``, uninitialized parents, as can appear upon @@ -331,16 +349,16 @@ def Hom(X, Y, category=None, check=True): uninitialized parent:: sage: P. = QQ['x,y'] - sage: Q = P.quotient([x^2-1,y^2-1]) - sage: q = Q.an_element() - sage: explain_pickle(dumps(Q)) + sage: Q = P.quotient([x^2-1, y^2-1]) # optional - sage.libs.singular + sage: q = Q.an_element() # optional - sage.libs.singular + sage: explain_pickle(dumps(Q)) # optional - sage.libs.singular pg_... ... = pg_dynamic_class('QuotientRing_generic_with_category', (pg_QuotientRing_generic, pg_getattr(..., 'parent_class')), None, None, pg_QuotientRing_generic) si... = unpickle_newobj(..., ()) ... si... = pg_unpickle_MPolynomialRing_libsingular(..., ('x', 'y'), ...) si... = ... pg_Hom(si..., si..., ...) ... - sage: Q == loads(dumps(Q)) + sage: Q == loads(dumps(Q)) # optional - sage.libs.singular True Check that the ``_Hom_`` method of the ``category`` input is used:: @@ -486,21 +504,24 @@ def End(X, category=None): EXAMPLES:: - sage: V = VectorSpace(QQ, 3) - sage: End(V) - Set of Morphisms (Linear Transformations) from - Vector space of dimension 3 over Rational Field to - Vector space of dimension 3 over Rational Field + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: End(V) # optional - sage.modules + Set of Morphisms (Linear Transformations) + from Vector space of dimension 3 over Rational Field + to Vector space of dimension 3 over Rational Field :: - sage: G = AlternatingGroup(3) - sage: S = End(G); S - Set of Morphisms from Alternating group of order 3!/2 as a permutation group to Alternating group of order 3!/2 as a permutation group in Category of finite enumerated permutation groups + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: S = End(G); S # optional - sage.groups + Set of Morphisms + from Alternating group of order 3!/2 as a permutation group + to Alternating group of order 3!/2 as a permutation group + in Category of finite enumerated permutation groups sage: from sage.categories.homset import is_Endset - sage: is_Endset(S) + sage: is_Endset(S) # optional - sage.groups True - sage: S.domain() + sage: S.domain() # optional - sage.groups Alternating group of order 3!/2 as a permutation group To avoid creating superfluous categories, a homset in a category @@ -512,13 +533,13 @@ def End(X, category=None): groups currently implement nothing more than unital magmas about their homsets, we have:: - sage: G = GL(3,3) - sage: G.category() + sage: G = GL(3, 3) # optional - sage.groups + sage: G.category() # optional - sage.groups Category of finite groups - sage: H = Hom(G,G) - sage: H.homset_category() + sage: H = Hom(G, G) # optional - sage.groups + sage: H.homset_category() # optional - sage.groups Category of finite groups - sage: H.category() + sage: H.category() # optional - sage.groups Category of endsets of unital magmas Similarly, a ring morphism just needs to preserve addition, @@ -557,8 +578,8 @@ class Homset(Set_generic): EXAMPLES:: - sage: H = Hom(QQ^2, QQ^3) - sage: loads(H.dumps()) is H + sage: H = Hom(QQ^2, QQ^3) # optional - sage.modules + sage: loads(H.dumps()) is H # optional - sage.modules True Homsets of unique parents are unique as well:: @@ -571,10 +592,11 @@ class Homset(Set_generic): Conversely, homsets of non-unique parents are non-unique:: - sage: H = End(ProductProjectiveSpaces(QQ, [1, 1])) - sage: loads(dumps(ProductProjectiveSpaces(QQ, [1, 1]))) is ProductProjectiveSpaces(QQ, [1, 1]) + sage: P11 = ProductProjectiveSpaces(QQ, [1, 1]) + sage: H = End(P11) + sage: loads(dumps(P11)) is ProductProjectiveSpaces(QQ, [1, 1]) False - sage: loads(dumps(ProductProjectiveSpaces(QQ, [1, 1]))) == ProductProjectiveSpaces(QQ, [1, 1]) + sage: loads(dumps(P11)) == ProductProjectiveSpaces(QQ, [1, 1]) True sage: loads(dumps(H)) is H False @@ -621,12 +643,12 @@ def __init__(self, X, Y, category=None, base=None, check=True): sage: Hom(R, R, category=Sets()).base_ring() sage: Hom(R, R, category=Modules(QQ)).base_ring() Rational Field - sage: Hom(QQ^3, QQ^3, category=Modules(QQ)).base_ring() + sage: Hom(QQ^3, QQ^3, category=Modules(QQ)).base_ring() # optional - sage.modules Rational Field For whatever it's worth, the ``base`` arguments takes precedence:: - sage: MyHomset(ZZ^3, ZZ^3, base = QQ).base_ring() + sage: MyHomset(ZZ^3, ZZ^3, base=QQ).base_ring() # optional - sage.modules Rational Field """ self._domain = X @@ -679,8 +701,8 @@ def __reduce__(self): EXAMPLES:: - sage: H = Hom(QQ^2, QQ^3) - sage: H.__reduce__() + sage: H = Hom(QQ^2, QQ^3) # optional - sage.modules + sage: H.__reduce__() # optional - sage.modules (, (Vector space of dimension 2 over Rational Field, Vector space of dimension 3 over Rational Field, @@ -690,18 +712,18 @@ def __reduce__(self): TESTS:: - sage: loads(H.dumps()) is H + sage: loads(H.dumps()) is H # optional - sage.modules True Homsets of non-unique parents are non-unique as well:: - sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]]) - sage: G is loads(dumps(G)) + sage: G = PermutationGroup([[(1, 2, 3), (4, 5)], [(3, 4)]]) # optional - sage.groups + sage: G is loads(dumps(G)) # optional - sage.groups False - sage: H = Hom(G,G) - sage: H is loads(dumps(H)) + sage: H = Hom(G, G) # optional - sage.groups + sage: H is loads(dumps(H)) # optional - sage.groups False - sage: H == loads(dumps(H)) + sage: H == loads(dumps(H)) # optional - sage.groups True """ return Hom, (self._domain, self._codomain, self.__category, False) @@ -710,7 +732,7 @@ def _repr_(self): """ TESTS:: - sage: Hom(ZZ^2, QQ, category=Sets())._repr_() + sage: Hom(ZZ^2, QQ, category=Sets())._repr_() # optional - sage.modules 'Set of Morphisms from Ambient free module of rank 2 over the principal ideal domain Integer Ring to Rational Field in Category of sets' """ return "Set of Morphisms from {} to {} in {}".format(self._domain, @@ -727,10 +749,10 @@ def __hash__(self): sage: hash(Hom(QQ, ZZ)) == hash((QQ, ZZ, QQ)) True - sage: E = EllipticCurve('37a') # optional - sage.symbolic - sage: H = E(0).parent(); H # optional - sage.symbolic + sage: E = EllipticCurve('37a') # optional - sage.symbolic + sage: H = E(0).parent(); H # optional - sage.symbolic Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field - sage: hash(H) == hash((H.domain(), H.codomain(), H.base())) + sage: hash(H) == hash((H.domain(), H.codomain(), H.base())) # optional - sage.symbolic True """ return hash((self._domain, self._codomain, self.base())) @@ -751,8 +773,8 @@ def homset_category(self): EXAMPLES:: - sage: H = Hom(AlternatingGroup(4), AlternatingGroup(7)) - sage: H.homset_category() + sage: H = Hom(AlternatingGroup(4), AlternatingGroup(7)) # optional - sage.groups + sage: H.homset_category() # optional - sage.groups Category of finite enumerated permutation groups """ return self.__category @@ -763,9 +785,9 @@ def _element_constructor_(self, x, check=None, **options): EXAMPLES:: - sage: H = Hom(SymmetricGroup(4), SymmetricGroup(7)) - sage: phi = Hom(SymmetricGroup(5), SymmetricGroup(6)).natural_map() - sage: phi + sage: H = Hom(SymmetricGroup(4), SymmetricGroup(7)) # optional - sage.groups + sage: phi = Hom(SymmetricGroup(5), SymmetricGroup(6)).natural_map() # optional - sage.groups + sage: phi # optional - sage.groups Coercion morphism: From: Symmetric group of order 5! as a permutation group To: Symmetric group of order 6! as a permutation group @@ -777,7 +799,7 @@ def _element_constructor_(self, x, check=None, **options): collection, if there is a strong reference to its domain (which is the case here):: - sage: H(phi) + sage: H(phi) # optional - sage.groups Composite map: From: Symmetric group of order 4! as a permutation group To: Symmetric group of order 7! as a permutation group @@ -798,7 +820,7 @@ def _element_constructor_(self, x, check=None, **options): Also note that making a copy of the resulting map will automatically make strengthened copies of the composed maps:: - sage: copy(H(phi)) + sage: copy(H(phi)) # optional - sage.groups Composite map: From: Symmetric group of order 4! as a permutation group To: Symmetric group of order 7! as a permutation group @@ -825,7 +847,7 @@ def _element_constructor_(self, x, check=None, **options): (2, 3, 4) sage: H = Hom(Set([1,2,3]), Set([1,2,3])) - sage: f = H( lambda x: 4-x ) + sage: f = H(lambda x: 4 - x) sage: f.parent() Set of Morphisms from {1, 2, 3} to {1, 2, 3} in Category of finite enumerated sets sage: f(1), f(2), f(3) # todo: not implemented @@ -884,24 +906,24 @@ def _element_constructor_(self, x, check=None, **options): TESTS:: - sage: G. = FreeGroup() - sage: H = Hom(G, G) - sage: H(H.identity()) + sage: G. = FreeGroup() # optional - sage.groups + sage: H = Hom(G, G) # optional - sage.groups + sage: H(H.identity()) # optional - sage.groups Identity endomorphism of Free Group on generators {x, y, z} - sage: H() + sage: H() # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to convert 0 to an element of Set of Morphisms from Free Group on generators {x, y, z} to Free Group on generators {x, y, z} in Category of infinite groups - sage: H("whatever") + sage: H("whatever") # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to convert 'whatever' to an element of Set of Morphisms from Free Group on generators {x, y, z} to Free Group on generators {x, y, z} in Category of infinite groups - sage: HH = Hom(H, H) - sage: HH(HH.identity(), foo="bar") + sage: HH = Hom(H, H) # optional - sage.groups + sage: HH(HH.identity(), foo="bar") # optional - sage.groups Traceback (most recent call last): ... NotImplementedError: no keywords are implemented for @@ -982,41 +1004,41 @@ class of ``C`` will be inherited by *all* subcategories of this point this is the simplest one to create (gosh):: sage: cat = Groups().Finite().Commutative() - sage: C3 = PermutationGroup([(1,2,3)]) - sage: C3._refine_category_(cat) - sage: C2 = PermutationGroup([(1,2)]) - sage: C2._refine_category_(cat) - sage: H = Hom(C3, C2, cat) - sage: H.homset_category() + sage: C3 = PermutationGroup([(1,2,3)]) # optional - sage.groups + sage: C3._refine_category_(cat) # optional - sage.groups + sage: C2 = PermutationGroup([(1,2)]) # optional - sage.groups + sage: C2._refine_category_(cat) # optional - sage.groups + sage: H = Hom(C3, C2, cat) # optional - sage.groups + sage: H.homset_category() # optional - sage.groups Category of finite commutative groups - sage: H.category() + sage: H.category() # optional - sage.groups Category of homsets of unital magmas - sage: cls = H._abstract_element_class; cls + sage: cls = H._abstract_element_class; cls # optional - sage.groups - sage: cls.__bases__ == (H.category().element_class, H.homset_category().morphism_class) + sage: cls.__bases__ == (H.category().element_class, H.homset_category().morphism_class) # optional - sage.groups True A morphism of finite commutative semigroups is also a morphism of semigroups, of magmas, ...; it thus inherits code from all those categories:: - sage: issubclass(cls, Semigroups().Finite().morphism_class) + sage: issubclass(cls, Semigroups().Finite().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Semigroups().morphism_class) + sage: issubclass(cls, Semigroups().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Magmas().Commutative().morphism_class) + sage: issubclass(cls, Magmas().Commutative().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Magmas().morphism_class) + sage: issubclass(cls, Magmas().morphism_class) # optional - sage.groups True - sage: issubclass(cls, Sets().morphism_class) + sage: issubclass(cls, Sets().morphism_class) # optional - sage.groups True Recall that FiniteMonoids() is a full subcategory of ``Monoids()``, but not of ``FiniteSemigroups()``. Thus:: - sage: issubclass(cls, Monoids().Finite().Homsets().element_class) + sage: issubclass(cls, Monoids().Finite().Homsets().element_class) # optional - sage.groups True - sage: issubclass(cls, Semigroups().Finite().Homsets().element_class) + sage: issubclass(cls, Semigroups().Finite().Homsets().element_class) # optional - sage.groups False """ class_name = "%s._abstract_element_class"%self.__class__.__name__ @@ -1117,11 +1139,13 @@ def natural_map(self): Coercion morphism: From: Univariate Polynomial Ring in t over Integer Ring To: Univariate Polynomial Ring in t over Rational Field - sage: H = Hom(QQ['t'],GF(3)['t']) - sage: H.natural_map() + sage: H = Hom(QQ['t'], GF(3)['t']) # optional - sage.rings.finite_rings + sage: H.natural_map() # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: natural coercion morphism from Univariate Polynomial Ring in t over Rational Field to Univariate Polynomial Ring in t over Finite Field of size 3 not defined + TypeError: natural coercion morphism + from Univariate Polynomial Ring in t over Rational Field + to Univariate Polynomial Ring in t over Finite Field of size 3 not defined """ return morphism.FormalCoercionMorphism(self) # good default in many cases @@ -1162,9 +1186,10 @@ def one(self): EXAMPLES:: - sage: K = GaussianIntegers() - sage: End(K).one() - Identity endomorphism of Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I + sage: K = GaussianIntegers() # optional - sage.rings.number_field + sage: End(K).one() # optional - sage.rings.number_field + Identity endomorphism of Gaussian Integers in Number Field in I + with defining polynomial x^2 + 1 with I = 1*I """ return self.identity() @@ -1205,21 +1230,21 @@ def reversed(self): EXAMPLES:: - sage: H = Hom(ZZ^2, ZZ^3); H + sage: H = Hom(ZZ^2, ZZ^3); H # optional - sage.modules Set of Morphisms from Ambient free module of rank 2 over the principal ideal domain Integer Ring to Ambient free module of rank 3 over the principal ideal domain Integer Ring in Category of finite dimensional modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: type(H) + sage: type(H) # optional - sage.modules - sage: H.reversed() + sage: H.reversed() # optional - sage.modules Set of Morphisms from Ambient free module of rank 3 over the principal ideal domain Integer Ring to Ambient free module of rank 2 over the principal ideal domain Integer Ring in Category of finite dimensional modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: type(H.reversed()) + sage: type(H.reversed()) # optional - sage.modules """ return Hom(self.codomain(), self.domain(), diff --git a/src/sage/categories/hopf_algebras.py b/src/sage/categories/hopf_algebras.py index 84858c7c5bf..ecff3fd58cc 100644 --- a/src/sage/categories/hopf_algebras.py +++ b/src/sage/categories/hopf_algebras.py @@ -67,17 +67,18 @@ def antipode(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: [a,b] = A.algebra_generators() - sage: a, a.antipode() + sage: A = HopfAlgebrasWithBasis(QQ).example(); A # optional - sage.groups + An example of Hopf algebra with basis: the group algebra of the + Dihedral group of order 6 as a permutation group over Rational Field + sage: [a,b] = A.algebra_generators() # optional - sage.groups + sage: a, a.antipode() # optional - sage.groups (B[(1,2,3)], B[(1,3,2)]) - sage: b, b.antipode() + sage: b, b.antipode() # optional - sage.groups (B[(1,3)], B[(1,3)]) TESTS:: - sage: all(x.antipode() * x == A.one() for x in A.basis()) + sage: all(x.antipode() * x == A.one() for x in A.basis()) # optional - sage.groups True """ return self.parent().antipode(self) @@ -135,9 +136,9 @@ def antipode(self): EXAMPLES:: - sage: A = SteenrodAlgebra(3) - sage: a = A.an_element() - sage: a, a.antipode() + sage: A = SteenrodAlgebra(3) # optional - sage.combinat sage.modules + sage: a = A.an_element() # optional - sage.combinat sage.modules + sage: a, a.antipode() # optional - sage.combinat sage.modules (2 Q_1 Q_3 P(2,1), Q_1 Q_3 P(2,1)) """ return self.parent().antipode(self) @@ -204,11 +205,11 @@ def antipode_by_coercion(self, x): EXAMPLES:: - sage: N = NonCommutativeSymmetricFunctions(QQ) - sage: R = N.ribbon() - sage: R.antipode_by_coercion.__module__ + sage: N = NonCommutativeSymmetricFunctions(QQ) # optional - sage.combinat + sage: R = N.ribbon() # optional - sage.combinat + sage: R.antipode_by_coercion.__module__ # optional - sage.combinat 'sage.categories.hopf_algebras' - sage: R.antipode_by_coercion(R[1,3,1]) + sage: R.antipode_by_coercion(R[1,3,1]) # optional - sage.combinat -R[2, 1, 2] """ R = self.realization_of().a_realization() diff --git a/src/sage/categories/hopf_algebras_with_basis.py b/src/sage/categories/hopf_algebras_with_basis.py index 79a0b69ce14..ea401896ca0 100644 --- a/src/sage/categories/hopf_algebras_with_basis.py +++ b/src/sage/categories/hopf_algebras_with_basis.py @@ -33,43 +33,44 @@ class HopfAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): We now show how to use a simple Hopf algebra, namely the group algebra of the dihedral group (see also AlgebrasWithBasis):: - sage: A = C.example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: A.__custom_name = "A" - sage: A.category() + sage: A = C.example(); A # optional - sage.groups + An example of Hopf algebra with basis: the group algebra of the + Dihedral group of order 6 as a permutation group over Rational Field + sage: A.__custom_name = "A" # optional - sage.groups + sage: A.category() # optional - sage.groups Category of finite dimensional hopf algebras with basis over Rational Field - sage: A.one_basis() + sage: A.one_basis() # optional - sage.groups () - sage: A.one() + sage: A.one() # optional - sage.groups B[()] - sage: A.base_ring() + sage: A.base_ring() # optional - sage.groups Rational Field - sage: A.basis().keys() + sage: A.basis().keys() # optional - sage.groups Dihedral group of order 6 as a permutation group - sage: [a,b] = A.algebra_generators() - sage: a, b + sage: [a,b] = A.algebra_generators() # optional - sage.groups + sage: a, b # optional - sage.groups (B[(1,2,3)], B[(1,3)]) - sage: a^3, b^2 + sage: a^3, b^2 # optional - sage.groups (B[()], B[()]) - sage: a*b + sage: a*b # optional - sage.groups B[(1,2)] - sage: A.product # todo: not quite ... + sage: A.product # todo: not quite ... # optional - sage.groups - sage: A.product(b,b) + sage: A.product(b, b) # optional - sage.groups B[()] - sage: A.zero().coproduct() + sage: A.zero().coproduct() # optional - sage.groups 0 - sage: A.zero().coproduct().parent() + sage: A.zero().coproduct().parent() # optional - sage.groups A # A - sage: a.coproduct() + sage: a.coproduct() # optional - sage.groups B[(1,2,3)] # B[(1,2,3)] - sage: TestSuite(A).run(verbose=True) + sage: TestSuite(A).run(verbose=True) # optional - sage.groups running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_antipode() . . . pass @@ -100,32 +101,35 @@ class HopfAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): running ._test_prod() . . . pass running ._test_some_elements() . . . pass running ._test_zero() . . . pass - sage: A.__class__ + sage: A.__class__ # optional - sage.groups - sage: A.element_class + sage: A.element_class # optional - sage.groups Let us look at the code for implementing A:: - sage: A?? # todo: not implemented + sage: A?? # todo: not implemented # optional - sage.groups TESTS:: - sage: TestSuite(A).run() - sage: TestSuite(C).run() + sage: TestSuite(A).run() # optional - sage.groups + sage: TestSuite(C).run() # optional - sage.groups """ def example(self, G=None): """ Returns an example of algebra with basis:: - sage: HopfAlgebrasWithBasis(QQ['x']).example() - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Univariate Polynomial Ring in x over Rational Field + sage: HopfAlgebrasWithBasis(QQ['x']).example() # optional - sage.groups + An example of Hopf algebra with basis: the group algebra of the + Dihedral group of order 6 as a permutation group + over Univariate Polynomial Ring in x over Rational Field An other group can be specified as optional argument:: - sage: HopfAlgebrasWithBasis(QQ).example(SymmetricGroup(4)) - An example of Hopf algebra with basis: the group algebra of the Symmetric group of order 4! as a permutation group over Rational Field + sage: HopfAlgebrasWithBasis(QQ).example(SymmetricGroup(4)) # optional - sage.groups + An example of Hopf algebra with basis: the group algebra of the + Symmetric group of order 4! as a permutation group over Rational Field """ from sage.categories.examples.hopf_algebras_with_basis import MyGroupAlgebra from sage.groups.perm_gps.permgroup_named import DihedralGroup @@ -175,12 +179,12 @@ def antipode_on_basis(self, x): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example() - sage: W = A.basis().keys(); W + sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups + sage: W = A.basis().keys(); W # optional - sage.groups Dihedral group of order 6 as a permutation group - sage: w = W.gen(0); w + sage: w = W.gen(0); w # optional - sage.groups (1,2,3) - sage: A.antipode_on_basis(w) + sage: A.antipode_on_basis(w) # optional - sage.groups B[(1,3,2)] """ @@ -196,18 +200,19 @@ def antipode(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(ZZ).example(); A - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Integer Ring - sage: A = HopfAlgebrasWithBasis(QQ).example() - sage: [a,b] = A.algebra_generators() - sage: a, A.antipode(a) + sage: A = HopfAlgebrasWithBasis(ZZ).example(); A # optional - sage.groups + An example of Hopf algebra with basis: the group algebra of the + Dihedral group of order 6 as a permutation group over Integer Ring + sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups + sage: [a,b] = A.algebra_generators() # optional - sage.groups + sage: a, A.antipode(a) # optional - sage.groups (B[(1,2,3)], B[(1,3,2)]) - sage: b, A.antipode(b) + sage: b, A.antipode(b) # optional - sage.groups (B[(1,3)], B[(1,3)]) TESTS:: - sage: all(A.antipode(x) * x == A.one() for x in A.basis()) + sage: all(A.antipode(x) * x == A.one() for x in A.basis()) # optional - sage.groups True """ if self.antipode_on_basis is not NotImplemented: @@ -239,13 +244,13 @@ def _test_antipode(self, **options): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() - sage: R._test_antipode() + sage: R = NonCommutativeSymmetricFunctions(QQ).ribbon() # optional - sage.combinat + sage: R._test_antipode() # optional - sage.combinat :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s._test_antipode() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s._test_antipode() # optional - sage.combinat """ tester = self._tester(**options) diff --git a/src/sage/categories/integral_domains.py b/src/sage/categories/integral_domains.py index 2d5d7730693..a5cd4ec11da 100644 --- a/src/sage/categories/integral_domains.py +++ b/src/sage/categories/integral_domains.py @@ -45,7 +45,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in IntegralDomains() + sage: GF(4, "a") in IntegralDomains() # optional - sage.libs.pari True sage: QQ in IntegralDomains() True @@ -129,7 +129,7 @@ def _test_fraction_field(self, **options): tester = self._tester(**options) try: fraction_field = self.fraction_field() - except AttributeError: + except (AttributeError, ImportError): # some integral domains do not implement fraction_field() yet if self in Fields(): raise diff --git a/src/sage/categories/kac_moody_algebras.py b/src/sage/categories/kac_moody_algebras.py index cd7af55333d..040387a3325 100644 --- a/src/sage/categories/kac_moody_algebras.py +++ b/src/sage/categories/kac_moody_algebras.py @@ -43,12 +43,12 @@ def example(self, n=2): EXAMPLES:: sage: from sage.categories.kac_moody_algebras import KacMoodyAlgebras - sage: KacMoodyAlgebras(QQ).example() + sage: KacMoodyAlgebras(QQ).example() # optional - sage.combinat sage.modules Lie algebra of ['A', 2] in the Chevalley basis We can specify the rank of the example:: - sage: KacMoodyAlgebras(QQ).example(4) + sage: KacMoodyAlgebras(QQ).example(4) # optional - sage.combinat sage.modules Lie algebra of ['A', 4] in the Chevalley basis """ from sage.algebras.lie_algebras.classical_lie_algebra import LieAlgebraChevalleyBasis @@ -61,8 +61,8 @@ def cartan_type(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) - sage: L.cartan_type() + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules + sage: L.cartan_type() # optional - sage.combinat sage.modules ['A', 2] """ return self._cartan_type @@ -73,8 +73,8 @@ def weyl_group(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) - sage: L.weyl_group() + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # optional - sage.combinat sage.modules + sage: L.weyl_group() # optional - sage.combinat sage.modules Weyl Group of type ['A', 2] (as a matrix group acting on the ambient space) """ from sage.combinat.root_system.weyl_group import WeylGroup diff --git a/src/sage/categories/lambda_bracket_algebras.py b/src/sage/categories/lambda_bracket_algebras.py index 531cfb826b1..8818c0a918a 100644 --- a/src/sage/categories/lambda_bracket_algebras.py +++ b/src/sage/categories/lambda_bracket_algebras.py @@ -45,9 +45,10 @@ def __classcall_private__(cls, R, check=True): EXAMPLES:: - sage: LieConformalAlgebras(QuaternionAlgebra(2)) + sage: LieConformalAlgebras(QuaternionAlgebra(2)) # optional - sage.combinat sage.modules Traceback (most recent call last): - ValueError: base must be a commutative ring got Quaternion Algebra (-1, -1) with base ring Rational Field + ValueError: base must be a commutative ring + got Quaternion Algebra (-1, -1) with base ring Rational Field sage: LieConformalAlgebras(ZZ) Category of Lie conformal algebras over Integer Ring """ @@ -117,8 +118,8 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) - sage: Vir.ideal() + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: Vir.ideal() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: ideals of Lie Conformal algebras are not implemented yet @@ -136,21 +137,21 @@ def bracket(self, rhs): The brackets of the Virasoro Lie conformal algebra:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L.bracket(L) + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules + sage: L.bracket(L) # optional - sage.combinat sage.modules {0: TL, 1: 2*L, 3: 1/2*C} - sage: L.bracket(L.T()) + sage: L.bracket(L.T()) # optional - sage.combinat sage.modules {0: 2*T^(2)L, 1: 3*TL, 2: 4*L, 4: 2*C} Now with a current algebra:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') - sage: V.gens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: V.gens() # optional - sage.combinat sage.modules (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: E = V.0; H = V.1; F = V.2; - sage: H.bracket(H) + sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules + sage: H.bracket(H) # optional - sage.combinat sage.modules {1: 2*B['K']} - sage: E.bracket(F) + sage: E.bracket(F) # optional - sage.combinat sage.modules {0: B[alphacheck[1]], 1: B['K']} """ return self._bracket_(rhs) @@ -169,21 +170,21 @@ def _bracket_(self, rhs): The brackets of the Virasoro Lie conformal Algebra:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L._bracket_(L) + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules + sage: L._bracket_(L) # optional - sage.combinat sage.modules {0: TL, 1: 2*L, 3: 1/2*C} - sage: L._bracket_(L.T()) + sage: L._bracket_(L.T()) # optional - sage.combinat sage.modules {0: 2*T^(2)L, 1: 3*TL, 2: 4*L, 4: 2*C} Now with a current algebra:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') - sage: V.gens() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: V.gens() # optional - sage.combinat sage.modules (B[alpha[1]], B[alphacheck[1]], B[-alpha[1]], B['K']) - sage: E = V.0; H = V.1; F = V.2; - sage: H._bracket_(H) + sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules + sage: H._bracket_(H) # optional - sage.combinat sage.modules {1: 2*B['K']} - sage: E._bracket_(F) + sage: E._bracket_(F) # optional - sage.combinat sage.modules {0: B[alphacheck[1]], 1: B['K']} """ @@ -194,16 +195,16 @@ def nproduct(self, rhs, n): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L.nproduct(L, 3) + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules + sage: L.nproduct(L, 3) # optional - sage.combinat sage.modules 1/2*C - sage: L.nproduct(L.T(), 0) + sage: L.nproduct(L.T(), 0) # optional - sage.combinat sage.modules 2*T^(2)L - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') - sage: E = V.0; H = V.1; F = V.2; - sage: E.nproduct(H, 0) == - 2*E + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules + sage: E.nproduct(H, 0) == - 2*E # optional - sage.combinat sage.modules True - sage: E.nproduct(F, 1) + sage: E.nproduct(F, 1) # optional - sage.combinat sage.modules B['K'] """ return self._nproduct_(rhs,n) @@ -219,16 +220,16 @@ def _nproduct_(self, rhs, n): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 - sage: L._nproduct_(L,3) + sage: Vir = lie_conformal_algebras.Virasoro(QQ); L = Vir.0 # optional - sage.combinat sage.modules + sage: L._nproduct_(L, 3) # optional - sage.combinat sage.modules 1/2*C - sage: L._nproduct_(L.T(),0) + sage: L._nproduct_(L.T(), 0) # optional - sage.combinat sage.modules 2*T^(2)L - sage: V = lie_conformal_algebras.Affine(QQ, 'A1') - sage: E = V.0; H = V.1; F = V.2; - sage: E._nproduct_(H,0) == - 2*E + sage: V = lie_conformal_algebras.Affine(QQ, 'A1') # optional - sage.combinat sage.modules + sage: E = V.0; H = V.1; F = V.2 # optional - sage.combinat sage.modules + sage: E._nproduct_(H, 0) == - 2*E # optional - sage.combinat sage.modules True - sage: E._nproduct_(F,1) + sage: E._nproduct_(F, 1) # optional - sage.combinat sage.modules B['K'] """ if n >= 0: @@ -253,14 +254,14 @@ def T(self, n=1): EXAMPLES:: - sage: Vir = lie_conformal_algebras.Virasoro(QQ) - sage: Vir.inject_variables() + sage: Vir = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: Vir.inject_variables() # optional - sage.combinat sage.modules Defining L, C - sage: L.T() + sage: L.T() # optional - sage.combinat sage.modules TL - sage: L.T(3) + sage: L.T(3) # optional - sage.combinat sage.modules 6*T^(3)L - sage: C.T() + sage: C.T() # optional - sage.combinat sage.modules 0 """ diff --git a/src/sage/categories/lambda_bracket_algebras_with_basis.py b/src/sage/categories/lambda_bracket_algebras_with_basis.py index 9b48ba34615..165fbe6294c 100644 --- a/src/sage/categories/lambda_bracket_algebras_with_basis.py +++ b/src/sage/categories/lambda_bracket_algebras_with_basis.py @@ -25,7 +25,7 @@ class LambdaBracketAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis() + sage: LieConformalAlgebras(QQbar).WithBasis() # optional - sage.rings.number_field Category of Lie conformal algebras with basis over Algebraic Field """ class ElementMethods: @@ -36,14 +36,14 @@ def index(self): EXAMPLES:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: V.inject_variables() + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: V.inject_variables() # optional - sage.combinat sage.modules Defining L, G, C - sage: G.T(3).index() + sage: G.T(3).index() # optional - sage.combinat sage.modules ('G', 3) - sage: v = V.an_element(); v + sage: v = V.an_element(); v # optional - sage.combinat sage.modules L + G + C - sage: v.index() + sage: v.index() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: index can only be computed for monomials, got L + G + C @@ -63,10 +63,11 @@ class FinitelyGeneratedAsLambdaBracketAlgebra(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) - sage: C.WithBasis().FinitelyGenerated() - Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.WithBasis().FinitelyGenerated() is C.FinitelyGenerated().WithBasis() + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: C.WithBasis().FinitelyGenerated() # optional - sage.rings.number_field + Category of finitely generated Lie conformal algebras with basis + over Algebraic Field + sage: C.WithBasis().FinitelyGenerated() is C.FinitelyGenerated().WithBasis() # optional - sage.rings.number_field True """ class Graded(GradedModulesCategory): @@ -76,8 +77,9 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() - Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated Lie conformal algebras with basis + over Algebraic Field """ class ParentMethods: @@ -88,8 +90,8 @@ def degree_on_basis(self, m): EXAMPLES:: - sage: V = lie_conformal_algebras.Virasoro(QQ) - sage: V.degree_on_basis(('L',2)) + sage: V = lie_conformal_algebras.Virasoro(QQ) # optional - sage.combinat sage.modules + sage: V.degree_on_basis(('L', 2)) # optional - sage.combinat sage.modules 4 """ if m[0] in self._central_elements: diff --git a/src/sage/categories/lattice_posets.py b/src/sage/categories/lattice_posets.py index d29635f078e..3872ca9b51f 100644 --- a/src/sage/categories/lattice_posets.py +++ b/src/sage/categories/lattice_posets.py @@ -66,8 +66,8 @@ def meet(self, x, y): EXAMPLES:: - sage: D = LatticePoset((divisors(30), attrcall("divides"))) - sage: D.meet( D(6), D(15) ) + sage: D = LatticePoset((divisors(30), attrcall("divides"))) # optional - sage.combinat + sage: D.meet( D(6), D(15) ) # optional - sage.combinat 3 """ @@ -82,7 +82,7 @@ def join(self, x, y): EXAMPLES:: - sage: D = LatticePoset((divisors(60), attrcall("divides"))) - sage: D.join( D(6), D(10) ) + sage: D = LatticePoset((divisors(60), attrcall("divides"))) # optional - sage.combinat + sage: D.join( D(6), D(10) ) # optional - sage.combinat 30 """ diff --git a/src/sage/categories/lie_algebras.py b/src/sage/categories/lie_algebras.py index 269ca3dabbe..23b9a0b796a 100644 --- a/src/sage/categories/lie_algebras.py +++ b/src/sage/categories/lie_algebras.py @@ -45,24 +45,24 @@ class LieAlgebras(Category_over_base_ring): We construct a typical parent in this category, and do some computations with it:: - sage: A = C.example(); A + sage: A = C.example(); A # optional - sage.groups sage.modules An example of a Lie algebra: the Lie algebra from the associative algebra Symmetric group algebra of order 3 over Rational Field generated by ([2, 1, 3], [2, 3, 1]) - sage: A.category() + sage: A.category() # optional - sage.groups sage.modules Category of Lie algebras over Rational Field - sage: A.base_ring() + sage: A.base_ring() # optional - sage.groups sage.modules Rational Field - sage: a,b = A.lie_algebra_generators() - sage: a.bracket(b) + sage: a, b = A.lie_algebra_generators() # optional - sage.groups sage.modules + sage: a.bracket(b) # optional - sage.groups sage.modules -[1, 3, 2] + [3, 2, 1] - sage: b.bracket(2*a + b) + sage: b.bracket(2*a + b) # optional - sage.groups sage.modules 2*[1, 3, 2] - 2*[3, 2, 1] - sage: A.bracket(a, b) + sage: A.bracket(a, b) # optional - sage.groups sage.modules -[1, 3, 2] + [3, 2, 1] Please see the source code of `A` (with ``A??``) for how to @@ -70,9 +70,9 @@ class LieAlgebras(Category_over_base_ring): TESTS:: - sage: C = LieAlgebras(QQ) - sage: TestSuite(C).run() - sage: TestSuite(C.example()).run() + sage: C = LieAlgebras(QQ) # optional - sage.combinat sage.modules + sage: TestSuite(C).run() # optional - sage.combinat sage.modules + sage: TestSuite(C.example()).run() # optional - sage.combinat sage.modules .. TODO:: @@ -151,15 +151,15 @@ def example(self, gens=None): EXAMPLES:: - sage: LieAlgebras(QQ).example() + sage: LieAlgebras(QQ).example() # optional - sage.groups sage.modules An example of a Lie algebra: the Lie algebra from the associative algebra Symmetric group algebra of order 3 over Rational Field generated by ([2, 1, 3], [2, 3, 1]) Another set of generators can be specified as an optional argument:: - sage: F. = FreeAlgebra(QQ) - sage: LieAlgebras(QQ).example(F.gens()) + sage: F. = FreeAlgebra(QQ) # optional - sage.combinat sage.modules + sage: LieAlgebras(QQ).example(F.gens()) # optional - sage.combinat sage.modules An example of a Lie algebra: the Lie algebra from the associative algebra Free Algebra on 3 generators (x, y, z) over Rational Field generated by (x, y, z) @@ -189,11 +189,14 @@ def extra_super_categories(self): [Category of finite sets] sage: LieAlgebras(ZZ).FiniteDimensional().extra_super_categories() [] - sage: LieAlgebras(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) + sage: C = LieAlgebras(GF(5)).FiniteDimensional() # optional - sage.libs.pari + sage: C.is_subcategory(Sets().Finite()) # optional - sage.libs.pari True - sage: LieAlgebras(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) + sage: C = LieAlgebras(ZZ).FiniteDimensional() + sage: C.is_subcategory(Sets().Finite()) False - sage: LieAlgebras(GF(5)).WithBasis().FiniteDimensional().is_subcategory(Sets().Finite()) + sage: C = LieAlgebras(GF(5)).WithBasis().FiniteDimensional() # optional - sage.libs.pari + sage: C.is_subcategory(Sets().Finite()) # optional - sage.libs.pari True """ if self.base_ring() in Sets().Finite(): @@ -206,8 +209,8 @@ class Nilpotent(CategoryWithAxiom_over_base_ring): TESTS:: - sage: C = LieAlgebras(QQ).Nilpotent() - sage: TestSuite(C).run() + sage: C = LieAlgebras(QQ).Nilpotent() # optional - sage.combinat sage.modules + sage: TestSuite(C).run() # optional - sage.combinat sage.modules """ class ParentMethods: @abstract_method @@ -217,8 +220,8 @@ def step(self): EXAMPLES:: - sage: h = lie_algebras.Heisenberg(ZZ, oo) - sage: h.step() + sage: h = lie_algebras.Heisenberg(ZZ, oo) # optional - sage.combinat sage.modules + sage: h.step() # optional - sage.combinat sage.modules 2 """ @@ -228,8 +231,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: h = lie_algebras.Heisenberg(ZZ, oo) - sage: h.is_nilpotent() + sage: h = lie_algebras.Heisenberg(ZZ, oo) # optional - sage.combinat sage.modules + sage: h.is_nilpotent() # optional - sage.combinat sage.modules True """ return True @@ -254,30 +257,30 @@ def bracket(self, lhs, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L.bracket(x, x + y) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.bracket(x, x + y) # optional - sage.combinat sage.modules -[1, 3, 2] + [3, 2, 1] - sage: L.bracket(x, 0) + sage: L.bracket(x, 0) # optional - sage.combinat sage.modules 0 - sage: L.bracket(0, x) + sage: L.bracket(0, x) # optional - sage.combinat sage.modules 0 Constructing the product space:: - sage: L = lie_algebras.Heisenberg(QQ, 1) - sage: Z = L.bracket(L, L); Z + sage: L = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: Z = L.bracket(L, L); Z # optional - sage.combinat sage.modules Ideal (z) of Heisenberg algebra of rank 1 over Rational Field - sage: L.bracket(L, Z) + sage: L.bracket(L, Z) # optional - sage.combinat sage.modules Ideal () of Heisenberg algebra of rank 1 over Rational Field Constructing ideals:: - sage: p,q,z = L.basis(); (p,q,z) + sage: p, q, z = L.basis(); p, q, z # optional - sage.combinat sage.modules (p1, q1, z) - sage: L.bracket(3*p, L) + sage: L.bracket(3*p, L) # optional - sage.combinat sage.modules Ideal (3*p1) of Heisenberg algebra of rank 1 over Rational Field - sage: L.bracket(L, q+p) + sage: L.bracket(L, q + p) # optional - sage.combinat sage.modules Ideal (p1 + q1) of Heisenberg algebra of rank 1 over Rational Field """ if lhs in LieAlgebras: @@ -297,15 +300,15 @@ def universal_enveloping_algebra(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.universal_enveloping_algebra() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # optional - sage.combinat sage.modules Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} :: - sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) - sage: L.universal_enveloping_algebra() + sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) # optional - sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # optional - sage.combinat sage.modules Multivariate Polynomial Ring in x0, x1, x2 over Rational Field .. SEEALSO:: @@ -330,15 +333,15 @@ def _construct_UEA(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L._construct_UEA() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L._construct_UEA() # optional - sage.combinat sage.modules Noncommutative Multivariate Polynomial Ring in b0, b1, b2 over Rational Field, nc-relations: {} :: - sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) - sage: L.universal_enveloping_algebra() # indirect doctest + sage: L = LieAlgebra(QQ, 3, 'x', abelian=True) # optional - sage.combinat sage.modules + sage: L.universal_enveloping_algebra() # indirect doctest # optional - sage.combinat sage.modules Multivariate Polynomial Ring in x0, x1, x2 over Rational Field """ @@ -394,8 +397,8 @@ def module(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.module() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.module() # optional - sage.combinat sage.modules Vector space of dimension 3 over Rational Field """ @@ -410,10 +413,10 @@ def from_vector(self, v, order=None, coerce=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.combinat sage.modules (1, 0, 0) - sage: parent(u) is L + sage: parent(u) is L # optional - sage.combinat sage.modules True """ @@ -430,11 +433,11 @@ def lift(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: lifted = L.lift(2*a + b - c); lifted + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: lifted = L.lift(2*a + b - c); lifted # optional - sage.combinat sage.modules 2*b0 + b1 - b2 - sage: lifted.parent() is L.universal_enveloping_algebra() + sage: lifted.parent() is L.universal_enveloping_algebra() # optional - sage.combinat sage.modules True """ M = LiftMorphism(self, self._construct_UEA()) @@ -447,9 +450,9 @@ def subalgebra(self, gens, names=None, index_set=None, category=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.subalgebra([2*a - c, b + c]) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.subalgebra([2*a - c, b + c]) # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 2-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -458,9 +461,9 @@ def subalgebra(self, gens, names=None, index_set=None, category=None): :: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L.subalgebra([x + y]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.subalgebra([x + y]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: subalgebras not yet implemented: see #17416 @@ -475,9 +478,9 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.ideal([2*a - c, b + c]) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.ideal([2*a - c, b + c]) # optional - sage.combinat sage.modules An example of a finite dimensional Lie algebra with basis: the 2-dimensional abelian Lie algebra over Rational Field with basis matrix: @@ -486,9 +489,9 @@ def ideal(self, *gens, **kwds): :: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L.ideal([x + y]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x, y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.ideal([x + y]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: ideals not yet implemented: see #16824 @@ -508,8 +511,8 @@ def is_ideal(self, A): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.is_ideal(L) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L.is_ideal(L) # optional - sage.combinat sage.modules True """ if A == self: @@ -525,9 +528,9 @@ def killing_form(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.killing_form(a, b+c) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.killing_form(a, b + c) # optional - sage.combinat sage.modules 0 """ @@ -540,21 +543,21 @@ def is_abelian(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.is_abelian() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules False - sage: R = QQ['x,y'] - sage: L = LieAlgebras(QQ).example(R.gens()) - sage: L.is_abelian() + sage: R = QQ['x,y'] # optional - sage.combinat sage.modules + sage: L = LieAlgebras(QQ).example(R.gens()) # optional - sage.combinat sage.modules + sage: L.is_abelian() # optional - sage.combinat sage.modules True :: - sage: L. = LieAlgebra(QQ,1) # todo: not implemented - #16823 - sage: L.is_abelian() # todo: not implemented - #16823 + sage: L. = LieAlgebra(QQ, 1) # todo: not implemented - #16823 # optional - sage.combinat sage.modules + sage: L.is_abelian() # todo: not implemented - #16823 # optional - sage.combinat sage.modules True - sage: L. = LieAlgebra(QQ,2) # todo: not implemented - #16823 - sage: L.is_abelian() # todo: not implemented - #16823 + sage: L. = LieAlgebra(QQ, 2) # todo: not implemented - #16823 # optional - sage.combinat sage.modules + sage: L.is_abelian() # todo: not implemented - #16823 # optional - sage.combinat sage.modules False """ G = self.lie_algebra_generators() @@ -570,14 +573,14 @@ def is_commutative(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: L.is_commutative() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L.is_commutative() # optional - sage.combinat sage.modules False :: - sage: L. = LieAlgebra(QQ, 1) # todo: not implemented - #16823 - sage: L.is_commutative() # todo: not implemented - #16823 + sage: L. = LieAlgebra(QQ, 1) # todo: not implemented - #16823 # optional - sage.combinat sage.modules + sage: L.is_commutative() # todo: not implemented - #16823 # optional - sage.combinat sage.modules True """ return self.is_abelian() @@ -589,8 +592,8 @@ def is_solvable(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_solvable() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_solvable() # optional - sage.combinat sage.modules True """ @@ -601,8 +604,8 @@ def is_nilpotent(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.is_nilpotent() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: L.is_nilpotent() # optional - sage.combinat sage.modules True """ @@ -627,37 +630,40 @@ def bch(self, X, Y, prec=None): The BCH formula for the generators of a free nilpotent Lie algebra of step 4:: - sage: L = LieAlgebra(QQ, 2, step=4) - sage: L.inject_variables() + sage: L = LieAlgebra(QQ, 2, step=4) # optional - sage.combinat sage.modules + sage: L.inject_variables() # optional - sage.combinat sage.modules Defining X_1, X_2, X_12, X_112, X_122, X_1112, X_1122, X_1222 - sage: L.bch(X_1, X_2) + sage: L.bch(X_1, X_2) # optional - sage.combinat sage.modules X_1 + X_2 + 1/2*X_12 + 1/12*X_112 + 1/12*X_122 + 1/24*X_1122 An example of the BCH formula in a quotient:: - sage: Q = L.quotient(X_112 + X_122) - sage: x, y = Q.basis().list()[:2] - sage: Q.bch(x, y) + sage: Q = L.quotient(X_112 + X_122) # optional - sage.combinat sage.modules + sage: x, y = Q.basis().list()[:2] # optional - sage.combinat sage.modules + sage: Q.bch(x, y) # optional - sage.combinat sage.modules X_1 + X_2 + 1/2*X_12 - 1/24*X_1112 The BCH formula for a non-nilpotent Lie algebra requires the precision to be explicitly stated:: - sage: L. = LieAlgebra(QQ) - sage: L.bch(X, Y) + sage: L. = LieAlgebra(QQ) # optional - sage.combinat sage.modules + sage: L.bch(X, Y) # optional - sage.combinat sage.modules Traceback (most recent call last): ... - ValueError: the Lie algebra is not known to be nilpotent, so you must specify the precision - sage: L.bch(X, Y, 4) - X + 1/12*[X, [X, Y]] + 1/24*[X, [[X, Y], Y]] + 1/2*[X, Y] + 1/12*[[X, Y], Y] + Y + ValueError: the Lie algebra is not known to be nilpotent, + so you must specify the precision + sage: L.bch(X, Y, 4) # optional - sage.combinat sage.modules + X + 1/12*[X, [X, Y]] + 1/24*[X, [[X, Y], Y]] + + 1/2*[X, Y] + 1/12*[[X, Y], Y] + Y The BCH formula requires a coercion from the rationals:: - sage: L. = LieAlgebra(ZZ, 2, step=2) - sage: L.bch(X, Y) + sage: L. = LieAlgebra(ZZ, 2, step=2) # optional - sage.combinat sage.modules + sage: L.bch(X, Y) # optional - sage.combinat sage.modules Traceback (most recent call last): ... - TypeError: the BCH formula is not well defined since Integer Ring has no coercion from Rational Field + TypeError: the BCH formula is not well defined + since Integer Ring has no coercion from Rational Field """ if self not in LieAlgebras.Nilpotent and prec is None: raise ValueError("the Lie algebra is not known to be nilpotent," @@ -682,8 +688,8 @@ def lie_group(self, name='G', **kwds): EXAMPLES:: - sage: L = lie_algebras.Heisenberg(QQ, 1) - sage: G = L.lie_group('G'); G # optional - sage.symbolic + sage: L = lie_algebras.Heisenberg(QQ, 1) # optional - sage.combinat sage.modules + sage: G = L.lie_group('G'); G # optional - sage.combinat sage.modules sage.symbolic Lie group G of Heisenberg algebra of rank 1 over Rational Field """ @@ -701,15 +707,15 @@ def _test_jacobi_identity(self, **options): By default, this method runs the tests only on the elements returned by ``self.some_elements()``:: - sage: L = LieAlgebras(QQ).example() - sage: L._test_jacobi_identity() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L._test_jacobi_identity() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L._test_jacobi_identity(elements=[x+y, x, 2*y, x.bracket(y)]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L._test_jacobi_identity(elements=[x + y, x, 2*y, x.bracket(y)]) # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. """ @@ -740,15 +746,15 @@ def _test_antisymmetry(self, **options): By default, this method runs the tests only on the elements returned by ``self.some_elements()``:: - sage: L = LieAlgebras(QQ).example() - sage: L._test_antisymmetry() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L._test_antisymmetry() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: L._test_antisymmetry(elements=[x+y, x, 2*y, x.bracket(y)]) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L._test_antisymmetry(elements=[x + y, x, 2*y, x.bracket(y)]) # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. """ @@ -769,27 +775,27 @@ def _test_distributivity(self, **options): TESTS:: - sage: L = LieAlgebras(QQ).example() - sage: L._test_distributivity() + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: L._test_distributivity() # optional - sage.combinat sage.modules EXAMPLES: By default, this method runs the tests only on the elements returned by ``self.some_elements()``:: - sage: L = LieAlgebra(QQ, 3, 'x,y,z', representation="polynomial") - sage: L.some_elements() + sage: L = LieAlgebra(QQ, 3, 'x,y,z', representation="polynomial") # optional - sage.combinat sage.modules + sage: L.some_elements() # optional - sage.combinat sage.modules [x + y + z] - sage: L._test_distributivity() + sage: L._test_distributivity() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument:: - sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # todo: not implemented - #16821 - sage: h1 = L.gen(0) # todo: not implemented - #16821 - sage: h2 = L.gen(1) # todo: not implemented - #16821 - sage: e2 = L.gen(3) # todo: not implemented - #16821 - sage: L._test_distributivity(elements=[h1, h2, e2]) # todo: not implemented - #16821 + sage: L = LieAlgebra(QQ, cartan_type=['A', 2]) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: h1 = L.gen(0) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: h2 = L.gen(1) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: e2 = L.gen(3) # todo: not implemented - #16821 # optional - sage.combinat sage.modules + sage: L._test_distributivity(elements=[h1, h2, e2]) # todo: not implemented - #16821 # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. """ @@ -812,11 +818,11 @@ def bracket(self, rhs): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x.bracket(y) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: x.bracket(y) # optional - sage.combinat sage.modules -[1, 3, 2] + [3, 2, 1] - sage: x.bracket(0) + sage: x.bracket(0) # optional - sage.combinat sage.modules 0 """ return self._bracket_(rhs) @@ -831,13 +837,13 @@ def _bracket_(self, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).example() - sage: x,y = L.lie_algebra_generators() - sage: x._bracket_(y) + sage: L = LieAlgebras(QQ).example() # optional - sage.combinat sage.modules + sage: x,y = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: x._bracket_(y) # optional - sage.combinat sage.modules -[1, 3, 2] + [3, 2, 1] - sage: y._bracket_(x) + sage: y._bracket_(x) # optional - sage.combinat sage.modules [1, 3, 2] - [3, 2, 1] - sage: x._bracket_(x) + sage: x._bracket_(x) # optional - sage.combinat sage.modules 0 """ @@ -853,10 +859,10 @@ def to_vector(self, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L((1, 0, 0)).to_vector(); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: u = L((1, 0, 0)).to_vector(); u # optional - sage.combinat sage.modules (1, 0, 0) - sage: parent(u) + sage: parent(u) # optional - sage.combinat sage.modules Vector space of dimension 3 over Rational Field """ @@ -868,16 +874,16 @@ def lift(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: elt = 3*a + b - c - sage: elt.lift() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: elt = 3*a + b - c # optional - sage.combinat sage.modules + sage: elt.lift() # optional - sage.combinat sage.modules 3*b0 + b1 - b2 :: - sage: L. = LieAlgebra(QQ, abelian=True) - sage: x.lift() + sage: L. = LieAlgebra(QQ, abelian=True) # optional - sage.combinat sage.modules + sage: x.lift() # optional - sage.combinat sage.modules x """ @@ -887,9 +893,9 @@ def killing_form(self, x): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: a.killing_form(b) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: a.killing_form(b) # optional - sage.combinat sage.modules 0 """ return self.parent().killing_form(self, x) @@ -906,24 +912,26 @@ def exp(self, lie_group=None): EXAMPLES:: - sage: L. = LieAlgebra(QQ, 2, step=2) - sage: g = (X + Y + Z).exp(); g # optional - sage.symbolic + sage: L. = LieAlgebra(QQ, 2, step=2) # optional - sage.combinat sage.modules + sage: g = (X + Y + Z).exp(); g # optional - sage.combinat sage.modules sage.symbolic exp(X + Y + Z) - sage: h = X.exp(); h # optional - sage.symbolic + sage: h = X.exp(); h # optional - sage.combinat sage.modules sage.symbolic exp(X) - sage: g.parent() # optional - sage.symbolic - Lie group G of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) over Rational Field - sage: g.parent() is h.parent() # optional - sage.symbolic + sage: g.parent() # optional - sage.combinat sage.modules sage.symbolic + Lie group G of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) + over Rational Field + sage: g.parent() is h.parent() # optional - sage.combinat sage.modules sage.symbolic True The Lie group can be specified explicitly:: - sage: H = L.lie_group('H') # optional - sage.symbolic - sage: k = Z.exp(lie_group=H); k # optional - sage.symbolic + sage: H = L.lie_group('H') # optional - sage.combinat sage.modules sage.symbolic + sage: k = Z.exp(lie_group=H); k # optional - sage.combinat sage.modules sage.symbolic exp(Z) - sage: k.parent() # optional - sage.symbolic - Lie group H of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) over Rational Field - sage: g.parent() == k.parent() # optional - sage.symbolic + sage: k.parent() # optional - sage.combinat sage.modules sage.symbolic + Lie group H of Free Nilpotent Lie algebra on 3 generators (X, Y, Z) + over Rational Field + sage: g.parent() == k.parent() # optional - sage.combinat sage.modules sage.symbolic False """ if lie_group is None: @@ -941,13 +949,13 @@ def __init__(self, domain, codomain): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: f = L.lift + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: f = L.lift # optional - sage.combinat sage.modules We skip the category test since this is currently not an element of a homspace:: - sage: TestSuite(f).run(skip="_test_category") + sage: TestSuite(f).run(skip="_test_category") # optional - sage.combinat sage.modules """ Morphism.__init__(self, Hom(domain, codomain)) @@ -957,9 +965,9 @@ def _call_(self, x): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: a, b, c = L.lie_algebra_generators() - sage: L.lift(3*a + b - c) + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat sage.modules + sage: a, b, c = L.lie_algebra_generators() # optional - sage.combinat sage.modules + sage: L.lift(3*a + b - c) # optional - sage.combinat sage.modules 3*b0 + b1 - b2 """ return x.lift() diff --git a/src/sage/categories/lie_algebras_with_basis.py b/src/sage/categories/lie_algebras_with_basis.py index 71916e3d6ad..4f6cf394651 100644 --- a/src/sage/categories/lie_algebras_with_basis.py +++ b/src/sage/categories/lie_algebras_with_basis.py @@ -34,13 +34,13 @@ def example(self, gens=None): EXAMPLES:: - sage: LieAlgebras(QQ).WithBasis().example() + sage: LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat An example of a Lie algebra: the abelian Lie algebra on the generators indexed by Partitions over Rational Field Another set of generators can be specified as an optional argument:: - sage: LieAlgebras(QQ).WithBasis().example(Compositions()) + sage: LieAlgebras(QQ).WithBasis().example(Compositions()) # optional - sage.combinat An example of a Lie algebra: the abelian Lie algebra on the generators indexed by Compositions of non-negative integers over Rational Field @@ -64,8 +64,8 @@ def _basis_key(self, x): TESTS:: - sage: L = LieAlgebras(QQ).WithBasis().example() - sage: L._basis_key(Partition([3,1])) + sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: L._basis_key(Partition([3,1])) # optional - sage.combinat [3, 1] """ return x @@ -79,8 +79,8 @@ def bracket_on_basis(self, x, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() - sage: L.bracket_on_basis(Partition([3,1]), Partition([2,2,1,1])) + sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: L.bracket_on_basis(Partition([3,1]), Partition([2,2,1,1])) # optional - sage.combinat 0 """ @@ -95,8 +95,8 @@ def module(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() - sage: L.module() + sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: L.module() # optional - sage.combinat Free module generated by Partitions over Rational Field """ from sage.combinat.free_module import CombinatorialFreeModule @@ -119,10 +119,10 @@ def from_vector(self, v, order=None, coerce=False): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat + sage: u = L.from_vector(vector(QQ, (1, 0, 0))); u # optional - sage.combinat (1, 0, 0) - sage: parent(u) is L + sage: parent(u) is L # optional - sage.combinat True """ B = self.basis() @@ -135,14 +135,14 @@ def dimension(self): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.dimension() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.combinat + sage: L.dimension() # optional - sage.combinat 3 :: - sage: L = LieAlgebra(QQ, 'x,y', {('x','y'): {'x':1}}) - sage: L.dimension() + sage: L = LieAlgebra(QQ, 'x,y', {('x','y'): {'x':1}}) # optional - sage.combinat sage.modules + sage: L.dimension() # optional - sage.combinat sage.modules 2 """ return self.basis().cardinality() @@ -154,8 +154,8 @@ def pbw_basis(self, basis_key=None, **kwds): EXAMPLES:: - sage: L = lie_algebras.sl(QQ, 2) - sage: PBW = L.pbw_basis() + sage: L = lie_algebras.sl(QQ, 2) # optional - sage.combinat sage.modules + sage: PBW = L.pbw_basis() # optional - sage.combinat sage.modules """ from sage.algebras.lie_algebras.poincare_birkhoff_witt \ import PoincareBirkhoffWittBasis @@ -173,11 +173,11 @@ def _bracket_(self, y): EXAMPLES:: - sage: L = LieAlgebras(QQ).WithBasis().example() - sage: G = L.lie_algebra_generators() - sage: x = G[Partition([4,3,3,1])] - sage: y = G[Partition([6,1])] - sage: x.bracket(y) + sage: L = LieAlgebras(QQ).WithBasis().example() # optional - sage.combinat + sage: G = L.lie_algebra_generators() # optional - sage.combinat + sage: x = G[Partition([4,3,3,1])] # optional - sage.combinat + sage: y = G[Partition([6,1])] # optional - sage.combinat + sage: x.bracket(y) # optional - sage.combinat 0 """ P = self.parent() @@ -206,8 +206,8 @@ def to_vector(self, order=None): EXAMPLES:: - sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() - sage: L.an_element().to_vector() + sage: L = LieAlgebras(QQ).FiniteDimensional().WithBasis().example() # optional - sage.modules + sage: L.an_element().to_vector() # optional - sage.modules (0, 0, 0) .. TODO:: @@ -224,15 +224,15 @@ def lift(self): EXAMPLES:: - sage: S = SymmetricGroup(3).algebra(QQ) - sage: L = LieAlgebra(associative=S) - sage: x = L.gen(3) - sage: y = L.gen(1) - sage: x.lift() + sage: S = SymmetricGroup(3).algebra(QQ) # optional - sage.groups + sage: L = LieAlgebra(associative=S) # optional - sage.groups + sage: x = L.gen(3) # optional - sage.groups + sage: y = L.gen(1) # optional - sage.groups + sage: x.lift() # optional - sage.groups b3 - sage: y.lift() + sage: y.lift() # optional - sage.groups b1 - sage: x * y + sage: x * y # optional - sage.groups b1*b3 + b4 - b5 """ P = self.parent() diff --git a/src/sage/categories/lie_conformal_algebras.py b/src/sage/categories/lie_conformal_algebras.py index 54e3956c283..4e59d4758b0 100644 --- a/src/sage/categories/lie_conformal_algebras.py +++ b/src/sage/categories/lie_conformal_algebras.py @@ -152,15 +152,16 @@ class LieConformalAlgebras(Category_over_base_ring): Some subcategories:: - sage: LieConformalAlgebras(QQbar).FinitelyGenerated().WithBasis() - Category of finitely generated Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).FinitelyGenerated().WithBasis() # optional - sage.rings.number_field + Category of finitely generated Lie conformal algebras with basis + over Algebraic Field In addition we support functorial constructions ``Graded`` and ``Super``. These functors commute:: - sage: LieConformalAlgebras(AA).Graded().Super() + sage: CGS = LieConformalAlgebras(AA).Graded().Super(); CGS # optional - sage.rings.number_field Category of H-graded super Lie conformal algebras over Algebraic Real Field - sage: LieConformalAlgebras(AA).Graded().Super() is LieConformalAlgebras(AA).Super().Graded() + sage: CGS is LieConformalAlgebras(AA).Super().Graded() # optional - sage.rings.number_field True That is, we only consider gradings on super Lie conformal algebras @@ -168,9 +169,10 @@ class LieConformalAlgebras(Category_over_base_ring): The base ring needs to be a commutative ring:: - sage: LieConformalAlgebras(QuaternionAlgebra(2)) + sage: LieConformalAlgebras(QuaternionAlgebra(2)) # optional - sage.combinat sage.modules Traceback (most recent call last): - ValueError: base must be a commutative ring got Quaternion Algebra (-1, -1) with base ring Rational Field + ValueError: base must be a commutative ring + got Quaternion Algebra (-1, -1) with base ring Rational Field """ @cached_method def super_categories(self): @@ -219,7 +221,7 @@ def example(self): EXAMPLES:: - sage: LieConformalAlgebras(QQ).example() + sage: LieConformalAlgebras(QQ).example() # optional - sage.combinat sage.modules The Virasoro Lie conformal algebra over Rational Field """ from sage.algebras.lie_conformal_algebras.virasoro_lie_conformal_algebra\ @@ -252,27 +254,27 @@ def _test_jacobi(self, **options): By default, this method tests only the elements returned by ``self.some_elements()``:: - sage: V = lie_conformal_algebras.Affine(QQ, 'B2') - sage: V._test_jacobi() # long time (6 seconds) + sage: V = lie_conformal_algebras.Affine(QQ, 'B2') # optional - sage.combinat sage.modules + sage: V._test_jacobi() # long time (6 seconds) # optional - sage.combinat sage.modules It works for super Lie conformal algebras too:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: V._test_jacobi() + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: V._test_jacobi() # optional - sage.combinat sage.modules We can use specific elements by passing the ``elements`` keyword argument:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) - sage: V.inject_variables() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) # optional - sage.combinat sage.modules + sage: V.inject_variables() # optional - sage.combinat sage.modules Defining e, h, f, K - sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) + sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) # optional - sage.combinat sage.modules TESTS:: sage: wrongdict = {('a', 'a'): {0: {('b', 0): 1}}, ('b', 'a'): {0: {('a', 0): 1}}} - sage: V = LieConformalAlgebra(QQ, wrongdict, names=('a', 'b'), parity=(1, 0)) - sage: V._test_jacobi() + sage: V = LieConformalAlgebra(QQ, wrongdict, names=('a', 'b'), parity=(1, 0)) # optional - sage.combinat sage.modules + sage: V._test_jacobi() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: {(0, 0): -3*a} != {} @@ -323,10 +325,10 @@ def is_even_odd(self): EXAMPLES:: - sage: R = lie_conformal_algebras.NeveuSchwarz(QQ); - sage: R.inject_variables() + sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: R.inject_variables() # optional - sage.combinat sage.modules Defining L, G, C - sage: G.is_even_odd() + sage: G.is_even_odd() # optional - sage.combinat sage.modules 1 """ return 0 diff --git a/src/sage/categories/lie_conformal_algebras_with_basis.py b/src/sage/categories/lie_conformal_algebras_with_basis.py index 50f67d2a970..6f31b6b4cca 100644 --- a/src/sage/categories/lie_conformal_algebras_with_basis.py +++ b/src/sage/categories/lie_conformal_algebras_with_basis.py @@ -27,7 +27,7 @@ class LieConformalAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis() + sage: LieConformalAlgebras(QQbar).WithBasis() # optional - sage.rings.number_field Category of Lie conformal algebras with basis over Algebraic Field """ class Super(SuperModulesCategory): @@ -36,8 +36,9 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).WithBasis().Super() - Category of super Lie conformal algebras with basis over Algebraic Real Field + sage: LieConformalAlgebras(AA).WithBasis().Super() # optional - sage.rings.number_field + Category of super Lie conformal algebras with basis + over Algebraic Real Field """ class ParentMethods: @@ -52,9 +53,9 @@ def _even_odd_on_basis(self, m): EXAMPLES:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: B = V._indices - sage: V._even_odd_on_basis(B(('G',1))) + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: B = V._indices # optional - sage.combinat sage.modules + sage: V._even_odd_on_basis(B(('G', 1))) # optional - sage.combinat sage.modules 1 """ return self._parity[self.monomial((m[0],0))] @@ -65,8 +66,9 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().Super().Graded() - Category of H-graded super Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).WithBasis().Super().Graded() # optional - sage.rings.number_field + Category of H-graded super Lie conformal algebras with basis + over Algebraic Field """ class Graded(GradedLieConformalAlgebrasCategory): @@ -75,7 +77,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().Graded() + sage: LieConformalAlgebras(QQbar).WithBasis().Graded() # optional - sage.rings.number_field Category of H-graded Lie conformal algebras with basis over Algebraic Field """ @@ -86,10 +88,11 @@ class FinitelyGeneratedAsLambdaBracketAlgebra(CategoryWithAxiom_over_base_ring): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar) - sage: C.WithBasis().FinitelyGenerated() - Category of finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.WithBasis().FinitelyGenerated() is C.FinitelyGenerated().WithBasis() + sage: C = LieConformalAlgebras(QQbar) # optional - sage.rings.number_field + sage: CWF = C.WithBasis().FinitelyGenerated(); CWF # optional - sage.rings.number_field + Category of finitely generated Lie conformal algebras with basis + over Algebraic Field + sage: CWF is C.FinitelyGenerated().WithBasis() # optional - sage.rings.number_field True """ class Super(SuperModulesCategory): @@ -99,8 +102,9 @@ class Super(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).WithBasis().FinitelyGenerated().Super() - Category of super finitely generated Lie conformal algebras with basis over Algebraic Real Field + sage: LieConformalAlgebras(AA).WithBasis().FinitelyGenerated().Super() # optional - sage.rings.number_field + Category of super finitely generated Lie conformal algebras with basis + over Algebraic Real Field """ class Graded(GradedModulesCategory): """ @@ -109,10 +113,11 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() - sage: C.Graded().Super() - Category of H-graded super finitely generated Lie conformal algebras with basis over Algebraic Field - sage: C.Graded().Super() is C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # optional - sage.rings.number_field + sage: C.Graded().Super() # optional - sage.rings.number_field + Category of H-graded super finitely generated Lie conformal algebras + with basis over Algebraic Field + sage: C.Graded().Super() is C.Super().Graded() # optional - sage.rings.number_field True """ def _repr_object_names(self): @@ -121,8 +126,8 @@ def _repr_object_names(self): EXAMPLES:: - sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() - sage: C.Super().Graded() + sage: C = LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated() # optional - sage.rings.number_field + sage: C.Super().Graded() # optional - sage.rings.number_field Category of H-graded super finitely generated Lie conformal algebras with basis over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) @@ -134,6 +139,7 @@ class Graded(GradedLieConformalAlgebrasCategory): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() - Category of H-graded finitely generated Lie conformal algebras with basis over Algebraic Field + sage: LieConformalAlgebras(QQbar).WithBasis().FinitelyGenerated().Graded() # optional - sage.rings.number_field + Category of H-graded finitely generated Lie conformal algebras with basis + over Algebraic Field """ diff --git a/src/sage/categories/loop_crystals.py b/src/sage/categories/loop_crystals.py index 415d8c308f7..b7dbd37a3c6 100644 --- a/src/sage/categories/loop_crystals.py +++ b/src/sage/categories/loop_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs sage.combinat r""" Loop Crystals """ @@ -390,11 +391,17 @@ def R_matrix(self, K): sage: K2 = crystals.KirillovReshetikhin(['A',2,1],2,1) sage: T1 = crystals.TensorProduct(K1,K2) sage: T2 = crystals.TensorProduct(K2,K1) - sage: T1.digraph().is_isomorphic(T2.digraph(), edge_labels=True, certificate=True) #todo: not implemented (see #10904 and #10549) - (True, {[[[1]], [[2], [3]]]: [[[1], [3]], [[2]]], [[[3]], [[2], [3]]]: [[[2], [3]], [[3]]], - [[[3]], [[1], [3]]]: [[[1], [3]], [[3]]], [[[1]], [[1], [3]]]: [[[1], [3]], [[1]]], [[[1]], - [[1], [2]]]: [[[1], [2]], [[1]]], [[[2]], [[1], [2]]]: [[[1], [2]], [[2]]], [[[3]], - [[1], [2]]]: [[[2], [3]], [[1]]], [[[2]], [[1], [3]]]: [[[1], [2]], [[3]]], [[[2]], [[2], [3]]]: [[[2], [3]], [[2]]]}) + sage: T1.digraph().is_isomorphic(T2.digraph(), edge_labels=True, # todo: not implemented (see #10904 and #10549) + ....: certificate=True) + (True, {[[[1]], [[2], [3]]]: [[[1], [3]], [[2]]], + [[[3]], [[2], [3]]]: [[[2], [3]], [[3]]], + [[[3]], [[1], [3]]]: [[[1], [3]], [[3]]], + [[[1]], [[1], [3]]]: [[[1], [3]], [[1]]], [[[1]], + [[1], [2]]]: [[[1], [2]], [[1]]], + [[[2]], [[1], [2]]]: [[[1], [2]], [[2]]], [[[3]], + [[1], [2]]]: [[[2], [3]], [[1]]], + [[[2]], [[1], [3]]]: [[[1], [2]], [[3]]], + [[[2]], [[2], [3]]]: [[[2], [3]], [[2]]]}) """ from sage.combinat.crystals.tensor_product import TensorProductOfCrystals T1 = TensorProductOfCrystals(self, K) @@ -514,7 +521,7 @@ def is_perfect(self, ell=None): sage: K.is_perfect() True - sage: K = crystals.KirillovReshetikhin(['E',6,1], 1,3) + sage: K = crystals.KirillovReshetikhin(['E',6,1], 1, 3) sage: K.is_perfect() True @@ -523,7 +530,7 @@ def is_perfect(self, ell=None): Check that this works correctly for `B^{n,s}` of type `A_{2n}^{(2)\dagger}` (:trac:`24364`):: - sage: K = crystals.KirillovReshetikhin(CartanType(['A',6,2]).dual(), 3,1) + sage: K = crystals.KirillovReshetikhin(CartanType(['A',6,2]).dual(), 3, 1) sage: K.is_perfect() True sage: K.is_perfect(1) @@ -835,7 +842,8 @@ def one_dimensional_configuration_sum(self, q=None, group_components=True): sage: R = RootSystem(['A',2,1]) sage: La = R.weight_space().basis() sage: LS = crystals.ProjectedLevelZeroLSPaths(2*La[1]) - sage: LS.one_dimensional_configuration_sum() == T.one_dimensional_configuration_sum() # long time + sage: (LS.one_dimensional_configuration_sum() # long time + ....: == T.one_dimensional_configuration_sum()) True TESTS:: diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index 33dc2bb973a..395f18b4ece 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -296,11 +296,13 @@ def Distributive(self): sage: Magmas().Distributive() Traceback (most recent call last): ... - ValueError: The distributive axiom only makes sense on a magma which is simultaneously an additive magma + ValueError: The distributive axiom only makes sense on a magma + which is simultaneously an additive magma sage: Semigroups().Distributive() Traceback (most recent call last): ... - ValueError: The distributive axiom only makes sense on a magma which is simultaneously an additive magma + ValueError: The distributive axiom only makes sense on a magma + which is simultaneously an additive magma TESTS:: @@ -331,7 +333,8 @@ def JTrivial(self): sage: Magmas().JTrivial() Category of j trivial magmas - sage: (Semigroups().RTrivial() & Semigroups().LTrivial()) is Semigroups().JTrivial() + sage: C = Semigroups().RTrivial() & Semigroups().LTrivial() + sage: C is Semigroups().JTrivial() True """ return self._with_axiom('JTrivial') @@ -349,19 +352,22 @@ def extra_super_categories(self): """ EXAMPLES:: - sage: Magmas().Commutative().Algebras(QQ).extra_super_categories() + sage: MCA = Magmas().Commutative().Algebras(QQ) + sage: MCA.extra_super_categories() [Category of commutative magmas] This implements the fact that the algebra of a commutative magma is commutative:: - sage: Magmas().Commutative().Algebras(QQ).super_categories() - [Category of magma algebras over Rational Field, Category of commutative magmas] + sage: MCA.super_categories() + [Category of magma algebras over Rational Field, + Category of commutative magmas] In particular, commutative monoid algebras are commutative algebras:: - sage: Monoids().Commutative().Algebras(QQ).is_subcategory(Algebras(QQ).Commutative()) + sage: MoCA = Monoids().Commutative().Algebras(QQ) + sage: MoCA.is_subcategory(Algebras(QQ).Commutative()) True """ from sage.categories.magmatic_algebras import MagmaticAlgebras @@ -377,11 +383,11 @@ def is_field(self, proof=True): EXAMPLES:: - sage: SymmetricGroup(1).algebra(QQ).is_field() + sage: SymmetricGroup(1).algebra(QQ).is_field() # optional - sage.groups True - sage: SymmetricGroup(1).algebra(ZZ).is_field() + sage: SymmetricGroup(1).algebra(ZZ).is_field() # optional - sage.groups False - sage: SymmetricGroup(2).algebra(QQ).is_field() + sage: SymmetricGroup(2).algebra(QQ).is_field() # optional - sage.groups False """ if not self.base_ring().is_field(proof): @@ -397,7 +403,7 @@ def is_commutative(self): EXAMPLES:: - sage: Parent(QQ,category=CommutativeRings()).is_commutative() + sage: Parent(QQ, category=CommutativeRings()).is_commutative() True """ return True @@ -408,20 +414,22 @@ def extra_super_categories(self): """ EXAMPLES:: - sage: Magmas().Commutative().Algebras(QQ).extra_super_categories() + sage: MCA = Magmas().Commutative().Algebras(QQ) + sage: MCA.extra_super_categories() [Category of commutative magmas] This implements the fact that the algebra of a commutative magma is commutative:: - sage: Magmas().Commutative().Algebras(QQ).super_categories() + sage: MCA.super_categories() [Category of magma algebras over Rational Field, Category of commutative magmas] In particular, commutative monoid algebras are commutative algebras:: - sage: Monoids().Commutative().Algebras(QQ).is_subcategory(Algebras(QQ).Commutative()) + sage: MoCA = Monoids().Commutative().Algebras(QQ) + sage: MoCA.is_subcategory(Algebras(QQ).Commutative()) True """ return [Magmas().Commutative()] @@ -480,7 +488,8 @@ def one(self): EXAMPLES:: sage: M = Monoids().example(); M - An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') + An example of a monoid: + the free monoid generated by ('a', 'b', 'c', 'd') sage: M.one() '' """ @@ -531,8 +540,8 @@ def is_empty(self): EXAMPLES:: - sage: S = SymmetricGroup(2) - sage: S.is_empty() + sage: S = SymmetricGroup(2) # optional - sage.groups + sage: S.is_empty() # optional - sage.groups False sage: M = Monoids().example() @@ -541,7 +550,7 @@ def is_empty(self): TESTS:: - sage: S.is_empty.__module__ + sage: S.is_empty.__module__ # optional - sage.groups 'sage.categories.magmas' sage: M.is_empty.__module__ 'sage.categories.magmas' @@ -684,20 +693,22 @@ def extra_super_categories(self): """ EXAMPLES:: - sage: Magmas().Commutative().Algebras(QQ).extra_super_categories() + sage: MCA = Magmas().Commutative().Algebras(QQ) + sage: MCA.extra_super_categories() [Category of commutative magmas] This implements the fact that the algebra of a commutative magma is commutative:: - sage: Magmas().Commutative().Algebras(QQ).super_categories() + sage: MCA.super_categories() [Category of magma algebras over Rational Field, Category of commutative magmas] In particular, commutative monoid algebras are commutative algebras:: - sage: Monoids().Commutative().Algebras(QQ).is_subcategory(Algebras(QQ).Commutative()) + sage: MoCA = Monoids().Commutative().Algebras(QQ) + sage: MoCA.is_subcategory(Algebras(QQ).Commutative()) True """ return [Magmas().Unital()] @@ -713,11 +724,11 @@ def one(self): EXAMPLES:: - sage: from sage.combinat.root_system.extended_affine_weyl_group import ExtendedAffineWeylGroup - sage: PvW0 = ExtendedAffineWeylGroup(['A',2,1]).PvW0() - sage: PvW0 in Magmas().Unital().Realizations() + sage: from sage.combinat.root_system.extended_affine_weyl_group import ExtendedAffineWeylGroup # optional - sage.combinat sage.groups + sage: PvW0 = ExtendedAffineWeylGroup(['A',2,1]).PvW0() # optional - sage.combinat sage.groups + sage: PvW0 in Magmas().Unital().Realizations() # optional - sage.combinat sage.groups True - sage: PvW0.one() + sage: PvW0.one() # optional - sage.combinat sage.groups 1 """ return self(self.realization_of().a_realization().one()) @@ -758,7 +769,8 @@ def product(self, x, y): Currently, ``S.product`` is just a bound method:: sage: bin - + When Sage will support multivariate morphisms, it will be possible, and in fact recommended, to enrich ``S.product`` @@ -872,8 +884,8 @@ def multiplication_table(self, names='letters', elements=None): The default is to represent elements as lowercase ASCII letters. :: - sage: G = CyclicPermutationGroup(5) - sage: G.multiplication_table() + sage: G = CyclicPermutationGroup(5) # optional - sage.groups + sage: G.multiplication_table() # optional - sage.groups * a b c d e +---------- a| a b c d e @@ -890,10 +902,10 @@ def multiplication_table(self, names='letters', elements=None): sage: from sage.categories.examples.finite_semigroups import LeftRegularBand sage: L = LeftRegularBand(('a', 'b')) - sage: T = L.multiplication_table(names='digits') - sage: T.column_keys() + sage: T = L.multiplication_table(names='digits') # optional - sage.matrix + sage: T.column_keys() # optional - sage.matrix ('a', 'ab', 'b', 'ba') - sage: T + sage: T # optional - sage.matrix * 0 1 2 3 +-------- 0| 0 1 1 1 @@ -906,7 +918,7 @@ def multiplication_table(self, names='letters', elements=None): sage: L = LeftRegularBand(('a', 'b', 'c')) sage: elts = sorted(L.list()) - sage: L.multiplication_table(elements=elts) + sage: L.multiplication_table(elements=elts) # optional - sage.matrix * a b c d e f g h i j k l m n o +------------------------------ a| a b c d e b b c c c d d e e e @@ -935,7 +947,7 @@ def multiplication_table(self, names='letters', elements=None): sage: L = LeftRegularBand(('a','b','c')) sage: elts=['a', 'c', 'ac', 'ca'] - sage: L.multiplication_table(names='elements', elements=elts) + sage: L.multiplication_table(names='elements', elements=elts) # optional - sage.matrix * 'a' 'c' 'ac' 'ca' +-------------------- 'a'| 'a' 'ac' 'ac' 'ac' @@ -948,16 +960,16 @@ def multiplication_table(self, names='letters', elements=None): :class:`~sage.matrix.operation_table.OperationTable` for more comprehensive documentation. :: - sage: G = AlternatingGroup(3) - sage: T = G.multiplication_table() - sage: T.column_keys() + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = G.multiplication_table() # optional - sage.groups sage.matrix + sage: T.column_keys() # optional - sage.groups sage.matrix ((), (1,2,3), (1,3,2)) - sage: T.translation() + sage: T.translation() # optional - sage.groups sage.matrix {'a': (), 'b': (1,2,3), 'c': (1,3,2)} - sage: T.change_names(['x', 'y', 'z']) - sage: T.translation() + sage: T.change_names(['x', 'y', 'z']) # optional - sage.groups sage.matrix + sage: T.translation() # optional - sage.groups sage.matrix {'x': (), 'y': (1,2,3), 'z': (1,3,2)} - sage: T + sage: T # optional - sage.groups sage.matrix * x y z +------ x| x y z @@ -999,7 +1011,8 @@ def is_idempotent(self): EXAMPLES:: sage: S = Semigroups().example("free"); S - An example of a semigroup: the free semigroup generated by ('a', 'b', 'c', 'd') + An example of a semigroup: + the free semigroup generated by ('a', 'b', 'c', 'd') sage: a = S('a') sage: a^2 'aa' @@ -1071,12 +1084,12 @@ def product(self, left, right): sage: x * x (1/4, 1, 1) - sage: A = SymmetricGroupAlgebra(QQ, 3) - sage: x = cartesian_product([A([1,3,2]), A([2,3,1])]) - sage: y = cartesian_product([A([1,3,2]), A([2,3,1])]) - sage: cartesian_product([A,A]).product(x,y) + sage: A = SymmetricGroupAlgebra(QQ, 3) # optional - sage.groups + sage: x = cartesian_product([A([1,3,2]), A([2,3,1])]) # optional - sage.groups + sage: y = cartesian_product([A([1,3,2]), A([2,3,1])]) # optional - sage.groups + sage: cartesian_product([A,A]).product(x,y) # optional - sage.groups B[(0, [1, 2, 3])] + B[(1, [3, 1, 2])] - sage: x*y + sage: x*y # optional - sage.groups B[(0, [1, 2, 3])] + B[(1, [3, 1, 2])] """ prods = ((a * b) for a, b in zip(left.cartesian_factors(), @@ -1125,9 +1138,9 @@ def product(self, x, y): Here is a more elaborate example involving a sub algebra:: - sage: Z = SymmetricGroup(5).algebra(QQ).center() - sage: B = Z.basis() - sage: B[3] * B[2] + sage: Z = SymmetricGroup(5).algebra(QQ).center() # optional - sage.groups + sage: B = Z.basis() # optional - sage.groups + sage: B[3] * B[2] # optional - sage.groups 4*B[2] + 6*B[3] + 5*B[6] """ assert x in self @@ -1149,15 +1162,18 @@ def product_by_coercion(self, left, right): EXAMPLES:: - sage: Out = Sets().WithRealizations().example().Out(); Out - The subset algebra of {1, 2, 3} over Rational Field in the Out basis - sage: Out.product - - sage: Out.product.__module__ + sage: Out = Sets().WithRealizations().example().Out(); Out # optional - sage.combinat sage.modules + The subset algebra of {1, 2, 3} over Rational Field + in the Out basis + sage: Out.product # optional - sage.combinat sage.modules + + sage: Out.product.__module__ # optional - sage.combinat sage.modules 'sage.categories.magmas' - sage: x = Out.an_element() - sage: y = Out.an_element() - sage: Out.product(x, y) + sage: x = Out.an_element() # optional - sage.combinat sage.modules + sage: y = Out.an_element() # optional - sage.combinat sage.modules + sage: Out.product(x, y) # optional - sage.combinat sage.modules Out[{}] + 4*Out[{1}] + 9*Out[{2}] + Out[{1, 2}] """ diff --git a/src/sage/categories/magmatic_algebras.py b/src/sage/categories/magmatic_algebras.py index ef82ba4319b..171f564534e 100644 --- a/src/sage/categories/magmatic_algebras.py +++ b/src/sage/categories/magmatic_algebras.py @@ -40,7 +40,8 @@ class MagmaticAlgebras(Category_over_base_ring): sage: C = MagmaticAlgebras(ZZ); C Category of magmatic algebras over Integer Ring sage: C.super_categories() - [Category of additive commutative additive associative additive unital distributive magmas and additive magmas, + [Category of additive commutative additive associative additive + unital distributive magmas and additive magmas, Category of modules over Integer Ring] TESTS:: @@ -54,11 +55,14 @@ def super_categories(self): EXAMPLES:: sage: from sage.categories.magmatic_algebras import MagmaticAlgebras - sage: MagmaticAlgebras(ZZ).super_categories() - [Category of additive commutative additive associative additive unital distributive magmas and additive magmas, Category of modules over Integer Ring] + sage: MA = MagmaticAlgebras(ZZ) + sage: MA.super_categories() + [Category of additive commutative additive associative additive + unital distributive magmas and additive magmas, + Category of modules over Integer Ring] sage: from sage.categories.additive_semigroups import AdditiveSemigroups - sage: MagmaticAlgebras(ZZ).is_subcategory((AdditiveSemigroups() & Magmas()).Distributive()) + sage: MA.is_subcategory((AdditiveSemigroups() & Magmas()).Distributive()) True """ @@ -106,9 +110,10 @@ def algebra_generators(self): EXAMPLES:: - sage: F = AlgebrasWithBasis(QQ).example(); F - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: F.algebra_generators() + sage: F = AlgebrasWithBasis(QQ).example(); F # 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: F.algebra_generators() # optional - sage.combinat sage.modules Family (B[word: a], B[word: b], B[word: c]) """ @@ -131,16 +136,18 @@ def algebra_generators(self): EXAMPLES:: - sage: D4 = DescentAlgebra(QQ, 4).B() - sage: D4.algebra_generators() + sage: D4 = DescentAlgebra(QQ, 4).B() # optional - sage.combinat sage.modules + sage: D4.algebra_generators() # optional - sage.combinat sage.modules Lazy family (...)_{i in Compositions of 4} sage: R. = ZZ[] - sage: P = PartitionAlgebra(1, x, R) - sage: P.algebra_generators() - Lazy family (Term map from Partition diagrams of order 1 to - Partition Algebra of rank 1 with parameter x over Univariate Polynomial Ring in x - over Integer Ring(i))_{i in Partition diagrams of order 1} + sage: P = PartitionAlgebra(1, x, R) # optional - sage.combinat sage.modules + sage: P.algebra_generators() # optional - sage.combinat sage.modules + Lazy family (Term map + from Partition diagrams of order 1 + to Partition Algebra of rank 1 with parameter x + over Univariate Polynomial Ring in x + over Integer Ring(i))_{i in Partition diagrams of order 1} """ return self.basis() @@ -162,9 +169,9 @@ def product_on_basis(self, i, j): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: Word = A.basis().keys() - sage: A.product_on_basis(Word("abc"),Word("cba")) + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: Word = A.basis().keys() # optional - sage.combinat sage.modules + sage: A.product_on_basis(Word("abc"), Word("cba")) # optional - sage.combinat sage.modules B[word: abccba] """ @@ -183,9 +190,9 @@ def product(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: a, b, c = A.algebra_generators() - sage: A.product(a + 2*b, 3*c) + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules + sage: A.product(a + 2*b, 3*c) # optional - sage.combinat sage.modules 3*B[word: ac] + 6*B[word: bc] """ if self.product_on_basis is not NotImplemented: @@ -205,10 +212,11 @@ def _product_from_product_on_basis_multiply( self, left, right ): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: (a,b,c) = A.algebra_generators() - sage: A._product_from_product_on_basis_multiply(a*b + 2*c, a - b) + 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: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules + sage: A._product_from_product_on_basis_multiply(a*b + 2*c, a - b) # optional - sage.combinat sage.modules B[word: aba] - B[word: abb] + 2*B[word: ca] - 2*B[word: cb] """ @@ -239,17 +247,17 @@ def derivations_basis(self): We construct the Heisenberg Lie algebra as a multiplicative algebra:: - sage: p_mult = matrix([[0,0,0],[0,0,-1],[0,0,0]]) - sage: q_mult = matrix([[0,0,1],[0,0,0],[0,0,0]]) - sage: A = algebras.FiniteDimensional(QQ, - ....: [p_mult,q_mult,matrix(QQ,3,3)], 'p,q,z') - sage: A.inject_variables() + sage: p_mult = matrix([[0,0,0], [0,0,-1], [0,0,0]]) # optional - sage.combinat sage.modules + sage: q_mult = matrix([[0,0,1], [0,0,0], [0,0,0]]) # optional - sage.combinat sage.modules + sage: A = algebras.FiniteDimensional(QQ, # optional - sage.combinat sage.modules + ....: [p_mult, q_mult, matrix(QQ, 3, 3)], 'p,q,z') + sage: A.inject_variables() # optional - sage.combinat sage.modules Defining p, q, z - sage: p*q + sage: p * q # optional - sage.combinat sage.modules z - sage: q*p + sage: q * p # optional - sage.combinat sage.modules -z - sage: A.derivations_basis() + sage: A.derivations_basis() # optional - sage.combinat sage.modules ( [1 0 0] [0 1 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] [1 0 0] [0 1 0] [0 0 0] [0 0 0] @@ -259,15 +267,16 @@ def derivations_basis(self): We construct another example using the exterior algebra and verify we obtain a derivation:: - sage: A = algebras.Exterior(QQ, 1) - sage: A.derivations_basis() + sage: A = algebras.Exterior(QQ, 1) # optional - sage.combinat sage.modules + sage: A.derivations_basis() # optional - sage.combinat sage.modules ( [0 0] [0 1] ) - sage: D = A.module_morphism(matrix=A.derivations_basis()[0], codomain=A) - sage: one, e = A.basis() - sage: all(D(a*b) == D(a) * b + a * D(b) + sage: D = A.module_morphism(matrix=A.derivations_basis()[0], # optional - sage.combinat sage.modules + ....: codomain=A) + sage: one, e = A.basis() # optional - sage.combinat sage.modules + sage: all(D(a*b) == D(a) * b + a * D(b) # optional - sage.combinat sage.modules ....: for a in A.basis() for b in A.basis()) True diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 5a7445913bb..674d008476d 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -115,7 +115,7 @@ cdef class Map(Element): Using domain and codomain:: - sage: Map(QQ['x'], SymmetricGroup(6)) + sage: Map(QQ['x'], SymmetricGroup(6)) # optional - sage.groups Generic map: From: Univariate Polynomial Ring in x over Rational Field To: Symmetric group of order 6! as a permutation group @@ -196,34 +196,44 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_convert_map_from(Q) - sage: print(phi.parent()) - Set of field embeddings from Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I to Complex Double Field + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # optional - sage.rings.number_field + sage: print(phi.parent()) # optional - sage.rings.number_field + Set of field embeddings + from Number Field in a with defining polynomial x^2 + 5 + with a = 2.236067977499790?*I + to Complex Double Field We now demonstrate that the reference to the coercion map `\phi` does not prevent `Q` from being garbage collected:: sage: import gc - sage: del Q + sage: del Q # optional - sage.rings.number_field sage: _ = gc.collect() - sage: phi.parent() + sage: phi.parent() # optional - sage.rings.number_field Traceback (most recent call last): ... - ValueError: This map is in an invalid state, the domain has been garbage collected + ValueError: This map is in an invalid state, + the domain has been garbage collected You can still obtain copies of the maps used by the coercion system with strong references:: - sage: Q = QuadraticField(-5) - sage: phi = CDF.convert_map_from(Q) - sage: print(phi.parent()) - Set of field embeddings from Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I to Complex Double Field + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF.convert_map_from(Q) # optional - sage.rings.number_field + sage: print(phi.parent()) # optional - sage.rings.number_field + Set of field embeddings + from Number Field in a with defining polynomial x^2 + 5 + with a = 2.236067977499790?*I + to Complex Double Field sage: import gc - sage: del Q + sage: del Q # optional - sage.rings.number_field sage: _ = gc.collect() - sage: phi.parent() - Set of field embeddings from Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I to Complex Double Field + sage: phi.parent() # optional - sage.rings.number_field + Set of field embeddings + from Number Field in a with defining polynomial x^2 + 5 + with a = 2.236067977499790?*I + to Complex Double Field """ if self._parent is None: D = self.domain() @@ -250,28 +260,28 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_convert_map_from(Q) + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # optional - sage.rings.number_field By :trac:`14711`, maps used in the coercion and conversion system use *weak* references to domain and codomain, in contrast to other maps:: - sage: phi.domain + sage: phi.domain # optional - sage.rings.number_field - sage: phi._make_strong_references() - sage: print(phi.domain) + sage: phi._make_strong_references() # optional - sage.rings.number_field + sage: print(phi.domain) # optional - sage.rings.number_field The constant function (...) -> Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I Now, as there is a strong reference, `Q` cannot be garbage collected:: sage: import gc sage: _ = gc.collect() - sage: C = Q.__class__.__base__ - sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x, C)]) - sage: del Q, x + sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x, C)]) # optional - sage.rings.number_field + sage: del Q, x # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) # optional - sage.rings.number_field True However, if we now make the references weak again, the number field can @@ -279,11 +289,11 @@ cdef class Map(Element): invalid. This is why :meth:`_make_weak_references` should only be used if one really knows what one is doing:: - sage: phi._make_weak_references() + sage: phi._make_weak_references() # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + 1 + sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + 1 # optional - sage.rings.number_field True - sage: phi + sage: phi # optional - sage.rings.number_field Defunct map """ if not isinstance(self.domain, ConstantFunction): @@ -311,28 +321,28 @@ cdef class Map(Element): EXAMPLES:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_convert_map_from(Q) + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_convert_map_from(Q) # optional - sage.rings.number_field By :trac:`14711`, maps used in the coercion and conversion system use *weak* references to domain and codomain, in contrast to other maps:: - sage: phi.domain + sage: phi.domain # optional - sage.rings.number_field - sage: phi._make_strong_references() - sage: print(phi.domain) + sage: phi._make_strong_references() # optional - sage.rings.number_field + sage: print(phi.domain) # optional - sage.rings.number_field The constant function (...) -> Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I Now, as there is a strong reference, `Q` cannot be garbage collected:: sage: import gc sage: _ = gc.collect() - sage: C = Q.__class__.__base__ - sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x, C)]) - sage: del Q, x + sage: C = Q.__class__.__base__ # optional - sage.rings.number_field + sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x, C)]) # optional - sage.rings.number_field + sage: del Q, x # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) # optional - sage.rings.number_field True However, if we now make the references weak again, the number field can @@ -340,17 +350,17 @@ cdef class Map(Element): invalid. This is why :meth:`_make_weak_references` should only be used if one really knows what one is doing:: - sage: phi._make_weak_references() + sage: phi._make_weak_references() # optional - sage.rings.number_field sage: _ = gc.collect() - sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + 1 + sage: numberQuadFields == len([x for x in gc.get_objects() if isinstance(x, C)]) + 1 # optional - sage.rings.number_field True - sage: phi + sage: phi # optional - sage.rings.number_field Defunct map - sage: phi._make_strong_references() + sage: phi._make_strong_references() # optional - sage.rings.number_field Traceback (most recent call last): ... RuntimeError: The domain of this map became garbage collected - sage: phi.parent() + sage: phi.parent() # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: This map is in an invalid state, the domain has been garbage collected @@ -544,16 +554,16 @@ cdef class Map(Element): TESTS:: - sage: Q = QuadraticField(-5) - sage: phi = CDF._internal_coerce_map_from(Q); phi + sage: Q = QuadraticField(-5) # optional - sage.rings.number_field + sage: phi = CDF._internal_coerce_map_from(Q); phi # optional - sage.rings.number_field (map internal to coercion system -- copy before use) Composite map: From: Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I To: Complex Double Field - sage: del Q + sage: del Q # optional - sage.rings.number_field sage: import gc sage: _ = gc.collect() - sage: phi + sage: phi # optional - sage.rings.number_field Defunct map """ D = self.domain() @@ -746,11 +756,11 @@ cdef class Map(Element): ``pushforward`` fails, ``_call_`` is tried after conversion:: sage: g = FOO(QQ, ZZ) - sage: g(SR(3)) # optional - sage.symbolic + sage: g(SR(3)) # optional - sage.symbolic pushforward Symbolic Ring _call_ Rational Field 3 - sage: g(SR(3), exponent=2) # optional - sage.symbolic + sage: g(SR(3), exponent=2) # optional - sage.symbolic pushforward Symbolic Ring _call_with_args Rational Field 9 @@ -1122,7 +1132,8 @@ cdef class Map(Element): sage: mor.extend_domain(ZZ['x']) Traceback (most recent call last): ... - TypeError: No coercion from Univariate Polynomial Ring in x over Integer Ring to Real Double Field + TypeError: No coercion from Univariate Polynomial Ring in x over Integer Ring + to Real Double Field """ D = self.domain() if D is None: @@ -1162,7 +1173,7 @@ cdef class Map(Element): Native morphism: From: Rational Field To: Real Double Field - sage: mor.extend_codomain(GF(7)) + sage: mor.extend_codomain(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: No coercion from Rational Field to Finite Field of size 7 @@ -1217,14 +1228,14 @@ cdef class Map(Element): ... TypeError: self must be an endomorphism - sage: K. = NumberField(x^4 - 5*x + 5) - sage: C5. = CyclotomicField(5) - sage: tau = K.hom([z - z^2]); tau + sage: K. = NumberField(x^4 - 5*x + 5) # optional - sage.rings.number_field + sage: C5. = CyclotomicField(5) # optional - sage.rings.number_field + sage: tau = K.hom([z - z^2]); tau # optional - sage.rings.number_field Ring morphism: From: Number Field in a with defining polynomial x^4 - 5*x + 5 To: Cyclotomic Field of order 5 and degree 4 Defn: a |--> -z^2 + z - sage: tau^-1 + sage: tau^-1 # optional - sage.rings.number_field Ring morphism: From: Cyclotomic Field of order 5 and degree 4 To: Number Field in a with defining polynomial x^4 - 5*x + 5 @@ -1851,24 +1862,26 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: - sage: V1 = QQ^2 - sage: V2 = QQ^3 - sage: phi1 = (QQ^1).hom(Matrix([[1, 1]]), V1) - sage: phi2 = V1.hom(Matrix([[1, 2, 3], [4, 5, 6]]), V2) + sage: V1 = QQ^2 # optional - sage.modules + sage: V2 = QQ^3 # optional - sage.modules + sage: phi1 = (QQ^1).hom(Matrix([[1, 1]]), V1) # optional - sage.modules + sage: phi2 = V1.hom(Matrix([[1, 2, 3], [4, 5, 6]]), V2) # optional - sage.modules If both constituents are injective, the composition is injective:: sage: from sage.categories.map import FormalCompositeMap - sage: c1 = FormalCompositeMap(Hom(QQ^1, V2, phi1.category_for()), phi1, phi2) - sage: c1.is_injective() + sage: c1 = FormalCompositeMap(Hom(QQ^1, V2, phi1.category_for()), # optional - sage.modules + ....: phi1, phi2) + sage: c1.is_injective() # optional - sage.modules True If it cannot be determined whether the composition is injective, an error is raised:: - sage: psi1 = V2.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V1) - sage: c2 = FormalCompositeMap(Hom(V1, V1, phi2.category_for()), phi2, psi1) - sage: c2.is_injective() + sage: psi1 = V2.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V1) # optional - sage.modules + sage: c2 = FormalCompositeMap(Hom(V1, V1, phi2.category_for()), # optional - sage.modules + ....: phi2, psi1) + sage: c2.is_injective() # optional - sage.modules Traceback (most recent call last): ... NotImplementedError: not enough information to deduce injectivity @@ -1876,17 +1889,18 @@ cdef class FormalCompositeMap(Map): If the first map is surjective and the second map is not injective, then the composition is not injective:: - sage: psi2 = V1.hom([[1], [1]], QQ^1) - sage: c3 = FormalCompositeMap(Hom(V2, QQ^1, phi2.category_for()), psi2, psi1) - sage: c3.is_injective() + sage: psi2 = V1.hom([[1], [1]], QQ^1) # optional - sage.modules + sage: c3 = FormalCompositeMap(Hom(V2, QQ^1, phi2.category_for()), # optional - sage.modules + ....: psi2, psi1) + sage: c3.is_injective() # optional - sage.modules False TESTS: Check that :trac:`23205` has been resolved:: - sage: f = QQ.hom(QQbar)*ZZ.hom(QQ) - sage: f.is_injective() + sage: f = QQ.hom(QQbar) * ZZ.hom(QQ) # optional - sage.rings.number_field + sage: f.is_injective() # optional - sage.rings.number_field True """ @@ -1923,33 +1937,38 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: sage: from sage.categories.map import FormalCompositeMap - sage: V3 = QQ^3 - sage: V2 = QQ^2 - sage: V1 = QQ^1 + sage: V3 = QQ^3 # optional - sage.modules + sage: V2 = QQ^2 # optional - sage.modules + sage: V1 = QQ^1 # optional - sage.modules If both maps are surjective, the composition is surjective:: - sage: phi32 = V3.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V2) - sage: phi21 = V2.hom(Matrix([[1], [1]]), V1) - sage: c_phi = FormalCompositeMap(Hom(V3, V1, phi32.category_for()), phi32, phi21) - sage: c_phi.is_surjective() + sage: phi32 = V3.hom(Matrix([[1, 2], [3, 4], [5, 6]]), V2) # optional - sage.modules + sage: phi21 = V2.hom(Matrix([[1], [1]]), V1) # optional - sage.modules + sage: c_phi = FormalCompositeMap(Hom(V3, V1, phi32.category_for()), # optional - sage.modules + ....: phi32, phi21) + sage: c_phi.is_surjective() # optional - sage.modules True If the second map is not surjective, the composition is not surjective:: - sage: FormalCompositeMap(Hom(V3, V1, phi32.category_for()), phi32, V2.hom(Matrix([[0], [0]]), V1)).is_surjective() + sage: FormalCompositeMap(Hom(V3, V1, phi32.category_for()), # optional - sage.modules + ....: phi32, + ....: V2.hom(Matrix([[0], [0]]), V1)).is_surjective() False If the second map is an isomorphism and the first map is not surjective, then the composition is not surjective:: - sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), V2.hom(Matrix([[0], [0]]), V1), V1.hom(Matrix([[1]]), V1)).is_surjective() + sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # optional - sage.modules + ....: V2.hom(Matrix([[0], [0]]), V1), + ....: V1.hom(Matrix([[1]]), V1)).is_surjective() False Otherwise, surjectivity of the composition cannot be determined:: - sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), + sage: FormalCompositeMap(Hom(V2, V1, phi32.category_for()), # optional - sage.modules ....: V2.hom(Matrix([[1, 1], [1, 1]]), V2), ....: V2.hom(Matrix([[1], [1]]), V1)).is_surjective() Traceback (most recent call last): @@ -1991,8 +2010,8 @@ cdef class FormalCompositeMap(Map): EXAMPLES:: sage: f = QQ.coerce_map_from(ZZ) - sage: g = MatrixSpace(QQ, 2, 2).coerce_map_from(QQ) - sage: list((g*f).domains()) + sage: g = MatrixSpace(QQ, 2, 2).coerce_map_from(QQ) # optional - sage.modules + sage: list((g * f).domains()) # optional - sage.modules [Integer Ring, Rational Field] """ for f in self.__list: @@ -2026,9 +2045,9 @@ cdef class FormalCompositeMap(Map): of :class:`sage.rings.polynomial.polynomial_element.Polynomial` before (see comment there):: - sage: k = GF(47) - sage: R. = PolynomialRing(k) - sage: R.coerce_map_from(ZZ).section() + sage: k = GF(47) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: R.coerce_map_from(ZZ).section() # optional - sage.rings.finite_rings Composite map: From: Univariate Polynomial Ring in x over Finite Field of size 47 To: Integer Ring @@ -2039,9 +2058,9 @@ cdef class FormalCompositeMap(Map): Lifting map: From: Finite Field of size 47 To: Integer Ring - sage: ZZ(R(45)) # indirect doctest + sage: ZZ(R(45)) # indirect doctest # optional - sage.rings.finite_rings 45 - sage: ZZ(3*x + 45) # indirect doctest + sage: ZZ(3*x + 45) # indirect doctest # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: not a constant polynomial diff --git a/src/sage/categories/modules.py b/src/sage/categories/modules.py index cb878f1c6f2..81f6df6f51f 100644 --- a/src/sage/categories/modules.py +++ b/src/sage/categories/modules.py @@ -72,10 +72,12 @@ class Modules(Category_module): Category of modules over Ring of integers modulo 9 sage: Modules(Integers(9)).super_categories() - [Category of bimodules over Ring of integers modulo 9 on the left and Ring of integers modulo 9 on the right] + [Category of bimodules over Ring of integers modulo 9 on the left + and Ring of integers modulo 9 on the right] sage: Modules(ZZ).super_categories() - [Category of bimodules over Integer Ring on the left and Integer Ring on the right] + [Category of bimodules over Integer Ring on the left + and Integer Ring on the right] sage: Modules == RingModules True @@ -162,7 +164,8 @@ def super_categories(self): EXAMPLES:: sage: Modules(ZZ).super_categories() - [Category of bimodules over Integer Ring on the left and Integer Ring on the right] + [Category of bimodules over Integer Ring on the left + and Integer Ring on the right] Nota bene:: @@ -204,7 +207,8 @@ def base_ring(self): EXAMPLES:: sage: C = Modules(QQ) & Semigroups(); C - Join of Category of semigroups and Category of vector spaces over Rational Field + Join of Category of semigroups + and Category of vector spaces over Rational Field sage: C.base_ring() Rational Field sage: C.base_ring.__module__ @@ -217,16 +221,16 @@ def base_ring(self): sage: C.base_ring.__module__ 'sage.categories.modules' - sage: C = DescentAlgebra(QQ,3).B().category() - sage: C.base_ring.__module__ + sage: C = DescentAlgebra(QQ,3).B().category() # optional - sage.combinat sage.modules + sage: C.base_ring.__module__ # optional - sage.combinat sage.modules 'sage.categories.modules' - sage: C.base_ring() + sage: C.base_ring() # optional - sage.combinat sage.modules Rational Field - sage: C = QuasiSymmetricFunctions(QQ).F().category() - sage: C.base_ring.__module__ + sage: C = QuasiSymmetricFunctions(QQ).F().category() # optional - sage.combinat sage.modules + sage: C.base_ring.__module__ # optional - sage.combinat sage.modules 'sage.categories.modules' - sage: C.base_ring() + sage: C.base_ring() # optional - sage.combinat sage.modules Rational Field """ for C in self.super_categories(): @@ -361,10 +365,11 @@ def FinitelyPresented(self): sage: Modules(ZZ).FinitelyPresented() Category of finitely presented modules over Integer Ring - sage: A = SteenrodAlgebra(2) - sage: from sage.modules.fp_graded.module import FPModule - sage: FPModule(A, [0, 1], [[Sq(2), Sq(1)]]).category() - Category of finitely presented graded modules over mod 2 Steenrod algebra, milnor basis + sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules + sage: from sage.modules.fp_graded.module import FPModule # optional - sage.combinat sage.modules + sage: FPModule(A, [0, 1], [[Sq(2), Sq(1)]]).category() # optional - sage.combinat sage.modules + Category of finitely presented graded modules + over mod 2 Steenrod algebra, milnor basis TESTS:: @@ -516,7 +521,7 @@ def extra_super_categories(self): [Category of finite sets] sage: Modules(ZZ).FiniteDimensional().extra_super_categories() [] - sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) + sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings True sage: Modules(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) False @@ -547,7 +552,8 @@ def extra_super_categories(self): sage: Modules(ZZ).FiniteDimensional().TensorProducts().extra_super_categories() [Category of finite dimensional modules over Integer Ring] sage: Modules(QQ).FiniteDimensional().TensorProducts().FiniteDimensional() - Category of tensor products of finite dimensional vector spaces over Rational Field + Category of tensor products of finite dimensional vector spaces + over Rational Field """ return [self.base_category()] @@ -565,7 +571,7 @@ def extra_super_categories(self): [Category of finite sets] sage: Modules(ZZ).FiniteDimensional().extra_super_categories() [] - sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) + sage: Modules(GF(5)).FiniteDimensional().is_subcategory(Sets().Finite()) # optional - sage.rings.finite_rings True sage: Modules(ZZ).FiniteDimensional().is_subcategory(Sets().Finite()) False @@ -612,9 +618,9 @@ def linear_combination(self, iter_of_elements_coeff, factor_on_left=True): EXAMPLES:: - sage: m = matrix([[0,1],[1,1]]) - sage: J. = JordanAlgebra(m) - sage: J.linear_combination(((a+b, 1), (-2*b + c, -1))) + sage: m = matrix([[0,1], [1,1]]) # optional - sage.modules + sage: J. = JordanAlgebra(m) # optional - sage.combinat sage.modules + sage: J.linear_combination(((a+b, 1), (-2*b + c, -1))) # optional - sage.combinat sage.modules 1 + (3, -1) """ if factor_on_left: @@ -631,8 +637,8 @@ def tensor_square(self): EXAMPLES:: - sage: A = HopfAlgebrasWithBasis(QQ).example() - sage: A.tensor_square() + sage: A = HopfAlgebrasWithBasis(QQ).example() # optional - sage.groups sage.modules + sage: A.tensor_square() # optional - sage.groups sage.modules An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field # An example @@ -661,12 +667,14 @@ def module_morphism(self, *, function, category=None, codomain, **keywords): EXAMPLES:: - sage: V = FiniteRankFreeModule(QQ, 2) - sage: e = V.basis('e'); e - Basis (e_0,e_1) on the 2-dimensional vector space over the Rational Field - sage: neg = V.module_morphism(function=operator.neg, codomain=V); neg - Generic endomorphism of 2-dimensional vector space over the Rational Field - sage: neg(e[0]) + sage: V = FiniteRankFreeModule(QQ, 2) # optional - sage.modules + sage: e = V.basis('e'); e # optional - sage.modules + Basis (e_0,e_1) on the + 2-dimensional vector space over the Rational Field + sage: neg = V.module_morphism(function=operator.neg, codomain=V); neg # optional - sage.modules + Generic endomorphism of + 2-dimensional vector space over the Rational Field + sage: neg(e[0]) # optional - sage.modules Element -e_0 of the 2-dimensional vector space over the Rational Field """ @@ -698,11 +706,12 @@ def quotient(self, submodule, check=True, **kwds): EXAMPLES:: - sage: C = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: TA = TensorAlgebra(C) - sage: TA.quotient + sage: C = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: TA = TensorAlgebra(C) # optional - sage.modules + sage: TA.quotient # optional - sage.modules + Tensor Algebra of Free module generated by {'a', 'b', 'c'} + over Rational Field> """ return self.quotient_module(submodule, check=check, **kwds) @@ -748,21 +757,21 @@ def base_ring(self): EXAMPLES:: - 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 This ``base_ring`` method is actually overridden by :meth:`sage.structure.category_object.CategoryObject.base_ring`:: - sage: H.base_ring.__module__ + sage: H.base_ring.__module__ # optional - sage.modules Here we call it directly:: - sage: method = H.category().parent_class.base_ring - sage: method.__get__(H)() + sage: method = H.category().parent_class.base_ring # optional - sage.modules + sage: method.__get__(H)() # optional - sage.modules Integer Ring """ return self.domain().base_ring() @@ -772,24 +781,24 @@ def zero(self): """ EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) - sage: H = Hom(E, F) - sage: f = H.zero() - sage: f + 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: f = H.zero() # optional - sage.modules + sage: f # optional - sage.modules Generic morphism: From: Free module generated by {1, 2, 3} over Integer Ring To: Free module generated by {2, 3, 4} over Integer Ring - sage: f(E.monomial(2)) + sage: f(E.monomial(2)) # optional - sage.modules 0 - sage: f(E.monomial(3)) == F.zero() + sage: f(E.monomial(3)) == F.zero() # optional - sage.modules True TESTS: We check that ``H.zero()`` is picklable:: - sage: loads(dumps(f.parent().zero())) + sage: loads(dumps(f.parent().zero())) # optional - sage.modules Generic morphism: From: Free module generated by {1, 2, 3} over Integer Ring To: Free module generated by {2, 3, 4} over Integer Ring @@ -813,7 +822,7 @@ def extra_super_categories(self): sage: Modules(ZZ).Endsets().extra_super_categories() [Category of magmatic algebras over Integer Ring] - sage: End(ZZ^3) in Algebras(ZZ) + sage: End(ZZ^3) in Algebras(ZZ) # optional - sage.modules True """ from .magmatic_algebras import MagmaticAlgebras @@ -852,38 +861,46 @@ def __init_extra__(self): EXAMPLES:: - sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) - sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) - sage: C = cartesian_product([E, F]); C + sage: E = CombinatorialFreeModule(ZZ, [1,2,3]) # optional - sage.modules + sage: F = CombinatorialFreeModule(ZZ, [2,3,4]) # optional - sage.modules + sage: C = cartesian_product([E, F]); C # optional - sage.modules Free module generated by {1, 2, 3} over Integer Ring (+) Free module generated by {2, 3, 4} over Integer Ring - sage: C.base_ring() + sage: C.base_ring() # optional - sage.modules Integer Ring Check that :trac:`29225` is fixed:: - sage: M = cartesian_product((ZZ^2, ZZ^3)); M - The Cartesian product of (Ambient free module of rank 2 over the principal ideal domain Integer Ring, Ambient free module of rank 3 over the principal ideal domain Integer Ring) - sage: M.category() - Category of Cartesian products of modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) - sage: M.base_ring() + sage: M = cartesian_product((ZZ^2, ZZ^3)); M # optional - sage.modules + The Cartesian product of + (Ambient free module of rank 2 over the principal ideal domain Integer Ring, + Ambient free module of rank 3 over the principal ideal domain Integer Ring) + sage: M.category() # optional - sage.modules + Category of Cartesian products of modules with basis + over (euclidean domains and infinite enumerated sets and metric spaces) + sage: M.base_ring() # optional - sage.modules Integer Ring - sage: A = cartesian_product((QQ^2, QQ['x'])); A - The Cartesian product of (Vector space of dimension 2 over Rational Field, Univariate Polynomial Ring in x over Rational Field) - sage: A.category() - Category of Cartesian products of vector spaces over (number fields and quotient fields and metric spaces) - sage: A.base_ring() + sage: A = cartesian_product((QQ^2, QQ['x'])); A # optional - sage.modules + The Cartesian product of + (Vector space of dimension 2 over Rational Field, + Univariate Polynomial Ring in x over Rational Field) + sage: A.category() # optional - sage.modules + Category of Cartesian products of vector spaces + over (number fields and quotient fields and metric spaces) + sage: A.base_ring() # optional - sage.modules Rational Field This currently only works if all factors have the same base ring:: - sage: B = cartesian_product((ZZ['x'], QQ^3)); B - The Cartesian product of (Univariate Polynomial Ring in x over Integer Ring, Vector space of dimension 3 over Rational Field) - sage: B.category() + sage: B = cartesian_product((ZZ['x'], QQ^3)); B # optional - sage.modules + The Cartesian product of + (Univariate Polynomial Ring in x over Integer Ring, + Vector space of dimension 3 over Rational Field) + sage: B.category() # optional - sage.modules Category of Cartesian products of commutative additive groups - sage: B.base_ring() + sage: B.base_ring() # optional - sage.modules """ factors = self._sets if factors: @@ -899,10 +916,12 @@ def _lmul_(self, x): EXAMPLES:: - sage: A = FreeModule(ZZ, 2) - sage: B = cartesian_product([A, A]); B - The Cartesian product of (Ambient free module of rank 2 over the principal ideal domain Integer Ring, Ambient free module of rank 2 over the principal ideal domain Integer Ring) - sage: 5*B(([1, 2], [3, 4])) + sage: A = FreeModule(ZZ, 2) # optional - sage.modules + sage: B = cartesian_product([A, A]); B # optional - sage.modules + The Cartesian product of + (Ambient free module of rank 2 over the principal ideal domain Integer Ring, + Ambient free module of rank 2 over the principal ideal domain Integer Ring) + sage: 5*B(([1, 2], [3, 4])) # optional - sage.modules ((5, 10), (15, 20)) """ return self.parent()._cartesian_product_of_elements( @@ -934,9 +953,9 @@ def construction(self): EXAMPLES:: - sage: A = algebras.Free(QQ,2) - sage: T = A.tensor(A) - sage: T.construction() + sage: A = algebras.Free(QQ, 2) # optional - sage.combinat sage.modules + sage: T = A.tensor(A) # optional - sage.combinat sage.modules + sage: T.construction() # optional - sage.combinat sage.modules (The tensor functorial construction, (Free Algebra on 2 generators (None0, None1) over Rational Field, Free Algebra on 2 generators (None0, None1) over Rational Field)) @@ -957,20 +976,20 @@ def tensor_factors(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [1,2]) - sage: F.rename("F") - sage: G = CombinatorialFreeModule(ZZ, [3,4]) - sage: G.rename("G") - sage: T = tensor([F, G]); T + sage: F = CombinatorialFreeModule(ZZ, [1,2]) # optional - sage.modules + sage: F.rename("F") # optional - sage.modules + sage: G = CombinatorialFreeModule(ZZ, [3,4]) # optional - sage.modules + sage: G.rename("G") # optional - sage.modules + sage: T = tensor([F, G]); T # optional - sage.modules F # G - sage: T.tensor_factors() + sage: T.tensor_factors() # optional - sage.modules (F, G) TESTS:: - sage: M = CombinatorialFreeModule(ZZ, ((1, 1), (1, 2), (2, 1), (2, 2)), - ....: category=ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts()) - sage: M.construction() + sage: Cat = ModulesWithBasis(ZZ).FiniteDimensional().TensorProducts() # optional - sage.modules + sage: M = CombinatorialFreeModule(ZZ, ((1, 1), (1, 2), (2, 1), (2, 2)), category=Cat) # optional - sage.modules + sage: M.construction() # optional - sage.modules doctest:warning... DeprecationWarning: implementations of Modules().TensorProducts() now must define the method tensor_factors See https://github.com/sagemath/sage/issues/34393 for details. diff --git a/src/sage/categories/modules_with_basis.py b/src/sage/categories/modules_with_basis.py index 99b57ff8c8e..e16eaaefbe9 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -66,22 +66,23 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): Let `X` and `Y` be two modules with basis. We can build `Hom(X,Y)`:: - sage: X = CombinatorialFreeModule(QQ, [1,2]); X.__custom_name = "X" - sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y.__custom_name = "Y" - sage: H = Hom(X, Y); H - Set of Morphisms from X to Y in Category of finite dimensional vector spaces with basis over Rational Field + sage: X = CombinatorialFreeModule(QQ, [1,2]); X.__custom_name = "X" # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y.__custom_name = "Y" # optional - sage.modules + sage: H = Hom(X, Y); H # optional - sage.modules + Set of Morphisms from X to Y + in Category of finite dimensional vector spaces with basis over Rational Field The simplest morphism is the zero map:: - sage: H.zero() # todo: move this test into module once we have an example + sage: H.zero() # todo: move this test into module once we have an example # optional - sage.modules Generic morphism: From: X To: Y which we can apply to elements of `X`:: - sage: x = X.monomial(1) + 3 * X.monomial(2) - sage: H.zero()(x) + sage: x = X.monomial(1) + 3 * X.monomial(2) # optional - sage.modules + sage: H.zero()(x) # optional - sage.modules 0 EXAMPLES: @@ -89,17 +90,17 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): We now construct a more interesting morphism by extending a function by linearity:: - sage: phi = H(on_basis = lambda i: Y.monomial(i+2)); phi + sage: phi = H(on_basis=lambda i: Y.monomial(i + 2)); phi # optional - sage.modules Generic morphism: From: X To: Y - sage: phi(x) + sage: phi(x) # optional - sage.modules B[3] + 3*B[4] We can retrieve the function acting on indices of the basis:: - sage: f = phi.on_basis() - sage: f(1), f(2) + sage: f = phi.on_basis() # optional - sage.modules + sage: f(1), f(2) # optional - sage.modules (B[3], B[4]) `Hom(X,Y)` has a natural module structure (except for the zero, @@ -108,14 +109,14 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): basis; but see :class:`FiniteDimensionalModulesWithBasis` and :class:`GradedModulesWithBasis`:: - sage: H in ModulesWithBasis(QQ), H in Modules(QQ) + sage: H in ModulesWithBasis(QQ), H in Modules(QQ) # optional - sage.modules (False, True) Some more playing around with categories and higher order homsets:: - sage: H.category() + sage: H.category() # optional - sage.modules Category of homsets of modules with basis over Rational Field - sage: Hom(H, H).category() + sage: Hom(H, H).category() # optional - sage.modules Category of endsets of homsets of modules with basis over Rational Field .. TODO:: ``End(X)`` is an algebra. @@ -128,10 +129,10 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): TESTS:: - sage: f = H.zero().on_basis() - sage: f(1) + sage: f = H.zero().on_basis() # optional - sage.modules + sage: f(1) # optional - sage.modules 0 - sage: f(2) + sage: f(2) # optional - sage.modules 0 sage: TestSuite(ModulesWithBasis(ZZ)).run() @@ -151,20 +152,20 @@ def _call_(self, x): ``x`` is returned unchanged if it is already in this category:: - sage: CZ(CombinatorialFreeModule(ZZ, ('a','b','c'))) + sage: CZ(CombinatorialFreeModule(ZZ, ('a', 'b', 'c'))) # optional - sage.modules Free module generated by {'a', 'b', 'c'} over Integer Ring - sage: CZ(ZZ^3) + sage: CZ(ZZ^3) # optional - sage.modules Ambient free module of rank 3 over the principal ideal domain Integer Ring If needed (and possible) the base ring is changed appropriately:: - sage: CQ(ZZ^3) # indirect doctest + sage: CQ(ZZ^3) # indirect doctest # optional - sage.modules Vector space of dimension 3 over Rational Field 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 + sage: CQ(AbelianVariety(Gamma0(37))) # indirect doctest # optional - sage.modules Vector space of dimension 4 over Rational Field """ try: @@ -209,14 +210,14 @@ def basis(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: F.basis() + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.basis() # optional - sage.modules Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']} :: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: list(QS3.basis()) + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.group sage.modules + sage: list(QS3.basis()) # optional - sage.group sage.modules [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ from sage.sets.family import Family @@ -297,14 +298,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") - sage: phi = X.module_morphism(lambda i: Y.monomial(i) + 2*Y.monomial(i+1), codomain = Y) - sage: x = X.basis(); y = Y.basis() - sage: phi(x[1] + x[3]) + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules + sage: def f(i): + ....: return Y.monomial(i) + 2*Y.monomial(i+1) + sage: phi = X.module_morphism(f, codomain=Y) # optional - sage.modules + sage: x = X.basis(); y = Y.basis() # optional - sage.modules + sage: phi(x[1] + x[3]) # optional - sage.modules B[1] + 2*B[2] + B[3] + 2*B[4] - sage: phi + sage: phi # optional - sage.modules Generic morphism: From: X To: Y @@ -315,101 +318,105 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, ``CommutativeAdditiveMonoids()`` that contains both the domain and the codomain:: - sage: phi.category_for() - Category of finite dimensional vector spaces with basis over Rational Field + sage: phi.category_for() # optional - sage.modules + Category of finite dimensional vector spaces with basis + over Rational Field With the ``zero`` argument, one can define affine morphisms:: - sage: phi = X.module_morphism(lambda i: Y.monomial(i) + 2*Y.monomial(i+1), - ....: codomain = Y, zero = 10*y[1]) - sage: phi(x[1] + x[3]) + sage: def f(i): + ....: return Y.monomial(i) + 2*Y.monomial(i+1) + sage: phi = X.module_morphism(f, codomain=Y, zero=10*y[1]) # optional - sage.modules + sage: phi(x[1] + x[3]) # optional - sage.modules 11*B[1] + 2*B[2] + B[3] + 2*B[4] In this special case, the default category is ``Sets()``:: - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of sets One can construct morphisms with the base ring as codomain:: - sage: X = CombinatorialFreeModule(ZZ,[1,-1]) - sage: phi = X.module_morphism( on_basis=lambda i: i, codomain=ZZ ) - sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) ) + sage: X = CombinatorialFreeModule(ZZ, [1, -1]) # optional - sage.modules + sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=ZZ) # optional - sage.modules + sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # optional - sage.modules -1 - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (ZZ is currently not in Modules(ZZ)) + sage: phi.category_for() # todo: not implemented (ZZ is currently not in Modules(ZZ)) # optional - sage.modules Category of modules over Integer Ring Or more generally any ring admitting a coercion map from the base ring:: - sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=RR ) - sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) ) + sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=RR) # optional - sage.modules + sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # optional - sage.modules -1.00000000000000 - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (RR is currently not in Modules(ZZ)) + sage: phi.category_for() # todo: not implemented (RR is currently not in Modules(ZZ)) # optional - sage.modules Category of modules over Integer Ring - sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=Zmod(4) ) - sage: phi( 2 * X.monomial(1) + 3 * X.monomial(-1) ) + sage: phi = X.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # optional - sage.modules + sage: phi(2 * X.monomial(1) + 3 * X.monomial(-1)) # optional - sage.modules 3 - sage: phi = Y.module_morphism(on_basis=lambda i: i, codomain=Zmod(4) ) + sage: phi = Y.module_morphism(on_basis=lambda i: i, codomain=Zmod(4)) # optional - sage.modules Traceback (most recent call last): ... - ValueError: codomain(=Ring of integers modulo 4) should be a module over the base ring of the domain(=Y) + ValueError: codomain(=Ring of integers modulo 4) should be a module + over the base ring of the domain(=Y) On can also define module morphisms between free modules over different base rings; here we implement the natural map from `X = \RR^2` to `Y = \CC`:: - sage: X = CombinatorialFreeModule(RR,['x','y']) - sage: Y = CombinatorialFreeModule(CC,['z']) - sage: x = X.monomial('x') - sage: y = X.monomial('y') - sage: z = Y.monomial('z') - sage: def on_basis( a ): + sage: X = CombinatorialFreeModule(RR, ['x', 'y']) # optional - sage.modules + sage: Y = CombinatorialFreeModule(CC, ['z']) # optional - sage.modules + sage: x = X.monomial('x') # optional - sage.modules + sage: y = X.monomial('y') # optional - sage.modules + sage: z = Y.monomial('z') # optional - sage.modules + sage: def on_basis(a): # optional - sage.modules ....: if a == 'x': ....: return CC(1) * z ....: elif a == 'y': ....: return CC(I) * z - sage: phi = X.module_morphism( on_basis=on_basis, codomain=Y ) - sage: v = 3 * x + 2 * y; v + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules + sage: v = 3 * x + 2 * y; v # optional - sage.modules 3.00000000000000*B['x'] + 2.00000000000000*B['y'] - sage: phi(v) + sage: phi(v) # optional - sage.modules (3.00000000000000+2.00000000000000*I)*B['z'] - sage: phi.category_for() + sage: phi.category_for() # optional - sage.modules Category of commutative additive semigroups - sage: phi.category_for() # todo: not implemented (CC is currently not in Modules(RR)!) + sage: phi.category_for() # todo: not implemented (CC is currently not in Modules(RR)!) # optional - sage.modules Category of vector spaces over Real Field with 53 bits of precision - sage: Y = CombinatorialFreeModule(CC['q'],['z']) - sage: z = Y.monomial('z') - sage: phi = X.module_morphism( on_basis=on_basis, codomain=Y ) - sage: phi(v) + sage: Y = CombinatorialFreeModule(CC['q'], ['z']) # optional - sage.modules + sage: z = Y.monomial('z') # optional - sage.modules + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules + sage: phi(v) # optional - sage.modules (3.00000000000000+2.00000000000000*I)*B['z'] Of course, there should be a coercion between the respective base rings of the domain and the codomain for this to be meaningful:: - sage: Y = CombinatorialFreeModule(QQ,['z']) - sage: phi = X.module_morphism( on_basis=on_basis, codomain=Y ) + sage: Y = CombinatorialFreeModule(QQ, ['z']) # optional - sage.modules + sage: phi = X.module_morphism(on_basis=on_basis, codomain=Y) # optional - sage.modules Traceback (most recent call last): ... ValueError: codomain(=Free module generated by {'z'} over Rational Field) - should be a module over the base ring of the - domain(=Free module generated by {'x', 'y'} over Real Field with 53 bits of precision) + should be a module over the base ring of the domain(=Free module + generated by {'x', 'y'} over Real Field with 53 bits of precision) - sage: Y = CombinatorialFreeModule(RR['q'],['z']) - sage: phi = Y.module_morphism( on_basis=on_basis, codomain=X ) + sage: Y = CombinatorialFreeModule(RR['q'], ['z']) # optional - sage.modules + sage: phi = Y.module_morphism(on_basis=on_basis, codomain=X) # optional - sage.modules Traceback (most recent call last): ... - ValueError: codomain(=Free module generated by {'x', 'y'} over Real Field with 53 bits of precision) - should be a module over the base ring of the - domain(=Free module generated by {'z'} over Univariate Polynomial Ring in q over Real Field with 53 bits of precision) + ValueError: codomain(=Free module generated by {'x', 'y'} + over Real Field with 53 bits of precision) should be a module over + the base ring of the domain(=Free module generated by {'z'} over + Univariate Polynomial Ring in q over Real Field with 53 bits of precision) With the ``diagonal=d`` argument, this constructs the @@ -422,11 +429,11 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, This assumes that the respective bases `x` and `y` of `X` and `Y` have the same index set `I`:: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: from sage.arith.misc import factorial - sage: phi = X.module_morphism(diagonal=factorial, codomain=X) - sage: x = X.basis() - sage: phi(x[1]), phi(x[2]), phi(x[3]) + sage: X = CombinatorialFreeModule(ZZ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: from sage.arith.misc import factorial # optional - sage.modules + sage: phi = X.module_morphism(diagonal=factorial, codomain=X) # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: phi(x[1]), phi(x[2]), phi(x[3]) # optional - sage.modules (B[1], 2*B[2], 6*B[3]) See also: :class:`sage.modules.with_basis.morphism.DiagonalModuleMorphism`. @@ -435,13 +442,15 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, morphism whose matrix in the distinguished basis of `X` and `Y` is `m`:: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X"); x = X.basis() - sage: Y = CombinatorialFreeModule(ZZ, [3,4]); Y.rename("Y"); y = Y.basis() - sage: m = matrix([[0,1,2],[3,5,0]]) - sage: phi = X.module_morphism(matrix=m, codomain=Y) - sage: phi(x[1]) + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: Y = CombinatorialFreeModule(ZZ, [3,4]); Y.rename("Y") # optional - sage.modules + sage: y = Y.basis() # optional - sage.modules + sage: m = matrix([[0,1,2], [3,5,0]]) # optional - sage.modules + sage: phi = X.module_morphism(matrix=m, codomain=Y) # optional - sage.modules + sage: phi(x[1]) # optional - sage.modules 3*B[4] - sage: phi(x[2]) + sage: phi(x[2]) # optional - sage.modules B[3] + 5*B[4] @@ -454,35 +463,36 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, preimages and to invert the morphism:: sage: I = list(range(1, 200)) - sage: X = CombinatorialFreeModule(QQ, I); X.rename("X"); x = X.basis() - sage: Y = CombinatorialFreeModule(QQ, I); Y.rename("Y"); y = Y.basis() - sage: f = Y.sum_of_monomials * divisors - sage: phi = X.module_morphism(f, triangular="upper", codomain = Y) - sage: phi(x[2]) + sage: X = CombinatorialFreeModule(QQ, I); X.rename("X"); x = X.basis() # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, I); Y.rename("Y"); y = Y.basis() # optional - sage.modules + sage: f = Y.sum_of_monomials * divisors # optional - sage.modules + sage: phi = X.module_morphism(f, triangular="upper", codomain=Y) # optional - sage.modules + sage: phi(x[2]) # optional - sage.modules B[1] + B[2] - sage: phi(x[6]) + sage: phi(x[6]) # optional - sage.modules B[1] + B[2] + B[3] + B[6] - sage: phi(x[30]) + sage: phi(x[30]) # optional - sage.modules B[1] + B[2] + B[3] + B[5] + B[6] + B[10] + B[15] + B[30] - sage: phi.preimage(y[2]) + sage: phi.preimage(y[2]) # optional - sage.modules -B[1] + B[2] - sage: phi.preimage(y[6]) + sage: phi.preimage(y[6]) # optional - sage.modules B[1] - B[2] - B[3] + B[6] - sage: phi.preimage(y[30]) + sage: phi.preimage(y[30]) # optional - sage.modules -B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30] - sage: (phi^-1)(y[30]) + sage: (phi^-1)(y[30]) # optional - sage.modules -B[1] + B[2] + B[3] + B[5] - B[6] - B[10] - B[15] + B[30] Since :trac:`8678`, one can also define a triangular morphism from a function:: - sage: X = CombinatorialFreeModule(QQ, [0,1,2,3,4]); x = X.basis() - sage: from sage.modules.with_basis.morphism import TriangularModuleMorphismFromFunction - sage: def f(x): return x + X.term(0, sum(x.coefficients())) - sage: phi = X.module_morphism(function=f, codomain=X, triangular="upper") - sage: phi(x[2] + 3*x[4]) + sage: X = CombinatorialFreeModule(QQ, [0,1,2,3,4]); x = X.basis() # optional - sage.modules + sage: from sage.modules.with_basis.morphism import TriangularModuleMorphismFromFunction # optional - sage.modules + sage: def f(x): return x + X.term(0, sum(x.coefficients())) # optional - sage.modules + sage: phi = X.module_morphism(function=f, codomain=X, # optional - sage.modules + ....: triangular="upper") + sage: phi(x[2] + 3*x[4]) # optional - sage.modules 4*B[0] + B[2] + 3*B[4] - sage: phi.preimage(_) + sage: phi.preimage(_) # optional - sage.modules B[2] + 3*B[4] For details and further optional arguments, see @@ -505,8 +515,8 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, TESTS:: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(codomain=X) + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: phi = X.module_morphism(codomain=X) # optional - sage.modules Traceback (most recent call last): ... ValueError: module_morphism() takes exactly one option @@ -514,8 +524,8 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(diagonal=factorial, matrix=matrix(), codomain=X) + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: phi = X.module_morphism(diagonal=factorial, matrix=matrix(), codomain=X) # optional - sage.modules Traceback (most recent call last): ... ValueError: module_morphism() takes exactly one option @@ -523,16 +533,16 @@ def module_morphism(self, on_basis=None, matrix=None, function=None, :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(matrix=factorial, codomain=X) + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: phi = X.module_morphism(matrix=factorial, codomain=X) # optional - sage.modules Traceback (most recent call last): ... ValueError: matrix (=...factorial...) should be a matrix :: - sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") - sage: phi = X.module_morphism(diagonal=3, codomain=X) + sage: X = CombinatorialFreeModule(ZZ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: phi = X.module_morphism(diagonal=3, codomain=X) # optional - sage.modules Traceback (most recent call last): ... ValueError: diagonal (=3) should be a function @@ -571,20 +581,20 @@ def _repr_(self): """ EXAMPLES:: - sage: class FooBar(CombinatorialFreeModule): pass - sage: C = FooBar(QQ, (1,2,3)); C # indirect doctest + sage: class FooBar(CombinatorialFreeModule): pass # optional - sage.modules + sage: C = FooBar(QQ, (1,2,3)); C # indirect doctest # optional - sage.modules Free module generated by {1, 2, 3} over Rational Field - sage: C._name = "foobar"; C + sage: C._name = "foobar"; C # optional - sage.modules foobar over Rational Field - sage: C.rename("barfoo"); C + sage: C.rename("barfoo"); C # optional - sage.modules barfoo sage: class FooBar(Parent): - ....: def basis(self): return Family({1:"foo", 2:"bar"}) + ....: def basis(self): return Family({1: "foo", 2: "bar"}) ....: def base_ring(self): return QQ - sage: FooBar(category = ModulesWithBasis(QQ)) + sage: FooBar(category=ModulesWithBasis(QQ)) Free module generated by [1, 2] over Rational Field """ if hasattr(self, "_name"): @@ -608,26 +618,26 @@ def _compute_support_order(self, elements, support_order=None): A finite dimensional module:: - sage: V = CombinatorialFreeModule(QQ, range(10), prefix='x') - sage: B = V.basis() - sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], B[2], B[3], B[1] + B[2] + B[8]] - sage: V._compute_support_order(elts) + sage: V = CombinatorialFreeModule(QQ, range(10), prefix='x') # optional - sage.modules + sage: B = V.basis() # optional - sage.modules + sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], B[2], B[3], B[1] + B[2] + B[8]] # optional - sage.modules + sage: V._compute_support_order(elts) # optional - sage.modules (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) + sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) # optional - sage.modules (1, 2, 0, 4, 3, 5, 9, 8, 7, 6) - sage: V._compute_support_order(elts, lambda x: -x) + sage: V._compute_support_order(elts, lambda x: -x) # optional - sage.modules (8, 5, 3, 2, 1, 0) An infinite dimensional module:: - sage: V = CombinatorialFreeModule(QQ, ZZ, prefix='z') - sage: B = V.basis() - sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], B[2], B[3], B[1] + B[2] + B[8]] - sage: V._compute_support_order(elts) + sage: V = CombinatorialFreeModule(QQ, ZZ, prefix='z') # optional - sage.modules + sage: B = V.basis() # optional - sage.modules + sage: elts = [B[0] - 2*B[3], B[5] + 2*B[0], B[2], B[3], B[1] + B[2] + B[8]] # optional - sage.modules + sage: V._compute_support_order(elts) # optional - sage.modules (0, 1, 2, 3, 5, 8) - sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) + sage: V._compute_support_order(elts, [1,2,0,4,3,5,9,8,7,6]) # optional - sage.modules (1, 2, 0, 4, 3, 5, 9, 8, 7, 6) - sage: V._compute_support_order(elts, lambda x: -x) + sage: V._compute_support_order(elts, lambda x: -x) # optional - sage.modules (8, 5, 3, 2, 1, 0) """ if support_order is None: @@ -672,17 +682,17 @@ def echelon_form(self, elements, row_reduced=False, order=None): EXAMPLES:: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, ZZ, prefix='z') - sage: z = C.basis() - sage: C.echelon_form([z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]]) + sage: C = CombinatorialFreeModule(R, ZZ, prefix='z') # optional - sage.modules + sage: z = C.basis() # optional - sage.modules + sage: C.echelon_form([z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]]) # optional - sage.modules [z[0] - z[2], z[1] - z[2]] TESTS: We convert the input elements to ``self``:: - sage: s = SymmetricFunctions(QQ).s() - sage: s.echelon_form([1, s[1] + 5]) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat sage.modules + sage: s.echelon_form([1, s[1] + 5]) # optional - sage.combinat sage.modules [s[], s[1]] """ # Make sure elements consists of elements of ``self`` @@ -751,21 +761,21 @@ def submodule(self, gens, check=True, already_echelonized=False, `x_0, x_1, x_2`. The submodule is spanned by `y_0 = x_0 - x_1` and `y_1 - x_1 - x_2`, and its basis elements are indexed by `0` and `1`:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") - sage: x = X.basis() - sage: gens = [x[0] - x[1], x[1] - x[2]]; gens + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: gens = [x[0] - x[1], x[1] - x[2]]; gens # optional - sage.modules [x[0] - x[1], x[1] - x[2]] - sage: Y = X.submodule(gens, already_echelonized=True) - sage: Y.print_options(prefix='y'); Y + sage: Y = X.submodule(gens, already_echelonized=True) # optional - sage.modules + sage: Y.print_options(prefix='y'); Y # optional - sage.modules Free module generated by {0, 1} over Rational Field - sage: y = Y.basis() - sage: y[1] + sage: y = Y.basis() # optional - sage.modules + sage: y[1] # optional - sage.modules y[1] - sage: y[1].lift() + sage: y[1].lift() # optional - sage.modules x[1] - x[2] - sage: Y.retract(x[0]-x[2]) + sage: Y.retract(x[0] - x[2]) # optional - sage.modules y[0] + y[1] - sage: Y.retract(x[0]) + sage: Y.retract(x[0]) # optional - sage.modules Traceback (most recent call last): ... ValueError: x[0] is not in the image @@ -773,23 +783,23 @@ def submodule(self, gens, check=True, already_echelonized=False, By using a family to specify a basis of the submodule, we obtain a submodule whose index set coincides with the index set of the family:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") - sage: x = X.basis() - sage: gens = Family({1 : x[0] - x[1], 3: x[1] - x[2]}); gens + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: gens = Family({1: x[0] - x[1], 3: x[1] - x[2]}); gens # optional - sage.modules Finite family {1: x[0] - x[1], 3: x[1] - x[2]} - sage: Y = X.submodule(gens, already_echelonized=True) - sage: Y.print_options(prefix='y'); Y + sage: Y = X.submodule(gens, already_echelonized=True) # optional - sage.modules + sage: Y.print_options(prefix='y'); Y # optional - sage.modules Free module generated by {1, 3} over Rational Field - sage: y = Y.basis() - sage: y[1] + sage: y = Y.basis() # optional - sage.modules + sage: y[1] # optional - sage.modules y[1] - sage: y[1].lift() + sage: y[1].lift() # optional - sage.modules x[0] - x[1] - sage: y[3].lift() + sage: y[3].lift() # optional - sage.modules x[1] - x[2] - sage: Y.retract(x[0]-x[2]) + sage: Y.retract(x[0] - x[2]) # optional - sage.modules y[1] + y[3] - sage: Y.retract(x[0]) + sage: Y.retract(x[0]) # optional - sage.modules Traceback (most recent call last): ... ValueError: x[0] is not in the image @@ -797,55 +807,56 @@ def submodule(self, gens, check=True, already_echelonized=False, It is not necessary that the generators of the submodule form a basis (an explicit basis will be computed):: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") - sage: x = X.basis() - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]; gens + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]]; gens # optional - sage.modules [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] - sage: Y = X.submodule(gens, already_echelonized=False) - sage: Y.print_options(prefix='y') - sage: Y + sage: Y = X.submodule(gens, already_echelonized=False) # optional - sage.modules + sage: Y.print_options(prefix='y') # optional - sage.modules + sage: Y # optional - sage.modules Free module generated by {0, 1} over Rational Field - sage: [b.lift() for b in Y.basis()] + sage: [b.lift() for b in Y.basis()] # optional - sage.modules [x[0] - x[2], x[1] - x[2]] We now implement by hand the center of the algebra of the symmetric group `S_3`:: - sage: S3 = SymmetricGroup(3) - sage: S3A = S3.algebra(QQ) - sage: basis = S3A.annihilator_basis(S3A.algebra_generators(), S3A.bracket) - sage: basis + sage: S3 = SymmetricGroup(3) # optional - sage.groups sage.modules + sage: S3A = S3.algebra(QQ) # optional - sage.groups sage.modules + sage: basis = S3A.annihilator_basis(S3A.algebra_generators(), # optional - sage.groups sage.modules + ....: S3A.bracket) + sage: basis # optional - sage.groups sage.modules ((), (1,2,3) + (1,3,2), (2,3) + (1,2) + (1,3)) - sage: center = S3A.submodule(basis, - ....: category=AlgebrasWithBasis(QQ).Subobjects(), - ....: already_echelonized=True) - sage: center + sage: center = S3A.submodule(basis, # optional - sage.groups sage.modules + ....: category=AlgebrasWithBasis(QQ).Subobjects(), + ....: already_echelonized=True) + sage: center # optional - sage.groups sage.modules Free module generated by {0, 1, 2} over Rational Field - sage: center in Algebras + sage: center in Algebras # optional - sage.groups sage.modules True - sage: center.print_options(prefix='c') - sage: c = center.basis() - sage: c[1].lift() + sage: center.print_options(prefix='c') # optional - sage.groups sage.modules + sage: c = center.basis() # optional - sage.groups sage.modules + sage: c[1].lift() # optional - sage.groups sage.modules (1,2,3) + (1,3,2) - sage: c[0]^2 + sage: c[0]^2 # optional - sage.groups sage.modules c[0] - sage: e = 1/6*(c[0]+c[1]+c[2]) - sage: e.is_idempotent() + sage: e = 1/6 * (c[0]+c[1]+c[2]) # optional - sage.groups sage.modules + sage: e.is_idempotent() # optional - sage.groups sage.modules True Of course, this center is best constructed using:: - sage: center = S3A.center() + sage: center = S3A.center() # optional - sage.groups sage.modules We can also automatically construct a basis such that the lift morphism is (lower) unitriangular:: sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') - sage: x = C.basis() - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] - sage: Y = C.submodule(gens, unitriangular=True) - sage: Y.lift.matrix() + sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # optional - sage.modules + sage: x = C.basis() # optional - sage.modules + sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] # optional - sage.modules + sage: Y = C.submodule(gens, unitriangular=True) # optional - sage.modules + sage: Y.lift.matrix() # optional - sage.modules [ 1 0] [ 0 1] [-1 -1] @@ -853,17 +864,17 @@ def submodule(self, gens, check=True, already_echelonized=False, We now construct a (finite-dimensional) submodule of an infinite dimensional free module:: - sage: C = CombinatorialFreeModule(QQ, ZZ, prefix='z') - sage: z = C.basis() - sage: gens = [z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]] - sage: Y = C.submodule(gens) - sage: [Y.lift(b) for b in Y.basis()] + sage: C = CombinatorialFreeModule(QQ, ZZ, prefix='z') # optional - sage.modules + sage: z = C.basis() # optional - sage.modules + sage: gens = [z[0] - z[1], 2*z[1] - 2*z[2], z[0] - z[2]] # optional - sage.modules + sage: Y = C.submodule(gens) # optional - sage.modules + sage: [Y.lift(b) for b in Y.basis()] # optional - sage.modules [z[0] - z[2], z[1] - z[2]] TESTS:: - sage: TestSuite(Y).run() - sage: TestSuite(center).run() + sage: TestSuite(Y).run() # optional - sage.modules + sage: TestSuite(center).run() # optional - sage.groups sage.modules """ # Make sure gens consists of elements of ``self`` from sage.sets.family import Family, AbstractFamily @@ -906,24 +917,25 @@ def quotient_module(self, submodule, check=True, already_echelonized=False, cate EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") - sage: x = X.basis() - sage: Y = X.quotient_module([x[0]-x[1], x[1]-x[2]], already_echelonized=True) - sage: Y.print_options(prefix='y'); Y + sage: X = CombinatorialFreeModule(QQ, range(3), prefix="x") # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: Y = X.quotient_module([x[0] - x[1], x[1] - x[2]], # optional - sage.modules + ....: already_echelonized=True) + sage: Y.print_options(prefix='y'); Y # optional - sage.modules Free module generated by {2} over Rational Field - sage: y = Y.basis() - sage: y[2] + sage: y = Y.basis() # optional - sage.modules + sage: y[2] # optional - sage.modules y[2] - sage: y[2].lift() + sage: y[2].lift() # optional - sage.modules x[2] - sage: Y.retract(x[0]+2*x[1]) + sage: Y.retract(x[0] + 2*x[1]) # optional - sage.modules 3*y[2] sage: R. = QQ[] - sage: C = CombinatorialFreeModule(R, range(3), prefix='x') - sage: x = C.basis() - sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] - sage: Y = C.quotient_module(gens) + sage: C = CombinatorialFreeModule(R, range(3), prefix='x') # optional - sage.modules + sage: x = C.basis() # optional - sage.modules + sage: gens = [x[0] - x[1], 2*x[1] - 2*x[2], x[0] - x[2]] # optional - sage.modules + sage: Y = C.quotient_module(gens) # optional - sage.modules .. SEEALSO:: @@ -945,10 +957,10 @@ def tensor(*parents, **kwargs): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example(); A.rename("A") - sage: A.tensor(A,A) + sage: A = C.example(); A.rename("A") # optional - sage.combinat sage.modules + sage: A.tensor(A, A) # optional - sage.combinat sage.modules A # A # A - sage: A.rename(None) + sage: A.rename(None) # optional - sage.combinat sage.modules """ constructor = kwargs.pop('constructor', tensor) cat = constructor.category_from_parents(parents) @@ -960,24 +972,24 @@ def cardinality(self): EXAMPLES:: - sage: S = SymmetricGroupAlgebra(QQ, 4) - sage: S.cardinality() + sage: S = SymmetricGroupAlgebra(QQ, 4) # optional - sage.groups sage.modules + sage: S.cardinality() # optional - sage.groups sage.modules +Infinity - sage: S = SymmetricGroupAlgebra(GF(2), 4) # not tested -- MRO bug trac #15475 - sage: S.cardinality() # not tested -- MRO bug trac #15475 + sage: S = SymmetricGroupAlgebra(GF(2), 4) # not tested -- MRO bug trac #15475 # optional - sage.groups sage.libs.pari sage.modules + sage: S.cardinality() # not tested -- MRO bug trac #15475 # optional - sage.groups sage.libs.pari sage.modules 16777216 - sage: S.cardinality().factor() # not tested -- MRO bug trac #15475 + sage: S.cardinality().factor() # not tested -- MRO bug trac #15475 # optional - sage.groups sage.libs.pari sage.modules 2^24 - sage: E. = ExteriorAlgebra(QQ) - sage: E.cardinality() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: E.cardinality() # optional - sage.combinat sage.modules +Infinity - sage: E. = ExteriorAlgebra(GF(3)) - sage: E.cardinality() + sage: E. = ExteriorAlgebra(GF(3)) # optional - sage.combinat sage.libs.pari sage.modules + sage: E.cardinality() # optional - sage.combinat sage.libs.pari sage.modules 81 - sage: s = SymmetricFunctions(GF(2)).s() - sage: s.cardinality() + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.combinat sage.libs.pari sage.modules + sage: s.cardinality() # optional - sage.combinat sage.libs.pari sage.modules +Infinity """ from sage.rings.infinity import Infinity @@ -994,11 +1006,11 @@ def is_finite(self): EXAMPLES:: - sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() + sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() # optional - sage.groups sage.modules True - sage: GroupAlgebra(SymmetricGroup(2)).is_finite() + sage: GroupAlgebra(SymmetricGroup(2)).is_finite() # optional - sage.groups sage.modules False - sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() + sage: GroupAlgebra(AbelianGroup(1), IntegerModRing(10)).is_finite() # optional - sage.groups sage.modules False """ return (self.base_ring().is_finite() and self.group().is_finite()) @@ -1013,14 +1025,15 @@ def monomial(self, i): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.monomial('a') + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.monomial('a') # optional - sage.modules B['a'] ``F.monomial`` is in fact (almost) a map:: - sage: F.monomial - Term map from {'a', 'b', 'c'} to Free module generated by {'a', 'b', 'c'} over Rational Field + sage: F.monomial # optional - sage.modules + Term map from {'a', 'b', 'c'} + to Free module generated by {'a', 'b', 'c'} over Rational Field """ return self.basis()[i] @@ -1029,8 +1042,8 @@ def _sum_of_monomials(self, indices): TESTS:: sage: R. = QQ[] - sage: W = DifferentialWeylAlgebra(R) - sage: W._sum_of_monomials([((1,0), (1,0)), ((0,0), (0,1))]) + sage: W = DifferentialWeylAlgebra(R) # optional - sage.combinat sage.modules + sage: W._sum_of_monomials([((1,0), (1,0)), ((0,0), (0,1))]) # optional - sage.combinat sage.modules dy + x*dx """ # This is the generic implementation. When implementing a @@ -1051,16 +1064,16 @@ def sum_of_monomials(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.sum_of_monomials(['a', 'b']) + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.sum_of_monomials(['a', 'b']) # optional - sage.modules B['a'] + B['b'] - sage: F.sum_of_monomials(['a', 'b', 'a']) + sage: F.sum_of_monomials(['a', 'b', 'a']) # optional - sage.modules 2*B['a'] + B['b'] ``F.sum_of_monomials`` is in fact (almost) a map:: - sage: F.sum_of_monomials + sage: F.sum_of_monomials # optional - sage.modules A map to Free module generated by {'a', 'b', 'c'} over Rational Field """ # domain = iterables of basis indices of self. @@ -1070,10 +1083,10 @@ def monomial_or_zero_if_none(self, i): """ EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) - sage: F.monomial_or_zero_if_none('a') + sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # optional - sage.modules + sage: F.monomial_or_zero_if_none('a') # optional - sage.modules B['a'] - sage: F.monomial_or_zero_if_none(None) + sage: F.monomial_or_zero_if_none(None) # optional - sage.modules 0 """ if i is None: @@ -1095,9 +1108,9 @@ def term(self, index, coeff=None): EXAMPLES:: - sage: m = matrix([[0,1],[1,1]]) - sage: J. = JordanAlgebra(m) - sage: J.term(1, -2) + sage: m = matrix([[0,1], [1,1]]) # optional - sage.modules + sage: J. = JordanAlgebra(m) # optional - sage.combinat sage.modules + sage: J.term(1, -2) # optional - sage.combinat sage.modules 0 + (-2, 0) Design: should this do coercion on the coefficient ring? @@ -1121,9 +1134,9 @@ def sum_of_terms(self, terms): EXAMPLES:: - sage: m = matrix([[0,1],[1,1]]) - sage: J. = JordanAlgebra(m) - sage: J.sum_of_terms([(0, 2), (2, -3)]) + sage: m = matrix([[0,1], [1,1]]) # optional - sage.modules + sage: J. = JordanAlgebra(m) # optional - sage.combinat sage.modules + sage: J.sum_of_terms([(0, 2), (2, -3)]) # optional - sage.combinat sage.modules 2 + (0, -3) """ return self.sum(self.term(index, coeff) for (index, coeff) in terms) @@ -1150,21 +1163,21 @@ def _apply_module_morphism(self, x, on_basis, codomain=False): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([3]) + s([2,1]) + s([1,1,1]) - sage: b = 2*a - sage: f = lambda part: Integer( len(part) ) - sage: s._apply_module_morphism(a, f) #1+2+3 + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: a = s([3]) + s([2,1]) + s([1,1,1]) # optional - sage.combinat sage.modules + sage: b = 2*a # optional - sage.combinat sage.modules + sage: f = lambda part: Integer(len(part)) # optional - sage.combinat sage.modules + sage: s._apply_module_morphism(a, f) #1+2+3 # optional - sage.combinat sage.modules 6 - sage: s._apply_module_morphism(b, f) #2*(1+2+3) + sage: s._apply_module_morphism(b, f) #2*(1+2+3) # optional - sage.combinat sage.modules 12 - sage: s._apply_module_morphism(s(0), f) + sage: s._apply_module_morphism(s(0), f) # optional - sage.combinat sage.modules 0 - sage: s._apply_module_morphism(s(1), f) + sage: s._apply_module_morphism(s(1), f) # optional - sage.combinat sage.modules 0 - sage: s._apply_module_morphism(s(1), lambda part: len(part), ZZ) + sage: s._apply_module_morphism(s(1), lambda part: len(part), ZZ) # optional - sage.combinat sage.modules 0 - sage: s._apply_module_morphism(s(1), lambda part: len(part)) + sage: s._apply_module_morphism(s(1), lambda part: len(part)) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: codomain could not be determined @@ -1206,9 +1219,9 @@ def _apply_module_endomorphism(self, x, on_basis): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).schur() - sage: f = lambda part: 2*s(part.conjugate()) - sage: s._apply_module_endomorphism( s([2,1]) + s([1,1,1]), f) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = lambda part: 2 * s(part.conjugate()) # optional - sage.combinat sage.modules + sage: s._apply_module_endomorphism(s([2,1]) + s([1,1,1]), f) # optional - sage.combinat sage.modules 2*s[2, 1] + 2*s[3] """ mc = x.monomial_coefficients(copy=False) @@ -1221,8 +1234,8 @@ def dimension(self): EXAMPLES:: - sage: A. = algebras.DifferentialWeyl(QQ) - sage: A.dimension() + sage: A. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules + sage: A.dimension() # optional - sage.combinat sage.modules +Infinity """ try: @@ -1242,17 +1255,17 @@ def _from_dict(self, d, coerce=True, remove_zeros=True): EXAMPLES:: - sage: A. = algebras.DifferentialWeyl(QQ) - sage: K = A.basis().keys() - sage: d = {K[0]: 3, K[12]: -4/3} - sage: A._from_dict(d) + sage: A. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules + sage: K = A.basis().keys() # optional - sage.combinat sage.modules + sage: d = {K[0]: 3, K[12]: -4/3} # optional - sage.combinat sage.modules + sage: A._from_dict(d) # optional - sage.combinat sage.modules -4/3*dx^2 + 3 sage: R. = QQ[] - sage: d = {K[0]: y, K[12]: -4/3} - sage: A._from_dict(d, coerce=False) + sage: d = {K[0]: y, K[12]: -4/3} # optional - sage.combinat sage.modules + sage: A._from_dict(d, coerce=False) # optional - sage.combinat sage.modules -4/3*dx^2 + y - sage: A._from_dict(d, coerce=True) + sage: A._from_dict(d, coerce=True) # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: not a constant polynomial @@ -1291,21 +1304,21 @@ def random_element(self, n=2): EXAMPLES:: - sage: x = DihedralGroup(6).algebra(QQ).random_element() - sage: x.parent() is DihedralGroup(6).algebra(QQ) + sage: x = DihedralGroup(6).algebra(QQ).random_element() # optional - sage.groups sage.modules + sage: x.parent() is DihedralGroup(6).algebra(QQ) # optional - sage.groups sage.modules True Note, this result can depend on the PRNG state in libgap in a way that depends on which packages are loaded, so we must re-seed GAP to ensure a consistent result for this example:: - sage: libgap.set_seed(0) + sage: libgap.set_seed(0) # optional - sage.libs.gap 0 - sage: m = SU(2, 13).algebra(QQ).random_element(1) - sage: m.parent() is SU(2, 13).algebra(QQ) + sage: m = SU(2, 13).algebra(QQ).random_element(1) # optional - sage.groups sage.modules + sage: m.parent() is SU(2, 13).algebra(QQ) # optional - sage.groups sage.modules True - sage: p = CombinatorialFreeModule(ZZ, Partitions(4)).random_element() - sage: p.parent() is CombinatorialFreeModule(ZZ, Partitions(4)) + sage: p = CombinatorialFreeModule(ZZ, Partitions(4)).random_element() # optional - sage.combinat sage.modules + sage: p.parent() is CombinatorialFreeModule(ZZ, Partitions(4)) # optional - sage.combinat sage.modules True TESTS: @@ -1315,17 +1328,16 @@ def random_element(self, n=2): coerce the base ring's zero into the algebra, and that we can find a random element in a trivial module:: - sage: class Foo(CombinatorialFreeModule): + sage: class Foo(CombinatorialFreeModule): # optional - sage.modules ....: def _element_constructor_(self,x): ....: if x in self: ....: return x ....: else: ....: raise ValueError - sage: from sage.categories.magmatic_algebras \ - ....: import MagmaticAlgebras + sage: from sage.categories.magmatic_algebras import MagmaticAlgebras sage: C = MagmaticAlgebras(QQ).WithBasis().Unital() - sage: F = Foo(QQ, tuple(), category=C) - sage: F.random_element() == F.zero() + sage: F = Foo(QQ, tuple(), category=C) # optional - sage.modules + sage: F.random_element() == F.zero() # optional - sage.modules True """ @@ -1365,25 +1377,25 @@ def monomial_coefficients(self, copy=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] + 3*B['c'] - sage: d = f.monomial_coefficients() - sage: d['a'] + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] + 3*B['c'] # optional - sage.modules + sage: d = f.monomial_coefficients() # optional - sage.modules + sage: d['a'] # optional - sage.modules 1 - sage: d['c'] + sage: d['c'] # optional - sage.modules 3 TESTS: We check that we make a copy of the coefficient dictionary:: - sage: F = CombinatorialFreeModule(ZZ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] + 3*B['c'] - sage: d = f.monomial_coefficients() - sage: d['a'] = 5 - sage: f + sage: F = CombinatorialFreeModule(ZZ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] + 3*B['c'] # optional - sage.modules + sage: d = f.monomial_coefficients() # optional - sage.modules + sage: d['a'] = 5 # optional - sage.modules + sage: f # optional - sage.modules B['a'] + 3*B['c'] """ @@ -1393,10 +1405,10 @@ def __getitem__(self, m): EXAMPLES:: - sage: W. = DifferentialWeylAlgebra(QQ) - sage: x[((0,0,0),(0,0,0))] + sage: W. = DifferentialWeylAlgebra(QQ) # optional - sage.combinat sage.modules + sage: x[((0,0,0), (0,0,0))] # optional - sage.combinat sage.modules 0 - sage: x[((1,0,0),(0,0,0))] + sage: x[((1,0,0), (0,0,0))] # optional - sage.combinat sage.modules 1 """ res = self.monomial_coefficients(copy=False).get(m) @@ -1422,19 +1434,19 @@ def coefficient(self, m): EXAMPLES:: - sage: s = CombinatorialFreeModule(QQ, Partitions()) - sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) - sage: z.coefficient([4]) + sage: s = CombinatorialFreeModule(QQ, Partitions()) # optional - sage.combinat sage.modules + sage: z = s([4]) - 2*s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules + sage: z.coefficient([4]) # optional - sage.combinat sage.modules 1 - sage: z.coefficient([2,1]) + sage: z.coefficient([2,1]) # optional - sage.combinat sage.modules -2 - sage: z.coefficient(Partition([2,1])) + sage: z.coefficient(Partition([2,1])) # optional - sage.combinat sage.modules -2 - sage: z.coefficient([1,2]) + sage: z.coefficient([1,2]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [1, 2] should be an element of Partitions - sage: z.coefficient(Composition([2,1])) + sage: z.coefficient(Composition([2,1])) # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [2, 1] should be an element of Partitions @@ -1442,12 +1454,12 @@ def coefficient(self, m): Test that ``coefficient`` also works for those parents that do not have an ``element_class``:: - sage: H = pAdicWeightSpace(3) - sage: F = CombinatorialFreeModule(QQ, H) - sage: hasattr(H, "element_class") + sage: H = pAdicWeightSpace(3) # optional - sage.modules sage.rings.padics + sage: F = CombinatorialFreeModule(QQ, H) # optional - sage.modules sage.rings.padics + sage: hasattr(H, "element_class") # optional - sage.modules sage.rings.padics False - sage: h = H.an_element() - sage: (2*F.monomial(h)).coefficient(h) + sage: h = H.an_element() # optional - sage.modules sage.rings.padics + sage: (2*F.monomial(h)).coefficient(h) # optional - sage.modules sage.rings.padics 2 """ # NT: coefficient_fast should be the default, just with appropriate assertions @@ -1465,22 +1477,22 @@ def is_zero(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.is_zero() + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] - 3*B['c'] # optional - sage.modules + sage: f.is_zero() # optional - sage.modules False - sage: F.zero().is_zero() + sage: F.zero().is_zero() # optional - sage.modules True :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s([2,1]).is_zero() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: s([2,1]).is_zero() # optional - sage.combinat sage.modules False - sage: s(0).is_zero() + sage: s(0).is_zero() # optional - sage.combinat sage.modules True - sage: (s([2,1]) - s([2,1])).is_zero() + sage: (s([2,1]) - s([2,1])).is_zero() # optional - sage.combinat sage.modules True """ zero = self.parent().base_ring().zero() @@ -1493,17 +1505,17 @@ def __len__(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: len(f) + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] - 3*B['c'] # optional - sage.modules + sage: len(f) # optional - sage.modules 2 :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: len(z) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules + sage: len(z) # optional - sage.combinat sage.modules 4 """ return len(self.support()) @@ -1515,17 +1527,17 @@ def length(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.length() + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] - 3*B['c'] # optional - sage.modules + sage: f.length() # optional - sage.modules 2 :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: z.length() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules + sage: z.length() # optional - sage.combinat sage.modules 4 """ return len(self) @@ -1540,17 +1552,17 @@ def support(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: sorted(f.support()) + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] - 3*B['c'] # optional - sage.modules + sage: sorted(f.support()) # optional - sage.modules ['a', 'c'] :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: sorted(z.support()) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules + sage: sorted(z.support()) # optional - sage.combinat sage.modules [[1], [1, 1, 1], [2, 1], [4]] """ try: @@ -1578,13 +1590,13 @@ def monomials(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] + 2*B['c'] - sage: f.monomials() + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] + 2*B['c'] # optional - sage.modules + sage: f.monomials() # optional - sage.modules [B['a'], B['c']] - sage: (F.zero()).monomials() + sage: (F.zero()).monomials() # optional - sage.modules [] """ P = self.parent() @@ -1599,10 +1611,10 @@ def terms(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] + 2*B['c'] - sage: f.terms() + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] + 2*B['c'] # optional - sage.modules + sage: f.terms() # optional - sage.modules [B['a'], 2*B['c']] """ P = self.parent() @@ -1627,20 +1639,20 @@ def coefficients(self, sort=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.coefficients() + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] - 3*B['c'] # optional - sage.modules + sage: f.coefficients() # optional - sage.modules [1, -3] - sage: f = B['c'] - 3*B['a'] - sage: f.coefficients() + sage: f = B['c'] - 3*B['a'] # optional - sage.modules + sage: f.coefficients() # optional - sage.modules [-3, 1] :: - sage: s = SymmetricFunctions(QQ).schur() - sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) - sage: z.coefficients() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: z = s([4]) + s([2,1]) + s([1,1,1]) + s([1]) # optional - sage.combinat sage.modules + sage: z.coefficients() # optional - sage.combinat sage.modules [1, 1, 1, 1] """ zero = self.parent().base_ring().zero() @@ -1659,15 +1671,15 @@ def support_of_term(self): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") - sage: X.monomial(2).support_of_term() + sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") # optional - sage.modules + sage: X.monomial(2).support_of_term() # optional - sage.modules 2 - sage: X.term(3, 2).support_of_term() + sage: X.term(3, 2).support_of_term() # optional - sage.modules 3 An exception is raised if ``self`` has more than one term:: - sage: (X.monomial(2) + X.monomial(3)).support_of_term() + sage: (X.monomial(2) + X.monomial(3)).support_of_term() # optional - sage.modules Traceback (most recent call last): ... ValueError: B[2] + B[3] is not a single term @@ -1689,18 +1701,18 @@ def leading_support(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]) - sage: X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) - sage: x.leading_support() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]) # optional - sage.modules + sage: X.rename("X"); x = X.basis() # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # optional - sage.modules + sage: x.leading_support() # optional - sage.modules 3 - sage: def key(x): return -x - sage: x.leading_support(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_support(key=key) # optional - sage.modules 1 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_support() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.leading_support() # optional - sage.combinat sage.modules [3] """ return max(self.support(), *args, **kwds) @@ -1724,17 +1736,17 @@ def leading_item(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) - sage: x.leading_item() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # optional - sage.modules + sage: x.leading_item() # optional - sage.modules (3, 4) - sage: def key(x): return -x - sage: x.leading_item(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_item(key=key) # optional - sage.modules (1, 3) - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_item() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.leading_item() # optional - sage.combinat sage.modules ([3], -5) """ k = self.leading_support(*args, **kwds) @@ -1753,17 +1765,17 @@ def leading_monomial(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.leading_monomial() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.leading_monomial() # optional - sage.modules B[3] - sage: def key(x): return -x - sage: x.leading_monomial(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_monomial(key=key) # optional - sage.modules B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_monomial() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.leading_monomial() # optional - sage.combinat sage.modules s[3] """ return self.parent().monomial(self.leading_support(*args, **kwds)) @@ -1781,17 +1793,17 @@ def leading_coefficient(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.leading_coefficient() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.leading_coefficient() # optional - sage.modules 1 - sage: def key(x): return -x - sage: x.leading_coefficient(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_coefficient(key=key) # optional - sage.modules 3 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_coefficient() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.leading_coefficient() # optional - sage.combinat sage.modules -5 """ return self.leading_item(*args, **kwds)[1] @@ -1809,17 +1821,17 @@ def leading_term(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.leading_term() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.leading_term() # optional - sage.modules B[3] - sage: def key(x): return -x - sage: x.leading_term(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.leading_term(key=key) # optional - sage.modules 3*B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.leading_term() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.leading_term() # optional - sage.combinat sage.modules -5*s[3] """ return self.parent().term(*self.leading_item(*args, **kwds)) @@ -1835,18 +1847,18 @@ def trailing_support(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) - sage: x.trailing_support() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + 4*X.monomial(3) # optional - sage.modules + sage: x.trailing_support() # optional - sage.modules 1 - sage: def key(x): return -x - sage: x.trailing_support(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_support(key=key) # optional - sage.modules 3 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_support() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.trailing_support() # optional - sage.combinat sage.modules [1] """ return min(self.support(), *args, **kwds) @@ -1865,17 +1877,17 @@ def trailing_item(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_item() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.trailing_item() # optional - sage.modules (1, 3) - sage: def key(x): return -x - sage: x.trailing_item(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_item(key=key) # optional - sage.modules (3, 1) - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_item() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.trailing_item() # optional - sage.combinat sage.modules ([1], 2) """ k = self.trailing_support(*args, **kwds) @@ -1894,17 +1906,17 @@ def trailing_monomial(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_monomial() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.trailing_monomial() # optional - sage.modules B[1] - sage: def key(x): return -x - sage: x.trailing_monomial(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_monomial(key=key) # optional - sage.modules B[3] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_monomial() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.trailing_monomial() # optional - sage.combinat sage.modules s[1] """ return self.parent().monomial(self.trailing_support(*args, **kwds)) @@ -1922,17 +1934,17 @@ def trailing_coefficient(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_coefficient() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.trailing_coefficient() # optional - sage.modules 3 - sage: def key(x): return -x - sage: x.trailing_coefficient(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_coefficient(key=key) # optional - sage.modules 1 - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_coefficient() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.trailing_coefficient() # optional - sage.combinat sage.modules 2 """ return self.trailing_item(*args, **kwds)[1] @@ -1950,17 +1962,17 @@ def trailing_term(self, *args, **kwds): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X"); x = X.basis() - sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) - sage: x.trailing_term() + sage: X = CombinatorialFreeModule(QQ, [1, 2, 3]); X.rename("X") # optional - sage.modules + sage: x = 3*X.monomial(1) + 2*X.monomial(2) + X.monomial(3) # optional - sage.modules + sage: x.trailing_term() # optional - sage.modules 3*B[1] - sage: def key(x): return -x - sage: x.trailing_term(key=key) + sage: def key(x): return -x # optional - sage.modules + sage: x.trailing_term(key=key) # optional - sage.modules B[3] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] - sage: f.trailing_term() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = 2*s[1] + 3*s[2,1] - 5*s[3] # optional - sage.combinat sage.modules + sage: f.trailing_term() # optional - sage.combinat sage.modules 2*s[1] """ return self.parent().term(*self.trailing_item(*args, **kwds)) @@ -1979,24 +1991,24 @@ def map_coefficients(self, f): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) - sage: B = F.basis() - sage: f = B['a'] - 3*B['c'] - sage: f.map_coefficients(lambda x: x+5) + sage: F = CombinatorialFreeModule(QQ, ['a','b','c']) # optional - sage.modules + sage: B = F.basis() # optional - sage.modules + sage: f = B['a'] - 3*B['c'] # optional - sage.modules + sage: f.map_coefficients(lambda x: x + 5) # optional - sage.modules 6*B['a'] + 2*B['c'] Killed coefficients are handled properly:: - sage: f.map_coefficients(lambda x: 0) + sage: f.map_coefficients(lambda x: 0) # optional - sage.modules 0 - sage: list(f.map_coefficients(lambda x: 0)) + sage: list(f.map_coefficients(lambda x: 0)) # optional - sage.modules [] :: - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1])+2*s([3,2]) - sage: a.map_coefficients(lambda x: x*2) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: a = s([2,1]) + 2*s([3,2]) # optional - sage.combinat sage.modules + sage: a.map_coefficients(lambda x: x * 2) # optional - sage.combinat sage.modules 2*s[2, 1] + 4*s[3, 2] """ return self.parent().sum_of_terms( (m, f(c)) for m,c in self ) @@ -2015,30 +2027,30 @@ def map_support(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) - sage: x = B.an_element(); x + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules + sage: x = B.an_element(); x # optional - sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_support(lambda i: -i) + sage: x.map_support(lambda i: -i) # optional - sage.modules 3*B[-1] + 2*B[0] + 2*B[1] ``f`` needs not be injective:: - sage: x.map_support(lambda i: 1) + sage: x.map_support(lambda i: 1) # optional - sage.modules 7*B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1])+2*s([3,2]) - sage: a.map_support(lambda x: x.conjugate()) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: a = s([2,1]) + 2*s([3,2]) # optional - sage.combinat sage.modules + sage: a.map_support(lambda x: x.conjugate()) # optional - sage.combinat sage.modules s[2, 1] + 2*s[2, 2, 1] TESTS:: - sage: B.zero() # This actually failed at some point!!! See #8890 + sage: B.zero() # This actually failed at some point!!! See #8890 # optional - sage.modules 0 - sage: y = B.zero().map_support(lambda i: i/0); y + sage: y = B.zero().map_support(lambda i: i/0); y # optional - sage.modules 0 - sage: y.parent() is B + sage: y.parent() is B # optional - sage.modules True """ return self.parent().sum_of_terms( (f(m), c) for m,c in self ) @@ -2057,22 +2069,22 @@ def map_support_skip_none(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) - sage: x = B.an_element(); x + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules + sage: x = B.an_element(); x # optional - sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_support_skip_none(lambda i: -i if i else None) + sage: x.map_support_skip_none(lambda i: -i if i else None) # optional - sage.modules 3*B[-1] + 2*B[1] ``f`` needs not be injective:: - sage: x.map_support_skip_none(lambda i: 1 if i else None) + sage: x.map_support_skip_none(lambda i: 1 if i else None) # optional - sage.modules 5*B[1] TESTS:: - sage: y = x.map_support_skip_none(lambda i: None); y + sage: y = x.map_support_skip_none(lambda i: None); y # optional - sage.modules 0 - sage: y.parent() is B + sage: y.parent() is B # optional - sage.modules True """ return self.parent().sum_of_terms( (fm,c) for (fm,c) in ((f(m), c) for m,c in self) if fm is not None) @@ -2092,21 +2104,21 @@ def map_item(self, f): EXAMPLES:: - sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) - sage: x = B.an_element(); x + sage: B = CombinatorialFreeModule(ZZ, [-1, 0, 1]) # optional - sage.modules + sage: x = B.an_element(); x # optional - sage.modules 2*B[-1] + 2*B[0] + 3*B[1] - sage: x.map_item(lambda i, c: (-i, 2*c)) + sage: x.map_item(lambda i, c: (-i, 2*c)) # optional - sage.modules 6*B[-1] + 4*B[0] + 4*B[1] ``f`` needs not be injective:: - sage: x.map_item(lambda i, c: (1, 2*c)) + sage: x.map_item(lambda i, c: (1, 2*c)) # optional - sage.modules 14*B[1] - sage: s = SymmetricFunctions(QQ).schur() - sage: f = lambda m,c: (m.conjugate(), 2*c) - sage: a = s([2,1]) + s([1,1,1]) - sage: a.map_item(f) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat sage.modules + sage: f = lambda m, c: (m.conjugate(), 2 * c) # optional - sage.combinat sage.modules + sage: a = s([2,1]) + s([1,1,1]) # optional - sage.combinat sage.modules + sage: a.map_item(f) # optional - sage.combinat sage.modules 2*s[2, 1] + 2*s[3] """ return self.parent().sum_of_terms( f(m,c) for m,c in self ) @@ -2119,9 +2131,9 @@ def tensor(*elements): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example() - sage: (a,b,c) = A.algebra_generators() - sage: a.tensor(b, c) + sage: A = C.example() # optional - sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules + sage: a.tensor(b, c) # optional - sage.combinat sage.modules B[word: a] # B[word: b] # B[word: c] FIXME: is this a policy that we want to enforce on all parents? @@ -2151,47 +2163,47 @@ def __call_on_basis__(self, **options): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") - sage: H = Hom(X, Y) - sage: x = X.basis() + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules + sage: H = Hom(X, Y) # optional - sage.modules + sage: x = X.basis() # optional - sage.modules - sage: phi = H(on_basis = lambda i: Y.monomial(i) + 2*Y.monomial(i+1)) # indirect doctest - sage: phi + sage: phi = H(on_basis=lambda i: Y.monomial(i) + 2*Y.monomial(i+1)) # indirect doctest # optional - sage.modules + sage: phi # optional - sage.modules Generic morphism: From: X To: Y - sage: phi(x[1] + x[3]) + sage: phi(x[1] + x[3]) # optional - sage.modules B[1] + 2*B[2] + B[3] + 2*B[4] Diagonal functions can be constructed using the ``diagonal`` option:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4], key="Y"); Y.rename("Y") - sage: H = Hom(X, Y) - sage: x = X.basis() - sage: phi = H(diagonal = lambda x: x^2) - sage: phi(x[1] + x[2] + x[3]) + sage: X = CombinatorialFreeModule(QQ, [1,2,3,4]); X.rename("X") # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4], key="Y"); Y.rename("Y") # optional - sage.modules + sage: H = Hom(X, Y) # optional - sage.modules + sage: x = X.basis() # optional - sage.modules + sage: phi = H(diagonal=lambda x: x^2) # optional - sage.modules + sage: phi(x[1] + x[2] + x[3]) # optional - sage.modules B[1] + 4*B[2] + 9*B[3] TESTS: As for usual homsets, the argument can be a Python function:: - sage: phi = H(lambda x: Y.zero()) - sage: phi + sage: phi = H(lambda x: Y.zero()) # optional - sage.modules + sage: phi # optional - sage.modules Generic morphism: From: X To: Y - sage: phi(x[1] + x[3]) + sage: phi(x[1] + x[3]) # optional - sage.modules 0 We check that the homset category is properly set up:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") - sage: H = Hom(X, Y) - sage: H.zero().category_for() + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules + sage: H = Hom(X, Y) # optional - sage.modules + sage: H.zero().category_for() # optional - sage.modules Category of finite dimensional vector spaces with basis over Rational Field """ return self.domain().module_morphism(codomain=self.codomain(), @@ -2210,20 +2222,20 @@ def on_basis(self): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") - sage: H = Hom(X, Y) - sage: x = X.basis() + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [1,2,3,4]); Y.rename("Y") # optional - sage.modules + sage: H = Hom(X, Y) # optional - sage.modules + sage: x = X.basis() # optional - sage.modules - sage: f = H(lambda x: Y.zero()).on_basis() - sage: f(2) + sage: f = H(lambda x: Y.zero()).on_basis() # optional - sage.modules + sage: f(2) # optional - sage.modules 0 - sage: f = lambda i: Y.monomial(i) + 2*Y.monomial(i+1) - sage: g = H(on_basis = f).on_basis() - sage: g(2) + sage: f = lambda i: Y.monomial(i) + 2*Y.monomial(i+1) # optional - sage.modules + sage: g = H(on_basis=f).on_basis() # optional - sage.modules + sage: g(2) # optional - sage.modules B[2] + 2*B[3] - sage: g == f + sage: g == f # optional - sage.modules True """ return self._on_basis @@ -2238,9 +2250,9 @@ def _on_basis(self, i): EXAMPLES:: - sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") - sage: phi = End(X)(lambda x: 2*x) - sage: phi._on_basis(3) + sage: X = CombinatorialFreeModule(QQ, [1,2,3]); X.rename("X") # optional - sage.modules + sage: phi = End(X)(lambda x: 2*x) # optional - sage.modules + sage: phi._on_basis(3) # optional - sage.modules 2*B[3] """ return self(self.domain().monomial(i)) @@ -2270,15 +2282,17 @@ def _an_element_(self): """ EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: B = HopfAlgebrasWithBasis(QQ).example(); B - An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: A.an_element() + 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: B = HopfAlgebrasWithBasis(QQ).example(); B # optional - sage.combinat sage.modules + An example of Hopf algebra with basis: + the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field + sage: A.an_element() # optional - sage.combinat sage.modules B[word: ] + 2*B[word: a] + 3*B[word: b] + B[word: bab] - sage: B.an_element() + sage: B.an_element() # optional - sage.combinat sage.modules B[()] + B[(1,2)] + 3*B[(1,2,3)] + 2*B[(1,3,2)] - sage: cartesian_product((A, B, A)).an_element() # indirect doctest + sage: cartesian_product((A, B, A)).an_element() # indirect doctest # optional - sage.combinat sage.modules 2*B[(0, word: )] + 2*B[(0, word: a)] + 3*B[(0, word: b)] """ from .cartesian_product import cartesian_product @@ -2341,8 +2355,10 @@ def apply_multilinear_morphism(self, f, codomain=None): We start with simple (admittedly not so interesting) examples, with two modules `A` and `B`:: - sage: A = CombinatorialFreeModule(ZZ, [1,2], prefix="A"); A.rename("A") - sage: B = CombinatorialFreeModule(ZZ, [3,4], prefix="B"); B.rename("B") + sage: A = CombinatorialFreeModule(ZZ, [1,2], prefix="A") # optional - sage.modules + sage: A.rename("A") # optional - sage.modules + sage: B = CombinatorialFreeModule(ZZ, [3,4], prefix="B") # optional - sage.modules + sage: B.rename("B") # optional - sage.modules and `f` the bilinear morphism `(a,b) \mapsto b \otimes a` from `A \times B` to `B \otimes A`:: @@ -2353,23 +2369,23 @@ def apply_multilinear_morphism(self, f, codomain=None): Now, calling applying `f` on `a \otimes b` returns the same as `f(a,b)`:: - sage: a = A.monomial(1) + 2 * A.monomial(2); a + sage: a = A.monomial(1) + 2 * A.monomial(2); a # optional - sage.modules A[1] + 2*A[2] - sage: b = B.monomial(3) - 2 * B.monomial(4); b + sage: b = B.monomial(3) - 2 * B.monomial(4); b # optional - sage.modules B[3] - 2*B[4] - sage: f(a,b) + sage: f(a, b) # optional - sage.modules B[3] # A[1] + 2*B[3] # A[2] - 2*B[4] # A[1] - 4*B[4] # A[2] - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules B[3] # A[1] + 2*B[3] # A[2] - 2*B[4] # A[1] - 4*B[4] # A[2] `f` may be a bilinear morphism to any module over the base ring of `A` and `B`. Here the codomain is `\ZZ`:: - sage: def f(a,b): + sage: def f(a, b): ....: return sum(a.coefficients(), 0) * sum(b.coefficients(), 0) - sage: f(a,b) + sage: f(a, b) # optional - sage.modules -3 - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules -3 Mind the `0` in the sums above; otherwise `f` would @@ -2377,12 +2393,12 @@ def apply_multilinear_morphism(self, f, codomain=None): sage: def f(a,b): ....: return sum(a.coefficients()) * sum(b.coefficients()) - sage: type(f(A.zero(), B.zero())) + sage: type(f(A.zero(), B.zero())) # optional - sage.modules <... 'int'> Which would be wrong and break this method:: - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules Traceback (most recent call last): ... AttributeError: 'int' object has no attribute 'parent' @@ -2390,12 +2406,14 @@ def apply_multilinear_morphism(self, f, codomain=None): Here we consider an example where the codomain is a module with basis with a different base ring:: - sage: C = CombinatorialFreeModule(QQ, [(1,3),(2,4)], prefix="C"); C.rename("C") - sage: def f(a,b): - ....: return C.sum_of_terms( [((1,3), QQ(a[1]*b[3])), ((2,4), QQ(a[2]*b[4]))] ) - sage: f(a,b) + sage: C = CombinatorialFreeModule(QQ, [(1,3),(2,4)], prefix="C") # optional - sage.modules + sage: C.rename("C") # optional - sage.modules + sage: def f(a, b): + ....: return C.sum_of_terms([((1,3), QQ(a[1]*b[3])), + ....: ((2,4), QQ(a[2]*b[4]))]) + sage: f(a,b) # optional - sage.modules C[(1, 3)] - 4*C[(2, 4)] - sage: tensor([a,b]).apply_multilinear_morphism(f) + sage: tensor([a, b]).apply_multilinear_morphism(f) # optional - sage.modules C[(1, 3)] - 4*C[(2, 4)] We conclude with a real life application, where we @@ -2403,14 +2421,14 @@ def apply_multilinear_morphism(self, f, codomain=None): Symmetric functions on the Schur basis satisfies its defining formula:: - sage: Sym = SymmetricFunctions(QQ) - sage: s = Sym.schur() - sage: def f(a,b): return a*b.antipode() - sage: x = 4*s.an_element(); x + sage: Sym = SymmetricFunctions(QQ) # optional - sage.combinat sage.modules + sage: s = Sym.schur() # optional - sage.combinat sage.modules + sage: def f(a, b): return a * b.antipode() # optional - sage.combinat sage.modules + sage: x = 4 * s.an_element(); x # optional - sage.combinat sage.modules 8*s[] + 8*s[1] + 12*s[2] - sage: x.coproduct().apply_multilinear_morphism(f) + sage: x.coproduct().apply_multilinear_morphism(f) # optional - sage.combinat sage.modules 8*s[] - sage: x.coproduct().apply_multilinear_morphism(f) == x.counit() + sage: x.coproduct().apply_multilinear_morphism(f) == x.counit() # optional - sage.combinat sage.modules True We recover the constant term of `x`, as desired. @@ -2445,6 +2463,7 @@ def extra_super_categories(self): sage: ModulesWithBasis(ZZ).DualObjects().extra_super_categories() [Category of modules over Integer Ring] sage: ModulesWithBasis(QQ).DualObjects().super_categories() - [Category of duals of vector spaces over Rational Field, Category of duals of modules with basis over Rational Field] + [Category of duals of vector spaces over Rational Field, + Category of duals of modules with basis over Rational Field] """ return [Modules(self.base_category().base_ring())] diff --git a/src/sage/categories/monoids.py b/src/sage/categories/monoids.py index dc548a72e66..386b1b133f1 100644 --- a/src/sage/categories/monoids.py +++ b/src/sage/categories/monoids.py @@ -69,7 +69,7 @@ class Monoids(CategoryWithAxiom): Check for :trac:`31212`:: sage: R = IntegerModRing(15) - sage: R.submonoid([R.one()]).list() + sage: R.submonoid([R.one()]).list() # optional - sage.groups [1] """ _base_category_class_and_axiom = (Semigroups, "Unital") @@ -98,11 +98,11 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Monoids.free(index_set=ZZ) + sage: Monoids.free(index_set=ZZ) # optional - sage.groups Free monoid indexed by Integer Ring - sage: Monoids().free(ZZ) + sage: Monoids().free(ZZ) # optional - sage.groups Free monoid indexed by Integer Ring - sage: F. = Monoids().free(); F + sage: F. = Monoids().free(); F # optional - sage.groups Free monoid indexed by {'x', 'y', 'z'} """ if names is not None: @@ -130,8 +130,8 @@ def semigroup_generators(self): EXAMPLES:: - sage: M = Monoids().free([1,2,3]) - sage: M.semigroup_generators() + sage: M = Monoids().free([1,2,3]) # optional - sage.groups + sage: M.semigroup_generators() # optional - sage.groups Family (1, F[1], F[2], F[3]) """ G = self.monoid_generators() @@ -212,22 +212,22 @@ def submonoid(self, generators, category=None): EXAMPLES:: sage: R = IntegerModRing(15) - sage: M = R.submonoid([R(3),R(5)]); M + sage: M = R.submonoid([R(3), R(5)]); M # optional - sage.groups A submonoid of (Ring of integers modulo 15) with 2 generators - sage: M.list() + sage: M.list() # optional - sage.groups [1, 3, 5, 9, 0, 10, 12, 6] Not the presence of the unit, unlike in:: - sage: S = R.subsemigroup([R(3),R(5)]); S + sage: S = R.subsemigroup([R(3), R(5)]); S # optional - sage.groups A subsemigroup of (Ring of integers modulo 15) with 2 generators - sage: S.list() + sage: S.list() # optional - sage.groups [3, 5, 9, 0, 10, 12, 6] This method is really a shorthand for subsemigroup:: - sage: M2 = R.subsemigroup([R(3),R(5)], one=R.one()) - sage: M2 is M + sage: M2 = R.subsemigroup([R(3), R(5)], one=R.one()) # optional - sage.groups + sage: M2 is M # optional - sage.groups True """ return self.subsemigroup(generators, one=self.one()) @@ -245,11 +245,11 @@ def _div_(left, right): EXAMPLES:: - sage: G = FreeGroup(2) - sage: x0, x1 = G.group_generators() - sage: c1 = cartesian_product([x0, x1]) - sage: c2 = cartesian_product([x1, x0]) - sage: c1._div_(c2) + sage: G = FreeGroup(2) # optional - sage.groups + sage: x0, x1 = G.group_generators() # optional - sage.groups + sage: c1 = cartesian_product([x0, x1]) # optional - sage.groups + sage: c2 = cartesian_product([x1, x0]) # optional - sage.groups + sage: c1._div_(c2) # optional - sage.groups (x0*x1^-1, x1*x0^-1) With this default implementation, division will fail as @@ -267,7 +267,7 @@ def _div_(left, right): TESTS:: - sage: c1._div_.__module__ + sage: c1._div_.__module__ # optional - sage.groups 'sage.categories.monoids' """ return left * ~right @@ -336,8 +336,8 @@ def powers(self, n): EXAMPLES:: - sage: A = Matrix([[1, 1], [-1, 0]]) - sage: A.powers(6) + sage: A = Matrix([[1, 1], [-1, 0]]) # optional - sage.modules + sage: A.powers(6) # optional - sage.modules [ [1 0] [ 1 1] [ 0 1] [-1 0] [-1 -1] [ 0 -1] [0 1], [-1 0], [-1 -1], [ 0 -1], [ 1 0], [ 1 1] @@ -363,8 +363,8 @@ def __invert__(self): EXAMPLES:: - sage: A = Matrix([[1, 0], [1, 1]]) - sage: ~A + sage: A = Matrix([[1, 0], [1, 1]]) # optional - sage.modules + sage: ~A # optional - sage.modules [ 1 0] [-1 1] """ @@ -379,7 +379,7 @@ def inverse(self): EXAMPLES:: - sage: AA(sqrt(~2)).inverse() + sage: AA(sqrt(~2)).inverse() # optional - sage.symbolic sage.rings.number_field 1.414213562373095? """ # Nota Bene: Element classes should implement ``__invert__`` only. @@ -412,11 +412,11 @@ def free(index_set=None, names=None, **kwds): EXAMPLES:: - sage: Monoids.Commutative.free(index_set=ZZ) + sage: Monoids.Commutative.free(index_set=ZZ) # optional - sage.groups Free abelian monoid indexed by Integer Ring - sage: Monoids().Commutative().free(ZZ) + sage: Monoids().Commutative().free(ZZ) # optional - sage.groups Free abelian monoid indexed by Integer Ring - sage: F. = Monoids().Commutative().free(); F + sage: F. = Monoids().Commutative().free(); F # optional - sage.groups Free abelian monoid indexed by {'x', 'y', 'z'} """ if names is not None: @@ -447,18 +447,18 @@ def one(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.one.__module__ + sage: A.one.__module__ # optional - sage.combinat sage.modules 'sage.categories.monoids' - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules F[{}] TESTS:: - sage: A.one() is A.a_realization().one() + sage: A.one() is A.a_realization().one() # optional - sage.combinat sage.modules True - sage: A._test_one() + sage: A._test_one() # optional - sage.combinat sage.modules """ return self.a_realization().one() @@ -510,12 +510,12 @@ def one_basis(self): EXAMPLES:: - sage: A = Monoids().example().algebra(ZZ) - sage: A.one_basis() + sage: A = Monoids().example().algebra(ZZ) # optional - sage.modules + sage: A.one_basis() # optional - sage.modules '' - sage: A.one() + sage: A.one() # optional - sage.modules B[''] - sage: A(3) + sage: A(3) # optional - sage.modules 3*B[''] """ return self.basis().keys().one() @@ -542,7 +542,7 @@ def algebra_generators(self): the free monoid generated by ('a', 'b', 'c', 'd') sage: M.monoid_generators() Finite family {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd'} - sage: M.algebra(ZZ).algebra_generators() + sage: M.algebra(ZZ).algebra_generators() # optional - sage.modules Finite family {'a': B['a'], 'b': B['b'], 'c': B['c'], 'd': B['d']} sage: Z12 = Monoids().Finite().example(); Z12 @@ -555,17 +555,18 @@ def algebra_generators(self): has no attribute 'monoid_generators' sage: Z12.semigroup_generators() Family (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) - sage: Z12.algebra(QQ).algebra_generators() + sage: Z12.algebra(QQ).algebra_generators() # optional - sage.modules Family (B[0], B[1], B[2], B[3], B[4], B[5], B[6], B[7], B[8], B[9], B[10], B[11]) - sage: GroupAlgebras(QQ).example(AlternatingGroup(10)).algebra_generators() + sage: A10 = AlternatingGroup(10) # optional - sage.groups + sage: GroupAlgebras(QQ).example(A10).algebra_generators() # optional - sage.groups sage.modules Family ((8,9,10), (1,2,3,4,5,6,7,8,9)) - sage: A = DihedralGroup(3).algebra(QQ); A + sage: A = DihedralGroup(3).algebra(QQ); A # optional - sage.groups sage.modules Algebra of Dihedral group of order 6 as a permutation group over Rational Field - sage: A.algebra_generators() + sage: A.algebra_generators() # optional - sage.groups sage.modules Family ((1,2,3), (1,3)) """ monoid = self.basis().keys() @@ -583,14 +584,15 @@ def is_central(self): EXAMPLES:: - sage: SG4 = SymmetricGroupAlgebra(ZZ,4) - sage: SG4(1).is_central() + sage: SG4 = SymmetricGroupAlgebra(ZZ,4) # optional - sage.groups sage.modules + sage: SG4(1).is_central() # optional - sage.groups sage.modules True - sage: SG4(Permutation([1,3,2,4])).is_central() + sage: SG4(Permutation([1,3,2,4])).is_central() # optional - sage.groups sage.modules False - sage: A = GroupAlgebras(QQ).example(); A - Algebra of Dihedral group of order 8 as a permutation group over Rational Field - sage: sum(i for i in A.basis()).is_central() + sage: A = GroupAlgebras(QQ).example(); A # optional - sage.groups sage.modules + Algebra of Dihedral group of order 8 + as a permutation group over Rational Field + sage: sum(i for i in A.basis()).is_central() # optional - sage.groups sage.modules True """ return all(i * self == self * i @@ -628,19 +630,19 @@ def monoid_generators(self): EXAMPLES:: - sage: M = Monoids.free([1,2,3]) - sage: N = Monoids.free(['a','b']) - sage: C = cartesian_product([M, N]) - sage: C.monoid_generators() + sage: M = Monoids.free([1, 2, 3]) # optional - sage.groups + sage: N = Monoids.free(['a', 'b']) # optional - sage.groups + sage: C = cartesian_product([M, N]) # optional - sage.groups + sage: C.monoid_generators() # optional - sage.groups Family ((F[1], 1), (F[2], 1), (F[3], 1), (1, F['a']), (1, F['b'])) An example with an infinitely generated group (a better output is needed):: - sage: N = Monoids.free(ZZ) - sage: C = cartesian_product([M, N]) - sage: C.monoid_generators() + sage: N = Monoids.free(ZZ) # optional - sage.groups + sage: C = cartesian_product([M, N]) # optional - sage.groups + sage: C.monoid_generators() # optional - sage.groups Lazy family (gen(i))_{i in The Cartesian product of (...)} """ F = self.cartesian_factors() @@ -677,10 +679,10 @@ def multiplicative_order(self): EXAMPLES:: - sage: G1 = SymmetricGroup(3) - sage: G2 = SL(2,3) - sage: G = cartesian_product([G1,G2]) - sage: G((G1.gen(0), G2.gen(1))).multiplicative_order() + sage: G1 = SymmetricGroup(3) # optional - sage.groups sage.modules + sage: G2 = SL(2, 3) # optional - sage.groups sage.modules + sage: G = cartesian_product([G1, G2]) # optional - sage.groups sage.modules + sage: G((G1.gen(0), G2.gen(1))).multiplicative_order() # optional - sage.groups sage.modules 12 """ from sage.rings.infinity import Infinity @@ -697,10 +699,10 @@ def __invert__(self): EXAMPLES:: - sage: a1 = Permutation((4,2,1,3)) - sage: a2 = SL(2,3)([2,1,1,1]) - sage: h = cartesian_product([a1,a2]) - sage: ~h + sage: a1 = Permutation((4,2,1,3)) # optional - sage.groups sage.modules + sage: a2 = SL(2, 3)([2,1,1,1]) # optional - sage.groups sage.modules + sage: h = cartesian_product([a1, a2]) # optional - sage.groups sage.modules + sage: ~h # optional - sage.groups sage.modules ([2, 4, 1, 3], [1 2] [2 2]) """ diff --git a/src/sage/categories/morphism.pyx b/src/sage/categories/morphism.pyx index 031b41218e3..514140b2333 100644 --- a/src/sage/categories/morphism.pyx +++ b/src/sage/categories/morphism.pyx @@ -69,25 +69,25 @@ cdef class Morphism(Map): EXAMPLES:: sage: R. = ZZ[] - sage: f = R.hom([t+1]) + sage: f = R.hom([t + 1]) sage: f # indirect doctest Ring endomorphism of Univariate Polynomial Ring in t over Integer Ring Defn: t |--> t + 1 TESTS:: - sage: K = CyclotomicField(12) - sage: L = CyclotomicField(132) - sage: phi = L._internal_coerce_map_from(K); phi + sage: K = CyclotomicField(12) # optional - sage.rings.number_field + sage: L = CyclotomicField(132) # optional - sage.rings.number_field + sage: phi = L._internal_coerce_map_from(K); phi # optional - sage.rings.number_field (map internal to coercion system -- copy before use) Generic morphism: From: Cyclotomic Field of order 12 and degree 4 To: Cyclotomic Field of order 132 and degree 40 - sage: del K + sage: del K # optional - sage.rings.number_field sage: import gc sage: _ = gc.collect() - sage: phi + sage: phi # optional - sage.rings.number_field Defunct morphism """ D = self.domain() @@ -182,10 +182,10 @@ cdef class Morphism(Map): and left modules over (euclidean domains and infinite enumerated sets and metric spaces) - sage: K = CyclotomicField(12) - sage: L = CyclotomicField(132) - sage: phi = L._internal_coerce_map_from(K) - sage: phi.category() + sage: K = CyclotomicField(12) # optional - sage.rings.number_field + sage: L = CyclotomicField(132) # optional - sage.rings.number_field + sage: phi = L._internal_coerce_map_from(K) # optional - sage.rings.number_field + sage: phi.category() # optional - sage.rings.number_field Category of homsets of number fields """ # Should it be Category of elements of ...? @@ -202,10 +202,10 @@ cdef class Morphism(Map): sage: f.is_endomorphism() True - sage: K = CyclotomicField(12) - sage: L = CyclotomicField(132) - sage: phi = L._internal_coerce_map_from(K) - sage: phi.is_endomorphism() + sage: K = CyclotomicField(12) # optional - sage.rings.number_field + sage: L = CyclotomicField(132) # optional - sage.rings.number_field + sage: phi = L._internal_coerce_map_from(K) # optional - sage.rings.number_field + sage: phi.is_endomorphism() # optional - sage.rings.number_field False """ return self.parent().is_endomorphism_set() @@ -260,7 +260,9 @@ cdef class Morphism(Map): sage: x^2 + y Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring' + TypeError: unsupported operand parent(s) for +: + 'Univariate Polynomial Ring in x over Integer Ring' and + 'Univariate Polynomial Ring in y over Integer Ring' Let us declare a coercion from `\ZZ[x]` to `\ZZ[z]`:: @@ -284,7 +286,9 @@ cdef class Morphism(Map): sage: phi.register_as_coercion() Traceback (most recent call last): ... - AssertionError: coercion from Univariate Polynomial Ring in x over Integer Ring to Univariate Polynomial Ring in z over Integer Ring already registered or discovered + AssertionError: coercion from Univariate Polynomial Ring in x over Integer Ring + to Univariate Polynomial Ring in z over Integer Ring + already registered or discovered """ self._codomain.register_coercion(self) @@ -300,14 +304,14 @@ cdef class Morphism(Map): Let us declare a conversion from the symmetric group to `\ZZ` through the sign map:: - sage: S = SymmetricGroup(4) - sage: phi = Hom(S, ZZ)(lambda x: ZZ(x.sign())) - sage: x = S.an_element(); x + sage: S = SymmetricGroup(4) # optional - sage.groups + sage: phi = Hom(S, ZZ)(lambda x: ZZ(x.sign())) # optional - sage.groups + sage: x = S.an_element(); x # optional - sage.groups (2,3,4) - sage: phi(x) + sage: phi(x) # optional - sage.groups 1 - sage: phi.register_as_conversion() - sage: ZZ(x) + sage: phi.register_as_conversion() # optional - sage.groups + sage: ZZ(x) # optional - sage.groups 1 """ self._codomain.register_conversion(self) @@ -347,26 +351,27 @@ cdef class Morphism(Map): TESTS:: sage: from sage.categories.morphism import SetMorphism - sage: E = End(Partitions(5)) - sage: f = E.identity() - sage: g = SetMorphism(E, lambda x:x) - sage: f == g + sage: E = End(Partitions(5)) # optional - sage.combinat + sage: f = E.identity() # optional - sage.combinat + sage: g = SetMorphism(E, lambda x: x) # optional - sage.combinat + sage: f == g # optional - sage.combinat Traceback (most recent call last): ... - NotImplementedError: unable to compare morphisms of type <... 'sage.categories.morphism.IdentityMorphism'> and <... 'sage.categories.morphism.SetMorphism'> with domain Partitions of the integer 5 + NotImplementedError: unable to compare morphisms of type <... 'sage.categories.morphism.IdentityMorphism'> + and <... 'sage.categories.morphism.SetMorphism'> with domain Partitions of the integer 5 We check that :trac:`28617` is fixed:: - sage: FF = GF(2^20) - sage: f = FF.frobenius_endomorphism() - sage: f == FF.frobenius_endomorphism() + sage: FF = GF(2^20) # optional - sage.libs.combinat + sage: f = FF.frobenius_endomorphism() # optional - sage.libs.combinat + sage: f == FF.frobenius_endomorphism() # optional - sage.libs.combinat True and that :trac:`29632` is fixed:: - sage: R. = QuadraticField(-1)[] - sage: f = R.hom(R.gens(), R) - sage: f.is_identity() + sage: R. = QuadraticField(-1)[] # optional - sage.rings.number_field + sage: f = R.hom(R.gens(), R) # optional - sage.rings.number_field + sage: f.is_identity() # optional - sage.rings.number_field True """ if self is other: @@ -502,17 +507,17 @@ cdef class IdentityMorphism(Morphism): EXAMPLES:: - sage: E = End(Partitions(5)) - sage: E.identity().is_identity() + sage: E = End(Partitions(5)) # optional - sage.combinat + sage: E.identity().is_identity() # optional - sage.combinat True Check that :trac:`15478` is fixed:: - sage: K. = GF(4) - sage: phi = End(K)([z^2]) - sage: R. = K[] - sage: psi = End(R)(phi) - sage: psi.is_identity() + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: phi = End(K)([z^2]) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: psi = End(R)(phi) # optional - sage.rings.finite_rings + sage: psi.is_identity() # optional - sage.rings.finite_rings False """ return True diff --git a/src/sage/categories/number_fields.py b/src/sage/categories/number_fields.py index 8386ea03912..f3610cd8b7f 100644 --- a/src/sage/categories/number_fields.py +++ b/src/sage/categories/number_fields.py @@ -42,16 +42,16 @@ class NumberFields(Category_singleton): course also in this category:: sage: x = PolynomialRing(RationalField(), 'x').gen() - sage: K = NumberField(x - 1, 'a'); K + sage: K = NumberField(x - 1, 'a'); K # optional - sage.rings.number_field Number Field in a with defining polynomial x - 1 - sage: K in C + sage: K in C # optional - sage.rings.number_field True Number fields all lie in this category, regardless of the name of the variable:: - sage: K = NumberField(x^2 + 1, 'a') - sage: K in C + sage: K = NumberField(x^2 + 1, 'a') # optional - sage.rings.number_field + sage: K in C # optional - sage.rings.number_field True TESTS:: @@ -75,11 +75,11 @@ def __contains__(self, x): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: NumberField(x^2 + 1, 'a') in NumberFields() + sage: NumberField(x^2 + 1, 'a') in NumberFields() # optional - sage.rings.number_field True - sage: QuadraticField(-97, 'theta') in NumberFields() + sage: QuadraticField(-97, 'theta') in NumberFields() # optional - sage.rings.number_field True - sage: CyclotomicField(97) in NumberFields() + sage: CyclotomicField(97) in NumberFields() # optional - sage.rings.number_field True Note that the rational numbers QQ are a number field:: @@ -105,10 +105,10 @@ def _call_(self, x): sage: C(QQ) Rational Field - sage: C(NumberField(x^2 + 1, 'a')) + sage: C(NumberField(x^2 + 1, 'a')) # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 + 1 - sage: C(UnitGroup(NumberField(x^2 + 1, 'a'))) # indirect doctest + sage: C(UnitGroup(NumberField(x^2 + 1, 'a'))) # indirect doctest # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 + 1 sage: C(ZZ) @@ -151,34 +151,35 @@ def zeta_function(self, prec=53, EXAMPLES:: - sage: K. = NumberField(ZZ['x'].0^2+ZZ['x'].0-1) - sage: Z = K.zeta_function(); Z # optional - sage.symbolic - PARI zeta function associated to Number Field in a with defining polynomial x^2 + x - 1 - sage: Z(-1) # optional - sage.symbolic + sage: K. = NumberField(ZZ['x'].0^2 + ZZ['x'].0 - 1) # optional - sage.rings.number_field + sage: Z = K.zeta_function(); Z # optional - sage.rings.number_field sage.symbolic + PARI zeta function associated to Number Field in a + with defining polynomial x^2 + x - 1 + sage: Z(-1) # optional - sage.rings.number_field sage.symbolic 0.0333333333333333 - sage: x = polygen(QQ, 'x') # optional - sage.symbolic - sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.symbolic - sage: Z = L.zeta_function() # optional - sage.symbolic - sage: Z(5) # optional - sage.symbolic + sage: x = polygen(QQ, 'x') + sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.rings.number_field + sage: Z = L.zeta_function() # optional - sage.rings.number_field sage.symbolic + sage: Z(5) # optional - sage.rings.number_field sage.symbolic 1.00199015670185 Using the algorithm "pari":: - sage: K. = NumberField(ZZ['x'].0^2+ZZ['x'].0-1) # optional - sage.symbolic - sage: Z = K.zeta_function(algorithm="pari") # optional - sage.symbolic - sage: Z(-1) # optional - sage.symbolic + sage: K. = NumberField(ZZ['x'].0^2 + ZZ['x'].0 - 1) # optional - sage.rings.number_field + sage: Z = K.zeta_function(algorithm="pari") # optional - sage.rings.number_field sage.symbolic + sage: Z(-1) # optional - sage.rings.number_field sage.symbolic 0.0333333333333333 - sage: x = polygen(QQ, 'x') # optional - sage.symbolic - sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.symbolic - sage: Z = L.zeta_function(algorithm="pari") # optional - sage.symbolic - sage: Z(5) # optional - sage.symbolic + sage: x = polygen(QQ, 'x') + sage: L. = NumberField([x^2 - 5, x^2 + 3, x^2 + 1]) # optional - sage.rings.number_field + sage: Z = L.zeta_function(algorithm="pari") # optional - sage.rings.number_field sage.symbolic + sage: Z(5) # optional - sage.rings.number_field sage.symbolic 1.00199015670185 TESTS:: - sage: QQ.zeta_function() # optional - sage.symbolic + sage: QQ.zeta_function() # optional - sage.symbolic PARI zeta function associated to Rational Field """ if algorithm == 'gp': @@ -222,8 +223,9 @@ def _test_absolute_disc(self, **options): EXAMPLES:: - sage: S = NumberField(x**3-x-1, 'a') - sage: S._test_absolute_disc() + sage: x = polygen(ZZ, 'x') + sage: S = NumberField(x**3 - x - 1, 'a') # optional - sage.rings.number_field + sage: S._test_absolute_disc() # optional - sage.rings.number_field """ from sage.rings.integer import Integer tester = self._tester(**options) diff --git a/src/sage/categories/polyhedra.py b/src/sage/categories/polyhedra.py index 20e43bff108..7bfb89bd2ae 100644 --- a/src/sage/categories/polyhedra.py +++ b/src/sage/categories/polyhedra.py @@ -26,10 +26,10 @@ class PolyhedralSets(Category_over_base_ring): sage: TestSuite(PolyhedralSets(RDF)).run() - sage: P = Polyhedron() - sage: P.parent().category().element_class + sage: P = Polyhedron() # optional - sage.geometry.polyhedron + sage: P.parent().category().element_class # optional - sage.geometry.polyhedron - sage: P.parent().category().element_class.mro() + sage: P.parent().category().element_class.mro() # optional - sage.geometry.polyhedron [, , , @@ -45,7 +45,7 @@ class PolyhedralSets(Category_over_base_ring): , , ] - sage: isinstance(P, P.parent().category().element_class) + sage: isinstance(P, P.parent().category().element_class) # optional - sage.geometry.polyhedron True """ @@ -53,7 +53,7 @@ def __init__(self, R): """ TESTS:: - sage: PolyhedralSets(AA) + sage: PolyhedralSets(AA) # optional - sage.rings.number_field Category of polyhedral sets over Algebraic Real Field """ Category_over_base_ring.__init__(self, R) diff --git a/src/sage/categories/poor_man_map.py b/src/sage/categories/poor_man_map.py index d0fca4b658d..6912c4878cf 100644 --- a/src/sage/categories/poor_man_map.py +++ b/src/sage/categories/poor_man_map.py @@ -39,7 +39,7 @@ class PoorManMap(sage.structure.sage_object.SageObject): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1, 2, 3), codomain = (1, 2, 6)) + sage: f = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6)) sage: f A map from (1, 2, 3) to (1, 2, 6) sage: f(3) @@ -48,12 +48,12 @@ class PoorManMap(sage.structure.sage_object.SageObject): The composition of several functions can be created by passing in a tuple of functions:: - sage: i = PoorManMap((factorial, sqrt), domain= (1, 4, 9), codomain = (1, 2, 6)) + sage: i = PoorManMap((factorial, sqrt), domain=(1, 4, 9), codomain=(1, 2, 6)) However, the same effect can also be achieved by just composing maps:: - sage: g = PoorManMap(factorial, domain = (1, 2, 3), codomain = (1, 2, 6)) - sage: h = PoorManMap(sqrt, domain = (1, 4, 9), codomain = (1, 2, 3)) + sage: g = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6)) + sage: h = PoorManMap(sqrt, domain=(1, 4, 9), codomain=(1, 2, 3)) sage: i == g*h True @@ -63,8 +63,8 @@ def __init__(self, function, domain=None, codomain=None, name=None): TESTS:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1, 2, 3), codomain = (1, 2, 6)) - sage: g = PoorManMap(sqrt, domain = (1, 4, 9), codomain = (1, 2, 6)) + sage: f = PoorManMap(factorial, domain=(1, 2, 3), codomain=(1, 2, 6)) + sage: g = PoorManMap(sqrt, domain=(1, 4, 9), codomain=(1, 2, 6)) sage: TestSuite(f).run() sage: TestSuite(f*g).run() @@ -85,11 +85,11 @@ def _repr_(self): sage: from sage.categories.poor_man_map import PoorManMap sage: PoorManMap(lambda x: x+2) # indirect doctest A map - sage: PoorManMap(lambda x: x+2, domain = (1,2,3)) + sage: PoorManMap(lambda x: x+2, domain=(1,2,3)) A map from (1, 2, 3) - sage: PoorManMap(lambda x: x+2, domain = (1,2,3)) + sage: PoorManMap(lambda x: x+2, domain=(1,2,3)) A map from (1, 2, 3) - sage: PoorManMap(lambda x: x+2, codomain = (3,4,5)) + sage: PoorManMap(lambda x: x+2, codomain=(3,4,5)) A map to (3, 4, 5) """ @@ -104,7 +104,7 @@ def domain(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)).domain() + sage: PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)).domain() (1, 2, 3) """ return self._domain @@ -116,7 +116,7 @@ def codomain(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)).codomain() + sage: PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)).codomain() (2, 3, 4) """ return self._codomain @@ -128,12 +128,12 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: g = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: h1 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h2 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h3 = PoorManMap(factorial, domain = (1,2,3,4), codomain = (1,2,6)) - sage: h4 = PoorManMap(lambda x: x, domain = (1,2,3), codomain = (1,2,6)) + sage: f = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: g = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: h1 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h2 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h3 = PoorManMap(factorial, domain=(1,2,3,4), codomain=(1,2,6)) + sage: h4 = PoorManMap(lambda x: x, domain=(1,2,3), codomain=(1,2,6)) sage: f == g, f == h1, f == h2, f == h3, f == h4, f == 1, 1 == f (True, False, False, False, False, False, False) @@ -153,12 +153,12 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: g = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: h1 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h2 = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6,8)) - sage: h3 = PoorManMap(factorial, domain = (1,2,3,4), codomain = (1,2,6)) - sage: h4 = PoorManMap(lambda x: x, domain = (1,2,3), codomain = (1,2,6)) + sage: f = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: g = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: h1 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h2 = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6,8)) + sage: h3 = PoorManMap(factorial, domain=(1,2,3,4), codomain=(1,2,6)) + sage: h4 = PoorManMap(lambda x: x, domain=(1,2,3), codomain=(1,2,6)) sage: f != g, f != h1, f != h2, f != h3, f != h4, f != 1, 1 != f (False, True, True, True, True, True, True) @@ -172,8 +172,8 @@ def __hash__(self): TESTS:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) - sage: g = PoorManMap(factorial, domain = (1,2,3), codomain = (1,2,6)) + sage: f = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) + sage: g = PoorManMap(factorial, domain=(1,2,3), codomain=(1,2,6)) sage: hash(f) == hash(g) True @@ -194,8 +194,8 @@ def __mul__(self, other): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)) - sage: g = PoorManMap(lambda x: -x, domain = (2,3,4), codomain = (-2,-3,-4)) + sage: f = PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)) + sage: g = PoorManMap(lambda x: -x, domain=(2,3,4), codomain=(-2,-3,-4)) sage: g*f A map from (1, 2, 3) to (-2, -3, -4) @@ -208,8 +208,8 @@ def __mul__(self, other): But it is detected here:: - sage: g = PoorManMap(factorial, domain = ZZ, codomain = ZZ) - sage: h = PoorManMap(sqrt, domain = RR, codomain = CC) + sage: g = PoorManMap(factorial, domain=ZZ, codomain=ZZ) + sage: h = PoorManMap(sqrt, domain=RR, codomain=CC) sage: g*h Traceback (most recent call last): ... @@ -248,11 +248,11 @@ def __call__(self, *args): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: f = PoorManMap(lambda x: x+1, domain = (1,2,3), codomain = (2,3,4)) + sage: f = PoorManMap(lambda x: x+1, domain=(1,2,3), codomain=(2,3,4)) sage: f(2) 3 - sage: g = PoorManMap(lambda x: -x, domain = (2,3,4), codomain = (-2,-3,-4)) + sage: g = PoorManMap(lambda x: -x, domain=(2,3,4), codomain=(-2,-3,-4)) sage: (g*f)(2) -3 @@ -266,8 +266,8 @@ def _sympy_(self): EXAMPLES:: sage: from sage.categories.poor_man_map import PoorManMap - sage: h = PoorManMap(sin, domain=RR, codomain=RR) - sage: h._sympy_() + sage: h = PoorManMap(sin, domain=RR, codomain=RR) # optional - sage.symbolic + sage: h._sympy_() # optional - sage.symbolic sin """ from sympy import Lambda, sympify diff --git a/src/sage/categories/posets.py b/src/sage/categories/posets.py index b1a2ba1942d..24a83e02dbd 100644 --- a/src/sage/categories/posets.py +++ b/src/sage/categories/posets.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Posets """ @@ -112,7 +113,8 @@ def example(self, choice=None): An example of a poset: sets ordered by inclusion sage: Posets().example("facade") - An example of a facade poset: the positive integers ordered by divisibility + An example of a facade poset: + the positive integers ordered by divisibility """ from sage.categories.examples.posets import FiniteSetsOrderedByInclusion, PositiveIntegersOrderedByDivisibilityFacade if choice == "facade": @@ -457,7 +459,8 @@ def is_order_ideal(self, o): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_order_ideal([1, 3]) @@ -483,7 +486,8 @@ def is_order_filter(self, o): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_order_filter([4, 12]) @@ -527,7 +531,8 @@ def is_chain_of_poset(self, o, ordered=False): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_chain_of_poset([1, 3]) @@ -575,11 +580,16 @@ def is_chain_of_poset(self, o, ordered=False): sage: from sage.categories.examples.posets import FiniteSetsOrderedByInclusion sage: R = FiniteSetsOrderedByInclusion() - sage: R.is_chain_of_poset([R(set([3, 1, 2])), R(set([1, 4])), R(set([4, 5]))]) + sage: R.is_chain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 4])), + ....: R(set([4, 5]))]) False - sage: R.is_chain_of_poset([R(set([3, 1, 2])), R(set([1, 2])), R(set([1]))], ordered=True) + sage: R.is_chain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 2])), + ....: R(set([1]))], ordered=True) False - sage: R.is_chain_of_poset([R(set([3, 1, 2])), R(set([1, 2])), R(set([1]))]) + sage: R.is_chain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 2])), R(set([1]))]) True sage: from sage.categories.examples.posets import PositiveIntegersOrderedByDivisibilityFacade @@ -632,7 +642,8 @@ def is_antichain_of_poset(self, o): EXAMPLES:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True, linear_extension=True) + sage: P = Poset((divisors(12), attrcall("divides")), + ....: facade=True, linear_extension=True) sage: sorted(P.list()) [1, 2, 3, 4, 6, 12] sage: P.is_antichain_of_poset([1, 3]) @@ -653,9 +664,11 @@ def is_antichain_of_poset(self, o): False sage: P.is_antichain_of_poset([6, 4]) True - sage: P.is_antichain_of_poset(i for i in divisors(12) if (2 < i and i < 6)) + sage: P.is_antichain_of_poset(i for i in divisors(12) + ....: if (2 < i and i < 6)) True - sage: P.is_antichain_of_poset(i for i in divisors(12) if (2 <= i and i < 6)) + sage: P.is_antichain_of_poset(i for i in divisors(12) + ....: if (2 <= i and i < 6)) False sage: Q = Poset({2: [3, 1], 3: [4], 1: [4]}) @@ -680,9 +693,11 @@ def is_antichain_of_poset(self, o): sage: from sage.categories.examples.posets import FiniteSetsOrderedByInclusion sage: R = FiniteSetsOrderedByInclusion() - sage: R.is_antichain_of_poset([R(set([3, 1, 2])), R(set([1, 4])), R(set([4, 5]))]) + sage: R.is_antichain_of_poset([R(set([3, 1, 2])), + ....: R(set([1, 4])), R(set([4, 5]))]) True - sage: R.is_antichain_of_poset([R(set([3, 1, 2, 4])), R(set([1, 4])), R(set([4, 5]))]) + sage: R.is_antichain_of_poset([R(set([3, 1, 2, 4])), + ....: R(set([1, 4])), R(set([4, 5]))]) False """ return all(not self.lt(x,y) for x in o for y in o) diff --git a/src/sage/categories/primer.py b/src/sage/categories/primer.py index 7ecc75e711a..3f80e2f0756 100644 --- a/src/sage/categories/primer.py +++ b/src/sage/categories/primer.py @@ -75,15 +75,15 @@ Similar objects should behave similarly:: - sage: Permutations(5).cardinality() + sage: Permutations(5).cardinality() # optional - sage.combinat 120 - sage: GL(2,2).cardinality() + sage: GL(2,2).cardinality() # optional - sage.groups 6 - sage: A = random_matrix(ZZ,6,3,x=7) - sage: L = LatticePolytope(A.rows()) - sage: L.npoints() # oops! # random + sage: A = random_matrix(ZZ, 6, 3, x=7) # optional - sage.modules + sage: L = LatticePolytope(A.rows()) # optional - sage.geometry.polyhedron + sage: L.npoints() # oops! # random # optional - sage.geometry.polyhedron 37 - How to ensure robustness? @@ -98,8 +98,9 @@ :: - sage: m = random_matrix(QQ, 4, algorithm='echelonizable', rank=3, upper_bound=60) - sage: m^8 == m*m*m*m*m*m*m*m == ((m^2)^2)^2 + sage: m = random_matrix(QQ, 4, algorithm='echelonizable', # optional - sage.modules + ....: rank=3, upper_bound=60) + sage: m^8 == m*m*m*m*m*m*m*m == ((m^2)^2)^2 # optional - sage.modules True We want to implement binary powering only once, as *generic* code @@ -130,7 +131,7 @@ That's our bookshelf! And it's used in many places:: - sage: GL(2,ZZ) in Monoids() + sage: GL(2, ZZ) in Monoids() # optional - sage.modules True sage: NN in Monoids() True @@ -168,20 +169,20 @@ Each set in Sage knows which bookshelf of generic algorithms it can use, that is to which category it belongs:: - sage: G = GL(2,ZZ) - sage: G.category() + sage: G = GL(2, ZZ) # optional - sage.modules + sage: G.category() # optional - sage.modules Category of infinite groups In fact a group is a semigroup, and Sage knows about this:: sage: Groups().is_subcategory(Semigroups()) True - sage: G in Semigroups() + sage: G in Semigroups() # optional - sage.modules True Altogether, our group gets algorithms from a bunch of bookshelves:: - sage: G.categories() + sage: G.categories() # optional - sage.modules [Category of infinite groups, Category of groups, Category of monoids, ..., Category of magmas, @@ -189,19 +190,19 @@ Those can be viewed graphically:: - sage: g = Groups().category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + sage: g = Groups().category_graph() # optional - sage.modules sage.graphs + sage: g.set_latex_options(format="dot2tex") # optional - sage.modules sage.graphs + sage: view(g) # not tested # optional - sage.modules sage.graphs sage.plot In case ``dot2tex`` is not available, you can use instead:: - sage: g.show(vertex_shape=None, figsize=20) + sage: g.show(vertex_shape=None, figsize=20) # optional - sage.modules sage.graphs sage.plot Here is an overview of all categories in Sage:: - sage: g = sage.categories.category.category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + sage: g = sage.categories.category.category_graph() # optional - sage.modules sage.graphs + sage: g.set_latex_options(format="dot2tex") # optional - sage.modules sage.graphs + sage: view(g) # not tested # optional - sage.modules sage.graphs sage.plot Wrap-up: generic algorithms in Sage are organized in a hierarchy of bookshelves modelled upon the usual hierarchy of categories provided @@ -370,9 +371,9 @@ Category of sets with partial maps, Category of objects] - sage: g = EuclideanDomains().category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + sage: g = EuclideanDomains().category_graph() # optional - sage.graphs + sage: g.set_latex_options(format="dot2tex") # optional - sage.graphs + sage: view(g) # not tested # optional - sage.graphs sage.plot A bit of help from computer science =================================== @@ -406,11 +407,11 @@ class implements: sage: i.factor() 2^2 * 3 - sage: x = var('x') # optional - sage.symbolic - sage: p = 6*x^2 + 12*x + 6 # optional - sage.symbolic - sage: type(p) # optional - sage.symbolic + sage: x = var('x') # optional - sage.symbolic + sage: p = 6*x^2 + 12*x + 6 # optional - sage.symbolic + sage: type(p) # optional - sage.symbolic - sage: p.factor() # optional - sage.symbolic + sage: p.factor() # optional - sage.symbolic 6*(x + 1)^2 sage: R. = PolynomialRing(QQ, sparse=True) @@ -466,9 +467,9 @@ class implements: hierarchy of categories (bookshelves). Here is for example a piece of the hierarchy of classes for an element of a group of permutations:: - sage: P = Permutations(4) - sage: m = P.an_element() - sage: for cls in m.__class__.mro(): print(cls) + sage: P = Permutations(4) # optional - sage.combinat + sage: m = P.an_element() # optional - sage.combinat + sage: for cls in m.__class__.mro(): print(cls) # optional - sage.combinat @@ -486,9 +487,9 @@ class implements: The full hierarchy is best viewed graphically:: - sage: g = class_graph(m.__class__) - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + sage: g = class_graph(m.__class__) # optional - sage.combinat sage.graphs + sage: g.set_latex_options(format="dot2tex") # optional - sage.combinat sage.graphs + sage: view(g) # not tested # optional - sage.combinat sage.graphs sage.plot Parallel hierarchy of classes for parents ----------------------------------------- @@ -540,10 +541,10 @@ class implements: categories and parallel to that we had seen for the elements. This is best viewed graphically:: - sage: g = class_graph(m.__class__) - sage: g.relabel(lambda x: x.replace("_",r"\_")) - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + sage: g = class_graph(m.__class__) # optional - sage.modules sage.graphs + sage: g.relabel(lambda x: x.replace("_",r"\_")) # optional - sage.modules sage.graphs + sage: g.set_latex_options(format="dot2tex") # optional - sage.modules sage.graphs + sage: view(g) # not tested # optional - sage.modules sage.graphs sage.plot .. NOTE:: @@ -724,7 +725,7 @@ class SubcategoryMethods: Note that categories themselves are naturally modelled by instances because they can have operations of their own. An important one is:: - sage: Groups().example() + sage: Groups().example() # optional - sage.modules General Linear Group of degree 4 over Rational Field which gives an example of object of the category. Besides illustrating @@ -1017,16 +1018,17 @@ class SubcategoryMethods: example, permutation groups are by default in the category of finite permutation groups (no surprise):: - sage: P = PermutationGroup([[(1,2,3)]]); P + sage: P = PermutationGroup([[(1,2,3)]]); P # optional - sage.combinat Permutation Group with generators [(1,2,3)] - sage: P.category() + sage: P.category() # optional - sage.combinat Category of finite enumerated permutation groups In this case, the group is commutative, so we can specify this:: - sage: P = PermutationGroup([[(1,2,3)]], category=PermutationGroups().Finite().Commutative()); P + sage: P = PermutationGroup([[(1,2,3)]], # optional - sage.combinat + ....: category=PermutationGroups().Finite().Commutative()); P Permutation Group with generators [(1,2,3)] - sage: P.category() + sage: P.category() # optional - sage.combinat Category of finite enumerated commutative permutation groups This feature can even be used, typically in experimental code, to add @@ -1041,18 +1043,18 @@ class SubcategoryMethods: ....: class ElementMethods: ....: def bar(self): print("bar") - sage: P = PermutationGroup([[(1,2,3)]], category=Foos()) - sage: P.foo() + sage: P = PermutationGroup([[(1,2,3)]], category=Foos()) # optional - sage.combinat + sage: P.foo() # optional - sage.combinat foo - sage: p = P.an_element() - sage: p.bar() + sage: p = P.an_element() # optional - sage.combinat + sage: p.bar() # optional - sage.combinat bar In the long run, it would be thinkable to use this idiom to implement forgetful functors; for example the above group could be constructed as a plain set with:: - sage: P = PermutationGroup([[(1,2,3)]], category=Sets()) # todo: not implemented + sage: P = PermutationGroup([[(1,2,3)]], category=Sets()) # todo: not implemented # optional - sage.combinat At this stage though, this is still to be explored for robustness and practicality. For now, most parents that accept a category argument @@ -1100,9 +1102,9 @@ class SubcategoryMethods: Let for example `A` and `B` be two parents, and let us construct the Cartesian product `A \times B \times B`:: - sage: A = AlgebrasWithBasis(QQ).example(); A.rename("A") - sage: B = HopfAlgebrasWithBasis(QQ).example(); B.rename("B") - sage: C = cartesian_product([A, B, B]); C + sage: A = AlgebrasWithBasis(QQ).example(); A.rename("A") # optional - sage.combinat sage.modules + sage: B = HopfAlgebrasWithBasis(QQ).example(); B.rename("B") # optional - sage.combinat sage.modules + sage: C = cartesian_product([A, B, B]); C # optional - sage.combinat sage.modules A (+) B (+) B In which category should this new parent be? Since `A` and `B` are @@ -1111,14 +1113,14 @@ class SubcategoryMethods: are monoids, `A \times B \times B` is naturally endowed with a monoid structure for pointwise multiplication:: - sage: C in Monoids() + sage: C in Monoids() # optional - sage.combinat sage.modules True the unit being the Cartesian product of the units of the operands:: - sage: C.one() + sage: C.one() # optional - sage.combinat sage.modules B[(0, word: )] + B[(1, ())] + B[(2, ())] - sage: cartesian_product([A.one(), B.one(), B.one()]) + sage: cartesian_product([A.one(), B.one(), B.one()]) # optional - sage.combinat sage.modules B[(0, word: )] + B[(1, ())] + B[(2, ())] The pointwise product can be implemented generically for all magmas @@ -1126,7 +1128,7 @@ class SubcategoryMethods: constructed as Cartesian products. It's thus implemented in the :class:`Magmas` category:: - sage: C.product.__module__ + sage: C.product.__module__ # optional - sage.combinat sage.modules 'sage.categories.magmas' More specifically, keeping on using nested classes to structure the @@ -1158,7 +1160,7 @@ class naming and introspection. Sage currently works around the Let us now look at the categories of ``C``:: - sage: C.categories() + sage: C.categories() # optional - sage.combinat sage.modules [Category of finite dimensional Cartesian products of algebras with basis over Rational Field, ... Category of Cartesian products of algebras over Rational Field, ... Category of Cartesian products of semigroups, Category of semigroups, ... @@ -1369,13 +1371,14 @@ class naming and introspection. Sage currently works around the sage: C = (Magmas() & AdditiveMagmas()).Distributive(); C Category of distributive magmas and additive magmas - sage: C.Associative().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().AdditiveInverse() + sage: CAA = C.Associative().AdditiveAssociative() + sage: CAA.AdditiveCommutative().AdditiveUnital().AdditiveInverse() Category of rngs - sage: C.Associative().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().Unital() + sage: CAA.AdditiveCommutative().AdditiveUnital().Unital() Category of semirings - sage: C.Associative().AdditiveAssociative().AdditiveCommutative().AdditiveUnital().AdditiveInverse().Unital() + sage: CAA.AdditiveCommutative().AdditiveUnital().AdditiveInverse().Unital() Category of rings sage: Rings().Division() @@ -1389,9 +1392,9 @@ class naming and introspection. Sage currently works around the or for more advanced categories:: - sage: g = HopfAlgebras(QQ).WithBasis().Graded().Connected().category_graph() - sage: g.set_latex_options(format="dot2tex") - sage: view(g) # not tested + sage: g = HopfAlgebras(QQ).WithBasis().Graded().Connected().category_graph() # optional - sage.graphs + sage: g.set_latex_options(format="dot2tex") # optional - sage.graphs + sage: view(g) # not tested # optional - sage.graphs sage.plot Difference between axioms and regressive covariant functorial constructions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1413,7 +1416,7 @@ class naming and introspection. Sage currently works around the A finite dimensional algebra is also a finite dimensional module:: - sage: Algebras(QQ).FiniteDimensional().is_subcategory( Modules(QQ).FiniteDimensional() ) + sage: Algebras(QQ).FiniteDimensional().is_subcategory(Modules(QQ).FiniteDimensional()) True Similarly a graded algebra is also a graded module:: diff --git a/src/sage/categories/principal_ideal_domains.py b/src/sage/categories/principal_ideal_domains.py index 2821fdf0ef6..fa8b2632cc1 100644 --- a/src/sage/categories/principal_ideal_domains.py +++ b/src/sage/categories/principal_ideal_domains.py @@ -70,22 +70,22 @@ def _test_gcd_vs_xgcd(self, **options): sage: ZZ._test_gcd_vs_xgcd() sage: QQ._test_gcd_vs_xgcd() sage: QQ['x']._test_gcd_vs_xgcd() - sage: QQbar['x']._test_gcd_vs_xgcd() + sage: QQbar['x']._test_gcd_vs_xgcd() # optional - sage.rings.number_field sage: RR._test_gcd_vs_xgcd() sage: RR['x']._test_gcd_vs_xgcd() A slightly more involved example of polynomial ring with a non UFD base ring:: - sage: K = QuadraticField(5) - sage: O = K.maximal_order() - sage: O in UniqueFactorizationDomains() + sage: K = QuadraticField(5) # optional - sage.rings.number_field + sage: O = K.maximal_order() # optional - sage.rings.number_field + sage: O in UniqueFactorizationDomains() # optional - sage.rings.number_field False - sage: R = PolynomialRing(O, 'x') - sage: F = R.fraction_field() - sage: F in PrincipalIdealDomains() + sage: R = PolynomialRing(O, 'x') # optional - sage.rings.number_field + sage: F = R.fraction_field() # optional - sage.rings.number_field + sage: F in PrincipalIdealDomains() # optional - sage.rings.number_field True - sage: F._test_gcd_vs_xgcd() + sage: F._test_gcd_vs_xgcd() # optional - sage.rings.number_field """ tester = self._tester(**options) elts = list(tester.some_elements()) diff --git a/src/sage/categories/pushout.py b/src/sage/categories/pushout.py index 71c20a6d82b..1f52b2c3e5a 100644 --- a/src/sage/categories/pushout.py +++ b/src/sage/categories/pushout.py @@ -107,17 +107,20 @@ class ConstructionFunctor(Functor): sage: P. = ZZ[] sage: F = P.construction()[0]; F MPoly[x,y] - sage: A. = GF(5)[] - sage: f = A.hom([a+b,a-b],A) - sage: F(A) - Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 - sage: F(f) - Ring endomorphism of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 + sage: A. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = A.hom([a + b, a - b], A) # optional - sage.rings.finite_rings + sage: F(A) # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Finite Field of size 5 + sage: F(f) # optional - sage.rings.finite_rings + Ring endomorphism of Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Finite Field of size 5 Defn: Induced from base ring by - Ring endomorphism of Multivariate Polynomial Ring in a, b over Finite Field of size 5 + Ring endomorphism of Multivariate Polynomial Ring in a, b + over Finite Field of size 5 Defn: a |--> a + b b |--> a - b - sage: F(f)(F(A)(x)*a) + sage: F(f)(F(A)(x)*a) # optional - sage.rings.finite_rings (a + b)*x """ @@ -430,22 +433,27 @@ class CompositeConstructionFunctor(ConstructionFunctor): EXAMPLES:: sage: from sage.categories.pushout import CompositeConstructionFunctor - sage: F = CompositeConstructionFunctor(QQ.construction()[0],ZZ['x'].construction()[0],QQ.construction()[0],ZZ['y'].construction()[0]) + sage: F = CompositeConstructionFunctor(QQ.construction()[0], ZZ['x'].construction()[0], + ....: QQ.construction()[0], ZZ['y'].construction()[0]) sage: F Poly[y](FractionField(Poly[x](FractionField(...)))) sage: F == loads(dumps(F)) True sage: F == CompositeConstructionFunctor(*F.all) True - sage: F(GF(2)['t']) - Univariate Polynomial Ring in y over Fraction Field of Univariate Polynomial Ring in x over Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) + sage: F(GF(2)['t']) # optional - sage.rings.finite_rings + Univariate Polynomial Ring in y + over Fraction Field of Univariate Polynomial Ring in x + over Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) """ def __init__(self, *args): """ TESTS:: sage: from sage.categories.pushout import CompositeConstructionFunctor - sage: F = CompositeConstructionFunctor(QQ.construction()[0],ZZ['x'].construction()[0],QQ.construction()[0],ZZ['y'].construction()[0]) + sage: F = CompositeConstructionFunctor(QQ.construction()[0], ZZ['x'].construction()[0], + ....: QQ.construction()[0], ZZ['y'].construction()[0]) sage: F Poly[y](FractionField(Poly[x](FractionField(...)))) sage: F == CompositeConstructionFunctor(*F.all) @@ -587,7 +595,10 @@ def expand(self): EXAMPLES:: sage: from sage.categories.pushout import CompositeConstructionFunctor - sage: F = CompositeConstructionFunctor(QQ.construction()[0],ZZ['x'].construction()[0],QQ.construction()[0],ZZ['y'].construction()[0]) + sage: F = CompositeConstructionFunctor(QQ.construction()[0], + ....: ZZ['x'].construction()[0], + ....: QQ.construction()[0], + ....: ZZ['y'].construction()[0]) sage: F Poly[y](FractionField(Poly[x](FractionField(...)))) sage: prod(F.expand()) == F @@ -801,32 +812,32 @@ class PolynomialFunctor(ConstructionFunctor): EXAMPLES:: sage: P = ZZ['t'].construction()[0] - sage: P(GF(3)) + sage: P(GF(3)) # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 3 - sage: P == loads(dumps(P)) + sage: P == loads(dumps(P)) # optional - sage.rings.finite_rings True - sage: R. = GF(5)[] - sage: f = R.hom([x+2*y,3*x-y],R) - sage: P(f)((x+y)*P(R).0) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = R.hom([x + 2*y, 3*x - y], R) # optional - sage.rings.finite_rings + sage: P(f)((x+y) * P(R).0) # optional - sage.rings.finite_rings (-x + y)*t By :trac:`9944`, the construction functor distinguishes sparse and dense polynomial rings. Before, the following example failed:: - sage: R. = PolynomialRing(GF(5), sparse=True) - sage: F,B = R.construction() - sage: F(B) is R + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings + sage: F, B = R.construction() # optional - sage.rings.finite_rings + sage: F(B) is R # optional - sage.rings.finite_rings True sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.rings.finite_rings False - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.rings.finite_rings False - sage: S.0 + R.0 + sage: S.0 + R.0 # optional - sage.rings.finite_rings 2*x - sage: (S.0 + R.0).parent() + sage: (S.0 + R.0).parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 - sage: (S.0 + R.0).parent().is_sparse() + sage: (S.0 + R.0).parent().is_sparse() # optional - sage.rings.finite_rings False """ @@ -838,7 +849,7 @@ def __init__(self, var, multi_variate=False, sparse=False, implementation=None): sage: from sage.categories.pushout import PolynomialFunctor sage: P = PolynomialFunctor('x') - sage: P(GF(3)) + sage: P(GF(3)) # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 3 There is an optional parameter ``multi_variate``, but @@ -865,7 +876,7 @@ def _apply_functor(self, R): TESTS:: sage: P = ZZ['x'].construction()[0] - sage: P(GF(3)) # indirect doctest + sage: P(GF(3)) # indirect doctest # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 3 """ @@ -882,7 +893,7 @@ def _apply_functor_to_morphism(self, f): TESTS:: sage: P = ZZ['x'].construction()[0] - sage: P(ZZ.hom(GF(3))) # indirect doctest + sage: P(ZZ.hom(GF(3))) # indirect doctest # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Univariate Polynomial Ring in x over Finite Field of size 3 @@ -992,17 +1003,19 @@ class MultiPolynomialFunctor(ConstructionFunctor): sage: P. = ZZ[] sage: F = P.construction()[0]; F MPoly[x,y] - sage: A. = GF(5)[] - sage: F(A) - Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 - sage: f = A.hom([a+b,a-b],A) - sage: F(f) - Ring endomorphism of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Finite Field of size 5 + sage: A. = GF(5)[] # optional - sage.rings.finite_rings + sage: F(A) # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Finite Field of size 5 + sage: f = A.hom([a+b, a-b], A) # optional - sage.rings.finite_rings + sage: F(f) # optional - sage.rings.finite_rings + Ring endomorphism of Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Finite Field of size 5 Defn: Induced from base ring by Ring endomorphism of Multivariate Polynomial Ring in a, b over Finite Field of size 5 Defn: a |--> a + b b |--> a - b - sage: F(f)(F(A)(x)*a) + sage: F(f)(F(A)(x)*a) # optional - sage.rings.finite_rings (a + b)*x """ @@ -1203,7 +1216,7 @@ class InfinitePolynomialFunctor(ConstructionFunctor): sage: B. = PolynomialRing(QQ, order='lex') sage: B.construction() (MPoly[x,y,a_3,a_1], Rational Field) - sage: A.construction()[0]*B.construction()[0] + sage: A.construction()[0] * B.construction()[0] InfPoly{[a,b], "lex", "dense"}(MPoly[x,y](...)) Apparently the variables `a_1,a_3` of the polynomial ring are merged with the variables @@ -1211,7 +1224,8 @@ class InfinitePolynomialFunctor(ConstructionFunctor): However, if the polynomial ring was given a different ordering, merging would not be allowed, resulting in a name conflict:: - sage: A.construction()[0]*PolynomialRing(QQ,names=['x','y','a_3','a_1']).construction()[0] + sage: R = PolynomialRing(QQ, names=['x','y','a_3','a_1']) + sage: A.construction()[0] * R.construction()[0] Traceback (most recent call last): ... CoercionException: Incompatible term orders lex, degrevlex @@ -1219,25 +1233,30 @@ class InfinitePolynomialFunctor(ConstructionFunctor): In an infinite polynomial ring with generator `a_\ast`, the variable `a_3` will always be greater than the variable `a_1`. Hence, the orders are incompatible in the next example as well:: - sage: A.construction()[0]*PolynomialRing(QQ,names=['x','y','a_1','a_3'], order='lex').construction()[0] + sage: R = PolynomialRing(QQ, names=['x','y','a_1','a_3'], order='lex') + sage: A.construction()[0] * R.construction()[0] Traceback (most recent call last): ... - CoercionException: Overlapping variables (('a', 'b'),['a_1', 'a_3']) are incompatible + CoercionException: Overlapping variables (('a', 'b'),['a_1', 'a_3']) + are incompatible Another requirement is that after merging the order of the remaining variables must be unique. This is not the case in the following example, since it is not clear whether the variables `x,y` should be greater or smaller than the variables `b_\ast`:: - sage: A.construction()[0]*PolynomialRing(QQ,names=['a_3','a_1','x','y'], order='lex').construction()[0] + sage: R = PolynomialRing(QQ, names=['a_3','a_1','x','y'], order='lex') + sage: A.construction()[0] * R.construction()[0] Traceback (most recent call last): ... - CoercionException: Overlapping variables (('a', 'b'),['a_3', 'a_1']) are incompatible + CoercionException: Overlapping variables (('a', 'b'),['a_3', 'a_1']) + are incompatible Since the construction functors are actually used to construct infinite polynomial rings, the following result is no surprise:: sage: C. = InfinitePolynomialRing(B); C - Infinite polynomial ring in a, b over Multivariate Polynomial Ring in x, y over Rational Field + Infinite polynomial ring in a, b + over Multivariate Polynomial Ring in x, y over Rational Field There is also an overlap in the next example:: @@ -1472,8 +1491,8 @@ def merge(self, other): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: Y. = InfinitePolynomialRing(QQ,order='degrevlex') + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: Y. = InfinitePolynomialRing(QQ, order='degrevlex') sage: X.construction() [InfPoly{[x,y], "lex", "sparse"}, Rational Field] sage: Y.construction() @@ -1525,11 +1544,13 @@ def expand(self): EXAMPLES:: - sage: F = InfinitePolynomialRing(QQ, ['x','y'],order='degrevlex').construction()[0]; F + sage: A = InfinitePolynomialRing(QQ, ['x','y'], order='degrevlex') + sage: F = A.construction()[0]; F InfPoly{[x,y], "degrevlex", "dense"} sage: F.expand() [InfPoly{[y], "degrevlex", "dense"}, InfPoly{[x], "degrevlex", "dense"}] - sage: F = InfinitePolynomialRing(QQ, ['x','y','z'],order='degrevlex').construction()[0]; F + sage: A = InfinitePolynomialRing(QQ, ['x','y','z'], order='degrevlex') + sage: F = A.construction()[0]; F InfPoly{[x,y,z], "degrevlex", "dense"} sage: F.expand() [InfPoly{[z], "degrevlex", "dense"}, @@ -1551,23 +1572,27 @@ class MatrixFunctor(ConstructionFunctor): EXAMPLES:: - sage: MS = MatrixSpace(ZZ,2, 3) - sage: F = MS.construction()[0]; F + sage: MS = MatrixSpace(ZZ, 2, 3) # optional - sage.modules + sage: F = MS.construction()[0]; F # optional - sage.modules MatrixFunctor - sage: MS = MatrixSpace(ZZ,2) - sage: F = MS.construction()[0]; F + sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: F = MS.construction()[0]; F # optional - sage.modules MatrixFunctor - sage: P. = QQ[] - sage: R = F(P); R - Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field - sage: f = P.hom([x+y,x-y],P); F(f) - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field + sage: P. = QQ[] # optional - sage.modules + sage: R = F(P); R # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices + over Multivariate Polynomial Ring in x, y over Rational Field + sage: f = P.hom([x+y, x-y], P); F(f) # optional - sage.modules + Ring endomorphism + of Full MatrixSpace of 2 by 2 dense matrices + over Multivariate Polynomial Ring in x, y over Rational Field Defn: Induced from base ring by - Ring endomorphism of Multivariate Polynomial Ring in x, y over Rational Field + Ring endomorphism + of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x + y y |--> x - y - sage: M = R([x,y,x*y,x+y]) - sage: F(f)(M) + sage: M = R([x, y, x*y, x + y]) # optional - sage.modules + sage: F(f)(M) # optional - sage.modules [ x + y x - y] [x^2 - y^2 2*x] @@ -1579,21 +1604,21 @@ def __init__(self, nrows, ncols, is_sparse=False): TESTS:: sage: from sage.categories.pushout import MatrixFunctor - sage: F = MatrixFunctor(2,3) - sage: F == MatrixSpace(ZZ,2,3).construction()[0] + sage: F = MatrixFunctor(2, 3) # optional - sage.modules + sage: F == MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules True - sage: F.codomain() + sage: F.codomain() # optional - sage.modules Category of commutative additive groups - sage: R = MatrixSpace(ZZ,2,2).construction()[0] - sage: R.codomain() + sage: R = MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules + sage: R.codomain() # optional - sage.modules Category of rings - sage: F(ZZ) + sage: F(ZZ) # optional - sage.modules Full MatrixSpace of 2 by 3 dense matrices over Integer Ring - sage: F(ZZ) in F.codomain() + sage: F(ZZ) in F.codomain() # optional - sage.modules True - sage: R(GF(2)) + sage: R(GF(2)) # optional - sage.rings.finite_rings sage.modules Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 2 - sage: R(GF(2)) in R.codomain() + sage: R(GF(2)) in R.codomain() # optional - sage.rings.finite_rings sage.modules True """ if nrows == ncols: @@ -1613,10 +1638,10 @@ def _apply_functor(self, R): The following is a test against a bug discussed at :trac:`8800`:: - sage: F = MatrixSpace(ZZ,2,3).construction()[0] - sage: F(RR) # indirect doctest + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F(RR) # indirect doctest # optional - sage.modules Full MatrixSpace of 2 by 3 dense matrices over Real Field with 53 bits of precision - sage: F(RR) in F.codomain() + sage: F(RR) in F.codomain() # optional - sage.modules True """ @@ -1627,10 +1652,10 @@ def __eq__(self, other): """ TESTS:: - sage: F = MatrixSpace(ZZ,2,3).construction()[0] - sage: F == loads(dumps(F)) + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F == loads(dumps(F)) # optional - sage.modules True - sage: F == MatrixSpace(ZZ,2,2).construction()[0] + sage: F == MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules False """ if isinstance(other, MatrixFunctor): @@ -1643,10 +1668,10 @@ def __ne__(self, other): EXAMPLES:: - sage: F = MatrixSpace(ZZ,2,3).construction()[0] - sage: F != loads(dumps(F)) + sage: F = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F != loads(dumps(F)) # optional - sage.modules False - sage: F != MatrixSpace(ZZ,2,2).construction()[0] + sage: F != MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules True """ return not (self == other) @@ -1661,20 +1686,20 @@ def merge(self, other): EXAMPLES:: - sage: F1 = MatrixSpace(ZZ,2,2).construction()[0] - sage: F2 = MatrixSpace(ZZ,2,3).construction()[0] - sage: F3 = MatrixSpace(ZZ,2,2,sparse=True).construction()[0] - sage: F1.merge(F2) - sage: F1.merge(F3) + sage: F1 = MatrixSpace(ZZ, 2, 2).construction()[0] # optional - sage.modules + sage: F2 = MatrixSpace(ZZ, 2, 3).construction()[0] # optional - sage.modules + sage: F3 = MatrixSpace(ZZ, 2, 2, sparse=True).construction()[0] # optional - sage.modules + sage: F1.merge(F2) # optional - sage.modules + sage: F1.merge(F3) # optional - sage.modules MatrixFunctor - sage: F13 = F1.merge(F3) - sage: F13.is_sparse + sage: F13 = F1.merge(F3) # optional - sage.modules + sage: F13.is_sparse # optional - sage.modules False - sage: F1.is_sparse + sage: F1.is_sparse # optional - sage.modules False - sage: F3.is_sparse + sage: F3.is_sparse # optional - sage.modules True - sage: F3.merge(F3).is_sparse + sage: F3.merge(F3).is_sparse # optional - sage.modules True """ @@ -1698,16 +1723,18 @@ class LaurentPolynomialFunctor(ConstructionFunctor): Univariate Laurent Polynomial Ring in t over Rational Field sage: K. = LaurentPolynomialRing(ZZ) sage: F(K) - Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in x over Integer Ring + Univariate Laurent Polynomial Ring in t + over Univariate Laurent Polynomial Ring in x over Integer Ring sage: P. = ZZ[] - sage: f = P.hom([x+2*y,3*x-y],P) + sage: f = P.hom([x + 2*y, 3*x - y],P) sage: F(f) - Ring endomorphism of Univariate Laurent Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Integer Ring + Ring endomorphism of Univariate Laurent Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by Ring endomorphism of Multivariate Polynomial Ring in x, y over Integer Ring Defn: x |--> x + 2*y y |--> 3*x - y - sage: F(f)(x*F(P).gen()^-2+y*F(P).gen()^3) + sage: F(f)(x*F(P).gen()^-2 + y*F(P).gen()^3) (x + 2*y)*t^-2 + (3*x - y)*t^3 """ @@ -1824,10 +1851,11 @@ def merge(self, other): sage: F2 = LaurentPolynomialFunctor('t', multi_variate=True) sage: F1.merge(F2) LaurentPolynomialFunctor - sage: F1.merge(F2)(LaurentPolynomialRing(GF(2),'a')) + sage: F1.merge(F2)(LaurentPolynomialRing(GF(2), 'a')) # optional - sage.rings.finite_rings Multivariate Laurent Polynomial Ring in a, t over Finite Field of size 2 - sage: F1.merge(F1)(LaurentPolynomialRing(GF(2),'a')) - Univariate Laurent Polynomial Ring in t over Univariate Laurent Polynomial Ring in a over Finite Field of size 2 + sage: F1.merge(F1)(LaurentPolynomialRing(GF(2), 'a')) # optional - sage.rings.finite_rings + Univariate Laurent Polynomial Ring in t over + Univariate Laurent Polynomial Ring in a over Finite Field of size 2 """ if self == other or isinstance(other, PolynomialFunctor) and self.var == other.var: @@ -1842,11 +1870,12 @@ class VectorFunctor(ConstructionFunctor): EXAMPLES:: - sage: F = (ZZ^3).construction()[0] - sage: F + sage: F = (ZZ^3).construction()[0] # optional - sage.modules + sage: F # optional - sage.modules VectorFunctor - sage: F(GF(2)['t']) - Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) + sage: F(GF(2)['t']) # optional - sage.rings.finite_rings sage.modules + Ambient free module of rank 3 + over the principal ideal domain Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) """ rank = 10 # ranking of functor, not rank of module. # This coincides with the rank of the matrix construction functor, but this is OK since they cannot both be applied in any order @@ -1866,21 +1895,21 @@ def __init__(self, n=None, is_sparse=False, inner_product_matrix=None, *, TESTS:: sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: F1.domain() + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules + sage: F1.domain() # optional - sage.modules Category of commutative rings - sage: F1.codomain() + sage: F1.codomain() # optional - sage.modules Category of commutative additive groups - sage: M1 = F1(ZZ) - sage: M1.is_sparse() + sage: M1 = F1(ZZ) # optional - sage.modules + sage: M1.is_sparse() # optional - sage.modules False - sage: v = M1([3, 2, 1]) - sage: v*Matrix(3,3,range(9))*v.column() + sage: v = M1([3, 2, 1]) # optional - sage.modules + sage: v * Matrix(3, 3, range(9)) * v.column() # optional - sage.modules (96) - sage: v.inner_product(v) + sage: v.inner_product(v) # optional - sage.modules 96 sage: F2 = VectorFunctor(3, is_sparse=True) - sage: M2 = F2(QQ); M2; M2.is_sparse() + sage: M2 = F2(QQ); M2; M2.is_sparse() # optional - sage.modules Sparse vector space of dimension 3 over Rational Field True @@ -1908,28 +1937,28 @@ def _apply_functor(self, R): TESTS:: sage: from sage.categories.pushout import VectorFunctor, pushout - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: M1 = F1(ZZ) # indirect doctest - sage: M1.is_sparse() + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules + sage: M1 = F1(ZZ) # indirect doctest # optional - sage.modules + sage: M1.is_sparse() # optional - sage.modules False - sage: v = M1([3, 2, 1]) - sage: v*Matrix(3,3,range(9))*v.column() + sage: v = M1([3, 2, 1]) # optional - sage.modules + sage: v * Matrix(3, 3, range(9)) * v.column() # optional - sage.modules (96) - sage: v.inner_product(v) + sage: v.inner_product(v) # optional - sage.modules 96 - sage: F2 = VectorFunctor(3, is_sparse=True) - sage: M2 = F2(QQ); M2; M2.is_sparse() + sage: F2 = VectorFunctor(3, is_sparse=True) # optional - sage.modules + sage: M2 = F2(QQ); M2; M2.is_sparse() # optional - sage.modules Sparse vector space of dimension 3 over Rational Field True - sage: v = M2([3, 2, 1]) - sage: v.inner_product(v) + sage: v = M2([3, 2, 1]) # optional - sage.modules + sage: v.inner_product(v) # optional - sage.modules 14 - sage: M = FreeModule(ZZ, 4, with_basis=None, name='M') - sage: latex(M) + sage: M = FreeModule(ZZ, 4, with_basis=None, name='M') # optional - sage.modules + sage: latex(M) # optional - sage.modules M - sage: M_QQ = pushout(M, QQ) - sage: latex(M_QQ) + sage: M_QQ = pushout(M, QQ) # optional - sage.modules + sage: latex(M_QQ) # optional - sage.modules M \otimes \Bold{Q} """ @@ -1957,10 +1986,10 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: F = (ZZ^3).construction()[0] + sage: F = (ZZ^3).construction()[0] # optional - sage.modules sage: P. = ZZ[] - sage: f = P.hom([x+2*y,3*x-y],P) - sage: F(f) # indirect doctest + sage: f = P.hom([x + 2*y, 3*x - y], P) + sage: F(f) # indirect doctest # optional - sage.modules Traceback (most recent call last): ... NotImplementedError: Cannot create induced morphisms of free modules yet @@ -1975,13 +2004,13 @@ def __eq__(self, other): TESTS:: sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: F2 = (ZZ^3).construction()[0] - sage: F1 == F2 + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules + sage: F2 = (ZZ^3).construction()[0] # optional - sage.modules + sage: F1 == F2 # optional - sage.modules False - sage: F1(QQ) == F2(QQ) + sage: F1(QQ) == F2(QQ) # optional - sage.modules False - sage: F1 == loads(dumps(F1)) + sage: F1 == loads(dumps(F1)) # optional - sage.modules True """ if isinstance(other, VectorFunctor): @@ -2000,13 +2029,13 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.pushout import VectorFunctor - sage: F1 = VectorFunctor(3, inner_product_matrix = Matrix(3,3,range(9))) - sage: F2 = (ZZ^3).construction()[0] - sage: F1 != F2 + sage: F1 = VectorFunctor(3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules + sage: F2 = (ZZ^3).construction()[0] # optional - sage.modules + sage: F1 != F2 # optional - sage.modules True - sage: F1(QQ) != F2(QQ) + sage: F1(QQ) != F2(QQ) # optional - sage.modules True - sage: F1 != loads(dumps(F1)) + sage: F1 != loads(dumps(F1)) # optional - sage.modules False """ return not (self == other) @@ -2022,19 +2051,19 @@ def merge(self, other): Two modules without explicitly given inner product allow coercion:: - sage: M1 = QQ^3 + sage: M1 = QQ^3 # optional - sage.modules sage: P. = ZZ[] - sage: M2 = FreeModule(P,3) - sage: M1([1,1/2,1/3]) + M2([t,t^2+t,3]) # indirect doctest + sage: M2 = FreeModule(P, 3) # optional - sage.modules + sage: M1([1,1/2,1/3]) + M2([t,t^2+t,3]) # indirect doctest # optional - sage.modules (t + 1, t^2 + t + 1/2, 10/3) If only one summand has an explicit inner product, the result will be provided with it:: - sage: M3 = FreeModule(P,3, inner_product_matrix = Matrix(3,3,range(9))) - sage: M1([1,1/2,1/3]) + M3([t,t^2+t,3]) + sage: M3 = FreeModule(P, 3, inner_product_matrix=Matrix(3, 3, range(9))) # optional - sage.modules + sage: M1([1,1/2,1/3]) + M3([t,t^2+t,3]) # optional - sage.modules (t + 1, t^2 + t + 1/2, 10/3) - sage: (M1([1,1/2,1/3]) + M3([t,t^2+t,3])).parent().inner_product_matrix() + sage: (M1([1,1/2,1/3]) + M3([t,t^2+t,3])).parent().inner_product_matrix() # optional - sage.modules [0 1 2] [3 4 5] [6 7 8] @@ -2045,19 +2074,22 @@ def merge(self, other): inner product was *explicitly* requested for ``M4``. It is therefore not possible to coerce with a different inner product:: - sage: M4 = FreeModule(QQ,3, inner_product_matrix = Matrix(3,3,1)) - sage: M4 == M1 + sage: M4 = FreeModule(QQ, 3, inner_product_matrix=Matrix(3, 3, 1)) # optional - sage.modules + sage: M4 == M1 # optional - sage.modules True - sage: M4.inner_product_matrix() == M1.inner_product_matrix() + sage: M4.inner_product_matrix() == M1.inner_product_matrix() # optional - sage.modules True - sage: M4([1,1/2,1/3]) + M3([t,t^2+t,3]) # indirect doctest + sage: M4([1,1/2,1/3]) + M3([t,t^2+t,3]) # indirect doctest # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Ambient quadratic space of dimension 3 over Rational Field + TypeError: unsupported operand parent(s) for +: + 'Ambient quadratic space of dimension 3 over Rational Field Inner product matrix: [1 0 0] [0 1 0] - [0 0 1]' and 'Ambient free quadratic module of rank 3 over the integral domain Univariate Polynomial Ring in t over Integer Ring + [0 0 1]' and + 'Ambient free quadratic module of rank 3 over the integral domain + Univariate Polynomial Ring in t over Integer Ring Inner product matrix: [0 1 2] [3 4 5] @@ -2066,14 +2098,17 @@ def merge(self, other): Names are removed when they conflict:: sage: from sage.categories.pushout import VectorFunctor, pushout - sage: M_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='M_ZZx') - sage: N_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='N_ZZx') - sage: pushout(M_ZZx, QQ) - Rank-4 free module M_ZZx_base_ext over the Univariate Polynomial Ring in x over Rational Field - sage: pushout(M_ZZx, N_ZZx) - Rank-4 free module over the Univariate Polynomial Ring in x over Integer Ring - sage: pushout(pushout(M_ZZx, N_ZZx), QQ) - Rank-4 free module over the Univariate Polynomial Ring in x over Rational Field + sage: M_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='M_ZZx') # optional - sage.modules + sage: N_ZZx = FreeModule(ZZ['x'], 4, with_basis=None, name='N_ZZx') # optional - sage.modules + sage: pushout(M_ZZx, QQ) # optional - sage.modules + Rank-4 free module M_ZZx_base_ext + over the Univariate Polynomial Ring in x over Rational Field + sage: pushout(M_ZZx, N_ZZx) # optional - sage.modules + Rank-4 free module + over the Univariate Polynomial Ring in x over Integer Ring + sage: pushout(pushout(M_ZZx, N_ZZx), QQ) # optional - sage.modules + Rank-4 free module + over the Univariate Polynomial Ring in x over Rational Field """ if not isinstance(other, VectorFunctor): return None @@ -2143,14 +2178,14 @@ class SubspaceFunctor(ConstructionFunctor): EXAMPLES:: - sage: M = ZZ^3 - sage: S = M.submodule([(1,2,3),(4,5,6)]); S + sage: M = ZZ^3 # optional - sage.modules + sage: S = M.submodule([(1,2,3), (4,5,6)]); S # optional - sage.modules Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [1 2 3] [0 3 6] - sage: F = S.construction()[0] - sage: F(GF(2)^3) + sage: F = S.construction()[0] # optional - sage.modules + sage: F(GF(2)^3) # optional - sage.rings.finite_rings sage.modules Vector space of degree 3 and dimension 2 over Finite Field of size 2 User basis matrix: [1 0 1] @@ -2172,9 +2207,9 @@ def __init__(self, basis): TESTS:: sage: from sage.categories.pushout import SubspaceFunctor - sage: M = ZZ^3 - sage: F = SubspaceFunctor([M([1,2,3]),M([4,5,6])]) - sage: F(GF(5)^3) + sage: M = ZZ^3 # optional - sage.modules + sage: F = SubspaceFunctor([M([1,2,3]), M([4,5,6])]) # optional - sage.modules + sage: F(GF(5)^3) # optional - sage.rings.finite_rings sage.modules Vector space of degree 3 and dimension 2 over Finite Field of size 5 User basis matrix: [1 2 3] @@ -2194,14 +2229,14 @@ def _apply_functor(self, ambient): TESTS:: - sage: M = ZZ^3 - sage: S = M.submodule([(1,2,3),(4,5,6)]); S + sage: M = ZZ^3 # optional - sage.modules + sage: S = M.submodule([(1,2,3), (4,5,6)]); S # optional - sage.modules Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [1 2 3] [0 3 6] - sage: F = S.construction()[0] - sage: F(GF(2)^3) # indirect doctest + sage: F = S.construction()[0] # optional - sage.modules + sage: F(GF(2)^3) # indirect doctest # optional - sage.rings.finite_rings sage.modules Vector space of degree 3 and dimension 2 over Finite Field of size 2 User basis matrix: [1 0 1] @@ -2215,10 +2250,10 @@ def _apply_functor_to_morphism(self, f): TESTS:: - sage: F = (ZZ^3).span([(1,2,3),(4,5,6)]).construction()[0] - sage: P. = ZZ[] - sage: f = P.hom([x+2*y,3*x-y],P) - sage: F(f) # indirect doctest + sage: F = (ZZ^3).span([(1,2,3), (4,5,6)]).construction()[0] # optional - sage.modules + sage: P. = ZZ[] # optional - sage.modules + sage: f = P.hom([x + 2*y, 3*x - y],P) # optional - sage.modules + sage: F(f) # indirect doctest # optional - sage.modules Traceback (most recent call last): ... NotImplementedError: Cannot create morphisms of free sub-modules yet @@ -2229,32 +2264,32 @@ def __eq__(self, other): """ TESTS:: - sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] - sage: F2 = (ZZ^3).span([(1,2,3),(4,5,6)]).construction()[0] - sage: F3 = (QQ^3).span([(1,2,3),(4,5,6)]).construction()[0] - sage: F4 = (ZZ^3).span([(1,0,-1),(0,1,2)]).construction()[0] - sage: F1 == loads(dumps(F1)) + sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules sage.rings.finite_rings + sage: F2 = (ZZ^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules + sage: F3 = (QQ^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules + sage: F4 = (ZZ^3).span([(1,0,-1),(0,1,2)]).construction()[0] # optional - sage.modules + sage: F1 == loads(dumps(F1)) # optional - sage.modules sage.rings.finite_rings True The ``span`` method automatically transforms the given basis into echelon form. The bases look like that:: - sage: F1.basis + sage: F1.basis # optional - sage.modules sage.rings.finite_rings [ (1, 0, 4), (0, 1, 2) ] - sage: F2.basis + sage: F2.basis # optional - sage.modules [ (1, 2, 3), (0, 3, 6) ] - sage: F3.basis + sage: F3.basis # optional - sage.modules [ (1, 0, -1), (0, 1, 2) ] - sage: F4.basis + sage: F4.basis # optional - sage.modules [ (1, 0, -1), (0, 1, 2) @@ -2264,18 +2299,18 @@ def __eq__(self, other): The basis of ``F2`` is modulo 5 different from the other bases. So, we have:: - sage: F1 != F2 != F3 + sage: F1 != F2 != F3 # optional - sage.modules sage.rings.finite_rings True The bases of ``F1``, ``F3`` and ``F4`` are the same modulo 5; however, there is no coercion from ``QQ^3`` to ``GF(5)^3``. Therefore, we have:: - sage: F1 == F3 + sage: F1 == F3 # optional - sage.modules sage.rings.finite_rings False But there are coercions from ``ZZ^3`` to ``QQ^3`` and ``GF(5)^3``, thus:: - sage: F1 == F4 == F3 + sage: F1 == F4 == F3 # optional - sage.modules sage.rings.finite_rings True """ @@ -2301,8 +2336,8 @@ def __ne__(self, other): EXAMPLES:: - sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] - sage: F1 != loads(dumps(F1)) + sage: F1 = (GF(5)^3).span([(1,2,3),(4,5,6)]).construction()[0] # optional - sage.modules sage.rings.finite_rings + sage: F1 != loads(dumps(F1)) # optional - sage.modules sage.rings.finite_rings False """ return not (self == other) @@ -2315,17 +2350,18 @@ def merge(self, other): EXAMPLES:: - sage: M = GF(5)^3 - sage: S1 = M.submodule([(1,2,3),(4,5,6)]) - sage: S2 = M.submodule([(2,2,3)]) - sage: F1 = S1.construction()[0] - sage: F2 = S2.construction()[0] - sage: F1.merge(F2) + sage: M = GF(5)^3 # optional - sage.modules sage.rings.finite_rings + sage: S1 = M.submodule([(1,2,3),(4,5,6)]) # optional - sage.modules sage.rings.finite_rings + sage: S2 = M.submodule([(2,2,3)]) # optional - sage.modules sage.rings.finite_rings + sage: F1 = S1.construction()[0] # optional - sage.modules sage.rings.finite_rings + sage: F2 = S2.construction()[0] # optional - sage.modules sage.rings.finite_rings + sage: F1.merge(F2) # optional - sage.modules sage.rings.finite_rings SubspaceFunctor - sage: F1.merge(F2)(GF(5)^3) == S1+S2 + sage: F1.merge(F2)(GF(5)^3) == S1 + S2 # optional - sage.modules sage.rings.finite_rings True - sage: F1.merge(F2)(GF(5)['t']^3) - Free module of degree 3 and rank 3 over Univariate Polynomial Ring in t over Finite Field of size 5 + sage: F1.merge(F2)(GF(5)['t']^3) # optional - sage.modules sage.rings.finite_rings + Free module of degree 3 and rank 3 + over Univariate Polynomial Ring in t over Finite Field of size 5 User basis matrix: [1 0 0] [0 1 0] @@ -2334,12 +2370,13 @@ def merge(self, other): TESTS:: sage: P. = ZZ[] - sage: S1 = (ZZ^3).submodule([(1,2,3),(4,5,6)]) - sage: S2 = (Frac(P)^3).submodule([(t,t^2,t^3+1),(4*t,0,1)]) - sage: v = S1([0,3,6]) + S2([2,0,1/(2*t)]); v # indirect doctest + sage: S1 = (ZZ^3).submodule([(1,2,3), (4,5,6)]) # optional - sage.modules + sage: S2 = (Frac(P)^3).submodule([(t,t^2,t^3+1), (4*t,0,1)]) # optional - sage.modules + sage: v = S1([0,3,6]) + S2([2,0,1/(2*t)]); v # indirect doctest # optional - sage.modules (2, 3, (-12*t - 1)/(-2*t)) - sage: v.parent() - Vector space of degree 3 and dimension 3 over Fraction Field of Univariate Polynomial Ring in t over Integer Ring + sage: v.parent() # optional - sage.modules + Vector space of degree 3 and dimension 3 + over Fraction Field of Univariate Polynomial Ring in t over Integer Ring User basis matrix: [1 0 0] [0 1 0] @@ -2384,14 +2421,15 @@ class FractionField(ConstructionFunctor): Category of integral domains sage: F.codomain() Category of fields - sage: F(GF(5)) is GF(5) + sage: F(GF(5)) is GF(5) # optional - sage.rings.finite_rings True sage: F(ZZ['t']) Fraction Field of Univariate Polynomial Ring in t over Integer Ring sage: P. = QQ[] sage: f = P.hom([x+2*y,3*x-y],P) sage: F(f) - Ring endomorphism of Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field + Ring endomorphism of + Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x + 2*y y |--> 3*x - y sage: F(f)(1/x) @@ -2424,8 +2462,9 @@ def _apply_functor(self, R): TESTS:: sage: F = QQ.construction()[0] - sage: F(GF(5)['t']) # indirect doctest - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 + sage: F(GF(5)['t']) # indirect doctest # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 """ return R.fraction_field() @@ -2436,15 +2475,15 @@ class CompletionFunctor(ConstructionFunctor): EXAMPLES:: - sage: R = Zp(5) - sage: R + sage: R = Zp(5) # optional - sage.rings.padics + sage: R # optional - sage.rings.padics 5-adic Ring with capped relative precision 20 - sage: F1 = R.construction()[0] - sage: F1 + sage: F1 = R.construction()[0] # optional - sage.rings.padics + sage: F1 # optional - sage.rings.padics Completion[5, prec=20] - sage: F1(ZZ) is R + sage: F1(ZZ) is R # optional - sage.rings.padics True - sage: F1(QQ) + sage: F1(QQ) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 sage: F2 = RR.construction()[0] sage: F2 @@ -2456,16 +2495,16 @@ class CompletionFunctor(ConstructionFunctor): sage: Px Power Series Ring in x over Integer Ring sage: F3 = Px.construction()[0] - sage: F3(GF(3)['x']) + sage: F3(GF(3)['x']) # optional - sage.rings.finite_rings Power Series Ring in x over Finite Field of size 3 TESTS:: - sage: R1. = Zp(5,prec=20)[] - sage: R2 = Qp(5,prec=40) - sage: R2(1) + a + sage: R1. = Zp(5, prec=20)[] # optional - sage.rings.padics + sage: R2 = Qp(5, prec=40) # optional - sage.rings.padics + sage: R2(1) + a # optional - sage.rings.padics (1 + O(5^20))*a + 1 + O(5^40) - sage: 1/2 + a + sage: 1/2 + a # optional - sage.rings.padics (1 + O(5^20))*a + 3 + 2*5 + 2*5^2 + 2*5^3 + 2*5^4 + 2*5^5 + 2*5^6 + 2*5^7 + 2*5^8 + 2*5^9 + 2*5^10 + 2*5^11 + 2*5^12 + 2*5^13 + 2*5^14 + 2*5^15 + 2*5^16 + 2*5^17 + 2*5^18 + 2*5^19 + O(5^20) """ @@ -2496,14 +2535,14 @@ def __init__(self, p, prec, extras=None): TESTS:: sage: from sage.categories.pushout import CompletionFunctor - sage: F1 = CompletionFunctor(5,100) - sage: F1(QQ) + sage: F1 = CompletionFunctor(5, 100) # optional - sage.rings.padics + sage: F1(QQ) # optional - sage.rings.padics 5-adic Field with capped relative precision 100 - sage: F1(ZZ) + sage: F1(ZZ) # optional - sage.rings.padics 5-adic Ring with capped relative precision 100 - sage: F1.type is None + sage: F1.type is None # optional - sage.rings.padics True - sage: sorted(F1.extras.items()) + sage: sorted(F1.extras.items()) # optional - sage.rings.padics [] sage: F2 = RR.construction()[0] sage: F2 @@ -2535,7 +2574,7 @@ def _repr_(self): """ TESTS:: - sage: Zp(7).construction() # indirect doctest + sage: Zp(7).construction() # indirect doctest # optional - sage.rings.padics (Completion[7, prec=20], Integer Ring) sage: RR.construction() # indirect doctest @@ -2549,11 +2588,11 @@ def _apply_functor(self, R): TESTS:: - sage: R = Zp(5) - sage: F1 = R.construction()[0] - sage: F1(ZZ) is R # indirect doctest + sage: R = Zp(5) # optional - sage.rings.padics + sage: F1 = R.construction()[0] # optional - sage.rings.padics + sage: F1(ZZ) is R # indirect doctest # optional - sage.rings.padics True - sage: F1(QQ) + sage: F1(QQ) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 """ @@ -2592,19 +2631,19 @@ def __eq__(self, other): TESTS:: - sage: R1 = Zp(5,prec=30) - sage: R2 = Zp(5,prec=40) - sage: F1 = R1.construction()[0] - sage: F2 = R2.construction()[0] - sage: F1 == loads(dumps(F1)) # indirect doctest + sage: R1 = Zp(5, prec=30) # optional - sage.rings.padics + sage: R2 = Zp(5, prec=40) # optional - sage.rings.padics + sage: F1 = R1.construction()[0] # optional - sage.rings.padics + sage: F2 = R2.construction()[0] # optional - sage.rings.padics + sage: F1 == loads(dumps(F1)) # indirect doctest # optional - sage.rings.padics True - sage: F1 == F2 + sage: F1 == F2 # optional - sage.rings.padics True - sage: F1(QQ) == F2(QQ) + sage: F1(QQ) == F2(QQ) # optional - sage.rings.padics False - sage: R3 = Zp(7) - sage: F3 = R3.construction()[0] - sage: F1 == F3 + sage: R3 = Zp(7) # optional - sage.rings.padics + sage: F3 = R3.construction()[0] # optional - sage.rings.padics + sage: F1 == F3 # optional - sage.rings.padics False """ if isinstance(other, CompletionFunctor): @@ -2617,19 +2656,19 @@ def __ne__(self, other): EXAMPLES:: - sage: R1 = Zp(5,prec=30) - sage: R2 = Zp(5,prec=40) - sage: F1 = R1.construction()[0] - sage: F2 = R2.construction()[0] - sage: F1 != loads(dumps(F1)) # indirect doctest + sage: R1 = Zp(5, prec=30) # optional - sage.rings.padics + sage: R2 = Zp(5, prec=40) # optional - sage.rings.padics + sage: F1 = R1.construction()[0] # optional - sage.rings.padics + sage: F2 = R2.construction()[0] # optional - sage.rings.padics + sage: F1 != loads(dumps(F1)) # indirect doctest # optional - sage.rings.padics False - sage: F1 != F2 + sage: F1 != F2 # optional - sage.rings.padics False - sage: F1(QQ) != F2(QQ) + sage: F1(QQ) != F2(QQ) # optional - sage.rings.padics True - sage: R3 = Zp(7) - sage: F3 = R3.construction()[0] - sage: F1 != F3 + sage: R3 = Zp(7) # optional - sage.rings.padics + sage: F3 = R3.construction()[0] # optional - sage.rings.padics + sage: F1 != F3 # optional - sage.rings.padics True """ return not (self == other) @@ -2647,15 +2686,15 @@ def merge(self, other): EXAMPLES:: - sage: R1. = Zp(5,prec=20)[] - sage: R2 = Qp(5,prec=40) - sage: R2(1)+a # indirect doctest + sage: R1. = Zp(5, prec=20)[] # optional - sage.rings.padics + sage: R2 = Qp(5, prec=40) # optional - sage.rings.padics + sage: R2(1) + a # indirect doctest # optional - sage.rings.padics (1 + O(5^20))*a + 1 + O(5^40) - sage: R3 = RealField(30) - sage: R4 = RealField(50) - sage: R3(1) + R4(1) # indirect doctest + sage: R3 = RealField(30) # optional - sage.rings.padics + sage: R4 = RealField(50) # optional - sage.rings.padics + sage: R3(1) + R4(1) # indirect doctest # optional - sage.rings.padics 2.0000000 - sage: (R3(1) + R4(1)).parent() + sage: (R3(1) + R4(1)).parent() # optional - sage.rings.padics Real Field with 30 bits of precision TESTS: @@ -2689,18 +2728,18 @@ def merge(self, other): :: - sage: P0 = ZpFM(5, 10) - sage: P1 = ZpFM(5, 20) - sage: P2 = ZpCR(5, 10) - sage: P3 = ZpCR(5, 20) - sage: P4 = ZpCA(5, 10) - sage: P5 = ZpCA(5, 20) - sage: P6 = Qp(5, 10) - sage: P7 = Qp(5, 20) - sage: Plist = [P2,P3,P4,P5,P6,P7] + sage: P0 = ZpFM(5, 10) # optional - sage.rings.padics + sage: P1 = ZpFM(5, 20) # optional - sage.rings.padics + sage: P2 = ZpCR(5, 10) # optional - sage.rings.padics + sage: P3 = ZpCR(5, 20) # optional - sage.rings.padics + sage: P4 = ZpCA(5, 10) # optional - sage.rings.padics + sage: P5 = ZpCA(5, 20) # optional - sage.rings.padics + sage: P6 = Qp(5, 10) # optional - sage.rings.padics + sage: P7 = Qp(5, 20) # optional - sage.rings.padics + sage: Plist = [P2,P3,P4,P5,P6,P7] # optional - sage.rings.padics sage: from sage.categories.pushout import pushout - sage: pushouts = [P2,P3,P4,P5,P6,P7,P3,P3,P5,P5,P7,P7,P4,P5,P4,P5,P6,P7,P5,P5,P5,P5,P7,P7,P6,P7,P6,P7,P6,P7,P7,P7,P7,P7,P7,P7] - sage: all(P is Q for P, Q in zip(pushouts, [pushout(a, b) for a in Plist for b in Plist])) + sage: pushouts = [P2,P3,P4,P5,P6,P7,P3,P3,P5,P5,P7,P7,P4,P5,P4,P5,P6,P7,P5,P5,P5,P5,P7,P7,P6,P7,P6,P7,P6,P7,P7,P7,P7,P7,P7,P7] # optional - sage.rings.padics + sage: all(P is Q for P, Q in zip(pushouts, [pushout(a, b) for a in Plist for b in Plist])) # optional - sage.rings.padics True """ if self == other: # both are Completion functors with the same p @@ -2742,9 +2781,9 @@ def commutes(self, other): EXAMPLES:: - sage: F1 = Zp(5).construction()[0] + sage: F1 = Zp(5).construction()[0] # optional - sage.rings.padics sage: F2 = QQ.construction()[0] - sage: F1.commutes(F2) + sage: F1.commutes(F2) # optional - sage.rings.padics True TESTS: @@ -2771,10 +2810,12 @@ def commutes(self, other): Ambiguous base extension error raised):: sage: from sage.categories.pushout import pushout - sage: pushout(Qp(7),RLF) + sage: pushout(Qp(7), RLF) # optional - sage.rings.padics Traceback (most recent call last): ... - CoercionException: Don't know how to apply Completion[+Infinity, prec=+Infinity] to 7-adic Ring with capped relative precision 20 + CoercionException: Don't know how to + apply Completion[+Infinity, prec=+Infinity] + to 7-adic Ring with capped relative precision 20 """ return isinstance(other, FractionField) @@ -2792,17 +2833,19 @@ class QuotientFunctor(ConstructionFunctor): EXAMPLES:: sage: P. = ZZ[] - sage: Q = P.quo([x^2+y^2]*P) - sage: F = Q.construction()[0] - sage: F(QQ['x','y']) - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: F(QQ['x','y']) == QQ['x','y'].quo([x^2+y^2]*QQ['x','y']) + sage: Q = P.quo([x^2 + y^2] * P) # optional - sage.rings.finite_rings + sage: F = Q.construction()[0] # optional - sage.rings.finite_rings + sage: F(QQ['x','y']) # optional - sage.rings.finite_rings + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) + sage: F(QQ['x','y']) == QQ['x','y'].quo([x^2 + y^2] * QQ['x','y']) # optional - sage.rings.finite_rings True - sage: F(QQ['x','y','z']) + sage: F(QQ['x','y','z']) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - CoercionException: Cannot apply this quotient functor to Multivariate Polynomial Ring in x, y, z over Rational Field - sage: F(QQ['y','z']) + CoercionException: Cannot apply this quotient functor to + Multivariate Polynomial Ring in x, y, z over Rational Field + sage: F(QQ['y','z']) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: Could not find a mapping of the passed element to this ring. @@ -2831,21 +2874,21 @@ def __init__(self, I, names=None, as_field=False, domain=None, sage: from sage.categories.pushout import QuotientFunctor sage: P. = ZZ[] - sage: F = QuotientFunctor([5+t^2]*P) - sage: F(P) + sage: F = QuotientFunctor([5 + t^2] * P) + sage: F(P) # optional - sage.rings.finite_rings Univariate Quotient Polynomial Ring in tbar over Integer Ring with modulus t^2 + 5 - sage: F(QQ['t']) + sage: F(QQ['t']) # optional - sage.rings.finite_rings Univariate Quotient Polynomial Ring in tbar over Rational Field with modulus t^2 + 5 - sage: F = QuotientFunctor([5+t^2]*P,names='s') - sage: F(P) + sage: F = QuotientFunctor([5 + t^2] * P, names='s') + sage: F(P) # optional - sage.rings.finite_rings Univariate Quotient Polynomial Ring in s over Integer Ring with modulus t^2 + 5 - sage: F(QQ['t']) + sage: F(QQ['t']) # optional - sage.rings.finite_rings Univariate Quotient Polynomial Ring in s over Rational Field with modulus t^2 + 5 - sage: F = QuotientFunctor([5]*ZZ,as_field=True) - sage: F(ZZ) + sage: F = QuotientFunctor([5] * ZZ, as_field=True) + sage: F(ZZ) # optional - sage.rings.finite_rings Finite Field of size 5 - sage: F = QuotientFunctor([5]*ZZ) - sage: F(ZZ) + sage: F = QuotientFunctor([5] * ZZ) + sage: F(ZZ) # optional - sage.rings.finite_rings Ring of integers modulo 5 """ @@ -2872,10 +2915,10 @@ def _apply_functor(self, R): TESTS:: sage: P. = ZZ[] - sage: Q = P.quo([2+x^2,3*x+y^2]) - sage: F = Q.construction()[0]; F + sage: Q = P.quo([2 + x^2, 3*x + y^2]) # optional - sage.rings.finite_rings + sage: F = Q.construction()[0]; F # optional - sage.rings.finite_rings QuotientFunctor - sage: F(QQ['x','y']) # indirect doctest + sage: F(QQ['x','y']) # indirect doctest # optional - sage.rings.finite_rings Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + 2, y^2 + 3*x) Note that the ``quo()`` method of a field used to return the @@ -2919,14 +2962,14 @@ def __eq__(self, other): TESTS:: sage: P. = QQ[] - sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] - sage: F == loads(dumps(F)) + sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings + sage: F == loads(dumps(F)) # optional - sage.rings.finite_rings True sage: P2. = QQ[] - sage: F == P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + sage: F == P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings False sage: P3. = ZZ[] - sage: F == P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + sage: F == P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings True """ if not isinstance(other, QuotientFunctor): @@ -2944,14 +2987,14 @@ def __ne__(self, other): EXAMPLES:: sage: P. = QQ[] - sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] - sage: F != loads(dumps(F)) + sage: F = P.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings + sage: F != loads(dumps(F)) # optional - sage.rings.finite_rings False sage: P2. = QQ[] - sage: F != P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + sage: F != P2.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings True sage: P3. = ZZ[] - sage: F != P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] + sage: F != P3.quo([(x^2+1)^2*(x^2-3),(x^2+1)^2*(x^5+3)]).construction()[0] # optional - sage.rings.finite_rings False """ return not (self == other) @@ -2970,15 +3013,16 @@ def merge(self, other): EXAMPLES:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.rings.finite_rings + sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) # optional - sage.rings.finite_rings sage: from sage.categories.pushout import pushout - sage: pushout(Q1,Q2) # indirect doctest - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^4 + 2*x^2 + 1 + sage: pushout(Q1,Q2) # indirect doctest # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^4 + 2*x^2 + 1 The following was fixed in :trac:`8800`:: - sage: pushout(GF(5), Integers(5)) + sage: pushout(GF(5), Integers(5)) # optional - sage.rings.finite_rings Finite Field of size 5 """ @@ -3038,65 +3082,72 @@ class AlgebraicExtensionFunctor(ConstructionFunctor): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F(ZZ['t']) - Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in t over Integer Ring with modulus a^3 + a^2 + 1 + sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field + sage: F = K.construction()[0] # optional - sage.rings.number_field + sage: F(ZZ['t']) # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in a + over Univariate Polynomial Ring in t over Integer Ring + with modulus a^3 + a^2 + 1 Note that, even if a field is algebraically closed, the algebraic extension will be constructed as the quotient of a univariate polynomial ring:: - sage: F(CC) - Univariate Quotient Polynomial Ring in a over Complex Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 - sage: F(RR) - Univariate Quotient Polynomial Ring in a over Real Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 + sage: F(CC) # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in a + over Complex Field with 53 bits of precision + with modulus a^3 + a^2 + 1.00000000000000 + sage: F(RR) # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in a + over Real Field with 53 bits of precision + with modulus a^3 + a^2 + 1.00000000000000 Note that the construction functor of a number field applied to the integers returns an order (not necessarily maximal) of that field, similar to the behaviour of ``ZZ.extension(...)``:: - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^3 + x^2 + 1 This also holds for non-absolute number fields:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField([x^3 + x^2 + 1, x^2 + x + 1]) - sage: F = K.construction()[0] - sage: O = F(ZZ); O - Relative Order in Number Field in a with defining polynomial x^3 + x^2 + 1 over its base field - sage: O.ambient() is K + sage: K. = NumberField([x^3 + x^2 + 1, x^2 + x + 1]) # optional - sage.rings.number_field + sage: F = K.construction()[0] # optional - sage.rings.number_field + sage: O = F(ZZ); O # optional - sage.rings.number_field + Relative Order in Number Field in a + with defining polynomial x^3 + x^2 + 1 over its base field + sage: O.ambient() is K # optional - sage.rings.number_field True Special cases are made for cyclotomic fields and residue fields:: - sage: C = CyclotomicField(8) - sage: F,R = C.construction() - sage: F + sage: C = CyclotomicField(8) # optional - sage.rings.number_field + sage: F, R = C.construction() # optional - sage.rings.number_field + sage: F # optional - sage.rings.number_field AlgebraicExtensionFunctor - sage: R + sage: R # optional - sage.rings.number_field Rational Field - sage: F(R) + sage: F(R) # optional - sage.rings.number_field Cyclotomic Field of order 8 and degree 4 - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field Maximal Order in Cyclotomic Field of order 8 and degree 4 :: - sage: K. = CyclotomicField(7) - sage: P = K.factor(17)[0][0] - sage: k = K.residue_field(P) - sage: F, R = k.construction() - sage: F + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: P = K.factor(17)[0][0] # optional - sage.rings.number_field + sage: k = K.residue_field(P) # optional - sage.rings.number_field + sage: F, R = k.construction() # optional - sage.rings.number_field + sage: F # optional - sage.rings.number_field AlgebraicExtensionFunctor - sage: R + sage: R # optional - sage.rings.number_field Cyclotomic Field of order 7 and degree 6 - sage: F(R) is k + sage: F(R) is k # optional - sage.rings.number_field True - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field Residue field of Integers modulo 17 - sage: F(CyclotomicField(49)) + sage: F(CyclotomicField(49)) # optional - sage.rings.number_field Residue field in zbar of Fractional ideal (17) """ @@ -3158,23 +3209,25 @@ def __init__(self, polys, names, embeddings=None, structures=None, sage: from sage.categories.pushout import AlgebraicExtensionFunctor sage: P. = ZZ[] - sage: F1 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [None]) - sage: F2 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [0]) - sage: F1==F2 + sage: F1 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [None]) # optional - sage.rings.number_field + sage: F2 = AlgebraicExtensionFunctor([x^3 - x^2 + 1], ['a'], [0]) # optional - sage.rings.number_field + sage: F1 == F2 # optional - sage.rings.number_field False - sage: F1(QQ) + sage: F1(QQ) # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - x^2 + 1 - sage: F1(QQ).coerce_embedding() - sage: phi = F2(QQ).coerce_embedding().__copy__(); phi + sage: F1(QQ).coerce_embedding() # optional - sage.rings.number_field + sage: phi = F2(QQ).coerce_embedding().__copy__(); phi # optional - sage.rings.number_field Generic morphism: - From: Number Field in a with defining polynomial x^3 - x^2 + 1 with a = -0.7548776662466928? + From: Number Field in a with defining polynomial x^3 - x^2 + 1 + with a = -0.7548776662466928? To: Real Lazy Field Defn: a -> -0.7548776662466928? - sage: F1(QQ)==F2(QQ) + sage: F1(QQ) == F2(QQ) # optional - sage.rings.number_field False - sage: F1(GF(5)) - Univariate Quotient Polynomial Ring in a over Finite Field of size 5 with modulus a^3 + 4*a^2 + 1 - sage: F2(GF(5)) + sage: F1(GF(5)) # optional - sage.rings.finite_rings sage.rings.number_field + Univariate Quotient Polynomial Ring in a over Finite Field of size 5 + with modulus a^3 + 4*a^2 + 1 + sage: F2(GF(5)) # optional - sage.rings.finite_rings sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: ring extension with prescribed embedding is not implemented @@ -3183,38 +3236,38 @@ def __init__(self, polys, names, embeddings=None, structures=None, integers, an order (not necessarily maximal) of that field is returned, similar to the behaviour of ``ZZ.extension``:: - sage: F1(ZZ) + sage: F1(ZZ) # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^3 - x^2 + 1 The cyclotomic fields form a special case of number fields with prescribed embeddings:: - sage: C = CyclotomicField(8) - sage: F,R = C.construction() - sage: F + sage: C = CyclotomicField(8) # optional - sage.rings.number_field + sage: F, R = C.construction() # optional - sage.rings.number_field + sage: F # optional - sage.rings.number_field AlgebraicExtensionFunctor - sage: R + sage: R # optional - sage.rings.number_field Rational Field - sage: F(R) + sage: F(R) # optional - sage.rings.number_field Cyclotomic Field of order 8 and degree 4 - sage: F(ZZ) + sage: F(ZZ) # optional - sage.rings.number_field Maximal Order in Cyclotomic Field of order 8 and degree 4 The data stored in this construction includes structural morphisms of number fields (see :trac:`20826`):: sage: R. = ZZ[] - sage: K. = NumberField(x^2 - 3) - sage: L0. = K.change_names() - sage: L0.structure() + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: L0. = K.change_names() # optional - sage.rings.number_field + sage: L0.structure() # optional - sage.rings.number_field (Isomorphism given by variable name change map: From: Number Field in b with defining polynomial x^2 - 3 To: Number Field in a with defining polynomial x^2 - 3, Isomorphism given by variable name change map: From: Number Field in a with defining polynomial x^2 - 3 To: Number Field in b with defining polynomial x^2 - 3) - sage: L1 = (b*x).parent().base_ring() - sage: L1 is L0 + sage: L1 = (b*x).parent().base_ring() # optional - sage.rings.number_field + sage: L1 is L0 # optional - sage.rings.number_field True """ Functor.__init__(self, Rings(), Rings()) @@ -3258,21 +3311,21 @@ def _apply_functor(self, R): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F(ZZ) # indirect doctest + sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field + sage: F = K.construction()[0] # optional - sage.rings.number_field + sage: F(ZZ) # indirect doctest # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^3 + x^2 + 1 - sage: F(ZZ['t']) # indirect doctest + sage: F(ZZ['t']) # indirect doctest # optional - sage.rings.number_field Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in t over Integer Ring with modulus a^3 + a^2 + 1 - sage: F(RR) # indirect doctest + sage: F(RR) # indirect doctest # optional - sage.rings.number_field Univariate Quotient Polynomial Ring in a over Real Field with 53 bits of precision with modulus a^3 + a^2 + 1.00000000000000 Check that :trac:`13538` is fixed:: - sage: K = Qp(3,3) - sage: R. = K[] - sage: AEF = sage.categories.pushout.AlgebraicExtensionFunctor([a^2-3], ['a'], [None]) - sage: AEF(K) + sage: K = Qp(3, 3) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: AEF = sage.categories.pushout.AlgebraicExtensionFunctor([a^2 - 3], ['a'], [None]) # optional - sage.rings.padics + sage: AEF(K) # optional - sage.rings.padics 3-adic Eisenstein Extension Field in a defined by a^2 - 3 """ @@ -3303,19 +3356,19 @@ def __eq__(self, other): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F == loads(dumps(F)) + sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field + sage: F = K.construction()[0] # optional - sage.rings.number_field + sage: F == loads(dumps(F)) # optional - sage.rings.number_field True - sage: K2. = NumberField(x^3 + x^2 + 1, latex_names='a') - sage: F2 = K2.construction()[0] - sage: F2 == F + sage: K2. = NumberField(x^3 + x^2 + 1, latex_names='a') # optional - sage.rings.number_field + sage: F2 = K2.construction()[0] # optional - sage.rings.number_field + sage: F2 == F # optional - sage.rings.number_field True - sage: K3. = NumberField(x^3 + x^2 + 1, latex_names='alpha') - sage: F3 = K3.construction()[0] - sage: F3 == F + sage: K3. = NumberField(x^3 + x^2 + 1, latex_names='alpha') # optional - sage.rings.number_field + sage: F3 = K3.construction()[0] # optional - sage.rings.number_field + sage: F3 == F # optional - sage.rings.number_field False """ if not isinstance(other, AlgebraicExtensionFunctor): @@ -3334,9 +3387,9 @@ def __ne__(self, other): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3 + x^2 + 1) - sage: F = K.construction()[0] - sage: F != loads(dumps(F)) + sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field + sage: F = K.construction()[0] # optional - sage.rings.number_field + sage: F != loads(dumps(F)) # optional - sage.rings.number_field False """ return not (self == other) @@ -3380,36 +3433,39 @@ def merge(self, other): The following demonstrate coercions for finite fields using Conway or pseudo-Conway polynomials:: - sage: k = GF(3^2, prefix='z'); a = k.gen() - sage: l = GF(3^3, prefix='z'); b = l.gen() - sage: a + b # indirect doctest + sage: k = GF(3^2, prefix='z'); a = k.gen() # optional - sage.rings.finite_rings + sage: l = GF(3^3, prefix='z'); b = l.gen() # optional - sage.rings.finite_rings + sage: a + b # indirect doctest # optional - sage.rings.finite_rings z6^5 + 2*z6^4 + 2*z6^3 + z6^2 + 2*z6 + 1 Note that embeddings are compatible in lattices of such finite fields:: - sage: m = GF(3^5, prefix='z'); c = m.gen() - sage: (a+b)+c == a+(b+c) # indirect doctest + sage: m = GF(3^5, prefix='z'); c = m.gen() # optional - sage.rings.finite_rings + sage: (a + b) + c == a + (b + c) # indirect doctest # optional - sage.rings.finite_rings True sage: from sage.categories.pushout import pushout - sage: n = pushout(k, l) - sage: o = pushout(l, m) - sage: q = pushout(n, o) - sage: q(o(b)) == q(n(b)) # indirect doctest + sage: n = pushout(k, l) # optional - sage.rings.finite_rings + sage: o = pushout(l, m) # optional - sage.rings.finite_rings + sage: q = pushout(n, o) # optional - sage.rings.finite_rings + sage: q(o(b)) == q(n(b)) # indirect doctest # optional - sage.rings.finite_rings True Coercion is also available for number fields:: - sage: P. = QQ[] - sage: L. = NumberField(x^8-x^4+1, embedding=CDF.0) - sage: M1. = NumberField(x^2+x+1, embedding=b^4-1) - sage: M2. = NumberField(x^2+1, embedding=-b^6) - sage: M1.coerce_map_from(M2) - sage: M2.coerce_map_from(M1) - sage: c1+c2; parent(c1+c2) #indirect doctest + sage: P. = QQ[] # optional - sage.rings.number_field + sage: L. = NumberField(x^8 - x^4 + 1, embedding=CDF.0) # optional - sage.rings.number_field + sage: M1. = NumberField(x^2 + x + 1, embedding=b^4 - 1) # optional - sage.rings.number_field + sage: M2. = NumberField(x^2 + 1, embedding=-b^6) # optional - sage.rings.number_field + sage: M1.coerce_map_from(M2) # optional - sage.rings.number_field + sage: M2.coerce_map_from(M1) # optional - sage.rings.number_field + sage: c1 + c2; parent(c1 + c2) #indirect doctest # optional - sage.rings.number_field -b^6 + b^4 - 1 - Number Field in b with defining polynomial x^8 - x^4 + 1 with b = -0.2588190451025208? + 0.9659258262890683?*I - sage: pushout(M1['x'],M2['x']) - Univariate Polynomial Ring in x over Number Field in b with defining polynomial x^8 - x^4 + 1 with b = -0.2588190451025208? + 0.9659258262890683?*I + Number Field in b with defining polynomial x^8 - x^4 + 1 + with b = -0.2588190451025208? + 0.9659258262890683?*I + sage: pushout(M1['x'], M2['x']) # optional - sage.rings.number_field + Univariate Polynomial Ring in x + over Number Field in b with defining polynomial x^8 - x^4 + 1 + with b = -0.2588190451025208? + 0.9659258262890683?*I In the previous example, the number field ``L`` becomes the pushout of ``M1`` and ``M2`` since both are provided with an embedding into @@ -3419,14 +3475,16 @@ def merge(self, other): sage: cbrt2 = CDF(2)^(1/3) sage: zeta3 = CDF.zeta(3) - sage: K. = NumberField(x^3-2, embedding=cbrt2 * zeta3) - sage: L. = NumberField(x^6-2, embedding=1.1) - sage: L.coerce_map_from(K) - sage: K.coerce_map_from(L) - sage: pushout(K,L) + sage: K. = NumberField(x^3 - 2, embedding=cbrt2 * zeta3) # optional - sage.rings.number_field + sage: L. = NumberField(x^6 - 2, embedding=1.1) # optional - sage.rings.number_field + sage: L.coerce_map_from(K) # optional - sage.rings.number_field + sage: K.coerce_map_from(L) # optional - sage.rings.number_field + sage: pushout(K, L) # optional - sage.rings.number_field Traceback (most recent call last): ... - CoercionException: ('Ambiguous Base Extension', Number Field in a with defining polynomial x^3 - 2 with a = -0.6299605249474365? + 1.091123635971722?*I, Number Field in b with defining polynomial x^6 - 2 with b = 1.122462048309373?) + CoercionException: ('Ambiguous Base Extension', Number Field in a with + defining polynomial x^3 - 2 with a = -0.6299605249474365? + 1.091123635971722?*I, + Number Field in b with defining polynomial x^6 - 2 with b = 1.122462048309373?) """ if isinstance(other, AlgebraicClosureFunctor): @@ -3496,10 +3554,10 @@ def __mul__(self, other): TESTS:: sage: P. = QQ[] - sage: K. = NumberField(x^3-5,embedding=0) - sage: L. = K.extension(x^2+a) - sage: F,R = L.construction() - sage: prod(F.expand())(R) == L #indirect doctest + sage: K. = NumberField(x^3 - 5, embedding=0) # optional - sage.rings.number_field + sage: L. = K.extension(x^2 + a) # optional - sage.rings.number_field + sage: F, R = L.construction() # optional - sage.rings.number_field + sage: prod(F.expand())(R) == L #indirect doctest # optional - sage.rings.number_field True """ @@ -3528,18 +3586,18 @@ def expand(self): EXAMPLES:: sage: P. = QQ[] - sage: K. = NumberField(x^3-5,embedding=0) - sage: L. = K.extension(x^2+a) - sage: F,R = L.construction() - sage: prod(F.expand())(R) == L + sage: K. = NumberField(x^3 - 5, embedding=0) # optional - sage.rings.number_field + sage: L. = K.extension(x^2 + a) # optional - sage.rings.number_field + sage: F, R = L.construction() # optional - sage.rings.number_field + sage: prod(F.expand())(R) == L # optional - sage.rings.number_field True - sage: K = NumberField([x^2-2, x^2-3],'a') - sage: F, R = K.construction() - sage: F + sage: K = NumberField([x^2 - 2, x^2 - 3],'a') # optional - sage.rings.number_field + sage: F, R = K.construction() # optional - sage.rings.number_field + sage: F # optional - sage.rings.number_field AlgebraicExtensionFunctor - sage: L = F.expand(); L + sage: L = F.expand(); L # optional - sage.rings.number_field [AlgebraicExtensionFunctor, AlgebraicExtensionFunctor] - sage: L[-1](QQ) + sage: L[-1](QQ) # optional - sage.rings.number_field Number Field in a1 with defining polynomial x^2 - 3 """ n = len(self.polys) @@ -3559,11 +3617,11 @@ class AlgebraicClosureFunctor(ConstructionFunctor): EXAMPLES:: sage: F = CDF.construction()[0] - sage: F(QQ) + sage: F(QQ) # optional - sage.rings.number_field Algebraic Field sage: F(RR) Complex Field with 53 bits of precision - sage: F(F(QQ)) is F(QQ) + sage: F(F(QQ)) is F(QQ) # optional - sage.rings.number_field True """ @@ -3575,7 +3633,7 @@ def __init__(self): sage: from sage.categories.pushout import AlgebraicClosureFunctor sage: F = AlgebraicClosureFunctor() - sage: F(QQ) + sage: F(QQ) # optional - sage.rings.number_field Algebraic Field sage: F(RR) Complex Field with 53 bits of precision @@ -3592,7 +3650,7 @@ def _apply_functor(self, R): TESTS:: sage: F = CDF.construction()[0] - sage: F(QQ) # indirect doctest + sage: F(QQ) # indirect doctest # optional - sage.rings.number_field Algebraic Field """ try: @@ -3612,10 +3670,10 @@ def merge(self, other): TESTS:: sage: x = polygen(QQ, 'x') - sage: K. = NumberField(x^3+x^2+1) - sage: CDF.construction()[0].merge(K.construction()[0]) is None + sage: K. = NumberField(x^3 + x^2 + 1) # optional - sage.rings.number_field + sage: CDF.construction()[0].merge(K.construction()[0]) is None # optional - sage.rings.number_field True - sage: CDF.construction()[0].merge(CDF.construction()[0]) + sage: CDF.construction()[0].merge(CDF.construction()[0]) # optional - sage.rings.number_field AlgebraicClosureFunctor """ @@ -3638,7 +3696,7 @@ def __init__(self, gens, domain): EXAMPLES:: sage: from sage.categories.pushout import PermutationGroupFunctor - sage: PF = PermutationGroupFunctor([PermutationGroupElement([(1,2)])], [1,2]); PF + sage: PF = PermutationGroupFunctor([PermutationGroupElement([(1,2)])], [1,2]); PF # optional - sage.groups PermutationGroupFunctor[(1,2)] """ Functor.__init__(self, Groups(), Groups()) @@ -3649,9 +3707,9 @@ def _repr_(self): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF, P = P1.construction() - sage: PF + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF, P = P1.construction() # optional - sage.groups + sage: PF # optional - sage.groups PermutationGroupFunctor[(1,2)] """ return "PermutationGroupFunctor%s" % list(self.gens()) @@ -3660,9 +3718,9 @@ def __call__(self, R): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF, P = P1.construction() - sage: PF(P) + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF, P = P1.construction() # optional - sage.groups + sage: PF(P) # optional - sage.groups Permutation Group with generators [(1,2)] """ from sage.groups.perm_gps.permgroup import PermutationGroup @@ -3673,9 +3731,9 @@ def gens(self): """ EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF, P = P1.construction() - sage: PF.gens() + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF, P = P1.construction() # optional - sage.groups + sage: PF.gens() # optional - sage.groups ((1,2),) """ return self._gens @@ -3686,11 +3744,11 @@ def merge(self, other): EXAMPLES:: - sage: P1 = PermutationGroup([[(1,2)]]) - sage: PF1, P = P1.construction() - sage: P2 = PermutationGroup([[(1,3)]]) - sage: PF2, P = P2.construction() - sage: PF1.merge(PF2) + sage: P1 = PermutationGroup([[(1,2)]]) # optional - sage.groups + sage: PF1, P = P1.construction() # optional - sage.groups + sage: P2 = PermutationGroup([[(1,3)]]) # optional - sage.groups + sage: PF2, P = P2.construction() # optional - sage.groups + sage: PF1.merge(PF2) # optional - sage.groups PermutationGroupFunctor[(1,2), (1,3)] """ if self.__class__ != other.__class__: @@ -3736,13 +3794,13 @@ class EquivariantSubobjectConstructionFunctor(ConstructionFunctor): column (index 1); the order of the extra element 2 in a permutation determines whether it is a symmetry or an antisymmetry:: - sage: GSym01 = PermutationGroup([[(0,1),(2,),(3,)]]); GSym01 + sage: GSym01 = PermutationGroup([[(0,1),(2,),(3,)]]); GSym01 # optional - sage.groups Permutation Group with generators [(0,1)] - sage: GASym01 = PermutationGroup([[(0,1),(2,3)]]); GASym01 + sage: GASym01 = PermutationGroup([[(0,1),(2,3)]]); GASym01 # optional - sage.groups Permutation Group with generators [(0,1)(2,3)] sage: from sage.categories.action import Action sage: from sage.structure.element import Matrix - sage: class TensorIndexAction(Action): + sage: class TensorIndexAction(Action): # optional - sage.modules ....: def _act_(self, g, x): ....: if isinstance(x, Matrix): ....: if g(0) == 1: @@ -3753,39 +3811,40 @@ class EquivariantSubobjectConstructionFunctor(ConstructionFunctor): ....: else: ....: return x ....: raise NotImplementedError - sage: M = matrix([[1, 2], [3, 4]]); M + sage: M = matrix([[1, 2], [3, 4]]); M # optional - sage.modules [1 2] [3 4] - sage: GSym01_action = TensorIndexAction(GSym01, M.parent()) - sage: GASym01_action = TensorIndexAction(GASym01, M.parent()) - sage: GSym01_action.act(GSym01.0, M) + sage: GSym01_action = TensorIndexAction(GSym01, M.parent()) # optional - sage.groups sage.modules + sage: GASym01_action = TensorIndexAction(GASym01, M.parent()) # optional - sage.groups sage.modules + sage: GSym01_action.act(GSym01.0, M) # optional - sage.groups sage.modules [1 3] [2 4] - sage: GASym01_action.act(GASym01.0, M) + sage: GASym01_action.act(GASym01.0, M) # optional - sage.groups sage.modules [-1 -3] [-2 -4] - sage: Sym01 = M.parent().invariant_module(GSym01, action=GSym01_action); Sym01 + sage: Sym01 = M.parent().invariant_module(GSym01, action=GSym01_action); Sym01 # optional - sage.groups sage.modules (Permutation Group with generators [(0,1)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: list(Sym01.basis()) + sage: list(Sym01.basis()) # optional - sage.groups sage.modules [B[0], B[1], B[2]] - sage: list(Sym01.basis().map(Sym01.lift)) + sage: list(Sym01.basis().map(Sym01.lift)) # optional - sage.groups sage.modules [ [1 0] [0 1] [0 0] [0 0], [1 0], [0 1] ] - sage: ASym01 = M.parent().invariant_module(GASym01, action=GASym01_action); ASym01 + sage: ASym01 = M.parent().invariant_module(GASym01, action=GASym01_action) # optional - sage.groups sage.modules + sage: ASym01 # optional - sage.groups sage.modules (Permutation Group with generators [(0,1)(2,3)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: list(ASym01.basis()) + sage: list(ASym01.basis()) # optional - sage.groups sage.modules [B[0]] - sage: list(ASym01.basis().map(ASym01.lift)) + sage: list(ASym01.basis().map(ASym01.lift)) # optional - sage.groups sage.modules [ [ 0 1] [-1 0] ] sage: from sage.categories.pushout import pushout - sage: pushout(Sym01, QQ) + sage: pushout(Sym01, QQ) # optional - sage.groups sage.modules (Permutation Group with generators [(0,1)])-invariant submodule of Full MatrixSpace of 2 by 2 dense matrices over Rational Field """ @@ -3794,12 +3853,12 @@ def __init__(self, S, action=operator.mul, side='left', """ EXAMPLES:: - sage: G = SymmetricGroup(3); G.rename('S3') - sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') - sage: action = lambda g, x: M.term(g(x)) - sage: I = M.invariant_module(G, action_on_basis=action); I + sage: G = SymmetricGroup(3); G.rename('S3') # optional - sage.groups sage.modules + sage: M = FreeModule(ZZ, [1,2,3], prefix='M'); M.rename('M') # optional - sage.groups sage.modules + sage: action = lambda g, x: M.term(g(x)) # optional - sage.groups sage.modules + sage: I = M.invariant_module(G, action_on_basis=action); I # optional - sage.groups sage.modules (S3)-invariant submodule of M - sage: I.construction() + sage: I.construction() # optional - sage.groups sage.modules (EquivariantSubobjectConstructionFunctor, Representation of S3 indexed by {1, 2, 3} over Integer Ring) """ @@ -3818,13 +3877,13 @@ def _apply_functor(self, X): TESTS:: sage: from sage.categories.pushout import EquivariantSubobjectConstructionFunctor - sage: M2 = MatrixSpace(QQ, 2); M2 + sage: M2 = MatrixSpace(QQ, 2); M2 # optional - sage.groups sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: F = EquivariantSubobjectConstructionFunctor(M2, - ....: operator.mul, 'left', - ....: operator.mul, 'right'); F + sage: F = EquivariantSubobjectConstructionFunctor(M2, # optional - sage.groups sage.modules + ....: operator.mul, 'left', + ....: operator.mul, 'right'); F EquivariantSubobjectConstructionFunctor - sage: F(M2) + sage: F(M2) # optional - sage.groups sage.modules Traceback (most recent call last): ... NotImplementedError: non-trivial other_action= is not implemented @@ -3843,24 +3902,24 @@ class BlackBoxConstructionFunctor(ConstructionFunctor): EXAMPLES:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FS = BlackBoxConstructionFunctor(singular) - sage: FG + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FS = BlackBoxConstructionFunctor(singular) # optional - sage.libs.singular + sage: FG # optional - sage.libs.gap BlackBoxConstructionFunctor - sage: FG(ZZ) + sage: FG(ZZ) # optional - sage.libs.gap Integers - sage: FG(ZZ).parent() + sage: FG(ZZ).parent() # optional - sage.libs.gap Gap - sage: FS(QQ['t']) + sage: FS(QQ['t']) # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 // block 1 : ordering lp // : names t // block 2 : ordering C - sage: FG == FS + sage: FG == FS # optional - sage.libs.gap sage.libs.singular False - sage: FG == loads(dumps(FG)) + sage: FG == loads(dumps(FG)) # optional - sage.libs.gap True """ rank = 100 @@ -3870,11 +3929,11 @@ def __init__(self, box): TESTS:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # optional - sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic + sage: FM == FG # optional - sage.symbolic False - sage: FM == loads(dumps(FM)) # optional - sage.symbolic + sage: FM == loads(dumps(FM)) # optional - sage.symbolic True """ ConstructionFunctor.__init__(self, Objects(), Objects()) @@ -3891,7 +3950,7 @@ def _apply_functor(self, R): sage: from sage.categories.pushout import BlackBoxConstructionFunctor sage: f = lambda x: x^2 sage: F = BlackBoxConstructionFunctor(f) - sage: F(ZZ) # indirect doctest + sage: F(ZZ) # indirect doctest # optional - sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring """ @@ -3902,11 +3961,11 @@ def __eq__(self, other): TESTS:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM == FG # indirect doctest # optional - sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic + sage: FM == FG # indirect doctest # optional - sage.symbolic False - sage: FM == loads(dumps(FM)) # optional - sage.symbolic + sage: FM == loads(dumps(FM)) # optional - sage.symbolic True """ if not isinstance(other, BlackBoxConstructionFunctor): @@ -3921,11 +3980,11 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.categories.pushout import BlackBoxConstructionFunctor - sage: FG = BlackBoxConstructionFunctor(gap) - sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic - sage: FM != FG # indirect doctest # optional - sage.symbolic + sage: FG = BlackBoxConstructionFunctor(gap) # optional - sage.libs.gap + sage: FM = BlackBoxConstructionFunctor(maxima) # optional - sage.symbolic + sage: FM != FG # indirect doctest # optional - sage.symbolic True - sage: FM != loads(dumps(FM)) # optional - sage.symbolic + sage: FM != loads(dumps(FM)) # optional - sage.symbolic False """ return not (self == other) @@ -3984,16 +4043,19 @@ def pushout(R, S): which give us `Frac(Poly_x(Complete_7(Frac(\ZZ))))`:: sage: from sage.categories.pushout import pushout - sage: pushout(Qp(7), Frac(ZZ['x'])) - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 + sage: pushout(Qp(7), Frac(ZZ['x'])) # optional - sage.rings.padics + Fraction Field of Univariate Polynomial Ring in x + over 7-adic Field with capped relative precision 20 Note we get the same thing with :: - sage: pushout(Zp(7), Frac(QQ['x'])) - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 - sage: pushout(Zp(7)['x'], Frac(QQ['x'])) - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 + sage: pushout(Zp(7), Frac(QQ['x'])) # optional - sage.rings.padics + Fraction Field of Univariate Polynomial Ring in x + over 7-adic Field with capped relative precision 20 + sage: pushout(Zp(7)['x'], Frac(QQ['x'])) # optional - sage.rings.padics + Fraction Field of Univariate Polynomial Ring in x + over 7-adic Field with capped relative precision 20 Note that polynomial variable ordering must be unambiguously determined. :: @@ -4001,49 +4063,57 @@ def pushout(R, S): sage: pushout(ZZ['x,y,z'], QQ['w,z,t']) Traceback (most recent call last): ... - CoercionException: ('Ambiguous Base Extension', Multivariate Polynomial Ring in x, y, z over Integer Ring, Multivariate Polynomial Ring in w, z, t over Rational Field) + CoercionException: ('Ambiguous Base Extension', + Multivariate Polynomial Ring in x, y, z over Integer Ring, + Multivariate Polynomial Ring in w, z, t over Rational Field) sage: pushout(ZZ['x,y,z'], QQ['w,x,z,t']) Multivariate Polynomial Ring in w, x, y, z, t over Rational Field Some other examples:: - sage: pushout(Zp(7)['y'], Frac(QQ['t'])['x,y,z']) - Multivariate Polynomial Ring in x, y, z over Fraction Field of Univariate Polynomial Ring in t over 7-adic Field with capped relative precision 20 + sage: pushout(Zp(7)['y'], Frac(QQ['t'])['x,y,z']) # optional - sage.rings.padics + Multivariate Polynomial Ring in x, y, z + over Fraction Field of Univariate Polynomial Ring in t + over 7-adic Field with capped relative precision 20 sage: pushout(ZZ['x,y,z'], Frac(ZZ['x'])['y']) - Multivariate Polynomial Ring in y, z over Fraction Field of Univariate Polynomial Ring in x over Integer Ring - sage: pushout(MatrixSpace(RDF, 2, 2), Frac(ZZ['x'])) - Full MatrixSpace of 2 by 2 dense matrices over Fraction Field of Univariate Polynomial Ring in x over Real Double Field - sage: pushout(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) - Full MatrixSpace of 3 by 3 dense matrices over Power Series Ring in x over Integer Ring + Multivariate Polynomial Ring in y, z + over Fraction Field of Univariate Polynomial Ring in x over Integer Ring + sage: pushout(MatrixSpace(RDF, 2, 2), Frac(ZZ['x'])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices + over Fraction Field of Univariate Polynomial Ring in x over Real Double Field + sage: pushout(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # optional - sage.modules + Full MatrixSpace of 3 by 3 dense matrices + over Power Series Ring in x over Integer Ring sage: pushout(QQ['x,y'], ZZ[['x']]) - Univariate Polynomial Ring in y over Power Series Ring in x over Rational Field + Univariate Polynomial Ring in y + over Power Series Ring in x over Rational Field sage: pushout(Frac(ZZ['x']), QQ[['x']]) Laurent Series Ring in x over Rational Field - A construction with ``coercion_reversed = True`` (currently only + A construction with ``coercion_reversed=True`` (currently only the :class:`SubspaceFunctor` construction) is only applied if it leads to a valid coercion:: - sage: A = ZZ^2 - sage: V = span([[1, 2]], QQ) - sage: P = sage.categories.pushout.pushout(A, V) - sage: P + sage: A = ZZ^2 # optional - sage.modules + sage: V = span([[1, 2]], QQ) # optional - sage.modules + sage: P = sage.categories.pushout.pushout(A, V) # optional - sage.modules + sage: P # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: P.has_coerce_map_from(A) + sage: P.has_coerce_map_from(A) # optional - sage.modules True - sage: V = (QQ^3).span([[1, 2, 3/4]]) - sage: A = ZZ^3 - sage: pushout(A, V) + sage: V = (QQ^3).span([[1, 2, 3/4]]) # optional - sage.modules + sage: A = ZZ^3 # optional - sage.modules + sage: pushout(A, V) # optional - sage.modules Vector space of dimension 3 over Rational Field - sage: B = A.span([[0, 0, 2/3]]) - sage: pushout(B, V) + sage: B = A.span([[0, 0, 2/3]]) # optional - sage.modules + sage: pushout(B, V) # optional - sage.modules Vector space of degree 3 and dimension 2 over Rational Field User basis matrix: [1 2 0] [0 0 1] - Some more tests with ``coercion_reversed = True``:: + Some more tests with ``coercion_reversed=True``:: sage: from sage.categories.pushout import ConstructionFunctor sage: class EvenPolynomialRing(type(QQ['x'])): @@ -4082,10 +4152,14 @@ def pushout(R, S): sage: pushout(EvenPolynomialRing(QQ, 'x'), EvenPolynomialRing(RR, 'x')) Even Power Univariate Polynomial Ring in x over Real Field with 53 bits of precision - sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR^2) - Ambient free module of rank 2 over the principal ideal domain Even Power Univariate Polynomial Ring in x over Real Field with 53 bits of precision - sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR['x']^2) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Real Field with 53 bits of precision + sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR^2) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Even Power Univariate Polynomial Ring in x + over Real Field with 53 bits of precision + sage: pushout(EvenPolynomialRing(QQ, 'x')^2, RR['x']^2) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x + over Real Field with 53 bits of precision Some more tests related to univariate/multivariate constructions. We consider a generalization of polynomial rings, @@ -4153,7 +4227,8 @@ def pushout(R, S): sage: pushout(GP_ZZ(ZZ), GP_ZZ(QQ)) Generalized Polynomial Ring in X^(Integer Ring) over Rational Field sage: pushout(GP_ZZ(ZZ['t']), GP_ZZ(QQ)) - Generalized Polynomial Ring in X^(Integer Ring) over Univariate Polynomial Ring in t over Rational Field + Generalized Polynomial Ring in X^(Integer Ring) + over Univariate Polynomial Ring in t over Rational Field sage: pushout(GP_ZZ(ZZ['a,b']), GP_ZZ(ZZ['b,c'])) Generalized Polynomial Ring in X^(Integer Ring) over Multivariate Polynomial Ring in a, b, c over Integer Ring @@ -4197,14 +4272,17 @@ def pushout(R, S): ... CoercionException: ('Ambiguous Base Extension', ...) sage: pushout(GP_ZZt(ZZ['a,b']), GP_QQ(ZZ['b,c'])) - Generalized Polynomial Ring in X^(Univariate Polynomial Ring in t over Rational Field) + Generalized Polynomial Ring + in X^(Univariate Polynomial Ring in t over Rational Field) over Multivariate Polynomial Ring in a, b, c over Integer Ring Some tests with Cartesian products:: sage: from sage.sets.cartesian_product import CartesianProduct - sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), Sets().CartesianProducts()) - sage: B = CartesianProduct((ZZ['x'], ZZ['y'], ZZ['t']['z']), Sets().CartesianProducts()) + sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), + ....: Sets().CartesianProducts()) + sage: B = CartesianProduct((ZZ['x'], ZZ['y'], ZZ['t']['z']), + ....: Sets().CartesianProducts()) sage: A.construction() (The cartesian_product functorial construction, (Univariate Polynomial Ring in x over Integer Ring, @@ -4214,7 +4292,8 @@ def pushout(R, S): The Cartesian product of (Univariate Polynomial Ring in x over Integer Ring, Univariate Polynomial Ring in y over Rational Field, - Univariate Polynomial Ring in z over Univariate Polynomial Ring in t over Rational Field) + Univariate Polynomial Ring in z over + Univariate Polynomial Ring in t over Rational Field) sage: pushout(ZZ, cartesian_product([ZZ, QQ])) Traceback (most recent call last): ... @@ -4226,10 +4305,12 @@ def pushout(R, S): sage: from sage.sets.cartesian_product import CartesianProduct sage: class CartesianProductPoly(CartesianProduct): ....: def __init__(self, polynomial_rings): - ....: sort = sorted(polynomial_rings, key=lambda P: P.variable_name()) + ....: sort = sorted(polynomial_rings, + ....: key=lambda P: P.variable_name()) ....: super().__init__(sort, Sets().CartesianProducts()) ....: def vars(self): - ....: return tuple(P.variable_name() for P in self.cartesian_factors()) + ....: return tuple(P.variable_name() + ....: for P in self.cartesian_factors()) ....: def _pushout_(self, other): ....: if isinstance(other, CartesianProductPoly): ....: s_vars = self.vars() @@ -4263,7 +4344,7 @@ def pushout(R, S): (Univariate Polynomial Ring in x over Integer Ring, Univariate Polynomial Ring in y over Integer Ring, Univariate Polynomial Ring in z over Integer Ring) - sage: pushout(CartesianProductPoly((QQ['a,b']['x'], QQ['y'])), # optional - sage.symbolic + sage: pushout(CartesianProductPoly((QQ['a,b']['x'], QQ['y'])), # optional - sage.symbolic ....: CartesianProductPoly((ZZ['b,c']['x'], SR['z']))) The Cartesian product of (Univariate Polynomial Ring in x over @@ -4476,14 +4557,16 @@ def pushout_lattice(R, S): EXAMPLES:: sage: from sage.categories.pushout import pushout_lattice - sage: A, B = pushout_lattice(Qp(7), Frac(ZZ['x'])) - sage: A.codomain() - Fraction Field of Univariate Polynomial Ring in x over 7-adic Field with capped relative precision 20 - sage: A.codomain() is B.codomain() + sage: A, B = pushout_lattice(Qp(7), Frac(ZZ['x'])) # optional - sage.rings.padics + sage: A.codomain() # optional - sage.rings.padics + Fraction Field of Univariate Polynomial Ring in x + over 7-adic Field with capped relative precision 20 + sage: A.codomain() is B.codomain() # optional - sage.rings.padics True - sage: A, B = pushout_lattice(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) - sage: B - Identity endomorphism of Full MatrixSpace of 3 by 3 dense matrices over Power Series Ring in x over Integer Ring + sage: A, B = pushout_lattice(ZZ, MatrixSpace(ZZ[['x']], 3, 3)) # optional - sage.modules + sage: B # optional - sage.modules + Identity endomorphism of Full MatrixSpace of 3 by 3 dense matrices + over Power Series Ring in x over Integer Ring AUTHOR: @@ -4652,8 +4735,13 @@ def construction_tower(R): EXAMPLES:: sage: from sage.categories.pushout import construction_tower - sage: construction_tower(MatrixSpace(FractionField(QQ['t']),2)) - [(None, Full MatrixSpace of 2 by 2 dense matrices over Fraction Field of Univariate Polynomial Ring in t over Rational Field), (MatrixFunctor, Fraction Field of Univariate Polynomial Ring in t over Rational Field), (FractionField, Univariate Polynomial Ring in t over Rational Field), (Poly[t], Rational Field), (FractionField, Integer Ring)] + sage: construction_tower(MatrixSpace(FractionField(QQ['t']), 2)) # optional - sage.modules + [(None, Full MatrixSpace of 2 by 2 dense matrices over Fraction Field + of Univariate Polynomial Ring in t over Rational Field), + (MatrixFunctor, Fraction Field + of Univariate Polynomial Ring in t over Rational Field), + (FractionField, Univariate Polynomial Ring in t over Rational Field), + (Poly[t], Rational Field), (FractionField, Integer Ring)] """ tower = [(None, R)] @@ -4691,7 +4779,8 @@ def expand_tower(tower): (FractionField, Integer Ring)] sage: expand_tower(construction_tower(QQ['x,y,z'])) [(None, Multivariate Polynomial Ring in x, y, z over Rational Field), - (MPoly[z], Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field), + (MPoly[z], Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field), (MPoly[y], Univariate Polynomial Ring in x over Rational Field), (MPoly[x], Rational Field), (FractionField, Integer Ring)] diff --git a/src/sage/categories/quantum_group_representations.py b/src/sage/categories/quantum_group_representations.py index 125f06c03fa..08219858ca5 100644 --- a/src/sage/categories/quantum_group_representations.py +++ b/src/sage/categories/quantum_group_representations.py @@ -38,7 +38,7 @@ def super_categories(self): sage: from sage.categories.quantum_group_representations import QuantumGroupRepresentations sage: QuantumGroupRepresentations(ZZ['q'].fraction_field()).super_categories() [Category of vector spaces over - Fraction Field of Univariate Polynomial Ring in q over Integer Ring] + Fraction Field of Univariate Polynomial Ring in q over Integer Ring] """ return [Modules(self.base_ring())] @@ -51,7 +51,7 @@ def example(self): sage: from sage.categories.quantum_group_representations import QuantumGroupRepresentations sage: Cat = QuantumGroupRepresentations(ZZ['q'].fraction_field()) - sage: Cat.example() + sage: Cat.example() # optional - sage.combinat sage.modules V((2, 1, 0)) """ from sage.algebras.quantum_groups.representations import AdjointRepresentation @@ -79,7 +79,7 @@ def extra_super_categories(self): sage: Cat = QuantumGroupRepresentations(ZZ['q'].fraction_field()) sage: Cat.WithBasis().TensorProducts().extra_super_categories() [Category of quantum group representations with basis over - Fraction Field of Univariate Polynomial Ring in q over Integer Ring] + Fraction Field of Univariate Polynomial Ring in q over Integer Ring] """ return [self.base_category()] @@ -96,34 +96,34 @@ def e_on_basis(self, i, b): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: CM = crystals.Tableaux(['D',4], shape=[1]) - sage: VM = MinusculeRepresentation(R, CM) - sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) - sage: VA = AdjointRepresentation(R, CA) - sage: v = tensor([VM.an_element(), VA.an_element()]); v + sage: CM = crystals.Tableaux(['D',4], shape=[1]) # optional - sage.combinat sage.modules + sage: VM = MinusculeRepresentation(R, CM) # optional - sage.combinat sage.modules + sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) # optional - sage.combinat sage.modules + sage: VA = AdjointRepresentation(R, CA) # optional - sage.combinat sage.modules + sage: v = tensor([VM.an_element(), VA.an_element()]); v # optional - sage.combinat sage.modules 4*B[[[1]]] # B[[[1], [2]]] + 4*B[[[1]]] # B[[[1], [3]]] + 6*B[[[1]]] # B[[[2], [3]]] + 4*B[[[2]]] # B[[[1], [2]]] + 4*B[[[2]]] # B[[[1], [3]]] + 6*B[[[2]]] # B[[[2], [3]]] + 6*B[[[3]]] # B[[[1], [2]]] + 6*B[[[3]]] # B[[[1], [3]]] + 9*B[[[3]]] # B[[[2], [3]]] - sage: v.e(1) # indirect doctest + sage: v.e(1) # indirect doctest # optional - sage.combinat sage.modules 4*B[[[1]]] # B[[[1], [2]]] + ((4*q+6)/q)*B[[[1]]] # B[[[1], [3]]] + 6*B[[[1]]] # B[[[2], [3]]] + 6*q*B[[[2]]] # B[[[1], [3]]] + 9*B[[[3]]] # B[[[1], [3]]] - sage: v.e(2) # indirect doctest + sage: v.e(2) # indirect doctest # optional - sage.combinat sage.modules 4*B[[[1]]] # B[[[1], [2]]] + ((6*q+4)/q)*B[[[2]]] # B[[[1], [2]]] + 6*B[[[2]]] # B[[[1], [3]]] + 9*B[[[2]]] # B[[[2], [3]]] + 6*q*B[[[3]]] # B[[[1], [2]]] - sage: v.e(3) # indirect doctest + sage: v.e(3) # indirect doctest # optional - sage.combinat sage.modules 0 - sage: v.e(4) # indirect doctest + sage: v.e(4) # indirect doctest # optional - sage.combinat sage.modules 0 """ K_elt = [self._sets[k].K_on_basis(i, elt, -1) for k,elt in enumerate(b)] @@ -146,38 +146,38 @@ def f_on_basis(self, i, b): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: KM = crystals.KirillovReshetikhin(['B',3,1], 3,1) - sage: VM = MinusculeRepresentation(R, KM) - sage: KA = crystals.KirillovReshetikhin(['B',3,1], 2,1) - sage: VA = AdjointRepresentation(R, KA) - sage: v = tensor([VM.an_element(), VA.an_element()]); v + sage: KM = crystals.KirillovReshetikhin(['B',3,1], 3,1) # optional - sage.combinat sage.modules + sage: VM = MinusculeRepresentation(R, KM) # optional - sage.combinat sage.modules + sage: KA = crystals.KirillovReshetikhin(['B',3,1], 2,1) # optional - sage.combinat sage.modules + sage: VA = AdjointRepresentation(R, KA) # optional - sage.combinat sage.modules + sage: v = tensor([VM.an_element(), VA.an_element()]); v # optional - sage.combinat sage.modules 4*B[[+++, []]] # B[[]] + 4*B[[+++, []]] # B[[[1], [2]]] + 6*B[[+++, []]] # B[[[1], [3]]] + 4*B[[++-, []]] # B[[]] + 4*B[[++-, []]] # B[[[1], [2]]] + 6*B[[++-, []]] # B[[[1], [3]]] + 6*B[[+-+, []]] # B[[]] + 6*B[[+-+, []]] # B[[[1], [2]]] + 9*B[[+-+, []]] # B[[[1], [3]]] - sage: v.f(0) # indirect doctest + sage: v.f(0) # indirect doctest # optional - sage.combinat sage.modules ((4*q^4+4)/q^2)*B[[+++, []]] # B[[[1], [2]]] + ((4*q^4+4)/q^2)*B[[++-, []]] # B[[[1], [2]]] + ((6*q^4+6)/q^2)*B[[+-+, []]] # B[[[1], [2]]] - sage: v.f(1) # indirect doctest + sage: v.f(1) # indirect doctest # optional - sage.combinat sage.modules 6*B[[+++, []]] # B[[[2], [3]]] + 6*B[[++-, []]] # B[[[2], [3]]] + 9*B[[+-+, []]] # B[[[2], [3]]] + 6*B[[-++, []]] # B[[]] + 6*B[[-++, []]] # B[[[1], [2]]] + 9*q^2*B[[-++, []]] # B[[[1], [3]]] - sage: v.f(2) # indirect doctest + sage: v.f(2) # indirect doctest # optional - sage.combinat sage.modules 4*B[[+++, []]] # B[[[1], [3]]] + 4*B[[++-, []]] # B[[[1], [3]]] + 4*B[[+-+, []]] # B[[]] + 4*q^2*B[[+-+, []]] # B[[[1], [2]]] + ((6*q^2+6)/q^2)*B[[+-+, []]] # B[[[1], [3]]] - sage: v.f(3) # indirect doctest + sage: v.f(3) # indirect doctest # optional - sage.combinat sage.modules 6*B[[+++, []]] # B[[[1], [0]]] + 4*B[[++-, []]] # B[[]] + 4*B[[++-, []]] # B[[[1], [2]]] @@ -209,22 +209,22 @@ def K_on_basis(self, i, b, power=1): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: CM = crystals.Tableaux(['A',2], shape=[1]) - sage: VM = MinusculeRepresentation(R, CM) - sage: CA = crystals.Tableaux(['A',2], shape=[2,1]) - sage: VA = AdjointRepresentation(R, CA) - sage: v = tensor([sum(VM.basis()), VA.module_generator()]); v + sage: CM = crystals.Tableaux(['A',2], shape=[1]) # optional - sage.combinat sage.modules + sage: VM = MinusculeRepresentation(R, CM) # optional - sage.combinat sage.modules + sage: CA = crystals.Tableaux(['A',2], shape=[2,1]) # optional - sage.combinat sage.modules + sage: VA = AdjointRepresentation(R, CA) # optional - sage.combinat sage.modules + sage: v = tensor([sum(VM.basis()), VA.module_generator()]); v # optional - sage.combinat sage.modules B[[[1]]] # B[[[1, 1], [2]]] + B[[[2]]] # B[[[1, 1], [2]]] + B[[[3]]] # B[[[1, 1], [2]]] - sage: v.K(1) # indirect doctest + sage: v.K(1) # indirect doctest # optional - sage.combinat sage.modules q^2*B[[[1]]] # B[[[1, 1], [2]]] + B[[[2]]] # B[[[1, 1], [2]]] + q*B[[[3]]] # B[[[1, 1], [2]]] - sage: v.K(2, -1) # indirect doctest + sage: v.K(2, -1) # indirect doctest # optional - sage.combinat sage.modules 1/q*B[[[1]]] # B[[[1, 1], [2]]] + 1/q^2*B[[[2]]] # B[[[1, 1], [2]]] + B[[[3]]] # B[[[1, 1], [2]]] @@ -241,24 +241,24 @@ def tensor(*factors): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) sage: R = ZZ['q'].fraction_field() - sage: CM = crystals.Tableaux(['D',4], shape=[1]) - sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) - sage: V = MinusculeRepresentation(R, CM) - sage: V.tensor(V, V) + sage: CM = crystals.Tableaux(['D',4], shape=[1]) # optional - sage.combinat sage.modules + sage: CA = crystals.Tableaux(['D',4], shape=[1,1]) # optional - sage.combinat sage.modules + sage: V = MinusculeRepresentation(R, CM) # optional - sage.combinat sage.modules + sage: V.tensor(V, V) # optional - sage.combinat sage.modules V((1, 0, 0, 0)) # V((1, 0, 0, 0)) # V((1, 0, 0, 0)) - sage: A = MinusculeRepresentation(R, CA) - sage: V.tensor(A) + sage: A = MinusculeRepresentation(R, CA) # optional - sage.combinat sage.modules + sage: V.tensor(A) # optional - sage.combinat sage.modules V((1, 0, 0, 0)) # V((1, 1, 0, 0)) - sage: B = crystals.Tableaux(['A',2], shape=[1]) - sage: W = MinusculeRepresentation(R, B) - sage: tensor([W,V]) + sage: B = crystals.Tableaux(['A',2], shape=[1]) # optional - sage.combinat sage.modules + sage: W = MinusculeRepresentation(R, B) # optional - sage.combinat sage.modules + sage: tensor([W,V]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: all factors must be of the same Cartan type - sage: tensor([V,A,W]) + sage: tensor([V,A,W]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: all factors must be of the same Cartan type @@ -279,15 +279,15 @@ def e(self, i): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation - sage: C = crystals.Tableaux(['G',2], shape=[1,1]) - sage: R = ZZ['q'].fraction_field() - sage: V = AdjointRepresentation(R, C) - sage: v = V.an_element(); v + sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation # optional - sage.combinat sage.modules + sage: C = crystals.Tableaux(['G',2], shape=[1,1]) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = AdjointRepresentation(R, C) # optional - sage.combinat sage.modules + sage: v = V.an_element(); v # optional - sage.combinat sage.modules 2*B[[[1], [2]]] + 2*B[[[1], [3]]] + 3*B[[[2], [3]]] - sage: v.e(1) + sage: v.e(1) # optional - sage.combinat sage.modules ((3*q^4+3*q^2+3)/q^2)*B[[[1], [3]]] - sage: v.e(2) + sage: v.e(2) # optional - sage.combinat sage.modules 2*B[[[1], [2]]] """ F = self.parent() @@ -305,21 +305,21 @@ def f(self, i): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation - sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,1) - sage: R = ZZ['q'].fraction_field() - sage: V = AdjointRepresentation(R, K) - sage: v = V.an_element(); v + sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation # optional - sage.combinat sage.modules + sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,1) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = AdjointRepresentation(R, K) # optional - sage.combinat sage.modules + sage: v = V.an_element(); v # optional - sage.combinat sage.modules 2*B[[]] + 2*B[[[1], [2]]] + 3*B[[[1], [3]]] - sage: v.f(0) + sage: v.f(0) # optional - sage.combinat sage.modules ((2*q^2+2)/q)*B[[[1], [2]]] - sage: v.f(1) + sage: v.f(1) # optional - sage.combinat sage.modules 3*B[[[2], [3]]] - sage: v.f(2) + sage: v.f(2) # optional - sage.combinat sage.modules 2*B[[[1], [3]]] - sage: v.f(3) + sage: v.f(3) # optional - sage.combinat sage.modules 3*B[[[1], [4]]] - sage: v.f(4) + sage: v.f(4) # optional - sage.combinat sage.modules 3*B[[[1], [-4]]] """ F = self.parent() @@ -338,19 +338,19 @@ def K(self, i, power=1): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation - sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1) - sage: R = ZZ['q'].fraction_field() - sage: V = AdjointRepresentation(R, K) - sage: v = V.an_element(); v + sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation # optional - sage.combinat sage.modules + sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = AdjointRepresentation(R, K) # optional - sage.combinat sage.modules + sage: v = V.an_element(); v # optional - sage.combinat sage.modules 2*B[[]] + 2*B[[[1]]] + 3*B[[[2]]] - sage: v.K(0) + sage: v.K(0) # optional - sage.combinat sage.modules 2*B[[]] + 2/q^2*B[[[1]]] + 3*B[[[2]]] - sage: v.K(1) + sage: v.K(1) # optional - sage.combinat sage.modules 2*B[[]] + 2*q^2*B[[[1]]] + 3/q^2*B[[[2]]] - sage: v.K(1, 2) + sage: v.K(1, 2) # optional - sage.combinat sage.modules 2*B[[]] + 2*q^4*B[[[1]]] + 3/q^4*B[[[2]]] - sage: v.K(1, -1) + sage: v.K(1, -1) # optional - sage.combinat sage.modules 2*B[[]] + 2/q^2*B[[[1]]] + 3*q^2*B[[[2]]] """ F = self.parent() @@ -388,12 +388,12 @@ def cartan_type(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation - sage: C = crystals.Tableaux(['C',2], shape=[1]) - sage: R = ZZ['q'].fraction_field() - sage: V = MinusculeRepresentation(R, C) - sage: T = tensor([V,V]) - sage: T.cartan_type() + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules + sage: C = crystals.Tableaux(['C',2], shape=[1]) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules + sage: T = tensor([V,V]) # optional - sage.combinat sage.modules + sage: T.cartan_type() # optional - sage.combinat sage.modules ['C', 2] """ return self._sets[0].cartan_type() @@ -407,18 +407,18 @@ def _test_representation(self, tester=None, **options): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import \ - ....: MinusculeRepresentation, AdjointRepresentation - sage: C = crystals.Tableaux(['G',2], shape=[1,1]) - sage: R = ZZ['q'].fraction_field() - sage: V = AdjointRepresentation(R, C) - sage: V._test_representation() + sage: from sage.algebras.quantum_groups.representations import ( # optional - sage.combinat sage.modules + ....: MinusculeRepresentation, AdjointRepresentation) + sage: C = crystals.Tableaux(['G',2], shape=[1,1]) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = AdjointRepresentation(R, C) # optional - sage.combinat sage.modules + sage: V._test_representation() # optional - sage.combinat sage.modules We verify that ``C`` does not define a minuscule representation:: - sage: M = MinusculeRepresentation(R, C) - sage: M._test_representation() + sage: M = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules + sage: M._test_representation() # optional - sage.combinat sage.modules Traceback (most recent call last): ... AssertionError: [e,f] = (K-K^-1)/(q_i-q_i^-1) -- i: 1 j: 1 @@ -489,11 +489,11 @@ def cartan_type(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation - sage: C = crystals.Tableaux(['C',4], shape=[1]) - sage: R = ZZ['q'].fraction_field() - sage: V = MinusculeRepresentation(R, C) - sage: V.cartan_type() + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules + sage: C = crystals.Tableaux(['C',4], shape=[1]) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules + sage: V.cartan_type() # optional - sage.combinat sage.modules ['C', 4] """ @@ -504,11 +504,11 @@ def index_set(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation - sage: C = crystals.Tableaux(['C',4], shape=[1]) - sage: R = ZZ['q'].fraction_field() - sage: V = MinusculeRepresentation(R, C) - sage: V.index_set() + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules + sage: C = crystals.Tableaux(['C',4], shape=[1]) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules + sage: V.index_set() # optional - sage.combinat sage.modules (1, 2, 3, 4) """ return self.cartan_type().index_set() @@ -519,11 +519,11 @@ def q(self): EXAMPLES:: - sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation - sage: C = crystals.Tableaux(['C',4], shape=[1]) - sage: R = ZZ['q'].fraction_field() - sage: V = MinusculeRepresentation(R, C) - sage: V.q() + sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation # optional - sage.combinat sage.modules + sage: C = crystals.Tableaux(['C',4], shape=[1]) # optional - sage.combinat sage.modules + sage: R = ZZ['q'].fraction_field() # optional - sage.combinat sage.modules + sage: V = MinusculeRepresentation(R, C) # optional - sage.combinat sage.modules + sage: V.q() # optional - sage.combinat sage.modules q """ return self._q diff --git a/src/sage/categories/quotient_fields.py b/src/sage/categories/quotient_fields.py index 02780268c8f..02497982e72 100644 --- a/src/sage/categories/quotient_fields.py +++ b/src/sage/categories/quotient_fields.py @@ -75,17 +75,17 @@ def gcd(self, other): sage: R. = QQ['x'] sage: p = (1+x)^3*(1+2*x^2)/(1-x^5) sage: q = (1+x)^2*(1+3*x^2)/(1-x^4) - sage: factor(p) + sage: factor(p) # optional - sage.libs.pari (-2) * (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/2) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(q) + sage: factor(q) # optional - sage.libs.pari (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) - sage: gcd(p,q) + sage: gcd(p, q) (x + 1)/(x^7 + x^5 - x^2 - 1) - sage: factor(gcd(p,q)) + sage: factor(gcd(p, q)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(gcd(p,1+x)) + sage: factor(gcd(p, 1 + x)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(gcd(1+x,q)) + sage: factor(gcd(1 + x, q)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 TESTS: @@ -93,22 +93,25 @@ def gcd(self, other): The following tests that the fraction field returns a correct gcd even if the base ring does not provide lcm and gcd:: - sage: R = ZZ.extension(x^2+1, names='i') - sage: i = R.1 - sage: gcd(5, 3 + 4*i) + sage: R = ZZ.extension(x^2 + 1, names='i') # optional - sage.rings.number_field + sage: i = R.1 # optional - sage.rings.number_field + sage: gcd(5, 3 + 4*i) # optional - sage.rings.number_field -i - 2 - sage: P. = R[] - sage: gcd(t, i) + sage: P. = R[] # optional - sage.rings.number_field + sage: gcd(t, i) # optional - sage.rings.number_field Traceback (most recent call last): ... - NotImplementedError: Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 does not provide a gcd implementation for univariate polynomials - sage: q = t/(t+1); q.parent() - Fraction Field of Univariate Polynomial Ring in t over Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 - sage: gcd(q, q) + NotImplementedError: Gaussian Integers in Number Field in i with + defining polynomial x^2 + 1 does not provide a gcd implementation + for univariate polynomials + sage: q = t/(t + 1); q.parent() # optional - sage.rings.number_field + Fraction Field of Univariate Polynomial Ring in t over Gaussian + Integers in Number Field in i with defining polynomial x^2 + 1 + sage: gcd(q, q) # optional - sage.rings.number_field 1 - sage: q.gcd(0) + sage: q.gcd(0) # optional - sage.rings.number_field 1 - sage: (q*0).gcd(0) + sage: (q*0).gcd(0) # optional - sage.rings.number_field 0 """ P = self.parent() @@ -177,15 +180,15 @@ def lcm(self, other): sage: R. = QQ[] sage: p = (1+x)^3*(1+2*x^2)/(1-x^5) sage: q = (1+x)^2*(1+3*x^2)/(1-x^4) - sage: factor(p) + sage: factor(p) # optional - sage.libs.pari (-2) * (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/2) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(q) + sage: factor(q) # optional - sage.libs.pari (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) - sage: factor(lcm(p,q)) + sage: factor(lcm(p, q)) # optional - sage.libs.pari (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/3) * (x^2 + 1/2) - sage: factor(lcm(p,1+x)) + sage: factor(lcm(p, 1 + x)) # optional - sage.libs.pari (x + 1)^3 * (x^2 + 1/2) - sage: factor(lcm(1+x,q)) + sage: factor(lcm(1 + x, q)) # optional - sage.libs.pari (x + 1) * (x^2 + 1/3) TESTS: @@ -193,20 +196,23 @@ def lcm(self, other): The following tests that the fraction field returns a correct lcm even if the base ring does not provide lcm and gcd:: - sage: R = ZZ.extension(x^2+1, names='i') - sage: i = R.1 - sage: P. = R[] - sage: lcm(t, i) + sage: R = ZZ.extension(x^2+1, names='i') # optional - sage.rings.number_field + sage: i = R.1 # optional - sage.rings.number_field + sage: P. = R[] # optional - sage.rings.number_field + sage: lcm(t, i) # optional - sage.rings.number_field Traceback (most recent call last): ... - NotImplementedError: Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 does not provide a gcd implementation for univariate polynomials - sage: q = t/(t+1); q.parent() - Fraction Field of Univariate Polynomial Ring in t over Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 - sage: lcm(q, q) + NotImplementedError: Gaussian Integers in Number Field in i with + defining polynomial x^2 + 1 does not provide a gcd implementation + for univariate polynomials + sage: q = t/(t + 1); q.parent() # optional - sage.rings.number_field + Fraction Field of Univariate Polynomial Ring in t over Gaussian + Integers in Number Field in i with defining polynomial x^2 + 1 + sage: lcm(q, q) # optional - sage.rings.number_field 1 - sage: q.lcm(0) + sage: q.lcm(0) # optional - sage.rings.number_field 0 - sage: (q*0).lcm(0) + sage: (q*0).lcm(0) # optional - sage.rings.number_field 0 Check that it is possible to take lcm of a rational and an integer @@ -266,11 +272,11 @@ def xgcd(self, other): sage: R. = QQ['x'] sage: p = (1+x)^3*(1+2*x^2)/(1-x^5) sage: q = (1+x)^2*(1+3*x^2)/(1-x^4) - sage: factor(p) + sage: factor(p) # optional - sage.libs.pari (-2) * (x - 1)^-1 * (x + 1)^3 * (x^2 + 1/2) * (x^4 + x^3 + x^2 + x + 1)^-1 - sage: factor(q) + sage: factor(q) # optional - sage.libs.pari (-3) * (x - 1)^-1 * (x + 1) * (x^2 + 1)^-1 * (x^2 + 1/3) - sage: g,s,t = xgcd(p,q) + sage: g, s, t = xgcd(p, q) sage: g (x + 1)/(x^7 + x^5 - x^2 - 1) sage: g == s*p + t*q @@ -278,21 +284,21 @@ def xgcd(self, other): An example without a well defined gcd or xgcd on its base ring:: - sage: K = QuadraticField(5) - sage: O = K.maximal_order() - sage: R = PolynomialRing(O, 'x') - sage: F = R.fraction_field() - sage: x = F.gen(0) - sage: x.gcd(x+1) + sage: K = QuadraticField(5) # optional - sage.rings.number_field + sage: O = K.maximal_order() # optional - sage.rings.number_field + sage: R = PolynomialRing(O, 'x') # optional - sage.rings.number_field + sage: F = R.fraction_field() # optional - sage.rings.number_field + sage: x = F.gen(0) # optional - sage.rings.number_field + sage: x.gcd(x+1) # optional - sage.rings.number_field 1 - sage: x.xgcd(x+1) + sage: x.xgcd(x+1) # optional - sage.rings.number_field (1, 1/x, 0) - sage: zero = F.zero() - sage: zero.gcd(x) + sage: zero = F.zero() # optional - sage.rings.number_field + sage: zero.gcd(x) # optional - sage.rings.number_field 1 - sage: zero.xgcd(x) + sage: zero.xgcd(x) # optional - sage.rings.number_field (1, 0, 1/x) - sage: zero.xgcd(zero) + sage: zero.xgcd(zero) # optional - sage.rings.number_field (0, 0, 0) """ P = self.parent() @@ -340,14 +346,14 @@ def factor(self, *args, **kwds): sage: K. = QQ[] sage: f = (x^3+x)/(x-3) - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (x - 3)^-1 * x * (x^2 + 1) Here is an example to show that :trac:`7868` has been resolved:: - sage: R. = GF(2)[] - sage: f = x*y/(x+y) - sage: f.factor() + sage: R. = GF(2)[] # optional - sage.libs.pari + sage: f = x*y/(x+y) # optional - sage.libs.pari + sage: f.factor() # optional - sage.libs.pari (x + y)^-1 * y * x """ return (self.numerator().factor(*args, **kwds) / @@ -380,36 +386,38 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: S. = QQ[] sage: q = 1/(t+1) + 2/(t+2) + 3/(t-3); q (6*t^2 + 4*t - 6)/(t^3 - 7*t - 6) - sage: whole, parts = q.partial_fraction_decomposition(); parts + sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.libs.pari [3/(t - 3), 1/(t + 1), 2/(t + 2)] - sage: sum(parts) == q + sage: sum(parts) == q # optional - sage.libs.pari True - sage: q = 1/(t^3+1) + 2/(t^2+2) + 3/(t-3)^5 - sage: whole, parts = q.partial_fraction_decomposition(); parts - [1/3/(t + 1), 3/(t^5 - 15*t^4 + 90*t^3 - 270*t^2 + 405*t - 243), (-1/3*t + 2/3)/(t^2 - t + 1), 2/(t^2 + 2)] - sage: sum(parts) == q + sage: q = 1/(t^3+1) + 2/(t^2+2) + 3/(t-3)^5 # optional - sage.libs.pari + sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.libs.pari + [1/3/(t + 1), 3/(t^5 - 15*t^4 + 90*t^3 - 270*t^2 + 405*t - 243), + (-1/3*t + 2/3)/(t^2 - t + 1), 2/(t^2 + 2)] + sage: sum(parts) == q # optional - sage.libs.pari True - sage: q = 2*t / (t + 3)^2 - sage: q.partial_fraction_decomposition() + sage: q = 2*t / (t + 3)^2 # optional - sage.libs.pari + sage: q.partial_fraction_decomposition() # optional - sage.libs.pari (0, [2/(t + 3), -6/(t^2 + 6*t + 9)]) - sage: for p in q.partial_fraction_decomposition()[1]: print(p.factor()) + sage: for p in q.partial_fraction_decomposition()[1]: # optional - sage.libs.pari + ....: print(p.factor()) (2) * (t + 3)^-1 (-6) * (t + 3)^-2 - sage: q.partial_fraction_decomposition(decompose_powers=False) + sage: q.partial_fraction_decomposition(decompose_powers=False) # optional - sage.libs.pari (0, [2*t/(t^2 + 6*t + 9)]) We can decompose over a given algebraic extension:: - sage: R. = QQ[sqrt(2)][] - sage: r = 1/(x^4+1) - sage: r.partial_fraction_decomposition() + sage: R. = QQ[sqrt(2)][] # optional - sage.rings.number_field + sage: r = 1/(x^4+1) # optional - sage.rings.number_field + sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field (0, [(-1/4*sqrt2*x + 1/2)/(x^2 - sqrt2*x + 1), (1/4*sqrt2*x + 1/2)/(x^2 + sqrt2*x + 1)]) - sage: R. = QQ[I][] # of QQ[sqrt(-1)] - sage: r = 1/(x^4+1) - sage: r.partial_fraction_decomposition() + sage: R. = QQ[I][] # of QQ[sqrt(-1)] # optional - sage.rings.number_field + sage: r = 1/(x^4+1) # optional - sage.rings.number_field + sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field (0, [(-1/2*I)/(x^2 - I), 1/2*I/(x^2 + I)]) We can also ask Sage to find the least extension where the @@ -417,12 +425,12 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = QQ[] sage: r = 1/(x^4+2) - sage: N = r.denominator().splitting_field('a') - sage: N + sage: N = r.denominator().splitting_field('a') # optional - sage.rings.number_field + sage: N # optional - sage.rings.number_field Number Field in a with defining polynomial x^8 - 8*x^6 + 28*x^4 + 16*x^2 + 36 - sage: R1.=N[] - sage: r1 = 1/(x1^4+2) - sage: r1.partial_fraction_decomposition() + sage: R1. = N[] # optional - sage.rings.number_field + sage: r1 = 1/(x1^4+2) # optional - sage.rings.number_field + sage: r1.partial_fraction_decomposition() # optional - sage.rings.number_field (0, [(-1/224*a^6 + 13/448*a^4 - 5/56*a^2 - 25/224)/(x1 - 1/28*a^6 + 13/56*a^4 - 5/7*a^2 - 25/28), (1/224*a^6 - 13/448*a^4 + 5/56*a^2 + 25/224)/(x1 + 1/28*a^6 - 13/56*a^4 + 5/7*a^2 + 25/28), @@ -431,9 +439,9 @@ def partial_fraction_decomposition(self, decompose_powers=True): Or we may work directly over an algebraically closed field:: - sage: R. = QQbar[] - sage: r = 1/(x^4+1) - sage: r.partial_fraction_decomposition() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: r = 1/(x^4+1) # optional - sage.rings.number_field + sage: r.partial_fraction_decomposition() # optional - sage.rings.number_field (0, [(-0.1767766952966369? - 0.1767766952966369?*I)/(x - 0.7071067811865475? - 0.7071067811865475?*I), (-0.1767766952966369? + 0.1767766952966369?*I)/(x - 0.7071067811865475? + 0.7071067811865475?*I), @@ -445,7 +453,7 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = RealField(20)[] sage: q = 1/(x^2 + x + 2)^2 + 1/(x-1); q (x^4 + 2.0000*x^3 + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) - sage: whole, parts = q.partial_fraction_decomposition(); parts + sage: whole, parts = q.partial_fraction_decomposition(); parts # optional - sage.rings.number_field [1.0000/(x - 1.0000), 1.0000/(x^4 + 2.0000*x^3 + 5.0000*x^2 + 4.0000*x + 4.0000)] sage: sum(parts) (x^4 + 2.0000*x^3 + 5.0000*x^2 + 5.0000*x + 3.0000)/(x^5 + x^4 + 3.0000*x^3 - x^2 - 4.0000) @@ -456,23 +464,23 @@ def partial_fraction_decomposition(self, decompose_powers=True): sage: R. = ZZ[] sage: q = x^2/(x-1) - sage: q.partial_fraction_decomposition() + sage: q.partial_fraction_decomposition() # optional - sage.libs.pari (x + 1, [1/(x - 1)]) sage: q = x^10/(x-1)^5 - sage: whole, parts = q.partial_fraction_decomposition() - sage: whole + sum(parts) == q + sage: whole, parts = q.partial_fraction_decomposition() # optional - sage.libs.pari + sage: whole + sum(parts) == q # optional - sage.libs.pari True And also over finite fields (see :trac:`6052`, :trac:`9945`):: - sage: R. = GF(2)[] - sage: q = (x+1)/(x^3+x+1) - sage: q.partial_fraction_decomposition() + sage: R. = GF(2)[] # optional - sage.libs.pari + sage: q = (x+1)/(x^3+x+1) # optional - sage.libs.pari + sage: q.partial_fraction_decomposition() # optional - sage.libs.pari (0, [(x + 1)/(x^3 + x + 1)]) - sage: R. = GF(11)[] - sage: q = x + 1 + 1/(x+1) + x^2/(x^3 + 2*x + 9) - sage: q.partial_fraction_decomposition() + sage: R. = GF(11)[] # optional - sage.libs.pari + sage: q = x + 1 + 1/(x+1) + x^2/(x^3 + 2*x + 9) # optional - sage.libs.pari + sage: q.partial_fraction_decomposition() # optional - sage.libs.pari (x + 1, [1/(x + 1), x^2/(x^3 + 2*x + 9)]) And even the rationals:: diff --git a/src/sage/categories/realizations.py b/src/sage/categories/realizations.py index bbe9a8e8ad4..0207b66a4be 100644 --- a/src/sage/categories/realizations.py +++ b/src/sage/categories/realizations.py @@ -66,19 +66,23 @@ def Realizations(self): The category of realizations of some algebra:: sage: Algebras(QQ).Realizations() - Join of Category of algebras over Rational Field and Category of realizations of unital magmas + Join of Category of algebras over Rational Field + and Category of realizations of unital magmas The category of realizations of a given algebra:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.Realizations() - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field + sage: A.Realizations() # optional - sage.combinat sage.modules + Category of realizations of + The subset algebra of {1, 2, 3} over Rational Field sage: C = GradedHopfAlgebrasWithBasis(QQ).Realizations(); C - Join of Category of graded hopf algebras with basis over Rational Field and Category of realizations of hopf algebras over Rational Field + Join of Category of graded hopf algebras with basis over Rational Field + and Category of realizations of hopf algebras over Rational Field sage: C.super_categories() - [Category of graded hopf algebras with basis over Rational Field, Category of realizations of hopf algebras over Rational Field] + [Category of graded hopf algebras with basis over Rational Field, + Category of realizations of hopf algebras over Rational Field] sage: TestSuite(C).run() @@ -91,7 +95,7 @@ def Realizations(self): Add an optional argument to allow for:: - sage: Realizations(A, category = Blahs()) # todo: not implemented + sage: Realizations(A, category=Blahs()) # todo: not implemented """ if isinstance(self, Category): return RealizationsCategory.category_of(self) @@ -112,7 +116,7 @@ class Category_realization_of_parent(Category_over_base, BindableClass): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field The role of this base class is to implement some technical goodies, like @@ -120,8 +124,9 @@ class Category_realization_of_parent(Category_over_base, BindableClass): implemented as a nested class in ``A`` (see the :mod:`code of the example `):: - sage: C = A.Realizations(); C - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field + sage: C = A.Realizations(); C # optional - sage.combinat sage.modules + Category of realizations of + The subset algebra of {1, 2, 3} over Rational Field as well as the name for that category. """ @@ -130,15 +135,16 @@ def __init__(self, parent_with_realization): TESTS:: sage: from sage.categories.realizations import Category_realization_of_parent - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: C = A.Realizations(); C - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field - sage: isinstance(C, Category_realization_of_parent) + sage: C = A.Realizations(); C # optional - sage.combinat sage.modules + Category of realizations of + The subset algebra of {1, 2, 3} over Rational Field + sage: isinstance(C, Category_realization_of_parent) # optional - sage.combinat sage.modules True - sage: C.parent_with_realization + sage: C.parent_with_realization # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: TestSuite(C).run(skip=["_test_category_over_bases"]) + sage: TestSuite(C).run(skip=["_test_category_over_bases"]) # optional - sage.combinat sage.modules .. TODO:: @@ -161,8 +167,8 @@ def _get_name(self): sage: from sage.categories.realizations import Category_realization_of_parent sage: class MultiplicativeBasesOnPrimitiveElements(Category_realization_of_parent): ....: def super_categories(self): return [Objects()] - sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") - sage: MultiplicativeBasesOnPrimitiveElements(Sym)._get_name() + sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # optional - sage.combinat + sage: MultiplicativeBasesOnPrimitiveElements(Sym)._get_name() # optional - sage.combinat 'multiplicative bases on primitive elements' """ import re @@ -179,10 +185,10 @@ def _repr_object_names(self): sage: from sage.categories.realizations import Category_realization_of_parent sage: class MultiplicativeBasesOnPrimitiveElements(Category_realization_of_parent): ....: def super_categories(self): return [Objects()] - sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") - sage: C = MultiplicativeBasesOnPrimitiveElements(Sym); C + sage: Sym = SymmetricFunctions(QQ); Sym.rename("Sym") # optional - sage.combinat + sage: C = MultiplicativeBasesOnPrimitiveElements(Sym); C # optional - sage.combinat Category of multiplicative bases on primitive elements of Sym - sage: C._repr_object_names() + sage: C._repr_object_names() # optional - sage.combinat 'multiplicative bases on primitive elements of Sym' """ return "{} of {}".format(self._get_name(), self.base()) diff --git a/src/sage/categories/regular_crystals.py b/src/sage/categories/regular_crystals.py index f5412fe6ab1..afad9e78c22 100644 --- a/src/sage/categories/regular_crystals.py +++ b/src/sage/categories/regular_crystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Regular Crystals """ @@ -133,21 +134,21 @@ def is_isomorphism(self): EXAMPLES:: - sage: La = RootSystem(['A',2,1]).weight_space(extended=True).fundamental_weights() + sage: A21 = RootSystem(['A',2,1]) + sage: La = A21.weight_space(extended=True).fundamental_weights() sage: B = crystals.LSPaths(La[0]) - sage: La = RootSystem(['A',2,1]).weight_lattice(extended=True).fundamental_weights() + sage: La = A21.weight_lattice(extended=True).fundamental_weights() sage: C = crystals.GeneralizedYoungWalls(2, La[0]) sage: H = Hom(B, C) sage: from sage.categories.highest_weight_crystals import HighestWeightCrystalMorphism sage: class Psi(HighestWeightCrystalMorphism): ....: def is_strict(self): ....: return True - sage: psi = Psi(H, C.module_generators) - sage: psi + sage: psi = Psi(H, C.module_generators); psi ['A', 2, 1] Crystal morphism: From: The crystal of LS paths of type ['A', 2, 1] and weight Lambda[0] - To: Highest weight crystal of generalized Young walls of Cartan type ['A', 2, 1] - and highest weight Lambda[0] + To: Highest weight crystal of generalized Young walls + of Cartan type ['A', 2, 1] and highest weight Lambda[0] Defn: (Lambda[0],) |--> [] sage: psi.is_isomorphism() True @@ -184,25 +185,28 @@ def demazure_operator(self, element, reduced_word): EXAMPLES:: sage: T = crystals.Tableaux(['A',2], shape=[2,1]) - sage: C = CombinatorialFreeModule(QQ,T) + sage: C = CombinatorialFreeModule(QQ, T) sage: t = T.highest_weight_vector() sage: b = 2*C(t) sage: T.demazure_operator(b,[1,2,1]) - 2*B[[[1, 1], [2]]] + 2*B[[[1, 2], [2]]] + 2*B[[[1, 3], [2]]] + 2*B[[[1, 1], [3]]] - + 2*B[[[1, 2], [3]]] + 2*B[[[1, 3], [3]]] + 2*B[[[2, 2], [3]]] + 2*B[[[2, 3], [3]]] + 2*B[[[1, 1], [2]]] + 2*B[[[1, 2], [2]]] + 2*B[[[1, 3], [2]]] + + 2*B[[[1, 1], [3]]] + 2*B[[[1, 2], [3]]] + 2*B[[[1, 3], [3]]] + + 2*B[[[2, 2], [3]]] + 2*B[[[2, 3], [3]]] The Demazure operator is idempotent:: - sage: T = crystals.Tableaux("A1",shape=[4]) - sage: C = CombinatorialFreeModule(QQ,T) + sage: T = crystals.Tableaux("A1", shape=[4]) + sage: C = CombinatorialFreeModule(QQ, T) sage: b = C(T.module_generators[0]); b B[[[1, 1, 1, 1]]] sage: e = T.demazure_operator(b,[1]); e - B[[[1, 1, 1, 1]]] + B[[[1, 1, 1, 2]]] + B[[[1, 1, 2, 2]]] + B[[[1, 2, 2, 2]]] + B[[[2, 2, 2, 2]]] + B[[[1, 1, 1, 1]]] + B[[[1, 1, 1, 2]]] + B[[[1, 1, 2, 2]]] + + B[[[1, 2, 2, 2]]] + B[[[2, 2, 2, 2]]] sage: e == T.demazure_operator(e,[1]) True - sage: all(T.demazure_operator(T.demazure_operator(C(t),[1]),[1]) == T.demazure_operator(C(t),[1]) for t in T) + sage: all(T.demazure_operator(T.demazure_operator(C(t),[1]),[1]) + ....: == T.demazure_operator(C(t),[1]) for t in T) True """ M = element.parent() diff --git a/src/sage/categories/regular_supercrystals.py b/src/sage/categories/regular_supercrystals.py index 2ed4531c673..9fd6f5c8a83 100644 --- a/src/sage/categories/regular_supercrystals.py +++ b/src/sage/categories/regular_supercrystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.graphs r""" Regular Supercrystals """ @@ -107,7 +108,7 @@ def epsilon(self, i): EXAMPLES:: - sage: C = crystals.Tableaux(['A',[1,2]], shape = [2,1]) + sage: C = crystals.Tableaux(['A',[1,2]], shape=[2,1]) sage: c = C.an_element(); c [[-2, -2], [-1]] sage: c.epsilon(2) @@ -132,7 +133,7 @@ def phi(self, i): EXAMPLES:: - sage: C = crystals.Tableaux(['A',[1,2]], shape = [2,1]) + sage: C = crystals.Tableaux(['A',[1,2]], shape=[2,1]) sage: c = C.an_element(); c [[-2, -2], [-1]] sage: c.phi(1) diff --git a/src/sage/categories/rings.py b/src/sage/categories/rings.py index 50dba914250..ceb1ec8d25a 100644 --- a/src/sage/categories/rings.py +++ b/src/sage/categories/rings.py @@ -67,16 +67,16 @@ def is_injective(self) -> bool: EXAMPLES:: sage: R. = QQ[] - sage: R.hom([x, y^2], R).is_injective() + sage: R.hom([x, y^2], R).is_injective() # optional - sage.libs.singular True - sage: R.hom([x, x^2], R).is_injective() + sage: R.hom([x, x^2], R).is_injective() # optional - sage.libs.singular False - sage: S. = R.quotient(x^3*y) - sage: R.hom([v, u], S).is_injective() + sage: S. = R.quotient(x^3*y) # optional - sage.libs.singular + sage: R.hom([v, u], S).is_injective() # optional - sage.libs.singular False - sage: S.hom([-u, v], S).is_injective() + sage: S.hom([-u, v], S).is_injective() # optional - sage.libs.singular True - sage: S.cover().is_injective() + sage: S.cover().is_injective() # optional - sage.libs.singular False If the domain is a field, the homomorphism is injective:: @@ -102,12 +102,12 @@ def is_injective(self) -> bool: characteristic can not be injective:: sage: R. = ZZ[] - sage: f = R.hom([GF(3)(1)]); f + sage: f = R.hom([GF(3)(1)]); f # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 3 Defn: x |--> 1 - sage: f.is_injective() + sage: f.is_injective() # optional - sage.rings.finite_rings False A morphism whose domain is an order in a number field is injective if @@ -120,18 +120,20 @@ def is_injective(self) -> bool: To: Rational function field in x over Rational Field Defn: Conversion via FractionFieldElement_1poly_field map: From: Integer Ring - To: Fraction Field of Univariate Polynomial Ring in x over Rational Field + To: Fraction Field of Univariate Polynomial Ring in x + over Rational Field then Isomorphism: - From: Fraction Field of Univariate Polynomial Ring in x over Rational Field + From: Fraction Field of Univariate Polynomial Ring in x + over Rational Field To: Rational function field in x over Rational Field sage: f.is_injective() True A coercion to the fraction field is injective:: - sage: R = ZpFM(3) - sage: R.fraction_field().coerce_map_from(R).is_injective() + sage: R = ZpFM(3) # optional - sage.rings.padics + sage: R.fraction_field().coerce_map_from(R).is_injective() # optional - sage.rings.padics True """ @@ -212,23 +214,24 @@ def extend_to_fraction_field(self): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x+1]); f + sage: f = S.hom([x + 1]); f Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 sage: g = f.extend_to_fraction_field(); g - Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field + Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x + over Rational Field Defn: x |--> x + 1 - sage: g(x) + sage: g(x) # optional - sage.libs.singular x + 1 - sage: g(1/x) + sage: g(1/x) # optional - sage.libs.singular 1/(x + 1) If this morphism is not injective, it does not extend to the fraction field and an error is raised:: - sage: f = GF(5).coerce_map_from(ZZ) - sage: f.extend_to_fraction_field() + sage: f = GF(5).coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: f.extend_to_fraction_field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -236,9 +239,10 @@ def extend_to_fraction_field(self): TESTS:: sage: A. = RR[] - sage: phi = A.hom([x+1]) + sage: phi = A.hom([x + 1]) sage: phi.extend_to_fraction_field() - Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Real Field with 53 bits of precision + Ring endomorphism of Fraction Field of + Univariate Polynomial Ring in x over Real Field with 53 bits of precision Defn: x |--> x + 1.00000000000000 """ from sage.rings.morphism import RingHomomorphism_from_fraction_field @@ -332,10 +336,10 @@ def is_zero(self) -> bool: sage: R. = ZZ[] sage: R.quo(1).is_zero() True - sage: R. = GF(101)[] - sage: R.quo(77).is_zero() + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: R.quo(77).is_zero() # optional - sage.rings.finite_rings True - sage: R.quo(x^2+1).is_zero() + sage: R.quo(x^2 + 1).is_zero() # optional - sage.rings.finite_rings False """ return self.one() == self.zero() @@ -350,18 +354,20 @@ def bracket(self, x, y): EXAMPLES:: - sage: F = AlgebrasWithBasis(QQ).example() - sage: F - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: a,b,c = F.algebra_generators() - sage: F.bracket(a,b) + sage: F = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: F # 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: a, b, c = F.algebra_generators() # optional - sage.combinat sage.modules + sage: F.bracket(a, b) # optional - sage.combinat sage.modules B[word: ab] - B[word: ba] This measures the default of commutation between `x` and `y`. `F` endowed with the bracket operation is a Lie algebra; in particular, it satisfies Jacobi's identity:: - sage: F.bracket( F.bracket(a,b), c) + F.bracket(F.bracket(b,c),a) + F.bracket(F.bracket(c,a),b) + sage: (F.bracket(F.bracket(a,b), c) + F.bracket(F.bracket(b,c), a) # optional - sage.combinat sage.modules + ....: + F.bracket(F.bracket(c,a), b)) 0 """ return x * y - y * x @@ -386,20 +392,20 @@ def _Hom_(self, Y, category): EXAMPLES:: - sage: H = QQ._Hom_(QQ, category = Rings()); H + sage: H = QQ._Hom_(QQ, category=Rings()); H Set of Homomorphisms from Rational Field to Rational Field sage: H.__class__ TESTS:: - sage: Hom(QQ, QQ, category = Rings()).__class__ + sage: Hom(QQ, QQ, category=Rings()).__class__ - sage: Hom(CyclotomicField(3), QQ, category = Rings()).__class__ + sage: Hom(CyclotomicField(3), QQ, category=Rings()).__class__ # optional - sage.rings.number_field - sage: TestSuite(Hom(QQ, QQ, category = Rings())).run() # indirect doctest + sage: TestSuite(Hom(QQ, QQ, category=Rings())).run() # indirect doctest """ if category is not None and not category.is_subcategory(Rings()): raise TypeError(f"{category} is not a subcategory of Rings()") @@ -439,12 +445,12 @@ def _mul_(self, x, switch_sides=False): from the base class of rings. This is the case, e.g., for matrix algebras:: - sage: MS = MatrixSpace(QQ,2,2) - sage: isinstance(MS,Ring) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: isinstance(MS, Ring) # optional - sage.modules False - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True - sage: MS*2 # indirect doctest + sage: MS * 2 # indirect doctest # optional - sage.modules Left Ideal ( [2 0] @@ -455,7 +461,7 @@ def _mul_(self, x, switch_sides=False): In the next example, the ring and the other factor switch sides in the product:: - sage: [MS.2]*MS + sage: [MS.2] * MS # optional - sage.modules Right Ideal ( [0 0] @@ -501,12 +507,12 @@ def __pow__(self, n): EXAMPLES:: - sage: QQ^5 + sage: QQ^5 # optional - sage.modules Vector space of dimension 5 over Rational Field - sage: Integers(20)^1000 + sage: Integers(20)^1000 # optional - sage.modules Ambient free module of rank 1000 over Ring of integers modulo 20 - sage: QQ^(2,3) + sage: QQ^(2, 3) # optional - sage.modules Full MatrixSpace of 2 by 3 dense matrices over Rational Field """ if isinstance(n, tuple): @@ -531,18 +537,18 @@ def ideal_monoid(self): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) - sage: isinstance(MS,Ring) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: isinstance(MS, Ring) # optional - sage.modules False - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True - sage: MS.ideal_monoid() + sage: MS.ideal_monoid() # optional - sage.modules Monoid of ideals of Full MatrixSpace of 2 by 2 dense matrices over Rational Field Note that the monoid is cached:: - sage: MS.ideal_monoid() is MS.ideal_monoid() + sage: MS.ideal_monoid() is MS.ideal_monoid() # optional - sage.modules True """ try: @@ -560,11 +566,11 @@ def characteristic(self): sage: QQ.characteristic() 0 - sage: GF(19).characteristic() + sage: GF(19).characteristic() # optional - sage.rings.finite_rings 19 sage: Integers(8).characteristic() 8 - sage: Zp(5).characteristic() + sage: Zp(5).characteristic() # optional - sage.rings.padics 0 """ from sage.rings.infinity import infinity @@ -619,19 +625,19 @@ def ideal(self, *args, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) - sage: isinstance(MS,Ring) + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: isinstance(MS, Ring) # optional - sage.modules False - sage: MS in Rings() + sage: MS in Rings() # optional - sage.modules True - sage: MS.ideal(2) + sage: MS.ideal(2) # optional - sage.modules Twosided Ideal ( [2 0] [0 2] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: MS.ideal([MS.0,MS.1],side='right') + sage: MS.ideal([MS.0, MS.1], side='right') # optional - sage.modules Right Ideal ( [1 0] @@ -733,8 +739,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2,2) - sage: MS._ideal_class_() + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: MS._ideal_class_() # optional - sage.modules We do not know of a commutative ring in Sage that does not inherit @@ -782,28 +788,34 @@ def quotient(self, I, names=None, **kwds): So, we need a bit of effort to make the following example work with the category framework:: - sage: F. = FreeAlgebra(QQ) - sage: from sage.rings.noncommutative_ideals import Ideal_nc + sage: F. = FreeAlgebra(QQ) # optional - sage.combinat sage.modules + sage: from sage.rings.noncommutative_ideals import Ideal_nc # optional - sage.combinat sage.modules sage: from itertools import product - sage: class PowerIdeal(Ideal_nc): + sage: class PowerIdeal(Ideal_nc): # optional - sage.combinat sage.modules ....: def __init__(self, R, n): ....: self._power = n - ....: Ideal_nc.__init__(self, R, [R.prod(m) for m in product(R.gens(), repeat=n)]) + ....: Ideal_nc.__init__(self, R, [R.prod(m) + ....: for m in product(R.gens(), repeat=n)]) ....: def reduce(self, x): ....: R = self.ring() - ....: return add([c*R(m) for m,c in x if len(m) < self._power], R(0)) - sage: I = PowerIdeal(F,3) - sage: Q = Rings().parent_class.quotient(F, I); Q - Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) - sage: Q.0 + ....: return add([c*R(m) for m, c in x + ....: if len(m) < self._power], R(0)) + sage: I = PowerIdeal(F, 3) # optional - sage.combinat sage.modules + sage: Q = Rings().parent_class.quotient(F, I); Q # optional - sage.combinat sage.modules + Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, + x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, + y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, + z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) + sage: Q.0 # optional - sage.combinat sage.modules xbar - sage: Q.1 + sage: Q.1 # optional - sage.combinat sage.modules ybar - sage: Q.2 + sage: Q.2 # optional - sage.combinat sage.modules zbar - sage: Q.0*Q.1 + sage: Q.0*Q.1 # optional - sage.combinat sage.modules xbar*ybar - sage: Q.0*Q.1*Q.0 + sage: Q.0*Q.1*Q.0 # optional - sage.combinat sage.modules 0 An example with polynomial rings:: @@ -814,13 +826,14 @@ def quotient(self, I, names=None, **kwds): sage: S.gens() (a,) - sage: R. = PolynomialRing(QQ,2) - sage: S. = R.quotient((x^2, y)) - sage: S - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) - sage: S.gens() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = R.quotient((x^2, y)) # optional - sage.libs.singular + sage: S # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y) + sage: S.gens() # optional - sage.libs.singular (a, 0) - sage: a == b + sage: a == b # optional - sage.libs.singular False """ from sage.rings.quotient_ring import QuotientRing @@ -836,8 +849,8 @@ def quo(self, I, names=None, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2) - sage: I = MS*MS.gens()*MS + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: I = MS * MS.gens() * MS # optional - sage.modules ``MS`` is not an instance of :class:`~sage.rings.ring.Ring`. @@ -845,12 +858,13 @@ def quo(self, I, names=None, **kwds): category of rings. The quotient method is inherited from there:: - sage: isinstance(MS,sage.rings.ring.Ring) + sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules False - sage: isinstance(MS,Rings().parent_class) + sage: isinstance(MS, Rings().parent_class) # optional - sage.modules True - sage: MS.quo(I,names = ['a','b','c','d']) - Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal + sage: MS.quo(I, names=['a','b','c','d']) # optional - sage.modules + Quotient of Full MatrixSpace of 2 by 2 dense matrices + over Rational Field by the ideal ( [1 0] [0 0], @@ -867,13 +881,14 @@ def quo(self, I, names=None, **kwds): A test with a subclass of :class:`~sage.rings.ring.Ring`:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = R.quo((x^2, y)) - sage: S - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) - sage: S.gens() + sage: R. = PolynomialRing(QQ, 2) # optional - sage.libs.singular + sage: S. = R.quo((x^2, y)) # optional - sage.libs.singular + sage: S # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y) + sage: S.gens() # optional - sage.libs.singular (a, 0) - sage: a == b + sage: a == b # optional - sage.libs.singular False """ return self.quotient(I, names=names, **kwds) @@ -903,19 +918,20 @@ def quotient_ring(self, I, names=None, **kwds): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2) - sage: I = MS*MS.gens()*MS + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: I = MS * MS.gens() * MS # optional - sage.modules ``MS`` is not an instance of :class:`~sage.rings.ring.Ring`, but it is an instance of the parent class of the category of rings. The quotient method is inherited from there:: - sage: isinstance(MS,sage.rings.ring.Ring) + sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules False - sage: isinstance(MS,Rings().parent_class) + sage: isinstance(MS, Rings().parent_class) # optional - sage.modules True - sage: MS.quotient_ring(I,names = ['a','b','c','d']) - Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal + sage: MS.quotient_ring(I, names=['a','b','c','d']) # optional - sage.modules + Quotient of Full MatrixSpace of 2 by 2 dense matrices + over Rational Field by the ideal ( [1 0] [0 0], @@ -938,13 +954,14 @@ def quotient_ring(self, I, names=None, **kwds): sage: S.gens() (a,) - sage: R. = PolynomialRing(QQ,2) - sage: S. = R.quotient_ring((x^2, y)) - sage: S - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) - sage: S.gens() + sage: R. = PolynomialRing(QQ,2) # optional - sage.libs.singular + sage: S. = R.quotient_ring((x^2, y)) # optional - sage.libs.singular + sage: S # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y) + sage: S.gens() # optional - sage.libs.singular (a, 0) - sage: a == b + sage: a == b # optional - sage.libs.singular False """ return self.quotient(I, names=names, **kwds) @@ -957,9 +974,9 @@ def __truediv__(self, I): EXAMPLES:: - sage: MS = MatrixSpace(QQ,2) - sage: I = MS*MS.gens()*MS - sage: MS/I + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: I = MS * MS.gens() * MS # optional - sage.modules + sage: MS/I # optional - sage.modules Traceback (most recent call last): ... TypeError: use self.quotient(I) to construct the quotient ring @@ -996,24 +1013,28 @@ def __getitem__(self, arg): Univariate Polynomial Ring in x over Integer Ring sage: QQ['x'] Univariate Polynomial Ring in x over Rational Field - sage: GF(17)['abc'] + sage: GF(17)['abc'] # optional - sage.rings.finite_rings Univariate Polynomial Ring in abc over Finite Field of size 17 - sage: GF(17)['a,b,c'] + sage: GF(17)['a,b,c'] # optional - sage.rings.finite_rings Multivariate Polynomial Ring in a, b, c over Finite Field of size 17 - sage: GF(17)['a']['b'] - Univariate Polynomial Ring in b over Univariate Polynomial Ring in a over Finite Field of size 17 + sage: GF(17)['a']['b'] # optional - sage.rings.finite_rings + Univariate Polynomial Ring in b over + Univariate Polynomial Ring in a over Finite Field of size 17 We can create Ore polynomial rings:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: k['x', Frob] - Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: k['x', Frob] # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over Finite Field in t of size 5^3 + twisted by t |--> t^5 sage: R. = QQ[] - sage: der = R.derivation() - sage: R['d', der] - Ore Polynomial Ring in d over Univariate Polynomial Ring in t over Rational Field twisted by d/dt + sage: der = R.derivation() # optional - sage.modules + sage: R['d', der] # optional - sage.modules + Ore Polynomial Ring in d + over Univariate Polynomial Ring in t over Rational Field + twisted by d/dt We can also create power series rings by using double brackets:: @@ -1050,32 +1071,38 @@ def __getitem__(self, arg): :: - sage: QQ[sqrt(2)] # optional - sage.symbolic - Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? - sage: QQ[sqrt(2)].coerce_embedding() # optional - sage.symbolic + sage: QQ[sqrt(2)] # optional - sage.symbolic sage.rings.number_field + Number Field in sqrt2 with defining polynomial x^2 - 2 + with sqrt2 = 1.414213562373095? + sage: QQ[sqrt(2)].coerce_embedding() # optional - sage.symbolic sage.rings.number_field Generic morphism: - From: Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095? + From: Number Field in sqrt2 with defining polynomial x^2 - 2 + with sqrt2 = 1.414213562373095? To: Real Lazy Field Defn: sqrt2 -> 1.414213562373095? :: - sage: QQ[sqrt(2), sqrt(3)] # optional - sage.symbolic - Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field + sage: QQ[sqrt(2), sqrt(3)] # optional - sage.symbolic sage.rings.number_field + Number Field in sqrt2 + with defining polynomial x^2 - 2 over its base field and orders in number fields:: - sage: ZZ[I] - Order in Number Field in I0 with defining polynomial x^2 + 1 with I0 = 1*I - sage: ZZ[sqrt(5)] # optional - sage.symbolic - Order in Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? - sage: ZZ[sqrt(2) + sqrt(3)] # optional - sage.symbolic - Order in Number Field in a with defining polynomial x^4 - 10*x^2 + 1 with a = 3.146264369941973? + sage: ZZ[I] # optional - sage.symbolic sage.rings.number_field + Order in Number Field in I0 + with defining polynomial x^2 + 1 with I0 = 1*I + sage: ZZ[sqrt(5)] # optional - sage.symbolic sage.rings.number_field + Order in Number Field in sqrt5 + with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? + sage: ZZ[sqrt(2) + sqrt(3)] # optional - sage.symbolic sage.rings.number_field + Order in Number Field in a + with defining polynomial x^4 - 10*x^2 + 1 with a = 3.146264369941973? Embeddings are found for simple extensions (when that makes sense):: - sage: QQi. = QuadraticField(-1, 'i') - sage: QQ[i].coerce_embedding() + sage: QQi. = QuadraticField(-1, 'i') # optional - sage.symbolic sage.rings.number_field + sage: QQ[i].coerce_embedding() # optional - sage.symbolic sage.rings.number_field Generic morphism: From: Number Field in i with defining polynomial x^2 + 1 with i = 1*I To: Complex Lazy Field @@ -1111,25 +1138,28 @@ def __getitem__(self, arg): Extension towers are built as follows and use distinct generator names:: - sage: K = QQ[2^(1/3), 2^(1/2), 3^(1/3)] - sage: K - Number Field in a with defining polynomial x^3 - 2 over its base field - sage: K.base_field() - Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field - sage: K.base_field().base_field() + sage: K = QQ[2^(1/3), 2^(1/2), 3^(1/3)] # optional - sage.symbolic sage.rings.number_field + sage: K # optional - sage.symbolic sage.rings.number_field + Number Field in a with defining polynomial x^3 - 2 + over its base field + sage: K.base_field() # optional - sage.symbolic sage.rings.number_field + Number Field in sqrt2 with defining polynomial x^2 - 2 + over its base field + sage: K.base_field().base_field() # optional - sage.symbolic sage.rings.number_field Number Field in b with defining polynomial x^3 - 3 Embeddings:: - sage: a = 10^100; expr = (2*a + sqrt(2))/(2*a^2-1) # optional - sage.symbolic - sage: QQ[expr].coerce_embedding() is None # optional - sage.symbolic + sage: a = 10^100; expr = (2*a + sqrt(2))/(2*a^2-1) # optional - sage.symbolic sage.rings.number_field + sage: QQ[expr].coerce_embedding() is None # optional - sage.symbolic sage.rings.number_field False - sage: QQ[sqrt(5)].gen() > 0 # optional - sage.symbolic + sage: QQ[sqrt(5)].gen() > 0 # optional - sage.symbolic sage.rings.number_field True - sage: expr = sqrt(2) + I*(cos(pi/4, hold=True) - sqrt(2)/2) # optional - sage.symbolic - sage: QQ[expr].coerce_embedding() # optional - sage.symbolic + sage: expr = sqrt(2) + I*(cos(pi/4, hold=True) - sqrt(2)/2) # optional - sage.symbolic sage.rings.number_field + sage: QQ[expr].coerce_embedding() # optional - sage.symbolic sage.rings.number_field Generic morphism: - From: Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095? + From: Number Field in a with defining polynomial x^2 - 2 + with a = 1.414213562373095? To: Real Lazy Field Defn: a -> 1.414213562373095? """ @@ -1251,17 +1281,17 @@ def free_module(self, base=None, basis=None, map=True): EXAMPLES:: sage: R. = QQ[[]] - sage: V, from_V, to_V = R.free_module(R) - sage: v = to_V(1+x); v + sage: V, from_V, to_V = R.free_module(R) # optional - sage.modules + sage: v = to_V(1 + x); v # optional - sage.modules (1 + x) - sage: from_V(v) + sage: from_V(v) # optional - sage.modules 1 + x - sage: W, from_W, to_W = R.free_module(R, basis=(1-x)) - sage: W is V + sage: W, from_W, to_W = R.free_module(R, basis=(1 - x)) # optional - sage.modules + sage: W is V # optional - sage.modules True - sage: w = to_W(1+x); w + sage: w = to_W(1 + x); w # optional - sage.modules (1 - x^2) - sage: from_W(w) + sage: from_W(w) # optional - sage.modules 1 + x + O(x^20) """ if base is None: @@ -1303,12 +1333,12 @@ def is_unit(self) -> bool: EXAMPLES:: - sage: MS = MatrixSpace(ZZ, 2) - sage: MS.one().is_unit() + sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: MS.one().is_unit() # optional - sage.modules True - sage: MS.zero().is_unit() + sage: MS.zero().is_unit() # optional - sage.modules False - sage: MS([1,2,3,4]).is_unit() + sage: MS([1,2,3,4]).is_unit() # optional - sage.modules False """ if self.is_one() or (-self).is_one(): @@ -1328,8 +1358,8 @@ def inverse_of_unit(self): EXAMPLES:: sage: R. = ZZ[] - sage: S = R.quo(x^2 + x + 1) - sage: S(1).inverse_of_unit() + sage: S = R.quo(x^2 + x + 1) # optional - sage.libs.pari + sage: S(1).inverse_of_unit() # optional - sage.libs.pari 1 This method fails when the element is not a unit:: @@ -1401,9 +1431,9 @@ def _gen_names(elts): EXAMPLES:: sage: from sage.categories.rings import _gen_names - sage: list(_gen_names([sqrt(5)])) # optional - sage.symbolic + sage: list(_gen_names([sqrt(5)])) # optional - sage.symbolic ['sqrt5'] - sage: list(_gen_names([sqrt(-17), 2^(1/3)])) # optional - sage.symbolic + sage: list(_gen_names([sqrt(-17), 2^(1/3)])) # optional - sage.symbolic ['a', 'b'] sage: list(_gen_names((1..27)))[-1] 'aa' diff --git a/src/sage/categories/semigroups.py b/src/sage/categories/semigroups.py index 10e2617e1ab..526af9349a6 100644 --- a/src/sage/categories/semigroups.py +++ b/src/sage/categories/semigroups.py @@ -196,30 +196,37 @@ def cayley_graph(self, side="right", simple=False, elements=None, We start with the (right) Cayley graphs of some classical groups:: - sage: D4 = DihedralGroup(4); D4 + sage: D4 = DihedralGroup(4); D4 # optional - sage.groups Dihedral group of order 8 as a permutation group - sage: G = D4.cayley_graph() - sage: show(G, color_by_label=True, edge_labels=True) - sage: A5 = AlternatingGroup(5); A5 + sage: G = D4.cayley_graph() # optional - sage.groups sage.graphs + sage: show(G, color_by_label=True, edge_labels=True) # optional - sage.groups sage.graphs sage.plot + sage: A5 = AlternatingGroup(5); A5 # optional - sage.groups Alternating group of order 5!/2 as a permutation group - sage: G = A5.cayley_graph() - sage: G.show3d(color_by_label=True, edge_size=0.01, edge_size2=0.02, vertex_size=0.03) - sage: G.show3d(vertex_size=0.03, edge_size=0.01, edge_size2=0.02, vertex_colors={(1,1,1):G.vertices(sort=True)}, bgcolor=(0,0,0), color_by_label=True, xres=700, yres=700, iterations=200) # long time (less than a minute) - sage: G.num_edges() + sage: G = A5.cayley_graph() # optional - sage.groups sage.graphs + sage: G.show3d(color_by_label=True, edge_size=0.01, # optional - sage.groups sage.graphs sage.plot + ....: edge_size2=0.02, vertex_size=0.03) + sage: G.show3d(vertex_size=0.03, # long time (less than a minute) # optional - sage.groups sage.graphs sage.plot + ....: edge_size=0.01, edge_size2=0.02, + ....: vertex_colors={(1,1,1): G.vertices(sort=True)}, + ....: bgcolor=(0,0,0), color_by_label=True, + ....: xres=700, yres=700, iterations=200) + sage: G.num_edges() # optional - sage.groups sage.graphs 120 - sage: w = WeylGroup(['A',3]) - sage: d = w.cayley_graph(); d + sage: w = WeylGroup(['A', 3]) # optional - sage.combinat sage.groups + sage: d = w.cayley_graph(); d # optional - sage.combinat sage.groups sage.graphs Digraph on 24 vertices - sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) + sage: d.show3d(color_by_label=True, edge_size=0.01, vertex_size=0.03) # optional - sage.combinat sage.groups sage.graphs sage.plot Alternative generators may be specified:: - sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) - sage: G.num_edges() + sage: G = A5.cayley_graph(generators=[A5.gens()[0]]) # optional - sage.groups sage.graphs + sage: G.num_edges() # optional - sage.groups sage.graphs 60 - sage: g = PermutationGroup([(i+1,j+1) for i in range(5) for j in range(5) if j!=i]) - sage: g.cayley_graph(generators=[(1,2),(2,3)]) + sage: g = PermutationGroup([(i + 1, j + 1) # optional - sage.groups sage.graphs + ....: for i in range(5) + ....: for j in range(5) if j != i]) + sage: g.cayley_graph(generators=[(1,2), (2,3)]) # optional - sage.groups sage.graphs Digraph on 120 vertices If ``elements`` is specified, then only the subgraph @@ -228,57 +235,60 @@ def cayley_graph(self, side="right", simple=False, elements=None, the elements of length at most 3:: sage: M = Monoids().example(); M - An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - sage: elements = [ M.prod(w) for w in sum((list(Words(M.semigroup_generators(),k)) for k in range(4)),[]) ] - sage: G = M.cayley_graph(elements = elements) - sage: G.num_verts(), G.num_edges() + An example of a monoid: + the free monoid generated by ('a', 'b', 'c', 'd') + sage: elements = [M.prod(w) # optional - sage.combinat + ....: for w in sum((list(Words(M.semigroup_generators(), k)) + ....: for k in range(4)), [])] + sage: G = M.cayley_graph(elements=elements) # optional - sage.combinat sage.graphs + sage: G.num_verts(), G.num_edges() # optional - sage.combinat sage.graphs (85, 84) - sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) + sage: G.show3d(color_by_label=True, edge_size=0.001, vertex_size=0.01) # optional - sage.combinat sage.graphs sage.plot We now illustrate the ``side`` and ``simple`` options on a semigroup:: - sage: S = FiniteSemigroups().example(alphabet=('a','b')) - sage: g = S.cayley_graph(simple=True) - sage: g.vertices(sort=True) + sage: S = FiniteSemigroups().example(alphabet=('a', 'b')) + sage: g = S.cayley_graph(simple=True) # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [('a', 'ab', None), ('b', 'ba', None)] :: - sage: g = S.cayley_graph(side="left", simple=True) - sage: g.vertices(sort=True) + sage: g = S.cayley_graph(side="left", simple=True) # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None), ('ba', 'ab', None)] :: - sage: g = S.cayley_graph(side="twosided", simple=True) - sage: g.vertices(sort=True) + sage: g = S.cayley_graph(side="twosided", simple=True) # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [('a', 'ab', None), ('a', 'ba', None), ('ab', 'ba', None), ('b', 'ab', None), ('b', 'ba', None), ('ba', 'ab', None)] :: - sage: g = S.cayley_graph(side="twosided") - sage: g.vertices(sort=True) + sage: g = S.cayley_graph(side="twosided") # optional - sage.graphs + sage: g.vertices(sort=True) # optional - sage.graphs ['a', 'ab', 'b', 'ba'] - sage: g.edges(sort=True) + sage: g.edges(sort=True) # optional - sage.graphs [('a', 'a', (0, 'left')), ('a', 'a', (0, 'right')), ('a', 'ab', (1, 'right')), ('a', 'ba', (1, 'left')), ('ab', 'ab', (0, 'left')), ('ab', 'ab', (0, 'right')), ('ab', 'ab', (1, 'right')), ('ab', 'ba', (1, 'left')), ('b', 'ab', (0, 'left')), ('b', 'b', (1, 'left')), ('b', 'b', (1, 'right')), ('b', 'ba', (0, 'right')), ('ba', 'ab', (0, 'left')), ('ba', 'ba', (0, 'right')), ('ba', 'ba', (1, 'left')), ('ba', 'ba', (1, 'right'))] :: - sage: s1 = SymmetricGroup(1); s = s1.cayley_graph(); s.vertices(sort=False) + sage: s1 = SymmetricGroup(1); s = s1.cayley_graph(); s.vertices(sort=False) # optional - sage.groups sage.graphs [()] TESTS:: - sage: SymmetricGroup(2).cayley_graph(side="both") + sage: SymmetricGroup(2).cayley_graph(side="both") # optional - sage.groups sage.graphs Traceback (most recent call last): ... ValueError: option 'side' must be 'left', 'right' or 'twosided' @@ -375,51 +385,52 @@ def subsemigroup(self, generators, one=None, category=None): EXAMPLES:: sage: R = IntegerModRing(15) - sage: M = R.subsemigroup([R(3),R(5)]); M + sage: M = R.subsemigroup([R(3), R(5)]); M # optional - sage.groups A subsemigroup of (Ring of integers modulo 15) with 2 generators - sage: M.list() + sage: M.list() # optional - sage.groups [3, 5, 9, 0, 10, 12, 6] By default, `M` is just in the category of subsemigroups:: - sage: M in Semigroups().Subobjects() + sage: M in Semigroups().Subobjects() # optional - sage.groups True In the following example, we specify that `M` is a submonoid of the finite monoid `R` (it shares the same unit), and a group by itself:: - sage: M = R.subsemigroup([R(-1)], + sage: M = R.subsemigroup([R(-1)], # optional - sage.groups ....: category=Monoids().Finite().Subobjects() & Groups()); M A submonoid of (Ring of integers modulo 15) with 1 generators - sage: M.list() + sage: M.list() # optional - sage.groups [1, 14] - sage: M.one() + sage: M.one() # optional - sage.groups 1 - In the following example `M` is a group; however its unit + In the following example, `M` is a group; however, its unit does not coincide with that of `R`, so `M` is only a subsemigroup, and we need to specify its unit explicitly:: - sage: M = R.subsemigroup([R(5)], + sage: M = R.subsemigroup([R(5)], # optional - sage.groups ....: category=Semigroups().Finite().Subobjects() & Groups()); M Traceback (most recent call last): ... - ValueError: For a monoid which is just a subsemigroup, the unit should be specified + ValueError: For a monoid which is just a subsemigroup, + the unit should be specified - sage: M = R.subsemigroup([R(5)], one=R(10), + sage: M = R.subsemigroup([R(5)], one=R(10), # optional - sage.groups ....: category=Semigroups().Finite().Subobjects() & Groups()); M A subsemigroup of (Ring of integers modulo 15) with 1 generators - sage: M in Groups() + sage: M in Groups() # optional - sage.groups True - sage: M.list() + sage: M.list() # optional - sage.groups [10, 5] - sage: M.one() + sage: M.one() # optional - sage.groups 10 TESTS:: - sage: TestSuite(M).run() + sage: TestSuite(M).run() # optional - sage.groups Failure in _test_inverse: Traceback (most recent call last): ... @@ -449,8 +460,8 @@ def trivial_representation(self, base_ring=None, side="twosided"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: G.trivial_representation() + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: G.trivial_representation() # optional - sage.groups Trivial representation of Dihedral group of order 8 as a permutation group over Integer Ring """ @@ -469,8 +480,8 @@ def regular_representation(self, base_ring=None, side="left"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: G.regular_representation() + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: G.regular_representation() # optional - sage.groups Left Regular Representation of Dihedral group of order 8 as a permutation group over Integer Ring """ @@ -880,7 +891,7 @@ def algebra_generators(self): the left regular band generated by ('a', 'b', 'c', 'd') sage: M.semigroup_generators() Family ('a', 'b', 'c', 'd') - sage: M.algebra(ZZ).algebra_generators() + sage: M.algebra(ZZ).algebra_generators() # optional - sage.modules Family (B['a'], B['b'], B['c'], B['d']) """ return self.basis().keys().semigroup_generators().map(self.monomial) @@ -895,12 +906,12 @@ def gens(self): EXAMPLES:: - sage: a, b = SL2Z.algebra(ZZ).gens(); a, b + sage: a, b = SL2Z.algebra(ZZ).gens(); a, b # optional - sage.groups sage.modules ([ 0 -1] [ 1 0], [1 1] [0 1]) - sage: 2*a + b + sage: 2*a + b # optional - sage.groups sage.modules 2*[ 0 -1] [ 1 0] + @@ -915,9 +926,9 @@ def ngens(self): EXAMPLES:: - sage: SL2Z.algebra(ZZ).ngens() + sage: SL2Z.algebra(ZZ).ngens() # optional - sage.groups sage.modules 2 - sage: DihedralGroup(4).algebra(RR).ngens() + sage: DihedralGroup(4).algebra(RR).ngens() # optional - sage.groups sage.modules 2 """ return self.basis().keys().ngens() @@ -928,8 +939,8 @@ def gen(self, i=0): EXAMPLES:: - sage: A = GL(3, GF(7)).algebra(ZZ) - sage: A.gen(0) + sage: A = GL(3, GF(7)).algebra(ZZ) # optional - sage.groups sage.libs.pari sage.modules + sage: A.gen(0) # optional - sage.groups sage.libs.pari sage.modules [3 0 0] [0 1 0] [0 0 1] @@ -948,10 +959,11 @@ def product_on_basis(self, g1, g2): EXAMPLES:: sage: S = FiniteSemigroups().example(); S - An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ) - sage: a,b,c,d = A.algebra_generators() - sage: a * b + b * d * c * d + An example of a finite semigroup: + the left regular band generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ) # optional - sage.modules + sage: a, b, c, d = A.algebra_generators() # optional - sage.modules + sage: a * b + b * d * c * d # optional - sage.modules B['ab'] + B['bdc'] """ return self.monomial(g1 * g2) @@ -966,10 +978,10 @@ def trivial_representation(self, side="twosided"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: A = G.algebra(QQ) - sage: V = A.trivial_representation() - sage: V == G.trivial_representation(QQ) + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: A = G.algebra(QQ) # optional - sage.groups sage.modules + sage: V = A.trivial_representation() # optional - sage.groups sage.modules + sage: V == G.trivial_representation(QQ) # optional - sage.groups sage.modules True """ S = self.basis().keys() @@ -986,10 +998,10 @@ def regular_representation(self, side="left"): EXAMPLES:: - sage: G = groups.permutation.Dihedral(4) - sage: A = G.algebra(QQ) - sage: V = A.regular_representation() - sage: V == G.regular_representation(QQ) + sage: G = groups.permutation.Dihedral(4) # optional - sage.groups + sage: A = G.algebra(QQ) # optional - sage.groups sage.modules + sage: V = A.regular_representation() # optional - sage.groups sage.modules + sage: V == G.regular_representation(QQ) # optional - sage.groups sage.modules True """ S = self.basis().keys() diff --git a/src/sage/categories/semisimple_algebras.py b/src/sage/categories/semisimple_algebras.py index be7a581c798..9be6bb8d571 100644 --- a/src/sage/categories/semisimple_algebras.py +++ b/src/sage/categories/semisimple_algebras.py @@ -37,15 +37,15 @@ class SemisimpleAlgebras(Category_over_base_ring): Typically, finite group algebras are semisimple:: - sage: DihedralGroup(5).algebra(QQ) in SemisimpleAlgebras + sage: DihedralGroup(5).algebra(QQ) in SemisimpleAlgebras # optional - sage.groups True Unless the characteristic of the field divides the order of the group:: - sage: DihedralGroup(5).algebra(IntegerModRing(5)) in SemisimpleAlgebras + sage: DihedralGroup(5).algebra(IntegerModRing(5)) in SemisimpleAlgebras # optional - sage.groups False - sage: DihedralGroup(5).algebra(IntegerModRing(7)) in SemisimpleAlgebras + sage: DihedralGroup(5).algebra(IntegerModRing(7)) in SemisimpleAlgebras # optional - sage.groups True .. SEEALSO:: :wikipedia:`Semisimple_algebra` @@ -96,13 +96,13 @@ def radical_basis(self, **keywords): EXAMPLES:: - sage: A = SymmetricGroup(4).algebra(QQ) - sage: A.radical_basis() + sage: A = SymmetricGroup(4).algebra(QQ) # optional - sage.groups + sage: A.radical_basis() # optional - sage.groups () TESTS:: - sage: A.radical_basis.__module__ + sage: A.radical_basis.__module__ # optional - sage.groups 'sage.categories.finite_dimensional_semisimple_algebras_with_basis' """ return () diff --git a/src/sage/categories/sets_cat.py b/src/sage/categories/sets_cat.py index bc3c55e9029..069ebc5337c 100644 --- a/src/sage/categories/sets_cat.py +++ b/src/sage/categories/sets_cat.py @@ -147,7 +147,7 @@ class Sets(Category_singleton): We run some generic checks on P:: - sage: TestSuite(P).run(verbose=True) + sage: TestSuite(P).run(verbose=True) # optional - sage.libs.pari running ._test_an_element() . . . pass running ._test_cardinality() . . . pass running ._test_category() . . . pass @@ -867,11 +867,11 @@ def Facade(self): 1. as plain integers:: - sage: P = Poset((divisors(12), attrcall("divides")), facade=True) + sage: P = Poset((divisors(12), attrcall("divides")), facade=True) # optional - sage.graphs sage.combinat 2. as integers, modified to be aware that their parent is `P`:: - sage: Q = Poset((divisors(12), attrcall("divides")), facade=False) + sage: Q = Poset((divisors(12), attrcall("divides")), facade=False) # optional - sage.graphs sage.combinat The advantage of option 1. is that one needs not do conversions back and forth between `P` and `\ZZ`. The @@ -885,23 +885,23 @@ def Facade(self): To raise this ambiguity, one needs to explicitly specify the underlying poset as in `2 <_P 3`:: - sage: P = Posets().example("facade") - sage: P.lt(2,3) + sage: P = Posets().example("facade") # optional - sage.graphs sage.combinat + sage: P.lt(2,3) # optional - sage.graphs sage.combinat False On the other hand, with option 2. and once constructed, the elements know unambiguously how to compare themselves:: - sage: Q(2) < Q(3) + sage: Q(2) < Q(3) # optional - sage.graphs sage.combinat False - sage: Q(2) < Q(6) + sage: Q(2) < Q(6) # optional - sage.graphs sage.combinat True Beware that ``P(2)`` is still the integer `2`. Therefore ``P(2) < P(3)`` still compares `2` and `3` as integers!:: - sage: P(2) < P(3) + sage: P(2) < P(3) # optional - sage.graphs sage.combinat True In short `P` being a facade parent is one of the programmatic @@ -970,17 +970,19 @@ def _element_constructor_(self): sage: S(17) # indirect doctest 17 - sage: A = FreeModule(QQ, 3) - sage: A.element_class + sage: A = FreeModule(QQ, 3) # optional - sage.modules + sage: A.element_class # optional - sage.modules - sage: A._element_constructor_ - + sage: A._element_constructor_ # optional - sage.modules + - sage: B = SymmetricGroup(3).algebra(ZZ) - sage: B.element_class + sage: B = SymmetricGroup(3).algebra(ZZ) # optional - sage.groups sage.modules + sage: B.element_class # optional - sage.groups sage.modules <...SymmetricGroupAlgebra_n_with_category.element_class'> - sage: B._element_constructor_ - + sage: B._element_constructor_ # optional - sage.groups sage.modules + """ if hasattr(self, "element_class"): return self._element_constructor_from_element_class @@ -1190,12 +1192,12 @@ def _test_elements_eq_reflexive(self, **options): We try a non-reflexive equality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_eq_reflexive() + sage: P._test_elements_eq_reflexive() # optional - sage.libs.pari sage: eq = P.element_class.__eq__ sage: P.element_class.__eq__ = (lambda x, y: ....: False if eq(x, P(47)) and eq(y, P(47)) else eq(x, y)) - sage: P._test_elements_eq_reflexive() + sage: P._test_elements_eq_reflexive() # optional - sage.libs.pari Traceback (most recent call last): ... AssertionError: 47 != 47 @@ -1226,7 +1228,7 @@ def _test_elements_eq_symmetric(self, **options): We test a non symmetric equality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_eq_symmetric() + sage: P._test_elements_eq_symmetric() # optional - sage.libs.pari sage: eq = P.element_class.__eq__ sage: def non_sym_eq(x, y): @@ -1234,7 +1236,7 @@ def _test_elements_eq_symmetric(self, **options): ....: elif eq(x, P(47)) and eq(y, P(53)): return True ....: else: return eq(x, y) sage: P.element_class.__eq__ = non_sym_eq - sage: P._test_elements_eq_symmetric() + sage: P._test_elements_eq_symmetric() # optional - sage.libs.pari Traceback (most recent call last): ... AssertionError: non symmetric equality: 47 == 53 but 53 != 47 @@ -1267,9 +1269,9 @@ def _test_elements_eq_transitive(self, **options): We test a non transitive equality:: - sage: R = Zp(3) - sage: test = raw_getattr(Sets().ParentMethods, "_test_elements_eq_transitive") - sage: test(R, elements=[R(3,2),R(3,1),R(0)]) + sage: R = Zp(3) # optional - sage.rings.padics + sage: test = raw_getattr(Sets().ParentMethods, "_test_elements_eq_transitive") # optional - sage.rings.padics + sage: test(R, elements=[R(3,2), R(3,1), R(0)]) # optional - sage.rings.padics Traceback (most recent call last): ... AssertionError: non transitive equality: @@ -1316,12 +1318,12 @@ def _test_elements_neq(self, **options): We try a broken inequality:: sage: P = Sets().example("wrapper") - sage: P._test_elements_neq() + sage: P._test_elements_neq() # optional - sage.libs.pari sage: ne = P.element_class.__ne__ sage: eq = P.element_class.__eq__ sage: P.element_class.__ne__ = lambda x, y: False - sage: P._test_elements_neq() + sage: P._test_elements_neq() # optional - sage.libs.pari Traceback (most recent call last): ... AssertionError: __eq__ and __ne__ inconsistency: @@ -1560,20 +1562,21 @@ def cartesian_product(*parents, **kwargs): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example(); A.rename("A") - sage: A.cartesian_product(A,A) + sage: A = C.example(); A.rename("A") # optional - sage.combinat sage.modules + sage: A.cartesian_product(A, A) # optional - sage.combinat sage.modules A (+) A (+) A - sage: ZZ.cartesian_product(GF(2), FiniteEnumeratedSet([1,2,3])) - The Cartesian product of (Integer Ring, Finite Field of size 2, {1, 2, 3}) + sage: ZZ.cartesian_product(GF(2), FiniteEnumeratedSet([1,2,3])) # optional - sage.rings.finite_rings + The Cartesian product of (Integer Ring, + Finite Field of size 2, {1, 2, 3}) - sage: C = ZZ.cartesian_product(A); C + sage: C = ZZ.cartesian_product(A); C # optional - sage.combinat sage.modules The Cartesian product of (Integer Ring, A) TESTS:: - sage: type(C) + sage: type(C) # optional - sage.combinat sage.modules - sage: C.category() + sage: C.category() # optional - sage.combinat sage.modules Join of Category of rings and ... and Category of Cartesian products of commutative additive groups @@ -1626,21 +1629,21 @@ def algebra(self, base_ring, category=None, **kwds): If `S` is a :class:`group `, the result is its group algebra `KS`:: - sage: S = DihedralGroup(4); S - Dihedral group of order 8 as a permutation group - sage: A = S.algebra(QQ); A + sage: S = DihedralGroup(4); S # optional - sage.groups + Dihedral group of order 8 as a permutation group + sage: A = S.algebra(QQ); A # optional - sage.groups sage.modules Algebra of Dihedral group of order 8 as a permutation group - over Rational Field - sage: A.category() + over Rational Field + sage: A.category() # optional - sage.groups sage.modules Category of finite group algebras over Rational Field - sage: a = A.an_element(); a + sage: a = A.an_element(); a # optional - sage.groups sage.modules () + (1,3) + 2*(1,3)(2,4) + 3*(1,4,3,2) This space is endowed with an algebra structure, obtained by extending by bilinearity the multiplication of `G` to a multiplication on `RG`:: - sage: a * a + sage: a * a # optional - sage.groups sage.modules 6*() + 4*(2,4) + 3*(1,2)(3,4) + 12*(1,2,3,4) + 2*(1,3) + 13*(1,3)(2,4) + 6*(1,4,3,2) + 3*(1,4)(2,3) @@ -1648,11 +1651,13 @@ def algebra(self, base_ring, category=None, **kwds): monoid algebra `KS`:: sage: S = Monoids().example(); S - An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - sage: A = S.algebra(QQ); A - Algebra of An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') - over Rational Field - sage: A.category() + An example of a monoid: + the free monoid generated by ('a', 'b', 'c', 'd') + sage: A = S.algebra(QQ); A # optional - sage.modules + Algebra of + An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd') + over Rational Field + sage: A.category() # optional - sage.modules Category of monoid algebras over Rational Field Similarly, we can construct algebras for additive magmas, @@ -1662,17 +1667,17 @@ def algebra(self, base_ring, category=None, **kwds): here we build the algebra of the additive group `GF_3`:: sage: from sage.categories.additive_groups import AdditiveGroups - sage: S = GF(7) - sage: A = S.algebra(QQ, category=AdditiveGroups()); A + sage: S = GF(7) # optional - sage.rings.finite_rings + sage: A = S.algebra(QQ, category=AdditiveGroups()); A # optional - sage.rings.finite_rings sage.modules Algebra of Finite Field of size 7 over Rational Field - sage: A.category() + sage: A.category() # optional - sage.rings.finite_rings sage.modules Category of finite dimensional additive group algebras over Rational Field - sage: a = A(S(1)) - sage: a + sage: a = A(S(1)) # optional - sage.rings.finite_rings sage.modules + sage: a # optional - sage.rings.finite_rings sage.modules 1 - sage: 1 + a * a * a + sage: 1 + a * a * a # optional - sage.rings.finite_rings sage.modules 0 + 3 Note that the ``category`` keyword needs to be fed with @@ -1717,29 +1722,29 @@ def _sympy_(self): sage: F = FiniteEnumeratedSets().example(); F An example of a finite enumerated set: {1,2,3} - sage: sF = F._sympy_(); sF + sage: sF = F._sympy_(); sF # optional - sympy SageSet(An example of a finite enumerated set: {1,2,3}) - sage: sF.is_finite_set + sage: sF.is_finite_set # optional - sympy True - sage: bool(sF) + sage: bool(sF) # optional - sympy True - sage: len(sF) + sage: len(sF) # optional - sympy 3 - sage: list(sF) + sage: list(sF) # optional - sympy [1, 2, 3] - sage: from sympy import FiniteSet - sage: FiniteSet.fromiter(sF) # random - this output format is sympy >= 1.9 + sage: from sympy import FiniteSet # optional - sympy + sage: FiniteSet.fromiter(sF) # random - this output is sympy >= 1.9 # optional - sympy FiniteSet(1, 2, 3) - sage: RR._sympy_().is_finite_set + sage: RR._sympy_().is_finite_set # optional - sympy False sage: F = Family([1, 2]) sage: F is Family([1, 2]) False - sage: sF = F._sympy_(); sF + sage: sF = F._sympy_(); sF # optional - sympy SageSet(Family (1, 2)) - sage: sF._sage_() is F + sage: sF._sage_() is F # optional - sympy True """ from sage.interfaces.sympy_wrapper import SageSet @@ -1764,9 +1769,9 @@ def cartesian_product(*elements): EXAMPLES:: sage: C = AlgebrasWithBasis(QQ) - sage: A = C.example() - sage: (a,b,c) = A.algebra_generators() - sage: a.cartesian_product(b, c) + sage: A = C.example() # optional - sage.combinat sage.modules + sage: a, b, c = A.algebra_generators() # optional - sage.combinat sage.modules + sage: a.cartesian_product(b, c) # optional - sage.combinat sage.modules B[(0, word: a)] + B[(1, word: b)] + B[(2, word: c)] FIXME: is this a policy that we want to enforce on all parents? @@ -1800,22 +1805,22 @@ def __invert__(self): We now try to inverse a couple of morphisms defined by a matrix:: - sage: H = End(QQ^2) - sage: phi = H(matrix([[1,1],[0,1]])); phi + sage: H = End(QQ^2) # optional - sage.modules + sage: phi = H(matrix([[1,1], [0,1]])); phi # optional - sage.modules Vector space morphism represented by the matrix: [1 1] [0 1] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of dimension 2 over Rational Field - sage: ~phi + sage: ~phi # optional - sage.modules Vector space morphism represented by the matrix: [ 1 -1] [ 0 1] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of dimension 2 over Rational Field - sage: phi = H(matrix([[1,1],[1,1]])) - sage: ~phi + sage: phi = H(matrix([[1,1], [1,1]])) # optional - sage.modules + sage: ~phi # optional - sage.modules Traceback (most recent call last): ... ZeroDivisionError: matrix morphism not invertible @@ -1832,11 +1837,11 @@ def is_injective(self): EXAMPLES:: - sage: f = ZZ.hom(GF(3)); f + sage: f = ZZ.hom(GF(3)); f # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 3 - sage: f.is_injective() + sage: f.is_injective() # optional - sage.rings.finite_rings False """ if self.domain().cardinality() <= 1: @@ -1851,11 +1856,11 @@ def image(self, domain_subset=None): EXAMPLES:: - sage: P = Partitions(6) - sage: H = Hom(P, ZZ) - sage: f = H(ZZ.sum) - sage: X = f.image() - sage: list(X) + sage: P = Partitions(6) # optional - sage.combinat + sage: H = Hom(P, ZZ) # optional - sage.combinat + sage: f = H(ZZ.sum) # optional - sage.combinat + sage: X = f.image() # optional - sage.combinat + sage: list(X) # optional - sage.combinat [6] """ D = self.domain() @@ -2006,7 +2011,8 @@ def lift(self, x): sage: S = Semigroups().Subquotients().example() sage: s = S.an_element() sage: s, s.parent() - (42, An example of a (sub)quotient semigroup: a quotient of the left zero semigroup) + (42, An example of a (sub)quotient semigroup: + a quotient of the left zero semigroup) sage: S.lift(s), S.lift(s).parent() (42, An example of a semigroup: the left zero semigroup) sage: s.lift(), s.lift().parent() @@ -2041,7 +2047,8 @@ def retract(self, x): sage: s, s.parent() (42, An example of a semigroup: the left zero semigroup) sage: S.retract(s), S.retract(s).parent() - (42, An example of a (sub)quotient semigroup: a quotient of the left zero semigroup) + (42, An example of a (sub)quotient semigroup: + a quotient of the left zero semigroup) """ class ElementMethods: @@ -2055,7 +2062,8 @@ def lift(self): sage: S = Semigroups().Subquotients().example() sage: s = S.an_element() sage: s, s.parent() - (42, An example of a (sub)quotient semigroup: a quotient of the left zero semigroup) + (42, An example of a (sub)quotient semigroup: + a quotient of the left zero semigroup) sage: S.lift(s), S.lift(s).parent() (42, An example of a semigroup: the left zero semigroup) sage: s.lift(), s.lift().parent() @@ -2132,7 +2140,7 @@ def _repr_(self): EXAMPLES:: sage: from sage.categories.examples.semigroups import IncompleteSubquotientSemigroup - sage: S = IncompleteSubquotientSemigroup(category = Semigroups().Subobjects()) + sage: S = IncompleteSubquotientSemigroup(category=Semigroups().Subobjects()) sage: S._repr_() 'A subobject of An example of a semigroup: the left zero semigroup' """ @@ -2231,7 +2239,7 @@ def __iter__(self): Sets are intrinsically unordered:: - sage: for x,y in cartesian_product([Set([1,2]), Set(['a','b'])]): # random + sage: for x,y in cartesian_product([Set([1,2]), Set(['a','b'])]): # random ....: print((x, y)) (1, 'b') (1, 'a') @@ -2251,18 +2259,18 @@ def __iter__(self): sage: C.__iter__.__module__ 'sage.categories.sets_cat' - sage: F22 = GF(2).cartesian_product(GF(2)) - sage: list(F22) + sage: F22 = GF(2).cartesian_product(GF(2)) # optional - sage.rings.finite_rings + sage: list(F22) # optional - sage.rings.finite_rings [(0, 0), (0, 1), (1, 0), (1, 1)] - sage: C = cartesian_product([Permutations(10)]*4) - sage: it = iter(C) - sage: next(it) + sage: C = cartesian_product([Permutations(10)]*4) # optional - sage.combinat + sage: it = iter(C) # optional - sage.combinat + sage: next(it) # optional - sage.combinat ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - sage: next(it) + sage: next(it) # optional - sage.combinat ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], @@ -2271,8 +2279,8 @@ def __iter__(self): When all factors (except possibly the first factor) are known to be finite, it uses the lexicographic order:: - sage: it = iter(cartesian_product([ZZ, GF(2)])) - sage: [next(it) for _ in range(10)] + sage: it = iter(cartesian_product([ZZ, GF(2)])) # optional - sage.rings.finite_rings + sage: [next(it) for _ in range(10)] # optional - sage.rings.finite_rings [(0, 0), (0, 1), (1, 0), (1, 1), (-1, 0), (-1, 1), @@ -2292,8 +2300,8 @@ def __iter__(self): An example with the first factor finite, the second infinite:: - sage: it = iter(cartesian_product([GF(2), ZZ])) - sage: [next(it) for _ in range(11)] + sage: it = iter(cartesian_product([GF(2), ZZ])) # optional - sage.rings.finite_rings + sage: [next(it) for _ in range(11)] # optional - sage.rings.finite_rings [(0, 0), (1, 0), (0, 1), (1, 1), (0, -1), @@ -2378,8 +2386,8 @@ def is_finite(self): EXAMPLES:: sage: E = FiniteEnumeratedSet([1,2,3]) - sage: C = cartesian_product([E, SymmetricGroup(4)]) - sage: C.is_finite() + sage: C = cartesian_product([E, SymmetricGroup(4)]) # optional - sage.groups + sage: C.is_finite() # optional - sage.groups True sage: cartesian_product([ZZ,ZZ]).is_finite() @@ -2406,8 +2414,8 @@ def cardinality(self): EXAMPLES:: sage: E = FiniteEnumeratedSet([1,2,3]) - sage: C = cartesian_product([E,SymmetricGroup(4)]) - sage: C.cardinality() + sage: C = cartesian_product([E, SymmetricGroup(4)]) # optional - sage.groups + sage: C.cardinality() # optional - sage.groups 72 sage: E = FiniteEnumeratedSet([]) @@ -2419,9 +2427,9 @@ def cardinality(self): sage: C.cardinality() +Infinity - sage: cartesian_product([GF(5), Permutations(10)]).cardinality() + sage: cartesian_product([GF(5), Permutations(10)]).cardinality() # optional - sage.rings.finite_rings sage.combinat 18144000 - sage: cartesian_product([GF(71)]*20).cardinality() == 71**20 + sage: cartesian_product([GF(71)]*20).cardinality() == 71**20 # optional - sage.rings.finite_rings True """ f = self.cartesian_factors() @@ -2452,8 +2460,8 @@ def random_element(self, *args): EXAMPLES:: - sage: C = cartesian_product([Permutations(10)]*5) - sage: C.random_element() # random + sage: C = cartesian_product([Permutations(10)]*5) # optional - sage.combinat + sage: C.random_element() # random # optional - sage.combinat ([2, 9, 4, 7, 1, 8, 6, 10, 5, 3], [8, 6, 5, 7, 1, 4, 9, 3, 10, 2], [5, 10, 3, 8, 2, 9, 1, 4, 7, 6], @@ -2562,9 +2570,9 @@ def _sympy_(self): EXAMPLES:: sage: ZZ3 = cartesian_product([ZZ, ZZ, ZZ]) - sage: sZZ3 = ZZ3._sympy_(); sZZ3 + sage: sZZ3 = ZZ3._sympy_(); sZZ3 # optional - sympy ProductSet(Integers, Integers, Integers) - sage: (1, 2, 3) in sZZ3 + sage: (1, 2, 3) in sZZ3 # optional - sympy True """ from sympy import ProductSet @@ -2585,13 +2593,14 @@ def cartesian_projection(self, i): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.__custom_name = "F" - sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.__custom_name = "G" - sage: S = cartesian_product([F, G]) - sage: x = S.monomial((0,4)) + 2 * S.monomial((0,5)) + 3 * S.monomial((1,6)) - sage: x.cartesian_projection(0) + sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") # optional - sage.modules + sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") # optional - sage.modules + sage: S = cartesian_product([F, G]) # optional - sage.modules + sage: x = (S.monomial((0,4)) + 2 * S.monomial((0,5)) # optional - sage.modules + ....: + 3 * S.monomial((1,6))) + sage: x.cartesian_projection(0) # optional - sage.modules B[4] + 2*B[5] - sage: x.cartesian_projection(1) + sage: x.cartesian_projection(1) # optional - sage.modules 3*B[6] """ return self.parent().cartesian_projection(i)(self) @@ -2602,18 +2611,20 @@ def cartesian_factors(self): EXAMPLES:: - sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.__custom_name = "F" - sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.__custom_name = "G" - sage: H = CombinatorialFreeModule(ZZ, [4,7]); H.__custom_name = "H" - sage: S = cartesian_product([F, G, H]) - sage: x = S.monomial((0,4)) + 2 * S.monomial((0,5)) + 3 * S.monomial((1,6)) + 4 * S.monomial((2,4)) + 5 * S.monomial((2,7)) - sage: x.cartesian_factors() + sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") # optional - sage.modules + sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") # optional - sage.modules + sage: H = CombinatorialFreeModule(ZZ, [4,7]); H.rename("H") # optional - sage.modules + sage: S = cartesian_product([F, G, H]) # optional - sage.modules + sage: x = (S.monomial((0,4)) + 2 * S.monomial((0,5)) # optional - sage.modules + ....: + 3 * S.monomial((1,6)) + 4 * S.monomial((2,4)) + ....: + 5 * S.monomial((2,7))) + sage: x.cartesian_factors() # optional - sage.modules (B[4] + 2*B[5], 3*B[6], 4*B[4] + 5*B[7]) - sage: [s.parent() for s in x.cartesian_factors()] + sage: [s.parent() for s in x.cartesian_factors()] # optional - sage.modules [F, G, H] - sage: S.zero().cartesian_factors() + sage: S.zero().cartesian_factors() # optional - sage.modules (0, 0, 0) - sage: [s.parent() for s in S.zero().cartesian_factors()] + sage: [s.parent() for s in S.zero().cartesian_factors()] # optional - sage.modules [F, G, H] """ # TODO: optimize @@ -2633,7 +2644,7 @@ def extra_super_categories(self): sage: Sets().Algebras(QQ).extra_super_categories() [Category of vector spaces with basis over Rational Field] - sage: Sets().example().algebra(ZZ).categories() + sage: Sets().example().algebra(ZZ).categories() # optional - sage.groups sage.modules [Category of set algebras over Integer Ring, Category of modules with basis over Integer Ring, ... @@ -2650,20 +2661,20 @@ def construction(self): EXAMPLES:: - sage: A = GroupAlgebra(KleinFourGroup(), QQ) - sage: F, arg = A.construction(); F, arg + sage: A = GroupAlgebra(KleinFourGroup(), QQ) # optional - sage.groups sage.modules + sage: F, arg = A.construction(); F, arg # optional - sage.groups sage.modules (GroupAlgebraFunctor, Rational Field) - sage: F(arg) is A + sage: F(arg) is A # optional - sage.groups sage.modules True This also works for structures such as monoid algebras (see :trac:`27937`):: - sage: A = FreeAbelianMonoid('x,y').algebra(QQ) - sage: F, arg = A.construction(); F, arg + sage: A = FreeAbelianMonoid('x,y').algebra(QQ) # optional - sage.groups sage.modules + sage: F, arg = A.construction(); F, arg # optional - sage.groups sage.modules (The algebra functorial construction, Free abelian monoid on 2 generators (x, y)) - sage: F(arg) is A + sage: F(arg) is A # optional - sage.groups sage.modules True """ from sage.categories.algebra_functor import ( @@ -2681,14 +2692,14 @@ def _repr_(self): EXAMPLES:: - sage: A = Groups().example().algebra(QQ); A + sage: A = Groups().example().algebra(QQ); A # optional - sage.groups sage.modules Algebra of General Linear Group of degree 4 over Rational Field over Rational Field - sage: A._name = "foo" - sage: A + sage: A._name = "foo" # optional - sage.groups sage.modules + sage: A # optional - sage.groups sage.modules foo over Rational Field - sage: A = KleinFourGroup().algebra(ZZ) - sage: A + sage: A = KleinFourGroup().algebra(ZZ) # optional - sage.groups sage.modules + sage: A # optional - sage.groups sage.modules Algebra of The Klein 4 group of order 4, as a permutation group over Integer Ring """ @@ -2720,10 +2731,10 @@ def example(self, base_ring=None, set=None): EXAMPLES:: - sage: Sets().WithRealizations().example() + sage: Sets().WithRealizations().example() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: Sets().WithRealizations().example(ZZ, Set([1,2])) + sage: Sets().WithRealizations().example(ZZ, Set([1,2])) # optional - sage.combinat sage.modules The subset algebra of {1, 2} over Integer Ring """ from sage.rings.rational_field import QQ @@ -2749,8 +2760,8 @@ def _test_with_realizations(self, **options): EXAMPLES:: - sage: A = Sets().WithRealizations().example() - sage: A._test_with_realizations() + sage: A = Sets().WithRealizations().example() # optional - sage.combinat sage.modules + sage: A._test_with_realizations() # optional - sage.combinat sage.modules See the documentation for :class:`TestSuite` for more information. @@ -2780,13 +2791,15 @@ def _register_realization(self, realization): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(QQ['x']); A - The subset algebra of {1, 2, 3} over Univariate Polynomial Ring in x over Rational Field - sage: class ANewRealizationOfA(CombinatorialFreeModule): + sage: A = Sets().WithRealizations().example(QQ['x']); A # optional - sage.combinat sage.modules + The subset algebra of {1, 2, 3} + over Univariate Polynomial Ring in x over Rational Field + sage: class ANewRealizationOfA(CombinatorialFreeModule): # optional - sage.combinat sage.modules ....: pass - sage: category = A.Realizations() & Algebras(QQ[x]).WithBasis() - sage: R = ANewRealizationOfA(A.base_ring(), A.F().basis().keys(), category = category) - sage: R in A.realizations() # indirect doctest + sage: category = A.Realizations() & Algebras(QQ[x]).WithBasis() # optional - sage.combinat sage.modules + sage: R = ANewRealizationOfA(A.base_ring(), A.F().basis().keys(), # optional - sage.combinat sage.modules + ....: category=category) + sage: R in A.realizations() # indirect doctest # optional - sage.combinat sage.modules True Note: the test above uses ``QQ[x]`` to not interfer @@ -2814,82 +2827,102 @@ def inject_shorthands(self, shorthands=None, verbose=True): it is convenient to define shorthands for the various realizations, but cumbersome to do it by hand:: - sage: S = SymmetricFunctions(ZZ); S + sage: S = SymmetricFunctions(ZZ); S # optional - sage.combinat Symmetric Functions over Integer Ring - sage: s = S.s(); s + sage: s = S.s(); s # optional - sage.combinat Symmetric Functions over Integer Ring in the Schur basis - sage: e = S.e(); e + sage: e = S.e(); e # optional - sage.combinat Symmetric Functions over Integer Ring in the elementary basis This method automates the process:: - sage: S.inject_shorthands() - Defining e as shorthand for Symmetric Functions over Integer Ring in the elementary basis - Defining f as shorthand for Symmetric Functions over Integer Ring in the forgotten basis - Defining h as shorthand for Symmetric Functions over Integer Ring in the homogeneous basis - Defining m as shorthand for Symmetric Functions over Integer Ring in the monomial basis - Defining p as shorthand for Symmetric Functions over Integer Ring in the powersum basis - Defining s as shorthand for Symmetric Functions over Integer Ring in the Schur basis - sage: s[1] + e[2] * p[1,1] + 2*h[3] + m[2,1] - s[1] - 2*s[1, 1, 1] + s[1, 1, 1, 1] + s[2, 1] + 2*s[2, 1, 1] + s[2, 2] + 2*s[3] + s[3, 1] - - sage: e + sage: S.inject_shorthands() # optional - sage.combinat + Defining e as shorthand for + Symmetric Functions over Integer Ring in the elementary basis + Defining f as shorthand for + Symmetric Functions over Integer Ring in the forgotten basis + Defining h as shorthand for + Symmetric Functions over Integer Ring in the homogeneous basis + Defining m as shorthand for + Symmetric Functions over Integer Ring in the monomial basis + Defining p as shorthand for + Symmetric Functions over Integer Ring in the powersum basis + Defining s as shorthand for + Symmetric Functions over Integer Ring in the Schur basis + sage: s[1] + e[2] * p[1,1] + 2*h[3] + m[2,1] # optional - sage.combinat + s[1] - 2*s[1, 1, 1] + s[1, 1, 1, 1] + s[2, 1] + + 2*s[2, 1, 1] + s[2, 2] + 2*s[3] + s[3, 1] + + sage: e # optional - sage.combinat Symmetric Functions over Integer Ring in the elementary basis - sage: p + sage: p # optional - sage.combinat Symmetric Functions over Integer Ring in the powersum basis - sage: s + sage: s # optional - sage.combinat Symmetric Functions over Integer Ring in the Schur basis Sometimes, like for symmetric functions, one can request for all shorthands to be defined, including less common ones:: - sage: S.inject_shorthands("all") - Defining e as shorthand for Symmetric Functions over Integer Ring in the elementary basis - Defining f as shorthand for Symmetric Functions over Integer Ring in the forgotten basis - Defining h as shorthand for Symmetric Functions over Integer Ring in the homogeneous basis - Defining ht as shorthand for Symmetric Functions over Integer Ring in the induced trivial symmetric group character basis - Defining m as shorthand for Symmetric Functions over Integer Ring in the monomial basis - Defining o as shorthand for Symmetric Functions over Integer Ring in the orthogonal basis - Defining p as shorthand for Symmetric Functions over Integer Ring in the powersum basis - Defining s as shorthand for Symmetric Functions over Integer Ring in the Schur basis - Defining sp as shorthand for Symmetric Functions over Integer Ring in the symplectic basis - Defining st as shorthand for Symmetric Functions over Integer Ring in the irreducible symmetric group character basis - Defining w as shorthand for Symmetric Functions over Integer Ring in the Witt basis + sage: S.inject_shorthands("all") # optional - sage.combinat + Defining e as shorthand for + Symmetric Functions over Integer Ring in the elementary basis + Defining f as shorthand for + Symmetric Functions over Integer Ring in the forgotten basis + Defining h as shorthand for + Symmetric Functions over Integer Ring in the homogeneous basis + Defining ht as shorthand for + Symmetric Functions over Integer Ring in the + induced trivial symmetric group character basis + Defining m as shorthand for + Symmetric Functions over Integer Ring in the monomial basis + Defining o as shorthand for + Symmetric Functions over Integer Ring in the orthogonal basis + Defining p as shorthand for + Symmetric Functions over Integer Ring in the powersum basis + Defining s as shorthand for + Symmetric Functions over Integer Ring in the Schur basis + Defining sp as shorthand for + Symmetric Functions over Integer Ring in the symplectic basis + Defining st as shorthand for + Symmetric Functions over Integer Ring in the + irreducible symmetric group character basis + Defining w as shorthand for + Symmetric Functions over Integer Ring in the Witt basis The messages can be silenced by setting ``verbose=False``:: - sage: Q = QuasiSymmetricFunctions(ZZ) - sage: Q.inject_shorthands(verbose=False) + sage: Q = QuasiSymmetricFunctions(ZZ) # optional - sage.combinat + sage: Q.inject_shorthands(verbose=False) # optional - sage.combinat - sage: F[1,2,1] + 5*M[1,3] + F[2]^2 + sage: F[1,2,1] + 5*M[1,3] + F[2]^2 # optional - sage.combinat 5*F[1, 1, 1, 1] - 5*F[1, 1, 2] - 3*F[1, 2, 1] + 6*F[1, 3] + 2*F[2, 2] + F[3, 1] + F[4] - sage: F + sage: F # optional - sage.combinat Quasisymmetric functions over the Integer Ring in the Fundamental basis - sage: M + sage: M # optional - sage.combinat Quasisymmetric functions over the Integer Ring in the Monomial basis One can also just import a subset of the shorthands:: - sage: SQ = SymmetricFunctions(QQ) - sage: SQ.inject_shorthands(['p', 's'], verbose=False) - sage: p + sage: SQ = SymmetricFunctions(QQ) # optional - sage.combinat + sage: SQ.inject_shorthands(['p', 's'], verbose=False) # optional - sage.combinat + sage: p # optional - sage.combinat Symmetric Functions over Rational Field in the powersum basis - sage: s + sage: s # optional - sage.combinat Symmetric Functions over Rational Field in the Schur basis Note that ``e`` is left unchanged:: - sage: e + sage: e # optional - sage.combinat Symmetric Functions over Integer Ring in the elementary basis TESTS:: - sage: e == S.e(), h == S.h(), m == S.m(), p == SQ.p(), s == SQ.s() + sage: e == S.e(), h == S.h(), m == S.m(), p == SQ.p(), s == SQ.s() # optional - sage.combinat (True, True, True, True, True) """ from sage.misc.misc import inject_variable @@ -2912,10 +2945,11 @@ def a_realization(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.a_realization() - The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis + sage: A.a_realization() # optional - sage.combinat sage.modules + The subset algebra of {1, 2, 3} over Rational Field + in the Fundamental basis """ def realizations(self): @@ -2925,10 +2959,12 @@ def realizations(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.realizations() - [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] + sage: A.realizations() # optional - sage.combinat sage.modules + [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, + The subset algebra of {1, 2, 3} over Rational Field in the In basis, + The subset algebra of {1, 2, 3} over Rational Field in the Out basis] .. NOTE:: @@ -2945,20 +2981,22 @@ def facade_for(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.facade_for() - [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] + sage: A.facade_for() # optional - sage.combinat sage.modules + [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, + The subset algebra of {1, 2, 3} over Rational Field in the In basis, + The subset algebra of {1, 2, 3} over Rational Field in the Out basis] - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: f = A.F().an_element(); f + sage: f = A.F().an_element(); f # optional - sage.combinat sage.modules F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] - sage: i = A.In().an_element(); i + sage: i = A.In().an_element(); i # optional - sage.combinat sage.modules In[{}] + 2*In[{1}] + 3*In[{2}] + In[{1, 2}] - sage: o = A.Out().an_element(); o + sage: o = A.Out().an_element(); o # optional - sage.combinat sage.modules Out[{}] + 2*Out[{1}] + 3*Out[{2}] + Out[{1, 2}] - sage: f in A, i in A, o in A + sage: f in A, i in A, o in A # optional - sage.combinat sage.modules (True, True, True) """ return self.realizations() @@ -2970,9 +3008,9 @@ def super_categories(self): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.Realizations().super_categories() + sage: A.Realizations().super_categories() # optional - sage.combinat sage.modules [Category of realizations of sets] """ return [Sets().Realizations()] @@ -2983,9 +3021,9 @@ def _an_element_(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.an_element() # indirect doctest + sage: A.an_element() # indirect doctest # optional - sage.combinat sage.modules F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] TESTS: @@ -2993,9 +3031,9 @@ def _an_element_(self): Check that we are consistent no matter which basis is created first:: - sage: M = posets.BooleanLattice(4).moebius_algebra(QQ) - sage: I = M.I() - sage: M._an_element_() + sage: M = posets.BooleanLattice(4).moebius_algebra(QQ) # optional - sage.combinat sage.graphs sage.modules + sage: I = M.I() # optional - sage.combinat sage.graphs sage.modules + sage: M._an_element_() # optional - sage.combinat sage.graphs sage.modules 2*E[0] + 2*E[1] + 3*E[2] """ return self.a_realization().an_element() @@ -3008,19 +3046,19 @@ def __contains__(self, x): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: A.an_element() in A + sage: A.an_element() in A # optional - sage.combinat sage.modules True - sage: A.In().an_element() in A + sage: A.In().an_element() in A # optional - sage.combinat sage.modules True - sage: A.F().an_element() in A + sage: A.F().an_element() in A # optional - sage.combinat sage.modules True - sage: A.Out().an_element() in A + sage: A.Out().an_element() in A # optional - sage.combinat sage.modules True - sage: 1 in A + sage: 1 in A # optional - sage.combinat sage.modules True - sage: QQ['x'].an_element() in A + sage: QQ['x'].an_element() in A # optional - sage.combinat sage.modules False """ return any(x in realization for realization in self.realizations()) @@ -3035,8 +3073,8 @@ def __init_extra__(self): TESTS:: - sage: A = Sets().WithRealizations().example() - sage: A.realizations() # indirect doctest + sage: A = Sets().WithRealizations().example() # optional - sage.combinat sage.modules + sage: A.realizations() # indirect doctest # optional - sage.combinat sage.modules [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] @@ -3050,11 +3088,11 @@ def realization_of(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In + sage: In = A.In(); In # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: In.realization_of() + sage: In.realization_of() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field """ for category in self.categories(): @@ -3070,11 +3108,11 @@ def _realization_name(self): EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In + sage: In = A.In(); In # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: In._realization_name() + sage: In._realization_name() # optional - sage.combinat sage.modules 'In' """ # The __base__ gets rid of the with_category @@ -3085,9 +3123,9 @@ def _repr_(self): """ EXAMPLES:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field - sage: In = A.In(); In + sage: In = A.In(); In # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis In the example above, :meth:`repr` was overridden by @@ -3099,8 +3137,9 @@ def _repr_(self): sage: from sage.categories.realizations import Realizations sage: class Blah(Parent): ....: pass - sage: P = Blah(category = Sets.WithRealizations.ParentMethods.Realizations(A)) - sage: P # indirect doctest + sage: C = Sets.WithRealizations.ParentMethods.Realizations(A) # optional - sage.combinat sage.modules + sage: P = Blah(category=C) # optional - sage.combinat sage.modules + sage: P # indirect doctest # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the realization Blah """ return "{} in the realization {}".format(self.realization_of(), self._realization_name()) diff --git a/src/sage/categories/sets_with_grading.py b/src/sage/categories/sets_with_grading.py index 5d01bfab999..a9cc219e06e 100644 --- a/src/sage/categories/sets_with_grading.py +++ b/src/sage/categories/sets_with_grading.py @@ -161,9 +161,9 @@ def subset(self, *args, **options): EXAMPLES:: - sage: W = WeightedIntegerVectors([3,2,1]); W + sage: W = WeightedIntegerVectors([3,2,1]); W # optional - sage.combinat Integer vectors weighted by [3, 2, 1] - sage: W.subset(4) + sage: W.subset(4) # optional - sage.combinat Integer vectors of 4 weighted by [3, 2, 1] """ @@ -213,7 +213,7 @@ def generating_series(self): sage: N.generating_series() 1/(-z + 1) - sage: Permutations().generating_series() + sage: Permutations().generating_series() # optional - sage.combinat 1 + z + 2*z^2 + 6*z^3 + 24*z^4 + 120*z^5 + 720*z^6 + O(z^7) .. TODO:: diff --git a/src/sage/categories/simplicial_complexes.py b/src/sage/categories/simplicial_complexes.py index 0e35d866239..87c266858d8 100644 --- a/src/sage/categories/simplicial_complexes.py +++ b/src/sage/categories/simplicial_complexes.py @@ -67,8 +67,8 @@ def dimension(self): EXAMPLES:: - sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) - sage: S.dimension() + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs + sage: S.dimension() # optional - sage.graphs 2 """ return max(c.dimension() for c in self.facets()) @@ -81,8 +81,8 @@ def facets(self): EXAMPLES:: - sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) - sage: sorted(S.facets()) + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs + sage: sorted(S.facets()) # optional - sage.graphs [(1, 2), (1, 3, 4), (2, 5), (4, 5)] """ @@ -93,8 +93,8 @@ def faces(self): EXAMPLES:: - sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) - sage: S.faces() + sage: S = SimplicialComplex([[1,3,4], [1,2],[2,5],[4,5]]) # optional - sage.graphs + sage: S.faces() # optional - sage.graphs {-1: {()}, 0: {(1,), (2,), (3,), (4,), (5,)}, 1: {(1, 2), (1, 3), (1, 4), (2, 5), (3, 4), (4, 5)}, diff --git a/src/sage/categories/simplicial_sets.py b/src/sage/categories/simplicial_sets.py index bcc7150186d..26e8dffabbb 100644 --- a/src/sage/categories/simplicial_sets.py +++ b/src/sage/categories/simplicial_sets.py @@ -71,10 +71,10 @@ def is_finite(self): EXAMPLES:: - sage: simplicial_sets.Torus().is_finite() + sage: simplicial_sets.Torus().is_finite() # optional - sage.graphs True - sage: C5 = groups.misc.MultiplicativeAbelian([5]) - sage: simplicial_sets.ClassifyingSpace(C5).is_finite() + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups + sage: simplicial_sets.ClassifyingSpace(C5).is_finite() # optional - sage.graphs sage.groups False """ return SimplicialSets.Finite() in self.categories() @@ -86,15 +86,15 @@ def is_pointed(self): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet - sage: v = AbstractSimplex(0) - sage: w = AbstractSimplex(0) - sage: e = AbstractSimplex(1) - sage: X = SimplicialSet({e: (v, w)}) - sage: Y = SimplicialSet({e: (v, w)}, base_point=w) - sage: X.is_pointed() + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs + sage: v = AbstractSimplex(0) # optional - sage.graphs + sage: w = AbstractSimplex(0) # optional - sage.graphs + sage: e = AbstractSimplex(1) # optional - sage.graphs + sage: X = SimplicialSet({e: (v, w)}) # optional - sage.graphs + sage: Y = SimplicialSet({e: (v, w)}, base_point=w) # optional - sage.graphs + sage: X.is_pointed() # optional - sage.graphs False - sage: Y.is_pointed() + sage: Y.is_pointed() # optional - sage.graphs True """ return SimplicialSets.Pointed() in self.categories() @@ -110,29 +110,29 @@ def set_base_point(self, point): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet - sage: v = AbstractSimplex(0, name='v_0') - sage: w = AbstractSimplex(0, name='w_0') - sage: e = AbstractSimplex(1) - sage: X = SimplicialSet({e: (v, w)}) - sage: Y = SimplicialSet({e: (v, w)}, base_point=w) - sage: Y.base_point() + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs + sage: v = AbstractSimplex(0, name='v_0') # optional - sage.graphs + sage: w = AbstractSimplex(0, name='w_0') # optional - sage.graphs + sage: e = AbstractSimplex(1) # optional - sage.graphs + sage: X = SimplicialSet({e: (v, w)}) # optional - sage.graphs + sage: Y = SimplicialSet({e: (v, w)}, base_point=w) # optional - sage.graphs + sage: Y.base_point() # optional - sage.graphs w_0 - sage: X_star = X.set_base_point(w) - sage: X_star.base_point() + sage: X_star = X.set_base_point(w) # optional - sage.graphs + sage: X_star.base_point() # optional - sage.graphs w_0 - sage: Y_star = Y.set_base_point(v) - sage: Y_star.base_point() + sage: Y_star = Y.set_base_point(v) # optional - sage.graphs + sage: Y_star.base_point() # optional - sage.graphs v_0 TESTS:: - sage: X.set_base_point(e) + sage: X.set_base_point(e) # optional - sage.graphs Traceback (most recent call last): ... ValueError: the "point" is not a zero-simplex - sage: pt = AbstractSimplex(0) - sage: X.set_base_point(pt) + sage: pt = AbstractSimplex(0) # optional - sage.graphs + sage: X.set_base_point(pt) # optional - sage.graphs Traceback (most recent call last): ... ValueError: the point is not a simplex in this simplicial set @@ -154,8 +154,8 @@ def one(self): EXAMPLES:: - sage: T = simplicial_sets.Torus() - sage: Hom(T, T).identity() + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: Hom(T, T).identity() # optional - sage.graphs Simplicial set endomorphism of Torus Defn: Identity map """ @@ -197,13 +197,13 @@ def base_point(self): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet - sage: v = AbstractSimplex(0, name='*') - sage: e = AbstractSimplex(1) - sage: S1 = SimplicialSet({e: (v, v)}, base_point=v) - sage: S1.is_pointed() + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs + sage: v = AbstractSimplex(0, name='*') # optional - sage.graphs + sage: e = AbstractSimplex(1) # optional - sage.graphs + sage: S1 = SimplicialSet({e: (v, v)}, base_point=v) # optional - sage.graphs + sage: S1.is_pointed() # optional - sage.graphs True - sage: S1.base_point() + sage: S1.base_point() # optional - sage.graphs * """ return self._basepoint @@ -226,26 +226,26 @@ def base_point_map(self, domain=None): EXAMPLES:: - sage: T = simplicial_sets.Torus() - sage: f = T.base_point_map(); f + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: f = T.base_point_map(); f # optional - sage.graphs Simplicial set morphism: From: Point To: Torus Defn: Constant map at (v_0, v_0) - sage: S3 = simplicial_sets.Sphere(3) - sage: g = S3.base_point_map() - sage: f.domain() == g.domain() + sage: S3 = simplicial_sets.Sphere(3) # optional - sage.graphs + sage: g = S3.base_point_map() # optional - sage.graphs + sage: f.domain() == g.domain() # optional - sage.graphs True - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) - sage: temp = simplicial_sets.Simplex(0) - sage: pt = temp.set_base_point(temp.n_cells(0)[0]) - sage: h = RP3.base_point_map(domain=pt) - sage: f.domain() == h.domain() + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs + sage: temp = simplicial_sets.Simplex(0) # optional - sage.graphs + sage: pt = temp.set_base_point(temp.n_cells(0)[0]) # optional - sage.graphs + sage: h = RP3.base_point_map(domain=pt) # optional - sage.graphs + sage: f.domain() == h.domain() # optional - sage.graphs False - sage: C5 = groups.misc.MultiplicativeAbelian([5]) - sage: BC5 = simplicial_sets.ClassifyingSpace(C5) - sage: BC5.base_point_map() + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups + sage: BC5 = simplicial_sets.ClassifyingSpace(C5) # optional - sage.graphs sage.groups + sage: BC5.base_point_map() # optional - sage.graphs sage.groups Simplicial set morphism: From: Point To: Classifying space of Multiplicative Abelian group isomorphic to C5 @@ -285,49 +285,49 @@ def fundamental_group(self, simplify=True): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) - sage: eight = S1.wedge(S1) - sage: eight.fundamental_group() # free group on 2 generators + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs + sage: eight = S1.wedge(S1) # optional - sage.graphs + sage: eight.fundamental_group() # free group on 2 generators # optional - sage.graphs sage.groups Finitely presented group < e0, e1 | > The fundamental group of a disjoint union of course depends on the choice of base point:: - sage: T = simplicial_sets.Torus() - sage: K = simplicial_sets.KleinBottle() - sage: X = T.disjoint_union(K) + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: K = simplicial_sets.KleinBottle() # optional - sage.graphs + sage: X = T.disjoint_union(K) # optional - sage.graphs - sage: X_0 = X.set_base_point(X.n_cells(0)[0]) - sage: X_0.fundamental_group().is_abelian() + sage: X_0 = X.set_base_point(X.n_cells(0)[0]) # optional - sage.graphs + sage: X_0.fundamental_group().is_abelian() # optional - sage.graphs sage.groups True - sage: X_1 = X.set_base_point(X.n_cells(0)[1]) - sage: X_1.fundamental_group().is_abelian() + sage: X_1 = X.set_base_point(X.n_cells(0)[1]) # optional - sage.graphs + sage: X_1.fundamental_group().is_abelian() # optional - sage.graphs sage.groups False - sage: RP3 = simplicial_sets.RealProjectiveSpace(3) - sage: RP3.fundamental_group() + sage: RP3 = simplicial_sets.RealProjectiveSpace(3) # optional - sage.graphs + sage: RP3.fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < e | e^2 > Compute the fundamental group of some classifying spaces:: - sage: C5 = groups.misc.MultiplicativeAbelian([5]) - sage: BC5 = C5.nerve() - sage: BC5.fundamental_group() + sage: C5 = groups.misc.MultiplicativeAbelian([5]) # optional - sage.graphs sage.groups + sage: BC5 = C5.nerve() # optional - sage.graphs sage.groups + sage: BC5.fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < e0 | e0^5 > - sage: Sigma3 = groups.permutation.Symmetric(3) - sage: BSigma3 = Sigma3.nerve() - sage: pi = BSigma3.fundamental_group(); pi + sage: Sigma3 = groups.permutation.Symmetric(3) # optional - sage.graphs sage.groups + sage: BSigma3 = Sigma3.nerve() # optional - sage.graphs sage.groups + sage: pi = BSigma3.fundamental_group(); pi # optional - sage.graphs sage.groups Finitely presented group < e1, e2 | e2^2, e1^3, (e2*e1)^2 > - sage: pi.order() + sage: pi.order() # optional - sage.graphs sage.groups 6 - sage: pi.is_abelian() + sage: pi.is_abelian() # optional - sage.graphs sage.groups False The sphere has a trivial fundamental group:: - sage: S2 = simplicial_sets.Sphere(2) - sage: S2.fundamental_group() + sage: S2 = simplicial_sets.Sphere(2) # optional - sage.graphs + sage: S2.fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < | > """ # Import this here to prevent importing libgap upon startup. @@ -578,26 +578,26 @@ def is_simply_connected(self): EXAMPLES:: - sage: T = simplicial_sets.Torus() - sage: T.is_simply_connected() + sage: T = simplicial_sets.Torus() # optional - sage.graphs + sage: T.is_simply_connected() # optional - sage.graphs False - sage: T.suspension().is_simply_connected() + sage: T.suspension().is_simply_connected() # optional - sage.graphs True - sage: simplicial_sets.KleinBottle().is_simply_connected() + sage: simplicial_sets.KleinBottle().is_simply_connected() # optional - sage.graphs False - sage: S2 = simplicial_sets.Sphere(2) - sage: S3 = simplicial_sets.Sphere(3) - sage: (S2.wedge(S3)).is_simply_connected() + sage: S2 = simplicial_sets.Sphere(2) # optional - sage.graphs + sage: S3 = simplicial_sets.Sphere(3) # optional - sage.graphs + sage: (S2.wedge(S3)).is_simply_connected() # optional - sage.graphs True - sage: X = S2.disjoint_union(S3) - sage: X = X.set_base_point(X.n_cells(0)[0]) - sage: X.is_simply_connected() + sage: X = S2.disjoint_union(S3) # optional - sage.graphs + sage: X = X.set_base_point(X.n_cells(0)[0]) # optional - sage.graphs + sage: X.is_simply_connected() # optional - sage.graphs False - sage: C3 = groups.misc.MultiplicativeAbelian([3]) - sage: BC3 = simplicial_sets.ClassifyingSpace(C3) - sage: BC3.is_simply_connected() + sage: C3 = groups.misc.MultiplicativeAbelian([3]) # optional - sage.graphs sage.groups + sage: BC3 = simplicial_sets.ClassifyingSpace(C3) # optional - sage.graphs sage.groups + sage: BC3.is_simply_connected() # optional - sage.graphs sage.groups False """ if not self.is_connected(): @@ -641,21 +641,21 @@ def connectivity(self, max_dim=None): EXAMPLES:: - sage: simplicial_sets.Sphere(3).connectivity() + sage: simplicial_sets.Sphere(3).connectivity() # optional - sage.graphs 2 - sage: simplicial_sets.Sphere(0).connectivity() + sage: simplicial_sets.Sphere(0).connectivity() # optional - sage.graphs -1 - sage: K = simplicial_sets.Simplex(4) - sage: K = K.set_base_point(K.n_cells(0)[0]) - sage: K.connectivity() + sage: K = simplicial_sets.Simplex(4) # optional - sage.graphs + sage: K = K.set_base_point(K.n_cells(0)[0]) # optional - sage.graphs + sage: K.connectivity() # optional - sage.graphs +Infinity - sage: X = simplicial_sets.Torus().suspension(2) - sage: X.connectivity() + sage: X = simplicial_sets.Torus().suspension(2) # optional - sage.graphs + sage: X.connectivity() # optional - sage.graphs 2 - sage: C2 = groups.misc.MultiplicativeAbelian([2]) - sage: BC2 = simplicial_sets.ClassifyingSpace(C2) - sage: BC2.connectivity() + sage: C2 = groups.misc.MultiplicativeAbelian([2]) # optional - sage.graphs sage.groups + sage: BC2 = simplicial_sets.ClassifyingSpace(C2) # optional - sage.graphs sage.groups + sage: BC2.connectivity() # optional - sage.graphs sage.groups 0 """ if not self.is_connected(): @@ -689,17 +689,17 @@ def unset_base_point(self): EXAMPLES:: - sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet - sage: v = AbstractSimplex(0, name='v_0') - sage: w = AbstractSimplex(0, name='w_0') - sage: e = AbstractSimplex(1) - sage: Y = SimplicialSet({e: (v, w)}, base_point=w) - sage: Y.is_pointed() + sage: from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet # optional - sage.graphs + sage: v = AbstractSimplex(0, name='v_0') # optional - sage.graphs + sage: w = AbstractSimplex(0, name='w_0') # optional - sage.graphs + sage: e = AbstractSimplex(1) # optional - sage.graphs + sage: Y = SimplicialSet({e: (v, w)}, base_point=w) # optional - sage.graphs + sage: Y.is_pointed() # optional - sage.graphs True - sage: Y.base_point() + sage: Y.base_point() # optional - sage.graphs w_0 - sage: Z = Y.unset_base_point() - sage: Z.is_pointed() + sage: Z = Y.unset_base_point() # optional - sage.graphs + sage: Z.is_pointed() # optional - sage.graphs False """ from sage.topology.simplicial_set import SimplicialSet @@ -718,14 +718,14 @@ def fat_wedge(self, n): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) - sage: S1.fat_wedge(0) + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs + sage: S1.fat_wedge(0) # optional - sage.graphs Point - sage: S1.fat_wedge(1) + sage: S1.fat_wedge(1) # optional - sage.graphs S^1 - sage: S1.fat_wedge(2).fundamental_group() + sage: S1.fat_wedge(2).fundamental_group() # optional - sage.graphs sage.groups Finitely presented group < e0, e1 | > - sage: S1.fat_wedge(4).homology() + sage: S1.fat_wedge(4).homology() # optional - sage.graphs sage.modules {0: 0, 1: Z x Z x Z x Z, 2: Z^6, 3: Z x Z x Z x Z} """ from sage.topology.simplicial_set_examples import Point @@ -745,18 +745,18 @@ def smash_product(self, *others): EXAMPLES:: - sage: S1 = simplicial_sets.Sphere(1) - sage: RP2 = simplicial_sets.RealProjectiveSpace(2) - sage: X = S1.smash_product(RP2) - sage: X.homology(base_ring=GF(2)) + sage: S1 = simplicial_sets.Sphere(1) # optional - sage.graphs + sage: RP2 = simplicial_sets.RealProjectiveSpace(2) # optional - sage.graphs + sage: X = S1.smash_product(RP2) # optional - sage.graphs + sage: X.homology(base_ring=GF(2)) # optional - sage.graphs sage.modules {0: Vector space of dimension 0 over Finite Field of size 2, 1: Vector space of dimension 0 over Finite Field of size 2, 2: Vector space of dimension 1 over Finite Field of size 2, 3: Vector space of dimension 1 over Finite Field of size 2} - sage: T = S1.product(S1) - sage: X = T.smash_product(S1) - sage: X.homology(reduced=False) + sage: T = S1.product(S1) # optional - sage.graphs + sage: X = T.smash_product(S1) # optional - sage.graphs + sage: X.homology(reduced=False) # optional - sage.graphs sage.modules {0: Z, 1: 0, 2: Z x Z, 3: Z} """ from sage.topology.simplicial_set_constructions import SmashProductOfSimplicialSets_finite diff --git a/src/sage/categories/super_algebras.py b/src/sage/categories/super_algebras.py index 77fe3a8982b..cad158f689a 100644 --- a/src/sage/categories/super_algebras.py +++ b/src/sage/categories/super_algebras.py @@ -76,22 +76,22 @@ def tensor(*parents, **kwargs): EXAMPLES:: - sage: A. = ExteriorAlgebra(ZZ); A.rename("A") - sage: T = A.tensor(A,A); T + sage: A. = ExteriorAlgebra(ZZ); A.rename("A") # optional - sage.combinat sage.modules + sage: T = A.tensor(A,A); T # optional - sage.combinat sage.modules A # A # A - sage: T in Algebras(ZZ).Graded().SignedTensorProducts() + sage: T in Algebras(ZZ).Graded().SignedTensorProducts() # optional - sage.combinat sage.modules True - sage: T in Algebras(ZZ).Graded().TensorProducts() + sage: T in Algebras(ZZ).Graded().TensorProducts() # optional - sage.combinat sage.modules False - sage: A.rename(None) + sage: A.rename(None) # optional - sage.combinat sage.modules This also works when the other elements do not have a signed tensor product (:trac:`31266`):: - sage: a = SteenrodAlgebra(3).an_element() - sage: M = CombinatorialFreeModule(GF(3), ['s', 't', 'u']) - sage: s = M.basis()['s'] - sage: tensor([a, s]) + sage: a = SteenrodAlgebra(3).an_element() # optional - sage.modules + sage: M = CombinatorialFreeModule(GF(3), ['s', 't', 'u']) # optional - sage.modules sage.rings.finite_rings + sage: s = M.basis()['s'] # optional - sage.modules sage.rings.finite_rings + sage: tensor([a, s]) # optional - sage.modules sage.rings.finite_rings 2*Q_1 Q_3 P(2,1) # B['s'] """ constructor = kwargs.pop('constructor', tensor_signed) diff --git a/src/sage/categories/super_algebras_with_basis.py b/src/sage/categories/super_algebras_with_basis.py index 2cee5d8ad87..affa3386377 100644 --- a/src/sage/categories/super_algebras_with_basis.py +++ b/src/sage/categories/super_algebras_with_basis.py @@ -52,8 +52,8 @@ def graded_algebra(self): EXAMPLES:: - sage: W. = algebras.DifferentialWeyl(QQ) - sage: W.graded_algebra() + sage: W. = algebras.DifferentialWeyl(QQ) # optional - sage.combinat sage.modules + sage: W.graded_algebra() # optional - sage.combinat sage.modules Graded Algebra of Differential Weyl algebra of polynomials in x, y over Rational Field """ @@ -76,27 +76,27 @@ def supercommutator(self, x): EXAMPLES:: - sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) - sage: Cl. = CliffordAlgebra(Q) - sage: a = x*y - z - sage: b = x - y + y*z - sage: a.supercommutator(b) + sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6]) # optional - sage.modules + sage: Cl. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: a = x*y - z # optional - sage.combinat sage.modules + sage: b = x - y + y*z # optional - sage.combinat sage.modules + sage: a.supercommutator(b) # optional - sage.combinat sage.modules -5*x*y + 8*x*z - 2*y*z - 6*x + 12*y - 5*z - sage: a.supercommutator(Cl.one()) + sage: a.supercommutator(Cl.one()) # optional - sage.combinat sage.modules 0 - sage: Cl.one().supercommutator(a) + sage: Cl.one().supercommutator(a) # optional - sage.combinat sage.modules 0 - sage: Cl.zero().supercommutator(a) + sage: Cl.zero().supercommutator(a) # optional - sage.combinat sage.modules 0 - sage: a.supercommutator(Cl.zero()) + sage: a.supercommutator(Cl.zero()) # optional - sage.combinat sage.modules 0 - sage: Q = QuadraticForm(ZZ, 2, [-1,1,-3]) - sage: Cl. = CliffordAlgebra(Q) - sage: [a.supercommutator(b) for a in Cl.basis() for b in Cl.basis()] + sage: Q = QuadraticForm(ZZ, 2, [-1,1,-3]) # optional - sage.modules + sage: Cl. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: [a.supercommutator(b) for a in Cl.basis() for b in Cl.basis()] # optional - sage.combinat sage.modules [0, 0, 0, 0, 0, -2, 1, -x - 2*y, 0, 1, -6, 6*x + y, 0, x + 2*y, -6*x - y, 0] - sage: [a*b-b*a for a in Cl.basis() for b in Cl.basis()] + sage: [a*b-b*a for a in Cl.basis() for b in Cl.basis()] # optional - sage.combinat sage.modules [0, 0, 0, 0, 0, 0, 2*x*y - 1, -x - 2*y, 0, -2*x*y + 1, 0, 6*x + y, 0, x + 2*y, -6*x - y, 0] @@ -104,8 +104,8 @@ def supercommutator(self, x): supercommutators work as well. We verify the exterior algebra is supercommutative:: - sage: E. = ExteriorAlgebra(QQ) - sage: all(b1.supercommutator(b2) == 0 + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: all(b1.supercommutator(b2) == 0 # optional - sage.combinat sage.modules ....: for b1 in E.basis() for b2 in E.basis()) True """ diff --git a/src/sage/categories/super_hopf_algebras_with_basis.py b/src/sage/categories/super_hopf_algebras_with_basis.py index 4fd09867b45..e8974390ba5 100644 --- a/src/sage/categories/super_hopf_algebras_with_basis.py +++ b/src/sage/categories/super_hopf_algebras_with_basis.py @@ -42,15 +42,15 @@ def antipode(self): EXAMPLES:: - sage: A = SteenrodAlgebra(7) - sage: a = A.an_element() - sage: a, A.antipode(a) + sage: A = SteenrodAlgebra(7) # optional - sage.combinat sage.modules + sage: a = A.an_element() # optional - sage.combinat sage.modules + sage: a, A.antipode(a) # optional - sage.combinat sage.modules (6 Q_1 Q_3 P(2,1), Q_1 Q_3 P(2,1)) TESTS:: - sage: E. = ExteriorAlgebra(QQ) - sage: [b.antipode() for b in E.basis()] + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: [b.antipode() for b in E.basis()] # optional - sage.combinat sage.modules [1, -x, -y, x*y] """ if self.antipode_on_basis is not NotImplemented: @@ -88,8 +88,8 @@ def _test_antipode(self, **options): TESTS:: - sage: A = SteenrodAlgebra(7) - sage: A._test_antipode() # long time + sage: A = SteenrodAlgebra(7) # optional - sage.combinat sage.modules + sage: A._test_antipode() # long time # optional - sage.combinat sage.modules """ tester = self._tester(**options) diff --git a/src/sage/categories/super_lie_conformal_algebras.py b/src/sage/categories/super_lie_conformal_algebras.py index 849a0fbdb13..82a11f5f2cc 100644 --- a/src/sage/categories/super_lie_conformal_algebras.py +++ b/src/sage/categories/super_lie_conformal_algebras.py @@ -27,16 +27,16 @@ class SuperLieConformalAlgebras(SuperModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).Super() + sage: LieConformalAlgebras(AA).Super() # optional - sage.rings.number_field Category of super Lie conformal algebras over Algebraic Real Field Notice that we can force to have a *purely even* super Lie conformal algebra:: - sage: bosondict = {('a','a'):{1:{('K',0):1}}} - sage: R = LieConformalAlgebra(QQ,bosondict,names=('a',), + sage: bosondict = {('a','a'): {1:{('K',0):1}}} + sage: R = LieConformalAlgebra(QQ, bosondict, names=('a',), # optional - sage.combinat sage.modules ....: central_elements=('K',), super=True) - sage: [g.is_even_odd() for g in R.gens()] + sage: [g.is_even_odd() for g in R.gens()] # optional - sage.combinat sage.modules [0, 0] """ def extra_super_categories(self): @@ -57,7 +57,7 @@ def example(self): EXAMPLES:: - sage: LieConformalAlgebras(QQ).Super().example() + sage: LieConformalAlgebras(QQ).Super().example() # optional - sage.combinat sage.modules The Neveu-Schwarz super Lie conformal algebra over Rational Field """ from sage.algebras.lie_conformal_algebras.neveu_schwarz_lie_conformal_algebra\ @@ -79,32 +79,33 @@ def _test_jacobi(self, **options): By default, this method tests only the elements returned by ``self.some_elements()``:: - sage: V = lie_conformal_algebras.Affine(QQ, 'B2') - sage: V._test_jacobi() # long time (6 seconds) + sage: V = lie_conformal_algebras.Affine(QQ, 'B2') # optional - sage.combinat sage.modules + sage: V._test_jacobi() # long time (6 seconds) # optional - sage.combinat sage.modules It works for super Lie conformal algebras too:: - sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) - sage: V._test_jacobi() + sage: V = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: V._test_jacobi() # optional - sage.combinat sage.modules We can use specific elements by passing the ``elements`` keyword argument:: - sage: V = lie_conformal_algebras.Affine(QQ, 'A1', names=('e', 'h', 'f')) - sage: V.inject_variables() + sage: V = lie_conformal_algebras.Affine(QQ, 'A1', # optional - sage.combinat sage.modules + ....: names=('e', 'h', 'f')) + sage: V.inject_variables() # optional - sage.combinat sage.modules Defining e, h, f, K - sage: V._test_jacobi(elements=(e, 2*f+h, 3*h)) + sage: V._test_jacobi(elements=(e, 2*f + h, 3*h)) # optional - sage.combinat sage.modules TESTS:: - sage: wrongdict = {('a', 'a'): {0: {('b', 0): 1}}, ('b', 'a'): {0: {('a', 0): 1}}} - sage: V = LieConformalAlgebra(QQ, wrongdict, names=('a', 'b'), parity=(1, 0)) - sage: V._test_jacobi() + sage: wrongdict = {('a', 'a'): {0: {('b', 0): 1}}, + ....: ('b', 'a'): {0: {('a', 0): 1}}} + sage: V = LieConformalAlgebra(QQ, wrongdict, # optional - sage.combinat sage.modules + ....: names=('a', 'b'), parity=(1, 0)) + sage: V._test_jacobi() # optional - sage.combinat sage.modules Traceback (most recent call last): ... - AssertionError: {(0, 0): -3*a} != {} - - {(0, 0): -3*a} - + {} + AssertionError: {(0, 0): -3*a} != {} - {(0, 0): -3*a} + {} """ tester = self._tester(**options) S = tester.some_elements() @@ -162,10 +163,10 @@ def is_even_odd(self): EXAMPLES:: - sage: R = lie_conformal_algebras.NeveuSchwarz(QQ); - sage: R.inject_variables() + sage: R = lie_conformal_algebras.NeveuSchwarz(QQ) # optional - sage.combinat sage.modules + sage: R.inject_variables() # optional - sage.combinat sage.modules Defining L, G, C - sage: G.is_even_odd() + sage: G.is_even_odd() # optional - sage.combinat sage.modules 1 """ @@ -175,7 +176,7 @@ class Graded(GradedModulesCategory): EXAMPLES:: - sage: LieConformalAlgebras(AA).Super().Graded() + sage: LieConformalAlgebras(AA).Super().Graded() # optional - sage.rings.number_field Category of H-graded super Lie conformal algebras over Algebraic Real Field """ def _repr_object_names(self): @@ -184,7 +185,7 @@ def _repr_object_names(self): EXAMPLES:: - sage: LieConformalAlgebras(QQbar).Graded() + sage: LieConformalAlgebras(QQbar).Graded() # optional - sage.rings.number_field Category of H-graded Lie conformal algebras over Algebraic Field """ return "H-graded {}".format(self.base_category()._repr_object_names()) diff --git a/src/sage/categories/super_modules.py b/src/sage/categories/super_modules.py index 091b808408e..2efd5f6e7e2 100644 --- a/src/sage/categories/super_modules.py +++ b/src/sage/categories/super_modules.py @@ -45,7 +45,7 @@ def default_super_categories(cls, category, *args): EXAMPLES:: - sage: HopfAlgebras(ZZ).WithBasis().FiniteDimensional().Super() # indirect doctest + sage: HopfAlgebras(ZZ).WithBasis().FiniteDimensional().Super() # indirect doctest Category of finite dimensional super hopf algebras with basis over Integer Ring """ axioms = axiom_whitelist.intersection(category.axioms()) @@ -183,11 +183,11 @@ def is_even_odd(self): EXAMPLES:: sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) - sage: C.degree_on_basis = sum - sage: C.basis()[2,2,1].is_even_odd() + sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) # optional - sage.combinat sage.modules + sage: C.degree_on_basis = sum # optional - sage.combinat sage.modules + sage: C.basis()[2,2,1].is_even_odd() # optional - sage.combinat sage.modules 1 - sage: C.basis()[2,2].is_even_odd() + sage: C.basis()[2,2].is_even_odd() # optional - sage.combinat sage.modules 0 """ return self.degree() % 2 @@ -199,11 +199,11 @@ def is_even(self): EXAMPLES:: sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) - sage: C.degree_on_basis = sum - sage: C.basis()[2,2,1].is_even() + sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) # optional - sage.combinat sage.modules + sage: C.degree_on_basis = sum # optional - sage.combinat sage.modules + sage: C.basis()[2,2,1].is_even() # optional - sage.combinat sage.modules False - sage: C.basis()[2,2].is_even() + sage: C.basis()[2,2].is_even() # optional - sage.combinat sage.modules True """ return self.is_even_odd() == 0 @@ -215,11 +215,11 @@ def is_odd(self): EXAMPLES:: sage: cat = Algebras(QQ).WithBasis().Super() - sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) - sage: C.degree_on_basis = sum - sage: C.basis()[2,2,1].is_odd() + sage: C = CombinatorialFreeModule(QQ, Partitions(), category=cat) # optional - sage.combinat sage.modules + sage: C.degree_on_basis = sum # optional - sage.combinat sage.modules + sage: C.basis()[2,2,1].is_odd() # optional - sage.combinat sage.modules True - sage: C.basis()[2,2].is_odd() + sage: C.basis()[2,2].is_odd() # optional - sage.combinat sage.modules False """ return self.is_even_odd() == 1 diff --git a/src/sage/categories/super_modules_with_basis.py b/src/sage/categories/super_modules_with_basis.py index 7317d42f95c..dff6b54fbe2 100644 --- a/src/sage/categories/super_modules_with_basis.py +++ b/src/sage/categories/super_modules_with_basis.py @@ -53,11 +53,11 @@ def _even_odd_on_basis(self, m): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: C._even_odd_on_basis((0,)) + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules + sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: C._even_odd_on_basis((0,)) # optional - sage.combinat sage.modules 1 - sage: C._even_odd_on_basis((0,1)) + sage: C._even_odd_on_basis((0,1)) # optional - sage.combinat sage.modules 0 """ return self.degree_on_basis(m) % 2 @@ -70,27 +70,27 @@ def is_super_homogeneous(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x + y - sage: a.is_super_homogeneous() + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules + sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: a = x + y # optional - sage.combinat sage.modules + sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules True - sage: a = x*y + 4 - sage: a.is_super_homogeneous() + sage: a = x*y + 4 # optional - sage.combinat sage.modules + sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules True - sage: a = x*y + x - 3*y + 4 - sage: a.is_super_homogeneous() + sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules + sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules False The exterior algebra has a `\ZZ` grading, which induces the `\ZZ / 2\ZZ` grading. However the definition of homogeneous elements differs because of the different gradings:: - sage: E. = ExteriorAlgebra(QQ) - sage: a = x*y + 4 - sage: a.is_super_homogeneous() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: a = x*y + 4 # optional - sage.combinat sage.modules + sage: a.is_super_homogeneous() # optional - sage.combinat sage.modules True - sage: a.is_homogeneous() + sage: a.is_homogeneous() # optional - sage.combinat sage.modules False """ even_odd = self.parent()._even_odd_on_basis @@ -110,22 +110,22 @@ def is_even_odd(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x + y - sage: a.is_even_odd() + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules + sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: a = x + y # optional - sage.combinat sage.modules + sage: a.is_even_odd() # optional - sage.combinat sage.modules 1 - sage: a = x*y + 4 - sage: a.is_even_odd() + sage: a = x*y + 4 # optional - sage.combinat sage.modules + sage: a.is_even_odd() # optional - sage.combinat sage.modules 0 - sage: a = x + 4 - sage: a.is_even_odd() + sage: a = x + 4 # optional - sage.combinat sage.modules + sage: a.is_even_odd() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous - sage: E. = ExteriorAlgebra(QQ) - sage: (x*y).is_even_odd() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: (x*y).is_even_odd() # optional - sage.combinat sage.modules 0 """ if not self.support(): @@ -140,18 +140,18 @@ def even_component(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x*y + x - 3*y + 4 - sage: a.even_component() + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules + sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules + sage: a.even_component() # optional - sage.combinat sage.modules x*y + 4 TESTS: Check that this really return ``A.zero()`` and not a plain ``0``:: - sage: a = x + y - sage: a.even_component().parent() is C + sage: a = x + y # optional - sage.combinat sage.modules + sage: a.even_component().parent() is C # optional - sage.combinat sage.modules True """ even_odd = self.parent()._even_odd_on_basis @@ -165,18 +165,18 @@ def odd_component(self): EXAMPLES:: - sage: Q = QuadraticForm(QQ, 2, [1,2,3]) - sage: C. = CliffordAlgebra(Q) - sage: a = x*y + x - 3*y + 4 - sage: a.odd_component() + sage: Q = QuadraticForm(QQ, 2, [1,2,3]) # optional - sage.modules + sage: C. = CliffordAlgebra(Q) # optional - sage.combinat sage.modules + sage: a = x*y + x - 3*y + 4 # optional - sage.combinat sage.modules + sage: a.odd_component() # optional - sage.combinat sage.modules x - 3*y TESTS: Check that this really return ``A.zero()`` and not a plain ``0``:: - sage: a = x*y - sage: a.odd_component().parent() is C + sage: a = x*y # optional - sage.combinat sage.modules + sage: a.odd_component().parent() is C # optional - sage.combinat sage.modules True """ even_odd = self.parent()._even_odd_on_basis diff --git a/src/sage/categories/supercommutative_algebras.py b/src/sage/categories/supercommutative_algebras.py index 4cd44e849c9..9cb2f609a8c 100644 --- a/src/sage/categories/supercommutative_algebras.py +++ b/src/sage/categories/supercommutative_algebras.py @@ -73,15 +73,15 @@ def _test_supercommutativity(self, **options): By default, this method tests only the elements returned by ``self.some_elements()``:: - sage: E. = ExteriorAlgebra(QQ) - sage: E._test_supercommutativity() + sage: E. = ExteriorAlgebra(QQ) # optional - sage.combinat sage.modules + sage: E._test_supercommutativity() # optional - sage.combinat sage.modules However, the elements tested can be customized with the ``elements`` keyword argument, but the elements must be homogeneous:: - sage: E._test_supercommutativity(elements=[x+y, x*y-3*y*z, x*y*z]) - sage: E._test_supercommutativity(elements=[x+x*y]) + sage: E._test_supercommutativity(elements=[x+y, x*y-3*y*z, x*y*z]) # optional - sage.combinat sage.modules + sage: E._test_supercommutativity(elements=[x+x*y]) # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not homogeneous diff --git a/src/sage/categories/supercrystals.py b/src/sage/categories/supercrystals.py index 1e15c935599..a68c1d7c591 100644 --- a/src/sage/categories/supercrystals.py +++ b/src/sage/categories/supercrystals.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs sage.combinat r""" Supercrystals """ @@ -42,11 +43,13 @@ def tensor(self, *crystals, **options): sage: B = crystals.Letters(['A',[1,2]]) sage: C = crystals.Tableaux(['A',[1,2]], shape = [2,1]) sage: T = C.tensor(B); T - Full tensor product of the crystals [Crystal of BKK tableaux of shape [2, 1] of gl(2|3), - The crystal of letters for type ['A', [1, 2]]] + Full tensor product of the crystals + [Crystal of BKK tableaux of shape [2, 1] of gl(2|3), + The crystal of letters for type ['A', [1, 2]]] sage: S = B.tensor(C); S - Full tensor product of the crystals [The crystal of letters for type ['A', [1, 2]], - Crystal of BKK tableaux of shape [2, 1] of gl(2|3)] + Full tensor product of the crystals + [The crystal of letters for type ['A', [1, 2]], + Crystal of BKK tableaux of shape [2, 1] of gl(2|3)] sage: G = T.digraph() sage: H = S.digraph() sage: G.is_isomorphic(H, edge_labels= True) diff --git a/src/sage/categories/triangular_kac_moody_algebras.py b/src/sage/categories/triangular_kac_moody_algebras.py index 95c7881043f..434ff22c1c7 100644 --- a/src/sage/categories/triangular_kac_moody_algebras.py +++ b/src/sage/categories/triangular_kac_moody_algebras.py @@ -60,10 +60,10 @@ def _part_on_basis(self, m): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) - sage: L.f() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L.f() # optional - sage.combinat sage.modules Finite family {1: E[-alpha[1]], 2: E[-alpha[2]]} - sage: L.f(1) + sage: L.f(1) # optional - sage.combinat sage.modules E[-alpha[1]] """ deg = self.degree_on_basis(m) @@ -100,8 +100,8 @@ def _part_generators(self, positive=False): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type=['E',6]) - sage: list(L._part_generators(False)) + sage: L = LieAlgebra(QQ, cartan_type=['E', 6]) # optional - sage.combinat sage.modules + sage: list(L._part_generators(False)) # optional - sage.combinat sage.modules [E[-alpha[1]], E[-alpha[2]], E[-alpha[3]], E[-alpha[4]], E[-alpha[5]], E[-alpha[6]]] """ @@ -128,10 +128,10 @@ def e(self, i=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) - sage: L.e() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L.e() # optional - sage.combinat sage.modules Finite family {1: E[alpha[1]], 2: E[alpha[2]]} - sage: L.e(1) + sage: L.e(1) # optional - sage.combinat sage.modules E[alpha[1]] """ E = self._part_generators(True) @@ -150,10 +150,10 @@ def f(self, i=None): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) - sage: L.f() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L.f() # optional - sage.combinat sage.modules Finite family {1: E[-alpha[1]], 2: E[-alpha[2]]} - sage: L.f(1) + sage: L.f(1) # optional - sage.combinat sage.modules E[-alpha[1]] """ F = self._part_generators(False) @@ -168,8 +168,8 @@ def _negative_half_index_set(self): EXAMPLES:: - sage: L = lie_algebras.so(QQ, 5) - sage: L._negative_half_index_set() + sage: L = lie_algebras.so(QQ, 5) # optional - sage.combinat sage.modules + sage: L._negative_half_index_set() # optional - sage.combinat sage.modules [-alpha[2], -alpha[1], -alpha[1] - alpha[2], -alpha[1] - 2*alpha[2]] """ @@ -186,15 +186,15 @@ def _weight_action(self, m, wt): EXAMPLES:: - sage: L = lie_algebras.sp(QQ, 6) - sage: La = L.cartan_type().root_system().weight_space().fundamental_weights() - sage: mu = La[1] - 3/5*La[2] - sage: ac = L.cartan_type().root_system().coroot_lattice().simple_roots() - sage: L._weight_action(ac[1], mu) + sage: L = lie_algebras.sp(QQ, 6) # optional - sage.combinat sage.modules + sage: La = L.cartan_type().root_system().weight_space().fundamental_weights() # optional - sage.combinat sage.modules + sage: mu = La[1] - 3/5*La[2] # optional - sage.combinat sage.modules + sage: ac = L.cartan_type().root_system().coroot_lattice().simple_roots() # optional - sage.combinat sage.modules + sage: L._weight_action(ac[1], mu) # optional - sage.combinat sage.modules 1 - sage: L._weight_action(ac[2], mu) + sage: L._weight_action(ac[2], mu) # optional - sage.combinat sage.modules -3/5 - sage: L._weight_action(ac[3], mu) + sage: L._weight_action(ac[3], mu) # optional - sage.combinat sage.modules 0 """ @@ -210,11 +210,11 @@ def verma_module(self, la, basis_key=None, **kwds): EXAMPLES:: - sage: L = lie_algebras.sl(QQ, 3) - sage: P = L.cartan_type().root_system().weight_lattice() - sage: La = P.fundamental_weights() - sage: M = L.verma_module(La[1]+La[2]) - sage: M + sage: L = lie_algebras.sl(QQ, 3) # optional - sage.combinat sage.modules + sage: P = L.cartan_type().root_system().weight_lattice() # optional - sage.combinat sage.modules + sage: La = P.fundamental_weights() # optional - sage.combinat sage.modules + sage: M = L.verma_module(La[1] + La[2]) # optional - sage.combinat sage.modules + sage: M # optional - sage.combinat sage.modules Verma module with highest weight Lambda[1] + Lambda[2] of Lie algebra of ['A', 2] in the Chevalley basis """ @@ -234,18 +234,18 @@ def part(self): EXAMPLES:: - sage: L = LieAlgebra(QQ, cartan_type="F4") - sage: L.inject_variables() + sage: L = LieAlgebra(QQ, cartan_type="F4") # optional - sage.combinat sage.modules + sage: L.inject_variables() # optional - sage.combinat sage.modules Defining e1, e2, e3, e4, f1, f2, f3, f4, h1, h2, h3, h4 - sage: e1.part() + sage: e1.part() # optional - sage.combinat sage.modules 1 - sage: f4.part() + sage: f4.part() # optional - sage.combinat sage.modules -1 - sage: (h2 + h3).part() + sage: (h2 + h3).part() # optional - sage.combinat sage.modules 0 - sage: (f1.bracket(f2) + 4*f4).part() + sage: (f1.bracket(f2) + 4*f4).part() # optional - sage.combinat sage.modules -1 - sage: (e1 + f1).part() + sage: (e1 + f1).part() # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: element is not in one part diff --git a/src/sage/categories/unique_factorization_domains.py b/src/sage/categories/unique_factorization_domains.py index 280320474d8..f3d6b565316 100644 --- a/src/sage/categories/unique_factorization_domains.py +++ b/src/sage/categories/unique_factorization_domains.py @@ -65,7 +65,7 @@ def __contains__(self, x): """ EXAMPLES:: - sage: GF(4, "a") in UniqueFactorizationDomains() + sage: GF(4, "a") in UniqueFactorizationDomains() # optional - sage.rings.finite_rings True sage: QQ in UniqueFactorizationDomains() True @@ -123,7 +123,8 @@ def is_unique_factorization_domain(self, proof=True): EXAMPLES:: - sage: Parent(QQ,category=UniqueFactorizationDomains()).is_unique_factorization_domain() + sage: UFD = UniqueFactorizationDomains() + sage: Parent(QQ, category=UFD).is_unique_factorization_domain() True """ @@ -154,16 +155,17 @@ def _gcd_univariate_polynomial(self, f, g): sage: q = (-x^2 - 4*x - 5)*T^2 + (6*x^2 + x + 1)*T + 2*x^2 - x sage: quo,rem=p.pseudo_quo_rem(q); quo,rem ((3*x^4 + 13*x^3 + 19*x^2 + 5*x)*T + 18*x^4 + 12*x^3 + 16*x^2 + 16*x, - (-113*x^6 - 106*x^5 - 133*x^4 - 101*x^3 - 42*x^2 - 41*x)*T - 34*x^6 + 13*x^5 + 54*x^4 + 126*x^3 + 134*x^2 - 5*x - 50) + (-113*x^6 - 106*x^5 - 133*x^4 - 101*x^3 - 42*x^2 - 41*x)*T + - 34*x^6 + 13*x^5 + 54*x^4 + 126*x^3 + 134*x^2 - 5*x - 50) sage: (-x^2 - 4*x - 5)^(3-2+1) * p == quo*q + rem True Check that :trac:`23620` has been resolved:: - sage: R. = ZpFM(2)[] - sage: f = 2*x + 2 - sage: g = 4*x + 2 - sage: f.gcd(g).parent() is R + sage: R. = ZpFM(2)[] # optional - sage.rings.padics + sage: f = 2*x + 2 # optional - sage.rings.padics + sage: g = 4*x + 2 # optional - sage.rings.padics + sage: f.gcd(g).parent() is R # optional - sage.rings.padics True """ diff --git a/src/sage/categories/unital_algebras.py b/src/sage/categories/unital_algebras.py index d245b4de8c1..388a6e940a7 100644 --- a/src/sage/categories/unital_algebras.py +++ b/src/sage/categories/unital_algebras.py @@ -61,9 +61,10 @@ def from_base_ring(self, r): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.from_base_ring(1) + 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: A.from_base_ring(1) # optional - sage.combinat sage.modules B[word: ] """ return self.one()._lmul_(r) @@ -75,16 +76,18 @@ def __init_extra__(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example(); A - An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field + 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: coercion_model = sage.structure.element.get_coercion_model() - sage: coercion_model.discover_coercion(QQ, A) + sage: coercion_model.discover_coercion(QQ, A) # optional - sage.combinat sage.modules ((map internal to coercion system -- copy before use) Generic morphism: From: Rational Field - To: An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field, + To: An example of an algebra with basis: + the free algebra on the generators ('a', 'b', 'c') over Rational Field, None) - sage: A(1) # indirect doctest + sage: A(1) # indirect doctest # optional - sage.combinat sage.modules B[word: ] TESTS: @@ -92,16 +95,15 @@ def __init_extra__(self): Ensure that :trac:`28328` is fixed and that non-associative algebras are supported:: - sage: class Foo(CombinatorialFreeModule): + sage: class Foo(CombinatorialFreeModule): # optional - sage.modules ....: def one(self): ....: return self.monomial(0) - sage: from sage.categories.magmatic_algebras \ - ....: import MagmaticAlgebras + sage: from sage.categories.magmatic_algebras import MagmaticAlgebras sage: C = MagmaticAlgebras(QQ).WithBasis().Unital() - sage: F = Foo(QQ,(1,),category=C) - sage: F(0) + sage: F = Foo(QQ, (1,), category=C) # optional - sage.modules + sage: F(0) # optional - sage.modules 0 - sage: F(3) + sage: F(3) # optional - sage.modules 3*B[0] sage: class Bar(Parent): @@ -183,8 +185,8 @@ def _coerce_map_from_base_ring(self): Check that :trac:`29312` is fixed:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: F._coerce_map_from_base_ring() + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: F._coerce_map_from_base_ring() # optional - sage.combinat sage.modules Generic morphism: From: Rational Field To: Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field @@ -274,12 +276,12 @@ def one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules word: - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules B[word: ] - sage: A.from_base_ring(4) + sage: A.from_base_ring(4) # optional - sage.combinat sage.modules 4*B[word: ] """ @@ -295,33 +297,33 @@ def one_from_one_basis(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules word: - sage: A.one_from_one_basis() + sage: A.one_from_one_basis() # optional - sage.combinat sage.modules B[word: ] - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules B[word: ] TESTS: Try to check that :trac:`5843` Heisenbug is fixed:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: B = AlgebrasWithBasis(QQ).example(('a', 'c')) - sage: A == B + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: B = AlgebrasWithBasis(QQ).example(('a', 'c')) # optional - sage.combinat sage.modules + sage: A == B # optional - sage.combinat sage.modules False - sage: Aone = A.one_from_one_basis - sage: Bone = B.one_from_one_basis - sage: Aone is Bone + sage: Aone = A.one_from_one_basis # optional - sage.combinat sage.modules + sage: Bone = B.one_from_one_basis # optional - sage.combinat sage.modules + sage: Aone is Bone # optional - sage.combinat sage.modules False Even if called in the wrong order, they should returns their respective one:: - sage: Bone().parent() is B + sage: Bone().parent() is B # optional - sage.combinat sage.modules True - sage: Aone().parent() is A + sage: Aone().parent() is A # optional - sage.combinat sage.modules True """ return self.monomial(self.one_basis()) #. @@ -333,10 +335,10 @@ def one(self): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.one_basis() + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.one_basis() # optional - sage.combinat sage.modules word: - sage: A.one() + sage: A.one() # optional - sage.combinat sage.modules B[word: ] """ if self.one_basis is NotImplemented: @@ -348,8 +350,8 @@ def from_base_ring(self): """ TESTS:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.from_base_ring(3) + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.from_base_ring(3) # optional - sage.combinat sage.modules 3*B[word: ] """ if self.one_basis is NotImplemented: @@ -366,12 +368,12 @@ def from_base_ring_from_one_basis(self, r): EXAMPLES:: - sage: A = AlgebrasWithBasis(QQ).example() - sage: A.from_base_ring_from_one_basis(3) + sage: A = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules + sage: A.from_base_ring_from_one_basis(3) # optional - sage.combinat sage.modules 3*B[word: ] - sage: A.from_base_ring(3) + sage: A.from_base_ring(3) # optional - sage.combinat sage.modules 3*B[word: ] - sage: A(3) + sage: A(3) # optional - sage.combinat sage.modules 3*B[word: ] """ return self.term(self.one_basis(), r) diff --git a/src/sage/categories/vector_spaces.py b/src/sage/categories/vector_spaces.py index 66534879b5a..ef41dec6c3a 100644 --- a/src/sage/categories/vector_spaces.py +++ b/src/sage/categories/vector_spaces.py @@ -82,8 +82,8 @@ def __init__(self, K): TESTS:: - sage: C = QQ^10 # vector space - sage: TestSuite(C).run() + sage: C = QQ^10 # vector space # optional - sage.modules + sage: TestSuite(C).run() # optional - sage.modules sage: TestSuite(VectorSpaces(QQ)).run() """ Category_module.__init__(self, K) @@ -94,15 +94,15 @@ def _call_(self, x): EXAMPLES:: - sage: VectorSpaces(QQ)(ZZ^3) + sage: VectorSpaces(QQ)(ZZ^3) # optional - sage.modules Vector space of dimension 3 over Rational Field TESTS: Check whether :trac:`30174` is fixed:: - sage: Q3 = FiniteRankFreeModule(QQ, 3) - sage: Modules(QQ)(Q3) is Q3 + sage: Q3 = FiniteRankFreeModule(QQ, 3) # optional - sage.modules + sage: Modules(QQ)(Q3) is Q3 # optional - sage.modules True """ @@ -162,15 +162,15 @@ def dimension(self): EXAMPLES:: - sage: M = FreeModule(FiniteField(19), 100) - sage: W = M.submodule([M.gen(50)]) - sage: W.dimension() + sage: M = FreeModule(FiniteField(19), 100) # optional - sage.libs.pari sage.modules + sage: W = M.submodule([M.gen(50)]) # optional - sage.libs.pari sage.modules + sage: W.dimension() # optional - sage.libs.pari sage.modules 1 - sage: M = FiniteRankFreeModule(QQ, 3) - sage: M.dimension() + sage: M = FiniteRankFreeModule(QQ, 3) # optional - sage.modules + sage: M.dimension() # optional - sage.modules 3 - sage: M.tensor_module(1,2).dimension() + sage: M.tensor_module(1, 2).dimension() # optional - sage.modules 27 """ @@ -253,7 +253,7 @@ def example(self, base_ring=None): EXAMPLES:: - sage: Modules(QQ).WithBasis().Graded().example() + sage: Modules(QQ).WithBasis().Graded().example() # optional - sage.combinat sage.modules An example of a graded module with basis: the free module on partitions over Rational Field """ @@ -274,7 +274,7 @@ def example(self, base_ring=None): EXAMPLES:: - sage: Modules(QQ).WithBasis().Graded().example() + sage: Modules(QQ).WithBasis().Graded().example() # optional - sage.combinat sage.modules An example of a graded module with basis: the free module on partitions over Rational Field """ diff --git a/src/sage/categories/weyl_groups.py b/src/sage/categories/weyl_groups.py index ed094d6554d..70f8879353e 100644 --- a/src/sage/categories/weyl_groups.py +++ b/src/sage/categories/weyl_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat sage.groups r""" Weyl Groups """ @@ -182,13 +183,15 @@ def bruhat_cone(self, x, y, side='upper', backend='cdd'): sage: x = W.from_reduced_word([1]) sage: y = W.w0 sage: W.bruhat_cone(x, y) - A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex and 2 rays + A 2-dimensional polyhedron in QQ^3 + defined as the convex hull of 1 vertex and 2 rays sage: W = WeylGroup(['E',6]) sage: x = W.one() sage: y = W.w0 sage: W.bruhat_cone(x, y, side='lower') - A 6-dimensional polyhedron in QQ^8 defined as the convex hull of 1 vertex and 6 rays + A 6-dimensional polyhedron in QQ^8 + defined as the convex hull of 1 vertex and 6 rays TESTS:: @@ -242,7 +245,9 @@ def quantum_bruhat_graph(self, index_set=()): sage: W = WeylGroup(['A',3], prefix="s") sage: g = W.quantum_bruhat_graph((1,3)) sage: g - Parabolic Quantum Bruhat Graph of Weyl Group of type ['A', 3] (as a matrix group acting on the ambient space) for nodes (1, 3): Digraph on 6 vertices + Parabolic Quantum Bruhat Graph of Weyl Group of type ['A', 3] + (as a matrix group acting on the ambient space) + for nodes (1, 3): Digraph on 6 vertices sage: g.vertices(sort=True) [s2*s3*s1*s2, s3*s1*s2, s1*s2, s3*s2, s2, 1] sage: g.edges(sort=True) @@ -385,14 +390,16 @@ def left_pieri_factorizations(self, max_length=None): 3 sage: W.from_reduced_word([1,2]).left_pieri_factorizations().cardinality() 2 - sage: [W.from_reduced_word([1,2]).left_pieri_factorizations(max_length=i).cardinality() for i in [-1, 0, 1, 2]] + sage: [W.from_reduced_word([1,2]).left_pieri_factorizations(max_length=i).cardinality() + ....: for i in [-1, 0, 1, 2]] [0, 1, 2, 2] sage: W = WeylGroup(['C',4,1]) sage: w = W.from_reduced_word([0,3,2,1,0]) sage: w.left_pieri_factorizations().cardinality() 7 - sage: [(u.reduced_word(),v.reduced_word()) for (u,v) in w.left_pieri_factorizations()] + sage: [(u.reduced_word(),v.reduced_word()) + ....: for (u,v) in w.left_pieri_factorizations()] [([], [3, 2, 0, 1, 0]), ([0], [3, 2, 1, 0]), ([3], [2, 0, 1, 0]), @@ -460,9 +467,11 @@ def stanley_symmetric_function_as_polynomial(self, max_length=None): 2*x1^3 + x1*x2 sage: W.from_reduced_word([1,2,1,0]).stanley_symmetric_function_as_polynomial() 3*x1^4 + 2*x1^2*x2 + x2^2 + x1*x3 - sage: W.from_reduced_word([1,2,3,1,2,1,0]).stanley_symmetric_function_as_polynomial() # long time + sage: x = W.from_reduced_word([1,2,3,1,2,1,0]) + sage: x.stanley_symmetric_function_as_polynomial() # long time 22*x1^7 + 11*x1^5*x2 + 5*x1^3*x2^2 + 3*x1^4*x3 + 2*x1*x2^3 + x1^2*x2*x3 - sage: W.from_reduced_word([3,1,2,0,3,1,0]).stanley_symmetric_function_as_polynomial() # long time + sage: y = W.from_reduced_word([3,1,2,0,3,1,0]) + sage: y.stanley_symmetric_function_as_polynomial() # long time 8*x1^7 + 4*x1^5*x2 + 2*x1^3*x2^2 + x1*x2^3 sage: W = WeylGroup(['C',3,1]) @@ -516,10 +525,12 @@ def stanley_symmetric_function(self): sage: W = WeylGroup(['A', 3, 1]) sage: W.from_reduced_word([3,1,2,0,3,1,0]).stanley_symmetric_function() - 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] + 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] sage: A = AffinePermutationGroup(['A',3,1]) sage: A.from_reduced_word([3,1,2,0,3,1,0]).stanley_symmetric_function() - 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] + 8*m[1, 1, 1, 1, 1, 1, 1] + 4*m[2, 1, 1, 1, 1, 1] + + 2*m[2, 2, 1, 1, 1] + m[2, 2, 2, 1] sage: W = WeylGroup(['C',3,1]) sage: W.from_reduced_word([0,2,1,0]).stanley_symmetric_function() @@ -537,10 +548,11 @@ def stanley_symmetric_function(self): sage: A = AffinePermutationGroup(['A',4,1]) sage: a = A([-2,0,1,4,12]) sage: a.stanley_symmetric_function() - 6*m[1, 1, 1, 1, 1, 1, 1, 1] + 5*m[2, 1, 1, 1, 1, 1, 1] + 4*m[2, 2, 1, 1, 1, 1] - + 3*m[2, 2, 2, 1, 1] + 2*m[2, 2, 2, 2] + 4*m[3, 1, 1, 1, 1, 1] + 3*m[3, 2, 1, 1, 1] - + 2*m[3, 2, 2, 1] + 2*m[3, 3, 1, 1] + m[3, 3, 2] + 3*m[4, 1, 1, 1, 1] + 2*m[4, 2, 1, 1] - + m[4, 2, 2] + m[4, 3, 1] + 6*m[1, 1, 1, 1, 1, 1, 1, 1] + 5*m[2, 1, 1, 1, 1, 1, 1] + + 4*m[2, 2, 1, 1, 1, 1] + 3*m[2, 2, 2, 1, 1] + 2*m[2, 2, 2, 2] + + 4*m[3, 1, 1, 1, 1, 1] + 3*m[3, 2, 1, 1, 1] + 2*m[3, 2, 2, 1] + + 2*m[3, 3, 1, 1] + m[3, 3, 2] + 3*m[4, 1, 1, 1, 1] + + 2*m[4, 2, 1, 1] + m[4, 2, 2] + m[4, 3, 1] One more example (:trac:`14095`):: @@ -807,7 +819,8 @@ def quantum_bruhat_successors(self, index_set=None, roots=False, quantum_only=Fa sage: w.quantum_bruhat_successors([1,3]) Traceback (most recent call last): ... - ValueError: s2*s3 is not of minimum length in its coset of the parabolic subgroup generated by the reflections (1, 3) + ValueError: s2*s3 is not of minimum length in its coset + of the parabolic subgroup generated by the reflections (1, 3) """ W = self.parent() if not W.cartan_type().is_finite(): diff --git a/src/sage/categories/with_realizations.py b/src/sage/categories/with_realizations.py index 7f59b92d72b..dd463186a2a 100644 --- a/src/sage/categories/with_realizations.py +++ b/src/sage/categories/with_realizations.py @@ -69,45 +69,46 @@ def WithRealizations(self): represented. Consider for example an algebra `A` which admits several natural bases:: - sage: A = Sets().WithRealizations().example(); A + sage: A = Sets().WithRealizations().example(); A # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field For each such basis `B` one implements a parent `P_B` which realizes `A` with its elements represented by expanding them on the basis `B`:: - sage: A.F() + sage: A.F() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis - sage: A.Out() + sage: A.Out() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the Out basis - sage: A.In() + sage: A.In() # optional - sage.combinat sage.modules The subset algebra of {1, 2, 3} over Rational Field in the In basis - sage: A.an_element() + sage: A.an_element() # optional - sage.combinat sage.modules F[{}] + 2*F[{1}] + 3*F[{2}] + F[{1, 2}] If `B` and `B'` are two bases, then the change of basis from `B` to `B'` is implemented by a canonical coercion between `P_B` and `P_{B'}`:: - sage: F = A.F(); In = A.In(); Out = A.Out() - sage: i = In.an_element(); i + sage: F = A.F(); In = A.In(); Out = A.Out() # optional - sage.combinat sage.modules + sage: i = In.an_element(); i # optional - sage.combinat sage.modules In[{}] + 2*In[{1}] + 3*In[{2}] + In[{1, 2}] - sage: F(i) + sage: F(i) # optional - sage.combinat sage.modules 7*F[{}] + 3*F[{1}] + 4*F[{2}] + F[{1, 2}] - sage: F.coerce_map_from(Out) + sage: F.coerce_map_from(Out) # optional - sage.combinat sage.modules Generic morphism: From: The subset algebra of {1, 2, 3} over Rational Field in the Out basis To: The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis allowing for mixed arithmetic:: - sage: (1 + Out.from_set(1)) * In.from_set(2,3) - Out[{}] + 2*Out[{1}] + 2*Out[{2}] + 2*Out[{3}] + 2*Out[{1, 2}] + 2*Out[{1, 3}] + 4*Out[{2, 3}] + 4*Out[{1, 2, 3}] + sage: (1 + Out.from_set(1)) * In.from_set(2,3) # optional - sage.combinat sage.modules + Out[{}] + 2*Out[{1}] + 2*Out[{2}] + 2*Out[{3}] + 2*Out[{1, 2}] + + 2*Out[{1, 3}] + 4*Out[{2, 3}] + 4*Out[{1, 2, 3}] In our example, there are three realizations:: - sage: A.realizations() + sage: A.realizations() # optional - sage.combinat sage.modules [The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis, The subset algebra of {1, 2, 3} over Rational Field in the In basis, The subset algebra of {1, 2, 3} over Rational Field in the Out basis] @@ -115,10 +116,13 @@ def WithRealizations(self): Instead of manually defining the shorthands ``F``, ``In``, and ``Out``, as above one can just do:: - sage: A.inject_shorthands() - Defining F as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis - Defining In as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the In basis - Defining Out as shorthand for The subset algebra of {1, 2, 3} over Rational Field in the Out basis + sage: A.inject_shorthands() # optional - sage.combinat sage.modules + Defining F as shorthand for + The subset algebra of {1, 2, 3} over Rational Field in the Fundamental basis + Defining In as shorthand for + The subset algebra of {1, 2, 3} over Rational Field in the In basis + Defining Out as shorthand for + The subset algebra of {1, 2, 3} over Rational Field in the Out basis .. RUBRIC:: Rationale @@ -138,26 +142,28 @@ def WithRealizations(self): We now illustrate this second point by defining the polynomial ring with coefficients in `A`:: - sage: P = A['x']; P - Univariate Polynomial Ring in x over The subset algebra of {1, 2, 3} over Rational Field - sage: x = P.gen() + sage: P = A['x']; P # optional - sage.combinat sage.modules + Univariate Polynomial Ring in x over + The subset algebra of {1, 2, 3} over Rational Field + sage: x = P.gen() # optional - sage.combinat sage.modules In the following examples, the coefficients turn out to be all represented in the `F` basis:: - sage: P.one() + sage: P.one() # optional - sage.combinat sage.modules F[{}] - sage: (P.an_element() + 1)^2 + sage: (P.an_element() + 1)^2 # optional - sage.combinat sage.modules F[{}]*x^2 + 2*F[{}]*x + F[{}] However we can create a polynomial with mixed coefficients, and compute with it:: - sage: p = P([1, In[{1}], Out[{2}] ]); p + sage: p = P([1, In[{1}], Out[{2}] ]); p # optional - sage.combinat sage.modules Out[{2}]*x^2 + In[{1}]*x + F[{}] - sage: p^2 + sage: p^2 # optional - sage.combinat sage.modules Out[{2}]*x^4 - + (-8*In[{}] + 4*In[{1}] + 8*In[{2}] + 4*In[{3}] - 4*In[{1, 2}] - 2*In[{1, 3}] - 4*In[{2, 3}] + 2*In[{1, 2, 3}])*x^3 + + (-8*In[{}] + 4*In[{1}] + 8*In[{2}] + 4*In[{3}] + - 4*In[{1, 2}] - 2*In[{1, 3}] - 4*In[{2, 3}] + 2*In[{1, 2, 3}])*x^3 + (F[{}] + 3*F[{1}] + 2*F[{2}] - 2*F[{1, 2}] - 2*F[{2, 3}] + 2*F[{1, 2, 3}])*x^2 + (2*F[{}] + 2*F[{1}])*x + F[{}] @@ -169,16 +175,21 @@ def WithRealizations(self): One can easily coerce all coefficient to a given basis with:: - sage: p.map_coefficients(In) - (-4*In[{}] + 2*In[{1}] + 4*In[{2}] + 2*In[{3}] - 2*In[{1, 2}] - In[{1, 3}] - 2*In[{2, 3}] + In[{1, 2, 3}])*x^2 + In[{1}]*x + In[{}] + sage: p.map_coefficients(In) # optional - sage.combinat sage.modules + (-4*In[{}] + 2*In[{1}] + 4*In[{2}] + 2*In[{3}] + - 2*In[{1, 2}] - In[{1, 3}] - 2*In[{2, 3}] + In[{1, 2, 3}])*x^2 + + In[{1}]*x + In[{}] Alas, the natural notation for constructing such polynomials does not yet work:: - sage: In[{1}] * x + sage: In[{1}] * x # optional - sage.combinat sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'The subset algebra of {1, 2, 3} over Rational Field in the In basis' and 'Univariate Polynomial Ring in x over The subset algebra of {1, 2, 3} over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'The subset algebra of {1, 2, 3} over Rational Field in the In basis' + and 'Univariate Polynomial Ring in x over + The subset algebra of {1, 2, 3} over Rational Field' .. RUBRIC:: The category of realizations of `A` @@ -186,17 +197,18 @@ def WithRealizations(self): is a category (whose class inherits from :class:`~sage.categories.realizations.Category_realization_of_parent`):: - sage: A.Realizations() - Category of realizations of The subset algebra of {1, 2, 3} over Rational Field + sage: A.Realizations() # optional - sage.combinat sage.modules + Category of realizations of + The subset algebra of {1, 2, 3} over Rational Field The various parent realizing `A` belong to this category:: - sage: A.F() in A.Realizations() + sage: A.F() in A.Realizations() # optional - sage.combinat sage.modules True `A` itself is in the category of algebras with realizations:: - sage: A in Algebras(QQ).WithRealizations() + sage: A in Algebras(QQ).WithRealizations() # optional - sage.combinat sage.modules True The (mostly technical) ``WithRealizations`` categories are the @@ -216,12 +228,12 @@ def WithRealizations(self): On our example, this simply means that `A` is automatically in the category of rings with realizations (covariance):: - sage: A in Rings().WithRealizations() + sage: A in Rings().WithRealizations() # optional - sage.combinat sage.modules True and in the category of algebras (regressiveness):: - sage: A in Algebras(QQ) + sage: A in Algebras(QQ) # optional - sage.combinat sage.modules True .. NOTE:: diff --git a/src/sage/combinat/cartesian_product.py b/src/sage/combinat/cartesian_product.py index b15185685c7..7ab49439557 100644 --- a/src/sage/combinat/cartesian_product.py +++ b/src/sage/combinat/cartesian_product.py @@ -51,27 +51,27 @@ class for ``cartesian_product``; sage: F1 = ['a', 'b'] sage: F2 = [1, 2, 3, 4] - sage: F3 = Permutations(3) + sage: F3 = Permutations(3) # optional - sage.combinat sage: from sage.combinat.cartesian_product import CartesianProduct_iters - sage: C = CartesianProduct_iters(F1, F2, F3) - sage: c = cartesian_product([F1, F2, F3]) + sage: C = CartesianProduct_iters(F1, F2, F3) # optional - sage.combinat + sage: c = cartesian_product([F1, F2, F3]) # optional - sage.combinat - sage: type(C.an_element()) + sage: type(C.an_element()) # optional - sage.combinat - sage: type(c.an_element()) + sage: type(c.an_element()) # optional - sage.combinat - sage: l = ['a', 1, Permutation([3,2,1])] - sage: l in C + sage: l = ['a', 1, Permutation([3,2,1])] # optional - sage.combinat + sage: l in C # optional - sage.combinat True - sage: l in c + sage: l in c # optional - sage.combinat False - sage: elt = c(l) - sage: elt + sage: elt = c(l) # optional - sage.combinat + sage: elt # optional - sage.combinat ('a', 1, [3, 2, 1]) - sage: elt in c + sage: elt in c # optional - sage.combinat True - sage: elt.parent() is c + sage: elt.parent() is c # optional - sage.combinat True """ diff --git a/src/sage/combinat/designs/block_design.py b/src/sage/combinat/designs/block_design.py index 608a06581e1..3f926aa4793 100644 --- a/src/sage/combinat/designs/block_design.py +++ b/src/sage/combinat/designs/block_design.py @@ -401,19 +401,19 @@ def q3_minus_one_matrix(K): sage: from sage.combinat.designs.block_design import q3_minus_one_matrix sage: m = q3_minus_one_matrix(GF(3)) - sage: m.multiplicative_order() == 3**3 - 1 + sage: m.multiplicative_order() == 3**3 - 1 # optional - sage.symbolic True - sage: m = q3_minus_one_matrix(GF(4,'a')) - sage: m.multiplicative_order() == 4**3 - 1 + sage: m = q3_minus_one_matrix(GF(4, 'a')) + sage: m.multiplicative_order() == 4**3 - 1 # optional - sage.symbolic True sage: m = q3_minus_one_matrix(GF(5)) - sage: m.multiplicative_order() == 5**3 - 1 + sage: m.multiplicative_order() == 5**3 - 1 # optional - sage.symbolic True - sage: m = q3_minus_one_matrix(GF(9,'a')) - sage: m.multiplicative_order() == 9**3 - 1 + sage: m = q3_minus_one_matrix(GF(9, 'a')) + sage: m.multiplicative_order() == 9**3 - 1 # optional - sage.symbolic True """ q = K.cardinality() diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index bd281fdbb77..3fb03ec7140 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -2053,9 +2053,9 @@ def order(self): EXAMPLES:: - sage: q = var('q') - sage: PA = PartitionAlgebra(2, q) - sage: PA.order() + sage: q = var('q') # optional - sage.symbolic + sage: PA = PartitionAlgebra(2, q) # optional - sage.symbolic + sage: PA.order() # optional - sage.symbolic 2 """ return self._k @@ -2412,12 +2412,13 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): :: - sage: q = var('q') - sage: PA = PartitionAlgebra(2, q); PA + sage: q = var('q') # optional - sage.symbolic + sage: PA = PartitionAlgebra(2, q); PA # optional - sage.symbolic Partition Algebra of rank 2 with parameter q over Symbolic Ring - sage: PA([[1,2],[-2,-1]])^2 == q*PA([[1,2],[-2,-1]]) + sage: PA([[1,2],[-2,-1]])^2 == q*PA([[1,2],[-2,-1]]) # optional - sage.symbolic True - sage: (PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 == (4*q-4)*PA([[1, 2], [-2, -1]]) + PA([[2, -2], [1, -1]]) + sage: ((PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 # optional - sage.symbolic + ....: == (4*q-4)*PA([[1, 2], [-2, -1]]) + PA([[2, -2], [1, -1]])) True The identity element of the partition algebra is the set @@ -2445,21 +2446,22 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): sage: PA = PartitionAlgebra(2, 5, base_ring=ZZ, prefix='B') sage: PA Partition Algebra of rank 2 with parameter 5 over Integer Ring - sage: (PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 == 16*PA([[-2, -1], [1, 2]]) + PA([[2, -2], [1, -1]]) + sage: ((PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 + ....: == 16*PA([[-2, -1], [1, 2]]) + PA([[2, -2], [1, -1]])) True Symmetric group algebra elements and elements from other subalgebras of the partition algebra (e.g., ``BrauerAlgebra`` and ``TemperleyLiebAlgebra``) can also be coerced into the partition algebra:: - sage: S = SymmetricGroupAlgebra(SR, 2) - sage: B = BrauerAlgebra(2, x, SR) - sage: A = PartitionAlgebra(2, x, SR) - sage: S([2,1])*A([[1,-1],[2,-2]]) + sage: S = SymmetricGroupAlgebra(SR, 2) # optional - sage.symbolic + sage: B = BrauerAlgebra(2, x, SR) # optional - sage.symbolic + sage: A = PartitionAlgebra(2, x, SR) # optional - sage.symbolic + sage: S([2,1]) * A([[1,-1],[2,-2]]) # optional - sage.symbolic P{{-2, 1}, {-1, 2}} - sage: B([[-1,-2],[2,1]]) * A([[1],[-1],[2,-2]]) + sage: B([[-1,-2],[2,1]]) * A([[1],[-1],[2,-2]]) # optional - sage.symbolic P{{-2}, {-1}, {1, 2}} - sage: A([[1],[-1],[2,-2]]) * B([[-1,-2],[2,1]]) + sage: A([[1],[-1],[2,-2]]) * B([[-1,-2],[2,1]]) # optional - sage.symbolic P{{-2, -1}, {1}, {2}} The same is true if the elements come from a subalgebra of a partition @@ -2470,7 +2472,7 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): sage: S = SymmetricGroupAlgebra(ZZ, 2) sage: B = BrauerAlgebra(2, q, ZZ[q]) sage: A = PartitionAlgebra(3, q, R) - sage: S([2,1])*A([[1,-1],[2,-3],[3,-2]]) + sage: S([2,1]) * A([[1,-1],[2,-3],[3,-2]]) P{{-3, 1}, {-2, 3}, {-1, 2}} sage: A(B([[-1,-2],[2,1]])) P{{-3, 3}, {-2, -1}, {1, 2}} diff --git a/src/sage/combinat/finite_state_machine_generators.py b/src/sage/combinat/finite_state_machine_generators.py index ed5cca2588b..545596db163 100644 --- a/src/sage/combinat/finite_state_machine_generators.py +++ b/src/sage/combinat/finite_state_machine_generators.py @@ -1079,15 +1079,15 @@ def _parse_recursion_equation_(self, equation, base, function, var, EXAMPLES:: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: transducers._parse_recursion_equation_( + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic ....: f(8*n + 7) == f(2*n + 3) + 5, ....: 2, f, n) RecursionRule(K=3, r=7, k=1, s=3, t=[5]) - sage: transducers._parse_recursion_equation_( + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic ....: f(42) == 5, ....: 2, f, n) {42: [5]} @@ -1096,14 +1096,14 @@ def _parse_recursion_equation_(self, equation, base, function, var, The following tests check that the equations are well-formed:: - sage: transducers._parse_recursion_equation_(f(4*n + 1), 2, f, n) + sage: transducers._parse_recursion_equation_(f(4*n + 1), 2, f, n) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: f(4*n + 1) is not an equation with ==. :: - sage: transducers._parse_recursion_equation_(f(n) + 1 == f(2*n), + sage: transducers._parse_recursion_equation_(f(n) + 1 == f(2*n), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1111,7 +1111,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n, 5) == 3, + sage: transducers._parse_recursion_equation_(f(2*n, 5) == 3, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1119,7 +1119,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(1/n) == f(n) + 3, + sage: transducers._parse_recursion_equation_(f(1/n) == f(n) + 3, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1127,7 +1127,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(n^2 + 5) == 3, + sage: transducers._parse_recursion_equation_(f(n^2 + 5) == 3, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1135,7 +1135,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(3*n + 5) == f(n) + 7, + sage: transducers._parse_recursion_equation_(f(3*n + 5) == f(n) + 7, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1143,7 +1143,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(n + 5) == f(n) + 7, + sage: transducers._parse_recursion_equation_(f(n + 5) == f(n) + 7, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1151,7 +1151,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_( + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic ....: f(2*n + 1) == f(n + 1) + f(n) + 2, ....: 2, f, n) Traceback (most recent call last): @@ -1161,7 +1161,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n) + 2, + sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n) + 2, # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1170,7 +1170,8 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n) + n + 2, + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + ....: f(2*n + 1) == f(n) + n + 2, ....: 2, f, n) Traceback (most recent call last): ... @@ -1178,7 +1179,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1186,7 +1187,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n, 2), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n, 2), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1194,7 +1195,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(1/n), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(1/n), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1202,7 +1203,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n^2 + 5), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n^2 + 5), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1210,7 +1211,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(3*n + 5), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(3*n + 5), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1218,7 +1219,8 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f((1/2)*n + 5), + sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + ....: f(2*n + 1) == f((1/2)*n + 5), ....: QQ(2), f, n) Traceback (most recent call last): ... @@ -1226,7 +1228,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(2*n + 5), + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(2*n + 5), # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1432,17 +1434,17 @@ def Recursion(self, recursions, base, function=None, var=None, - The following example computes the Hamming weight of the ternary expansion of integers. :: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(3*n + 1) == f(n) + 1, ....: f(3*n + 2) == f(n) + 1, ....: f(3*n) == f(n), ....: f(0) == 0], ....: 3, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (0, 0): 1|1, Transition from (0, 0) to (0, 0): 2|1] @@ -1450,13 +1452,13 @@ def Recursion(self, recursions, base, function=None, var=None, To illustrate what this transducer does, we consider the example of `n=601`:: - sage: ternary_expansion = 601.digits(base=3) - sage: ternary_expansion + sage: ternary_expansion = 601.digits(base=3) # optional - sage.symbolic + sage: ternary_expansion # optional - sage.symbolic [1, 2, 0, 1, 1, 2] - sage: weight_sequence = T(ternary_expansion) - sage: weight_sequence + sage: weight_sequence = T(ternary_expansion) # optional - sage.symbolic + sage: weight_sequence # optional - sage.symbolic [1, 1, 1, 1, 1] - sage: sum(weight_sequence) + sage: sum(weight_sequence) # optional - sage.symbolic 5 Note that the digit zero does not show up in the output because @@ -1466,24 +1468,24 @@ def Recursion(self, recursions, base, function=None, var=None, - The following example computes the Hamming weight of the non-adjacent form, cf. the :wikipedia:`Non-adjacent_form`. :: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(4*n + 1) == f(n) + 1, ....: f(4*n - 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 0], ....: 2, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (0, 0): 0|1, Transition from (1, 1) to (1, 0): 1|1, Transition from (1, 0) to (1, 1): 0|-, Transition from (1, 0) to (1, 0): 1|-] - sage: [(s.label(), s.final_word_out) + sage: [(s.label(), s.final_word_out) # optional - sage.symbolic ....: for s in T.iter_final_states()] [((0, 0), []), ((1, 1), [1]), @@ -1533,11 +1535,11 @@ def Recursion(self, recursions, base, function=None, var=None, the point of view of this method---is a contradicting recursion. We override this by the parameter ``is_zero``. :: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f w') + sage: function('f w') # optional - sage.symbolic (f, w) - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n) == f(n) + w(0), ....: f(4*n + 1) == f(n) + w(1, 0), ....: f(4*n - 1) == f(n) + w(-1, 0), @@ -1545,14 +1547,14 @@ def Recursion(self, recursions, base, function=None, var=None, ....: 2, f, n, ....: word_function=w, ....: is_zero=lambda x: sum(x).is_zero()) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|0, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (0, 0): 0|1,0, Transition from (1, 1) to (1, 0): 1|-1,0, Transition from (1, 0) to (1, 1): 0|-, Transition from (1, 0) to (1, 0): 1|0] - sage: for s in T.iter_states(): + sage: for s in T.iter_states(): # optional - sage.symbolic ....: print("{} {}".format(s, s.final_word_out)) (0, 0) [] (1, 1) [1, 0] @@ -1580,16 +1582,16 @@ def Recursion(self, recursions, base, function=None, var=None, - Here is an artificial example where some of the `s` are negative:: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n-1) + 1, ....: f(2*n) == f(n), ....: f(1) == 1, ....: f(0) == 0], 2, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (-1, 1): 0|1, @@ -1600,7 +1602,7 @@ def Recursion(self, recursions, base, function=None, var=None, Transition from (-1, 2) to (0, 0): 1|1, Transition from (1, 2) to (-1, 2): 0|1, Transition from (1, 2) to (1, 2): 1|1] - sage: [(s.label(), s.final_word_out) + sage: [(s.label(), s.final_word_out) # optional - sage.symbolic ....: for s in T.iter_final_states()] [((0, 0), []), ((1, 1), [1]), @@ -1611,7 +1613,7 @@ def Recursion(self, recursions, base, function=None, var=None, - Abelian complexity of the paperfolding sequence (cf. [HKP2015]_, Example 2.8):: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(4*n) == f(2*n), ....: f(4*n+2) == f(2*n+1)+1, ....: f(16*n+1) == f(8*n+1), @@ -1621,7 +1623,7 @@ def Recursion(self, recursions, base, function=None, var=None, ....: f(1) == 2, f(0) == 0] ....: + [f(16*n+jj) == f(2*n+1)+2 for jj in [3,7,9,13]], ....: 2, f, n) - sage: T.transitions() + sage: T.transitions() # optional - sage.symbolic [Transition from (0, 0) to (0, 1): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (0, 1) to (0, 1): 0|-, @@ -1642,7 +1644,7 @@ def Recursion(self, recursions, base, function=None, var=None, Transition from (7, 3) to (2, 1): 1|1, Transition from (2, 1) to (1, 1): 0|1, Transition from (2, 1) to (2, 1): 1|-] - sage: for s in T.iter_states(): + sage: for s in T.iter_states(): # optional - sage.symbolic ....: print("{} {}".format(s, s.final_word_out)) (0, 0) [] (0, 1) [] @@ -1654,52 +1656,52 @@ def Recursion(self, recursions, base, function=None, var=None, (3, 3) [2, 2] (7, 3) [2, 2] (2, 1) [1, 2] - sage: list(sum(T(n.bits())) for n in srange(1, 21)) + sage: list(sum(T(n.bits())) for n in srange(1, 21)) # optional - sage.symbolic [2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 4, 5, 6, 5] - We now demonstrate the use of the ``output_rings`` parameter. If no ``output_rings`` are specified, the output labels are converted into ``ZZ``:: - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 2], ....: 2, f, n) - sage: for t in T.transitions(): + sage: for t in T.transitions(): # optional - sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Integer Ring] - sage: [x.parent() for x in T.states()[0].final_word_out] + sage: [x.parent() for x in T.states()[0].final_word_out] # optional - sage.symbolic [Integer Ring] In contrast, if ``output_rings`` is set to the empty list, the results are not converted:: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 2], ....: 2, f, n, output_rings=[]) - sage: for t in T.transitions(): + sage: for t in T.transitions(): # optional - sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Symbolic Ring] - sage: [x.parent() for x in T.states()[0].final_word_out] + sage: [x.parent() for x in T.states()[0].final_word_out] # optional - sage.symbolic [Symbolic Ring] Finally, we use a somewhat questionable conversion:: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.rings.finite_rings sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 0], ....: 2, f, n, output_rings=[GF(5)]) - sage: for t in T.transitions(): + sage: for t in T.transitions(): # optional - sage.rings.finite_rings sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Finite Field of size 5] @@ -1726,11 +1728,11 @@ def Recursion(self, recursions, base, function=None, var=None, The following tests fail due to missing or superfluous recursions or initial conditions. :: - sage: var('n') + sage: var('n') # optional - sage.symbolic n - sage: function('f') + sage: function('f') # optional - sage.symbolic f - sage: transducers.Recursion([f(2*n) == f(n)], + sage: transducers.Recursion([f(2*n) == f(n)], # optional - sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1739,9 +1741,9 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n), + sage: transducers.Recursion([f(2*n + 1) == f(n), # optional - sage.symbolic ....: f(4*n) == f(2*n) + 1, - ....: f(2*n) == f(n) +1], + ....: f(2*n) == f(n) + 1], ....: 2, f, n) Traceback (most recent call last): ... @@ -1749,7 +1751,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, + sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # optional - sage.symbolic ....: f(2*n) == f(n), ....: f(0) == 0, ....: f(42) == 42], 2, f, n) @@ -1759,7 +1761,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, + sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # optional - sage.symbolic ....: f(2*n) == f(n - 2) + 4, ....: f(0) == 0], 2, f, n) Traceback (most recent call last): @@ -1769,7 +1771,7 @@ def Recursion(self, recursions, base, function=None, var=None, Here is an example of a transducer with a conflicting rule (it cannot hold for `n = 0`):: - sage: T = transducers.Recursion([ + sage: T = transducers.Recursion([ # optional - sage.symbolic ....: f(2*n + 1) == f(n - 1), ....: f(2*n) == f(n) + 1, ....: f(1) == 1, diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py index 746b0079b9e..4c2a913c44d 100644 --- a/src/sage/combinat/free_module.py +++ b/src/sage/combinat/free_module.py @@ -151,7 +151,7 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): The constructed module is in the category of modules with basis over the base ring:: - sage: CombinatorialFreeModule(QQ, Partitions()).category() + sage: CombinatorialFreeModule(QQ, Partitions()).category() # optional - sage.combinat Category of vector spaces with basis over Rational Field If furthermore the index set is finite (i.e. in the category @@ -160,7 +160,7 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): sage: CombinatorialFreeModule(QQ, [1,2,3,4]).category() Category of finite dimensional vector spaces with basis over Rational Field - sage: CombinatorialFreeModule(QQ, Partitions(3), + sage: CombinatorialFreeModule(QQ, Partitions(3), # optional - sage.combinat ....: category=Algebras(QQ).WithBasis()).category() Category of finite dimensional algebras with basis over Rational Field @@ -252,8 +252,8 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): TESTS:: - sage: XQ = SchubertPolynomialRing(QQ) - sage: XZ = SchubertPolynomialRing(ZZ) + sage: XQ = SchubertPolynomialRing(QQ) # optional - sage.combinat + sage: XZ = SchubertPolynomialRing(ZZ) # optional - sage.combinat sage: XQ == XZ False sage: XQ == XQ @@ -288,16 +288,16 @@ def __classcall_private__(cls, base_ring, basis_keys=None, category=None, We check that the category is properly straightened:: sage: F = CombinatorialFreeModule(QQ, ['a','b']) - sage: F1 = CombinatorialFreeModule(QQ, ['a','b'], category = ModulesWithBasis(QQ)) - sage: F2 = CombinatorialFreeModule(QQ, ['a','b'], category = [ModulesWithBasis(QQ)]) - sage: F3 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),)) - sage: F4 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),CommutativeAdditiveSemigroups())) - sage: F5 = CombinatorialFreeModule(QQ, ['a','b'], category = (ModulesWithBasis(QQ),Category.join((LeftModules(QQ), RightModules(QQ))))) + sage: F1 = CombinatorialFreeModule(QQ, ['a','b'], category=ModulesWithBasis(QQ)) + sage: F2 = CombinatorialFreeModule(QQ, ['a','b'], category=[ModulesWithBasis(QQ)]) + sage: F3 = CombinatorialFreeModule(QQ, ['a','b'], category=(ModulesWithBasis(QQ),)) + sage: F4 = CombinatorialFreeModule(QQ, ['a','b'], category=(ModulesWithBasis(QQ),CommutativeAdditiveSemigroups())) + sage: F5 = CombinatorialFreeModule(QQ, ['a','b'], category=(ModulesWithBasis(QQ),Category.join((LeftModules(QQ), RightModules(QQ))))) sage: F6 = CombinatorialFreeModule(QQ, ['a','b'], category=ModulesWithBasis(QQ).FiniteDimensional()) sage: F1 is F, F2 is F, F3 is F, F4 is F, F5 is F, F6 is F (True, True, True, True, True, True) - sage: G = CombinatorialFreeModule(QQ, ['a','b'], category = AlgebrasWithBasis(QQ)) + sage: G = CombinatorialFreeModule(QQ, ['a','b'], category=AlgebrasWithBasis(QQ)) sage: F is G False """ @@ -347,21 +347,21 @@ def element_class(self): EXAMPLES:: - sage: A = Algebras(QQ).WithBasis().example(); A + sage: A = Algebras(QQ).WithBasis().example(); A # optional - sage.combinat An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - sage: A.element_class.mro() + sage: A.element_class.mro() # optional - sage.combinat [, , ...] - sage: a,b,c = A.algebra_generators() - sage: a * b + sage: a,b,c = A.algebra_generators() # optional - sage.combinat + sage: a * b # optional - sage.combinat B[word: ab] TESTS:: - sage: A.__class__.element_class.__module__ + sage: A.__class__.element_class.__module__ # optional - sage.combinat 'sage.combinat.free_module' """ return self.__make_element_class__(self.Element, @@ -385,12 +385,13 @@ def __init__(self, R, basis_keys=None, element_class=None, category=None, sage: F.category() Category of finite dimensional algebras with basis over Rational Field - sage: F = CombinatorialFreeModule(GF(3), ['a','b','c'], - ....: category=(Modules(GF(3)).WithBasis(), Semigroups())) - sage: F.category() - Join of Category of finite semigroups and Category of finite dimensional vector spaces with basis over Finite Field of size 3 + sage: F = CombinatorialFreeModule(GF(3), ['a','b','c'], # optional - sage.rings.finite_rings + ....: category=(Modules(GF(3)).WithBasis(), Semigroups())) + sage: F.category() # optional - sage.rings.finite_rings + Join of Category of finite semigroups + and Category of finite dimensional vector spaces with basis over Finite Field of size 3 - sage: F = CombinatorialFreeModule(QQ, ['a','b','c'], category = FiniteDimensionalModulesWithBasis(QQ)) + sage: F = CombinatorialFreeModule(QQ, ['a','b','c'], category=FiniteDimensionalModulesWithBasis(QQ)) sage: F.basis() Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']} sage: F.category() @@ -518,8 +519,8 @@ def _ascii_art_term(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: ascii_art(R.one()) # indirect doctest + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: ascii_art(R.one()) # indirect doctest # optional - sage.combinat 1 """ try: @@ -535,8 +536,8 @@ def _unicode_art_term(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: unicode_art(R.one()) # indirect doctest + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: unicode_art(R.one()) # indirect doctest # optional - sage.combinat 1 """ try: @@ -620,26 +621,26 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ,["a", "b"]) + sage: F = CombinatorialFreeModule(QQ, ["a", "b"]) sage: F(F.monomial("a")) # indirect doctest B['a'] Do not rely on the following feature which may be removed in the future:: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: QS3([2,3,1]) # indirect doctest + sage: QS3 = SymmetricGroupAlgebra(QQ,3) # optional - sage.combinat + sage: QS3([2,3,1]) # indirect doctest # optional - sage.combinat [2, 3, 1] instead, use:: - sage: P = QS3.basis().keys() - sage: QS3.monomial(P([2,3,1])) # indirect doctest + sage: P = QS3.basis().keys() # optional - sage.combinat + sage: QS3.monomial(P([2,3,1])) # indirect doctest # optional - sage.combinat [2, 3, 1] or:: - sage: B = QS3.basis() - sage: B[P([2,3,1])] + sage: B = QS3.basis() # optional - sage.combinat + sage: B[P([2,3,1])] # optional - sage.combinat [2, 3, 1] TODO: The symmetric group algebra (and in general, @@ -691,17 +692,17 @@ def _element_constructor_(self, x): Here is a real life example illustrating that this yielded mathematically wrong results:: - sage: S = SymmetricFunctions(QQ) - sage: s = S.s(); p = S.p() - sage: ss = tensor([s,s]); pp = tensor([p,p]) - sage: a = tensor((s[2],s[2])) + sage: S = SymmetricFunctions(QQ) # optional - sage.combinat + sage: s = S.s(); p = S.p() # optional - sage.combinat + sage: ss = tensor([s,s]); pp = tensor([p,p]) # optional - sage.combinat + sage: a = tensor((s[2],s[2])) # optional - sage.combinat The following originally used to yield ``p[[2]] # p[[2]]``, and if there was no natural coercion between ``s`` and ``p``, this would raise a ``NotImplementedError``. Since :trac:`15305`, this takes the coercion between ``s`` and ``p`` and lifts it to the tensor product. :: - sage: pp(a) + sage: pp(a) # optional - sage.combinat 1/4*p[1, 1] # p[1, 1] + 1/4*p[1, 1] # p[2] + 1/4*p[2] # p[1, 1] + 1/4*p[2] # p[2] General extensions of the ground ring should probably be reintroduced @@ -715,8 +716,8 @@ def _element_constructor_(self, x): Conversion from the ground ring is implemented for algebras:: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: QS3(2) + sage: QS3 = SymmetricGroupAlgebra(QQ,3) # optional - sage.combinat + sage: QS3(2) # optional - sage.combinat 2*[1, 2, 3] """ R = self.base_ring() @@ -797,8 +798,8 @@ def _first_ngens(self, n): sage: C._first_ngens(3) (B[0], B[1], B[-1]) - sage: R. = FreeAlgebra(QQ, 2) - sage: x,y + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: x,y # optional - sage.combinat (x, y) """ try: @@ -834,13 +835,13 @@ def _coerce_map_from_(self, R): sage: C.has_coerce_map_from(CQ) False - sage: CF2 = CombinatorialFreeModule(GF(2), Set([1,2])) - sage: CF2.has_coerce_map_from(C) + sage: CF2 = CombinatorialFreeModule(GF(2), Set([1,2])) # optional - sage.rings.finite_rings + sage: CF2.has_coerce_map_from(C) # optional - sage.rings.finite_rings True - sage: c = C.monomial(1) - sage: CF2(2*c) + sage: c = C.monomial(1) # optional - sage.rings.finite_rings + sage: CF2(2*c) # optional - sage.rings.finite_rings 0 - sage: CF2(3*c) + sage: CF2(3*c) # optional - sage.rings.finite_rings B[1] """ if isinstance(R, CombinatorialFreeModule): @@ -876,8 +877,8 @@ def dimension(self): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s.dimension() + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s.dimension() # optional - sage.combinat +Infinity """ return self._indices.cardinality() @@ -892,11 +893,11 @@ def is_exact(self): EXAMPLES:: - sage: GroupAlgebra(GL(3, GF(7))).is_exact() + sage: GroupAlgebra(GL(3, GF(7))).is_exact() # optional - sage.groups sage.rings.finite_rings True - sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() + sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() # optional - sage.groups sage.rings.finite_rings False - sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented correctly (not my fault)! + sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented correctly (not my fault)! # optional - sage.groups sage.rings.padics False """ # The index set may not have a check for exactness @@ -926,11 +927,11 @@ def set_order(self, order): EXAMPLES:: - sage: QS2 = SymmetricGroupAlgebra(QQ,2) - sage: b = list(QS2.basis().keys()) - sage: b.reverse() - sage: QS2.set_order(b) - sage: QS2.get_order() + sage: QS2 = SymmetricGroupAlgebra(QQ,2) # optional - sage.combinat + sage: b = list(QS2.basis().keys()) # optional - sage.combinat + sage: b.reverse() # optional - sage.combinat + sage: QS2.set_order(b) # optional - sage.combinat + sage: QS2.get_order() # optional - sage.combinat [[2, 1], [1, 2]] """ self._order = order @@ -944,8 +945,8 @@ def get_order(self): EXAMPLES:: - sage: QS2 = SymmetricGroupAlgebra(QQ,2) - sage: QS2.get_order() # note: order changed on 2009-03-13 + sage: QS2 = SymmetricGroupAlgebra(QQ,2) # optional - sage.combinat + sage: QS2.get_order() # note: order changed on 2009-03-13 # optional - sage.combinat [[2, 1], [1, 2]] """ if self._order is None: @@ -1001,11 +1002,11 @@ def from_vector(self, vector, order=None, coerce=True): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) - sage: b = QS3.from_vector(vector((2, 0, 0, 0, 0, 4))); b + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat + sage: b = QS3.from_vector(vector((2, 0, 0, 0, 0, 4))); b # optional - sage.combinat 2*[1, 2, 3] + 4*[3, 2, 1] - sage: a = 2*QS3([1,2,3])+4*QS3([3,2,1]) - sage: a == b + sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) # optional - sage.combinat + sage: a == b # optional - sage.combinat True """ if order is None: @@ -1057,7 +1058,7 @@ def linear_combination(self, iter_of_elements_coeff, factor_on_left=True): EXAMPLES:: - sage: F = CombinatorialFreeModule(QQ,[1,2]) + sage: F = CombinatorialFreeModule(QQ, [1,2]) sage: f = F.an_element(); f 2*B[1] + 2*B[2] sage: F.linear_combination( (f,i) for i in range(5) ) @@ -1132,8 +1133,8 @@ def _sum_of_monomials(self, indices): sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) sage: F._sum_of_monomials(['a', 'b', 'b']) B['a'] + 2*B['b'] - sage: F = CombinatorialFreeModule(GF(3), ['a', 'b', 'c']) - sage: F._sum_of_monomials(['a', 'b', 'b', 'b']) + sage: F = CombinatorialFreeModule(GF(3), ['a', 'b', 'c']) # optional - sage.rings.finite_rings + sage: F._sum_of_monomials(['a', 'b', 'b', 'b']) # optional - sage.rings.finite_rings B['a'] """ R = self.base_ring() @@ -1208,26 +1209,26 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).elementary() - sage: s = SymmetricFunctions(QQ).schur() - sage: a = e([2,1]) + e([1,1,1]); a + sage: e = SymmetricFunctions(QQ).elementary() # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = e([2,1]) + e([1,1,1]); a # optional - sage.combinat e[1, 1, 1] + e[2, 1] - sage: s._from_dict(a.monomial_coefficients()) + sage: s._from_dict(a.monomial_coefficients()) # optional - sage.combinat s[1, 1, 1] + s[2, 1] If the optional argument ``coerce`` is ``True``, then the coefficients are coerced into the base ring of ``self``:: - sage: part = Partition([2,1]) - sage: d = {part:1} - sage: a = s._from_dict(d,coerce=True); a + sage: part = Partition([2,1]) # optional - sage.combinat + sage: d = {part: 1} # optional - sage.combinat + sage: a = s._from_dict(d, coerce=True); a # optional - sage.combinat s[2, 1] - sage: a.coefficient(part).parent() + sage: a.coefficient(part).parent() # optional - sage.combinat Rational Field With ``remove_zeros=True``, zero coefficients are removed:: - sage: s._from_dict({part:0}) + sage: s._from_dict({part: 0}) # optional - sage.combinat 0 .. WARNING:: @@ -1236,7 +1237,7 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): coefficient of the dictionary is zero. Otherwise, this may lead to illegal results:: - sage: list(s._from_dict({part:0}, remove_zeros=False)) + sage: list(s._from_dict({part: 0}, remove_zeros=False)) # optional - sage.combinat [([2, 1], 0)] """ assert isinstance(d, dict) @@ -1262,7 +1263,8 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): F # G sage: T.category() - Category of tensor products of finite dimensional modules with basis over Integer Ring + Category of tensor products of + finite dimensional modules with basis over Integer Ring sage: T.construction() # todo: not implemented [tensor, ] @@ -1275,7 +1277,8 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): The basis of T is indexed by tuples of basis indices of F and G:: sage: T.basis().keys() - Image of Cartesian product of {1, 2}, {3, 4} by The map from Cartesian product of {1, 2}, {3, 4} + Image of Cartesian product of {1, 2}, {3, 4} + by The map from Cartesian product of {1, 2}, {3, 4} sage: T.basis().keys().list() [(1, 3), (1, 4), (2, 3), (2, 4)] @@ -1424,9 +1427,9 @@ def _ascii_art_(self, term): """ TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: Partitions.options(diagram_str="#", convention="french") - sage: s = ascii_art(tensor((R[1,2], R[3,1,2]))); s + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat + sage: s = ascii_art(tensor((R[1,2], R[3,1,2]))); s # optional - sage.combinat R # R # ### ## # @@ -1434,7 +1437,7 @@ def _ascii_art_(self, term): Check that the breakpoints are correct (:trac:`29202`):: - sage: s._breakpoints + sage: s._breakpoints # optional - sage.combinat [6] """ if hasattr(self, "_print_options"): @@ -1453,9 +1456,9 @@ def _unicode_art_(self, term): """ TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() - sage: Partitions.options(diagram_str="#", convention="french") - sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat + sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat + sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s # optional - sage.combinat R ⊗ R ┌┐ ┌┬┬┐ ├┼┐ └┴┼┤ @@ -1464,7 +1467,7 @@ def _unicode_art_(self, term): Check that the breakpoints are correct (:trac:`29202`):: - sage: s._breakpoints + sage: s._breakpoints # optional - sage.combinat [7] """ if hasattr(self, "_print_options"): @@ -1548,22 +1551,26 @@ def tensor_constructor(self, modules): sage: G = CombinatorialFreeModule(ZZ, [3,4]); G.rename("G") sage: H = CombinatorialFreeModule(ZZ, [5,6]); H.rename("H") - sage: f = F.monomial(1) + 2 * F.monomial(2) - sage: g = 2*G.monomial(3) + G.monomial(4) - sage: h = H.monomial(5) + H.monomial(6) - sage: FG = tensor([F, G ]) + sage: f = F.monomial(1) + 2*F.monomial(2) + sage: g = 2*G.monomial(3) + G.monomial(4) + sage: h = H.monomial(5) + H.monomial(6) + sage: FG = tensor([F, G]) sage: phi_fg = FG.tensor_constructor((F, G)) - sage: phi_fg(f,g) + sage: phi_fg(f, g) 2*B[1] # B[3] + B[1] # B[4] + 4*B[2] # B[3] + 2*B[2] # B[4] sage: FGH = tensor([F, G, H]) sage: phi_fgh = FGH.tensor_constructor((F, G, H)) sage: phi_fgh(f, g, h) - 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] + 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] sage: phi_fg_h = FGH.tensor_constructor((FG, H)) sage: phi_fg_h(phi_fg(f, g), h) - 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] + 2*B[1] # B[3] # B[5] + 2*B[1] # B[3] # B[6] + B[1] # B[4] # B[5] + + B[1] # B[4] # B[6] + 4*B[2] # B[3] # B[5] + 4*B[2] # B[3] # B[6] + + 2*B[2] # B[4] # B[5] + 2*B[2] # B[4] # B[6] """ assert(module in ModulesWithBasis(self.base_ring()) for module in modules) assert(tensor(modules) == self) @@ -1727,7 +1734,9 @@ class CombinatorialFreeModule_CartesianProduct(CombinatorialFreeModule): sage: S F (+) G sage: S.basis() - Lazy family (Term map from Disjoint union of Family ({4, 5}, {4, 6}) to F (+) G(i))_{i in Disjoint union of Family ({4, 5}, {4, 6})} + Lazy family (Term map + from Disjoint union of Family ({4, 5}, {4, 6}) + to F (+) G(i))_{i in Disjoint union of Family ({4, 5}, {4, 6})} Note that the indices of the basis elements of F and G intersect non trivially. This is handled by forcing the union to be disjoint:: @@ -1737,19 +1746,19 @@ class CombinatorialFreeModule_CartesianProduct(CombinatorialFreeModule): We now compute the Cartesian product of elements of free modules:: - sage: f = F.monomial(4) + 2 * F.monomial(5) - sage: g = 2*G.monomial(4) + G.monomial(6) - sage: h = H.monomial(4) + H.monomial(7) - sage: cartesian_product([f,g]) + sage: f = F.monomial(4) + 2*F.monomial(5) + sage: g = 2*G.monomial(4) + G.monomial(6) + sage: h = H.monomial(4) + H.monomial(7) + sage: cartesian_product([f, g]) B[(0, 4)] + 2*B[(0, 5)] + 2*B[(1, 4)] + B[(1, 6)] - sage: cartesian_product([f,g,h]) + sage: cartesian_product([f, g, h]) B[(0, 4)] + 2*B[(0, 5)] + 2*B[(1, 4)] + B[(1, 6)] + B[(2, 4)] + B[(2, 7)] - sage: cartesian_product([f,g,h]).parent() + sage: cartesian_product([f, g, h]).parent() F (+) G (+) H TODO: choose an appropriate semantic for Cartesian products of Cartesian products (associativity?):: - sage: S = cartesian_product([cartesian_product([F, G]), H]) # todo: not implemented + sage: S = cartesian_product([cartesian_product([F, G]), H]) # todo: not implemented F (+) G (+) H """ @@ -1881,8 +1890,8 @@ def _cartesian_product_of_elements(self, elements): sage: F = CombinatorialFreeModule(ZZ, [4,5]); F.rename("F") sage: G = CombinatorialFreeModule(ZZ, [4,6]); G.rename("G") sage: S = cartesian_product([F, G]) - sage: f = F.monomial(4) + 2 * F.monomial(5) - sage: g = 2*G.monomial(4) + G.monomial(6) + sage: f = F.monomial(4) + 2*F.monomial(5) + sage: g = 2*G.monomial(4) + G.monomial(6) sage: S._cartesian_product_of_elements([f, g]) B[(0, 4)] + 2*B[(0, 5)] + 2*B[(1, 4)] + B[(1, 6)] sage: S._cartesian_product_of_elements([f, g]).parent() == S diff --git a/src/sage/combinat/integer_vector.py b/src/sage/combinat/integer_vector.py index 9f01bfd787d..503f802847a 100644 --- a/src/sage/combinat/integer_vector.py +++ b/src/sage/combinat/integer_vector.py @@ -92,11 +92,11 @@ def is_gale_ryser(r,s): EXAMPLES:: sage: from sage.combinat.integer_vector import is_gale_ryser - sage: is_gale_ryser([4,2,2],[3,3,1,1]) + sage: is_gale_ryser([4,2,2], [3,3,1,1]) # optional - sage.combinat True - sage: is_gale_ryser([4,2,1,1],[3,3,1,1]) + sage: is_gale_ryser([4,2,1,1], [3,3,1,1]) # optional - sage.combinat True - sage: is_gale_ryser([3,2,1,1],[3,3,1,1]) + sage: is_gale_ryser([3,2,1,1], [3,3,1,1]) # optional - sage.combinat False REMARK: In the literature, what we are calling a @@ -207,14 +207,14 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", sage: from sage.combinat.integer_vector import gale_ryser_theorem sage: p1 = [2,2,1] sage: p2 = [2,2,1] - sage: print(gale_ryser_theorem(p1, p2)) # not tested + sage: print(gale_ryser_theorem(p1, p2)) # not tested # optional - sage.combinat [1 1 0] [1 0 1] [0 1 0] - sage: A = gale_ryser_theorem(p1, p2) - sage: rs = [sum(x) for x in A.rows()] - sage: cs = [sum(x) for x in A.columns()] - sage: p1 == rs; p2 == cs + sage: A = gale_ryser_theorem(p1, p2) # optional - sage.combinat + sage: rs = [sum(x) for x in A.rows()] # optional - sage.combinat + sage: cs = [sum(x) for x in A.columns()] # optional - sage.combinat + sage: p1 == rs; p2 == cs # optional - sage.combinat True True @@ -224,27 +224,27 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", sage: from sage.combinat.integer_vector import gale_ryser_theorem sage: p1 = [3,3,1,1] sage: p2 = [3,3,1,1] - sage: gale_ryser_theorem(p1, p2, algorithm = "ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 0] [1 1 0 1] [1 0 0 0] [0 1 0 0] sage: p1 = [4,2,2] sage: p2 = [3,3,1,1] - sage: gale_ryser_theorem(p1, p2, algorithm = "ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 1] [1 1 0 0] [1 1 0 0] sage: p1 = [4,2,2,0] sage: p2 = [3,3,1,1,0,0] - sage: gale_ryser_theorem(p1, p2, algorithm = "ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 1 0 0] [1 1 0 0 0 0] [1 1 0 0 0 0] [0 0 0 0 0 0] sage: p1 = [3,3,2,1] sage: p2 = [3,2,2,1,1] - sage: print(gale_ryser_theorem(p1, p2, algorithm="gale")) # not tested + sage: print(gale_ryser_theorem(p1, p2, algorithm="gale")) # not tested # optional - sage.combinat [1 1 1 0 0] [1 1 0 0 1] [1 0 1 0 0] @@ -253,7 +253,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", With `0` in the sequences, and with unordered inputs:: sage: from sage.combinat.integer_vector import gale_ryser_theorem - sage: gale_ryser_theorem([3,3,0,1,1,0], [3,1,3,1,0], algorithm="ryser") + sage: gale_ryser_theorem([3,3,0,1,1,0], [3,1,3,1,0], algorithm="ryser") # optional - sage.combinat [1 1 1 0 0] [1 0 1 1 0] [0 0 0 0 0] @@ -261,7 +261,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", [0 0 1 0 0] [0 0 0 0 0] sage: p1 = [3,1,1,1,1]; p2 = [3,2,2,0] - sage: gale_ryser_theorem(p1, p2, algorithm="ryser") + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat [1 1 1 0] [1 0 0 0] [1 0 0 0] @@ -288,17 +288,17 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", ....: print("Algorithm %s failed with this input:" % algorithm) ....: print(s1, s2) - sage: for algorithm in ["gale", "ryser"]: # long time + sage: for algorithm in ["gale", "ryser"]: # long time # optional - sage.combinat ....: for i in range(50): ....: test_algorithm(algorithm, 3, 10) Null matrix:: - sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="gale") + sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="gale") # optional - sage.combinat [0 0 0 0] [0 0 0 0] [0 0 0 0] - sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="ryser") + sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="ryser") # optional - sage.combinat [0 0 0 0] [0 0 0 0] [0 0 0 0] @@ -595,7 +595,7 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): Note that trailing zeros are ignored so that ``[3, 0]`` does not show up in the following list (since ``[3]`` does):: - sage: IntegerVectors(3, max_length=2).list() + sage: IntegerVectors(3, max_length=2).list() # optional - sage.combinat [[3], [2, 1], [1, 2], [0, 3]] If ``n`` and ``k`` are both specified, then it returns the class @@ -614,9 +614,9 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): Further examples:: - sage: IntegerVectors(-1, 0, min_part = 1).list() + sage: IntegerVectors(-1, 0, min_part=1).list() [] - sage: IntegerVectors(-1, 2, min_part = 1).list() + sage: IntegerVectors(-1, 2, min_part=1).list() [] sage: IntegerVectors(0, 0, min_part=1).list() [[]] @@ -667,9 +667,9 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): An example showing the same output by using IntegerListsLex:: - sage: IntegerVectors(4, max_length=2).list() + sage: IntegerVectors(4, max_length=2).list() # optional - sage.combinat [[4], [3, 1], [2, 2], [1, 3], [0, 4]] - sage: list(IntegerListsLex(4, max_length=2)) + sage: list(IntegerListsLex(4, max_length=2)) # optional - sage.combinat [[4], [3, 1], [2, 2], [1, 3], [0, 4]] .. SEEALSO:: @@ -1392,12 +1392,12 @@ def __contains__(self, x): """ TESTS:: - sage: [3,2,2,1] in IntegerVectors(8,4, min_part = 1) + sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=1) # optional - sage.combinat True - sage: [3,2,2,1] in IntegerVectors(8,4, min_part = 2) + sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=2) # optional - sage.combinat False - sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3) + sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3) # optional - sage.combinat False """ if isinstance(x, IntegerVector) and x.parent() is self: @@ -1421,17 +1421,17 @@ def cardinality(self): EXAMPLES:: - sage: IntegerVectors(3, 3, min_part=1).cardinality() + sage: IntegerVectors(3, 3, min_part=1).cardinality() # optional - sage.combinat 1 - sage: IntegerVectors(5, 3, min_part=1).cardinality() + sage: IntegerVectors(5, 3, min_part=1).cardinality() # optional - sage.combinat 6 - sage: IntegerVectors(13, 4, max_part=4).cardinality() + sage: IntegerVectors(13, 4, max_part=4).cardinality() # optional - sage.combinat 20 - sage: IntegerVectors(k=4, max_part=3).cardinality() + sage: IntegerVectors(k=4, max_part=3).cardinality() # optional - sage.combinat 256 - sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality() + sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality() # optional - sage.combinat 27 - sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality() + sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality() # optional - sage.combinat 16 """ if self.k is None: @@ -1465,9 +1465,9 @@ def __iter__(self): """ EXAMPLES:: - sage: IntegerVectors(-1, 0, min_part = 1).list() + sage: IntegerVectors(-1, 0, min_part=1).list() [] - sage: IntegerVectors(-1, 2, min_part = 1).list() + sage: IntegerVectors(-1, 2, min_part=1).list() [] sage: IntegerVectors(0, 0, min_part=1).list() [[]] @@ -1512,7 +1512,7 @@ def __iter__(self): sage: all(map(lambda x: x.cardinality() == len(x.list()), iv)) True sage: essai = [[1,1,1], [2,5,6], [6,5,2]] - sage: iv = [ IntegerVectors(x[0], x[1], max_part = x[2]-1) for x in essai ] + sage: iv = [ IntegerVectors(x[0], x[1], max_part=x[2]-1) for x in essai ] sage: all(map(lambda x: x.cardinality() == len(x.list()), iv)) True """ diff --git a/src/sage/combinat/ranker.py b/src/sage/combinat/ranker.py index bcb5c967dcb..6d7fb2998a2 100644 --- a/src/sage/combinat/ranker.py +++ b/src/sage/combinat/ranker.py @@ -207,7 +207,7 @@ def unrank(L, i): Enumerated sets:: - sage: unrank(GF(7), 2) + sage: unrank(GF(7), 2) # optional - sage.rings.finite_rings 2 sage: unrank(IntegerModRing(29), 10) 10 diff --git a/src/sage/cpython/debug.pyx b/src/sage/cpython/debug.pyx index e00f31ac94e..f86166ca825 100644 --- a/src/sage/cpython/debug.pyx +++ b/src/sage/cpython/debug.pyx @@ -101,7 +101,7 @@ def getattr_debug(obj, name, default=_no_default): found '__doc__' in dict of got ... 'str'>) returning ... 'str'>) - sage: _ = getattr_debug(gp(1), "log") + sage: _ = getattr_debug(gp(1), "log") # optional - sage.libs.pari getattr_debug(obj=1, name='log'): type(obj) = object has __dict__ slot () diff --git a/src/sage/cpython/getattr.pyx b/src/sage/cpython/getattr.pyx index 0eabdfd36ab..525ea5aa934 100644 --- a/src/sage/cpython/getattr.pyx +++ b/src/sage/cpython/getattr.pyx @@ -54,7 +54,8 @@ cdef class AttributeErrorMessage: Traceback (most recent call last): ... AttributeError: 'sage.rings.integer.Integer' object has no attribute 'bla' - sage: QQ[x].gen().bla + sage: x = polygen(ZZ, 'x') + sage: QQ[x].gen().bla # optional - sage.libs.flint Traceback (most recent call last): ... AttributeError: 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint' object has no attribute 'bla' @@ -83,7 +84,7 @@ cdef class AttributeErrorMessage: ....: except AttributeError as exc: ....: ElementError2 = exc sage: ElementError - AttributeError('sage.symbolic.expression.Expression' object has no attribute '__bla'...) + AttributeError('sage.rings.polynomial...' object has no attribute '__bla'...) sage: ElementError2.args[0] is ElementError.args[0] True sage: isinstance(ElementError.args[0], sage.cpython.getattr.AttributeErrorMessage) @@ -406,13 +407,13 @@ def dir_with_other_class(self, *cls): Check that objects without dicts are well handled:: - sage: cython("cdef class A:\n cdef public int a") # optional - sage.misc.cython - sage: cython("cdef class B:\n cdef public int b") # optional - sage.misc.cython - sage: x = A() # optional - sage.misc.cython - sage: x.a = 1 # optional - sage.misc.cython - sage: hasattr(x,'__dict__') # optional - sage.misc.cython + sage: cython("cdef class A:\n cdef public int a") # optional - sage.misc.cython + sage: cython("cdef class B:\n cdef public int b") # optional - sage.misc.cython + sage: x = A() # optional - sage.misc.cython + sage: x.a = 1 # optional - sage.misc.cython + sage: hasattr(x,'__dict__') # optional - sage.misc.cython False - sage: dir_with_other_class(x, B) # optional - sage.misc.cython + sage: dir_with_other_class(x, B) # optional - sage.misc.cython [..., 'a', 'b'] TESTS: diff --git a/src/sage/data_structures/bitset.pyx b/src/sage/data_structures/bitset.pyx index 29bbeeb0d1c..32e821fc828 100644 --- a/src/sage/data_structures/bitset.pyx +++ b/src/sage/data_structures/bitset.pyx @@ -204,38 +204,38 @@ cdef class FrozenBitset: the number of elements currently in the bitset, while the capacity is the number of elements that the bitset can hold. :: - sage: p = primes_first_n(10); p + sage: p = primes_first_n(10); p # optional - sage.libs.pari [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] - sage: tuple(p) + sage: tuple(p) # optional - sage.libs.pari (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) - sage: F = FrozenBitset(p); F; FrozenBitset(tuple(p)) + sage: F = FrozenBitset(p); F; FrozenBitset(tuple(p)) # optional - sage.libs.pari 001101010001010001010001000001 001101010001010001010001000001 Recover the primes from the bitset:: - sage: for b in F: + sage: for b in F: # optional - sage.libs.pari ....: print(b) 2 3 ... 29 - sage: list(F) + sage: list(F) # optional - sage.libs.pari [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] Query the bitset:: - sage: len(F) + sage: len(F) # optional - sage.libs.pari 10 - sage: len(list(F)) + sage: len(list(F)) # optional - sage.libs.pari 10 - sage: F.capacity() + sage: F.capacity() # optional - sage.libs.pari 30 - sage: s = str(F); len(s) + sage: s = str(F); len(s) # optional - sage.libs.pari 30 - sage: 2 in F + sage: 2 in F # optional - sage.libs.pari True - sage: 1 in F + sage: 1 in F # optional - sage.libs.pari False A random iterable, with all duplicate elements removed:: diff --git a/src/sage/data_structures/blas_dict.pyx b/src/sage/data_structures/blas_dict.pyx index df6bf29641e..fb247f150a9 100644 --- a/src/sage/data_structures/blas_dict.pyx +++ b/src/sage/data_structures/blas_dict.pyx @@ -371,7 +371,7 @@ cpdef dict sum_of_monomials(monomials, scalar): {'a': 2, 'b': 3} sage: blas.sum_of_monomials(['a', 'a', 'b', 'b', 'b'], 2) {'a': 4, 'b': 6} - sage: blas.sum_of_monomials(['a', 'a', 'b', 'b', 'b'], GF(3).one()) + sage: blas.sum_of_monomials(['a', 'a', 'b', 'b', 'b'], GF(3).one()) # optional - sage.rings.finite_rings {'a': 2} """ cdef dict result = {} @@ -398,7 +398,8 @@ cpdef dict sum_of_terms(index_coeff_pairs): {'a': 1, 'b': 3} sage: blas.sum_of_terms([('a', 5), ('b', 3), ('a', -5)]) {'b': 3} - sage: blas.sum_of_terms([('a', 5), ('b', GF(2).one()), ('a', -5), ('b', GF(2).one())]) + sage: blas.sum_of_terms([('a', 5), ('b', GF(2).one()), # optional - sage.rings.finite_rings + ....: ('a', -5), ('b', GF(2).one())]) {} """ cdef dict result = {} @@ -434,7 +435,7 @@ cpdef dict convert_remove_zeroes(dict D, R): sage: from sage.data_structures.blas_dict import convert_remove_zeroes sage: d = {1: -2, 2: -4, 3: -3} - sage: convert_remove_zeroes(d, GF(2)) + sage: convert_remove_zeroes(d, GF(2)) # optional - sage.rings.finite_rings {3: 1} """ cdef list for_removal = [] diff --git a/src/sage/databases/cubic_hecke_db.py b/src/sage/databases/cubic_hecke_db.py index 99e96a9b816..52f5f7cc142 100644 --- a/src/sage/databases/cubic_hecke_db.py +++ b/src/sage/databases/cubic_hecke_db.py @@ -1494,10 +1494,10 @@ def read_markov(bas_ele, variables, num_strands=4): EXAMPLES:: sage: from sage.databases.cubic_hecke_db import read_markov - sage: from sympy import var - sage: u, v, w, s = var('u, v, w, s') - sage: variables = (u, v, w, s) - sage: read_markov('U2', variables, num_strands=3) + sage: from sympy import var # optional - sympy + sage: u, v, w, s = var('u, v, w, s') # optional - sympy + sage: variables = (u, v, w, s) # optional - sympy + sage: read_markov('U2', variables, num_strands=3) # optional - sympy [0, s, 1/s, s, 1/s, 0, 0, 0, 0, -s*v, s, s, -s*u/w, -v/s, 1/s, 0, 0, 0, 0, 1/s, -u/(s*w), -v/s, 0, 0] """ diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index fe58e2bde3e..b21c44656b5 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -131,10 +131,10 @@ def init_sage(controller=None): Check that SymPy equation pretty printer is limited in doctest mode to default width (80 chars):: - sage: from sympy import sympify # optional - sage.symbolic - sage: from sympy.printing.pretty.pretty import PrettyPrinter # optional - sage.symbolic - sage: s = sympify('+x^'.join(str(i) for i in range(30))) # optional - sage.symbolic - sage: print(PrettyPrinter(settings={'wrap_line': True}).doprint(s)) # optional - sage.symbolic + sage: from sympy import sympify # optional - sympy + sage: from sympy.printing.pretty.pretty import PrettyPrinter # optional - sympy + sage: s = sympify('+x^'.join(str(i) for i in range(30))) # optional - sympy + sage: print(PrettyPrinter(settings={'wrap_line': True}).doprint(s)) # optional - sympy 29 28 27 26 25 24 23 22 21 20 19 18 17 x + x + x + x + x + x + x + x + x + x + x + x + x + @@ -514,7 +514,8 @@ def __init__(self, *args, **kwds): sage: from sage.doctest.forker import SageDocTestRunner sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: DTR """ @@ -557,7 +558,8 @@ def _run(self, test, compileflags, out): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -831,7 +833,8 @@ def run(self, test, compileflags=0, out=None, clear_globs=True): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -891,7 +894,8 @@ def summarize(self, verbose=None): sage: from sage.doctest.forker import SageDocTestRunner sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: DTR._name2ft['sage.doctest.forker'] = (1,120) sage: results = DTR.summarize() ********************************************************************** @@ -975,7 +979,8 @@ def update_digests(self, example): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os, hashlib - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -1037,7 +1042,8 @@ def compile_and_execute(self, example, compiler, globs): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os, hashlib - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: DTR.running_doctest_digest = hashlib.md5() sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) @@ -1047,7 +1053,9 @@ def compile_and_execute(self, example, compiler, globs): sage: doctests, extras = FDS.create_doctests(globs) sage: ex0 = doctests[0].examples[0] sage: flags = 32768 if sys.version_info.minor < 8 else 524288 - sage: compiler = lambda ex: compile(ex.source, '', 'single', flags, 1) + sage: def compiler(ex): + ....: return compile(ex.source, '', + ....: 'single', flags, 1) sage: DTR.compile_and_execute(ex0, compiler, globs) 1764 sage: globs['doctest_var'] @@ -1060,7 +1068,9 @@ def compile_and_execute(self, example, compiler, globs): Now we can execute some more doctests to see the dependencies. :: sage: ex1 = doctests[0].examples[1] - sage: compiler = lambda ex:compile(ex.source, '', 'single', flags, 1) + sage: def compiler(ex): + ....: return compile(ex.source, '', + ....: 'single', flags, 1) sage: DTR.compile_and_execute(ex1, compiler, globs) sage: sorted(list(globs.set)) ['R', 'a'] @@ -1072,7 +1082,9 @@ def compile_and_execute(self, example, compiler, globs): :: sage: ex2 = doctests[0].examples[2] - sage: compiler = lambda ex:compile(ex.source, '', 'single', flags, 1) + sage: def compiler(ex): + ....: return compile(ex.source, '', + ....: 'single', flags, 1) sage: DTR.compile_and_execute(ex2, compiler, globs) a + 42 sage: list(globs.set) @@ -1131,7 +1143,8 @@ def _failure_header(self, test, example, message='Failed example:'): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -1202,7 +1215,8 @@ def report_start(self, out, test, example): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -1256,7 +1270,8 @@ def report_success(self, out, test, example, got, *, check_duration=0): sage: from sage.misc.misc import walltime sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -1297,7 +1312,8 @@ def report_failure(self, out, test, example, got, globs): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -1430,13 +1446,15 @@ def report_overtime(self, out, test, example, got, *, check_duration=0): sage: from sage.misc.misc import walltime sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=True, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) sage: ex = doctests[0].examples[0] sage: ex.walltime = 1.23 - sage: DTR.report_overtime(sys.stdout.write, doctests[0], ex, 'BAD ANSWER\n', check_duration=2.34) + sage: DTR.report_overtime(sys.stdout.write, doctests[0], ex, 'BAD ANSWER\n', + ....: check_duration=2.34) ********************************************************************** File ".../sage/doctest/forker.py", line 11, in sage.doctest.forker Warning, slow doctest: @@ -1554,7 +1572,8 @@ def update_results(self, D): sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults() sage: from sage.env import SAGE_SRC sage: import doctest, sys, os - sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) + sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, + ....: optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS) sage: filename = os.path.join(SAGE_SRC,'sage','doctest','forker.py') sage: FDS = FileDocTestSource(filename,DD) sage: doctests, extras = FDS.create_doctests(globals()) @@ -1563,11 +1582,12 @@ def update_results(self, D): sage: DTR.run(doctests[0]) TestResults(failed=0, attempted=4) sage: T.stop().annotate(DTR) - sage: D = DictAsObject({'cputime':[],'walltime':[],'err':None}) + sage: D = DictAsObject({'cputime': [], 'walltime': [], 'err': None}) sage: DTR.update_results(D) 0 sage: sorted(list(D.items())) - [('cputime', [...]), ('err', None), ('failures', 0), ('tests', 4), ('walltime', [...]), ('walltime_skips', 0)] + [('cputime', [...]), ('err', None), ('failures', 0), + ('tests', 4), ('walltime', [...]), ('walltime_skips', 0)] """ for key in ["cputime", "walltime"]: if key not in D: @@ -2112,7 +2132,7 @@ def run(self): TESTS:: - sage: run_doctests(sage.symbolic.units) # indirect doctest # optional - sage.symbolic + sage: run_doctests(sage.symbolic.units) # indirect doctest # optional - sage.symbolic Running doctests with ID ... Doctesting 1 file. sage -t .../sage/symbolic/units.py diff --git a/src/sage/env.py b/src/sage/env.py index f4899639a6d..e2baa8f297f 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -353,18 +353,18 @@ def cython_aliases(required_modules=None, EXAMPLES:: sage: from sage.env import cython_aliases - sage: cython_aliases() + sage: cython_aliases() # optional - sage.misc.cython {...} - sage: sorted(cython_aliases().keys()) + sage: sorted(cython_aliases().keys()) # optional - sage.misc.cython ['ARB_LIBRARY', 'CBLAS_CFLAGS', ..., 'ZLIB_LIBRARIES'] - sage: cython_aliases(required_modules=('module-that-is-assumed-to-not-exist')) + sage: cython_aliases(required_modules=('module-that-is-assumed-to-not-exist')) # optional - sage.misc.cython Traceback (most recent call last): ... PackageNotFoundError: ... - sage: cython_aliases(required_modules=(), optional_modules=('module-that-is-assumed-to-not-exist')) + sage: cython_aliases(required_modules=(), optional_modules=('module-that-is-assumed-to-not-exist')) # optional - sage.misc.cython {...} TESTS: @@ -372,7 +372,7 @@ def cython_aliases(required_modules=None, We can use ``cython.parallel`` regardless of whether OpenMP is supported. This will run in parallel, if OpenMP is supported:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: #distutils: extra_compile_args = OPENMP_CFLAGS ....: #distutils: extra_link_args = OPENMP_CFLAGS diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index d21bddd5deb..cc65b1f994a 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -42,41 +42,41 @@ You can specify a particular domain for the evaluation using sage: fc_wilk_zz = fast_callable(wilk, vars=[x], domain=ZZ) -The meaning of domain=D is that each intermediate and final result -is converted to type D. For instance, the previous example of -``sin(x) + 3*x^2`` with domain=D would be equivalent to +The meaning of ``domain=D`` is that each intermediate and final result +is converted to type ``D``. For instance, the previous example of +``sin(x) + 3*x^2`` with ``domain=D`` would be equivalent to ``D(D(sin(D(x))) + D(D(3)*D(D(x)^2)))``. (This example also demonstrates the one exception to the general rule: if an exponent is an -integral constant, then it is not wrapped with D().) +integral constant, then it is not wrapped with ``D()``.) At first glance, this seems like a very bad idea if you want to compute quickly. And it is a bad idea, for types where we don't have a special interpreter. It's not too bad of a slowdown, though. To mitigate the costs, we check whether the value already has -the correct parent before we call D. +the correct parent before we call ``D``. -We don't yet have a special interpreter with domain ZZ, so we can see +We don't yet have a special interpreter with domain ``ZZ``, so we can see how that compares to the generic fc_wilk example above:: sage: timeit('fc_wilk_zz(30)') # random, long time 625 loops, best of 3: 15.4 us per loop -However, for other types, using domain=D will get a large speedup, +However, for other types, using ``domain=D`` will get a large speedup, because we have special-purpose interpreters for those types. One -example is RDF. Since with domain=RDF we know that every single +example is ``RDF``. Since with ``domain=RDF`` we know that every single operation will be floating-point, we can just execute the floating-point operations directly and skip all the Python object -creations that you would get from actually using RDF objects:: +creations that you would get from actually using ``RDF`` objects:: sage: fc_wilk_rdf = fast_callable(wilk, vars=[x], domain=RDF) sage: timeit('fc_wilk_rdf(30.0)') # random, long time 625 loops, best of 3: 7 us per loop -The domain does not need to be a Sage type; for instance, domain=float -also works. (We actually use the same fast interpreter for domain=float -and domain=RDF; the only difference is that when domain=RDF is used, -the return value is an RDF element, and when domain=float is used, -the return value is a Python float.) :: +The domain does not need to be a Sage type; for instance, ``domain=float`` +also works. (We actually use the same fast interpreter for ``domain=float`` +and ``domain=RDF``; the only difference is that when ``domain=RDF`` is used, +the return value is an ``RDF`` element, and when ``domain=float`` is used, +the return value is a Python :class:`float`.) :: sage: fc_wilk_float = fast_callable(wilk, vars=[x], domain=float) sage: timeit('fc_wilk_float(30.0)') # random, long time @@ -94,7 +94,6 @@ For ``CC``:: sage: timeit('fc_wilk_cc(30.0)') # random, long time 625 loops, best of 3: 23 us per loop - And support for ``CDF``:: sage: fc_wilk_cdf = fast_callable(wilk, vars=[x], domain=CDF) @@ -314,24 +313,24 @@ from sage.structure.element cimport Expression as Expression_abc def fast_callable(x, domain=None, vars=None, expect_one_var=False): r""" - Given an expression x, compile it into a form that can be quickly - evaluated, given values for the variables in x. + Given an expression ``x``, compile it into a form that can be quickly + evaluated, given values for the variables in ``x``. - Currently, x can be an expression object, an element of SR, or a + Currently, ``x`` can be an expression object, an element of ``SR``, or a (univariate or multivariate) polynomial; this list will probably be extended soon. - By default, x is evaluated the same way that a Python function - would evaluate it -- addition maps to PyNumber_Add, etc. However, - you can specify domain=D where D is some Sage parent or Python + By default, ``x`` is evaluated the same way that a Python function + would evaluate it -- addition maps to ``PyNumber_Add``, etc. However, + you can specify ``domain=D`` where ``D`` is some Sage parent or Python type; in this case, all arithmetic is done in that domain. If we - have a special-purpose interpreter for that parent (like RDF or float), - domain=... will trigger the use of that interpreter. + have a special-purpose interpreter for that parent (like ``RDF`` or :class:`float`), + ``domain=...`` will trigger the use of that interpreter. - If vars is None and x is a polynomial, then we will use the - generators of parent(x) as the variables; otherwise, vars must be - specified (unless x is a symbolic expression with only one variable, - and expect_one_var is True, in which case we will use that variable). + If ``vars`` is ``None`` and ``x`` is a polynomial, then we will use the + generators of parent(x) as the variables; otherwise, ``vars`` must be + specified (unless ``x`` is a symbolic expression with only one variable, + and ``expect_one_var`` is ``True``, in which case we will use that variable). EXAMPLES:: @@ -344,11 +343,11 @@ def fast_callable(x, domain=None, vars=None, sage: f(2.0) 12.9092974268257 - We have special fast interpreters for domain=float and domain=RDF. + We have special fast interpreters for ``domain=float`` and ``domain=RDF``. (Actually it's the same interpreter; only the return type varies.) Note that the float interpreter is not actually more accurate than - the RDF interpreter; elements of RDF just don't display all - their digits. We have special fast interpreter for domain=CDF:: + the ``RDF`` interpreter; elements of ``RDF`` just don't display all + their digits. We have special fast interpreter for ``domain=CDF``:: sage: f_float = fast_callable(expr, vars=[x], domain=float) sage: f_float(2) @@ -395,7 +394,7 @@ def fast_callable(x, domain=None, vars=None, sage: fc(5, 7) 0.5514266812416906 - Check that fast_callable also works for symbolic functions with evaluation + Check that :func:`fast_callable` also works for symbolic functions with evaluation functions:: sage: def evalf_func(self, x, y, parent): return parent(x*y) if parent is not None else x*y @@ -505,7 +504,8 @@ def function_name(fn): Given a function, return a string giving a name for the function. For functions we recognize, we use our standard opcode name for the - function (so operator.add becomes 'add', and sage.all.sin becomes 'sin'). + function (so :func:`operator.add` becomes ``'add'``, and :func:`sage.all.sin` + becomes ``'sin'``). For functions we don't recognize, we try to come up with a name, but the name will be wrapped in braces; this is a signal that @@ -536,13 +536,14 @@ def function_name(fn): except AttributeError: return "{%r}" % fn + cdef class ExpressionTreeBuilder: r""" A class with helper methods for building Expressions. - An instance of this class is passed to _fast_callable_ methods; + An instance of this class is passed to :meth:`_fast_callable_` methods; you can also instantiate it yourself to create your own expressions - for fast_callable, bypassing _fast_callable_. + for :func:`fast_callable`, bypassing :meth:`_fast_callable_`. EXAMPLES:: @@ -558,17 +559,18 @@ cdef class ExpressionTreeBuilder: def __init__(self, vars, domain=None): r""" - Initialize an instance of ExpressionTreeBuilder. Takes - a list or tuple of variable names to use, and also an optional - domain. If a domain is given, then creating an ExpressionConstant - node with the __call__, make, or constant methods will convert + Initialize an instance of :class:`ExpressionTreeBuilder`. + + Takes a list or tuple of variable names to use, and also an optional + ``domain``. If a ``domain`` is given, then creating an :class:`ExpressionConstant` + node with the :meth:`__call__`, make, or constant methods will convert the value into the given domain. Note that this is the only effect of the domain parameter. It is quite possible to use different domains for - ExpressionTreeBuilder and for fast_callable; in that case, + :class:`ExpressionTreeBuilder` and for :func:`fast_callable`; in that case, constants will be converted twice (once when building the - Expression, and once when generating code). + :class:`Expression`, and once when generating code). EXAMPLES:: @@ -593,10 +595,11 @@ cdef class ExpressionTreeBuilder: def __call__(self, x): r""" - Try to convert the given value to an Expression. If it is already - an Expression, just return it. If it has a _fast_callable_ - method, then call the method with self as an argument. Otherwise, - use self.constant() to turn it into a constant. + Try to convert the given value to an :class:`Expression`. + + If it is already an Expression, just return it. If it has a :meth:`_fast_callable_` + method, then call the method with ``self`` as an argument. Otherwise, + use ``self.constant()`` to turn it into a constant. EXAMPLES:: @@ -645,7 +648,7 @@ cdef class ExpressionTreeBuilder: def constant(self, c): r""" - Turn the argument into an ExpressionConstant, converting it to + Turn the argument into an :class:`ExpressionConstant`, converting it to our domain if we have one. EXAMPLES:: @@ -664,7 +667,7 @@ cdef class ExpressionTreeBuilder: def var(self, v): r""" - Turn the argument into an ExpressionVariable. Look it up in + Turn the argument into an :class:`ExpressionVariable`. Look it up in the list of variables. (Variables are matched by name.) EXAMPLES:: @@ -718,10 +721,10 @@ cdef class ExpressionTreeBuilder: Construct a call node, given a function and a list of arguments. The arguments will be converted to Expressions using - ExpressionTreeBuilder.__call__. + :meth:`ExpressionTreeBuilder.__call__`. - As a special case, notices if the function is operator.pow and - the second argument is integral, and constructs an ExpressionIPow + As a special case, notices if the function is :func:`operator.pow` and + the second argument is integral, and constructs an :class:`ExpressionIPow` instead. EXAMPLES:: @@ -764,6 +767,7 @@ cdef class ExpressionTreeBuilder: self(iftrue), self(iffalse)) + # Cache these values, to make expression building a tiny bit faster # (by skipping the hash-table lookup in the operator module). cdef op_add = operator.add @@ -781,14 +785,15 @@ cdef op_neg = operator.neg cdef op_abs = operator.abs cdef op_inv = operator.inv + cdef class Expression: r""" - Represent an expression for fast_callable. + Represent an expression for :func:`fast_callable`. Supports the standard Python arithmetic operators; if arithmetic is attempted between an Expression and a non-Expression, the non-Expression is converted to an expression (using the - __call__ method of the Expression's ExpressionTreeBuilder). + :meth:`__call__` method of the Expression's :class:`ExpressionTreeBuilder`). EXAMPLES:: @@ -956,7 +961,7 @@ cdef class Expression: Compute a power expression from two Expressions. If the second Expression is a constant integer, then return - an ExpressionIPow instead of an ExpressionCall. + an :class:`ExpressionIPow` instead of an :class:`ExpressionCall`. EXAMPLES:: @@ -1079,7 +1084,7 @@ cdef class ExpressionConstant(Expression): def __init__(self, etb, c): r""" - Initialize an ExpressionConstant. + Initialize an :class:`ExpressionConstant`. EXAMPLES:: @@ -1101,7 +1106,7 @@ cdef class ExpressionConstant(Expression): def value(self): r""" - Return the constant value of an ExpressionConstant. + Return the constant value of an :class:`ExpressionConstant`. EXAMPLES:: @@ -1114,7 +1119,7 @@ cdef class ExpressionConstant(Expression): def __repr__(self): r""" - Give a string representing this ExpressionConstant. + Give a string representing this :class:`ExpressionConstant`. (We use the repr of its value.) EXAMPLES:: @@ -1166,7 +1171,7 @@ cdef class ExpressionVariable(Expression): def variable_index(self): r""" - Return the variable index of an ExpressionVariable. + Return the variable index of an :class:`ExpressionVariable`. EXAMPLES:: @@ -1179,7 +1184,7 @@ cdef class ExpressionVariable(Expression): def __repr__(self): r""" - Give a string representing this ExpressionVariable. + Give a string representing this :class:`ExpressionVariable`. EXAMPLES:: @@ -1198,6 +1203,7 @@ cdef class ExpressionVariable(Expression): # from the original expression when we have an Expression. return "v_%d" % self._variable_index + cdef class ExpressionCall(Expression): r""" An Expression that represents a function call. @@ -1214,7 +1220,7 @@ cdef class ExpressionCall(Expression): def __init__(self, etb, fn, args): r""" - Initialize an ExpressionCall. + Initialize an :class:`ExpressionCall`. EXAMPLES:: @@ -1238,7 +1244,7 @@ cdef class ExpressionCall(Expression): def function(self): r""" - Return the function from this ExpressionCall. + Return the function from this :class:`ExpressionCall`. EXAMPLES:: @@ -1251,7 +1257,7 @@ cdef class ExpressionCall(Expression): def arguments(self): r""" - Return the arguments from this ExpressionCall. + Return the arguments from this :class:`ExpressionCall`. EXAMPLES:: @@ -1264,7 +1270,7 @@ cdef class ExpressionCall(Expression): def __repr__(self): r""" - Give a string representing this ExpressionCall. + Give a string representing this :class:`ExpressionCall`. EXAMPLES:: @@ -1327,7 +1333,7 @@ cdef class ExpressionIPow(Expression): def base(self): r""" - Return the base from this ExpressionIPow. + Return the base from this :class:`ExpressionIPow`. EXAMPLES:: @@ -1340,7 +1346,7 @@ cdef class ExpressionIPow(Expression): def exponent(self): r""" - Return the exponent from this ExpressionIPow. + Return the exponent from this :class:`ExpressionIPow`. EXAMPLES:: @@ -1353,7 +1359,7 @@ cdef class ExpressionIPow(Expression): def __repr__(self): r""" - Give a string representing this ExpressionIPow. + Give a string representing this :class:`ExpressionIPow`. EXAMPLES:: @@ -1374,6 +1380,7 @@ cdef class ExpressionIPow(Expression): """ return 'ipow(%s, %d)' % (repr(self._base), self._exponent) + cdef class ExpressionChoice(Expression): r""" A conditional expression. @@ -1394,7 +1401,7 @@ cdef class ExpressionChoice(Expression): def __init__(self, etb, cond, iftrue, iffalse): r""" - Initialize an ExpressionChoice. + Initialize an :class:`ExpressionChoice`. EXAMPLES:: @@ -1421,7 +1428,7 @@ cdef class ExpressionChoice(Expression): def condition(self): r""" - Return the condition of an ExpressionChoice. + Return the condition of an :class:`ExpressionChoice`. EXAMPLES:: @@ -1435,7 +1442,7 @@ cdef class ExpressionChoice(Expression): def if_true(self): r""" - Return the true branch of an ExpressionChoice. + Return the true branch of an :class:`ExpressionChoice`. EXAMPLES:: @@ -1449,7 +1456,7 @@ cdef class ExpressionChoice(Expression): def if_false(self): r""" - Return the false branch of an ExpressionChoice. + Return the false branch of an :class:`ExpressionChoice`. EXAMPLES:: @@ -1463,7 +1470,7 @@ cdef class ExpressionChoice(Expression): def __repr__(self): r""" - Give a string representation for this ExpressionChoice. + Give a string representation for this :class:`ExpressionChoice`. (Based on the syntax for Python conditional expressions.) EXAMPLES:: @@ -1483,10 +1490,12 @@ cdef class ExpressionChoice(Expression): repr(self._cond), repr(self._iffalse)) + cpdef _expression_binop_helper(s, o, op): r""" - Make an Expression for (s op o). Either s or o (or both) must already - be an expression. + Make an :class:`Expression` for (``s`` ``op`` ``o``). + + Either ``s`` or ``o`` (or both) must already be an :class:`Expression`. EXAMPLES:: @@ -1496,7 +1505,7 @@ cpdef _expression_binop_helper(s, o, op): sage: etb = ExpressionTreeBuilder(vars=(x,y)) sage: x = etb(x) - Now x is an Expression, but y is not. Still, all the following + Now ``x`` is an :class:`Expression`, but ``y`` is not. Still, all the following cases work:: sage: _expression_binop_helper(x, x, operator.add) @@ -1537,9 +1546,10 @@ cpdef _expression_binop_helper(s, o, op): class IntegerPowerFunction(): r""" - This class represents the function x^n for an arbitrary integral - power n. That is, IntegerPowerFunction(2) is the squaring function; - IntegerPowerFunction(-1) is the reciprocal function. + This class represents the function `x^n` for an arbitrary integral power `n`. + + That is, ``IntegerPowerFunction(2)`` is the squaring function; + ``IntegerPowerFunction(-1)`` is the reciprocal function. EXAMPLES:: @@ -1566,7 +1576,7 @@ class IntegerPowerFunction(): def __init__(self, n): r""" - Initialize an IntegerPowerFunction. + Initialize an :class:`IntegerPowerFunction`. EXAMPLES:: @@ -1583,7 +1593,7 @@ class IntegerPowerFunction(): def __repr__(self): r""" - Return a string representing this IntegerPowerFunction. + Return a string representing this :class:`IntegerPowerFunction`. EXAMPLES:: @@ -1605,7 +1615,7 @@ class IntegerPowerFunction(): def __call__(self, x): r""" - Call this IntegerPowerFunction, to compute a power of its argument. + Call this :class:`IntegerPowerFunction`, to compute a power of its argument. EXAMPLES:: @@ -1618,6 +1628,7 @@ class IntegerPowerFunction(): """ return x**self.exponent + cdef dict builtin_functions = None cpdef dict get_builtin_functions(): r""" @@ -1633,11 +1644,13 @@ cpdef dict get_builtin_functions(): sage: from sage.ext.fast_callable import get_builtin_functions sage: builtins = get_builtin_functions() - sage: sorted(set(builtins.values())) - ['abs', 'acos', 'acosh', 'add', 'asin', 'asinh', 'atan', 'atanh', 'ceil', 'cos', 'cosh', 'cot', 'csc', 'div', 'exp', 'floor', 'floordiv', 'inv', 'log', 'mul', 'neg', 'pow', 'sec', 'sin', 'sinh', 'sqrt', 'sub', 'tan', 'tanh'] - sage: builtins[sin] + sage: sorted(set(builtins.values())) # optional - sage.symbolic + ['abs', 'acos', 'acosh', 'add', 'asin', 'asinh', 'atan', 'atanh', 'ceil', + 'cos', 'cosh', 'cot', 'csc', 'div', 'exp', 'floor', 'floordiv', 'inv', 'log', + 'mul', 'neg', 'pow', 'sec', 'sin', 'sinh', 'sqrt', 'sub', 'tan', 'tanh'] + sage: builtins[sin] # optional - sage.symbolic 'sin' - sage: builtins[ln] + sage: builtins[ln] # optional - sage.symbolic 'log' """ # We delay building builtin_functions to break a circular import @@ -1658,47 +1671,53 @@ cpdef dict get_builtin_functions(): op_pow: 'pow', } - # not handled: atan2, log2, log10 - import sage.functions.all as func_all - for fn in ('sqrt', 'ceil', 'floor', - 'sin', 'cos', 'tan', 'sec', 'csc', 'cot', - 'asin', 'acos', 'atan', 'sinh', 'cosh', 'tanh', - 'asinh', 'acosh', 'atanh', 'exp', 'log'): - builtin_functions[getattr(func_all, fn)] = fn - builtin_functions[func_all.abs_symbolic] = 'abs' - builtin_functions[func_all.ln] = 'log' + try: + import sage.functions.all as func_all + except ImportError: + pass + else: + # not handled: atan2, log2, log10 + for fn in ('sqrt', 'ceil', 'floor', + 'sin', 'cos', 'tan', 'sec', 'csc', 'cot', + 'asin', 'acos', 'atan', 'sinh', 'cosh', 'tanh', + 'asinh', 'acosh', 'atanh', 'exp', 'log'): + builtin_functions[getattr(func_all, fn)] = fn + builtin_functions[func_all.abs_symbolic] = 'abs' + builtin_functions[func_all.ln] = 'log' return builtin_functions + cdef class InstructionStream # forward declaration + cpdef generate_code(Expression expr, InstructionStream stream): r""" - Generate code from an Expression tree; write the result into an - InstructionStream. + Generate code from an :class:`Expression` tree; write the result into an + :class:`InstructionStream`. - In fast_callable, first we create an Expression, either directly - with an ExpressionTreeBuilder or with _fast_callable_ methods. - Then we optimize the Expression in tree form. (Unfortunately, + In :func:`fast_callable`, first we create an :class:`Expression`, either directly + with an :class:`ExpressionTreeBuilder` or with :meth:`_fast_callable_` methods. + Then we optimize the :class:`Expression` in tree form. (Unfortunately, this step is currently missing -- we do no optimizations.) - Then we linearize the Expression into a sequence of instructions, - by walking the Expression and sending the corresponding stack - instructions to an InstructionStream. + Then we linearize the :class:`Expression` into a sequence of instructions, + by walking the :class:`Expression` and sending the corresponding stack + instructions to an :class:`InstructionStream`. EXAMPLES:: sage: from sage.ext.fast_callable import ExpressionTreeBuilder, generate_code, InstructionStream sage: etb = ExpressionTreeBuilder('x') sage: x = etb.var('x') - sage: expr = ((x+pi)*(x+1)) + sage: expr = (x+pi) * (x+1) # optional - sage.symbolic sage: from sage.ext.interpreters.wrapper_py import metadata, Wrapper_py sage: instr_stream = InstructionStream(metadata, 1) - sage: generate_code(expr, instr_stream) + sage: generate_code(expr, instr_stream) # optional - sage.symbolic sage: instr_stream.instr('return') sage: v = Wrapper_py(instr_stream.get_current()) sage: type(v) - sage: v(7) + sage: v(7) # optional - sage.symbolic 8*pi + 56 TESTS:: @@ -1708,33 +1727,33 @@ cpdef generate_code(Expression expr, InstructionStream stream): sage: def my_sqrt(x): ....: if x < 0: raise ValueError("sqrt of negative number") ....: return sqrt(x, extend=False) - sage: fc = fast_callable(expr, domain=RealField(130)) - sage: fc(0) + sage: fc = fast_callable(expr, domain=RealField(130)) # optional - sage.symbolic + sage: fc(0) # optional - sage.symbolic 3.1415926535897932384626433832795028842 - sage: fc(1) + sage: fc(1) # optional - sage.symbolic 8.2831853071795864769252867665590057684 - sage: fc = fast_callable(expr, domain=RDF) - sage: fc(0) + sage: fc = fast_callable(expr, domain=RDF) # optional - sage.symbolic + sage: fc(0) # optional - sage.symbolic 3.141592653589793 - sage: fc(1) + sage: fc(1) # optional - sage.symbolic 8.283185307179586 - sage: fc.op_list() + sage: fc.op_list() # optional - sage.symbolic [('load_arg', 0), ('load_const', pi), 'add', ('load_arg', 0), ('load_const', 1), 'add', 'mul', 'return'] - sage: fc = fast_callable(etb.call(sin, x) + etb.call(sqrt, x), domain=RDF) - sage: fc(1) + sage: fc = fast_callable(etb.call(sin, x) + etb.call(sqrt, x), domain=RDF) # optional - sage.symbolic + sage: fc(1) # optional - sage.symbolic 1.8414709848078965 - sage: fc.op_list() + sage: fc.op_list() # optional - sage.symbolic [('load_arg', 0), 'sin', ('load_arg', 0), 'sqrt', 'add', 'return'] - sage: fc = fast_callable(etb.call(sin, x) + etb.call(sqrt, x)) - sage: fc(1) + sage: fc = fast_callable(etb.call(sin, x) + etb.call(sqrt, x)) # optional - sage.symbolic + sage: fc(1) # optional - sage.symbolic sin(1) + 1 - sage: fc.op_list() + sage: fc.op_list() # optional - sage.symbolic [('load_arg', 0), ('py_call', sin, 1), ('load_arg', 0), ('py_call', , 1), 'add', 'return'] sage: fc = fast_callable(etb.call(my_sin, x), domain=RDF) - sage: fc(3) + sage: fc(3) # optional - sage.symbolic 0.1411200080598672 sage: fc = fast_callable(etb.call(my_sin, x), domain=RealField(100)) - sage: fc(3) + sage: fc(3) # optional - sage.symbolic 0.14112000805986722210074480281 sage: fc.op_list() [('load_arg', 0), ('py_call', , 1), 'return'] @@ -1785,10 +1804,10 @@ cpdef generate_code(Expression expr, InstructionStream stream): TypeError: no conversion of this rational to integer sage: fc(6) 2 - sage: fc = fast_callable(etb.call(sin, x), domain=ZZ) - sage: fc(0) + sage: fc = fast_callable(etb.call(sin, x), domain=ZZ) # optional - sage.symbolic + sage: fc(0) # optional - sage.symbolic 0 - sage: fc(3) + sage: fc(3) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert sin(3) to an integer @@ -1796,7 +1815,7 @@ cpdef generate_code(Expression expr, InstructionStream stream): :: sage: fc = fast_callable(etb(x)^100) - sage: fc(pi) + sage: fc(pi) # optional - sage.symbolic pi^100 sage: fc = fast_callable(etb(x)^100, domain=ZZ) sage: fc(2) @@ -1908,14 +1927,16 @@ cpdef generate_code(Expression expr, InstructionStream stream): else: raise ValueError("Unhandled expression kind %s in generate_code" % type(expr)) + cdef class InterpreterMetadata # forward declaration + cdef class InstructionStream: r""" - An InstructionStream takes a sequence of instructions (passed in by + An :class:`InstructionStream` takes a sequence of instructions (passed in by a series of method calls) and computes the data structures needed by the interpreter. This is the stage where we switch from operating - on Expression trees to a linear representation. If we had a peephole + on :classL`Expression` trees to a linear representation. If we had a peephole optimizer (we don't) it would go here. Currently, this class is not very general; it only works for @@ -1925,7 +1946,7 @@ cdef class InstructionStream: a description of the memory chunks involved and the instruction stream can handle any interpreter. - Once you're done adding instructions, you call get_current() to retrieve + Once you're done adding instructions, you call :meth:`get_current` to retrieve the information needed by the interpreter (as a Python dictionary). """ @@ -1943,16 +1964,16 @@ cdef class InstructionStream: def __init__(self, metadata, n_args, domain=None): r""" - Initialize an InstructionStream. + Initialize an :class:`InstructionStream`. INPUT: - - metadata -- The metadata_by_opname from a wrapper module + - ``metadata`` -- The ``metadata_by_opname`` from a wrapper module - - n_args -- The number of arguments accessible by the generated code + - ``n_args`` -- The number of arguments accessible by the generated code (this is just passed to the wrapper class) - - domain -- The domain of interpretation (this is just passed to the + - ``domain`` -- The domain of interpretation (this is just passed to the wrapper class) EXAMPLES:: @@ -1989,7 +2010,7 @@ cdef class InstructionStream: def load_const(self, c): r""" - Add a 'load_const' instruction to this InstructionStream. + Add a ``'load_const'`` instruction to this :class:`InstructionStream`. EXAMPLES:: @@ -2014,7 +2035,7 @@ cdef class InstructionStream: def load_arg(self, n): r""" - Add a 'load_arg' instruction to this InstructionStream. + Add a ``'load_arg'`` instruction to this :class:`InstructionStream`. EXAMPLES:: @@ -2032,7 +2053,7 @@ cdef class InstructionStream: cpdef bint has_instr(self, opname): r""" - Check whether this InstructionStream knows how to generate code + Check whether this :class:`InstructionStream` knows how to generate code for a given instruction. EXAMPLES:: @@ -2051,12 +2072,12 @@ cdef class InstructionStream: def instr(self, opname, *args): r""" - Generate code in this InstructionStream for the given instruction + Generate code in this :class:`InstructionStream` for the given instruction and arguments. - The opname is used to look up a CompilerInstrSpec; the - CompilerInstrSpec describes how to interpret the arguments. - (This is documented in the class docstring for CompilerInstrSpec.) + The opname is used to look up a :class:`CompilerInstrSpec`; the + :class:`CompilerInstrSpec` describes how to interpret the arguments. + (This is documented in the class docstring for :class:`CompilerInstrSpec`.) EXAMPLES:: @@ -2064,15 +2085,15 @@ cdef class InstructionStream: sage: from sage.ext.fast_callable import InstructionStream sage: instr_stream = InstructionStream(metadata, 1) sage: instr_stream.instr('load_arg', 0) - sage: instr_stream.instr('sin') + sage: instr_stream.instr('sin') # optional - sage.symbolic sage: instr_stream.instr('py_call', math.sin, 1) - sage: instr_stream.instr('abs') + sage: instr_stream.instr('abs') # optional - sage.symbolic sage: instr_stream.instr('factorial') Traceback (most recent call last): ... KeyError: 'factorial' sage: instr_stream.instr('return') - sage: instr_stream.current_op_list() + sage: instr_stream.current_op_list() # optional - sage.symbolic [('load_arg', 0), 'sin', ('py_call', , 1), 'abs', 'return'] """ self.instr0(opname, args) @@ -2130,8 +2151,7 @@ cdef class InstructionStream: def get_metadata(self): r""" - Return the interpreter metadata being used by the current - InstructionStream. + Return the interpreter metadata being used by the current :class:`InstructionStream`. The code generator sometimes uses this to decide which code to generate. @@ -2150,7 +2170,7 @@ cdef class InstructionStream: def current_op_list(self): r""" Return the list of instructions that have been added to this - InstructionStream so far. + :class:`InstructionStream` so far. It's OK to call this, then add more instructions. @@ -2170,11 +2190,11 @@ cdef class InstructionStream: def get_current(self): r""" - Return the current state of the InstructionStream, as a dictionary + Return the current state of the :class:`InstructionStream`, as a dictionary suitable for passing to a wrapper class. NOTE: The dictionary includes internal data structures of the - InstructionStream; you must not modify it. + :class:`InstructionStream`; you must not modify it. EXAMPLES:: @@ -2213,17 +2233,18 @@ cdef class InstructionStream: cdef class InterpreterMetadata(): r""" - The interpreter metadata for a fast_callable interpreter. Currently - consists of a dictionary mapping instruction names to - (CompilerInstrSpec, opcode) pairs, a list mapping opcodes to - (instruction name, CompilerInstrSpec) pairs, and a range of exponents - for which the ipow instruction can be used. This range can be - False (if the ipow instruction should never be used), a pair of - two integers (a,b), if ipow should be used for a<=n<=b, or True, - if ipow should always be used. When ipow cannot be used, then - we fall back on calling IntegerPowerFunction. - - See the class docstring for CompilerInstrSpec for more information. + The interpreter metadata for a :func:`fast_callable` interpreter. + + Currently consists of a dictionary mapping instruction names to + (:class:`CompilerInstrSpec`, opcode) pairs, a list mapping opcodes to + (instruction name, :class:`CompilerInstrSpec`) pairs, and a range of exponents + for which the ``'ipow'`` instruction can be used. This range can be + ``False`` (if the ``'ipow'`` instruction should never be used), a pair of + two integers ``(a, b)``, if ``'ipow'`` should be used for a<=n<=b, or ``True``, + if ``'ipow'`` should always be used. When ``'ipow'`` cannot be used, then + we fall back on calling :class:`IntegerPowerFunction`. + + See the class docstring for :class:`CompilerInstrSpec` for more information. NOTE: You must not modify the metadata. """ @@ -2253,25 +2274,25 @@ cdef class InterpreterMetadata(): class CompilerInstrSpec(): r""" - Describe a single instruction to the fast_callable code generator. + Describe a single instruction to the :func:`fast_callable` code generator. An instruction has a number of stack inputs, a number of stack outputs, and a parameter list describing extra arguments that - must be passed to the InstructionStream.instr method (that end up + must be passed to the :meth:`InstructionStream.instr` method (that end up as extra words in the code). The parameter list is a list of strings. Each string is one of the following: - - 'args' - The instruction argument refers to an input argument of the + - ``'args'`` - The instruction argument refers to an input argument of the wrapper class; it is just appended to the code. - - 'constants', 'py_constants' - The instruction argument is a value; the + - ``'constants'``, ``'py_constants'`` - The instruction argument is a value; the value is added to the corresponding list (if it's not already there) and the index is appended to the code. - - 'n_inputs', 'n_outputs' - The instruction actually takes a variable - number of inputs or outputs (the n_inputs and n_outputs attributes of + - ``'n_inputs'``, ``'n_outputs'`` - The instruction actually takes a variable + number of inputs or outputs (the ``n_inputs`` and ``n_outputs`` attributes of this instruction are ignored). The instruction argument specifies the number of inputs or outputs (respectively); it is just appended to the code. @@ -2279,7 +2300,7 @@ class CompilerInstrSpec(): def __init__(self, n_inputs, n_outputs, parameters): r""" - Initialize a CompilerInstrSpec. + Initialize a :class:`CompilerInstrSpec`. EXAMPLES:: @@ -2293,7 +2314,7 @@ class CompilerInstrSpec(): def __repr__(self): r""" - Give a string representation for this CompilerInstrSpec. + Give a string representation for this :class:`CompilerInstrSpec`. EXAMPLES:: @@ -2308,10 +2329,11 @@ class CompilerInstrSpec(): """ return "CompilerInstrSpec(%d, %d, %s)" % (self.n_inputs, self.n_outputs, self.parameters) + def op_list(args, metadata): r""" - Given a dictionary with the result of calling get_current on an - InstructionStream, and the corresponding interpreter metadata, + Given a dictionary with the result of calling :meth:`get_current` on an + :class:`InstructionStream`, and the corresponding interpreter metadata, return a list of the instructions, in a simple somewhat human-readable format. @@ -2321,8 +2343,8 @@ def op_list(args, metadata): screen.) There's probably no reason to call this directly; if you - have a wrapper object, call op_list on it; if you have an - InstructionStream object, call current_op_list on it. + have a wrapper object, call :func:`op_list` on it; if you have an + :class:`InstructionStream` object, call :meth:`current_op_list` on it. EXAMPLES:: @@ -2360,8 +2382,9 @@ def op_list(args, metadata): cdef class Wrapper: r""" - The parent class for all fast_callable wrappers. Implements shared - behavior (currently only debugging). + The parent class for all :func:`fast_callable` wrappers. + + Implements shared behavior (currently only debugging). """ def __init__(self, args, metadata): @@ -2373,20 +2396,20 @@ cdef class Wrapper: sage: from sage.ext.fast_callable import ExpressionTreeBuilder, generate_code, InstructionStream sage: etb = ExpressionTreeBuilder('x') sage: x = etb.var('x') - sage: expr = ((x+pi)*(x+1)) + sage: expr = (x+pi) * (x+1) # optional - sage.symbolic sage: from sage.ext.interpreters.wrapper_py import metadata, Wrapper_py sage: instr_stream = InstructionStream(metadata, 1) - sage: generate_code(expr, instr_stream) + sage: generate_code(expr, instr_stream) # optional - sage.symbolic sage: instr_stream.instr('return') sage: v = Wrapper_py(instr_stream.get_current()) - sage: v.get_orig_args() + sage: v.get_orig_args() # optional - sage.symbolic {'args': 1, 'code': [0, 0, 1, 0, 4, 0, 0, 1, 1, 4, 6, 2], 'constants': [pi, 1], 'domain': None, 'py_constants': [], 'stack': 3} - sage: v.op_list() + sage: v.op_list() # optional - sage.symbolic [('load_arg', 0), ('load_const', pi), 'add', ('load_arg', 0), ('load_const', 1), 'add', 'mul', 'return'] """ @@ -2399,14 +2422,13 @@ cdef class Wrapper: def get_orig_args(self): r""" - Get the original arguments used when initializing this - wrapper. + Get the original arguments used when initializing this wrapper. (Probably only useful when writing doctests.) EXAMPLES:: - sage: fast_callable(sin(x)/x, vars=[x], domain=RDF).get_orig_args() + sage: fast_callable(sin(x)/x, vars=[x], domain=RDF).get_orig_args() # optional - sage.symbolic {'args': 1, 'code': [0, 0, 16, 0, 0, 8, 2], 'constants': [], @@ -2422,7 +2444,7 @@ cdef class Wrapper: EXAMPLES:: - sage: fast_callable(cos(x)*x, vars=[x], domain=RDF).op_list() + sage: fast_callable(cos(x) * x, vars=[x], domain=RDF).op_list() # optional - sage.symbolic [('load_arg', 0), ('load_arg', 0), 'cos', 'mul', 'return'] """ return op_list(self._orig_args, self._metadata) @@ -2438,9 +2460,9 @@ cdef class Wrapper: EXAMPLES:: - sage: fast_callable(abs(sin(x)), vars=[x], domain=RDF).python_calls() + sage: fast_callable(abs(sin(x)), vars=[x], domain=RDF).python_calls() # optional - sage.symbolic [] - sage: fast_callable(abs(sin(factorial(x))), vars=[x]).python_calls() + sage: fast_callable(abs(sin(factorial(x))), vars=[x]).python_calls() # optional - sage.symbolic [factorial, sin] """ ops = self.op_list() @@ -2460,15 +2482,15 @@ class FastCallableFloatWrapper: faster form with :func:`fast_callable`. That function takes a ``domain`` parameter that forces the end (and all intermediate) results of evaluation to a specific type. Though usually always - want the end result to be of type ``float``, correctly choosing + want the end result to be of type :class:`float`, correctly choosing the ``domain`` presents some problems: - * ``float`` is a bad choice because it's common for real + * :class:`float` is a bad choice because it's common for real functions to have complex terms in them. Moreover precision issues can produce terms like ``1.0 + 1e-12*I`` that are hard to avoid if calling ``real()`` on everything is infeasible. - * ``complex`` has essentially the same problem as ``float``. + * :class:`complex` has essentially the same problem as :class:`float`. There are several symbolic functions like :func:`min_symbolic`, :func:`max_symbolic`, and :func:`floor` that are unable to operate on complex numbers. @@ -2482,7 +2504,7 @@ class FastCallableFloatWrapper: min/max), and supports :func:`floor`. However, most numerical functions cannot handle complex numbers, so using ``CDF`` would require us to wrap every evaluation in a - ``CDF``-to-``float`` conversion routine. That would slow + ``CDF``-to-:class:`float` conversion routine. That would slow things down less than a domain of ``None`` would, but is unattractive mainly because of how invasive it would be to "fix" the output everywhere. @@ -2501,8 +2523,8 @@ class FastCallableFloatWrapper: :func:`fast_callable`. Whenever we need to support intermediate complex terms in a numerical routine, we can set ``domain=CDF`` while creating its fast-callable incarnation, and then wrap the - result in this class. The ``__call__`` method of this class then - ensures that the ``CDF`` output is converted to a ``float`` if + result in this class. The :meth:`__call__` method of this class then + ensures that the ``CDF`` output is converted to a :class:`float` if its imaginary part is within an acceptable tolerance. EXAMPLES: @@ -2524,7 +2546,7 @@ class FastCallableFloatWrapper: """ def __init__(self, ff, imag_tol): r""" - Construct a ``FastCallableFloatWrapper``. + Construct a :class:`FastCallableFloatWrapper`. INPUT: @@ -2537,9 +2559,9 @@ class FastCallableFloatWrapper: OUTPUT: - An instance of ``FastCallableFloatWrapper`` that can be - called just like ``ff``, but that always returns a ``float`` - if no error is raised. A ``ValueError`` is raised if the + An instance of :class:`FastCallableFloatWrapper` that can be + called just like ``ff``, but that always returns a :class:`float` + if no error is raised. A :class:`ValueError` is raised if the imaginary part of the result exceeds ``imag_tol``. EXAMPLES: @@ -2566,13 +2588,11 @@ class FastCallableFloatWrapper: def __call__(self, *args): r""" - Evaluate the underlying fast-callable and convert the result to - ``float``. + Evaluate the underlying fast-callable and convert the result to :class:`float`. TESTS: - Evaluation either returns a ``float``, or raises a - ``ValueError``:: + Evaluation either returns a :class:`float`, or raises a :class:`ValueError`:: sage: from sage.ext.fast_callable import FastCallableFloatWrapper sage: f = x diff --git a/src/sage/features/sagemath.py b/src/sage/features/sagemath.py index 7e545404de2..27faca1d3fa 100644 --- a/src/sage/features/sagemath.py +++ b/src/sage/features/sagemath.py @@ -134,6 +134,53 @@ 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')]) + + +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')]) + + class sage__libs__pari(JoinFeature): r""" A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.pari`. @@ -290,6 +337,28 @@ 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')]) + + class sage__rings__real_double(PythonModule): r""" A :class:`~sage.features.Feature` describing the presence of :mod:`sage.rings.real_double`. @@ -382,6 +451,8 @@ def all_features(): sage__geometry__polyhedron(), sage__graphs(), sage__groups(), + sage__libs__flint(), + sage__libs__ntl(), sage__libs__pari(), sage__modules(), sage__plot(), @@ -389,6 +460,7 @@ def all_features(): sage__rings__function_field(), sage__rings__number_field(), sage__rings__padics(), + sage__rings__polynomial__pbori(), sage__rings__real_double(), sage__rings__real_mpfr(), sage__symbolic()] diff --git a/src/sage/functions/gamma.py b/src/sage/functions/gamma.py index e93e518b0b9..aba008a38a4 100644 --- a/src/sage/functions/gamma.py +++ b/src/sage/functions/gamma.py @@ -150,10 +150,10 @@ def __init__(self): Check that the implementations roughly agrees (note there might be difference of several ulp on more complicated entries):: - sage: import mpmath - sage: float(gamma(10.)) == gamma(10.r) == float(gamma(mpmath.mpf(10))) + sage: import mpmath # optional - mpmath + sage: float(gamma(10.)) == gamma(10.r) == float(gamma(mpmath.mpf(10))) # optional - mpmath True - sage: float(gamma(8.5)) == gamma(8.5r) == float(gamma(mpmath.mpf(8.5))) + sage: float(gamma(8.5)) == gamma(8.5r) == float(gamma(mpmath.mpf(8.5))) # optional - mpmath True Check that ``QQbar`` half integers work with the ``pi`` formula:: diff --git a/src/sage/functions/hyperbolic.py b/src/sage/functions/hyperbolic.py index 9a362b8882f..6f58a2ce75c 100644 --- a/src/sage/functions/hyperbolic.py +++ b/src/sage/functions/hyperbolic.py @@ -65,7 +65,7 @@ def __init__(self): sage: latex(sinh(x)) \sinh\left(x\right) - sage: sinh(x)._sympy_() + sage: sinh(x)._sympy_() # optional - sympy sinh(x) To prevent automatic evaluation, use the ``hold`` parameter:: @@ -102,7 +102,7 @@ def __init__(self): sage: latex(cosh(x)) \cosh\left(x\right) - sage: cosh(x)._sympy_() + sage: cosh(x)._sympy_() # optional - sympy cosh(x) To prevent automatic evaluation, use the ``hold`` parameter:: @@ -164,7 +164,7 @@ def __init__(self): sage: latex(tanh(x)) \tanh\left(x\right) - sage: tanh(x)._sympy_() + sage: tanh(x)._sympy_() # optional - sympy tanh(x) Check that real/imaginary parts are correct (:trac:`20098`):: @@ -222,7 +222,7 @@ def __init__(self): -1/sinh(x)^2 sage: latex(coth(x)) \coth\left(x\right) - sage: coth(x)._sympy_() + sage: coth(x)._sympy_() # optional - sympy coth(x) """ GinacFunction.__init__(self, "coth", latex_name=r"\coth") @@ -231,9 +231,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: coth(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: coth(a) # optional - numpy array([1.03731472, 1.00496982, 1.00067115]) """ return 1.0 / tanh(x) @@ -276,7 +276,7 @@ def __init__(self): -sech(x)*tanh(x) sage: latex(sech(x)) \operatorname{sech}\left(x\right) - sage: sech(x)._sympy_() + sage: sech(x)._sympy_() # optional - sympy sech(x) """ GinacFunction.__init__(self, "sech", latex_name=r"\operatorname{sech}",) @@ -285,9 +285,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: sech(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: sech(a) # optional - numpy array([0.26580223, 0.09932793, 0.03661899]) """ return 1.0 / cosh(x) @@ -328,7 +328,7 @@ def __init__(self): -coth(x)*csch(x) sage: latex(csch(x)) \operatorname{csch}\left(x\right) - sage: csch(x)._sympy_() + sage: csch(x)._sympy_() # optional - sympy csch(x) """ GinacFunction.__init__(self, "csch", latex_name=r"\operatorname{csch}") @@ -337,9 +337,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: csch(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: csch(a) # optional - numpy array([0.27572056, 0.09982157, 0.03664357]) """ return 1.0 / sinh(x) @@ -403,7 +403,7 @@ def __init__(self): arcsinh sage: latex(asinh(x)) \operatorname{arsinh}\left(x\right) - sage: asinh(x)._sympy_() + sage: asinh(x)._sympy_() # optional - sympy asinh(x) """ GinacFunction.__init__(self, "arcsinh", @@ -489,7 +489,7 @@ def __init__(self): arccosh sage: latex(acosh(x)) \operatorname{arcosh}\left(x\right) - sage: acosh(x)._sympy_() + sage: acosh(x)._sympy_() # optional - sympy acosh(x) """ GinacFunction.__init__(self, "arccosh", @@ -549,7 +549,7 @@ def __init__(self): arctanh sage: latex(atanh(x)) \operatorname{artanh}\left(x\right) - sage: atanh(x)._sympy_() + sage: atanh(x)._sympy_() # optional - sympy atanh(x) """ GinacFunction.__init__(self, "arctanh", @@ -593,7 +593,7 @@ def __init__(self): sage: latex(acoth(x)) \operatorname{arcoth}\left(x\right) - sage: acoth(x)._sympy_() + sage: acoth(x)._sympy_() # optional - sympy acoth(x) Check that :trac:`23636` is fixed:: @@ -611,9 +611,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2,5) - sage: acoth(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2,5) # optional - numpy + sage: acoth(a) # optional - numpy array([0.54930614, 0.34657359, 0.25541281]) """ return arctanh(1.0 / x) @@ -644,7 +644,7 @@ def __init__(self): -1/(sqrt(-x^2 + 1)*x) sage: latex(asech(x)) \operatorname{arsech}\left(x\right) - sage: asech(x)._sympy_() + sage: asech(x)._sympy_() # optional - sympy asech(x) """ GinacFunction.__init__(self, "arcsech", @@ -657,9 +657,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.linspace(0,1,3) - sage: asech(a) + sage: import numpy # optional - numpy + sage: a = numpy.linspace(0,1,3) # optional - numpy + sage: asech(a) # optional - numpy doctest:...: RuntimeWarning: divide by zero encountered in ...divide array([ inf, 1.3169579, 0. ]) """ @@ -698,7 +698,7 @@ def __init__(self): sage: acsch(float(0.1)) 2.99822295029797 - sage: acsch(x)._sympy_() + sage: acsch(x)._sympy_() # optional - sympy acsch(x) """ GinacFunction.__init__(self, "arccsch", @@ -711,9 +711,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.linspace(0,1,3) - sage: acsch(a) + sage: import numpy # optional - numpy + sage: a = numpy.linspace(0,1,3) # optional - numpy + sage: acsch(a) # optional - numpy doctest:...: RuntimeWarning: divide by zero encountered in ...divide array([ inf, 1.44363548, 0.88137359]) """ diff --git a/src/sage/functions/jacobi.py b/src/sage/functions/jacobi.py index 6fe3b2ade89..3e751bd7f71 100644 --- a/src/sage/functions/jacobi.py +++ b/src/sage/functions/jacobi.py @@ -208,70 +208,70 @@ def _eval_(self, x, m): Check that the simplifications are correct:: - sage: from mpmath import almosteq - sage: almosteq(n(jacobi_nd(8, 0, hold=True)), n(jacobi_nd(8, 0))) + sage: from mpmath import almosteq # optional - mpmath + sage: almosteq(n(jacobi_nd(8, 0, hold=True)), n(jacobi_nd(8, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_nd(1, 1, hold=True)), n(jacobi_nd(1, 1))) + sage: almosteq(n(jacobi_nd(1, 1, hold=True)), n(jacobi_nd(1, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_nd(0, -5, hold=True)), n(jacobi_nd(0, -5))) + sage: almosteq(n(jacobi_nd(0, -5, hold=True)), n(jacobi_nd(0, -5))) # optional - mpmath True - sage: almosteq(n(jacobi_ns(-4, 0, hold=True)), n(jacobi_ns(-4, 0))) + sage: almosteq(n(jacobi_ns(-4, 0, hold=True)), n(jacobi_ns(-4, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_ns(-2, 1, hold=True)), n(jacobi_ns(-2, 1))) + sage: almosteq(n(jacobi_ns(-2, 1, hold=True)), n(jacobi_ns(-2, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_nc(2, 0, hold=True)), n(jacobi_nc(2, 0))) + sage: almosteq(n(jacobi_nc(2, 0, hold=True)), n(jacobi_nc(2, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_nc(1, 1, hold=True)), n(jacobi_nc(1, 1))) + sage: almosteq(n(jacobi_nc(1, 1, hold=True)), n(jacobi_nc(1, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_nc(0, 0, hold=True)), n(jacobi_nc(0, 0))) + sage: almosteq(n(jacobi_nc(0, 0, hold=True)), n(jacobi_nc(0, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_dn(-10, 0, hold=True)), n(jacobi_dn(-10, 0))) + sage: almosteq(n(jacobi_dn(-10, 0, hold=True)), n(jacobi_dn(-10, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_dn(-1, 1, hold=True)), n(jacobi_dn(-1, 1))) + sage: almosteq(n(jacobi_dn(-1, 1, hold=True)), n(jacobi_dn(-1, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_dn(0, 3, hold=True)), n(jacobi_dn(0, 3))) + sage: almosteq(n(jacobi_dn(0, 3, hold=True)), n(jacobi_dn(0, 3))) # optional - mpmath True - sage: almosteq(n(jacobi_ds(2, 0, hold=True)), n(jacobi_ds(2, 0))) + sage: almosteq(n(jacobi_ds(2, 0, hold=True)), n(jacobi_ds(2, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_dc(-1, 0, hold=True)), n(jacobi_dc(-1, 0))) + sage: almosteq(n(jacobi_dc(-1, 0, hold=True)), n(jacobi_dc(-1, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_dc(-8, 1, hold=True)), n(jacobi_dc(-8, 1))) + sage: almosteq(n(jacobi_dc(-8, 1, hold=True)), n(jacobi_dc(-8, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_dc(0, -10, hold=True)), n(jacobi_dc(0, -10))) + sage: almosteq(n(jacobi_dc(0, -10, hold=True)), n(jacobi_dc(0, -10))) # optional - mpmath True - sage: almosteq(n(jacobi_sn(-7, 0, hold=True)), n(jacobi_sn(-7, 0))) + sage: almosteq(n(jacobi_sn(-7, 0, hold=True)), n(jacobi_sn(-7, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_sn(-3, 1, hold=True)), n(jacobi_sn(-3, 1))) + sage: almosteq(n(jacobi_sn(-3, 1, hold=True)), n(jacobi_sn(-3, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_sn(0, -6, hold=True)), n(jacobi_sn(0, -6))) + sage: almosteq(n(jacobi_sn(0, -6, hold=True)), n(jacobi_sn(0, -6))) # optional - mpmath True - sage: almosteq(n(jacobi_sd(4, 0, hold=True)), n(jacobi_sd(4, 0))) + sage: almosteq(n(jacobi_sd(4, 0, hold=True)), n(jacobi_sd(4, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_sd(0, 1, hold=True)), n(jacobi_sd(0, 1))) + sage: almosteq(n(jacobi_sd(0, 1, hold=True)), n(jacobi_sd(0, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_sd(0, 3, hold=True)), n(jacobi_sd(0, 3))) + sage: almosteq(n(jacobi_sd(0, 3, hold=True)), n(jacobi_sd(0, 3))) # optional - mpmath True - sage: almosteq(n(jacobi_sc(-9, 0, hold=True)), n(jacobi_sc(-9, 0))) + sage: almosteq(n(jacobi_sc(-9, 0, hold=True)), n(jacobi_sc(-9, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_sc(0, 1, hold=True)), n(jacobi_sc(0, 1))) + sage: almosteq(n(jacobi_sc(0, 1, hold=True)), n(jacobi_sc(0, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_sc(0, -10, hold=True)), n(jacobi_sc(0, -10))) + sage: almosteq(n(jacobi_sc(0, -10, hold=True)), n(jacobi_sc(0, -10))) # optional - mpmath True - sage: almosteq(n(jacobi_cn(-2, 0, hold=True)), n(jacobi_cn(-2, 0))) + sage: almosteq(n(jacobi_cn(-2, 0, hold=True)), n(jacobi_cn(-2, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_cn(6, 1, hold=True)), n(jacobi_cn(6, 1))) + sage: almosteq(n(jacobi_cn(6, 1, hold=True)), n(jacobi_cn(6, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_cn(0, -10, hold=True)), n(jacobi_cn(0, -10))) + sage: almosteq(n(jacobi_cn(0, -10, hold=True)), n(jacobi_cn(0, -10))) # optional - mpmath True - sage: almosteq(n(jacobi_cd(9, 0, hold=True)), n(jacobi_cd(9, 0))) + sage: almosteq(n(jacobi_cd(9, 0, hold=True)), n(jacobi_cd(9, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_cd(-8, 1, hold=True)), n(jacobi_cd(-8, 1))) + sage: almosteq(n(jacobi_cd(-8, 1, hold=True)), n(jacobi_cd(-8, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_cd(0, 1, hold=True)), n(jacobi_cd(0, 1))) + sage: almosteq(n(jacobi_cd(0, 1, hold=True)), n(jacobi_cd(0, 1))) # optional - mpmath True - sage: almosteq(n(jacobi_cs(-9, 0, hold=True)), n(jacobi_cs(-9, 0))) + sage: almosteq(n(jacobi_cs(-9, 0, hold=True)), n(jacobi_cs(-9, 0))) # optional - mpmath True - sage: almosteq(n(jacobi_cs(-6, 1, hold=True)), n(jacobi_cs(-6, 1))) + sage: almosteq(n(jacobi_cs(-6, 1, hold=True)), n(jacobi_cs(-6, 1))) # optional - mpmath True """ if self.kind == 'nd': @@ -371,16 +371,16 @@ def _derivative_(self, x, m, diff_param): sn, cn, and dn are analytic for all real ``x``, so we can check that the derivatives are correct by computing the series:: - sage: from mpmath import almosteq + sage: from mpmath import almosteq # optional - mpmath sage: a = 0.9327542442482303 sage: b = 0.7402326293643771 - sage: almosteq(jacobi_sn(x, b).series(x, 10).subs(x=a), + sage: almosteq(jacobi_sn(x, b).series(x, 10).subs(x=a), # optional - mpmath ....: jacobi_sn(a, b), abs_eps=0.01) True - sage: almosteq(jacobi_cn(x, b).series(x, 10).subs(x=a), + sage: almosteq(jacobi_cn(x, b).series(x, 10).subs(x=a), # optional - mpmath ....: jacobi_cn(a, b), abs_eps=0.01) True - sage: almosteq(jacobi_dn(x, b).series(x, 10).subs(x=a), + sage: almosteq(jacobi_dn(x, b).series(x, 10).subs(x=a), # optional - mpmath ....: jacobi_dn(a, b), abs_eps=0.01) True """ @@ -560,77 +560,77 @@ def _eval_(self, x, m): Check that the simplifications are correct:: - sage: from mpmath import almosteq - sage: almosteq(n(inverse_jacobi_cd(1, -8, hold=True)), + sage: from mpmath import almosteq # optional - mpmath + sage: almosteq(n(inverse_jacobi_cd(1, -8, hold=True)), # optional - mpmath ....: n(inverse_jacobi_cd(1, -8))) True - sage: almosteq(n(inverse_jacobi_cn(0, -5, hold=True)), + sage: almosteq(n(inverse_jacobi_cn(0, -5, hold=True)), # optional - mpmath ....: n(inverse_jacobi_cn(0, -5))) True - sage: almosteq(n(inverse_jacobi_cn(1, -8, hold=True)), + sage: almosteq(n(inverse_jacobi_cn(1, -8, hold=True)), # optional - mpmath ....: n(inverse_jacobi_cn(1, -8))) True - sage: almosteq(n(inverse_jacobi_cs(7, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_cs(7, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_cs(7, 1))) True - sage: almosteq(n(inverse_jacobi_dc(3, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_dc(3, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_dc(3, 0))) True - sage: almosteq(n(inverse_jacobi_dc(1, 7, hold=True)), + sage: almosteq(n(inverse_jacobi_dc(1, 7, hold=True)), # optional - mpmath ....: n(inverse_jacobi_dc(1, 7))) True - sage: almosteq(n(inverse_jacobi_dn(1, -1, hold=True)), + sage: almosteq(n(inverse_jacobi_dn(1, -1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_dn(1, -1))) True - sage: almosteq(n(inverse_jacobi_ds(7, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_ds(7, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_ds(7, 0))) True - sage: almosteq(n(inverse_jacobi_ds(5, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_ds(5, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_ds(5, 1))) True - sage: almosteq(n(inverse_jacobi_nc(-2, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_nc(-2, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_nc(-2, 0))) True - sage: almosteq(n(inverse_jacobi_nc(-1, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_nc(-1, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_nc(-1, 1))) True - sage: almosteq(n(inverse_jacobi_nc(1, 4, hold=True)), + sage: almosteq(n(inverse_jacobi_nc(1, 4, hold=True)), # optional - mpmath ....: n(inverse_jacobi_nc(1, 4))) True - sage: almosteq(n(inverse_jacobi_nd(9, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_nd(9, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_nd(9, 1))) True - sage: almosteq(n(inverse_jacobi_nd(1, -9, hold=True)), + sage: almosteq(n(inverse_jacobi_nd(1, -9, hold=True)), # optional - mpmath ....: n(inverse_jacobi_nd(1, -9))) True - sage: almosteq(n(inverse_jacobi_ns(-6, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_ns(-6, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_ns(-6, 0))) True - sage: almosteq(n(inverse_jacobi_ns(6, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_ns(6, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_ns(6, 1))) True - sage: almosteq(n(inverse_jacobi_sc(9, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_sc(9, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sc(9, 0))) True - sage: almosteq(n(inverse_jacobi_sc(8, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_sc(8, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sc(8, 1))) True - sage: almosteq(n(inverse_jacobi_sc(0, -8, hold=True)), + sage: almosteq(n(inverse_jacobi_sc(0, -8, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sc(0, -8))) True - sage: almosteq(n(inverse_jacobi_sd(-1, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_sd(-1, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sd(-1, 0))) True - sage: almosteq(n(inverse_jacobi_sd(-2, 1, hold=True)), + sage: almosteq(n(inverse_jacobi_sd(-2, 1, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sd(-2, 1))) True - sage: almosteq(n(inverse_jacobi_sd(0, -2, hold=True)), + sage: almosteq(n(inverse_jacobi_sd(0, -2, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sd(0, -2))) True - sage: almosteq(n(inverse_jacobi_sn(0, 0, hold=True)), + sage: almosteq(n(inverse_jacobi_sn(0, 0, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sn(0, 0))) True - sage: almosteq(n(inverse_jacobi_sn(0, 6, hold=True)), + sage: almosteq(n(inverse_jacobi_sn(0, 6, hold=True)), # optional - mpmath ....: n(inverse_jacobi_sn(0, 6))) True """ @@ -726,55 +726,55 @@ def _derivative_(self, x, m, diff_param): Check that ``dy/dx * dx/dy == 1``, where ``y = jacobi_pq(x, m)`` and ``x = inverse_jacobi_pq(y, m)``:: - sage: from mpmath import almosteq + sage: from mpmath import almosteq # optional - mpmath sage: a = 0.130103220857094 sage: b = 0.437176765041986 sage: m = var('m') - sage: almosteq(abs((diff(jacobi_cd(x, m), x) * + sage: almosteq(abs((diff(jacobi_cd(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_cd(x, m), x).subs(x=jacobi_cd(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_cn(x, m), x) * + sage: almosteq(abs((diff(jacobi_cn(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_cn(x, m), x).subs(x=jacobi_cn(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_cs(x, m), x) * + sage: almosteq(abs((diff(jacobi_cs(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_cs(x, m), x).subs(x=jacobi_cs(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_dc(x, m), x) * + sage: almosteq(abs((diff(jacobi_dc(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_dc(x, m), x).subs(x=jacobi_dc(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_dn(x, m), x) * + sage: almosteq(abs((diff(jacobi_dn(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_dn(x, m), x).subs(x=jacobi_dn(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_ds(x, m), x) * + sage: almosteq(abs((diff(jacobi_ds(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_ds(x, m), x).subs(x=jacobi_ds(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_nc(x, m), x) * + sage: almosteq(abs((diff(jacobi_nc(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_nc(x, m), x).subs(x=jacobi_nc(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_nd(x, m), x) * + sage: almosteq(abs((diff(jacobi_nd(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_nd(x, m), x).subs(x=jacobi_nd(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_ns(x, m), x) * + sage: almosteq(abs((diff(jacobi_ns(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_ns(x, m), x).subs(x=jacobi_ns(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_sc(x, m), x) * + sage: almosteq(abs((diff(jacobi_sc(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_sc(x, m), x).subs(x=jacobi_sc(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_sd(x, m), x) * + sage: almosteq(abs((diff(jacobi_sd(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_sd(x, m), x).subs(x=jacobi_sd(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True - sage: almosteq(abs((diff(jacobi_sn(x, m), x) * + sage: almosteq(abs((diff(jacobi_sn(x, m), x) * # optional - mpmath ....: diff(inverse_jacobi_sn(x, m), x).subs(x=jacobi_sn(x, m))).subs(x=a, m=b)), ....: 1, abs_eps=1e-14) True @@ -1143,129 +1143,129 @@ def inverse_jacobi_f(kind, x, m): TESTS:: - sage: from mpmath import ellipfun, chop + sage: from mpmath import ellipfun, chop # optional - mpmath sage: from sage.functions.jacobi import inverse_jacobi_f - sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.6, 0), 0)) + sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.6, 0), 0)) # optional - mpmath mpf('0.59999999999999998') - sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.6, 1), 1)) + sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.6, 1), 1)) # optional - mpmath mpf('0.59999999999999998') - sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0, -3), -3)) + sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0, -3), -3)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('sn', inverse_jacobi_f('sn', -1, 4), 4)) + sage: chop(ellipfun('sn', inverse_jacobi_f('sn', -1, 4), 4)) # optional - mpmath mpf('-1.0') - sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.3, 4), 4)) + sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.3, 4), 4)) # optional - mpmath mpf('0.29999999999999999') - sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.8, 4), 4)) + sage: chop(ellipfun('sn', inverse_jacobi_f('sn', 0.8, 4), 4)) # optional - mpmath mpf('0.80000000000000004') - sage: chop(ellipfun('ns', inverse_jacobi_f('ns', 0.8, 0), 0)) + sage: chop(ellipfun('ns', inverse_jacobi_f('ns', 0.8, 0), 0)) # optional - mpmath mpf('0.80000000000000004') - sage: chop(ellipfun('ns', inverse_jacobi_f('ns', -0.7, 1), 1)) + sage: chop(ellipfun('ns', inverse_jacobi_f('ns', -0.7, 1), 1)) # optional - mpmath mpf('-0.69999999999999996') - sage: chop(ellipfun('ns', inverse_jacobi_f('ns', 0.01, 2), 2)) + sage: chop(ellipfun('ns', inverse_jacobi_f('ns', 0.01, 2), 2)) # optional - mpmath mpf('0.01') - sage: chop(ellipfun('ns', inverse_jacobi_f('ns', 0, 2), 2)) + sage: chop(ellipfun('ns', inverse_jacobi_f('ns', 0, 2), 2)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('ns', inverse_jacobi_f('ns', -10, 6), 6)) + sage: chop(ellipfun('ns', inverse_jacobi_f('ns', -10, 6), 6)) # optional - mpmath mpf('-10.0') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', -10, 0), 0)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', -10, 0), 0)) # optional - mpmath mpf('-9.9999999999999982') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 50, 1), 1)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 50, 1), 1)) # optional - mpmath mpf('50.000000000000071') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 1, 5), 5)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 1, 5), 5)) # optional - mpmath mpf('1.0') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 0.5, -5), -5)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 0.5, -5), -5)) # optional - mpmath mpf('0.5') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', -0.75, -15), -15)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', -0.75, -15), -15)) # optional - mpmath mpf('-0.75000000000000022') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 10, 0.8), 0.8)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', 10, 0.8), 0.8)) # optional - mpmath mpf('9.9999999999999982') - sage: chop(ellipfun('cn', inverse_jacobi_f('cn', -2, 0.9), 0.9)) + sage: chop(ellipfun('cn', inverse_jacobi_f('cn', -2, 0.9), 0.9)) # optional - mpmath mpf('-2.0') - sage: chop(ellipfun('nc', inverse_jacobi_f('nc', -4, 0), 0)) + sage: chop(ellipfun('nc', inverse_jacobi_f('nc', -4, 0), 0)) # optional - mpmath mpf('-3.9999999999999987') - sage: chop(ellipfun('nc', inverse_jacobi_f('nc', 7, 1), 1)) + sage: chop(ellipfun('nc', inverse_jacobi_f('nc', 7, 1), 1)) # optional - mpmath mpf('7.0000000000000009') - sage: chop(ellipfun('nc', inverse_jacobi_f('nc', 7, 3), 3)) + sage: chop(ellipfun('nc', inverse_jacobi_f('nc', 7, 3), 3)) # optional - mpmath mpf('7.0') - sage: chop(ellipfun('nc', inverse_jacobi_f('nc', 0, 2), 2)) + sage: chop(ellipfun('nc', inverse_jacobi_f('nc', 0, 2), 2)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('nc', inverse_jacobi_f('nc', -18, -4), -4)) + sage: chop(ellipfun('nc', inverse_jacobi_f('nc', -18, -4), -4)) # optional - mpmath mpf('-17.999999999999925') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -0.3, 1), 1)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -0.3, 1), 1)) # optional - mpmath mpf('-0.29999999999999999') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 1, -1), -1)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 1, -1), -1)) # optional - mpmath mpf('1.0') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 0.8, 0.5), 0.5)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 0.8, 0.5), 0.5)) # optional - mpmath mpf('0.80000000000000004') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 5, -4), -4)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 5, -4), -4)) # optional - mpmath mpf('5.0') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 0.4, 0.5), 0.5)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', 0.4, 0.5), 0.5)) # optional - mpmath mpf('0.40000000000000002') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -0.4, 0.5), 0.5)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -0.4, 0.5), 0.5)) # optional - mpmath mpf('-0.40000000000000002') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -0.9, 0.5), 0.5)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -0.9, 0.5), 0.5)) # optional - mpmath mpf('-0.90000000000000002') - sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -1.9, 0.2), 0.2)) + sage: chop(ellipfun('dn', inverse_jacobi_f('dn', -1.9, 0.2), 0.2)) # optional - mpmath mpf('-1.8999999999999999') - sage: chop(ellipfun('nd', inverse_jacobi_f('nd', -1.9, 1), 1)) + sage: chop(ellipfun('nd', inverse_jacobi_f('nd', -1.9, 1), 1)) # optional - mpmath mpf('-1.8999999999999999') - sage: chop(ellipfun('nd', inverse_jacobi_f('nd', 1, -1), -1)) + sage: chop(ellipfun('nd', inverse_jacobi_f('nd', 1, -1), -1)) # optional - mpmath mpf('1.0') - sage: chop(ellipfun('nd', inverse_jacobi_f('nd', 11, -6), -6)) + sage: chop(ellipfun('nd', inverse_jacobi_f('nd', 11, -6), -6)) # optional - mpmath mpf('11.0') - sage: chop(ellipfun('nd', inverse_jacobi_f('nd', 0, 8), 8)) + sage: chop(ellipfun('nd', inverse_jacobi_f('nd', 0, 8), 8)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('nd', inverse_jacobi_f('nd', -3, 0.8), 0.8)) + sage: chop(ellipfun('nd', inverse_jacobi_f('nd', -3, 0.8), 0.8)) # optional - mpmath mpf('-2.9999999999999996') - sage: chop(ellipfun('sc', inverse_jacobi_f('sc', -3, 0), 0)) + sage: chop(ellipfun('sc', inverse_jacobi_f('sc', -3, 0), 0)) # optional - mpmath mpf('-3.0') - sage: chop(ellipfun('sc', inverse_jacobi_f('sc', 2, 1), 1)) + sage: chop(ellipfun('sc', inverse_jacobi_f('sc', 2, 1), 1)) # optional - mpmath mpf('2.0') - sage: chop(ellipfun('sc', inverse_jacobi_f('sc', 0, 9), 9)) + sage: chop(ellipfun('sc', inverse_jacobi_f('sc', 0, 9), 9)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('sc', inverse_jacobi_f('sc', -7, 3), 3)) + sage: chop(ellipfun('sc', inverse_jacobi_f('sc', -7, 3), 3)) # optional - mpmath mpf('-7.0') - sage: chop(ellipfun('cs', inverse_jacobi_f('cs', -7, 0), 0)) + sage: chop(ellipfun('cs', inverse_jacobi_f('cs', -7, 0), 0)) # optional - mpmath mpf('-6.9999999999999991') - sage: chop(ellipfun('cs', inverse_jacobi_f('cs', 8, 1), 1)) + sage: chop(ellipfun('cs', inverse_jacobi_f('cs', 8, 1), 1)) # optional - mpmath mpf('8.0') - sage: chop(ellipfun('cs', inverse_jacobi_f('cs', 2, 6), 6)) + sage: chop(ellipfun('cs', inverse_jacobi_f('cs', 2, 6), 6)) # optional - mpmath mpf('2.0') - sage: chop(ellipfun('cs', inverse_jacobi_f('cs', 0, 4), 4)) + sage: chop(ellipfun('cs', inverse_jacobi_f('cs', 0, 4), 4)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('cs', inverse_jacobi_f('cs', -6, 8), 8)) + sage: chop(ellipfun('cs', inverse_jacobi_f('cs', -6, 8), 8)) # optional - mpmath mpf('-6.0000000000000018') - sage: chop(ellipfun('cd', inverse_jacobi_f('cd', -6, 0), 0)) + sage: chop(ellipfun('cd', inverse_jacobi_f('cd', -6, 0), 0)) # optional - mpmath mpf('-6.0000000000000009') - sage: chop(ellipfun('cd', inverse_jacobi_f('cd', 1, 3), 3)) + sage: chop(ellipfun('cd', inverse_jacobi_f('cd', 1, 3), 3)) # optional - mpmath mpf('1.0') - sage: chop(ellipfun('cd', inverse_jacobi_f('cd', 6, 8), 8)) + sage: chop(ellipfun('cd', inverse_jacobi_f('cd', 6, 8), 8)) # optional - mpmath mpf('6.0000000000000027') - sage: chop(ellipfun('dc', inverse_jacobi_f('dc', 5, 0), 0)) + sage: chop(ellipfun('dc', inverse_jacobi_f('dc', 5, 0), 0)) # optional - mpmath mpf('5.0000000000000018') - sage: chop(ellipfun('dc', inverse_jacobi_f('dc', -4, 2), 2)) + sage: chop(ellipfun('dc', inverse_jacobi_f('dc', -4, 2), 2)) # optional - mpmath mpf('-4.0000000000000018') - sage: chop(ellipfun('sd', inverse_jacobi_f('sd', -4, 0), 0)) + sage: chop(ellipfun('sd', inverse_jacobi_f('sd', -4, 0), 0)) # optional - mpmath mpf('-3.9999999999999991') - sage: chop(ellipfun('sd', inverse_jacobi_f('sd', 7, 1), 1)) + sage: chop(ellipfun('sd', inverse_jacobi_f('sd', 7, 1), 1)) # optional - mpmath mpf('7.0') - sage: chop(ellipfun('sd', inverse_jacobi_f('sd', 0, 9), 9)) + sage: chop(ellipfun('sd', inverse_jacobi_f('sd', 0, 9), 9)) # optional - mpmath mpf('0.0') - sage: chop(ellipfun('sd', inverse_jacobi_f('sd', 8, 0.8), 0.8)) + sage: chop(ellipfun('sd', inverse_jacobi_f('sd', 8, 0.8), 0.8)) # optional - mpmath mpf('7.9999999999999991') - sage: chop(ellipfun('ds', inverse_jacobi_f('ds', 4, 0.25), 0.25)) + sage: chop(ellipfun('ds', inverse_jacobi_f('ds', 4, 0.25), 0.25)) # optional - mpmath mpf('4.0') """ from mpmath import mp @@ -1611,19 +1611,19 @@ def jacobi_am_f(x, m): TESTS:: - sage: from mpmath import ellipf + sage: from mpmath import ellipf # optional - mpmath sage: from sage.functions.jacobi import jacobi_am_f - sage: ellipf(jacobi_am_f(0.5, 1), 1) + sage: ellipf(jacobi_am_f(0.5, 1), 1) # optional - mpmath mpf('0.5') - sage: ellipf(jacobi_am(3, 0.3), 0.3) + sage: ellipf(jacobi_am(3, 0.3), 0.3) # optional - mpmath mpf('3.0') - sage: ellipf(jacobi_am_f(2, -0.5), -0.5) + sage: ellipf(jacobi_am_f(2, -0.5), -0.5) # optional - mpmath mpf('2.0') - sage: jacobi_am_f(2, -0.5) + sage: jacobi_am_f(2, -0.5) # optional - mpmath mpf('2.2680930777934176') - sage: jacobi_am_f(-2, -0.5) + sage: jacobi_am_f(-2, -0.5) # optional - mpmath mpf('-2.2680930777934176') - sage: jacobi_am_f(-3, 2) + sage: jacobi_am_f(-3, 2) # optional - mpmath mpf('0.36067407399586108') """ from mpmath import mp diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py index 7398c763971..9f5f1cc51fc 100644 --- a/src/sage/functions/orthogonal_polys.py +++ b/src/sage/functions/orthogonal_polys.py @@ -898,18 +898,18 @@ def _eval_numpy_(self, n, x): EXAMPLES:: - sage: import numpy - sage: z = numpy.array([1,2]) - sage: z2 = numpy.array([[1,2],[1,2]]) - sage: z3 = numpy.array([1,2,3.]) - sage: chebyshev_T(1,z) + sage: import numpy # optional - numpy + sage: z = numpy.array([1,2]) # optional - numpy + sage: z2 = numpy.array([[1,2],[1,2]]) # optional - numpy + sage: z3 = numpy.array([1,2,3.]) # optional - numpy + sage: chebyshev_T(1,z) # optional - numpy array([1., 2.]) - sage: chebyshev_T(1,z2) + sage: chebyshev_T(1,z2) # optional - numpy array([[1., 2.], [1., 2.]]) - sage: chebyshev_T(1,z3) + sage: chebyshev_T(1,z3) # optional - numpy array([1., 2., 3.]) - sage: chebyshev_T(z,0.1) + sage: chebyshev_T(z,0.1) # optional - numpy array([ 0.1 , -0.98]) """ from scipy.special import eval_chebyt @@ -1185,18 +1185,18 @@ def _eval_numpy_(self, n, x): EXAMPLES:: - sage: import numpy - sage: z = numpy.array([1,2]) - sage: z2 = numpy.array([[1,2],[1,2]]) - sage: z3 = numpy.array([1,2,3.]) - sage: chebyshev_U(1,z) + sage: import numpy # optional - numpy + sage: z = numpy.array([1,2]) # optional - numpy + sage: z2 = numpy.array([[1,2],[1,2]]) # optional - numpy + sage: z3 = numpy.array([1,2,3.]) # optional - numpy + sage: chebyshev_U(1,z) # optional - numpy array([2., 4.]) - sage: chebyshev_U(1,z2) + sage: chebyshev_U(1,z2) # optional - numpy array([[2., 4.], [2., 4.]]) - sage: chebyshev_U(1,z3) + sage: chebyshev_U(1,z3) # optional - numpy array([2., 4., 6.]) - sage: chebyshev_U(z,0.1) + sage: chebyshev_U(z,0.1) # optional - numpy array([ 0.2 , -0.96]) """ from scipy.special import eval_chebyu @@ -2297,12 +2297,12 @@ class Func_ultraspherical(GinacFunction): Numerical evaluation with the mpmath library:: - sage: from mpmath import gegenbauer as gegenbauer_mp - sage: from mpmath import mp - sage: mp.pretty = True; mp.dps=25 - sage: gegenbauer_mp(-7,0.5,0.3) + sage: from mpmath import gegenbauer as gegenbauer_mp # optional - mpmath + sage: from mpmath import mp # optional - mpmath + sage: mp.pretty = True; mp.dps=25 # optional - mpmath + sage: gegenbauer_mp(-7,0.5,0.3) # optional - mpmath 0.1291811875 - sage: gegenbauer_mp(2+3j, -0.75, -1000j) + sage: gegenbauer_mp(2+3j, -0.75, -1000j) # optional - mpmath (-5038991.358609026523401901 + 9414549.285447104177860806j) TESTS: diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index 3e2570e889e..925bfa24abb 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -381,14 +381,14 @@ def __init__(self): sage: latex(ceil(x)) \left \lceil x \right \rceil - sage: ceil(x)._sympy_() + sage: ceil(x)._sympy_() # optional - sympy ceiling(x) :: - sage: import numpy - sage: a = numpy.linspace(0,2,6) - sage: ceil(a) + sage: import numpy # optional - numpy + sage: a = numpy.linspace(0,2,6) # optional - numpy + sage: ceil(a) # optional - numpy array([0., 1., 1., 2., 2., 2.]) Test pickling:: @@ -550,11 +550,11 @@ def __init__(self): :: - sage: import numpy - sage: a = numpy.linspace(0,2,6) - sage: floor(a) + sage: import numpy # optional - numpy + sage: a = numpy.linspace(0,2,6) # optional - numpy + sage: floor(a) # optional - numpy array([0., 0., 0., 1., 1., 2.]) - sage: floor(x)._sympy_() + sage: floor(x)._sympy_() # optional - sympy floor(x) Test pickling:: diff --git a/src/sage/functions/special.py b/src/sage/functions/special.py index faa6a73cc7e..df5d77660b8 100644 --- a/src/sage/functions/special.py +++ b/src/sage/functions/special.py @@ -191,10 +191,10 @@ class SphericalHarmonic(BuiltinFunction): sage: spherical_harmonic(1, 1, x, y) -1/4*sqrt(3)*sqrt(2)*e^(I*y)*sin(x)/sqrt(pi) - sage: from sympy import Ynm - sage: Ynm(1, 1, x, y).expand(func=True) + sage: from sympy import Ynm # optional - sympy + sage: Ynm(1, 1, x, y).expand(func=True) # optional - sympy -sqrt(6)*exp(I*y)*sin(x)/(4*sqrt(pi)) - sage: spherical_harmonic(1, 1, x, y) - Ynm(1, 1, x, y) + sage: spherical_harmonic(1, 1, x, y) - Ynm(1, 1, x, y) # optional - sympy 0 It also agrees with SciPy's spherical harmonics:: diff --git a/src/sage/functions/transcendental.py b/src/sage/functions/transcendental.py index 2511d47f13e..b7fdb331a7b 100644 --- a/src/sage/functions/transcendental.py +++ b/src/sage/functions/transcendental.py @@ -348,7 +348,7 @@ def __init__(self): zetaderiv(n, x) sage: zetaderiv(1, 4).n() -0.0689112658961254 - sage: import mpmath; mpmath.diff(lambda x: mpmath.zeta(x), 4) + sage: import mpmath; mpmath.diff(lambda x: mpmath.zeta(x), 4) # optional - mpmath mpf('-0.068911265896125382') TESTS:: diff --git a/src/sage/functions/trig.py b/src/sage/functions/trig.py index 16aeeae43ab..2941866fb24 100644 --- a/src/sage/functions/trig.py +++ b/src/sage/functions/trig.py @@ -336,9 +336,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: cot(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: cot(a) # optional - numpy array([-0.45765755, -7.01525255, 0.86369115]) """ return 1.0 / tan(x) @@ -406,9 +406,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: sec(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: sec(a) # optional - numpy array([-2.40299796, -1.01010867, -1.52988566]) """ return 1 / cos(x) @@ -476,9 +476,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: csc(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: csc(a) # optional - numpy array([ 1.09975017, 7.0861674 , -1.32134871]) """ return 1 / sin(x) @@ -745,9 +745,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: arccot(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: arccot(a) # optional - numpy array([0.46364761, 0.32175055, 0.24497866]) """ return math.pi / 2 - arctan(x) @@ -805,9 +805,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: arccsc(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: arccsc(a) # optional - numpy array([0.52359878, 0.33983691, 0.25268026]) """ return arcsin(1.0 / x) @@ -867,9 +867,9 @@ def _eval_numpy_(self, x): """ EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(2, 5) - sage: arcsec(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2, 5) # optional - numpy + sage: arcsec(a) # optional - numpy array([1.04719755, 1.23095942, 1.31811607]) """ return arccos(1.0 / x) @@ -943,16 +943,16 @@ def __init__(self): The function also works with numpy arrays as input:: - sage: import numpy - sage: a = numpy.linspace(1, 3, 3) - sage: b = numpy.linspace(3, 6, 3) - sage: atan2(a, b) + sage: import numpy # optional - numpy + sage: a = numpy.linspace(1, 3, 3) # optional - numpy + sage: b = numpy.linspace(3, 6, 3) # optional - numpy + sage: atan2(a, b) # optional - numpy array([0.32175055, 0.41822433, 0.46364761]) - sage: atan2(1,a) + sage: atan2(1,a) # optional - numpy array([0.78539816, 0.46364761, 0.32175055]) - sage: atan2(a, 1) + sage: atan2(a, 1) # optional - numpy array([0.78539816, 1.10714872, 1.24904577]) TESTS:: diff --git a/src/sage/geometry/cone.py b/src/sage/geometry/cone.py index 1d9b1b4f080..40823a8f389 100644 --- a/src/sage/geometry/cone.py +++ b/src/sage/geometry/cone.py @@ -129,31 +129,31 @@ You can work with subcones that form faces of other cones:: - sage: face = four_rays.faces(dim=2)[0] - sage: face + sage: face = four_rays.faces(dim=2)[0] # optional - sage.graphs + sage: face # optional - sage.graphs 2-d face of 3-d cone in 3-d lattice N - sage: face.rays() + sage: face.rays() # optional - sage.graphs N(-1, -1, 1), N(-1, 1, 1) in 3-d lattice N - sage: face.ambient_ray_indices() + sage: face.ambient_ray_indices() # optional - sage.graphs (2, 3) - sage: four_rays.rays(face.ambient_ray_indices()) + sage: four_rays.rays(face.ambient_ray_indices()) # optional - sage.graphs N(-1, -1, 1), N(-1, 1, 1) in 3-d lattice N If you need to know inclusion relations between faces, you can use :: - sage: L = four_rays.face_lattice() - sage: [len(s) for s in L.level_sets()] + sage: L = four_rays.face_lattice() # optional - sage.graphs + sage: [len(s) for s in L.level_sets()] # optional - sage.graphs [1, 4, 4, 1] - sage: face = L.level_sets()[2][0] - sage: face.rays() + sage: face = L.level_sets()[2][0] # optional - sage.graphs + sage: face.rays() # optional - sage.graphs N(1, 1, 1), N(1, -1, 1) in 3-d lattice N - sage: L.hasse_diagram().neighbors_in(face) + sage: L.hasse_diagram().neighbors_in(face) # optional - sage.graphs [1-d face of 3-d cone in 3-d lattice N, 1-d face of 3-d cone in 3-d lattice N] @@ -572,9 +572,9 @@ def _ambient_space_point(body, data): (1, 1/3) sage: _ambient_space_point(c, vector(QQ,[1,1/3])) (1, 1/3) - sage: _ambient_space_point(c, [1/2,1/sqrt(3)]) + sage: _ambient_space_point(c, [1/2, 1/sqrt(3)]) # optional - sage.symbolic sage.rings.number_field (1/2, 0.5773502691896258?) - sage: _ambient_space_point(c, vector(AA,[1/2,1/sqrt(3)])) + sage: _ambient_space_point(c, vector(AA, [1/2, 1/sqrt(3)])) # optional - sage.symbolic sage.rings.number_field (1/2, 0.5773502691896258?) sage: _ambient_space_point(c, [1,1,3]) Traceback (most recent call last): @@ -592,9 +592,9 @@ def _ambient_space_point(body, data): sage: from sage.geometry.cone import _ambient_space_point sage: c = Cone([(1,0), (0,1)]) - sage: _ambient_space_point(c, [1, pi]) + sage: _ambient_space_point(c, [1, pi]) # optional - sage.symbolic sage.rings.number_field (1.00000000000000, 3.14159265358979) - sage: _ambient_space_point(c, vector(SR,[1, pi])) + sage: _ambient_space_point(c, vector(SR,[1, pi])) # optional - sage.symbolic sage.rings.number_field (1.00000000000000, 3.14159265358979) """ @@ -1005,7 +1005,7 @@ def ambient_vector_space(self, base_field=None): sage: c = Cone([(1,0)]) sage: c.ambient_vector_space() Vector space of dimension 2 over Rational Field - sage: c.ambient_vector_space(AA) + sage: c.ambient_vector_space(AA) # optional - sage.rings.number_field Vector space of dimension 2 over Algebraic Real Field """ return self.lattice().vector_space(base_field=base_field) @@ -1601,7 +1601,7 @@ def __getstate__(self): TESTS:: sage: C = Cone([(1,0)]) - sage: C.face_lattice() + sage: C.face_lattice() # optional - sage.graphs sage.combinat Finite lattice containing 2 elements with distinguished linear extension sage: C._test_pickling() sage: C2 = loads(dumps(C)); C2 @@ -1674,17 +1674,17 @@ def _contains(self, point, region='whole cone'): We can test vectors with irrational components:: sage: c = Cone([(1,0), (0,1)]) - sage: c._contains((1,sqrt(2))) + sage: c._contains((1, sqrt(2))) # optional - sage.symbolic True - sage: c._contains(vector(SR, [1,pi])) + sage: c._contains(vector(SR, [1, pi])) # optional - sage.symbolic True Ensure that complex vectors are not contained in a real cone:: sage: c = Cone([(1,0), (0,1)]) - sage: c._contains((1,I)) + sage: c._contains((1,I)) # optional - sage.symbolic False - sage: c._contains(vector(QQbar,[1,I])) + sage: c._contains(vector(QQbar, [1,I])) # optional - sage.symbolic False And we refuse to coerce elements of another lattice into ours:: @@ -1971,7 +1971,7 @@ def _latex_(self): sage: quadrant = Cone([(1,0), (0,1)]) sage: quadrant._latex_() '\\sigma^{2}' - sage: quadrant.facets()[0]._latex_() + sage: quadrant.facets()[0]._latex_() # optional - sage.graphs '\\sigma^{1} \\subset \\sigma^{2}' """ if self.ambient() is self: @@ -1995,7 +1995,7 @@ def _repr_(self): '2-d cone in 2-d lattice N' sage: quadrant 2-d cone in 2-d lattice N - sage: quadrant.facets()[0] + sage: quadrant.facets()[0] # optional - sage.graphs 1-d face of 2-d cone in 2-d lattice N """ result = "%d-d" % self.dim() @@ -2051,7 +2051,7 @@ def _sort_faces(self, faces): sage: octant = Cone(identity_matrix(3).columns()) sage: # indirect doctest - sage: for i, face in enumerate(octant.faces(1)): + sage: for i, face in enumerate(octant.faces(1)): # optional - sage.graphs ....: if face.ray(0) != octant.ray(i): ....: print("Wrong order!") """ @@ -2096,12 +2096,12 @@ def adjacent(self): EXAMPLES:: sage: octant = Cone([(1,0,0), (0,1,0), (0,0,1)]) - sage: octant.adjacent() + sage: octant.adjacent() # optional - sage.graphs () - sage: one_face = octant.faces(1)[0] - sage: len(one_face.adjacent()) + sage: one_face = octant.faces(1)[0] # optional - sage.graphs + sage: len(one_face.adjacent()) # optional - sage.graphs 2 - sage: one_face.adjacent()[1] + sage: one_face.adjacent()[1] # optional - sage.graphs 1-d face of 3-d cone in 3-d lattice N Things are a little bit subtle with fans, as we illustrate below. @@ -2111,7 +2111,7 @@ def adjacent(self): sage: fan = Fan(cones=[(0,1), (1,2)], ....: rays=[(1,0), (0,1), (-1,0)]) sage: cone = fan.generating_cone(0) - sage: len(cone.adjacent()) + sage: len(cone.adjacent()) # optional - sage.graphs 1 The second generating cone is adjacent to this one. Now we create the @@ -2120,7 +2120,7 @@ def adjacent(self): sage: fan = Fan(cones=[(0,1), (1,2)], ....: rays=[(1,0,0), (0,1,0), (-1,0,0)]) sage: cone = fan.generating_cone(0) - sage: len(cone.adjacent()) + sage: len(cone.adjacent()) # optional - sage.graphs 1 The result is as before, since we still have:: @@ -2133,7 +2133,7 @@ def adjacent(self): sage: fan = Fan(cones=[(0,1), (1,2), (3,)], ....: rays=[(1,0,0), (0,1,0), (-1,0,0), (0,0,1)]) sage: cone = fan.generating_cone(0) - sage: len(cone.adjacent()) + sage: len(cone.adjacent()) # optional - sage.graphs 0 Since now ``cone`` has smaller dimension than ``fan``, it and its @@ -2176,12 +2176,12 @@ def ambient(self): 3-d cone in 3-d lattice N sage: cone.ambient() is cone True - sage: face = cone.faces(1)[0] - sage: face + sage: face = cone.faces(1)[0] # optional - sage.graphs + sage: face # optional - sage.graphs 1-d face of 3-d cone in 3-d lattice N - sage: face.ambient() + sage: face.ambient() # optional - sage.graphs 3-d cone in 3-d lattice N - sage: face.ambient() is cone + sage: face.ambient() is cone # optional - sage.graphs True """ return self._ambient @@ -2199,7 +2199,7 @@ def ambient_ray_indices(self): sage: quadrant = Cone([(1,0), (0,1)]) sage: quadrant.ambient_ray_indices() (0, 1) - sage: quadrant.facets()[1].ambient_ray_indices() + sage: quadrant.facets()[1].ambient_ray_indices() # optional - sage.graphs (1,) """ return self._ambient_ray_indices @@ -2238,9 +2238,9 @@ def contains(self, *args): False sage: c.contains(1) False - sage: c.contains(1/2, sqrt(3)) + sage: c.contains(1/2, sqrt(3)) # optional - sage.symbolic True - sage: c.contains(-1/2, sqrt(3)) + sage: c.contains(-1/2, sqrt(3)) # optional - sage.symbolic False """ point = flatten(args) @@ -2369,7 +2369,7 @@ def embed(self, cone): 1-d cone in 3-d lattice N sage: ray.ambient_ray_indices() (0,) - sage: ray.adjacent() + sage: ray.adjacent() # optional - sage.graphs () sage: ray.ambient() 1-d cone in 3-d lattice N @@ -2377,22 +2377,22 @@ def embed(self, cone): If we want to operate with this ray as a face of the cone, we need to embed it first:: - sage: e_ray = c.embed(ray) - sage: e_ray + sage: e_ray = c.embed(ray) # optional - sage.graphs + sage: e_ray # optional - sage.graphs 1-d face of 3-d cone in 3-d lattice N - sage: e_ray.rays() + sage: e_ray.rays() # optional - sage.graphs N(0, -1, 1) in 3-d lattice N - sage: e_ray is ray + sage: e_ray is ray # optional - sage.graphs False - sage: e_ray.is_equivalent(ray) + sage: e_ray.is_equivalent(ray) # optional - sage.graphs True - sage: e_ray.ambient_ray_indices() + sage: e_ray.ambient_ray_indices() # optional - sage.graphs (3,) - sage: e_ray.adjacent() + sage: e_ray.adjacent() # optional - sage.graphs (1-d face of 3-d cone in 3-d lattice N, 1-d face of 3-d cone in 3-d lattice N) - sage: e_ray.ambient() + sage: e_ray.ambient() # optional - sage.graphs 3-d cone in 3-d lattice N Not every cone can be embedded into a fixed ambient cone:: @@ -2402,7 +2402,7 @@ def embed(self, cone): ... ValueError: 1-d cone in 3-d lattice N is not a face of 3-d cone in 3-d lattice N! - sage: c.embed(Cone([(1,0,1), (-1,0,1)])) + sage: c.embed(Cone([(1,0,1), (-1,0,1)])) # optional - sage.graphs Traceback (most recent call last): ... ValueError: 2-d cone in 3-d lattice N is not a face @@ -2447,13 +2447,13 @@ def face_lattice(self): Let's take a look at the face lattice of the first quadrant:: sage: quadrant = Cone([(1,0), (0,1)]) - sage: L = quadrant.face_lattice() - sage: L + sage: L = quadrant.face_lattice() # optional - sage.graphs sage.combinat + sage: L # optional - sage.graphs sage.combinat Finite lattice containing 4 elements with distinguished linear extension To see all faces arranged by dimension, you can do this:: - sage: for level in L.level_sets(): print(level) + sage: for level in L.level_sets(): print(level) # optional - sage.graphs sage.combinat [0-d face of 2-d cone in 2-d lattice N] [1-d face of 2-d cone in 2-d lattice N, 1-d face of 2-d cone in 2-d lattice N] @@ -2461,15 +2461,15 @@ def face_lattice(self): For a particular face you can look at its actual rays... :: - sage: face = L.level_sets()[1][0] - sage: face.rays() + sage: face = L.level_sets()[1][0] # optional - sage.graphs sage.combinat + sage: face.rays() # optional - sage.graphs sage.combinat N(1, 0) in 2-d lattice N ... or you can see the index of the ray of the original cone that corresponds to the above one:: - sage: face.ambient_ray_indices() + sage: face.ambient_ray_indices() # optional - sage.graphs sage.combinat (0,) sage: quadrant.ray(0) N(1, 0) @@ -2477,34 +2477,34 @@ def face_lattice(self): An alternative to extracting faces from the face lattice is to use :meth:`faces` method:: - sage: face is quadrant.faces(dim=1)[0] + sage: face is quadrant.faces(dim=1)[0] # optional - sage.graphs sage.combinat True The advantage of working with the face lattice directly is that you can (relatively easily) get faces that are related to the given one:: - sage: face = L.level_sets()[1][0] - sage: D = L.hasse_diagram() - sage: sorted(D.neighbors(face)) + sage: face = L.level_sets()[1][0] # optional - sage.graphs sage.combinat + sage: D = L.hasse_diagram() # optional - sage.graphs sage.combinat + sage: sorted(D.neighbors(face)) # optional - sage.graphs sage.combinat [0-d face of 2-d cone in 2-d lattice N, 2-d cone in 2-d lattice N] However, you can achieve some of this functionality using :meth:`facets`, :meth:`facet_of`, and :meth:`adjacent` methods:: - sage: face = quadrant.faces(1)[0] - sage: face + sage: face = quadrant.faces(1)[0] # optional - sage.graphs + sage: face # optional - sage.graphs 1-d face of 2-d cone in 2-d lattice N - sage: face.rays() + sage: face.rays() # optional - sage.graphs N(1, 0) in 2-d lattice N - sage: face.facets() + sage: face.facets() # optional - sage.graphs (0-d face of 2-d cone in 2-d lattice N,) - sage: face.facet_of() + sage: face.facet_of() # optional - sage.graphs (2-d cone in 2-d lattice N,) - sage: face.adjacent() + sage: face.adjacent() # optional - sage.graphs (1-d face of 2-d cone in 2-d lattice N,) - sage: face.adjacent()[0].rays() + sage: face.adjacent()[0].rays() # optional - sage.graphs N(0, 1) in 2-d lattice N @@ -2513,20 +2513,20 @@ def face_lattice(self): sage: supercone = Cone([(1,2,3,4), (5,6,7,8), ....: (1,2,4,8), (1,3,9,7)]) - sage: supercone.face_lattice() + sage: supercone.face_lattice() # optional - sage.graphs sage.combinat Finite lattice containing 16 elements with distinguished linear extension - sage: supercone.face_lattice().top() + sage: supercone.face_lattice().top() # optional - sage.graphs sage.combinat 4-d cone in 4-d lattice N - sage: cone = supercone.facets()[0] - sage: cone + sage: cone = supercone.facets()[0] # optional - sage.graphs sage.combinat + sage: cone # optional - sage.graphs sage.combinat 3-d face of 4-d cone in 4-d lattice N - sage: cone.face_lattice() + sage: cone.face_lattice() # optional - sage.graphs sage.combinat Finite poset containing 8 elements with distinguished linear extension - sage: cone.face_lattice().bottom() + sage: cone.face_lattice().bottom() # optional - sage.graphs sage.combinat 0-d face of 4-d cone in 4-d lattice N - sage: cone.face_lattice().top() + sage: cone.face_lattice().top() # optional - sage.graphs sage.combinat 3-d face of 4-d cone in 4-d lattice N - sage: cone.face_lattice().top() == cone + sage: cone.face_lattice().top() == cone # optional - sage.graphs sage.combinat True TESTS:: @@ -2542,19 +2542,19 @@ def face_lattice(self): to have non identical face lattices, even if the faces themselves are equal (see :trac:`10998`):: - sage: C1.face_lattice() is C2.face_lattice() + sage: C1.face_lattice() is C2.face_lattice() # optional - sage.graphs sage.combinat False - sage: C1.facets()[0] + sage: C1.facets()[0] # optional - sage.graphs 0-d face of 1-d cone in 2-d lattice N - sage: C2.facets()[0] + sage: C2.facets()[0] # optional - sage.graphs 0-d face of 1-d cone in 2-d lattice N - sage: C1.facets()[0].ambient() is C1 + sage: C1.facets()[0].ambient() is C1 # optional - sage.graphs True - sage: C2.facets()[0].ambient() is C1 + sage: C2.facets()[0].ambient() is C1 # optional - sage.graphs False - sage: C2.facets()[0].ambient() is C2 + sage: C2.facets()[0].ambient() is C2 # optional - sage.graphs True """ if "_face_lattice" not in self.__dict__: @@ -2680,50 +2680,50 @@ def faces(self, dim=None, codim=None): Let's take a look at the faces of the first quadrant:: sage: quadrant = Cone([(1,0), (0,1)]) - sage: quadrant.faces() + sage: quadrant.faces() # optional - sage.graphs ((0-d face of 2-d cone in 2-d lattice N,), (1-d face of 2-d cone in 2-d lattice N, 1-d face of 2-d cone in 2-d lattice N), (2-d cone in 2-d lattice N,)) - sage: quadrant.faces(dim=1) + sage: quadrant.faces(dim=1) # optional - sage.graphs (1-d face of 2-d cone in 2-d lattice N, 1-d face of 2-d cone in 2-d lattice N) - sage: face = quadrant.faces(dim=1)[0] + sage: face = quadrant.faces(dim=1)[0] # optional - sage.graphs Now you can look at the actual rays of this face... :: - sage: face.rays() + sage: face.rays() # optional - sage.graphs N(1, 0) in 2-d lattice N ... or you can see indices of the rays of the original cone that correspond to the above ray:: - sage: face.ambient_ray_indices() + sage: face.ambient_ray_indices() # optional - sage.graphs (0,) sage: quadrant.ray(0) N(1, 0) Note that it is OK to ask for faces of too small or high dimension:: - sage: quadrant.faces(-1) + sage: quadrant.faces(-1) # optional - sage.graphs () - sage: quadrant.faces(3) + sage: quadrant.faces(3) # optional - sage.graphs () In the case of non-strictly convex cones even faces of small non-negative dimension may be missing:: sage: halfplane = Cone([(1,0), (0,1), (-1,0)]) - sage: halfplane.faces(0) + sage: halfplane.faces(0) # optional - sage.graphs () - sage: halfplane.faces() + sage: halfplane.faces() # optional - sage.graphs ((1-d face of 2-d cone in 2-d lattice N,), (2-d cone in 2-d lattice N,)) - sage: plane = Cone([(1,0), (0,1), (-1,-1)]) - sage: plane.faces(1) + sage: plane = Cone([(1,0), (0,1), (-1,-1)]) # optional - sage.graphs + sage: plane.faces(1) # optional - sage.graphs () - sage: plane.faces() + sage: plane.faces() # optional - sage.graphs ((2-d cone in 2-d lattice N,),) TESTS: @@ -2732,7 +2732,7 @@ def faces(self, dim=None, codim=None): dimension of the ambient space work as expected (see :trac:`9188`):: sage: c = Cone([(1,1,1,3),(1,-1,1,3),(-1,-1,1,3)]) - sage: c.faces() + sage: c.faces() # optional - sage.graphs ((0-d face of 3-d cone in 4-d lattice N,), (1-d face of 3-d cone in 4-d lattice N, 1-d face of 3-d cone in 4-d lattice N, @@ -2747,14 +2747,14 @@ def faces(self, dim=None, codim=None): sage: cone = toric_varieties.dP8().fan().generating_cone(0); cone # optional - palp 2-d cone of Rational polyhedral fan in 2-d lattice N - sage: for f in cone.facets(): print(f.rays()) # optional - palp + sage: for f in cone.facets(): print(f.rays()) # optional - palp sage.graphs N(1, 1) in 2-d lattice N N(0, 1) in 2-d lattice N - sage: len(cone.faces()) # optional - palp + sage: len(cone.faces()) # optional - palp sage.graphs 3 - sage: for f in cone.facets(): print(f.rays()) # optional - palp + sage: for f in cone.facets(): print(f.rays()) # optional - palp sage.graphs N(1, 1) in 2-d lattice N N(0, 1) @@ -2901,25 +2901,25 @@ def facet_of(self): EXAMPLES:: sage: octant = Cone([(1,0,0), (0,1,0), (0,0,1)]) - sage: octant.facet_of() + sage: octant.facet_of() # optional - sage.graphs () - sage: one_face = octant.faces(1)[0] - sage: len(one_face.facet_of()) + sage: one_face = octant.faces(1)[0] # optional - sage.graphs + sage: len(one_face.facet_of()) # optional - sage.graphs 2 - sage: one_face.facet_of()[1] + sage: one_face.facet_of()[1] # optional - sage.graphs 2-d face of 3-d cone in 3-d lattice N While fan is the top element of its own cone lattice, which is a variant of a face lattice, we do not refer to cones as its facets:: sage: fan = Fan([octant]) - sage: fan.generating_cone(0).facet_of() + sage: fan.generating_cone(0).facet_of() # optional - sage.graphs () Subcones of generating cones work as before:: - sage: one_cone = fan(1)[0] - sage: len(one_cone.facet_of()) + sage: one_cone = fan(1)[0] # optional - sage.graphs + sage: len(one_cone.facet_of()) # optional - sage.graphs 2 """ L = self._ambient._face_lattice_function() @@ -2938,7 +2938,7 @@ def facets(self): EXAMPLES:: sage: quadrant = Cone([(1,0), (0,1)]) - sage: quadrant.facets() + sage: quadrant.facets() # optional - sage.graphs (1-d face of 2-d cone in 2-d lattice N, 1-d face of 2-d cone in 2-d lattice N) """ @@ -3257,19 +3257,19 @@ def is_isomorphic(self, other): We check that :trac:`18613` is fixed:: sage: K = cones.trivial(0) - sage: K.is_isomorphic(K) + sage: K.is_isomorphic(K) # optional - sage.graphs True sage: K = cones.trivial(1) - sage: K.is_isomorphic(K) + sage: K.is_isomorphic(K) # optional - sage.graphs True sage: K = cones.trivial(2) - sage: K.is_isomorphic(K) + sage: K.is_isomorphic(K) # optional - sage.graphs True A random (strictly convex) cone is isomorphic to itself:: sage: K = random_cone(max_ambient_dim=6, strictly_convex=True) - sage: K.is_isomorphic(K) + sage: K.is_isomorphic(K) # optional - sage.graphs True """ if self.is_strictly_convex() and other.is_strictly_convex(): @@ -3754,7 +3754,7 @@ def solid_restriction(self): the original:: sage: K = random_cone(max_ambient_dim=6) - sage: len(K.solid_restriction().facets()) == len(K.facets()) + sage: len(K.solid_restriction().facets()) == len(K.facets()) # optional - sage.graphs True """ if self.is_solid(): @@ -3916,16 +3916,16 @@ def sublattice_quotient(self, *args, **kwds): EXAMPLES:: sage: C2_Z2 = Cone([(1,0),(1,2)]) # C^2/Z_2 - sage: c1, c2 = C2_Z2.facets() - sage: c2.sublattice_quotient() + sage: c1, c2 = C2_Z2.facets() # optional - sage.graphs + sage: c2.sublattice_quotient() # optional - sage.graphs 1-d lattice, quotient of 2-d lattice N by Sublattice sage: N = C2_Z2.lattice() sage: n = N(1,1) - sage: n_bar = c2.sublattice_quotient(n); n_bar + sage: n_bar = c2.sublattice_quotient(n); n_bar # optional - sage.graphs N[1, 1] - sage: n_bar.lift() + sage: n_bar.lift() # optional - sage.graphs N(1, 1) - sage: vector(n_bar) + sage: vector(n_bar) # optional - sage.graphs (-1) """ if "_sublattice_quotient" not in self.__dict__: @@ -3968,10 +3968,10 @@ def sublattice_complement(self, *args, **kwds): EXAMPLES:: sage: C2_Z2 = Cone([(1,0),(1,2)]) # C^2/Z_2 - sage: c1, c2 = C2_Z2.facets() - sage: c2.sublattice() + sage: c1, c2 = C2_Z2.facets() # optional - sage.graphs + sage: c2.sublattice() # optional - sage.graphs Sublattice - sage: c2.sublattice_complement() + sage: c2.sublattice_complement() # optional - sage.graphs Sublattice A more complicated example:: @@ -4200,27 +4200,27 @@ def relative_orthogonal_quotient(self, supercone): sage: rho = Cone([(1,1,1,3),(1,-1,1,3),(-1,-1,1,3),(-1,1,1,3)]) sage: rho.orthogonal_sublattice() Sublattice - sage: sigma = rho.facets()[1] - sage: sigma.orthogonal_sublattice() + sage: sigma = rho.facets()[1] # optional - sage.graphs + sage: sigma.orthogonal_sublattice() # optional - sage.graphs Sublattice - sage: sigma.is_face_of(rho) + sage: sigma.is_face_of(rho) # optional - sage.graphs True - sage: Q = sigma.relative_orthogonal_quotient(rho); Q + sage: Q = sigma.relative_orthogonal_quotient(rho); Q # optional - sage.graphs 1-d lattice, quotient of Sublattice by Sublattice - sage: Q.gens() + sage: Q.gens() # optional - sage.graphs (M[0, 1, 1, 0],) Different codimension:: sage: rho = Cone([[1,-1,1,3],[-1,-1,1,3]]) - sage: sigma = rho.facets()[0] - sage: sigma.orthogonal_sublattice() + sage: sigma = rho.facets()[0] # optional - sage.graphs + sage: sigma.orthogonal_sublattice() # optional - sage.graphs Sublattice - sage: rho.orthogonal_sublattice() + sage: rho.orthogonal_sublattice() # optional - sage.graphs Sublattice - sage: sigma.relative_orthogonal_quotient(rho).gens() + sage: sigma.relative_orthogonal_quotient(rho).gens() # optional - sage.graphs (M[-1, 0, -2, 1],) Sign choice in the codimension one case:: @@ -5735,17 +5735,17 @@ def positive_operators_gens(self, K2=None): sage: K = random_cone(max_ambient_dim=3) sage: L = ToricLattice(K.lattice_dim()**2) - sage: p = SymmetricGroup(K.lattice_dim()).random_element().matrix() - sage: pK = Cone(( p*k for k in K ), K.lattice(), check=False) - sage: pi_gens = pK.positive_operators_gens() - sage: actual = Cone((g.list() for g in pi_gens), + sage: p = SymmetricGroup(K.lattice_dim()).random_element().matrix() # optional - sage.groups + sage: pK = Cone(( p*k for k in K ), K.lattice(), check=False) # optional - sage.groups + sage: pi_gens = pK.positive_operators_gens() # optional - sage.groups + sage: actual = Cone((g.list() for g in pi_gens), # optional - sage.groups ....: lattice=L, ....: check=False) sage: pi_gens = K.positive_operators_gens() - sage: expected = Cone(((p*g*p.inverse()).list() for g in pi_gens), + sage: expected = Cone(((p*g*p.inverse()).list() for g in pi_gens), # optional - sage.groups ....: lattice=L, ....: check=False) - sage: actual.is_equivalent(expected) + sage: actual.is_equivalent(expected) # optional - sage.groups True An operator is positive from one cone to another if and only if @@ -6058,17 +6058,17 @@ def cross_positive_operators_gens(self): sage: K = random_cone(max_ambient_dim=3) sage: L = ToricLattice(K.lattice_dim()**2) - sage: p = SymmetricGroup(K.lattice_dim()).random_element().matrix() - sage: pK = Cone(( p*k for k in K ), K.lattice(), check=False) - sage: cp_gens = pK.cross_positive_operators_gens() - sage: actual = Cone((g.list() for g in cp_gens), + sage: p = SymmetricGroup(K.lattice_dim()).random_element().matrix() # optional - sage.groups + sage: pK = Cone(( p*k for k in K ), K.lattice(), check=False) # optional - sage.groups + sage: cp_gens = pK.cross_positive_operators_gens() # optional - sage.groups + sage: actual = Cone((g.list() for g in cp_gens), # optional - sage.groups ....: lattice=L, ....: check=False) sage: cp_gens = K.cross_positive_operators_gens() - sage: expected = Cone(((p*g*p.inverse()).list() for g in cp_gens), + sage: expected = Cone(((p*g*p.inverse()).list() for g in cp_gens), # optional - sage.groups ....: lattice=L, ....: check=False) - sage: actual.is_equivalent(expected) + sage: actual.is_equivalent(expected) # optional - sage.groups True An operator is cross-positive on a cone if and only if its diff --git a/src/sage/geometry/fan.py b/src/sage/geometry/fan.py index cd8041262a4..3fe3039efab 100644 --- a/src/sage/geometry/fan.py +++ b/src/sage/geometry/fan.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.graphs, sage.combinat r""" Rational polyhedral fans diff --git a/src/sage/geometry/fan_morphism.py b/src/sage/geometry/fan_morphism.py index e94e2cce8c0..abcdd4bcd8d 100644 --- a/src/sage/geometry/fan_morphism.py +++ b/src/sage/geometry/fan_morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs, sage.combinat r""" Morphisms between toric lattices compatible with fans diff --git a/src/sage/geometry/hasse_diagram.py b/src/sage/geometry/hasse_diagram.py index eeed5f560d9..eae47c2127e 100644 --- a/src/sage/geometry/hasse_diagram.py +++ b/src/sage/geometry/hasse_diagram.py @@ -104,11 +104,10 @@ def lattice_from_incidences(atom_to_coatoms, coatom_to_atoms, and we can compute the lattice as :: sage: from sage.geometry.cone import lattice_from_incidences - sage: L = lattice_from_incidences( - ....: atom_to_coatoms, coatom_to_atoms) - sage: L + sage: L = lattice_from_incidences(atom_to_coatoms, coatom_to_atoms) # optional - sage.graphs + sage: L # optional - sage.graphs Finite lattice containing 8 elements with distinguished linear extension - sage: for level in L.level_sets(): print(level) + sage: for level in L.level_sets(): print(level) # optional - sage.graphs [((), (0, 1, 2))] [((0,), (0, 1)), ((1,), (0, 2)), ((2,), (1, 2))] [((0, 1), (0,)), ((0, 2), (1,)), ((1, 2), (2,))] diff --git a/src/sage/geometry/hyperplane_arrangement/arrangement.py b/src/sage/geometry/hyperplane_arrangement/arrangement.py index b740ef79956..20358546a56 100644 --- a/src/sage/geometry/hyperplane_arrangement/arrangement.py +++ b/src/sage/geometry/hyperplane_arrangement/arrangement.py @@ -66,7 +66,7 @@ Number fields are also possible:: - sage: x = var('x') + sage: x = polygen(QQ, 'x') sage: NF. = NumberField(x**4 - 5*x**2 + 5, embedding=1.90) # optional - sage.rings.number_field sage: H. = HyperplaneArrangements(NF) # optional - sage.rings.number_field sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1], # optional - sage.rings.number_field @@ -423,8 +423,8 @@ def _first_ngens(self, n): EXAMPLES:: - sage: a. = hyperplane_arrangements.braid(3) # indirect doctest - sage: (x, y) == a._first_ngens(2) + sage: a. = hyperplane_arrangements.braid(3) # indirect doctest # optional - sage.graphs + sage: (x, y) == a._first_ngens(2) # optional - sage.graphs True """ return self.parent()._first_ngens(n) diff --git a/src/sage/geometry/hyperplane_arrangement/hyperplane.py b/src/sage/geometry/hyperplane_arrangement/hyperplane.py index c431291a3a6..ab1559a9f5c 100644 --- a/src/sage/geometry/hyperplane_arrangement/hyperplane.py +++ b/src/sage/geometry/hyperplane_arrangement/hyperplane.py @@ -26,7 +26,7 @@ (3, 2, -5) sage: h.constant_term() -7 - sage: h.change_ring(GF(3)) + sage: h.change_ring(GF(3)) # optional - sage.libs.pari Hyperplane 0*x + 2*y + z + 2 sage: h.point() (21/38, 7/19, -35/38) @@ -238,9 +238,9 @@ def _normal_pivot(self): sage: (x + 3/2*y - 2*z)._normal_pivot() 2 - sage: H. = HyperplaneArrangements(GF(5)) - sage: V = H.ambient_space() - sage: (x + 3*y - 4*z)._normal_pivot() + sage: H. = HyperplaneArrangements(GF(5)) # optional - sage.libs.pari + sage: V = H.ambient_space() # optional - sage.libs.pari + sage: (x + 3*y - 4*z)._normal_pivot() # optional - sage.libs.pari 1 """ try: @@ -397,16 +397,16 @@ def point(self): sage: h.point() in h True - sage: H. = HyperplaneArrangements(GF(3)) - sage: h = 2*x + y + z + 1 - sage: h.point() + sage: H. = HyperplaneArrangements(GF(3)) # optional - sage.libs.pari + sage: h = 2*x + y + z + 1 # optional - sage.libs.pari + sage: h.point() # optional - sage.libs.pari (1, 0, 0) - sage: h.point().base_ring() + sage: h.point().base_ring() # optional - sage.libs.pari Finite Field of size 3 - sage: H. = HyperplaneArrangements(GF(3)) - sage: h = x + y + z + 1 - sage: h.point() + sage: H. = HyperplaneArrangements(GF(3)) # optional - sage.libs.pari + sage: h = x + y + z + 1 # optional - sage.libs.pari + sage: h.point() # optional - sage.libs.pari (2, 0, 0) """ P = self.parent() @@ -552,21 +552,21 @@ def primitive(self, signed=True): Check that :trac:`30078` is fixed:: - sage: R. = QuadraticField(2) - sage: H. = HyperplaneArrangements(base_ring=R) - sage: B = H([1,1,0], [2,2,0], [sqrt2,sqrt2,0]) - sage: B + sage: R. = QuadraticField(2) # optional - sage.rings.number_field + sage: H. = HyperplaneArrangements(base_ring=R) # optional - sage.rings.number_field + sage: B = H([1,1,0], [2,2,0], [sqrt2,sqrt2,0]) # optional - sage.rings.number_field + sage: B # optional - sage.rings.number_field Arrangement Check that :trac:`30749` is fixed:: - sage: tau = (1+AA(5).sqrt()) / 2 - sage: ncn = [[2*tau+1,2*tau,tau],[2*tau+2,2*tau+1,tau+1]] - sage: ncn += [[tau+1,tau+1,tau],[2*tau,2*tau,tau],[tau+1,tau+1,1]] - sage: ncn += [[1,1,1],[1,1,0],[0,1,0],[1,0,0],[tau+1,tau,tau]] - sage: H = HyperplaneArrangements(AA,names='xyz') - sage: A = H([[0]+v for v in ncn]) - sage: A.n_regions() + sage: tau = (1+AA(5).sqrt()) / 2 # optional - sage.rings.number_field + sage: ncn = [[2*tau+1,2*tau,tau],[2*tau+2,2*tau+1,tau+1]] # optional - sage.rings.number_field + sage: ncn += [[tau+1,tau+1,tau],[2*tau,2*tau,tau],[tau+1,tau+1,1]] # optional - sage.rings.number_field + sage: ncn += [[1,1,1],[1,1,0],[0,1,0],[1,0,0],[tau+1,tau,tau]] # optional - sage.rings.number_field + sage: H = HyperplaneArrangements(AA,names='xyz') # optional - sage.rings.number_field + sage: A = H([[0]+v for v in ncn]) # optional - sage.rings.number_field + sage: A.n_regions() # optional - sage.rings.number_field 60 """ from sage.rings.rational_field import QQ diff --git a/src/sage/geometry/hyperplane_arrangement/library.py b/src/sage/geometry/hyperplane_arrangement/library.py index 37da03eda7c..228ae024914 100644 --- a/src/sage/geometry/hyperplane_arrangement/library.py +++ b/src/sage/geometry/hyperplane_arrangement/library.py @@ -486,7 +486,7 @@ def semiorder(self, n, K=QQ, names=None): EXAMPLES:: - sage: hyperplane_arrangements.semiorder(4) + sage: hyperplane_arrangements.semiorder(4) # optional - sage.combinat Arrangement of 12 hyperplanes of dimension 4 and rank 3 TESTS:: @@ -547,29 +547,29 @@ def Shi(self, data, K=QQ, names=None, m=1): EXAMPLES:: - sage: hyperplane_arrangements.Shi(4) + sage: hyperplane_arrangements.Shi(4) # optional - sage.combinat Arrangement of 12 hyperplanes of dimension 4 and rank 3 - sage: hyperplane_arrangements.Shi("A3") + sage: hyperplane_arrangements.Shi("A3") # optional - sage.combinat Arrangement of 12 hyperplanes of dimension 4 and rank 3 - sage: hyperplane_arrangements.Shi("A3",m=2) + sage: hyperplane_arrangements.Shi("A3", m=2) # optional - sage.combinat Arrangement of 24 hyperplanes of dimension 4 and rank 3 - sage: hyperplane_arrangements.Shi("B4") + sage: hyperplane_arrangements.Shi("B4") # optional - sage.combinat Arrangement of 32 hyperplanes of dimension 4 and rank 4 - sage: hyperplane_arrangements.Shi("B4",m=3) + sage: hyperplane_arrangements.Shi("B4", m=3) # optional - sage.combinat Arrangement of 96 hyperplanes of dimension 4 and rank 4 - sage: hyperplane_arrangements.Shi("C3") + sage: hyperplane_arrangements.Shi("C3") # optional - sage.combinat Arrangement of 18 hyperplanes of dimension 3 and rank 3 - sage: hyperplane_arrangements.Shi("D4",m=3) + sage: hyperplane_arrangements.Shi("D4", m=3) # optional - sage.combinat Arrangement of 72 hyperplanes of dimension 4 and rank 4 - sage: hyperplane_arrangements.Shi("E6") + sage: hyperplane_arrangements.Shi("E6") # optional - sage.combinat Arrangement of 72 hyperplanes of dimension 8 and rank 6 - sage: hyperplane_arrangements.Shi("E6",m=2) + sage: hyperplane_arrangements.Shi("E6", m=2) # optional - sage.combinat Arrangement of 144 hyperplanes of dimension 8 and rank 6 If the Cartan type is not crystallographic, the Shi arrangement is not defined:: - sage: hyperplane_arrangements.Shi("H4") + sage: hyperplane_arrangements.Shi("H4") # optional - sage.combinat Traceback (most recent call last): ... NotImplementedError: Shi arrangements are not defined for non crystallographic Cartan types @@ -577,36 +577,36 @@ def Shi(self, data, K=QQ, names=None, m=1): The characteristic polynomial is pre-computed using the results of [Ath1996]_:: - sage: hyperplane_arrangements.Shi("A3").characteristic_polynomial() + sage: hyperplane_arrangements.Shi("A3").characteristic_polynomial() # optional - sage.combinat x^4 - 12*x^3 + 48*x^2 - 64*x - sage: hyperplane_arrangements.Shi("A3",m=2).characteristic_polynomial() + sage: hyperplane_arrangements.Shi("A3", m=2).characteristic_polynomial() # optional - sage.combinat x^4 - 24*x^3 + 192*x^2 - 512*x - sage: hyperplane_arrangements.Shi("C3").characteristic_polynomial() + sage: hyperplane_arrangements.Shi("C3").characteristic_polynomial() # optional - sage.combinat x^3 - 18*x^2 + 108*x - 216 - sage: hyperplane_arrangements.Shi("E6").characteristic_polynomial() + sage: hyperplane_arrangements.Shi("E6").characteristic_polynomial() # optional - sage.combinat x^8 - 72*x^7 + 2160*x^6 - 34560*x^5 + 311040*x^4 - 1492992*x^3 + 2985984*x^2 - sage: hyperplane_arrangements.Shi("B4",m=3).characteristic_polynomial() + sage: hyperplane_arrangements.Shi("B4", m=3).characteristic_polynomial() # optional - sage.combinat x^4 - 96*x^3 + 3456*x^2 - 55296*x + 331776 TESTS:: - sage: h = hyperplane_arrangements.Shi(4) - sage: h.characteristic_polynomial() + sage: h = hyperplane_arrangements.Shi(4) # optional - sage.combinat + sage: h.characteristic_polynomial() # optional - sage.combinat x^4 - 12*x^3 + 48*x^2 - 64*x - sage: h.characteristic_polynomial.clear_cache() # long time - sage: h.characteristic_polynomial() # long time + sage: h.characteristic_polynomial.clear_cache() # long time # optional - sage.combinat + sage: h.characteristic_polynomial() # long time # optional - sage.combinat x^4 - 12*x^3 + 48*x^2 - 64*x - sage: h = hyperplane_arrangements.Shi("A3",m=2) - sage: h.characteristic_polynomial() + sage: h = hyperplane_arrangements.Shi("A3", m=2) # optional - sage.combinat + sage: h.characteristic_polynomial() # optional - sage.combinat x^4 - 24*x^3 + 192*x^2 - 512*x - sage: h.characteristic_polynomial.clear_cache() - sage: h.characteristic_polynomial() + sage: h.characteristic_polynomial.clear_cache() # optional - sage.combinat + sage: h.characteristic_polynomial() # optional - sage.combinat x^4 - 24*x^3 + 192*x^2 - 512*x - sage: h = hyperplane_arrangements.Shi("B3",m=3) - sage: h.characteristic_polynomial() + sage: h = hyperplane_arrangements.Shi("B3", m=3) # optional - sage.combinat + sage: h.characteristic_polynomial() # optional - sage.combinat x^3 - 54*x^2 + 972*x - 5832 - sage: h.characteristic_polynomial.clear_cache() - sage: h.characteristic_polynomial() + sage: h.characteristic_polynomial.clear_cache() # optional - sage.combinat + sage: h.characteristic_polynomial() # optional - sage.combinat x^3 - 54*x^2 + 972*x - 5832 """ if data in NN: diff --git a/src/sage/geometry/hyperplane_arrangement/plot.py b/src/sage/geometry/hyperplane_arrangement/plot.py index 05176797415..f900403f095 100644 --- a/src/sage/geometry/hyperplane_arrangement/plot.py +++ b/src/sage/geometry/hyperplane_arrangement/plot.py @@ -114,7 +114,6 @@ lazy_import("sage.plot.text", "text") lazy_import("sage.plot.point", "point") lazy_import("sage.plot.plot", "parametric_plot") -from sage.symbolic.ring import SR def plot(hyperplane_arrangement, **kwds): @@ -144,8 +143,8 @@ def plot(hyperplane_arrangement, **kwds): EXAMPLES:: - sage: B = hyperplane_arrangements.semiorder(4) - sage: B.plot() # optional - sage.plot + sage: B = hyperplane_arrangements.semiorder(4) # optional - sage.combinat + sage: B.plot() # optional - sage.combinat sage.plot Displaying the essentialization. Graphics3d Object """ @@ -420,6 +419,7 @@ def plot_hyperplane(hyperplane, **kwds): elif hyperplane.dimension() == 1: # a line in the plane pnt = hyperplane.point() w = hyperplane.linear_part().matrix() + from sage.symbolic.ring import SR t = SR.var('t') if ranges_set: if isinstance(ranges, (list, tuple)): @@ -440,6 +440,7 @@ def plot_hyperplane(hyperplane, **kwds): elif hyperplane.dimension() == 2: # a plane in 3-space pnt = hyperplane.point() w = hyperplane.linear_part().matrix() + from sage.symbolic.ring import SR s, t = SR.var('s t') if ranges_set: if isinstance(ranges, (list, tuple)): @@ -484,22 +485,22 @@ def legend_3d(hyperplane_arrangement, hyperplane_colors, length): EXAMPLES:: - sage: a = hyperplane_arrangements.semiorder(3) + sage: a = hyperplane_arrangements.semiorder(3) # optional - sage.combinat sage: from sage.geometry.hyperplane_arrangement.plot import legend_3d - sage: legend_3d(a, list(colors.values())[:6],length='long') + sage: legend_3d(a, list(colors.values())[:6],length='long') # optional - sage.combinat sage.plot Graphics object consisting of 6 graphics primitives - sage: b = hyperplane_arrangements.semiorder(4) - sage: c = b.essentialization() - sage: legend_3d(c, list(colors.values())[:12], length='long') + sage: b = hyperplane_arrangements.semiorder(4) # optional - sage.combinat + sage: c = b.essentialization() # optional - sage.combinat + sage: legend_3d(c, list(colors.values())[:12], length='long') # optional - sage.combinat sage.plot Graphics object consisting of 12 graphics primitives - sage: legend_3d(c, list(colors.values())[:12], length='short') + sage: legend_3d(c, list(colors.values())[:12], length='short') # optional - sage.plot Graphics object consisting of 12 graphics primitives - sage: p = legend_3d(c, list(colors.values())[:12], length='short') - sage: p.set_legend_options(ncol=4) - sage: type(p) + sage: p = legend_3d(c, list(colors.values())[:12], length='short') # optional - sage.plot + sage: p.set_legend_options(ncol=4) # optional - sage.plot + sage: type(p) # optional - sage.plot """ if hyperplane_arrangement.dimension() != 3: diff --git a/src/sage/geometry/integral_points.pxi b/src/sage/geometry/integral_points.pxi index e5ddce891a1..4c19ac6e9ce 100644 --- a/src/sage/geometry/integral_points.pxi +++ b/src/sage/geometry/integral_points.pxi @@ -474,8 +474,8 @@ cpdef rectangular_box_points(list box_min, list box_max, Long ints and non-integral polyhedra are explicitly allowed:: - sage: polytope = Polyhedron([[1], [10*pi.n()]], base_ring=RDF) - sage: len( rectangular_box_points([-100], [100], polytope) ) + sage: polytope = Polyhedron([[1], [10*pi.n()]], base_ring=RDF) # optional - sage.symbolic + sage: len(rectangular_box_points([-100], [100], polytope)) # optional - sage.symbolic 31 sage: halfplane = Polyhedron(ieqs=[(-1,1,0)]) @@ -488,15 +488,15 @@ cpdef rectangular_box_points(list box_min, list box_max, Using a PPL polyhedron:: - sage: from ppl import Variable, Generator_System, C_Polyhedron, point - sage: gs = Generator_System() - sage: x = Variable(0); y = Variable(1); z = Variable(2) - sage: gs.insert(point(0*x + 1*y + 0*z)) - sage: gs.insert(point(0*x + 1*y + 3*z)) - sage: gs.insert(point(3*x + 1*y + 0*z)) - sage: gs.insert(point(3*x + 1*y + 3*z)) - sage: poly = C_Polyhedron(gs) - sage: rectangular_box_points([0]*3, [3]*3, poly) + sage: from ppl import Variable, Generator_System, C_Polyhedron, point # optional - pplpy + sage: gs = Generator_System() # optional - pplpy + sage: x = Variable(0); y = Variable(1); z = Variable(2) # optional - pplpy + sage: gs.insert(point(0*x + 1*y + 0*z)) # optional - pplpy + sage: gs.insert(point(0*x + 1*y + 3*z)) # optional - pplpy + sage: gs.insert(point(3*x + 1*y + 0*z)) # optional - pplpy + sage: gs.insert(point(3*x + 1*y + 3*z)) # optional - pplpy + sage: poly = C_Polyhedron(gs) # optional - pplpy + sage: rectangular_box_points([0]*3, [3]*3, poly) # optional - pplpy ((0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 1, 3), (1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 1, 3), (2, 1, 0), (2, 1, 1), (2, 1, 2), (2, 1, 3), (3, 1, 0), (3, 1, 1), (3, 1, 2), (3, 1, 3)) @@ -739,7 +739,7 @@ cdef class Inequality_generic: EXAMPLES:: sage: from sage.geometry.integral_points import Inequality_generic - sage: Inequality_generic([2*pi,sqrt(3),7/2], -5.5) + sage: Inequality_generic([2 * pi, sqrt(3), 7/2], -5.5) # optional - sage.symbolic generic: (2*pi, sqrt(3), 7/2) x + -5.50000000000000 >= 0 """ @@ -761,7 +761,7 @@ cdef class Inequality_generic: EXAMPLES:: sage: from sage.geometry.integral_points import Inequality_generic - sage: Inequality_generic([2*pi,sqrt(3),7/2], -5.5) + sage: Inequality_generic([2 * pi, sqrt(3), 7/2], -5.5) # optional - sage.symbolic generic: (2*pi, sqrt(3), 7/2) x + -5.50000000000000 >= 0 """ self.A = A @@ -1131,16 +1131,16 @@ cdef class InequalityCollection: EXAMPLES:: - sage: from ppl import Variable, Generator_System, C_Polyhedron, point - sage: gs = Generator_System() - sage: x = Variable(0); y = Variable(1); z = Variable(2) - sage: gs.insert(point(0*x + 0*y + 1*z)) - sage: gs.insert(point(0*x + 3*y + 1*z)) - sage: gs.insert(point(3*x + 0*y + 1*z)) - sage: gs.insert(point(3*x + 3*y + 1*z)) - sage: poly = C_Polyhedron(gs) - sage: from sage.geometry.integral_points import InequalityCollection - sage: InequalityCollection(poly, [0,2,1], [0]*3, [3]*3 ) + sage: from ppl import Variable, Generator_System, C_Polyhedron, point # optional - pplpy + sage: gs = Generator_System() # optional - pplpy + sage: x = Variable(0); y = Variable(1); z = Variable(2) # optional - pplpy + sage: gs.insert(point(0*x + 0*y + 1*z)) # optional - pplpy + sage: gs.insert(point(0*x + 3*y + 1*z)) # optional - pplpy + sage: gs.insert(point(3*x + 0*y + 1*z)) # optional - pplpy + sage: gs.insert(point(3*x + 3*y + 1*z)) # optional - pplpy + sage: poly = C_Polyhedron(gs) # optional - pplpy + sage: from sage.geometry.integral_points import InequalityCollection # optional - pplpy + sage: InequalityCollection(poly, [0,2,1], [0]*3, [3]*3 ) # optional - pplpy The collection of inequalities integer: (0, 1, 0) x + -1 >= 0 integer: (0, -1, 0) x + 1 >= 0 diff --git a/src/sage/geometry/lattice_polytope.py b/src/sage/geometry/lattice_polytope.py index 778e7934d3f..c99b3b0bff5 100644 --- a/src/sage/geometry/lattice_polytope.py +++ b/src/sage/geometry/lattice_polytope.py @@ -295,7 +295,7 @@ def LatticePolytope(data, compute_vertices=True, n=0, lattice=None): sage: p.points() Empty collection in 3-d lattice M - sage: p.faces() + sage: p.faces() # optional - sage.graphs ((-1-d lattice polytope in 3-d lattice M,),) """ if isinstance(data, LatticePolytopeClass): @@ -765,15 +765,15 @@ def _compute_facets(self): sage: p = LatticePolytope([], lattice=ToricLattice(3).dual()); p -1-d lattice polytope in 3-d lattice M - sage: a = p.faces()[0][0] + sage: a = p.faces()[0][0] # optional - sage.graphs sage: p = LatticePolytope([], lattice=ToricLattice(3).dual()); p -1-d lattice polytope in 3-d lattice M - sage: a = p.faces()[0][0]; a + sage: a = p.faces()[0][0]; a # optional - sage.graphs -1-d lattice polytope in 3-d lattice M - sage: a.facet_normals() + sage: a.facet_normals() # optional - sage.graphs Empty collection in 3-d lattice N - sage: a + sage: a # optional - sage.graphs -1-d lattice polytope in 3-d lattice M """ assert not hasattr(self, "_facet_normals") @@ -1335,7 +1335,7 @@ def _sort_faces(self, faces): sage: o = lattice_polytope.cross_polytope(3) sage: # indirect doctest - sage: for i, face in enumerate(o.faces(0)): + sage: for i, face in enumerate(o.faces(0)): # optional - sage.graphs ....: if face.vertex(0) != o.vertex(i): ....: print("Wrong order!") """ @@ -1380,10 +1380,10 @@ def adjacent(self): EXAMPLES:: sage: o = lattice_polytope.cross_polytope(3) - sage: o.adjacent() + sage: o.adjacent() # optional - sage.graphs () - sage: face = o.faces(1)[0] - sage: face.adjacent() + sage: face = o.faces(1)[0] # optional - sage.graphs + sage: face.adjacent() # optional - sage.graphs (1-d face of 3-d reflexive polytope in 3-d lattice M, 1-d face of 3-d reflexive polytope in 3-d lattice M, 1-d face of 3-d reflexive polytope in 3-d lattice M, @@ -1505,12 +1505,12 @@ def ambient(self): 3-d reflexive polytope in 3-d lattice M sage: o.ambient() is o True - sage: face = o.faces(1)[0] - sage: face + sage: face = o.faces(1)[0] # optional - sage.graphs + sage: face # optional - sage.graphs 1-d face of 3-d reflexive polytope in 3-d lattice M - sage: face.ambient() + sage: face.ambient() # optional - sage.graphs 3-d reflexive polytope in 3-d lattice M - sage: face.ambient() is o + sage: face.ambient() is o # optional - sage.graphs True """ return self._ambient @@ -1533,14 +1533,14 @@ def ambient_facet_indices(self): But each of its other faces is contained in one or more facets:: - sage: face = o.faces(1)[0] - sage: face.ambient_facet_indices() + sage: face = o.faces(1)[0] # optional - sage.graphs + sage: face.ambient_facet_indices() # optional - sage.graphs (4, 5) - sage: face.vertices() + sage: face.vertices() # optional - sage.graphs M(1, 0, 0), M(0, 1, 0) in 3-d lattice M - sage: o.facets()[face.ambient_facet_indices()[0]].vertices() + sage: o.facets()[face.ambient_facet_indices()[0]].vertices() # optional - sage.graphs M(1, 0, 0), M(0, 1, 0), M(0, 0, -1) @@ -1561,10 +1561,10 @@ def ambient_point_indices(self): EXAMPLES:: sage: cube = lattice_polytope.cross_polytope(3).polar() - sage: face = cube.facets()[0] - sage: face.ambient_point_indices() # optional - palp + sage: face = cube.facets()[0] # optional - sage.graphs + sage: face.ambient_point_indices() # optional - palp # optional - sage.graphs (4, 5, 6, 7, 8, 9, 10, 11, 12) - sage: cube.points(face.ambient_point_indices()) == face.points() # optional - palp + sage: cube.points(face.ambient_point_indices()) == face.points() # optional - palp # optional - sage.graphs True """ if self._ambient is self: @@ -1587,10 +1587,10 @@ def ambient_ordered_point_indices(self): EXAMPLES:: sage: cube = lattice_polytope.cross_polytope(3).polar() - sage: face = cube.facets()[0] - sage: face.ambient_ordered_point_indices() # optional - palp + sage: face = cube.facets()[0] # optional - sage.graphs + sage: face.ambient_ordered_point_indices() # optional - palp # optional - sage.graphs (5, 8, 4, 9, 10, 11, 6, 12, 7) - sage: cube.points(face.ambient_ordered_point_indices()) # optional - palp + sage: cube.points(face.ambient_ordered_point_indices()) # optional - palp # optional - sage.graphs N(-1, -1, -1), N(-1, -1, 0), N(-1, -1, 1), @@ -1621,8 +1621,8 @@ def ambient_vertex_indices(self): sage: o = lattice_polytope.cross_polytope(3) sage: o.ambient_vertex_indices() (0, 1, 2, 3, 4, 5) - sage: face = o.faces(1)[0] - sage: face.ambient_vertex_indices() + sage: face = o.faces(1)[0] # optional - sage.graphs + sage: face.ambient_vertex_indices() # optional - sage.graphs (0, 1) """ return self._ambient_vertex_indices @@ -1657,13 +1657,13 @@ def boundary_point_indices(self): For an edge the boundary is formed by the end points:: - sage: face = square.edges()[0] - sage: face.points() + sage: face = square.edges()[0] # optional - sage.graphs + sage: face.points() # optional - sage.graphs N(-1, -1), N(-1, 1), N(-1, 0) in 2-d lattice N - sage: face.boundary_point_indices() + sage: face.boundary_point_indices() # optional - sage.graphs (0, 1) """ return tuple(i @@ -1696,8 +1696,8 @@ def boundary_points(self): For an edge the boundary is formed by the end points:: - sage: face = square.edges()[0] - sage: face.boundary_points() + sage: face = square.edges()[0] # optional - sage.graphs + sage: face.boundary_points() # optional - sage.graphs N(-1, -1), N(-1, 1) in 2-d lattice N @@ -1794,7 +1794,7 @@ def distances(self, point=None): sage: o.distances([1,2,3/2]) (-3/2, 5/2, 11/2, 3/2, -1/2, -7/2, 1/2, 7/2) - sage: o.distances([1,2,sqrt(2)]) + sage: o.distances([1,2,sqrt(2)]) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert sqrt(2) to an element of Rational Field @@ -1842,15 +1842,15 @@ def dual(self): EXAMPLES:: sage: o = lattice_polytope.cross_polytope(4) - sage: e = o.edges()[0]; e + sage: e = o.edges()[0]; e # optional - sage.graphs 1-d face of 4-d reflexive polytope in 4-d lattice M - sage: ed = e.dual(); ed + sage: ed = e.dual(); ed # optional - sage.graphs 2-d face of 4-d reflexive polytope in 4-d lattice N - sage: ed.ambient() is e.ambient().polar() + sage: ed.ambient() is e.ambient().polar() # optional - sage.graphs True - sage: e.ambient_vertex_indices() == ed.ambient_facet_indices() + sage: e.ambient_vertex_indices() == ed.ambient_facet_indices() # optional - sage.graphs True - sage: e.ambient_facet_indices() == ed.ambient_vertex_indices() + sage: e.ambient_facet_indices() == ed.ambient_vertex_indices() # optional - sage.graphs True """ for f in self._ambient.polar().faces(codim=self.dim() + 1): @@ -1893,11 +1893,11 @@ def edges(self): EXAMPLES:: sage: o = lattice_polytope.cross_polytope(3) - sage: o.edges() + sage: o.edges() # optional - sage.graphs (1-d face of 3-d reflexive polytope in 3-d lattice M, ... 1-d face of 3-d reflexive polytope in 3-d lattice M) - sage: len(o.edges()) + sage: len(o.edges()) # optional - sage.graphs 12 """ return self.faces(dim=1) @@ -1920,13 +1920,13 @@ def face_lattice(self): Let's take a look at the face lattice of a square:: sage: square = LatticePolytope([(0,0), (1,0), (1,1), (0,1)]) - sage: L = square.face_lattice() - sage: L + sage: L = square.face_lattice() # optional - sage.graphs + sage: L # optional - sage.graphs Finite lattice containing 10 elements with distinguished linear extension To see all faces arranged by dimension, you can do this:: - sage: for level in L.level_sets(): print(level) + sage: for level in L.level_sets(): print(level) # optional - sage.graphs [-1-d face of 2-d lattice polytope in 2-d lattice M] [0-d face of 2-d lattice polytope in 2-d lattice M, 0-d face of 2-d lattice polytope in 2-d lattice M, @@ -1940,31 +1940,31 @@ def face_lattice(self): For a particular face you can look at its actual vertices... :: - sage: face = L.level_sets()[1][0] - sage: face.vertices() + sage: face = L.level_sets()[1][0] # optional - sage.graphs + sage: face.vertices() # optional - sage.graphs M(0, 0) in 2-d lattice M ... or you can see the index of the vertex of the original polytope that corresponds to the above one:: - sage: face.ambient_vertex_indices() + sage: face.ambient_vertex_indices() # optional - sage.graphs (0,) - sage: square.vertex(0) + sage: square.vertex(0) # optional - sage.graphs M(0, 0) An alternative to extracting faces from the face lattice is to use :meth:`faces` method:: - sage: face is square.faces(dim=0)[0] + sage: face is square.faces(dim=0)[0] # optional - sage.graphs True The advantage of working with the face lattice directly is that you can (relatively easily) get faces that are related to the given one:: - sage: face = L.level_sets()[1][0] - sage: D = L.hasse_diagram() - sage: sorted(D.neighbors(face)) + sage: face = L.level_sets()[1][0] # optional - sage.graphs + sage: D = L.hasse_diagram() # optional - sage.graphs + sage: sorted(D.neighbors(face)) # optional - sage.graphs [-1-d face of 2-d lattice polytope in 2-d lattice M, 1-d face of 2-d lattice polytope in 2-d lattice M, 1-d face of 2-d lattice polytope in 2-d lattice M] @@ -1972,21 +1972,21 @@ def face_lattice(self): However, you can achieve some of this functionality using :meth:`facets`, :meth:`facet_of`, and :meth:`adjacent` methods:: - sage: face = square.faces(0)[0] - sage: face + sage: face = square.faces(0)[0] # optional - sage.graphs + sage: face # optional - sage.graphs 0-d face of 2-d lattice polytope in 2-d lattice M - sage: face.vertices() + sage: face.vertices() # optional - sage.graphs M(0, 0) in 2-d lattice M - sage: face.facets() + sage: face.facets() # optional - sage.graphs (-1-d face of 2-d lattice polytope in 2-d lattice M,) - sage: face.facet_of() + sage: face.facet_of() # optional - sage.graphs (1-d face of 2-d lattice polytope in 2-d lattice M, 1-d face of 2-d lattice polytope in 2-d lattice M) - sage: face.adjacent() + sage: face.adjacent() # optional - sage.graphs (0-d face of 2-d lattice polytope in 2-d lattice M, 0-d face of 2-d lattice polytope in 2-d lattice M) - sage: face.adjacent()[0].vertices() + sage: face.adjacent()[0].vertices() # optional - sage.graphs M(1, 0) in 2-d lattice M @@ -1995,20 +1995,20 @@ def face_lattice(self): sage: superp = LatticePolytope([(1,2,3,4), (5,6,7,8), ....: (1,2,4,8), (1,3,9,7)]) - sage: superp.face_lattice() + sage: superp.face_lattice() # optional - sage.graphs Finite lattice containing 16 elements with distinguished linear extension - sage: superp.face_lattice().top() + sage: superp.face_lattice().top() # optional - sage.graphs 3-d lattice polytope in 4-d lattice M - sage: p = superp.facets()[0] - sage: p + sage: p = superp.facets()[0] # optional - sage.graphs + sage: p # optional - sage.graphs 2-d face of 3-d lattice polytope in 4-d lattice M - sage: p.face_lattice() + sage: p.face_lattice() # optional - sage.graphs Finite poset containing 8 elements with distinguished linear extension - sage: p.face_lattice().bottom() + sage: p.face_lattice().bottom() # optional - sage.graphs -1-d face of 3-d lattice polytope in 4-d lattice M - sage: p.face_lattice().top() + sage: p.face_lattice().top() # optional - sage.graphs 2-d face of 3-d lattice polytope in 4-d lattice M - sage: p.face_lattice().top() is p + sage: p.face_lattice().top() is p # optional - sage.graphs True """ if self._ambient is self: @@ -2098,7 +2098,7 @@ def faces(self, dim=None, codim=None): Let's take a look at the faces of a square:: sage: square = LatticePolytope([(0,0), (1,0), (1,1), (0,1)]) - sage: square.faces() + sage: square.faces() # optional - sage.graphs ((-1-d face of 2-d lattice polytope in 2-d lattice M,), (0-d face of 2-d lattice polytope in 2-d lattice M, 0-d face of 2-d lattice polytope in 2-d lattice M, @@ -2112,7 +2112,7 @@ def faces(self, dim=None, codim=None): Its faces of dimension one (i.e., edges):: - sage: square.faces(dim=1) + sage: square.faces(dim=1) # optional - sage.graphs (1-d face of 2-d lattice polytope in 2-d lattice M, 1-d face of 2-d lattice polytope in 2-d lattice M, 1-d face of 2-d lattice polytope in 2-d lattice M, @@ -2120,16 +2120,16 @@ def faces(self, dim=None, codim=None): Its faces of codimension one are the same (also edges):: - sage: square.faces(codim=1) is square.faces(dim=1) + sage: square.faces(codim=1) is square.faces(dim=1) # optional - sage.graphs True Let's pick a particular face:: - sage: face = square.faces(dim=1)[0] + sage: face = square.faces(dim=1)[0] # optional - sage.graphs Now you can look at the actual vertices of this face... :: - sage: face.vertices() + sage: face.vertices() # optional - sage.graphs M(0, 0), M(0, 1) in 2-d lattice M @@ -2137,9 +2137,9 @@ def faces(self, dim=None, codim=None): ... or you can see indices of the vertices of the original polytope that correspond to the above ones:: - sage: face.ambient_vertex_indices() + sage: face.ambient_vertex_indices() # optional - sage.graphs (0, 3) - sage: square.vertices(face.ambient_vertex_indices()) + sage: square.vertices(face.ambient_vertex_indices()) # optional - sage.graphs M(0, 0), M(0, 1) in 2-d lattice M @@ -2365,12 +2365,12 @@ def facet_of(self): EXAMPLES:: sage: square = LatticePolytope([(0,0), (1,0), (1,1), (0,1)]) - sage: square.facet_of() + sage: square.facet_of() # optional - sage.graphs () - sage: face = square.faces(0)[0] - sage: len(face.facet_of()) + sage: face = square.faces(0)[0] # optional - sage.graphs + sage: len(face.facet_of()) # optional - sage.graphs 2 - sage: face.facet_of()[1] + sage: face.facet_of()[1] # optional - sage.graphs 1-d face of 2-d lattice polytope in 2-d lattice M """ L = self._ambient.face_lattice() @@ -2388,11 +2388,11 @@ def facets(self): EXAMPLES:: sage: o = lattice_polytope.cross_polytope(3) - sage: o.facets() + sage: o.facets() # optional - sage.graphs (2-d face of 3-d reflexive polytope in 3-d lattice M, ... 2-d face of 3-d reflexive polytope in 3-d lattice M) - sage: len(o.facets()) + sage: len(o.facets()) # optional - sage.graphs 8 """ return self.faces(codim=1) @@ -2420,14 +2420,14 @@ def incidence_matrix(self): [0 1 1 0] [1 1 0 0] [1 0 0 1] - sage: o.faces(1)[0].incidence_matrix() + sage: o.faces(1)[0].incidence_matrix() # optional - sage.graphs [1 0] [0 1] sage: o = lattice_polytope.cross_polytope(4) sage: o.incidence_matrix().column(3).nonzero_positions() [3, 4, 5, 6] - sage: o.facets()[3].ambient_vertex_indices() + sage: o.facets()[3].ambient_vertex_indices() # optional - sage.graphs (3, 4, 5, 6) TESTS:: @@ -2580,8 +2580,8 @@ def interior_points(self): Its edges also have a single interior point each:: - sage: face = square.edges()[0] - sage: face.interior_points() + sage: face = square.edges()[0] # optional - sage.graphs + sage: face.interior_points() # optional - sage.graphs N(-1, 0) in 2-d lattice N """ @@ -3055,13 +3055,13 @@ def _palp_modified_normal_form(self, permutation=False): M(-1, 0), M( 0, -1) in 2-d lattice M - sage: o._palp_modified_normal_form() + sage: o._palp_modified_normal_form() # optional - sage.graphs M( 1, 0), M( 0, 1), M( 0, -1), M(-1, 0) in 2-d lattice M - sage: o._palp_modified_normal_form(permutation=True) + sage: o._palp_modified_normal_form(permutation=True) # optional - sage.graphs (M( 1, 0), M( 0, 1), M( 0, -1), @@ -3108,13 +3108,13 @@ def _palp_native_normal_form(self, permutation=False): M(-1, 0), M( 0, -1) in 2-d lattice M - sage: o._palp_native_normal_form() + sage: o._palp_native_normal_form() # optional - sage.groups M( 1, 0), M( 0, 1), M( 0, -1), M(-1, 0) in 2-d lattice M - sage: o._palp_native_normal_form(permutation=True) + sage: o._palp_native_normal_form(permutation=True) # optional - sage.groups (M( 1, 0), M( 0, 1), M( 0, -1), @@ -3159,8 +3159,8 @@ def _palp_PM_max(self, check=False): sage: o = lattice_polytope.cross_polytope(2) sage: PM = o.vertex_facet_pairing_matrix() - sage: PM_max = PM.permutation_normal_form() - sage: PM_max == o._palp_PM_max() + sage: PM_max = PM.permutation_normal_form() # optional - sage.graphs + sage: PM_max == o._palp_PM_max() # optional - sage.graphs True sage: P2 = ReflexivePolytope(2, 0) sage: PM_max, permutations = P2._palp_PM_max(check=True) @@ -4074,7 +4074,7 @@ def traverse_boundary(self): EXAMPLES:: sage: p = lattice_polytope.cross_polytope(2).polar() - sage: p.traverse_boundary() + sage: p.traverse_boundary() # optional - sage.graphs [3, 0, 1, 2] """ if self.dim() != 2: diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 3d4a65b3df0..46b6433b640 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -317,12 +317,12 @@ def boundary_complex(self): The boundary complex of the octahedron:: sage: oc = polytopes.octahedron() - sage: sc_oc = oc.boundary_complex() - sage: fl_oc = oc.face_lattice() # optional - sage.combinat - sage: fl_sc = sc_oc.face_poset() # optional - sage.combinat - sage: [len(x) for x in fl_oc.level_sets()] # optional - sage.combinat + sage: sc_oc = oc.boundary_complex() # optional - sage.graphs + sage: fl_oc = oc.face_lattice() # optional - sage.combinat sage.graphs + sage: fl_sc = sc_oc.face_poset() # optional - sage.combinat sage.graphs + sage: [len(x) for x in fl_oc.level_sets()] # optional - sage.combinat sage.graphs [1, 6, 12, 8, 1] - sage: [len(x) for x in fl_sc.level_sets()] # optional - sage.combinat + sage: [len(x) for x in fl_sc.level_sets()] # optional - sage.combinat sage.graphs [6, 12, 8] sage: sc_oc.euler_characteristic() 2 diff --git a/src/sage/geometry/polyhedron/base2.py b/src/sage/geometry/polyhedron/base2.py index ab83971f35f..41ec3ad203d 100644 --- a/src/sage/geometry/polyhedron/base2.py +++ b/src/sage/geometry/polyhedron/base2.py @@ -143,8 +143,9 @@ def lattice_polytope(self, envelope=False): First, a polyhedron with integral vertices:: sage: P = Polyhedron(vertices=[(1, 0), (0, 1), (-1, 0), (0, -1)]) - sage: lp = P.lattice_polytope() - sage: lp # optional - palp + sage: lp = P.lattice_polytope(); lp + 2-d reflexive polytope... in 2-d lattice M + sage: lp # optional - palp polytopes_db 2-d reflexive polytope #3 in 2-d lattice M sage: lp.vertices() M(-1, 0), @@ -163,7 +164,7 @@ def lattice_polytope(self, envelope=False): to add the argument "envelope=True" to compute an enveloping lattice polytope. sage: lp = P.lattice_polytope(True) - sage: lp # optional - palp + sage: lp # optional - palp polytopes_db 2-d reflexive polytope #5 in 2-d lattice M sage: lp.vertices() M(-1, 0), diff --git a/src/sage/geometry/polyhedron/base7.py b/src/sage/geometry/polyhedron/base7.py index 3465f22875d..e5471ef0570 100644 --- a/src/sage/geometry/polyhedron/base7.py +++ b/src/sage/geometry/polyhedron/base7.py @@ -544,13 +544,13 @@ def volume(self, measure='ambient', engine='auto', **kwds): 0 sage: P.volume(measure='induced') # optional - pynormaliz # optional - sage.rings.number_field 2.598076211353316? - sage: P.volume(measure='induced',engine='normaliz') # optional - pynormaliz + sage: P.volume(measure='induced',engine='normaliz') # optional - pynormaliz 2.598076211353316 - sage: P.volume(measure='induced_rational') # optional - pynormaliz, latte_int + sage: P.volume(measure='induced_rational') # optional - pynormaliz latte_int 3/2 - sage: P.volume(measure='induced_rational',engine='normaliz') # optional - pynormaliz + sage: P.volume(measure='induced_rational',engine='normaliz') # optional - pynormaliz 3/2 - sage: P.volume(measure='induced_lattice') # optional - pynormaliz + sage: P.volume(measure='induced_lattice') # optional - pynormaliz 3 The same polytope without normaliz backend:: diff --git a/src/sage/geometry/polyhedron/ppl_lattice_polytope.py b/src/sage/geometry/polyhedron/ppl_lattice_polytope.py index 08b767e54e2..7e6851b11d6 100644 --- a/src/sage/geometry/polyhedron/ppl_lattice_polytope.py +++ b/src/sage/geometry/polyhedron/ppl_lattice_polytope.py @@ -118,36 +118,36 @@ def LatticePolytope_PPL(*args): sage: LatticePolytope_PPL((0,0),(1,0),(0,1)) A 2-dimensional lattice polytope in ZZ^2 with 3 vertices - sage: from ppl import point, Generator_System, C_Polyhedron, Linear_Expression, Variable - sage: p = point(Linear_Expression([2,3],0)); p + sage: from ppl import point, Generator_System, C_Polyhedron, Linear_Expression, Variable # optional - pplpy + sage: p = point(Linear_Expression([2,3],0)); p # optional - pplpy point(2/1, 3/1) - sage: LatticePolytope_PPL(p) + sage: LatticePolytope_PPL(p) # optional - pplpy A 0-dimensional lattice polytope in ZZ^2 with 1 vertex - sage: P = C_Polyhedron(Generator_System(p)); P + sage: P = C_Polyhedron(Generator_System(p)); P # optional - pplpy A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point - sage: LatticePolytope_PPL(P) + sage: LatticePolytope_PPL(P) # optional - pplpy A 0-dimensional lattice polytope in ZZ^2 with 1 vertex A ``TypeError`` is raised if the arguments do not specify a lattice polytope:: - sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL - sage: LatticePolytope_PPL((0,0),(1/2,1)) + sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL # optional - pplpy + sage: LatticePolytope_PPL((0,0),(1/2,1)) # optional - pplpy Traceback (most recent call last): ... TypeError: unable to convert rational 1/2 to an integer - sage: from ppl import point, Generator_System, C_Polyhedron, Linear_Expression, Variable - sage: p = point(Linear_Expression([2,3],0), 5); p + sage: from ppl import point, Generator_System, C_Polyhedron, Linear_Expression, Variable # optional - pplpy + sage: p = point(Linear_Expression([2,3],0), 5); p # optional - pplpy point(2/5, 3/5) - sage: LatticePolytope_PPL(p) + sage: LatticePolytope_PPL(p) # optional - pplpy Traceback (most recent call last): ... TypeError: generator is not a lattice polytope generator - sage: P = C_Polyhedron(Generator_System(p)); P + sage: P = C_Polyhedron(Generator_System(p)); P # optional - pplpy A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point - sage: LatticePolytope_PPL(P) + sage: LatticePolytope_PPL(P) # optional - pplpy Traceback (most recent call last): ... TypeError: polyhedron has non-integral generators diff --git a/src/sage/geometry/pseudolines.py b/src/sage/geometry/pseudolines.py index 37b9ee324ca..175e79b5c63 100644 --- a/src/sage/geometry/pseudolines.py +++ b/src/sage/geometry/pseudolines.py @@ -49,7 +49,7 @@ sage: p = PseudolineArrangement(permutations) sage: p Arrangement of pseudolines of size 4 - sage: p.show() + sage: p.show() # optional - sage.plot **Sequence of transpositions** @@ -67,7 +67,7 @@ sage: p = PseudolineArrangement(transpositions) sage: p Arrangement of pseudolines of size 4 - sage: p.show() + sage: p.show() # optional - sage.plot Note that this ordering is not necessarily unique. @@ -129,8 +129,8 @@ avoid a common crossing of three lines by adding a random noise to `b`:: sage: n = 20 - sage: l = sorted(zip(Subsets(20*n,n).random_element(), [randint(0,20*n)+random() for i in range(n)])) - sage: print(l[:5]) # not tested + sage: l = sorted(zip(Subsets(20*n,n).random_element(), [randint(0,20*n)+random() for i in range(n)])) # optional - sage.combinat + sage: print(l[:5]) # not tested # optional - sage.combinat [(96, 278.0130613051349), (74, 332.92512282478714), (13, 155.65820951249867), (209, 34.753946221755307), (147, 193.51376457741441)] We can now compute for each `i` the order in which line `i` meets the other lines:: @@ -138,16 +138,16 @@ sage: permutations = [[0..i-1]+[i+1..n-1] for i in range(n)] sage: a = lambda x : l[x][0] sage: b = lambda x : l[x][1] - sage: for i, perm in enumerate(permutations): + sage: for i, perm in enumerate(permutations): # optional - sage.combinat ....: perm.sort(key = lambda j : (b(j)-b(i))/(a(i)-a(j))) And finally build the line arrangement:: sage: from sage.geometry.pseudolines import PseudolineArrangement - sage: p = PseudolineArrangement(permutations) - sage: print(p) + sage: p = PseudolineArrangement(permutations) # optional - sage.combinat + sage: print(p) # optional - sage.combinat Arrangement of pseudolines of size 20 - sage: p.show(figsize=[20,8]) + sage: p.show(figsize=[20,8]) # optional - sage.combinat sage.plot Author ^^^^^^ @@ -417,14 +417,14 @@ def show(self, **args): sage: from sage.geometry.pseudolines import PseudolineArrangement sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 1, 0], [2, 1, 0]] sage: p = PseudolineArrangement(permutations) - sage: p.show(figsize=[7,5]) + sage: p.show(figsize=[7,5]) # optional - sage.plot TESTS:: sage: from sage.geometry.pseudolines import PseudolineArrangement sage: permutations = [[3, 2, 1], [3, 2, 0], [3, 0, 1], [2, 0, 1]] sage: p = PseudolineArrangement(permutations) - sage: p.show() + sage: p.show() # optional - sage.plot Traceback (most recent call last): ... ValueError: There has been a problem while plotting the figure... diff --git a/src/sage/geometry/relative_interior.py b/src/sage/geometry/relative_interior.py index 262c927a08a..d9ba65bbff5 100644 --- a/src/sage/geometry/relative_interior.py +++ b/src/sage/geometry/relative_interior.py @@ -324,11 +324,11 @@ def __eq__(self, other): sage: ri_segment = segment.relative_interior(); ri_segment Relative interior of a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices - sage: segment2 = Polyhedron([[1, 2], [3, 4]], base_ring=AA) - sage: ri_segment2 = segment2.relative_interior(); ri_segment2 + sage: segment2 = Polyhedron([[1, 2], [3, 4]], base_ring=AA) # optional - sage.rings.number_field + sage: ri_segment2 = segment2.relative_interior(); ri_segment2 # optional - sage.rings.number_field Relative interior of a 1-dimensional polyhedron in AA^2 defined as the convex hull of 2 vertices - sage: ri_segment == ri_segment2 + sage: ri_segment == ri_segment2 # optional - sage.rings.number_field True TESTS:: @@ -355,11 +355,11 @@ def __ne__(self, other): sage: ri_segment = segment.relative_interior(); ri_segment Relative interior of a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices - sage: segment2 = Polyhedron([[1, 2], [3, 4]], base_ring=AA) - sage: ri_segment2 = segment2.relative_interior(); ri_segment2 + sage: segment2 = Polyhedron([[1, 2], [3, 4]], base_ring=AA) # optional - sage.rings.number_field + sage: ri_segment2 = segment2.relative_interior(); ri_segment2 # optional - sage.rings.number_field Relative interior of a 1-dimensional polyhedron in AA^2 defined as the convex hull of 2 vertices - sage: ri_segment != ri_segment2 + sage: ri_segment != ri_segment2 # optional - sage.rings.number_field False """ return not (self == other) diff --git a/src/sage/geometry/toric_plotter.py b/src/sage/geometry/toric_plotter.py index 07aed17663a..6613414ed07 100644 --- a/src/sage/geometry/toric_plotter.py +++ b/src/sage/geometry/toric_plotter.py @@ -169,11 +169,11 @@ class ToricPlotter(SageObject): sage: tp.include_points(fan.rays()) # optional - palp sage: tp.adjust_options() # optional - palp sage: tp.set_rays(fan.rays()) # optional - palp - sage: result = tp.plot_lattice() # optional - palp - sage: result += tp.plot_rays() # optional - palp - sage: result += tp.plot_generators() # optional - palp - sage: result += tp.plot_walls(fan(2)) # optional - palp - sage: result # optional - palp + sage: result = tp.plot_lattice() # optional - palp sage.plot + sage: result += tp.plot_rays() # optional - palp sage.plot + sage: result += tp.plot_generators() # optional - palp sage.plot + sage: result += tp.plot_walls(fan(2)) # optional - palp sage.plot + sage: result # optional - palp sage.plot Graphics object consisting of 31 graphics primitives In most situations it is only necessary to include generators of rays, in @@ -389,7 +389,7 @@ def plot_generators(self): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2, [(3,4)]) - sage: tp.plot_generators() + sage: tp.plot_generators() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ generators = self.generators @@ -440,7 +440,7 @@ def plot_labels(self, labels, positions): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2) - sage: tp.plot_labels("u", [(1.5,0)]) + sage: tp.plot_labels("u", [(1.5,0)]) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ result = Graphics() @@ -474,7 +474,7 @@ def plot_lattice(self): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2) sage: tp.adjust_options() - sage: tp.plot_lattice() + sage: tp.plot_lattice() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ if not self.show_lattice: @@ -518,7 +518,7 @@ def plot_points(self, points): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2) sage: tp.adjust_options() - sage: tp.plot_points([(1,0), (0,1)]) + sage: tp.plot_points([(1,0), (0,1)]) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ return point(points, color=self.point_color, size=self.point_size, @@ -542,7 +542,7 @@ def plot_ray_labels(self): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2, [(3,4)]) - sage: tp.plot_ray_labels() + sage: tp.plot_ray_labels() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ return self.plot_labels(self.ray_label, @@ -563,7 +563,7 @@ def plot_rays(self): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2, [(3,4)]) - sage: tp.plot_rays() + sage: tp.plot_rays() # optional - sage.plot Graphics object consisting of 2 graphics primitives """ result = Graphics() @@ -605,14 +605,14 @@ def plot_walls(self, walls): sage: quadrant = Cone([(1,0), (0,1)]) sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2, quadrant.rays()) - sage: tp.plot_walls([quadrant]) + sage: tp.plot_walls([quadrant]) # optional - sage.plot Graphics object consisting of 2 graphics primitives Let's also check that the truncating polyhedron is functioning correctly:: sage: tp = ToricPlotter({"mode": "box"}, 2, quadrant.rays()) - sage: tp.plot_walls([quadrant]) + sage: tp.plot_walls([quadrant]) # optional - sage.plot Graphics object consisting of 2 graphics primitives """ result = Graphics() @@ -702,12 +702,12 @@ def set_rays(self, generators): sage: from sage.geometry.toric_plotter import ToricPlotter sage: tp = ToricPlotter(dict(), 2) sage: tp.adjust_options() - sage: tp.plot_rays() + sage: tp.plot_rays() # optional - sage.plot Traceback (most recent call last): ... AttributeError: 'ToricPlotter' object has no attribute 'rays' sage: tp.set_rays([(0,1)]) - sage: tp.plot_rays() + sage: tp.plot_rays() # optional - sage.plot Graphics object consisting of 2 graphics primitives """ d = self.dimension @@ -782,20 +782,20 @@ def color_list(color, n): EXAMPLES:: sage: from sage.geometry.toric_plotter import color_list - sage: color_list("grey", 1) + sage: color_list("grey", 1) # optional - sage.plot [RGB color (0.5019607843137255, 0.5019607843137255, 0.5019607843137255)] - sage: len(color_list("grey", 3)) + sage: len(color_list("grey", 3)) # optional - sage.plot 3 - sage: L = color_list("rainbow", 3) - sage: L + sage: L = color_list("rainbow", 3) # optional - sage.plot + sage: L # optional - sage.plot [RGB color (1.0, 0.0, 0.0), RGB color (0.0, 1.0, 0.0), RGB color (0.0, 0.0, 1.0)] - sage: color_list(L, 3) + sage: color_list(L, 3) # optional - sage.plot [RGB color (1.0, 0.0, 0.0), RGB color (0.0, 1.0, 0.0), RGB color (0.0, 0.0, 1.0)] - sage: color_list(L, 4) + sage: color_list(L, 4) # optional - sage.plot Traceback (most recent call last): ... ValueError: expected 4 colors, got 3! diff --git a/src/sage/geometry/triangulation/element.py b/src/sage/geometry/triangulation/element.py index b32cb952190..49822857d58 100644 --- a/src/sage/geometry/triangulation/element.py +++ b/src/sage/geometry/triangulation/element.py @@ -568,13 +568,13 @@ def simplicial_complex(self): EXAMPLES:: sage: p = polytopes.cuboctahedron() - sage: sc = p.triangulate(engine='internal').simplicial_complex() - sage: sc + sage: sc = p.triangulate(engine='internal').simplicial_complex() # optional - sage.graphs + sage: sc # optional - sage.graphs Simplicial complex with 12 vertices and 16 facets Any convex set is contractable, so its reduced homology groups vanish:: - sage: sc.homology() + sage: sc.homology() # optional - sage.graphs {0: 0, 1: 0, 2: 0, 3: 0} """ from sage.topology.simplicial_complex import SimplicialComplex @@ -672,20 +672,20 @@ def boundary_simplicial_complex(self): sage: p = polytopes.cuboctahedron() sage: triangulation = p.triangulate(engine='internal') - sage: bd_sc = triangulation.boundary_simplicial_complex() - sage: bd_sc + sage: bd_sc = triangulation.boundary_simplicial_complex() # optional - sage.graphs + sage: bd_sc # optional - sage.graphs Simplicial complex with 12 vertices and 20 facets The boundary of every convex set is a topological sphere, so it has spherical homology:: - sage: bd_sc.homology() + sage: bd_sc.homology() # optional - sage.graphs {0: 0, 1: 0, 2: Z} It is a subcomplex of ``self`` as a :meth:`simplicial_complex`:: - sage: sc = triangulation.simplicial_complex() - sage: all(f in sc for f in bd_sc.maximal_faces()) + sage: sc = triangulation.simplicial_complex() # optional - sage.graphs + sage: all(f in sc for f in bd_sc.maximal_faces()) # optional - sage.graphs True """ from sage.topology.simplicial_complex import SimplicialComplex @@ -921,7 +921,7 @@ def adjacency_graph(self): sage: p = PointConfiguration([[1,0,0], [0,1,0], [0,0,1], [-1,0,1], ....: [1,0,-1], [-1,0,0], [0,-1,0], [0,0,-1]]) sage: t = p.triangulate() - sage: t.adjacency_graph() + sage: t.adjacency_graph() # optional - sage.graphs Graph on 8 vertices """ diff --git a/src/sage/geometry/triangulation/point_configuration.py b/src/sage/geometry/triangulation/point_configuration.py index 055ecae5d60..f62ddc70099 100644 --- a/src/sage/geometry/triangulation/point_configuration.py +++ b/src/sage/geometry/triangulation/point_configuration.py @@ -1124,10 +1124,10 @@ def restricted_automorphism_group(self): EXAMPLES:: sage: pyramid = PointConfiguration([[1,0,0],[0,1,1],[0,1,-1],[0,-1,-1],[0,-1,1]]) - sage: G = pyramid.restricted_automorphism_group() # optional - sage.graphs, sage.groups - sage: G == PermutationGroup([[(3,5)], [(2,3),(4,5)], [(2,4)]]) # optional - sage.graphs, sage.groups + sage: G = pyramid.restricted_automorphism_group() # optional - sage.graphs sage.groups + sage: G == PermutationGroup([[(3,5)], [(2,3),(4,5)], [(2,4)]]) # optional - sage.graphs sage.groups True - sage: DihedralGroup(4).is_isomorphic(G) # optional - sage.graphs, sage.groups + sage: DihedralGroup(4).is_isomorphic(G) # optional - sage.graphs sage.groups True The square with an off-center point in the middle. Note that @@ -1135,9 +1135,9 @@ def restricted_automorphism_group(self): `D_4` of the convex hull:: sage: square = PointConfiguration([(3/4,3/4),(1,1),(1,-1),(-1,-1),(-1,1)]) - sage: square.restricted_automorphism_group() # optional - sage.graphs, sage.groups + sage: square.restricted_automorphism_group() # optional - sage.graphs sage.groups Permutation Group with generators [(3,5)] - sage: DihedralGroup(1).is_isomorphic(_) # optional - sage.graphs, sage.groups + sage: DihedralGroup(1).is_isomorphic(_) # optional - sage.graphs sage.groups True """ v_list = [ vector(p.projective()) for p in self ] diff --git a/src/sage/groups/additive_abelian/additive_abelian_group.py b/src/sage/groups/additive_abelian/additive_abelian_group.py index 62274a7bfef..fc9cb6a3088 100644 --- a/src/sage/groups/additive_abelian/additive_abelian_group.py +++ b/src/sage/groups/additive_abelian/additive_abelian_group.py @@ -450,7 +450,7 @@ def permutation_group(self): EXAMPLES:: sage: G = AdditiveAbelianGroup([2, 3]) - sage: G.permutation_group() + sage: G.permutation_group() # optional - sage.groups Permutation Group with generators [(3,4,5), (1,2)] TESTS: diff --git a/src/sage/groups/additive_abelian/additive_abelian_wrapper.py b/src/sage/groups/additive_abelian/additive_abelian_wrapper.py index 372519833bc..9224bc6a915 100644 --- a/src/sage/groups/additive_abelian/additive_abelian_wrapper.py +++ b/src/sage/groups/additive_abelian/additive_abelian_wrapper.py @@ -85,12 +85,12 @@ def __init__(self, domain): r""" EXAMPLES:: - sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) - sage: F = QQbar.coerce_map_from(G); F + sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) # optional - sage.rings.number_field + sage: F = QQbar.coerce_map_from(G); F # optional - sage.rings.number_field Generic morphism: From: Additive abelian group isomorphic to Z + Z embedded in Algebraic Field To: Algebraic Field - sage: type(F) + sage: type(F) # optional - sage.rings.number_field """ Morphism.__init__(self, domain.Hom(domain.universe())) @@ -127,8 +127,8 @@ def __init__(self, parent, vector, element=None, check=False): EXAMPLES:: sage: from sage.groups.additive_abelian.additive_abelian_wrapper import AdditiveAbelianGroupWrapper - sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) - sage: G.0 # indirect doctest + sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) # optional - sage.rings.number_field + sage: G.0 # indirect doctest # optional - sage.rings.number_field 1.414213562373095? """ addgp.AdditiveAbelianGroupElement.__init__(self, parent, vector, check) @@ -185,13 +185,15 @@ class AdditiveAbelianGroupWrapper(addgp.AdditiveAbelianGroup_fixed_gens): :: - sage: AdditiveAbelianGroupWrapper(QQbar, [sqrt(2), sqrt(3)], [0, 0]) + sage: AdditiveAbelianGroupWrapper(QQbar, [sqrt(2), sqrt(3)], [0, 0]) # optional - sage.rings.number_field sage.symbolic Additive abelian group isomorphic to Z + Z embedded in Algebraic Field :: - sage: EllipticCurve(GF(419**2), [1,0]).abelian_group() # indirect doctest - Additive abelian group isomorphic to Z/420 + Z/420 embedded in Abelian group of points on Elliptic Curve defined by y^2 = x^3 + x over Finite Field in z2 of size 419^2 + sage: EllipticCurve(GF(419**2), [1,0]).abelian_group() # indirect doctest # optional - sage.libs.pari + Additive abelian group isomorphic to Z/420 + Z/420 embedded in + Abelian group of points on Elliptic Curve + defined by y^2 = x^3 + x over Finite Field in z2 of size 419^2 """ Element = AdditiveAbelianGroupWrapperElement @@ -200,7 +202,7 @@ def __init__(self, universe, gens, invariants): r""" EXAMPLES:: - sage: AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) # indirect doctest + sage: AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) # indirect doctest # optional - sage.rings.number_field Additive abelian group isomorphic to Z + Z embedded in Algebraic Field """ self._universe = universe @@ -217,8 +219,8 @@ def universe(self): EXAMPLES:: - sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) - sage: G.universe() + sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) # optional - sage.rings.number_field + sage: G.universe() # optional - sage.rings.number_field Algebraic Field """ return self._universe @@ -246,8 +248,8 @@ def _repr_(self): r""" EXAMPLES:: - sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) - sage: repr(G) # indirect doctest + sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), sqrt(QQbar(3))], [0, 0]) # optional - sage.rings.number_field + sage: repr(G) # indirect doctest # optional - sage.rings.number_field 'Additive abelian group isomorphic to Z + Z embedded in Algebraic Field' """ return addgp.AdditiveAbelianGroup_fixed_gens._repr_(self) + " embedded in " + self.universe()._repr_() @@ -283,10 +285,10 @@ def discrete_exp(self, v): EXAMPLES:: - sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), -1], [0, 0]) - sage: v = G.discrete_exp([3, 5]); v + sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(QQbar(2)), -1], [0, 0]) # optional - sage.rings.number_field + sage: v = G.discrete_exp([3, 5]); v # optional - sage.rings.number_field -0.7573593128807148? - sage: v.parent() is QQbar + sage: v.parent() is QQbar # optional - sage.rings.number_field True This method is an inverse of :meth:`discrete_log`:: @@ -338,9 +340,10 @@ def discrete_log(self, x, gens=None): :: - sage: F. = GF(1009**2, modulus=x**2+11); E = EllipticCurve(j=F(940)) - sage: P, Q = E(900*t + 228, 974*t + 185), E(1007*t + 214, 865*t + 802) - sage: E.abelian_group().discrete_log(123 * P + 777 * Q, [P, Q]) + sage: x = polygen(ZZ, 'x') + sage: F. = GF(1009**2, modulus=x**2+11); E = EllipticCurve(j=F(940)) # optional - sage.libs.pari + sage: P, Q = E(900*t + 228, 974*t + 185), E(1007*t + 214, 865*t + 802) # optional - sage.libs.pari + sage: E.abelian_group().discrete_log(123 * P + 777 * Q, [P, Q]) # optional - sage.libs.pari (123, 777) :: @@ -356,8 +359,8 @@ def discrete_log(self, x, gens=None): :: - sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(2)], [0]) - sage: G.discrete_log(QQbar(2*sqrt(2))) + sage: G = AdditiveAbelianGroupWrapper(QQbar, [sqrt(2)], [0]) # optional - sage.rings.number_field + sage: G.discrete_log(QQbar(2*sqrt(2))) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: No black-box discrete log for infinite abelian groups @@ -425,17 +428,20 @@ def torsion_subgroup(self, n=None): sage: A = AdditiveAbelianGroupWrapper(G.0.parent(), G.gens(), ords) sage: T = A.torsion_subgroup(5) sage: T - Additive abelian group isomorphic to Z/5 + Z/5 + Z/5 embedded in Additive abelian group isomorphic to Z/2 + Z/6 + Z/30 + Z + Z/210 + Z/2310 + Additive abelian group isomorphic to Z/5 + Z/5 + Z/5 embedded in + Additive abelian group isomorphic to Z/2 + Z/6 + Z/30 + Z + Z/210 + Z/2310 sage: T.gens() ((0, 0, 6, 0, 0, 0), (0, 0, 0, 0, 42, 0), (0, 0, 0, 0, 0, 462)) :: - sage: E = EllipticCurve(GF(487^2), [311,205]) - sage: T = E.abelian_group().torsion_subgroup(42) - sage: T - Additive abelian group isomorphic to Z/42 + Z/6 embedded in Abelian group of points on Elliptic Curve defined by y^2 = x^3 + 311*x + 205 over Finite Field in z2 of size 487^2 - sage: [P.order() for P in T.gens()] + sage: E = EllipticCurve(GF(487^2), [311,205]) # optional - sage.libs.pari + sage: T = E.abelian_group().torsion_subgroup(42) # optional - sage.libs.pari + sage: T # optional - sage.libs.pari + Additive abelian group isomorphic to Z/42 + Z/6 embedded in + Abelian group of points on Elliptic Curve + defined by y^2 = x^3 + 311*x + 205 over Finite Field in z2 of size 487^2 + sage: [P.order() for P in T.gens()] # optional - sage.libs.pari [42, 6] :: @@ -551,12 +557,12 @@ def _discrete_log_pgroup(p, vals, aa, b): Check for :trac:`34716`:: - sage: E = EllipticCurve(GF(487^2), [311,205]) - sage: G = E.abelian_group().torsion_subgroup(42) - sage: G.invariants() + sage: E = EllipticCurve(GF(487^2), [311,205]) # optional - sage.libs.pari + sage: G = E.abelian_group().torsion_subgroup(42) # optional - sage.libs.pari + sage: G.invariants() # optional - sage.libs.pari (6, 42) - sage: P, Q = G.torsion_subgroup(6).gens() - sage: G.discrete_log(2*P + 3*Q, [P, Q]) # indirect doctest + sage: P, Q = G.torsion_subgroup(6).gens() # optional - sage.libs.pari + sage: G.discrete_log(2*P + 3*Q, [P, Q]) # indirect doctest # optional - sage.groups (2, 3) """ from itertools import product as iproduct diff --git a/src/sage/groups/group.pyx b/src/sage/groups/group.pyx index 7947f0f876d..38df92c175d 100644 --- a/src/sage/groups/group.pyx +++ b/src/sage/groups/group.pyx @@ -39,11 +39,11 @@ def is_Group(x): EXAMPLES:: - sage: F. = FreeGroup() + sage: F. = FreeGroup() # optional - sage.groups sage: from sage.groups.group import is_Group - sage: is_Group(F) + sage: is_Group(F) # optional - sage.groups True - sage: is_Group("a string") + sage: is_Group("a string") # optional - sage.groups False """ from sage.groups.old import Group as OldGroup @@ -91,7 +91,7 @@ cdef class Group(Parent): sage: G = Group(category=Groups()) # todo: do the same test with some subcategory of Groups when there will exist one sage: G.category() Category of groups - sage: G = Group(category = CommutativeAdditiveGroups()) + sage: G = Group(category=CommutativeAdditiveGroups()) Traceback (most recent call last): ... ValueError: (Category of commutative additive groups,) is not a subcategory of Category of groups @@ -100,10 +100,10 @@ cdef class Group(Parent): Check for :trac:`8119`:: - sage: G = SymmetricGroup(2) - sage: h = hash(G) - sage: G.rename('S2') - sage: h == hash(G) + sage: G = SymmetricGroup(2) # optional - sage.groups + sage: h = hash(G) # optional - sage.groups + sage: G.rename('S2') # optional - sage.groups + sage: h == hash(G) # optional - sage.groups True """ from sage.categories.groups import Groups diff --git a/src/sage/groups/old.pyx b/src/sage/groups/old.pyx index c17082f59cb..8049eb8e2e5 100644 --- a/src/sage/groups/old.pyx +++ b/src/sage/groups/old.pyx @@ -50,10 +50,10 @@ cdef class Group(sage.structure.parent.Parent): Check for :trac:`8119`:: - sage: G = SymmetricGroup(2) - sage: h = hash(G) - sage: G.rename('S2') - sage: h == hash(G) + sage: G = SymmetricGroup(2) # optional - sage.groups + sage: h = hash(G) # optional - sage.groups + sage: G.rename('S2') # optional - sage.groups + sage: h == hash(G) # optional - sage.groups True """ from sage.categories.basic import Groups @@ -123,7 +123,7 @@ cdef class Group(sage.structure.parent.Parent): EXAMPLES:: - sage: SL(2, 7).is_commutative() + sage: SL(2, 7).is_commutative() # optional - sage.modules False """ return self.is_abelian() diff --git a/src/sage/homology/algebraic_topological_model.py b/src/sage/homology/algebraic_topological_model.py index f89a1529dd9..ecb18e2c5e1 100644 --- a/src/sage/homology/algebraic_topological_model.py +++ b/src/sage/homology/algebraic_topological_model.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.graphs r""" Algebraic topological model for a cell complex diff --git a/src/sage/homology/all__sagemath_polyhedra.py b/src/sage/homology/all__sagemath_polyhedra.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/sage/homology/chain_complex.py b/src/sage/homology/chain_complex.py index 08e9158e590..2b6de167bdc 100644 --- a/src/sage/homology/chain_complex.py +++ b/src/sage/homology/chain_complex.py @@ -85,7 +85,7 @@ def _latex_module(R, m): '\\Bold{Z}^{3}' sage: _latex_module(ZZ, 0) '0' - sage: _latex_module(GF(3), 1) + sage: _latex_module(GF(3), 1) # optional - sage.libs.pari '\\Bold{F}_{3}^{1}' """ if m == 0: @@ -188,11 +188,11 @@ def ChainComplex(data=None, base_ring=None, grading_group=None, Chain complex with at most 2 nonzero terms over Integer Ring sage: m = matrix(ZZ, 2, 2, [0, 1, 0, 0]) - sage: D = ChainComplex([m, m], base_ring=GF(2)); D + sage: D = ChainComplex([m, m], base_ring=GF(2)); D # optional - sage.libs.pari Chain complex with at most 3 nonzero terms over Finite Field of size 2 - sage: D == loads(dumps(D)) + sage: D == loads(dumps(D)) # optional - sage.libs.pari True - sage: D.differential(0)==m, m.is_immutable(), D.differential(0).is_immutable() + sage: D.differential(0)==m, m.is_immutable(), D.differential(0).is_immutable() # optional - sage.libs.pari (True, False, True) Note that when a chain complex is defined in Sage, new @@ -214,12 +214,12 @@ def ChainComplex(data=None, base_ring=None, grading_group=None, sage: ChainComplex([matrix(QQ, 3, 1), matrix(ZZ, 4, 3)]) Chain complex with at most 3 nonzero terms over Rational Field - sage: ChainComplex([matrix(GF(125, 'a'), 3, 1), matrix(ZZ, 4, 3)]) + sage: ChainComplex([matrix(GF(125, 'a'), 3, 1), matrix(ZZ, 4, 3)]) # optional - sage.libs.pari Chain complex with at most 3 nonzero terms over Finite Field in a of size 5^3 If the matrices are defined over incompatible rings, an error results:: - sage: ChainComplex([matrix(GF(125, 'a'), 3, 1), matrix(QQ, 4, 3)]) + sage: ChainComplex([matrix(GF(125, 'a'), 3, 1), matrix(QQ, 4, 3)]) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: 'Finite Field in a of size 5^3' and 'Rational Field' @@ -227,7 +227,7 @@ def ChainComplex(data=None, base_ring=None, grading_group=None, If the base ring is given explicitly but is not compatible with the matrices, an error results:: - sage: ChainComplex([matrix(GF(125, 'a'), 3, 1)], base_ring=QQ) + sage: ChainComplex([matrix(GF(125, 'a'), 3, 1)], base_ring=QQ) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: unable to convert 0 to a rational @@ -335,8 +335,8 @@ def __init__(self, parent, vectors, check=True): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(7)) - sage: C.category() + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(7)) # optional - sage.libs.pari + sage: C.category() # optional - sage.libs.pari Category of chain complexes over Finite Field of size 7 TESTS:: @@ -767,7 +767,7 @@ def rank(self, degree, ring=None): [2] sage: C.rank(0) 1 - sage: C.rank(0, ring=GF(2)) + sage: C.rank(0, ring=GF(2)) # optional - sage.libs.pari 0 """ degree = self.grading_group()(degree) @@ -1075,9 +1075,11 @@ def __eq__(self, other): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(2)) - sage: D = ChainComplex({0: matrix(GF(2), 2, 3, [1, 0, 0, 0, 0, 0]), 1: matrix(ZZ, 0, 2), 3: matrix(ZZ, 0, 0)}) # base_ring determined from the matrices - sage: C == D + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(2)) # optional - sage.libs.pari + sage: D = ChainComplex({0: matrix(GF(2), 2, 3, [1, 0, 0, 0, 0, 0]), # optional - sage.libs.pari + ....: 1: matrix(ZZ, 0, 2), + ....: 3: matrix(ZZ, 0, 0)}) # base_ring determined from the matrices + sage: C == D # optional - sage.libs.pari True """ if not isinstance(other, ChainComplex_class) or self.base_ring() != other.base_ring(): @@ -1101,12 +1103,14 @@ def __ne__(self, other): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(2)) - sage: D = ChainComplex({0: matrix(GF(2), 2, 3, [1, 0, 0, 0, 0, 0]), 1: matrix(ZZ, 0, 2), 3: matrix(ZZ, 0, 0)}) # base_ring determined from the matrices - sage: C != D + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(2)) # optional - sage.libs.pari + sage: D = ChainComplex({0: matrix(GF(2), 2, 3, [1, 0, 0, 0, 0, 0]), # optional - sage.libs.pari + ....: 1: matrix(ZZ, 0, 2), + ....: 3: matrix(ZZ, 0, 0)}) # base_ring determined from the matrices + sage: C != D # optional - sage.libs.pari False sage: E = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=ZZ) - sage: C != E + sage: C != E # optional - sage.libs.pari True """ return not self == other @@ -1132,15 +1136,15 @@ def _homology_chomp(self, deg, base_ring, verbose, generators): EXAMPLES:: - sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(2)) - sage: C._homology_chomp(None, GF(2), False, False) # optional - CHomP + sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}, base_ring=GF(2)) # optional - sage.libs.pari + sage: C._homology_chomp(None, GF(2), False, False) # optional - CHomP # optional - sage.libs.pari doctest:...: DeprecationWarning: the CHomP interface is deprecated; hence so is this function See https://github.com/sagemath/sage/issues/33777 for details. {0: Vector space of dimension 2 over Finite Field of size 2, 1: Vector space of dimension 1 over Finite Field of size 2} sage: D = ChainComplex({0: matrix(ZZ,1,0,[]), 1: matrix(ZZ,1,1,[0]), ....: 2: matrix(ZZ,0,1,[])}) - sage: D._homology_chomp(None, GF(2), False, False) # optional - CHomP + sage: D._homology_chomp(None, GF(2), False, False) # optional - CHomP # optional - sage.libs.pari {1: Vector space of dimension 1 over Finite Field of size 2, 2: Vector space of dimension 1 over Finite Field of size 2} """ @@ -1242,7 +1246,7 @@ def homology(self, deg=None, base_ring=None, generators=False, sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) sage: C.homology() {0: Z x Z, 1: Z x C3} - sage: C.homology(deg=1, base_ring = GF(3)) + sage: C.homology(deg=1, base_ring=GF(3)) # optional - sage.libs.pari Vector space of dimension 2 over Finite Field of size 3 sage: D = ChainComplex({0: identity_matrix(ZZ, 4), 4: identity_matrix(ZZ, 30)}) sage: D.homology() @@ -1269,9 +1273,9 @@ def homology(self, deg=None, base_ring=None, generators=False, From a torus using a field:: - sage: T = simplicial_complexes.Torus() - sage: C_t = T.chain_complex() - sage: C_t.homology(base_ring=QQ, generators=True) + sage: T = simplicial_complexes.Torus() # optional - sage.graphs + sage: C_t = T.chain_complex() # optional - sage.graphs + sage: C_t.homology(base_ring=QQ, generators=True) # optional - sage.graphs {0: [(Vector space of dimension 1 over Rational Field, Chain(0:(0, 0, 0, 0, 0, 0, 1)))], 1: [(Vector space of dimension 1 over Rational Field, @@ -1450,8 +1454,8 @@ def betti(self, deg=None, base_ring=None): sage: C.betti() {0: 2, 1: 1} - sage: D = ChainComplex({0:matrix(GF(5), [[3, 1],[1, 2]])}) - sage: D.betti() + sage: D = ChainComplex({0:matrix(GF(5), [[3, 1],[1, 2]])}) # optional - sage.libs.pari + sage: D.betti() # optional - sage.libs.pari {0: 1, 1: 1} """ if base_ring is None: @@ -1502,14 +1506,14 @@ def torsion_list(self, max_prime, min_prime=2): sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) sage: C.homology() {0: Z x Z, 1: Z x C3} - sage: C.torsion_list(11) + sage: C.torsion_list(11) # optional - sage.libs.pari [(3, [1])] sage: C = ChainComplex([matrix(ZZ, 1, 1, [2]), matrix(ZZ, 1, 1), matrix(1, 1, [3])]) sage: C.homology(1) C2 sage: C.homology(3) C3 - sage: C.torsion_list(5) + sage: C.torsion_list(5) # optional - sage.libs.pari [(2, [1]), (3, [3])] """ if self.base_ring() != ZZ: @@ -1549,11 +1553,11 @@ def _Hom_(self, other, category=None): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(2) - sage: T = simplicial_complexes.Torus() - sage: C = S.chain_complex(augmented=True,cochain=True) - sage: D = T.chain_complex(augmented=True,cochain=True) - sage: Hom(C,D) # indirect doctest + sage: S = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: T = simplicial_complexes.Torus() # optional - sage.graphs + sage: C = S.chain_complex(augmented=True,cochain=True) # optional - sage.graphs + sage: D = T.chain_complex(augmented=True,cochain=True) # optional - sage.graphs + sage: Hom(C, D) # indirect doctest # optional - sage.graphs Set of Morphisms from Chain complex with at most 4 nonzero terms over Integer Ring to Chain complex with at most 4 nonzero terms over Integer Ring in Category of chain complexes over Integer Ring @@ -1615,25 +1619,25 @@ def shift(self, n=1): EXAMPLES:: - sage: S1 = simplicial_complexes.Sphere(1).chain_complex() - sage: S1.shift(1).differential(2) == -S1.differential(1) + sage: S1 = simplicial_complexes.Sphere(1).chain_complex() # optional - sage.graphs + sage: S1.shift(1).differential(2) == -S1.differential(1) # optional - sage.graphs True - sage: S1.shift(2).differential(3) == S1.differential(1) + sage: S1.shift(2).differential(3) == S1.differential(1) # optional - sage.graphs True - sage: S1.shift(3).homology(4) + sage: S1.shift(3).homology(4) # optional - sage.graphs Z For cochain complexes, shifting goes in the other direction. Topologically, this makes sense if we grade the cochain complex for a space negatively:: - sage: T = simplicial_complexes.Torus() - sage: co_T = T.chain_complex()._flip_() - sage: co_T.homology() + sage: T = simplicial_complexes.Torus() # optional - sage.graphs + sage: co_T = T.chain_complex()._flip_() # optional - sage.graphs + sage: co_T.homology() # optional - sage.graphs {-2: Z, -1: Z x Z, 0: Z} - sage: co_T.degree_of_differential() + sage: co_T.degree_of_differential() # optional - sage.graphs 1 - sage: co_T.shift(2).homology() + sage: co_T.shift(2).homology() # optional - sage.graphs {-4: Z, -3: Z x Z, -2: Z} You can achieve the same result by tensoring (on the left, to @@ -1641,7 +1645,7 @@ def shift(self, n=1): ``-n * deg``, if ``deg`` is the degree of the differential:: sage: C = ChainComplex({-2: matrix(ZZ, 0, 1)}) - sage: C.tensor(co_T).homology() + sage: C.tensor(co_T).homology() # optional - sage.graphs {-4: Z, -3: Z x Z, -2: Z} """ deg = self.degree_of_differential() diff --git a/src/sage/homology/chain_complex_homspace.py b/src/sage/homology/chain_complex_homspace.py index 5679b275a82..037a1a4bad0 100644 --- a/src/sage/homology/chain_complex_homspace.py +++ b/src/sage/homology/chain_complex_homspace.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs (because all doctests use SimplicialComplex) r""" Homspaces between chain complexes @@ -12,13 +13,16 @@ sage: S = simplicial_complexes.Sphere(2) sage: T = simplicial_complexes.Torus() - sage: C = S.chain_complex(augmented=True,cochain=True) - sage: D = T.chain_complex(augmented=True,cochain=True) - sage: G = Hom(C,D) + sage: C = S.chain_complex(augmented=True, cochain=True) + sage: D = T.chain_complex(augmented=True, cochain=True) + sage: G = Hom(C, D) sage: G - Set of Morphisms from Chain complex with at most 4 nonzero terms over Integer Ring to Chain complex with at most 4 nonzero terms over Integer Ring in Category of chain complexes over Integer Ring + Set of Morphisms + from Chain complex with at most 4 nonzero terms over Integer Ring + to Chain complex with at most 4 nonzero terms over Integer Ring + in Category of chain complexes over Integer Ring - sage: S = simplicial_complexes.ChessboardComplex(3,3) + sage: S = simplicial_complexes.ChessboardComplex(3, 3) sage: H = Hom(S,S) sage: i = H.identity() sage: x = i.associated_chain_complex_morphism(augmented=True) @@ -60,7 +64,7 @@ [0 0 0 0 0 1]} sage: S = simplicial_complexes.Sphere(2) - sage: A = Hom(S,S) + sage: A = Hom(S, S) sage: i = A.identity() sage: x = i.associated_chain_complex_morphism() sage: x @@ -75,7 +79,7 @@ To: Chain complex with at most 3 nonzero terms over Integer Ring sage: f = x._matrix_dictionary sage: C = S.chain_complex() - sage: G = Hom(C,C) + sage: G = Hom(C, C) sage: w = G(f) sage: w == x True @@ -111,7 +115,7 @@ def is_ChainComplexHomspace(x): sage: from sage.homology.chain_complex_homspace import is_ChainComplexHomspace sage: T = SimplicialComplex([[1,2,3,4],[7,8,9]]) sage: C = T.chain_complex(augmented=True, cochain=True) - sage: G = Hom(C,C) + sage: G = Hom(C, C) sage: is_ChainComplexHomspace(G) True @@ -127,9 +131,12 @@ class ChainComplexHomspace(sage.categories.homset.Homset): sage: T = SimplicialComplex([[1,2,3,4],[7,8,9]]) sage: C = T.chain_complex(augmented=True, cochain=True) - sage: G = Hom(C,C) + sage: G = Hom(C, C) sage: G - Set of Morphisms from Chain complex with at most 5 nonzero terms over Integer Ring to Chain complex with at most 5 nonzero terms over Integer Ring in Category of chain complexes over Integer Ring + Set of Morphisms + from Chain complex with at most 5 nonzero terms over Integer Ring + to Chain complex with at most 5 nonzero terms over Integer Ring + in Category of chain complexes over Integer Ring """ def __call__(self, f): @@ -139,10 +146,10 @@ def __call__(self, f): EXAMPLES:: sage: S = simplicial_complexes.Sphere(5) - sage: H = Hom(S,S) + sage: H = Hom(S, S) sage: i = H.identity() sage: C = S.chain_complex() - sage: G = Hom(C,C) + sage: G = Hom(C, C) sage: x = i.associated_chain_complex_morphism() sage: f = x._matrix_dictionary sage: y = G(f) diff --git a/src/sage/homology/chain_complex_morphism.py b/src/sage/homology/chain_complex_morphism.py index b049b534e0b..e79ec6c6cc9 100644 --- a/src/sage/homology/chain_complex_morphism.py +++ b/src/sage/homology/chain_complex_morphism.py @@ -14,20 +14,20 @@ EXAMPLES:: - sage: S = simplicial_complexes.Sphere(1) - sage: S + sage: S = simplicial_complexes.Sphere(1) # optional - sage.graphs + sage: S # optional - sage.graphs Minimal triangulation of the 1-sphere - sage: C = S.chain_complex() - sage: C.differential() + sage: C = S.chain_complex() # optional - sage.graphs + sage: C.differential() # optional - sage.graphs {0: [], 1: [-1 -1 0] [ 1 0 -1] [ 0 1 1], 2: []} sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)} - sage: G = Hom(C,C) - sage: x = G(f) - sage: x + sage: G = Hom(C,C) # optional - sage.graphs + sage: x = G(f) # optional - sage.graphs + sage: x # optional - sage.graphs Chain complex endomorphism of Chain complex with at most 2 nonzero terms over Integer Ring - sage: x._matrix_dictionary + sage: x._matrix_dictionary # optional - sage.graphs {0: [0 0 0] [0 0 0] [0 0 0], 1: [0 0 0] @@ -64,18 +64,18 @@ def is_ChainComplexMorphism(x): EXAMPLES:: sage: from sage.homology.chain_complex_morphism import is_ChainComplexMorphism - sage: S = simplicial_complexes.Sphere(14) - sage: H = Hom(S,S) - sage: i = H.identity() # long time (8s on sage.math, 2011) - sage: S = simplicial_complexes.Sphere(6) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: x # indirect doctest + sage: S = simplicial_complexes.Sphere(14) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # long time (8s on sage.math, 2011) # optional - sage.graphs + sage: S = simplicial_complexes.Sphere(6) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: x # indirect doctest # optional - sage.graphs Chain complex morphism: From: Chain complex with at most 7 nonzero terms over Integer Ring To: Chain complex with at most 7 nonzero terms over Integer Ring - sage: is_ChainComplexMorphism(x) + sage: is_ChainComplexMorphism(x) # optional - sage.graphs True """ return isinstance(x, ChainComplexMorphism) @@ -91,20 +91,20 @@ def __init__(self, matrices, C, D, check=True): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(1) - sage: S + sage: S = simplicial_complexes.Sphere(1) # optional - sage.graphs + sage: S # optional - sage.graphs Minimal triangulation of the 1-sphere - sage: C = S.chain_complex() - sage: C.differential() + sage: C = S.chain_complex() # optional - sage.graphs + sage: C.differential() # optional - sage.graphs {0: [], 1: [-1 -1 0] [ 1 0 -1] [ 0 1 1], 2: []} sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)} - sage: G = Hom(C,C) - sage: x = G(f) - sage: x + sage: G = Hom(C,C) # optional - sage.graphs + sage: x = G(f) # optional - sage.graphs + sage: x # optional - sage.graphs Chain complex endomorphism of Chain complex with at most 2 nonzero terms over Integer Ring - sage: x._matrix_dictionary + sage: x._matrix_dictionary # optional - sage.graphs {0: [0 0 0] [0 0 0] [0 0 0], 1: [0 0 0] @@ -113,10 +113,10 @@ def __init__(self, matrices, C, D, check=True): Check that the bug in :trac:`13220` has been fixed:: - sage: X = simplicial_complexes.Simplex(1) - sage: Y = simplicial_complexes.Simplex(0) - sage: g = Hom(X,Y)({0:0, 1:0}) - sage: g.associated_chain_complex_morphism() + sage: X = simplicial_complexes.Simplex(1) # optional - sage.graphs + sage: Y = simplicial_complexes.Simplex(0) # optional - sage.graphs + sage: g = Hom(X,Y)({0:0, 1:0}) # optional - sage.graphs + sage: g.associated_chain_complex_morphism() # optional - sage.graphs Chain complex morphism: From: Chain complex with at most 2 nonzero terms over Integer Ring To: Chain complex with at most 1 nonzero terms over Integer Ring @@ -264,24 +264,24 @@ def dual(self): EXAMPLES:: - sage: X = simplicial_complexes.Simplex(1) - sage: Y = simplicial_complexes.Simplex(0) - sage: g = Hom(X,Y)({0:0, 1:0}) - sage: f = g.associated_chain_complex_morphism() - sage: f.in_degree(0) + sage: X = simplicial_complexes.Simplex(1) # optional - sage.graphs + sage: Y = simplicial_complexes.Simplex(0) # optional - sage.graphs + sage: g = Hom(X,Y)({0:0, 1:0}) # optional - sage.graphs + sage: f = g.associated_chain_complex_morphism() # optional - sage.graphs + sage: f.in_degree(0) # optional - sage.graphs [1 1] - sage: f.dual() + sage: f.dual() # optional - sage.graphs Chain complex morphism: From: Chain complex with at most 1 nonzero terms over Integer Ring To: Chain complex with at most 2 nonzero terms over Integer Ring - sage: f.dual().in_degree(0) + sage: f.dual().in_degree(0) # optional - sage.graphs [1] [1] - sage: ascii_art(f.domain()) + sage: ascii_art(f.domain()) # optional - sage.graphs [-1] [ 1] 0 <-- C_0 <----- C_1 <-- 0 - sage: ascii_art(f.dual().codomain()) + sage: ascii_art(f.dual().codomain()) # optional - sage.graphs [-1 1] 0 <-- C_1 <-------- C_0 <-- 0 """ @@ -295,12 +295,12 @@ def __neg__(self): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(2) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: w = -x - sage: w._matrix_dictionary + sage: S = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: w = -x # optional - sage.graphs + sage: w._matrix_dictionary # optional - sage.graphs {0: [-1 0 0 0] [ 0 -1 0 0] [ 0 0 -1 0] @@ -328,12 +328,12 @@ def __add__(self,x): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(2) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: z = x+x - sage: z._matrix_dictionary + sage: S = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: z = x+x # optional - sage.graphs + sage: z._matrix_dictionary # optional - sage.graphs {0: [2 0 0 0] [0 2 0 0] [0 0 2 0] @@ -363,12 +363,12 @@ def __mul__(self, x): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(2) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: y = x*2 - sage: y._matrix_dictionary + sage: S = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: y = x*2 # optional - sage.graphs + sage: y._matrix_dictionary # optional - sage.graphs {0: [2 0 0 0] [0 2 0 0] [0 0 2 0] @@ -383,8 +383,8 @@ def __mul__(self, x): [0 2 0 0] [0 0 2 0] [0 0 0 2]} - sage: z = y*y - sage: z._matrix_dictionary + sage: z = y*y # optional - sage.graphs + sage: z._matrix_dictionary # optional - sage.graphs {0: [4 0 0 0] [0 4 0 0] [0 0 4 0] @@ -449,13 +449,13 @@ def __rmul__(self,x): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(2) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: 2*x == x*2 + sage: S = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: 2*x == x*2 # optional - sage.graphs True - sage: 3*x == x*2 + sage: 3*x == x*2 # optional - sage.graphs False """ try: @@ -473,12 +473,12 @@ def __sub__(self,x): EXAMPLES:: - sage: S = simplicial_complexes.Sphere(2) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: y = x-x - sage: y._matrix_dictionary + sage: S = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: y = x-x # optional - sage.graphs + sage: y._matrix_dictionary # optional - sage.graphs {0: [0 0 0 0] [0 0 0 0] [0 0 0 0] @@ -502,19 +502,19 @@ def __eq__(self,x): EXAMPLES:: - sage: S = SimplicialComplex(is_mutable=False) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: x + sage: S = SimplicialComplex(is_mutable=False) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: x # optional - sage.graphs Chain complex morphism: From: Trivial chain complex over Integer Ring To: Trivial chain complex over Integer Ring - sage: f = x._matrix_dictionary - sage: C = S.chain_complex() - sage: G = Hom(C,C) - sage: y = G(f) - sage: x == y + sage: f = x._matrix_dictionary # optional - sage.graphs + sage: C = S.chain_complex() # optional - sage.graphs + sage: G = Hom(C,C) # optional - sage.graphs + sage: y = G(f) # optional - sage.graphs + sage: x == y # optional - sage.graphs True """ return isinstance(x,ChainComplexMorphism) \ @@ -528,11 +528,11 @@ def is_identity(self): EXAMPLES:: - sage: S = SimplicialComplex(is_mutable=False) - sage: H = Hom(S,S) - sage: i = H.identity() - sage: x = i.associated_chain_complex_morphism() - sage: x.is_identity() + sage: S = SimplicialComplex(is_mutable=False) # optional - sage.graphs + sage: H = Hom(S,S) # optional - sage.graphs + sage: i = H.identity() # optional - sage.graphs + sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs + sage: x.is_identity() # optional - sage.graphs True """ return self.to_matrix().is_one() @@ -543,17 +543,17 @@ def is_surjective(self): EXAMPLES:: - sage: S1 = simplicial_complexes.Sphere(1) - sage: H = Hom(S1, S1) - sage: flip = H({0:0, 1:2, 2:1}) - sage: flip.associated_chain_complex_morphism().is_surjective() + sage: S1 = simplicial_complexes.Sphere(1) # optional - sage.graphs + sage: H = Hom(S1, S1) # optional - sage.graphs + sage: flip = H({0:0, 1:2, 2:1}) # optional - sage.graphs + sage: flip.associated_chain_complex_morphism().is_surjective() # optional - sage.graphs True - sage: pt = simplicial_complexes.Simplex(0) - sage: inclusion = Hom(pt, S1)({0:2}) - sage: inclusion.associated_chain_complex_morphism().is_surjective() + sage: pt = simplicial_complexes.Simplex(0) # optional - sage.graphs + sage: inclusion = Hom(pt, S1)({0:2}) # optional - sage.graphs + sage: inclusion.associated_chain_complex_morphism().is_surjective() # optional - sage.graphs False - sage: inclusion.associated_chain_complex_morphism(cochain=True).is_surjective() + sage: inclusion.associated_chain_complex_morphism(cochain=True).is_surjective() # optional - sage.graphs True """ m = self.to_matrix() @@ -565,17 +565,17 @@ def is_injective(self): EXAMPLES:: - sage: S1 = simplicial_complexes.Sphere(1) - sage: H = Hom(S1, S1) - sage: flip = H({0:0, 1:2, 2:1}) - sage: flip.associated_chain_complex_morphism().is_injective() + sage: S1 = simplicial_complexes.Sphere(1) # optional - sage.graphs + sage: H = Hom(S1, S1) # optional - sage.graphs + sage: flip = H({0:0, 1:2, 2:1}) # optional - sage.graphs + sage: flip.associated_chain_complex_morphism().is_injective() # optional - sage.graphs True - sage: pt = simplicial_complexes.Simplex(0) - sage: inclusion = Hom(pt, S1)({0:2}) - sage: inclusion.associated_chain_complex_morphism().is_injective() + sage: pt = simplicial_complexes.Simplex(0) # optional - sage.graphs + sage: inclusion = Hom(pt, S1)({0:2}) # optional - sage.graphs + sage: inclusion.associated_chain_complex_morphism().is_injective() # optional - sage.graphs True - sage: inclusion.associated_chain_complex_morphism(cochain=True).is_injective() + sage: inclusion.associated_chain_complex_morphism(cochain=True).is_injective() # optional - sage.graphs False """ return self.to_matrix().right_nullity() == 0 diff --git a/src/sage/homology/chain_homotopy.py b/src/sage/homology/chain_homotopy.py index afeaee2430c..946973f95be 100644 --- a/src/sage/homology/chain_homotopy.py +++ b/src/sage/homology/chain_homotopy.py @@ -121,7 +121,8 @@ def __init__(self, matrices, f, g=None): `f - (H \partial + \partial H)`. :: sage: from sage.homology.chain_homotopy import ChainHomotopy - sage: C = ChainComplex({1: matrix(ZZ, 1, 2, (1,0)), 2: matrix(ZZ, 2, 1, (0, 2))}, degree_of_differential=-1) + sage: C = ChainComplex({1: matrix(ZZ, 1, 2, (1,0)), 2: matrix(ZZ, 2, 1, (0, 2))}, + ....: degree_of_differential=-1) sage: D = ChainComplex({2: matrix(ZZ, 1, 1, (6,))}, degree_of_differential=-1) sage: f_d = {1: matrix(ZZ, 1, 2, (0,3)), 2: identity_matrix(ZZ, 1)} sage: f = Hom(C,D)(f_d) @@ -488,20 +489,20 @@ def pi(self): EXAMPLES:: - sage: S2 = simplicial_complexes.Sphere(2) - sage: phi, M = S2.algebraic_topological_model(QQ) - sage: phi.pi() + sage: S2 = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: phi, M = S2.algebraic_topological_model(QQ) # optional - sage.graphs + sage: phi.pi() # optional - sage.graphs Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Rational Field To: Chain complex with at most 3 nonzero terms over Rational Field - sage: phi.pi().in_degree(0) # Every vertex represents a homology class. + sage: phi.pi().in_degree(0) # Every vertex represents a homology class. # optional - sage.graphs [1 1 1 1] - sage: phi.pi().in_degree(1) # No homology in degree 1. + sage: phi.pi().in_degree(1) # No homology in degree 1. # optional - sage.graphs [] The degree 2 homology generator is detected on a single simplex:: - sage: phi.pi().in_degree(2) + sage: phi.pi().in_degree(2) # optional - sage.graphs [0 0 0 1] """ return self._pi @@ -512,16 +513,16 @@ def iota(self): EXAMPLES:: - sage: S2 = simplicial_complexes.Sphere(2) - sage: phi, M = S2.algebraic_topological_model(QQ) - sage: phi.iota() + sage: S2 = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: phi, M = S2.algebraic_topological_model(QQ) # optional - sage.graphs + sage: phi.iota() # optional - sage.graphs Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Rational Field To: Chain complex with at most 3 nonzero terms over Rational Field Lifting the degree zero homology class gives a single vertex:: - sage: phi.iota().in_degree(0) + sage: phi.iota().in_degree(0) # optional - sage.graphs [0] [0] [0] @@ -530,7 +531,7 @@ def iota(self): Lifting the degree two homology class gives the signed sum of all of the 2-simplices:: - sage: phi.iota().in_degree(2) + sage: phi.iota().in_degree(2) # optional - sage.graphs [-1] [ 1] [-1] @@ -546,9 +547,9 @@ def dual(self): EXAMPLES:: - sage: S2 = simplicial_complexes.Sphere(2) - sage: phi, M = S2.algebraic_topological_model(QQ) - sage: phi.iota() + sage: S2 = simplicial_complexes.Sphere(2) # optional - sage.graphs + sage: phi, M = S2.algebraic_topological_model(QQ) # optional - sage.graphs + sage: phi.iota() # optional - sage.graphs Chain complex morphism: From: Chain complex with at most 3 nonzero terms over Rational Field To: Chain complex with at most 3 nonzero terms over Rational Field @@ -557,22 +558,22 @@ def dual(self): but the degree zero cohomology class needs to be detected on every vertex, and vice versa for degree 2:: - sage: phi.iota().in_degree(0) + sage: phi.iota().in_degree(0) # optional - sage.graphs [0] [0] [0] [1] - sage: phi.dual().iota().in_degree(0) + sage: phi.dual().iota().in_degree(0) # optional - sage.graphs [1] [1] [1] [1] - sage: phi.iota().in_degree(2) + sage: phi.iota().in_degree(2) # optional - sage.graphs [-1] [ 1] [-1] [ 1] - sage: phi.dual().iota().in_degree(2) + sage: phi.dual().iota().in_degree(2) # optional - sage.graphs [0] [0] [0] diff --git a/src/sage/homology/chains.py b/src/sage/homology/chains.py index 7bd375f35fd..86e2eaec897 100644 --- a/src/sage/homology/chains.py +++ b/src/sage/homology/chains.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.graphs (because all doctests use the catalogs simplicial_complexes, cubical_complexes) r""" Chains and cochains diff --git a/src/sage/homology/free_resolution.py b/src/sage/homology/free_resolution.py index 424086d283e..14cd5aaaf79 100644 --- a/src/sage/homology/free_resolution.py +++ b/src/sage/homology/free_resolution.py @@ -17,33 +17,33 @@ sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() - sage: r = FreeResolution(m, name='S') - sage: r + sage: r = FreeResolution(m, name='S') # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 - sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.free_resolution() - sage: r + sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) # optional - sage.libs.singular + sage: r = I.free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 :: sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 An example of a minimal free resolution from [CLO2005]_:: sage: R. = QQ[] sage: I = R.ideal([y*z - x*w, y^3 - x^2*z, x*z^2 - y^2*w, z^3 - y*w^2]) - sage: r = I.free_resolution() - sage: r + sage: r = I.free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S^1 <-- S^4 <-- S^4 <-- S^1 <-- 0 - sage: len(r) + sage: len(r) # optional - sage.libs.singular 3 - sage: r.matrix(2) + sage: r.matrix(2) # optional - sage.libs.singular [-z^2 -x*z y*w -y^2] [ y 0 -x 0] [ -w y z x] @@ -107,14 +107,14 @@ def __classcall_private__(cls, module, *args, graded=False, degrees=None, shifts sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) - sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() - sage: r = FreeResolution(m, name='S') - sage: type(r) + sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() # optional - sage.libs.singular + sage: r = FreeResolution(m, name='S') # optional - sage.libs.singular + sage: type(r) # optional - sage.libs.singular - sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: type(r) + sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) # optional - sage.libs.singular + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: type(r) # optional - sage.libs.singular sage: R. = QQ[] @@ -122,8 +122,8 @@ def __classcall_private__(cls, module, *args, graded=False, degrees=None, shifts sage: v = M([x^2, 2*x^2, 3*x^2]) sage: w = M([0, x, 2*x]) sage: S = M.submodule([v, w]) - sage: r = FreeResolution(S) - sage: type(r) + sage: r = FreeResolution(S) # optional - sage.libs.singular + sage: type(r) # optional - sage.libs.singular sage: I = R.ideal([x^4 + 3*x^2 + 2]) @@ -134,10 +134,10 @@ def __classcall_private__(cls, module, *args, graded=False, degrees=None, shifts sage: R. = QQ[] sage: I = R.ideal([x^2, y^3]) sage: Q = R.quo(I) - sage: Q.is_integral_domain() + sage: Q.is_integral_domain() # optional - sage.libs.singular False - sage: xb, yb = Q.gens() - sage: FreeResolution(Q.ideal([xb])) # has torsion + sage: xb, yb = Q.gens() # optional - sage.libs.singular + sage: FreeResolution(Q.ideal([xb])) # has torsion # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError: the ring must be a polynomial ring using Singular @@ -199,8 +199,8 @@ def __init__(self, module, name='S', **kwds): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: m1 = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]) - sage: r = FreeResolution(m1, name='S') - sage: TestSuite(r).run(skip=['_test_pickling']) + sage: r = FreeResolution(m1, name='S') # optional - sage.libs.singular + sage: TestSuite(r).run(skip=['_test_pickling']) # optional - sage.libs.singular """ if isinstance(module, Ideal_generic): S = module.ring() @@ -220,8 +220,8 @@ def _repr_(self): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: m1 = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]) - sage: r = FreeResolution(m1, name='S') - sage: print(FreeResolution._repr_(r)) + sage: r = FreeResolution(m1, name='S') # optional - sage.libs.singular + sage: print(FreeResolution._repr_(r)) # optional - sage.libs.singular Free resolution of the row space of the matrix: [z^2 - y*w y*z - x*w y^2 - x*z] """ @@ -242,10 +242,10 @@ def _repr_module(self, i): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: m = matrix(S, 1, [y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(m.transpose(), name='S') - sage: r._repr_module(2) + sage: r = FreeResolution(m.transpose(), name='S') # optional - sage.libs.singular + sage: r._repr_module(2) # optional - sage.libs.singular 'S^2' - sage: r # indirect doctest + sage: r # indirect doctest # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 """ if i == 0: @@ -276,8 +276,8 @@ def differential(self, i): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: m1 = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]) - sage: r = FreeResolution(m1, name='S') - sage: FreeResolution.differiental(r, 1) + sage: r = FreeResolution(m1, name='S') # optional - sage.libs.singular + sage: FreeResolution.differiental(r, 1) # optional - sage.libs.singular Traceback (most recent call last): ... AttributeError: type object 'FreeResolution' has no attribute 'differiental' @@ -294,10 +294,10 @@ def target(self): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: r.target() + sage: r.target() # optional - sage.libs.singular Quotient module by Submodule of Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field Generated by the rows of the matrix: @@ -333,8 +333,8 @@ class FiniteFreeResolution(FreeResolution): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: r.differential(0) + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: r.differential(0) # optional - sage.libs.singular Coercion map: From: Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field @@ -355,8 +355,8 @@ def _length(self): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: r._length + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: r._length # optional - sage.libs.singular 2 """ return len(self._maps) @@ -373,8 +373,8 @@ def _repr_(self): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 """ s = self._repr_module(0) @@ -393,10 +393,10 @@ def __len__(self): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: len(r) + sage: len(r) # optional - sage.libs.singular 2 """ return len(self._maps) @@ -413,10 +413,10 @@ def __getitem__(self, i): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: r.target() + sage: r.target() # optional - sage.libs.singular Quotient module by Submodule of Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field Generated by the rows of the matrix: @@ -446,17 +446,17 @@ def differential(self, i): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: r.differential(3) + sage: r.differential(3) # optional - sage.libs.singular Free module morphism defined by the matrix [] Domain: Ambient free module of rank 0 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field Codomain: Ambient free module of rank 2 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field - sage: r.differential(2) + sage: r.differential(2) # optional - sage.libs.singular Free module morphism defined as left-multiplication by the matrix [-y x] [ z -y] @@ -465,14 +465,14 @@ def differential(self, i): Multivariate Polynomial Ring in x, y, z, w over Rational Field Codomain: Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field - sage: r.differential(1) + sage: r.differential(1) # optional - sage.libs.singular Free module morphism defined as left-multiplication by the matrix [z^2 - y*w y*z - x*w y^2 - x*z] Domain: Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field Codomain: Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field - sage: r.differential(0) + sage: r.differential(0) # optional - sage.libs.singular Coercion map: From: Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field @@ -516,16 +516,16 @@ def matrix(self, i): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: r.matrix(3) + sage: r.matrix(3) # optional - sage.libs.singular [] - sage: r.matrix(2) + sage: r.matrix(2) # optional - sage.libs.singular [-y x] [ z -y] [-w z] - sage: r.matrix(1) + sage: r.matrix(1) # optional - sage.libs.singular [z^2 - y*w y*z - x*w y^2 - x*z] """ if i <= 0: @@ -545,8 +545,8 @@ def chain_complex(self): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: unicode_art(r.chain_complex()) + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: unicode_art(r.chain_complex()) # optional - sage.libs.singular ⎛-y x⎞ ⎜ z -y⎟ (z^2 - y*w y*z - x*w y^2 - x*z) ⎝-w z⎠ @@ -568,8 +568,8 @@ def _initial_differential(self): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: r._initial_differential + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: r._initial_differential # optional - sage.libs.singular Coercion map: From: Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y, z, w over Rational Field @@ -607,19 +607,19 @@ def _m(self): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: r._m() + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: r._m() # optional - sage.libs.singular Ideal (-z^2 + y*w, y*z - x*w, -y^2 + x*z) of Multivariate Polynomial Ring in x, y, z, w over Rational Field - sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() - sage: r = FreeResolution(m, name='S') - sage: r._m() + sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() # optional - sage.libs.singular + sage: r = FreeResolution(m, name='S') # optional - sage.libs.singular + sage: r._m() # optional - sage.libs.singular [z^2 - y*w y*z - x*w y^2 - x*z] - sage: M = m.image() - sage: r = FreeResolution(M, name='S') - sage: r._m() + sage: M = m.image() # optional - sage.libs.singular + sage: r = FreeResolution(M, name='S') # optional - sage.libs.singular + sage: r._m() # optional - sage.libs.singular [z^2 - y*w y*z - x*w y^2 - x*z] """ if isinstance(self._module, Ideal_generic): @@ -653,10 +653,10 @@ class FiniteFreeResolution_free_module(FiniteFreeResolution): Echelon basis matrix: [ x^2 2*x^2 3*x^2] [ 0 x 2*x] - sage: res = S.free_resolution() - sage: res + sage: res = S.free_resolution() # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S^3 <-- S^2 <-- 0 - sage: ascii_art(res.chain_complex()) + sage: ascii_art(res.chain_complex()) # optional - sage.libs.singular [ x^2 0] [2*x^2 x] [3*x^2 2*x] @@ -680,15 +680,15 @@ def _maps(self): sage: v = M([x^2, 2*x^2, 3*x^2]) sage: w = M([0, x, 2*x]) sage: S = M.submodule([v, w]) - sage: res = S.free_resolution() - sage: res + sage: res = S.free_resolution() # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S^3 <-- S^2 <-- 0 - sage: ascii_art(res.chain_complex()) + sage: ascii_art(res.chain_complex()) # optional - sage.libs.singular [ x^2 0] [2*x^2 x] [3*x^2 2*x] 0 <-- C_0 <-------------- C_1 <-- 0 - sage: res._maps + sage: res._maps # optional - sage.libs.singular [ [ x^2 0] [2*x^2 x] @@ -776,51 +776,51 @@ class FiniteFreeResolution_singular(FiniteFreeResolution): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: r + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 - sage: len(r) + sage: len(r) # optional - sage.libs.singular 2 :: - sage: FreeResolution(I, algorithm='minimal') + sage: FreeResolution(I, algorithm='minimal') # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 - sage: FreeResolution(I, algorithm='shreyer') + sage: FreeResolution(I, algorithm='shreyer') # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 - sage: FreeResolution(I, algorithm='standard') + sage: FreeResolution(I, algorithm='standard') # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 - sage: FreeResolution(I, algorithm='heuristic') + sage: FreeResolution(I, algorithm='heuristic') # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 We can also construct a resolution by passing in a matrix defining the initial differential:: sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() - sage: r = FreeResolution(m, name='S') - sage: r + sage: r = FreeResolution(m, name='S') # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 - sage: r.matrix(1) + sage: r.matrix(1) # optional - sage.libs.singular [z^2 - y*w y*z - x*w y^2 - x*z] An additional construction is using a submodule of a free module:: - sage: M = m.image() - sage: r = FreeResolution(M, name='S') - sage: r + sage: M = m.image() # optional - sage.libs.singular + sage: r = FreeResolution(M, name='S') # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S^1 <-- S^3 <-- S^2 <-- 0 A nonhomogeneous ideal:: sage: I = S.ideal([z^2 - y*w, y*z - x*w, y^2 - x]) - sage: R = FreeResolution(I) - sage: R + sage: R = FreeResolution(I) # optional - sage.libs.singular + sage: R # optional - sage.libs.singular S^1 <-- S^3 <-- S^3 <-- S^1 <-- 0 - sage: R.matrix(2) + sage: R.matrix(2) # optional - sage.libs.singular [ y*z - x*w y^2 - x 0] [-z^2 + y*w 0 y^2 - x] [ 0 -z^2 + y*w -y*z + x*w] - sage: R.matrix(3) + sage: R.matrix(3) # optional - sage.libs.singular [ y^2 - x] [-y*z + x*w] [ z^2 - y*w] @@ -834,16 +834,16 @@ def __init__(self, module, name='S', algorithm='heuristic', **kwds): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: TestSuite(r).run(skip=['_test_pickling']) + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: TestSuite(r).run(skip=['_test_pickling']) # optional - sage.libs.singular sage: m = matrix(S, 1, [z^2 - y*w, y*z - x*w, y^2 - x*z]).transpose() - sage: r = FreeResolution(m, name='S') - sage: TestSuite(r).run(skip=['_test_pickling']) + sage: r = FreeResolution(m, name='S') # optional - sage.libs.singular + sage: TestSuite(r).run(skip=['_test_pickling']) # optional - sage.libs.singular sage: M = m.image() - sage: r = FreeResolution(M, name='S') - sage: TestSuite(r).run(skip=['_test_pickling']) + sage: r = FreeResolution(M, name='S') # optional - sage.libs.singular + sage: TestSuite(r).run(skip=['_test_pickling']) # optional - sage.libs.singular """ self._algorithm = algorithm super().__init__(module, name=name, **kwds) @@ -858,8 +858,8 @@ def _maps(self): sage: from sage.homology.free_resolution import FreeResolution sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = FreeResolution(I) - sage: r._maps + sage: r = FreeResolution(I) # optional - sage.libs.singular + sage: r._maps # optional - sage.libs.singular [ [-y x] [ z -y] diff --git a/src/sage/homology/graded_resolution.py b/src/sage/homology/graded_resolution.py index d9aa9e11119..476a3d6cccf 100644 --- a/src/sage/homology/graded_resolution.py +++ b/src/sage/homology/graded_resolution.py @@ -9,36 +9,36 @@ sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution(algorithm='minimal') - sage: r + sage: r = I.graded_free_resolution(algorithm='minimal') # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: I.graded_free_resolution(algorithm='shreyer') + sage: I.graded_free_resolution(algorithm='shreyer') # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: I.graded_free_resolution(algorithm='standard') + sage: I.graded_free_resolution(algorithm='standard') # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: I.graded_free_resolution(algorithm='heuristic') + sage: I.graded_free_resolution(algorithm='heuristic') # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 :: - sage: d = r.differential(2) - sage: d + sage: d = r.differential(2) # optional - sage.libs.singular + sage: d # optional - sage.libs.singular Free module morphism defined as left-multiplication by the matrix [ y x] [-z -y] [ w z] - Domain: Ambient free module of rank 2 over the integral domain Multivariate Polynomial Ring - in x, y, z, w over Rational Field - Codomain: Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring - in x, y, z, w over Rational Field - sage: d.image() - Submodule of Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring - in x, y, z, w over Rational Field + Domain: Ambient free module of rank 2 over the integral domain + Multivariate Polynomial Ring in x, y, z, w over Rational Field + Codomain: Ambient free module of rank 3 over the integral domain + Multivariate Polynomial Ring in x, y, z, w over Rational Field + sage: d.image() # optional - sage.libs.singular + Submodule of Ambient free module of rank 3 over the integral domain + Multivariate Polynomial Ring in x, y, z, w over Rational Field Generated by the rows of the matrix: [ y -z w] [ x -y z] - sage: m = d.image() - sage: m.graded_free_resolution(shifts=(2,2,2)) + sage: m = d.image() # optional - sage.libs.singular + sage: m.graded_free_resolution(shifts=(2,2,2)) # optional - sage.libs.singular S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 An example of multigraded resolution from Example 9.1 of [MilStu2005]_:: @@ -46,14 +46,15 @@ sage: R. = QQ[] sage: S. = QQ[] sage: phi = S.hom([s, s*t, s*t^2, s*t^3]) - sage: I = phi.kernel(); I - Ideal (c^2 - b*d, b*c - a*d, b^2 - a*c) of Multivariate Polynomial Ring in a, b, c, d over Rational Field - sage: P3 = ProjectiveSpace(S) - sage: C = P3.subscheme(I) # twisted cubic curve - sage: r = I.graded_free_resolution(degrees=[(1,0), (1,1), (1,2), (1,3)]) - sage: r + sage: I = phi.kernel(); I # optional - sage.libs.singular + Ideal (c^2 - b*d, b*c - a*d, b^2 - a*c) of + Multivariate Polynomial Ring in a, b, c, d over Rational Field + sage: P3 = ProjectiveSpace(S) # optional - sage.libs.singular + sage: C = P3.subscheme(I) # twisted cubic curve # optional - sage.libs.singular + sage: r = I.graded_free_resolution(degrees=[(1,0), (1,1), (1,2), (1,3)]) # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S((0, 0)) <-- S((-2, -4))⊕S((-2, -3))⊕S((-2, -2)) <-- S((-3, -5))⊕S((-3, -4)) <-- 0 - sage: r.K_polynomial(names='s,t') + sage: r.K_polynomial(names='s,t') # optional - sage.libs.singular s^3*t^5 + s^3*t^4 - s^2*t^4 - s^2*t^3 - s^2*t^2 + 1 AUTHORS: @@ -115,8 +116,8 @@ def __init__(self, module, degrees=None, shifts=None, name='S', **kwds): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: TestSuite(r).run(skip=['_test_pickling']) + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: TestSuite(r).run(skip=['_test_pickling']) # optional - sage.libs.singular An overdetermined system over a PID:: @@ -124,10 +125,10 @@ def __init__(self, module, degrees=None, shifts=None, name='S', **kwds): sage: M = matrix([[x^2, 2*x^2], ....: [3*x^2, 5*x^2], ....: [5*x^2, 4*x^2]]) - sage: res = FreeResolution(M, graded=True) - sage: res + sage: res = FreeResolution(M, graded=True) # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S(0)⊕S(0) <-- S(-2)⊕S(-2) <-- 0 - sage: res._res_shifts + sage: res._res_shifts # optional - sage.libs.singular [[2, 2]] """ super().__init__(module, name=name, **kwds) @@ -169,18 +170,18 @@ def _repr_module(self, i): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r._repr_module(0) + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r._repr_module(0) # optional - sage.libs.singular 'S(0)' - sage: r._repr_module(1) + sage: r._repr_module(1) # optional - sage.libs.singular 'S(-2)⊕S(-2)⊕S(-2)' - sage: r._repr_module(2) + sage: r._repr_module(2) # optional - sage.libs.singular 'S(-3)⊕S(-3)' - sage: r._repr_module(3) + sage: r._repr_module(3) # optional - sage.libs.singular '0' - sage: r = I.graded_free_resolution(shifts=[-1]) - sage: r._repr_module(0) + sage: r = I.graded_free_resolution(shifts=[-1]) # optional - sage.libs.singular + sage: r._repr_module(0) # optional - sage.libs.singular 'S(1)' """ self._maps # to set _res_shifts @@ -206,14 +207,14 @@ def shifts(self, i): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r.shifts(0) + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r.shifts(0) # optional - sage.libs.singular [0] - sage: r.shifts(1) + sage: r.shifts(1) # optional - sage.libs.singular [2, 2, 2] - sage: r.shifts(2) + sage: r.shifts(2) # optional - sage.libs.singular [3, 3] - sage: r.shifts(3) + sage: r.shifts(3) # optional - sage.libs.singular [] """ if i < 0: @@ -242,18 +243,18 @@ def betti(self, i, a=None): sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r.betti(0) + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r.betti(0) # optional - sage.libs.singular {0: 1} - sage: r.betti(1) + sage: r.betti(1) # optional - sage.libs.singular {2: 3} - sage: r.betti(2) + sage: r.betti(2) # optional - sage.libs.singular {3: 2} - sage: r.betti(1, 0) + sage: r.betti(1, 0) # optional - sage.libs.singular 0 - sage: r.betti(1, 1) + sage: r.betti(1, 1) # optional - sage.libs.singular 0 - sage: r.betti(1, 2) + sage: r.betti(1, 2) # optional - sage.libs.singular 3 """ shifts = self.shifts(i) @@ -284,9 +285,9 @@ def K_polynomial(self, names=None): EXAMPLES:: sage: S. = PolynomialRing(QQ) - sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r.K_polynomial() + sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) # optional - sage.libs.singular + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r.K_polynomial() # optional - sage.libs.singular 2*t^3 - 3*t^2 + 1 """ if self._multigrade: @@ -327,8 +328,8 @@ class GradedFiniteFreeResolution_free_module(GradedFiniteFreeResolution, FiniteF sage: R. = QQ[] sage: M = matrix([[x^3, 3*x^3, 5*x^3], ....: [0, x, 2*x]]) - sage: res = FreeResolution(M, graded=True) - sage: res + sage: res = FreeResolution(M, graded=True) # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S(0)⊕S(0)⊕S(0) <-- S(-3)⊕S(-1) <-- 0 """ def __init__(self, module, degrees=None, *args, **kwds): @@ -341,8 +342,8 @@ def __init__(self, module, degrees=None, *args, **kwds): sage: R. = QQ[] sage: M = matrix([[x^3, 3*x^3, 5*x^3], ....: [0, x, 2*x]]) - sage: res = FreeResolution(M, graded=True) - sage: TestSuite(res).run(skip="_test_pickling") + sage: res = FreeResolution(M, graded=True) # optional - sage.libs.singular + sage: TestSuite(res).run(skip="_test_pickling") # optional - sage.libs.singular """ super().__init__(module, degrees=degrees, *args, **kwds) @@ -363,25 +364,25 @@ def _maps(self): sage: R. = QQ[] sage: M = matrix([[x^3, 3*x^3, 5*x^3], ....: [0, x, 2*x]]) - sage: res = FreeResolution(M, graded=True) - sage: res + sage: res = FreeResolution(M, graded=True) # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S(0)⊕S(0)⊕S(0) <-- S(-3)⊕S(-1) <-- 0 - sage: res._maps + sage: res._maps # optional - sage.libs.singular [ [ x^3 0] [3*x^3 x] [5*x^3 2*x] ] - sage: res._res_shifts + sage: res._res_shifts # optional - sage.libs.singular [[3, 1]] sage: I = R.ideal([x^4]) - sage: res = I.graded_free_resolution(shifts=[1], degrees=[2]) - sage: res + sage: res = I.graded_free_resolution(shifts=[1], degrees=[2]) # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S(-1) <-- S(-9) <-- 0 - sage: res._maps + sage: res._maps # optional - sage.libs.singular [[x^4]] - sage: res._res_shifts + sage: res._res_shifts # optional - sage.libs.singular [[9]] """ def compute_degree(base, i): @@ -473,17 +474,17 @@ class GradedFiniteFreeResolution_singular(GradedFiniteFreeResolution, FiniteFree sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0 - sage: len(r) + sage: len(r) # optional - sage.libs.singular 2 sage: I = S.ideal([z^2 - y*w, y*z - x*w, y - x]) sage: I.is_homogeneous() True - sage: r = I.graded_free_resolution() - sage: r + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r # optional - sage.libs.singular S(0) <-- S(-1)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3)⊕S(-4) <-- S(-5) <-- 0 """ def __init__(self, module, degrees=None, shifts=None, name='S', algorithm='heuristic', **kwds): @@ -494,8 +495,8 @@ def __init__(self, module, degrees=None, shifts=None, name='S', algorithm='heuri sage: S. = PolynomialRing(QQ) sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: TestSuite(r).run(skip=['_test_pickling']) + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: TestSuite(r).run(skip=['_test_pickling']) # optional - sage.libs.singular """ super().__init__(module, degrees=degrees, shifts=shifts, name=name, **kwds) self._algorithm = algorithm @@ -510,15 +511,15 @@ def _maps(self): TESTS:: sage: S. = PolynomialRing(QQ) - sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) - sage: r = I.graded_free_resolution() - sage: r._maps + sage: I = S.ideal([y*w - z^2, -x*w + y*z, x*z - y^2]) # optional - sage.libs.singular + sage: r = I.graded_free_resolution() # optional - sage.libs.singular + sage: r._maps # optional - sage.libs.singular [ [-y x] [ z -y] [z^2 - y*w y*z - x*w y^2 - x*z], [-w z] ] - sage: r._res_shifts + sage: r._res_shifts # optional - sage.libs.singular [[2, 2, 2], [3, 3]] """ #cdef int i, j, k, ncols, nrows diff --git a/src/sage/homology/hochschild_complex.py b/src/sage/homology/hochschild_complex.py index f372a08e0e8..05af2b6cbce 100644 --- a/src/sage/homology/hochschild_complex.py +++ b/src/sage/homology/hochschild_complex.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat (because all doctests use FreeAlgebra, SymmetricGroupAlgebra, etc.) """ Hochschild Complexes """ diff --git a/src/sage/homology/homology_group.py b/src/sage/homology/homology_group.py index 0b27087a362..5948d206371 100644 --- a/src/sage/homology/homology_group.py +++ b/src/sage/homology/homology_group.py @@ -32,13 +32,13 @@ class HomologyGroup_class(AdditiveAbelianGroup_fixed_gens): EXAMPLES:: sage: from sage.homology.homology_group import HomologyGroup - sage: G = AbelianGroup(5, [5,5,7,8,9]); G + sage: G = AbelianGroup(5, [5,5,7,8,9]); G # optional - sage.groups Multiplicative Abelian group isomorphic to C5 x C5 x C7 x C8 x C9 sage: H = HomologyGroup(5, ZZ, [5,5,7,8,9]); H C5 x C5 x C7 x C8 x C9 - sage: G == loads(dumps(G)) + sage: G == loads(dumps(G)) # optional - sage.groups True - sage: AbelianGroup(4) + sage: AbelianGroup(4) # optional - sage.groups Multiplicative Abelian group isomorphic to Z x Z x Z x Z sage: HomologyGroup(4, ZZ) Z x Z x Z x Z @@ -156,11 +156,11 @@ def HomologyGroup(n, base_ring, invfac=None): EXAMPLES:: sage: from sage.homology.homology_group import HomologyGroup - sage: G = AbelianGroup(5, [5,5,7,8,9]); G + sage: G = AbelianGroup(5, [5,5,7,8,9]); G # optional - sage.groups Multiplicative Abelian group isomorphic to C5 x C5 x C7 x C8 x C9 sage: H = HomologyGroup(5, ZZ, [5,5,7,8,9]); H C5 x C5 x C7 x C8 x C9 - sage: AbelianGroup(4) + sage: AbelianGroup(4) # optional - sage.groups Multiplicative Abelian group isomorphic to Z x Z x Z x Z sage: HomologyGroup(4, ZZ) Z x Z x Z x Z diff --git a/src/sage/homology/homology_morphism.py b/src/sage/homology/homology_morphism.py index 7dfd5fc8b08..95dee87a61c 100644 --- a/src/sage/homology/homology_morphism.py +++ b/src/sage/homology/homology_morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.graphs (because all doctests use the catalog simplicial_complexes) r""" Induced morphisms on homology diff --git a/src/sage/homology/homology_vector_space_with_basis.py b/src/sage/homology/homology_vector_space_with_basis.py index 63a80657917..cf877a610ce 100644 --- a/src/sage/homology/homology_vector_space_with_basis.py +++ b/src/sage/homology/homology_vector_space_with_basis.py @@ -1,4 +1,5 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.graphs (because all doctests use the catalogs simplicial_complexes, cubical_complexes) + """ Homology and cohomology with a basis diff --git a/src/sage/interfaces/sympy.py b/src/sage/interfaces/sympy.py index 9ca4203b648..6d186e89e9d 100644 --- a/src/sage/interfaces/sympy.py +++ b/src/sage/interfaces/sympy.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sympy """ SymPy --> Sage conversion diff --git a/src/sage/matrix/action.pyx b/src/sage/matrix/action.pyx index dc057d1dce5..b9ae87fa9d3 100644 --- a/src/sage/matrix/action.pyx +++ b/src/sage/matrix/action.pyx @@ -19,11 +19,15 @@ Actions used by the coercion model for matrix and vector multiplications sage: MSZ = MatrixSpace(ZZ['x'], 2) sage: A = MSQ.get_action(MSZ) sage: A - Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field + on Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring sage: import gc sage: _ = gc.collect() sage: A - Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field + on Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring .. NOTE:: @@ -83,13 +87,17 @@ cdef class MatrixMulAction(Action): sage: MSQ = MatrixSpace(QQ, 2) sage: MSZ = MatrixSpace(ZZ['x'], 2) sage: A = MSQ.get_action(MSZ); A - Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field + on Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring sage: A.actor() Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: A.domain() - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring sage: A.codomain() - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field + Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Rational Field """ def __init__(self, G, S, is_left): if not is_MatrixSpace(G): @@ -130,9 +138,13 @@ cdef class MatrixMatrixAction(MatrixMulAction): sage: MSQ = MatrixSpace(QQ, 3, 2) sage: from sage.matrix.action import MatrixMatrixAction sage: A = MatrixMatrixAction(MSR, MSQ); A - Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring on Full MatrixSpace of 3 by 2 dense matrices over Rational Field + Left action + by Full MatrixSpace of 3 by 3 dense matrices + over Univariate Polynomial Ring in x over Integer Ring + on Full MatrixSpace of 3 by 2 dense matrices over Rational Field sage: A.codomain() - Full MatrixSpace of 3 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field + Full MatrixSpace of 3 by 2 dense matrices + over Univariate Polynomial Ring in x over Rational Field sage: A(matrix(R, 3, 3, x), matrix(QQ, 3, 2, range(6))) [ 0 x] [2*x 3*x] @@ -183,7 +195,8 @@ cdef class MatrixMatrixAction(MatrixMulAction): sage: MSR = MatrixSpace(R, 3, 3) sage: MSQ = MatrixSpace(QQ, 3, 2) sage: A = MatrixMatrixAction(MSR, MSQ); A - Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring on Full MatrixSpace of 3 by 2 dense matrices over Rational Field + Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring + on Full MatrixSpace of 3 by 2 dense matrices over Rational Field sage: A.codomain() Full MatrixSpace of 3 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field @@ -209,23 +222,23 @@ cdef class MatrixMatrixAction(MatrixMulAction): Respects compatible subdivisions:: - sage: M = matrix(5, 5, prime_range(100)) - sage: M.subdivide(2,3); M + sage: M = matrix(5, 5, prime_range(100)) # optional - sage.libs.pari + sage: M.subdivide(2, 3); M # optional - sage.libs.pari [ 2 3 5| 7 11] [13 17 19|23 29] [--------+-----] [31 37 41|43 47] [53 59 61|67 71] [73 79 83|89 97] - sage: N = matrix(5,2,[n^2 for n in range(10)]) - sage: N.subdivide(3,1); N + sage: N = matrix(5, 2, [n^2 for n in range(10)]) + sage: N.subdivide(3, 1); N [ 0| 1] [ 4| 9] [16|25] [--+--] [36|49] [64|81] - sage: M*N + sage: M*N # optional - sage.libs.pari [ 1048| 1388] [ 3056| 4117] [-----+-----] @@ -235,7 +248,7 @@ cdef class MatrixMatrixAction(MatrixMulAction): Note that this is just like block matrix multiplication:: - sage: M.subdivision(0,0) * N.subdivision(0,0) + M.subdivision(0,1) * N.subdivision(1,0) + sage: M.subdivision(0,0) * N.subdivision(0,0) + M.subdivision(0,1) * N.subdivision(1,0) # optional - sage.libs.pari [1048] [3056] @@ -249,7 +262,7 @@ cdef class MatrixMatrixAction(MatrixMulAction): [16|25] [36|49] [64|81] - sage: M*N + sage: M*N # optional - sage.libs.pari [ 1048 1388] [ 3056 4117] [ 5360 7303] @@ -304,7 +317,8 @@ cdef class MatrixVectorAction(MatrixMulAction): sage: M = MatrixSpace(QQ, 5, 3) sage: V = VectorSpace(CDF, 3) # strong reference prevents garbage collection sage: A = MatrixVectorAction(M, V); A - Left action by Full MatrixSpace of 5 by 3 dense matrices over Rational Field on Vector space of dimension 3 over Complex Double Field + Left action by Full MatrixSpace of 5 by 3 dense matrices over Rational Field + on Vector space of dimension 3 over Complex Double Field sage: A.codomain() Vector space of dimension 5 over Complex Double Field """ @@ -355,7 +369,8 @@ cdef class VectorMatrixAction(MatrixMulAction): sage: V = VectorSpace(CDF, 3) sage: A = VectorMatrixAction(M, V) sage: A - Right action by Full MatrixSpace of 3 by 5 dense matrices over Rational Field on Vector space of dimension 3 over Complex Double Field + Right action by Full MatrixSpace of 3 by 5 dense matrices over Rational Field + on Vector space of dimension 3 over Complex Double Field sage: A.codomain() Vector space of dimension 5 over Complex Double Field """ diff --git a/src/sage/matrix/args.pyx b/src/sage/matrix/args.pyx index 9e738312c27..ec4ce79d322 100644 --- a/src/sage/matrix/args.pyx +++ b/src/sage/matrix/args.pyx @@ -82,7 +82,7 @@ cdef class SparseEntry: sage: from sage.matrix.args import SparseEntry sage: SparseEntry(123, 456, "abc") SparseEntry(123, 456, 'abc') - sage: SparseEntry(1/3, 2/3, x) + sage: SparseEntry(1/3, 2/3, x) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert rational 1/3 to an integer @@ -155,94 +155,133 @@ cdef class MatrixArgs: sage: ma = MatrixArgs(2, 2, (x for x in range(4))); ma > sage: ma.finalized() - + Many types of input are possible:: - sage: ma = MatrixArgs(2, 2, entries=None); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(2, 2, entries=None); ma.finalized() + + sage: ma.matrix() [0 0] [0 0] - sage: ma = MatrixArgs(2, 2, entries={}); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(2, 2, entries={}); ma.finalized() + + sage: ma.matrix() [0 0] [0 0] - sage: ma = MatrixArgs(2, 2, entries=[1,2,3,4]); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(2, 2, entries=[1,2,3,4]); ma.finalized() + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(2, 2, entries=math.pi); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(2, 2, entries=math.pi); ma.finalized() + + sage: ma.matrix() [3.141592653589793 0.0] [ 0.0 3.141592653589793] - sage: ma = MatrixArgs(2, 2, entries=pi); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(2, 2, entries=pi); ma.finalized() # optional - sage.symbolic + + sage: ma.matrix() [pi 0] [ 0 pi] - sage: ma = MatrixArgs(ZZ, 2, 2, entries={(0,0):7}); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(ZZ, 2, 2, entries={(0,0): 7}); ma.finalized() + + sage: ma.matrix() [7 0] [0 0] - sage: ma = MatrixArgs(ZZ, 2, 2, entries=((1,2),(3,4))); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(ZZ, 2, 2, entries=((1,2), (3,4))); ma.finalized() + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(ZZ, 2, 2, entries=(1,2,3,4)); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(ZZ, 2, 2, entries=(1,2,3,4)); ma.finalized() + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(QQ, entries=pari("[1,2;3,4]")); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(QQ, entries=pari("[1,2;3,4]")); ma.finalized() # optional - sage.libs.pari + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("[1,2,3,4]")); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("[1,2,3,4]")); ma.finalized() # optional - sage.libs.pari + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("3/5")); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("3/5")); ma.finalized() # optional - sage.libs.pari + + sage: ma.matrix() [3/5 0] [ 0 3/5] - sage: ma = MatrixArgs(entries=matrix(2,2)); ma.finalized(); ma.matrix() - + sage: ma.matrix() [0 0] [0 0] - sage: ma = MatrixArgs(2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized() + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(ZZ, 2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized(); ma.matrix() - > + sage: ma = MatrixArgs(ZZ, 2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized() + > + sage: ma.matrix() [1 2] [3 4] - sage: from numpy import array - sage: ma = MatrixArgs(array([[1,2],[3,4]])); ma.finalized(); ma.matrix() - + sage: from numpy import array # optional - numpy + sage: ma = MatrixArgs(array([[1,2],[3,4]])); ma.finalized() # optional - numpy + + sage: ma.matrix() [1 2] [3 4] - sage: ma = MatrixArgs(array([[1.,2.],[3.,4.]])); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(array([[1.,2.],[3.,4.]])); ma.finalized() # optional - numpy + + sage: ma.matrix() [1.0 2.0] [3.0 4.0] - sage: ma = MatrixArgs(RealField(20), array([[1.,2.],[3.,4.]])); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(RealField(20), array([[1.,2.],[3.,4.]])); ma.finalized() # optional - numpy + + sage: ma.matrix() [1.0000 2.0000] [3.0000 4.0000] - sage: ma = MatrixArgs(graphs.CycleGraph(3)); ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs(graphs.CycleGraph(3)); ma.finalized() # optional - sage.graphs + + sage: ma.matrix() [0 1 1] [1 0 1] [1 1 0] - sage: ma = MatrixArgs([vector([0,1], sparse=True), vector([0,0], sparse=True)], sparse=True) - sage: ma.finalized(); ma.matrix() - + sage: ma = MatrixArgs([vector([0,1], sparse=True), + ....: vector([0,0], sparse=True)], sparse=True) + sage: ma.finalized() + + sage: ma.matrix() [0 1] [0 0] @@ -457,8 +496,8 @@ cdef class MatrixArgs: Sparse examples:: - sage: ma = MatrixArgs(3, 3, pi) - sage: list(ma.iter(sparse=True)) + sage: ma = MatrixArgs(3, 3, pi) # optional - sage.symbolic + sage: list(ma.iter(sparse=True)) # optional - sage.symbolic [SparseEntry(0, 0, pi), SparseEntry(1, 1, pi), SparseEntry(2, 2, pi)] sage: ma = MatrixArgs(2, 3) sage: list(ma.iter(sparse=True)) @@ -610,7 +649,8 @@ cdef class MatrixArgs: :: sage: ma = MatrixArgs(M); ma.finalized() - sage: ma.matrix() [0 1 2] @@ -619,8 +659,9 @@ cdef class MatrixArgs: :: sage: ma = MatrixArgs(M, sparse=False); ma.finalized() - + sage: ma.matrix() [0 1 2] [3 4 5] @@ -628,8 +669,9 @@ cdef class MatrixArgs: :: sage: ma = MatrixArgs(RDF, M); ma.finalized() - + sage: ma.matrix(convert=False) [0 1 2] [3 4 5] @@ -757,10 +799,10 @@ cdef class MatrixArgs: :: - sage: ma = MatrixArgs(GF(2), 2, 3, L) - sage: ma.dict(convert=False) + sage: ma = MatrixArgs(GF(2), 2, 3, L) # optional - sage.rings.finite_rings + sage: ma.dict(convert=False) # optional - sage.rings.finite_rings {(0, 1): 1, (0, 2): 2, (1, 0): 3, (1, 1): 4, (1, 2): 5} - sage: ma.dict() + sage: ma.dict() # optional - sage.rings.finite_rings {(0, 1): 1, (1, 0): 1, (1, 2): 1} """ self.finalize() @@ -789,7 +831,8 @@ cdef class MatrixArgs: sage: S = MatrixSpace(QQ, 3, 2, sparse=True) sage: _ = ma.set_space(S) sage: ma.finalized() - + sage: M = ma.matrix(); M [0 0] [0 0] @@ -818,16 +861,17 @@ cdef class MatrixArgs: EXAMPLES:: sage: from sage.matrix.args import MatrixArgs - sage: MatrixArgs(pi).finalized() + sage: MatrixArgs(pi).finalized() # optional - sage.symbolic Traceback (most recent call last): ... TypeError: the dimensions of the matrix must be specified - sage: MatrixArgs(RR, pi).finalized() + sage: MatrixArgs(RR, pi).finalized() # optional - sage.symbolic Traceback (most recent call last): ... TypeError: the dimensions of the matrix must be specified sage: MatrixArgs(2, 3, 0.0).finalized() - + sage: MatrixArgs(RR, 2, 3, 1.0).finalized() Traceback (most recent call last): ... @@ -973,19 +1017,21 @@ cdef class MatrixArgs: EXAMPLES:: sage: from sage.matrix.args import MatrixArgs - sage: ma = MatrixArgs({(2,5):1/2, (4,-3):1/3}) - sage: ma = MatrixArgs(2, 2, {(-1,0):2, (0,-1):1}, sparse=True) + sage: ma = MatrixArgs({(2,5): 1/2, (4,-3): 1/3}) + sage: ma = MatrixArgs(2, 2, {(-1,0): 2, (0,-1): 1}, sparse=True) sage: ma.finalized() - - sage: ma = MatrixArgs(2, 2, {(-1,0):2, (0,-1):1}, sparse=False) + + sage: ma = MatrixArgs(2, 2, {(-1,0): 2, (0,-1): 1}, sparse=False) sage: ma.finalized() - - sage: ma = MatrixArgs(2, 1, {(1,0):88, (0,1):89}) + + sage: ma = MatrixArgs(2, 1, {(1,0): 88, (0,1): 89}) sage: ma.finalized() Traceback (most recent call last): ... IndexError: invalid column index 1 - sage: ma = MatrixArgs(1, 2, {(1,0):88, (0,1):89}) + sage: ma = MatrixArgs(1, 2, {(1,0): 88, (0,1): 89}) sage: ma.finalized() Traceback (most recent call last): ... @@ -1196,21 +1242,21 @@ cdef class MatrixArgs: Check that :trac:`26655` is fixed:: - sage: F. = GF(9) - sage: M = MatrixSpace(F, 2, 2) - sage: A = M([[1, a], [0, 1]]) - sage: M(pari(A)) + sage: F. = GF(9) # optional - sage.rings.finite_rings + sage: M = MatrixSpace(F, 2, 2) # optional - sage.rings.finite_rings + sage: A = M([[1, a], [0, 1]]) # optional - sage.rings.finite_rings + sage: M(pari(A)) # optional - sage.rings.finite_rings [1 a] [0 1] Constructing a matrix from a PARI ``t_VEC`` or ``t_COL`` with ``t_VEC`` or ``t_COL`` elements is currently not supported:: - sage: M(pari([1, a, 0, 1])) + sage: M(pari([1, a, 0, 1])) # optional - sage.libs.pari Traceback (most recent call last): ... NameError: name 'a' is not defined - sage: M(pari([[1, a], [0, 1]])) + sage: M(pari([[1, a], [0, 1]])) # optional - sage.libs.pari Traceback (most recent call last): ... NameError: name 'a' is not defined @@ -1322,12 +1368,12 @@ cpdef MatrixArgs MatrixArgs_init(space, entries): EXAMPLES:: sage: from sage.matrix.args import MatrixArgs_init - sage: S = MatrixSpace(GF(2), 2, 4) - sage: ma = MatrixArgs_init(S, {(1,3):7}) - sage: M = ma.matrix(); M + sage: S = MatrixSpace(GF(2), 2, 4) # optional - sage.rings.finite_rings + sage: ma = MatrixArgs_init(S, {(1, 3): 7}) # optional - sage.rings.finite_rings + sage: M = ma.matrix(); M # optional - sage.rings.finite_rings [0 0 0 0] [0 0 0 1] - sage: parent(M) is S + sage: parent(M) is S # optional - sage.rings.finite_rings True """ cdef MatrixArgs ret diff --git a/src/sage/matrix/berlekamp_massey.py b/src/sage/matrix/berlekamp_massey.py index 716ed428745..9ea72f510cd 100644 --- a/src/sage/matrix/berlekamp_massey.py +++ b/src/sage/matrix/berlekamp_massey.py @@ -55,11 +55,11 @@ def berlekamp_massey(a): sage: from sage.matrix.berlekamp_massey import berlekamp_massey sage: berlekamp_massey([1,2,1,2,1,2]) x^2 - 1 - sage: berlekamp_massey([GF(7)(1),19,1,19]) + sage: berlekamp_massey([GF(7)(1), 19, 1, 19]) # optional - sage.rings.finite_rings x^2 + 6 sage: berlekamp_massey([2,2,1,2,1,191,393,132]) x^4 - 36727/11711*x^3 + 34213/5019*x^2 + 7024942/35133*x - 335813/1673 - sage: berlekamp_massey(prime_range(2,38)) + sage: berlekamp_massey(prime_range(2, 38)) # optional - sage.libs.pari x^6 - 14/9*x^5 - 7/9*x^4 + 157/54*x^3 - 25/27*x^2 - 73/18*x + 37/9 TESTS:: diff --git a/src/sage/matrix/compute_J_ideal.py b/src/sage/matrix/compute_J_ideal.py index 55dcb5e7072..53960564b6e 100644 --- a/src/sage/matrix/compute_J_ideal.py +++ b/src/sage/matrix/compute_J_ideal.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari (for charpoly, minimal_polynomial in __init__) r""" `J`-ideals of matrices @@ -540,8 +541,8 @@ def mccoy_column(self, p, t, nu): sage: x = polygen(ZZ, 'x') sage: nu_4 = x^2 + 3*x + 2 sage: g = C.mccoy_column(2, 2, nu_4) - sage: b = matrix(9, 1, (x-B).adjugate().list()) - sage: M = matrix.block([[b , -B.charpoly(x)*matrix.identity(9)]]) + sage: b = matrix(9, 1, (x - B).adjugate().list()) + sage: M = matrix.block([[b, -B.charpoly(x)*matrix.identity(9)]]) sage: (M*g % 4).is_zero() True diff --git a/src/sage/matrix/constructor.pyx b/src/sage/matrix/constructor.pyx index ae4652c45f8..0ad16955c87 100644 --- a/src/sage/matrix/constructor.pyx +++ b/src/sage/matrix/constructor.pyx @@ -98,32 +98,32 @@ def matrix(*args, **kwds): :: - sage: m = matrix(2,3); m; m.parent() + sage: m = matrix(2, 3); m; m.parent() [0 0 0] [0 0 0] Full MatrixSpace of 2 by 3 dense matrices over Integer Ring :: - sage: m = matrix(QQ,[[1,2,3],[4,5,6]]); m; m.parent() + sage: m = matrix(QQ, [[1,2,3], [4,5,6]]); m; m.parent() [1 2 3] [4 5 6] Full MatrixSpace of 2 by 3 dense matrices over Rational Field :: - sage: m = matrix(QQ, 3, 3, lambda i, j: i+j); m + sage: m = matrix(QQ, 3, 3, lambda i, j: i + j); m [0 1 2] [1 2 3] [2 3 4] - sage: m = matrix(3, lambda i,j: i-j); m + sage: m = matrix(3, lambda i, j: i - j); m [ 0 -1 -2] [ 1 0 -1] [ 2 1 0] :: - sage: matrix(QQ, 2, 3, lambda x, y: x+y) + sage: matrix(QQ, 2, 3, lambda x, y: x + y) [0 1 2] [1 2 3] sage: matrix(QQ, 5, 5, lambda x, y: (x+1) / (y+1)) @@ -172,9 +172,9 @@ def matrix(*args, **kwds): :: - sage: import numpy - sage: n = numpy.array([[1,2],[3,4]],float) - sage: m = matrix(n); m; m.parent() + sage: import numpy # optional - numpy + sage: n = numpy.array([[1,2], [3,4]], float) # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1.0 2.0] [3.0 4.0] Full MatrixSpace of 2 by 2 dense matrices over Real Double Field @@ -185,10 +185,10 @@ def matrix(*args, **kwds): sage: m = matrix(v); m; m.parent() [ 1 10 100] Full MatrixSpace of 1 by 3 dense matrices over Integer Ring - sage: m = matrix(GF(7), v); m; m.parent() + sage: m = matrix(GF(7), v); m; m.parent() # optional - sage.rings.finite_rings [1 3 2] Full MatrixSpace of 1 by 3 dense matrices over Finite Field of size 7 - sage: m = matrix(GF(7), 3, 1, v); m; m.parent() + sage: m = matrix(GF(7), 3, 1, v); m; m.parent() # optional - sage.rings.finite_rings [1] [3] [2] @@ -196,15 +196,15 @@ def matrix(*args, **kwds): :: - sage: matrix(pari.mathilbert(3)) + sage: matrix(pari.mathilbert(3)) # optional - sage.libs.pari [ 1 1/2 1/3] [1/2 1/3 1/4] [1/3 1/4 1/5] :: - sage: g = graphs.PetersenGraph() - sage: m = matrix(g); m; m.parent() + sage: g = graphs.PetersenGraph() # optional - sage.graphs + sage: m = matrix(g); m; m.parent() # optional - sage.graphs [0 1 0 0 1 1 0 0 0 0] [1 0 1 0 0 0 1 0 0 0] [0 1 0 1 0 0 0 1 0 0] @@ -278,11 +278,11 @@ def matrix(*args, **kwds): [0 0] [0 0] Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: m = matrix(QQ,2); m; m.parent() + sage: m = matrix(QQ, 2); m; m.parent() [0 0] [0 0] Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: m = matrix(QQ,2,3); m; m.parent() + sage: m = matrix(QQ, 2, 3); m; m.parent() [0 0 0] [0 0 0] Full MatrixSpace of 2 by 3 dense matrices over Rational Field @@ -323,19 +323,19 @@ def matrix(*args, **kwds): [1 2 3] [4 5 6] Full MatrixSpace of 2 by 3 dense matrices over Integer Ring - sage: m = matrix(QQ,2,[[1,2,3],[4,5,6]]); m; m.parent() + sage: m = matrix(QQ, 2, [[1,2,3],[4,5,6]]); m; m.parent() [1 2 3] [4 5 6] Full MatrixSpace of 2 by 3 dense matrices over Rational Field - sage: m = matrix(QQ,3,[[1,2,3],[4,5,6]]); m; m.parent() + sage: m = matrix(QQ, 3, [[1,2,3],[4,5,6]]); m; m.parent() Traceback (most recent call last): ... ValueError: inconsistent number of rows: should be 3 but got 2 - sage: m = matrix(QQ,2,3,[[1,2,3],[4,5,6]]); m; m.parent() + sage: m = matrix(QQ, 2, 3, [[1,2,3],[4,5,6]]); m; m.parent() [1 2 3] [4 5 6] Full MatrixSpace of 2 by 3 dense matrices over Rational Field - sage: m = matrix(QQ,2,4,[[1,2,3],[4,5,6]]); m; m.parent() + sage: m = matrix(QQ, 2, 4, [[1,2,3],[4,5,6]]); m; m.parent() Traceback (most recent call last): ... ValueError: sequence too short (expected length 4, got 3) @@ -349,19 +349,19 @@ def matrix(*args, **kwds): sage: m = matrix((1,2,3,4,5,6)); m; m.parent() [1 2 3 4 5 6] Full MatrixSpace of 1 by 6 dense matrices over Integer Ring - sage: m = matrix(QQ,[1,2,3,4,5,6]); m; m.parent() + sage: m = matrix(QQ, [1,2,3,4,5,6]); m; m.parent() [1 2 3 4 5 6] Full MatrixSpace of 1 by 6 dense matrices over Rational Field - sage: m = matrix(QQ,3,2,[1,2,3,4,5,6]); m; m.parent() + sage: m = matrix(QQ, 3, 2, [1,2,3,4,5,6]); m; m.parent() [1 2] [3 4] [5 6] Full MatrixSpace of 3 by 2 dense matrices over Rational Field - sage: m = matrix(QQ,2,4,[1,2,3,4,5,6]); m; m.parent() + sage: m = matrix(QQ, 2, 4, [1,2,3,4,5,6]); m; m.parent() Traceback (most recent call last): ... ValueError: sequence too short (expected length 8, got 6) - sage: m = matrix(QQ,5,[1,2,3,4,5,6]); m; m.parent() + sage: m = matrix(QQ, 5, [1,2,3,4,5,6]); m; m.parent() Traceback (most recent call last): ... ValueError: sequence too long (expected length 5, got more) @@ -376,47 +376,47 @@ def matrix(*args, **kwds): [0 0] [0 2] Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: m = matrix(QQ,{(1,1): 2}); m; m.parent() + sage: m = matrix(QQ, {(1,1): 2}); m; m.parent() [0 0] [0 2] Full MatrixSpace of 2 by 2 sparse matrices over Rational Field - sage: m = matrix(QQ,3,{(1,1): 2}); m; m.parent() + sage: m = matrix(QQ, 3, {(1,1): 2}); m; m.parent() [0 0 0] [0 2 0] [0 0 0] Full MatrixSpace of 3 by 3 sparse matrices over Rational Field - sage: m = matrix(QQ,3,4,{(1,1): 2}); m; m.parent() + sage: m = matrix(QQ, 3, 4, {(1,1): 2}); m; m.parent() [0 0 0 0] [0 2 0 0] [0 0 0 0] Full MatrixSpace of 3 by 4 sparse matrices over Rational Field - sage: m = matrix(QQ,2,{(1,1): 2}); m; m.parent() + sage: m = matrix(QQ, 2, {(1,1): 2}); m; m.parent() [0 0] [0 2] Full MatrixSpace of 2 by 2 sparse matrices over Rational Field - sage: m = matrix(QQ,1,{(1,1): 2}); m; m.parent() + sage: m = matrix(QQ, 1, {(1,1): 2}); m; m.parent() Traceback (most recent call last): ... IndexError: invalid row index 1 sage: m = matrix({}); m; m.parent() [] Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring - sage: m = matrix(QQ,{}); m; m.parent() + sage: m = matrix(QQ, {}); m; m.parent() [] Full MatrixSpace of 0 by 0 sparse matrices over Rational Field - sage: m = matrix(QQ,2,{}); m; m.parent() + sage: m = matrix(QQ, 2, {}); m; m.parent() [0 0] [0 0] Full MatrixSpace of 2 by 2 sparse matrices over Rational Field - sage: m = matrix(QQ,2,3,{}); m; m.parent() + sage: m = matrix(QQ, 2, 3, {}); m; m.parent() [0 0 0] [0 0 0] Full MatrixSpace of 2 by 3 sparse matrices over Rational Field - sage: m = matrix(2,{}); m; m.parent() + sage: m = matrix(2, {}); m; m.parent() [0 0] [0 0] Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring - sage: m = matrix(2,3,{}); m; m.parent() + sage: m = matrix(2, 3, {}); m; m.parent() [0 0 0] [0 0 0] Full MatrixSpace of 2 by 3 sparse matrices over Integer Ring @@ -429,104 +429,104 @@ def matrix(*args, **kwds): sage: m = matrix(2,0); m; m.parent() [] Full MatrixSpace of 2 by 0 dense matrices over Integer Ring - sage: m = matrix(0,[1]); m; m.parent() + sage: m = matrix(0, [1]); m; m.parent() Traceback (most recent call last): ... ValueError: sequence too long (expected length 0, got more) - sage: m = matrix(1,0,[]); m; m.parent() + sage: m = matrix(1, 0, []); m; m.parent() [] Full MatrixSpace of 1 by 0 dense matrices over Integer Ring - sage: m = matrix(0,1,[]); m; m.parent() + sage: m = matrix(0, 1, []); m; m.parent() [] Full MatrixSpace of 0 by 1 dense matrices over Integer Ring - sage: m = matrix(0,[]); m; m.parent() + sage: m = matrix(0, []); m; m.parent() [] Full MatrixSpace of 0 by 0 dense matrices over Integer Ring - sage: m = matrix(0,{}); m; m.parent() + sage: m = matrix(0, {}); m; m.parent() [] Full MatrixSpace of 0 by 0 sparse matrices over Integer Ring - sage: m = matrix(0,{(1,1):2}); m; m.parent() + sage: m = matrix(0, {(1,1): 2}); m; m.parent() Traceback (most recent call last): ... IndexError: invalid row index 1 - sage: m = matrix(2,0,{(1,1):2}); m; m.parent() + sage: m = matrix(2, 0, {(1,1): 2}); m; m.parent() Traceback (most recent call last): ... IndexError: invalid column index 1 Check conversion from numpy:: - sage: import numpy - sage: n = numpy.array([[complex(0,1),complex(0,2)],[3,4]],complex) - sage: m = matrix(n); m; m.parent() + sage: import numpy # optional - numpy + sage: n = numpy.array([[complex(0,1),complex(0,2)], [3,4]], complex) # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1.0*I 2.0*I] [ 3.0 4.0] Full MatrixSpace of 2 by 2 dense matrices over Complex Double Field - sage: n = numpy.array([[1,2],[3,4]],'int32') - sage: m = matrix(n); m; m.parent() + sage: n = numpy.array([[1,2], [3,4]], 'int32') # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1 2] [3 4] Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: n = numpy.array([[1,2,3],[4,5,6],[7,8,9]],'float32') - sage: m = matrix(n); m; m.parent() + sage: n = numpy.array([[1,2,3], [4,5,6], [7,8,9]], 'float32') # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1.0 2.0 3.0] [4.0 5.0 6.0] [7.0 8.0 9.0] Full MatrixSpace of 3 by 3 dense matrices over Real Double Field - sage: n = numpy.matrix([[1,2,3],[4,5,6],[7,8,9]],'float64') - sage: m = matrix(n); m; m.parent() + sage: n = numpy.matrix([[1,2,3], [4,5,6], [7,8,9]], 'float64') # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1.0 2.0 3.0] [4.0 5.0 6.0] [7.0 8.0 9.0] Full MatrixSpace of 3 by 3 dense matrices over Real Double Field - sage: n = numpy.array([[1,2,3],[4,5,6],[7,8,9]],'complex64') - sage: m = matrix(n); m; m.parent() + sage: n = numpy.array([[1,2,3], [4,5,6], [7,8,9]], 'complex64') # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1.0 2.0 3.0] [4.0 5.0 6.0] [7.0 8.0 9.0] Full MatrixSpace of 3 by 3 dense matrices over Complex Double Field - sage: n = numpy.matrix([[1,2,3],[4,5,6],[7,8,9]],'complex128') - sage: m = matrix(n); m; m.parent() + sage: n = numpy.matrix([[1,2,3], [4,5,6], [7,8,9]], 'complex128') # optional - numpy + sage: m = matrix(n); m; m.parent() # optional - numpy [1.0 2.0 3.0] [4.0 5.0 6.0] [7.0 8.0 9.0] Full MatrixSpace of 3 by 3 dense matrices over Complex Double Field - sage: a = matrix([[1,2],[3,4]]) - sage: b = matrix(a.numpy()); b + sage: a = matrix([[1,2], [3,4]]) + sage: b = matrix(a.numpy()); b # optional - numpy [1 2] [3 4] - sage: a == b + sage: a == b # optional - numpy True - sage: c = matrix(a.numpy('float32')); c + sage: c = matrix(a.numpy('float32')); c # optional - numpy [1.0 2.0] [3.0 4.0] - sage: matrix(numpy.array([[5]])) + sage: matrix(numpy.array([[5]])) # optional - numpy [5] - sage: matrix(numpy.matrix([[5]])) + sage: matrix(numpy.matrix([[5]])) # optional - numpy [5] A ring and a numpy array:: - sage: n = numpy.array([[1,2,3],[4,5,6],[7,8,9]],'float32') - sage: m = matrix(ZZ, n); m; m.parent() + sage: n = numpy.array([[1,2,3], [4,5,6], [7,8,9]],'float32') # optional - numpy + sage: m = matrix(ZZ, n); m; m.parent() # optional - numpy [1 2 3] [4 5 6] [7 8 9] Full MatrixSpace of 3 by 3 dense matrices over Integer Ring - sage: n = matrix(QQ, 2, 2, [1, 1/2, 1/3, 1/4]).numpy(); n + sage: n = matrix(QQ, 2, 2, [1, 1/2, 1/3, 1/4]).numpy(); n # optional - numpy array([[1. , 0.5 ], [0.33333333, 0.25 ]]) - sage: matrix(QQ, n) + sage: matrix(QQ, n) # optional - numpy [ 1 1/2] [1/3 1/4] The dimensions of a matrix may be given as numpy types:: - sage: matrix(numpy.int32(2), numpy.int32(3)) + sage: matrix(numpy.int32(2), numpy.int32(3)) # optional - numpy [0 0 0] [0 0 0] - sage: matrix(nrows=numpy.int32(2), ncols=numpy.int32(3)) + sage: matrix(nrows=numpy.int32(2), ncols=numpy.int32(3)) # optional - numpy [0 0 0] [0 0 0] @@ -542,10 +542,11 @@ def matrix(*args, **kwds): sage: v = vector(ZZ, [1, 10, 100]) sage: m = matrix(ZZ['x'], v); m; m.parent() [ 1 10 100] - Full MatrixSpace of 1 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring + Full MatrixSpace of 1 by 3 dense matrices + over Univariate Polynomial Ring in x over Integer Ring sage: matrix(ZZ, 10, 10, range(100)).parent() Full MatrixSpace of 10 by 10 dense matrices over Integer Ring - sage: m = matrix(GF(7), [[1/3,2/3,1/2], [3/4,4/5,7]]); m; m.parent() + sage: m = matrix(GF(7), [[1/3,2/3,1/2], [3/4,4/5,7]]); m; m.parent() # optional - sage.rings.finite_rings [5 3 4] [6 5 0] Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 7 @@ -553,7 +554,7 @@ def matrix(*args, **kwds): [ 1.0 2.0 3.0] [ 2.0 1.0 + 2.0*I 3.0] Full MatrixSpace of 2 by 3 dense matrices over Complex Double Field - sage: m = matrix(3,3,1/2); m; m.parent() + sage: m = matrix(3, 3, 1/2); m; m.parent() [1/2 0 0] [ 0 1/2 0] [ 0 0 1/2] @@ -566,7 +567,7 @@ def matrix(*args, **kwds): Traceback (most recent call last): ... TypeError: 'sage.rings.integer.Integer' object is not iterable - sage: matrix(vector(RR,[1,2,3])).parent() + sage: matrix(vector(RR, [1,2,3])).parent() Full MatrixSpace of 1 by 3 dense matrices over Real Field with 53 bits of precision Check :trac:`10158`:: diff --git a/src/sage/matrix/echelon_matrix.pyx b/src/sage/matrix/echelon_matrix.pyx index 3fc43b485ca..6a962fd2f82 100644 --- a/src/sage/matrix/echelon_matrix.pyx +++ b/src/sage/matrix/echelon_matrix.pyx @@ -48,8 +48,8 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True, EXAMPLES:: sage: from sage.matrix.echelon_matrix import reduced_echelon_matrix_iterator - sage: it = reduced_echelon_matrix_iterator(GF(2),2,3) - sage: for m in it: + sage: it = reduced_echelon_matrix_iterator(GF(2), 2, 3) # optional - sage.rings.finite_rings + sage: for m in it: # optional - sage.rings.finite_rings ....: print(m) ....: print(m.pivots()) ....: print("*******") @@ -87,21 +87,21 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True, Testing cardinalities:: sage: q = 71 - sage: F = GF(q) - sage: len(list(reduced_echelon_matrix_iterator(F, 1, 3, copy=False))) == q**2+q+1 + sage: F = GF(q) # optional - sage.rings.finite_rings + sage: len(list(reduced_echelon_matrix_iterator(F, 1, 3, copy=False))) == q**2+q+1 # optional - sage.rings.finite_rings True - sage: len(list(reduced_echelon_matrix_iterator(F, 2, 3, copy=False))) == q**2+q+1 + sage: len(list(reduced_echelon_matrix_iterator(F, 2, 3, copy=False))) == q**2+q+1 # optional - sage.rings.finite_rings True Testing options:: - sage: it = reduced_echelon_matrix_iterator(GF(4,'z'), 2, 4, copy=False) - sage: next(it) is next(it) + sage: it = reduced_echelon_matrix_iterator(GF(4, 'z'), 2, 4, copy=False) # optional - sage.rings.finite_rings + sage: next(it) is next(it) # optional - sage.rings.finite_rings True - sage: for a in it: pass + sage: for a in it: pass # optional - sage.rings.finite_rings - sage: it = reduced_echelon_matrix_iterator(GF(4,'z'), 2, 4, set_immutable=True) - sage: all(a.is_immutable() and a.echelon_form() == a for a in it) + sage: it = reduced_echelon_matrix_iterator(GF(4, 'z'), 2, 4, set_immutable=True) # optional - sage.rings.finite_rings + sage: all(a.is_immutable() and a.echelon_form() == a for a in it) # optional - sage.rings.finite_rings True """ cdef Matrix m0,m,mm diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index d3a5fee358e..bfacad13d55 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -8,7 +8,7 @@ Base class for matrices, part 0 EXAMPLES:: - sage: matrix(2,[1,2,3,4]) + sage: matrix(2, [1,2,3,4]) [1 2] [3 4] """ @@ -469,7 +469,8 @@ cdef class Matrix(sage.structure.element.Matrix): sage: A[0,0] = 10 Traceback (most recent call last): ... - ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M). + ValueError: matrix is immutable; please change a copy instead + (i.e., use copy(M) to change a copy of M). sage: hash(A) #random 12 sage: v = {A:1}; v @@ -545,11 +546,11 @@ cdef class Matrix(sage.structure.element.Matrix): TESTS:: - sage: class MyAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): + sage: class MyAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): # optional - sage.rings.number_fields ....: def __bool__(self): ....: raise ValueError - sage: mat = matrix(1,1,MyAlgebraicNumber(1)) - sage: bool(mat) + sage: mat = matrix(1, 1, MyAlgebraicNumber(1)) # optional - sage.rings.number_fields + sage: bool(mat) # optional - sage.rings.number_fields Traceback (most recent call last): ... ValueError @@ -677,7 +678,7 @@ cdef class Matrix(sage.structure.element.Matrix): ... TypeError: index must be an integer - sage: m=[(1, -2, -1, -1,9), (1, 8, 6, 2,2), (1, 1, -1, 1,4), (-1, 2, -2, -1,4)];M= matrix(m) + sage: m = [(1, -2, -1, -1,9), (1, 8, 6, 2,2), (1, 1, -1, 1,4), (-1, 2, -2, -1,4)]; M = matrix(m) sage: M [ 1 -2 -1 -1 9] [ 1 8 6 2 2] @@ -909,16 +910,18 @@ cdef class Matrix(sage.structure.element.Matrix): Check that submatrices with a specified implementation have the same implementation:: - sage: M = MatrixSpace(GF(2), 3, 3, implementation='generic') - sage: m = M(range(9)) - sage: type(m) + sage: M = MatrixSpace(GF(2), 3, 3, implementation='generic') # optional - sage.libs.pari + sage: m = M(range(9)) # optional - sage.libs.pari + sage: type(m) # optional - sage.libs.pari - sage: parent(m) - Full MatrixSpace of 3 by 3 dense matrices over Finite Field of size 2 (using Matrix_generic_dense) - sage: type(m[:2,:2]) + sage: parent(m) # optional - sage.libs.pari + Full MatrixSpace of 3 by 3 dense matrices + over Finite Field of size 2 (using Matrix_generic_dense) + sage: type(m[:2,:2]) # optional - sage.libs.pari - sage: parent(m[:2,:2]) - Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 2 (using Matrix_generic_dense) + sage: parent(m[:2,:2]) # optional - sage.libs.pari + Full MatrixSpace of 2 by 2 dense matrices + over Finite Field of size 2 (using Matrix_generic_dense) """ cdef list row_list cdef list col_list @@ -1620,7 +1623,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: m=matrix(QQ,2,[1,2,3,4]) + sage: m = matrix(QQ, 2, [1,2,3,4]) sage: m.base_ring() Rational Field """ @@ -1638,13 +1641,14 @@ cdef class Matrix(sage.structure.element.Matrix): sage: A = Matrix(QQ, 2, 2, [1/2, 1/3, 1/3, 1/4]) sage: A.parent() - Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: A.change_ring(GF(25,'a')) + Full MatrixSpace of 2 by 2 dense matrices over Rational Field + sage: A.change_ring(GF(25,'a')) # optional - sage.rings.finite_rings [3 2] [2 4] - sage: A.change_ring(GF(25,'a')).parent() - Full MatrixSpace of 2 by 2 dense matrices over Finite Field in a of size 5^2 - sage: A.change_ring(ZZ) + sage: A.change_ring(GF(25,'a')).parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 2 by 2 dense matrices + over Finite Field in a of size 5^2 + sage: A.change_ring(ZZ) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: matrix has denominators so can...t change to ZZ @@ -1655,7 +1659,7 @@ cdef class Matrix(sage.structure.element.Matrix): [1/2 1/3] [-------] [1/3 1/4] - sage: A.change_ring(GF(25,'a')) + sage: A.change_ring(GF(25,'a')) # optional - sage.rings.finite_rings [3 2] [---] [2 4] @@ -2363,17 +2367,17 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: f(x,y) = x^2+y - sage: m = matrix([[f,f*f],[f^3,f^4]]); m + sage: f(x,y) = x^2 + y # optional - sage.symbolic + sage: m = matrix([[f, f*f], [f^3, f^4]]); m # optional - sage.symbolic [ (x, y) |--> x^2 + y (x, y) |--> (x^2 + y)^2] [(x, y) |--> (x^2 + y)^3 (x, y) |--> (x^2 + y)^4] - sage: m(1,2) + sage: m(1, 2) # optional - sage.symbolic [ 3 9] [27 81] - sage: m(y=2,x=1) + sage: m(y=2, x=1) # optional - sage.symbolic [ 3 9] [27 81] - sage: m(2,1) + sage: m(2, 1) # optional - sage.symbolic [ 5 25] [125 625] """ @@ -2550,7 +2554,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create a matrix:: - sage: M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) + sage: M = matrix(ZZ, [[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) sage: M [1 0 0 0 0] [0 2 0 0 0] @@ -2561,12 +2565,12 @@ cdef class Matrix(sage.structure.element.Matrix): Next of all, create a permutation group element and act on ``M`` with it:: - sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) - sage: sigma, tau = G.gens() - sage: sigma + sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) # optional - sage.groups + sage: sigma, tau = G.gens() # optional - sage.groups + sage: sigma # optional - sage.groups (1,2,3)(4,5) - sage: M.permute_columns(sigma) - sage: M + sage: M.permute_columns(sigma) # optional - sage.groups + sage: M # optional - sage.groups [0 0 1 0 0] [2 0 0 0 0] [0 3 0 0 0] @@ -2601,7 +2605,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create some matrix:: - sage: M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) + sage: M = matrix(ZZ, [[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) sage: M [1 0 0 0 0] [0 2 0 0 0] @@ -2612,11 +2616,11 @@ cdef class Matrix(sage.structure.element.Matrix): Next of all, create a permutation group element and act on ``M``:: - sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) - sage: sigma, tau = G.gens() - sage: sigma + sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) # optional - sage.groups + sage: sigma, tau = G.gens() # optional - sage.groups + sage: sigma # optional - sage.groups (1,2,3)(4,5) - sage: M.with_permuted_columns(sigma) + sage: M.with_permuted_columns(sigma) # optional - sage.groups [0 0 1 0 0] [2 0 0 0 0] [0 3 0 0 0] @@ -2646,8 +2650,8 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create a rational matrix:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,9,-7,4/5,4,3,6,4,3]) + sage: M = MatrixSpace(QQ, 3, 3) + sage: A = M([1,9,-7, 4/5,4,3, 6,4,3]) sage: A [ 1 9 -7] [4/5 4 3] @@ -2656,7 +2660,7 @@ cdef class Matrix(sage.structure.element.Matrix): Since the first row is numbered zero, this swaps the first and third rows:: - sage: A.swap_rows(0,2); A + sage: A.swap_rows(0, 2); A [ 6 4 3] [4/5 4 3] [ 1 9 -7] @@ -2733,7 +2737,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create a matrix:: - sage: M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) + sage: M = matrix(ZZ, [[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) sage: M [1 0 0 0 0] [0 2 0 0 0] @@ -2743,12 +2747,12 @@ cdef class Matrix(sage.structure.element.Matrix): Next of all, create a permutation group element and act on ``M``:: - sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) - sage: sigma, tau = G.gens() - sage: sigma + sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) # optional - sage.groups + sage: sigma, tau = G.gens() # optional - sage.groups + sage: sigma # optional - sage.groups (1,2,3)(4,5) - sage: M.permute_rows(sigma) - sage: M + sage: M.permute_rows(sigma) # optional - sage.groups + sage: M # optional - sage.groups [0 2 0 0 0] [0 0 3 0 0] [1 0 0 0 0] @@ -2782,7 +2786,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create a matrix:: - sage: M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) + sage: M = matrix(ZZ, [[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) sage: M [1 0 0 0 0] [0 2 0 0 0] @@ -2792,11 +2796,11 @@ cdef class Matrix(sage.structure.element.Matrix): Next of all, create a permutation group element and act on ``M``:: - sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) - sage: sigma, tau = G.gens() - sage: sigma + sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) # optional - sage.groups + sage: sigma, tau = G.gens() # optional - sage.groups + sage: sigma # optional - sage.groups (1,2,3)(4,5) - sage: M.with_permuted_rows(sigma) + sage: M.with_permuted_rows(sigma) # optional - sage.groups [0 2 0 0 0] [0 0 3 0 0] [1 0 0 0 0] @@ -2840,7 +2844,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create a matrix:: - sage: M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) + sage: M = matrix(ZZ, [[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) sage: M [1 0 0 0 0] [0 2 0 0 0] @@ -2850,12 +2854,12 @@ cdef class Matrix(sage.structure.element.Matrix): Next of all, create a permutation group element and act on ``M``:: - sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) - sage: sigma, tau = G.gens() - sage: sigma + sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) # optional - sage.groups + sage: sigma, tau = G.gens() # optional - sage.groups + sage: sigma # optional - sage.groups (1,2,3)(4,5) - sage: M.permute_rows_and_columns(sigma,tau) - sage: M + sage: M.permute_rows_and_columns(sigma,tau) # optional - sage.groups + sage: M # optional - sage.groups [2 0 0 0 0] [0 3 0 0 0] [0 0 0 0 1] @@ -2885,7 +2889,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We create a matrix:: - sage: M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) + sage: M = matrix(ZZ, [[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]]) sage: M [1 0 0 0 0] [0 2 0 0 0] @@ -2895,11 +2899,11 @@ cdef class Matrix(sage.structure.element.Matrix): Next of all, create a permutation group element and act on ``M``:: - sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) - sage: sigma, tau = G.gens() - sage: sigma + sage: G = PermutationGroup(['(1,2,3)(4,5)', '(1,2,3,4,5)']) # optional - sage.groups + sage: sigma, tau = G.gens() # optional - sage.groups + sage: sigma # optional - sage.groups (1,2,3)(4,5) - sage: M.with_permuted_rows_and_columns(sigma,tau) + sage: M.with_permuted_rows_and_columns(sigma,tau) # optional - sage.groups [2 0 0 0 0] [0 3 0 0 0] [0 0 0 0 1] @@ -2933,10 +2937,11 @@ cdef class Matrix(sage.structure.element.Matrix): If not, we get an error message:: - sage: a.add_multiple_of_row(1,0,SR.I()) + sage: a.add_multiple_of_row(1, 0, SR.I()) # optional - sage.symbolic Traceback (most recent call last): ... - TypeError: Multiplying row by Symbolic Ring element cannot be done over Rational Field, use change_ring or with_added_multiple_of_row instead. + TypeError: Multiplying row by Symbolic Ring element cannot be done over + Rational Field, use change_ring or with_added_multiple_of_row instead. """ self.check_row_bounds_and_mutability(i,j) try: @@ -3017,10 +3022,11 @@ cdef class Matrix(sage.structure.element.Matrix): If not, we get an error message:: - sage: a.add_multiple_of_column(1,0,SR.I()) + sage: a.add_multiple_of_column(1, 0, SR.I()) # optional - sage.symbolic Traceback (most recent call last): ... - TypeError: Multiplying column by Symbolic Ring element cannot be done over Rational Field, use change_ring or with_added_multiple_of_column instead. + TypeError: Multiplying column by Symbolic Ring element cannot be done over + Rational Field, use change_ring or with_added_multiple_of_column instead. """ self.check_column_bounds_and_mutability(i,j) try: @@ -3041,10 +3047,10 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We add -1 times the third column to the second column of an integer matrix, remembering to start numbering cols at zero:: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: b = a.with_added_multiple_of_column(1,2,-1); b + sage: b = a.with_added_multiple_of_column(1, 2, -1); b [ 0 -1 2] [ 3 -1 5] @@ -3057,7 +3063,7 @@ cdef class Matrix(sage.structure.element.Matrix): Adding a rational multiple is okay, and reassigning a variable is okay:: - sage: a = a.with_added_multiple_of_column(0,1,1/3); a + sage: a = a.with_added_multiple_of_column(0, 1, 1/3); a [ 1/3 1 2] [13/3 4 5] """ @@ -3094,11 +3100,11 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We rescale the second row of a matrix over the rational numbers:: - sage: a = matrix(QQ,3,range(6)); a + sage: a = matrix(QQ, 3, range(6)); a [0 1] [2 3] [4 5] - sage: a.rescale_row(1,1/2); a + sage: a.rescale_row(1, 1/2); a [ 0 1] [ 1 3/2] [ 4 5] @@ -3106,11 +3112,11 @@ cdef class Matrix(sage.structure.element.Matrix): We rescale the second row of a matrix over a polynomial ring:: sage: R. = QQ[] - sage: a = matrix(R,3,[1,x,x^2,x^3,x^4,x^5]);a + sage: a = matrix(R, 3, [1,x,x^2,x^3,x^4,x^5]); a [ 1 x] [x^2 x^3] [x^4 x^5] - sage: a.rescale_row(1,1/2); a + sage: a.rescale_row(1, 1/2); a [ 1 x] [1/2*x^2 1/2*x^3] [ x^4 x^5] @@ -3118,13 +3124,14 @@ cdef class Matrix(sage.structure.element.Matrix): We try and fail to rescale a matrix over the integers by a non-integer:: - sage: a = matrix(ZZ,2,3,[0,1,2, 3,4,4]); a + sage: a = matrix(ZZ, 2, 3, [0,1,2, 3,4,4]); a [0 1 2] [3 4 4] - sage: a.rescale_row(1,1/2) + sage: a.rescale_row(1, 1/2) Traceback (most recent call last): ... - TypeError: Rescaling row by Rational Field element cannot be done over Integer Ring, use change_ring or with_rescaled_row instead. + TypeError: Rescaling row by Rational Field element cannot be done + over Integer Ring, use change_ring or with_rescaled_row instead. To rescale the matrix by 1/2, you must change the base ring to the rationals:: @@ -3132,7 +3139,7 @@ cdef class Matrix(sage.structure.element.Matrix): sage: a = a.change_ring(QQ); a [0 1 2] [3 4 4] - sage: a.rescale_col(1,1/2); a + sage: a.rescale_col(1, 1/2); a [ 0 1/2 2] [ 3 2 4] """ @@ -3155,11 +3162,11 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We rescale the second row of a matrix over the integers:: - sage: a = matrix(ZZ,3,2,range(6)); a + sage: a = matrix(ZZ, 3, 2, range(6)); a [0 1] [2 3] [4 5] - sage: b = a.with_rescaled_row(1,-2); b + sage: b = a.with_rescaled_row(1, -2); b [ 0 1] [-4 -6] [ 4 5] @@ -3174,7 +3181,7 @@ cdef class Matrix(sage.structure.element.Matrix): Adding a rational multiple is okay, and reassigning a variable is okay:: - sage: a = a.with_rescaled_row(2,1/3); a + sage: a = a.with_rescaled_row(2, 1/3); a [ 0 1] [ 2 3] [4/3 5/3] @@ -3212,33 +3219,34 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We rescale the last column of a matrix over the rational numbers:: - sage: a = matrix(QQ,2,3,range(6)); a + sage: a = matrix(QQ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: a.rescale_col(2,1/2); a + sage: a.rescale_col(2, 1/2); a [ 0 1 1] [ 3 4 5/2] sage: R. = QQ[] We rescale the last column of a matrix over a polynomial ring:: - sage: a = matrix(R,2,3,[1,x,x^2,x^3,x^4,x^5]); a + sage: a = matrix(R, 2, 3, [1,x,x^2,x^3,x^4,x^5]); a [ 1 x x^2] [x^3 x^4 x^5] - sage: a.rescale_col(2,1/2); a + sage: a.rescale_col(2, 1/2); a [ 1 x 1/2*x^2] [ x^3 x^4 1/2*x^5] We try and fail to rescale a matrix over the integers by a non-integer:: - sage: a = matrix(ZZ,2,3,[0,1,2, 3,4,4]); a + sage: a = matrix(ZZ, 2, 3, [0,1,2, 3,4,4]); a [0 1 2] [3 4 4] - sage: a.rescale_col(2,1/2) + sage: a.rescale_col(2, 1/2) Traceback (most recent call last): ... - TypeError: Rescaling column by Rational Field element cannot be done over Integer Ring, use change_ring or with_rescaled_col instead. + TypeError: Rescaling column by Rational Field element cannot be done over + Integer Ring, use change_ring or with_rescaled_col instead. To rescale the matrix by 1/2, you must change the base ring to the rationals:: @@ -3270,10 +3278,10 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We rescale the last column of a matrix over the integers:: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: b = a.with_rescaled_col(2,-2); b + sage: b = a.with_rescaled_col(2, -2); b [ 0 1 -4] [ 3 4 -10] @@ -3286,7 +3294,7 @@ cdef class Matrix(sage.structure.element.Matrix): Adding a rational multiple is okay, and reassigning a variable is okay:: - sage: a = a.with_rescaled_col(1,1/3); a + sage: a = a.with_rescaled_col(1, 1/3); a [ 0 1/3 2] [ 3 4/3 5] """ @@ -3311,10 +3319,10 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We change the second row to -3 times the first row:: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: a.set_row_to_multiple_of_row(1,0,-3) + sage: a.set_row_to_multiple_of_row(1, 0, -3) sage: a [ 0 1 2] [ 0 -3 -6] @@ -3322,10 +3330,11 @@ cdef class Matrix(sage.structure.element.Matrix): If we try to multiply a row by a rational number, we get an error message:: - sage: a.set_row_to_multiple_of_row(1,0,1/2) + sage: a.set_row_to_multiple_of_row(1, 0, 1/2) Traceback (most recent call last): ... - TypeError: Multiplying row by Rational Field element cannot be done over Integer Ring, use change_ring or with_row_set_to_multiple_of_row instead. + TypeError: Multiplying row by Rational Field element cannot be done over + Integer Ring, use change_ring or with_row_set_to_multiple_of_row instead. """ self.check_row_bounds_and_mutability(i,j) cdef Py_ssize_t n @@ -3342,10 +3351,10 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES: We change the second row to -3 times the first row:: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: b = a.with_row_set_to_multiple_of_row(1,0,-3); b + sage: b = a.with_row_set_to_multiple_of_row(1, 0, -3); b [ 0 1 2] [ 0 -3 -6] @@ -3358,7 +3367,7 @@ cdef class Matrix(sage.structure.element.Matrix): Adding a rational multiple is okay, and reassigning a variable is okay:: - sage: a = a.with_row_set_to_multiple_of_row(1,0,1/2); a + sage: a = a.with_row_set_to_multiple_of_row(1, 0, 1/2); a [ 0 1 2] [ 0 1/2 1] """ @@ -3389,10 +3398,10 @@ cdef class Matrix(sage.structure.element.Matrix): :: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: a.set_col_to_multiple_of_col(1,0,-3) + sage: a.set_col_to_multiple_of_col(1, 0, -3) sage: a [ 0 0 2] [ 3 -9 5] @@ -3400,7 +3409,7 @@ cdef class Matrix(sage.structure.element.Matrix): If we try to multiply a column by a rational number, we get an error message:: - sage: a.set_col_to_multiple_of_col(1,0,1/2) + sage: a.set_col_to_multiple_of_col(1, 0, 1/2) Traceback (most recent call last): ... TypeError: Multiplying column by Rational Field element cannot be done over Integer Ring, use change_ring or with_col_set_to_multiple_of_col instead. @@ -3425,10 +3434,10 @@ cdef class Matrix(sage.structure.element.Matrix): :: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] - sage: b = a.with_col_set_to_multiple_of_col(1,0,-3); b + sage: b = a.with_col_set_to_multiple_of_col(1, 0, -3); b [ 0 0 2] [ 3 -9 5] @@ -3441,7 +3450,7 @@ cdef class Matrix(sage.structure.element.Matrix): Adding a rational multiple is okay, and reassigning a variable is okay:: - sage: a = a.with_col_set_to_multiple_of_col(1,0,1/2); a + sage: a = a.with_col_set_to_multiple_of_col(1, 0, 1/2); a [ 0 0 2] [ 3 3/2 5] """ @@ -3592,7 +3601,7 @@ cdef class Matrix(sage.structure.element.Matrix): Mutation of the B-matrix of the quiver of type `A_3`:: - sage: M = matrix(ZZ,3,[0,1,0,-1,0,-1,0,1,0]); M + sage: M = matrix(ZZ, 3, [0,1,0,-1,0,-1,0,1,0]); M [ 0 1 0] [-1 0 -1] [ 0 1 0] @@ -3607,7 +3616,7 @@ cdef class Matrix(sage.structure.element.Matrix): [-1 0 1] [ 1 -1 0] - sage: M = matrix(ZZ,6,[0,1,0,-1,0,-1,0,1,0,1,0,0,0,1,0,0,0,1]); M + sage: M = matrix(ZZ, 6, [0,1,0,-1,0,-1,0,1,0,1,0,0,0,1,0,0,0,1]); M [ 0 1 0] [-1 0 -1] [ 0 1 0] @@ -3675,12 +3684,12 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: M = matrix(ZZ,3,[0,1,0,-1,0,-1,0,1,0]); M + sage: M = matrix(ZZ, 3, [0,1,0,-1,0,-1,0,1,0]); M [ 0 1 0] [-1 0 -1] [ 0 1 0] - sage: M._travel_column({0:1},0,-1,True) + sage: M._travel_column({0: 1}, 0, -1, True) [1] """ cdef list L = [] @@ -3789,7 +3798,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] sage: a.linear_combination_of_rows([1,2]) @@ -3810,7 +3819,7 @@ cdef class Matrix(sage.structure.element.Matrix): We check that a matrix with no rows behaves properly. :: - sage: matrix(QQ,0,2).linear_combination_of_rows([]) + sage: matrix(QQ, 0, 2).linear_combination_of_rows([]) (0, 0) The object returned is a vector, or a free module element. :: @@ -3830,7 +3839,7 @@ cdef class Matrix(sage.structure.element.Matrix): The length of v can be less than the number of rows, but not greater. :: - sage: A = matrix(QQ,3,4,range(12)) + sage: A = matrix(QQ, 3, 4, range(12)) sage: A.linear_combination_of_rows([2,3]) (12, 17, 22, 27) sage: A.linear_combination_of_rows([1,2,3,4]) @@ -3866,7 +3875,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: a = matrix(ZZ,2,3,range(6)); a + sage: a = matrix(ZZ, 2, 3, range(6)); a [0 1 2] [3 4 5] sage: a.linear_combination_of_columns([1,1,1]) @@ -3887,7 +3896,7 @@ cdef class Matrix(sage.structure.element.Matrix): We check that a matrix with no columns behaves properly. :: - sage: matrix(QQ,2,0).linear_combination_of_columns([]) + sage: matrix(QQ, 2, 0).linear_combination_of_columns([]) (0, 0) The object returned is a vector, or a free module element. :: @@ -3907,7 +3916,7 @@ cdef class Matrix(sage.structure.element.Matrix): The length of v can be less than the number of columns, but not greater. :: - sage: A = matrix(QQ,3,5, range(15)) + sage: A = matrix(QQ, 3, 5, range(15)) sage: A.linear_combination_of_columns([1,-2,3,-4]) (-8, -18, -28) sage: A.linear_combination_of_columns([1,2,3,4,5,6]) @@ -3935,15 +3944,15 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: m=Matrix(QQ,2,range(0,4)) + sage: m = Matrix(QQ, 2, range(0,4)) sage: m.is_symmetric() False - sage: m=Matrix(QQ,2,(1,1,1,1,1,1)) + sage: m = Matrix(QQ, 2, (1,1,1,1,1,1)) sage: m.is_symmetric() False - sage: m=Matrix(QQ,1,(2,)) + sage: m = Matrix(QQ, 1, (2,)) sage: m.is_symmetric() True @@ -3989,44 +3998,44 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: A = matrix(QQbar, [[ 1 + I, 1 - 6*I, -1 - I], + sage: A = matrix(QQbar, [[ 1 + I, 1 - 6*I, -1 - I], # optional - sage.rings.number_field ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) - sage: A._is_hermitian(skew=False, tolerance=0) + sage: A._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field False - sage: B = A*A.conjugate_transpose() - sage: B._is_hermitian(skew=False, tolerance=0) + sage: B = A*A.conjugate_transpose() # optional - sage.rings.number_field + sage: B._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field True Sage has several fields besides the entire complex numbers where conjugation is non-trivial:: - sage: F. = QuadraticField(-7) - sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], + sage: F. = QuadraticField(-7) # optional - sage.rings.number_field + sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], # optional - sage.rings.number_field ....: [-2*b - 3, -3*b + 2, -2*b], ....: [ b + 1, 0, -2]]) - sage: C._is_hermitian(skew=False, tolerance=0) + sage: C._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field False - sage: C = C*C.conjugate_transpose() - sage: C._is_hermitian(skew=False, tolerance=0) + sage: C = C*C.conjugate_transpose() # optional - sage.rings.number_field + sage: C._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field True A matrix that is nearly Hermitian, but for a non-real diagonal entry:: - sage: A = matrix(QQbar, [[ 2, 2-I, 1+4*I], + sage: A = matrix(QQbar, [[ 2, 2-I, 1+4*I], # optional - sage.rings.number_field ....: [ 2+I, 3+I, 2-6*I], ....: [1-4*I, 2+6*I, 5]]) - sage: A._is_hermitian(skew=False, tolerance=0) + sage: A._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field False - sage: A[1,1] = 132 - sage: A._is_hermitian(skew=False, tolerance=0) + sage: A[1, 1] = 132 # optional - sage.rings.number_field + sage: A._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field True Rectangular matrices are never Hermitian:: - sage: A = matrix(QQbar, 3, 4) - sage: A._is_hermitian(skew=False, tolerance=0) + sage: A = matrix(QQbar, 3, 4) # optional - sage.rings.number_field + sage: A._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field False A square, empty matrix is trivially Hermitian:: @@ -4036,10 +4045,11 @@ cdef class Matrix(sage.structure.element.Matrix): True A matrix that is skew-Hermitian:: - sage: A = matrix(QQbar, [[-I, 2+I], [-2+I, 0]]) - sage: A._is_hermitian(skew=False, tolerance=0) + + sage: A = matrix(QQbar, [[-I, 2+I], [-2+I, 0]]) # optional - sage.rings.number_field + sage: A._is_hermitian(skew=False, tolerance=0) # optional - sage.rings.number_field False - sage: A._is_hermitian(skew=True, tolerance=0) + sage: A._is_hermitian(skew=True, tolerance=0) # optional - sage.rings.number_field True """ key = ("_is_hermitian", skew, tolerance) @@ -4131,44 +4141,44 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: A = matrix(QQbar, [[ 1 + I, 1 - 6*I, -1 - I], + sage: A = matrix(QQbar, [[ 1 + I, 1 - 6*I, -1 - I], # optional - sage.rings.number_field ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) - sage: A.is_hermitian() + sage: A.is_hermitian() # optional - sage.rings.number_field False - sage: B = A*A.conjugate_transpose() - sage: B.is_hermitian() + sage: B = A * A.conjugate_transpose() # optional - sage.rings.number_field + sage: B.is_hermitian() # optional - sage.rings.number_field True Sage has several fields besides the entire complex numbers where conjugation is non-trivial. :: - sage: F. = QuadraticField(-7) - sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], + sage: F. = QuadraticField(-7) # optional - sage.rings.number_field + sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], # optional - sage.rings.number_field ....: [-2*b - 3, -3*b + 2, -2*b], ....: [ b + 1, 0, -2]]) - sage: C.is_hermitian() + sage: C.is_hermitian() # optional - sage.rings.number_field False - sage: C = C*C.conjugate_transpose() - sage: C.is_hermitian() + sage: C = C*C.conjugate_transpose() # optional - sage.rings.number_field + sage: C.is_hermitian() # optional - sage.rings.number_field True A matrix that is nearly Hermitian, but for a non-real diagonal entry. :: - sage: A = matrix(QQbar, [[ 2, 2-I, 1+4*I], + sage: A = matrix(QQbar, [[ 2, 2-I, 1+4*I], # optional - sage.rings.number_field ....: [ 2+I, 3+I, 2-6*I], ....: [1-4*I, 2+6*I, 5]]) - sage: A.is_hermitian() + sage: A.is_hermitian() # optional - sage.rings.number_field False - sage: A[1,1] = 132 - sage: A.is_hermitian() + sage: A[1, 1] = 132 # optional - sage.rings.number_field + sage: A.is_hermitian() # optional - sage.rings.number_field True Rectangular matrices are never Hermitian. :: - sage: A = matrix(QQbar, 3, 4) - sage: A.is_hermitian() + sage: A = matrix(QQbar, 3, 4) # optional - sage.rings.number_field + sage: A.is_hermitian() # optional - sage.rings.number_field False A square, empty matrix is trivially Hermitian. :: @@ -4206,27 +4216,27 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: A = matrix(QQbar, [[0, -1], + sage: A = matrix(QQbar, [[0, -1], # optional - sage.rings.number_field ....: [1, 0]]) - sage: A.is_skew_hermitian() + sage: A.is_skew_hermitian() # optional - sage.rings.number_field True A matrix that is nearly skew-Hermitian, but for a non-real diagonal entry. :: - sage: A = matrix(QQbar, [[ -I, -1, 1-I], + sage: A = matrix(QQbar, [[ -I, -1, 1-I], # optional - sage.rings.number_field ....: [ 1, 1, -1], ....: [-1-I, 1, -I]]) - sage: A.is_skew_hermitian() + sage: A.is_skew_hermitian() # optional - sage.rings.number_field False - sage: A[1,1] = -I - sage: A.is_skew_hermitian() + sage: A[1, 1] = -I # optional - sage.rings.number_field + sage: A.is_skew_hermitian() # optional - sage.rings.number_field True Rectangular matrices are never skew-Hermitian. :: - sage: A = matrix(QQbar, 3, 4) - sage: A.is_skew_hermitian() + sage: A = matrix(QQbar, 3, 4) # optional - sage.rings.number_field + sage: A.is_skew_hermitian() # optional - sage.rings.number_field False A square, empty matrix is trivially Hermitian. :: @@ -4399,7 +4409,7 @@ cdef class Matrix(sage.structure.element.Matrix): sage: matrix([[0,6],[3,0]]).is_skew_symmetrizable(positive=True) False - sage: M = matrix(4,[0,1,0,0,-1,0,-1,0,0,2,0,1,0,0,-1,0]); M + sage: M = matrix(4, [0,1,0,0, -1,0,-1,0, 0,2,0,1, 0,0,-1,0]); M [ 0 1 0 0] [-1 0 -1 0] [ 0 2 0 1] @@ -4408,7 +4418,7 @@ cdef class Matrix(sage.structure.element.Matrix): sage: M.is_skew_symmetrizable(return_diag=True) [1, 1, 1/2, 1/2] - sage: M2 = diagonal_matrix([1,1,1/2,1/2])*M; M2 + sage: M2 = diagonal_matrix([1,1,1/2,1/2]) * M; M2 [ 0 1 0 0] [ -1 0 -1 0] [ 0 1 0 1/2] @@ -4434,9 +4444,9 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: matrix(QQ,2,2,range(4)).is_dense() + sage: matrix(QQ, 2, 2, range(4)).is_dense() True - sage: matrix(QQ,2,2,range(4),sparse=True).is_dense() + sage: matrix(QQ, 2, 2, range(4), sparse=True).is_dense() False """ return self.is_dense_c() @@ -4450,9 +4460,9 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: matrix(QQ,2,2,range(4)).is_sparse() + sage: matrix(QQ, 2, 2, range(4)).is_sparse() False - sage: matrix(QQ,2,2,range(4),sparse=True).is_sparse() + sage: matrix(QQ, 2, 2, range(4), sparse=True).is_sparse() True """ return self.is_sparse_c() @@ -4464,9 +4474,9 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: matrix(QQ,2,2,range(4)).is_square() + sage: matrix(QQ, 2, 2, range(4)).is_square() True - sage: matrix(QQ,2,3,range(6)).is_square() + sage: matrix(QQ, 2, 3, range(6)).is_square() False """ return self._nrows == self._ncols @@ -4499,7 +4509,7 @@ cdef class Matrix(sage.structure.element.Matrix): :: - sage: A = MatrixSpace(IntegerRing(),2)([1,10,0,-1]) + sage: A = MatrixSpace(IntegerRing(), 2)([1,10,0,-1]) sage: A.is_invertible() True sage: ~A # compute the inverse @@ -4512,7 +4522,7 @@ cdef class Matrix(sage.structure.element.Matrix): :: sage: R. = PolynomialRing(IntegerRing()) - sage: A = MatrixSpace(R,2)([1,x,0,-1]) + sage: A = MatrixSpace(R, 2)([1,x,0,-1]) sage: A.is_invertible() True sage: ~A @@ -4549,7 +4559,7 @@ cdef class Matrix(sage.structure.element.Matrix): A singular matrix over the field ``QQ``. :: - sage: A = matrix(QQ, 4, [-1,2,-3,6,0,-1,-1,0,-1,1,-5,7,-1,6,5,2]) + sage: A = matrix(QQ, 4, [-1,2,-3,6, 0,-1,-1,0, -1,1,-5,7, -1,6,5,2]) sage: A.is_singular() True sage: A.right_kernel().dimension() @@ -4557,7 +4567,7 @@ cdef class Matrix(sage.structure.element.Matrix): A matrix that is not singular, i.e. nonsingular, over a field. :: - sage: B = matrix(QQ, 4, [1,-3,-1,-5,2,-5,-2,-7,-2,5,3,4,-1,4,2,6]) + sage: B = matrix(QQ, 4, [1,-3,-1,-5, 2,-5,-2,-7, -2,5,3,4, -1,4,2,6]) sage: B.is_singular() False sage: B.left_kernel().dimension() @@ -4577,7 +4587,7 @@ cdef class Matrix(sage.structure.element.Matrix): When the base ring is not a field, then a matrix may be both not invertible and not singular. :: - sage: D = matrix(ZZ, 4, [2,0,-4,8,2,1,-2,7,2,5,7,0,0,1,4,-6]) + sage: D = matrix(ZZ, 4, [2,0,-4,8, 2,1,-2,7, 2,5,7,0, 0,1,4,-6]) sage: D.is_invertible() False sage: D.is_singular() @@ -4629,8 +4639,8 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: m = matrix(GF(7),5,range(25)) - sage: m.rank() + sage: m = matrix(GF(7), 5, range(25)) # optional - sage.rings.finite_rings + sage: m.rank() # optional - sage.rings.finite_rings 2 Rank is not implemented over the integers modulo a composite yet.:: @@ -4646,10 +4656,10 @@ cdef class Matrix(sage.structure.element.Matrix): We should be able to compute the rank of a matrix whose entries are polynomials over a finite field (:trac:`5014`):: - sage: P. = PolynomialRing(GF(17)) - sage: m = matrix(P, [ [ 6*x^2 + 8*x + 12, 10*x^2 + 4*x + 11], - ....: [8*x^2 + 12*x + 15, 8*x^2 + 9*x + 16] ]) - sage: m.rank() + sage: P. = PolynomialRing(GF(17)) # optional - sage.rings.finite_rings + sage: m = matrix(P, [[ 6*x^2 + 8*x + 12, 10*x^2 + 4*x + 11], # optional - sage.rings.finite_rings + ....: [8*x^2 + 12*x + 15, 8*x^2 + 9*x + 16]]) + sage: m.rank() # optional - sage.rings.finite_rings 2 """ x = self.fetch('rank') @@ -4670,7 +4680,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: a = matrix(QQ,3,3,range(9)); a + sage: a = matrix(QQ, 3, 3, range(9)); a [0 1 2] [3 4 5] [6 7 8] @@ -4881,42 +4891,42 @@ cdef class Matrix(sage.structure.element.Matrix): Over finite fields:: - sage: A = matrix(GF(59),3,[10,56,39,53,56,33,58,24,55]) - sage: A.multiplicative_order() + sage: A = matrix(GF(59), 3, [10,56,39,53,56,33,58,24,55]) # optional - sage.rings.finite_rings + sage: A.multiplicative_order() # optional - sage.rings.finite_rings 580 - sage: (A^580).is_one() + sage: (A^580).is_one() # optional - sage.rings.finite_rings True - sage: B = matrix(GF(10007^3,'b'),0) - sage: B.multiplicative_order() + sage: B = matrix(GF(10007^3, 'b'), 0) # optional - sage.rings.finite_rings + sage: B.multiplicative_order() # optional - sage.rings.finite_rings 1 - sage: M = MatrixSpace(GF(11^2,'e'),5) - sage: E = M.random_element() - sage: while E.det() == 0: + sage: M = MatrixSpace(GF(11^2, 'e'), 5) # optional - sage.rings.finite_rings + sage: E = M.random_element() # optional - sage.rings.finite_rings + sage: while E.det() == 0: # optional - sage.rings.finite_rings ....: E = M.random_element() - sage: (E^E.multiplicative_order()).is_one() + sage: (E^E.multiplicative_order()).is_one() # optional - sage.rings.finite_rings True Over `\ZZ`:: - sage: m = matrix(ZZ,2,2,[-1,1,-1,0]) - sage: m.multiplicative_order() + sage: m = matrix(ZZ, 2, 2, [-1,1,-1,0]) + sage: m.multiplicative_order() # optional - sage.groups 3 - sage: m = posets.ChainPoset(6).coxeter_transformation() - sage: m.multiplicative_order() + sage: m = posets.ChainPoset(6).coxeter_transformation() # optional - sage.combinat sage.graphs + sage: m.multiplicative_order() # optional - sage.combinat sage.graphs sage.groups 7 - sage: P = posets.TamariLattice(4).coxeter_transformation() - sage: P.multiplicative_order() + sage: P = posets.TamariLattice(4).coxeter_transformation() # optional - sage.combinat sage.graphs + sage: P.multiplicative_order() # optional - sage.combinat sage.graphs sage.groups 10 sage: M = matrix(ZZ, 2, 2, [1, 1, 0, 1]) - sage: M.multiplicative_order() + sage: M.multiplicative_order() # optional - sage.groups +Infinity - sage: for k in range(600): + sage: for k in range(600): # optional - sage.groups ....: m = SL2Z.random_element() ....: o = m.multiplicative_order() ....: if o != Infinity and m**o != SL2Z.one(): @@ -4931,19 +4941,19 @@ cdef class Matrix(sage.structure.element.Matrix): ....: else: ....: return ZZ.random_element(-100,100) sage: rnd = matrix(ZZ, 8, 8, val) - sage: (rnd * m24 * rnd.inverse_of_unit()).multiplicative_order() + sage: (rnd * m24 * rnd.inverse_of_unit()).multiplicative_order() # optional - sage.groups 24 TESTS:: - sage: C = matrix(GF(2^10,'c'),2,3,[1]*6) - sage: C.multiplicative_order() + sage: C = matrix(GF(2^10, 'c'), 2, 3, [1]*6) # optional - sage.rings.finite_rings + sage: C.multiplicative_order() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: self must be invertible ... - sage: D = matrix(IntegerModRing(6),3,[5,5,3,0,2,5,5,4,0]) - sage: D.multiplicative_order() + sage: D = matrix(IntegerModRing(6), 3, [5,5,3,0,2,5,5,4,0]) + sage: D.multiplicative_order() # optional - sage.groups Traceback (most recent call last): ... NotImplementedError: ... only ... over finite fields or ZZ @@ -5033,7 +5043,7 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: B = matrix(QQ,2, [1,2,3,4]) + sage: B = matrix(QQ, 2, [1,2,3,4]) sage: V = VectorSpace(QQ, 2) sage: v = V([-1,5]) sage: v*B @@ -5062,11 +5072,11 @@ cdef class Matrix(sage.structure.element.Matrix): Check that :trac:`8198` is fixed:: - sage: R = Qp(5, 5) - sage: x = R(5).add_bigoh(1) - sage: I = matrix(R, [[1, 0], [0, 1]]) - sage: v = vector(R, [1, x]) - sage: v*I + sage: R = Qp(5, 5) # optional - sage.rings.padics + sage: x = R(5).add_bigoh(1) # optional - sage.rings.padics + sage: I = matrix(R, [[1, 0], [0, 1]]) # optional - sage.rings.padics + sage: v = vector(R, [1, x]) # optional - sage.rings.padics + sage: v*I # optional - sage.rings.padics (1 + O(5^5), O(5)) """ @@ -5096,11 +5106,11 @@ cdef class Matrix(sage.structure.element.Matrix): Check that :trac:`8198` is fixed:: - sage: R = Qp(5, 5) - sage: x = R(5).add_bigoh(1) - sage: I = matrix(R, [[1, 0], [0, 1]]) - sage: v = vector(R, [1, x]) - sage: I*v + sage: R = Qp(5, 5) # optional - sage.rings.padics + sage: x = R(5).add_bigoh(1) # optional - sage.rings.padics + sage: I = matrix(R, [[1, 0], [0, 1]]) # optional - sage.rings.padics + sage: v = vector(R, [1, x]) # optional - sage.rings.padics + sage: I*v # optional - sage.rings.padics (1 + O(5^5), O(5)) """ @@ -5136,13 +5146,13 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: A = matrix(ZZ,2, [1,1,3,5]); A + sage: A = matrix(ZZ, 2, [1,1,3,5]); A [1 1] [3 5] sage: v = vector([1,0]) - sage: A.iterates(v,0) + sage: A.iterates(v, 0) [] - sage: A.iterates(v,5) + sage: A.iterates(v, 5) [ 1 0] [ 1 1] [ 4 6] @@ -5151,17 +5161,17 @@ cdef class Matrix(sage.structure.element.Matrix): Another example:: - sage: a = matrix(ZZ,3,range(9)); a + sage: a = matrix(ZZ, 3, range(9)); a [0 1 2] [3 4 5] [6 7 8] sage: v = vector([1,0,0]) - sage: a.iterates(v,4) + sage: a.iterates(v, 4) [ 1 0 0] [ 0 1 2] [ 15 18 21] [180 234 288] - sage: a.iterates(v,4,rows=False) + sage: a.iterates(v, 4, rows=False) [ 1 0 15 180] [ 0 3 42 558] [ 0 6 69 936] @@ -5193,10 +5203,10 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: R. = FreeAlgebra(QQ,2) - sage: a = matrix(2,2, [1,2,x*y,y*x]) - sage: b = matrix(2,2, [1,2,y*x,y*x]) - sage: a+b # indirect doctest + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: a = matrix(2, 2, [1,2,x*y,y*x]) # optional - sage.combinat + sage: b = matrix(2, 2, [1,2,y*x,y*x]) # optional - sage.combinat + sage: a + b # indirect doctest # optional - sage.combinat [ 2 4] [x*y + y*x 2*y*x] @@ -5216,10 +5226,10 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: - sage: R. = FreeAlgebra(QQ,2) - sage: a = matrix(2,2, [1,2,x*y,y*x]) - sage: b = matrix(2,2, [1,2,y*x,y*x]) - sage: a-b # indirect doctest + sage: R. = FreeAlgebra(QQ,2) # optional - sage.combinat + sage: a = matrix(2, 2, [1,2,x*y,y*x]) # optional - sage.combinat + sage: b = matrix(2, 2, [1,2,y*x,y*x]) # optional - sage.combinat + sage: a - b # indirect doctest # optional - sage.combinat [ 0 0] [x*y - y*x 0] @@ -5279,24 +5289,24 @@ cdef class Matrix(sage.structure.element.Matrix): """ EXAMPLES:: - sage: a = matrix(QQ['x'],2,range(6)) + sage: a = matrix(QQ['x'], 2, range(6)) sage: (3/4) * a [ 0 3/4 3/2] [ 9/4 3 15/4] sage: R. = QQ[] - sage: a = matrix(R,2,3,[1,x,y,-x*y,x+y,x-y]); a + sage: a = matrix(R, 2, 3, [1,x,y, -x*y,x+y,x-y]); a [ 1 x y] [ -x*y x + y x - y] sage: (x*y) * a [ x*y x^2*y x*y^2] [ -x^2*y^2 x^2*y + x*y^2 x^2*y - x*y^2] - sage: R. = FreeAlgebra(ZZ,2) - sage: a = matrix(R,2,3,[1,x,y,-x*y,x+y,x-y]); a + sage: R. = FreeAlgebra(ZZ,2) # optional - sage.combinat + sage: a = matrix(R, 2, 3, [1,x,y, -x*y,x+y,x-y]); a # optional - sage.combinat [ 1 x y] [ -x*y x + y x - y] - sage: (x*y) * a # indirect doctest + sage: (x*y) * a # indirect doctest # optional - sage.combinat [ x*y x*y*x x*y^2] [ -x*y*x*y x*y*x + x*y^2 x*y*x - x*y^2] """ @@ -5325,22 +5335,22 @@ cdef class Matrix(sage.structure.element.Matrix): An example in which the base ring is not commutative:: - sage: F. = FreeAlgebra(QQ,2) - sage: a = matrix(2,[x,y,x^2,y^2]); a + sage: F. = FreeAlgebra(QQ,2) # optional - sage.combinat + sage: a = matrix(2, [x,y, x^2,y^2]); a # optional - sage.combinat [ x y] [x^2 y^2] - sage: x * a # indirect doctest + sage: x * a # indirect doctest # optional - sage.combinat [ x^2 x*y] [ x^3 x*y^2] - sage: a * y + sage: a * y # optional - sage.combinat [ x*y y^2] [x^2*y y^3] - sage: R. = FreeAlgebra(ZZ,2) - sage: a = matrix(R,2,3,[1,x,y,-x*y,x+y,x-y]); a + sage: R. = FreeAlgebra(ZZ,2) # optional - sage.combinat + sage: a = matrix(R, 2, 3, [1,x,y, -x*y,x+y,x-y]); a # optional - sage.combinat [ 1 x y] [ -x*y x + y x - y] - sage: a * (x*y) + sage: a * (x*y) # optional - sage.combinat [ x*y x^2*y y*x*y] [ -x*y*x*y x^2*y + y*x*y x^2*y - y*x*y] """ @@ -5364,17 +5374,17 @@ cdef class Matrix(sage.structure.element.Matrix): :: sage: R. = QQ[] - sage: a = matrix(R,2,3,[1,x,y,-x*y,x+y,x-y]); a + sage: a = matrix(R, 2, 3, [1,x,y, -x*y,x+y,x-y]); a [ 1 x y] [ -x*y x + y x - y] sage: b = a.transpose(); b [ 1 -x*y] [ x x + y] [ y x - y] - sage: a*b # indirect doctest + sage: a*b # indirect doctest [ x^2 + y^2 + 1 x^2 + x*y - y^2] [ x^2 + x*y - y^2 x^2*y^2 + 2*x^2 + 2*y^2] - sage: b*a # indirect doctest + sage: b*a # indirect doctest [ x^2*y^2 + 1 -x^2*y - x*y^2 + x -x^2*y + x*y^2 + y] [ -x^2*y - x*y^2 + x 2*x^2 + 2*x*y + y^2 x^2 + x*y - y^2] [ -x^2*y + x*y^2 + y x^2 + x*y - y^2 x^2 - 2*x*y + 2*y^2] @@ -5382,63 +5392,65 @@ cdef class Matrix(sage.structure.element.Matrix): We verify that the matrix multiplies are correct by comparing them with what PARI gets:: - sage: gp(a)*gp(b) - gp(a*b) + sage: gp(a)*gp(b) - gp(a*b) # optional - sage.libs.pari [0, 0; 0, 0] - sage: gp(b)*gp(a) - gp(b*a) + sage: gp(b)*gp(a) - gp(b*a) # optional - sage.libs.pari [0, 0, 0; 0, 0, 0; 0, 0, 0] EXAMPLE of matrix times matrix over different base rings:: - sage: a = matrix(ZZ,2,2,range(4)) - sage: b = matrix(GF(7),2,2,range(4)) - sage: c = matrix(QQ,2,2,range(4)) - sage: d = a*b; d + sage: a = matrix(ZZ, 2, 2, range(4)) + sage: b = matrix(GF(7), 2, 2, range(4)) # optional - sage.rings.finite_rings + sage: c = matrix(QQ, 2, 2, range(4)) + sage: d = a * b; d # optional - sage.rings.finite_rings [2 3] [6 4] - sage: parent(d) + sage: parent(d) # optional - sage.rings.finite_rings Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7 - sage: parent(b*a) + sage: parent(b * a) # optional - sage.rings.finite_rings Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7 - sage: d = a*c; d + sage: d = a * c; d [ 2 3] [ 6 11] sage: parent(d) Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: d = b+c + sage: d = b + c # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7' and 'Full MatrixSpace of 2 by 2 dense matrices over Rational Field' - sage: d = b+c.change_ring(GF(7)); d + TypeError: unsupported operand parent(s) for +: + 'Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7' and + 'Full MatrixSpace of 2 by 2 dense matrices over Rational Field' + sage: d = b + c.change_ring(GF(7)); d # optional - sage.rings.finite_rings [0 2] [4 6] EXAMPLE of matrix times matrix where one matrix is sparse and the other is dense (in such mixed cases, the result is always dense):: - sage: a = matrix(ZZ,2,2,range(4),sparse=True) - sage: b = matrix(GF(7),2,2,range(4),sparse=False) - sage: c = a*b; c + sage: a = matrix(ZZ, 2, 2, range(4), sparse=True) + sage: b = matrix(GF(7), 2, 2, range(4), sparse=False) # optional - sage.rings.finite_rings + sage: c = a * b; c # optional - sage.rings.finite_rings [2 3] [6 4] - sage: parent(c) + sage: parent(c) # optional - sage.rings.finite_rings Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7 - sage: c = b*a; c + sage: c = b * a; c # optional - sage.rings.finite_rings [2 3] [6 4] - sage: parent(c) + sage: parent(c) # optional - sage.rings.finite_rings Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 7 EXAMPLE of matrix multiplication over a noncommutative base ring:: - sage: R. = FreeAlgebra(QQ,2) - sage: x*y - y*x + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: x*y - y*x # optional - sage.combinat x*y - y*x - sage: a = matrix(2,2, [1,2,x,y]) - sage: b = matrix(2,2, [x,y,x^2,y^2]) - sage: a*b + sage: a = matrix(2, 2, [1,2, x,y]) # optional - sage.combinat + sage: b = matrix(2, 2, [x,y, x^2,y^2]) # optional - sage.combinat + sage: a*b # optional - sage.combinat [ x + 2*x^2 y + 2*y^2] [x^2 + y*x^2 x*y + y^3] - sage: b*a + sage: b*a # optional - sage.combinat [ x + y*x 2*x + y^2] [x^2 + y^2*x 2*x^2 + y^3] @@ -5459,7 +5471,9 @@ cdef class Matrix(sage.structure.element.Matrix): sage: a*v Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 2 by 3 dense matrices over Integer Ring' and 'Ambient free module of rank 2 over the principal ideal domain Integer Ring' + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 3 dense matrices over Integer Ring' and + 'Ambient free module of rank 2 over the principal ideal domain Integer Ring' This illustrates how coercion works:: @@ -5506,15 +5520,15 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLE of scalar multiplication in the noncommutative case:: - sage: R. = FreeAlgebra(ZZ,2) - sage: a = matrix(2,[x,y,x^2,y^2]) - sage: a * x + sage: R. = FreeAlgebra(ZZ, 2) # optional - sage.combinat + sage: a = matrix(2, [x,y, x^2,y^2]) # optional - sage.combinat + sage: a * x # optional - sage.combinat [ x^2 y*x] [ x^3 y^2*x] - sage: x * a + sage: x * a # optional - sage.combinat [ x^2 x*y] [ x^3 x*y^2] - sage: a*x - x*a + sage: a*x - x*a # optional - sage.combinat [ 0 -x*y + y*x] [ 0 -x*y^2 + y^2*x] """ @@ -5599,7 +5613,7 @@ cdef class Matrix(sage.structure.element.Matrix): :: - sage: I = MatrixSpace(ZZ,2)(1) # identity matrix + sage: I = MatrixSpace(ZZ, 2)(1) # identity matrix sage: ~I [1 0] [0 1] @@ -5614,7 +5628,7 @@ cdef class Matrix(sage.structure.element.Matrix): A matrix with 0 rows and 0 columns is invertible (see :trac:`3734`):: - sage: M = MatrixSpace(RR,0,0)(0); M + sage: M = MatrixSpace(RR, 0, 0)(0); M [] sage: M.determinant() 1.00000000000000 @@ -5625,13 +5639,13 @@ cdef class Matrix(sage.structure.element.Matrix): Matrices over the integers modulo a composite modulus:: - sage: m = matrix(Zmod(49),2,[2,1,3,3]) + sage: m = matrix(Zmod(49), 2, [2,1,3,3]) sage: type(m) sage: ~m [ 1 16] [48 17] - sage: m = matrix(Zmod(2^100),2,[2,1,3,3]) + sage: m = matrix(Zmod(2^100), 2, [2,1,3,3]) sage: type(m) sage: (~m)*m @@ -5643,8 +5657,8 @@ cdef class Matrix(sage.structure.element.Matrix): Matrices over p-adics. See :trac:`17272` :: - sage: R = ZpCA(5,5,print_mode='val-unit') - sage: A = matrix(R,3,3,[250,2369,1147,106,927,362,90,398,2483]) + sage: R = ZpCA(5, 5, print_mode='val-unit') + sage: A = matrix(R, 3, 3, [250,2369,1147,106,927,362,90,398,2483]) sage: A [5^3 * 2 + O(5^5) 2369 + O(5^5) 1147 + O(5^5)] [ 106 + O(5^5) 927 + O(5^5) 362 + O(5^5)] @@ -5656,7 +5670,7 @@ cdef class Matrix(sage.structure.element.Matrix): This matrix is not invertible:: - sage: m = matrix(Zmod(9),2,[2,1,3,3]) + sage: m = matrix(Zmod(9), 2, [2,1,3,3]) sage: ~m Traceback (most recent call last): ... @@ -5770,19 +5784,19 @@ cdef class Matrix(sage.structure.element.Matrix): EXAMPLES:: sage: R. = ZZ[] - sage: RR = R.quotient(a*d-b*c-1) - sage: a,b,c,d = RR.gens() - sage: m = matrix(2, [a,b,c,d]) - sage: n = m.inverse_of_unit() - sage: m * n + sage: RR = R.quotient(a*d - b*c - 1) # optional - sage.libs.singular + sage: a,b,c,d = RR.gens() # optional - sage.libs.singular + sage: m = matrix(2, [a,b, c,d]) # optional - sage.libs.singular + sage: n = m.inverse_of_unit() # optional - sage.libs.singular + sage: m * n # optional - sage.libs.singular [1 0] [0 1] - sage: matrix(RR, 2, 1, [a,b]).inverse_of_unit() + sage: matrix(RR, 2, 1, [a,b]).inverse_of_unit() # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: self must be a square matrix - sage: matrix(RR, 1, 1, [2]).inverse_of_unit() + sage: matrix(RR, 1, 1, [2]).inverse_of_unit() # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError: Lifting of multivariate polynomials over non-fields is not implemented. @@ -5795,9 +5809,9 @@ cdef class Matrix(sage.structure.element.Matrix): Tests for :trac:`28570`:: - sage: P = posets.TamariLattice(7) - sage: M = P._hasse_diagram._leq_matrix - sage: M.inverse_of_unit() # this was very slow, now 1s + sage: P = posets.TamariLattice(7) # optional - sage.combinat sage.graphs + sage: M = P._hasse_diagram._leq_matrix # optional - sage.combinat sage.graphs + sage: M.inverse_of_unit() # this was very slow, now 1s # optional - sage.combinat sage.graphs 429 x 429 sparse matrix over Integer Ring... sage: m = matrix(Zmod(2**2), 1, 1, [1], sparse=True) @@ -5890,9 +5904,9 @@ cdef class Matrix(sage.structure.element.Matrix): Non-integer (symbolic) exponents are also supported:: - sage: k = var('k') - sage: A = matrix([[2, -1], [1, 0]]) - sage: A^(2*k+1) + sage: k = var('k') # optional - sage.symbolic + sage: A = matrix([[2, -1], [1, 0]]) # optional - sage.symbolic + sage: A^(2*k+1) # optional - sage.symbolic [ 2*k + 2 -2*k - 1] [ 2*k + 1 -2*k] """ @@ -6106,8 +6120,8 @@ def unpickle(cls, parent, immutability, cache, data, version): OVER `\ZZ`:: - sage: A = matrix(ZZ,2,range(4)) - sage: loads(dumps(A)) # indirect doctest + sage: A = matrix(ZZ, 2, range(4)) + sage: loads(dumps(A)) # indirect doctest [0 1] [2 3] diff --git a/src/sage/matrix/matrix1.pyx b/src/sage/matrix/matrix1.pyx index f38c429d994..3e89649126c 100644 --- a/src/sage/matrix/matrix1.pyx +++ b/src/sage/matrix/matrix1.pyx @@ -5,8 +5,8 @@ For design documentation see :mod:`sage.matrix.docs`. TESTS:: - sage: A = Matrix(GF(5),3,3,srange(9)) - sage: TestSuite(A).run() + sage: A = Matrix(GF(5), 3, 3, srange(9)) # optional - sage.rings.finite_rings + sage: TestSuite(A).run() # optional - sage.rings.finite_rings """ #***************************************************************************** @@ -40,11 +40,11 @@ cdef class Matrix(Matrix0): sage: a = matrix(R,2,[x+1,2/3, x^2/2, 1+x^3]); a [ x + 1 2/3] [1/2*x^2 x^3 + 1] - sage: b = gp(a); b # indirect doctest + sage: b = gp(a); b # indirect doctest # optional - sage.libs.pari [x + 1, 2/3; 1/2*x^2, x^3 + 1] sage: a.determinant() x^4 + x^3 - 1/3*x^2 + x + 1 - sage: b.matdet() + sage: b.matdet() # optional - sage.libs.pari x^4 + x^3 - 1/3*x^2 + x + 1 """ w = self.list() @@ -69,11 +69,11 @@ cdef class Matrix(Matrix0): sage: a = matrix(R,2,[x+1,2/3, x^2/2, 1+x^3]); a [ x + 1 2/3] [1/2*x^2 x^3 + 1] - sage: b = pari(a); b # indirect doctest + sage: b = pari(a); b # indirect doctest # optional - sage.libs.pari [x + 1, 2/3; 1/2*x^2, x^3 + 1] sage: a.determinant() x^4 + x^3 - 1/3*x^2 + x + 1 - sage: b.matdet() + sage: b.matdet() # optional - sage.libs.pari x^4 + x^3 - 1/3*x^2 + x + 1 This function preserves precision for entries of inexact type (e.g. @@ -97,33 +97,33 @@ cdef class Matrix(Matrix0): EXAMPLES:: sage: A = MatrixSpace(QQ,3,3)([0,1,2,3,4,5,6,7,8]) - sage: g = gap(A) # indirect doctest - sage: g + sage: g = gap(A) # indirect doctest # optional - sage.libs.gap + sage: g # optional - sage.libs.gap [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - sage: g.CharacteristicPolynomial() + sage: g.CharacteristicPolynomial() # optional - sage.libs.gap x_1^3-12*x_1^2-18*x_1 - sage: A.characteristic_polynomial() + sage: A.characteristic_polynomial() # optional - sage.libs.gap x^3 - 12*x^2 - 18*x - sage: matrix(QQ, g) == A + sage: matrix(QQ, g) == A # optional - sage.libs.gap True Particularly difficult is the case of matrices over cyclotomic fields and general number fields. See :trac:`5618` and :trac:`8909`:: - sage: K. = CyclotomicField(8) - sage: A = MatrixSpace(K,2,2)([0,1+zeta,2*zeta,3]) - sage: g = gap(A); g + sage: K. = CyclotomicField(8) # optional - sage.rings.number_field + sage: A = MatrixSpace(K, 2, 2)([0, 1+zeta, 2*zeta, 3]) # optional - sage.rings.number_field + sage: g = gap(A); g # optional - sage.rings.number_field [ [ 0, 1+E(8) ], [ 2*E(8), 3 ] ] - sage: matrix(K, g) == A + sage: matrix(K, g) == A # optional - sage.rings.number_field True - sage: g.IsMatrix() + sage: g.IsMatrix() # optional - sage.rings.number_field true - sage: L. = NumberField(x^3-2) - sage: A = MatrixSpace(L,2,2)([0,1+tau,2*tau,3]) - sage: g = gap(A); g + sage: L. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A = MatrixSpace(L, 2, 2)([0, 1+tau, 2*tau, 3]) # optional - sage.rings.number_field + sage: g = gap(A); g # optional - sage.rings.number_field [ [ !0, tau+1 ], [ 2*tau, !3 ] ] - sage: matrix(L, g) == A + sage: matrix(L, g) == A # optional - sage.rings.number_field True """ cdef Py_ssize_t i, j @@ -152,9 +152,9 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: libgap(identity_matrix(ZZ,2)) + sage: libgap(identity_matrix(ZZ, 2)) # optional - sage.libs.gap [ [ 1, 0 ], [ 0, 1 ] ] - sage: libgap(matrix(GF(3),2,2,[4,5,6,7])) + sage: libgap(matrix(GF(3), 2, 2, [4,5,6,7])) # optional - sage.libs.gap sage.rings.finite_rings [ [ Z(3)^0, Z(3) ], [ 0*Z(3), Z(3)^0 ] ] """ from sage.libs.gap.libgap import libgap @@ -191,9 +191,9 @@ cdef class Matrix(Matrix0): :: - sage: y = var('y') - sage: M = matrix(SR, 2, [y+sin(y), y - 4, 1/y, dilog(y)]) - sage: M == fricas(M).sage() # optional - fricas + sage: y = var('y') # optional - sage.symbolic + sage: M = matrix(SR, 2, [y+sin(y), y - 4, 1/y, dilog(y)]) # optional - sage.symbolic + sage: M == fricas(M).sage() # optional - fricas # optional - sage.symbolic True """ s = ','.join('[' + ','.join(cf._fricas_init_() for cf in row) + ']' @@ -211,22 +211,22 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: M = matrix(ZZ,2,range(4)) - sage: giac(M) + sage: M = matrix(ZZ, 2, range(4)) + sage: giac(M) # optional - sage.libs.giac [[0,1],[2,3]] - sage: M = matrix(QQ,3,[1,2,3,4/3,5/3,6/4,7,8,9]) - sage: giac(M) + sage: M = matrix(QQ, 3, [1,2,3, 4/3,5/3,6/4, 7,8,9]) + sage: giac(M) # optional - sage.libs.giac [[1,2,3],[4/3,5/3,3/2],[7,8,9]] sage: P. = ZZ[] sage: M = matrix(P, 2, [-9*x^2-2*x+2, x-1, x^2+8*x, -3*x^2+5]) - sage: giac(M) + sage: giac(M) # optional - sage.libs.giac [[-9*sageVARx^2-2*sageVARx+2,sageVARx-1],[sageVARx^2+8*sageVARx,-3*sageVARx^2+5]] - sage: y = var('y') - sage: M = matrix(SR, 2, [y+sin(y), y - 4, 1/y, dilog(y)]) - sage: giac(M).det().sage() + sage: y = var('y') # optional - sage.symbolic + sage: M = matrix(SR, 2, [y+sin(y), y - 4, 1/y, dilog(y)]) # optional - sage.symbolic + sage: giac(M).det().sage() # optional - sage.libs.giac sage.symbolic (y^2*dilog(y) + y*dilog(y)*sin(y) - y + 4)/y """ s = ','.join('[' + ','.join(cf._giac_init_() for cf in row) + ']' @@ -243,11 +243,11 @@ cdef class Matrix(Matrix0): [0 1 2] [3 4 5] [6 7 8] - sage: m._maxima_init_() + sage: m._maxima_init_() # optional - sage.symbolic 'matrix([0,1,2],[3,4,5],[6,7,8])' - sage: a = maxima(m); a + sage: a = maxima(m); a # optional - sage.symbolic matrix([0,1,2],[3,4,5],[6,7,8]) - sage: a.charpoly('x').expand() + sage: a.charpoly('x').expand() # optional - sage.symbolic (-x^3)+12*x^2+18*x sage: m.charpoly() x^3 - 12*x^2 - 18*x @@ -335,9 +335,9 @@ cdef class Matrix(Matrix0): We coerce a matrix over a cyclotomic field, where the generator must be named during the coercion. :: - sage: K = CyclotomicField(9) ; z = K.0 - sage: M = matrix(K,3,3,[0,1,3,z,z**4,z-1,z**17,1,0]) - sage: M + sage: K = CyclotomicField(9); z = K.0 # optional - sage.rings.number_field + sage: M = matrix(K, 3, 3, [0,1,3,z,z**4,z-1,z**17,1,0]) # optional - sage.rings.number_field + sage: M # optional - sage.rings.number_field [ 0 1 3] [ zeta9 zeta9^4 zeta9 - 1] [-zeta9^5 - zeta9^2 1 0] @@ -388,9 +388,9 @@ cdef class Matrix(Matrix0): sage: maple(M) # optional - maple Matrix(2, 2, [[-9*x^2-2*x+2,x-1],[x^2+8*x,-3*x^2+5]]) - sage: y = var('y') - sage: M = matrix(SR, 2, [y+sin(y), y - 4, 1/y, dilog(y)]) - sage: M == maple(M).sage() # optional - maple + sage: y = var('y') # optional - sage.symbolic + sage: M = matrix(SR, 2, [y+sin(y), y - 4, 1/y, dilog(y)]) # optional - sage.symbolic + sage: M == maple(M).sage() # optional - maple # optional - sage.symbolic True """ s = ','.join('[' + ','.join(cf._maple_init_() for cf in row) + ']' @@ -404,12 +404,12 @@ cdef class Matrix(Matrix0): EXAMPLES:: sage: M = matrix(ZZ,2,range(4)) - sage: polymake(M) # optional - jupymake + sage: polymake(M) # optional - jupymake 0 1 2 3 - sage: K. = QuadraticField(5) - sage: M = matrix(K, [[1, 2], [sqrt5, 3]]) - sage: polymake(M) # optional - jupymake + sage: K. = QuadraticField(5) # optional - sage.rings.number_field + sage: M = matrix(K, [[1, 2], [sqrt5, 3]]) # optional - sage.rings.number_field + sage: polymake(M) # optional - jupymake # optional - sage.rings.number_field 1 2 0+1r5 3 """ @@ -484,7 +484,7 @@ cdef class Matrix(Matrix0): [1 2 3] [4 5 6] [7 8 9] - sage: a._scilab_init_() + sage: a._scilab_init_() # optional - sage.libs.pari '[1,2,3;4,5,6;7,8,9]' AUTHORS: @@ -539,49 +539,49 @@ cdef class Matrix(Matrix0): [1 2 3] [4 5 6] [7 8 9] - sage: sA = A._sympy_(); sA + sage: sA = A._sympy_(); sA # optional - sympy Matrix([ [1, 2, 3], [4, 5, 6], [7, 8, 9]]) - sage: type(sA) + sage: type(sA) # optional - sympy sage: I = MatrixSpace(QQ, 5, 5, sparse=True).identity_matrix() - sage: sI = I._sympy_(); sI + sage: sI = I._sympy_(); sI # optional - sympy Matrix([ [1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) - sage: type(sI) + sage: type(sI) # optional - sympy If ``self`` was immutable, then converting the result to Sage gives back ``self``:: sage: immA = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]], immutable=True) - sage: immA._sympy_()._sage_() is immA + sage: immA._sympy_()._sage_() is immA # optional - sympy True If ``self`` was mutable, then converting back to Sage creates a new matrix:: - sage: sA._sage_() is A + sage: sA._sage_() is A # optional - sympy False - sage: sA._sage_() == A + sage: sA._sage_() == A # optional - sympy True Symbolic matrices are supported:: - sage: M = matrix([[sin(x), cos(x)], [-cos(x), sin(x)]]); M + sage: M = matrix([[sin(x), cos(x)], [-cos(x), sin(x)]]); M # optional - sage.symbolic [ sin(x) cos(x)] [-cos(x) sin(x)] - sage: sM = M._sympy_(); sM + sage: sM = M._sympy_(); sM # optional - sage.symbolic sympy Matrix([ [ sin(x), cos(x)], [-cos(x), sin(x)]]) - sage: sM.subs(x, pi/4) + sage: sM.subs(x, pi/4) # optional - sage.symbolic sympy Matrix([ [ sqrt(2)/2, sqrt(2)/2], [-sqrt(2)/2, sqrt(2)/2]]) @@ -592,12 +592,12 @@ cdef class Matrix(Matrix0): sage: ZeroCol = matrix(QQ, 3, 0, sparse=False); ZeroCol [] - sage: sZeroCol = ZeroCol._sympy_(); sZeroCol + sage: sZeroCol = ZeroCol._sympy_(); sZeroCol # optional - sympy Matrix(3, 0, []) sage: ZeroRow = matrix(QQ, 0, 2, sparse=False); ZeroRow [] - sage: sZeroRow = ZeroRow._sympy_(); sZeroRow + sage: sZeroRow = ZeroRow._sympy_(); sZeroRow # optional - sympy Matrix(0, 2, []) """ @@ -625,9 +625,9 @@ cdef class Matrix(Matrix0): sage: sage_input(matrix(QQ, 3, 3, [5..13])/7, verify=True) # Verified matrix(QQ, [[5/7, 6/7, 1], [8/7, 9/7, 10/7], [11/7, 12/7, 13/7]]) - sage: M = MatrixSpace(GF(5), 50, 50, sparse=True).random_element(density=0.002) - sage: input = sage_input(M, verify=True) - sage: sage_eval(input) == M + sage: M = MatrixSpace(GF(5), 50, 50, sparse=True).random_element(density=0.002) # optional - sage.rings.finite_rings + sage: input = sage_input(M, verify=True) # optional - sage.rings.finite_rings + sage: sage_eval(input) == M # optional - sage.rings.finite_rings True sage: from sage.misc.sage_input import SageInputBuilder sage: matrix(RDF, [[3, 1], [4, 1]])._sage_input_(SageInputBuilder(), False) @@ -677,20 +677,20 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: a = matrix(3,range(12)) - sage: a.numpy() + sage: a = matrix(3, range(12)) + sage: a.numpy() # optional - numpy array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) - sage: a.numpy('f') + sage: a.numpy('f') # optional - numpy array([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.]], dtype=float32) - sage: a.numpy('d') + sage: a.numpy('d') # optional - numpy array([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.]]) - sage: a.numpy('B') + sage: a.numpy('B') # optional - numpy array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], dtype=uint8) @@ -698,23 +698,26 @@ cdef class Matrix(Matrix0): Type ``numpy.typecodes`` for a list of the possible typecodes:: - sage: import numpy - sage: sorted(numpy.typecodes.items()) - [('All', '?bhilqpBHILQPefdgFDGSUVOMm'), ('AllFloat', 'efdgFDG'), ('AllInteger', 'bBhHiIlLqQpP'), ('Character', 'c'), ('Complex', 'FDG'), ('Datetime', 'Mm'), ('Float', 'efdg'), ('Integer', 'bhilqp'), ('UnsignedInteger', 'BHILQP')] + sage: import numpy # optional - numpy + sage: sorted(numpy.typecodes.items()) # optional - numpy + [('All', '?bhilqpBHILQPefdgFDGSUVOMm'), ('AllFloat', 'efdgFDG'), + ('AllInteger', 'bBhHiIlLqQpP'), ('Character', 'c'), ('Complex', 'FDG'), + ('Datetime', 'Mm'), ('Float', 'efdg'), ('Integer', 'bhilqp'), + ('UnsignedInteger', 'BHILQP')] Alternatively, numpy automatically calls this function (via the magic :meth:`__array__` method) to convert Sage matrices to numpy arrays:: - sage: import numpy - sage: b=numpy.array(a); b + sage: import numpy # optional - numpy + sage: b = numpy.array(a); b # optional - numpy array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) - sage: b.dtype + sage: b.dtype # optional - numpy dtype('int32') # 32-bit dtype('int64') # 64-bit - sage: b.shape + sage: b.shape # optional - numpy (3, 4) """ import numpy @@ -972,14 +975,14 @@ cdef class Matrix(Matrix0): sage: matrix(3, [1..9]).columns() [(1, 4, 7), (2, 5, 8), (3, 6, 9)] - sage: matrix(RR, 2, [sqrt(2), pi, exp(1), 0]).columns() + sage: matrix(RR, 2, [sqrt(2), pi, exp(1), 0]).columns() # optional - sage.symbolic [(1.41421356237310, 2.71828182845905), (3.14159265358979, 0.000000000000000)] sage: matrix(RR, 0, 2, []).columns() [(), ()] sage: matrix(RR, 2, 0, []).columns() [] - sage: m = matrix(RR, 3, 3, {(1,2): pi, (2, 2): -1, (0,1): sqrt(2)}) - sage: parent(m.columns()[0]) + sage: m = matrix(RR, 3, 3, {(1,2): pi, (2, 2): -1, (0,1): sqrt(2)}) # optional - sage.symbolic + sage: parent(m.columns()[0]) # optional - sage.symbolic Sparse vector space of dimension 3 over Real Field with 53 bits of precision Sparse matrices produce sparse columns. :: @@ -1034,8 +1037,8 @@ cdef class Matrix(Matrix0): [] sage: matrix(RR, 2, 0, []).rows() [(), ()] - sage: m = matrix(RR, 3, 3, {(1,2): pi, (2, 2): -1, (0,1): sqrt(2)}) - sage: parent(m.rows()[0]) + sage: m = matrix(RR, 3, 3, {(1,2): pi, (2, 2): -1, (0,1): sqrt(2)}) # optional - sage.symbolic + sage: parent(m.rows()[0]) # optional - sage.symbolic Sparse vector space of dimension 3 over Real Field with 53 bits of precision Sparse matrices produce sparse rows. :: @@ -1081,7 +1084,7 @@ cdef class Matrix(Matrix0): An example over the integers:: - sage: a = matrix(3,3,range(9)); a + sage: a = matrix(3, 3, range(9)); a [0 1 2] [3 4 5] [6 7 8] @@ -1090,7 +1093,7 @@ cdef class Matrix(Matrix0): We do an example over a polynomial ring:: - sage: R. = QQ[ ] + sage: R. = QQ[] sage: a = matrix(R, 2, [x,x^2, 2/3*x,1+x^5]); a [ x x^2] [ 2/3*x x^5 + 1] @@ -1100,13 +1103,14 @@ cdef class Matrix(Matrix0): sage: c = a.dense_columns(); c [(x, 2/3*x), (x^2, x^5 + 1)] sage: parent(c[1]) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + Ambient free module of rank 2 over the principal ideal domain + Univariate Polynomial Ring in x over Rational Field TESTS: Check that the returned rows are immutable as per :trac:`14874`:: - sage: m = Mat(ZZ,3,3)(range(9)) + sage: m = Mat(ZZ, 3, 3)(range(9)) sage: v = m.dense_columns() sage: [x.is_mutable() for x in v] [False, False, False] @@ -1160,7 +1164,7 @@ cdef class Matrix(Matrix0): Check that the returned rows are immutable as per :trac:`14874`:: - sage: m = Mat(ZZ,3,3)(range(9)) + sage: m = Mat(ZZ, 3, 3)(range(9)) sage: v = m.dense_rows() sage: [x.is_mutable() for x in v] [False, False, False] @@ -1196,7 +1200,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: a = matrix(2,3,range(6)); a + sage: a = matrix(2, 3, range(6)); a [0 1 2] [3 4 5] sage: v = a.sparse_columns(); v @@ -1216,7 +1220,7 @@ cdef class Matrix(Matrix0): Check that the returned columns are immutable as per :trac:`14874`:: - sage: m = Mat(ZZ,3,3,sparse=True)(range(9)) + sage: m = Mat(ZZ, 3, 3, sparse=True)(range(9)) sage: v = m.sparse_columns() sage: [x.is_mutable() for x in v] [False, False, False] @@ -1272,7 +1276,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: m = Mat(ZZ,3,3,sparse=True)(range(9)); m + sage: m = Mat(ZZ, 3, 3, sparse=True)(range(9)); m [0 1 2] [3 4 5] [6 7 8] @@ -1298,7 +1302,7 @@ cdef class Matrix(Matrix0): Check that the returned rows are immutable as per :trac:`14874`:: - sage: m = Mat(ZZ,3,3,sparse=True)(range(9)) + sage: m = Mat(ZZ, 3, 3, sparse=True)(range(9)) sage: v = m.sparse_rows() sage: [x.is_mutable() for x in v] [False, False, False] @@ -1363,7 +1367,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: a = matrix(2,3,range(6)); a + sage: a = matrix(2, 3, range(6)); a [0 1 2] [3 4 5] sage: a.column(1) @@ -1377,7 +1381,7 @@ cdef class Matrix(Matrix0): TESTS:: - sage: a = matrix(2,3,range(6)); a + sage: a = matrix(2, 3, range(6)); a [0 1 2] [3 4 5] sage: a.column(3) @@ -1422,7 +1426,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: a = matrix(2,3,range(6)); a + sage: a = matrix(2, 3, range(6)); a [0 1 2] [3 4 5] sage: a.row(0) @@ -1434,7 +1438,7 @@ cdef class Matrix(Matrix0): TESTS:: - sage: a = matrix(2,3,range(6)); a + sage: a = matrix(2, 3, range(6)); a [0 1 2] [3 4 5] sage: a.row(2) @@ -1614,13 +1618,15 @@ cdef class Matrix(Matrix0): [ 1.00000000000000 2.00000000000000] [0.891207360061435 0.808496403819590] sage: C.parent() - Full MatrixSpace of 2 by 2 dense matrices over Real Field with 53 bits of precision + Full MatrixSpace of 2 by 2 dense matrices + over Real Field with 53 bits of precision sage: D = B.stack(A); D [0.891207360061435 0.808496403819590] [ 1.00000000000000 2.00000000000000] sage: D.parent() - Full MatrixSpace of 2 by 2 dense matrices over Real Field with 53 bits of precision + Full MatrixSpace of 2 by 2 dense matrices + over Real Field with 53 bits of precision :: @@ -1632,7 +1638,8 @@ cdef class Matrix(Matrix0): [ 1 2/3] [ y y^2] sage: C.parent() - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field + Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in y over Rational Field Stacking a dense matrix atop a sparse one returns a sparse matrix:: @@ -1888,7 +1895,8 @@ cdef class Matrix(Matrix0): [0.89120736006... 1.00000000000000] [0.80849640381... 2.00000000000000] sage: D.parent() - Full MatrixSpace of 2 by 2 dense matrices over Real Field with 53 bits of precision + Full MatrixSpace of 2 by 2 dense matrices + over Real Field with 53 bits of precision Sometimes it is not possible to coerce into the base ring of ``self``. A solution is to change the base ring of ``self`` to @@ -1902,7 +1910,8 @@ cdef class Matrix(Matrix0): sage: C = B.augment(A); C [ y y^2 1 2] sage: C.parent() - Full MatrixSpace of 1 by 4 dense matrices over Univariate Polynomial Ring in y over Rational Field + Full MatrixSpace of 1 by 4 dense matrices + over Univariate Polynomial Ring in y over Rational Field sage: D = A.augment(B) Traceback (most recent call last): @@ -1913,7 +1922,8 @@ cdef class Matrix(Matrix0): sage: F = E.augment(B); F [ 1 2 y y^2] sage: F.parent() - Full MatrixSpace of 1 by 4 dense matrices over Univariate Polynomial Ring in y over Rational Field + Full MatrixSpace of 1 by 4 dense matrices + over Univariate Polynomial Ring in y over Rational Field AUTHORS: @@ -1963,7 +1973,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: M = MatrixSpace(Integers(8),3,3) + sage: M = MatrixSpace(Integers(8), 3, 3) sage: A = M(range(9)); A [0 1 2] [3 4 5] @@ -2002,7 +2012,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: A = Matrix(3,4,range(12)); A + sage: A = Matrix(3, 4, range(12)); A [ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11] @@ -2061,7 +2071,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: M = MatrixSpace(Integers(8),3,3) + sage: M = MatrixSpace(Integers(8), 3, 3) sage: A = M(range(9)); A [0 1 2] [3 4 5] @@ -2099,7 +2109,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: A = Matrix(4,3,range(12)); A + sage: A = Matrix(4, 3, range(12)); A [ 0 1 2] [ 3 4 5] [ 6 7 8] @@ -2157,7 +2167,7 @@ cdef class Matrix(Matrix0): EXAMPLES:: - sage: M = MatrixSpace(Integers(8),3,3) + sage: M = MatrixSpace(Integers(8), 3, 3) sage: A = M(range(9)); A [0 1 2] [3 4 5] @@ -2179,7 +2189,7 @@ cdef class Matrix(Matrix0): :: - sage: A.matrix_from_rows_and_columns([1,1,1],[2,0,0]) + sage: A.matrix_from_rows_and_columns([1,1,1], [2,0,0]) [5 3 3] [5 3 3] [5 3 3] @@ -2399,7 +2409,8 @@ cdef class Matrix(Matrix0): sage: A.set_column(0, [1/4, 1]); A Traceback (most recent call last): ... - TypeError: Cannot set column with Rational Field elements over Integer Ring, use change_ring first. + TypeError: Cannot set column with Rational Field elements + over Integer Ring, use change_ring first. """ if len(v) != self._nrows: msg = "list of new entries must be of length {0} (not {1})" @@ -2449,7 +2460,7 @@ cdef class Matrix(Matrix0): Specify a different base ring for the output:: - sage: M.zero_pattern_matrix(GF(2)).base_ring() + sage: M.zero_pattern_matrix(GF(2)).base_ring() # optional - sage.rings.finite_rings Finite Field of size 2 Examples for different base rings for ``self``:: @@ -2465,36 +2476,36 @@ cdef class Matrix(Matrix0): :: - sage: W. = CyclotomicField(100) - sage: M = Matrix(2, 3, [a, a/2, 0, a^2, a^100-1, a^2 - a]); M + sage: W. = CyclotomicField(100) # optional - sage.rings.number_field + sage: M = Matrix(2, 3, [a, a/2, 0, a^2, a^100-1, a^2 - a]); M # optional - sage.rings.number_field [ a 1/2*a 0] [ a^2 0 a^2 - a] - sage: M.zero_pattern_matrix() + sage: M.zero_pattern_matrix() # optional - sage.rings.number_field [0 0 1] [0 1 0] :: - sage: K. = GF(2^4) - sage: l = [a^2 + 1, a^3 + 1, 0, 0, a, a^3 + a + 1, a + 1, + sage: K. = GF(2^4) # optional - sage.rings.finite_rings + sage: l = [a^2 + 1, a^3 + 1, 0, 0, a, a^3 + a + 1, a + 1, # optional - sage.rings.finite_rings ....: a + 1, a^2, a^3 + a + 1, a^3 + a, a^3 + a] - sage: M = Matrix(K, 3, 4, l); M + sage: M = Matrix(K, 3, 4, l); M # optional - sage.rings.finite_rings [ a^2 + 1 a^3 + 1 0 0] [ a a^3 + a + 1 a + 1 a + 1] [ a^2 a^3 + a + 1 a^3 + a a^3 + a] - sage: M.zero_pattern_matrix() + sage: M.zero_pattern_matrix() # optional - sage.rings.finite_rings [0 0 1 1] [0 0 0 0] [0 0 0 0] :: - sage: K. = GF(25) - sage: M = Matrix(K, 2, 3, [0, 2, 3, 5, a, a^2]) - sage: M + sage: K. = GF(25) # optional - sage.rings.finite_rings + sage: M = Matrix(K, 2, 3, [0, 2, 3, 5, a, a^2]) # optional - sage.rings.finite_rings + sage: M # optional - sage.rings.finite_rings [ 0 2 3] [ 0 a a + 3] - sage: M.zero_pattern_matrix() + sage: M.zero_pattern_matrix() # optional - sage.rings.finite_rings [1 0 0] [1 0 0] @@ -2581,7 +2592,7 @@ cdef class Matrix(Matrix0): dict items are ETuples (see :trac:`17658`):: sage: from sage.rings.polynomial.polydict import ETuple - sage: matrix(GF(5^2,"z"),{ETuple((1, 1)): 2}).dense_matrix() + sage: matrix(GF(5^2, "z"), {ETuple((1, 1)): 2}).dense_matrix() # optional - sage.rings.finite_rings [0 0] [0 2] """ @@ -2665,9 +2676,11 @@ cdef class Matrix(Matrix0): sage: M = MatrixSpace(QQ, 3, implementation='generic') sage: m = M.an_element() sage: m.matrix_space() - Full MatrixSpace of 3 by 3 dense matrices over Rational Field (using Matrix_generic_dense) + Full MatrixSpace of 3 by 3 dense matrices over Rational Field + (using Matrix_generic_dense) sage: m.matrix_space(nrows=2, ncols=12) - Full MatrixSpace of 2 by 12 dense matrices over Rational Field (using Matrix_generic_dense) + Full MatrixSpace of 2 by 12 dense matrices over Rational Field + (using Matrix_generic_dense) sage: m.matrix_space(nrows=2, sparse=True) Full MatrixSpace of 2 by 3 sparse matrices over Rational Field """ @@ -2739,16 +2752,19 @@ cdef class Matrix(Matrix0): [0.000000000000000 0.000000000000000 0.000000000000000] [0.000000000000000 0.000000000000000 0.000000000000000] sage: A.new_matrix().parent() - Full MatrixSpace of 2 by 3 dense matrices over Real Field with 53 bits of precision + Full MatrixSpace of 2 by 3 dense matrices + over Real Field with 53 bits of precision :: sage: M = MatrixSpace(ZZ, 2, 3, implementation='generic') sage: m = M.an_element() sage: m.new_matrix().parent() - Full MatrixSpace of 2 by 3 dense matrices over Integer Ring (using Matrix_generic_dense) + Full MatrixSpace of 2 by 3 dense matrices over Integer Ring + (using Matrix_generic_dense) sage: m.new_matrix(3,3).parent() - Full MatrixSpace of 3 by 3 dense matrices over Integer Ring (using Matrix_generic_dense) + Full MatrixSpace of 3 by 3 dense matrices over Integer Ring + (using Matrix_generic_dense) sage: m.new_matrix(3,3, sparse=True).parent() Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring """ diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index e2e6449dfa9..26f1fe4a6fa 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -168,16 +168,16 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: var('a,b,d,e') + sage: var('a,b,d,e') # optional - sage.symbolic (a, b, d, e) - sage: m = matrix([[a,b], [d,e]]) - sage: m.substitute(a=1) + sage: m = matrix([[a,b], [d,e]]) # optional - sage.symbolic + sage: m.substitute(a=1) # optional - sage.symbolic [1 b] [d e] - sage: m.subs(a=b, b=d) + sage: m.subs(a=b, b=d) # optional - sage.symbolic [b d] [d e] - sage: m.subs({a: 3, b:2, d:1, e:-1}) + sage: m.subs({a: 3, b: 2, d: 1, e: -1}) # optional - sage.symbolic [ 3 2] [ 1 -1] @@ -196,7 +196,7 @@ cdef class Matrix(Matrix1): However, sparse matrices remain sparse:: - sage: m = matrix({(3,2): -x, (59,38): x^2+2}, nrows=1000, ncols=1000) + sage: m = matrix({(3,2): -x, (59,38): x^2 + 2}, nrows=1000, ncols=1000) sage: m1 = m.subs(x=1) sage: m1.is_sparse() True @@ -267,8 +267,8 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,4,2, [0, -1, 1, 0, -2, 2, 1, 0]) - sage: B = matrix(QQ,2,2, [1, 0, 1, -1]) + sage: A = matrix(QQ, 4,2, [0, -1, 1, 0, -2, 2, 1, 0]) + sage: B = matrix(QQ, 2,2, [1, 0, 1, -1]) sage: X = A.solve_left(B) sage: X*A == B True @@ -307,7 +307,8 @@ cdef class Matrix(Matrix1): ....: [ 3*I, -1 - I, -1 + I, -3 + I]]) sage: b = vector(CDF, [2 -3*I, 3, -2 + 3*I, 8]) sage: x = A.solve_left(b); x - (-1.55765124... - 0.644483985...*I, 0.183274021... + 0.286476868...*I, 0.270818505... + 0.246619217...*I, -1.69003558... - 0.828113879...*I) + (-1.55765124... - 0.644483985...*I, 0.183274021... + 0.286476868...*I, + 0.270818505... + 0.246619217...*I, -1.69003558... - 0.828113879...*I) sage: x.parent() Vector space of dimension 4 over Complex Double Field sage: abs(x*A - b) < 1e-14 @@ -317,7 +318,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 3, 3, [2, 5, 0, 7, 7, -2, -4.3, 0, 1]) sage: b = matrix(RDF, 2, 3, [2, -4, -5, 1, 1, 0.1]) - sage: A.solve_left(b) # tol 1e-14 + sage: A.solve_left(b) # tol 1e-14 [ -6.495454545454545 4.068181818181818 3.1363636363636354] [ 0.5277272727272727 -0.2340909090909091 -0.36818181818181817] @@ -341,8 +342,8 @@ cdef class Matrix(Matrix1): TESTS:: - sage: A = matrix(QQ,4,2, [0, -1, 1, 0, -2, 2, 1, 0]) - sage: B = vector(QQ,2, [2,1]) + sage: A = matrix(QQ, 4,2, [0, -1, 1, 0, -2, 2, 1, 0]) + sage: B = vector(QQ, 2, [2,1]) sage: X = A.solve_left(B) sage: X*A == B True @@ -392,9 +393,9 @@ cdef class Matrix(Matrix1): The vector of constants needs to be compatible with the base ring of the coefficient matrix:: - sage: F. = FiniteField(27) - sage: b = vector(F, [a,a,a,a,a]) - sage: A.solve_left(b) + sage: F. = FiniteField(27) # optional - sage.rings.finite_rings + sage: b = vector(F, [a,a,a,a,a]) # optional - sage.rings.finite_rings + sage: A.solve_left(b) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: ... @@ -413,9 +414,9 @@ cdef class Matrix(Matrix1): any are inexact, however, the ``check`` is still skipped (:trac:`29729` and :trac:`33159`):: - sage: A = matrix(SR, [[1, 1]]) # optional - sage.symbolic - sage: b = vector(SR, [2, 3]) # optional - sage.symbolic - sage: A.solve_left(b) # optional - sage.symbolic + sage: A = matrix(SR, [[1, 1]]) # optional - sage.symbolic + sage: b = vector(SR, [2, 3]) # optional - sage.symbolic + sage: A.solve_left(b) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: matrix equation has no solutions @@ -423,7 +424,7 @@ cdef class Matrix(Matrix1): In this case, turning off the ``check`` leads to a wrong result:: - sage: A.solve_left(b, check=False) # optional - sage.symbolic + sage: A.solve_left(b, check=False) # optional - sage.symbolic (2) """ @@ -497,7 +498,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: sage: A = matrix(QQ, 3, [1,2,3,-1,2,5,2,3,1]) - sage: b = vector(QQ,[1,2,3]) + sage: b = vector(QQ, [1,2,3]) sage: x = A \ b; x (-13/12, 23/12, -7/12) sage: A * x @@ -505,7 +506,8 @@ cdef class Matrix(Matrix1): We solve with A nonsquare:: - sage: A = matrix(QQ,2,4, [0, -1, 1, 0, -2, 2, 1, 0]); B = matrix(QQ,2,2, [1, 0, 1, -1]) + sage: A = matrix(QQ, 2,4, [0, -1, 1, 0, -2, 2, 1, 0]) + sage: B = matrix(QQ, 2,2, [1, 0, 1, -1]) sage: X = A.solve_right(B); X [-3/2 1/2] [ -1 0] @@ -516,7 +518,7 @@ cdef class Matrix(Matrix1): Another nonsingular example:: - sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); v = vector([-1/2,-1]) + sage: A = matrix(QQ, 2,3, [1,2,3,2,4,6]); v = vector([-1/2,-1]) sage: x = A \ v; x (-1/2, 0, 0) sage: A*x == v @@ -524,13 +526,13 @@ cdef class Matrix(Matrix1): Same example but over `\ZZ`:: - sage: A = matrix(ZZ,2,3, [1,2,3,2,4,6]); v = vector([-1,-2]) + sage: A = matrix(ZZ, 2,3, [1,2,3,2,4,6]); v = vector([-1,-2]) sage: A \ v (-1, 0, 0) An example in which there is no solution:: - sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); v = vector([1,1]) + sage: A = matrix(QQ, 2,3, [1,2,3,2,4,6]); v = vector([1,1]) sage: A \ v Traceback (most recent call last): ... @@ -538,8 +540,8 @@ cdef class Matrix(Matrix1): A ValueError is raised if the input is invalid:: - sage: A = matrix(QQ,4,2, [0, -1, 1, 0, -2, 2, 1, 0]) - sage: B = matrix(QQ,2,2, [1, 0, 1, -1]) + sage: A = matrix(QQ, 4,2, [0, -1, 1, 0, -2, 2, 1, 0]) + sage: B = matrix(QQ, 2,2, [1, 0, 1, -1]) sage: X = A.solve_right(B) Traceback (most recent call last): ... @@ -548,7 +550,7 @@ cdef class Matrix(Matrix1): We solve with A singular:: - sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); B = matrix(QQ,2,2, [6, -6, 12, -12]) + sage: A = matrix(QQ, 2,3, [1,2,3,2,4,6]); B = matrix(QQ, 2,2, [6, -6, 12, -12]) sage: X = A.solve_right(B); X [ 6 -6] [ 0 0] @@ -583,11 +585,12 @@ cdef class Matrix(Matrix1): Solving over a polynomial ring:: sage: x = polygen(QQ, 'x') - sage: A = matrix(2, [x,2*x,-5*x^2+1,3]) - sage: v = vector([3,4*x - 2]) + sage: A = matrix(2, [x, 2*x, -5*x^2 + 1, 3]) + sage: v = vector([3, 4*x - 2]) sage: X = A \ v sage: X - ((-4/5*x^2 + 2/5*x + 9/10)/(x^3 + 1/10*x), (19/10*x^2 - 1/5*x - 3/10)/(x^3 + 1/10*x)) + ((-4/5*x^2 + 2/5*x + 9/10)/(x^3 + 1/10*x), + (19/10*x^2 - 1/5*x - 3/10)/(x^3 + 1/10*x)) sage: A * X == v True @@ -595,58 +598,58 @@ cdef class Matrix(Matrix1): sage: A = Matrix(Zmod(6), 3, 2, [1,2,3,4,5,6]) sage: B = vector(Zmod(6), [1,1,1]) - sage: A.solve_right(B) + sage: A.solve_right(B) # optional - sage.libs.pari (5, 1) sage: B = vector(Zmod(6), [5,1,1]) - sage: A.solve_right(B) + sage: A.solve_right(B) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: matrix equation has no solutions sage: A = Matrix(Zmod(128), 2, 3, [23,11,22,4,1,0]) sage: B = Matrix(Zmod(128), 2, 1, [1,0]) - sage: A.solve_right(B) + sage: A.solve_right(B) # optional - sage.libs.pari [ 5] [108] [127] sage: B = B.column(0) - sage: A.solve_right(B) + sage: A.solve_right(B) # optional - sage.libs.pari (5, 108, 127) sage: A = Matrix(Zmod(15), 3,4, range(12)) sage: B = Matrix(Zmod(15), 3,3, range(3,12)) - sage: X = A.solve_right(B) - sage: A*X == B + sage: X = A.solve_right(B) # optional - sage.libs.pari + sage: A*X == B # optional - sage.libs.pari True Solving a system over the p-adics:: - sage: k = Qp(5,4) - sage: a = matrix(k, 3, [1,7,3,2,5,4,1,1,2]); a + sage: k = Qp(5, 4) # optional - sage.rings.padics + sage: a = matrix(k, 3, [1,7,3, 2,5,4, 1,1,2]); a # optional - sage.rings.padics [ 1 + O(5^4) 2 + 5 + O(5^4) 3 + O(5^4)] [ 2 + O(5^4) 5 + O(5^5) 4 + O(5^4)] [ 1 + O(5^4) 1 + O(5^4) 2 + O(5^4)] - sage: v = vector(k, 3, [1,2,3]) - sage: x = a \ v; x + sage: v = vector(k, 3, [1,2,3]) # optional - sage.rings.padics + sage: x = a \ v; x # optional - sage.rings.padics (4 + 5 + 5^2 + 3*5^3 + O(5^4), 2 + 5 + 3*5^2 + 5^3 + O(5^4), 1 + 5 + O(5^4)) - sage: a * x == v + sage: a * x == v # optional - sage.rings.padics True Solving a system of linear equations symbolically using symbolic matrices:: - sage: var('a,b,c,d,x,y') # optional - sage.symbolic + sage: var('a,b,c,d,x,y') # optional - sage.symbolic (a, b, c, d, x, y) - sage: A = matrix(SR, 2, [a,b,c,d]); A # optional - sage.symbolic + sage: A = matrix(SR, 2, [a,b,c,d]); A # optional - sage.symbolic [a b] [c d] - sage: result = vector(SR, [3,5]); result # optional - sage.symbolic + sage: result = vector(SR, [3,5]); result # optional - sage.symbolic (3, 5) - sage: soln = A.solve_right(result); soln # optional - sage.symbolic + sage: soln = A.solve_right(result); soln # optional - sage.symbolic (-b*(3*c/a - 5)/(a*(b*c/a - d)) + 3/a, (3*c/a - 5)/(b*c/a - d)) - sage: (a*x+b*y).subs(x=soln[0], y=soln[1]).simplify_full() # optional - sage.symbolic + sage: (a*x + b*y).subs(x=soln[0], y=soln[1]).simplify_full() # optional - sage.symbolic 3 - sage: (c*x+d*y).subs(x=soln[0], y=soln[1]).simplify_full() # optional - sage.symbolic + sage: (c*x + d*y).subs(x=soln[0], y=soln[1]).simplify_full() # optional - sage.symbolic 5 - sage: (A*soln).apply_map(lambda x: x.simplify_full()) # optional - sage.symbolic + sage: (A*soln).apply_map(lambda x: x.simplify_full()) # optional - sage.symbolic (3, 5) Over inexact rings, the output of this function may not be an exact @@ -666,7 +669,7 @@ cdef class Matrix(Matrix1): [ 1.0 2.0 5.0] [ 7.6 2.3 1.0] [ 1.0 2.0 -1.0] - sage: b = vector(RDF,[1,2,3]) + sage: b = vector(RDF, [1,2,3]) sage: x = A.solve_right(b); x # tol 1e-14 (-0.1136950904392765, 1.3901808785529717, -0.33333333333333337) sage: x.parent() @@ -680,9 +683,10 @@ cdef class Matrix(Matrix1): ....: [2 + 4*I, -2 + 3*I, -1 + 2*I, -1 - I], ....: [ 2 + I, 1 - I, -1, 5], ....: [ 3*I, -1 - I, -1 + I, -3 + I]]) - sage: b = vector(CDF, [2 -3*I, 3, -2 + 3*I, 8]) + sage: b = vector(CDF, [2 - 3*I, 3, -2 + 3*I, 8]) sage: x = A.solve_right(b); x - (1.96841637... - 1.07606761...*I, -0.614323843... + 1.68416370...*I, 0.0733985765... + 1.73487544...*I, -1.6018683... + 0.524021352...*I) + (1.96841637... - 1.07606761...*I, -0.614323843... + 1.68416370...*I, + 0.0733985765... + 1.73487544...*I, -1.6018683... + 0.524021352...*I) sage: x.parent() Vector space of dimension 4 over Complex Double Field sage: abs(A*x - b) < 1e-14 @@ -692,7 +696,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 3, 3, [1, 2, 2, 3, 4, 5, 2, 2, 2]) sage: b = matrix(RDF, 3, 2, [3, 2, 3, 2, 3, 2]) - sage: A.solve_right(b) # tol 1e-14 + sage: A.solve_right(b) # tol 1e-14 [ 0.0 0.0] [ 4.5 3.0] [-3.0 -2.0] @@ -737,7 +741,7 @@ cdef class Matrix(Matrix1): sage: A = Matrix(Zmod(6), 3, 2, [1,2,3,4,5,6]) sage: b = vector(ZZ, [1,1,1]) - sage: A.solve_right(b).base_ring() is Zmod(6) + sage: A.solve_right(b).base_ring() is Zmod(6) # optional - sage.libs.pari True Check that the coercion mechanism gives consistent results @@ -778,9 +782,9 @@ cdef class Matrix(Matrix1): The vector of constants needs to be compatible with the base ring of the coefficient matrix. :: - sage: F. = FiniteField(27) - sage: b = vector(F, [a,a,a,a,a]) - sage: A.solve_right(b) + sage: F. = FiniteField(27) # optional - sage.rings.finite_rings + sage: b = vector(F, [a,a,a,a,a]) # optional - sage.rings.finite_rings + sage: A.solve_right(b) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: ... @@ -816,31 +820,31 @@ cdef class Matrix(Matrix1): any are inexact, however, the ``check`` is still skipped (:trac:`29729` and :trac:`33159`):: - sage: m = matrix(SR, [0]) # optional - sage.symbolic - sage: b = vector(SR, [1]) # optional - sage.symbolic - sage: m.solve_right(b, check=True) # optional - sage.symbolic + sage: m = matrix(SR, [0]) # optional - sage.symbolic + sage: b = vector(SR, [1]) # optional - sage.symbolic + sage: m.solve_right(b, check=True) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: matrix equation has no solutions In this case, turning off the ``check`` leads to a wrong result:: - sage: m.solve_right(b, check=False) # optional - sage.symbolic + sage: m.solve_right(b, check=False) # optional - sage.symbolic (0) In the following, we have an inexact entry in the matrix, so the ``check`` is still skipped leading to a wrong result:: - sage: m = matrix(SR, [0.0]) # optional - sage.symbolic - sage: m.solve_right(b, check=True) # optional - sage.symbolic + sage: m = matrix(SR, [0.0]) # optional - sage.symbolic + sage: m.solve_right(b, check=True) # optional - sage.symbolic (0) :: - sage: SC = SR.subring(no_variables=True) # optional - sage.symbolic - sage: m = matrix(SC, [0]) # optional - sage.symbolic - sage: b = vector(SC, [1]) # optional - sage.symbolic - sage: m.solve_right(b) # optional - sage.symbolic + sage: SC = SR.subring(no_variables=True) # optional - sage.symbolic + sage: m = matrix(SC, [0]) # optional - sage.symbolic + sage: b = vector(SC, [1]) # optional - sage.symbolic + sage: m.solve_right(b) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: matrix equation has no solutions @@ -943,8 +947,8 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,3,[1,2,4,5,3,1,1,2,-1]) - sage: B = matrix(QQ,3,2,[1,5,1,2,1,5]) + sage: A = matrix(QQ, 3, [1,2,4,5,3,1,1,2,-1]) + sage: B = matrix(QQ, 3,2, [1,5,1,2,1,5]) sage: A._solve_right_nonsingular_square(B) [ -1/7 -11/7] [ 4/7 23/7] @@ -975,7 +979,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,3,3, [0,0,0,1,2,3,2,4,6]); A + sage: A = matrix(QQ, 3,3, [0,0,0,1,2,3,2,4,6]); A [0 0 0] [1 2 3] [2 4 6] @@ -1011,7 +1015,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); B = matrix(QQ,2,2, [6, -6, 12, -12]) + sage: A = matrix(QQ, 2,3, [1,2,3,2,4,6]); B = matrix(QQ, 2,2, [6, -6, 12, -12]) sage: A._solve_right_general(B) [ 6 -6] [ 0 0] @@ -1120,6 +1124,7 @@ cdef class Matrix(Matrix1): Notice the base ring of the results in the next two examples. :: + sage: x = polygen(ZZ, 'x') sage: D = matrix(ZZ['x'],2,[1+x^2,2,3,4-x]) sage: E = matrix(QQ,2,[1,2,3,4]) sage: F = D.elementwise_product(E) @@ -1127,63 +1132,72 @@ cdef class Matrix(Matrix1): [ x^2 + 1 4] [ 9 -4*x + 16] sage: F.parent() - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field + Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Rational Field :: - sage: G = matrix(GF(3),2,[0,1,2,2]) - sage: H = matrix(ZZ,2,[1,2,3,4]) - sage: J = G.elementwise_product(H) - sage: J + sage: G = matrix(GF(3), 2, [0, 1, 2, 2]) # optional - sage.rings.finite_rings + sage: H = matrix(ZZ, 2, [1, 2, 3, 4]) + sage: J = G.elementwise_product(H) # optional - sage.rings.finite_rings + sage: J # optional - sage.rings.finite_rings [0 2] [0 2] - sage: J.parent() - Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3 + sage: J.parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 2 by 2 dense matrices + over Finite Field of size 3 Non-commutative rings behave as expected. These are the usual quaternions. :: - sage: R. = QuaternionAlgebra(-1, -1) - sage: A = matrix(R, 2, [1,i,j,k]) - sage: B = matrix(R, 2, [i,i,i,i]) - sage: A.elementwise_product(B) + sage: R. = QuaternionAlgebra(-1, -1) # optional - sage.combinat + sage: A = matrix(R, 2, [1,i,j,k]) # optional - sage.combinat + sage: B = matrix(R, 2, [i,i,i,i]) # optional - sage.combinat + sage: A.elementwise_product(B) # optional - sage.combinat [ i -1] [-k j] - sage: B.elementwise_product(A) + sage: B.elementwise_product(A) # optional - sage.combinat [ i -1] [ k -j] Input that is not a matrix will raise an error. :: - sage: A = random_matrix(ZZ,5,10,x=20) + sage: A = random_matrix(ZZ, 5, 10, x=20) sage: A.elementwise_product(vector(ZZ, [1,2,3,4])) Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Full MatrixSpace of 5 by 10 dense matrices over Integer Ring' and 'Ambient free module of rank 4 over the principal ideal domain Integer Ring' + TypeError: no common canonical parent for objects with parents: + 'Full MatrixSpace of 5 by 10 dense matrices over Integer Ring' and + 'Ambient free module of rank 4 over the principal ideal domain Integer Ring' sage: A = matrix(2, 2, range(4)) sage: A.elementwise_product(polygen(parent(A))) Traceback (most recent call last): ... - TypeError: elementwise_product() argument should be a matrix or coercible to a matrix + TypeError: elementwise_product() argument should be a matrix + or coercible to a matrix Matrices of different sizes for operands will raise an error. :: - sage: A = random_matrix(ZZ,5,10,x=20) - sage: B = random_matrix(ZZ,10,5,x=40) + sage: A = random_matrix(ZZ, 5, 10, x=20) + sage: B = random_matrix(ZZ, 10, 5, x=40) sage: A.elementwise_product(B) Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Full MatrixSpace of 5 by 10 dense matrices over Integer Ring' and 'Full MatrixSpace of 10 by 5 dense matrices over Integer Ring' + TypeError: no common canonical parent for objects with parents: + 'Full MatrixSpace of 5 by 10 dense matrices over Integer Ring' and + 'Full MatrixSpace of 10 by 5 dense matrices over Integer Ring' Some pairs of rings do not have a common parent where multiplication makes sense. This will raise an error. :: sage: A = matrix(QQ, 3, 2, range(6)) - sage: B = matrix(GF(3), 3, [2]*6) - sage: A.elementwise_product(B) + sage: B = matrix(GF(3), 3, [2]*6) # optional - sage.rings.finite_rings + sage: A.elementwise_product(B) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Full MatrixSpace of 3 by 2 dense matrices over Rational Field' and 'Full MatrixSpace of 3 by 2 dense matrices over Finite Field of size 3' + TypeError: no common canonical parent for objects with parents: + 'Full MatrixSpace of 3 by 2 dense matrices over Rational Field' and + 'Full MatrixSpace of 3 by 2 dense matrices over Finite Field of size 3' We illustrate various combinations of sparse and dense matrices. The usual coercion rules apply:: @@ -1288,7 +1302,7 @@ cdef class Matrix(Matrix1): sage: A.permanent() 24 - sage: A = matrix(3,6,[1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1]) + sage: A = matrix(3,6, [1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1]) sage: A.permanent() 36 sage: B = A.change_ring(RR) @@ -1307,7 +1321,7 @@ cdef class Matrix(Matrix1): :: - sage: A = matrix(4,5,[1,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,0]) + sage: A = matrix(4,5, [1,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,0]) sage: A.permanent() 32 @@ -1323,21 +1337,21 @@ cdef class Matrix(Matrix1): :: - sage: A = matrix(QQ,2,2,[1/5,2/7,3/2,4/5]) + sage: A = matrix(QQ, 2,2, [1/5,2/7,3/2,4/5]) sage: A.permanent() 103/175 :: sage: R. = PolynomialRing(ZZ) - sage: A = matrix(R,2,2,[a,1,a,a+1]) + sage: A = matrix(R, 2,2, [a,1,a,a+1]) sage: A.permanent() a^2 + 2*a :: - sage: R. = PolynomialRing(ZZ,2) - sage: A = matrix(R,2,2,[x, y, x^2, y^2]) + sage: R. = PolynomialRing(ZZ, 2) + sage: A = matrix(R, 2,2, [x, y, x^2, y^2]) sage: A.permanent() x^2*y + x*y^2 """ @@ -1416,13 +1430,13 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(4,[1,0,1,0,1,0,1,0,1,0,10,10,1,0,1,1]) + sage: A = matrix(4, [1,0,1,0,1,0,1,0,1,0,10,10,1,0,1,1]) sage: A.permanental_minor(2) 114 :: - sage: A = matrix(3,6,[1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1]) + sage: A = matrix(3,6, [1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1]) sage: A.permanental_minor(0) 1 sage: A.permanental_minor(1) @@ -1443,7 +1457,8 @@ cdef class Matrix(Matrix1): sage: m, n = 3, 6 sage: C = matrix(m, n, lambda i,j: 1 - A[i,j]) - sage: sum((-1)^k * C.permanental_minor(k)*factorial(n-k)/factorial(n-m) for k in range(m+1)) + sage: sum((-1)^k * C.permanental_minor(k)*factorial(n-k)/factorial(n-m) + ....: for k in range(m+1)) 36 See Theorem 7.2.1 of Brualdi and Ryser: Combinatorial Matrix @@ -1545,28 +1560,28 @@ cdef class Matrix(Matrix1): Beware that the ``exact`` algorithm is not numerically stable, but the default ``numpy`` algorithm is:: - sage: M = matrix.hilbert(12,ring=RR) - sage: (~M*M).norm() # a considerable error + sage: M = matrix.hilbert(12, ring=RR) + sage: (~M * M).norm() # a considerable error 1.3... sage: Mx = M.pseudoinverse(algorithm="exact") - sage: (Mx*M).norm() # huge error + sage: (Mx * M).norm() # huge error 11.5... - sage: Mx = M.pseudoinverse(algorithm="numpy") - sage: (Mx*M).norm() # still OK + sage: Mx = M.pseudoinverse(algorithm="numpy") # optional - numpy + sage: (Mx * M).norm() # still OK 1.00... When multiplying the given matrix with the pseudoinverse, the result is symmetric for the ``exact`` algorithm or hermitian for the ``exactconj`` algorithm:: - sage: M = matrix(QQbar, 2, 2, [1, sqrt(-3), -sqrt(-3), 3]) - sage: M * M.pseudoinverse() + sage: M = matrix(QQbar, 2, 2, [1, sqrt(-3), -sqrt(-3), 3]) # optional - sage.rings.number_field sage.symbolic + sage: M * M.pseudoinverse() # optional - sage.rings.number_field sage.symbolic [ 0.2500000000000000? 0.4330127018922193?*I] [-0.4330127018922193?*I 0.750000000000000?] - sage: M * M.pseudoinverse(algorithm="exactconj") + sage: M * M.pseudoinverse(algorithm="exactconj") # optional - sage.rings.number_field sage.symbolic [ 1/4 0.4330127018922193?*I] [-0.4330127018922193?*I 3/4] - sage: M * M.pseudoinverse(algorithm="exact") + sage: M * M.pseudoinverse(algorithm="exact") # optional - sage.rings.number_field sage.symbolic [ -1/2 0.866025403784439?*I] [0.866025403784439?*I 3/2] @@ -1583,13 +1598,13 @@ cdef class Matrix(Matrix1): Numpy gives a strange answer due to rounding errors:: - sage: M.pseudoinverse(algorithm="numpy") # random + sage: M.pseudoinverse(algorithm="numpy") # random # optional - numpy [-1286742750677287/643371375338643 1000799917193445/1000799917193444] [ 519646110850445/346430740566963 -300239975158034/600479950316067] Although it is not too far off:: - sage: (~M-M.pseudoinverse(algorithm="numpy")).norm() < 1e-14 + sage: (~M - M.pseudoinverse(algorithm="numpy")).norm() < 1e-14 # optional - numpy True TESTS:: @@ -1758,20 +1773,20 @@ cdef class Matrix(Matrix1): An example with an exotic matrix (for which only Butera-Pernici and Ryser algorithms are available):: - sage: R. = PolynomialRing(GF(5)) - sage: A = matrix(R,[[1,x,y],[x*y,x**2+y,0]]) - sage: A.rook_vector(algorithm="ButeraPernici") + sage: R. = PolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: A = matrix(R, [[1, x, y], [x*y, x**2+y, 0]]) # optional - sage.rings.finite_rings + sage: A.rook_vector(algorithm="ButeraPernici") # optional - sage.rings.finite_rings [1, x^2 + x*y + x + 2*y + 1, 2*x^2*y + x*y^2 + x^2 + y^2 + y] - sage: A.rook_vector(algorithm="Ryser") + sage: A.rook_vector(algorithm="Ryser") # optional - sage.rings.finite_rings [1, x^2 + x*y + x + 2*y + 1, 2*x^2*y + x*y^2 + x^2 + y^2 + y] - sage: A.rook_vector(algorithm="Godsil") + sage: A.rook_vector(algorithm="Godsil") # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: coefficients must be zero or one, but we have 'x' in position (0,1). - sage: B = A.transpose() - sage: B.rook_vector(algorithm="ButeraPernici") + sage: B = A.transpose() # optional - sage.rings.finite_rings + sage: B.rook_vector(algorithm="ButeraPernici") # optional - sage.rings.finite_rings [1, x^2 + x*y + x + 2*y + 1, 2*x^2*y + x*y^2 + x^2 + y^2 + y] - sage: B.rook_vector(algorithm="Ryser") + sage: B.rook_vector(algorithm="Ryser") # optional - sage.rings.finite_rings [1, x^2 + x*y + x + 2*y + 1, 2*x^2*y + x*y^2 + x^2 + y^2 + y] TESTS:: @@ -1900,7 +1915,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = Matrix(ZZ,2,3,[1,2,3,4,5,6]); A + sage: A = Matrix(ZZ, 2,3, [1,2,3,4,5,6]); A [1 2 3] [4 5 6] sage: A.minors(2) @@ -1914,15 +1929,17 @@ cdef class Matrix(Matrix1): :: - sage: k = GF(37) - sage: P. = PolynomialRing(k) - sage: A = Matrix(P,2,3,[x0*x1, x0, x1, x2, x2 + 16, x2 + 5*x1 ]) - sage: A.minors(2) - [x0*x1*x2 + 16*x0*x1 - x0*x2, 5*x0*x1^2 + x0*x1*x2 - x1*x2, 5*x0*x1 + x0*x2 - x1*x2 - 16*x1] + sage: k = GF(37) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: A = Matrix(P, 2, 3, [x0*x1, x0, x1, x2, x2 + 16, x2 + 5*x1]) # optional - sage.rings.finite_rings + sage: A.minors(2) # optional - sage.rings.finite_rings + [x0*x1*x2 + 16*x0*x1 - x0*x2, + 5*x0*x1^2 + x0*x1*x2 - x1*x2, + 5*x0*x1 + x0*x2 - x1*x2 - 16*x1] This test addresses an issue raised at :trac:`20512`:: - sage: A.minors(0)[0].parent() == P + sage: A.minors(0)[0].parent() == P # optional - sage.rings.finite_rings True """ from sage.combinat.combination import Combinations @@ -1942,7 +1959,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = MatrixSpace(Integers(8),3)([1,7,3, 1,1,1, 3,4,5]) + sage: A = MatrixSpace(Integers(8), 3)([1,7,3, 1,1,1, 3,4,5]) sage: A.det() 6 """ @@ -1975,7 +1992,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = MatrixSpace(Integers(8),3)([1,7,3, 1,1,1, 3,4,5]) + sage: A = MatrixSpace(Integers(8), 3)([1,7,3, 1,1,1, 3,4,5]) sage: A.determinant() 6 sage: A.determinant() is A.determinant() @@ -1986,8 +2003,8 @@ cdef class Matrix(Matrix1): We compute the determinant of the arbitrary 3x3 matrix:: - sage: R = PolynomialRing(QQ,9,'x') - sage: A = matrix(R,3,R.gens()) + sage: R = PolynomialRing(QQ, 9, 'x') + sage: A = matrix(R, 3, R.gens()) sage: A [x0 x1 x2] [x3 x4 x5] @@ -2000,7 +2017,7 @@ cdef class Matrix(Matrix1): :: - sage: R. = PolynomialRing(IntegerRing(),2) + sage: R. = PolynomialRing(IntegerRing(), 2) sage: A = MatrixSpace(R,2)([x, y, x**2, y**2]) sage: A.determinant() -x^2*y + x*y^2 @@ -2013,35 +2030,40 @@ cdef class Matrix(Matrix1): TESTS:: - sage: A = matrix(5, 5, [next_prime(i^2) for i in range(25)]) - sage: B = MatrixSpace(ZZ['x'], 5, 5)(A) - sage: A.det() - B.det() + sage: A = matrix(5, 5, [next_prime(i^2) for i in range(25)]) # optional - sage.libs.pari + sage: B = MatrixSpace(ZZ['x'], 5, 5)(A) # optional - sage.libs.pari + sage: A.det() - B.det() # optional - sage.libs.pari 0 We verify that :trac:`5569` is resolved (otherwise the following would hang for hours):: - sage: d = random_matrix(GF(next_prime(10^20)),50).det() - sage: d = random_matrix(Integers(10^50),50).det() + sage: d = random_matrix(GF(next_prime(10^20)), 50).det() # optional - sage.rings.finite_rings + sage: d = random_matrix(Integers(10^50), 50).det() # optional - sage.rings.finite_rings We verify that :trac:`7704` is resolved:: - sage: matrix(ZZ, {(0,0):1,(1,1):2,(2,2):3,(3,3):4}).det() + sage: matrix(ZZ, {(0,0): 1, (1,1): 2, (2,2): 3, (3,3): 4}).det() 24 - sage: matrix(QQ, {(0,0):1,(1,1):2,(2,2):3,(3,3):4}).det() + sage: matrix(QQ, {(0,0): 1, (1,1): 2, (2,2): 3, (3,3): 4}).det() 24 We verify that :trac:`10063` is resolved:: - sage: A = GF(2)['x,y,z'] - sage: A.inject_variables() + sage: A = GF(2)['x,y,z'] # optional - sage.rings.finite_rings + sage: A.inject_variables() # optional - sage.rings.finite_rings Defining x, y, z - sage: R = A.quotient(x^2 + 1).quotient(y^2 + 1).quotient(z^2 + 1) - sage: R.inject_variables() + sage: R = A.quotient(x^2 + 1).quotient(y^2 + 1).quotient(z^2 + 1) # optional - sage.rings.finite_rings + sage: R.inject_variables() # optional - sage.rings.finite_rings Defining xbarbarbar, ybarbarbar, zbarbarbar - sage: M = matrix([[1,1,1,1],[xbarbarbar,ybarbarbar,1,1],[0,1,zbarbarbar,1],[xbarbarbar,zbarbarbar,1,1]]) - sage: M.determinant() - xbarbarbar*ybarbarbar*zbarbarbar + xbarbarbar*ybarbarbar + xbarbarbar*zbarbarbar + ybarbarbar*zbarbarbar + xbarbarbar + ybarbarbar + zbarbarbar + 1 + sage: M = matrix([[1, 1, 1, 1], # optional - sage.rings.finite_rings + ....: [xbarbarbar, ybarbarbar, 1, 1], + ....: [0, 1, zbarbarbar, 1], + ....: [xbarbarbar, zbarbarbar, 1, 1]]) + sage: M.determinant() # optional - sage.rings.finite_rings + xbarbarbar*ybarbarbar*zbarbarbar + xbarbarbar*ybarbarbar + + xbarbarbar*zbarbarbar + ybarbarbar*zbarbarbar + xbarbarbar + + ybarbarbar + zbarbarbar + 1 Check that the determinant is computed from a cached charpoly properly:: @@ -2203,14 +2225,14 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(SR, 2, lambda i, j: f'a{i}{j}'); A # optional - sage.symbolic + sage: A = matrix(SR, 2, lambda i, j: f'a{i}{j}'); A # optional - sage.symbolic [a00 a01] [a10 a11] - sage: A.quantum_determinant() # optional - sage.symbolic + sage: A.quantum_determinant() # optional - sage.symbolic -a01*a10*q + a00*a11 - sage: A = matrix(SR, 3, lambda i, j: f'a{i}{j}') # optional - sage.symbolic - sage: A.quantum_determinant() # optional - sage.symbolic + sage: A = matrix(SR, 3, lambda i, j: f'a{i}{j}') # optional - sage.symbolic + sage: A.quantum_determinant() # optional - sage.symbolic -a02*a11*a20*q^3 + (a01*a12*a20 + a02*a10*a21)*q^2 + (-a00*a12*a21 - a01*a10*a22)*q + a00*a11*a22 @@ -2222,17 +2244,17 @@ cdef class Matrix(Matrix1): sage: A.quantum_determinant(q^-2) 7*q^-6 + q^-4 + q^-2 + 5 - sage: S. = PolynomialRing(GF(7)) - sage: R. = LaurentPolynomialRing(S) - sage: MS = MatrixSpace(S, 3, sparse=True) - sage: A = MS([[x, y, 3], [4, 2+y, x^2], [0, 1-x, x+y]]) - sage: A.det() + sage: S. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: R. = LaurentPolynomialRing(S) # optional - sage.rings.finite_rings + sage: MS = MatrixSpace(S, 3, sparse=True) # optional - sage.rings.finite_rings + sage: A = MS([[x, y, 3], [4, 2+y, x^2], [0, 1-x, x+y]]) # optional - sage.rings.finite_rings + sage: A.det() # optional - sage.rings.finite_rings x^4 - x^3 + x^2*y + x*y^2 + 2*x^2 - 2*x*y + 3*y^2 + 2*x - 2 - sage: A.quantum_determinant() + sage: A.quantum_determinant() # optional - sage.rings.finite_rings (2*x - 2)*q^2 + (x^4 - x^3 + 3*x*y + 3*y^2)*q + x^2*y + x*y^2 + 2*x^2 + 2*x*y - sage: A.quantum_determinant(int(2)) + sage: A.quantum_determinant(int(2)) # optional - sage.rings.finite_rings 2*x^4 - 2*x^3 + x^2*y + x*y^2 + 2*x^2 + x*y - y^2 + x - 1 - sage: A.quantum_determinant(q*x + q^-1*y) + sage: A.quantum_determinant(q*x + q^-1*y) # optional - sage.rings.finite_rings (2*x*y^2 - 2*y^2)*q^-2 + (x^4*y - x^3*y + 3*x*y^2 + 3*y^3)*q^-1 + (-2*x^2*y + x*y^2 + 2*x^2 - 2*x*y) + (x^5 - x^4 + 3*x^2*y + 3*x*y^2)*q + (2*x^3 - 2*x^2)*q^2 @@ -2400,13 +2422,13 @@ cdef class Matrix(Matrix1): In order to use the Bär-Faddeev-LeVerrier algorithm, the base ring must have characteristic zero:: - sage: A = matrix(GF(5), [(0, 3, 4, 1, 3, 4), + sage: A = matrix(GF(5), [(0, 3, 4, 1, 3, 4), # optional - sage.rings.finite_rings ....: (2, 0, 2, 0, 1, 0), ....: (1, 3, 0, 4, 1, 0), ....: (4, 0, 1, 0, 2, 0), ....: (2, 4, 4, 3, 0, 0), ....: (1, 0, 0, 0, 0, 0)]) - sage: A.pfaffian(algorithm='bfl') + sage: A.pfaffian(algorithm='bfl') # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: Bär-Faddeev-LeVerrier algorithm not applicable, @@ -2414,7 +2436,7 @@ cdef class Matrix(Matrix1): In that case, the definition by perfect matchings is used instead:: - sage: A.pfaffian() + sage: A.pfaffian() # optional - sage.combinat sage.rings.finite_rings 2 """ @@ -2499,7 +2521,7 @@ cdef class Matrix(Matrix1): ....: (2, -1, 0, 0, 1, 5/2), ....: (-2, 1, -3/2, -1, 0, 1/2), ....: (1/2, -3/2, -1, -5/2, -1/2, 0)]) - sage: A._pf_perfect_matchings() + sage: A._pf_perfect_matchings() # optional - sage.combinat -1/2 """ @@ -2555,9 +2577,9 @@ cdef class Matrix(Matrix1): TESTS:: - sage: A = random_matrix(ZZ[x], 6) + sage: A = random_matrix(ZZ['x'], 6) sage: A = A - A.transpose() - sage: A.pfaffian(algorithm='bfl') == A._pf_perfect_matchings() + sage: A.pfaffian(algorithm='bfl') == A._pf_perfect_matchings() # optional - sage.combinat True """ @@ -2602,13 +2624,14 @@ cdef class Matrix(Matrix1): EXAMPLES:: sage: m = matrix(ZZ, 3, 3, range(9)) - sage: phi = ZZ.hom(GF(5)) - sage: m.apply_morphism(phi) + sage: phi = ZZ.hom(GF(5)) # optional - sage.rings.finite_rings + sage: m.apply_morphism(phi) # optional - sage.rings.finite_rings [0 1 2] [3 4 0] [1 2 3] - sage: parent(m.apply_morphism(phi)) - Full MatrixSpace of 3 by 3 dense matrices over Finite Field of size 5 + sage: parent(m.apply_morphism(phi)) # optional - sage.rings.finite_rings + Full MatrixSpace of 3 by 3 dense matrices + over Finite Field of size 5 We apply a morphism to a matrix over a polynomial ring:: @@ -2650,27 +2673,29 @@ cdef class Matrix(Matrix1): EXAMPLES:: sage: m = matrix(ZZ, 3, 3, range(9)) - sage: k. = GF(9) - sage: f = lambda x: k(x) - sage: n = m.apply_map(f); n + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: f = lambda x: k(x) # optional - sage.rings.finite_rings + sage: n = m.apply_map(f); n # optional - sage.rings.finite_rings [0 1 2] [0 1 2] [0 1 2] - sage: n.parent() - Full MatrixSpace of 3 by 3 dense matrices over Finite Field in a of size 3^2 + sage: n.parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 3 by 3 dense matrices + over Finite Field in a of size 3^2 In this example, we explicitly specify the codomain. :: - sage: s = GF(3) - sage: f = lambda x: s(x) - sage: n = m.apply_map(f, k); n + sage: s = GF(3) # optional - sage.rings.finite_rings + sage: f = lambda x: s(x) # optional - sage.rings.finite_rings + sage: n = m.apply_map(f, k); n # optional - sage.rings.finite_rings [0 1 2] [0 1 2] [0 1 2] - sage: n.parent() - Full MatrixSpace of 3 by 3 dense matrices over Finite Field in a of size 3^2 + sage: n.parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 3 by 3 dense matrices + over Finite Field in a of size 3^2 If self is subdivided, the result will be as well:: @@ -2763,7 +2788,7 @@ cdef class Matrix(Matrix1): sage: a = matrix(QQ, 2,2, [1,2,3,4]); a [1 2] [3 4] - sage: a.characteristic_polynomial('T') + sage: a.characteristic_polynomial('T') # optional - sage.libs.pari T^2 - 5*T - 2 """ return self.charpoly(*args, **kwds) @@ -2775,9 +2800,9 @@ cdef class Matrix(Matrix1): EXAMPLES:: sage: a = matrix(QQ, 4, 4, range(16)) - sage: a.minimal_polynomial('z') + sage: a.minimal_polynomial('z') # optional - sage.libs.pari z^3 - 30*z^2 - 80*z - sage: a.minpoly() + sage: a.minpoly() # optional - sage.libs.pari x^3 - 30*x^2 - 80*x """ return self.minpoly(var, **kwds) @@ -2792,18 +2817,18 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(GF(9,'c'), 4, [1, 1, 0,0, 0,1,0,0, 0,0,5,0, 0,0,0,5]) - sage: factor(A.minpoly()) + sage: A = matrix(GF(9, 'c'), 4, [1,1,0,0, 0,1,0,0, 0,0,5,0, 0,0,0,5]) # optional - sage.rings.finite_rings + sage: factor(A.minpoly()) # optional - sage.rings.finite_rings (x + 1) * (x + 2)^2 - sage: A.minpoly()(A) == 0 + sage: A.minpoly()(A) == 0 # optional - sage.rings.finite_rings True - sage: factor(A.charpoly()) + sage: factor(A.charpoly()) # optional - sage.rings.finite_rings (x + 1)^2 * (x + 2)^2 The default variable name is `x`, but you can specify another name:: - sage: factor(A.minpoly('y')) + sage: factor(A.minpoly('y')) # optional - sage.rings.finite_rings (y + 1) * (y + 2)^2 """ f = self.fetch('minpoly') @@ -2850,8 +2875,8 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: a = matrix([[1,2],[3,4]]) - sage: a._test_minpoly() + sage: a = matrix([[1,2], [3,4]]) # optional - sage.libs.pari + sage: a._test_minpoly() # optional - sage.libs.pari """ if self.nrows() == self.ncols() and self.base_ring().is_exact(): tester = self._tester(**options) @@ -2911,8 +2936,8 @@ cdef class Matrix(Matrix1): An example over `\QQ`:: - sage: A = MatrixSpace(QQ,3)(range(9)) - sage: A.charpoly('x') + sage: A = MatrixSpace(QQ, 3)(range(9)) + sage: A.charpoly('x') # optional - sage.libs.pari x^3 - 12*x^2 - 18*x sage: A.trace() 12 @@ -2923,13 +2948,14 @@ cdef class Matrix(Matrix1): polynomial ring `\ZZ[a]`:: sage: R. = PolynomialRing(ZZ) - sage: M = MatrixSpace(R,2)([a,1, a,a+1]); M + sage: M = MatrixSpace(R, 2)([a,1, a,a+1]); M [ a 1] [ a a + 1] sage: f = M.charpoly('x'); f x^2 + (-2*a - 1)*x + a^2 sage: f.parent() - Univariate Polynomial Ring in x over Univariate Polynomial Ring in a over Integer Ring + Univariate Polynomial Ring in x + over Univariate Polynomial Ring in a over Integer Ring sage: M.trace() 2*a + 1 sage: M.determinant() @@ -2939,7 +2965,7 @@ cdef class Matrix(Matrix1): multi-variate polynomial ring `\ZZ[x,y]`:: sage: R. = PolynomialRing(ZZ,2) - sage: A = MatrixSpace(R,2)([x, y, x^2, y^2]) + sage: A = MatrixSpace(R, 2)([x, y, x^2, y^2]) sage: f = A.charpoly('x'); f x^2 + (-y^2 - x)*x - x^2*y + x*y^2 @@ -2957,16 +2983,16 @@ cdef class Matrix(Matrix1): Here is an example over a number field:: sage: x = QQ['x'].gen() - sage: K. = NumberField(x^2 - 2) - sage: m = matrix(K, [[a-1, 2], [a, a+1]]) - sage: m.charpoly('Z') + sage: K. = NumberField(x^2 - 2) # optional - sage.rings.number_field + sage: m = matrix(K, [[a-1, 2], [a, a+1]]) # optional - sage.rings.number_field + sage: m.charpoly('Z') # optional - sage.rings.number_field Z^2 - 2*a*Z - 2*a + 1 - sage: m.charpoly('a')(m) == 0 + sage: m.charpoly('a')(m) == 0 # optional - sage.rings.number_field True Over integers modulo `n` with composite `n`:: - sage: A = Mat(Integers(6),3,3)(range(9)) + sage: A = Mat(Integers(6), 3, 3)(range(9)) sage: A.charpoly() x^3 @@ -2977,7 +3003,7 @@ cdef class Matrix(Matrix1): sage: R. = QQ[] sage: S. = R.quo((b^3)) - sage: A = matrix(S, [[x*y^2,2*x],[2,x^10*y]]) + sage: A = matrix(S, [[x*y^2, 2*x], [2, x^10*y]]) sage: A [ x*y^2 2*x] [ 2 x^10*y] @@ -2987,7 +3013,7 @@ cdef class Matrix(Matrix1): TESTS:: sage: P. = PolynomialRing(Rationals()) - sage: u = MatrixSpace(P,3)([[0,0,a],[1,0,b],[0,1,c]]) + sage: u = MatrixSpace(P, 3)([[0,0,a], [1,0,b], [0,1,c]]) sage: Q. = PolynomialRing(P) sage: u.charpoly('x') x^3 - c*x^2 - b*x - a @@ -2997,15 +3023,15 @@ cdef class Matrix(Matrix1): and crash if an empty dictionary was cached. We don't cache dictionaries anymore, but this test should still pass:: - sage: z = Zp(p=5) - sage: A = matrix(z, [ [3 + O(5^1), 4 + O(5^1), 4 + O(5^1)], + sage: z = Zp(p=5) # optional - sage.rings.padics + sage: A = matrix(z, [ [3 + O(5^1), 4 + O(5^1), 4 + O(5^1)], # optional - sage.rings.padics ....: [2*5^2 + O(5^3), 2 + O(5^1), 1 + O(5^1)], ....: [5 + O(5^2), 1 + O(5^1), 1 + O(5^1)] ]) - sage: A.charpoly(algorithm='hessenberg') + sage: A.charpoly(algorithm='hessenberg') # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: negative valuation - sage: A.det() + sage: A.det() # optional - sage.rings.padics 3 + O(5) The cached polynomial should be independent of the ``var`` @@ -3114,8 +3140,8 @@ cdef class Matrix(Matrix1): Test that :trac:`27937` is fixed:: - sage: R = FreeAbelianMonoid('u,v').algebra(QQ) - sage: matrix(4, 4, lambda i, j: R.an_element())._charpoly_df() + sage: R = FreeAbelianMonoid('u,v').algebra(QQ) # optional - sage.groups + sage: matrix(4, 4, lambda i, j: R.an_element())._charpoly_df() # optional - sage.groups B[1]*x^4 - 4*B[u]*x^3 .. NOTE:: @@ -3224,12 +3250,12 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,9,-7,4/5,4,3,6,4,3]) - sage: A.fcp() + sage: M = MatrixSpace(QQ, 3, 3) + sage: A = M([1,9,-7, 4/5,4,3, 6,4,3]) + sage: A.fcp() # optional - sage.libs.pari x^3 - 8*x^2 + 209/5*x - 286 sage: A = M([3, 0, -2, 0, -2, 0, 0, 0, 0]) - sage: A.fcp('T') + sage: A.fcp('T') # optional - sage.libs.pari (T - 3) * T * (T + 2) """ return self.charpoly(var).factor() @@ -3244,7 +3270,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = MatrixSpace(QQ,2)([1/2, 1/3, 1/5, 1/7]) + sage: A = MatrixSpace(QQ, 2)([1/2, 1/3, 1/5, 1/7]) sage: A.denominator() 210 @@ -3274,14 +3300,14 @@ cdef class Matrix(Matrix1): Here's an example involving a cyclotomic field:: - sage: K. = CyclotomicField(3) - sage: M = MatrixSpace(K,3,sparse=True) - sage: A = M([(1+z)/3,(2+z)/3,z/3,1,1+z,-2,1,5,-1+z]) - sage: print(A) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: M = MatrixSpace(K, 3, sparse=True) # optional - sage.rings.number_field + sage: A = M([(1+z)/3, (2+z)/3, z/3, 1, 1+z, -2, 1, 5, -1+z]) # optional - sage.rings.number_field + sage: print(A) # optional - sage.rings.number_field [1/3*z + 1/3 1/3*z + 2/3 1/3*z] [ 1 z + 1 -2] [ 1 5 z - 1] - sage: print(A.denominator()) + sage: print(A.denominator()) # optional - sage.rings.number_field 3 """ if self.nrows() == 0 or self.ncols() == 0: @@ -3311,7 +3337,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix([[2,5],[3,7]]); A + sage: A = matrix([[2,5], [3,7]]); A [2 5] [3 7] sage: A.diagonal() @@ -3358,13 +3384,13 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: a = matrix(3,3,range(9)); a + sage: a = matrix(3, 3, range(9)); a [0 1 2] [3 4 5] [6 7 8] sage: a.trace() 12 - sage: a = matrix({(1,1):10, (2,1):-3, (2,2):4/3}); a + sage: a = matrix({(1,1): 10, (2,1): -3, (2,2): 4/3}); a [ 0 0 0] [ 0 10 0] [ 0 -3 4/3] @@ -3413,7 +3439,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(ZZ,4,[2, 1, 1, -2, 2, 2, -1, -1, -1,1,2,3,4,5,6,7]) + sage: A = matrix(ZZ, 4, [2, 1, 1, -2, 2, 2, -1, -1, -1,1,2,3,4,5,6,7]) sage: h = A.hessenberg_form(); h [ 2 -7/2 -19/5 -2] [ 2 1/2 -17/5 -1] @@ -3457,7 +3483,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,3, [2, 1, 1, -2, 2, 2, -1, -1, -1]) + sage: A = matrix(QQ, 3, [2, 1, 1, -2, 2, 2, -1, -1, -1]) sage: A.hessenbergize(); A [ 2 3/2 1] [ -2 3 2] @@ -3465,7 +3491,7 @@ cdef class Matrix(Matrix1): :: - sage: A = matrix(QQ,4, [2, 1, 1, -2, 2, 2, -1, -1, -1,1,2,3,4,5,6,7]) + sage: A = matrix(QQ, 4, [2, 1, 1, -2, 2, 2, -1, -1, -1,1,2,3,4,5,6,7]) sage: A.hessenbergize(); A [ 2 -7/2 -19/5 -2] [ 2 1/2 -17/5 -1] @@ -3553,15 +3579,15 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: matrix(QQ,3,3,range(9))._charpoly_hessenberg('Z') + sage: matrix(QQ, 3,3, range(9))._charpoly_hessenberg('Z') Z^3 - 12*Z^2 - 18*Z - sage: matrix(ZZ,3,3,range(9))._charpoly_hessenberg('Z') + sage: matrix(ZZ, 3,3, range(9))._charpoly_hessenberg('Z') Z^3 - 12*Z^2 - 18*Z - sage: matrix(GF(7),3,3,range(9))._charpoly_hessenberg('Z') + sage: matrix(GF(7), 3, 3, range(9))._charpoly_hessenberg('Z') # optional - sage.rings.finite_rings Z^3 + 2*Z^2 + 3*Z - sage: matrix(QQ['x'],3,3,range(9))._charpoly_hessenberg('Z') + sage: matrix(QQ['x'], 3,3, range(9))._charpoly_hessenberg('Z') Z^3 - 12*Z^2 - 18*Z - sage: matrix(ZZ['ZZ'],3,3,range(9))._charpoly_hessenberg('Z') + sage: matrix(ZZ['ZZ'], 3,3, range(9))._charpoly_hessenberg('Z') Z^3 - 12*Z^2 - 18*Z """ if self._nrows != self._ncols: @@ -3627,7 +3653,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = Matrix(QQ,[[1,0,0,1],[0,1,1,0],[1,1,1,0]]) + sage: M = Matrix(QQ, [[1,0,0,1], [0,1,1,0], [1,1,1,0]]) sage: M.nullity() 0 sage: M.left_nullity() @@ -3684,7 +3710,7 @@ cdef class Matrix(Matrix1): OUTPUT: - Returns a pair. First item is the string 'pivot-pari-numberfield' + Returns a pair. First item is the string ``'pivot-pari-numberfield'`` that identifies the nature of the basis vectors. Second item is a matrix whose rows are a basis for the right kernel, @@ -3692,32 +3718,34 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: Q = QuadraticField(-7) - sage: a = Q.gen(0) - sage: A = matrix(Q, [[ 2, 5-a, 15-a], - ....: [2+a, a, -7 + 5*a]]) - sage: result = A._right_kernel_matrix_over_number_field() - sage: result[0] + sage: Q = QuadraticField(-7) # optional - sage.rings.number_field + sage: a = Q.gen(0) # optional - sage.rings.number_field + sage: A = matrix(Q, [[ 2, 5 - a, 15 - a], # optional - sage.rings.number_field + ....: [2 + a, a, -7 + 5*a]]) + sage: result = A._right_kernel_matrix_over_number_field() # optional - sage.rings.number_field sage.libs.pari + sage: result[0] # optional - sage.rings.number_field sage.libs.pari 'pivot-pari-numberfield' - sage: P = result[1]; P + sage: P = result[1]; P # optional - sage.rings.number_field sage.libs.pari [-a -3 1] - sage: A*P.transpose() == zero_matrix(Q, 2, 1) + sage: A * P.transpose() == zero_matrix(Q, 2, 1) # optional - sage.rings.number_field sage.libs.pari True TESTS: We test some trivial cases. :: - sage: Q = QuadraticField(-7) - sage: A = matrix(Q, 0, 2) - sage: A._right_kernel_matrix_over_number_field()[1] + sage: Q = QuadraticField(-7) # optional - sage.rings.number_field + sage: A = matrix(Q, 0, 2) # optional - sage.rings.number_field + sage: A._right_kernel_matrix_over_number_field()[1] # optional - sage.rings.number_field sage.libs.pari [1 0] [0 1] - sage: A = matrix(Q, 2, 0) - sage: A._right_kernel_matrix_over_number_field()[1].parent() - Full MatrixSpace of 0 by 0 dense matrices over Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I - sage: A = zero_matrix(Q, 4, 3) - sage: A._right_kernel_matrix_over_number_field()[1] + sage: A = matrix(Q, 2, 0) # optional - sage.rings.number_field sage.libs.pari + sage: A._right_kernel_matrix_over_number_field()[1].parent() # optional - sage.rings.number_field sage.libs.pari + Full MatrixSpace of 0 by 0 dense matrices + over Number Field in a with defining polynomial x^2 + 7 + with a = 2.645751311064591?*I + sage: A = zero_matrix(Q, 4, 3) # optional - sage.rings.number_field sage.libs.pari + sage: A._right_kernel_matrix_over_number_field()[1] # optional - sage.rings.number_field sage.libs.pari [1 0 0] [0 1 0] [0 0 1] @@ -3746,34 +3774,35 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: C = CyclotomicField(14) - sage: a = C.gen(0) - sage: A = matrix(C, 3, 4, [[ 1, a, 1+a, a^3+a^5], + sage: C = CyclotomicField(14) # optional - sage.rings.number_field + sage: a = C.gen(0) # optional - sage.rings.number_field + sage: A = matrix(C, 3, 4, [[ 1, a, 1+a, a^3+a^5], # optional - sage.rings.number_field ....: [ a, a^4, a+a^4, a^4+a^8], ....: [a^2, a^6, a^2+a^6, a^5+a^10]]) - sage: result = A._right_kernel_matrix_over_field() - sage: result[0] + sage: result = A._right_kernel_matrix_over_field() # optional - sage.rings.number_field + sage: result[0] # optional - sage.rings.number_field 'pivot-generic' - sage: P = result[1]; P + sage: P = result[1]; P # optional - sage.rings.number_field [ -1 -1 1 0] [-zeta14^3 -zeta14^4 0 1] - sage: A*P.transpose() == zero_matrix(C, 3, 2) + sage: A * P.transpose() == zero_matrix(C, 3, 2) # optional - sage.rings.number_field True TESTS: We test some trivial cases. :: - sage: C = CyclotomicField(14) - sage: A = matrix(C, 0, 2) - sage: A._right_kernel_matrix_over_field()[1] + sage: C = CyclotomicField(14) # optional - sage.rings.number_field + sage: A = matrix(C, 0, 2) # optional - sage.rings.number_field + sage: A._right_kernel_matrix_over_field()[1] # optional - sage.rings.number_field [1 0] [0 1] - sage: A = matrix(C, 2, 0) - sage: A._right_kernel_matrix_over_field()[1].parent() - Full MatrixSpace of 0 by 0 dense matrices over Cyclotomic Field of order 14 and degree 6 - sage: A = zero_matrix(C, 4, 3) - sage: A._right_kernel_matrix_over_field()[1] + sage: A = matrix(C, 2, 0) # optional - sage.rings.number_field + sage: A._right_kernel_matrix_over_field()[1].parent() # optional - sage.rings.number_field + Full MatrixSpace of 0 by 0 dense matrices + over Cyclotomic Field of order 14 and degree 6 + sage: A = zero_matrix(C, 4, 3) # optional - sage.rings.number_field + sage: A._right_kernel_matrix_over_field()[1] # optional - sage.rings.number_field [1 0 0] [0 1 0] [0 0 1] @@ -3844,7 +3873,7 @@ cdef class Matrix(Matrix1): 'computed-smith-form' sage: P = result[1]; P [-1 -y 1] - sage: A*P.transpose() == zero_matrix(R, 2, 1) + sage: A * P.transpose() == zero_matrix(R, 2, 1) True TESTS: @@ -3858,7 +3887,8 @@ cdef class Matrix(Matrix1): [0 1] sage: A = matrix(R, 2, 0) sage: A._right_kernel_matrix_over_domain()[1].parent() - Full MatrixSpace of 0 by 0 dense matrices over Univariate Polynomial Ring in y over Rational Field + Full MatrixSpace of 0 by 0 dense matrices + over Univariate Polynomial Ring in y over Rational Field sage: A = zero_matrix(R, 4, 3) sage: A._right_kernel_matrix_over_domain()[1] [1 0 0] @@ -3892,15 +3922,15 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(Zmod(24480), [[1,2,3,4,5],[7,7,7,7,7]]) - sage: result = A._right_kernel_matrix_over_integer_mod_ring() - sage: result[0] + sage: A = matrix(Zmod(24480), [[1,2,3,4,5], [7,7,7,7,7]]) + sage: result = A._right_kernel_matrix_over_integer_mod_ring() # optional - sage.libs.pari + sage: result[0] # optional - sage.libs.pari 'computed-pari-matkermod' - sage: P = result[1]; P + sage: P = result[1]; P # optional - sage.libs.pari [ 1 24478 1 0 0] [ 2 24477 0 1 0] [ 3 24476 0 0 1] - sage: A*P.transpose() == 0 + sage: A * P.transpose() == 0 # optional - sage.libs.pari True """ R = self.base_ring() @@ -3989,19 +4019,19 @@ cdef class Matrix(Matrix1): sage: C = A.right_kernel_matrix(algorithm='default', basis='computed'); C [-1 2 -2 -1 0] [ 1 2 0 0 -1] - sage: A*C.transpose() == zero_matrix(QQ, 4, 2) + sage: A * C.transpose() == zero_matrix(QQ, 4, 2) True sage: P = A.right_kernel_matrix(algorithm='padic', basis='pivot'); P [ 1 -2 2 1 0] [-1 -2 0 0 1] - sage: A*P.transpose() == zero_matrix(QQ, 4, 2) + sage: A * P.transpose() == zero_matrix(QQ, 4, 2) True sage: C == -P True sage: E = A.right_kernel_matrix(algorithm='default', basis='echelon'); E [ 1 0 1 1/2 -1/2] [ 0 1 -1/2 -1/4 -1/4] - sage: A*E.transpose() == zero_matrix(QQ, 4, 2) + sage: A * E.transpose() == zero_matrix(QQ, 4, 2) True Since the rationals are a field, we can call the general code @@ -4014,7 +4044,7 @@ cdef class Matrix(Matrix1): sage: G = A.right_kernel_matrix(algorithm='generic', basis='echelon'); G [ 1 0 1 1/2 -1/2] [ 0 1 -1/2 -1/4 -1/4] - sage: A*G.transpose() == zero_matrix(QQ, 4, 2) + sage: A * G.transpose() == zero_matrix(QQ, 4, 2) True We verify that the rational matrix code is called for both @@ -4053,55 +4083,56 @@ cdef class Matrix(Matrix1): basis, so the `basis` keywords 'computed' and 'pivot' will return the same results. :: - sage: Q = QuadraticField(-7) - sage: a = Q.gen(0) - sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a], + sage: Q = QuadraticField(-7) # optional - sage.rings.number_field + sage: a = Q.gen(0) # optional - sage.rings.number_field + sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a], # optional - sage.rings.number_field ....: [2+a, a, -7 + 5*a, -3+3*a]]) - sage: C = A.right_kernel_matrix(algorithm='default', basis='computed'); C + sage: C = A.right_kernel_matrix(algorithm='default', basis='computed'); C # optional - sage.rings.number_field [ -a -3 1 0] [ -2 -a - 1 0 1] - sage: A*C.transpose() == zero_matrix(Q, 2, 2) + sage: A*C.transpose() == zero_matrix(Q, 2, 2) # optional - sage.rings.number_field True - sage: P = A.right_kernel_matrix(algorithm='pari', basis='pivot'); P + sage: P = A.right_kernel_matrix(algorithm='pari', basis='pivot'); P # optional - sage.rings.number_field sage.libs.pari [ -a -3 1 0] [ -2 -a - 1 0 1] - sage: A*P.transpose() == zero_matrix(Q, 2, 2) + sage: A*P.transpose() == zero_matrix(Q, 2, 2) # optional - sage.rings.number_field sage.libs.pari True - sage: E = A.right_kernel_matrix(algorithm='default', basis='echelon'); E + sage: E = A.right_kernel_matrix(algorithm='default', basis='echelon'); E # optional - sage.rings.number_field [ 1 0 7/88*a + 3/88 -3/176*a - 39/176] [ 0 1 -1/88*a - 13/88 13/176*a - 7/176] - sage: A*E.transpose() == zero_matrix(Q, 2, 2) + sage: A*E.transpose() == zero_matrix(Q, 2, 2) # optional - sage.rings.number_field True We can bypass using PARI for number fields and use Sage's general code for matrices over any field. The basis vectors as computed are in pivot format. :: - sage: Q = QuadraticField(-7) - sage: a = Q.gen(0) - sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a],[2+a, a, -7 + 5*a, -3+3*a]]) - sage: G = A.right_kernel_matrix(algorithm='generic', basis='computed'); G + sage: Q = QuadraticField(-7) # optional - sage.rings.number_field + sage: a = Q.gen(0) # optional - sage.rings.number_field + sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a], [2+a, a, -7 + 5*a, -3+3*a]]) # optional - sage.rings.number_field + sage: G = A.right_kernel_matrix(algorithm='generic', basis='computed'); G # optional - sage.rings.number_field [ -a -3 1 0] [ -2 -a - 1 0 1] - sage: A*G.transpose() == zero_matrix(Q, 2, 2) + sage: A*G.transpose() == zero_matrix(Q, 2, 2) # optional - sage.rings.number_field True We check that number fields are handled by the right routine as part of typical right kernel computation. :: - sage: Q = QuadraticField(-7) - sage: a = Q.gen(0) - sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a],[2+a, a, -7 + 5*a, -3+3*a]]) + sage: Q = QuadraticField(-7) # optional - sage.rings.number_field + sage: a = Q.gen(0) # optional - sage.rings.number_field + sage: A = matrix(Q, [[2, 5-a, 15-a, 16+4*a], [2+a, a, -7 + 5*a, -3+3*a]]) # optional - sage.rings.number_field sage: set_verbose(1) - sage: A.right_kernel(algorithm='default') + sage: A.right_kernel(algorithm='default') # optional - sage.rings.number_field verbose ... verbose 1 () computing right kernel matrix over a number field for 2x4 matrix verbose 1 () done computing right kernel matrix over a number field for 2x4 matrix ... - Vector space of degree 4 and dimension 2 over Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I - Basis matrix: - [ 1 0 7/88*a + 3/88 -3/176*a - 39/176] - [ 0 1 -1/88*a - 13/88 13/176*a - 7/176] + Vector space of degree 4 and dimension 2 over Number Field in a + with defining polynomial x^2 + 7 with a = 2.645751311064591?*I + Basis matrix: + [ 1 0 7/88*a + 3/88 -3/176*a - 39/176] + [ 0 1 -1/88*a - 13/88 13/176*a - 7/176] sage: set_verbose(0) Over the Finite Field of Order 2: @@ -4111,15 +4142,15 @@ cdef class Matrix(Matrix1): :meth:`~sage.matrix.matrix_mod2_dense.Matrix_mod2_dense._right_kernel_matrix` method. There are no options for the algorithm used. :: - sage: A = matrix(GF(2),[[0, 1, 1, 0, 0, 0], + sage: A = matrix(GF(2),[[0, 1, 1, 0, 0, 0], # optional - sage.rings.finite_rings ....: [1, 0, 0, 0, 1, 1,], ....: [1, 0, 0, 0, 1, 1]]) - sage: E = A.right_kernel_matrix(algorithm='default', format='echelon'); E + sage: E = A.right_kernel_matrix(algorithm='default', format='echelon'); E # optional - sage.rings.finite_rings [1 0 0 0 0 1] [0 1 1 0 0 0] [0 0 0 1 0 0] [0 0 0 0 1 1] - sage: A*E.transpose() == zero_matrix(GF(2), 3, 4) + sage: A*E.transpose() == zero_matrix(GF(2), 3, 4) # optional - sage.rings.finite_rings True Since GF(2) is a field we can route this computation to the generic @@ -4127,24 +4158,24 @@ cdef class Matrix(Matrix1): keywords, 'pluq', 'default' and unspecified, all have the same effect as there is no optional behavior. :: - sage: A = matrix(GF(2),[[0, 1, 1, 0, 0, 0], - ....: [1, 0, 0, 0, 1, 1,], - ....: [1, 0, 0, 0, 1, 1]]) - sage: P = A.right_kernel_matrix(algorithm='generic', basis='pivot'); P + sage: A = matrix(GF(2), [[0, 1, 1, 0, 0, 0], # optional - sage.rings.finite_rings + ....: [1, 0, 0, 0, 1, 1,], + ....: [1, 0, 0, 0, 1, 1]]) + sage: P = A.right_kernel_matrix(algorithm='generic', basis='pivot'); P # optional - sage.rings.finite_rings [0 1 1 0 0 0] [0 0 0 1 0 0] [1 0 0 0 1 0] [1 0 0 0 0 1] - sage: A*P.transpose() == zero_matrix(GF(2), 3, 4) + sage: A*P.transpose() == zero_matrix(GF(2), 3, 4) # optional - sage.rings.finite_rings True - sage: DP = A.right_kernel_matrix(algorithm='default', basis='pivot'); DP + sage: DP = A.right_kernel_matrix(algorithm='default', basis='pivot'); DP # optional - sage.rings.finite_rings [0 1 1 0 0 0] [0 0 0 1 0 0] [1 0 0 0 1 0] [1 0 0 0 0 1] - sage: A*DP.transpose() == zero_matrix(GF(2), 3, 4) + sage: A*DP.transpose() == zero_matrix(GF(2), 3, 4) # optional - sage.rings.finite_rings True - sage: A.right_kernel_matrix(algorithm='pluq', basis='echelon') + sage: A.right_kernel_matrix(algorithm='pluq', basis='echelon') # optional - sage.rings.finite_rings [1 0 0 0 0 1] [0 1 1 0 0 0] [0 0 0 1 0 0] @@ -4152,11 +4183,11 @@ cdef class Matrix(Matrix1): We test that the mod 2 code is called for matrices over GF(2). :: - sage: A = matrix(GF(2),[[0, 1, 1, 0, 0, 0], - ....: [1, 0, 0, 0, 1, 1,], - ....: [1, 0, 0, 0, 1, 1]]) + sage: A = matrix(GF(2), [[0, 1, 1, 0, 0, 0], # optional - sage.rings.finite_rings + ....: [1, 0, 0, 0, 1, 1,], + ....: [1, 0, 0, 0, 1, 1]]) sage: set_verbose(1) - sage: A.right_kernel(algorithm='default') + sage: A.right_kernel(algorithm='default') # optional - sage.rings.finite_rings verbose ... verbose 1 () computing right kernel matrix over integers mod 2 for 3x6 matrix verbose 1 () done computing right kernel matrix over integers mod 2 for 3x6 matrix @@ -4175,19 +4206,19 @@ cdef class Matrix(Matrix1): will compute a set of basis vectors in the pivot format. These could be returned as a basis in echelon form. :: - sage: F. = FiniteField(5^2) - sage: A = matrix(F, 3, 4, [[ 1, a, 1+a, a^3+a^5], + sage: F. = FiniteField(5^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, 3, 4, [[ 1, a, 1+a, a^3+a^5], # optional - sage.rings.finite_rings ....: [ a, a^4, a+a^4, a^4+a^8], ....: [a^2, a^6, a^2+a^6, a^5+a^10]]) - sage: P = A.right_kernel_matrix(algorithm='default', basis='pivot'); P + sage: P = A.right_kernel_matrix(algorithm='default', basis='pivot'); P # optional - sage.rings.finite_rings [ 4 4 1 0] [ a + 2 3*a + 3 0 1] - sage: A*P.transpose() == zero_matrix(F, 3, 2) + sage: A*P.transpose() == zero_matrix(F, 3, 2) # optional - sage.rings.finite_rings True - sage: E = A.right_kernel_matrix(algorithm='default', basis='echelon'); E + sage: E = A.right_kernel_matrix(algorithm='default', basis='echelon'); E # optional - sage.rings.finite_rings [ 1 0 3*a + 4 2*a + 2] [ 0 1 2*a 3*a + 3] - sage: A*E.transpose() == zero_matrix(F, 3, 2) + sage: A*E.transpose() == zero_matrix(F, 3, 2) # optional - sage.rings.finite_rings True This general code can be requested for matrices over any field @@ -4214,12 +4245,12 @@ cdef class Matrix(Matrix1): We test that the generic code is called for matrices over fields, lacking any more specific routine. :: - sage: F. = FiniteField(5^2) - sage: A = matrix(F, 3, 4, [[ 1, a, 1+a, a^3+a^5], + sage: F. = FiniteField(5^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, 3, 4, [[ 1, a, 1+a, a^3+a^5], # optional - sage.rings.finite_rings ....: [ a, a^4, a+a^4, a^4+a^8], ....: [a^2, a^6, a^2+a^6, a^5+a^10]]) sage: set_verbose(1) - sage: A.right_kernel(algorithm='default') + sage: A.right_kernel(algorithm='default') # optional - sage.rings.finite_rings verbose ... verbose 1 () computing right kernel matrix over an arbitrary field for 3x4 matrix ... @@ -4333,7 +4364,8 @@ cdef class Matrix(Matrix1): sage: A.right_kernel_matrix() Traceback (most recent call last): ... - ArithmeticError: Ideal Ideal (x^2 - x, x^2 - 8) of Univariate Polynomial Ring in x over Integer Ring not principal + ArithmeticError: Ideal Ideal (x^2 - x, x^2 - 8) of + Univariate Polynomial Ring in x over Integer Ring not principal We test that the domain code is called for domains that lack any extra structure. :: @@ -4347,9 +4379,10 @@ cdef class Matrix(Matrix1): verbose 1 () computing right kernel matrix over a domain for 2x3 matrix verbose 1 () done computing right kernel matrix over a domain for 2x3 matrix ... - Free module of degree 3 and rank 1 over Univariate Polynomial Ring in y over Rational Field - Echelon basis matrix: - [-1 -y 1] + Free module of degree 3 and rank 1 over + Univariate Polynomial Ring in y over Rational Field + Echelon basis matrix: + [-1 -y 1] sage: set_verbose(0) Over inexact rings: @@ -4369,9 +4402,9 @@ cdef class Matrix(Matrix1): ....: [-0.8090169944, 0.0, 0.5], ....: [ 0.8090169944, 0.0, -0.5], ....: [-0.8090169944, 0.0, -0.5]]).transpose() - sage: (A*A.right_kernel_matrix().transpose()).norm() > 2 + sage: (A * A.right_kernel_matrix().transpose()).norm() > 2 True - sage: (A*A.right_kernel_matrix(basis='computed').transpose()).norm() < 1e-15 + sage: (A * A.right_kernel_matrix(basis='computed').transpose()).norm() < 1e-15 True Trivial Cases: @@ -4383,8 +4416,8 @@ cdef class Matrix(Matrix1): sage: A.right_kernel_matrix() [1 0] [0 1] - sage: A = matrix(FiniteField(7), 2, 0) - sage: A.right_kernel_matrix().parent() + sage: A = matrix(FiniteField(7), 2, 0) # optional - sage.rings.finite_rings + sage: A.right_kernel_matrix().parent() # optional - sage.rings.finite_rings Full MatrixSpace of 0 by 0 dense matrices over Finite Field of size 7 TESTS: @@ -4406,7 +4439,7 @@ cdef class Matrix(Matrix1): Traceback (most recent call last): ... ValueError: matrix kernel algorithm 'junk' not recognized - sage: matrix(GF(2), 2, 2).right_kernel_matrix(algorithm='padic') + sage: matrix(GF(2), 2, 2).right_kernel_matrix(algorithm='padic') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: 'padic' matrix kernel algorithm only available over the rationals and the integers, not over Finite Field of size 2 @@ -4658,7 +4691,7 @@ cdef class Matrix(Matrix1): [ 0 1 0 0 5 5 5] [ 0 0 1 0 -1 -2 -3] [ 0 0 0 1 0 1 1] - sage: A*K.basis_matrix().transpose() == zero_matrix(QQ, 4, 4) + sage: A * K.basis_matrix().transpose() == zero_matrix(QQ, 4, 4) True The default is basis vectors that form a matrix in echelon form. @@ -4685,7 +4718,7 @@ cdef class Matrix(Matrix1): [-1 0 0 -1 1 0 0] [-1 0 1 2 0 1 0] [ 1 0 -1 -1 0 0 1] - sage: A*K.basis_matrix().transpose() == zero_matrix(QQ, 4, 4) + sage: A * K.basis_matrix().transpose() == zero_matrix(QQ, 4, 4) True Matrices may have any field as a base ring. Number fields are @@ -4698,16 +4731,17 @@ cdef class Matrix(Matrix1): Over an arbitrary field, with two basis formats. Same vector space, different bases. :: - sage: F. = FiniteField(5^2) - sage: A = matrix(F, 3, 4, [[ 1, a, 1+a, a^3+a^5], + sage: F. = FiniteField(5^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, 3, 4, [[ 1, a, 1+a, a^3+a^5], # optional - sage.rings.finite_rings ....: [ a, a^4, a+a^4, a^4+a^8], ....: [a^2, a^6, a^2+a^6, a^5+a^10]]) - sage: K = A.right_kernel(); K - Vector space of degree 4 and dimension 2 over Finite Field in a of size 5^2 + sage: K = A.right_kernel(); K # optional - sage.rings.finite_rings + Vector space of degree 4 and dimension 2 + over Finite Field in a of size 5^2 Basis matrix: [ 1 0 3*a + 4 2*a + 2] [ 0 1 2*a 3*a + 3] - sage: A*K.basis_matrix().transpose() == zero_matrix(F, 3, 2) + sage: A * K.basis_matrix().transpose() == zero_matrix(F, 3, 2) # optional - sage.rings.finite_rings True In the following test, we have to force usage of @@ -4717,9 +4751,10 @@ cdef class Matrix(Matrix1): installed. :: sage: from sage.matrix.matrix_generic_dense import Matrix_generic_dense - sage: B = Matrix_generic_dense(A.parent(), A.list(), False, False) - sage: P = B.right_kernel(basis = 'pivot'); P - Vector space of degree 4 and dimension 2 over Finite Field in a of size 5^2 + sage: B = Matrix_generic_dense(A.parent(), A.list(), False, False) # optional - sage.rings.finite_rings + sage: P = B.right_kernel(basis='pivot'); P # optional - sage.rings.finite_rings + Vector space of degree 4 and dimension 2 + over Finite Field in a of size 5^2 User basis matrix: [ 4 4 1 0] [ a + 2 3*a + 3 0 1] @@ -4727,34 +4762,39 @@ cdef class Matrix(Matrix1): If the optional meataxe package is installed, we again have to make sure to work with a copy of B that has the same type as ``P.basis_matrix()``:: - sage: B.parent()(B.list())*P.basis_matrix().transpose() == zero_matrix(F, 3, 2) + sage: (B.parent()(B.list()) * P.basis_matrix().transpose() # optional - sage.rings.finite_rings + ....: == zero_matrix(F, 3, 2)) True - sage: K == P + sage: K == P # optional - sage.rings.finite_rings True Over number fields, PARI is used by default, but general-purpose code can be requested. Same vector space, same bases, different code.:: - sage: Q = QuadraticField(-7) - sage: a = Q.gen(0) - sage: A = matrix(Q, [[ 2, 5-a, 15-a, 16+4*a], - ....: [2+a, a, -7 + 5*a, -3+3*a]]) - sage: K = A.right_kernel(algorithm='default'); K - Vector space of degree 4 and dimension 2 over Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I + sage: Q = QuadraticField(-7) # optional - sage.rings.number_field + sage: a = Q.gen(0) # optional - sage.rings.number_field + sage: A = matrix(Q, [[ 2, 5 - a, 15 - a, 16 + 4*a], # optional - sage.rings.number_field + ....: [2 + a, a, -7 + 5*a, -3 + 3*a]]) + sage: K = A.right_kernel(algorithm='default'); K # optional - sage.rings.number_field + Vector space of degree 4 and dimension 2 + over Number Field in a with defining polynomial x^2 + 7 + with a = 2.645751311064591?*I Basis matrix: [ 1 0 7/88*a + 3/88 -3/176*a - 39/176] [ 0 1 -1/88*a - 13/88 13/176*a - 7/176] - sage: A*K.basis_matrix().transpose() == zero_matrix(Q, 2, 2) + sage: A * K.basis_matrix().transpose() == zero_matrix(Q, 2, 2) # optional - sage.rings.number_field True - sage: B = copy(A) - sage: G = A.right_kernel(algorithm='generic'); G - Vector space of degree 4 and dimension 2 over Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I + sage: B = copy(A) # optional - sage.rings.number_field + sage: G = A.right_kernel(algorithm='generic'); G # optional - sage.rings.number_field + Vector space of degree 4 and dimension 2 + over Number Field in a with defining polynomial x^2 + 7 + with a = 2.645751311064591?*I Basis matrix: [ 1 0 7/88*a + 3/88 -3/176*a - 39/176] [ 0 1 -1/88*a - 13/88 13/176*a - 7/176] - sage: B*G.basis_matrix().transpose() == zero_matrix(Q, 2, 2) + sage: B * G.basis_matrix().transpose() == zero_matrix(Q, 2, 2) # optional - sage.rings.number_field True - sage: K == G + sage: K == G # optional - sage.rings.number_field True For matrices over the integers, several options are possible. @@ -4805,10 +4845,11 @@ cdef class Matrix(Matrix1): sage: A = matrix(R, [[ 1, y, 1+y^2], ....: [y^3, y^2, 2*y^3]]) sage: K = A.right_kernel(algorithm='default', basis='echelon'); K - Free module of degree 3 and rank 1 over Univariate Polynomial Ring in y over Rational Field - Echelon basis matrix: - [-1 -y 1] - sage: A*K.basis_matrix().transpose() == zero_matrix(ZZ, 2, 1) + Free module of degree 3 and rank 1 + over Univariate Polynomial Ring in y over Rational Field + Echelon basis matrix: + [-1 -y 1] + sage: A * K.basis_matrix().transpose() == zero_matrix(ZZ, 2, 1) True It is possible to compute a kernel for a matrix over an integral @@ -4820,7 +4861,8 @@ cdef class Matrix(Matrix1): sage: A.right_kernel() Traceback (most recent call last): ... - ArithmeticError: Ideal Ideal (x^2 - x, x^2 - 8) of Univariate Polynomial Ring in x over Integer Ring not principal + ArithmeticError: Ideal Ideal (x^2 - x, x^2 - 8) of Univariate + Polynomial Ring in x over Integer Ring not principal Matrices over non-commutative rings are not a good idea either. These are the "usual" quaternions. :: @@ -4830,7 +4872,8 @@ cdef class Matrix(Matrix1): sage: A.right_kernel() Traceback (most recent call last): ... - NotImplementedError: Cannot compute a matrix kernel over Quaternion Algebra (-1, -1) with base ring Rational Field + NotImplementedError: Cannot compute a matrix kernel over + Quaternion Algebra (-1, -1) with base ring Rational Field Sparse matrices, over the rationals and the integers, use the same routines as the dense versions. :: @@ -5018,11 +5061,11 @@ cdef class Matrix(Matrix1): Over a finite field, with a basis matrix in "pivot" format. :: - sage: A = matrix(FiniteField(7), [[5, 0, 5, 2, 4], + sage: A = matrix(FiniteField(7), [[5, 0, 5, 2, 4], # optional - sage.rings.finite_rings ....: [1, 3, 2, 3, 6], ....: [1, 1, 6, 5, 3], ....: [2, 5, 6, 0, 0]]) - sage: A.kernel(basis='pivot') + sage: A.kernel(basis='pivot') # optional - sage.rings.finite_rings Vector space of degree 4 and dimension 2 over Finite Field of size 7 User basis matrix: [5 2 1 0] @@ -5131,7 +5174,7 @@ cdef class Matrix(Matrix1): [ 0 2 0 -1] [ 0 1 -2 0] [ 0 2 0 -2] - sage: t.fcp() + sage: t.fcp() # optional - sage.libs.pari (x - 39) * (x + 2) * (x^2 - 2) sage: s = (t-39)*(t^2-2) sage: V = s.kernel(); V @@ -5227,13 +5270,14 @@ cdef class Matrix(Matrix1): An example over a bigger ring:: - sage: L. = NumberField(x^2 - x + 2) - sage: OL = L.ring_of_integers() - sage: A = matrix(L, 2, [1, w/2]) - sage: A.integer_kernel(OL) - Free module of degree 2 and rank 1 over Maximal Order in Number Field in w with defining polynomial x^2 - x + 2 - Echelon basis matrix: - [ -1 -w + 1] + sage: L. = NumberField(x^2 - x + 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers() # optional - sage.rings.number_field + sage: A = matrix(L, 2, [1, w/2]) # optional - sage.rings.number_field + sage: A.integer_kernel(OL) # optional - sage.rings.number_field + Free module of degree 2 and rank 1 over + Maximal Order in Number Field in w with defining polynomial x^2 - x + 2 + Echelon basis matrix: + [ -1 -w + 1] """ try: @@ -5253,9 +5297,9 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: MS1 = MatrixSpace(ZZ,4) - sage: MS2 = MatrixSpace(QQ,6) - sage: A = MS1.matrix([3,4,5,6,7,3,8,10,14,5,6,7,2,2,10,9]) + sage: MS1 = MatrixSpace(ZZ, 4) + sage: MS2 = MatrixSpace(QQ, 6) + sage: A = MS1.matrix([3,4,5,6, 7,3,8,10, 14,5,6,7, 2,2,10,9]) sage: B = MS2.random_element() :: @@ -5358,23 +5402,24 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,9,-7,4/5,4,3,6,4,3]) + sage: M = MatrixSpace(QQ, 3, 3) + sage: A = M([1,9,-7, 4/5,4,3, 6,4,3]) sage: A.column_space() Vector space of degree 3 and dimension 3 over Rational Field Basis matrix: [1 0 0] [0 1 0] [0 0 1] - sage: W = MatrixSpace(CC,2,2) - sage: B = W([1, 2+3*I,4+5*I,9]); B + sage: W = MatrixSpace(CC, 2, 2) + sage: B = W([1, 2 + 3*I, 4 + 5*I, 9]); B [ 1.00000000000000 2.00000000000000 + 3.00000000000000*I] [4.00000000000000 + 5.00000000000000*I 9.00000000000000] sage: B.column_space() - Vector space of degree 2 and dimension 2 over Complex Field with 53 bits of precision - Basis matrix: - [ 1.00000000000000 0.000000000000000] - [0.000000000000000 1.00000000000000] + Vector space of degree 2 and dimension 2 + over Complex Field with 53 bits of precision + Basis matrix: + [ 1.00000000000000 0.000000000000000] + [0.000000000000000 1.00000000000000] """ return self.column_module() @@ -5434,7 +5479,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(ZZ, 4, [3,4,5,6,7,3,8,10,14,5,6,7,2,2,10,9]) + sage: A = matrix(ZZ, 4, [3,4,5,6, 7,3,8,10, 14,5,6,7, 2,2,10,9]) sage: B = matrix(QQ, 6, 6, range(36)) sage: B*11 [ 0 11 22 33 44 55] @@ -5443,23 +5488,23 @@ cdef class Matrix(Matrix1): [198 209 220 231 242 253] [264 275 286 297 308 319] [330 341 352 363 374 385] - sage: A.decomposition() - [ - (Ambient free module of rank 4 over the principal ideal domain Integer Ring, True) - ] - sage: B.decomposition() - [ - (Vector space of degree 6 and dimension 2 over Rational Field - Basis matrix: - [ 1 0 -1 -2 -3 -4] - [ 0 1 2 3 4 5], True), - (Vector space of degree 6 and dimension 4 over Rational Field - Basis matrix: - [ 1 0 0 0 -5 4] - [ 0 1 0 0 -4 3] - [ 0 0 1 0 -3 2] - [ 0 0 0 1 -2 1], False) - ] + sage: A.decomposition() # optional - sage.libs.pari + [ (Ambient free module of rank 4 + over the principal ideal domain Integer Ring, + True) ] + sage: B.decomposition() # optional - sage.libs.pari + [ (Vector space of degree 6 and dimension 2 over Rational Field + Basis matrix: + [ 1 0 -1 -2 -3 -4] + [ 0 1 2 3 4 5], + True), + (Vector space of degree 6 and dimension 4 over Rational Field + Basis matrix: + [ 1 0 0 0 -5 4] + [ 0 1 0 0 -4 3] + [ 0 0 1 0 -3 2] + [ 0 0 0 1 -2 1], + False) ] """ if algorithm == 'kernel' or self.base_ring() not in _Fields: return self._decomposition_using_kernels(is_diagonalizable = is_diagonalizable, dual=dual) @@ -5636,48 +5681,46 @@ cdef class Matrix(Matrix1): [ 3 0 -2] [ 0 -2 0] [ 0 0 0] - sage: t.fcp('X') # factored charpoly + sage: t.fcp('X') # factored charpoly # optional - sage.libs.pari (X - 3) * X * (X + 2) sage: v = kernel(t*(t+2)); v # an invariant subspace Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [0 1 0] [0 0 1] - sage: D = t.decomposition_of_subspace(v); D - [ - (Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [0 0 1], True), - (Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [0 1 0], True) - ] - sage: t.restrict(D[0][0]) + sage: D = t.decomposition_of_subspace(v); D # optional - sage.libs.pari + [ (Vector space of degree 3 and dimension 1 over Rational Field + Basis matrix: [0 0 1], + True), + (Vector space of degree 3 and dimension 1 over Rational Field + Basis matrix: [0 1 0], + True) ] + sage: t.restrict(D[0][0]) # optional - sage.libs.pari [0] - sage: t.restrict(D[1][0]) + sage: t.restrict(D[1][0]) # optional - sage.libs.pari [-2] We do a decomposition over ZZ:: - sage: a = matrix(ZZ,6,[0, 0, -2, 0, 2, 0, 2, -4, -2, 0, 2, 0, 0, 0, -2, -2, 0, 0, 2, 0, -2, -4, 2, -2, 0, 2, 0, -2, -2, 0, 0, 2, 0, -2, 0, 0]) - sage: a.decomposition_of_subspace(ZZ^6) - [ - (Free module of degree 6 and rank 2 over Integer Ring - Echelon basis matrix: - [ 1 0 1 -1 1 -1] - [ 0 1 0 -1 2 -1], False), - (Free module of degree 6 and rank 4 over Integer Ring - Echelon basis matrix: - [ 1 0 -1 0 1 0] - [ 0 1 0 0 0 0] - [ 0 0 0 1 0 0] - [ 0 0 0 0 0 1], False) - ] + sage: a = matrix(ZZ, 6, [0, 0, -2, 0, 2, 0, 2, -4, -2, 0, 2, 0, 0, 0, -2, -2, 0, 0, 2, 0, -2, -4, 2, -2, 0, 2, 0, -2, -2, 0, 0, 2, 0, -2, 0, 0]) + sage: a.decomposition_of_subspace(ZZ^6) # optional - sage.libs.pari + [ (Free module of degree 6 and rank 2 over Integer Ring + Echelon basis matrix: + [ 1 0 1 -1 1 -1] + [ 0 1 0 -1 2 -1], + False), + (Free module of degree 6 and rank 4 over Integer Ring + Echelon basis matrix: + [ 1 0 -1 0 1 0] + [ 0 1 0 0 0 0] + [ 0 0 0 1 0 0] + [ 0 0 0 0 0 1], + False) ] TESTS:: sage: t = matrix(QQ, 3, [3, 0, -2, 0, -2, 0, 0, 0, 0]) - sage: t.decomposition_of_subspace(v, check_restrict = False) == t.decomposition_of_subspace(v) + sage: t.decomposition_of_subspace(v, check_restrict = False) == t.decomposition_of_subspace(v) # optional - sage.libs.pari True """ if not sage.modules.free_module.is_FreeModule(M): @@ -5813,7 +5856,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: sage: V = QQ^3 - sage: A = matrix(QQ,3,[1,2,0, 3,4,0, 0,0,0]) + sage: A = matrix(QQ, 3, [1,2,0, 3,4,0, 0,0,0]) sage: W = V.subspace([[1,0,0], [1,2,3]]) sage: A.restrict_domain(W) [1 2 0] @@ -5848,7 +5891,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,3,[1..9]) + sage: A = matrix(QQ, 3, [1..9]) sage: V = (QQ^3).span([[1,2,3], [7,8,9]]); V Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: @@ -5951,7 +5994,7 @@ cdef class Matrix(Matrix1): [6 7 8] sage: t.wiedemann(0) x^2 - 12*x - 18 - sage: t.charpoly() + sage: t.charpoly() # optional - sage.libs.pari x^3 - 12*x^2 - 18*x """ i = int(i); t=int(t) @@ -6015,17 +6058,17 @@ cdef class Matrix(Matrix1): of finite fields:: sage: A = matrix(QQ, 2, range(4)) - sage: A._eigenspace_format(None) == 'all' + sage: A._eigenspace_format(None) == 'all' # optional - sage.rings.number_field True - sage: B = matrix(GF(13), 2, range(4)) - sage: B._eigenspace_format(None) + sage: B = matrix(GF(13), 2, range(4)) # optional - sage.rings.finite_rings + sage: B._eigenspace_format(None) # optional - sage.rings.finite_rings 'all' Subrings are promoted to fraction fields and then checked for the existence of algebraic closures. :: sage: A = matrix(ZZ, 2, range(4)) - sage: A._eigenspace_format(None) == 'all' + sage: A._eigenspace_format(None) == 'all' # optional - sage.rings.number_field True """ if format not in [None, 'all', 'galois']: @@ -6105,61 +6148,68 @@ cdef class Matrix(Matrix1): Then we request just one eigenspace per irreducible factor of the characteristic polynomial with the `galois` keyword. :: - sage: A = matrix(QQ,3,3,range(9)); A + sage: A = matrix(QQ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: es = A.eigenspaces_left(format='all'); es - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1]), - (-1.348469228349535?, Vector space of degree 3 and dimension 1 over Algebraic Field - User basis matrix: - [ 1 0.3101020514433644? -0.3797958971132713?]), - (13.34846922834954?, Vector space of degree 3 and dimension 1 over Algebraic Field - User basis matrix: - [ 1 1.289897948556636? 1.579795897113272?]) - ] - - sage: es = A.eigenspaces_left(format='galois'); es - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1]), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 - 12*x - 18 - User basis matrix: - [ 1 1/15*a1 + 2/5 2/15*a1 - 1/5]) - ] - sage: es = A.eigenspaces_left(format='galois', algebraic_multiplicity=True); es - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1], 1), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 - 12*x - 18 - User basis matrix: - [ 1 1/15*a1 + 2/5 2/15*a1 - 1/5], 1) - ] - sage: e, v, n = es[0]; v = v.basis()[0] - sage: delta = e*v - v*A - sage: abs(abs(delta)) < 1e-10 + sage: es = A.eigenspaces_left(format='all'); es # optional - sage.rings.number_field + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1]), + (-1.348469228349535?, + Vector space of degree 3 and dimension 1 over Algebraic Field + User basis matrix: + [ 1 0.3101020514433644? -0.3797958971132713?]), + (13.34846922834954?, + Vector space of degree 3 and dimension 1 over Algebraic Field + User basis matrix: + [ 1 1.289897948556636? 1.579795897113272?]) ] + + sage: es = A.eigenspaces_left(format='galois'); es # optional - sage.rings.number_field + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1]), + (a1, + Vector space of degree 3 and dimension 1 over + Number Field in a1 with defining polynomial x^2 - 12*x - 18 + User basis matrix: + [ 1 1/15*a1 + 2/5 2/15*a1 - 1/5]) ] + sage: es = A.eigenspaces_left(format='galois', # optional - sage.rings.number_field + ....: algebraic_multiplicity=True); es + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1], + 1), + (a1, + Vector space of degree 3 and dimension 1 over + Number Field in a1 with defining polynomial x^2 - 12*x - 18 + User basis matrix: + [ 1 1/15*a1 + 2/5 2/15*a1 - 1/5], + 1) ] + sage: e, v, n = es[0]; v = v.basis()[0] # optional - sage.rings.number_field + sage: delta = e*v - v*A # optional - sage.rings.number_field + sage: abs(abs(delta)) < 1e-10 # optional - sage.rings.number_field True The same computation, but with implicit base change to a field. :: - sage: A = matrix(ZZ,3,3,range(9)); A + sage: A = matrix(ZZ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: A.eigenspaces_left(format='galois') - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1]), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 - 12*x - 18 - User basis matrix: - [ 1 1/15*a1 + 2/5 2/15*a1 - 1/5]) - ] + sage: A.eigenspaces_left(format='galois') # optional - sage.rings.number_field + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1]), + (a1, + Vector space of degree 3 and dimension 1 over + Number Field in a1 with defining polynomial x^2 - 12*x - 18 + User basis matrix: + [ 1 1/15*a1 + 2/5 2/15*a1 - 1/5]) ] We compute the left eigenspaces of the matrix of the Hecke operator `T_2` on level 43 modular symbols, both with all eigenvalues (the default) @@ -6180,61 +6230,72 @@ cdef class Matrix(Matrix1): sage: factor(f) (x - 3) * (x + 2)^2 * (x^2 - 2)^2 sage: A.eigenspaces_left(algebraic_multiplicity=True) - [ - (3, Vector space of degree 7 and dimension 1 over Rational Field - User basis matrix: - [ 1 0 1/7 0 -1/7 0 -2/7], 1), - (-2, Vector space of degree 7 and dimension 2 over Rational Field - User basis matrix: - [ 0 1 0 1 -1 1 -1] - [ 0 0 1 0 -1 2 -1], 2), - (-1.414213562373095?, Vector space of degree 7 and dimension 2 over Algebraic Field - User basis matrix: - [ 0 1 0 -1 0.4142135623730951? 1 -1] - [ 0 0 1 0 -1 0 2.414213562373095?], 2), - (1.414213562373095?, Vector space of degree 7 and dimension 2 over Algebraic Field - User basis matrix: - [ 0 1 0 -1 -2.414213562373095? 1 -1] - [ 0 0 1 0 -1 0 -0.4142135623730951?], 2) - ] + [ (3, + Vector space of degree 7 and dimension 1 over Rational Field + User basis matrix: + [ 1 0 1/7 0 -1/7 0 -2/7], + 1), + (-2, + Vector space of degree 7 and dimension 2 over Rational Field + User basis matrix: + [ 0 1 0 1 -1 1 -1] + [ 0 0 1 0 -1 2 -1], + 2), + (-1.414213562373095?, + Vector space of degree 7 and dimension 2 over Algebraic Field + User basis matrix: + [ 0 1 0 -1 0.4142135623730951? 1 -1] + [ 0 0 1 0 -1 0 2.414213562373095?], + 2), + (1.414213562373095?, + Vector space of degree 7 and dimension 2 over Algebraic Field + User basis matrix: + [ 0 1 0 -1 -2.414213562373095? 1 -1] + [ 0 0 1 0 -1 0 -0.4142135623730951?], + 2) ] sage: A.eigenspaces_left(format='galois', algebraic_multiplicity=True) - [ - (3, Vector space of degree 7 and dimension 1 over Rational Field - User basis matrix: - [ 1 0 1/7 0 -1/7 0 -2/7], 1), - (-2, Vector space of degree 7 and dimension 2 over Rational Field - User basis matrix: - [ 0 1 0 1 -1 1 -1] - [ 0 0 1 0 -1 2 -1], 2), - (a2, Vector space of degree 7 and dimension 2 over Number Field in a2 with defining polynomial x^2 - 2 - User basis matrix: - [ 0 1 0 -1 -a2 - 1 1 -1] - [ 0 0 1 0 -1 0 -a2 + 1], 2) - ] + [ (3, + Vector space of degree 7 and dimension 1 over Rational Field + User basis matrix: + [ 1 0 1/7 0 -1/7 0 -2/7], + 1), + (-2, + Vector space of degree 7 and dimension 2 over Rational Field + User basis matrix: + [ 0 1 0 1 -1 1 -1] + [ 0 0 1 0 -1 2 -1], + 2), + (a2, + Vector space of degree 7 and dimension 2 + over Number Field in a2 with defining polynomial x^2 - 2 + User basis matrix: + [ 0 1 0 -1 -a2 - 1 1 -1] + [ 0 0 1 0 -1 0 -a2 + 1], + 2) ] Next we compute the left eigenspaces over the finite field of order 11. :: - sage: A = ModularSymbols(43, base_ring=GF(11), sign=1).T(2).matrix(); A + sage: A = ModularSymbols(43, base_ring=GF(11), sign=1).T(2).matrix(); A # optional - sage.rings.finite_rings [ 3 0 9 0] [ 0 9 0 10] [ 0 0 10 1] [ 0 0 1 1] - sage: A.base_ring() + sage: A.base_ring() # optional - sage.rings.finite_rings Finite Field of size 11 - sage: A.charpoly() + sage: A.charpoly() # optional - sage.rings.finite_rings x^4 + 10*x^3 + 3*x^2 + 2*x + 1 - sage: A.eigenspaces_left(format='galois', var = 'beta') - [ - (9, Vector space of degree 4 and dimension 1 over Finite Field of size 11 - User basis matrix: - [0 1 5 6]), - (3, Vector space of degree 4 and dimension 1 over Finite Field of size 11 - User basis matrix: - [1 0 1 6]), - (beta2, Vector space of degree 4 and dimension 1 over Univariate Quotient Polynomial Ring in beta2 over Finite Field of size 11 with modulus x^2 + 9 - User basis matrix: - [ 0 0 1 beta2 + 1]) - ] + sage: A.eigenspaces_left(format='galois', var='beta') # optional - sage.rings.finite_rings + [ (9, + Vector space of degree 4 and dimension 1 over Finite Field of size 11 + User basis matrix: [0 1 5 6]), + (3, + Vector space of degree 4 and dimension 1 over Finite Field of size 11 + User basis matrix: [1 0 1 6]), + (beta2, + Vector space of degree 4 and dimension 1 + over Univariate Quotient Polynomial Ring in beta2 + over Finite Field of size 11 with modulus x^2 + 9 + User basis matrix: [ 0 0 1 beta2 + 1]) ] This method is only applicable to exact matrices. The "eigenmatrix" routines for matrices with double-precision @@ -6248,11 +6309,12 @@ cdef class Matrix(Matrix1): sage: A.change_ring(RR).eigenspaces_left() Traceback (most recent call last): ... - NotImplementedError: eigenspaces cannot be computed reliably for inexact rings such as Real Field with 53 bits of precision, + NotImplementedError: eigenspaces cannot be computed reliably + for inexact rings such as Real Field with 53 bits of precision, consult numerical or symbolic matrix classes for other options sage: em = A.change_ring(RDF).eigenmatrix_left() - sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13 + sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13 [13.348469228349522 0.0 0.0] [ 0.0 -1.348469228349534 0.0] [ 0.0 0.0 0.0] @@ -6261,13 +6323,13 @@ cdef class Matrix(Matrix1): [ 0.897878732... 0.278434036... -0.341010658...] [ 0.408248290... -0.816496580... 0.408248290...] - sage: x, y = var('x y') - sage: S = matrix([[x, y], [y, 3*x^2]]) - sage: em = S.eigenmatrix_left() - sage: eigenvalues = em[0]; eigenvalues + sage: x, y = var('x y') # optional - sage.symbolic + sage: S = matrix([[x, y], [y, 3*x^2]]) # optional - sage.symbolic + sage: em = S.eigenmatrix_left() # optional - sage.symbolic + sage: eigenvalues = em[0]; eigenvalues # optional - sage.symbolic [3/2*x^2 + 1/2*x - 1/2*sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2) 0] [ 0 3/2*x^2 + 1/2*x + 1/2*sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2)] - sage: eigenvectors = em[1]; eigenvectors + sage: eigenvectors = em[1]; eigenvectors # optional - sage.symbolic [ 1 1/2*(3*x^2 - x - sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2))/y] [ 1 1/2*(3*x^2 - x + sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2))/y] @@ -6275,20 +6337,22 @@ cdef class Matrix(Matrix1): possible, will raise an error. Using the ``'galois'`` format option is more likely to be successful. :: - sage: F. = FiniteField(11^2) - sage: A = matrix(F, [[b + 1, b + 1], [10*b + 4, 5*b + 4]]) - sage: A.eigenspaces_left(format='all') + sage: F. = FiniteField(11^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[b + 1, b + 1], [10*b + 4, 5*b + 4]]) # optional - sage.rings.finite_rings + sage: A.eigenspaces_left(format='all') # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: unable to construct eigenspaces for eigenvalues outside the base field, try the keyword option: format='galois' - sage: A.eigenspaces_left(format='galois') - [ - (a0, Vector space of degree 2 and dimension 1 over Univariate Quotient Polynomial Ring in a0 over Finite Field in b of size 11^2 with modulus x^2 + (5*b + 6)*x + 8*b + 10 - User basis matrix: - [ 1 6*b*a0 + 3*b + 1]) - ] + sage: A.eigenspaces_left(format='galois') # optional - sage.rings.finite_rings + [ (a0, + Vector space of degree 2 and dimension 1 over + Univariate Quotient Polynomial Ring in a0 over + Finite Field in b of size 11^2 + with modulus x^2 + (5*b + 6)*x + 8*b + 10 + User basis matrix: + [ 1 6*b*a0 + 3*b + 1]) ] TESTS: @@ -6296,7 +6360,7 @@ cdef class Matrix(Matrix1): sage: M = ModularSymbols(Gamma1(23), sign=1) sage: m = M.cuspidal_subspace().hecke_matrix(2) - sage: [j*m==i[0]*j for i in m.eigenspaces_left(format='all') for j in i[1].basis()] # long time (4s) + sage: [j*m==i[0]*j for i in m.eigenspaces_left(format='all') for j in i[1].basis()] # long time (4s) [True, True, True, True, True, True, True, True, True, True, True, True] sage: B = matrix(QQ, 2, 3, range(6)) @@ -6449,43 +6513,49 @@ cdef class Matrix(Matrix1): We compute the right eigenspaces of a `3\times 3` rational matrix. :: - sage: A = matrix(QQ, 3 ,3, range(9)); A + sage: A = matrix(QQ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: A.eigenspaces_right() - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1]), - (-1.348469228349535?, Vector space of degree 3 and dimension 1 over Algebraic Field - User basis matrix: - [ 1 0.1303061543300932? -0.7393876913398137?]), - (13.34846922834954?, Vector space of degree 3 and dimension 1 over Algebraic Field - User basis matrix: - [ 1 3.069693845669907? 5.139387691339814?]) - ] - sage: es = A.eigenspaces_right(format='galois'); es - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1]), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 - 12*x - 18 - User basis matrix: - [ 1 1/5*a1 + 2/5 2/5*a1 - 1/5]) - ] - sage: es = A.eigenspaces_right(format='galois', algebraic_multiplicity=True); es - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1], 1), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 - 12*x - 18 - User basis matrix: - [ 1 1/5*a1 + 2/5 2/5*a1 - 1/5], 1) - ] - sage: e, v, n = es[0]; v = v.basis()[0] - sage: delta = v*e - A*v - sage: abs(abs(delta)) < 1e-10 + sage: A.eigenspaces_right() # optional - sage.rings.number_field + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1]), + (-1.348469228349535?, + Vector space of degree 3 and dimension 1 over Algebraic Field + User basis matrix: + [ 1 0.1303061543300932? -0.7393876913398137?]), + (13.34846922834954?, + Vector space of degree 3 and dimension 1 over Algebraic Field + User basis matrix: + [ 1 3.069693845669907? 5.139387691339814?]) ] + sage: es = A.eigenspaces_right(format='galois'); es # optional - sage.rings.number_field + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1]), + (a1, + Vector space of degree 3 and dimension 1 over + Number Field in a1 with defining polynomial x^2 - 12*x - 18 + User basis matrix: + [ 1 1/5*a1 + 2/5 2/5*a1 - 1/5]) ] + sage: es = A.eigenspaces_right(format='galois', # optional - sage.rings.number_field + ....: algebraic_multiplicity=True); es + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1], + 1), + (a1, + Vector space of degree 3 and dimension 1 over + Number Field in a1 with defining polynomial x^2 - 12*x - 18 + User basis matrix: + [ 1 1/5*a1 + 2/5 2/5*a1 - 1/5], + 1) ] + sage: e, v, n = es[0]; v = v.basis()[0] # optional - sage.rings.number_field + sage: delta = v*e - A*v # optional - sage.rings.number_field + sage: abs(abs(delta)) < 1e-10 # optional - sage.rings.number_field True The same computation, but with implicit base change to a field:: @@ -6494,15 +6564,16 @@ cdef class Matrix(Matrix1): [0 1 2] [3 4 5] [6 7 8] - sage: A.eigenspaces_right(format='galois') - [ - (0, Vector space of degree 3 and dimension 1 over Rational Field - User basis matrix: - [ 1 -2 1]), - (a1, Vector space of degree 3 and dimension 1 over Number Field in a1 with defining polynomial x^2 - 12*x - 18 - User basis matrix: - [ 1 1/5*a1 + 2/5 2/5*a1 - 1/5]) - ] + sage: A.eigenspaces_right(format='galois') # optional - sage.rings.number_field + [ (0, + Vector space of degree 3 and dimension 1 over Rational Field + User basis matrix: + [ 1 -2 1]), + (a1, + Vector space of degree 3 and dimension 1 over + Number Field in a1 with defining polynomial x^2 - 12*x - 18 + User basis matrix: + [ 1 1/5*a1 + 2/5 2/5*a1 - 1/5]) ] This method is only applicable to exact matrices. The "eigenmatrix" routines for matrices with double-precision @@ -6516,11 +6587,12 @@ cdef class Matrix(Matrix1): sage: B.eigenspaces_right() Traceback (most recent call last): ... - NotImplementedError: eigenspaces cannot be computed reliably for inexact rings such as Real Field with 53 bits of precision, + NotImplementedError: eigenspaces cannot be computed reliably + for inexact rings such as Real Field with 53 bits of precision, consult numerical or symbolic matrix classes for other options sage: em = B.change_ring(RDF).eigenmatrix_right() - sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13 + sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13 [13.348469228349522 0.0 0.0] [ 0.0 -1.348469228349534 0.0] [ 0.0 0.0 0.0] @@ -6529,13 +6601,13 @@ cdef class Matrix(Matrix1): [ 0.505774475... 0.104205787... -0.816496580...] [ 0.846785134... -0.591288087... 0.408248290...] - sage: x, y = var('x y') - sage: S = matrix([[x, y], [y, 3*x^2]]) - sage: em = S.eigenmatrix_right() - sage: eigenvalues = em[0]; eigenvalues + sage: x, y = var('x y') # optional - sage.symbolic + sage: S = matrix([[x, y], [y, 3*x^2]]) # optional - sage.symbolic + sage: em = S.eigenmatrix_right() # optional - sage.symbolic + sage: eigenvalues = em[0]; eigenvalues # optional - sage.symbolic [3/2*x^2 + 1/2*x - 1/2*sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2) 0] [ 0 3/2*x^2 + 1/2*x + 1/2*sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2)] - sage: eigenvectors = em[1]; eigenvectors + sage: eigenvectors = em[1]; eigenvectors # optional - sage.symbolic [ 1 1] [1/2*(3*x^2 - x - sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2))/y 1/2*(3*x^2 - x + sqrt(9*x^4 - 6*x^3 + x^2 + 4*y^2))/y] @@ -6589,11 +6661,11 @@ cdef class Matrix(Matrix1): right_eigenspaces = eigenspaces_right - def eigenvalues(self,extend=True): + def eigenvalues(self, extend=True): r""" Return a sequence of the eigenvalues of a matrix, with - multiplicity. If the eigenvalues are roots of polynomials in QQ, - then QQbar elements are returned that represent each separate + multiplicity. If the eigenvalues are roots of polynomials in ``QQ``, + then ``QQbar`` elements are returned that represent each separate root. If the option extend is set to False, only eigenvalues in the base @@ -6606,33 +6678,40 @@ cdef class Matrix(Matrix1): [ 4 5 6 7] [ 8 9 10 11] [12 13 14 15] - sage: sorted(a.eigenvalues(), reverse=True) + sage: sorted(a.eigenvalues(), reverse=True) # optional - sage.rings.number_field [32.46424919657298?, 0, 0, -2.464249196572981?] :: - sage: a=matrix([(1, 9, -1, -1), (-2, 0, -10, 2), (-1, 0, 15, -2), (0, 1, 0, -1)]) - sage: a.eigenvalues() - [-0.9386318578049146?, 15.50655435353258?, 0.2160387521361705? - 4.713151979747493?*I, 0.2160387521361705? + 4.713151979747493?*I] + sage: a = matrix([(1, 9, -1, -1), + ....: (-2, 0, -10, 2), + ....: (-1, 0, 15, -2), + ....: (0, 1, 0, -1)]) + sage: a.eigenvalues() # optional - sage.rings.number_field + [-0.9386318578049146?, + 15.50655435353258?, + 0.2160387521361705? - 4.713151979747493?*I, + 0.2160387521361705? + 4.713151979747493?*I] - A symmetric matrix a+a.transpose() should have real eigenvalues + A symmetric matrix ``a + a.transpose()`` should have real eigenvalues :: - sage: b=a+a.transpose() - sage: ev = b.eigenvalues(); ev - [-8.35066086057957?, -1.107247901349379?, 5.718651326708515?, 33.73925743522043?] + sage: b = a + a.transpose() + sage: ev = b.eigenvalues(); ev # optional - sage.rings.number_field + [-8.35066086057957?, -1.107247901349379?, + 5.718651326708515?, 33.73925743522043?] - The eigenvalues are elements of QQbar, so they really represent + The eigenvalues are elements of ``QQbar``, so they really represent exact roots of polynomials, not just approximations. :: - sage: e = ev[0]; e + sage: e = ev[0]; e # optional - sage.rings.number_field -8.35066086057957? - sage: p = e.minpoly(); p + sage: p = e.minpoly(); p # optional - sage.rings.number_field x^4 - 30*x^3 - 171*x^2 + 1460*x + 1784 - sage: p(e) == 0 + sage: p(e) == 0 # optional - sage.rings.number_field True To perform computations on the eigenvalue as an element of a number @@ -6640,42 +6719,46 @@ cdef class Matrix(Matrix1): :: - sage: e.as_number_field_element() - (Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264, + sage: e.as_number_field_element() # optional - sage.rings.number_field + (Number Field in a + with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264, a + 7, Ring morphism: - From: Number Field in a with defining polynomial y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264 + From: Number Field in a with defining polynomial + y^4 - 2*y^3 - 507*y^2 - 3972*y - 4264 To: Algebraic Real Field Defn: a |--> -15.35066086057957?) - Notice the effect of the extend option. + Notice the effect of the ``extend`` option. :: - sage: M=matrix(QQ,[[0,-1,0],[1,0,0],[0,0,2]]) - sage: M.eigenvalues() + sage: M = matrix(QQ, [[0,-1,0], [1,0,0], [0,0,2]]) + sage: M.eigenvalues() # optional - sage.rings.number_field [2, -1*I, 1*I] - sage: M.eigenvalues(extend=False) + sage: M.eigenvalues(extend=False) # optional - sage.rings.number_field [2] The method also works for matrices over finite fields:: - sage: M = matrix(GF(3), [[0,1,1],[1,2,0],[2,0,1]]) - sage: ev = sorted(M.eigenvalues()); ev + sage: M = matrix(GF(3), [[0,1,1], [1,2,0], [2,0,1]]) # optional - sage.rings.finite_rings + sage: ev = sorted(M.eigenvalues()); ev # optional - sage.rings.finite_rings [2*z3, 2*z3 + 1, 2*z3 + 2] - Similarly as in the case of QQbar, the eigenvalues belong to some + Similarly as in the case of ``QQbar``, the eigenvalues belong to some algebraic closure but they can be converted to elements of a finite field:: - sage: e = ev[0] - sage: e.parent() + sage: e = ev[0] # optional - sage.rings.finite_rings + sage: e.parent() # optional - sage.rings.finite_rings Algebraic closure of Finite Field of size 3 - sage: e.as_finite_field_element() - (Finite Field in z3 of size 3^3, 2*z3, Ring morphism: - From: Finite Field in z3 of size 3^3 - To: Algebraic closure of Finite Field of size 3 - Defn: z3 |--> z3) + sage: e.as_finite_field_element() # optional - sage.rings.finite_rings + (Finite Field in z3 of size 3^3, + 2*z3, + Ring morphism: + From: Finite Field in z3 of size 3^3 + To: Algebraic closure of Finite Field of size 3 + Defn: z3 |--> z3) """ x = self.fetch('eigenvalues') if x is not None: @@ -6744,31 +6827,29 @@ cdef class Matrix(Matrix1): :: - sage: A = matrix(QQ,3,3,range(9)); A + sage: A = matrix(QQ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: es = A.eigenvectors_left(); es - [(0, [ - (1, -2, 1) - ], 1), - (-1.348469228349535?, [(1, 0.3101020514433644?, -0.3797958971132713?)], 1), - (13.34846922834954?, [(1, 1.289897948556636?, 1.579795897113272?)], 1)] - sage: eval, [evec], mult = es[0] - sage: delta = eval*evec - evec*A - sage: abs(abs(delta)) < 1e-10 + sage: es = A.eigenvectors_left(); es # optional - sage.rings.number_field + [(0, [ (1, -2, 1) ], 1), + (-1.348469228349535?, [(1, 0.3101020514433644?, -0.3797958971132713?)], 1), + (13.34846922834954?, [(1, 1.289897948556636?, 1.579795897113272?)], 1)] + sage: eval, [evec], mult = es[0] # optional - sage.rings.number_field + sage: delta = eval*evec - evec*A # optional - sage.rings.number_field + sage: abs(abs(delta)) < 1e-10 # optional - sage.rings.number_field True Notice the difference between considering ring extensions or not. :: - sage: M=matrix(QQ,[[0,-1,0],[1,0,0],[0,0,2]]) - sage: M.eigenvectors_left() - [(2, [ - (0, 0, 1) - ], 1), (-1*I, [(1, -1*I, 0)], 1), (1*I, [(1, 1*I, 0)], 1)] - sage: M.eigenvectors_left(extend=False) + sage: M = matrix(QQ, [[0,-1,0], [1,0,0], [0,0,2]]) + sage: M.eigenvectors_left() # optional - sage.rings.number_field + [(2, [ (0, 0, 1) ], 1), + (-1*I, [(1, -1*I, 0)], 1), + (1*I, [(1, 1*I, 0)], 1)] + sage: M.eigenvectors_left(extend=False) # optional - sage.rings.number_field [(2, [ (0, 0, 1) ], 1)] @@ -6785,16 +6866,16 @@ cdef class Matrix(Matrix1): Check the deprecation:: - sage: matrix(QQ, [[1, 2], [3, 4]]).eigenvectors_left(False) + sage: matrix(QQ, [[1, 2], [3, 4]]).eigenvectors_left(False) # optional - sage.rings.number_field doctest:...: DeprecationWarning: "extend" should be used as keyword argument See https://github.com/sagemath/sage/issues/29243 for details. [] Check :trac:`30518`:: - sage: K. = QuadraticField(-1) - sage: m = matrix(K, 4, [2,4*i,-i,0, -4*i,2,-1,0, 2*i,-2,0,0, 4*i+4, 4*i-4,1-i,-2]) - sage: assert all(m*v == e*v for e, vs, _ in m.eigenvectors_right() for v in vs) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: m = matrix(K, 4, [2,4*i,-i,0, -4*i,2,-1,0, 2*i,-2,0,0, 4*i+4, 4*i-4,1-i,-2]) # optional - sage.rings.number_field + sage: assert all(m*v == e*v for e, vs, _ in m.eigenvectors_right() for v in vs) # optional - sage.rings.number_field """ if other is not None: if isinstance(other, bool): @@ -6878,23 +6959,21 @@ cdef class Matrix(Matrix1): :: - sage: A = matrix(QQ,3,3,range(9)); A + sage: A = matrix(QQ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: es = A.eigenvectors_right(); es - [(0, [ - (1, -2, 1) - ], 1), - (-1.348469228349535?, [(1, 0.1303061543300932?, -0.7393876913398137?)], 1), - (13.34846922834954?, [(1, 3.069693845669907?, 5.139387691339814?)], 1)] - sage: A.eigenvectors_right(extend=False) + sage: es = A.eigenvectors_right(); es # optional - sage.rings.number_field + [(0, [ (1, -2, 1) ], 1), + (-1.348469228349535?, [(1, 0.1303061543300932?, -0.7393876913398137?)], 1), + (13.34846922834954?, [(1, 3.069693845669907?, 5.139387691339814?)], 1)] + sage: A.eigenvectors_right(extend=False) # optional - sage.rings.number_field [(0, [ (1, -2, 1) ], 1)] - sage: eval, [evec], mult = es[0] - sage: delta = eval*evec - A*evec - sage: abs(abs(delta)) < 1e-10 + sage: eval, [evec], mult = es[0] # optional - sage.rings.number_field + sage: delta = eval*evec - A*evec # optional - sage.rings.number_field + sage: abs(abs(delta)) < 1e-10 # optional - sage.rings.number_field True TESTS:: @@ -6950,27 +7029,27 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,3,3,range(9)); A + sage: A = matrix(QQ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: D, P = A.eigenmatrix_left() - sage: D + sage: D, P = A.eigenmatrix_left() # optional - sage.rings.number_field + sage: D # optional - sage.rings.number_field [ 0 0 0] [ 0 -1.348469228349535? 0] [ 0 0 13.34846922834954?] - sage: P + sage: P # optional - sage.rings.number_field [ 1 -2 1] [ 1 0.3101020514433644? -0.3797958971132713?] [ 1 1.289897948556636? 1.579795897113272?] - sage: P*A == D*P + sage: P*A == D*P # optional - sage.rings.number_field True Because `P` is invertible, `A` is diagonalizable. :: - sage: A == (~P)*D*P + sage: A == (~P)*D*P # optional - sage.rings.number_field True The matrix `P` may contain zero rows corresponding to eigenvalues for @@ -6979,20 +7058,20 @@ cdef class Matrix(Matrix1): :: - sage: A = jordan_block(2,3); A + sage: A = jordan_block(2, 3); A [2 1 0] [0 2 1] [0 0 2] - sage: D, P = A.eigenmatrix_left() - sage: D + sage: D, P = A.eigenmatrix_left() # optional - sage.rings.number_field + sage: D # optional - sage.rings.number_field [2 0 0] [0 2 0] [0 0 2] - sage: P + sage: P # optional - sage.rings.number_field [0 0 1] [0 0 0] [0 0 0] - sage: P*A == D*P + sage: P*A == D*P # optional - sage.rings.number_field True A generalized eigenvector decomposition:: @@ -7041,7 +7120,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(QQ, 3, 3, range(9)) sage: em = A.change_ring(RDF).eigenmatrix_left() - sage: evalues = em[0]; evalues.dense_matrix() # abs tol 1e-13 + sage: evalues = em[0]; evalues.dense_matrix() # abs tol 1e-13 [13.348469228349522 0.0 0.0] [ 0.0 -1.348469228349534 0.0] [ 0.0 0.0 0.0] @@ -7077,21 +7156,23 @@ cdef class Matrix(Matrix1): the algebraic multiplicity. The following examples show that these cases are detected (:trac:`27842`):: - sage: A = matrix(SR, [(225/548, 0, -175/274*sqrt(193/1446)), # optional - sage.symbolic + sage: A = matrix(SR, [(225/548, 0, -175/274*sqrt(193/1446)), # optional - sage.symbolic ....: (0, 1/2, 0), ....: (-63/548*sqrt(723/386), 0, 49/548)]) - sage: A.eigenmatrix_left() # optional - sage.symbolic + sage: A.eigenmatrix_left() # optional - sage.symbolic Traceback (most recent call last): ... - RuntimeError: failed to compute eigenvectors for eigenvalue ..., check eigenvectors_left() for partial results - sage: B = matrix(SR, [(1/2, -7/2*sqrt(1/386), 0, 49/2*sqrt(1/279078)), # optional - sage.symbolic + RuntimeError: failed to compute eigenvectors for eigenvalue ..., + check eigenvectors_left() for partial results + sage: B = matrix(SR, [(1/2, -7/2*sqrt(1/386), 0, 49/2*sqrt(1/279078)), # optional - sage.symbolic ....: (-7/2*sqrt(1/386), 211/772, 0, -8425/772*sqrt(1/723)), ....: (0, 0, 1/2, 0), ....: (49/2*sqrt(1/279078), -8425/772*sqrt(1/723), 0, 561/772)]) - sage: B.eigenmatrix_left() # long time (1.2 seconds) # optional - sage.symbolic + sage: B.eigenmatrix_left() # long time (1.2 seconds) # optional - sage.symbolic Traceback (most recent call last): ... - RuntimeError: failed to compute eigenvectors for eigenvalue ..., check eigenvectors_left() for partial results + RuntimeError: failed to compute eigenvectors for eigenvalue ..., + check eigenvectors_left() for partial results The following example shows that :trac:`12595` has been resolved:: @@ -7166,27 +7247,27 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQ,3,3,range(9)); A + sage: A = matrix(QQ, 3, 3, range(9)); A [0 1 2] [3 4 5] [6 7 8] - sage: D, P = A.eigenmatrix_right() - sage: D + sage: D, P = A.eigenmatrix_right() # optional - sage.rings.number_field + sage: D # optional - sage.rings.number_field [ 0 0 0] [ 0 -1.348469228349535? 0] [ 0 0 13.34846922834954?] - sage: P + sage: P # optional - sage.rings.number_field [ 1 1 1] [ -2 0.1303061543300932? 3.069693845669907?] [ 1 -0.7393876913398137? 5.139387691339814?] - sage: A*P == P*D + sage: A*P == P*D # optional - sage.rings.number_field True Because `P` is invertible, `A` is diagonalizable. :: - sage: A == P*D*(~P) + sage: A == P*D*(~P) # optional - sage.rings.number_field True The matrix `P` may contain zero columns corresponding to eigenvalues @@ -7195,20 +7276,20 @@ cdef class Matrix(Matrix1): :: - sage: A = jordan_block(2,3); A + sage: A = jordan_block(2, 3); A [2 1 0] [0 2 1] [0 0 2] - sage: D, P = A.eigenmatrix_right() - sage: D + sage: D, P = A.eigenmatrix_right() # optional - sage.rings.number_field + sage: D # optional - sage.rings.number_field [2 0 0] [0 2 0] [0 0 2] - sage: P + sage: P # optional - sage.rings.number_field [1 0 0] [0 0 0] [0 0 0] - sage: A*P == P*D + sage: A*P == P*D # optional - sage.rings.number_field True A generalized eigenvector decomposition:: @@ -7308,8 +7389,8 @@ cdef class Matrix(Matrix1): sage: M.eigenvalue_multiplicity(1) 0 - sage: M = posets.DiamondPoset(5).coxeter_transformation() - sage: [M.eigenvalue_multiplicity(x) for x in [-1, 1]] + sage: M = posets.DiamondPoset(5).coxeter_transformation() # optional - sage.combinat, sage.graphs + sage: [M.eigenvalue_multiplicity(x) for x in [-1, 1]] # optional - sage.combinat, sage.graphs [3, 2] TESTS:: @@ -7362,7 +7443,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A=matrix(3,range(9)); A + sage: A = matrix(3, range(9)); A [0 1 2] [3 4 5] [6 7 8] @@ -7405,8 +7486,8 @@ cdef class Matrix(Matrix1): Since :meth:`echelon_form` is not implemented for every ring, sometimes behavior varies, as here:: - sage: R.=ZZ[] - sage: C = matrix(3,[2,x,x^2,x+1,3-x,-1,3,2,1]) + sage: R. = ZZ[] + sage: C = matrix(3, [2,x,x^2, x+1,3-x,-1, 3,2,1]) sage: C.rref() [1 0 0] [0 1 0] @@ -7416,9 +7497,11 @@ cdef class Matrix(Matrix1): sage: C.echelon_form() Traceback (most recent call last): ... - NotImplementedError: Ideal Ideal (2, x + 1) of Univariate Polynomial Ring in x over Integer Ring not principal - Echelon form not implemented over 'Univariate Polynomial Ring in x over Integer Ring'. - sage: C = matrix(3,[2,x,x^2,x+1,3-x,-1,3,2,1/2]) + NotImplementedError: Ideal Ideal (2, x + 1) of Univariate + Polynomial Ring in x over Integer Ring not principal + Echelon form not implemented over 'Univariate + Polynomial Ring in x over Integer Ring'. + sage: C = matrix(3, [2,x,x^2, x+1,3-x,-1, 3,2,1/2]) sage: C.echelon_form() [ 2 x x^2] [ 0 1 15*x^2 - 3/2*x - 31/2] @@ -7427,7 +7510,7 @@ cdef class Matrix(Matrix1): [1 0 0] [0 1 0] [0 0 1] - sage: C = matrix(3,[2,x,x^2,x+1,3-x,-1/x,3,2,1/2]) + sage: C = matrix(3, [2,x,x^2, x+1,3-x,-1/x, 3,2,1/2]) sage: C.echelon_form() [1 0 0] [0 1 0] @@ -7462,18 +7545,18 @@ cdef class Matrix(Matrix1): [ 0 4 8 12] [ 0 0 0 0] - sage: L. = NumberField(x^2 - x + 2) - sage: OL = L.ring_of_integers() - sage: m = matrix(OL, 2, 2, [1,2,3,4+w]) - sage: m.echelon_form() + sage: L. = NumberField(x^2 - x + 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers() # optional - sage.rings.number_field + sage: m = matrix(OL, 2, 2, [1,2,3,4+w]) # optional - sage.rings.number_field + sage: m.echelon_form() # optional - sage.rings.number_field [ 1 2] [ 0 w - 2] - sage: E, T = m.echelon_form(transformation=True); E,T + sage: E, T = m.echelon_form(transformation=True); E, T # optional - sage.rings.number_field ( [ 1 2] [ 1 0] [ 0 w - 2], [-3 1] ) - sage: E == T*m + sage: E == T*m # optional - sage.rings.number_field True TESTS: @@ -7575,7 +7658,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: a = matrix(QQ,3,3,range(9)); a + sage: a = matrix(QQ, 3,3, range(9)); a [0 1 2] [3 4 5] [6 7 8] @@ -7588,7 +7671,7 @@ cdef class Matrix(Matrix1): An immutable matrix cannot be transformed into echelon form. Use ``self.echelon_form()`` instead:: - sage: a = matrix(QQ,3,3,range(9)); a.set_immutable() + sage: a = matrix(QQ, 3,3, range(9)); a.set_immutable() sage: a.echelonize() Traceback (most recent call last): ... @@ -7602,7 +7685,7 @@ cdef class Matrix(Matrix1): Echelon form over the integers is what is also classically often known as Hermite normal form:: - sage: a = matrix(ZZ,3,3,range(9)) + sage: a = matrix(ZZ, 3,3, range(9)) sage: a.echelonize(); a [ 3 0 -3] [ 0 1 2] @@ -7611,7 +7694,7 @@ cdef class Matrix(Matrix1): We compute an echelon form both over a domain and fraction field:: sage: R. = QQ[] - sage: a = matrix(R, 2, [x,y,x,y]) + sage: a = matrix(R, 2, [x,y, x,y]) sage: a.echelon_form() # not very useful? -- why two copies of the same row? [x y] [x y] @@ -7626,21 +7709,21 @@ cdef class Matrix(Matrix1): We check that the echelon form works for matrices over p-adics. See :trac:`17272`:: - sage: R = ZpCA(5,5,print_mode='val-unit') - sage: A = matrix(R,3,3,[250,2369,1147,106,927,362,90,398,2483]) - sage: A + sage: R = ZpCA(5,5,print_mode='val-unit') # optional - sage.rings.padics + sage: A = matrix(R, 3,3, [250,2369,1147, 106,927,362, 90,398,2483]) # optional - sage.rings.padics + sage: A # optional - sage.rings.padics [5^3 * 2 + O(5^5) 2369 + O(5^5) 1147 + O(5^5)] [ 106 + O(5^5) 927 + O(5^5) 362 + O(5^5)] [ 5 * 18 + O(5^5) 398 + O(5^5) 2483 + O(5^5)] - sage: K = R.fraction_field() - sage: A.change_ring(K).augment(identity_matrix(K,3)).echelon_form() + sage: K = R.fraction_field() # optional - sage.rings.padics + sage: A.change_ring(K).augment(identity_matrix(K,3)).echelon_form() # optional - sage.rings.padics [ 1 + O(5^5) O(5^5) O(5^5) 5 * 212 + O(5^5) 3031 + O(5^5) 2201 + O(5^5)] [ O(5^5) 1 + O(5^5) O(5^5) 1348 + O(5^5) 5 * 306 + O(5^5) 2648 + O(5^5)] [ O(5^5) O(5^5) 1 + O(5^5) 1987 + O(5^5) 5 * 263 + O(5^5) 154 + O(5^5)] Echelon form is not defined over arbitrary rings:: - sage: a = matrix(Integers(9),3,3,range(9)) + sage: a = matrix(Integers(9), 3,3, range(9)) sage: a.echelon_form() Traceback (most recent call last): ... @@ -7672,8 +7755,8 @@ cdef class Matrix(Matrix1): Check that :trac:`34724` is fixed (indirect doctest):: - sage: a=6.12323399573677e-17 - sage: m=matrix(RR,[[-a, -1.72508242466029], [ 0.579682446302195, a]]) + sage: a = 6.12323399573677e-17 + sage: m = matrix(RR, [[-a, -1.72508242466029], [ 0.579682446302195, a]]) sage: (~m*m).norm() 1.0 """ @@ -7769,13 +7852,13 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: MS = MatrixSpace(GF(19),2,3) - sage: C = MS.matrix([1,2,3,4,5,6]) - sage: C.rank() + sage: MS = MatrixSpace(GF(19), 2, 3) # optional - sage.rings.finite_rings + sage: C = MS.matrix([1,2,3,4,5,6]) # optional - sage.rings.finite_rings + sage: C.rank() # optional - sage.rings.finite_rings 2 - sage: C.nullity() + sage: C.nullity() # optional - sage.rings.finite_rings 0 - sage: C.echelon_form() + sage: C.echelon_form() # optional - sage.rings.finite_rings [ 1 0 18] [ 0 1 2] @@ -7783,7 +7866,7 @@ cdef class Matrix(Matrix1): the transformation matrix, so the ``transformation`` option is ignored:: - sage: C.echelon_form(transformation=True) + sage: C.echelon_form(transformation=True) # optional - sage.rings.finite_rings [ 1 0 18] [ 0 1 2] @@ -7835,17 +7918,17 @@ cdef class Matrix(Matrix1): [ 1 0 -1] [ 0 1 2] [ 0 0 0] - sage: a = matrix(QQ,2,[1..6]) + sage: a = matrix(QQ, 2, [1..6]) sage: a._echelon('classical') [ 1 0 -1] [ 0 1 2] - sage: R = ZpCA(5,5,print_mode='val-unit') - sage: A = matrix(R,3,3,[250,2369,1147,106,927,362,90,398,2483]) - sage: A + sage: R = ZpCA(5, 5, print_mode='val-unit') # optional - sage.rings.padics + sage: A = matrix(R, 3, 3, [250,2369,1147, 106,927,362, 90,398,2483]) # optional - sage.rings.padics + sage: A # optional - sage.rings.padics [5^3 * 2 + O(5^5) 2369 + O(5^5) 1147 + O(5^5)] [ 106 + O(5^5) 927 + O(5^5) 362 + O(5^5)] [ 5 * 18 + O(5^5) 398 + O(5^5) 2483 + O(5^5)] - sage: A._echelon('partial_pivoting') + sage: A._echelon('partial_pivoting') # optional - sage.rings.padics [1 + O(5^5) O(5^5) O(5^5)] [ O(5^5) 1 + O(5^5) O(5^5)] [ O(5^5) O(5^5) 1 + O(5^5)] @@ -7893,7 +7976,7 @@ cdef class Matrix(Matrix1): [ 1 0 -1] [ 0 1 2] [ 0 0 0] - sage: a = matrix(QQ,2,[1..6]) + sage: a = matrix(QQ, 2, [1..6]) sage: a._echelon_classical() [ 1 0 -1] [ 0 1 2] @@ -7918,13 +8001,13 @@ cdef class Matrix(Matrix1): sage: P = a._echelon_in_place('classical'); a [ 1 0 -1] [ 0 1 2] - sage: R = ZpCA(5,5,print_mode='val-unit') - sage: A = matrix(R,3,3,[250,2369,1147,106,927,362,90,398,2483]) - sage: A + sage: R = ZpCA(5, 5, print_mode='val-unit') # optional - sage.rings.padics + sage: A = matrix(R,3,3,[250,2369,1147,106,927,362,90,398,2483]) # optional - sage.rings.padics + sage: A # optional - sage.rings.padics [5^3 * 2 + O(5^5) 2369 + O(5^5) 1147 + O(5^5)] [ 106 + O(5^5) 927 + O(5^5) 362 + O(5^5)] [ 5 * 18 + O(5^5) 398 + O(5^5) 2483 + O(5^5)] - sage: P = A._echelon_in_place('partial_pivoting'); A + sage: P = A._echelon_in_place('partial_pivoting'); A # optional - sage.rings.padics [1 + O(5^5) O(5^5) O(5^5)] [ O(5^5) 1 + O(5^5) O(5^5)] [ O(5^5) O(5^5) 1 + O(5^5)] @@ -8067,7 +8150,7 @@ cdef class Matrix(Matrix1): [ 1 0 -1] [ 0 1 2] [ 0 0 0] - sage: a = matrix(QQ,2,[1..6]) + sage: a = matrix(QQ, 2, [1..6]) sage: P = a._echelon_in_place_classical(); a [ 1 0 -1] [ 0 1 2] @@ -8209,20 +8292,20 @@ cdef class Matrix(Matrix1): Subdivided, or not, the result is immutable, so make a copy if you want to make changes. :: - sage: A = matrix(FiniteField(7), [[2,0,3], [5,5,3], [5,6,5]]) - sage: E = A.extended_echelon_form() - sage: E.is_mutable() + sage: A = matrix(FiniteField(7), [[2,0,3], [5,5,3], [5,6,5]]) # optional - sage.rings.finite_rings + sage: E = A.extended_echelon_form() # optional - sage.rings.finite_rings + sage: E.is_mutable() # optional - sage.rings.finite_rings False - sage: F = A.extended_echelon_form(subdivide=True) - sage: F + sage: F = A.extended_echelon_form(subdivide=True) # optional - sage.rings.finite_rings + sage: F # optional - sage.rings.finite_rings [1 0 0|0 4 6] [0 1 0|4 2 2] [0 0 1|5 2 3] [-----+-----] - sage: F.is_mutable() + sage: F.is_mutable() # optional - sage.rings.finite_rings False - sage: G = copy(F) - sage: G.subdivide([],[]); G + sage: G = copy(F) # optional - sage.rings.finite_rings + sage: G.subdivide([], []); G # optional - sage.rings.finite_rings [1 0 0 0 4 6] [0 1 0 4 2 2] [0 0 1 5 2 3] @@ -8296,14 +8379,14 @@ cdef class Matrix(Matrix1): [ 6 1/4] [ 8 -5] - sage: B = M.as_bipartite_graph() - sage: B + sage: B = M.as_bipartite_graph() # optional - sage.graphs + sage: B # optional - sage.graphs Bipartite graph on 5 vertices - sage: B.edges(sort=True) + sage: B.edges(sort=True) # optional - sage.graphs [(1, 4, 1/3), (1, 5, 7), (2, 4, 6), (2, 5, 1/4), (3, 4, 8), (3, 5, -5)] - sage: len(B.left) == M.nrows() + sage: len(B.left) == M.nrows() # optional - sage.graphs True - sage: len(B.right) == M.ncols() + sage: len(B.right) == M.ncols() # optional - sage.graphs True """ from sage.graphs.bipartite_graph import BipartiteGraph @@ -8325,23 +8408,23 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = matrix(ZZ,[[1,0],[1,0],[0,1]]) + sage: M = matrix(ZZ, [[1,0],[1,0],[0,1]]) sage: M [1 0] [1 0] [0 1] - sage: A = M.automorphisms_of_rows_and_columns() - sage: A + sage: A = M.automorphisms_of_rows_and_columns() # optional - sage.groups + sage: A # optional - sage.groups [((), ()), ((1,2), ())] - sage: M = matrix(ZZ,[[1,1,1,1],[1,1,1,1]]) - sage: A = M.automorphisms_of_rows_and_columns() - sage: len(A) + sage: M = matrix(ZZ, [[1,1,1,1],[1,1,1,1]]) # optional - sage.groups + sage: A = M.automorphisms_of_rows_and_columns() # optional - sage.groups + sage: len(A) # optional - sage.groups 48 One can now apply these automorphisms to ``M`` to show that it leaves it invariant:: - sage: all(M.with_permuted_rows_and_columns(*i) == M for i in A) + sage: all(M.with_permuted_rows_and_columns(*i) == M for i in A) # optional - sage.groups True Check that :trac:`25426` is fixed:: @@ -8351,7 +8434,7 @@ cdef class Matrix(Matrix1): ....: (1, 0, 3, 0, 2), ....: (0, 1, 0, 2, 1), ....: (0, 0, 2, 1, 2)]) - sage: j.automorphisms_of_rows_and_columns() + sage: j.automorphisms_of_rows_and_columns() # optional - sage.groups [((), ()), ((1,3)(2,5), (1,3)(2,5))] """ from sage.groups.perm_gps.constructor import \ @@ -8409,7 +8492,7 @@ cdef class Matrix(Matrix1): [-1 5] [ 2 4] - sage: M.permutation_normal_form(check=True) + sage: M.permutation_normal_form(check=True) # optional - sage.graphs ( [ 5 -1] [ 4 2] @@ -8420,7 +8503,7 @@ cdef class Matrix(Matrix1): TESTS:: sage: M = matrix(ZZ, [[3, 4, 5], [3, 4, 5], [3, 5, 4], [2, 0,1]]) - sage: M.permutation_normal_form() + sage: M.permutation_normal_form() # optional - sage.graphs [5 4 3] [5 4 3] [4 5 3] @@ -8561,47 +8644,47 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = matrix(ZZ,[[1,2,3],[3,5,3],[2,6,4]]) + sage: M = matrix(ZZ, [[1,2,3], [3,5,3], [2,6,4]]) sage: M [1 2 3] [3 5 3] [2 6 4] - sage: N = matrix(ZZ,[[1,2,3],[2,6,4],[3,5,3]]) + sage: N = matrix(ZZ, [[1,2,3], [2,6,4], [3,5,3]]) sage: N [1 2 3] [2 6 4] [3 5 3] - sage: M.is_permutation_of(N) + sage: M.is_permutation_of(N) # optional - sage.graphs True Some examples that are not permutations of each other:: - sage: N = matrix(ZZ,[[1,2,3],[4,5,6],[7,8,9]]) + sage: N = matrix(ZZ, [[1,2,3], [4,5,6], [7,8,9]]) sage: N [1 2 3] [4 5 6] [7 8 9] - sage: M.is_permutation_of(N) + sage: M.is_permutation_of(N) # optional - sage.graphs False - sage: N = matrix(ZZ,[[1,2],[3,4]]) + sage: N = matrix(ZZ, [[1,2], [3,4]]) sage: N [1 2] [3 4] - sage: M.is_permutation_of(N) + sage: M.is_permutation_of(N) # optional - sage.graphs False And for when ``check`` is True:: - sage: N = matrix(ZZ,[[3,5,3],[2,6,4],[1,2,3]]) + sage: N = matrix(ZZ, [[3,5,3], [2,6,4], [1,2,3]]) sage: N [3 5 3] [2 6 4] [1 2 3] - sage: r = M.is_permutation_of(N, check=True) - sage: r + sage: r = M.is_permutation_of(N, check=True) # optional - sage.graphs + sage: r # optional - sage.graphs (True, ((1,2,3), ())) - sage: p = r[1] - sage: M.with_permuted_rows_and_columns(*p) == N + sage: p = r[1] # optional - sage.graphs + sage: M.with_permuted_rows_and_columns(*p) == N # optional - sage.graphs True """ ncols = self.ncols() @@ -8647,7 +8730,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: a = matrix(ZZ,4,4,range(16)) + sage: a = matrix(ZZ, 4,4, range(16)) sage: a._multiply_strassen(a,2) [ 56 62 68 74] [152 174 196 218] @@ -8819,26 +8902,26 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = matrix(5, 5, prime_range(100)) - sage: M.subdivide(2,3); M + sage: M = matrix(5, 5, prime_range(100)) # optional - sage.libs.pari + sage: M.subdivide(2,3); M # optional - sage.libs.pari [ 2 3 5| 7 11] [13 17 19|23 29] [--------+-----] [31 37 41|43 47] [53 59 61|67 71] [73 79 83|89 97] - sage: M.subdivision(0,0) + sage: M.subdivision(0,0) # optional - sage.libs.pari [ 2 3 5] [13 17 19] - sage: M.subdivision(1,0) + sage: M.subdivision(1,0) # optional - sage.libs.pari [31 37 41] [53 59 61] [73 79 83] - sage: M.subdivision_entry(1,0,0,0) + sage: M.subdivision_entry(1,0,0,0) # optional - sage.libs.pari 31 - sage: M.subdivisions() + sage: M.subdivisions() # optional - sage.libs.pari ([2], [3]) - sage: M.subdivide(None, [1,3]); M + sage: M.subdivide(None, [1,3]); M # optional - sage.libs.pari [ 2| 3 5| 7 11] [13|17 19|23 29] [31|37 41|43 47] @@ -8847,7 +8930,7 @@ cdef class Matrix(Matrix1): Degenerate cases work too:: - sage: M.subdivide([2,5], [0,1,3]); M + sage: M.subdivide([2,5], [0,1,3]); M # optional - sage.libs.pari [| 2| 3 5| 7 11] [|13|17 19|23 29] [+--+-----+-----] @@ -8855,12 +8938,12 @@ cdef class Matrix(Matrix1): [|53|59 61|67 71] [|73|79 83|89 97] [+--+-----+-----] - sage: M.subdivision(0,0) + sage: M.subdivision(0,0) # optional - sage.libs.pari [] - sage: M.subdivision(0,1) + sage: M.subdivision(0,1) # optional - sage.libs.pari [ 2] [13] - sage: M.subdivide([2,2,3], [0,0,1,1]); M + sage: M.subdivide([2,2,3], [0,0,1,1]); M # optional - sage.libs.pari [|| 2|| 3 5 7 11] [||13||17 19 23 29] [++--++-----------] @@ -8869,14 +8952,14 @@ cdef class Matrix(Matrix1): [++--++-----------] [||53||59 61 67 71] [||73||79 83 89 97] - sage: M.subdivision(0,0) + sage: M.subdivision(0,0) # optional - sage.libs.pari [] - sage: M.subdivision(2,4) + sage: M.subdivision(2,4) # optional - sage.libs.pari [37 41 43 47] Indices do not need to be in the right order (:trac:`14064`):: - sage: M.subdivide([4, 2], [3, 1]); M + sage: M.subdivide([4, 2], [3, 1]); M # optional - sage.libs.pari [ 2| 3 5| 7 11] [13|17 19|23 29] [--+-----+-----] @@ -9200,15 +9283,17 @@ cdef class Matrix(Matrix1): Different base rings are handled sensibly. :: sage: A = matrix(ZZ, 2, 3, range(6)) - sage: B = matrix(FiniteField(23), 3, 4, range(12)) - sage: C = matrix(FiniteField(29), 4, 5, range(20)) - sage: D = A.tensor_product(B) - sage: D.parent() + sage: B = matrix(FiniteField(23), 3, 4, range(12)) # optional - sage.rings.finite_rings + sage: C = matrix(FiniteField(29), 4, 5, range(20)) # optional - sage.rings.finite_rings + sage: D = A.tensor_product(B) # optional - sage.rings.finite_rings + sage: D.parent() # optional - sage.rings.finite_rings Full MatrixSpace of 6 by 12 dense matrices over Finite Field of size 23 - sage: E = C.tensor_product(B) + sage: E = C.tensor_product(B) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Finite Field of size 29' and 'Full MatrixSpace of 3 by 4 dense matrices over Finite Field of size 23' + TypeError: unsupported operand parent(s) for *: + 'Finite Field of size 29' and + 'Full MatrixSpace of 3 by 4 dense matrices over Finite Field of size 23' The input is checked to be sure it is a matrix. :: @@ -9235,9 +9320,9 @@ cdef class Matrix(Matrix1): sage: m2.tensor_product(m3).dimensions() (0, 6) - sage: m1 = MatrixSpace(GF(5), 3, 2).an_element() - sage: m2 = MatrixSpace(GF(5), 0, 4).an_element() - sage: m1.tensor_product(m2).parent() + sage: m1 = MatrixSpace(GF(5), 3, 2).an_element() # optional - sage.rings.finite_rings + sage: m2 = MatrixSpace(GF(5), 0, 4).an_element() # optional - sage.rings.finite_rings + sage: m1.tensor_product(m2).parent() # optional - sage.rings.finite_rings Full MatrixSpace of 0 by 8 dense matrices over Finite Field of size 5 """ if not isinstance(A, Matrix): @@ -9361,22 +9446,22 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: m = matrix(QQ,2,2,range(4)) + sage: m = matrix(QQ, 2,2, range(4)) sage: m.is_one() False - sage: m = matrix(QQ,2,[5,0,0,5]) + sage: m = matrix(QQ, 2, [5,0,0,5]) sage: m.is_one() False - sage: m = matrix(QQ,2,[1,0,0,1]) + sage: m = matrix(QQ, 2, [1,0,0,1]) sage: m.is_one() True - sage: m = matrix(QQ,2,[1,1,1,1]) + sage: m = matrix(QQ, 2, [1,1,1,1]) sage: m.is_one() False """ return self.is_scalar(self.base_ring().one()) - def is_scalar(self, a = None): + def is_scalar(self, a=None): """ Return True if this matrix is a scalar matrix. @@ -9392,16 +9477,16 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: m = matrix(QQ,2,2,range(4)) + sage: m = matrix(QQ, 2,2, range(4)) sage: m.is_scalar(5) False - sage: m = matrix(QQ,2,[5,0,0,5]) + sage: m = matrix(QQ, 2, [5,0,0,5]) sage: m.is_scalar(5) True - sage: m = matrix(QQ,2,[1,0,0,1]) + sage: m = matrix(QQ, 2, [1,0,0,1]) sage: m.is_scalar(1) True - sage: m = matrix(QQ,2,[1,1,1,1]) + sage: m = matrix(QQ, 2, [1,1,1,1]) sage: m.is_scalar(1) False """ @@ -9434,16 +9519,16 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: m = matrix(QQ,2,2,range(4)) + sage: m = matrix(QQ, 2,2, range(4)) sage: m.is_diagonal() False - sage: m = matrix(QQ,2,[5,0,0,5]) + sage: m = matrix(QQ, 2, [5,0,0,5]) sage: m.is_diagonal() True - sage: m = matrix(QQ,2,[1,0,0,1]) + sage: m = matrix(QQ, 2, [1,0,0,1]) sage: m.is_diagonal() True - sage: m = matrix(QQ,2,[1,1,1,1]) + sage: m = matrix(QQ, 2, [1,1,1,1]) sage: m.is_diagonal() False """ @@ -9520,26 +9605,27 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQbar, [[(1/sqrt(5))*(1+i), (1/sqrt(55))*(3+2*I), (1/sqrt(22))*(2+2*I)], - ....: [(1/sqrt(5))*(1-i), (1/sqrt(55))*(2+2*I), (1/sqrt(22))*(-3+I)], - ....: [ (1/sqrt(5))*I, (1/sqrt(55))*(3-5*I), (1/sqrt(22))*(-2)]]) - sage: A.is_unitary() + sage: A = matrix(QQbar, # optional - sage.symbolic sage.rings.number_field + ....: [[(1/sqrt(5))*(1+i), (1/sqrt(55))*(3+2*I), (1/sqrt(22))*(2+2*I)], + ....: [(1/sqrt(5))*(1-i), (1/sqrt(55))*(2+2*I), (1/sqrt(22))*(-3+I)], + ....: [ (1/sqrt(5))*I, (1/sqrt(55))*(3-5*I), (1/sqrt(22))*(-2)]]) + sage: A.is_unitary() # optional - sage.symbolic sage.rings.number_field True A permutation matrix is always orthogonal. :: - sage: sigma = Permutation([1,3,4,5,2]) - sage: P = sigma.to_matrix(); P + sage: sigma = Permutation([1,3,4,5,2]) # optional - sage.combinat + sage: P = sigma.to_matrix(); P # optional - sage.combinat [1 0 0 0 0] [0 0 0 0 1] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] - sage: P.is_unitary() + sage: P.is_unitary() # optional - sage.combinat True - sage: P.change_ring(GF(3)).is_unitary() + sage: P.change_ring(GF(3)).is_unitary() # optional - sage.combinat sage.rings.finite_rings True - sage: P.change_ring(GF(3)).is_unitary() + sage: P.change_ring(GF(3)).is_unitary() # optional - sage.combinat sage.rings.finite_rings True A square matrix far from unitary. :: @@ -9550,7 +9636,7 @@ cdef class Matrix(Matrix1): Rectangular matrices are never unitary. :: - sage: A = matrix(QQbar, 3, 4) + sage: A = matrix(QQbar, 3, 4) # optional - sage.rings.number_field sage: A.is_unitary() False """ @@ -9674,30 +9760,30 @@ cdef class Matrix(Matrix1): Sage has several fields besides the entire complex numbers where conjugation is non-trivial. :: - sage: F. = QuadraticField(-7) - sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], + sage: F. = QuadraticField(-7) # optional - sage.rings.number_field + sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], # optional - sage.rings.number_field ....: [-2*b - 3, -3*b + 2, -2*b], ....: [ b + 1, 0, -2]]) - sage: C = C*C.conjugate_transpose() - sage: C.is_normal() + sage: C = C*C.conjugate_transpose() # optional - sage.rings.number_field + sage: C.is_normal() # optional - sage.rings.number_field True A matrix that is nearly normal, but for a non-real diagonal entry. :: - sage: A = matrix(QQbar, [[ 2, 2-I, 1+4*I], + sage: A = matrix(QQbar, [[ 2, 2-I, 1+4*I], # optional - sage.rings.number_field ....: [ 2+I, 3+I, 2-6*I], ....: [1-4*I, 2+6*I, 5]]) - sage: A.is_normal() + sage: A.is_normal() # optional - sage.rings.number_field False - sage: A[1,1] = 132 - sage: A.is_normal() + sage: A[1,1] = 132 # optional - sage.rings.number_field + sage: A.is_normal() # optional - sage.rings.number_field True Rectangular matrices are never normal. :: - sage: A = matrix(QQbar, 3, 4) - sage: A.is_normal() + sage: A = matrix(QQbar, 3, 4) # optional - sage.rings.number_field + sage: A.is_normal() # optional - sage.rings.number_field False A square, empty matrix is trivially normal. :: @@ -9762,19 +9848,20 @@ cdef class Matrix(Matrix1): try to deduce the decomposition from the matrix :: sage: L = [] - sage: L.append((9,Permutation([4, 1, 3, 5, 2]))) - sage: L.append((6,Permutation([5, 3, 4, 1, 2]))) - sage: L.append((3,Permutation([3, 1, 4, 2, 5]))) - sage: L.append((2,Permutation([1, 4, 2, 3, 5]))) - sage: M = sum([c * p.to_matrix() for (c,p) in L]) - sage: decomp = sage.combinat.permutation.bistochastic_as_sum_of_permutations(M) - sage: print(decomp) + sage: L.append((9, Permutation([4, 1, 3, 5, 2]))) # optional - sage.combinat + sage: L.append((6, Permutation([5, 3, 4, 1, 2]))) # optional - sage.combinat + sage: L.append((3, Permutation([3, 1, 4, 2, 5]))) # optional - sage.combinat + sage: L.append((2, Permutation([1, 4, 2, 3, 5]))) # optional - sage.combinat + sage: M = sum([c * p.to_matrix() for c, p in L]) # optional - sage.combinat + sage: from sage.combinat.permutation import bistochastic_as_sum_of_permutations # optional - sage.combinat + sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.combinat + sage: print(decomp) # optional - sage.combinat 2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]] An exception is raised when the matrix is not bistochastic:: sage: M = Matrix([[2,3],[2,2]]) - sage: decomp = sage.combinat.permutation.bistochastic_as_sum_of_permutations(M) + sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.combinat Traceback (most recent call last): ... ValueError: The matrix is not bistochastic @@ -9829,7 +9916,7 @@ cdef class Matrix(Matrix1): Test :trac:`17341`:: - sage: random_matrix(GF(2), 8, 586, sparse=True).visualize_structure() + sage: random_matrix(GF(2), 8, 586, sparse=True).visualize_structure() # optional - sage.rings.finite_rings 512x6px 24-bit RGB image """ cdef Py_ssize_t x, y, _x, _y, v, bi, bisq @@ -9881,13 +9968,13 @@ cdef class Matrix(Matrix1): :: - sage: A = random_matrix(GF(127),200,200,density=0.3) - sage: A.density() <= 0.3 + sage: A = random_matrix(GF(127), 200, 200, density=0.3) # optional - sage.rings.finite_rings + sage: A.density() <= 0.3 # optional - sage.rings.finite_rings True :: - sage: A = matrix(QQ,3,3,[0,1,2,3,0,0,6,7,8]) + sage: A = matrix(QQ, 3,3, [0,1,2,3,0,0,6,7,8]) sage: A.density() 2/3 @@ -9953,9 +10040,9 @@ cdef class Matrix(Matrix1): Test :trac:`27473`:: - sage: F. = LaurentSeriesRing(GF(2)) - sage: M = Matrix([[t,1],[0,t]]) - sage: ~M + sage: F. = LaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: M = Matrix([[t,1], [0,t]]) # optional - sage.rings.finite_rings + sage: ~M # optional - sage.rings.finite_rings [t^-1 t^-2] [ 0 t^-1] @@ -9974,10 +10061,10 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = Matrix(ZZ,2,2,[5,2,3,4]) ; M + sage: M = Matrix(ZZ, 2, 2, [5,2,3,4]); M [5 2] [3 4] - sage: N = M.adjugate() ; N + sage: N = M.adjugate(); N [ 4 -2] [-3 5] sage: M * N @@ -9986,25 +10073,25 @@ cdef class Matrix(Matrix1): sage: N * M [14 0] [ 0 14] - sage: M = Matrix(QQ,2,2,[5/3,2/56,33/13,41/10]) ; M + sage: M = Matrix(QQ, 2, 2, [5/3,2/56, 33/13,41/10]); M [ 5/3 1/28] [33/13 41/10] - sage: N = M.adjugate() ; N + sage: N = M.adjugate(); N # optional - sage.libs.pari [ 41/10 -1/28] [-33/13 5/3] - sage: M * N + sage: M * N # optional - sage.libs.pari [7363/1092 0] [ 0 7363/1092] An alias is :meth:`adjoint_classical`, which replaces the deprecated :meth:`adjoint` method:: - sage: M.adjoint() + sage: M.adjoint() # optional - sage.libs.pari ...: DeprecationWarning: adjoint is deprecated. Please use adjugate instead. See https://github.com/sagemath/sage/issues/10501 for details. [ 41/10 -1/28] [-33/13 5/3] - sage: M.adjoint_classical() + sage: M.adjoint_classical() # optional - sage.libs.pari [ 41/10 -1/28] [-33/13 5/3] @@ -10073,19 +10160,19 @@ cdef class Matrix(Matrix1): not an integral domain:: sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: A = matrix(S, [[x*y^2,2*x],[2,x^10*y]]) - sage: A + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: A = matrix(S, [[x*y^2, 2*x], [2, x^10*y]]) # optional - sage.libs.singular + sage: A # optional - sage.libs.singular [ x*y^2 2*x] [ 2 x^10*y] - sage: A.det() + sage: A.det() # optional - sage.libs.singular -4*x - sage: A.charpoly('T') + sage: A.charpoly('T') # optional - sage.libs.singular T^2 + (-x^10*y - x*y^2)*T - 4*x - sage: A.adjugate() + sage: A.adjugate() # optional - sage.libs.singular [x^10*y -2*x] [ -2 x*y^2] - sage: A.adjugate() * A + sage: A.adjugate() * A # optional - sage.libs.singular [-4*x 0] [ 0 -4*x] @@ -10108,8 +10195,8 @@ cdef class Matrix(Matrix1): presence of non-integral powers of the variable `x` (:trac:`14403`):: - sage: x = var('x') - sage: Matrix([[sqrt(x),x],[1,0]]).adjugate() + sage: x = var('x') # optional - sage.symbolic + sage: Matrix([[sqrt(x),x], [1,0]]).adjugate() # optional - sage.symbolic [ 0 -x] [ -1 sqrt(x)] @@ -10184,58 +10271,58 @@ cdef class Matrix(Matrix1): For a nonsingular matrix, the QR decomposition is unique. :: - sage: A = matrix(QQbar, [[-2, 0, -4, -1, -1], + sage: A = matrix(QQbar, [[-2, 0, -4, -1, -1], # optional - sage.rings.number_field ....: [-2, 1, -6, -3, -1], ....: [1, 1, 7, 4, 5], ....: [3, 0, 8, 3, 3], ....: [-1, 1, -6, -6, 5]]) - sage: Q, R = A.QR() - sage: Q + sage: Q, R = A.QR() # optional - sage.rings.number_field + sage: Q # optional - sage.rings.number_field [ -0.4588314677411235? -0.1260506983326509? 0.3812120831224489? -0.394573711338418? -0.6874400625964?] [ -0.4588314677411235? 0.4726901187474409? -0.05198346588033394? 0.7172941251646595? -0.2209628772631?] [ 0.2294157338705618? 0.6617661662464172? 0.6619227988762521? -0.1808720937375480? 0.1964114464561?] [ 0.6882472016116853? 0.1890760474989764? -0.2044682991293135? 0.0966302966543065? -0.6628886317894?] [ -0.2294157338705618? 0.5357154679137663? -0.609939332995919? -0.536422031427112? 0.0245514308070?] - sage: R + sage: R # optional - sage.rings.number_field [ 4.358898943540674? -0.4588314677411235? 13.07669683062202? 6.194224814505168? 2.982404540317303?] [ 0 1.670171752907625? 0.5987408170800917? -1.292019657909672? 6.207996892883057?] [ 0 0 5.444401659866974? 5.468660610611130? -0.6827161852283857?] [ 0 0 0 1.027626039419836? -3.619300149686620?] [ 0 0 0 0 0.024551430807012?] - sage: Q.conjugate_transpose()*Q + sage: Q.conjugate_transpose()*Q # optional - sage.rings.number_field [1.000000000000000? 0.?e-18 0.?e-17 0.?e-16 0.?e-13] [ 0.?e-18 1.000000000000000? 0.?e-17 0.?e-16 0.?e-13] [ 0.?e-17 0.?e-17 1.000000000000000? 0.?e-16 0.?e-13] [ 0.?e-16 0.?e-16 0.?e-16 1.000000000000000? 0.?e-13] [ 0.?e-13 0.?e-13 0.?e-13 0.?e-13 1.0000000000000?] - sage: Q*R == A + sage: Q * R == A # optional - sage.rings.number_field True An example with complex numbers in ``QQbar``, the field of algebraic numbers. :: - sage: A = matrix(QQbar, [[-8, 4*I + 1, -I + 2, 2*I + 1], + sage: A = matrix(QQbar, [[-8, 4*I + 1, -I + 2, 2*I + 1], # optional - sage.rings.number_field ....: [1, -2*I - 1, -I + 3, -I + 1], ....: [I + 7, 2*I + 1, -2*I + 7, -I + 1], ....: [I + 2, 0, I + 12, -1]]) - sage: Q, R = A.QR() - sage: Q + sage: Q, R = A.QR() # optional - sage.rings.number_field + sage: Q # optional - sage.rings.number_field [ -0.7302967433402215? 0.2070566455055649? + 0.5383472783144687?*I 0.2463049809998642? - 0.0764456358723292?*I 0.2381617683194332? - 0.1036596032779695?*I] [ 0.0912870929175277? -0.2070566455055649? - 0.3778783780476559?*I 0.3786559533863033? - 0.1952221495524667?*I 0.701244450214469? - 0.3643711650986595?*I] [ 0.6390096504226938? + 0.0912870929175277?*I 0.1708217325420910? + 0.6677576817554466?*I -0.03411475806452072? + 0.04090198741767143?*I 0.3140171085506764? - 0.0825191718705412?*I] [ 0.1825741858350554? + 0.0912870929175277?*I -0.03623491296347385? + 0.0724698259269477?*I 0.8632284069415110? + 0.06322839976356195?*I -0.4499694867611521? - 0.0116119181208918?*I] - sage: R + sage: R # optional - sage.rings.number_field [ 10.95445115010333? 0.?e-18 - 1.917028951268082?*I 5.385938482134133? - 2.190890230020665?*I -0.2738612787525831? - 2.190890230020665?*I] [ 0 4.829596256417300? + 0.?e-18*I -0.869637911123373? - 5.864879483945125?*I 0.993871898426712? - 0.3054085521207082?*I] [ 0 0 12.00160760935814? + 0.?e-16*I -0.2709533402297273? + 0.4420629644486323?*I] [ 0 0 0 1.942963944258992? + 0.?e-16*I] - sage: Q.conjugate_transpose()*Q + sage: Q.conjugate_transpose()*Q # optional - sage.rings.number_field [1.000000000000000? + 0.?e-19*I 0.?e-18 + 0.?e-17*I 0.?e-17 + 0.?e-17*I 0.?e-16 + 0.?e-16*I] [ 0.?e-18 + 0.?e-17*I 1.000000000000000? + 0.?e-17*I 0.?e-17 + 0.?e-17*I 0.?e-16 + 0.?e-16*I] [ 0.?e-17 + 0.?e-17*I 0.?e-17 + 0.?e-17*I 1.000000000000000? + 0.?e-17*I 0.?e-16 + 0.?e-16*I] [ 0.?e-16 + 0.?e-16*I 0.?e-16 + 0.?e-16*I 0.?e-16 + 0.?e-16*I 1.000000000000000? + 0.?e-16*I] - sage: Q*R - A + sage: Q*R - A # optional - sage.rings.number_field [ 0.?e-17 0.?e-17 + 0.?e-17*I 0.?e-16 + 0.?e-16*I 0.?e-16 + 0.?e-16*I] [ 0.?e-18 0.?e-17 + 0.?e-17*I 0.?e-16 + 0.?e-16*I 0.?e-16 + 0.?e-16*I] [0.?e-17 + 0.?e-18*I 0.?e-17 + 0.?e-17*I 0.?e-16 + 0.?e-16*I 0.?e-16 + 0.?e-16*I] @@ -10243,58 +10330,58 @@ cdef class Matrix(Matrix1): A rank-deficient rectangular matrix, with both values of the ``full`` keyword. :: - sage: A = matrix(QQbar, [[2, -3, 3], + sage: A = matrix(QQbar, [[2, -3, 3], # optional - sage.rings.number_field ....: [-1, 1, -1], ....: [-1, 3, -3], ....: [-5, 1, -1]]) - sage: Q, R = A.QR() - sage: Q + sage: Q, R = A.QR() # optional - sage.rings.number_field + sage: Q # optional - sage.rings.number_field [ 0.3592106040535498? -0.5693261797050169? 0.7239227659930268? 0.1509015305256380?] [ -0.1796053020267749? 0.1445907757980996? 0 0.9730546968377341?] [ -0.1796053020267749? 0.7048800320157352? 0.672213996993525? -0.1378927778941174?] [ -0.8980265101338745? -0.3976246334447737? 0.1551263069985058? -0.10667177157846818?] - sage: R + sage: R # optional - sage.rings.number_field [ 5.567764362830022? -2.694079530401624? 2.694079530401624?] [ 0 3.569584777515583? -3.569584777515583?] [ 0 0 0] [ 0 0 0] - sage: Q.conjugate_transpose()*Q + sage: Q.conjugate_transpose() * Q # optional - sage.rings.number_field [ 1 0.?e-18 0.?e-18 0.?e-18] [ 0.?e-18 1 0.?e-18 0.?e-18] [ 0.?e-18 0.?e-18 1.000000000000000? 0.?e-18] [ 0.?e-18 0.?e-18 0.?e-18 1.000000000000000?] - sage: Q, R = A.QR(full=False) - sage: Q + sage: Q, R = A.QR(full=False) # optional - sage.rings.number_field + sage: Q # optional - sage.rings.number_field [ 0.3592106040535498? -0.5693261797050169?] [-0.1796053020267749? 0.1445907757980996?] [-0.1796053020267749? 0.7048800320157352?] [-0.8980265101338745? -0.3976246334447737?] - sage: R + sage: R # optional - sage.rings.number_field [ 5.567764362830022? -2.694079530401624? 2.694079530401624?] [ 0 3.569584777515583? -3.569584777515583?] - sage: Q.conjugate_transpose()*Q + sage: Q.conjugate_transpose()*Q # optional - sage.rings.number_field [ 1 0.?e-18] [0.?e-18 1] Another rank-deficient rectangular matrix, with complex entries, as a reduced decomposition. :: - sage: A = matrix(QQbar, [[-3*I - 3, I - 3, -12*I + 1, -2], + sage: A = matrix(QQbar, [[-3*I - 3, I - 3, -12*I + 1, -2], # optional - sage.rings.number_field ....: [-I - 1, -2, 5*I - 1, -I - 2], ....: [-4*I - 4, I - 5, -7*I, -I - 4]]) - sage: Q, R = A.QR(full=False) - sage: Q + sage: Q, R = A.QR(full=False) # optional - sage.rings.number_field + sage: Q # optional - sage.rings.number_field [ -0.4160251471689219? - 0.4160251471689219?*I 0.5370861555295747? + 0.1790287185098583?*I] [ -0.1386750490563073? - 0.1386750490563073?*I -0.7519206177414046? - 0.2506402059138015?*I] [ -0.5547001962252291? - 0.5547001962252291?*I -0.2148344622118299? - 0.07161148740394329?*I] - sage: R + sage: R # optional - sage.rings.number_field [ 7.211102550927979? 3.328201177351375? - 5.269651864139676?*I 7.904477796209515? + 8.45917799243475?*I 4.021576422632911? - 2.634825932069838?*I] [ 0 1.074172311059150? -1.611258466588724? - 9.13046464400277?*I 1.611258466588724? + 0.5370861555295747?*I] - sage: Q.conjugate_transpose()*Q + sage: Q.conjugate_transpose()*Q # optional - sage.rings.number_field [1 0] [0 1] - sage: Q*R-A + sage: Q*R - A # optional - sage.rings.number_field [0 0 0 0] [0 0 0 0] [0 0 0 0] @@ -10302,29 +10389,29 @@ cdef class Matrix(Matrix1): Results of full decompositions are cached and thus returned immutable. :: - sage: A = random_matrix(QQbar, 2, 2) - sage: Q, R = A.QR() - sage: Q.is_mutable() + sage: A = random_matrix(QQbar, 2, 2) # optional - sage.rings.number_field + sage: Q, R = A.QR() # optional - sage.rings.number_field + sage: Q.is_mutable() # optional - sage.rings.number_field False - sage: R.is_mutable() + sage: R.is_mutable() # optional - sage.rings.number_field False Trivial cases return trivial results of the correct size, and we check `Q` itself in one case. :: - sage: A = zero_matrix(QQbar, 0, 10) - sage: Q, R = A.QR() - sage: Q.nrows(), Q.ncols() + sage: A = zero_matrix(QQbar, 0, 10) # optional - sage.rings.number_field + sage: Q, R = A.QR() # optional - sage.rings.number_field + sage: Q.nrows(), Q.ncols() # optional - sage.rings.number_field (0, 0) - sage: R.nrows(), R.ncols() + sage: R.nrows(), R.ncols() # optional - sage.rings.number_field (0, 10) - sage: A = zero_matrix(QQbar, 3, 0) - sage: Q, R = A.QR() - sage: Q.nrows(), Q.ncols() + sage: A = zero_matrix(QQbar, 3, 0) # optional - sage.rings.number_field + sage: Q, R = A.QR() # optional - sage.rings.number_field + sage: Q.nrows(), Q.ncols() # optional - sage.rings.number_field (3, 3) - sage: R.nrows(), R.ncols() + sage: R.nrows(), R.ncols() # optional - sage.rings.number_field (3, 0) - sage: Q + sage: Q # optional - sage.rings.number_field [1 0 0] [0 1 0] [0 0 1] @@ -10481,32 +10568,32 @@ cdef class Matrix(Matrix1): so we need to check with the conjugate-transpose. This example verifies that the bug on :trac:`10791` is fixed. :: - sage: F. = QuadraticField(-5) - sage: A = matrix(F, [[ 1, a - 3, a - 2, a + 1], + sage: F. = QuadraticField(-5) # optional - sage.rings.number_field + sage: A = matrix(F, [[ 1, a - 3, a - 2, a + 1], # optional - sage.rings.number_field ....: [ a, 2*a + 1, 3*a + 1, 1], ....: [a + 1, a - 6, 2*a - 5, 1], ....: [ 2*a, a, 3*a, -3], ....: [ 1, a - 1, a, a - 1]]) - sage: A.rank() + sage: A.rank() # optional - sage.rings.number_field 3 - sage: Q, R = A._gram_schmidt_noscale() - sage: Q + sage: Q, R = A._gram_schmidt_noscale() # optional - sage.rings.number_field + sage: Q # optional - sage.rings.number_field [ 1 25/33*a - 38/11 641/1163*a + 453/1163] [ a 17/11*a + 73/33 322/1163*a + 1566/1163] [ a + 1 10/33*a - 173/33 -784/1163*a + 1614/1163] [ 2*a 1/11*a + 80/33 196/1163*a - 1234/1163] [ 1 25/33*a - 16/11 855/1163*a - 1717/1163] - sage: R + sage: R # optional - sage.rings.number_field [ 1 8/33*a + 5/11 8/33*a + 16/11 2/11*a + 1/33] [ 0 1 1 -107/1163*a - 78/1163] [ 0 0 0 1] - sage: Q*R == A + sage: Q*R == A # optional - sage.rings.number_field True - sage: Q.transpose().conjugate()*Q + sage: Q.transpose().conjugate()*Q # optional - sage.rings.number_field [ 33 0 0] [ 0 2326/33 0] [ 0 0 16532/1163] - sage: Q.column_space() == A.column_space() + sage: Q.column_space() == A.column_space() # optional - sage.rings.number_field True Some trivial cases. :: @@ -10698,47 +10785,47 @@ cdef class Matrix(Matrix1): for small cases or instruction. Now we need to use the ``orthonormal`` keyword. :: - sage: A = matrix(QQbar, [[6, -8, 1], + sage: A = matrix(QQbar, [[6, -8, 1], # optional - sage.rings.number_field ....: [4, 1, 3], ....: [6, 3, 3], ....: [7, 1, -5], ....: [7, -3, 5]]) - sage: G, M = A.gram_schmidt(orthonormal=True) - sage: G + sage: G, M = A.gram_schmidt(orthonormal=True) # optional - sage.rings.number_field + sage: G # optional - sage.rings.number_field [ 0.5970223141259934? -0.7960297521679913? 0.09950371902099891?] [ 0.6063218341690895? 0.5289635311888953? 0.5937772444966257?] [ 0.5252981913594170? 0.2941669871612735? -0.798453250866314?] - sage: M + sage: M # optional - sage.rings.number_field [ 10.04987562112089? 0 0] [ 1.890570661398980? 4.735582601355131? 0] [ 1.492555785314984? 7.006153332071100? 1.638930357041381?] [ 2.885607851608969? 1.804330147889395? 7.963520581008761?] [ 7.064764050490923? 5.626248468100069? -1.197679876299471?] - sage: M*G-A + sage: M*G - A # optional - sage.rings.number_field [0 0 0] [0 0 0] [0 0 0] [0 0 0] [0 0 0] - sage: (G*G.transpose()-identity_matrix(3)).norm() < 10^-10 + sage: (G*G.transpose() - identity_matrix(3)).norm() < 10^-10 # optional - sage.rings.number_field True - sage: G.row_space() == A.row_space() + sage: G.row_space() == A.row_space() # optional - sage.rings.number_field True After :trac:`14047`, the matrix can also be over the algebraic reals ``AA``:: - sage: A = matrix(AA, [[6, -8, 1], + sage: A = matrix(AA, [[6, -8, 1], # optional - sage.rings.number_field ....: [4, 1, 3], ....: [6, 3, 3], ....: [7, 1, -5], ....: [7, -3, 5]]) - sage: G, M = A.gram_schmidt(orthonormal=True) - sage: G + sage: G, M = A.gram_schmidt(orthonormal=True) # optional - sage.rings.number_field + sage: G # optional - sage.rings.number_field [ 0.5970223141259934? -0.7960297521679913? 0.09950371902099891?] [ 0.6063218341690895? 0.5289635311888953? 0.5937772444966257?] [ 0.5252981913594170? 0.2941669871612735? -0.798453250866314?] - sage: M + sage: M # optional - sage.rings.number_field [ 10.04987562112089? 0 0] [ 1.890570661398980? 4.735582601355131? 0] [ 1.492555785314984? 7.006153332071100? 1.638930357041381?] @@ -10749,45 +10836,45 @@ cdef class Matrix(Matrix1): Note the use of the conjugate-transpose when checking the orthonormality. :: - sage: A = matrix(QQbar, [[ -2, -I - 1, 4*I + 2, -1], + sage: A = matrix(QQbar, [[ -2, -I - 1, 4*I + 2, -1], # optional - sage.rings.number_field ....: [-4*I, -2*I + 17, 0, 9*I + 1], ....: [ 1, -2*I - 6, -I + 11, -5*I + 1]]) - sage: G, M = A.gram_schmidt(orthonormal=True) - sage: (M*G-A).norm() < 10^-10 + sage: G, M = A.gram_schmidt(orthonormal=True) # optional - sage.rings.number_field + sage: (M*G - A).norm() < 10^-10 # optional - sage.rings.number_field True - sage: id3 = G*G.conjugate().transpose() - sage: (id3 - identity_matrix(3)).norm() < 10^-10 + sage: id3 = G*G.conjugate().transpose() # optional - sage.rings.number_field + sage: (id3 - identity_matrix(3)).norm() < 10^-10 # optional - sage.rings.number_field True - sage: G.row_space() == A.row_space() # long time + sage: G.row_space() == A.row_space() # long time # optional - sage.rings.number_field True A square matrix with small rank. The zero vectors produced as a result of linear dependence get eliminated, so the rows of ``G`` are a basis for the row space of ``A``. :: - sage: A = matrix(QQbar, [[2, -6, 3, 8], + sage: A = matrix(QQbar, [[2, -6, 3, 8], # optional - sage.rings.number_field ....: [1, -3, 2, 5], ....: [0, 0, 2, 4], ....: [2, -6, 3, 8]]) - sage: A.change_ring(QQ).rank() + sage: A.change_ring(QQ).rank() # optional - sage.rings.number_field 2 - sage: G, M = A.gram_schmidt(orthonormal=True) - sage: G + sage: G, M = A.gram_schmidt(orthonormal=True) # optional - sage.rings.number_field + sage: G # optional - sage.rings.number_field [ 0.1881441736767195? -0.5644325210301583? 0.2822162605150792? 0.7525766947068779?] [-0.2502818123591464? 0.750845437077439? 0.3688363550555841? 0.4873908977520218?] - sage: M + sage: M # optional - sage.rings.number_field [10.630145812734649? 0] [ 6.208757731331742? 0.6718090752798139?] [ 3.574739299857670? 2.687236301119256?] [10.630145812734649? 0] - sage: M*G-A + sage: M*G - A # optional - sage.rings.number_field [0 0 0 0] [0 0 0 0] [0 0 0 0] [0 0 0 0] - sage: (G*G.transpose()-identity_matrix(2)).norm() < 10^-10 + sage: (G*G.transpose() - identity_matrix(2)).norm() < 10^-10 # optional - sage.rings.number_field True - sage: G.row_space() == A.row_space() + sage: G.row_space() == A.row_space() # optional - sage.rings.number_field True Exact Rings, Orthogonalization: @@ -10831,28 +10918,28 @@ cdef class Matrix(Matrix1): A complex subfield of the complex numbers. :: - sage: C. = CyclotomicField(5) + sage: C. = CyclotomicField(5) # optional - sage.rings.number_field sage: A = matrix(C, [[ -z^3 - 2*z, -z^3 - 1, 2*z^3 - 2*z^2 + 2*z, 1], ....: [ z^3 - 2*z^2 + 1, -z^3 + 2*z^2 - z - 1, -1, z^2 + z], ....: [-1/2*z^3 - 2*z^2 + z + 1, -z^3 + z - 2, -2*z^3 + 1/2*z^2, 2*z^2 - z + 2]]) - sage: G, M = A.gram_schmidt(orthonormal=False) - sage: G + sage: G, M = A.gram_schmidt(orthonormal=False) # optional - sage.rings.number_field + sage: G # optional - sage.rings.number_field [ -z^3 - 2*z -z^3 - 1 2*z^3 - 2*z^2 + 2*z 1] [ 155/139*z^3 - 161/139*z^2 + 31/139*z + 13/139 -175/139*z^3 + 180/139*z^2 - 125/139*z - 142/139 230/139*z^3 + 124/139*z^2 + 6/139*z + 19/139 -14/139*z^3 + 92/139*z^2 - 6/139*z - 95/139] [-10359/19841*z^3 - 36739/39682*z^2 + 24961/39682*z - 11879/39682 -28209/39682*z^3 - 3671/19841*z^2 + 51549/39682*z - 38613/39682 -42769/39682*z^3 - 615/39682*z^2 - 1252/19841*z - 14392/19841 4895/19841*z^3 + 57885/39682*z^2 - 46094/19841*z + 65747/39682] - sage: M + sage: M # optional - sage.rings.number_field [ 1 0 0] [ 14/139*z^3 + 47/139*z^2 + 145/139*z + 95/139 1 0] [ -7/278*z^3 + 199/278*z^2 + 183/139*z + 175/278 -3785/39682*z^3 + 3346/19841*z^2 - 3990/19841*z + 2039/19841 1] - sage: M*G - A + sage: M*G - A # optional - sage.rings.number_field [0 0 0 0] [0 0 0 0] [0 0 0 0] - sage: G*G.conjugate().transpose() + sage: G*G.conjugate().transpose() # optional - sage.rings.number_field [ 15*z^3 + 15*z^2 + 28 0 0] [ 0 463/139*z^3 + 463/139*z^2 + 1971/139 0] [ 0 0 230983/19841*z^3 + 230983/19841*z^2 + 1003433/39682] - sage: G.row_space() == A.row_space() + sage: G.row_space() == A.row_space() # optional - sage.rings.number_field True A slightly edited legacy example. :: @@ -10962,27 +11049,27 @@ cdef class Matrix(Matrix1): [ 0 1 0 0] [ 1 -1 1 0] [ 1 -1 1 2] - sage: a.jordan_form() + sage: a.jordan_form() # optional - sage.combinat [2|0 0|0] [-+---+-] [0|1 1|0] [0|0 1|0] [-+---+-] [0|0 0|1] - sage: a.jordan_form(subdivide=False) + sage: a.jordan_form(subdivide=False) # optional - sage.combinat [2 0 0 0] [0 1 1 0] [0 0 1 0] [0 0 0 1] - sage: b = matrix(ZZ,3,3,range(9)); b + sage: b = matrix(ZZ,3,3,range(9)); b # optional - sage.combinat [0 1 2] [3 4 5] [6 7 8] - sage: b.jordan_form() + sage: b.jordan_form() # optional - sage.combinat Traceback (most recent call last): ... RuntimeError: Some eigenvalue does not exist in Rational Field. - sage: b.jordan_form(RealField(15)) + sage: b.jordan_form(RealField(15)) # optional - sage.combinat Traceback (most recent call last): ... ValueError: Jordan normal form not implemented over inexact rings. @@ -10990,8 +11077,8 @@ cdef class Matrix(Matrix1): Here we need to specify a field, since the eigenvalues are not defined in the smallest ring containing the matrix entries (:trac:`14508`):: - sage: c = matrix([[0,1,0],[0,0,1],[1,0,0]]) - sage: c.jordan_form(CyclotomicField(3)) + sage: c = matrix([[0,1,0], [0,0,1], [1,0,0]]) + sage: c.jordan_form(CyclotomicField(3)) # optional - sage.combinat sage.rings.number_field [ 1| 0| 0] [----------+----------+----------] [ 0| zeta3| 0] @@ -11001,20 +11088,20 @@ cdef class Matrix(Matrix1): If you need the transformation matrix as well as the Jordan form of ``self``, then pass the option ``transformation=True``. For example:: - sage: m = matrix([[5,4,2,1],[0,1,-1,-1],[-1,-1,3,0],[1,1,-1,2]]); m + sage: m = matrix([[5,4,2,1], [0,1,-1,-1], [-1,-1,3,0], [1,1,-1,2]]); m [ 5 4 2 1] [ 0 1 -1 -1] [-1 -1 3 0] [ 1 1 -1 2] - sage: jf, p = m.jordan_form(transformation=True) - sage: jf + sage: jf, p = m.jordan_form(transformation=True) # optional - sage.combinat + sage: jf # optional - sage.combinat [2|0|0 0] [-+-+---] [0|1|0 0] [-+-+---] [0|0|4 1] [0|0|0 4] - sage: ~p * m * p + sage: ~p * m * p # optional - sage.combinat [2 0 0 0] [0 1 0 0] [0 0 4 1] @@ -11024,7 +11111,7 @@ cdef class Matrix(Matrix1): compute the Jordan normal form, since it is not numerically stable:: - sage: b = matrix(ZZ,3,3,range(9)) + sage: b = matrix(ZZ, 3, 3, range(9)) sage: jf, p = b.jordan_form(RealField(15), transformation=True) Traceback (most recent call last): ... @@ -11036,7 +11123,7 @@ cdef class Matrix(Matrix1): [1 1 1] [1 1 1] [1 1 1] - sage: c.jordan_form(subdivide=False) + sage: c.jordan_form(subdivide=False) # optional - sage.combinat [3 0 0] [0 0 0] [0 0 0] @@ -11049,19 +11136,21 @@ cdef class Matrix(Matrix1): sage: p = random_matrix(ZZ,n,n) sage: while p.rank() != n: p = random_matrix(ZZ,n,n) sage: m = p * jf * ~p - sage: mjf, mp = m.jordan_form(transformation=True) - sage: mjf == jf + sage: mjf, mp = m.jordan_form(transformation=True) # optional - sage.combinat + sage: mjf == jf # optional - sage.combinat True sage: m = diagonal_matrix([1,1,0,0]) - sage: jf,P = m.jordan_form(transformation=True) - sage: jf == ~P*m*P + sage: jf, P = m.jordan_form(transformation=True) # optional - sage.combinat + sage: jf == ~P*m*P # optional - sage.combinat True We verify that the bug from :trac:`6942` is fixed:: - sage: M = Matrix(GF(2),[[1,0,1,0,0,0,1],[1,0,0,1,1,1,0],[1,1,0,1,1,1,1],[1,1,1,0,1,1,1],[1,1,1,0,0,1,0],[1,1,1,0,1,0,0],[1,1,1,1,1,1,0]]) - sage: J, T = M.jordan_form(transformation=True) - sage: J + sage: M = Matrix(GF(2),[[1,0,1,0,0,0,1], [1,0,0,1,1,1,0], [1,1,0,1,1,1,1], # optional - sage.rings.finite_rings + ....: [1,1,1,0,1,1,1], [1,1,1,0,0,1,0], [1,1,1,0,1,0,0], + ....: [1,1,1,1,1,1,0]]) + sage: J, T = M.jordan_form(transformation=True) # optional - sage.combinat sage.rings.finite_rings + sage: J # optional - sage.combinat sage.rings.finite_rings [1 1|0 0|0 0|0] [0 1|0 0|0 0|0] [---+---+---+-] @@ -11072,17 +11161,17 @@ cdef class Matrix(Matrix1): [0 0|0 0|0 1|0] [---+---+---+-] [0 0|0 0|0 0|1] - sage: M * T == T * J + sage: M * T == T * J # optional - sage.combinat sage.rings.finite_rings True - sage: T.rank() + sage: T.rank() # optional - sage.combinat sage.rings.finite_rings 7 - sage: M.rank() + sage: M.rank() # optional - sage.combinat sage.rings.finite_rings 7 We verify that the bug from :trac:`6932` is fixed:: - sage: M=Matrix(1,1,[1]) - sage: M.jordan_form(transformation=True) + sage: M = Matrix(1, 1, [1]) # optional - sage.combinat + sage: M.jordan_form(transformation=True) # optional - sage.combinat ([1], [1]) We now go through three `10 \times 10` matrices to exhibit cases where @@ -11099,7 +11188,7 @@ cdef class Matrix(Matrix1): [ 20 26/3 -66 -199/3 -42 -41/3 0 13/3 -55/3 -2/3] [ 18 57 -9 -54 -57 0 0 0 -15 0] [ 0 0 0 0 0 0 0 0 0 3] - sage: J, T = A.jordan_form(transformation=True); J + sage: J, T = A.jordan_form(transformation=True); J # optional - sage.combinat [3 1 0|0 0 0|0 0 0|0] [0 3 1|0 0 0|0 0 0|0] [0 0 3|0 0 0|0 0 0|0] @@ -11113,9 +11202,9 @@ cdef class Matrix(Matrix1): [0 0 0|0 0 0|0 0 3|0] [-----+-----+-----+-] [0 0 0|0 0 0|0 0 0|3] - sage: T * J * T**(-1) == A + sage: T * J * T**(-1) == A # optional - sage.combinat True - sage: T.rank() + sage: T.rank() # optional - sage.combinat 10 :: @@ -11131,7 +11220,7 @@ cdef class Matrix(Matrix1): [ 20 26/3 -66 -28/3 -42 -41/3 0 13/3 2/3 82/3] [ 18 57 -9 0 -57 0 0 0 3 28] [ 0 0 0 0 0 0 0 0 0 3] - sage: J, T = A.jordan_form(transformation=True); J + sage: J, T = A.jordan_form(transformation=True); J # optional - sage.combinat [3 1 0|0 0 0|0 0|0 0] [0 3 1|0 0 0|0 0|0 0] [0 0 3|0 0 0|0 0|0 0] @@ -11145,9 +11234,9 @@ cdef class Matrix(Matrix1): [-----+-----+---+---] [0 0 0|0 0 0|0 0|3 1] [0 0 0|0 0 0|0 0|0 3] - sage: T * J * T**(-1) == A + sage: T * J * T**(-1) == A # optional - sage.combinat True - sage: T.rank() + sage: T.rank() # optional - sage.combinat 10 :: @@ -11163,7 +11252,7 @@ cdef class Matrix(Matrix1): [ 20 26/3 -30 -199/3 -42 -14/3 70 13/3 -55/3 -2/3] [ 18 57 -9 -54 -57 0 63 0 -15 0] [ 0 0 0 0 0 0 0 0 0 3] - sage: J, T = A.jordan_form(transformation=True); J + sage: J, T = A.jordan_form(transformation=True); J # optional - sage.combinat [3 1 0|0 0|0 0|0 0|0] [0 3 1|0 0|0 0|0 0|0] [0 0 3|0 0|0 0|0 0|0] @@ -11178,7 +11267,7 @@ cdef class Matrix(Matrix1): [0 0 0|0 0|0 0|0 3|0] [-----+---+---+---+-] [0 0 0|0 0|0 0|0 0|3] - sage: T * J * T**(-1) == A + sage: T * J * T**(-1) == A # optional - sage.combinat True sage: T.rank() 10 @@ -11186,9 +11275,9 @@ cdef class Matrix(Matrix1): Verify that we smoothly move to QQ from ZZ (:trac:`12693`), i.e. we work in the vector space over the field:: - sage: M = matrix(((2,2,2),(0,0,0),(-2,-2,-2))) - sage: J, P = M.jordan_form(transformation=True) - sage: J; P + sage: M = matrix(((2,2,2), (0,0,0), (-2,-2,-2))) + sage: J, P = M.jordan_form(transformation=True) # optional - sage.combinat + sage: J; P # optional - sage.combinat [0 1|0] [0 0|0] [---+-] @@ -11196,15 +11285,15 @@ cdef class Matrix(Matrix1): [ 2 1 0] [ 0 0 1] [-2 0 -1] - sage: J - ~P * M * P + sage: J - ~P * M * P # optional - sage.combinat [0 0 0] [0 0 0] [0 0 0] - sage: parent(M) + sage: parent(M) # optional - sage.combinat Full MatrixSpace of 3 by 3 dense matrices over Integer Ring - sage: parent(J) == parent(P) == MatrixSpace(QQ, 3) + sage: parent(J) == parent(P) == MatrixSpace(QQ, 3) # optional - sage.combinat True - sage: M.jordan_form(transformation=True) == (M/1).jordan_form(transformation=True) + sage: M.jordan_form(transformation=True) == (M/1).jordan_form(transformation=True) # optional - sage.combinat True By providing eigenvalues ourselves, we can compute the Jordan form even @@ -11213,16 +11302,16 @@ cdef class Matrix(Matrix1): sage: Qx = PolynomialRing(QQ, 'x11, x12, x13, x21, x22, x23, x31, x32, x33') sage: x11, x12, x13, x21, x22, x23, x31, x32, x33 = Qx.gens() sage: M = matrix(Qx, [[0, 0, x31], [0, 0, x21], [0, 0, 0]]) # This is a nilpotent matrix. - sage: M.jordan_form(eigenvalues=[(0, 3)]) + sage: M.jordan_form(eigenvalues=[(0, 3)]) # optional - sage.combinat [0 1|0] [0 0|0] [---+-] [0 0|0] - sage: M.jordan_form(eigenvalues=[(0, 2)]) + sage: M.jordan_form(eigenvalues=[(0, 2)]) # optional - sage.combinat Traceback (most recent call last): ... ValueError: The provided list of eigenvalues is not correct. - sage: M.jordan_form(transformation=True, eigenvalues=[(0, 3)]) + sage: M.jordan_form(transformation=True, eigenvalues=[(0, 3)]) # optional - sage.combinat ( [0 1|0] [0 0|0] [x31 0 1] @@ -11234,17 +11323,17 @@ cdef class Matrix(Matrix1): and it needs to be implemented. :: sage: A = matrix(Integers(6), 2, 2, range(4)) - sage: A.jordan_form() + sage: A.jordan_form() # optional - sage.combinat Traceback (most recent call last): ... ValueError: Matrix entries must be from a field, not Ring of integers modulo 6 Test for :trac:`10563`:: - sage: R = FractionField(PolynomialRing(RationalField(),'a')) + sage: R = FractionField(PolynomialRing(RationalField(), 'a')) sage: a = R.gen() - sage: A = matrix(R,[[1,a],[a,1]]) - sage: A.jordan_form() + sage: A = matrix(R, [[1,a], [a,1]]) # optional - sage.combinat + sage: A.jordan_form() # optional - sage.combinat [ a + 1| 0] [------+------] [ 0|-a + 1] @@ -11417,31 +11506,31 @@ cdef class Matrix(Matrix1): [-3 5 3 3] [ 3 -6 -4 -3] [-3 6 3 2] - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.libs.pari True - sage: A.diagonalization() + sage: A.diagonalization() # optional - sage.libs.pari ( [ 2 0 0 0] [ 1 1 0 0] [ 0 -1 0 0] [ 1 0 1 0] [ 0 0 -1 0] [-1 0 0 1] [ 0 0 0 -1], [ 1 1 -2 -1] ) - sage: D, P = A.diagonalization() - sage: P^-1*A*P == D + sage: D, P = A.diagonalization() # optional - sage.libs.pari + sage: P^-1*A*P == D # optional - sage.libs.pari True sage: A = matrix(QQ, 2, [0, 2, 1, 0]) - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.libs.pari False - sage: A.is_diagonalizable(QQbar) + sage: A.is_diagonalizable(QQbar) # optional - sage.libs.pari sage.rings.number_field True - sage: D, P = A.diagonalization(QQbar) - sage: P^-1*A*P == D + sage: D, P = A.diagonalization(QQbar) # optional - sage.libs.pari sage.rings.number_field + sage: P^-1*A*P == D # optional - sage.libs.pari sage.rings.number_field True Matrices may fail to be diagonalizable for various reasons:: - sage: A = matrix(QQ, 2, [1,2,3,4,5,6]) + sage: A = matrix(QQ, 2, [1,2,3, 4,5,6]) sage: A [1 2 3] [4 5 6] @@ -11568,9 +11657,9 @@ cdef class Matrix(Matrix1): ....: [ 9, -8, 11, -12, 51], ....: [ 3, -4, 0, -1, 9], ....: [-1, 0, -4, 4, -12]]) - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.libs.pari True - sage: A.diagonalization() + sage: A.diagonalization() # optional - sage.libs.pari ( [ 2 0 0 0 0] [ 1 1 0 1 0] [ 0 3 0 0 0] [ 1/2 0 1 0 1] @@ -11587,9 +11676,9 @@ cdef class Matrix(Matrix1): ....: [-2, -14, 0, 0, 10], ....: [3, 13, -2, 0, -11], ....: [-1, 6, 1, -3, 1]]) - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.libs.pari False - sage: A.jordan_form(subdivide=False) + sage: A.jordan_form(subdivide=False) # optional - sage.libs.pari [-1 1 0 0 0] [ 0 -1 0 0 0] [ 0 0 2 1 0] @@ -11606,46 +11695,46 @@ cdef class Matrix(Matrix1): ....: [2, -1, 1, 0, -2], ....: [0, -1, -1, -5, -8]]) - sage: [e in QQ for e in A.eigenvalues()] + sage: [e in QQ for e in A.eigenvalues()] # optional - sage.rings.number_field [False, False, False, False, False] - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.libs.pari False - sage: A.diagonalization() + sage: A.diagonalization() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: not diagonalizable over Rational Field - sage: [e in QQbar for e in A.eigenvalues()] + sage: [e in QQbar for e in A.eigenvalues()] # optional - sage.rings.number_field [True, True, True, True, True] - sage: A.is_diagonalizable(base_field=QQbar) + sage: A.is_diagonalizable(base_field=QQbar) # optional - sage.rings.number_field True Other exact fields may be employed, though it will not always be possible to extend their base fields to contain all the eigenvalues. :: - sage: F. = FiniteField(5^2) - sage: A = matrix(F, [[ 4, 3*b + 2, 3*b + 1, 3*b + 4], + sage: F. = FiniteField(5^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[ 4, 3*b + 2, 3*b + 1, 3*b + 4], # optional - sage.rings.finite_rings ....: [2*b + 1, 4*b, 0, 2], ....: [ 4*b, b + 2, 2*b + 3, 3], ....: [ 2*b, 3*b, 4*b + 4, 3*b + 3]]) - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.rings.finite_rings False - sage: A.jordan_form() + sage: A.jordan_form() # optional - sage.rings.finite_rings [ 4 1| 0 0] [ 0 4| 0 0] [---------------+---------------] [ 0 0|2*b + 1 1] [ 0 0| 0 2*b + 1] - sage: F. = QuadraticField(-7) - sage: A = matrix(F, [[ c + 3, 2*c - 2, -2*c + 2, c - 1], + sage: F. = QuadraticField(-7) # optional - sage.rings.number_field + sage: A = matrix(F, [[ c + 3, 2*c - 2, -2*c + 2, c - 1], # optional - sage.rings.number_field ....: [2*c + 10, 13*c + 15, -13*c - 17, 11*c + 31], ....: [2*c + 10, 14*c + 10, -14*c - 12, 12*c + 30], ....: [ 0, 2*c - 2, -2*c + 2, 2*c + 2]]) - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.rings.number_field True - sage: A.diagonalization() + sage: A.diagonalization() # optional - sage.rings.number_field ( [ 4 0 0 0] [ 1 0 1 0] [ 0 -2 0 0] [ 4 1 0 1] @@ -11656,7 +11745,7 @@ cdef class Matrix(Matrix1): A trivial matrix is diagonalizable, trivially. :: sage: A = matrix(QQ, 0, 0) - sage: A.is_diagonalizable() + sage: A.is_diagonalizable() # optional - sage.libs.pari True A matrix must be square to be diagonalizable. :: @@ -11807,39 +11896,39 @@ cdef class Matrix(Matrix1): sage: B = matrix(ZZ, [[ 1, 12, 3], ....: [-1, -6, -1], ....: [ 0, 6, 1]]) - sage: A.is_similar(B) + sage: A.is_similar(B) # optional - sage.libs.pari True - sage: _, T = A.is_similar(B, transformation=True) - sage: T + sage: _, T = A.is_similar(B, transformation=True) # optional - sage.libs.pari + sage: T # optional - sage.libs.pari [ 1.00000000000000? + 0.?e-14*I 0.?e-14 + 0.?e-14*I 0.?e-14 + 0.?e-14*I] [-0.66666666666667? + 0.?e-15*I 0.166666666666667? + 0.?e-15*I -0.83333333333334? + 0.?e-14*I] [ 0.66666666666667? + 0.?e-14*I 0.?e-14 + 0.?e-14*I -0.33333333333333? + 0.?e-14*I] - sage: T.change_ring(QQ) + sage: T.change_ring(QQ) # optional - sage.libs.pari [ 1 0 0] [-2/3 1/6 -5/6] [ 2/3 0 -1/3] - sage: A == T.inverse()*B*T + sage: A == T.inverse()*B*T # optional - sage.libs.pari True Other exact fields are supported. :: - sage: F. = FiniteField(7^2) - sage: A = matrix(F,[[2*a + 5, 6*a + 6, a + 3], - ....: [ a + 3, 2*a + 2, 4*a + 2], - ....: [2*a + 6, 5*a + 5, 3*a]]) - sage: B = matrix(F,[[5*a + 5, 6*a + 4, a + 1], - ....: [ a + 5, 4*a + 3, 3*a + 3], - ....: [3*a + 5, a + 4, 5*a + 6]]) - sage: A.is_similar(B) + sage: F. = FiniteField(7^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[2*a + 5, 6*a + 6, a + 3], # optional - sage.rings.finite_rings + ....: [ a + 3, 2*a + 2, 4*a + 2], + ....: [2*a + 6, 5*a + 5, 3*a]]) + sage: B = matrix(F, [[5*a + 5, 6*a + 4, a + 1], # optional - sage.rings.finite_rings + ....: [ a + 5, 4*a + 3, 3*a + 3], + ....: [3*a + 5, a + 4, 5*a + 6]]) + sage: A.is_similar(B) # optional - sage.rings.finite_rings True - sage: B.is_similar(A) + sage: B.is_similar(A) # optional - sage.rings.finite_rings True - sage: _, T = A.is_similar(B, transformation=True) - sage: T + sage: _, T = A.is_similar(B, transformation=True) # optional - sage.rings.finite_rings + sage: T # optional - sage.rings.finite_rings [ 1 0 0] [6*a + 1 4*a + 3 4*a + 2] [6*a + 3 3*a + 5 3*a + 6] - sage: A == T.inverse()*B*T + sage: A == T.inverse() * B * T # optional - sage.rings.finite_rings True Two matrices with different sets of eigenvalues, so they @@ -11853,9 +11942,9 @@ cdef class Matrix(Matrix1): ....: [-1, 2, -3, -7], ....: [-2, 3, -4, -7], ....: [ 0, -1, 0, 0]]) - sage: A.eigenvalues() == B.eigenvalues() + sage: A.eigenvalues() == B.eigenvalues() # optional - sage.rings.number_field False - sage: A.is_similar(B, transformation=True) + sage: A.is_similar(B, transformation=True) # optional - sage.libs.pari (False, None) Similarity is an equivalence relation, so this routine computes @@ -11871,7 +11960,7 @@ cdef class Matrix(Matrix1): sage: B = matrix(QQ, [[-38, -63, 42], ....: [ 14, 25, -14], ....: [-14, -21, 18]]) - sage: A.charpoly() == B.charpoly() + sage: A.charpoly() == B.charpoly() # optional - sage.libs.pari True sage: A.rational_form() [ 0 0 -48] @@ -11898,19 +11987,19 @@ cdef class Matrix(Matrix1): design, but we are not able to resurrect a similarity transformation. :: - sage: F. = FiniteField(7^2) - sage: C = matrix(F,[[ a + 2, 5*a + 4], - ....: [6*a + 6, 6*a + 4]]) - sage: S = matrix(F, [[0, 1], + sage: F. = FiniteField(7^2) # optional - sage.rings.finite_rings + sage: C = matrix(F, [[ a + 2, 5*a + 4], # optional - sage.rings.finite_rings + ....: [6*a + 6, 6*a + 4]]) + sage: S = matrix(F, [[0, 1], # optional - sage.rings.finite_rings ....: [1, 0]]) - sage: D = S.inverse()*C*S - sage: C.is_similar(D) + sage: D = S.inverse()*C*S # optional - sage.rings.finite_rings + sage: C.is_similar(D) # optional - sage.rings.finite_rings True - sage: C.is_similar(D, transformation=True) + sage: C.is_similar(D, transformation=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... RuntimeError: unable to compute transformation for similar matrices - sage: C.jordan_form() + sage: C.jordan_form() # optional - sage.rings.finite_rings Traceback (most recent call last): ... RuntimeError: Some eigenvalue does not exist in @@ -11920,9 +12009,9 @@ cdef class Matrix(Matrix1): algebraic closure of this field to find the change-of-basis matrix:: - sage: cox = posets.TamariLattice(3).coxeter_transformation() - sage: M = cox.change_ring(GF(3)) - sage: M.is_similar(M**3, True) # long time + sage: cox = posets.TamariLattice(3).coxeter_transformation() # optional - sage.graphs sage.combinat sage.rings.finite_rings + sage: M = cox.change_ring(GF(3)) # optional - sage.graphs sage.combinat sage.rings.finite_rings + sage: M.is_similar(M**3, True) # long time # optional - sage.graphs sage.combinat sage.rings.finite_rings ( [1 0 0 0 0] [0 1 1 0 2] @@ -11955,9 +12044,9 @@ cdef class Matrix(Matrix1): If the fraction fields of the entries are unequal and do not coerce in a common field, it is an error. :: - sage: A = matrix(GF(3), 2, 2, range(4)) - sage: B = matrix(GF(2), 2, 2, range(4)) - sage: A.is_similar(B, transformation=True) + sage: A = matrix(GF(3), 2, 2, range(4)) # optional - sage.rings.finite_rings + sage: B = matrix(GF(2), 2, 2, range(4)) # optional - sage.rings.finite_rings + sage: A.is_similar(B, transformation=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: @@ -11971,8 +12060,8 @@ cdef class Matrix(Matrix1): of ``QQ`` in ``QQbar``). :: sage: A = matrix(ZZ, 2, 2, range(4)) - sage: B = matrix(QQbar, 2, 2, range(4)) - sage: A.is_similar(B) + sage: B = matrix(QQbar, 2, 2, range(4)) # optional - sage.rings.number_field + sage: A.is_similar(B) # optional - sage.rings.number_field True TESTS: @@ -12381,18 +12470,18 @@ cdef class Matrix(Matrix1): ... TypeError: first input should be a vector, not junk - sage: A.cyclic_subspace(v, var=sin(x)) + sage: A.cyclic_subspace(v, var=sin(x)) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: polynomial variable must be a string or polynomial ring generator, not sin(x) - sage: t = polygen(GF(7), 't') - sage: A.cyclic_subspace(v, var=t) + sage: t = polygen(GF(7), 't') # optional - sage.rings.finite_rings + sage: A.cyclic_subspace(v, var=t) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: polynomial generator must be over the same ring as the matrix entries - sage: A.cyclic_subspace(v, basis='garbage') + sage: A.cyclic_subspace(v, basis='garbage') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: basis format must be 'echelon' or 'iterates', not garbage @@ -12421,10 +12510,10 @@ cdef class Matrix(Matrix1): ... TypeError: matrix entries must be from an exact field, not Ring of integers modulo 6 - sage: F. = GF(2^4) - sage: G = matrix(QQ, 4, range(16)) - sage: w = vector(F, 4, [1, a, a^2, a^3]) - sage: G.cyclic_subspace(w) + sage: F. = GF(2^4) # optional - sage.rings.finite_rings + sage: G = matrix(QQ, 4, range(16)) # optional - sage.rings.finite_rings + sage: w = vector(F, 4, [1, a, a^2, a^3]) # optional - sage.rings.finite_rings + sage: G.cyclic_subspace(w) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unable to make vector entries compatible with matrix entries @@ -12568,55 +12657,55 @@ cdef class Matrix(Matrix1): ....: [ -2, -18, -38, 15]]) sage: A.is_symmetric() True - sage: L = A.cholesky() - sage: L + sage: L = A.cholesky() # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field [ 8.83176086632785? 0 0 0] [ -3.396831102433787? 9.51112708681461? 0 0] [ -4.189425026335004? 17.32383862241232? 2.886751345948129? 0] [-0.2264554068289192? -1.973397116652010? -1.649572197684645? 2.886751345948129?] - sage: L.parent() + sage: L.parent() # optional - sage.rings.number_field Full MatrixSpace of 4 by 4 dense matrices over Algebraic Real Field - sage: L*L.transpose() == A + sage: L*L.transpose() == A # optional - sage.rings.number_field True Some subfields of the complex numbers, such as this number field of complex numbers with rational real and imaginary parts, allow for this computation:: - sage: C. = QuadraticField(-1) - sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], + sage: C. = QuadraticField(-1) # optional - sage.rings.number_field + sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], # optional - sage.rings.number_field ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], ....: [ -21*I, -7*I + 15, -24*I + 6, 28]]) - sage: A.is_hermitian() + sage: A.is_hermitian() # optional - sage.rings.number_field True - sage: L = A.cholesky() + sage: L = A.cholesky() # optional - sage.rings.number_field sage: L [ 4.79...? 0 0 0] [ 0.62...? - 3.54...?*I 5.00...? 0 0] [ 5.21...? - 5.00...?*I 13.58...? + 10.72...?*I 24.98...? 0] [ -4.37...?*I -0.10...? - 0.85...?*I -0.21...? + 0.37...?*I 2.81...?] - sage: L.parent() + sage: L.parent() # optional - sage.rings.number_field Full MatrixSpace of 4 by 4 dense matrices over Algebraic Field - sage: (L*L.conjugate_transpose() - A.change_ring(QQbar)).norm() < 10^-10 + sage: (L*L.conjugate_transpose() - A.change_ring(QQbar)).norm() < 10^-10 # optional - sage.rings.number_field True The field of algebraic numbers is an ideal setting for this computation:: - sage: A = matrix(QQbar, [[ 2, 4 + 2*I, 6 - 4*I], + sage: A = matrix(QQbar, [[ 2, 4 + 2*I, 6 - 4*I], # optional - sage.rings.number_field ....: [ -2*I + 4, 11, 10 - 12*I], ....: [ 4*I + 6, 10 + 12*I, 37]]) - sage: A.is_hermitian() + sage: A.is_hermitian() # optional - sage.rings.number_field True - sage: L = A.cholesky() - sage: L + sage: L = A.cholesky() # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field [ 1.414213562373095? 0 0] [2.828427124746190? - 1.414213562373095?*I 1 0] [4.242640687119285? + 2.828427124746190?*I -2*I + 2 1.732050807568878?] - sage: L.parent() + sage: L.parent() # optional - sage.rings.number_field Full MatrixSpace of 3 by 3 dense matrices over Algebraic Field - sage: L*L.conjugate_transpose() == A + sage: L*L.conjugate_transpose() == A # optional - sage.rings.number_field True Results are cached, hence immutable. Use the ``copy`` function @@ -12652,8 +12741,8 @@ cdef class Matrix(Matrix1): Even symbolic matrices can sometimes be factored:: - sage: A = matrix(SR, [[pi,0], [0,pi]]) # optional - sage.symbolic - sage: A.cholesky() # optional - sage.symbolic + sage: A = matrix(SR, [[pi,0], [0,pi]]) # optional - sage.symbolic + sage: A.cholesky() # optional - sage.symbolic [sqrt(pi) 0] [ 0 sqrt(pi)] @@ -12672,22 +12761,22 @@ cdef class Matrix(Matrix1): The matrix may not be Hermitian:: - sage: F. = FiniteField(5^4) - sage: A = matrix(F, [[2+a^3, 3], [3, 3]]) - sage: A.cholesky() + sage: F. = FiniteField(5^4) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[2+a^3, 3], [3, 3]]) # optional - sage.rings.finite_rings + sage: A.cholesky() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: matrix is not Hermitian The matrix may not be positive-definite:: - sage: C. = QuadraticField(-1) - sage: B = matrix(C, [[ 2, 4 - 2*I, 2 + 2*I], + sage: C. = QuadraticField(-1) # optional - sage.rings.number_field + sage: B = matrix(C, [[ 2, 4 - 2*I, 2 + 2*I], # optional - sage.rings.number_field ....: [4 + 2*I, 8, 10*I], ....: [2 - 2*I, -10*I, -3]]) - sage: B.is_positive_definite() + sage: B.is_positive_definite() # optional - sage.rings.number_field False - sage: B.cholesky() + sage: B.cholesky() # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: matrix is not positive definite @@ -12878,32 +12967,32 @@ cdef class Matrix(Matrix1): A matrix containing real roots:: - sage: A = matrix(AA, [ [1, 0, sqrt(2)], + sage: A = matrix(AA, [ [1, 0, sqrt(2)], # optional - sage.rings.number_field sage.symbolic ....: [0, sqrt(3), 0 ], ....: [sqrt(2), 0, sqrt(5)] ]) - sage: A.is_positive_definite() + sage: A.is_positive_definite() # optional - sage.rings.number_field sage.symbolic True - sage: B = matrix(AA, [ [2*sqrt(5) + 5, 0, -sqrt(8*sqrt(5) + 18)], + sage: B = matrix(AA, [ [2*sqrt(5) + 5, 0, -sqrt(8*sqrt(5) + 18)], # optional - sage.rings.number_field sage.symbolic ....: [0, sqrt(1/3), 0], ....: [-sqrt(8*sqrt(5) + 18), 0, sqrt(5) + 2] ]) - sage: A.inverse_positive_definite() == B + sage: A.inverse_positive_definite() == B # optional - sage.rings.number_field sage.symbolic True - sage: A*B == A.matrix_space().identity_matrix() + sage: A*B == A.matrix_space().identity_matrix() # optional - sage.rings.number_field sage.symbolic True A Hermitian (but not symmetric) matrix with complex entries:: - sage: A = matrix(QQbar, [ [ 1, 0, I ], + sage: A = matrix(QQbar, [ [ 1, 0, I ], # optional - sage.rings.number_field sage.symbolic ....: [ 0, sqrt(5), 0 ], ....: [-I, 0, 3 ] ]) - sage: A.is_positive_definite() + sage: A.is_positive_definite() # optional - sage.rings.number_field sage.symbolic True - sage: B = matrix(QQbar, [ [ 3/2, 0, -I/2 ], + sage: B = matrix(QQbar, [ [ 3/2, 0, -I/2 ], # optional - sage.rings.number_field sage.symbolic ....: [ 0, sqrt(1/5), 0 ], ....: [ I/2, 0, 1/2 ] ]) - sage: A.inverse_positive_definite() == B + sage: A.inverse_positive_definite() == B # optional - sage.rings.number_field sage.symbolic True - sage: A*B == A.matrix_space().identity_matrix() + sage: A*B == A.matrix_space().identity_matrix() # optional - sage.rings.number_field sage.symbolic True TESTS: @@ -12933,15 +13022,15 @@ cdef class Matrix(Matrix1): sage: from sage.misc.prandom import choice sage: n = ZZ.random_element(2) - sage: ring = choice([AA, QQbar]) - sage: A = matrix.random(ring, n) - sage: I = matrix.identity(ring, n) - sage: A = A*A.conjugate_transpose() + I - sage: A.is_positive_definite() + sage: ring = choice([AA, QQbar]) # optional - sage.rings.number_field + sage: A = matrix.random(ring, n) # optional - sage.rings.number_field + sage: I = matrix.identity(ring, n) # optional - sage.rings.number_field + sage: A = A*A.conjugate_transpose() + I # optional - sage.rings.number_field + sage: A.is_positive_definite() # optional - sage.rings.number_field True - sage: actual = A.inverse_positive_definite() - sage: expected = A.inverse() - sage: actual == expected + sage: actual = A.inverse_positive_definite() # optional - sage.rings.number_field + sage: expected = A.inverse() # optional - sage.rings.number_field + sage: actual == expected # optional - sage.rings.number_field True """ P,L,D = self.block_ldlt() @@ -13066,47 +13155,47 @@ cdef class Matrix(Matrix1): ....: [2, 0, 1, 4, 2, 6, 0], ....: [1, 0, -1, 8, -1, -1, -3], ....: [1, 1, 2, -2, -1, 1, 3]]) - sage: P, L, U = A.LU(pivot='partial') - sage: P + sage: P, L, U = A.LU(pivot='partial') # optional - sage.combinat + sage: P # optional - sage.combinat [0 0 0 0 1] [1 0 0 0 0] [0 0 0 1 0] [0 0 1 0 0] [0 1 0 0 0] - sage: L + sage: L # optional - sage.combinat [ 1 0 0 0 0] [ 1/2 1 0 0 0] [ 1/2 1/3 1 0 0] [ 1 2/3 1/5 1 0] [ 1/2 -1/3 -2/5 0 1] - sage: U + sage: U # optional - sage.combinat [ 2 -1 0 6 4 8 -2] [ 0 3/2 2 -5 -3 -3 4] [ 0 0 -5/3 20/3 -2 -4 -10/3] [ 0 0 0 0 2/5 4/5 0] [ 0 0 0 0 1/5 2/5 0] - sage: A == P*L*U + sage: A == P*L*U # optional - sage.combinat True - sage: P, L, U = A.LU(pivot='nonzero') - sage: P + sage: P, L, U = A.LU(pivot='nonzero') # optional - sage.combinat + sage: P # optional - sage.combinat [1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1] - sage: L + sage: L # optional - sage.combinat [ 1 0 0 0 0] [ 2 1 0 0 0] [ 2 2 1 0 0] [ 1 1 -1 1 0] [ 1 2 2 0 1] - sage: U + sage: U # optional - sage.combinat [ 1 -1 0 2 4 7 -1] [ 0 1 0 2 -4 -6 0] [ 0 0 1 -4 2 4 2] [ 0 0 0 0 1 2 0] [ 0 0 0 0 -1 -2 0] - sage: A == P*L*U + sage: A == P*L*U # optional - sage.combinat True An example of the compact format. :: @@ -13116,10 +13205,10 @@ cdef class Matrix(Matrix1): ....: [-1, -4, -6, -6], ....: [ 0, -2, -5, -8], ....: [-2, -6, -6, -2]]) - sage: perm, M = B.LU(format='compact') - sage: perm + sage: perm, M = B.LU(format='compact') # optional - sage.combinat + sage: perm # optional - sage.combinat (4, 3, 0, 1, 2) - sage: M + sage: M # optional - sage.combinat [ -2 -6 -6 -2] [ 0 -2 -5 -8] [-1/2 0 2 4] @@ -13133,13 +13222,13 @@ cdef class Matrix(Matrix1): ....: [ 1, -2, 1, 3], ....: [-4, 7, -3, -8], ....: [-3, 8, -1, -5]]) - sage: P, L, U = C.LU(format='plu') - sage: perm, M = C.LU(format='compact') - sage: (L - identity_matrix(4)) + U == M + sage: P, L, U = C.LU(format='plu') # optional - sage.combinat + sage: perm, M = C.LU(format='compact') # optional - sage.combinat + sage: (L - identity_matrix(4)) + U == M # optional - sage.combinat True - sage: p = [perm[i]+1 for i in range(len(perm))] - sage: PP = Permutation(p).to_matrix() - sage: PP == P + sage: p = [perm[i]+1 for i in range(len(perm))] # optional - sage.combinat + sage: PP = Permutation(p).to_matrix() # optional - sage.combinat + sage: PP == P # optional - sage.combinat True For a nonsingular matrix, and the 'nonzero' pivot @@ -13155,29 +13244,29 @@ cdef class Matrix(Matrix1): ....: [-2, 2, -3, 2, 1, 0], ....: [ 0, -1, -1, 0, 2, 5], ....: [-1, 2, -4, -1, 5, -3]]) - sage: P, L, U = D.LU(pivot='nonzero') - sage: P + sage: P, L, U = D.LU(pivot='nonzero') # optional - sage.combinat + sage: P # optional - sage.combinat [1 0 0 0 0 0] [0 1 0 0 0 0] [0 0 1 0 0 0] [0 0 0 1 0 0] [0 0 0 0 1 0] [0 0 0 0 0 1] - sage: L + sage: L # optional - sage.combinat [ 1 0 0 0 0 0] [ 3 1 0 0 0 0] [ -4 -1 1 0 0 0] [ -2 -1 -1 1 0 0] [ 0 1/2 1/4 1/2 1 0] [ -1 -1 -5/2 -2 -6 1] - sage: U + sage: U # optional - sage.combinat [ 1 0 2 0 -2 -1] [ 0 -2 -3 -1 6 9] [ 0 0 2 0 -3 -3] [ 0 0 0 1 0 4] [ 0 0 0 0 -1/4 -3/4] [ 0 0 0 0 0 1] - sage: D == L*U + sage: D == L*U # optional - sage.combinat True The base ring of the matrix may be any field, or a ring @@ -13207,45 +13296,45 @@ cdef class Matrix(Matrix1): Traceback (most recent call last): ... TypeError: cannot take absolute value of matrix entries, try 'pivot=nonzero' - sage: P, L, U = B.LU(pivot='nonzero') - sage: P + sage: P, L, U = B.LU(pivot='nonzero') # optional - sage.combinat + sage: P # optional - sage.combinat [1 0] [0 1] - sage: L + sage: L # optional - sage.combinat [ 1 0] [y^2/(y + 1) 1] - sage: U + sage: U # optional - sage.combinat [ y + 1 y^2 + y] [ 0 0] - sage: L.base_ring() + sage: L.base_ring() # optional - sage.combinat Fraction Field of Univariate Polynomial Ring in y over Rational Field - sage: B == P*L*U + sage: B == P*L*U # optional - sage.combinat True - sage: F. = FiniteField(5^2) - sage: C = matrix(F, [[a + 3, 4*a + 4, 2, 4*a + 2], + sage: F. = FiniteField(5^2) # optional - sage.rings.finite_rings + sage: C = matrix(F, [[a + 3, 4*a + 4, 2, 4*a + 2], # optional - sage.rings.finite_rings ....: [3, 2*a + 4, 2*a + 4, 2*a + 1], ....: [3*a + 1, a + 3, 2*a + 4, 4*a + 3], ....: [a, 3, 3*a + 1, a]]) - sage: P, L, U = C.LU(pivot='nonzero') - sage: P + sage: P, L, U = C.LU(pivot='nonzero') # optional - sage.combinat sage.rings.finite_rings + sage: P # optional - sage.combinat sage.rings.finite_rings [1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1] - sage: L + sage: L # optional - sage.combinat sage.rings.finite_rings [ 1 0 0 0] [3*a + 3 1 0 0] [ 2*a 4*a + 2 1 0] [2*a + 3 2 2*a + 4 1] - sage: U + sage: U # optional - sage.combinat sage.rings.finite_rings [ a + 3 4*a + 4 2 4*a + 2] [ 0 a + 1 a + 3 2*a + 4] [ 0 0 1 4*a + 2] [ 0 0 0 0] - sage: L.base_ring() + sage: L.base_ring() # optional - sage.combinat sage.rings.finite_rings Finite Field in a of size 5^2 - sage: C == P*L*U + sage: C == P*L*U # optional - sage.combinat sage.rings.finite_rings True With no pivoting strategy given (i.e. ``pivot=None``) @@ -13257,10 +13346,10 @@ cdef class Matrix(Matrix1): sage: entries = [3, 20, 11, 7, 16, 28, 5, 15, 21, 23, 22, 18, 8, 23, 15, 2] sage: A = matrix(Integers(29), 4, 4, entries) - sage: perm, _ = A.LU(format='compact'); perm + sage: perm, _ = A.LU(format='compact'); perm # optional - sage.combinat (0, 1, 2, 3) sage: B = matrix(QQ, 4, 4, entries) - sage: perm, _ = B.LU(format='compact'); perm + sage: perm, _ = B.LU(format='compact'); perm # optional - sage.combinat (2, 0, 1, 3) The `U` matrix is only guaranteed to be upper-triangular. @@ -13272,8 +13361,8 @@ cdef class Matrix(Matrix1): ....: [ 0, 0, 1, -4, -1, -3, 6, -5, -6], ....: [-2, 8, -1, -4, 2, -4, 1, -8, -7], ....: [ 1, -4, 2, -4, -3, 2, 5, 6, 4]]) - sage: P, L, U = A.LU() - sage: U + sage: P, L, U = A.LU() # optional - sage.combinat + sage: U # optional - sage.combinat [ -2 8 -1 -4 2 -4 1 -8 -7] [ 0 0 1/2 -2 -1 -2 9/2 -3 -7/2] [ 0 0 3/2 -6 -2 0 11/2 2 1/2] @@ -13306,15 +13395,15 @@ cdef class Matrix(Matrix1): components of the 'plu' format are not. :: sage: A = matrix(ZZ, 2, range(4)) - sage: perm, M = A.LU(format='compact') - sage: perm[0] = 25 + sage: perm, M = A.LU(format='compact') # optional - sage.combinat + sage: perm[0] = 25 # optional - sage.combinat Traceback (most recent call last): ... TypeError: 'tuple' object does not support item assignment - sage: M.is_immutable() + sage: M.is_immutable() # optional - sage.combinat True - sage: P, L, U = A.LU(format='plu') - sage: all(A.is_mutable() for A in [P, L, U]) + sage: P, L, U = A.LU(format='plu') # optional - sage.combinat + sage: all(A.is_mutable() for A in [P, L, U]) # optional - sage.combinat True Partial pivoting is based on the absolute values of entries @@ -13322,18 +13411,18 @@ cdef class Matrix(Matrix1): absolute value must be handled carefully. This tests that situation in the case of cyclotomic fields. :: - sage: C = SymmetricGroup(5).character_table() - sage: C.base_ring() + sage: C = SymmetricGroup(5).character_table() # optional - sage.groups sage.rings.number_field + sage: C.base_ring() # optional - sage.groups sage.rings.number_field Cyclotomic Field of order 1 and degree 1 - sage: P, L, U = C.LU(pivot='partial') - sage: C == P*L*U + sage: P, L, U = C.LU(pivot='partial') # optional - sage.combinat sage.groups sage.rings.number_field + sage: C == P*L*U # optional - sage.combinat sage.groups sage.rings.number_field True Check that :trac:`32736` is solved:: - sage: M = Matrix(FiniteField(11), [[2,3],[4,5]]) - sage: P, L, U = M.LU() - sage: P.base_ring() + sage: M = Matrix(FiniteField(11), [[2,3],[4,5]]) # optional - sage.rings.finite_rings + sage: P, L, U = M.LU() # optional - sage.combinat sage.rings.finite_rings + sage: P.base_ring() # optional - sage.combinat sage.rings.finite_rings Finite Field of size 11 """ if pivot not in [None, 'partial', 'nonzero']: @@ -13502,23 +13591,23 @@ cdef class Matrix(Matrix1): A Hermitian matrix. :: - sage: x = var('x') - sage: C. = NumberField(x^2 + 1) - sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], + sage: x = polygen(ZZ) + sage: C. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], # optional - sage.rings.number_field ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], ....: [ -21*I, -7*I + 15, -24*I + 6, 28]]) - sage: A.is_hermitian() + sage: A.is_hermitian() # optional - sage.rings.number_field True - sage: L, d = A._indefinite_factorization('hermitian') - sage: L + sage: L, d = A._indefinite_factorization('hermitian') # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field [ 1 0 0 0] [ -17/23*I + 3/23 1 0 0] [ -24/23*I + 25/23 617/288*I + 391/144 1 0] [ -21/23*I -49/288*I - 1/48 1336/89885*I - 773/89885 1] - sage: d + sage: d # optional - sage.rings.number_field (23, 576/23, 89885/144, 142130/17977) - sage: A == L*diagonal_matrix(C, d)*L.conjugate_transpose() + sage: A == L*diagonal_matrix(C, d)*L.conjugate_transpose() # optional - sage.rings.number_field True A matrix may have a singular submatrix in the upper-left @@ -13785,23 +13874,23 @@ cdef class Matrix(Matrix1): with rational real and imaginary parts. As theory predicts, the diagonal entries will be real numbers. :: - sage: C. = QuadraticField(-1) - sage: B = matrix(C, [[ 2, 4 - 2*I, 2 + 2*I], + sage: C. = QuadraticField(-1) # optional - sage.rings.number_field + sage: B = matrix(C, [[ 2, 4 - 2*I, 2 + 2*I], # optional - sage.rings.number_field ....: [4 + 2*I, 8, 10*I], ....: [2 - 2*I, -10*I, -3]]) - sage: B.is_hermitian() + sage: B.is_hermitian() # optional - sage.rings.number_field True - sage: L, d = B.indefinite_factorization(algorithm='hermitian') - sage: D = diagonal_matrix(d) - sage: L + sage: L, d = B.indefinite_factorization(algorithm='hermitian') # optional - sage.rings.number_field + sage: D = diagonal_matrix(d) # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field [ 1 0 0] [ I + 2 1 0] [ -I + 1 2*I + 1 1] - sage: D + sage: D # optional - sage.rings.number_field [ 2 0 0] [ 0 -2 0] [ 0 0 3] - sage: B == L*D*L.conjugate_transpose() + sage: B == L*D*L.conjugate_transpose() # optional - sage.rings.number_field True If a leading principal submatrix has zero determinant, this @@ -13827,27 +13916,27 @@ cdef class Matrix(Matrix1): may be factored. This provides a reasonable alternative to the Cholesky decomposition. :: - sage: F. = FiniteField(5^3) - sage: A = matrix(F, + sage: F. = FiniteField(5^3) # optional - sage.rings.finite_rings + sage: A = matrix(F, # optional - sage.rings.finite_rings ....: [[ a^2 + 2*a, 4*a^2 + 3*a + 4, 3*a^2 + a, 2*a^2 + 2*a + 1], ....: [4*a^2 + 3*a + 4, 4*a^2 + 2, 3*a, 2*a^2 + 4*a + 2], ....: [ 3*a^2 + a, 3*a, 3*a^2 + 2, 3*a^2 + 2*a + 3], ....: [2*a^2 + 2*a + 1, 2*a^2 + 4*a + 2, 3*a^2 + 2*a + 3, 3*a^2 + 2*a + 4]]) - sage: A.is_symmetric() + sage: A.is_symmetric() # optional - sage.rings.finite_rings True - sage: L, d = A.indefinite_factorization() - sage: D = diagonal_matrix(d) - sage: L + sage: L, d = A.indefinite_factorization() # optional - sage.rings.finite_rings + sage: D = diagonal_matrix(d) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings [ 1 0 0 0] [4*a^2 + 4*a + 3 1 0 0] [ 3 4*a^2 + a + 2 1 0] [ 4*a^2 + 4 2*a^2 + 3*a + 3 2*a^2 + 3*a + 1 1] - sage: D + sage: D # optional - sage.rings.finite_rings [ a^2 + 2*a 0 0 0] [ 0 2*a^2 + 2*a + 4 0 0] [ 0 0 3*a^2 + 4*a + 3 0] [ 0 0 0 a^2 + 3*a] - sage: A == L*D*L.transpose() + sage: A == L*D*L.transpose() # optional - sage.rings.finite_rings True This works correctly for the 0x0 matrix:: @@ -14253,13 +14342,13 @@ cdef class Matrix(Matrix1): The same is true of the following complex Hermitian matrix:: - sage: A = matrix(QQbar, [ [ 0,I], + sage: A = matrix(QQbar, [ [ 0,I], # optional - sage.rings.number_field ....: [-I,0] ]) - sage: A.block_ldlt(classical=True) + sage: A.block_ldlt(classical=True) # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: matrix has no classical LDL^T factorization - sage: A.block_ldlt() + sage: A.block_ldlt() # optional - sage.rings.number_field ( [1 0] [1 0] [ 0 I] [0 1], [0 1], [-I 0] @@ -14347,11 +14436,11 @@ cdef class Matrix(Matrix1): An indefinite Hermitian matrix that happens to have a classical factorization:: - sage: F. = QuadraticField(-1) - sage: A = matrix(F, [[ 2, 4 - 2*I, 2 + 2*I], + sage: F. = QuadraticField(-1) # optional - sage.rings.number_field + sage: A = matrix(F, [[ 2, 4 - 2*I, 2 + 2*I], # optional - sage.rings.number_field ....: [4 + 2*I, 8, 10*I], ....: [2 - 2*I, -10*I, -3]]) - sage: A.block_ldlt(classical=True)[1:] + sage: A.block_ldlt(classical=True)[1:] # optional - sage.rings.number_field ( [ 2| 0| 0] [--+--+--] @@ -14383,11 +14472,11 @@ cdef class Matrix(Matrix1): correctly:: sage: n = ZZ.random_element(6) - sage: F = QuadraticField(-1, 'I') - sage: A = matrix.random(F, n) - sage: A = A + A.conjugate_transpose() - sage: P,L,D = A.block_ldlt() - sage: A == P*L*D*L.conjugate_transpose()*P.conjugate_transpose() + sage: F = QuadraticField(-1, 'I') # optional - sage.rings.number_field + sage: A = matrix.random(F, n) # optional - sage.rings.number_field + sage: A = A + A.conjugate_transpose() # optional - sage.rings.number_field + sage: P,L,D = A.block_ldlt() # optional - sage.rings.number_field + sage: A == P*L*D*L.conjugate_transpose()*P.conjugate_transpose() # optional - sage.rings.number_field True Ensure that a "random" complex positive-semidefinite matrix is @@ -14395,20 +14484,20 @@ cdef class Matrix(Matrix1): is in fact diagonal:: sage: n = ZZ.random_element(6) - sage: F = QuadraticField(-1, 'I') - sage: A = matrix.random(F, n) - sage: A = A*A.conjugate_transpose() - sage: P,L,D = A.block_ldlt() - sage: A == P*L*D*L.conjugate_transpose()*P.conjugate_transpose() + sage: F = QuadraticField(-1, 'I') # optional - sage.rings.number_field + sage: A = matrix.random(F, n) # optional - sage.rings.number_field + sage: A = A * A.conjugate_transpose() # optional - sage.rings.number_field + sage: P,L,D = A.block_ldlt() # optional - sage.rings.number_field + sage: A == P * L * D * L.conjugate_transpose() * P.conjugate_transpose() # optional - sage.rings.number_field True - sage: diagonal_matrix(D.diagonal()) == D + sage: diagonal_matrix(D.diagonal()) == D # optional - sage.rings.number_field True The factorization should be a no-op on diagonal matrices:: sage: n = ZZ.random_element(6) sage: A = matrix.diagonal(random_vector(QQ, n)) - sage: I = matrix.identity(QQ,n) + sage: I = matrix.identity(QQ, n) sage: P,L,D = A.block_ldlt() sage: P == I and L == I and A == D True @@ -14535,7 +14624,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(QQ, [ [2,1], ....: [1,2] ] ) - sage: A.eigenvalues() + sage: A.eigenvalues() # optional - sage.rings.number_field [3, 1] sage: A.is_positive_semidefinite() True @@ -14604,9 +14693,10 @@ cdef class Matrix(Matrix1): a Hermitian matrix (for a non-Hermitian matrix, both "obviously" return ``False``):: - sage: F = QuadraticField(-1, 'I') + sage: rings = [ZZ, QQ, RDF, CDF] + sage: rings.append(QuadraticField(-1, 'I')) # optional - sage.rings.number_field sage: from sage.misc.prandom import choice - sage: ring = choice([ZZ, QQ, F, RDF, CDF]) + sage: ring = choice(rings) sage: A = matrix.random(ring, 10); A = A + A.conjugate_transpose() sage: def is_positive_semidefinite_naive(A): ....: if A.nrows() == 0: @@ -14622,9 +14712,9 @@ cdef class Matrix(Matrix1): either real numbers, complex numbers, or symbolics; otherwise we risk returning nonsensical results:: - sage: F = FiniteField(5^2) - sage: A = matrix.identity(F, 1) - sage: A.is_positive_semidefinite() + sage: F = FiniteField(5^2) # optional - sage.rings.finite_rings + sage: A = matrix.identity(F, 1) # optional - sage.rings.finite_rings + sage: A.is_positive_semidefinite() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: Could not see Finite Field in z2 of size 5^2 @@ -14696,7 +14786,7 @@ cdef class Matrix(Matrix1): ....: [ 2, -7, 4, 7]]) sage: A.is_positive_definite() True - sage: [A[:i,:i].determinant() for i in range(1,A.nrows()+1)] + sage: [A[:i,:i].determinant() for i in range(1, A.nrows() + 1)] [4, 36, 144, 144] A real symmetric matrix that is not positive-definite and a @@ -14732,39 +14822,39 @@ cdef class Matrix(Matrix1): confirmed by the positive determinants of its leading principal submatrices:: - sage: C. = NumberField(x^2 + 1, embedding=CC(0,1)) + sage: C. = NumberField(x^2 + 1, embedding=CC(0,1)) # optional - sage.rings.number_field sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], ....: [ -21*I, -7*I + 15, -24*I + 6, 28]]) - sage: A.is_positive_definite() + sage: A.is_positive_definite() # optional - sage.rings.number_field True - sage: [A[:i,:i].determinant() for i in range(1,A.nrows()+1)] + sage: [A[:i,:i].determinant() for i in range(1,A.nrows()+1)] # optional - sage.rings.number_field [23, 576, 359540, 2842600] An Hermitian matrix that is not positive-definite and a vector ``u`` that makes the corresponding quadratic form negative:: - sage: C. = QuadraticField(-1) - sage: B = matrix(C, [[ 2, 4 - 2*I, 2 + 2*I], + sage: C. = QuadraticField(-1) # optional - sage.rings.number_field + sage: B = matrix(C, [[ 2, 4 - 2*I, 2 + 2*I], # optional - sage.rings.number_field ....: [4 + 2*I, 8, 10*I], ....: [2 - 2*I, -10*I, -3]]) - sage: B.is_positive_definite() + sage: B.is_positive_definite() # optional - sage.rings.number_field False - sage: u = vector(C, [-5 + 10*I, 4 - 3*I, 0]) - sage: (B*u).hermitian_inner_product(u) + sage: u = vector(C, [-5 + 10*I, 4 - 3*I, 0]) # optional - sage.rings.number_field + sage: (B*u).hermitian_inner_product(u) # optional - sage.rings.number_field -50 A positive-definite matrix over an algebraically-closed field, confirmed by the positive determinants of its leading principal submatrices:: - sage: A = matrix(QQbar, [[ 2, 4 + 2*I, 6 - 4*I], + sage: A = matrix(QQbar, [[ 2, 4 + 2*I, 6 - 4*I], # optional - sage.rings.number_field ....: [ -2*I + 4, 11, 10 - 12*I], ....: [ 4*I + 6, 10 + 12*I, 37]]) - sage: A.is_positive_definite() + sage: A.is_positive_definite() # optional - sage.rings.number_field True - sage: [A[:i,:i].determinant() for i in range(1,A.nrows()+1)] + sage: [A[:i,:i].determinant() for i in range(1, A.nrows() + 1)] # optional - sage.rings.number_field [2, 2, 6] TESTS: @@ -14773,17 +14863,17 @@ cdef class Matrix(Matrix1): numbers, complex numbers, or symbolic ring, then this routine will fail since comparison to zero is meaningless:: - sage: F. = FiniteField(5^3) - sage: a.conjugate() + sage: F. = FiniteField(5^3) # optional - sage.rings.finite_rings + sage: a.conjugate() # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: cardinality of the field must be a square number - sage: A = matrix(F, + sage: A = matrix(F, # optional - sage.rings.finite_rings ....: [[ a^2 + 2*a, 4*a^2 + 3*a + 4, 3*a^2 + a, 2*a^2 + 2*a + 1], ....: [4*a^2 + 3*a + 4, 4*a^2 + 2, 3*a, 2*a^2 + 4*a + 2], ....: [ 3*a^2 + a, 3*a, 3*a^2 + 2, 3*a^2 + 2*a + 3], ....: [2*a^2 + 2*a + 1, 2*a^2 + 4*a + 2, 3*a^2 + 2*a + 3, 3*a^2 + 2*a + 4]]) - sage: A.is_positive_definite() + sage: A.is_positive_definite() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: Could not see Finite Field in a of size 5^3 as a subring @@ -14801,7 +14891,7 @@ cdef class Matrix(Matrix1): True sage: matrix.identity(CC,4).is_positive_definite() True - sage: matrix.identity(SR,4).is_positive_definite() # optional - sage.symbolic + sage: matrix.identity(SR,4).is_positive_definite() # optional - sage.symbolic True """ result = self._is_positive_definite_or_semidefinite(False) @@ -14833,7 +14923,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = Matrix([[1,-1/2,0],[-1/2,1,-1/2],[0,-1/2,1]]) + sage: A = Matrix([[1,-1/2,0], [-1/2,1,-1/2], [0,-1/2,1]]) sage: B = A.principal_square_root() sage: A == B^2 True @@ -15002,21 +15092,21 @@ cdef class Matrix(Matrix1): A matrix over a not-totally-real number field:: - sage: K. = NumberField(x^2+5) - sage: M = matrix(K, [[1+j,1], [0,2*j]]) - sage: M.conjugate() + sage: K. = NumberField(x^2+5) # optional - sage.rings.number_field + sage: M = matrix(K, [[1+j,1], [0,2*j]]) # optional - sage.rings.number_field + sage: M.conjugate() # optional - sage.rings.number_field [-j + 1 1] [ 0 -2*j] There is a shortcut for the conjugate:: - sage: M.C + sage: M.C # optional - sage.rings.number_field [-j + 1 1] [ 0 -2*j] There is also a shortcut for the conjugate transpose, or "Hermitian transpose":: - sage: M.H + sage: M.H # optional - sage.rings.number_field [-j + 1 0] [ 1 -2*j] @@ -15057,10 +15147,10 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = matrix(SR, 2, 2, [[2-I, 3+4*I], [9-6*I, 5*I]]) # optional - sage.symbolic - sage: M.base_ring() # optional - sage.symbolic + sage: M = matrix(SR, 2, 2, [[2-I, 3+4*I], [9-6*I, 5*I]]) # optional - sage.symbolic + sage: M.base_ring() # optional - sage.symbolic Symbolic Ring - sage: M.conjugate_transpose() # optional - sage.symbolic + sage: M.conjugate_transpose() # optional - sage.symbolic [ I + 2 6*I + 9] [-4*I + 3 -5*I] @@ -15090,32 +15180,32 @@ cdef class Matrix(Matrix1): (Matrices over quadratic number fields are another class of examples.) :: - sage: C = CyclotomicField(5) - sage: a = C.gen(); a + sage: C = CyclotomicField(5) # optional - sage.rings.number_field + sage: a = C.gen(); a # optional - sage.rings.number_field zeta5 - sage: CC(a) + sage: CC(a) # optional - sage.rings.number_field 0.309016994374947 + 0.951056516295154*I - sage: M = matrix(C, 1, 2, [a^2, a+a^3]) - sage: M.conjugate_transpose() + sage: M = matrix(C, 1, 2, [a^2, a+a^3]) # optional - sage.rings.number_field + sage: M.conjugate_transpose() # optional - sage.rings.number_field [ zeta5^3] [-zeta5^3 - zeta5 - 1] Furthermore, this method can be applied to matrices over quadratic extensions of finite fields:: - sage: F. = GF(9,'a') - sage: N = matrix(F, 2, [0,a,-a,1]); N + sage: F. = GF(9,'a') # optional - sage.rings.finite_rings + sage: N = matrix(F, 2, [0,a,-a,1]); N # optional - sage.rings.finite_rings [ 0 a] [2*a 1] - sage: N.conjugate_transpose() + sage: N.conjugate_transpose() # optional - sage.rings.finite_rings [ 0 a + 2] [2*a + 1 1] Conjugation does not make sense over rings not containing complex numbers or finite fields which are not a quadratic extension:: - sage: N = matrix(GF(5), 2, [0,1,2,3]) - sage: N.conjugate_transpose() + sage: N = matrix(GF(5), 2, [0,1,2,3]) # optional - sage.rings.finite_rings + sage: N.conjugate_transpose() # optional - sage.rings.finite_rings Traceback (most recent call last): ... AttributeError: 'sage.rings.finite_rings.integer_mod.IntegerMod_int' object has no attribute 'conjugate' @@ -15133,8 +15223,7 @@ cdef class Matrix(Matrix1): INPUT: - - ``self`` - a matrix whose entries are coercible into - CDF + - ``self`` - a matrix whose entries are coercible into ``CDF`` - ``p`` - one of the following options: @@ -15155,7 +15244,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(ZZ, [[1,2,4,3],[-1,0,3,-10]]) + sage: A = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]]) sage: A.norm(1) 13.0 sage: A.norm(Infinity) @@ -15245,32 +15334,32 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: d = matrix([[3, 0],[0,sqrt(2)]]) - sage: b = matrix([[1, -1], [2, 2]]) ; e = b * d * b.inverse();e + sage: d = matrix([[3, 0], [0, sqrt(2)]]) # optional - sage.symbolic + sage: b = matrix([[1, -1], [2, 2]]); e = b * d * b.inverse(); e # optional - sage.symbolic [ 1/2*sqrt(2) + 3/2 -1/4*sqrt(2) + 3/4] [ -sqrt(2) + 3 1/2*sqrt(2) + 3/2] :: - sage: e.numerical_approx(53) + sage: e.numerical_approx(53) # optional - sage.symbolic [ 2.20710678118655 0.396446609406726] [ 1.58578643762690 2.20710678118655] :: - sage: e.numerical_approx(20) + sage: e.numerical_approx(20) # optional - sage.symbolic [ 2.2071 0.39645] [ 1.5858 2.2071] :: - sage: (e-I).numerical_approx(20) + sage: (e - I).numerical_approx(20) # optional - sage.symbolic [2.2071 - 1.0000*I 0.39645] [ 1.5858 2.2071 - 1.0000*I] :: - sage: M=matrix(QQ,4,[i/(i+1) for i in range(12)]);M + sage: M = matrix(QQ, 4, [i/(i+1) for i in range(12)]); M [ 0 1/2 2/3] [ 3/4 4/5 5/6] [ 6/7 7/8 8/9] @@ -15286,7 +15375,7 @@ cdef class Matrix(Matrix1): :: - sage: matrix(SR, 2, 2, range(4)).n() # optional - sage.symbolic + sage: matrix(SR, 2, 2, range(4)).n() # optional - sage.symbolic [0.000000000000000 1.00000000000000] [ 2.00000000000000 3.00000000000000] @@ -15300,9 +15389,9 @@ cdef class Matrix(Matrix1): We check that :trac:`29700` is fixed:: - sage: M = matrix(3,[1,1,1,1,0,0,0,1,0]) - sage: A,B = M.diagonalization(QQbar) - sage: _ = A.n() + sage: M = matrix(3, [1,1,1,1,0,0,0,1,0]) + sage: A, B = M.diagonalization(QQbar) # optional - sage.rings.number_field + sage: _ = A.n() # optional - sage.rings.number_field """ from sage.rings.real_mpfr import RealField @@ -15337,21 +15426,21 @@ cdef class Matrix(Matrix1): A matrix over ZZ colored with different grey levels:: sage: A = matrix([[1,3,5,1],[2,4,5,6],[1,3,5,7]]) - sage: A.plot() + sage: A.plot() # optional - sage.plot Graphics object consisting of 1 graphics primitive - Here we make a random matrix over RR and use cmap='hsv' to color + Here we make a random matrix over ``RR`` and use ``cmap='hsv'`` to color the matrix elements different RGB colors (see documentation for ``matrix_plot`` for more information on cmaps):: sage: A = random_matrix(RDF, 50) - sage: plot(A, cmap='hsv') + sage: plot(A, cmap='hsv') # optional - sage.plot Graphics object consisting of 1 graphics primitive Another random plot, but over GF(389):: - sage: A = random_matrix(GF(389), 10) - sage: A.plot(cmap='Oranges') + sage: A = random_matrix(GF(389), 10) # optional - sage.rings.finite_rings + sage: A.plot(cmap='Oranges') # optional - sage.rings.finite_rings sage.plot Graphics object consisting of 1 graphics primitive """ from sage.plot.matrix_plot import matrix_plot @@ -15367,17 +15456,17 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: v = vector([1,x,x^2]) - sage: v.derivative(x) + sage: v = vector([1,x,x^2]) # optional - sage.symbolic + sage: v.derivative(x) # optional - sage.symbolic (0, 1, 2*x) - sage: type(v.derivative(x)) == type(v) + sage: type(v.derivative(x)) == type(v) # optional - sage.symbolic True - sage: v = vector([1,x,x^2], sparse=True) - sage: v.derivative(x) + sage: v = vector([1,x,x^2], sparse=True) # optional - sage.symbolic + sage: v.derivative(x) # optional - sage.symbolic (0, 1, 2*x) - sage: type(v.derivative(x)) == type(v) + sage: type(v.derivative(x)) == type(v) # optional - sage.symbolic True - sage: v.derivative(x,x) + sage: v.derivative(x,x) # optional - sage.symbolic (0, 0, 2) """ from sage.misc.derivative import multi_derivative @@ -15402,24 +15491,24 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: a=matrix([[1,2],[3,4]]) - sage: a.exp() + sage: a = matrix([[1,2], [3,4]]) + sage: a.exp() # optional - sage.symbolic [-1/22*((sqrt(33) - 11)*e^sqrt(33) - sqrt(33) - 11)*e^(-1/2*sqrt(33) + 5/2) 2/33*(sqrt(33)*e^sqrt(33) - sqrt(33))*e^(-1/2*sqrt(33) + 5/2)] [ 1/11*(sqrt(33)*e^sqrt(33) - sqrt(33))*e^(-1/2*sqrt(33) + 5/2) 1/22*((sqrt(33) + 11)*e^sqrt(33) - sqrt(33) + 11)*e^(-1/2*sqrt(33) + 5/2)] - sage: type(a.exp()) + sage: type(a.exp()) # optional - sage.symbolic - sage: a=matrix([[1/2,2/3],[3/4,4/5]]) - sage: a.exp() + sage: a = matrix([[1/2,2/3], [3/4,4/5]]) + sage: a.exp() # optional - sage.symbolic [-1/418*((3*sqrt(209) - 209)*e^(1/10*sqrt(209)) - 3*sqrt(209) - 209)*e^(-1/20*sqrt(209) + 13/20) 20/627*(sqrt(209)*e^(1/10*sqrt(209)) - sqrt(209))*e^(-1/20*sqrt(209) + 13/20)] [ 15/418*(sqrt(209)*e^(1/10*sqrt(209)) - sqrt(209))*e^(-1/20*sqrt(209) + 13/20) 1/418*((3*sqrt(209) + 209)*e^(1/10*sqrt(209)) - 3*sqrt(209) + 209)*e^(-1/20*sqrt(209) + 13/20)] - sage: a=matrix(RR,[[1,pi.n()],[1e2,1e-2]]) - sage: a.exp() + sage: a = matrix(RR, [[1,pi.n()], [1e2,1e-2]]) # optional - sage.symbolic + sage: a.exp() # optional - sage.symbolic [ 1/11882424341266*((11*sqrt(227345670387496707609) + 5941212170633)*e^(3/1275529100*sqrt(227345670387496707609)) - 11*sqrt(227345670387496707609) + 5941212170633)*e^(-3/2551058200*sqrt(227345670387496707609) + 101/200) 445243650/75781890129165569203*(sqrt(227345670387496707609)*e^(3/1275529100*sqrt(227345670387496707609)) - sqrt(227345670387496707609))*e^(-3/2551058200*sqrt(227345670387496707609) + 101/200)] [ 10000/53470909535697*(sqrt(227345670387496707609)*e^(3/1275529100*sqrt(227345670387496707609)) - sqrt(227345670387496707609))*e^(-3/2551058200*sqrt(227345670387496707609) + 101/200) -1/11882424341266*((11*sqrt(227345670387496707609) - 5941212170633)*e^(3/1275529100*sqrt(227345670387496707609)) - 11*sqrt(227345670387496707609) - 5941212170633)*e^(-3/2551058200*sqrt(227345670387496707609) + 101/200)] - sage: a.change_ring(RDF).exp() # rel tol 1e-14 + sage: a.change_ring(RDF).exp() # rel tol 1e-14 # optional - sage.symbolic [42748127.31532951 7368259.244159399] [234538976.1381042 40426191.45156228] @@ -15427,9 +15516,9 @@ cdef class Matrix(Matrix1): Check that sparse matrices are handled correctly (:trac:`28935`):: - sage: matrix.diagonal([0], sparse=True).exp() + sage: matrix.diagonal([0], sparse=True).exp() # optional - sage.symbolic [1] - sage: matrix.zero(CBF, 2, sparse=True).exp() + sage: matrix.zero(CBF, 2, sparse=True).exp() # optional - sage.symbolic [1.000000000000000 0] [ 0 1.000000000000000] """ @@ -15456,9 +15545,9 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: OE. = EquationOrder(x^2 - x + 2) - sage: m = Matrix([ [1, w],[w,7]]) - sage: m.elementary_divisors() + sage: OE. = EquationOrder(x^2 - x + 2) # optional - sage.rings.number_field + sage: m = Matrix([[1, w], [w, 7]]) # optional - sage.rings.number_field + sage: m.elementary_divisors() # optional - sage.rings.number_field [1, -w + 9] .. SEEALSO:: @@ -15547,24 +15636,25 @@ cdef class Matrix(Matrix1): An example over the ring of integers of a number field (of class number 1):: - sage: OE. = EquationOrder(x^2 - x + 2) - sage: m = Matrix([ [1, w],[w,7]]) - sage: d, u, v = m.smith_form() - sage: (d, u, v) + sage: OE. = EquationOrder(x^2 - x + 2) # optional - sage.rings.number_field + sage: m = Matrix([[1, w], [w, 7]]) # optional - sage.rings.number_field + sage: d, u, v = m.smith_form() # optional - sage.rings.number_field + sage: (d, u, v) # optional - sage.rings.number_field ( [ 1 0] [ 1 0] [ 1 -w] [ 0 -w + 9], [-w 1], [ 0 1] ) - sage: u * m * v == d + sage: u * m * v == d # optional - sage.rings.number_field True - sage: u.base_ring() == v.base_ring() == d.base_ring() == OE + sage: u.base_ring() == v.base_ring() == d.base_ring() == OE # optional - sage.rings.number_field True - sage: u.det().is_unit() and v.det().is_unit() + sage: u.det().is_unit() and v.det().is_unit() # optional - sage.rings.number_field True An example over the polynomial ring QQ[x]:: - sage: R. = QQ[]; m=x*matrix(R,2,2,1) - matrix(R, 2,2,[3,-4,1,-1]); m.smith_form() + sage: R. = QQ[]; m = x*matrix(R, 2, 2, 1) - matrix(R, 2, 2, [3,-4,1,-1]) + sage: m.smith_form() ( [ 1 0] [ 0 -1] [ 1 x + 1] [ 0 x^2 - 2*x + 1], [ 1 x - 3], [ 0 1] @@ -15572,12 +15662,13 @@ cdef class Matrix(Matrix1): An example over a field:: - sage: m = matrix( GF(17), 3, 3, [11,5,1,3,6,8,1,16,0]); d,u,v = m.smith_form() - sage: d + sage: m = matrix(GF(17), 3, 3, [11,5,1, 3,6,8, 1,16,0]) # optional - sage.rings.finite_rings + sage: d, u, v = m.smith_form() # optional - sage.rings.finite_rings + sage: d # optional - sage.rings.finite_rings [1 0 0] [0 1 0] [0 0 0] - sage: u*m*v == d + sage: u * m * v == d # optional - sage.rings.finite_rings True When the base ring has a ``ring_of_integers`` method and supports denominators, @@ -15597,45 +15688,51 @@ cdef class Matrix(Matrix1): Some examples over non-PID's work anyway:: - sage: R. = EquationOrder(x^2 + 5) # class number 2 - sage: A = matrix(R, 2, 2, [s-1,-s,-s,2*s+1]) - sage: D, U, V = A.smith_form() - sage: D, U, V + sage: R. = EquationOrder(x^2 + 5) # class number 2 # optional - sage.rings.number_field + sage: A = matrix(R, 2, 2, [s - 1, -s, -s, 2*s + 1]) # optional - sage.rings.number_field + sage: D, U, V = A.smith_form() # optional - sage.rings.number_field + sage: D, U, V # optional - sage.rings.number_field ( [ 1 0] [ 4 s + 4] [ 1 -5*s + 6] [ 0 -s - 6], [ s s - 1], [ 0 1] ) - sage: D == U*A*V + sage: D == U * A * V # optional - sage.rings.number_field True Others don't, but they fail quite constructively:: - sage: matrix(R,2,2,[s-1,-s-2,-2*s,-s-2]).smith_form() + sage: matrix(R, 2, 2, [s - 1, -s - 2, -2*s, -s - 2]).smith_form() # optional - sage.rings.number_field Traceback (most recent call last): ... ArithmeticError: Ideal Fractional ideal (2, s + 1) not principal Empty matrices are handled safely:: - sage: m = MatrixSpace(OE, 2,0)(0); d,u,v=m.smith_form(); u*m*v == d + sage: m = MatrixSpace(OE, 2,0)(0); d, u, v = m.smith_form(); u * m * v == d True - sage: m = MatrixSpace(OE, 0,2)(0); d,u,v=m.smith_form(); u*m*v == d + sage: m = MatrixSpace(OE, 0,2)(0); d, u, v = m.smith_form(); u * m * v == d True - sage: m = MatrixSpace(OE, 0,0)(0); d,u,v=m.smith_form(); u*m*v == d + sage: m = MatrixSpace(OE, 0,0)(0); d, u, v = m.smith_form(); u * m * v == d True Some pathological cases that crashed earlier versions:: - sage: m = Matrix(OE, [[2*w,2*w-1,-w+1],[2*w+2,-2*w-1,w-1],[-2*w-1,-2*w-2,2*w-1]]); d, u, v = m.smith_form(); u * m * v == d + sage: m = Matrix(OE, [[ 2*w, 2*w - 1, -w + 1], # optional - sage.rings.number_field + ....: [ 2*w + 2, -2*w - 1, w - 1], + ....: [-2*w - 1, -2*w - 2, 2*w - 1]]) + sage: d, u, v = m.smith_form(); u * m * v == d # optional - sage.rings.number_field True - sage: m = matrix(OE, 3, 3, [-5*w-1,-2*w-2,4*w-10,8*w,-w,w-1,-1,1,-8]); d,u,v = m.smith_form(); u*m*v == d + sage: m = matrix(OE, [[-5*w - 1, -2*w - 2, 4*w - 10], # optional - sage.rings.number_field + ....: [ 8*w, -w, w - 1], + ....: [ -1, 1, -8]]) + sage: d, u, v = m.smith_form(); u * m * v == d # optional - sage.rings.number_field True Over local fields, we can request the transformation matrices to be integral:; - sage: K = Qp(2, 5, print_mode='terse') - sage: M = matrix(K, 2, 3, [1/2, 1, 2, 1/3, 1, 3]) - sage: M.smith_form(integral=True) + sage: K = Qp(2, 5, print_mode='terse') # optional - sage.rings.padics + sage: M = matrix(K, 2, 3, [1/2, 1, 2, 1/3, 1, 3]) # optional - sage.rings.padics + sage: M.smith_form(integral=True) # optional - sage.rings.padics ( [1/2 + O(2^4) 0 0] [ 1 + O(2^5) 0] [ 0 1 + O(2^5) 0], [42 + O(2^6) 1 + O(2^5)], @@ -15849,31 +15946,32 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = FunctionField(GF(7),'x').maximal_order() - sage: K. = FunctionField(GF(7)); M = K.maximal_order() - sage: A = matrix(M, 2, 3, [x, 1, 2*x, x, 1+x, 2]) - sage: A.hermite_form() + sage: M = FunctionField(GF(7), 'x').maximal_order() # optional - sage.rings.finite_rings + sage: K. = FunctionField(GF(7)); M = K.maximal_order() # optional - sage.rings.finite_rings + sage: A = matrix(M, 2, 3, [x, 1, 2*x, x, 1 + x, 2]) # optional - sage.rings.finite_rings + sage: A.hermite_form() # optional - sage.rings.finite_rings [ x 1 2*x] [ 0 x 5*x + 2] - sage: A.hermite_form(transformation=True) + sage: A.hermite_form(transformation=True) # optional - sage.rings.finite_rings ( [ x 1 2*x] [1 0] [ 0 x 5*x + 2], [6 1] ) - sage: A = matrix(M, 2, 3, [x, 1, 2*x, 2*x, 2, 4*x]) - sage: A.hermite_form(transformation=True, include_zero_rows=False) + sage: A = matrix(M, 2, 3, [x, 1, 2*x, 2*x, 2, 4*x]) # optional - sage.rings.finite_rings + sage: A.hermite_form(transformation=True, include_zero_rows=False) # optional - sage.rings.finite_rings ([ x 1 2*x], [1 0]) - sage: H, U = A.hermite_form(transformation=True, include_zero_rows=True); H, U + sage: H, U = A.hermite_form(transformation=True, include_zero_rows=True) # optional - sage.rings.finite_rings + sage: H, U ( [ x 1 2*x] [1 0] [ 0 0 0], [5 1] ) - sage: U*A == H + sage: U * A == H # optional - sage.rings.finite_rings True - sage: H, U = A.hermite_form(transformation=True, include_zero_rows=False) - sage: U*A + sage: H, U = A.hermite_form(transformation=True, include_zero_rows=False) # optional - sage.rings.finite_rings + sage: U * A # optional - sage.rings.finite_rings [ x 1 2*x] - sage: U*A == H + sage: U * A == H # optional - sage.rings.finite_rings True """ left, H, pivots = self._echelon_form_PID() @@ -15900,57 +15998,57 @@ cdef class Matrix(Matrix1): column pivot. EXAMPLES:: - sage: L. = NumberField(x^3 - 2) - sage: OL = L.ring_of_integers() + sage: L. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers() # optional - sage.rings.number_field We check some degenerate cases:: - sage: m = matrix(OL, 0, 0, []); r,s,p = m._echelon_form_PID() - sage: (r,s,p) + sage: m = matrix(OL, 0, 0, []); r,s,p = m._echelon_form_PID() # optional - sage.rings.number_field + sage: (r,s,p) # optional - sage.rings.number_field ([], [], []) - sage: r * m == s and r.det() == 1 + sage: r * m == s and r.det() == 1 # optional - sage.rings.number_field True - sage: m = matrix(OL, 0, 1, []); r,s,p = m._echelon_form_PID() - sage: (r,s,p) + sage: m = matrix(OL, 0, 1, []); r,s,p = m._echelon_form_PID() # optional - sage.rings.number_field + sage: (r,s,p) # optional - sage.rings.number_field ([], [], []) - sage: r * m == s and r.det() == 1 + sage: r * m == s and r.det() == 1 # optional - sage.rings.number_field True - sage: m = matrix(OL, 1, 0, []); r,s,p = m._echelon_form_PID() - sage: (r,s,p) + sage: m = matrix(OL, 1, 0, []); r,s,p = m._echelon_form_PID() # optional - sage.rings.number_field + sage: (r,s,p) # optional - sage.rings.number_field ([1], [], []) - sage: r * m == s and r.det() == 1 + sage: r * m == s and r.det() == 1 # optional - sage.rings.number_field True A 2x2 matrix:: - sage: m = matrix(OL, 2, 2, [1,0, a, 2]) - sage: r,s,p = m._echelon_form_PID(); (r,s,p) + sage: m = matrix(OL, 2, 2, [1, 0, a, 2]) # optional - sage.rings.number_field + sage: r,s,p = m._echelon_form_PID(); (r,s,p) # optional - sage.rings.number_field ( [ 1 0] [1 0] [-a 1], [0 2], [0, 1] ) - sage: r * m == s and r.det() == 1 + sage: r * m == s and r.det() == 1 # optional - sage.rings.number_field True A larger example:: - sage: m = matrix(OL, 3, 5, [a^2 - 3*a - 1, a^2 - 3*a + 1, a^2 + 1, + sage: m = matrix(OL, 3, 5, [a^2 - 3*a - 1, a^2 - 3*a + 1, a^2 + 1, # optional - sage.rings.number_field ....: -a^2 + 2, -3*a^2 - a - 1, -6*a - 1, a^2 - 3*a - 1, ....: 2*a^2 + a + 5, -2*a^2 + 5*a + 1, -a^2 + 13*a - 3, ....: -2*a^2 + 4*a - 2, -2*a^2 + 1, 2*a, a^2 - 6, 3*a^2 - a ]) - sage: r,s,p = m._echelon_form_PID() - sage: s[2] + sage: r,s,p = m._echelon_form_PID() # optional - sage.rings.number_field + sage: s[2] # optional - sage.rings.number_field (0, 0, -3*a^2 - 18*a + 34, -68*a^2 + 134*a - 53, -111*a^2 + 275*a - 90) - sage: r * m == s and r.det() == 1 + sage: r * m == s and r.det() == 1 # optional - sage.rings.number_field True We verify that :trac:`9053` is resolved:: - sage: R. = GF(7)[] - sage: A = R^3 - sage: L = A.span([x*A.0 + (x^3 + 1)*A.1, x*A.2]) - sage: M = A.span([x*L.0]) - sage: M.0 in L + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = R^3 # optional - sage.rings.finite_rings + sage: L = A.span([x*A.0 + (x^3 + 1)*A.1, x*A.2]) # optional - sage.rings.finite_rings + sage: M = A.span([x*L.0]) # optional - sage.rings.finite_rings + sage: M.0 in L # optional - sage.rings.finite_rings True """ @@ -16373,7 +16471,7 @@ cdef class Matrix(Matrix1): sage: U.inverse()*B*U == Z True - sage: A.jordan_form() == B.jordan_form() + sage: A.jordan_form() == B.jordan_form() # optional - sage.combinat True Two more examples, illustrating the two extremes of the zig-zag @@ -16434,38 +16532,38 @@ cdef class Matrix(Matrix1): sage: U.inverse()*D*U == Z True - sage: C.jordan_form() == D.jordan_form() + sage: C.jordan_form() == D.jordan_form() # optional - sage.combinat True ZigZag form is achieved entirely with the operations of the field, so while the eigenvalues may lie outside the field, this does not impede the computation of the form. :: - sage: F. = GF(5^4) - sage: A = matrix(F, [[ a, 0, 0, a + 3], + sage: F. = GF(5^4) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[ a, 0, 0, a + 3], # optional - sage.rings.finite_rings ....: [ 0,a^2 + 1, 0, 0], ....: [ 0, 0,a^3, 0], ....: [a^2 +4 , 0, 0,a + 2]]) - sage: A.zigzag_form() + sage: A.zigzag_form() # optional - sage.rings.finite_rings [ 0 a^3 + 2*a^2 + 2*a + 2| 0| 0] [ 1 2*a + 2| 0| 0] [-------------------------------------------+---------------------+---------------------] [ 0 0| a^3| 0] [-------------------------------------------+---------------------+---------------------] [ 0 0| 0| a^2 + 1] - sage: A.eigenvalues() + sage: A.eigenvalues() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: algebraic closures of finite fields are only implemented for prime fields Subdivisions are optional. :: - sage: F. = GF(5^4) - sage: A = matrix(F, [[ a, 0, 0, a + 3], + sage: F. = GF(5^4) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[ a, 0, 0, a + 3], # optional - sage.rings.finite_rings ....: [ 0,a^2 + 1, 0, 0], ....: [ 0, 0,a^3, 0], ....: [a^2 +4 , 0, 0,a + 2]]) - sage: A.zigzag_form(subdivide=False) + sage: A.zigzag_form(subdivide=False) # optional - sage.rings.finite_rings [ 0 a^3 + 2*a^2 + 2*a + 2 0 0] [ 1 2*a + 2 0 0] [ 0 0 a^3 0] @@ -16636,13 +16734,13 @@ cdef class Matrix(Matrix1): sage: invariants [[4, -4, 1], [-12, 4, 9, -6, 1], [216, -108, -306, 271, 41, -134, 64, -13, 1]] sage: polys = [R(p) for p in invariants] - sage: [p.factor() for p in polys] + sage: [p.factor() for p in polys] # optional - sage.rings.finite_rings [(x - 2)^2, (x - 3) * (x + 1) * (x - 2)^2, (x + 1)^2 * (x - 3)^3 * (x - 2)^3] sage: all(polys[i].divides(polys[i+1]) for i in range(len(polys)-1)) True - sage: polys[-1] == A.minimal_polynomial(var='x') + sage: polys[-1] == A.minimal_polynomial(var='x') # optional - sage.libs.pari True - sage: prod(polys) == A.characteristic_polynomial(var='x') + sage: prod(polys) == A.characteristic_polynomial(var='x') # optional - sage.libs.pari True Rational form is a canonical form. Any two matrices are similar @@ -16660,9 +16758,9 @@ cdef class Matrix(Matrix1): ....: [0, -42, 14, 8, 167, -17, -84, 13], ....: [0, -50, 17, 10, 199, -23, -98, 14], ....: [0, 15, -5, -2, -59, 7, 30, -2]]) - sage: C.minimal_polynomial().factor() + sage: C.minimal_polynomial().factor() # optional - sage.libs.pari (x - 2)^2 - sage: C.characteristic_polynomial().factor() + sage: C.characteristic_polynomial().factor() # optional - sage.libs.pari (x - 2)^8 sage: C.rational_form() [ 0 -4| 0 0| 0 0| 0 0] @@ -16685,9 +16783,9 @@ cdef class Matrix(Matrix1): ....: [ 31, -18, 135, 38, 12, 47, 155, -147], ....: [-33, 19, -138, -39, -13, -45, -156, 151], ....: [ -7, 4, -29, -8, -3, -10, -34, 34]]) - sage: D.minimal_polynomial().factor() + sage: D.minimal_polynomial().factor() # optional - sage.libs.pari (x - 2)^2 - sage: D.characteristic_polynomial().factor() + sage: D.characteristic_polynomial().factor() # optional - sage.libs.pari (x - 2)^8 sage: D.rational_form() [ 0 -4| 0 0| 0 0| 0 0] @@ -16710,9 +16808,9 @@ cdef class Matrix(Matrix1): ....: [-3, -7, 5, -6, -1, 5, -4, 14], ....: [ 6, 18, -10, 14, 4, -10, 10, -28], ....: [-2, -6, 4, -5, -1, 3, -3, 13]]) - sage: E.minimal_polynomial().factor() + sage: E.minimal_polynomial().factor() # optional - sage.libs.pari (x - 2)^3 - sage: E.characteristic_polynomial().factor() + sage: E.characteristic_polynomial().factor() # optional - sage.libs.pari (x - 2)^8 sage: E.rational_form() [ 2| 0 0| 0 0| 0 0 0] @@ -16749,9 +16847,9 @@ cdef class Matrix(Matrix1): ....: [ 139, -35, 99, -49, -18, 236, -41, -70, 370, -118, -377, -619], ....: [ 243, 9, 81, -72, -81, 386, 43, -105, 508, -124, -564, -911], ....: [-155, -3, -55, 45, 50, -245, -27, 65, -328, 77, 365, 583]]) - sage: A.characteristic_polynomial().factor() + sage: A.characteristic_polynomial().factor() # optional - sage.libs.pari (x^2 - 2)^2 * (x^2 + 2*x + 5)^4 - sage: A.eigenvalues(extend=False) + sage: A.eigenvalues(extend=False) # optional - sage.rings.number_field [] sage: A.rational_form() [ 0 -5| 0 0 0 0| 0 0 0 0 0 0] @@ -16770,14 +16868,14 @@ cdef class Matrix(Matrix1): [ 0 0| 0 0 0 0| 0 0 0 0 1 -4] sage: F. = QQ[] sage: polys = A.rational_form(format='invariants') - sage: [F(p).factor() for p in polys] + sage: [F(p).factor() for p in polys] # optional - sage.libs.pari [x^2 + 2*x + 5, (x^2 - 2) * (x^2 + 2*x + 5), (x^2 - 2) * (x^2 + 2*x + 5)^2] Rational form may be computed over any field. The matrix below is an example where the eigenvalues lie outside the field. :: - sage: F. = FiniteField(7^2) - sage: A = matrix(F, + sage: F. = FiniteField(7^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, # optional - sage.rings.finite_rings ....: [[5*a + 3, 4*a + 1, 6*a + 2, 2*a + 5, 6, 4*a + 5, 4*a + 5, 5, a + 6, 5, 4*a + 4], ....: [6*a + 3, 2*a + 4, 0, 6, 5*a + 5, 2*a, 5*a + 1, 1, 5*a + 2, 4*a, 5*a + 6], ....: [3*a + 1, 6*a + 6, a + 6, 2, 0, 3*a + 6, 5*a + 4, 5*a + 6, 5*a + 2, 3, 4*a + 2], @@ -16789,7 +16887,7 @@ cdef class Matrix(Matrix1): ....: [3*a + 5, 6*a + 2, 4*a, a + 5, 0, 5*a, 6*a + 5, 2*a + 1, 3*a + 1, 3*a + 5, 4*a + 2], ....: [3*a + 2, a + 3, 3*a + 6, a, 3*a + 5, 5*a + 1, 3*a + 2, a + 3, a + 2, 6*a + 1, 3*a + 3], ....: [6*a + 6, 5*a + 1, 4*a, 2, 5*a + 5, 3*a + 5, 3*a + 1, 2*a, 2*a, 2*a + 4, 4*a + 2]]) - sage: A.rational_form() + sage: A.rational_form() # optional - sage.rings.finite_rings [ a + 2| 0 0 0| 0 0 0 0 0 0 0] [-------+-----------------------+-------------------------------------------------------] [ 0| 0 0 a + 6| 0 0 0 0 0 0 0] @@ -16803,18 +16901,18 @@ cdef class Matrix(Matrix1): [ 0| 0 0 0| 0 0 0 1 0 0 a + 6] [ 0| 0 0 0| 0 0 0 0 1 0 2*a + 1] [ 0| 0 0 0| 0 0 0 0 0 1 2*a + 1] - sage: invariants = A.rational_form(format='invariants') - sage: invariants + sage: invariants = A.rational_form(format='invariants') # optional - sage.rings.finite_rings + sage: invariants # optional - sage.rings.finite_rings [[6*a + 5, 1], [6*a + 1, a + 3, a + 3, 1], [5*a, a + 4, a + 6, 6*a + 5, 6*a + 1, 5*a + 6, 5*a + 6, 1]] - sage: R. = F[] - sage: polys = [R(p) for p in invariants] - sage: [p.factor() for p in polys] + sage: R. = F[] # optional - sage.rings.finite_rings + sage: polys = [R(p) for p in invariants] # optional - sage.rings.finite_rings + sage: [p.factor() for p in polys] # optional - sage.rings.finite_rings [x + 6*a + 5, (x + 6*a + 5) * (x^2 + (2*a + 5)*x + 5*a), (x + 6*a + 5) * (x^2 + (2*a + 5)*x + 5*a)^3] - sage: polys[-1] == A.minimal_polynomial() + sage: polys[-1] == A.minimal_polynomial() # optional - sage.rings.finite_rings True - sage: prod(polys) == A.characteristic_polynomial() + sage: prod(polys) == A.characteristic_polynomial() # optional - sage.rings.finite_rings True - sage: A.eigenvalues() + sage: A.eigenvalues() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: algebraic closures of finite fields are only implemented for prime fields @@ -17011,46 +17109,47 @@ cdef class Matrix(Matrix1): Nonnegative matrices are positive operators on the nonnegative orthant:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = random_matrix(QQ,3).apply_map(abs) - sage: L.is_positive_operator_on(K) + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = random_matrix(QQ, 3).apply_map(abs) + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron True Symbolic entries also work in some easy cases:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = matrix(SR, [ [0, e, 0 ], + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = matrix(SR, [ [0, e, 0 ], # optional - sage.symbolic ....: [0, 2, pi], ....: [sqrt(2), 0, 0 ] ]) - sage: L.is_positive_operator_on(K) + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron sage.symbolic True Your matrix can be over any exact ring, for example the ring of univariate polynomials with rational coefficients:: - sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)]) - sage: K.is_full_space() + sage: K = Cone([(1,0), (-1,0), (0,1), (0,-1)]) # optional - sage.geometry.polyhedron + sage: K.is_full_space() # optional - sage.geometry.polyhedron True + sage: x = polygen(ZZ, 'x') sage: L = matrix(QQ[x], [[x,0],[0,1]]) - sage: L.is_positive_operator_on(K) + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron True TESTS: The identity matrix is always a positive operator:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = identity_matrix(R, K.lattice_dim()) - sage: L.is_positive_operator_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = identity_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron True The zero matrix is always a positive operator:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = zero_matrix(R, K.lattice_dim()) - sage: L.is_positive_operator_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = zero_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron True Everything in ``K1.positive_operators_gens(K2)`` should be @@ -17058,11 +17157,11 @@ cdef class Matrix(Matrix1): the underlying ring symbolic (the usual case is tested by the ``positive_operators_gens`` method):: - sage: K1 = random_cone(max_ambient_dim=5) - sage: K2 = random_cone(max_ambient_dim=5) - sage: results = ( L.change_ring(SR).is_positive_operator_on(K1, K2) + sage: K1 = random_cone(max_ambient_dim=5) # optional - sage.geometry.polyhedron + sage: K2 = random_cone(max_ambient_dim=5) # optional - sage.geometry.polyhedron + sage: results = ( L.change_ring(SR).is_positive_operator_on(K1, K2) # optional - sage.geometry.polyhedron sage.symbolic ....: for L in K1.positive_operators_gens(K2) ) - sage: all(results) # long time + sage: all(results) # long time # optional - sage.geometry.polyhedron sage.symbolic True Technically we could test this, but for now only closed convex cones @@ -17077,9 +17176,9 @@ cdef class Matrix(Matrix1): We can't give reliable answers over inexact rings:: - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(RR,3) - sage: L.is_positive_operator_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(RR, 3) + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron Traceback (most recent call last): ... ValueError: The base ring of the matrix is neither symbolic nor @@ -17087,11 +17186,11 @@ cdef class Matrix(Matrix1): Symbolic subrings are fine:: - sage: SCR = SR.subring(no_variables=True); SCR + sage: SCR = SR.subring(no_variables=True); SCR # optional - sage.symbolic Symbolic Constants Subring - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(SCR, 3) - sage: L.is_positive_operator_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(SCR, 3) # optional - sage.symbolic + sage: L.is_positive_operator_on(K) # optional - sage.geometry.polyhedron sage.symbolic True """ import sage.geometry.abc @@ -17169,38 +17268,38 @@ cdef class Matrix(Matrix1): Negative Z-matrices are cross-positive operators on the nonnegative orthant:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = matrix(SR, [ [-1, 2, 0], + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = matrix(SR, [ [-1, 2, 0], # optional - sage.symbolic ....: [ 0, 2, 7], ....: [ 3, 0, 3] ]) - sage: L.is_cross_positive_on(K) + sage: L.is_cross_positive_on(K) # optional - sage.geometry.polyhedron sage.symbolic True Symbolic entries also work in some easy cases:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = matrix(SR, [ [-1, e, 0 ], + sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = matrix(SR, [ [-1, e, 0 ], # optional - sage.symbolic ....: [ 0, 2, pi], ....: [ sqrt(2), 0, 3 ] ]) - sage: L.is_cross_positive_on(K) + sage: L.is_cross_positive_on(K) # optional - sage.geometry.polyhedron sage.symbolic True TESTS: The identity matrix is always cross-positive:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = identity_matrix(R, K.lattice_dim()) - sage: L.is_cross_positive_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = identity_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_cross_positive_on(K) # optional - sage.geometry.polyhedron True The zero matrix is always cross-positive:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = zero_matrix(R, K.lattice_dim()) - sage: L.is_cross_positive_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = zero_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_cross_positive_on(K) # optional - sage.geometry.polyhedron True Everything in ``K.cross_positive_operators_gens()`` should be @@ -17208,10 +17307,10 @@ cdef class Matrix(Matrix1): symbolic (the usual case is tested by the ``cross_positive_operators_gens`` method):: - sage: K = random_cone(max_ambient_dim=5) - sage: results = ( L.change_ring(SR).is_cross_positive_on(K) + sage: K = random_cone(max_ambient_dim=5) # optional - sage.geometry.polyhedron + sage: results = ( L.change_ring(SR).is_cross_positive_on(K) # optional - sage.geometry.polyhedron sage.symbolic ....: for L in K.cross_positive_operators_gens() ) - sage: all(results) # long time + sage: all(results) # long time # optional - sage.geometry.polyhedron sage.symbolic True Technically we could test this, but for now only closed convex cones @@ -17226,9 +17325,9 @@ cdef class Matrix(Matrix1): We can't give reliable answers over inexact rings:: - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(RR,3) - sage: L.is_cross_positive_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(RR, 3) + sage: L.is_cross_positive_on(K) # optional - sage.geometry.polyhedron Traceback (most recent call last): ... ValueError: The base ring of the matrix is neither symbolic nor @@ -17236,11 +17335,11 @@ cdef class Matrix(Matrix1): Symbolic subrings are fine:: - sage: SCR = SR.subring(no_variables=True); SCR + sage: SCR = SR.subring(no_variables=True); SCR # optional - sage.symbolic Symbolic Constants Subring - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(SCR, 3) - sage: L.is_cross_positive_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(SCR, 3) # optional - sage.symbolic + sage: L.is_cross_positive_on(K) # optional - sage.geometry.polyhedron sage.symbolic True """ import sage.geometry.abc @@ -17307,46 +17406,46 @@ cdef class Matrix(Matrix1): Z-matrices are Z-operators on the nonnegative orthant:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = matrix(SR, [ [-1, -2, 0], + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = matrix(SR, [ [-1, -2, 0], # optional - sage.symbolic ....: [ 0, 2, -7], ....: [-3, 0, 3] ]) - sage: L.is_Z_operator_on(K) + sage: L.is_Z_operator_on(K) # optional - sage.geometry.polyhedron sage.symbolic True Symbolic entries also work in some easy cases:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = matrix(SR, [ [-1, -e, 0 ], + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = matrix(SR, [ [-1, -e, 0 ], # optional - sage.symbolic ....: [ 0, 2, -pi], ....: [-sqrt(2), 0, 3 ] ]) - sage: L.is_Z_operator_on(K) + sage: L.is_Z_operator_on(K) # optional - sage.geometry.polyhedron sage.symbolic True TESTS: The identity matrix is always a Z-operator:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = identity_matrix(R, K.lattice_dim()) - sage: L.is_Z_operator_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = identity_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_Z_operator_on(K) # optional - sage.geometry.polyhedron True The zero matrix is always a Z-operator:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = zero_matrix(R, K.lattice_dim()) - sage: L.is_Z_operator_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = zero_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_Z_operator_on(K) # optional - sage.geometry.polyhedron True Everything in ``K.Z_operators_gens()`` should be a Z-operator on ``K``, , even if we make the underlying ring symbolic (the usual case is tested by the ``Z_operators_gens`` method):: - sage: K = random_cone(max_ambient_dim=5) - sage: all(L.change_ring(SR).is_Z_operator_on(K) # long time + sage: K = random_cone(max_ambient_dim=5) # optional - sage.geometry.polyhedron + sage: all(L.change_ring(SR).is_Z_operator_on(K) # long time # optional - sage.geometry.polyhedron sage.symbolic ....: for L in K.Z_operators_gens()) True @@ -17362,9 +17461,9 @@ cdef class Matrix(Matrix1): We can't give reliable answers over inexact rings:: - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(RR,3) - sage: L.is_Z_operator_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(RR, 3) + sage: L.is_Z_operator_on(K) # optional - sage.geometry.polyhedron Traceback (most recent call last): ... ValueError: The base ring of the matrix is neither symbolic nor @@ -17426,36 +17525,36 @@ cdef class Matrix(Matrix1): Diagonal matrices are Lyapunov-like operators on the nonnegative orthant:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = diagonal_matrix(random_vector(QQ,3)) - sage: L.is_lyapunov_like_on(K) + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = diagonal_matrix(random_vector(QQ, 3)) + sage: L.is_lyapunov_like_on(K) # optional - sage.geometry.polyhedron True Symbolic entries also work in some easy cases:: - sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)]) - sage: L = matrix(SR, [ [e, 0, 0 ], + sage: K = Cone([(1,0,0), (0,1,0), (0,0,1)]) # optional - sage.geometry.polyhedron + sage: L = matrix(SR, [ [e, 0, 0 ], # optional - sage.symbolic ....: [0, pi, 0 ], ....: [0, 0, sqrt(2)] ]) - sage: L.is_lyapunov_like_on(K) + sage: L.is_lyapunov_like_on(K) # optional - sage.geometry.polyhedron sage.symbolic True TESTS: The identity matrix is always Lyapunov-like:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = identity_matrix(R, K.lattice_dim()) - sage: L.is_lyapunov_like_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = identity_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_lyapunov_like_on(K) # optional - sage.geometry.polyhedron True The zero matrix is always Lyapunov-like:: - sage: K = random_cone(max_ambient_dim=8) - sage: R = K.lattice().vector_space().base_ring() - sage: L = zero_matrix(R, K.lattice_dim()) - sage: L.is_lyapunov_like_on(K) + sage: K = random_cone(max_ambient_dim=8) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = zero_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: L.is_lyapunov_like_on(K) # optional - sage.geometry.polyhedron True Everything in ``K.lyapunov_like_basis()`` should be @@ -17463,8 +17562,8 @@ cdef class Matrix(Matrix1): symbolic (the usual case is tested by the ``lyapunov_like_basis`` method):: - sage: K = random_cone(max_ambient_dim=5) - sage: all(L.change_ring(SR).is_lyapunov_like_on(K) # long time + sage: K = random_cone(max_ambient_dim=5) # optional - sage.geometry.polyhedron + sage: all(L.change_ring(SR).is_lyapunov_like_on(K) # long time # optional - sage.geometry.polyhedron sage.symbolic ....: for L in K.lyapunov_like_basis()) True @@ -17480,9 +17579,9 @@ cdef class Matrix(Matrix1): We can't give reliable answers over inexact rings:: - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(RR,3) - sage: L.is_lyapunov_like_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(RR, 3) + sage: L.is_lyapunov_like_on(K) # optional - sage.geometry.polyhedron Traceback (most recent call last): ... ValueError: The base ring of the matrix is neither symbolic nor @@ -17490,23 +17589,23 @@ cdef class Matrix(Matrix1): Symbolic subrings are fine:: - sage: SCR = SR.subring(no_variables=True); SCR + sage: SCR = SR.subring(no_variables=True); SCR # optional - sage.symbolic Symbolic Constants Subring - sage: K = Cone([(1,2,3), (4,5,6)]) - sage: L = identity_matrix(SCR, 3) - sage: L.is_lyapunov_like_on(K) + sage: K = Cone([(1,2,3), (4,5,6)]) # optional - sage.geometry.polyhedron + sage: L = identity_matrix(SCR, 3) # optional - sage.symbolic + sage: L.is_lyapunov_like_on(K) # optional - sage.geometry.polyhedron sage.symbolic True A matrix is Lyapunov-like on a cone if and only if both the matrix and its negation are cross-positive on the cone:: - sage: K = random_cone(max_ambient_dim=5) - sage: R = K.lattice().vector_space().base_ring() - sage: L = random_matrix(R, K.lattice_dim()) - sage: actual = L.is_lyapunov_like_on(K) # long time - sage: expected = (L.is_cross_positive_on(K) and # long time + sage: K = random_cone(max_ambient_dim=5) # optional - sage.geometry.polyhedron + sage: R = K.lattice().vector_space().base_ring() # optional - sage.geometry.polyhedron + sage: L = random_matrix(R, K.lattice_dim()) # optional - sage.geometry.polyhedron + sage: actual = L.is_lyapunov_like_on(K) # long time # optional - sage.geometry.polyhedron + sage: expected = (L.is_cross_positive_on(K) and # long time # optional - sage.geometry.polyhedron ....: (-L).is_cross_positive_on(K)) - sage: actual == expected # long time + sage: actual == expected # long time # optional - sage.geometry.polyhedron True """ import sage.geometry.abc @@ -17567,9 +17666,9 @@ cdef class Matrix(Matrix1): Create a Gram matrix and LLL-reduce it:: sage: M = Matrix(ZZ, 2, 2, [5, 3, 3, 2]) - sage: U = M.LLL_gram() - sage: MM = U.transpose() * M * U - sage: M, U, MM + sage: U = M.LLL_gram() # optional - sage.libs.pari + sage: MM = U.transpose() * M * U # optional - sage.libs.pari + sage: M, U, MM # optional - sage.libs.pari ( [5 3] [-1 1] [1 0] [3 2], [ 1 -2], [0 1] @@ -17581,28 +17680,28 @@ cdef class Matrix(Matrix1): preserve orientation). :: sage: M = Matrix(RDF, 2, 2, [1, 0, 0, 1e-5]) - sage: M.LLL_gram() + sage: M.LLL_gram() # optional - sage.libs.pari [ 0 -1] [ 1 0] The algorithm might work for some semidefinite and indefinite forms:: - sage: Matrix(ZZ, 2, 2, [2, 6, 6, 3]).LLL_gram() + sage: Matrix(ZZ, 2, 2, [2, 6, 6, 3]).LLL_gram() # optional - sage.libs.pari [-3 -1] [ 1 0] - sage: Matrix(ZZ, 2, 2, [1, 0, 0, -1]).LLL_gram() + sage: Matrix(ZZ, 2, 2, [1, 0, 0, -1]).LLL_gram() # optional - sage.libs.pari [ 0 -1] [ 1 0] However, it might fail for others, either raising a ``ValueError``:: - sage: Matrix(ZZ, 1, 1, [0]).LLL_gram() + sage: Matrix(ZZ, 1, 1, [0]).LLL_gram() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: qflllgram did not return a square matrix, perhaps the matrix is not positive definite - sage: Matrix(ZZ, 2, 2, [0, 1, 1, 0]).LLL_gram() + sage: Matrix(ZZ, 2, 2, [0, 1, 1, 0]).LLL_gram() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: qflllgram did not return a square matrix, @@ -17610,14 +17709,14 @@ cdef class Matrix(Matrix1): or running forever:: - sage: Matrix(ZZ, 2, 2, [-5, -1, -1, -5]).LLL_gram() # not tested + sage: Matrix(ZZ, 2, 2, [-5, -1, -1, -5]).LLL_gram() # not tested # optional - sage.libs.pari Traceback (most recent call last): ... RuntimeError: infinite loop while calling qflllgram Nonreal input leads to a value error:: - sage: Matrix(2, 2, [CDF(1, 1), 0, 0, 1]).LLL_gram() + sage: Matrix(2, 2, [CDF(1, 1), 0, 0, 1]).LLL_gram() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: qflllgram failed, perhaps the matrix is not positive definite @@ -17671,10 +17770,10 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQbar, [[ -3, 5 - 3*I, 7 - 4*I], + sage: A = matrix(QQbar, [[ -3, 5 - 3*I, 7 - 4*I], # optional - sage.rings.number_field ....: [7 + 3*I, -1 + 6*I, 3 + 5*I], ....: [3 + 3*I, -3 + 6*I, 5 + I]]) - sage: A.C + sage: A.C # optional - sage.rings.number_field [ -3 5 + 3*I 7 + 4*I] [ 7 - 3*I -1 - 6*I 3 - 5*I] [ 3 - 3*I -3 - 6*I 5 - 1*I] @@ -17689,10 +17788,10 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: A = matrix(QQbar, [[ -3, 5 - 3*I, 7 - 4*I], + sage: A = matrix(QQbar, [[ -3, 5 - 3*I, 7 - 4*I], # optional - sage.rings.number_field ....: [7 + 3*I, -1 + 6*I, 3 + 5*I], ....: [3 + 3*I, -3 + 6*I, 5 + I]]) - sage: A.H + sage: A.H # optional - sage.rings.number_field [ -3 7 - 3*I 3 - 3*I] [ 5 + 3*I -1 - 6*I -3 - 6*I] [ 7 + 4*I 3 - 5*I 5 - 1*I] @@ -17712,19 +17811,19 @@ def _smith_diag(d, transformation=True): EXAMPLES:: sage: from sage.matrix.matrix2 import _smith_diag - sage: OE = EquationOrder(x^2 - x + 2, 'w') - sage: A = matrix(OE, 2, [2,0,0,3]) - sage: D,U,V = _smith_diag(A); D,U,V + sage: OE = EquationOrder(x^2 - x + 2, 'w') # optional - sage.rings.number_field + sage: A = matrix(OE, 2, [2, 0, 0, 3]) # optional - sage.rings.number_field + sage: D,U,V = _smith_diag(A); D,U,V # optional - sage.rings.number_field ( [1 0] [2 1] [ 1 -3] [0 6], [3 2], [-1 4] ) - sage: D == U*A*V + sage: D == U*A*V # optional - sage.rings.number_field True - sage: m = matrix(GF(7),2, [3,0,0,6]); d,u,v = _smith_diag(m); d + sage: m = matrix(GF(7), 2, [3,0,0,6]); d,u,v = _smith_diag(m); d # optional - sage.rings.finite_rings [1 0] [0 1] - sage: u*m*v == d + sage: u*m*v == d # optional - sage.rings.finite_rings True """ @@ -17788,12 +17887,12 @@ def _generic_clear_column(m): EXAMPLES:: - sage: L. = NumberField(x^2 - x + 2) - sage: OL = L.ring_of_integers(); w = OL(w) - sage: m = matrix(OL, 8, 4, [2*w - 2, 2*w + 1, -2, w, 2, -2,-2*w - 2, -2*w + 2, -w + 2, 2*w + 1, -w + 2, -w - 2, -2*w, 2*w, -w+ 2, w - 1, -2*w + 2, 2*w + 2, 2*w - 1, -w, 2*w + 2, -w + 2, 2, 2*w -1, w - 4, -2*w - 2, 2*w - 1, 0, 6, 7, 2*w + 1, 14]) - sage: s,t = m.echelon_form(transformation=True); t*m == s # indirect doctest + sage: L. = NumberField(x^2 - x + 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers(); w = OL(w) # optional - sage.rings.number_field + sage: m = matrix(OL, 8, 4, [2*w - 2, 2*w + 1, -2, w, 2, -2,-2*w - 2, -2*w + 2, -w + 2, 2*w + 1, -w + 2, -w - 2, -2*w, 2*w, -w+ 2, w - 1, -2*w + 2, 2*w + 2, 2*w - 1, -w, 2*w + 2, -w + 2, 2, 2*w -1, w - 4, -2*w - 2, 2*w - 1, 0, 6, 7, 2*w + 1, 14]) # optional - sage.rings.number_field + sage: s,t = m.echelon_form(transformation=True); t*m == s # indirect doctest # optional - sage.rings.number_field True - sage: s[0] + sage: s[0] # optional - sage.rings.number_field (w, 0, 0, 0) """ if m.nrows() <= 1 or m.ncols() <= 0: @@ -17895,13 +17994,13 @@ def _smith_onestep(m): EXAMPLES:: sage: from sage.matrix.matrix2 import _smith_onestep - sage: OE. = EquationOrder(x^2 - x + 2) - sage: m = matrix(OE, 3,3,[1,0,7,2,w, w+17, 13+8*w, 0, 6]) - sage: a,b,c = _smith_onestep(m); b + sage: OE. = EquationOrder(x^2 - x + 2) # optional - sage.rings.number_field + sage: m = matrix(OE, 3, 3, [1, 0, 7, 2, w, w+17, 13+8*w, 0, 6]) # optional - sage.rings.number_field + sage: a,b,c = _smith_onestep(m); b # optional - sage.rings.number_field [ 1 0 0] [ 0 w w + 3] [ 0 0 -56*w - 85] - sage: a * m * c == b + sage: a * m * c == b # optional - sage.rings.number_field True """ @@ -18099,27 +18198,27 @@ def _matrix_power_symbolic(A, n): General power of a two by two matrix:: - sage: n = SR.var('n') + sage: n = SR.var('n') # optional - sage.symbolic sage: A = matrix(QQ, [[2, -1], [1, 0]]) - sage: B = A^n; B + sage: B = A^n; B # optional - sage.symbolic [ n + 1 -n] [ n -n + 1] - sage: all(A^k == B.subs({n: k}) for k in range(8)) + sage: all(A^k == B.subs({n: k}) for k in range(8)) # optional - sage.symbolic True General power of a three by three matrix in Jordan form:: - sage: n = SR.var('n') + sage: n = SR.var('n') # optional - sage.symbolic sage: A = matrix(QQ, 3, [[2, 1, 0], [0, 2, 0], [0, 0, 3]]) sage: A [2 1 0] [0 2 0] [0 0 3] - sage: B = A^n; B + sage: B = A^n; B # optional - sage.symbolic [ 2^n 2^(n - 1)*n 0] [ 0 2^n 0] [ 0 0 3^n] - sage: all(A^k == B.subs({n: k}) for k in range(8)) + sage: all(A^k == B.subs({n: k}) for k in range(8)) # optional - sage.symbolic True General power of a three by three matrix not in Jordan form:: @@ -18129,26 +18228,26 @@ def _matrix_power_symbolic(A, n): [ 4 1 2] [ 0 2 -4] [ 0 1 6] - sage: B = A^n; B + sage: B = A^n; B # optional - sage.symbolic [ 4^n 4^(n - 1)*n 2*4^(n - 1)*n] [ 0 -2*4^(n - 1)*n + 4^n -4*4^(n - 1)*n] [ 0 4^(n - 1)*n 2*4^(n - 1)*n + 4^n] - sage: [B.subs({n: k}) for k in range(4)] + sage: [B.subs({n: k}) for k in range(4)] # optional - sage.symbolic [ [1 0 0] [ 4 1 2] [ 16 8 16] [ 64 48 96] [0 1 0] [ 0 2 -4] [ 0 0 -32] [ 0 -32 -192] [0 0 1], [ 0 1 6], [ 0 8 32], [ 0 48 160] ] - sage: all(A^k == B.subs({n: k}) for k in range(8)) + sage: all(A^k == B.subs({n: k}) for k in range(8)) # optional - sage.symbolic True TESTS: Testing exponentiation in the symbolic ring:: - sage: n = var('n') - sage: A = matrix([[pi, e],[0, -2*I]]) - sage: (A^n).list() + sage: n = var('n') # optional - sage.symbolic + sage: A = matrix([[pi, e],[0, -2*I]]) # optional - sage.symbolic + sage: (A^n).list() # optional - sage.symbolic [pi^n, -(-2*I)^n/(pi*e^(-1) + 2*I*e^(-1)) + pi^n/(pi*e^(-1) + 2*I*e^(-1)), 0, @@ -18164,15 +18263,15 @@ def _matrix_power_symbolic(A, n): Testing exponentiation in the integer ring:: - sage: A = matrix(ZZ, [[1,-1],[-1,1]]) + sage: A = matrix(ZZ, [[1,-1], [-1,1]]) sage: A^(2*n+1) [ 1/2*2^(2*n + 1) -1/2*2^(2*n + 1)] [-1/2*2^(2*n + 1) 1/2*2^(2*n + 1)] Check if :trac:`23215` is fixed:: - sage: a, b, k = var('a, b, k') - sage: (matrix(2, [a, b, -b, a])^k).list() + sage: a, b, k = var('a, b, k') # optional - sage.symbolic + sage: (matrix(2, [a, b, -b, a])^k).list() # optional - sage.symbolic [1/2*(a + I*b)^k + 1/2*(a - I*b)^k, -1/2*I*(a + I*b)^k + 1/2*I*(a - I*b)^k, 1/2*I*(a + I*b)^k - 1/2*I*(a - I*b)^k, diff --git a/src/sage/matrix/matrix_cdv.pyx b/src/sage/matrix/matrix_cdv.pyx index 43421c74cb9..c67936f6e4c 100644 --- a/src/sage/matrix/matrix_cdv.pyx +++ b/src/sage/matrix/matrix_cdv.pyx @@ -35,29 +35,31 @@ cpdef hessenbergize_cdvf(Matrix_generic_dense H): TESTS:: - sage: K = Qp(5, print_mode="digits", prec=5) - sage: H = matrix(K, 3, 3, range(9)) - sage: H + sage: K = Qp(5, print_mode="digits", prec=5) # optional - sage.rings.padics + sage: H = matrix(K, 3, 3, range(9)) # optional - sage.rings.padics + sage: H # optional - sage.rings.padics [ 0 ...00001 ...00002] [ ...00003 ...00004 ...000010] [ ...00011 ...00012 ...00013] - sage: H.hessenbergize() - sage: H + sage: H.hessenbergize() # optional - sage.rings.padics + sage: H # optional - sage.rings.padics [ 0 ...00010 ...00002] [ ...00003 ...00024 ...000010] [ ...00000 ...44440 ...44443] :: - sage: M = random_matrix(K, 6, 6) - sage: M.charpoly()[0] == M.determinant() + sage: M = random_matrix(K, 6, 6) # optional - sage.rings.padics + sage: M.charpoly()[0] == M.determinant() # optional - sage.rings.padics True We check that :trac:`31753` is resolved:: - sage: R. = GF(5)[[]] - sage: M = matrix(3, 3, [ 1, t + O(t^3), t^2, 1 + t + O(t^3), 2 + t^2, 3 + 2*t + O(t^3), t - t^2, 2*t, 1 + t ]) - sage: M.charpoly() + sage: R. = GF(5)[[]] # optional - sage.libs.pari + sage: M = matrix(3, 3, [ 1, t + O(t^3), t^2, # optional - sage.libs.pari + ....: 1 + t + O(t^3), 2 + t^2, 3 + 2*t + O(t^3), + ....: t - t^2, 2*t, 1 + t ]) + sage: M.charpoly() # optional - sage.libs.pari x^3 + (1 + 4*t + 4*t^2 + O(t^3))*x^2 + (t + 2*t^2 + O(t^3))*x + 3 + 2*t^2 + O(t^3) """ cdef Py_ssize_t n, i, j, k diff --git a/src/sage/matrix/matrix_dense.pyx b/src/sage/matrix/matrix_dense.pyx index afc24c658e6..65d528f44dd 100644 --- a/src/sage/matrix/matrix_dense.pyx +++ b/src/sage/matrix/matrix_dense.pyx @@ -75,11 +75,11 @@ cdef class Matrix_dense(matrix.Matrix): Check :trac:`27629`:: - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: assume(x, 'real') - sage: M = matrix([[0, -x], [x, 0]]) - sage: M.transpose() == M + sage: assume(x, 'real') # optional - sage.symbolic + sage: M = matrix([[0, -x], [x, 0]]) # optional - sage.symbolic + sage: M.transpose() == M # optional - sage.symbolic False """ other = right @@ -271,8 +271,8 @@ cdef class Matrix_dense(matrix.Matrix): EXAMPLES:: - sage: m = matrix(2, [x^i for i in range(4)]) - sage: m._derivative(x) + sage: m = matrix(2, [x^i for i in range(4)]) # optional - sage.symbolic + sage: m._derivative(x) # optional - sage.symbolic [ 0 1] [ 2*x 3*x^2] """ diff --git a/src/sage/matrix/matrix_generic_dense.pyx b/src/sage/matrix/matrix_generic_dense.pyx index 49df19eacbf..313f3c5785c 100644 --- a/src/sage/matrix/matrix_generic_dense.pyx +++ b/src/sage/matrix/matrix_generic_dense.pyx @@ -70,12 +70,12 @@ cdef class Matrix_generic_dense(matrix_dense.Matrix_dense): We check that the problem related to :trac:`9049` is not an issue any more:: - sage: S.=PolynomialRing(QQ) - sage: F.=QQ.extension(t^4+1) - sage: R.=PolynomialRing(F) - sage: M = MatrixSpace(R, 1, 2) + sage: S. = PolynomialRing(QQ) + sage: F. = QQ.extension(t^4 + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(F) # optional - sage.rings.number_field + sage: M = MatrixSpace(R, 1, 2) # optional - sage.rings.number_field sage: from sage.matrix.matrix_generic_dense import Matrix_generic_dense - sage: Matrix_generic_dense(M, (x, y), True, True) + sage: Matrix_generic_dense(M, (x, y), True, True) # optional - sage.rings.number_field [x y] """ ma = MatrixArgs_init(parent, entries) @@ -215,10 +215,10 @@ cdef class Matrix_generic_dense(matrix_dense.Matrix_dense): EXAMPLES:: - sage: R. = FreeAlgebra(QQ,2) - sage: a = matrix(R, 2, 2, [1,2,x*y,y*x]) - sage: b = matrix(R, 2, 2, [1,2,y*x,y*x]) - sage: a._add_(b) + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: a = matrix(R, 2, 2, [1,2,x*y,y*x]) # optional - sage.combinat + sage: b = matrix(R, 2, 2, [1,2,y*x,y*x]) # optional - sage.combinat + sage: a._add_(b) # optional - sage.combinat [ 2 4] [x*y + y*x 2*y*x] """ @@ -238,10 +238,10 @@ cdef class Matrix_generic_dense(matrix_dense.Matrix_dense): EXAMPLES:: - sage: R. = FreeAlgebra(QQ,2) - sage: a = matrix(R, 2, 2, [1,2,x*y,y*x]) - sage: b = matrix(R, 2, 2, [1,2,y*x,y*x]) - sage: a._sub_(b) + sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: a = matrix(R, 2, 2, [1,2,x*y,y*x]) # optional - sage.combinat + sage: b = matrix(R, 2, 2, [1,2,y*x,y*x]) # optional - sage.combinat + sage: a._sub_(b) # optional - sage.combinat [ 0 0] [x*y - y*x 0] """ diff --git a/src/sage/matrix/matrix_generic_sparse.pyx b/src/sage/matrix/matrix_generic_sparse.pyx index a342d5b7353..c84d90fe179 100644 --- a/src/sage/matrix/matrix_generic_sparse.pyx +++ b/src/sage/matrix/matrix_generic_sparse.pyx @@ -4,8 +4,9 @@ Sparse Matrices over a general ring EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: M = MatrixSpace(QQ['x'],2,3,sparse=True); M - Full MatrixSpace of 2 by 3 sparse matrices over Univariate Polynomial Ring in x over Rational Field + sage: M = MatrixSpace(QQ['x'], 2, 3, sparse=True); M + Full MatrixSpace of 2 by 3 sparse matrices over + Univariate Polynomial Ring in x over Rational Field sage: a = M(range(6)); a [0 1 2] [3 4 5] @@ -15,7 +16,7 @@ EXAMPLES:: sage: a * b.transpose() [ 2*x^2 + x 2*x^5 + x^4] [ 5*x^2 + 4*x + 3 5*x^5 + 4*x^4 + 3*x^3] - sage: pari(a)*pari(b.transpose()) + sage: pari(a)*pari(b.transpose()) # optional - sage.libs.pari [2*x^2 + x, 2*x^5 + x^4; 5*x^2 + 4*x + 3, 5*x^5 + 4*x^4 + 3*x^3] sage: c = copy(b); c [ 1 x x^2] @@ -46,7 +47,8 @@ EXAMPLES:: [ 5 x x^2] [x^3 x^4 x^5] sage: parent(d) - Full MatrixSpace of 2 by 3 dense matrices over Univariate Polynomial Ring in x over Rational Field + Full MatrixSpace of 2 by 3 dense matrices + over Univariate Polynomial Ring in x over Rational Field sage: c.sparse_matrix() is c True sage: c.is_sparse() diff --git a/src/sage/matrix/matrix_polynomial_dense.pyx b/src/sage/matrix/matrix_polynomial_dense.pyx index c3fd4d5bf61..5b6469b5b01 100644 --- a/src/sage/matrix/matrix_polynomial_dense.pyx +++ b/src/sage/matrix/matrix_polynomial_dense.pyx @@ -114,11 +114,11 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix( pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) - sage: M._check_shift_dimension(shifts=[1,3,2]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M._check_shift_dimension(shifts=[1,3,2]) # optional - sage.rings.finite_rings - sage: M._check_shift_dimension(shifts=[1,3,2], row_wise=False) + sage: M._check_shift_dimension(shifts=[1,3,2], row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: shifts length should be the row dimension @@ -140,21 +140,21 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix( pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) - sage: M.degree() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.degree() # optional - sage.rings.finite_rings 3 The zero matrix has degree ``-1``:: - sage: M = Matrix( pR, 2, 3 ) - sage: M.degree() + sage: M = Matrix(pR, 2, 3) # optional - sage.rings.finite_rings + sage: M.degree() # optional - sage.rings.finite_rings -1 For an empty matrix, the degree is not defined:: - sage: M = Matrix( pR, 3, 0 ) - sage: M.degree() + sage: M = Matrix(pR, 3, 0) # optional - sage.rings.finite_rings + sage: M.degree() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have a degree @@ -194,20 +194,20 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix( pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) - sage: M.degree_matrix() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.degree_matrix() # optional - sage.rings.finite_rings [ 1 -1 0] [ 3 -1 -1] - sage: M.degree_matrix(shifts=[0,1,2]) + sage: M.degree_matrix(shifts=[0,1,2]) # optional - sage.rings.finite_rings [ 1 -1 2] [ 3 -1 -1] The zero entries in the polynomial matrix can be identified in the (shifted) degree matrix as the entries equal to ``min(shifts)-1``:: - sage: M.degree_matrix(shifts=[-2,1,2]) + sage: M.degree_matrix(shifts=[-2,1,2]) # optional - sage.rings.finite_rings [-1 -3 2] [ 1 -3 -3] @@ -215,7 +215,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): rows of the matrix (which, in terms of modules, means that we are working column-wise, see the class documentation):: - sage: M.degree_matrix(shifts=[-1,2], row_wise=False) + sage: M.degree_matrix(shifts=[-1,2], row_wise=False) # optional - sage.rings.finite_rings [ 0 -2 -1] [ 5 -2 -2] """ @@ -242,14 +242,14 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.constant_matrix() + sage: M.constant_matrix() # optional - sage.rings.finite_rings [1 5 4 0] [1 1 2 0] [4 1 5 6] @@ -267,18 +267,18 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.is_constant() + sage: M.is_constant() # optional - sage.rings.finite_rings False - sage: M = Matrix(pR,[[1,5,2],[3,1,5]]); M.is_constant() + sage: M = Matrix(pR, [[1,5,2], [3,1,5]]); M.is_constant() # optional - sage.rings.finite_rings True - sage: M = Matrix.zero(pR,3,5); M.is_constant() + sage: M = Matrix.zero(pR, 3, 5); M.is_constant() # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -314,48 +314,48 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.coefficient_matrix(2) + sage: M.coefficient_matrix(2) # optional - sage.rings.finite_rings [5 0 0 0] [6 0 0 0] [4 0 2 1] - sage: M.coefficient_matrix(0) == M.constant_matrix() + sage: M.coefficient_matrix(0) == M.constant_matrix() # optional - sage.rings.finite_rings True Row-wise and column-wise coefficient extraction are available:: - sage: M.coefficient_matrix([3,2,1]) + sage: M.coefficient_matrix([3,2,1]) # optional - sage.rings.finite_rings [1 0 0 0] [6 0 0 0] [6 5 5 5] - sage: M.coefficient_matrix([2,0,1,3], row_wise=False) + sage: M.coefficient_matrix([2,0,1,3], row_wise=False) # optional - sage.rings.finite_rings [5 5 6 0] [6 1 0 0] [4 1 5 0] Negative degrees give zero coefficients:: - sage: M.coefficient_matrix([-1,0,1,3], row_wise=False) + sage: M.coefficient_matrix([-1,0,1,3], row_wise=False) # optional - sage.rings.finite_rings [0 5 6 0] [0 1 0 0] [0 1 5 0] Length of list of degrees is checked:: - sage: M.coefficient_matrix([2,1,1,2]) + sage: M.coefficient_matrix([2,1,1,2]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input degree list should be the row dimension of the input matrix - sage: M.coefficient_matrix([3,2,1], row_wise=False) + sage: M.coefficient_matrix([3,2,1], row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input degree list should be the column @@ -410,41 +410,41 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.truncate(2) + sage: M.truncate(2) # optional - sage.rings.finite_rings [5*x + 1 5 6*x + 4 0] [3*x + 1 1 2 0] [6*x + 4 5*x + 1 5*x + 5 5*x + 6] - sage: M.truncate(1) == M.constant_matrix() + sage: M.truncate(1) == M.constant_matrix() # optional - sage.rings.finite_rings True Row-wise and column-wise truncation are available:: - sage: M.truncate([3,2,1]) + sage: M.truncate([3,2,1]) # optional - sage.rings.finite_rings [5*x^2 + 5*x + 1 5 6*x + 4 0] [ 3*x + 1 1 2 0] [ 4 1 5 6] - sage: M.truncate([2,1,1,2], row_wise=False) + sage: M.truncate([2,1,1,2], row_wise=False) # optional - sage.rings.finite_rings [5*x + 1 5 4 0] [3*x + 1 1 2 0] [6*x + 4 1 5 5*x + 6] Length of list of truncation orders is checked:: - sage: M.truncate([2,1,1,2]) + sage: M.truncate([2,1,1,2]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input precision list should be the row dimension of the input matrix - sage: M.truncate([3,2,1], row_wise=False) + sage: M.truncate([3,2,1], row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input precision list should be the column @@ -501,42 +501,42 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.shift(-2) + sage: M.shift(-2) # optional - sage.rings.finite_rings [ x + 5 0 0 0] [ 6 0 0 0] [2*x + 4 0 2 1] Row-wise and column-wise shifting are available:: - sage: M.shift([-1,2,-2]) + sage: M.shift([-1,2,-2]) # optional - sage.rings.finite_rings [ x^2 + 5*x + 5 0 6 0] [6*x^4 + 3*x^3 + x^2 x^2 2*x^2 0] [ 2*x + 4 0 2 1] - sage: M.shift([-1,1,0,0], row_wise=False) + sage: M.shift([-1,1,0,0], row_wise=False) # optional - sage.rings.finite_rings [ x^2 + 5*x + 5 5*x 6*x + 4 0] [ 6*x + 3 x 2 0] [2*x^2 + 4*x + 6 5*x^2 + x 2*x^2 + 5*x + 5 x^2 + 5*x + 6] - sage: M.shift([-d for d in M.row_degrees()]) == M.leading_matrix() + sage: M.shift([-d for d in M.row_degrees()]) == M.leading_matrix() # optional - sage.rings.finite_rings True Length of input shift degree list is checked:: - sage: M.shift([1,3,1,4]) + sage: M.shift([1,3,1,4]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input shift list should be the row dimension of the input matrix - sage: M.shift([5,2,-1], row_wise=False) + sage: M.shift([5,2,-1], row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input shift list should be the column @@ -609,14 +609,14 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.reverse() + sage: M.reverse() # optional - sage.rings.finite_rings [ x^3 + 5*x^2 + 5*x + 1 5*x^3 4*x^3 + 6*x^2 0] [ x^3 + 3*x^2 + 6*x x^3 @@ -624,17 +624,17 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [4*x^3 + 6*x^2 + 4*x + 2 x^3 + 5*x^2 5*x^3 + 5*x^2 + 2*x 6*x^3 + 5*x^2 + x] - sage: M.reverse(1) + sage: M.reverse(1) # optional - sage.rings.finite_rings [ x + 5 5*x 4*x + 6 0] [ x + 3 x 2*x 0] [4*x + 6 x + 5 5*x + 5 6*x + 5] - sage: M.reverse(0) == M.constant_matrix() + sage: M.reverse(0) == M.constant_matrix() # optional - sage.rings.finite_rings True Entry-wise reversing with respect to each entry's degree:: - sage: M.reverse(entry_wise=True) + sage: M.reverse(entry_wise=True) # optional - sage.rings.finite_rings [ x^3 + 5*x^2 + 5*x + 1 5 4*x + 6 0] [ x^2 + 3*x + 6 1 @@ -644,7 +644,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): Row-wise and column-wise degree reversing are available:: - sage: M.reverse([2,3,1]) + sage: M.reverse([2,3,1]) # optional - sage.rings.finite_rings [ x^2 + 5*x + 5 5*x^2 4*x^2 + 6*x 0] [x^3 + 3*x^2 + 6*x x^3 2*x^3 @@ -652,7 +652,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 4*x + 6 x + 5 5*x + 5 6*x + 5] - sage: M.reverse(M.column_degrees(),row_wise=False) + sage: M.reverse(M.column_degrees(), row_wise=False) # optional - sage.rings.finite_rings [ x^3 + 5*x^2 + 5*x + 1 5*x 4*x^2 + 6*x 0] [ x^3 + 3*x^2 + 6*x x @@ -662,19 +662,19 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): Wrong length or negativity of input degree raise errors: - sage: M.reverse([1,3,1,4]) + sage: M.reverse([1,3,1,4]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input degree list should be the row dimension of the input matrix - sage: M.reverse([5,2,1], row_wise=False) + sage: M.reverse([5,2,1], row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: length of input degree list should be the column dimension of the input matrix - sage: M.reverse([2,3,-1]) + sage: M.reverse([2,3,-1]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... OverflowError: can't convert negative value to unsigned long @@ -743,30 +743,30 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 3, 3, \ - [[4*x+5, 5*x^2 + x + 1, 4*x^2 + 4], \ - [6*x^2 + 6*x + 6, 4*x^2 + 5*x, 4*x^2 + x + 3], \ - [3*x^2 + 2, 4*x + 1, x^2 + 3*x]]) - sage: B = A.inverse_series_trunc(4); B + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x+5, 5*x^2 + x + 1, 4*x^2 + 4], + ....: [6*x^2 + 6*x + 6, 4*x^2 + 5*x, 4*x^2 + x + 3], + ....: [3*x^2 + 2, 4*x + 1, x^2 + 3*x]]) + sage: B = A.inverse_series_trunc(4); B # optional - sage.rings.finite_rings [ x^3 + 5*x^2 + x + 4 x^3 + 5*x^2 + 6*x + 4 6*x^2 + 5*x + 3] [ 4*x^2 + 5*x + 6 6*x^3 + x^2 + x + 6 3*x^3 + 2*x^2 + 2] [5*x^3 + 5*x^2 + 6*x + 6 4*x^3 + 2*x^2 + 6*x + 4 6*x^3 + x^2 + 6*x + 1] - sage: (B*A).truncate(4) == 1 + sage: (B*A).truncate(4) == 1 # optional - sage.rings.finite_rings True - sage: A.inverse_series_trunc(0) + sage: A.inverse_series_trunc(0) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the precision must be positive - sage: A[:2,:].inverse_series_trunc(4) + sage: A[:2,:].inverse_series_trunc(4) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: the input matrix must be square - sage: A[0,:] = A[0,:] - A[0,:](0) + A[1,:](0) + A[2,:](0) - sage: A.inverse_series_trunc(4) + sage: A[0,:] = A[0,:] - A[0,:](0) + A[1,:](0) + A[2,:](0) # optional - sage.rings.finite_rings + sage: A.inverse_series_trunc(4) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: the constant matrix term self(0) must be invertible @@ -840,61 +840,61 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 3, 3, \ - [[4*x+5, 5*x^2 + x + 1, 4*x^2 + 4], \ - [6*x^2 + 6*x + 6, 4*x^2 + 5*x, 4*x^2 + x + 3], \ - [3*x^2 + 2, 4*x + 1, x^2 + 3*x]]) - sage: A.is_square() and A.constant_matrix().is_invertible() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x+5, 5*x^2 + x + 1, 4*x^2 + 4], + ....: [6*x^2 + 6*x + 6, 4*x^2 + 5*x, 4*x^2 + x + 3], + ....: [3*x^2 + 2, 4*x + 1, x^2 + 3*x]]) + sage: A.is_square() and A.constant_matrix().is_invertible() # optional - sage.rings.finite_rings True - sage: B = vector([2*x^2 + 6*x + 6, 0, x + 6]) - sage: X = A.solve_left_series_trunc(B,4); X + sage: B = vector([2*x^2 + 6*x + 6, 0, x + 6]) # optional - sage.rings.finite_rings + sage: X = A.solve_left_series_trunc(B, 4); X # optional - sage.rings.finite_rings (3*x^3 + 3*x^2 + 2*x + 4, 4*x^3 + x^2 + 2*x + 6, 6*x^3 + x + 3) - sage: B == X*A % x**4 + sage: B == X*A % x**4 # optional - sage.rings.finite_rings True - sage: B = Matrix(pR, 2, 3, \ - [[3*x, x^2 + x + 2, x^2 + 2*x + 3], \ - [ 0, 6*x^2 + 1, 1]]) - sage: A.solve_left_series_trunc(B,3) + sage: B = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[3*x, x^2 + x + 2, x^2 + 2*x + 3], + ....: [ 0, 6*x^2 + 1, 1]]) + sage: A.solve_left_series_trunc(B, 3) # optional - sage.rings.finite_rings [6*x^2 + 2*x + 2 4*x + 3 2*x^2 + 3*x] [3*x^2 + 4*x + 5 4*x^2 + 3 x^2 + 6*x + 3] - sage: X = A.solve_left_series_trunc(B,37); B == X*A % x**37 + sage: X = A.solve_left_series_trunc(B, 37); B == X*A % x**37 # optional - sage.rings.finite_rings True Dimensions of input are checked:: - sage: A.solve_left_series_trunc(B[:,:2],3) + sage: A.solve_left_series_trunc(B[:,:2], 3) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: number of columns of self must equal number of columns of right-hand side Raises an exception when no solution:: - sage: A[2:,:].solve_left_series_trunc(B,4) + sage: A[2:,:].solve_left_series_trunc(B, 4) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: matrix equation has no solutions - sage: Ax = x*A; C = vector(pR, [1,1,1]) - sage: Ax.solve_left_series_trunc(C,5) + sage: Ax = x*A; C = vector(pR, [1,1,1]) # optional - sage.rings.finite_rings + sage: Ax.solve_left_series_trunc(C, 5) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: matrix equation has no solutions Supports rectangular and rank-deficient cases:: - sage: A[:,:2].solve_left_series_trunc(B[:,:2],4) + sage: A[:,:2].solve_left_series_trunc(B[:,:2], 4) # optional - sage.rings.finite_rings [5*x^2 + 2*x + 5 5*x + 5 2*x + 4] [5*x^3 + 2*x + 1 2*x^2 + 2*x + 5 4*x^2] - sage: V = Matrix([[3*x^2 + 4*x + 1, 4*x]]) - sage: A[:2,:].solve_left_series_trunc(V*A[:2,:], 4) == V + sage: V = Matrix([[3*x^2 + 4*x + 1, 4*x]]) # optional - sage.rings.finite_rings + sage: A[:2,:].solve_left_series_trunc(V*A[:2,:], 4) == V # optional - sage.rings.finite_rings True - sage: A[1,:] = (x+1) * A[0,:]; A[2,:] = (x+5) * A[0,:] - sage: B = (3*x^3+x^2+2)*A[0,:] - sage: A.solve_left_series_trunc(B, 6) + sage: A[1,:] = (x+1) * A[0,:]; A[2,:] = (x+5) * A[0,:] # optional - sage.rings.finite_rings + sage: B = (3*x^3+x^2+2)*A[0,:] # optional - sage.rings.finite_rings + sage: A.solve_left_series_trunc(B, 6) # optional - sage.rings.finite_rings [4*x^2 + 6*x + 2 3*x^2 + x 0] .. SEEALSO:: @@ -987,64 +987,64 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 3, 3, \ - [[4*x+5, 5*x^2 + x + 1, 4*x^2 + 4], \ - [6*x^2 + 6*x + 6, 4*x^2 + 5*x, 4*x^2 + x + 3], \ - [3*x^2 + 2, 4*x + 1, x^2 + 3*x]]) - sage: A.is_square() and A.constant_matrix().is_invertible() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x+5, 5*x^2 + x + 1, 4*x^2 + 4], + ....: [6*x^2 + 6*x + 6, 4*x^2 + 5*x, 4*x^2 + x + 3], + ....: [3*x^2 + 2, 4*x + 1, x^2 + 3*x]]) + sage: A.is_square() and A.constant_matrix().is_invertible() # optional - sage.rings.finite_rings True - sage: B = vector([2*x^2 + 6*x + 6, 0, x + 6]) - sage: X = A.solve_right_series_trunc(B,4); X + sage: B = vector([2*x^2 + 6*x + 6, 0, x + 6]) # optional - sage.rings.finite_rings + sage: X = A.solve_right_series_trunc(B, 4); X # optional - sage.rings.finite_rings (2*x^3 + x^2, 5*x^3 + x^2 + 5*x + 6, 4*x^3 + 6*x^2 + 4*x) - sage: B == A*X % x**4 + sage: B == A*X % x**4 # optional - sage.rings.finite_rings True - sage: B = Matrix(pR, 3, 2, \ - [[5*x^2 + 6*x + 3, 4*x^2 + 6*x + 4], \ - [ x^2 + 4*x + 2, 5*x + 2], \ - [ 5*x + 3, 0]]) - sage: A.solve_right_series_trunc(B,3) + sage: B = Matrix(pR, 3, 2, # optional - sage.rings.finite_rings + ....: [[5*x^2 + 6*x + 3, 4*x^2 + 6*x + 4], + ....: [ x^2 + 4*x + 2, 5*x + 2], + ....: [ 5*x + 3, 0]]) + sage: A.solve_right_series_trunc(B, 3) # optional - sage.rings.finite_rings [ 3*x^2 + x + 1 5*x^2 + 4*x + 3] [6*x^2 + 3*x + 1 4*x + 1] [ 6*x^2 + 1 2*x^2 + x + 4] - sage: X = A.solve_right_series_trunc(B,37); B == A*X % x**37 + sage: X = A.solve_right_series_trunc(B, 37); B == A*X % x**37 # optional - sage.rings.finite_rings True Dimensions of input are checked:: - sage: A.solve_right_series_trunc(B[:2,:],3) + sage: A.solve_right_series_trunc(B[:2,:], 3) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: number of rows of self must equal number of rows of right-hand side Raises an exception when no solution:: - sage: A[:,2:].solve_right_series_trunc(B,4) + sage: A[:,2:].solve_right_series_trunc(B, 4) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: matrix equation has no solutions - sage: Ax = x*A; C = vector(pR, [1,1,1]) - sage: Ax.solve_right_series_trunc(C,5) + sage: Ax = x*A; C = vector(pR, [1,1,1]) # optional - sage.rings.finite_rings + sage: Ax.solve_right_series_trunc(C, 5) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: matrix equation has no solutions Supports rectangular and rank-deficient cases:: - sage: A[:2,:].solve_right_series_trunc(B[:2,:],4) + sage: A[:2,:].solve_right_series_trunc(B[:2,:],4) # optional - sage.rings.finite_rings [ 5*x^2 + 4*x x + 4] [ x^2 + 3*x + 5 3*x^2 + 4*x + 4] [ 5*x + 3 3*x + 2] - sage: V = Matrix([[2*x^2 + 5*x + 1], [3*x^2+4]]) - sage: A[:,:2].solve_right_series_trunc(A[:,:2]*V, 4) == V + sage: V = Matrix([[2*x^2 + 5*x + 1], [3*x^2+4]]) # optional - sage.rings.finite_rings + sage: A[:,:2].solve_right_series_trunc(A[:,:2]*V, 4) == V # optional - sage.rings.finite_rings True - sage: A[:,1] = (x+1) * A[:,0]; A[:,2] = (x+5) * A[:,0] - sage: B = (3*x^3+x^2+2)*A[:,0] - sage: A.solve_right_series_trunc(B, 6) + sage: A[:,1] = (x+1) * A[:,0]; A[:,2] = (x+5) * A[:,0] # optional - sage.rings.finite_rings + sage: B = (3*x^3+x^2+2)*A[:,0] # optional - sage.rings.finite_rings + sage: A.solve_right_series_trunc(B, 6) # optional - sage.rings.finite_rings [4*x^2 + 6*x + 2] [ 3*x^2 + x] [ 0] @@ -1096,35 +1096,35 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [3*x+1, 0, 1], [x^3+3, 0, 0] ]) - sage: M.row_degrees() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.row_degrees() # optional - sage.rings.finite_rings [1, 3] - sage: M.row_degrees(shifts=[0,1,2]) + sage: M.row_degrees(shifts=[0,1,2]) # optional - sage.rings.finite_rings [2, 3] A zero row in a polynomial matrix can be identified in the (shifted) row degrees as the entries equal to ``min(shifts)-1``:: - sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0], [0, 0, 0]]) - sage: M.row_degrees() + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0], [0, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.row_degrees() # optional - sage.rings.finite_rings [1, 3, -1] - sage: M.row_degrees(shifts=[-2,1,2]) + sage: M.row_degrees(shifts=[-2,1,2]) # optional - sage.rings.finite_rings [2, 1, -3] The row degrees of an empty matrix (`0\times n` or `m\times 0`) is not defined:: - sage: M = Matrix( pR, 0, 3 ) - sage: M.row_degrees() + sage: M = Matrix(pR, 0, 3) # optional - sage.rings.finite_rings + sage: M.row_degrees() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have row degrees - sage: M = Matrix( pR, 3, 0 ) - sage: M.row_degrees() + sage: M = Matrix(pR, 3, 0) # optional - sage.rings.finite_rings + sage: M.row_degrees() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have row degrees @@ -1163,31 +1163,31 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [3*x+1, 0, 1], [x^3+3, 0, 0] ]) - sage: M.column_degrees() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.column_degrees() # optional - sage.rings.finite_rings [3, -1, 0] - sage: M.column_degrees(shifts=[0,2]) + sage: M.column_degrees(shifts=[0,2]) # optional - sage.rings.finite_rings [5, -1, 0] A zero column in a polynomial matrix can be identified in the (shifted) column degrees as the entries equal to ``min(shifts)-1``:: - sage: M.column_degrees(shifts=[-2,1]) + sage: M.column_degrees(shifts=[-2,1]) # optional - sage.rings.finite_rings [4, -3, -2] The column degrees of an empty matrix (`0\times n` or `m\times 0`) is not defined:: - sage: M = Matrix( pR, 0, 3 ) - sage: M.column_degrees() + sage: M = Matrix(pR, 0, 3) # optional - sage.rings.finite_rings + sage: M.column_degrees() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have column degrees - sage: M = Matrix( pR, 3, 0 ) - sage: M.column_degrees() + sage: M = Matrix(pR, 3, 0) # optional - sage.rings.finite_rings + sage: M.column_degrees() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have column degrees @@ -1244,28 +1244,28 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [3*x+1, 0, 1], [x^3+3, 0, 0] ]) - sage: M.leading_matrix() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.leading_matrix() # optional - sage.rings.finite_rings [3 0 0] [1 0 0] - sage: M.leading_matrix().base_ring() + sage: M.leading_matrix().base_ring() # optional - sage.rings.finite_rings Finite Field of size 7 - sage: M.leading_matrix(shifts=[0,1,2]) + sage: M.leading_matrix(shifts=[0,1,2]) # optional - sage.rings.finite_rings [0 0 1] [1 0 0] - sage: M.leading_matrix(row_wise=False) + sage: M.leading_matrix(row_wise=False) # optional - sage.rings.finite_rings [0 0 1] [1 0 0] - sage: M.leading_matrix(shifts=[-2,1], row_wise=False) + sage: M.leading_matrix(shifts=[-2,1], row_wise=False) # optional - sage.rings.finite_rings [0 0 1] [1 0 0] - sage: M.leading_matrix(shifts=[2,0], row_wise=False) + sage: M.leading_matrix(shifts=[2,0], row_wise=False) # optional - sage.rings.finite_rings [3 0 1] [1 0 0] """ @@ -1319,19 +1319,19 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, 0, 0) - sage: M._is_empty_popov() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, 0, 0) # optional - sage.rings.finite_rings + sage: M._is_empty_popov() # optional - sage.rings.finite_rings True - sage: M._is_empty_popov(include_zero_vectors=False) + sage: M._is_empty_popov(include_zero_vectors=False) # optional - sage.rings.finite_rings True - sage: M = Matrix(pR, 0, 3) - sage: M._is_empty_popov(include_zero_vectors=False) + sage: M = Matrix(pR, 0, 3) # optional - sage.rings.finite_rings + sage: M._is_empty_popov(include_zero_vectors=False) # optional - sage.rings.finite_rings True - sage: M._is_empty_popov(row_wise=False) + sage: M._is_empty_popov(row_wise=False) # optional - sage.rings.finite_rings True - sage: M._is_empty_popov(row_wise=False,include_zero_vectors=False) + sage: M._is_empty_popov(row_wise=False,include_zero_vectors=False) # optional - sage.rings.finite_rings False .. SEEALSO:: @@ -1390,23 +1390,23 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [3*x+1, 0, 1], [x^3+3, 0, 0] ]) - sage: M.is_reduced() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.is_reduced() # optional - sage.rings.finite_rings False - sage: M.is_reduced(shifts=[0,1,2]) + sage: M.is_reduced(shifts=[0,1,2]) # optional - sage.rings.finite_rings True - sage: M.is_reduced(shifts=[2,0], row_wise=False) + sage: M.is_reduced(shifts=[2,0], row_wise=False) # optional - sage.rings.finite_rings True - sage: M.is_reduced(shifts=[2,0], row_wise=False, - ....: include_zero_vectors=False) + sage: M.is_reduced(shifts=[2,0], row_wise=False, # optional - sage.rings.finite_rings + ....: include_zero_vectors=False) False - sage: M = Matrix(pR, [ [3*x+1, 0, 1], [x^3+3, 0, 0], [0, 1, 0] ]) - sage: M.is_reduced(shifts=[2,0,0], row_wise=False) + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0], [0, 1, 0]]) # optional - sage.rings.finite_rings + sage: M.is_reduced(shifts=[2,0,0], row_wise=False) # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -1470,50 +1470,51 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [3*x+1, 0, 1], [x^3+3, 0, 0] ]) - sage: M.leading_positions() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[3*x+1, 0, 1], [x^3+3, 0, 0]]) # optional - sage.rings.finite_rings + sage: M.leading_positions() # optional - sage.rings.finite_rings [0, 0] - sage: M.leading_positions(return_degree=True) + sage: M.leading_positions(return_degree=True) # optional - sage.rings.finite_rings ([0, 0], [1, 3]) - sage: M.leading_positions(shifts=[0,5,2], return_degree=True) + sage: M.leading_positions(shifts=[0,5,2], return_degree=True) # optional - sage.rings.finite_rings ([2, 0], [0, 3]) - sage: M.leading_positions(row_wise=False, return_degree=True) + sage: M.leading_positions(row_wise=False, return_degree=True) # optional - sage.rings.finite_rings ([1, -1, 0], [3, -1, 0]) - sage: M.leading_positions(shifts=[1,2], row_wise=False, - ....: return_degree=True) + sage: M.leading_positions(shifts=[1,2], row_wise=False, # optional - sage.rings.finite_rings + ....: return_degree=True) ([1, -1, 0], [3, -1, 0]) In case several entries in the row (resp. column) reach the shifted row (resp. column) degree, the leading position is chosen as the rightmost (resp. bottommost) such entry:: - sage: M.leading_positions(shifts=[0,5,1],return_degree=True) + sage: M.leading_positions(shifts=[0,5,1], return_degree=True) # optional - sage.rings.finite_rings ([2, 0], [0, 3]) - sage: M.leading_positions(shifts=[2,0], row_wise=False,return_degree=True) + sage: M.leading_positions(shifts=[2,0], row_wise=False, # optional - sage.rings.finite_rings + ....: return_degree=True) ([1, -1, 0], [3, -1, 0]) The leading positions and pivot degrees of an empty matrix (`0\times n` or `m\times 0`) is not defined:: - sage: M = Matrix( pR, 0, 3 ) - sage: M.leading_positions() + sage: M = Matrix(pR, 0, 3) # optional - sage.rings.finite_rings + sage: M.leading_positions() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have leading positions - sage: M.leading_positions(row_wise=False) + sage: M.leading_positions(row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have leading positions - sage: M = Matrix( pR, 3, 0 ) - sage: M.leading_positions(row_wise=False) + sage: M = Matrix(pR, 3, 0) # optional - sage.rings.finite_rings + sage: M.leading_positions(row_wise=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: empty matrix does not have leading positions @@ -1601,58 +1602,60 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix([ [x^3+3*x^2+6*x+6, 3*x^2+3*x+6, 4*x^2+x+3], + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix([ [x^3+3*x^2+6*x+6, 3*x^2+3*x+6, 4*x^2+x+3], # optional - sage.rings.finite_rings ....: [5, 1, 0 ], ....: [2*x^2+2, 2*x+5, x^2+4*x+6] ]) - sage: M.is_weak_popov() + sage: M.is_weak_popov() # optional - sage.rings.finite_rings True One can check whether the leading positions, in addition to being pairwise distinct, are actually in increasing order:: - sage: M.is_weak_popov(ordered=True) + sage: M.is_weak_popov(ordered=True) # optional - sage.rings.finite_rings True - sage: N = M.with_swapped_rows(1,2) - sage: N.is_weak_popov() + sage: N = M.with_swapped_rows(1, 2) # optional - sage.rings.finite_rings + sage: N.is_weak_popov() # optional - sage.rings.finite_rings True - sage: N.is_weak_popov(ordered=True) + sage: N.is_weak_popov(ordered=True) # optional - sage.rings.finite_rings False Shifts and orientation (row-wise or column-wise) are supported:: - sage: M.is_weak_popov(shifts=[2,3,1]) + sage: M.is_weak_popov(shifts=[2,3,1]) # optional - sage.rings.finite_rings False - sage: M.is_weak_popov(shifts=[0,2,0],row_wise=False,ordered=True) + sage: M.is_weak_popov(shifts=[0,2,0], row_wise=False, # optional - sage.rings.finite_rings + ....: ordered=True) True Rectangular matrices are supported:: - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ x^3+5*x^2+5*x+1, 5, 6*x+4, 0], ....: [ 6*x^2+3*x+1, 1, 2, 0], ....: [2*x^3+4*x^2+6*x+4, 5*x + 1, 2*x^2+5*x+5, x^2+5*x+6] ....: ]) - sage: M.is_weak_popov(shifts=[0,2,1,3]) + sage: M.is_weak_popov(shifts=[0,2,1,3]) # optional - sage.rings.finite_rings True - sage: M.is_weak_popov(shifts=[0,2,1,3],ordered=True) + sage: M.is_weak_popov(shifts=[0,2,1,3], ordered=True) # optional - sage.rings.finite_rings True Zero rows (resp. columns) can be forbidden:: - sage: M = Matrix([ + sage: M = Matrix([ # optional - sage.rings.finite_rings ....: [ 6*x+4, 0, 5*x+1, 0], ....: [ 2, 5*x + 1, 6*x^2+3*x+1, 0], ....: [2*x^2+5*x+5, 1, 2*x^3+4*x^2+6*x+4, 0] ....: ]) - sage: M.is_weak_popov(shifts=[2,1,0], row_wise=False, ordered=True) + sage: M.is_weak_popov(shifts=[2,1,0], row_wise=False, # optional - sage.rings.finite_rings + ....: ordered=True) True - sage: M.is_weak_popov(shifts=[2,1,0], row_wise=False, - ....: include_zero_vectors=False) + sage: M.is_weak_popov(shifts=[2,1,0], row_wise=False, # optional - sage.rings.finite_rings + ....: include_zero_vectors=False) False .. SEEALSO:: @@ -1730,60 +1733,60 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [x^4+6*x^3+4*x+4, 3*x+6, 3 ], - ....: [x^2+6*x+6, x^2+5*x+5, 2 ], - ....: [3*x, 6*x+5, x+5] ]) - sage: M.is_popov() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[x^4+6*x^3+4*x+4, 3*x+6, 3 ], # optional - sage.rings.finite_rings + ....: [x^2+6*x+6, x^2+5*x+5, 2 ], + ....: [3*x, 6*x+5, x+5]]) + sage: M.is_popov() # optional - sage.rings.finite_rings True - sage: M.is_popov(shifts=[0,1,2]) + sage: M.is_popov(shifts=[0,1,2]) # optional - sage.rings.finite_rings True - sage: M[:,:2].is_popov() + sage: M[:,:2].is_popov() # optional - sage.rings.finite_rings False - sage: M[:2,:].is_popov(shifts=[0,1,2]) + sage: M[:2,:].is_popov(shifts=[0,1,2]) # optional - sage.rings.finite_rings True - sage: M = Matrix(pR, [ [x^4+3*x^3+x^2+2*x+6, x^3+5*x^2+5*x+1], - ....: [6*x+1, x^2+4*x+1 ], - ....: [6, 6 ] ]) - sage: M.is_popov(row_wise=False) + sage: M = Matrix(pR, [[x^4+3*x^3+x^2+2*x+6, x^3+5*x^2+5*x+1], # optional - sage.rings.finite_rings + ....: [6*x+1, x^2+4*x+1 ], + ....: [6, 6 ]]) + sage: M.is_popov(row_wise=False) # optional - sage.rings.finite_rings False - sage: M.is_popov(shifts=[0,2,3], row_wise=False) + sage: M.is_popov(shifts=[0,2,3], row_wise=False) # optional - sage.rings.finite_rings True One can forbid zero rows (or columns if not working row-wise):: - sage: N = Matrix(pR, [ [x^4+3*x^3+x^2+2*x+6, 6*x+1 ], - ....: [5*x^2+5*x+1, x^2+4*x+1 ], - ....: [0, 0 ] ]) + sage: N = Matrix(pR, [[x^4+3*x^3+x^2+2*x+6, 6*x+1 ], # optional - sage.rings.finite_rings + ....: [5*x^2+5*x+1, x^2+4*x+1 ], + ....: [0, 0 ]]) - sage: N.is_popov() + sage: N.is_popov() # optional - sage.rings.finite_rings True - sage: N.is_popov(include_zero_vectors=False) + sage: N.is_popov(include_zero_vectors=False) # optional - sage.rings.finite_rings False One can verify Popov form up to row permutation (or column permutation if not working row-wise):: - sage: M.swap_columns(0,1) - sage: M.is_popov(shifts=[0,2,3], row_wise=False) + sage: M.swap_columns(0, 1) # optional - sage.rings.finite_rings + sage: M.is_popov(shifts=[0,2,3], row_wise=False) # optional - sage.rings.finite_rings False - sage: M.is_popov(shifts=[0,2,3], row_wise=False, - ....: up_to_permutation=True) + sage: M.is_popov(shifts=[0,2,3], row_wise=False, # optional - sage.rings.finite_rings + ....: up_to_permutation=True) True - sage: N.swap_rows(0,2) + sage: N.swap_rows(0, 2) # optional - sage.rings.finite_rings - sage: N.is_popov() + sage: N.is_popov() # optional - sage.rings.finite_rings False - sage: N.is_popov(up_to_permutation=True) + sage: N.is_popov(up_to_permutation=True) # optional - sage.rings.finite_rings True """ # the matrix should be in weak Popov form (ordered except if @@ -1868,41 +1871,41 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ [x^4+6*x^3+4*x+4, 3*x+6, 3 ], - ....: [0, x^2+5*x+5, 2 ], - ....: [0, 0, x+5] ]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [[x^4+6*x^3+4*x+4, 3*x+6, 3 ], # optional - sage.rings.finite_rings + ....: [0, x^2+5*x+5, 2 ], + ....: [0, 0, x+5]]) - sage: M.is_hermite() + sage: M.is_hermite() # optional - sage.rings.finite_rings True - sage: M.is_hermite(row_wise=False) + sage: M.is_hermite(row_wise=False) # optional - sage.rings.finite_rings True - sage: M.is_hermite(row_wise=False, lower_echelon=True) + sage: M.is_hermite(row_wise=False, lower_echelon=True) # optional - sage.rings.finite_rings False - sage: N = Matrix(pR, [ [x+5, 0, 0 ], - ....: [2, x^4+6*x^3+4*x+4, 0 ], - ....: [3, 3*x^3+6, x^2+5*x+5] ]) - sage: N.is_hermite() + sage: N = Matrix(pR, [[x+5, 0, 0 ], # optional - sage.rings.finite_rings + ....: [2, x^4+6*x^3+4*x+4, 0 ], + ....: [3, 3*x^3+6, x^2+5*x+5]]) + sage: N.is_hermite() # optional - sage.rings.finite_rings False - sage: N.is_hermite(lower_echelon=True) + sage: N.is_hermite(lower_echelon=True) # optional - sage.rings.finite_rings True - sage: N.is_hermite(row_wise=False) + sage: N.is_hermite(row_wise=False) # optional - sage.rings.finite_rings False - sage: N.is_hermite(row_wise=False, lower_echelon=True) + sage: N.is_hermite(row_wise=False, lower_echelon=True) # optional - sage.rings.finite_rings False Rectangular matrices with zero rows are supported. Zero rows (resp. columns) can be forbidden, and otherwise they should be at the bottom (resp. the right-hand side) of the matrix:: - sage: N[:,1:].is_hermite(lower_echelon=True) + sage: N[:,1:].is_hermite(lower_echelon=True) # optional - sage.rings.finite_rings False - sage: N[[1,2,0],1:].is_hermite(lower_echelon=True) + sage: N[[1,2,0],1:].is_hermite(lower_echelon=True) # optional - sage.rings.finite_rings True - sage: N[:2,:].is_hermite(row_wise=False, lower_echelon=True) + sage: N[:2,:].is_hermite(row_wise=False, lower_echelon=True) # optional - sage.rings.finite_rings True - sage: N[:2,:].is_hermite(row_wise=False, + sage: N[:2,:].is_hermite(row_wise=False, # optional - sage.rings.finite_rings ....: lower_echelon=True, ....: include_zero_vectors=False) False @@ -1983,61 +1986,61 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ \ - [ 6*x+4, 5*x^3+5*x, 6*x^2+2*x+2], \ - [4*x^2+5*x+2, x^4+5*x^2+2*x+4, 4*x^3+6*x^2+6*x+5]]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [ # optional - sage.rings.finite_rings + ....: [ 6*x+4, 5*x^3+5*x, 6*x^2+2*x+2], + ....: [4*x^2+5*x+2, x^4+5*x^2+2*x+4, 4*x^3+6*x^2+6*x+5]]) - sage: P,U = M.weak_popov_form(transformation=True) - sage: P + sage: P, U = M.weak_popov_form(transformation=True) # optional - sage.combinat sage.rings.finite_rings + sage: P # optional - sage.combinat sage.rings.finite_rings [ 4 x^2 6*x^2 + x + 2] [ 2 4*x^2 + 2*x + 4 5] - sage: U + sage: U # optional - sage.combinat sage.rings.finite_rings [2*x^2 + 1 4*x] [ 4*x 1] - sage: P.is_weak_popov() and U.is_invertible() and U*M==P + sage: P.is_weak_popov() and U.is_invertible() and U*M == P # optional - sage.combinat sage.rings.finite_rings True Demonstrating the ``ordered`` option:: - sage: P.leading_positions() + sage: P.leading_positions() # optional - sage.combinat sage.rings.finite_rings [2, 1] - sage: PP = M.weak_popov_form(ordered=True); PP + sage: PP = M.weak_popov_form(ordered=True); PP # optional - sage.combinat sage.rings.finite_rings [ 2 4*x^2 + 2*x + 4 5] [ 4 x^2 6*x^2 + x + 2] - sage: PP.leading_positions() + sage: PP.leading_positions() # optional - sage.combinat sage.rings.finite_rings [1, 2] Demonstrating shifts:: - sage: P = M.weak_popov_form(shifts=[0,2,4]); P + sage: P = M.weak_popov_form(shifts=[0,2,4]); P # optional - sage.combinat sage.rings.finite_rings [ 6*x^2 + 6*x + 4 5*x^4 + 4*x^3 + 5*x^2 + 5*x 2*x + 2] [ 2 4*x^2 + 2*x + 4 5] - sage: P==M.weak_popov_form(shifts=[-10,-8,-6]) + sage: P == M.weak_popov_form(shifts=[-10,-8,-6]) # optional - sage.combinat sage.rings.finite_rings True Column-wise form is the row-wise form of the transpose:: - sage: M.weak_popov_form() == M.T.weak_popov_form(row_wise=False).T + sage: M.weak_popov_form() == M.T.weak_popov_form(row_wise=False).T # optional - sage.combinat sage.rings.finite_rings True Zero vectors can be discarded:: - sage: M.weak_popov_form(row_wise=False) + sage: M.weak_popov_form(row_wise=False) # optional - sage.combinat sage.rings.finite_rings [x + 4 6 0] [ 5 1 0] - sage: P,U = M.weak_popov_form(transformation=True, \ - row_wise=False, \ - include_zero_vectors=False) - sage: P + sage: P, U = M.weak_popov_form(transformation=True, # optional - sage.combinat sage.rings.finite_rings + ....: row_wise=False, + ....: include_zero_vectors=False) + sage: P # optional - sage.combinat sage.rings.finite_rings [x + 4 6] [ 5 1] - sage: U + sage: U # optional - sage.combinat sage.rings.finite_rings [ 5*x + 2 5*x^2 + 4*x + 4 3*x^3 + 3*x^2 + 2*x + 4] [ 1 1 2*x + 1] [ 5*x + 5 2 6] - sage: M*U[:,:2] == P and (M*U[:,2]).is_zero() + sage: M*U[:,:2] == P and (M*U[:,2]).is_zero() # optional - sage.combinat sage.rings.finite_rings True .. SEEALSO:: @@ -2112,34 +2115,34 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: F. = GF(2^4,'a') - sage: PF. = F[] - sage: A = matrix(PF,[[1, a*x^17 + 1 ], + sage: F. = GF(2^4, 'a') # optional - sage.rings.finite_rings + sage: PF. = F[] # optional - sage.rings.finite_rings + sage: A = matrix(PF,[[1, a*x^17 + 1 ], # optional - sage.rings.finite_rings ....: [0, a*x^11 + a^2*x^7 + 1 ]]) - sage: M = A.__copy__() - sage: U = M._weak_popov_form(transformation=True) - sage: U * A == M + sage: M = A.__copy__() # optional - sage.rings.finite_rings + sage: U = M._weak_popov_form(transformation=True) # optional - sage.combinat sage.rings.finite_rings + sage: U * A == M # optional - sage.combinat sage.rings.finite_rings True - sage: M.is_weak_popov() + sage: M.is_weak_popov() # optional - sage.combinat sage.rings.finite_rings True - sage: U.is_invertible() + sage: U.is_invertible() # optional - sage.combinat sage.rings.finite_rings True sage: PF. = QQ[] sage: A = matrix(PF,3,[x, x^2, x^3, ....: x^2, x^1, 0, ....: x^3, x^3, x^3]) - sage: A.weak_popov_form() + sage: A.weak_popov_form() # optional - sage.combinat [ x x^2 x^3] [ x^2 x 0] [ x^3 - x x^3 - x^2 0] - sage: M = A.__copy__() - sage: U = M._weak_popov_form(transformation=True, shifts=[16,8,0]) - sage: M + sage: M = A.__copy__() # optional - sage.combinat + sage: U = M._weak_popov_form(transformation=True, shifts=[16,8,0]) # optional - sage.combinat + sage: M # optional - sage.combinat [ x x^2 x^3] [ 0 -x^2 + x -x^4 + x^3] [ 0 0 -x^5 + x^4 + x^3] - sage: U * A == M + sage: U * A == M # optional - sage.combinat True """ cdef Py_ssize_t i, j @@ -2267,56 +2270,56 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: M = Matrix(pR, [ \ - [ 6*x+4, 5*x^3+5*x, 6*x^2+2*x+2], \ - [4*x^2+5*x+2, x^4+5*x^2+2*x+4, 4*x^3+6*x^2+6*x+5]]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: M = Matrix(pR, [ # optional - sage.rings.finite_rings + ....: [ 6*x+4, 5*x^3+5*x, 6*x^2+2*x+2], + ....: [4*x^2+5*x+2, x^4+5*x^2+2*x+4, 4*x^3+6*x^2+6*x+5]]) - sage: P,U = M.popov_form(transformation=True) - sage: P + sage: P, U = M.popov_form(transformation=True) # optional - sage.combinat sage.rings.finite_rings + sage: P # optional - sage.combinat sage.rings.finite_rings [ 4 x^2 + 4*x + 1 3] [ 0 4*x + 1 x^2 + 6*x + 1] - sage: U + sage: U # optional - sage.combinat sage.rings.finite_rings [ x 2] [5*x^2 + x + 6 3*x + 2] - sage: P.is_popov() and U.is_invertible() and U*M==P + sage: P.is_popov() and U.is_invertible() and U*M == P # optional - sage.combinat sage.rings.finite_rings True Demonstrating shifts and specific case of Hermite form:: - sage: P = M.popov_form(shifts=[0,2,4]); P + sage: P = M.popov_form(shifts=[0,2,4]); P # optional - sage.combinat sage.rings.finite_rings [ 4*x^2 + 3*x + 4 x^4 + 3*x^3 + 5*x^2 + 5*x + 5 0] [ 6 5*x^2 + 6*x + 5 1] - sage: P.is_popov(shifts=[0,2,4]) + sage: P.is_popov(shifts=[0,2,4]) # optional - sage.combinat sage.rings.finite_rings True - sage: P==M.popov_form(shifts=[-6,-4,-2]) + sage: P == M.popov_form(shifts=[-6,-4,-2]) # optional - sage.combinat sage.rings.finite_rings True - sage: dd=sum(M.row_degrees())+1 - sage: M.popov_form(shifts=[2*dd,dd,0]) == M.hermite_form() + sage: dd = sum(M.row_degrees()) + 1 # optional - sage.combinat sage.rings.finite_rings + sage: M.popov_form(shifts=[2*dd,dd,0]) == M.hermite_form() # optional - sage.combinat sage.rings.finite_rings True Column-wise form is the row-wise form of the transpose:: - sage: M.popov_form() == M.T.popov_form(row_wise=False).T + sage: M.popov_form() == M.T.popov_form(row_wise=False).T # optional - sage.combinat sage.rings.finite_rings True Zero vectors can be discarded:: - sage: M.popov_form(row_wise=False) + sage: M.popov_form(row_wise=False) # optional - sage.combinat sage.rings.finite_rings [x + 2 6 0] [ 0 1 0] - sage: P,U = M.popov_form(transformation=True, \ - row_wise=False, \ - include_zero_vectors=False) - sage: P + sage: P, U = M.popov_form(transformation=True, # optional - sage.combinat sage.rings.finite_rings + ....: row_wise=False, + ....: include_zero_vectors=False) + sage: P # optional - sage.combinat sage.rings.finite_rings [x + 2 6] [ 0 1] - sage: U + sage: U # optional - sage.combinat sage.rings.finite_rings [ 3*x^2 + 6*x + 3 5*x^2 + 4*x + 4 3*x^3 + 3*x^2 + 2*x + 4] [ 3 1 2*x + 1] [ 5*x + 2 2 6] - sage: M*U[:,:2] == P and (M*U[:,2]).is_zero() + sage: M*U[:,:2] == P and (M*U[:,2]).is_zero() # optional - sage.combinat sage.rings.finite_rings True .. SEEALSO:: @@ -2458,40 +2461,40 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(3)[] - sage: A = matrix(pR,3,[x, x^2, x^3, - ....: x^2, x^1, 0, - ....: x^3, x^3, x^3]) - sage: R = A.reduced_form(); R + sage: pR. = GF(3)[] # optional - sage.rings.finite_rings + sage: A = matrix(pR, 3, [x, x^2, x^3, # optional - sage.rings.finite_rings + ....: x^2, x^1, 0, + ....: x^3, x^3, x^3]) + sage: R = A.reduced_form(); R # optional - sage.rings.finite_rings [ x x^2 x^3] [ x^2 x 0] [ x^3 + 2*x x^3 + 2*x^2 0] - sage: R.is_reduced() + sage: R.is_reduced() # optional - sage.rings.finite_rings True - sage: R2 = A.reduced_form(shifts=[6,3,0]); R2 + sage: R2 = A.reduced_form(shifts=[6,3,0]); R2 # optional - sage.rings.finite_rings [ x x^2 x^3] [ 0 2*x^2 + x 2*x^4 + x^3] [ 0 0 2*x^5 + x^4 + x^3] - sage: R2.is_reduced(shifts=[6,3,0]) + sage: R2.is_reduced(shifts=[6,3,0]) # optional - sage.rings.finite_rings True - sage: R2.is_reduced() + sage: R2.is_reduced() # optional - sage.rings.finite_rings False If the matrix is an `n \times 1` matrix with at least one non-zero entry, `R` has a single non-zero entry and that entry is a scalar multiple of the greatest-common-divisor of the entries of the matrix:: - sage: A = matrix([[x*(x-1)*(x+1)],[x*(x-2)*(x+2)],[x]]) - sage: R = A.reduced_form() - sage: R + sage: A = matrix([[x*(x-1)*(x+1)], [x*(x-2)*(x+2)], [x]]) # optional - sage.rings.finite_rings + sage: R = A.reduced_form() # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings [x] [0] [0] A zero matrix is already reduced:: - sage: A = matrix(pR, 2, [0,0,0,0]) - sage: A.reduced_form() + sage: A = matrix(pR, 2, [0,0,0,0]) # optional - sage.rings.finite_rings + sage: A.reduced_form() # optional - sage.rings.finite_rings [0 0] [0 0] @@ -2505,29 +2508,29 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [0 0 x] sage: A.is_reduced() True - sage: W = A.reduced_form(); W + sage: W = A.reduced_form(); W # optional - sage.combinat [ x x x] [-x -x 0] - sage: W.is_weak_popov() + sage: W.is_weak_popov() # optional - sage.combinat True The last example shows the usage of the transformation parameter:: - sage: Fq. = GF(2^3) - sage: pR. = Fq[] - sage: A = matrix(pR, [[x^2+a, x^4+a], - ....: [ x^3, a*x^4]]) - sage: W,U = A.reduced_form(transformation=True) - sage: W,U + sage: Fq. = GF(2^3) # optional - sage.rings.finite_rings + sage: pR. = Fq[] # optional - sage.rings.finite_rings + sage: A = matrix(pR, [[x^2+a, x^4+a], # optional - sage.rings.finite_rings + ....: [ x^3, a*x^4]]) + sage: W, U = A.reduced_form(transformation=True) # optional - sage.rings.finite_rings + sage: W, U # optional - sage.rings.finite_rings ( [ x^2 + a x^4 + a] [1 0] [x^3 + a*x^2 + a^2 a^2], [a 1] ) - sage: W.is_reduced() + sage: W.is_reduced() # optional - sage.rings.finite_rings True - sage: U*W == A + sage: U*W == A # optional - sage.rings.finite_rings True - sage: U.is_invertible() + sage: U.is_invertible() # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -2567,30 +2570,32 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: M. = GF(7)[] - sage: A = matrix(M, 2, 3, [x, 1, 2*x, x, 1+x, 2]) - sage: A.hermite_form() + sage: M. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = matrix(M, 2, 3, [x, 1, 2*x, x, 1+x, 2]) # optional - sage.rings.finite_rings + sage: A.hermite_form() # optional - sage.rings.finite_rings [ x 1 2*x] [ 0 x 5*x + 2] - sage: A.hermite_form(transformation=True) + sage: A.hermite_form(transformation=True) # optional - sage.rings.finite_rings ( [ x 1 2*x] [1 0] [ 0 x 5*x + 2], [6 1] ) - sage: A = matrix(M, 2, 3, [x, 1, 2*x, 2*x, 2, 4*x]) - sage: A.hermite_form(transformation=True, include_zero_rows=False) + sage: A = matrix(M, 2, 3, [x, 1, 2*x, 2*x, 2, 4*x]) # optional - sage.rings.finite_rings + sage: A.hermite_form(transformation=True, include_zero_rows=False) # optional - sage.rings.finite_rings ([ x 1 2*x], [0 4]) - sage: H, U = A.hermite_form(transformation=True, include_zero_rows=True); H, U + sage: H, U = A.hermite_form(transformation=True, # optional - sage.rings.finite_rings + ....: include_zero_rows=True); H, U ( [ x 1 2*x] [0 4] [ 0 0 0], [5 1] ) - sage: U * A == H + sage: U * A == H # optional - sage.rings.finite_rings True - sage: H, U = A.hermite_form(transformation=True, include_zero_rows=False) - sage: U * A + sage: H, U = A.hermite_form(transformation=True, # optional - sage.rings.finite_rings + ....: include_zero_rows=False) + sage: U * A # optional - sage.rings.finite_rings [ x 1 2*x] - sage: U * A == H + sage: U * A == H # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -2627,26 +2632,26 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 3, 2, \ - [[ 3*x^3 + 3*x, 2*x^3 + 4], \ - [ 3*x^3 + 6*x + 5, 6*x^3 + 5*x^2 + 1], \ - [ 2*x^3 + 2*x + 6, 3*x^2 + 2*x + 2]]) - sage: B = Matrix(pR, 3, 3, \ - [[ 3, x + 3, 6], \ - [3*x^3 + 3*x + 1, 4*x^2 + 3*x, 6*x^3 + x + 4], \ - [ 4*x^2 + x + 4, 3*x^2 + 4*x, 3*x^2 + 3*x + 2]]) - sage: Q,R = A.left_quo_rem(B); (Q,R) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 3, 2, # optional - sage.rings.finite_rings + ....: [[ 3*x^3 + 3*x, 2*x^3 + 4], + ....: [ 3*x^3 + 6*x + 5, 6*x^3 + 5*x^2 + 1], + ....: [ 2*x^3 + 2*x + 6, 3*x^2 + 2*x + 2]]) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[ 3, x + 3, 6], + ....: [3*x^3 + 3*x + 1, 4*x^2 + 3*x, 6*x^3 + x + 4], + ....: [ 4*x^2 + x + 4, 3*x^2 + 4*x, 3*x^2 + 3*x + 2]]) + sage: Q, R = A.left_quo_rem(B); Q, R # optional - sage.rings.finite_rings ( [2*x^2 + 4*x + 6 6*x^2 + 4*x + 1] [ 3 1] [ 3*x^2 + 5*x 2*x^2 + x + 5] [ 6 5*x^2 + 2*x + 3] [ 6*x^2 + 3*x 4*x^2 + 6*x + 1], [ 2*x + 3 6*x + 3] ) - sage: rdegR = R.row_degrees(); rdegB = B.row_degrees() - sage: A == B*Q+R and all([rdegR[i] < rdegB[i] for i in range(3)]) + sage: rdegR = R.row_degrees(); rdegB = B.row_degrees() # optional - sage.rings.finite_rings + sage: A == B*Q+R and all(rdegR[i] < rdegB[i] for i in range(3)) # optional - sage.rings.finite_rings True - sage: A[:2,:].left_quo_rem(B) + sage: A[:2,:].left_quo_rem(B) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: row dimension of self should be the row dimension of @@ -2656,19 +2661,19 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): no quotient and remainder (unless the matrix has full row rank, see :meth:`right_quo_rem`):: - sage: Q,R = A[:2,:].left_quo_rem(B[:2,:]); (Q,R) + sage: Q, R = A[:2,:].left_quo_rem(B[:2,:]); Q, R # optional - sage.rings.finite_rings ( [ 3*x + 3 2*x + 1] [ 3*x^2 + 5*x 2*x^2 + x + 5] [ 5 0] [ 0 0], [4*x^2 + x + 2 4*x^2 + x] ) - sage: rdegR = R.row_degrees(); rdegB = B[:2,:].row_degrees() - sage: A[:2,:] == B[:2,:]*Q+R + sage: rdegR = R.row_degrees(); rdegB = B[:2,:].row_degrees() # optional - sage.rings.finite_rings + sage: A[:2,:] == B[:2,:]*Q+R # optional - sage.rings.finite_rings True - sage: all([rdegR[i] < rdegB[i] for i in range(len(rdegR))]) + sage: all([rdegR[i] < rdegB[i] for i in range(len(rdegR))]) # optional - sage.rings.finite_rings True - sage: A.left_quo_rem(B[:,:2]) + sage: A.left_quo_rem(B[:,:2]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: division of these matrices does not admit a remainder @@ -2722,37 +2727,37 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): Case where `B` is a square, column reduced matrix:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 2, 3, \ - [[3*x^3 + 3*x, 3*x^3 + 6*x + 5, 2*x^3 + 2*x + 6], \ - [2*x^3 + 4, 6*x^3 + 5*x^2 + 1, 3*x^2 + 2*x + 2]]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[3*x^3 + 3*x, 3*x^3 + 6*x + 5, 2*x^3 + 2*x + 6], + ....: [2*x^3 + 4, 6*x^3 + 5*x^2 + 1, 3*x^2 + 2*x + 2]]) - sage: B = Matrix(pR, 3, 3, \ - [[4*x^2 + 3*x + 3, 3*x^2 + 3*x + 1, 4*x^2 + x + 4], \ - [6*x^2 + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], \ - [5*x^2 + 3*x + 6, 6*x^2 + x + 4, 3*x^2 + 3*x + 2]]) - sage: B.is_reduced(row_wise=False) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x^2 + 3*x + 3, 3*x^2 + 3*x + 1, 4*x^2 + x + 4], + ....: [6*x^2 + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], + ....: [5*x^2 + 3*x + 6, 6*x^2 + x + 4, 3*x^2 + 3*x + 2]]) + sage: B.is_reduced(row_wise=False) # optional - sage.rings.finite_rings True - sage: Q,R = A.right_quo_rem(B); (Q,R) + sage: Q, R = A.right_quo_rem(B); Q, R # optional - sage.rings.finite_rings ( [ 4*x x + 2 6*x + 1] [ x + 2 6*x + 1 5*x + 4] [4*x + 3 x + 6 3*x + 4], [4*x + 2 2*x + 3 4*x + 3] ) - sage: A == Q*B+R and R.degree() < 2 + sage: A == Q*B+R and R.degree() < 2 # optional - sage.rings.finite_rings True - sage: A[:,:2].right_quo_rem(B) + sage: A[:,:2].right_quo_rem(B) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: column dimension of self should be the column dimension of the input matrix - sage: B = Matrix(pR, 3, 3, \ - [[3, 3*x^3 + 3*x + 1, 4*x^2 + x + 4], \ - [x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], \ - [6, 6*x^3 + x + 4, 3*x^2 + 3*x + 2]]) - sage: B.is_reduced(row_wise=False) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[3, 3*x^3 + 3*x + 1, 4*x^2 + x + 4], + ....: [x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], + ....: [6, 6*x^3 + x + 4, 3*x^2 + 3*x + 2]]) + sage: B.is_reduced(row_wise=False) # optional - sage.rings.finite_rings True - sage: Q,R = A.right_quo_rem(B); (Q,R) + sage: Q, R = A.right_quo_rem(B); Q, R # optional - sage.rings.finite_rings ( [2*x^2 + 4*x + 6 3*x^2 + 5*x 6*x^2 + 3*x] [6*x^2 + 4*x + 1 2*x^2 + x + 5 4*x^2 + 6*x + 1], @@ -2760,20 +2765,20 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 3 6 2*x + 3] [ 1 5*x^2 + 2*x + 3 6*x + 3] ) - sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() - sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) + sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() # optional - sage.rings.finite_rings + sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) # optional - sage.rings.finite_rings True With a nonsingular but also non-reduced matrix, there exists a solution, but it might not be unique:: - sage: B = Matrix(pR, 3, 3, \ - [[ 5, 0, 2*x + 6], \ - [ 4*x, 3*x^2 + 4*x + 5, x + 1], \ - [3*x^2 + 5*x + 2, 6*x^3 + 4*x + 6, 3]]) - sage: B.det() != 0 and (not B.is_reduced(row_wise=False)) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[ 5, 0, 2*x + 6], + ....: [ 4*x, 3*x^2 + 4*x + 5, x + 1], + ....: [3*x^2 + 5*x + 2, 6*x^3 + 4*x + 6, 3]]) + sage: B.det() != 0 and (not B.is_reduced(row_wise=False)) # optional - sage.rings.finite_rings True - sage: Q,R = A.right_quo_rem(B); (Q,R) + sage: Q, R = A.right_quo_rem(B); Q, R # optional - sage.rings.finite_rings ( [ 6*x^2 + 3*x 4*x^2 + 3*x + 1 5*x + 1] [ x^2 + 5*x + 5 5*x^2 + 3*x + 5 x + 2], @@ -2781,17 +2786,17 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 4*x + 5 x^2 + 2*x + 1 2] [ 6*x + 3 5*x^2 + 6 3] ) - sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() - sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) + sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() # optional - sage.rings.finite_rings + sage: A == Q*B+R and all(cdegR[i] < cdegB[i] for i in range(3)) # optional - sage.rings.finite_rings True - sage: Q2 = Matrix(pR, 2, 3, \ - [[6*x^2 + 3*x + 1, 4*x^2 + 3*x + 6, 5*x + 1], \ - [ x^2 + 5*x + 3, 5*x^2 + 3*x + 2, x + 2]]) - sage: R2 = Matrix(pR, 2, 3, \ - [[ 5*x, 3*x + 4, 5], \ - [4*x + 6, 5*x, 4]]) - sage: A == Q2*B + R2 + sage: Q2 = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[6*x^2 + 3*x + 1, 4*x^2 + 3*x + 6, 5*x + 1], + ....: [ x^2 + 5*x + 3, 5*x^2 + 3*x + 2, x + 2]]) + sage: R2 = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[ 5*x, 3*x + 4, 5], + ....: [4*x + 6, 5*x, 4]]) + sage: A == Q2*B + R2 # optional - sage.rings.finite_rings True The same remark holds more generally for full column rank matrices: @@ -2799,8 +2804,8 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): other cases (rank-deficient matrix `B` or matrix `B` having strictly fewer rows than columns) there may be no solution:: - sage: C = B.stack(B[1,:] + B[2,:]) # matrix 4 x 3, full column rank - sage: Q,R = A.right_quo_rem(C); (Q,R) + sage: C = B.stack(B[1,:] + B[2,:]) # 4 x 3, full column rank # optional - sage.rings.finite_rings + sage: Q, R = A.right_quo_rem(C); Q, R # optional - sage.rings.finite_rings ( [ 6*x^2 + 3*x 4*x^2 + 3*x + 1 5*x + 1 0] [ x^2 + 5*x + 5 5*x^2 + 3*x + 5 x + 2 0], @@ -2809,13 +2814,13 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 6*x + 3 5*x^2 + 6 3] ) - sage: A.right_quo_rem(B[:2,:]) # matrix 2 x 3, full row rank + sage: A.right_quo_rem(B[:2,:]) # matrix 2 x 3, full row rank # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: division of these matrices does not admit a remainder with the required degree property - sage: D = copy(B); D[2,:] = B[0,:]+B[1,:] # square, singular - sage: A.right_quo_rem(D) + sage: D = copy(B); D[2,:] = B[0,:]+B[1,:] # square, singular # optional - sage.rings.finite_rings + sage: A.right_quo_rem(D) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: division of these matrices does not admit a remainder @@ -2826,11 +2831,11 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): remainder, in which case this method will find it via normal form computation:: - sage: B = Matrix(pR, 1, 2, [[x, x]]) - sage: A = Matrix(pR, 1, 2, [[x, x+2]]) - sage: A.right_quo_rem(B) + sage: B = Matrix(pR, 1, 2, [[x, x]]) # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 1, 2, [[x, x+2]]) # optional - sage.rings.finite_rings + sage: A.right_quo_rem(B) # optional - sage.rings.finite_rings ([1], [0 2]) - sage: A == 1*B + Matrix([[0,2]]) + sage: A == 1*B + Matrix([[0,2]]) # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -2878,32 +2883,32 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 2, 3, \ - [[3*x^3 + 3*x, 3*x^3 + 6*x + 5, 2*x^3 + 2*x + 6], \ - [2*x^3 + 4, 6*x^3 + 5*x^2 + 1, 3*x^2 + 2*x + 2]]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[3*x^3 + 3*x, 3*x^3 + 6*x + 5, 2*x^3 + 2*x + 6], + ....: [2*x^3 + 4, 6*x^3 + 5*x^2 + 1, 3*x^2 + 2*x + 2]]) - sage: B = Matrix(pR, 3, 3, \ - [[4*x^2 + 3*x + 3, 3*x^2 + 3*x + 1, 4*x^2 + x + 4], \ - [6*x^2 + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], \ - [5*x^2 + 3*x + 6, 6*x^2 + x + 4, 3*x^2 + 3*x + 2]]) - sage: B.is_reduced(row_wise=False) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x^2 + 3*x + 3, 3*x^2 + 3*x + 1, 4*x^2 + x + 4], + ....: [6*x^2 + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], + ....: [5*x^2 + 3*x + 6, 6*x^2 + x + 4, 3*x^2 + 3*x + 2]]) + sage: B.is_reduced(row_wise=False) # optional - sage.rings.finite_rings True - sage: Q,R = A._right_quo_rem_reduced(B); (Q,R) + sage: Q, R = A._right_quo_rem_reduced(B); Q, R # optional - sage.rings.finite_rings ( [ 4*x x + 2 6*x + 1] [ x + 2 6*x + 1 5*x + 4] [4*x + 3 x + 6 3*x + 4], [4*x + 2 2*x + 3 4*x + 3] ) - sage: A == Q*B+R and R.degree() < 2 + sage: A == Q*B+R and R.degree() < 2 # optional - sage.rings.finite_rings True - sage: B = Matrix(pR, 3, 3, \ - [[4*x + 3*x + 3, 3*x^3 + 3*x + 1, 4*x^2 + x + 4], \ - [6*x + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], \ - [6, 6*x^3 + x + 4, 3*x^2 + 3*x + 2]]) - sage: B.is_reduced(row_wise=False) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x + 3*x + 3, 3*x^3 + 3*x + 1, 4*x^2 + x + 4], + ....: [6*x + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], + ....: [6, 6*x^3 + x + 4, 3*x^2 + 3*x + 2]]) + sage: B.is_reduced(row_wise=False) # optional - sage.rings.finite_rings True - sage: Q,R = A._right_quo_rem_reduced(B); (Q,R) + sage: Q, R = A._right_quo_rem_reduced(B); Q, R # optional - sage.rings.finite_rings ( [2*x^2 + 4*x + 6 3*x^2 + 5*x 6*x^2 + 3*x] [6*x^2 + 4*x + 1 2*x^2 + x + 5 4*x^2 + 6*x + 1], @@ -2911,8 +2916,8 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 3 6 2*x + 3] [ 1 5*x^2 + 2*x + 3 6*x + 3] ) - sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() - sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) + sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() # optional - sage.rings.finite_rings + sage: A == Q*B+R and all(cdegR[i] < cdegB[i] for i in range(3)) # optional - sage.rings.finite_rings True """ # Step 0: find parameter d (delta in above reference) @@ -2957,16 +2962,16 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: A = Matrix(pR, 2, 3, \ - [[3*x^3 + 3*x, 3*x^3 + 6*x + 5, 2*x^3 + 2*x + 6], \ - [2*x^3 + 4, 6*x^3 + 5*x^2 + 1, 3*x^2 + 2*x + 2]]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[3*x^3 + 3*x, 3*x^3 + 6*x + 5, 2*x^3 + 2*x + 6], + ....: [2*x^3 + 4, 6*x^3 + 5*x^2 + 1, 3*x^2 + 2*x + 2]]) - sage: B = Matrix(pR, 3, 3, \ - [[4*x + 3*x + 3, 3*x^3 + 3*x + 1, 4*x^2 + x + 4], \ - [6*x + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], \ - [6, 6*x^3 + x + 4, 3*x^2 + 3*x + 2]]) - sage: Q,R = A._right_quo_rem_solve(B); (Q,R) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[4*x + 3*x + 3, 3*x^3 + 3*x + 1, 4*x^2 + x + 4], + ....: [6*x + 2*x + 3, 4*x^2 + 3*x, 3*x^2 + 4*x], + ....: [6, 6*x^3 + x + 4, 3*x^2 + 3*x + 2]]) + sage: Q, R = A._right_quo_rem_solve(B); Q, R # optional - sage.rings.finite_rings ( [2*x^2 + 4*x + 6 3*x^2 + 5*x 6*x^2 + 3*x] [6*x^2 + 4*x + 1 2*x^2 + x + 5 4*x^2 + 6*x + 1], @@ -2974,22 +2979,22 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 3 6 2*x + 3] [ 1 5*x^2 + 2*x + 3 6*x + 3] ) - sage: B.is_reduced(row_wise=False) + sage: B.is_reduced(row_wise=False) # optional - sage.rings.finite_rings True - sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() - sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) + sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() # optional - sage.rings.finite_rings + sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) # optional - sage.rings.finite_rings True With a nonsingular but also non-reduced matrix, there exists a solution and one is found by this method, but it might not be unique:: - sage: B = Matrix(pR, 3, 3, \ - [[ 5, 0, 2*x + 6], \ - [ 4*x, 3*x^2 + 4*x + 5, x + 1], \ - [3*x^2 + 5*x + 2, 6*x^3 + 4*x + 6, 3]]) - sage: B.det() != 0 and (not B.is_reduced(row_wise=False)) + sage: B = Matrix(pR, 3, 3, # optional - sage.rings.finite_rings + ....: [[ 5, 0, 2*x + 6], + ....: [ 4*x, 3*x^2 + 4*x + 5, x + 1], + ....: [3*x^2 + 5*x + 2, 6*x^3 + 4*x + 6, 3]]) + sage: B.det() != 0 and not B.is_reduced(row_wise=False) # optional - sage.rings.finite_rings True - sage: Q,R = A._right_quo_rem_solve(B); (Q,R) + sage: Q, R = A._right_quo_rem_solve(B); Q, R # optional - sage.rings.finite_rings ( [ 6*x^2 + 3*x 4*x^2 + 3*x + 1 5*x + 1] [ x^2 + 5*x + 5 5*x^2 + 3*x + 5 x + 2], @@ -2997,17 +3002,17 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 4*x + 5 x^2 + 2*x + 1 2] [ 6*x + 3 5*x^2 + 6 3] ) - sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() - sage: A == Q*B+R and all([cdegR[i] < cdegB[i] for i in range(3)]) + sage: cdegR = R.column_degrees(); cdegB = B.column_degrees() # optional - sage.rings.finite_rings + sage: A == Q*B+R and all(cdegR[i] < cdegB[i] for i in range(3)) # optional - sage.rings.finite_rings True - sage: Q2 = Matrix(pR, 2, 3, \ - [[6*x^2 + 3*x + 1, 4*x^2 + 3*x + 6, 5*x + 1], \ - [ x^2 + 5*x + 3, 5*x^2 + 3*x + 2, x + 2]]) - sage: R2 = Matrix(pR, 2, 3, \ - [[ 5*x, 3*x + 4, 5], \ - [4*x + 6, 5*x, 4]]) - sage: A == Q2*B + R2 + sage: Q2 = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[6*x^2 + 3*x + 1, 4*x^2 + 3*x + 6, 5*x + 1], + ....: [ x^2 + 5*x + 3, 5*x^2 + 3*x + 2, x + 2]]) + sage: R2 = Matrix(pR, 2, 3, # optional - sage.rings.finite_rings + ....: [[ 5*x, 3*x + 4, 5], + ....: [4*x + 6, 5*x, 4]]) + sage: A == Q2*B + R2 # optional - sage.rings.finite_rings True The same remark holds more generally for full column rank matrices: @@ -3015,8 +3020,8 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): other cases (rank-deficient or strictly fewer rows than columns) there might be no solution:: - sage: C = B.stack(B[1,:] + B[2,:]) # matrix 4 x 3, full column rank - sage: Q,R = A._right_quo_rem_solve(C); (Q,R) + sage: C = B.stack(B[1,:] + B[2,:]) # 4 x 3, full column rank # optional - sage.rings.finite_rings + sage: Q, R = A._right_quo_rem_solve(C); Q, R # optional - sage.rings.finite_rings ( [ 6*x^2 + 3*x 4*x^2 + 3*x + 1 5*x + 1 0] [ x^2 + 5*x + 5 5*x^2 + 3*x + 5 x + 2 0], @@ -3025,12 +3030,12 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 6*x + 3 5*x^2 + 6 3] ) - sage: A._right_quo_rem_solve(B[:2,:]) # matrix 2 x 3, full row rank + sage: A._right_quo_rem_solve(B[:2,:]) # 2 x 3, full row rank # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: dividing via system solving yields no solution - sage: D = copy(B); D[2,:] = B[0,:]+B[1,:] # square, singular - sage: A._right_quo_rem_solve(D) + sage: D = copy(B); D[2,:] = B[0,:]+B[1,:] # square, singular # optional - sage.rings.finite_rings + sage: A._right_quo_rem_solve(D) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: dividing via system solving yields no solution @@ -3039,11 +3044,11 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): columns), even when there is a solution, this method might not find it:: - sage: B = Matrix(pR, 1, 2, [[x, x]]) - sage: A = Matrix(pR, 1, 2, [[x, x+2]]) - sage: A == 1*B + Matrix([[0,2]]) # a valid quo_rem + sage: B = Matrix(pR, 1, 2, [[x, x]]) # optional - sage.rings.finite_rings + sage: A = Matrix(pR, 1, 2, [[x, x+2]]) # optional - sage.rings.finite_rings + sage: A == 1*B + Matrix([[0,2]]) # a valid quo_rem # optional - sage.rings.finite_rings True - sage: A._right_quo_rem_solve(B) + sage: A._right_quo_rem_solve(B) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: dividing via system solving yields no solution @@ -3124,24 +3129,24 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: B = Matrix(pR, [ \ - [ 6*x+4, 5*x^3+5*x, 6*x^2+2*x+2], \ - [4*x^2+5*x+2, x^4+5*x^2+2*x+4, 4*x^3+6*x^2+6*x+5]]) - sage: A = Matrix(pR, 1, 3, [ \ - [3*x^4+3*x^3+4*x^2+5*x+1, x^4+x^3+5*x^2+4*x+4, 4*x^4+2*x^3+x]]) + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: B = Matrix(pR, [ # optional - sage.rings.finite_rings + ....: [ 6*x+4, 5*x^3+5*x, 6*x^2+2*x+2], + ....: [4*x^2+5*x+2, x^4+5*x^2+2*x+4, 4*x^3+6*x^2+6*x+5]]) + sage: A = Matrix(pR, 1, 3, [ # optional - sage.rings.finite_rings + ....: [3*x^4+3*x^3+4*x^2+5*x+1, x^4+x^3+5*x^2+4*x+4, 4*x^4+2*x^3+x]]) - sage: (Q,R) = A.reduce(B,return_quotient=True); R + sage: Q, R = A.reduce(B,return_quotient=True); R # optional - sage.rings.finite_rings [3*x^4 + 3*x^3 + 4*x + 3 2*x + 2 2*x + 6] - sage: A == Q*B + R + sage: A == Q*B + R # optional - sage.rings.finite_rings True - sage: P = B.popov_form(); P.leading_positions(return_degree=True) + sage: P = B.popov_form(); P.leading_positions(return_degree=True) # optional - sage.rings.finite_rings ([1, 2], [2, 2]) - sage: R.degree_matrix() + sage: R.degree_matrix() # optional - sage.rings.finite_rings [4 1 1] - sage: A.reduce(P) == R + sage: A.reduce(P) == R # optional - sage.rings.finite_rings True - sage: A.reduce(P[:,:2]) + sage: A.reduce(P[:,:2]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: column dimension of self should be the column @@ -3149,41 +3154,41 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): Demonstrating shifts:: - sage: (Qs,Rs) = A.reduce(B,shifts=[0,2,4],return_quotient=True); Rs + sage: Qs, Rs = A.reduce(B, shifts=[0,2,4], return_quotient=True); Rs # optional - sage.rings.finite_rings [3*x^4 + 3*x^3 + 6*x + 2 4*x^3 + 5*x 0] - sage: A == Qs*B + Rs + sage: A == Qs*B + Rs # optional - sage.rings.finite_rings True - sage: Ps = B.popov_form(shifts=[0,2,4]) - sage: Ps.leading_positions(shifts=[0,2,4],return_degree=True) + sage: Ps = B.popov_form(shifts=[0,2,4]) # optional - sage.rings.finite_rings + sage: Ps.leading_positions(shifts=[0,2,4], return_degree=True) # optional - sage.rings.finite_rings ([1, 2], [4, 0]) - sage: Rs.degree_matrix() + sage: Rs.degree_matrix() # optional - sage.rings.finite_rings [ 4 3 -1] - sage: A.reduce(Ps, shifts=[0,2,4]) == Rs + sage: A.reduce(Ps, shifts=[0,2,4]) == Rs # optional - sage.rings.finite_rings True If ``return_quotient`` is ``False``, only the normal form is returned:: - sage: R == A.reduce(B) and Rs == A.reduce(B,shifts=[0,2,4]) + sage: R == A.reduce(B) and Rs == A.reduce(B, shifts=[0,2,4]) # optional - sage.rings.finite_rings True Demonstrating column-wise normal forms, with a matrix `A` which has several columns, and a matrix `B` which does not have full column rank (its column-wise Popov form has a zero column):: - sage: A = Matrix(pR, 2, 2, \ - [[5*x^3 + 2*x^2 + 4*x + 1, x^3 + 4*x + 4], \ - [2*x^3 + 5*x^2 + 2*x + 4, 2*x^3 + 3*x + 2]]) - sage: (Q,R) = A.reduce(B,row_wise=False,return_quotient=True); R + sage: A = Matrix(pR, 2, 2, # optional - sage.rings.finite_rings + ....: [[5*x^3 + 2*x^2 + 4*x + 1, x^3 + 4*x + 4], + ....: [2*x^3 + 5*x^2 + 2*x + 4, 2*x^3 + 3*x + 2]]) + sage: (Q,R) = A.reduce(B,row_wise=False, return_quotient=True); R # optional - sage.rings.finite_rings [0 3] [0 0] - sage: A == B*Q + R + sage: A == B*Q + R # optional - sage.rings.finite_rings True - sage: P = B.popov_form(row_wise=False); P + sage: P = B.popov_form(row_wise=False); P # optional - sage.rings.finite_rings [x + 2 6 0] [ 0 1 0] - sage: P.leading_positions(row_wise=False, return_degree=True) + sage: P.leading_positions(row_wise=False, return_degree=True) # optional - sage.rings.finite_rings ([0, 1, -1], [1, 0, -1]) - sage: R.degree_matrix() + sage: R.degree_matrix() # optional - sage.rings.finite_rings [-1 0] [-1 -1] @@ -3283,26 +3288,26 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(97)[] + sage: pR. = GF(97)[] # optional - sage.rings.finite_rings We consider the following example from [Arne Storjohann, Notes on computing minimal approximant bases, 2006]:: - sage: order = 8; shifts = [1,1,0,0,0] - sage: pmat = Matrix(pR, 5, 1, [ \ - pR([35, 0, 41, 87, 3, 42, 22, 90]), \ - pR([80, 15, 62, 87, 14, 93, 24, 0]), \ - pR([42, 57, 90, 87, 22, 80, 71, 53]), \ - pR([37, 72, 74, 6, 5, 75, 23, 47]), \ - pR([36, 10, 74, 1, 29, 44, 87, 74]) ]) - sage: appbas = Matrix(pR, [ \ - [x+47, 57, 58*x+44, 9*x+23, 93*x+76], \ - [ 15, x+18, 52*x+23, 15*x+58, 93*x+88], \ - [ 17, 86, x^2+77*x+16, 76*x+29, 90*x+78], \ - [ 44, 36, 3*x+42, x^2+50*x+26, 85*x+44], \ - [ 2, 22, 54*x+94, 73*x+24, x^2+2*x+25] ]) - sage: appbas.is_minimal_approximant_basis(pmat,\ - order, shifts, row_wise=True, normal_form=True) + sage: order = 8; shifts = [1,1,0,0,0] # optional - sage.rings.finite_rings + sage: pmat = Matrix(pR, 5, 1, [ # optional - sage.rings.finite_rings + ....: pR([35, 0, 41, 87, 3, 42, 22, 90]), + ....: pR([80, 15, 62, 87, 14, 93, 24, 0]), + ....: pR([42, 57, 90, 87, 22, 80, 71, 53]), + ....: pR([37, 72, 74, 6, 5, 75, 23, 47]), + ....: pR([36, 10, 74, 1, 29, 44, 87, 74])]) + sage: appbas = Matrix(pR, [ # optional - sage.rings.finite_rings + ....: [x+47, 57, 58*x+44, 9*x+23, 93*x+76], + ....: [ 15, x+18, 52*x+23, 15*x+58, 93*x+88], + ....: [ 17, 86, x^2+77*x+16, 76*x+29, 90*x+78], + ....: [ 44, 36, 3*x+42, x^2+50*x+26, 85*x+44], + ....: [ 2, 22, 54*x+94, 73*x+24, x^2+2*x+25]]) + sage: appbas.is_minimal_approximant_basis( # optional - sage.rings.finite_rings + ....: pmat, order, shifts, row_wise=True, normal_form=True) True The matrix `x^8 \mathrm{Id}_5` is square, nonsingular, in Popov form, @@ -3310,34 +3315,35 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): not an approximant basis since its rows generate a module strictly contained in the set of approximants for ``pmat`` at order 8:: - sage: (x^8*Matrix.identity(pR, 5)).is_minimal_approximant_basis(\ - pmat, 8) + sage: M = x^8 * Matrix.identity(pR, 5) # optional - sage.rings.finite_rings + sage: M.is_minimal_approximant_basis(pmat, 8) # optional - sage.rings.finite_rings False Since ``pmat`` is a single column, with nonzero constant coefficient, its column-wise approximant bases at order 8 are all `1\times 1` matrices `[c x^8]` for some nonzero field element `c`:: - sage: Matrix(pR, [x^8]).is_minimal_approximant_basis(pmat, \ - 8, row_wise=False, normal_form=True) + sage: M = Matrix(pR, [x^8]) # optional - sage.rings.finite_rings + sage: M.is_minimal_approximant_basis( # optional - sage.rings.finite_rings + ....: pmat, 8, row_wise=False, normal_form=True) True Exceptions are raised if input dimensions are not sound:: - sage: appbas.is_minimal_approximant_basis(pmat, [8,8], shifts) + sage: appbas.is_minimal_approximant_basis(pmat, [8,8], shifts) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: order length should be the column dimension of the input matrix - sage: appbas.is_minimal_approximant_basis(pmat, \ - order, shifts, row_wise=False) + sage: appbas.is_minimal_approximant_basis( # optional - sage.rings.finite_rings + ....: pmat, order, shifts, row_wise=False) Traceback (most recent call last): ... ValueError: shifts length should be the column dimension of the input matrix - sage: Matrix(pR, [x^8]).is_minimal_approximant_basis(pmat, 8) + sage: Matrix(pR, [x^8]).is_minimal_approximant_basis(pmat, 8) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: column dimension should be the row dimension of the @@ -3493,60 +3499,63 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings sage: order = [4, 3]; shifts = [-1, 2, 0] - sage: F = Matrix(pR, [[5*x^3 + 4*x^2 + 4*x + 6, 5*x^2 + 4*x + 1], \ - [ 2*x^2 + 2*x + 3, 6*x^2 + 6*x + 3], \ - [4*x^3 + x + 1, 4*x^2 + 2*x + 3] ]) - sage: P = F.minimal_approximant_basis(order, shifts) - sage: P.is_minimal_approximant_basis(F, order, shifts) + sage: F = Matrix(pR, [[5*x^3 + 4*x^2 + 4*x + 6, 5*x^2 + 4*x + 1], # optional - sage.rings.finite_rings + ....: [ 2*x^2 + 2*x + 3, 6*x^2 + 6*x + 3], + ....: [4*x^3 + x + 1, 4*x^2 + 2*x + 3]]) + sage: P = F.minimal_approximant_basis(order, shifts) # optional - sage.rings.finite_rings + sage: P.is_minimal_approximant_basis(F, order, shifts) # optional - sage.rings.finite_rings True By default, the computed basis is not required to be in normal form (and will not be except in rare special cases):: - sage: P.is_minimal_approximant_basis(F, order, shifts, \ - normal_form=True) + sage: P.is_minimal_approximant_basis(F, order, shifts, # optional - sage.rings.finite_rings + ....: normal_form=True) False - sage: P = F.minimal_approximant_basis(order, shifts, normal_form=True) - sage: P.is_minimal_approximant_basis(F, order, shifts, \ - normal_form=True) + sage: P = F.minimal_approximant_basis(order, shifts, # optional - sage.rings.finite_rings + ....: normal_form=True) + sage: P.is_minimal_approximant_basis(F, order, shifts, # optional - sage.rings.finite_rings + ....: normal_form=True) True If shifts are not specified, they are chosen as uniform `[0,\ldots,0]` by default. Besides, if the orders are all the same, one can rather give a single integer:: - sage: F.minimal_approximant_basis(3) == \ - F.minimal_approximant_basis([3,3], shifts=None) + sage: (F.minimal_approximant_basis(3) == # optional - sage.rings.finite_rings + ....: F.minimal_approximant_basis([3,3], shifts=None)) True One can work column-wise by specifying ``row_wise=False``:: - sage: P = F.minimal_approximant_basis([5,2,2], [0,1], row_wise=False) - sage: P.is_minimal_approximant_basis(F, [5,2,2], \ - shifts=[0,1], row_wise=False) + sage: P = F.minimal_approximant_basis([5,2,2], [0,1], # optional - sage.rings.finite_rings + ....: row_wise=False) + sage: P.is_minimal_approximant_basis(F, [5,2,2], shifts=[0,1], # optional - sage.rings.finite_rings + ....: row_wise=False) True - sage: F.minimal_approximant_basis(3, row_wise=True) == \ - F.transpose().minimal_approximant_basis(3, row_wise=False).transpose() + sage: (F.minimal_approximant_basis(3, row_wise=True) == # optional - sage.rings.finite_rings + ....: F.transpose().minimal_approximant_basis( + ....: 3, row_wise=False).transpose()) True Errors are raised if the input dimensions are not sound:: - sage: P = F.minimal_approximant_basis([4], shifts) + sage: P = F.minimal_approximant_basis([4], shifts) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: order length should be the column dimension - sage: P = F.minimal_approximant_basis(order, [0,0,0,0]) + sage: P = F.minimal_approximant_basis(order, [0,0,0,0]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: shifts length should be the row dimension An error is raised if order does not contain only positive integers:: - sage: P = F.minimal_approximant_basis([1,0], shifts) + sage: P = F.minimal_approximant_basis([1,0], shifts) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: order should consist of positive integers @@ -3643,31 +3652,31 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings This method supports any number of columns or rows, as well as arbitrary shifts and orders:: - sage: order = [4, 1, 2]; shifts = [-3, 4] - sage: pmat = Matrix(pR, [[5*x^3 + 4*x^2 + 4*x + 6, 5, 4], \ - [2*x^3 + 2*x^2 + 2*x + 3, 6, 6*x + 3]]) - sage: appbas,rdeg = pmat._approximant_basis_iterative(order, \ - shifts) - sage: appbas.is_minimal_approximant_basis(pmat, order, shifts) + sage: order = [4, 1, 2]; shifts = [-3, 4] # optional - sage.rings.finite_rings + sage: pmat = Matrix(pR, [[5*x^3 + 4*x^2 + 4*x + 6, 5, 4], # optional - sage.rings.finite_rings + ....: [2*x^3 + 2*x^2 + 2*x + 3, 6, 6*x + 3]]) + sage: appbas, rdeg = pmat._approximant_basis_iterative(order, # optional - sage.rings.finite_rings + ....: shifts) + sage: appbas.is_minimal_approximant_basis(pmat, order, shifts) # optional - sage.rings.finite_rings True The returned list is the shifted row degrees of ``appbas``:: - sage: rdeg == appbas.row_degrees(shifts) + sage: rdeg == appbas.row_degrees(shifts) # optional - sage.rings.finite_rings True Approximant bases for the zero matrix are all constant unimodular matrices; in fact, this algorithm returns the identity:: - sage: pmat = Matrix(pR, 3, 2) - sage: appbas,rdeg = pmat._approximant_basis_iterative([2,5], \ - [5,0,-4]) - sage: rdeg == [5,0,-4] and appbas == Matrix.identity(pR, 3) + sage: pmat = Matrix(pR, 3, 2) # optional - sage.rings.finite_rings + sage: appbas,rdeg = pmat._approximant_basis_iterative([2,5], # optional - sage.rings.finite_rings + ....: [5,0,-4]) + sage: rdeg == [5,0,-4] and appbas == Matrix.identity(pR, 3) # optional - sage.rings.finite_rings True """ # Define parameters and perform some sanity checks @@ -3796,24 +3805,26 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(97)[] - sage: pmat = Matrix(pR, [[1],[x],[x**2]]) + sage: pR. = GF(97)[] # optional - sage.rings.finite_rings + sage: pmat = Matrix(pR, [[1], [x], [x**2]]) # optional - sage.rings.finite_rings - sage: kerbas = Matrix(pR, [[x,-1,0],[0,x,-1]]) - sage: kerbas.is_minimal_kernel_basis(pmat) + sage: kerbas = Matrix(pR, [[x,-1,0], [0,x,-1]]) # optional - sage.rings.finite_rings + sage: kerbas.is_minimal_kernel_basis(pmat) # optional - sage.rings.finite_rings True A matrix in Popov form which has the right rank, all rows in the kernel, but does not generate the kernel:: - sage: kerbas = Matrix(pR, [[x**2,0,-1],[0,x,-1]]) - sage: kerbas.is_minimal_kernel_basis(pmat) + sage: kerbas = Matrix(pR, [[x**2,0,-1], [0,x,-1]]) # optional - sage.rings.finite_rings + sage: kerbas.is_minimal_kernel_basis(pmat) # optional - sage.rings.finite_rings False Shifts and right kernel bases are supported (with ``row_wise``), and one can test whether the kernel basis is normalized in shifted-Popov form (with ``normal_form``):: - sage: kerbas = Matrix(pR, [[-x,-x**2],[1,0],[0,1]]) - sage: kerbas.is_minimal_kernel_basis(pmat.transpose(),row_wise=False,normal_form=True,shifts=[0,1,2]) + sage: kerbas = Matrix(pR, [[-x,-x**2], [1,0], [0,1]]) # optional - sage.rings.finite_rings + sage: kerbas.is_minimal_kernel_basis( # optional - sage.rings.finite_rings + ....: pmat.transpose(), row_wise=False, + ....: normal_form=True, shifts=[0,1,2]) True """ m = pmat.nrows() @@ -3916,25 +3927,26 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): EXAMPLES:: - sage: pR. = GF(7)[] - sage: pmat = Matrix([[(x+1)*(x+3)],[(x+1)*(x+3)+1]]) - sage: pmat.minimal_kernel_basis() + sage: pR. = GF(7)[] # optional - sage.rings.finite_rings + sage: pmat = Matrix([[(x+1)*(x+3)], [(x+1)*(x+3)+1]]) # optional - sage.rings.finite_rings + sage: pmat.minimal_kernel_basis() # optional - sage.rings.finite_rings [6*x^2 + 3*x + 3 x^2 + 4*x + 3] - sage: pmat = Matrix([[(x+1)*(x+3)],[(x+1)*(x+4)]]) - sage: pmat.minimal_kernel_basis() + sage: pmat = Matrix([[(x+1)*(x+3)], [(x+1)*(x+4)]]) # optional - sage.rings.finite_rings + sage: pmat.minimal_kernel_basis() # optional - sage.rings.finite_rings [6*x + 3 x + 3] - sage: pmat.minimal_kernel_basis(row_wise=False) + sage: pmat.minimal_kernel_basis(row_wise=False) # optional - sage.rings.finite_rings [] - sage: pmat = Matrix(pR, [[1,x,x**2]]) - sage: pmat.minimal_kernel_basis(row_wise=False,normal_form=True) + sage: pmat = Matrix(pR, [[1, x, x**2]]) # optional - sage.rings.finite_rings + sage: pmat.minimal_kernel_basis(row_wise=False, normal_form=True) # optional - sage.rings.finite_rings [x 0] [6 x] [0 6] - sage: pmat.minimal_kernel_basis(row_wise=False,normal_form=True,shifts=[0,1,2]) + sage: pmat.minimal_kernel_basis(row_wise=False, normal_form=True, # optional - sage.rings.finite_rings + ....: shifts=[0,1,2]) [ 6*x 6*x^2] [ 1 0] [ 0 1] diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index a2583f7497a..fac0254d7bf 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -7,11 +7,11 @@ EXAMPLES:: - sage: MS = MatrixSpace(QQ,6,6,sparse=True); MS + sage: MS = MatrixSpace(QQ, 6,6, sparse=True); MS Full MatrixSpace of 6 by 6 sparse matrices over Rational Field sage: MS.base_ring() Rational Field - sage: MS = MatrixSpace(ZZ,3,5,sparse=False); MS + sage: MS = MatrixSpace(ZZ, 3,5, sparse=False); MS Full MatrixSpace of 3 by 5 dense matrices over Integer Ring TESTS:: @@ -19,7 +19,7 @@ sage: matrix(RR,2,2,sparse=True) [0.000000000000000 0.000000000000000] [0.000000000000000 0.000000000000000] - sage: matrix(GF(11),2,2,sparse=True) + sage: matrix(GF(11), 2, 2, sparse=True) # optional - sage.rings.finite_rings [0 0] [0 0] """ @@ -119,26 +119,26 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): sage: get_matrix_class(ZZ, 3, 3, False, 'generic') - sage: get_matrix_class(GF(2^15), 3, 3, False, None) + sage: get_matrix_class(GF(2^15), 3, 3, False, None) # optional - sage.rings.finite_rings - sage: get_matrix_class(GF(2^17), 3, 3, False, None) + sage: get_matrix_class(GF(2^17), 3, 3, False, None) # optional - sage.rings.finite_rings - sage: get_matrix_class(GF(2), 2, 2, False, 'm4ri') + sage: get_matrix_class(GF(2), 2, 2, False, 'm4ri') # optional - sage.rings.finite_rings - sage: get_matrix_class(GF(4), 2, 2, False, 'm4ri') + sage: get_matrix_class(GF(4), 2, 2, False, 'm4ri') # optional - sage.rings.finite_rings - sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-float') + sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-float') # optional - sage.rings.finite_rings - sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-double') + sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-double') # optional - sage.rings.finite_rings - sage: get_matrix_class(RDF, 2, 2, False, 'numpy') + sage: get_matrix_class(RDF, 2, 2, False, 'numpy') # optional - numpy - sage: get_matrix_class(CDF, 2, 3, False, 'numpy') + sage: get_matrix_class(CDF, 2, 3, False, 'numpy') # optional - numpy - sage: get_matrix_class(GF(25,'x'), 4, 4, False, 'meataxe') # optional - meataxe + sage: get_matrix_class(GF(25,'x'), 4, 4, False, 'meataxe') # optional - meataxe sage.rings.finite_rings sage: get_matrix_class(IntegerModRing(3), 4, 4, False, 'meataxe') # optional - meataxe @@ -146,7 +146,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): Traceback (most recent call last): ... ValueError: 'meataxe' matrix can only deal with finite fields of order < 256 - sage: get_matrix_class(GF(next_prime(255)), 4, 4, False, 'meataxe') + sage: get_matrix_class(GF(next_prime(255)), 4, 4, False, 'meataxe') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: 'meataxe' matrix can only deal with finite fields of order < 256 @@ -155,7 +155,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): Traceback (most recent call last): ... ValueError: unknown matrix implementation 'crazy_matrix' over Integer Ring - sage: get_matrix_class(GF(3), 2, 2, False, 'm4ri') + sage: get_matrix_class(GF(3), 2, 2, False, 'm4ri') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: 'm4ri' matrices are only available for fields of characteristic 2 and order <= 65536 @@ -168,19 +168,19 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): ... ValueError: 'linbox-double' matrices can only deal with order < 8388608 - sage: type(matrix(SR, 2, 2, 0)) + sage: type(matrix(SR, 2, 2, 0)) # optional - sage.symbolic - sage: type(matrix(GF(7), 2, range(4))) + sage: type(matrix(GF(7), 2, range(4))) # optional - sage.rings.finite_rings - sage: type(matrix(GF(16007), 2, range(4))) + sage: type(matrix(GF(16007), 2, range(4))) # optional - sage.rings.finite_rings sage: type(matrix(CBF, 2, range(4))) - sage: type(matrix(GF(2), 2, range(4))) + sage: type(matrix(GF(2), 2, range(4))) # optional - sage.rings.finite_rings - sage: type(matrix(GF(64,'z'), 2, range(4))) + sage: type(matrix(GF(64, 'z'), 2, range(4))) # optional - sage.rings.finite_rings - sage: type(matrix(GF(125,'z'), 2, range(4))) # optional - meataxe + sage: type(matrix(GF(125, 'z'), 2, range(4))) # optional - meataxe sage.rings.finite_rings """ @@ -477,36 +477,37 @@ class MatrixSpace(UniqueRepresentation, Parent): Check that different implementations play together as expected:: - sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') + sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # optional - sage.libs.flint sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') - sage: type(M1(range(4))) + sage: type(M1(range(4))) # optional - sage.libs.flint sage: type(M2(range(4))) - sage: M1(M2.an_element()) + sage: M1(M2.an_element()) # optional - sage.libs.flint [ 0 1] [-1 2] - sage: M2(M1.an_element()) + sage: M2(M1.an_element()) # optional - sage.libs.flint [ 0 1] [-1 2] - sage: all(((A.get_action(B) is not None) == (A is B)) for A in [M1,M2] for B in [M1,M2]) + sage: all((A.get_action(B) is not None) == (A is B) # optional - sage.libs.flint + ....: for A in [M1, M2] for B in [M1, M2]) True Check that libgap matrices over finite fields are working properly:: - sage: M2 = MatrixSpace(GF(2), 5, implementation='gap') - sage: M2.one() + sage: M2 = MatrixSpace(GF(2), 5, implementation='gap') # optional - sage.libs.gap sage.rings.finite_rings + sage: M2.one() # optional - sage.libs.gap sage.rings.finite_rings [1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1] - sage: m = M2.random_element() - sage: M1 = MatrixSpace(GF(2), 5) - sage: M1(m * m) == M1(m) * M1(m) + sage: m = M2.random_element() # optional - sage.libs.gap sage.rings.finite_rings + sage: M1 = MatrixSpace(GF(2), 5) # optional - sage.rings.finite_rings + sage: M1(m * m) == M1(m) * M1(m) # optional - sage.rings.finite_rings True """ @@ -521,16 +522,18 @@ def __classcall__(cls, base_ring, nrows, ncols=None, sparse=False, implementatio sage: M1 = MatrixSpace(QQ, 2) sage: M2 = MatrixSpace(QQ, 2) - sage: M3 = MatrixSpace(QQ, 2, implementation='flint') - sage: M1 is M2 and M1 is M3 + sage: M1 is M2 + True + sage: M3 = MatrixSpace(QQ, 2, implementation='flint') # optional - sage.libs.flint + sage: M1 is M3 # optional - sage.libs.flint True :: - sage: M = MatrixSpace(ZZ, 10, implementation="flint") - sage: M + sage: M = MatrixSpace(ZZ, 10, implementation="flint") # optional - sage.libs.flint + sage: M # optional - sage.libs.flint Full MatrixSpace of 10 by 10 dense matrices over Integer Ring - sage: loads(M.dumps()) is M + sage: loads(M.dumps()) is M # optional - sage.libs.flint True sage: MatrixSpace(ZZ, 10, implementation="foobar") @@ -712,7 +715,7 @@ def cardinality(self): EXAMPLES:: - sage: MatrixSpace(GF(3), 2, 3).cardinality() + sage: MatrixSpace(GF(3), 2, 3).cardinality() # optional - sage.rings.finite_rings 729 sage: MatrixSpace(ZZ, 2).cardinality() +Infinity @@ -733,7 +736,7 @@ def characteristic(self): sage: MatrixSpace(ZZ, 2).characteristic() 0 - sage: MatrixSpace(GF(9), 0).characteristic() + sage: MatrixSpace(GF(9), 0).characteristic() # optional - sage.rings.finite_rings 3 """ return self.base_ring().characteristic() @@ -758,11 +761,11 @@ def transposed(self): EXAMPLES:: - sage: MS = MatrixSpace(GF(3), 7, 10) - sage: MS.transposed + sage: MS = MatrixSpace(GF(3), 7, 10) # optional - sage.rings.finite_rings + sage: MS.transposed # optional - sage.rings.finite_rings Full MatrixSpace of 10 by 7 dense matrices over Finite Field of size 3 - sage: MS = MatrixSpace(GF(3), 7, 7) - sage: MS.transposed is MS + sage: MS = MatrixSpace(GF(3), 7, 7) # optional - sage.rings.finite_rings + sage: MS.transposed is MS # optional - sage.rings.finite_rings True sage: M = MatrixSpace(ZZ, 2, 3) @@ -780,15 +783,15 @@ def _copy_zero(self): EXAMPLES:: - sage: MS = MatrixSpace(GF(2),20,20) - sage: MS._copy_zero + sage: MS = MatrixSpace(GF(2), 20, 20) # optional - sage.rings.finite_rings + sage: MS._copy_zero # optional - sage.rings.finite_rings False - sage: MS = MatrixSpace(GF(3),20,20) - sage: MS._copy_zero + sage: MS = MatrixSpace(GF(3), 20, 20) # optional - sage.rings.finite_rings + sage: MS._copy_zero # optional - sage.rings.finite_rings True - sage: MS = MatrixSpace(GF(3),200,200) - sage: MS._copy_zero + sage: MS = MatrixSpace(GF(3), 200, 200) # optional - sage.rings.finite_rings + sage: MS._copy_zero # optional - sage.rings.finite_rings False sage: MS = MatrixSpace(ZZ,200,200) @@ -823,9 +826,10 @@ def _element_constructor_(self, entries, **kwds): EXAMPLES:: - sage: k = GF(7); G = MatrixGroup([matrix(k,2,[1,1,0,1]), matrix(k,2,[1,0,0,2])]) - sage: g = G.0 - sage: MatrixSpace(k,2)(g) + sage: k = GF(7) # optional - sage.rings.finite_rings + sage: G = MatrixGroup([matrix(k, 2, [1,1,0,1]), matrix(k, 2, [1,0,0,2])]) # optional - sage.rings.finite_rings + sage: g = G.0 # optional - sage.rings.finite_rings + sage: MatrixSpace(k, 2)(g) # optional - sage.rings.finite_rings [1 1] [0 1] @@ -875,14 +879,17 @@ def _element_constructor_(self, entries, **kwds): Ensure that :trac:`12020` is fixed:: + sage: rings = [ZZ, QQ, RealField(100), ComplexField(100), RDF, CDF] + sage: rings.append(PolynomialRing(QQ, 'x')) + sage: rings.append(PolynomialRing(CC, 2, 'x')) + sage: rings.append(SR) # optional - sage.symbolic + sage: rings.extend([GF(2), GF(11), GF(2^8,'a'), GF(3^19,'a')]) # optional - sage.rings.finite_rings sage: x = polygen(QQ) - sage: for R in [ZZ, QQ, RealField(100), ComplexField(100), RDF, CDF, - ....: SR, GF(2), GF(11), GF(2^8,'a'), GF(3^19,'a'), - ....: NumberField(x^3+2,'a'), CyclotomicField(4), - ....: PolynomialRing(QQ,'x'), PolynomialRing(CC,2,'x')]: - ....: A = MatrixSpace(R,60,30,sparse=False)(0) + sage: rings.extend([NumberField(x^3+2, 'a'), CyclotomicField(4)]) # optional - sage.rings.number_field + sage: for R in rings: + ....: A = MatrixSpace(R, 60, 30, sparse=False)(0) ....: B = A.augment(A) - ....: A = MatrixSpace(R,60,30,sparse=True)(0) + ....: A = MatrixSpace(R, 60, 30, sparse=True)(0) ....: B = A.augment(A) Check that :trac:`13012` is fixed:: @@ -943,8 +950,9 @@ def change_ring(self, R): EXAMPLES:: - sage: Mat(QQ,3,5).change_ring(GF(7)) - Full MatrixSpace of 3 by 5 dense matrices over Finite Field of size 7 + sage: Mat(QQ, 3, 5).change_ring(GF(7)) # optional - sage.rings.finite_rings + Full MatrixSpace of 3 by 5 dense matrices + over Finite Field of size 7 """ try: return self.__change_ring[R] @@ -968,9 +976,9 @@ def base_extend(self, R): EXAMPLES:: - sage: Mat(ZZ,3,5).base_extend(QQ) + sage: Mat(ZZ, 3, 5).base_extend(QQ) Full MatrixSpace of 3 by 5 dense matrices over Rational Field - sage: Mat(QQ,3,5).base_extend(GF(7)) + sage: Mat(QQ, 3, 5).base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined @@ -1124,13 +1132,13 @@ def _coerce_map_from_(self, S): There are also coercions possible from matrix group and arithmetic subgroups:: - sage: MS = MatrixSpace(GF(3), 2, 2) - sage: MS.coerce_map_from(GL(2, 3)) + sage: MS = MatrixSpace(GF(3), 2, 2) # optional - sage.rings.finite_rings + sage: MS.coerce_map_from(GL(2, 3)) # optional - sage.rings.finite_rings Coercion map: From: General Linear Group of degree 2 over Finite Field of size 3 To: Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3 - sage: MS.coerce_map_from(GL(2, 2)) - sage: MS.coerce_map_from(Gamma1(5)) + sage: MS.coerce_map_from(GL(2, 2)) # optional - sage.rings.finite_rings + sage: MS.coerce_map_from(Gamma1(5)) # optional - sage.rings.finite_rings Coercion map: From: Congruence Subgroup Gamma1(5) To: Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3 @@ -1264,7 +1272,7 @@ def _repr_(self): sage: MS Full MatrixSpace of 2 by 4 sparse matrices over Integer Ring - sage: MatrixSpace(ZZ, 2, implementation='flint') + sage: MatrixSpace(ZZ, 2, implementation='flint') # optional - sage.libs.flint Full MatrixSpace of 2 by 2 dense matrices over Integer Ring sage: MatrixSpace(ZZ, 2, implementation='generic') Full MatrixSpace of 2 by 2 dense matrices over Integer Ring (using Matrix_generic_dense) @@ -1319,14 +1327,14 @@ def __len__(self): EXAMPLES:: - sage: len(MatrixSpace(GF(3),3,2)) + sage: len(MatrixSpace(GF(3), 3, 2)) # optional - sage.rings.finite_rings 729 - sage: len(MatrixSpace(GF(3),2,3)) + sage: len(MatrixSpace(GF(3), 2, 3)) # optional - sage.rings.finite_rings 729 - sage: 3^(2*3) + sage: 3^(2*3) # optional - sage.rings.finite_rings 729 - sage: len(MatrixSpace(GF(2003),3,2)) + sage: len(MatrixSpace(GF(2003), 3, 2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... OverflowError: cannot fit 'int' into an index-sized integer @@ -1352,20 +1360,20 @@ def __iter__(self): :: - sage: list( GF(5) ) + sage: list(GF(5)) # optional - sage.rings.finite_rings [0, 1, 2, 3, 4] - sage: MS = MatrixSpace(GF(5), 2, 2) - sage: l = list(MS) + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.rings.finite_rings + sage: l = list(MS) # optional - sage.rings.finite_rings Then, consider the following matrices:: - sage: A = MS([2,1,0,1]); A + sage: A = MS([2,1,0,1]); A # optional - sage.rings.finite_rings [2 1] [0 1] - sage: B = MS([1,2,1,0]); B + sage: B = MS([1,2,1,0]); B # optional - sage.rings.finite_rings [1 2] [1 0] - sage: C = MS([1,2,0,0]); C + sage: C = MS([1,2,0,0]); C # optional - sage.rings.finite_rings [1 2] [0 0] @@ -1374,9 +1382,9 @@ def __iter__(self): :: - sage: l.index(A) + sage: l.index(A) # optional - sage.rings.finite_rings 41 - sage: l.index(B) + sage: l.index(B) # optional - sage.rings.finite_rings 46 However, A would come after the matrix C since C has a lower weight @@ -1384,9 +1392,9 @@ def __iter__(self): :: - sage: l.index(A) + sage: l.index(A) # optional - sage.rings.finite_rings 41 - sage: l.index(C) + sage: l.index(C) # optional - sage.rings.finite_rings 19 The weights of matrices over other base rings are not as obvious. @@ -1413,11 +1421,11 @@ def __iter__(self): Some more examples:: - sage: MS = MatrixSpace(GF(2),2) - sage: a = list(MS) - sage: len(a) + sage: MS = MatrixSpace(GF(2), 2) # optional - sage.rings.finite_rings + sage: a = list(MS) # optional - sage.rings.finite_rings + sage: len(a) # optional - sage.rings.finite_rings 16 - sage: for m in a: + sage: for m in a: # optional - sage.rings.finite_rings ....: print(m) ....: print('-') [0 0] @@ -1471,11 +1479,11 @@ def __iter__(self): :: - sage: MS = MatrixSpace(GF(2),2, 3) - sage: a = list(MS) - sage: len(a) + sage: MS = MatrixSpace(GF(2), 2, 3) # optional - sage.rings.finite_rings + sage: a = list(MS) # optional - sage.rings.finite_rings + sage: len(a) # optional - sage.rings.finite_rings 64 - sage: a[0] + sage: a[0] # optional - sage.rings.finite_rings [0 0 0] [0 0 0] @@ -1497,11 +1505,11 @@ def __iter__(self): :: - sage: list( MatrixSpace(GF(2), 2, 0) ) + sage: list(MatrixSpace(GF(2), 2, 0)) # optional - sage.rings.finite_rings [[]] - sage: list( MatrixSpace(GF(2), 0, 2) ) + sage: list(MatrixSpace(GF(2), 0, 2)) # optional - sage.rings.finite_rings [[]] - sage: list( MatrixSpace(GF(2), 0, 0) ) + sage: list(MatrixSpace(GF(2), 0, 0)) # optional - sage.rings.finite_rings [[]] If the base ring does not support iteration (for example, with the @@ -1571,13 +1579,15 @@ def __getitem__(self, x): EXAMPLES:: - sage: MS = MatrixSpace(GF(3), 2, 2) - sage: MS['x'] - Univariate Polynomial Ring in x over Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3 - sage: MS[0] + sage: MS = MatrixSpace(GF(3), 2, 2) # optional - sage.rings.finite_rings + sage: MS['x'] # optional - sage.rings.finite_rings + Univariate Polynomial Ring in x + over Full MatrixSpace of 2 by 2 dense matrices + over Finite Field of size 3 + sage: MS[0] # optional - sage.rings.finite_rings [0 0] [0 0] - sage: MS[9] + sage: MS[9] # optional - sage.rings.finite_rings [0 2] [0 0] @@ -1778,10 +1788,10 @@ def identity_matrix(self): Check different implementations:: - sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') + sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # optional - sage.libs.flint sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') - sage: type(M1.identity_matrix()) + sage: type(M1.identity_matrix()) # optional - sage.libs.flint sage: type(M2.identity_matrix()) @@ -1836,10 +1846,10 @@ def diagonal_matrix(self, entries): Check different implementations:: - sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') + sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # optional - sage.libs.flint sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') - sage: type(M1.diagonal_matrix([1, 2])) + sage: type(M1.diagonal_matrix([1, 2])) # optional - sage.libs.flint sage: type(M2.diagonal_matrix([1, 2])) @@ -1872,9 +1882,9 @@ def is_sparse(self): EXAMPLES:: - sage: Mat(GF(2011),10000).is_sparse() + sage: Mat(GF(2011), 10000).is_sparse() # optional - sage.rings.finite_rings False - sage: Mat(GF(2011),10000,sparse=True).is_sparse() + sage: Mat(GF(2011), 10000, sparse=True).is_sparse() # optional - sage.rings.finite_rings True """ return self.__is_sparse @@ -1885,7 +1895,7 @@ def is_finite(self): EXAMPLES:: - sage: MatrixSpace(GF(101), 10000).is_finite() + sage: MatrixSpace(GF(101), 10000).is_finite() # optional - sage.rings.finite_rings True sage: MatrixSpace(QQ, 2).is_finite() False @@ -1901,10 +1911,10 @@ def gen(self, n): EXAMPLES:: - sage: M = Mat(GF(7),10000,5); M.ngens() + sage: M = Mat(GF(7), 10000, 5); M.ngens() # optional - sage.rings.finite_rings 50000 - sage: a = M.10 - sage: a[:4] + sage: a = M.10 # optional - sage.rings.finite_rings + sage: a[:4] # optional - sage.rings.finite_rings [0 0 0 0 0] [0 0 0 0 0] [1 0 0 0 0] @@ -1928,10 +1938,10 @@ def zero_matrix(self): EXAMPLES:: - sage: z = MatrixSpace(GF(7),2,4).zero_matrix(); z + sage: z = MatrixSpace(GF(7), 2, 4).zero_matrix(); z # optional - sage.rings.finite_rings [0 0 0 0] [0 0 0 0] - sage: z.is_mutable() + sage: z.is_mutable() # optional - sage.rings.finite_rings False TESTS:: @@ -1962,7 +1972,7 @@ def ngens(self): EXAMPLES:: - sage: M = Mat(GF(7),100,200); M.ngens() + sage: M = Mat(GF(7), 100, 200); M.ngens() # optional - sage.rings.finite_rings 20000 """ return self.dimension() @@ -2031,17 +2041,17 @@ def matrix(self, x=None, **kwds): sage: MS([[1],[2]]) [1] [2] - sage: MS = MatrixSpace(CC,2,1) - sage: F = NumberField(x^2+1, name='x') - sage: MS([F(1),F(0)]) + sage: MS = MatrixSpace(CC, 2, 1) + sage: F = NumberField(x^2 + 1, name='x') # optional - sage.rings.number_field + sage: MS([F(1), F(0)]) # optional - sage.rings.number_field [ 1.00000000000000] [0.000000000000000] :trac:`10628` allowed to provide the data as lists of matrices, but :trac:`13012` prohibited it:: - sage: MS = MatrixSpace(ZZ,4,2) - sage: MS0 = MatrixSpace(ZZ,2) + sage: MS = MatrixSpace(ZZ, 4,2) + sage: MS0 = MatrixSpace(ZZ, 2) sage: MS.matrix([MS0([1,2,3,4]), MS0([5,6,7,8])]) Traceback (most recent call last): ... @@ -2056,29 +2066,29 @@ def matrix(self, x=None, **kwds): Check that :trac:`13302` is fixed:: - sage: MatrixSpace(Qp(3),1,1)([Qp(3).zero()]) + sage: MatrixSpace(Qp(3), 1,1)([Qp(3).zero()]) # optional - sage.rings.padics [0] - sage: MatrixSpace(Qp(3),1,1)([Qp(3)(4/3)]) + sage: MatrixSpace(Qp(3), 1,1)([Qp(3)(4/3)]) # optional - sage.rings.padics [3^-1 + 1 + O(3^19)] One-rowed matrices over combinatorial free modules used to break the constructor (:trac:`17124`). Check that this is fixed:: - sage: Sym = SymmetricFunctions(ZZ) - sage: h = Sym.h() - sage: MatrixSpace(h,1,1)([h[1]]) + sage: Sym = SymmetricFunctions(ZZ) # optional - sage.combinat + sage: h = Sym.h() # optional - sage.combinat + sage: MatrixSpace(h, 1,1)([h[1]]) # optional - sage.combinat [h[1]] - sage: MatrixSpace(h,2,1)([h[1], h[2]]) + sage: MatrixSpace(h, 2,1)([h[1], h[2]]) # optional - sage.combinat [h[1]] [h[2]] Converting sparse to dense matrices used to be too slow (:trac:`20470`). Check that this is fixed:: - sage: m = identity_matrix(GF(2), 2000, sparse=True) - sage: MS = MatrixSpace(GF(2), 2000, sparse=False) - sage: md = MS(m) # used to be slow - sage: md.parent() is MS + sage: m = identity_matrix(GF(2), 2000, sparse=True) # optional - sage.rings.finite_rings + sage: MS = MatrixSpace(GF(2), 2000, sparse=False) # optional - sage.rings.finite_rings + sage: md = MS(m) # used to be slow # optional - sage.rings.finite_rings + sage: md.parent() is MS # optional - sage.rings.finite_rings True """ return self(x, **kwds) @@ -2091,12 +2101,12 @@ def matrix_space(self, nrows=None, ncols=None, sparse=False): EXAMPLES:: - sage: M = Mat(GF(7),100,200) - sage: M.matrix_space(5000) + sage: M = Mat(GF(7), 100, 200) # optional - sage.rings.finite_rings + sage: M.matrix_space(5000) # optional - sage.rings.finite_rings Full MatrixSpace of 5000 by 200 dense matrices over Finite Field of size 7 - sage: M.matrix_space(ncols=5000) + sage: M.matrix_space(ncols=5000) # optional - sage.rings.finite_rings Full MatrixSpace of 100 by 5000 dense matrices over Finite Field of size 7 - sage: M.matrix_space(sparse=True) + sage: M.matrix_space(sparse=True) # optional - sage.rings.finite_rings Full MatrixSpace of 100 by 200 sparse matrices over Finite Field of size 7 """ if nrows is None: @@ -2112,7 +2122,7 @@ def ncols(self): EXAMPLES:: - sage: M = Mat(ZZ['x'],200000,500000,sparse=True) + sage: M = Mat(ZZ['x'], 200000, 500000, sparse=True) sage: M.ncols() 500000 """ @@ -2124,7 +2134,7 @@ def nrows(self): EXAMPLES:: - sage: M = Mat(ZZ,200000,500000) + sage: M = Mat(ZZ, 200000, 500000) sage: M.nrows() 200000 """ @@ -2156,7 +2166,7 @@ def column_space(self): EXAMPLES:: - sage: M = Mat(GF(9,'a'),20,5,sparse=True); M.column_space() + sage: M = Mat(GF(9,'a'), 20, 5, sparse=True); M.column_space() # optional - sage.rings.finite_rings Sparse vector space of dimension 20 over Finite Field in a of size 3^2 """ try: @@ -2215,8 +2225,8 @@ def random_element(self, density=None, *args, **kwds): sage: M = Mat(QQ, 3, sparse=True).random_element() sage: TestSuite(M).run() - sage: M = Mat(GF(9,'a'), 3, sparse=True).random_element() - sage: TestSuite(M).run() + sage: M = Mat(GF(9,'a'), 3, sparse=True).random_element() # optional - sage.rings.finite_rings + sage: TestSuite(M).run() # optional - sage.rings.finite_rings """ Z = self.zero_matrix().__copy__() if density is None: @@ -2248,8 +2258,8 @@ def _an_element_(self): Check that this works for large matrices and that it returns a matrix which is not too trivial:: - sage: M = MatrixSpace(GF(2), 100, 100).an_element() - sage: M.rank() >= 2 + sage: M = MatrixSpace(GF(2), 100, 100).an_element() # optional - sage.rings.finite_rings + sage: M.rank() >= 2 # optional - sage.rings.finite_rings True Check that this works for sparse matrices:: @@ -2313,8 +2323,8 @@ def some_elements(self): [ 1/2 -1/2 2] [1 0 0] [0 1 0] [0 0 1] [0 0 0] [0 0 0] [0 0 0] [ -2 0 1], [0 0 0], [0 0 0], [0 0 0], [1 0 0], [0 1 0], [0 0 1] ) - sage: M = MatrixSpace(SR, 2, 2) - sage: tuple(M.some_elements()) + sage: M = MatrixSpace(SR, 2, 2) # optional - sage.symbolic + sage: tuple(M.some_elements()) # optional - sage.symbolic ( [some_variable some_variable] [1 0] [0 1] [0 0] [0 0] [some_variable some_variable], [0 0], [0 0], [1 0], [0 1] @@ -2330,12 +2340,12 @@ def _magma_init_(self, magma): :: - sage: magma(MatrixSpace(QQ,3)) # optional - magma + sage: magma(MatrixSpace(QQ, 3)) # optional - magma Full Matrix Algebra of degree 3 over Rational Field :: - sage: magma(MatrixSpace(Integers(8),2,3)) # optional - magma + sage: magma(MatrixSpace(Integers(8), 2, 3)) # optional - magma Full RMatrixSpace of 2 by 3 matrices over IntegerRing(8) """ K = magma(self.base_ring()) @@ -2349,9 +2359,9 @@ def _polymake_init_(self): EXAMPLES:: - sage: polymake(MatrixSpace(QQ,3)) # optional - jupymake + sage: polymake(MatrixSpace(QQ, 3)) # optional - jupymake Matrix - sage: polymake(MatrixSpace(QuadraticField(5),3)) # optional - jupymake + sage: polymake(MatrixSpace(QuadraticField(5), 3)) # optional - jupymake # optional - sage.rings.number_field Matrix """ from sage.interfaces.polymake import polymake @@ -2456,23 +2466,23 @@ def _test_trivial_matrices_inverse(ring, sparse=True, implementation=None, check sage: from sage.matrix.matrix_space import _test_trivial_matrices_inverse as tinv sage: tinv(ZZ, sparse=True) - sage: tinv(ZZ, sparse=False, implementation='flint') + sage: tinv(ZZ, sparse=False, implementation='flint') # optional - sage.libs.flint sage: tinv(ZZ, sparse=False, implementation='generic') sage: tinv(QQ, sparse=True) - sage: tinv(QQ, sparse=False, implementation='flint') + sage: tinv(QQ, sparse=False, implementation='flint') # optional - sage.libs.flint sage: tinv(QQ, sparse=False, implementation='generic') - sage: tinv(GF(11), sparse=True) - sage: tinv(GF(11), sparse=False) - sage: tinv(GF(2), sparse=True) - sage: tinv(GF(2), sparse=False) - sage: tinv(SR, sparse=True) - sage: tinv(SR, sparse=False) + sage: tinv(GF(11), sparse=True) # optional - sage.rings.finite_rings + sage: tinv(GF(11), sparse=False) # optional - sage.rings.finite_rings + sage: tinv(GF(2), sparse=True) # optional - sage.rings.finite_rings + sage: tinv(GF(2), sparse=False) # optional - sage.rings.finite_rings + sage: tinv(SR, sparse=True) # optional - sage.symbolic + sage: tinv(SR, sparse=False) # optional - sage.symbolic sage: tinv(RDF, sparse=True) sage: tinv(RDF, sparse=False) sage: tinv(CDF, sparse=True) sage: tinv(CDF, sparse=False) - sage: tinv(CyclotomicField(7), sparse=True) - sage: tinv(CyclotomicField(7), sparse=False) + sage: tinv(CyclotomicField(7), sparse=True) # optional - sage.rings.number_field + sage: tinv(CyclotomicField(7), sparse=False) # optional - sage.rings.number_field sage: tinv(QQ['x,y'], sparse=True) sage: tinv(QQ['x,y'], sparse=False) diff --git a/src/sage/matrix/matrix_sparse.pyx b/src/sage/matrix/matrix_sparse.pyx index dcd9c2e1550..905cdf9fc0d 100644 --- a/src/sage/matrix/matrix_sparse.pyx +++ b/src/sage/matrix/matrix_sparse.pyx @@ -1,3 +1,4 @@ + r""" Base class for sparse matrices """ @@ -45,6 +46,7 @@ cdef class Matrix_sparse(matrix.Matrix): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A = matrix(QQ['x,y'], 2, [0,-1,2*x,-2], sparse=True); A [ 0 -1] [2*x -2] @@ -636,13 +638,14 @@ cdef class Matrix_sparse(matrix.Matrix): EXAMPLES:: sage: m = matrix(ZZ, 3, range(9), sparse=True) - sage: phi = ZZ.hom(GF(5)) - sage: m.apply_morphism(phi) + sage: phi = ZZ.hom(GF(5)) # optional - sage.rings.finite_rings + sage: m.apply_morphism(phi) # optional - sage.rings.finite_rings [0 1 2] [3 4 0] [1 2 3] - sage: m.apply_morphism(phi).parent() - Full MatrixSpace of 3 by 3 sparse matrices over Finite Field of size 5 + sage: m.apply_morphism(phi).parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 3 by 3 sparse matrices + over Finite Field of size 5 """ R = phi.codomain() M = sage.matrix.matrix_space.MatrixSpace(R, self._nrows, @@ -671,31 +674,33 @@ cdef class Matrix_sparse(matrix.Matrix): EXAMPLES:: sage: m = matrix(ZZ, 10000, {(1,2): 17}, sparse=True) - sage: k. = GF(9) - sage: f = lambda x: k(x) - sage: n = m.apply_map(f) - sage: n.parent() - Full MatrixSpace of 10000 by 10000 sparse matrices over Finite Field in a of size 3^2 - sage: n[1,2] + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: f = lambda x: k(x) # optional - sage.rings.finite_rings + sage: n = m.apply_map(f) # optional - sage.rings.finite_rings + sage: n.parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 10000 by 10000 sparse matrices + over Finite Field in a of size 3^2 + sage: n[1, 2] # optional - sage.rings.finite_rings 2 An example where the codomain is explicitly specified. :: - sage: n = m.apply_map(lambda x:x%3, GF(3)) - sage: n.parent() - Full MatrixSpace of 10000 by 10000 sparse matrices over Finite Field of size 3 - sage: n[1,2] + sage: n = m.apply_map(lambda x: x%3, GF(3)) # optional - sage.rings.finite_rings + sage: n.parent() # optional - sage.rings.finite_rings + Full MatrixSpace of 10000 by 10000 sparse matrices + over Finite Field of size 3 + sage: n[1, 2] # optional - sage.rings.finite_rings 2 If we did not specify the codomain, the resulting matrix in the above case ends up over `\ZZ` again:: - sage: n = m.apply_map(lambda x:x%3) + sage: n = m.apply_map(lambda x: x%3) sage: n.parent() Full MatrixSpace of 10000 by 10000 sparse matrices over Integer Ring - sage: n[1,2] + sage: n[1, 2] 2 If self is subdivided, the result will be as well:: @@ -806,8 +811,8 @@ cdef class Matrix_sparse(matrix.Matrix): EXAMPLES:: - sage: m = matrix(2, [x^i for i in range(4)], sparse=True) - sage: m._derivative(x) + sage: m = matrix(2, [x^i for i in range(4)], sparse=True) # optional - sage.symbolic + sage: m._derivative(x) # optional - sage.symbolic [ 0 1] [ 2*x 3*x^2] """ @@ -1175,10 +1180,10 @@ cdef class Matrix_sparse(matrix.Matrix): Check that the bug in :trac:`13854` has been fixed:: - sage: A. = FreeAlgebra(QQ, 2) - sage: P. = A.g_algebra(relations={y*x:-x*y}, order = 'lex') - sage: M = Matrix([[x]], sparse=True) - sage: w = vector([y]) + sage: A. = FreeAlgebra(QQ, 2) # optional - sage.combinat + sage: P. = A.g_algebra(relations={y*x: -x*y}, order='lex') # optional - sage.combinat + sage: M = Matrix([[x]], sparse=True) # optional - sage.combinat + sage: w = vector([y]) # optional - sage.combinat doctest:...: UserWarning: You are constructing a free module over a noncommutative ring. Sage does not have a concept of left/right and both sided modules, so be careful. @@ -1189,7 +1194,7 @@ cdef class Matrix_sparse(matrix.Matrix): of left/right and both sided modules, so be careful. It's also not guaranteed that all multiplications are done from the right side. - sage: M*w + sage: M*w # optional - sage.combinat (x*y) """ cdef int i, j diff --git a/src/sage/matrix/operation_table.py b/src/sage/matrix/operation_table.py index 79acaaf8390..c7c655463d4 100644 --- a/src/sage/matrix/operation_table.py +++ b/src/sage/matrix/operation_table.py @@ -81,8 +81,8 @@ class OperationTable(SageObject): In its most basic use, the table needs a structure and an operation:: sage: from sage.matrix.operation_table import OperationTable - sage: G=SymmetricGroup(3) - sage: OperationTable(G, operation=operator.mul) + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: OperationTable(G, operation=operator.mul) # optional - sage.groups * a b c d e f +------------ a| a b c d e f @@ -96,7 +96,7 @@ class OperationTable(SageObject): want:: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(6) + sage: R = Integers(6) sage: OperationTable(R, operation=operator.add) + a b c d e f +------------ @@ -112,8 +112,8 @@ class OperationTable(SageObject): 26 elements. :: sage: from sage.matrix.operation_table import OperationTable - sage: G=DihedralGroup(14) - sage: OperationTable(G, operator.mul, names='letters') + sage: G = DihedralGroup(14) # optional - sage.groups + sage: OperationTable(G, operator.mul, names='letters') # optional - sage.groups * aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb +------------------------------------------------------------------------------------ aa| aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb @@ -149,8 +149,8 @@ class OperationTable(SageObject): zeros to make a common width. :: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(4) - sage: OperationTable(G, operator.mul, names='digits') + sage: G = AlternatingGroup(4) # optional - sage.groups + sage: OperationTable(G, operator.mul, names='digits') # optional - sage.groups * 00 01 02 03 04 05 06 07 08 09 10 11 +------------------------------------ 00| 00 01 02 03 04 05 06 07 08 09 10 11 @@ -171,8 +171,8 @@ class OperationTable(SageObject): of the elements can be used. :: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(3) - sage: OperationTable(G, operator.mul, names='elements') + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: OperationTable(G, operator.mul, names='elements') # optional - sage.groups * () (1,2,3) (1,3,2) +------------------------ ()| () (1,2,3) (1,3,2) @@ -185,15 +185,15 @@ class OperationTable(SageObject): method. :: sage: from sage.matrix.operation_table import OperationTable - sage: G = QuaternionGroup() - sage: T = OperationTable(G, operator.mul) - sage: T.column_keys() + sage: G = QuaternionGroup() # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T.column_keys() # optional - sage.groups ((), (1,2,3,4)(5,6,7,8), ..., (1,8,3,6)(2,7,4,5)) - sage: names=['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] - sage: T.change_names(names=names) - sage: sorted(T.translation().items()) + sage: names=['1', 'I', '-1', '-I', 'J', '-K', '-J', 'K'] # optional - sage.groups + sage: T.change_names(names=names) # optional - sage.groups + sage: sorted(T.translation().items()) # optional - sage.groups [('-1', (1,3)(2,4)(5,7)(6,8)), ..., ('K', (1,8,3,6)(2,7,4,5))] - sage: T + sage: T # optional - sage.groups * 1 I -1 -I J -K -J K +------------------------ 1| 1 I -1 -I J -K -J K @@ -278,10 +278,10 @@ class OperationTable(SageObject): odd. The LaTeX version works much better. :: sage: from sage.matrix.operation_table import OperationTable - sage: L=FiniteSemigroups().example(()) + sage: L = FiniteSemigroups().example(()) sage: L An example of a finite semigroup: the left regular band generated by () - sage: T=OperationTable(L, operation=operator.mul) + sage: T = OperationTable(L, operation=operator.mul) sage: T * + @@ -302,11 +302,11 @@ class OperationTable(SageObject): Here we demonstrate the proper use first:: sage: from sage.matrix.operation_table import OperationTable - sage: H=CyclicPermutationGroup(4) - sage: H.list() + sage: H = CyclicPermutationGroup(4) # optional - sage.groups + sage: H.list() # optional - sage.groups [(), (1,2,3,4), (1,3)(2,4), (1,4,3,2)] - sage: elts = ['()', '(1,3)(2,4)'] - sage: OperationTable(H, operator.mul, elements=elts) + sage: elts = ['()', '(1,3)(2,4)'] # optional - sage.groups + sage: OperationTable(H, operator.mul, elements=elts) # optional - sage.groups * a b +---- a| a b @@ -315,11 +315,11 @@ class OperationTable(SageObject): This can be rewritten so as to pass the actual elements of the group ``H``, using a simple ``for`` loop:: - sage: L = H.list() #list of elements of the group H - sage: elts = [L[i] for i in {0, 2}] - sage: elts + sage: L = H.list() #list of elements of the group H # optional - sage.groups + sage: elts = [L[i] for i in {0, 2}] # optional - sage.groups + sage: elts # optional - sage.groups [(), (1,3)(2,4)] - sage: OperationTable(H, operator.mul, elements=elts) + sage: OperationTable(H, operator.mul, elements=elts) # optional - sage.groups * a b +---- a| a b @@ -327,31 +327,31 @@ class OperationTable(SageObject): Here are a couple of improper uses:: - sage: elts.append(5) - sage: OperationTable(H, operator.mul, elements=elts) + sage: elts.append(5) # optional - sage.groups + sage: OperationTable(H, operator.mul, elements=elts) # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to coerce 5 into Cyclic group of order 4 as a permutation group - sage: elts[2] = '(1,3,2,4)' - sage: OperationTable(H, operator.mul, elements=elts) + sage: elts[2] = '(1,3,2,4)' # optional - sage.groups + sage: OperationTable(H, operator.mul, elements=elts) # optional - sage.groups Traceback (most recent call last): ... TypeError: unable to coerce (1,3,2,4) into Cyclic group of order 4 as a permutation group - sage: elts[2] = '(1,2,3,4)' - sage: OperationTable(H, operator.mul, elements=elts) + sage: elts[2] = '(1,2,3,4)' # optional - sage.groups + sage: OperationTable(H, operator.mul, elements=elts) # optional - sage.groups Traceback (most recent call last): ... ValueError: (1,3)(2,4)*(1,2,3,4)=(1,4,3,2), and so the set is not closed Unusable functions should be recognized as such:: - sage: H=CyclicPermutationGroup(4) - sage: OperationTable(H, operator.add) + sage: H = CyclicPermutationGroup(4) # optional - sage.groups + sage: OperationTable(H, operator.add) # optional - sage.groups Traceback (most recent call last): ... TypeError: elements () and () of Cyclic group of order 4 as a permutation group are incompatible with operation: - sage: from operator import xor - sage: OperationTable(H, xor) + sage: from operator import xor # optional - sage.groups + sage: OperationTable(H, xor) # optional - sage.groups Traceback (most recent call last): ... TypeError: elements () and () of Cyclic group of order 4 as a permutation group are incompatible with operation: @@ -359,9 +359,9 @@ class OperationTable(SageObject): We construct the multiplication table for a finite finitely presented group, where there is no normalization done when computing the hash:: - sage: GU. = FreeGroup() - sage: gr0 = GU / (s^(-2)*t*s*t, t^(-2)*s*t*s, s*t*s*t) - sage: gr0.multiplication_table() + sage: GU. = FreeGroup() # optional - sage.groups + sage: gr0 = GU / (s^(-2)*t*s*t, t^(-2)*s*t*s, s*t*s*t) # optional - sage.groups + sage: gr0.multiplication_table() # optional - sage.groups * a b c d e f g h i j k l +------------------------ a| a b c d e f g h i j k l @@ -388,9 +388,9 @@ def __init__(self, S, operation, names='letters', elements=None): TESTS:: sage: from sage.matrix.operation_table import OperationTable - sage: G=SymmetricGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: TestSuite(T).run() + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: TestSuite(T).run() # optional - sage.groups """ # Determine the elements of S, specified or not # If elements are given, we check if they are all in S @@ -510,14 +510,14 @@ def _name_maker(self, names): the nature of the output here. :: sage: from sage.matrix.operation_table import OperationTable - sage: G=SymmetricGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: w, l, d = T._name_maker('letters') - sage: w + sage: G = SymmetricGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: w, l, d = T._name_maker('letters') # optional - sage.groups + sage: w # optional - sage.groups 1 - sage: l[0] + sage: l[0] # optional - sage.groups 'a' - sage: d['a'] + sage: d['a'] # optional - sage.groups () TESTS: @@ -527,17 +527,17 @@ def _name_maker(self, names): methods that rely on this one. :: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: T._name_maker(['x']) + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T._name_maker(['x']) # optional - sage.groups Traceback (most recent call last): ... ValueError: list of element names must be the same size as the set, 1 != 3 - sage: T._name_maker(['x', 'y', 4]) + sage: T._name_maker(['x', 'y', 4]) # optional - sage.groups Traceback (most recent call last): ... ValueError: list of element names must only contain strings, not 4 - sage: T._name_maker('blatzo') + sage: T._name_maker('blatzo') # optional - sage.groups Traceback (most recent call last): ... ValueError: element names must be a list, or one of the keywords: 'letters', 'digits', 'elements' @@ -608,31 +608,31 @@ def __getitem__(self, pair): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: G=DiCyclicGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: T.column_keys() + sage: G = DiCyclicGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T.column_keys() # optional - sage.groups ((), (5,6,7), ..., (1,4,2,3)(5,7)) - sage: T[G('(1,2)(3,4)(5,6,7)'), G('(1,3,2,4)(5,7)')] + sage: T[G('(1,2)(3,4)(5,6,7)'), G('(1,3,2,4)(5,7)')] # optional - sage.groups (1,4,2,3)(5,6) TESTS:: sage: from sage.matrix.operation_table import OperationTable - sage: G = DiCyclicGroup(3) - sage: T = OperationTable(G, operator.mul) - sage: T[G('(1,2)(3,4)(5,6,7)')] + sage: G = DiCyclicGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T[G('(1,2)(3,4)(5,6,7)')] # optional - sage.groups Traceback (most recent call last): ... TypeError: indexing into an operation table requires exactly two elements - sage: T[G('(1,2)(3,4)(5,6,7)'), G('(1,3,2,4)(5,7)'), G('(1,3,2,4)(5,7)')] + sage: T[G('(1,2)(3,4)(5,6,7)'), G('(1,3,2,4)(5,7)'), G('(1,3,2,4)(5,7)')] # optional - sage.groups Traceback (most recent call last): ... TypeError: indexing into an operation table requires exactly two elements - sage: T[2, 3] + sage: T[2, 3] # optional - sage.groups Traceback (most recent call last): ... IndexError: invalid indices of operation table: (2, 3) - sage: T['(1,512)', '(1,3,2,4)(5,7)'] + sage: T['(1,512)', '(1,3,2,4)(5,7)'] # optional - sage.groups Traceback (most recent call last): ... IndexError: invalid indices of operation table: ((1,512), (1,3,2,4)(5,7)) @@ -663,13 +663,13 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: G=CyclicPermutationGroup(6) - sage: H=CyclicPermutationGroup(3) - sage: P=OperationTable(G, operator.mul) - sage: Q=OperationTable(G, operator.mul) - sage: R=OperationTable(H, operator.mul) - sage: S=OperationTable(G, operator.truediv) - sage: P == P, P == Q, P == R, P == S + sage: G = CyclicPermutationGroup(6) # optional - sage.groups + sage: H = CyclicPermutationGroup(3) # optional - sage.groups + sage: P = OperationTable(G, operator.mul) # optional - sage.groups + sage: Q = OperationTable(G, operator.mul) # optional - sage.groups + sage: R = OperationTable(H, operator.mul) # optional - sage.groups + sage: S = OperationTable(G, operator.truediv) # optional - sage.groups + sage: P == P, P == Q, P == R, P == S # optional - sage.groups (True, True, False, False) """ return (self._elts == other._elts) and (self._operation == other._operation) @@ -681,13 +681,13 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: G=CyclicPermutationGroup(6) - sage: H=CyclicPermutationGroup(3) - sage: P=OperationTable(G, operator.mul) - sage: Q=OperationTable(G, operator.mul) - sage: R=OperationTable(H, operator.mul) - sage: S=OperationTable(G, operator.truediv) - sage: P != P, P != Q, P != R, P != S + sage: G = CyclicPermutationGroup(6) # optional - sage.groups + sage: H = CyclicPermutationGroup(3) # optional - sage.groups + sage: P = OperationTable(G, operator.mul) # optional - sage.groups + sage: Q = OperationTable(G, operator.mul) # optional - sage.groups + sage: R = OperationTable(H, operator.mul) # optional - sage.groups + sage: S = OperationTable(G, operator.truediv) # optional - sage.groups + sage: P != P, P != Q, P != R, P != S # optional - sage.groups (False, False, True, True) """ return not self == other @@ -699,8 +699,8 @@ def _repr_(self): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(5) - sage: T=OperationTable(R, operation=operator.add) + sage: R = Integers(5) + sage: T = OperationTable(R, operation=operator.add) sage: print(T._repr_()) + a b c d e +---------- @@ -725,32 +725,32 @@ def set_print_symbols(self, ascii, latex): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: T.set_print_symbols('@', '\\times') - sage: T + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T.set_print_symbols('@', '\\times') # optional - sage.groups + sage: T # optional - sage.groups @ a b c +------ a| a b c b| b c a c| c a b - sage: T._latex_() + sage: T._latex_() # optional - sage.groups '{\\setlength{\\arraycolsep}{2ex}\n\\begin{array}{r|*{3}{r}}\n\\multicolumn{1}{c|}{\\times}&a&b&c\\\\\\hline\n{}a&a&b&c\\\\\n{}b&b&c&a\\\\\n{}c&c&a&b\\\\\n\\end{array}}' TESTS:: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: T.set_print_symbols('@', 5) + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T.set_print_symbols('@', 5) # optional - sage.groups Traceback (most recent call last): ... ValueError: LaTeX symbol must be a string, not 5 - sage: T.set_print_symbols('@x@', '\\times') + sage: T.set_print_symbols('@x@', '\\times') # optional - sage.groups Traceback (most recent call last): ... ValueError: ASCII symbol should be a single character, not @x@ - sage: T.set_print_symbols(5, '\\times') + sage: T.set_print_symbols(5, '\\times') # optional - sage.groups Traceback (most recent call last): ... ValueError: ASCII symbol should be a single character, not 5 @@ -781,9 +781,9 @@ def column_keys(self): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(3) - sage: T=OperationTable(G, operator.mul) - sage: T.column_keys() + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T.column_keys() # optional - sage.groups ((), (1,2,3), (1,3,2)) """ return self._elts @@ -807,9 +807,9 @@ def translation(self): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: G=AlternatingGroup(3) - sage: T=OperationTable(G, operator.mul, names=['p','q','r']) - sage: T.translation() + sage: G = AlternatingGroup(3) # optional - sage.groups + sage: T = OperationTable(G, operator.mul, names=['p','q','r']) # optional - sage.groups + sage: T.translation() # optional - sage.groups {'p': (), 'q': (1,2,3), 'r': (1,3,2)} """ return self._name_dict @@ -828,9 +828,9 @@ def table(self): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: C=CyclicPermutationGroup(3) - sage: T=OperationTable(C, operator.mul) - sage: T.table() + sage: C = CyclicPermutationGroup(3) # optional - sage.groups + sage: T=OperationTable(C, operator.mul) # optional - sage.groups + sage: T.table() # optional - sage.groups [[0, 1, 2], [1, 2, 0], [2, 0, 1]] """ return self._table @@ -870,46 +870,46 @@ def change_names(self, names): operation table uses the same routine. :: sage: from sage.matrix.operation_table import OperationTable - sage: D=DihedralGroup(2) - sage: T=OperationTable(D, operator.mul) - sage: T + sage: D = DihedralGroup(2) # optional - sage.groups + sage: T = OperationTable(D, operator.mul) # optional - sage.groups + sage: T # optional - sage.groups * a b c d +-------- a| a b c d b| b a d c c| c d a b d| d c b a - sage: T.translation()['c'] + sage: T.translation()['c'] # optional - sage.groups (1,2) - sage: T.change_names('digits') - sage: T + sage: T.change_names('digits') # optional - sage.groups + sage: T # optional - sage.groups * 0 1 2 3 +-------- 0| 0 1 2 3 1| 1 0 3 2 2| 2 3 0 1 3| 3 2 1 0 - sage: T.translation()['2'] + sage: T.translation()['2'] # optional - sage.groups (1,2) - sage: T.change_names('elements') - sage: T + sage: T.change_names('elements') # optional - sage.groups + sage: T # optional - sage.groups * () (3,4) (1,2) (1,2)(3,4) +-------------------------------------------- ()| () (3,4) (1,2) (1,2)(3,4) (3,4)| (3,4) () (1,2)(3,4) (1,2) (1,2)| (1,2) (1,2)(3,4) () (3,4) (1,2)(3,4)| (1,2)(3,4) (1,2) (3,4) () - sage: T.translation()['(1,2)'] + sage: T.translation()['(1,2)'] # optional - sage.groups (1,2) - sage: T.change_names(['w', 'x', 'y', 'z']) - sage: T + sage: T.change_names(['w', 'x', 'y', 'z']) # optional - sage.groups + sage: T # optional - sage.groups * w x y z +-------- w| w x y z x| x w z y y| y z w x z| z y x w - sage: T.translation()['y'] + sage: T.translation()['y'] # optional - sage.groups (1,2) """ self._width, self._names, self._name_dict = self._name_maker(names) @@ -927,16 +927,16 @@ def matrix_of_variables(self): ``cayley_table()`` method for permutation groups. :: sage: from sage.matrix.operation_table import OperationTable - sage: G = PermutationGroup(['(1,2,3)', '(2,3)']) - sage: T = OperationTable(G, operator.mul) - sage: T.matrix_of_variables() + sage: G = PermutationGroup(['(1,2,3)', '(2,3)']) # optional - sage.groups + sage: T = OperationTable(G, operator.mul) # optional - sage.groups + sage: T.matrix_of_variables() # optional - sage.groups [x0 x1 x2 x3 x4 x5] [x1 x0 x3 x2 x5 x4] [x2 x4 x0 x5 x1 x3] [x3 x5 x1 x4 x0 x2] [x4 x2 x5 x0 x3 x1] [x5 x3 x4 x1 x2 x0] - sage: T.column_keys()[2]*T.column_keys()[2] == T.column_keys()[0] + sage: T.column_keys()[2]*T.column_keys()[2] == T.column_keys()[0] # optional - sage.groups True """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -1043,8 +1043,8 @@ def _ascii_table(self): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(5) - sage: T=OperationTable(R, operator.add) + sage: R = Integers(5) + sage: T = OperationTable(R, operator.add) sage: print(T._ascii_table()) + a b c d e +---------- @@ -1058,8 +1058,8 @@ def _ascii_table(self): strings used to represent elements. :: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(10) - sage: T=OperationTable(R, operator.mul, names='digits') + sage: R = Integers(10) + sage: T = OperationTable(R, operator.mul, names='digits') sage: print(T._ascii_table()) * 0 1 2 3 4 5 6 7 8 9 +-------------------- @@ -1077,8 +1077,8 @@ def _ascii_table(self): :: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(11) - sage: T=OperationTable(R, operator.mul, names='digits') + sage: R = Integers(11) + sage: T = OperationTable(R, operator.mul, names='digits') sage: print(T._ascii_table()) * 00 01 02 03 04 05 06 07 08 09 10 +--------------------------------- @@ -1097,8 +1097,8 @@ def _ascii_table(self): :: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(4) - sage: T=OperationTable(R, operator.mul, names=['x','y','wwww', 'z']) + sage: R = Integers(4) + sage: T = OperationTable(R, operator.mul, names=['x','y','wwww', 'z']) sage: print(T._ascii_table()) * x y wwww z +-------------------- @@ -1135,8 +1135,8 @@ def _latex_(self): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: R=Integers(2) - sage: T=OperationTable(R, operation=operator.mul) + sage: R = Integers(2) + sage: T = OperationTable(R, operation=operator.mul) sage: T._latex_() '{\\setlength{\\arraycolsep}{2ex}\n\\begin{array}{r|*{2}{r}}\n\\multicolumn{1}{c|}{\\ast}&a&b\\\\\\hline\n{}a&a&a\\\\\n{}b&a&b\\\\\n\\end{array}}' """ diff --git a/src/sage/matrix/special.py b/src/sage/matrix/special.py index 41a48c0e99f..92958d84a1f 100644 --- a/src/sage/matrix/special.py +++ b/src/sage/matrix/special.py @@ -7,7 +7,7 @@ For example, here is a circulant matrix of order five:: - sage: matrix.circulant(SR.var('a b c d e')) + sage: matrix.circulant(SR.var('a b c d e')) # optional - sage.symbolic [a b c d e] [e a b c d] [d e a b c] @@ -748,36 +748,36 @@ def diagonal_matrix(arg0=None, arg1=None, arg2=None, sparse=True): NumPy arrays may be used as input. :: - sage: import numpy - sage: entries = numpy.array([1.2, 5.6]); entries + sage: import numpy # optional - numpy + sage: entries = numpy.array([1.2, 5.6]); entries # optional - numpy array([1.2, 5.6]) - sage: A = diagonal_matrix(3, entries); A + sage: A = diagonal_matrix(3, entries); A # optional - numpy [1.2 0.0 0.0] [0.0 5.6 0.0] [0.0 0.0 0.0] - sage: A.parent() + sage: A.parent() # optional - numpy Full MatrixSpace of 3 by 3 sparse matrices over Real Double Field sage: j = complex(0,1) - sage: entries = numpy.array([2.0+j, 8.1, 3.4+2.6*j]); entries + sage: entries = numpy.array([2.0+j, 8.1, 3.4+2.6*j]); entries # optional - numpy array([2. +1.j , 8.1+0.j , 3.4+2.6j]) - sage: A = diagonal_matrix(entries); A + sage: A = diagonal_matrix(entries); A # optional - numpy [2.0 + 1.0*I 0.0 0.0] [ 0.0 8.1 0.0] [ 0.0 0.0 3.4 + 2.6*I] - sage: A.parent() + sage: A.parent() # optional - numpy Full MatrixSpace of 3 by 3 sparse matrices over Complex Double Field - sage: entries = numpy.array([4, 5, 6]) - sage: A = diagonal_matrix(entries); A + sage: entries = numpy.array([4, 5, 6]) # optional - numpy + sage: A = diagonal_matrix(entries); A # optional - numpy [4 0 0] [0 5 0] [0 0 6] - sage: A.parent() + sage: A.parent() # optional - numpy Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring - sage: entries = numpy.array([4.1, 5.2, 6.3]) - sage: A = diagonal_matrix(ZZ, entries); A + sage: entries = numpy.array([4.1, 5.2, 6.3]) # optional - numpy + sage: A = diagonal_matrix(ZZ, entries); A # optional - numpy Traceback (most recent call last): ... TypeError: unable to convert 4.1 to an element of Integer Ring @@ -3478,7 +3478,7 @@ def vandermonde(v, ring=None): A Vandermonde matrix of order three over the symbolic ring:: - sage: matrix.vandermonde(SR.var(['x0', 'x1', 'x2'])) + sage: matrix.vandermonde(SR.var(['x0', 'x1', 'x2'])) # optional - sage.symbolic [ 1 x0 x0^2] [ 1 x1 x1^2] [ 1 x2 x2^2] @@ -3565,7 +3565,7 @@ def hankel(c, r=None, ring=None): A Hankel matrix with symbolic entries:: - sage: matrix.hankel(SR.var('a, b, c, d, e')) + sage: matrix.hankel(SR.var('a, b, c, d, e')) # optional - sage.symbolic [a b c d e] [b c d e 0] [c d e 0 0] @@ -3574,7 +3574,7 @@ def hankel(c, r=None, ring=None): We can also pass the elements of the last row, starting at the second column:: - sage: matrix.hankel(SR.var('a, b, c, d, e'), SR.var('f, g, h, i')) + sage: matrix.hankel(SR.var('a, b, c, d, e'), SR.var('f, g, h, i')) # optional - sage.symbolic [a b c d e] [b c d e f] [c d e f g] diff --git a/src/sage/matrix/symplectic_basis.py b/src/sage/matrix/symplectic_basis.py index 4caee7a6da6..4a55deee93d 100644 --- a/src/sage/matrix/symplectic_basis.py +++ b/src/sage/matrix/symplectic_basis.py @@ -188,7 +188,12 @@ def symplectic_basis_over_field(M): An example over a finite field:: - sage: E = matrix(GF(7), 8, 8, [0, -1/2, -2, 1/2, 2, 0, -2, 1, 1/2, 0, -1, -3, 0, 2, 5/2, -3, 2, 1, 0, 3/2, -1, 0, -1, -2, -1/2, 3, -3/2, 0, 1, 3/2, -1/2, -1/2, -2, 0, 1, -1, 0, 0, 1, -1, 0, -2, 0, -3/2, 0, 0, 1/2, -2, 2, -5/2, 1, 1/2, -1, -1/2, 0, -1, -1, 3, 2, 1/2, 1, 2, 1, 0]); E + sage: E = matrix(GF(7), 8, 8, # optional - sage.rings.finite_rings + ....: [0, -1/2, -2, 1/2, 2, 0, -2, 1, 1/2, 0, -1, -3, 0, 2, 5/2, + ....: -3, 2, 1, 0, 3/2, -1, 0, -1, -2, -1/2, 3, -3/2, 0, 1, 3/2, + ....: -1/2, -1/2, -2, 0, 1, -1, 0, 0, 1, -1, 0, -2, 0, -3/2, 0, + ....: 0, 1/2, -2, 2, -5/2, 1, 1/2, -1, -1/2, 0, -1, -1, 3, 2, + ....: 1/2, 1, 2, 1, 0]); E [0 3 5 4 2 0 5 1] [4 0 6 4 0 2 6 4] [2 1 0 5 6 0 6 5] @@ -197,7 +202,7 @@ def symplectic_basis_over_field(M): [0 5 0 2 0 0 4 5] [2 1 1 4 6 3 0 6] [6 3 2 4 1 2 1 0] - sage: F, C = symplectic_basis_over_field(E); F + sage: F, C = symplectic_basis_over_field(E); F # optional - sage.rings.finite_rings [0 0 0 0 1 0 0 0] [0 0 0 0 0 1 0 0] [0 0 0 0 0 0 1 0] @@ -206,12 +211,16 @@ def symplectic_basis_over_field(M): [0 6 0 0 0 0 0 0] [0 0 6 0 0 0 0 0] [0 0 0 6 0 0 0 0] - sage: F == C * E * C.transpose() + sage: F == C * E * C.transpose() # optional - sage.rings.finite_rings True The tricky case of characteristic 2:: - sage: E = matrix(GF(2), 8, 8, [0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0]); E + sage: E = matrix(GF(2), 8, 8, # optional - sage.rings.finite_rings + ....: [0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + ....: 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, + ....: 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, + ....: 0, 1, 0, 0]); E [0 0 1 1 0 1 0 1] [0 0 0 0 0 0 0 0] [1 0 0 0 0 0 1 1] @@ -220,7 +229,7 @@ def symplectic_basis_over_field(M): [1 0 0 0 1 0 1 1] [0 0 1 0 1 1 0 0] [1 0 1 1 0 1 0 0] - sage: F, C = symplectic_basis_over_field(E); F + sage: F, C = symplectic_basis_over_field(E); F # optional - sage.rings.finite_rings [0 0 0 1 0 0 0 0] [0 0 0 0 1 0 0 0] [0 0 0 0 0 1 0 0] @@ -229,7 +238,7 @@ def symplectic_basis_over_field(M): [0 0 1 0 0 0 0 0] [0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0] - sage: F == C * E * C.transpose() + sage: F == C * E * C.transpose() # optional - sage.rings.finite_rings True An inexact example:: @@ -243,7 +252,7 @@ def symplectic_basis_over_field(M): [ 1.14718543053828 -0.278305070958958 0.0840205427053993 0.356957405431611 0.836072521423577 0.000000000000000 0.214878541347751 -1.20221688928379] [ -1.03076138152950 0.0781320488361574 -1.28202592892333 0.699960114607661 -0.450137632758469 -0.214878541347751 0.000000000000000 0.785074452163036] [ 0.227739521708484 0.496003664217833 0.512563654267693 -0.0260496330859998 0.696145287292091 1.20221688928379 -0.785074452163036 0.000000000000000] - sage: F, C = symplectic_basis_over_field(E); F # random + sage: F, C = symplectic_basis_over_field(E); F # random [ 0.000000000000000 0.000000000000000 2.22044604925031e-16 -2.22044604925031e-16 1.00000000000000 0.000000000000000 0.000000000000000 -3.33066907387547e-16] [ 0.000000000000000 8.14814392305203e-17 -1.66533453693773e-16 -1.11022302462516e-16 0.000000000000000 1.00000000000000 -1.11022302462516e-16 0.000000000000000] [-5.27829526256056e-16 -2.40004077757759e-16 1.28373418199470e-16 -1.11022302462516e-16 0.000000000000000 -3.15483812822081e-16 1.00000000000000 -4.44089209850063e-16] diff --git a/src/sage/matrix/tests.py b/src/sage/matrix/tests.py index 21b7920307a..8a556b2fba8 100644 --- a/src/sage/matrix/tests.py +++ b/src/sage/matrix/tests.py @@ -11,7 +11,7 @@ Vector space of degree 1 and dimension 1 over Rational Field Basis matrix: [1] - sage: matrix(GF(7),1,0).kernel() + sage: matrix(GF(7), 1, 0).kernel() # optional - sage.rings.finite_rings Vector space of degree 1 and dimension 1 over Finite Field of size 7 Basis matrix: [1] @@ -28,7 +28,7 @@ Vector space of degree 0 and dimension 0 over Rational Field Basis matrix: [] - sage: matrix(GF(7),0,1).kernel() + sage: matrix(GF(7), 0, 1).kernel() # optional - sage.rings.finite_rings Vector space of degree 0 and dimension 0 over Finite Field of size 7 Basis matrix: [] @@ -45,7 +45,7 @@ sage: matrix(QQ, 2, 2, [1, 1, 1, 1]) / (1/2) [2 2] [2 2] - sage: matrix(QQ['x,y'], 2, 2, [1, 1, 1, 1]) / x + sage: matrix(QQ['x,y'], 2, 2, [1, 1, 1, 1]) / x # optional - sage.symbolic [1/x 1/x] [1/x 1/x] sage: A = matrix(CC, 2, 2, [1, 1, 1, 1]) / I; A diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index 8555ff67152..89dbb8e5e56 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -473,8 +473,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted(M.groundset()) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted(M.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g'] """ return self._groundset @@ -495,17 +495,17 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: type(M.groundset()) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: type(M.groundset()) # optional - sage.libs.pari <... 'frozenset'> - sage: type(M.groundset_list()) + sage: type(M.groundset_list()) # optional - sage.libs.pari <... 'list'> - sage: sorted(M.groundset_list()) + sage: sorted(M.groundset_list()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: E = M.groundset_list() - sage: E.remove('a') - sage: sorted(M.groundset_list()) + sage: E = M.groundset_list() # optional - sage.libs.pari + sage: E.remove('a') # optional - sage.libs.pari + sage: sorted(M.groundset_list()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g'] """ return list(self._E) @@ -538,10 +538,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.full_rank() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.full_rank() # optional - sage.libs.pari 3 - sage: M.dual().full_rank() + sage: M.dual().full_rank() # optional - sage.libs.pari 4 """ return self._matroid_rank @@ -564,10 +564,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.full_corank() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.full_corank() # optional - sage.libs.pari 4 - sage: M.dual().full_corank() + sage: M.dual().full_corank() # optional - sage.libs.pari 3 """ return self._groundset_size - self._matroid_rank @@ -592,12 +592,12 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted(M.basis()) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted(M.basis()) # optional - sage.libs.pari ['a', 'b', 'c'] - sage: M.rank('cd') + sage: M.rank('cd') # optional - sage.libs.pari 2 - sage: sorted(M.basis()) + sage: sorted(M.basis()) # optional - sage.libs.pari ['a', 'c', 'd'] """ @@ -750,8 +750,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.P8() - sage: sorted(M._fundamental_circuit('abcd', 'e')) + sage: M = matroids.named_matroids.P8() # optional - sage.libs.pari + sage: sorted(M._fundamental_circuit('abcd', 'e')) # optional - sage.libs.pari ['a', 'b', 'c', 'e'] """ self.__pack(self._input, B) @@ -906,8 +906,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.P8() - sage: sorted(M._fundamental_cocircuit('efgh', 'e')) + sage: M = matroids.named_matroids.P8() # optional - sage.libs.pari + sage: sorted(M._fundamental_cocircuit('efgh', 'e')) # optional - sage.libs.pari ['b', 'c', 'd', 'e'] """ self.__pack(self._input, B) @@ -1255,8 +1255,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8() - sage: M.f_vector() + sage: M = matroids.named_matroids.S8() # optional - sage.libs.pari + sage: M.f_vector() # optional - sage.libs.pari [1, 8, 22, 14, 1] """ @@ -1321,14 +1321,14 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8() - sage: M.f_vector() + sage: M = matroids.named_matroids.S8() # optional - sage.libs.pari + sage: M.f_vector() # optional - sage.libs.pari [1, 8, 22, 14, 1] - sage: len(M.flats(2)) + sage: len(M.flats(2)) # optional - sage.libs.pari 22 - sage: len(M.flats(8)) + sage: len(M.flats(8)) # optional - sage.libs.pari 0 - sage: len(M.flats(4)) + sage: len(M.flats(4)) # optional - sage.libs.pari 1 """ cdef bitset_t *flats @@ -1396,14 +1396,14 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8().dual() - sage: M.f_vector() + sage: M = matroids.named_matroids.S8().dual() # optional - sage.libs.pari + sage: M.f_vector() # optional - sage.libs.pari [1, 8, 22, 14, 1] - sage: len(M.coflats(2)) + sage: len(M.coflats(2)) # optional - sage.libs.pari 22 - sage: len(M.coflats(8)) + sage: len(M.coflats(8)) # optional - sage.libs.pari 0 - sage: len(M.coflats(4)) + sage: len(M.coflats(4)) # optional - sage.libs.pari 1 """ cdef bitset_t *coflats @@ -1529,8 +1529,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: M.bases_count() + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: M.bases_count() # optional - sage.libs.pari 184 """ if self._bcount is not None: @@ -1556,9 +1556,9 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: I = M.independent_sets() - sage: len(I) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: I = M.independent_sets() # optional - sage.libs.pari + sage: len(I) # optional - sage.libs.pari 57 """ cdef bitset_t *I @@ -1617,10 +1617,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: M.bases_count() + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: M.bases_count() # optional - sage.libs.pari 184 - sage: [len(M.independent_r_sets(r)) for r in range(M.full_rank() + 1)] + sage: [len(M.independent_r_sets(r)) for r in range(M.full_rank() + 1)] # optional - sage.libs.pari [1, 10, 45, 120, 201, 184] """ @@ -1649,10 +1649,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: M.bases_count() + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: M.bases_count() # optional - sage.libs.pari 184 - sage: len([B for B in M.bases()]) + sage: len([B for B in M.bases()]) # optional - sage.libs.pari 184 """ return self.independent_r_sets(self.full_rank()) @@ -1671,10 +1671,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: len(M.nonbases()) + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: len(M.nonbases()) # optional - sage.libs.pari 68 - sage: [len(M.dependent_r_sets(r)) for r in range(M.full_rank() + 1)] + sage: [len(M.dependent_r_sets(r)) for r in range(M.full_rank() + 1)] # optional - sage.libs.pari [0, 0, 0, 0, 9, 68] """ @@ -1714,10 +1714,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: binomial(M.size(), M.full_rank())-M.bases_count() + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: binomial(M.size(), M.full_rank())-M.bases_count() # optional - sage.libs.pari 68 - sage: len([B for B in M.nonbases()]) + sage: len([B for B in M.nonbases()]) # optional - sage.libs.pari 68 """ return self.dependent_r_sets(self.full_rank()) @@ -1740,8 +1740,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: len(M.nonspanning_circuits()) + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: len(M.nonspanning_circuits()) # optional - sage.libs.pari 23 """ cdef SetSystem NSC @@ -1789,8 +1789,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: len(M.noncospanning_cocircuits()) + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: len(M.noncospanning_cocircuits()) # optional - sage.libs.pari 23 """ cdef SetSystem NSC @@ -1835,8 +1835,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.NonFano().bases()) - sage: sorted([sorted(C) for C in M.cocircuits()]) + sage: M = Matroid(bases=matroids.named_matroids.NonFano().bases()) # optional - sage.libs.pari + sage: sorted([sorted(C) for C in M.cocircuits()]) # optional - sage.libs.pari [['a', 'b', 'c', 'd', 'g'], ['a', 'b', 'c', 'e', 'g'], ['a', 'b', 'c', 'f', 'g'], ['a', 'b', 'd', 'e'], ['a', 'c', 'd', 'f'], ['a', 'e', 'f', 'g'], ['b', 'c', 'e', 'f'], @@ -1883,8 +1883,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(matroids.named_matroids.NonFano().bases()) - sage: sorted([sorted(C) for C in M.circuits()]) + sage: M = Matroid(matroids.named_matroids.NonFano().bases()) # optional - sage.libs.pari + sage: sorted([sorted(C) for C in M.circuits()]) # optional - sage.libs.pari [['a', 'b', 'c', 'g'], ['a', 'b', 'd', 'e'], ['a', 'b', 'f'], ['a', 'c', 'd', 'f'], ['a', 'c', 'e'], ['a', 'd', 'e', 'f'], ['a', 'd', 'g'], ['a', 'e', 'f', 'g'], ['b', 'c', 'd'], @@ -1932,10 +1932,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: M._characteristic_setsystem() + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: M._characteristic_setsystem() # optional - sage.libs.pari Iterator over a system of subsets - sage: len(M._characteristic_setsystem()) + sage: len(M._characteristic_setsystem()) # optional - sage.libs.pari 23 """ if 2 * self._matroid_rank > self._groundset_size: @@ -1958,9 +1958,9 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) - sage: N = Matroid(matroids.named_matroids.NonFano().bases()) - sage: M._weak_invariant() == N._weak_invariant() + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.libs.pari + sage: N = Matroid(matroids.named_matroids.NonFano().bases()) # optional - sage.libs.pari + sage: M._weak_invariant() == N._weak_invariant() # optional - sage.libs.pari False """ if self._weak_invariant_var is None: @@ -2003,9 +2003,9 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(matroids.named_matroids.Fano().bases()) - sage: N = Matroid(matroids.named_matroids.NonFano().bases()) - sage: M._strong_invariant() == N._strong_invariant() + sage: M = Matroid(matroids.named_matroids.Fano().bases()) # optional - sage.libs.pari + sage: N = Matroid(matroids.named_matroids.NonFano().bases()) # optional - sage.libs.pari + sage: M._strong_invariant() == N._strong_invariant() # optional - sage.libs.pari False """ if self._strong_invariant_var is None: @@ -2132,10 +2132,10 @@ cdef class BasisExchangeMatroid(Matroid): sage: N._is_isomorphism(M, {e:e for e in M.groundset()}) False - sage: M = matroids.named_matroids.Fano() \ ['g'] - sage: N = matroids.Wheel(3) - sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} - sage: M._is_isomorphism(N, morphism) + sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.libs.pari + sage: N = matroids.Wheel(3) # optional - sage.libs.pari + sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} # optional - sage.libs.pari + sage: M._is_isomorphism(N, morphism) # optional - sage.libs.pari True TESTS: @@ -2199,9 +2199,9 @@ cdef class BasisExchangeMatroid(Matroid): sage: morphism = M1._isomorphism(M2) sage: M1._is_isomorphism(M2, morphism) True - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = matroids.named_matroids.NonFano() - sage: M1._isomorphism(M2) is None + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M1._isomorphism(M2) is None # optional - sage.libs.pari True TESTS: @@ -2212,8 +2212,8 @@ cdef class BasisExchangeMatroid(Matroid): ....: return min(len(X), 2) ....: sage: M = Matroid(groundset='abcd', rank_function=f) - sage: N = Matroid(field=GF(3), reduced_matrix=[[1,1],[1,-1]]) - sage: N._isomorphism(M) is not None + sage: N = Matroid(field=GF(3), reduced_matrix=[[1,1],[1,-1]]) # optional - sage.libs.pari + sage: N._isomorphism(M) is not None # optional - sage.libs.pari True """ if not isinstance(other, BasisExchangeMatroid): @@ -2294,11 +2294,11 @@ cdef class BasisExchangeMatroid(Matroid): True sage: M1._is_isomorphic(M2, certificate=True) (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) - sage: M1 = BasisMatroid(matroids.named_matroids.Fano()) - sage: M2 = matroids.named_matroids.NonFano() - sage: M1._is_isomorphic(M2) + sage: M1 = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M2 = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M1._is_isomorphic(M2) # optional - sage.libs.pari False - sage: M1._is_isomorphic(M2, certificate=True) + sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.libs.pari (False, None) """ @@ -2370,8 +2370,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: M.is_valid() + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M.is_valid() # optional - sage.libs.pari True sage: M = Matroid(groundset='abcd', bases=['ab', 'cd']) sage: M.is_valid() @@ -2381,7 +2381,7 @@ cdef class BasisExchangeMatroid(Matroid): Verify that :trac:`20172` was fixed:: - sage: M=Matroid(groundset='1234',bases=['12','13','23','34']) + sage: M = Matroid(groundset='1234', bases=['12','13','23','34']) sage: M.is_valid() False """ diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 85f09fd8f97..4c9ccf70db5 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -110,11 +110,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): Create a BasisMatroid instance out of any other matroid:: sage: from sage.matroids.advanced import * - sage: F = matroids.named_matroids.Fano() - sage: M = BasisMatroid(F) - sage: F.groundset() == M.groundset() + sage: F = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M = BasisMatroid(F) # optional - sage.libs.pari + sage: F.groundset() == M.groundset() # optional - sage.libs.pari True - sage: len(set(F.bases()).difference(M.bases())) + sage: len(set(F.bases()).difference(M.bases())) # optional - sage.libs.pari 0 It is possible to provide either bases or nonbases:: @@ -150,11 +150,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: F = matroids.named_matroids.Fano() - sage: M = BasisMatroid(F) - sage: F.groundset() == M.groundset() + sage: F = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M = BasisMatroid(F) # optional - sage.libs.pari + sage: F.groundset() == M.groundset() # optional - sage.libs.pari True - sage: len(set(F.bases()).difference(M.bases())) + sage: len(set(F.bases()).difference(M.bases())) # optional - sage.libs.pari 0 """ cdef SetSystem NB @@ -254,8 +254,8 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: repr(M) # indirect doctest + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: repr(M) # indirect doctest # optional - sage.libs.pari 'Matroid of rank 3 on 7 elements with 28 bases' """ @@ -429,12 +429,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.N2().bases()) - sage: M.truncation() + sage: M = Matroid(bases=matroids.named_matroids.N2().bases()) # optional - sage.libs.pari + sage: M.truncation() # optional - sage.libs.pari Matroid of rank 5 on 12 elements with 702 bases - sage: M.f_vector() + sage: M.f_vector() # optional - sage.libs.pari [1, 12, 66, 190, 258, 99, 1] - sage: M.truncation().f_vector() + sage: M.truncation().f_vector() # optional - sage.libs.pari [1, 12, 66, 190, 258, 1] """ @@ -511,10 +511,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: M + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Matroid of rank 3 on 7 elements with 28 bases - sage: M._with_coloop('x') + sage: M._with_coloop('x') # optional - sage.libs.pari Matroid of rank 4 on 8 elements with 28 bases """ @@ -548,11 +548,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: sorted(M.groundset()) + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: sorted(M.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: N = M.relabel({'g':'x'}) - sage: sorted(N.groundset()) + sage: N = M.relabel({'g':'x'}) # optional - sage.libs.pari + sage: sorted(N.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'x'] """ @@ -572,10 +572,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) - sage: M + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Matroid of rank 3 on 7 elements with 28 bases - sage: M.bases_count() + sage: M.bases_count() # optional - sage.libs.pari 28 """ if self._bcount is None: @@ -594,10 +594,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) - sage: M + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Matroid of rank 3 on 7 elements with 28 bases - sage: len(M.bases()) + sage: len(M.bases()) # optional - sage.libs.pari 28 """ cdef long r, n @@ -630,10 +630,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) - sage: M + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Matroid of rank 3 on 7 elements with 28 bases - sage: len(M.nonbases()) + sage: len(M.nonbases()) # optional - sage.libs.pari 7 """ if self._nonbases is not None: @@ -674,9 +674,9 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: N = BasisMatroid(matroids.named_matroids.Fano()) - sage: M._bases_invariant() == N._bases_invariant() + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M._bases_invariant() == N._bases_invariant() # optional - sage.libs.pari True """ if self._bases_invariant_var is not None: @@ -733,9 +733,9 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: N = BasisMatroid(matroids.named_matroids.NonFano()) - sage: M._bases_invariant2() == N._bases_invariant2() + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.libs.pari + sage: M._bases_invariant2() == N._bases_invariant2() # optional - sage.libs.pari False """ if self._bases_invariant2_var is None: @@ -844,8 +844,8 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.N1()) - sage: sorted([e for e in M.groundset() if M.is_distinguished(e)]) + sage: M = BasisMatroid(matroids.named_matroids.N1()) # optional - sage.libs.pari + sage: sorted([e for e in M.groundset() if M.is_distinguished(e)]) # optional - sage.libs.pari ['c', 'g', 'h', 'j'] """ @@ -886,12 +886,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) - sage: N = BasisMatroid(matroids.named_matroids.Fano()) - sage: m = {e:e for e in M.groundset()} - sage: M._is_relaxation(N, m) + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: m = {e:e for e in M.groundset()} # optional - sage.libs.pari + sage: M._is_relaxation(N, m) # optional - sage.libs.pari True - sage: N._is_relaxation(M, m) + sage: N._is_relaxation(M, m) # optional - sage.libs.pari False """ cdef long i, j @@ -941,12 +941,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) - sage: N = BasisMatroid(matroids.named_matroids.Fano()) - sage: m = {e:e for e in M.groundset()} - sage: M._is_relaxation(N, m) + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: m = {e:e for e in M.groundset()} # optional - sage.libs.pari + sage: M._is_relaxation(N, m) # optional - sage.libs.pari True - sage: M._is_isomorphism(N, m) + sage: M._is_isomorphism(N, m) # optional - sage.libs.pari False """ if not isinstance(other, BasisMatroid): @@ -979,9 +979,9 @@ cdef class BasisMatroid(BasisExchangeMatroid): sage: morphism = M._isomorphism(N) sage: M._is_isomorphism(N, morphism) True - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) - sage: N = BasisMatroid(matroids.named_matroids.Fano()) - sage: M._isomorphism(N) is not None + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M._isomorphism(N) is not None # optional - sage.libs.pari False """ if not isinstance(other, BasisMatroid): @@ -1055,11 +1055,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) - sage: N = BasisMatroid(matroids.named_matroids.Fano()) - sage: M._is_isomorphic(N) + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M._is_isomorphic(N) # optional - sage.libs.pari False - sage: M._is_isomorphic(N, certificate=True) + sage: M._is_isomorphic(N, certificate=True) # optional - sage.libs.pari (False, None) """ if certificate: @@ -1127,12 +1127,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) - sage: N = BasisMatroid(matroids.named_matroids.Fano().dual()).dual() - sage: O = BasisMatroid(matroids.named_matroids.NonFano()) - sage: hash(M) == hash(N) + sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: N = BasisMatroid(matroids.named_matroids.Fano().dual()).dual() # optional - sage.libs.pari + sage: O = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.libs.pari + sage: hash(M) == hash(N) # optional - sage.libs.pari True - sage: hash(M) == hash(O) + sage: hash(M) == hash(O) # optional - sage.libs.pari False """ return hash((self.groundset(), self.bases_count(), self._weak_invariant())) diff --git a/src/sage/matroids/catalog.py b/src/sage/matroids/catalog.py index 769ef123923..c82ae02d063 100644 --- a/src/sage/matroids/catalog.py +++ b/src/sage/matroids/catalog.py @@ -67,13 +67,13 @@ def Q6(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Q6(); M + sage: M = matroids.named_matroids.Q6(); M # optional - sage.libs.pari Q6: Quaternary matroid of rank 3 on 6 elements - sage: setprint(M.hyperplanes()) + sage: setprint(M.hyperplanes()) # optional - sage.libs.pari [{'a', 'b', 'd'}, {'a', 'c'}, {'a', 'e'}, {'a', 'f'}, {'b', 'c', 'e'}, {'b', 'f'}, {'c', 'd'}, {'c', 'f'}, {'d', 'e'}, {'d', 'f'}, {'e', 'f'}] - sage: M.nonspanning_circuits() == M.noncospanning_cocircuits() + sage: M.nonspanning_circuits() == M.noncospanning_cocircuits() # optional - sage.libs.pari False """ F = GF(4, 'x') @@ -106,10 +106,10 @@ def P6(): {2: {{'a', 'b', 'c'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f'}}} sage: len(set(M.nonspanning_circuits()).difference(M.nonbases())) == 0 True - sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, + sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, # optional - sage.libs.pari ....: nrows=5)).has_minor(M) False - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ E = 'abcdef' @@ -134,13 +134,13 @@ def R6(): EXAMPLES:: - sage: M = matroids.named_matroids.R6(); M + sage: M = matroids.named_matroids.R6(); M # optional - sage.libs.pari R6: Ternary matroid of rank 3 on 6 elements, type 2+ - sage: M.equals(M.dual()) + sage: M.equals(M.dual()) # optional - sage.libs.pari True - sage: M.is_connected() + sage: M.is_connected() # optional - sage.libs.pari True - sage: M.is_3connected() + sage: M.is_3connected() # optional - sage.libs.pari False """ A = Matrix(GF(3), [ @@ -167,12 +167,12 @@ def Fano(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano(); M + sage: M = matroids.named_matroids.Fano(); M # optional - sage.libs.pari Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) - sage: setprint(sorted(M.nonspanning_circuits())) + sage: setprint(sorted(M.nonspanning_circuits())) # optional - sage.libs.pari [{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, {'d', 'e', 'f'}] - sage: M.delete(M.groundset_list()[randrange(0, + sage: M.delete(M.groundset_list()[randrange(0, # optional - sage.libs.pari ....: 7)]).is_isomorphic(matroids.CompleteGraphic(4)) True """ @@ -198,14 +198,14 @@ def NonFano(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.NonFano(); M + sage: M = matroids.named_matroids.NonFano(); M # optional - sage.libs.pari NonFano: Ternary matroid of rank 3 on 7 elements, type 0- - sage: setprint(M.nonbases()) + sage: setprint(M.nonbases()) # optional - sage.libs.pari [{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}] - sage: M.delete('f').is_isomorphic(matroids.CompleteGraphic(4)) + sage: M.delete('f').is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.libs.pari True - sage: M.delete('g').is_isomorphic(matroids.CompleteGraphic(4)) + sage: M.delete('g').is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.libs.pari False """ A = Matrix(GF(3), [ @@ -230,11 +230,11 @@ def O7(): EXAMPLES:: - sage: M = matroids.named_matroids.O7(); M + sage: M = matroids.named_matroids.O7(); M # optional - sage.libs.pari O7: Ternary matroid of rank 3 on 7 elements, type 0+ - sage: M.delete('e').is_isomorphic(matroids.CompleteGraphic(4)) + sage: M.delete('e').is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.libs.pari True - sage: M.tutte_polynomial() + sage: M.tutte_polynomial() # optional - sage.libs.pari y^4 + x^3 + x*y^2 + 3*y^3 + 4*x^2 + 5*x*y + 5*y^2 + 4*x + 4*y """ A = Matrix(GF(3), [ @@ -259,13 +259,13 @@ def P7(): EXAMPLES:: - sage: M = matroids.named_matroids.P7(); M + sage: M = matroids.named_matroids.P7(); M # optional - sage.libs.pari P7: Ternary matroid of rank 3 on 7 elements, type 1+ - sage: M.f_vector() + sage: M.f_vector() # optional - sage.libs.pari [1, 7, 11, 1] - sage: M.has_minor(matroids.CompleteGraphic(4)) + sage: M.has_minor(matroids.CompleteGraphic(4)) # optional - sage.libs.pari False - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(3), [ @@ -332,14 +332,14 @@ def R8(): EXAMPLES:: - sage: M = matroids.named_matroids.R8(); M + sage: M = matroids.named_matroids.R8(); M # optional - sage.libs.pari R8: Ternary matroid of rank 4 on 8 elements, type 0+ - sage: M.contract(M.groundset_list()[randrange(0, + sage: M.contract(M.groundset_list()[randrange(0, # optional - sage.libs.pari ....: 8)]).is_isomorphic(matroids.named_matroids.NonFano()) True - sage: M.equals(M.dual()) + sage: M.equals(M.dual()) # optional - sage.libs.pari True - sage: M.has_minor(matroids.named_matroids.Fano()) + sage: M.has_minor(matroids.named_matroids.Fano()) # optional - sage.libs.pari False """ A = Matrix(GF(3), [ @@ -477,21 +477,21 @@ def S8(): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.S8(); M + sage: M = matroids.named_matroids.S8(); M # optional - sage.libs.pari S8: Binary matroid of rank 4 on 8 elements, type (2, 0) - sage: M.contract('d').is_isomorphic(matroids.named_matroids.Fano()) + sage: M.contract('d').is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.libs.pari True - sage: M.delete('d').is_isomorphic( + sage: M.delete('d').is_isomorphic( # optional - sage.libs.pari ....: matroids.named_matroids.Fano().dual()) False - sage: M.is_graphic() + sage: M.is_graphic() # optional - sage.libs.pari False - sage: D = get_nonisomorphic_matroids( + sage: D = get_nonisomorphic_matroids( # optional - sage.libs.pari ....: list(matroids.named_matroids.Fano().linear_coextensions( ....: cosimple=True))) - sage: len(D) + sage: len(D) # optional - sage.libs.pari 2 - sage: [N.is_isomorphic(M) for N in D] + sage: [N.is_isomorphic(M) for N in D] # optional - sage.libs.pari [...True...] """ @@ -553,13 +553,13 @@ def T8(): EXAMPLES:: - sage: M = matroids.named_matroids.T8(); M + sage: M = matroids.named_matroids.T8(); M # optional - sage.libs.pari T8: Ternary matroid of rank 4 on 8 elements, type 0- - sage: M.truncation().is_isomorphic(matroids.Uniform(3, 8)) + sage: M.truncation().is_isomorphic(matroids.Uniform(3, 8)) # optional - sage.libs.pari True - sage: M.contract('e').is_isomorphic(matroids.named_matroids.P7()) + sage: M.contract('e').is_isomorphic(matroids.named_matroids.P7()) # optional - sage.libs.pari True - sage: M.has_minor(matroids.Uniform(3, 8)) + sage: M.has_minor(matroids.Uniform(3, 8)) # optional - sage.libs.pari False """ @@ -585,15 +585,15 @@ def J(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.J(); M + sage: M = matroids.named_matroids.J(); M # optional - sage.libs.pari J: Ternary matroid of rank 4 on 8 elements, type 0- - sage: setprint(M.truncation().nonbases()) + sage: setprint(M.truncation().nonbases()) # optional - sage.libs.pari [{'a', 'b', 'f'}, {'a', 'c', 'g'}, {'a', 'd', 'h'}] - sage: M.is_isomorphic(M.dual()) + sage: M.is_isomorphic(M.dual()) # optional - sage.libs.pari True - sage: M.has_minor(matroids.CompleteGraphic(4)) + sage: M.has_minor(matroids.CompleteGraphic(4)) # optional - sage.libs.pari False - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(3), [ @@ -619,14 +619,14 @@ def P8(): EXAMPLES:: - sage: M = matroids.named_matroids.P8(); M + sage: M = matroids.named_matroids.P8(); M # optional - sage.libs.pari P8: Ternary matroid of rank 4 on 8 elements, type 2+ - sage: M.is_isomorphic(M.dual()) + sage: M.is_isomorphic(M.dual()) # optional - sage.libs.pari True - sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, + sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, # optional - sage.libs.pari ....: nrows=5)).has_minor(M) False - sage: M.bicycle_dimension() + sage: M.bicycle_dimension() # optional - sage.libs.pari 2 """ @@ -719,11 +719,11 @@ def TernaryDowling3(): EXAMPLES:: - sage: M = matroids.named_matroids.TernaryDowling3(); M + sage: M = matroids.named_matroids.TernaryDowling3(); M # optional - sage.libs.pari Q3(GF(3)x): Ternary matroid of rank 3 on 9 elements, type 0- - sage: len(list(M.linear_subclasses())) + sage: len(list(M.linear_subclasses())) # optional - sage.libs.pari 72 - sage: M.fundamental_cycle('abc', 'd') + sage: M.fundamental_cycle('abc', 'd') # optional - sage.libs.pari {'a': 2, 'b': 1, 'd': 1} """ @@ -853,17 +853,17 @@ def Whirl(n): EXAMPLES:: - sage: M = matroids.Whirl(5); M + sage: M = matroids.Whirl(5); M # optional - sage.libs.pari Whirl(5): Ternary matroid of rank 5 on 10 elements, type 0- - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True - sage: M.tutte_polynomial() + sage: M.tutte_polynomial() # optional - sage.libs.pari x^5 + y^5 + 5*x^4 + 5*x^3*y + 5*x^2*y^2 + 5*x*y^3 + 5*y^4 + 10*x^3 + 15*x^2*y + 15*x*y^2 + 10*y^3 + 10*x^2 + 15*x*y + 10*y^2 + 5*x + 5*y - sage: M.is_isomorphic(matroids.Wheel(5)) + sage: M.is_isomorphic(matroids.Wheel(5)) # optional - sage.libs.pari False - sage: M = matroids.Whirl(3) - sage: M.is_isomorphic(matroids.CompleteGraphic(4)) + sage: M = matroids.Whirl(3) # optional - sage.libs.pari + sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.libs.pari False .. TODO:: @@ -960,12 +960,12 @@ def PG(n, q, x=None): EXAMPLES:: - sage: M = matroids.PG(2, 2) - sage: M.is_isomorphic(matroids.named_matroids.Fano()) + sage: M = matroids.PG(2, 2) # optional - sage.libs.pari + sage: M.is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.libs.pari True - sage: matroids.PG(5, 4, 'z').size() == (4^6 - 1) / (4 - 1) + sage: matroids.PG(5, 4, 'z').size() == (4^6 - 1) / (4 - 1) # optional - sage.libs.pari True - sage: M = matroids.PG(4, 7); M + sage: M = matroids.PG(4, 7); M # optional - sage.libs.pari PG(4, 7): Linear matroid of rank 5 on 2801 elements represented over the Finite Field of size 7 """ @@ -1003,13 +1003,13 @@ def AG(n, q, x=None): EXAMPLES:: - sage: M = matroids.AG(2, 3) \ 8 - sage: M.is_isomorphic(matroids.named_matroids.AG23minus()) + sage: M = matroids.AG(2, 3) \ 8 # optional - sage.libs.pari + sage: M.is_isomorphic(matroids.named_matroids.AG23minus()) # optional - sage.libs.pari True - sage: matroids.AG(5, 4, 'z').size() == ((4 ^ 6 - 1) / (4 - 1) - + sage: matroids.AG(5, 4, 'z').size() == ((4 ^ 6 - 1) / (4 - 1) - # optional - sage.libs.pari ....: (4 ^ 5 - 1)/(4 - 1)) True - sage: M = matroids.AG(4, 2); M + sage: M = matroids.AG(4, 2); M # optional - sage.libs.pari AG(4, 2): Binary matroid of rank 5 on 16 elements, type (5, 0) """ @@ -1243,10 +1243,10 @@ def Q10(): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() - sage: M.is_isomorphic(M.dual()) + sage: M = matroids.named_matroids.Q10() # optional - sage.libs.pari + sage: M.is_isomorphic(M.dual()) # optional - sage.libs.pari True - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True Check the splitter property. By Seymour's Theorem, and using self-duality, @@ -1255,8 +1255,8 @@ def Q10(): are quaternary are `U_{2, 5}, U_{3, 5}, F_7, F_7^*`. As it happens, it suffices to check for `U_{2, 5}`: - sage: S = matroids.named_matroids.Q10().linear_extensions(simple=True) - sage: [M for M in S if not M.has_line_minor(5)] # long time + sage: S = matroids.named_matroids.Q10().linear_extensions(simple=True) # optional - sage.libs.pari + sage: [M for M in S if not M.has_line_minor(5)] # long time # optional - sage.libs.pari [] """ F = GF(4, 'x') @@ -1281,10 +1281,10 @@ def N1(): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: M.is_field_isomorphic(M.dual()) + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: M.is_field_isomorphic(M.dual()) # optional - sage.libs.pari True - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ @@ -1308,10 +1308,10 @@ def N2(): EXAMPLES:: - sage: M = matroids.named_matroids.N2() - sage: M.is_field_isomorphic(M.dual()) + sage: M = matroids.named_matroids.N2() # optional - sage.libs.pari + sage: M.is_field_isomorphic(M.dual()) # optional - sage.libs.pari True - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ @@ -1422,11 +1422,11 @@ def ExtendedBinaryGolayCode(): EXAMPLES:: - sage: M = matroids.named_matroids.ExtendedBinaryGolayCode() - sage: C = LinearCode(M.representation()) - sage: C.is_permutation_equivalent(codes.GolayCode(GF(2))) # long time + sage: M = matroids.named_matroids.ExtendedBinaryGolayCode() # optional - sage.libs.pari + sage: C = LinearCode(M.representation()) # optional - sage.libs.pari + sage: C.is_permutation_equivalent(codes.GolayCode(GF(2))) # long time # optional - sage.libs.pari True - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(2), [ @@ -1457,11 +1457,11 @@ def ExtendedTernaryGolayCode(): EXAMPLES:: - sage: M = matroids.named_matroids.ExtendedTernaryGolayCode() - sage: C = LinearCode(M.representation()) - sage: C.is_permutation_equivalent(codes.GolayCode(GF(3))) # long time + sage: M = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari + sage: C = LinearCode(M.representation()) # optional - sage.libs.pari + sage: C.is_permutation_equivalent(codes.GolayCode(GF(3))) # long time # optional - sage.libs.pari True - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(3), [ @@ -1509,11 +1509,11 @@ def NotP8(): EXAMPLES:: - sage: M = matroids.named_matroids.P8() - sage: N = matroids.named_matroids.NotP8() - sage: M.is_isomorphic(N) + sage: M = matroids.named_matroids.P8() # optional - sage.libs.pari + sage: N = matroids.named_matroids.NotP8() # optional - sage.libs.pari + sage: M.is_isomorphic(N) # optional - sage.libs.pari False - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(3), [ @@ -1538,10 +1538,10 @@ def D16(): # A.K.A. the Carolyn Chun Matroid EXAMPLES:: - sage: M = matroids.named_matroids.D16() - sage: M + sage: M = matroids.named_matroids.D16() # optional - sage.libs.pari + sage: M # optional - sage.libs.pari D16: Binary matroid of rank 8 on 16 elements, type (0, 0) - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ @@ -1569,10 +1569,10 @@ def Terrahawk(): # A.K.A. the Dillon Mayhew Matroid EXAMPLES:: - sage: M = matroids.named_matroids.Terrahawk() - sage: M + sage: M = matroids.named_matroids.Terrahawk() # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Terrahawk: Binary matroid of rank 8 on 16 elements, type (0, 4) - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ @@ -1653,10 +1653,10 @@ def T12(): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: M + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: M # optional - sage.libs.pari T12: Binary matroid of rank 6 on 12 elements, type (2, None) - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(2), [ @@ -1681,10 +1681,10 @@ def P9(): EXAMPLES:: - sage: M = matroids.named_matroids.P9() - sage: M + sage: M = matroids.named_matroids.P9() # optional - sage.libs.pari + sage: M # optional - sage.libs.pari P9: Binary matroid of rank 4 on 9 elements, type (1, 1) - sage: M.is_valid() + sage: M.is_valid() # optional - sage.libs.pari True """ A = Matrix(GF(2), [ diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 679445a6a62..351f62c94c7 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -50,8 +50,8 @@ AUTHORS: TESTS:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) - sage: TestSuite(M).run() + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: TestSuite(M).run() # optional - sage.libs.pari Methods ======= @@ -117,8 +117,8 @@ cdef class CircuitClosuresMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) - sage: M + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Matroid of rank 3 on 7 elements with circuit-closures {2: {{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, @@ -127,7 +127,7 @@ cdef class CircuitClosuresMatroid(Matroid): ....: circuit_closures={3: ['edfg', 'acdg', 'bcfg', 'cefh', ....: 'afgh', 'abce', 'abdf', 'begh', 'bcdh', 'adeh'], ....: 4: ['abcdefgh']}) - sage: M.equals(matroids.named_matroids.P8()) + sage: M.equals(matroids.named_matroids.P8()) # optional - sage.libs.pari True """ @@ -140,8 +140,8 @@ cdef class CircuitClosuresMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) - sage: M + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Matroid of rank 3 on 7 elements with circuit-closures {2: {{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, @@ -152,7 +152,7 @@ cdef class CircuitClosuresMatroid(Matroid): ....: circuit_closures={3: ['edfg', 'acdg', 'bcfg', 'cefh', ....: 'afgh', 'abce', 'abdf', 'begh', 'bcdh', 'adeh'], ....: 4: ['abcdefgh']}) - sage: M.equals(matroids.named_matroids.P8()) + sage: M.equals(matroids.named_matroids.P8()) # optional - sage.libs.pari True """ if M is not None: diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index 99580562e96..6ab2f4917ef 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -53,8 +53,8 @@ A number of special matroids are collected under a ``named_matroids`` submenu. To see which, type ``matroids.named_matroids.`` as above:: - sage: F7 = matroids.named_matroids.Fano() - sage: len(F7.nonspanning_circuits()) + sage: F7 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: len(F7.nonspanning_circuits()) # optional - sage.libs.pari 7 Constructing matroids @@ -68,11 +68,11 @@ EXAMPLES:: - sage: A = Matrix(GF(2), [[1, 0, 0, 0, 1, 1, 1], + sage: A = Matrix(GF(2), [[1, 0, 0, 0, 1, 1, 1], # optional - sage.libs.pari ....: [0, 1, 0, 1, 0, 1, 1], ....: [0, 0, 1, 1, 1, 0, 1]]) - sage: M = Matroid(A) - sage: M.is_isomorphic(matroids.named_matroids.Fano()) + sage: M = Matroid(A) # optional - sage.libs.pari + sage: M.is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.libs.pari True sage: M = Matroid(graphs.PetersenGraph()) diff --git a/src/sage/matroids/dual_matroid.py b/src/sage/matroids/dual_matroid.py index 804e43f035b..73ad305e1d6 100644 --- a/src/sage/matroids/dual_matroid.py +++ b/src/sage/matroids/dual_matroid.py @@ -10,13 +10,13 @@ EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: N = M.dual() - sage: M.is_basis('abc') + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N = M.dual() # optional - sage.libs.pari + sage: M.is_basis('abc') # optional - sage.libs.pari True - sage: N.is_basis('defg') + sage: N.is_basis('defg') # optional - sage.libs.pari True - sage: M.dual().dual() == M + sage: M.dual().dual() == M # optional - sage.libs.pari True Implementation @@ -455,17 +455,17 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = CircuitClosuresMatroid(M1.dual()) - sage: M3 = CircuitClosuresMatroid(M1).dual() + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = CircuitClosuresMatroid(M1.dual()) # optional - sage.libs.pari + sage: M3 = CircuitClosuresMatroid(M1).dual() # optional - sage.libs.pari sage: M4 = CircuitClosuresMatroid(groundset='abcdefg', ....: circuit_closures={3: ['abcdefg'], 2: ['beg', 'cdb', 'cfg', ....: 'ace', 'fed', 'gad', 'fab']}).dual() - sage: M1.dual() == M2 # indirect doctest + sage: M1.dual() == M2 # indirect doctest # optional - sage.libs.pari False - sage: M2 == M3 + sage: M2 == M3 # optional - sage.libs.pari False - sage: M3 == M4 + sage: M3 == M4 # optional - sage.libs.pari True """ if not isinstance(other, DualMatroid): @@ -487,17 +487,17 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = CircuitClosuresMatroid(M1.dual()) - sage: M3 = CircuitClosuresMatroid(M1).dual() + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = CircuitClosuresMatroid(M1.dual()) # optional - sage.libs.pari + sage: M3 = CircuitClosuresMatroid(M1).dual() # optional - sage.libs.pari sage: M4 = CircuitClosuresMatroid(groundset='abcdefg', ....: circuit_closures={3: ['abcdefg'], 2: ['beg', 'cdb', 'cfg', ....: 'ace', 'fed', 'gad', 'fab']}).dual() - sage: M1.dual() != M2 # indirect doctest + sage: M1.dual() != M2 # indirect doctest # optional - sage.libs.pari True - sage: M2 != M3 + sage: M2 != M3 # optional - sage.libs.pari True - sage: M3 != M4 + sage: M3 != M4 # optional - sage.libs.pari False """ return not self == other diff --git a/src/sage/matroids/extension.pyx b/src/sage/matroids/extension.pyx index d762526d2fa..608d9363496 100644 --- a/src/sage/matroids/extension.pyx +++ b/src/sage/matroids/extension.pyx @@ -59,7 +59,7 @@ cdef class CutNode: EXAMPLES:: - sage: len(list(matroids.named_matroids.Fano().linear_subclasses())) # indirect doctest + sage: len(list(matroids.named_matroids.Fano().linear_subclasses())) # indirect doctest # optional - sage.libs.pari 16 """ cdef CutNode node diff --git a/src/sage/matroids/graphic_matroid.py b/src/sage/matroids/graphic_matroid.py index 9bafa6dc0c7..f91ad67ddcc 100644 --- a/src/sage/matroids/graphic_matroid.py +++ b/src/sage/matroids/graphic_matroid.py @@ -1,3 +1,5 @@ +# sage.doctest: optional - sage.graphs +# sage.doctest: optional - sage.groups (for DisjointSet) r""" Graphic Matroids diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 8d641737a8f..e693cbfb17d 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -216,7 +216,7 @@ in which the partition is specified as a list of lists:: sage: M = PartitionMatroid([[1, 2], [3, 4, 5], [6, 7]]) sage: M.full_rank() 3 - sage: M.tutte_polynomial(var('x'), var('y')) + sage: M.tutte_polynomial(var('x'), var('y')) # optional - sage.symbolic x^2*y^2 + 2*x*y^3 + y^4 + x^3 + 3*x^2*y + 3*x*y^2 + y^3 .. NOTE:: @@ -394,7 +394,7 @@ cdef class Matroid(SageObject): sage: M = PartitionMatroid([[1, 2], [3, 4, 5], [6, 7]]) sage: M.full_rank() 3 - sage: M.tutte_polynomial(var('x'), var('y')) + sage: M.tutte_polynomial(var('x'), var('y')) # optional - sage.symbolic x^2*y^2 + 2*x*y^3 + y^4 + x^3 + 3*x^2*y + 3*x*y^2 + y^3 .. NOTE:: @@ -1133,7 +1133,7 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.named_matroids.Vamos() - sage: M._has_minor(matroids.Whirl(3)) + sage: M._has_minor(matroids.Whirl(3)) # optional - sage.libs.pari False sage: M._has_minor(matroids.Uniform(2, 4)) True @@ -1361,12 +1361,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.rank() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.rank() # optional - sage.libs.pari 3 - sage: M.rank(['a', 'b', 'f']) + sage: M.rank(['a', 'b', 'f']) # optional - sage.libs.pari 2 - sage: M.rank(['a', 'b', 'x']) + sage: M.rank(['a', 'b', 'x']) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: ['a', 'b', 'x'] is not a subset of the groundset @@ -1672,12 +1672,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.corank() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.corank() # optional - sage.libs.pari 4 - sage: M.corank('cdeg') + sage: M.corank('cdeg') # optional - sage.libs.pari 3 - sage: M.rank(['a', 'b', 'x']) + sage: M.rank(['a', 'b', 'x']) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: ['a', 'b', 'x'] is not a subset of the groundset @@ -1914,10 +1914,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.loops() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.loops() # optional - sage.libs.pari frozenset() - sage: (M / ['a', 'b']).loops() + sage: (M / ['a', 'b']).loops() # optional - sage.libs.pari frozenset({'f'}) """ return self._closure(set()) @@ -2138,10 +2138,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual() - sage: M.coloops() + sage: M = matroids.named_matroids.Fano().dual() # optional - sage.libs.pari + sage: M.coloops() # optional - sage.libs.pari frozenset() - sage: (M \ ['a', 'b']).coloops() + sage: (M \ ['a', 'b']).coloops() # optional - sage.libs.pari frozenset({'f'}) """ return self._coclosure(set()) @@ -2384,8 +2384,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted([sorted(C) for C in M.circuits()]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted([sorted(C) for C in M.circuits()]) # optional - sage.libs.pari [['a', 'b', 'c', 'g'], ['a', 'b', 'd', 'e'], ['a', 'b', 'f'], ['a', 'c', 'd', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['a', 'e', 'f', 'g'], ['b', 'c', 'd'], ['b', 'c', 'e', 'f'], @@ -2416,8 +2416,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted([sorted(C) for C in M.nonspanning_circuits()]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted([sorted(C) for C in M.nonspanning_circuits()]) # optional - sage.libs.pari [['a', 'b', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['b', 'c', 'd'], ['b', 'e', 'g'], ['c', 'f', 'g'], ['d', 'e', 'f']] @@ -2442,8 +2442,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted([sorted(C) for C in M.cocircuits()]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted([sorted(C) for C in M.cocircuits()]) # optional - sage.libs.pari [['a', 'b', 'c', 'g'], ['a', 'b', 'd', 'e'], ['a', 'c', 'd', 'f'], ['a', 'e', 'f', 'g'], ['b', 'c', 'e', 'f'], ['b', 'd', 'f', 'g'], ['c', 'd', 'e', 'g']] @@ -2471,8 +2471,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual() - sage: sorted([sorted(C) for C in M.noncospanning_cocircuits()]) + sage: M = matroids.named_matroids.Fano().dual() # optional - sage.libs.pari + sage: sorted([sorted(C) for C in M.noncospanning_cocircuits()]) # optional - sage.libs.pari [['a', 'b', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['b', 'c', 'd'], ['b', 'e', 'g'], ['c', 'f', 'g'], ['d', 'e', 'f']] @@ -2497,17 +2497,17 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: CC = M.circuit_closures() - sage: len(CC[2]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: CC = M.circuit_closures() # optional - sage.libs.pari + sage: len(CC[2]) # optional - sage.libs.pari 7 - sage: len(CC[3]) + sage: len(CC[3]) # optional - sage.libs.pari 1 - sage: len(CC[1]) + sage: len(CC[1]) # optional - sage.libs.pari Traceback (most recent call last): ... KeyError: 1 - sage: [sorted(X) for X in CC[3]] + sage: [sorted(X) for X in CC[3]] # optional - sage.libs.pari [['a', 'b', 'c', 'd', 'e', 'f', 'g']] """ CC = [set([]) for r in xrange(self.rank() + 1)] @@ -2534,11 +2534,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: CC = M.nonspanning_circuit_closures() - sage: len(CC[2]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: CC = M.nonspanning_circuit_closures() # optional - sage.libs.pari + sage: len(CC[2]) # optional - sage.libs.pari 7 - sage: len(CC[3]) + sage: len(CC[3]) # optional - sage.libs.pari Traceback (most recent call last): ... KeyError: 3 @@ -2737,9 +2737,9 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: F = M._flags(1) - sage: sorted(M._extend_flags(F)) == sorted(M._flags(2)) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: F = M._flags(1) # optional - sage.libs.pari + sage: sorted(M._extend_flags(F)) == sorted(M._flags(2)) # optional - sage.libs.pari True """ newflags = [] @@ -2777,8 +2777,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted([M._flags(1)]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted([M._flags(1)]) # optional - sage.libs.pari [[[frozenset({'a'}), {'a'}, frozenset({'b', 'c', 'd', 'e', 'f', 'g'})], [frozenset({'b'}), {'b'}, frozenset({'c', 'd', 'e', 'f', 'g'})], [frozenset({'c'}), {'c'}, frozenset({'d', 'e', 'f', 'g'})], @@ -2815,8 +2815,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted([sorted(F) for F in M.flats(2)]) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted([sorted(F) for F in M.flats(2)]) # optional - sage.libs.pari [['a', 'b', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['b', 'c', 'd'], ['b', 'e', 'g'], ['c', 'f', 'g'], ['d', 'e', 'f']] @@ -2844,8 +2844,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Q6() - sage: sorted([sorted(F) for F in M.coflats(2)]) + sage: M = matroids.named_matroids.Q6() # optional - sage.libs.pari + sage: sorted([sorted(F) for F in M.coflats(2)]) # optional - sage.libs.pari [['a', 'b'], ['a', 'c'], ['a', 'd', 'f'], ['a', 'e'], ['b', 'c'], ['b', 'd'], ['b', 'e'], ['b', 'f'], ['c', 'd'], ['c', 'e', 'f'], ['d', 'e']] @@ -2858,8 +2858,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.lattice_of_flats() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.lattice_of_flats() # optional - sage.libs.pari Finite lattice containing 16 elements """ from sage.combinat.posets.lattices import LatticePoset @@ -3125,13 +3125,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.Whirl(4) - sage: P = M.matroid_polytope(); P + sage: M = matroids.Whirl(4) # optional - sage.libs.pari + sage: P = M.matroid_polytope(); P # optional - sage.geometry.polyhedron sage.libs.pari A 7-dimensional polyhedron in ZZ^8 defined as the convex hull of 46 vertices - sage: M = matroids.named_matroids.NonFano() - sage: M.matroid_polytope() + sage: M = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M.matroid_polytope() # optional - sage.geometry.polyhedron sage.libs.pari A 6-dimensional polyhedron in ZZ^7 defined as the convex hull of 29 vertices @@ -3168,13 +3168,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.Whirl(4) - sage: M.independence_matroid_polytope() + sage: M = matroids.Whirl(4) # optional - sage.libs.pari + sage: M.independence_matroid_polytope() # optional - sage.geometry.polyhedron sage.libs.pari A 8-dimensional polyhedron in ZZ^8 defined as the convex hull of 135 vertices - sage: M = matroids.named_matroids.NonFano() - sage: M.independence_matroid_polytope() + sage: M = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M.independence_matroid_polytope() # optional - sage.geometry.polyhedron sage.libs.pari A 7-dimensional polyhedron in ZZ^7 defined as the convex hull of 58 vertices @@ -3227,11 +3227,11 @@ cdef class Matroid(SageObject): TypeError: can only test for isomorphism between matroids. - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = matroids.named_matroids.NonFano() - sage: M1.is_isomorphic(M2) + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M1.is_isomorphic(M2) # optional - sage.libs.pari False - sage: M1.is_isomorphic(M2, certificate=True) + sage: M1.is_isomorphic(M2, certificate=True) # optional - sage.libs.pari (False, None) """ if not isinstance(other, Matroid): @@ -3267,9 +3267,9 @@ cdef class Matroid(SageObject): sage: M1._is_isomorphic(M2, certificate=True) (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = matroids.named_matroids.NonFano() - sage: M1._is_isomorphic(M2) + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M1._is_isomorphic(M2) # optional - sage.libs.pari False """ @@ -3309,9 +3309,9 @@ cdef class Matroid(SageObject): ... TypeError: can only give isomorphism between matroids. - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = matroids.named_matroids.NonFano() - sage: M1.isomorphism(M2) is not None + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M1.isomorphism(M2) is not None # optional - sage.libs.pari False """ if not isinstance(other, Matroid): @@ -3339,9 +3339,9 @@ cdef class Matroid(SageObject): sage: morphism=M1.isomorphism(M2) sage: M1.is_isomorphism(M2, morphism) True - sage: M1 = matroids.named_matroids.Fano() - sage: M2 = matroids.named_matroids.NonFano() - sage: M1.isomorphism(M2) is not None + sage: M1 = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M2 = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M1.isomorphism(M2) is not None # optional - sage.libs.pari False """ if self is other: @@ -3385,38 +3385,38 @@ cdef class Matroid(SageObject): yields ``False``, even if the matroids are equal:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() - sage: M + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M # optional - sage.libs.pari Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) - sage: M1 = BasisMatroid(M) - sage: M2 = Matroid(groundset='abcdefg', reduced_matrix=[ + sage: M1 = BasisMatroid(M) # optional - sage.libs.pari + sage: M2 = Matroid(groundset='abcdefg', reduced_matrix=[ # optional - sage.libs.pari ....: [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1]], field=GF(2)) - sage: M.equals(M1) + sage: M.equals(M1) # optional - sage.libs.pari True - sage: M.equals(M2) + sage: M.equals(M2) # optional - sage.libs.pari True - sage: M == M1 + sage: M == M1 # optional - sage.libs.pari False - sage: M == M2 + sage: M == M2 # optional - sage.libs.pari True :class:`LinearMatroid ` instances ``M`` and ``N`` satisfy ``M == N`` if the representations are equivalent up to row operations and column scaling:: - sage: M1 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), + sage: M1 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.libs.pari ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), + sage: M2 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.libs.pari ....: [[1, 0, 1, 1], [0, 1, 1, 3]])) - sage: M3 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), + sage: M3 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.libs.pari ....: [[2, 6, 1, 0], [6, 1, 0, 1]])) - sage: M1.equals(M2) + sage: M1.equals(M2) # optional - sage.libs.pari True - sage: M1.equals(M3) + sage: M1.equals(M3) # optional - sage.libs.pari True - sage: M1 == M2 + sage: M1 == M2 # optional - sage.libs.pari False - sage: M1 == M3 + sage: M1 == M3 # optional - sage.libs.pari True """ if self is other: @@ -3463,19 +3463,19 @@ cdef class Matroid(SageObject): sage: N.is_isomorphism(M, {e:e for e in M.groundset()}) False - sage: M = matroids.named_matroids.Fano() \ ['g'] - sage: N = matroids.Wheel(3) - sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} - sage: M.is_isomorphism(N, morphism) + sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.libs.pari + sage: N = matroids.Wheel(3) # optional - sage.libs.pari + sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} # optional - sage.libs.pari + sage: M.is_isomorphism(N, morphism) # optional - sage.libs.pari True A morphism can be specified as a dictionary (above), a permutation, a function, and many other types of maps:: - sage: M = matroids.named_matroids.Fano() - sage: P = PermutationGroup([[('a', 'b', 'c'), + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: P = PermutationGroup([[('a', 'b', 'c'), # optional - sage.libs.pari ....: ('d', 'e', 'f'), ('g')]]).gen() - sage: M.is_isomorphism(M, P) + sage: M.is_isomorphism(M, P) # optional - sage.libs.pari True sage: M = matroids.named_matroids.Pappus() @@ -3572,10 +3572,10 @@ cdef class Matroid(SageObject): sage: N._is_isomorphism(M, {e:e for e in M.groundset()}) False - sage: M = matroids.named_matroids.Fano() \ ['g'] + sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.libs.pari sage: N = matroids.Wheel(3) sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} - sage: M._is_isomorphism(N, morphism) + sage: M._is_isomorphism(N, morphism) # optional - sage.libs.pari True """ from . import basis_exchange_matroid @@ -3639,19 +3639,19 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M1 = Matroid(groundset='abcd', matrix=Matrix(GF(7), + sage: M1 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.libs.pari ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = Matroid(groundset='abcd', matrix=Matrix(GF(7), + sage: M2 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.libs.pari ....: [[1, 0, 1, 1], [0, 1, 1, 3]])) - sage: M3 = Matroid(groundset='abcd', matrix=Matrix(GF(7), + sage: M3 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.libs.pari ....: [[2, 6, 1, 0], [6, 1, 0, 1]])) - sage: M1.equals(M2) + sage: M1.equals(M2) # optional - sage.libs.pari True - sage: M1.equals(M3) + sage: M1.equals(M3) # optional - sage.libs.pari True - sage: M1 != M2 # indirect doctest + sage: M1 != M2 # indirect doctest # optional - sage.libs.pari True - sage: M1 == M3 # indirect doctest + sage: M1 == M3 # indirect doctest # optional - sage.libs.pari True """ if op not in [Py_EQ, Py_NE]: @@ -3713,10 +3713,10 @@ cdef class Matroid(SageObject): The sets of contractions and deletions need not be independent, respectively coindependent:: - sage: M = matroids.named_matroids.Fano() - sage: M.rank('abf') + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.rank('abf') # optional - sage.libs.pari 2 - sage: M.minor(contractions='abf') + sage: M.minor(contractions='abf') # optional - sage.libs.pari Binary matroid of rank 1 on 4 elements, type (1, 0) However, they need to be subsets of the groundset, and disjoint:: @@ -3819,12 +3819,12 @@ cdef class Matroid(SageObject): :: - sage: M = matroids.named_matroids.Fano() - sage: sorted(M.groundset()) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted(M.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: M.contract(['a', 'c']) + sage: M.contract(['a', 'c']) # optional - sage.libs.pari Binary matroid of rank 1 on 5 elements, type (1, 0) - sage: M.contract(['a']) == M / ['a'] + sage: M.contract(['a']) == M / ['a'] # optional - sage.libs.pari True One can use a single element, rather than a set:: @@ -3837,8 +3837,8 @@ cdef class Matroid(SageObject): Note that one can iterate over strings:: - sage: M = matroids.named_matroids.Fano() - sage: M / 'abc' + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M / 'abc' # optional - sage.libs.pari Binary matroid of rank 0 on 4 elements, type (0, 0) The following is therefore ambiguous. Sage will contract the single @@ -3896,12 +3896,12 @@ cdef class Matroid(SageObject): :: - sage: M = matroids.named_matroids.Fano() - sage: sorted(M.groundset()) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted(M.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: M.delete(['a', 'c']) + sage: M.delete(['a', 'c']) # optional - sage.libs.pari Binary matroid of rank 3 on 5 elements, type (1, 6) - sage: M.delete(['a']) == M \ ['a'] + sage: M.delete(['a']) == M \ ['a'] # optional - sage.libs.pari True One can use a single element, rather than a set:: @@ -3914,8 +3914,8 @@ cdef class Matroid(SageObject): Note that one can iterate over strings:: - sage: M = matroids.named_matroids.Fano() - sage: M \ 'abc' + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M \ 'abc' # optional - sage.libs.pari Binary matroid of rank 3 on 4 elements, type (0, 5) The following is therefore ambiguous. Sage will delete the single @@ -3994,9 +3994,9 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: N = M.truncation() - sage: N.is_isomorphic(matroids.Uniform(2, 7)) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N = M.truncation() # optional - sage.libs.pari + sage: N.is_isomorphic(matroids.Uniform(2, 7)) # optional - sage.libs.pari True """ if self.full_rank() == 0: @@ -4034,15 +4034,15 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.Whirl(3) - sage: matroids.named_matroids.Fano().has_minor(M) + sage: matroids.named_matroids.Fano().has_minor(M) # optional - sage.libs.pari False - sage: matroids.named_matroids.NonFano().has_minor(M) + sage: matroids.named_matroids.NonFano().has_minor(M) # optional - sage.libs.pari True - sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) + sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) # optional - sage.libs.pari (True, (frozenset(), frozenset({'g'}), {0: 'b', 1: 'c', 2: 'a', 3: 'd', 4: 'e', 5: 'f'})) - sage: M = matroids.named_matroids.Fano() - sage: M.has_minor(M, True) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.has_minor(M, True) # optional - sage.libs.pari (True, (frozenset(), frozenset(), @@ -4083,21 +4083,21 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.N1() - sage: M.has_line_minor(4) + sage: M = matroids.named_matroids.N1() # optional - sage.libs.pari + sage: M.has_line_minor(4) # optional - sage.libs.pari True - sage: M.has_line_minor(5) + sage: M.has_line_minor(5) # optional - sage.libs.pari False - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c']]) + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c']]) # optional - sage.libs.pari False - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], # optional - sage.libs.pari ....: ['a', 'b', 'd' ]]) True - sage: M.has_line_minor(4, certificate=True) + sage: M.has_line_minor(4, certificate=True) # optional - sage.libs.pari (True, frozenset({'a', 'b', 'd'})) - sage: M.has_line_minor(5, certificate=True) + sage: M.has_line_minor(5, certificate=True) # optional - sage.libs.pari (False, None) - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], # optional - sage.libs.pari ....: ['a', 'b', 'd' ]], certificate=True) (True, frozenset({'a', 'b', 'd'})) @@ -4231,9 +4231,9 @@ cdef class Matroid(SageObject): Putting an element in parallel with another:: - sage: M = matroids.named_matroids.Fano() - sage: N = M.extension('z', ['c']) - sage: N.rank('cz') + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N = M.extension('z', ['c']) # optional - sage.libs.pari + sage: N.rank('cz') # optional - sage.libs.pari 1 """ r = self.full_rank() - 1 @@ -4304,9 +4304,9 @@ cdef class Matroid(SageObject): Put an element in series with another:: - sage: M = matroids.named_matroids.Fano() - sage: N = M.coextension('z', ['c']) - sage: N.corank('cz') + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N = M.coextension('z', ['c']) # optional - sage.libs.pari + sage: N.corank('cz') # optional - sage.libs.pari 1 """ return self.dual().extension(element, subsets).dual() @@ -4374,8 +4374,8 @@ cdef class Matroid(SageObject): The modular cut of the full groundset is equal to just the groundset:: - sage: M = matroids.named_matroids.Fano() - sage: M.modular_cut([M.groundset()]).difference( + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.modular_cut([M.groundset()]).difference( # optional - sage.libs.pari ....: [frozenset(M.groundset())]) set() """ @@ -4446,12 +4446,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: len(list(M.linear_subclasses())) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: len(list(M.linear_subclasses())) # optional - sage.libs.pari 16 - sage: len(list(M.linear_subclasses(line_length=3))) + sage: len(list(M.linear_subclasses(line_length=3))) # optional - sage.libs.pari 8 - sage: len(list(M.linear_subclasses(subsets=[{'a', 'b'}]))) + sage: len(list(M.linear_subclasses(subsets=[{'a', 'b'}]))) # optional - sage.libs.pari 5 The following matroid has an extension by element `e` such that @@ -4515,14 +4515,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.P8() - sage: len(list(M.extensions())) + sage: M = matroids.named_matroids.P8() # optional - sage.libs.pari + sage: len(list(M.extensions())) # optional - sage.libs.pari 1705 - sage: len(list(M.extensions(line_length=4))) + sage: len(list(M.extensions(line_length=4))) # optional - sage.libs.pari 41 - sage: sorted(M.groundset()) + sage: sorted(M.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] - sage: len(list(M.extensions(subsets=[{'a', 'b'}], line_length=4))) + sage: len(list(M.extensions(subsets=[{'a', 'b'}], line_length=4))) # optional - sage.libs.pari 5 """ @@ -4583,14 +4583,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.P8() - sage: len(list(M.coextensions())) + sage: M = matroids.named_matroids.P8() # optional - sage.libs.pari + sage: len(list(M.coextensions())) # optional - sage.libs.pari 1705 - sage: len(list(M.coextensions(coline_length=4))) + sage: len(list(M.coextensions(coline_length=4))) # optional - sage.libs.pari 41 - sage: sorted(M.groundset()) + sage: sorted(M.groundset()) # optional - sage.libs.pari ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] - sage: len(list(M.coextensions(subsets=[{'a', 'b'}], coline_length=4))) + sage: len(list(M.coextensions(subsets=[{'a', 'b'}], coline_length=4))) # optional - sage.libs.pari 5 """ @@ -4624,8 +4624,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().contract('a') - sage: M.size() - M.simplify().size() + sage: M = matroids.named_matroids.Fano().contract('a') # optional - sage.libs.pari + sage: M.size() - M.simplify().size() # optional - sage.libs.pari 3 """ @@ -4663,8 +4663,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual().delete('a') - sage: M.cosimplify().size() + sage: M = matroids.named_matroids.Fano().dual().delete('a') # optional - sage.libs.pari + sage: M.cosimplify().size() # optional - sage.libs.pari 3 """ @@ -4698,11 +4698,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.is_simple() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.is_simple() # optional - sage.libs.pari True - sage: N = M / 'a' - sage: N.is_simple() + sage: N = M / 'a' # optional - sage.libs.pari + sage: N.is_simple() # optional - sage.libs.pari False """ if self._closure(frozenset()): @@ -4734,11 +4734,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual() - sage: M.is_cosimple() + sage: M = matroids.named_matroids.Fano().dual() # optional - sage.libs.pari + sage: M.is_cosimple() # optional - sage.libs.pari True - sage: N = M \ 'a' - sage: N.is_cosimple() + sage: N = M \ 'a' # optional - sage.libs.pari + sage: N.is_cosimple() # optional - sage.libs.pari False """ if self._coclosure(frozenset()): @@ -5281,14 +5281,14 @@ cdef class Matroid(SageObject): (False, True) sage: matroids.Uniform(4, 8).is_4connected() True - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.libs.pari ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M.is_4connected() == M.is_4connected(algorithm="shifting") + sage: M.is_4connected() == M.is_4connected(algorithm="shifting") # optional - sage.libs.pari True - sage: M.is_4connected() == M.is_4connected(algorithm="intersection") + sage: M.is_4connected() == M.is_4connected(algorithm="intersection") # optional - sage.libs.pari True """ if algorithm is None or algorithm == "intersection": @@ -5636,18 +5636,18 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.libs.pari ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M._shifting_all(M.basis(),set([0,1]),set([0,1]),set([]),set([]),3) + sage: M._shifting_all(M.basis(),set([0,1]),set([0,1]),set([]),set([]),3) # optional - sage.libs.pari (False, None) - sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], + sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], # optional - sage.libs.pari ....: [1,1,1,1,0], ....: [0,1,1,1,0], ....: [0,0,0,1,1]]) - sage: M._shifting_all(M.basis(), set([0,1]), set([5,8]), set([]), set([]), 3)[0] + sage: M._shifting_all(M.basis(), set([0,1]), set([5,8]), set([]), set([]), 3)[0] # optional - sage.libs.pari True """ @@ -5696,18 +5696,18 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.libs.pari ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M._shifting(M.basis(),set([0,1]),set([0,1]),set([]),set([]),3) + sage: M._shifting(M.basis(),set([0,1]),set([0,1]),set([]),set([]),3) # optional - sage.libs.pari (False, None) - sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], + sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], # optional - sage.libs.pari ....: [1,1,1,1,0], ....: [0,1,1,1,0], ....: [0,0,0,1,1]]) - sage: M._shifting(M.basis(), set([0,1]), set([5,8]), set([]), set([4]), 3)[0] + sage: M._shifting(M.basis(), set([0,1]), set([5,8]), set([]), set([4]), 3)[0] # optional - sage.libs.pari True """ @@ -5791,8 +5791,8 @@ cdef class Matroid(SageObject): False sage: matroids.named_matroids.BetsyRoss()._is_3connected_BC() True - sage: M = matroids.named_matroids.R6() - sage: M._is_3connected_BC() + sage: M = matroids.named_matroids.R6() # optional - sage.libs.pari + sage: M._is_3connected_BC() # optional - sage.libs.pari False """ # The 5 stages of the algorithm @@ -5837,9 +5837,9 @@ cdef class Matroid(SageObject): sage: M._is_3connected_BC_recursion(B, ....: [M.fundamental_cocircuit(B, e) for e in B]) True - sage: M = matroids.named_matroids.R6() - sage: B = M.basis() - sage: M._is_3connected_BC_recursion(B, + sage: M = matroids.named_matroids.R6() # optional - sage.libs.pari + sage: B = M.basis() # optional - sage.libs.pari + sage: M._is_3connected_BC_recursion(B, # optional - sage.libs.pari ....: [M.fundamental_cocircuit(B, e) for e in B]) False @@ -5929,13 +5929,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() - sage: M = N._local_binary_matroid() - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) + sage: N = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M = N._local_binary_matroid() # optional - sage.libs.pari + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.libs.pari True - sage: N = matroids.named_matroids.NonFano() - sage: M = N._local_binary_matroid() - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) + sage: N = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M = N._local_binary_matroid() # optional - sage.libs.pari + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.libs.pari False """ if basis is None: @@ -5987,11 +5987,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.binary_matroid() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.binary_matroid() # optional - sage.libs.pari Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) - sage: N = matroids.named_matroids.NonFano() - sage: N.binary_matroid() is None + sage: N = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: N.binary_matroid() is None # optional - sage.libs.pari True """ @@ -6039,11 +6039,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() - sage: N.is_binary() + sage: N = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N.is_binary() # optional - sage.libs.pari True - sage: N = matroids.named_matroids.NonFano() - sage: N.is_binary() + sage: N = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: N.is_binary() # optional - sage.libs.pari False """ @@ -6080,13 +6080,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() - sage: M = N._local_ternary_matroid() - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) + sage: N = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M = N._local_ternary_matroid() # optional - sage.libs.pari + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.libs.pari False - sage: N = matroids.named_matroids.NonFano() - sage: M = N._local_ternary_matroid() - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) + sage: N = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M = N._local_ternary_matroid() # optional - sage.libs.pari + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.libs.pari True """ if basis is None: @@ -6172,11 +6172,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.ternary_matroid() is None + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.ternary_matroid() is None # optional - sage.libs.pari True - sage: N = matroids.named_matroids.NonFano() - sage: N.ternary_matroid() + sage: N = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: N.ternary_matroid() # optional - sage.libs.pari NonFano: Ternary matroid of rank 3 on 7 elements, type 0- """ @@ -6224,11 +6224,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() - sage: N.is_ternary() + sage: N = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N.is_ternary() # optional - sage.libs.pari False - sage: N = matroids.named_matroids.NonFano() - sage: N.is_ternary() + sage: N = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: N.is_ternary() # optional - sage.libs.pari True """ @@ -6392,15 +6392,15 @@ cdef class Matroid(SageObject): sage: M = matroids.Uniform(2,4) sage: [M.is_chordal(i) for i in range(4, 8)] [True, True, True, True] - sage: M = matroids.named_matroids.NonFano() - sage: [M.is_chordal(i) for i in range(4, 8)] + sage: M = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: [M.is_chordal(i) for i in range(4, 8)] # optional - sage.libs.pari [False, True, True, True] - sage: M = matroids.named_matroids.N2() - sage: [M.is_chordal(i) for i in range(4, 10)] + sage: M = matroids.named_matroids.N2() # optional - sage.libs.pari + sage: [M.is_chordal(i) for i in range(4, 10)] # optional - sage.libs.pari [False, False, False, False, True, True] - sage: M.is_chordal(4, 5) + sage: M.is_chordal(4, 5) # optional - sage.libs.pari False - sage: M.is_chordal(4, 5, certificate=True) + sage: M.is_chordal(4, 5, certificate=True) # optional - sage.libs.pari (False, frozenset({'a', 'b', 'e', 'f', 'g'})) """ cdef frozenset C @@ -6428,11 +6428,11 @@ cdef class Matroid(SageObject): sage: M = matroids.Uniform(2,4) sage: M.chordality() 4 - sage: M = matroids.named_matroids.NonFano() - sage: M.chordality() + sage: M = matroids.named_matroids.NonFano() # optional - sage.libs.pari + sage: M.chordality() # optional - sage.libs.pari 5 - sage: M = matroids.named_matroids.Fano() - sage: M.chordality() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.chordality() # optional - sage.libs.pari 4 """ cdef frozenset C @@ -6474,14 +6474,14 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() - sage: X = M.max_weight_independent() - sage: M.is_basis(X) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: X = M.max_weight_independent() # optional - sage.libs.pari + sage: M.is_basis(X) # optional - sage.libs.pari True sage: wt = {'a': 1, 'b': 2, 'c': 2, 'd': 1/2, 'e': 1, ....: 'f': 2, 'g': 2} - sage: setprint(M.max_weight_independent(weights=wt)) + sage: setprint(M.max_weight_independent(weights=wt)) # optional - sage.libs.pari {'b', 'f', 'g'} sage: def wt(x): ....: return x @@ -6561,18 +6561,18 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() - sage: X = M.max_weight_coindependent() - sage: M.is_cobasis(X) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: X = M.max_weight_coindependent() # optional - sage.libs.pari + sage: M.is_cobasis(X) # optional - sage.libs.pari True sage: wt = {'a': 1, 'b': 2, 'c': 2, 'd': 1/2, 'e': 1, 'f': 2, ....: 'g': 2} - sage: setprint(M.max_weight_coindependent(weights=wt)) + sage: setprint(M.max_weight_coindependent(weights=wt)) # optional - sage.libs.pari {'b', 'c', 'f', 'g'} sage: wt = {'a': 1, 'b': -10, 'c': 2, 'd': 1/2, 'e': 1, 'f': 2, ....: 'g': 2} - sage: setprint(M.max_weight_coindependent(weights=wt)) + sage: setprint(M.max_weight_coindependent(weights=wt)) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: nonnegative weights were expected. @@ -6660,8 +6660,8 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() - sage: M.is_max_weight_independent_generic() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.is_max_weight_independent_generic() # optional - sage.libs.pari False sage: def wt(x): @@ -6810,8 +6810,8 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() - sage: M.is_max_weight_coindependent_generic() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.is_max_weight_coindependent_generic() # optional - sage.libs.pari False sage: def wt(x): @@ -6958,18 +6958,18 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari sage: w = {'a':30, 'b':10, 'c':11, 'd':20, 'e':70, 'f':21, 'g':90, ....: 'h':12, 'i':80, 'j':13, 'k':40, 'l':21} - sage: Y = M.intersection(N, w) - sage: sorted(Y) + sage: Y = M.intersection(N, w) # optional - sage.libs.pari + sage: sorted(Y) # optional - sage.libs.pari ['a', 'd', 'e', 'g', 'i', 'k'] - sage: sum([w[y] for y in Y]) + sage: sum([w[y] for y in Y]) # optional - sage.libs.pari 330 - sage: M = matroids.named_matroids.Fano() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari sage: N = matroids.Uniform(4, 7) - sage: M.intersection(N) + sage: M.intersection(N) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: matroid intersection requires equal groundsets. @@ -7017,14 +7017,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari sage: w = {'a':30, 'b':10, 'c':11, 'd':20, 'e':70, 'f':21, 'g':90, ....: 'h':12, 'i':80, 'j':13, 'k':40, 'l':21} - sage: Y = M._intersection(N, w) - sage: sorted(Y) + sage: Y = M._intersection(N, w) # optional - sage.libs.pari + sage: sorted(Y) # optional - sage.libs.pari ['a', 'd', 'e', 'g', 'i', 'k'] - sage: sum([w[y] for y in Y]) + sage: sum([w[y] for y in Y]) # optional - sage.libs.pari 330 """ Y = set() @@ -7063,14 +7063,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari sage: w = {'a':30, 'b':10, 'c':11, 'd':20, 'e':70, 'f':21, 'g':90, ....: 'h':12, 'i':80, 'j':13, 'k':40, 'l':21} - sage: Y = M.intersection(N, w) - sage: sorted(Y) + sage: Y = M.intersection(N, w) # optional - sage.libs.pari + sage: sorted(Y) # optional - sage.libs.pari ['a', 'd', 'e', 'g', 'i', 'k'] - sage: M._intersection_augmentation(N, w, Y)[0] + sage: M._intersection_augmentation(N, w, Y)[0] # optional - sage.libs.pari False """ X = self.groundset() - Y @@ -7144,13 +7144,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() - sage: len(M.intersection_unweighted(N)) + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari + sage: len(M.intersection_unweighted(N)) # optional - sage.libs.pari 6 - sage: M = matroids.named_matroids.Fano() - sage: N = matroids.Uniform(4, 7) - sage: M.intersection_unweighted(N) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: N = matroids.Uniform(4, 7) # optional - sage.libs.pari + sage: M.intersection_unweighted(N) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: matroid intersection requires equal groundsets. @@ -7185,9 +7185,9 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() - sage: len(M._intersection_unweighted(N)) + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari + sage: len(M._intersection_unweighted(N)) # optional - sage.libs.pari 6 """ Y = set() @@ -7219,15 +7219,15 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() - sage: Y = M.intersection(N) - sage: M._intersection_augmentation_unweighted(N, Y)[0] + sage: M = matroids.named_matroids.T12() # optional - sage.libs.pari + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.libs.pari + sage: Y = M.intersection(N) # optional - sage.libs.pari + sage: M._intersection_augmentation_unweighted(N, Y)[0] # optional - sage.libs.pari False - sage: Y = M._intersection_augmentation_unweighted(N,set()) - sage: Y[0] + sage: Y = M._intersection_augmentation_unweighted(N,set()) # optional - sage.libs.pari + sage: Y[0] # optional - sage.libs.pari True - sage: len(Y[1])>0 + sage: len(Y[1])>0 # optional - sage.libs.pari True """ E = self.groundset() @@ -7425,10 +7425,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted(M._internal({'a', 'b', 'c'})) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted(M._internal({'a', 'b', 'c'})) # optional - sage.libs.pari ['a', 'b', 'c'] - sage: sorted(M._internal({'e', 'f', 'g'})) + sage: sorted(M._internal({'e', 'f', 'g'})) # optional - sage.libs.pari [] """ N = self.groundset() - B @@ -7464,10 +7464,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: sorted(M._external({'a', 'b', 'c'})) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: sorted(M._external({'a', 'b', 'c'})) # optional - sage.libs.pari [] - sage: sorted(M._external({'e', 'f', 'g'})) + sage: sorted(M._external({'e', 'f', 'g'})) # optional - sage.libs.pari ['a', 'b', 'c', 'd'] """ @@ -7517,10 +7517,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M.tutte_polynomial() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.tutte_polynomial() # optional - sage.libs.pari y^4 + x^3 + 3*y^3 + 4*x^2 + 7*x*y + 6*y^2 + 3*x + 3*y - sage: M.tutte_polynomial(1, 1) == M.bases_count() + sage: M.tutte_polynomial(1, 1) == M.bases_count() # optional - sage.libs.pari True ALGORITHM: @@ -7565,8 +7565,8 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() - sage: setprint(M.flat_cover()) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: setprint(M.flat_cover()) # optional - sage.libs.pari [{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, {'d', 'e', 'f'}] @@ -7634,21 +7634,21 @@ cdef class Matroid(SageObject): We construct a more interesting example using the Fano matroid:: - sage: M = matroids.named_matroids.Fano() - sage: A = M.chow_ring(QQ) - sage: A + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: A = M.chow_ring(QQ) # optional - sage.libs.pari + sage: A # optional - sage.libs.pari Chow ring of Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) over Rational Field Next we get the non-trivial generators and do some computations:: - sage: G = A.gens()[6:] - sage: Ag, Aabf, Aace, Aadg, Abcd, Abeg, Acfg, Adef = G - sage: Ag * Ag + sage: G = A.gens()[6:] # optional - sage.libs.pari + sage: Ag, Aabf, Aace, Aadg, Abcd, Abeg, Acfg, Adef = G # optional - sage.libs.pari + sage: Ag * Ag # optional - sage.libs.pari 2*Adef^2 - sage: Ag * Abeg + sage: Ag * Abeg # optional - sage.libs.pari -Adef^2 - sage: matrix([[x * y for x in G] for y in G]) + sage: matrix([[x * y for x in G] for y in G]) # optional - sage.libs.pari [2*Adef^2 0 0 -Adef^2 0 -Adef^2 -Adef^2 0] [ 0 Adef^2 0 0 0 0 0 0] [ 0 0 Adef^2 0 0 0 0 0] @@ -7723,11 +7723,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M=matroids.named_matroids.Fano() - sage: G=M.plot() - sage: type(G) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: G = M.plot() # optional - sage.libs.pari sage.plot + sage: type(G) # optional - sage.libs.pari sage.plot - sage: G.show() + sage: G.show() # optional - sage.libs.pari sage.plot """ from . import matroids_plot_helpers @@ -7780,11 +7780,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M=matroids.named_matroids.TernaryDowling3() - sage: M.show(B=['a','b','c']) - sage: M.show(B=['a','b','c'],lineorders=[['f','e','i']]) - sage: pos = {'a':(0,0), 'b': (0,1), 'c':(1,0), 'd':(1,1), 'e':(1,-1), 'f':(-1,1), 'g':(-1,-1),'h':(2,0), 'i':(0,2)} - sage: M.show(pos_method=1, pos_dict=pos,lims=[-3,3,-3,3]) + sage: M = matroids.named_matroids.TernaryDowling3() # optional - sage.libs.pari + sage: M.show(B=['a','b','c']) # optional - sage.libs.pari sage.plot + sage: M.show(B=['a','b','c'], lineorders=[['f','e','i']]) # optional - sage.libs.pari sage.plot + sage: pos = {'a':(0,0), 'b': (0,1), 'c':(1,0), 'd':(1,1), # optional - sage.libs.pari sage.plot + ....: 'e':(1,-1), 'f':(-1,1), 'g':(-1,-1),'h':(2,0), 'i':(0,2)} + sage: M.show(pos_method=1, pos_dict=pos, lims=[-3,3,-3,3]) # optional - sage.libs.pari sage.plot """ if self.rank() > 3: raise NotImplementedError @@ -7886,8 +7887,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: B = M.bergman_complex(); B + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: B = M.bergman_complex(); B # optional - sage.libs.pari Simplicial complex with 14 vertices and 21 facets .. SEEALSO:: @@ -7925,8 +7926,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: A = M.augmented_bergman_complex(); A + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: A = M.augmented_bergman_complex(); A # optional - sage.libs.pari Simplicial complex with 22 vertices and 91 facets sage: M = matroids.Uniform(2,3) @@ -8059,7 +8060,7 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.named_matroids.Pappus() - sage: N = matroids.named_matroids.Fano().direct_sum(M); N + sage: N = matroids.named_matroids.Fano().direct_sum(M); N # optional - sage.libs.pari Matroid of rank 6 on 16 elements as matroid sum of Binary matroid of rank 3 on 7 elements, type (3, 0) Matroid of rank 3 on 9 elements with circuit-closures @@ -8067,9 +8068,9 @@ cdef class Matroid(SageObject): {'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'}, {'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}} - sage: len(N.independent_sets()) + sage: len(N.independent_sets()) # optional - sage.libs.pari 6897 - sage: len(N.bases()) + sage: len(N.bases()) # optional - sage.libs.pari 2100 """ from . import union_matroid diff --git a/src/sage/matroids/minor_matroid.py b/src/sage/matroids/minor_matroid.py index 907bb54356f..7c5cbbc55ba 100644 --- a/src/sage/matroids/minor_matroid.py +++ b/src/sage/matroids/minor_matroid.py @@ -13,23 +13,23 @@ EXAMPLES:: - sage: M = matroids.named_matroids.Fano() - sage: M \ ['a', 'c' ] == M.delete(['a', 'c']) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M \ ['a', 'c' ] == M.delete(['a', 'c']) # optional - sage.libs.pari True - sage: M / 'a' == M.contract('a') + sage: M / 'a' == M.contract('a') # optional - sage.libs.pari True - sage: M / 'c' \ 'ab' == M.minor(contractions='c', deletions='ab') + sage: M / 'c' \ 'ab' == M.minor(contractions='c', deletions='ab') # optional - sage.libs.pari True If a contraction set is not independent (or a deletion set not coindependent), this is taken care of:: - sage: M = matroids.named_matroids.Fano() - sage: M.rank('abf') + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.rank('abf') # optional - sage.libs.pari 2 - sage: M / 'abf' == M / 'ab' \ 'f' + sage: M / 'abf' == M / 'ab' \ 'f' # optional - sage.libs.pari True - sage: M / 'abf' == M / 'af' \ 'b' + sage: M / 'abf' == M / 'af' \ 'b' # optional - sage.libs.pari True .. SEEALSO:: @@ -132,9 +132,9 @@ def __init__(self, matroid, contractions=None, deletions=None): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = MinorMatroid(matroids.named_matroids.Fano(), # indirect doctest + sage: M = MinorMatroid(matroids.named_matroids.Fano(), # indirect doctest # optional - sage.libs.pari ....: contractions=set(), deletions=set(['g'])) - sage: M.is_isomorphic(matroids.Wheel(3)) + sage: M.is_isomorphic(matroids.Wheel(3)) # optional - sage.libs.pari True """ if not isinstance(matroid, Matroid): @@ -423,15 +423,15 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() - sage: M1 = MinorMatroid(M, set('ab'), set('f')) - sage: M2 = MinorMatroid(M, set('af'), set('b')) - sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) - sage: M1 == M2 # indirect doctest + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M1 = MinorMatroid(M, set('ab'), set('f')) # optional - sage.libs.pari + sage: M2 = MinorMatroid(M, set('af'), set('b')) # optional - sage.libs.pari + sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) # optional - sage.libs.pari + sage: M1 == M2 # indirect doctest # optional - sage.libs.pari False - sage: M1.equals(M2) + sage: M1.equals(M2) # optional - sage.libs.pari True - sage: M1 == M3 + sage: M1 == M3 # optional - sage.libs.pari True """ if not isinstance(other, MinorMatroid): @@ -455,15 +455,15 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() - sage: M1 = MinorMatroid(M, set('ab'), set('f')) - sage: M2 = MinorMatroid(M, set('af'), set('b')) - sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) - sage: M1 != M2 # indirect doctest + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M1 = MinorMatroid(M, set('ab'), set('f')) # optional - sage.libs.pari + sage: M2 = MinorMatroid(M, set('af'), set('b')) # optional - sage.libs.pari + sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) # optional - sage.libs.pari + sage: M1 != M2 # indirect doctest # optional - sage.libs.pari True - sage: M1.equals(M2) + sage: M1.equals(M2) # optional - sage.libs.pari True - sage: M1 != M3 + sage: M1 != M3 # optional - sage.libs.pari False """ return not self == other diff --git a/src/sage/matroids/set_system.pyx b/src/sage/matroids/set_system.pyx index d183f6ed5d1..9b68cfe342d 100644 --- a/src/sage/matroids/set_system.pyx +++ b/src/sage/matroids/set_system.pyx @@ -38,8 +38,8 @@ cdef class SetSystem: contents. One is most likely to encounter these as output from some Matroid methods:: - sage: M = matroids.named_matroids.Fano() - sage: M.circuits() + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: M.circuits() # optional - sage.libs.pari Iterator over a system of subsets To access the sets in this structure, simply iterate over them. The @@ -729,11 +729,11 @@ cdef class SetSystem: Check that :trac:`15189` is fixed:: - sage: M = Matroid(ring=GF(5), reduced_matrix=[[1,0,3],[0,1,1],[1,1,0]]) - sage: N = Matroid(ring=GF(5), reduced_matrix=[[1,0,1],[0,1,1],[1,1,0]]) - sage: M.is_field_isomorphic(N) + sage: M = Matroid(ring=GF(5), reduced_matrix=[[1,0,3],[0,1,1],[1,1,0]]) # optional - sage.libs.pari + sage: N = Matroid(ring=GF(5), reduced_matrix=[[1,0,1],[0,1,1],[1,1,0]]) # optional - sage.libs.pari + sage: M.is_field_isomorphic(N) # optional - sage.libs.pari False - sage: any(M.is_field_isomorphism(N, p) for p in Permutations(range(6))) + sage: any(M.is_field_isomorphism(N, p) for p in Permutations(range(6))) # optional - sage.combinat sage.libs.pari False """ cdef long v diff --git a/src/sage/matroids/unpickling.pyx b/src/sage/matroids/unpickling.pyx index b37ae49a37f..8916067025c 100644 --- a/src/sage/matroids/unpickling.pyx +++ b/src/sage/matroids/unpickling.pyx @@ -211,11 +211,11 @@ def unpickle_binary_matrix(version, data): EXAMPLES:: sage: from sage.matroids.lean_matrix import * - sage: A = BinaryMatrix(2, 5) - sage: A == loads(dumps(A)) # indirect doctest + sage: A = BinaryMatrix(2, 5) # optional - sage.libs.pari + sage: A == loads(dumps(A)) # indirect doctest # optional - sage.libs.pari True - sage: C = BinaryMatrix(2, 2, Matrix(GF(2), [[1, 1], [0, 1]])) - sage: C == loads(dumps(C)) + sage: C = BinaryMatrix(2, 2, Matrix(GF(2), [[1, 1], [0, 1]])) # optional - sage.libs.pari + sage: C == loads(dumps(C)) # optional - sage.libs.pari True """ cdef BinaryMatrix A @@ -240,11 +240,11 @@ def unpickle_ternary_matrix(version, data): EXAMPLES:: sage: from sage.matroids.lean_matrix import * - sage: A = TernaryMatrix(2, 5) - sage: A == loads(dumps(A)) # indirect doctest + sage: A = TernaryMatrix(2, 5) # optional - sage.libs.pari + sage: A == loads(dumps(A)) # indirect doctest # optional - sage.libs.pari True - sage: C = TernaryMatrix(2, 2, Matrix(GF(3), [[1, 1], [0, 1]])) - sage: C == loads(dumps(C)) + sage: C = TernaryMatrix(2, 2, Matrix(GF(3), [[1, 1], [0, 1]])) # optional - sage.libs.pari + sage: C == loads(dumps(C)) # optional - sage.libs.pari True """ cdef TernaryMatrix A @@ -270,11 +270,11 @@ def unpickle_quaternary_matrix(version, data): EXAMPLES:: sage: from sage.matroids.lean_matrix import * - sage: A = QuaternaryMatrix(2, 5, ring=GF(4, 'x')) - sage: A == loads(dumps(A)) # indirect doctest + sage: A = QuaternaryMatrix(2, 5, ring=GF(4, 'x')) # optional - sage.libs.pari + sage: A == loads(dumps(A)) # indirect doctest # optional - sage.libs.pari True - sage: C = QuaternaryMatrix(2, 2, Matrix(GF(4, 'x'), [[1, 1], [0, 1]])) - sage: C == loads(dumps(C)) + sage: C = QuaternaryMatrix(2, 2, Matrix(GF(4, 'x'), [[1, 1], [0, 1]])) # optional - sage.libs.pari + sage: C == loads(dumps(C)) # optional - sage.libs.pari True """ cdef QuaternaryMatrix A @@ -388,12 +388,12 @@ def unpickle_linear_matroid(version, data): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.libs.pari ....: [0, 1, 1, 1, 3]])) - sage: M == loads(dumps(M)) # indirect doctest + sage: M == loads(dumps(M)) # indirect doctest # optional - sage.libs.pari True - sage: M.rename("U35") - sage: loads(dumps(M)) + sage: M.rename("U35") # optional - sage.libs.pari + sage: loads(dumps(M)) # optional - sage.libs.pari U35 """ if version != 0: @@ -434,12 +434,12 @@ def unpickle_binary_matroid(version, data): EXAMPLES:: - sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], + sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.libs.pari ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest + sage: M == loads(dumps(M)) # indirect doctest # optional - sage.libs.pari True - sage: M.rename("U34") - sage: loads(dumps(M)) + sage: M.rename("U34") # optional - sage.libs.pari + sage: loads(dumps(M)) # optional - sage.libs.pari U34 """ if version != 0: @@ -481,12 +481,12 @@ def unpickle_ternary_matroid(version, data): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], + sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.libs.pari ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest + sage: M == loads(dumps(M)) # indirect doctest # optional - sage.libs.pari True - sage: M.rename("U34") - sage: loads(dumps(M)) + sage: M.rename("U34") # optional - sage.libs.pari + sage: loads(dumps(M)) # optional - sage.libs.pari U34 """ if version != 0: @@ -528,16 +528,16 @@ def unpickle_quaternary_matroid(version, data): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = QuaternaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], + sage: M = QuaternaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.libs.pari ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest + sage: M == loads(dumps(M)) # indirect doctest # optional - sage.libs.pari True - sage: M.rename("U34") - sage: loads(dumps(M)) + sage: M.rename("U34") # optional - sage.libs.pari + sage: loads(dumps(M)) # optional - sage.libs.pari U34 - sage: M = QuaternaryMatroid(Matrix(GF(4, 'x'), [[1, 0, 1], + sage: M = QuaternaryMatroid(Matrix(GF(4, 'x'), [[1, 0, 1], # optional - sage.libs.pari ....: [1, 0, 1]])) - sage: loads(dumps(M)).representation() + sage: loads(dumps(M)).representation() # optional - sage.libs.pari [1 0 1] [1 0 1] """ diff --git a/src/sage/matroids/utilities.py b/src/sage/matroids/utilities.py index eb2999ea07b..a9764c86891 100644 --- a/src/sage/matroids/utilities.py +++ b/src/sage/matroids/utilities.py @@ -74,10 +74,10 @@ def setprint(X): Note that for iterables, the effect can be undesirable:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano().delete('efg') - sage: M.bases() + sage: M = matroids.named_matroids.Fano().delete('efg') # optional - sage.libs.pari + sage: M.bases() # optional - sage.libs.pari Iterator over a system of subsets - sage: setprint(M.bases()) + sage: setprint(M.bases()) # optional - sage.libs.pari [{'a', 'b', 'c'}, {'a', 'b', 'd'}, {'a', 'c', 'd'}] An exception was made for subclasses of SageObject:: @@ -215,20 +215,20 @@ def sanitize_contractions_deletions(matroid, contractions, deletions): sage: from sage.matroids.utilities import setprint sage: from sage.matroids.utilities import sanitize_contractions_deletions - sage: M = matroids.named_matroids.Fano() - sage: setprint(sanitize_contractions_deletions(M, 'abc', 'defg')) + sage: M = matroids.named_matroids.Fano() # optional - sage.libs.pari + sage: setprint(sanitize_contractions_deletions(M, 'abc', 'defg')) # optional - sage.libs.pari [{'a', 'b', 'c'}, {'d', 'e', 'f', 'g'}] - sage: setprint(sanitize_contractions_deletions(M, 'defg', 'abc')) + sage: setprint(sanitize_contractions_deletions(M, 'defg', 'abc')) # optional - sage.libs.pari [{'a', 'b', 'c', 'f'}, {'d', 'e', 'g'}] - sage: setprint(sanitize_contractions_deletions(M, [1, 2, 3], 'efg')) + sage: setprint(sanitize_contractions_deletions(M, [1, 2, 3], 'efg')) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: [1, 2, 3] is not a subset of the groundset - sage: setprint(sanitize_contractions_deletions(M, 'efg', [1, 2, 3])) + sage: setprint(sanitize_contractions_deletions(M, 'efg', [1, 2, 3])) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: [1, 2, 3] is not a subset of the groundset - sage: setprint(sanitize_contractions_deletions(M, 'ade', 'efg')) + sage: setprint(sanitize_contractions_deletions(M, 'ade', 'efg')) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: contraction and deletion sets are not disjoint. @@ -532,25 +532,25 @@ def lift_cross_ratios(A, lift_map=None): EXAMPLES:: sage: from sage.matroids.advanced import lift_cross_ratios, lift_map, LinearMatroid - sage: R = GF(7) - sage: to_sixth_root_of_unity = lift_map('sru') - sage: A = Matrix(R, [[1, 0, 6, 1, 2],[6, 1, 0, 0, 1],[0, 6, 3, 6, 0]]) - sage: A + sage: R = GF(7) # optional - sage.libs.pari + sage: to_sixth_root_of_unity = lift_map('sru') # optional - sage.rings.number_field + sage: A = Matrix(R, [[1, 0, 6, 1, 2],[6, 1, 0, 0, 1],[0, 6, 3, 6, 0]]) # optional - sage.libs.pari + sage: A # optional - sage.libs.pari [1 0 6 1 2] [6 1 0 0 1] [0 6 3 6 0] - sage: Z = lift_cross_ratios(A, to_sixth_root_of_unity) - sage: Z + sage: Z = lift_cross_ratios(A, to_sixth_root_of_unity) # optional - sage.libs.pari sage.rings.number_field + sage: Z # optional - sage.libs.pari sage.rings.number_field [ 1 0 1 1 1] [ 1 1 0 0 z] [ 0 -1 z 1 0] - sage: M = LinearMatroid(reduced_matrix = A) - sage: sorted(M.cross_ratios()) + sage: M = LinearMatroid(reduced_matrix=A) # optional - sage.libs.pari + sage: sorted(M.cross_ratios()) # optional - sage.libs.pari [3, 5] - sage: N = LinearMatroid(reduced_matrix = Z) - sage: sorted(N.cross_ratios()) + sage: N = LinearMatroid(reduced_matrix=Z) # optional - sage.libs.pari sage.rings.number_field + sage: sorted(N.cross_ratios()) # optional - sage.libs.pari sage.rings.number_field [-z + 1, z] - sage: M.is_isomorphism(N, {e:e for e in M.groundset()}) + sage: M.is_isomorphism(N, {e:e for e in M.groundset()}) # optional - sage.libs.pari sage.rings.number_field True """ @@ -690,8 +690,8 @@ def lift_map(target): EXAMPLES:: sage: from sage.matroids.utilities import lift_map - sage: lm = lift_map('gm') - sage: for x in lm: + sage: lm = lift_map('gm') # optional - sage.libs.pari sage.rings.number_field + sage: for x in lm: # optional - sage.libs.pari sage.rings.number_field ....: if (x == 1) is not (lm[x] == 1): ....: print('not a proper lift map') ....: for y in lm: diff --git a/src/sage/misc/binary_tree.pyx b/src/sage/misc/binary_tree.pyx index 8827cac9ef2..2dcbe15cb99 100644 --- a/src/sage/misc/binary_tree.pyx +++ b/src/sage/misc/binary_tree.pyx @@ -286,9 +286,9 @@ cdef class BinaryTree: sage: from sage.misc.binary_tree import BinaryTree sage: t = BinaryTree() - sage: t.insert(0,Matrix([[0,0],[1,1]])) - sage: t.insert(0,1) - sage: t.get(0) + sage: t.insert(0, Matrix([[0,0], [1,1]])) # optional - sage.modules + sage: t.insert(0, 1) + sage: t.get(0) # optional - sage.modules [0 0] [1 1] """ @@ -307,7 +307,7 @@ cdef class BinaryTree: sage: t = BinaryTree() sage: t.contains(1) False - sage: t.insert(1,1) + sage: t.insert(1, 1) sage: t.contains(1) True """ diff --git a/src/sage/misc/c3_controlled.pyx b/src/sage/misc/c3_controlled.pyx index ebadb070d1d..4e0a1cde628 100644 --- a/src/sage/misc/c3_controlled.pyx +++ b/src/sage/misc/c3_controlled.pyx @@ -196,21 +196,23 @@ key. We consider the smallest poset describing a class hierarchy admitting no MRO whatsoever:: - sage: P = Poset({10: [9,8,7], 9:[6,1], 8:[5,2], 7:[4,3], 6: [3,2], 5:[3,1], 4: [2,1] }, linear_extension=True, facade=True) + sage: P = Poset({10: [9,8,7], 9: [6,1], 8: [5,2], 7: [4,3], # optional - sage.combinat sage.graphs + ....: 6: [3,2], 5: [3,1], 4: [2,1]}, + ....: linear_extension=True, facade=True) And build a :class:`HierarchyElement` from it:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: x = HierarchyElement(10, P) + sage: x = HierarchyElement(10, P) # optional - sage.combinat sage.graphs Here are its bases:: - sage: HierarchyElement(10, P)._bases + sage: HierarchyElement(10, P)._bases # optional - sage.combinat sage.graphs [9, 8, 7] Using the standard ``C3`` algorithm fails:: - sage: x.mro_standard + sage: x.mro_standard # optional - sage.combinat sage.graphs Traceback (most recent call last): ... ValueError: Cannot merge the items 3, 3, 2. @@ -219,18 +221,19 @@ We also get a failure when we relabel `P` according to another linear extension. For easy relabelling, we first need to set an appropriate default linear extension for `P`:: - sage: linear_extension = list(reversed(IntegerRange(1,11))) - sage: P = P.with_linear_extension(linear_extension) - sage: list(P) + sage: linear_extension = list(reversed(IntegerRange(1, 11))) # optional - sage.combinat sage.graphs + sage: P = P.with_linear_extension(linear_extension) # optional - sage.combinat sage.graphs + sage: list(P) # optional - sage.combinat sage.graphs [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] Now we play with a specific linear extension of `P`:: - sage: Q = P.linear_extension([10, 9, 8, 7, 6, 5, 4, 1, 2, 3]).to_poset() - sage: Q.cover_relations() - [[10, 9], [10, 8], [10, 7], [9, 6], [9, 3], [8, 5], [8, 2], [7, 4], [7, 1], [6, 2], [6, 1], [5, 3], [5, 1], [4, 3], [4, 2]] - sage: x = HierarchyElement(10, Q) - sage: x.mro_standard + sage: Q = P.linear_extension([10, 9, 8, 7, 6, 5, 4, 1, 2, 3]).to_poset() # optional - sage.combinat sage.graphs + sage: Q.cover_relations() # optional - sage.combinat sage.graphs + [[10, 9], [10, 8], [10, 7], [9, 6], [9, 3], [8, 5], [8, 2], [7, 4], + [7, 1], [6, 2], [6, 1], [5, 3], [5, 1], [4, 3], [4, 2]] + sage: x = HierarchyElement(10, Q) # optional - sage.combinat sage.graphs + sage: x.mro_standard # optional - sage.combinat sage.graphs Traceback (most recent call last): ... ValueError: Cannot merge the items 2, 3, 3. @@ -238,43 +241,43 @@ Now we play with a specific linear extension of `P`:: On the other hand, both the instrumented ``C3`` algorithm, and the controlled ``C3`` algorithm give the desired MRO:: - sage: x.mro + sage: x.mro # optional - sage.combinat sage.graphs [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] - sage: x.mro_controlled + sage: x.mro_controlled # optional - sage.combinat sage.graphs [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] The above checks, and more, can be run with:: - sage: x._test_mro() + sage: x._test_mro() # optional - sage.combinat sage.graphs In practice, the control was achieved by adding the following bases:: - sage: x._bases + sage: x._bases # optional - sage.combinat sage.graphs [9, 8, 7] - sage: x._bases_controlled + sage: x._bases_controlled # optional - sage.combinat sage.graphs [9, 8, 7, 6, 5] Altogether, four bases were added for control:: - sage: sum(len(HierarchyElement(q, Q)._bases) for q in Q) + sage: sum(len(HierarchyElement(q, Q)._bases) for q in Q) # optional - sage.combinat sage.graphs 15 - sage: sum(len(HierarchyElement(q, Q)._bases_controlled) for q in Q) + sage: sum(len(HierarchyElement(q, Q)._bases_controlled) for q in Q) # optional - sage.combinat sage.graphs 19 This information can also be recovered with:: - sage: x.all_bases_len() + sage: x.all_bases_len() # optional - sage.combinat sage.graphs 15 - sage: x.all_bases_controlled_len() + sage: x.all_bases_controlled_len() # optional - sage.combinat sage.graphs 19 We now check that the ``C3`` algorithm fails for all linear extensions `l` of this poset, whereas both the instrumented and controlled ``C3`` algorithms succeed; along the way, we collect some statistics:: - sage: L = P.linear_extensions() - sage: stats = [] - sage: for l in L: + sage: L = P.linear_extensions() # optional - sage.combinat sage.graphs + sage: stats = [] # optional - sage.combinat sage.graphs + sage: for l in L: # optional - sage.combinat sage.graphs ....: x = HierarchyElement(10, l.to_poset()) ....: try: # Check that x.mro_standard always fails with a ValueError ....: x.mro_standard @@ -291,7 +294,7 @@ Depending on the linear extension `l` it was necessary to add between one and five bases for control; for example, `216` linear extensions required the addition of four bases:: - sage: sorted(Word(stats).evaluation_sparse()) + sage: sorted(Word(stats).evaluation_sparse()) # optional - sage.combinat sage.graphs [(1, 36), (2, 108), (3, 180), (4, 216), (5, 180)] We now consider a hierarchy of categories:: @@ -336,7 +339,7 @@ list below does not change radically, it's fine to just update this doctest:: sage: from sage.categories.category import category_sample - sage: sorted([C for C in category_sample() + sage: sorted([C for C in category_sample() # optional - sage.combinat sage.graphs sage.modules sage.rings.number_field ....: if len(C._super_categories_for_classes) != len(C.super_categories())], ....: key=str) [Category of affine weyl groups, @@ -545,9 +548,9 @@ cdef class CmpKeyNamed: EXAMPLES:: - sage: Algebras(GF(3))._cmp_key == Algebras(GF(5))._cmp_key # indirect doctest + sage: Algebras(GF(3))._cmp_key == Algebras(GF(5))._cmp_key # indirect doctest # optional - sage.libs.pari True - sage: Algebras(ZZ)._cmp_key != Algebras(GF(5))._cmp_key + sage: Algebras(ZZ)._cmp_key != Algebras(GF(5))._cmp_key # optional - sage.libs.pari True """ @@ -555,9 +558,9 @@ cdef class CmpKeyNamed: """ EXAMPLES:: - sage: Algebras(GF(3))._cmp_key == Algebras(GF(5))._cmp_key # indirect doctest + sage: Algebras(GF(3))._cmp_key == Algebras(GF(5))._cmp_key # indirect doctest # optional - sage.libs.pari True - sage: Algebras(ZZ)._cmp_key != Algebras(GF(5))._cmp_key + sage: Algebras(ZZ)._cmp_key != Algebras(GF(5))._cmp_key # optional - sage.libs.pari True """ @@ -951,6 +954,7 @@ cpdef tuple C3_sorted_merge(list lists, key=identity): #assert C3_merge(lists[:-1]+[suggestion_list]) == out return (out, suggestion_list) + class HierarchyElement(object, metaclass=ClasscallMetaclass): """ A class for elements in a hierarchy. @@ -988,7 +992,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): :class:`HopfAlgebrasWithBasis`:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: G = DiGraph({ + sage: G = DiGraph({ # optional - sage.graphs ....: 44 : [43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], ....: 43 : [42, 41, 40, 36, 35, 39, 38, 37, 33, 32, 31, 30, 29, 28, 27, 26, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], ....: 42 : [36, 35, 37, 30, 29, 28, 27, 26, 15, 14, 12, 11, 9, 8, 5, 3, 2, 1, 0], @@ -1036,12 +1040,12 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): ....: 0 : [], ....: }) - sage: x = HierarchyElement(44, G) - sage: x.mro + sage: x = HierarchyElement(44, G) # optional - sage.combinat sage.graphs + sage: x.mro # optional - sage.combinat sage.graphs [44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] - sage: x.cls + sage: x.cls # optional - sage.combinat sage.graphs - sage: x.cls.mro() + sage: x.cls.mro() # optional - sage.combinat sage.graphs [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , <... 'object'>] """ @staticmethod @@ -1050,13 +1054,13 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: x = HierarchyElement(10, P) - sage: x + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(10, P) # optional - sage.combinat sage.graphs + sage: x # optional - sage.combinat sage.graphs 10 - sage: x.bases + sage: x.bases # optional - sage.combinat sage.graphs [5, 2] - sage: x.mro + sage: x.mro # optional - sage.combinat sage.graphs [10, 5, 2, 1] """ from sage.categories.sets_cat import Sets @@ -1082,25 +1086,25 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: x = HierarchyElement(10, P) - sage: x + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(10, P) # optional - sage.combinat sage.graphs + sage: x # optional - sage.combinat sage.graphs 10 - sage: x.value + sage: x.value # optional - sage.combinat sage.graphs 10 - sage: x._bases + sage: x._bases # optional - sage.combinat sage.graphs [5, 2] - sage: x._key + sage: x._key # optional - sage.combinat sage.graphs - sage: x._key(10) + sage: x._key(10) # optional - sage.combinat sage.graphs 10 The ``_from_value`` attribute is a function that can be used to reconstruct an element of the hierarchy from its value:: - sage: x._from_value + sage: x._from_value # optional - sage.combinat sage.graphs Cached version of .f at ...> - sage: x._from_value(x.value) is x + sage: x._from_value(x.value) is x # optional - sage.combinat sage.graphs True """ self.value = value @@ -1115,9 +1119,9 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: x = HierarchyElement(10, P) - sage: x + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(10, P) # optional - sage.combinat sage.graphs + sage: x # optional - sage.combinat sage.graphs 10 """ return repr(self.value) @@ -1134,15 +1138,15 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: x = HierarchyElement(10, P) - sage: x.bases + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(10, P) # optional - sage.combinat sage.graphs + sage: x.bases # optional - sage.combinat sage.graphs [5, 2] - sage: type(x.bases[0]) + sage: type(x.bases[0]) # optional - sage.combinat sage.graphs - sage: x.mro + sage: x.mro # optional - sage.combinat sage.graphs [10, 5, 2, 1] - sage: x._bases_controlled + sage: x._bases_controlled # optional - sage.combinat sage.graphs [5, 2] """ return self._bases @@ -1155,23 +1159,23 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement, C3_sorted_merge, identity - sage: P = Poset({7: [5,6], 5:[1,2], 6: [3,4]}, facade = True) - sage: x = HierarchyElement(5, P) - sage: x.mro + sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(5, P) # optional - sage.combinat sage.graphs + sage: x.mro # optional - sage.combinat sage.graphs [5, 2, 1] - sage: x = HierarchyElement(6, P) - sage: x.mro + sage: x = HierarchyElement(6, P) # optional - sage.combinat sage.graphs + sage: x.mro # optional - sage.combinat sage.graphs [6, 4, 3] - sage: x = HierarchyElement(7, P) - sage: x.mro + sage: x = HierarchyElement(7, P) # optional - sage.combinat sage.graphs + sage: x.mro # optional - sage.combinat sage.graphs [7, 6, 5, 4, 3, 2, 1] - sage: C3_sorted_merge([[6, 4, 3], [5, 2, 1], [6, 5]], identity) + sage: C3_sorted_merge([[6, 4, 3], [5, 2, 1], [6, 5]], identity) # optional - sage.combinat sage.graphs ([6, 5, 4, 3, 2, 1], [6, 5, 4]) TESTS:: - sage: assert all(isinstance(v, Integer) for v in x.mro) + sage: assert all(isinstance(v, Integer) for v in x.mro) # optional - sage.combinat sage.graphs """ bases = self._bases result, suggestion = C3_sorted_merge([base.mro for base in bases]+[[base.value for base in bases]], key=self._key) @@ -1191,11 +1195,11 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset({7: [5,6], 5:[1,2], 6: [3,4]}, facade = True) - sage: x = HierarchyElement(7, P) - sage: x._bases + sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(7, P) # optional - sage.combinat sage.graphs + sage: x._bases # optional - sage.combinat sage.graphs [6, 5] - sage: x._bases_controlled + sage: x._bases_controlled # optional - sage.combinat sage.graphs [6, 5, 4] """ self.mro @@ -1209,22 +1213,22 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement, C3_merge - sage: P = Poset({7: [5,6], 5:[1,2], 6: [3,4]}, facade=True) - sage: x = HierarchyElement(5, P) - sage: x.mro_standard + sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(5, P) # optional - sage.combinat sage.graphs + sage: x.mro_standard # optional - sage.combinat sage.graphs [5, 2, 1] - sage: x = HierarchyElement(6, P) - sage: x.mro_standard + sage: x = HierarchyElement(6, P) # optional - sage.combinat sage.graphs + sage: x.mro_standard # optional - sage.combinat sage.graphs [6, 4, 3] - sage: x = HierarchyElement(7, P) - sage: x.mro_standard + sage: x = HierarchyElement(7, P) # optional - sage.combinat sage.graphs + sage: x.mro_standard # optional - sage.combinat sage.graphs [7, 6, 4, 3, 5, 2, 1] - sage: C3_merge([[6, 4, 3], [5, 2, 1], [6, 5]]) + sage: C3_merge([[6, 4, 3], [5, 2, 1], [6, 5]]) # optional - sage.combinat sage.graphs [6, 4, 3, 5, 2, 1] TESTS:: - sage: assert all(isinstance(v, Integer) for v in x.mro_standard) + sage: assert all(isinstance(v, Integer) for v in x.mro_standard) # optional - sage.combinat sage.graphs """ bases = self._bases return [self.value] + C3_merge([base.mro_standard for base in bases]+[[base.value for base in bases]]) @@ -1238,19 +1242,19 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement, C3_merge - sage: P = Poset({7: [5,6], 5:[1,2], 6: [3,4]}, facade=True) - sage: x = HierarchyElement(5, P) - sage: x.mro_controlled + sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(5, P) # optional - sage.combinat sage.graphs + sage: x.mro_controlled # optional - sage.combinat sage.graphs [5, 2, 1] - sage: x = HierarchyElement(6, P) - sage: x.mro_controlled + sage: x = HierarchyElement(6, P) # optional - sage.combinat sage.graphs + sage: x.mro_controlled # optional - sage.combinat sage.graphs [6, 4, 3] - sage: x = HierarchyElement(7, P) - sage: x.mro_controlled + sage: x = HierarchyElement(7, P) # optional - sage.combinat sage.graphs + sage: x.mro_controlled # optional - sage.combinat sage.graphs [7, 6, 5, 4, 3, 2, 1] - sage: x._bases + sage: x._bases # optional - sage.combinat sage.graphs [6, 5] - sage: x._bases_controlled + sage: x._bases_controlled # optional - sage.combinat sage.graphs [6, 5, 4] sage: C3_merge([[6, 4, 3], [5, 2, 1], [6, 5]]) [6, 4, 3, 5, 2, 1] @@ -1259,14 +1263,14 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): TESTS:: - sage: assert all(isinstance(v, Integer) for v in x.mro_controlled) + sage: assert all(isinstance(v, Integer) for v in x.mro_controlled) # optional - sage.combinat sage.graphs """ return [self.value] + C3_merge([base.mro_controlled for base in self._bases]+[self._bases_controlled]) @cached_method def _test_mro(self): r""" - Runs consistency tests. + Run consistency tests. This checks in particular that the instrumented ``C3`` and controlled ``C3`` algorithms give, as desired, the @@ -1281,9 +1285,9 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset({7: [5,6], 5:[1,2], 6: [3,4]}, facade=True) - sage: x = HierarchyElement(7, P) - sage: x._test_mro() + sage: P = Poset({7: [5, 6], 5: [1, 2], 6: [3, 4]}, facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(7, P) # optional - sage.combinat sage.graphs + sage: x._test_mro() # optional - sage.combinat sage.graphs """ for b in self._bases: b._test_mro() @@ -1305,17 +1309,17 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: - sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: x = HierarchyElement(1, P) - sage: x.cls + sage: from sage.misc.c3_controlled import HierarchyElement # optional - sage.combinat sage.graphs + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: x = HierarchyElement(1, P) # optional - sage.combinat sage.graphs + sage: x.cls # optional - sage.combinat sage.graphs - sage: x.cls.mro() + sage: x.cls.mro() # optional - sage.combinat sage.graphs [, <... 'object'>] - sage: x = HierarchyElement(30, P) - sage: x.cls + sage: x = HierarchyElement(30, P) # optional - sage.combinat sage.graphs + sage: x.cls # optional - sage.combinat sage.graphs - sage: x.cls.mro() + sage: x.cls.mro() # optional - sage.combinat sage.graphs [, , , , , , , , <... 'object'>] """ super_classes = tuple(self._from_value(base).cls for base in self._bases_controlled) @@ -1333,12 +1337,12 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: HierarchyElement(1, P).all_bases() + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: HierarchyElement(1, P).all_bases() # optional - sage.combinat sage.graphs {1} - sage: HierarchyElement(10, P).all_bases() # random output + sage: HierarchyElement(10, P).all_bases() # random output # optional - sage.combinat sage.graphs {10, 5, 2, 1} - sage: sorted([x.value for x in HierarchyElement(10, P).all_bases()]) + sage: sorted([x.value for x in HierarchyElement(10, P).all_bases()]) # optional - sage.combinat sage.graphs [1, 2, 5, 10] """ return {self} | { x for base in self._bases for x in base.all_bases() } @@ -1350,8 +1354,8 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: HierarchyElement(30, P).all_bases_len() + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: HierarchyElement(30, P).all_bases_len() # optional - sage.combinat sage.graphs 12 """ return sum( len(x._bases) for x in self.all_bases()) @@ -1363,8 +1367,8 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass): EXAMPLES:: sage: from sage.misc.c3_controlled import HierarchyElement - sage: P = Poset((divisors(30), lambda x,y: y.divides(x)), facade=True) - sage: HierarchyElement(30, P).all_bases_controlled_len() + sage: P = Poset((divisors(30), lambda x, y: y.divides(x)), facade=True) # optional - sage.combinat sage.graphs + sage: HierarchyElement(30, P).all_bases_controlled_len() # optional - sage.combinat sage.graphs 13 """ return sum( len(x._bases_controlled) for x in self.all_bases()) diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index 9715726659b..d795ee4f43f 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -46,15 +46,15 @@ the name that the wrapped method or function should have, since otherwise the name of the original function would be used:: - sage: cython('''cpdef test_funct(x): return -x''') # optional - sage.misc.cython - sage: wrapped_funct = cached_function(test_funct, name='wrapped_funct') # optional - sage.misc.cython - sage: wrapped_funct # optional - sage.misc.cython + sage: cython('''cpdef test_funct(x): return -x''') # optional - sage.misc.cython + sage: wrapped_funct = cached_function(test_funct, name='wrapped_funct') # optional - sage.misc.cython + sage: wrapped_funct # optional - sage.misc.cython Cached version of - sage: wrapped_funct.__name__ # optional - sage.misc.cython + sage: wrapped_funct.__name__ # optional - sage.misc.cython 'wrapped_funct' - sage: wrapped_funct(5) # optional - sage.misc.cython + sage: wrapped_funct(5) # optional - sage.misc.cython -5 - sage: wrapped_funct(5) is wrapped_funct(5) # optional - sage.misc.cython + sage: wrapped_funct(5) is wrapped_funct(5) # optional - sage.misc.cython True We can proceed similarly for cached methods of Cython classes, @@ -77,21 +77,21 @@ approach is still needed for cpdef methods:: ....: ' "Some doc for direct method"', ....: ' return 2*x', ....: ' wrapped_method = cached_method(test_meth,name="wrapped_method")'] - sage: cython(os.linesep.join(cython_code)) # optional - sage.misc.cython - sage: O = MyClass() # optional - sage.misc.cython - sage: O.direct_method # optional - sage.misc.cython + sage: cython(os.linesep.join(cython_code)) # optional - sage.misc.cython + sage: O = MyClass() # optional - sage.misc.cython + sage: O.direct_method # optional - sage.misc.cython Cached version of - sage: O.wrapped_method # optional - sage.misc.cython + sage: O.wrapped_method # optional - sage.misc.cython Cached version of - sage: O.wrapped_method.__name__ # optional - sage.misc.cython + sage: O.wrapped_method.__name__ # optional - sage.misc.cython 'wrapped_method' - sage: O.wrapped_method(5) # optional - sage.misc.cython + sage: O.wrapped_method(5) # optional - sage.misc.cython -5 - sage: O.wrapped_method(5) is O.wrapped_method(5) # optional - sage.misc.cython + sage: O.wrapped_method(5) is O.wrapped_method(5) # optional - sage.misc.cython True - sage: O.direct_method(5) # optional - sage.misc.cython + sage: O.direct_method(5) # optional - sage.misc.cython 10 - sage: O.direct_method(5) is O.direct_method(5) # optional - sage.misc.cython + sage: O.direct_method(5) is O.direct_method(5) # optional - sage.misc.cython True In some cases, one would only want to keep the result in cache as long @@ -129,8 +129,8 @@ category (previously, the cache would have been broken):: ....: " @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: cython('\n'.join(cython_code)) # optional - sage.misc.cython + sage: C = MyCategory() # optional - sage.misc.cython In order to keep the memory footprint of elements small, it was decided to not support the same freedom of using cached methods @@ -181,88 +181,88 @@ hardly by used. ....: "from sage.structure.parent cimport Parent", ....: "cdef class MyParent(Parent):", ....: " Element = MyElement"] - sage: cython('\n'.join(cython_code)) # 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: 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 the parent works:: - sage: P.one() # optional - sage.misc.cython + sage: P.one() # optional - sage.misc.cython <1> - sage: P.one() is P.one() # optional - sage.misc.cython + sage: P.one() is P.one() # optional - sage.misc.cython True - sage: P.invert(e) # optional - sage.misc.cython + sage: P.invert(e) # optional - sage.misc.cython <-5> - sage: P.invert(e) is P.invert(e) # optional - sage.misc.cython + sage: P.invert(e) is P.invert(e) # optional - sage.misc.cython True 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 ``cached_in_parent_method``, since the cache is stored in the 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 The cache can be emptied:: - sage: a = test_pfunc(5) # optional - sage.misc.cython - sage: test_pfunc.clear_cache() # optional - sage.misc.cython - sage: a is test_pfunc(5) # optional - sage.misc.cython + sage: a = test_pfunc(5) # optional - sage.misc.cython + sage: test_pfunc.clear_cache() # optional - sage.misc.cython + sage: a is test_pfunc(5) # optional - sage.misc.cython False - sage: a = P.one() # optional - sage.misc.cython - sage: P.one.clear_cache() # optional - sage.misc.cython - sage: a is P.one() # optional - sage.misc.cython + sage: a = P.one() # optional - sage.misc.cython + sage: P.one.clear_cache() # optional - sage.misc.cython + sage: a is P.one() # 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 Introspection works:: sage: from sage.misc.edit_module import file_and_line sage: from sage.misc.sageinspect import sage_getdoc, sage_getfile, sage_getsource - sage: print(sage_getdoc(test_pfunc)) # optional - sage.misc.cython + sage: print(sage_getdoc(test_pfunc)) # optional - sage.misc.cython Some documentation - sage: print(sage_getdoc(O.wrapped_method)) # optional - sage.misc.cython + sage: print(sage_getdoc(O.wrapped_method)) # optional - sage.misc.cython some doc for a wrapped cython method - sage: print(sage_getdoc(O.direct_method)) # optional - sage.misc.cython + sage: print(sage_getdoc(O.direct_method)) # optional - sage.misc.cython Some doc for direct method - sage: print(sage_getsource(O.wrapped_method)) # optional - sage.misc.cython + sage: print(sage_getsource(O.wrapped_method)) # optional - sage.misc.cython cpdef test_meth(self,x): "some doc for a wrapped cython method" return -x - sage: print(sage_getsource(O.direct_method)) # optional - sage.misc.cython + sage: print(sage_getsource(O.direct_method)) # optional - sage.misc.cython def direct_method(self, x): "Some doc for direct method" return 2*x @@ -304,11 +304,11 @@ latter is easy:: ....: " @cached_method", ....: " def f(self, a,b):", ....: " return a*b"] - sage: cython(os.linesep.join(cython_code)) # optional - sage.misc.cython - sage: P = MyClass() # optional - sage.misc.cython - sage: P.f(2, 3) # optional - sage.misc.cython + sage: cython(os.linesep.join(cython_code)) # optional - sage.misc.cython + sage: P = MyClass() # optional - sage.misc.cython + sage: P.f(2, 3) # optional - sage.misc.cython 6 - sage: P.f(2, 3) is P.f(2, 3) # optional - sage.misc.cython + sage: P.f(2, 3) is P.f(2, 3) # optional - sage.misc.cython True Providing attribute access is a bit more tricky, since it is needed that @@ -333,19 +333,19 @@ enough in the following example:: ....: " @cached_method", ....: " def f(self, a,b):", ....: " return a+b"] - sage: cython(os.linesep.join(cython_code)) # optional - sage.misc.cython - sage: Q = MyOtherClass() # optional - sage.misc.cython - sage: Q.f(2, 3) # optional - sage.misc.cython + sage: cython(os.linesep.join(cython_code)) # optional - sage.misc.cython + sage: Q = MyOtherClass() # optional - sage.misc.cython + sage: Q.f(2, 3) # optional - sage.misc.cython 5 - sage: Q.f(2, 3) is Q.f(2, 3) # optional - sage.misc.cython + sage: Q.f(2, 3) is Q.f(2, 3) # optional - sage.misc.cython True Note that supporting attribute access is somehow faster than the easier method:: - sage: timeit("a = P.f(2,3)") # random # optional - sage.misc.cython + sage: timeit("a = P.f(2,3)") # random # optional - sage.misc.cython 625 loops, best of 3: 1.3 µs per loop - sage: timeit("a = Q.f(2,3)") # random # optional - sage.misc.cython + sage: timeit("a = Q.f(2,3)") # random # optional - sage.misc.cython 625 loops, best of 3: 931 ns per loop Some immutable objects (such as `p`-adic numbers) cannot implement a @@ -353,18 +353,18 @@ reasonable hash function because their ``==`` operator has been modified to return ``True`` for objects which might behave differently in some computations:: - sage: K. = Qq(9) # optional - sage.rings.padics - sage: b = a.add_bigoh(1) # optional - sage.rings.padics - sage: c = a + 3 # optional - sage.rings.padics - sage: b # optional - sage.rings.padics + sage: K. = Qq(9) # optional - sage.rings.padics + sage: b = a.add_bigoh(1) # optional - sage.rings.padics + sage: c = a + 3 # optional - sage.rings.padics + sage: b # optional - sage.rings.padics a + O(3) - sage: c # optional - sage.rings.padics + sage: c # optional - sage.rings.padics a + 3 + O(3^20) - sage: b == c # optional - sage.rings.padics + sage: b == c # optional - sage.rings.padics True - sage: b == a # optional - sage.rings.padics + sage: b == a # optional - sage.rings.padics True - sage: c == a # optional - sage.rings.padics + sage: c == a # optional - sage.rings.padics False If such objects defined a non-trivial hash function, this would break @@ -372,20 +372,20 @@ caching in many places. However, such objects should still be usable in caches. This can be achieved by defining an appropriate method ``_cache_key``:: - sage: hash(b) # optional - sage.rings.padics + sage: hash(b) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' sage: @cached_method ....: def f(x): return x == a - sage: f(b) # optional - sage.rings.padics + sage: f(b) # optional - sage.rings.padics True - sage: f(c) # if b and c were hashable, this would return True # optional - sage.rings.padics + sage: f(c) # if b and c were hashable, this would return True # optional - sage.rings.padics False - sage: b._cache_key() # optional - sage.rings.padics + sage: b._cache_key() # optional - sage.rings.padics (..., ((0, 1),), 0, 1) - sage: c._cache_key() # optional - sage.rings.padics + sage: c._cache_key() # optional - sage.rings.padics (..., ((0, 1), (1,)), 0, 20) .. NOTE:: @@ -398,9 +398,9 @@ if ``a != b``, then also ``a._cache_key() != b._cache_key()``. In practice this means that the ``_cache_key`` should always include the parent as its first argument:: - sage: S. = Qq(4) # optional - sage.rings.padics - sage: d = a.add_bigoh(1) # optional - sage.rings.padics - sage: b._cache_key() == d._cache_key() # this would be True if the parents were not included # optional - sage.rings.padics + sage: S. = Qq(4) # optional - sage.rings.padics + sage: d = a.add_bigoh(1) # optional - sage.rings.padics + sage: b._cache_key() == d._cache_key() # this would be True if the parents were not included # optional - sage.rings.padics False """ @@ -537,8 +537,8 @@ cpdef inline dict_key(o): sage: from sage.misc.cachefunc import dict_key sage: dict_key(42) 42 - sage: K. = Qq(9) # optional - sage.rings.padics - sage: dict_key(u) # optional - sage.rings.padics + sage: K. = Qq(9) # optional - sage.rings.padics + sage: dict_key(u) # optional - sage.rings.padics (, (..., 20)) """ try: @@ -561,24 +561,24 @@ cpdef inline cache_key(o): EXAMPLES:: sage: from sage.misc.cachefunc import cache_key - sage: K. = Qq(9) # optional - sage.rings.padics - sage: a = K(1); a # optional - sage.rings.padics + sage: K. = Qq(9) # optional - sage.rings.padics + sage: a = K(1); a # optional - sage.rings.padics 1 + O(3^20) - sage: cache_key(a) # optional - sage.rings.padics + sage: cache_key(a) # optional - sage.rings.padics (..., ((1,),), 0, 20) This function works if ``o`` is a tuple. In this case it unpacks its entries recursively:: - sage: o = (1, 2, (3, a)) # optional - sage.rings.padics - sage: cache_key(o) # optional - sage.rings.padics + sage: o = (1, 2, (3, a)) # optional - sage.rings.padics + sage: cache_key(o) # optional - sage.rings.padics (1, 2, (3, (..., ((1,),), 0, 20))) Note that tuples are only partially unpacked if some of its entries are hashable:: - sage: o = (1/2, a) # optional - sage.rings.padics - sage: cache_key(o) # optional - sage.rings.padics + sage: o = (1/2, a) # optional - sage.rings.padics + sage: cache_key(o) # optional - sage.rings.padics (1/2, (..., ((1,),), 0, 20)) """ try: @@ -688,14 +688,14 @@ cdef class CachedFunction(): TESTS:: - sage: g = CachedFunction(number_of_partitions) - sage: g.__name__ + sage: g = CachedFunction(number_of_partitions) # optional - sage.combinat + sage: g.__name__ # optional - sage.combinat 'number_of_partitions' - sage: 'partitions' in sage.misc.sageinspect.sage_getdoc(g) + sage: 'partitions' in sage.misc.sageinspect.sage_getdoc(g) # optional - sage.combinat True - sage: g(5) + sage: g(5) # optional - sage.combinat 7 - sage: g.cache + sage: g.cache # optional - sage.combinat {((5, 'default'), ()): 7} sage: def f(t=1): print(t) sage: h = CachedFunction(f) @@ -850,6 +850,7 @@ cdef class CachedFunction(): sage: I = P*[x,y] sage: from sage.misc.sageinspect import sage_getdoc sage: print(sage_getdoc(I.groebner_basis)) # indirect doctest + WARNING: the enclosing module is marked... Return the reduced Groebner basis of this ideal. ... @@ -896,8 +897,8 @@ cdef class CachedFunction(): TESTS:: sage: from sage.misc.sageinspect import sage_getsource - sage: g = CachedFunction(number_of_partitions) - sage: 'flint' in sage_getsource(g) # indirect doctest + sage: g = CachedFunction(number_of_partitions) # optional - sage.combinat + sage: 'flint' in sage_getsource(g) # indirect doctest # optional - sage.combinat True """ @@ -948,16 +949,16 @@ cdef class CachedFunction(): TESTS:: - sage: g = CachedFunction(number_of_partitions) - sage: a = g(5) - sage: g.cache + sage: g = CachedFunction(number_of_partitions) # optional - sage.combinat + sage: a = g(5) # optional - sage.combinat + sage: g.cache # optional - sage.combinat {((5, 'default'), ()): 7} - sage: a = g(10^5) # indirect doctest - sage: a == number_of_partitions(10^5) + sage: a = g(10^5) # indirect doctest # optional - sage.combinat + sage: a == number_of_partitions(10^5) # optional - sage.combinat True - sage: a is g(10^5) + sage: a is g(10^5) # optional - sage.combinat True - sage: a is number_of_partitions(10^5) + sage: a is number_of_partitions(10^5) # optional - sage.combinat True Check that :trac:`16316` has been fixed, i.e., caching works for @@ -966,16 +967,16 @@ cdef class CachedFunction(): sage: @cached_function ....: def f(x): return x+x - sage: K. = Qq(4) # optional - sage.rings.padics - sage: x = K(1,1); x # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: x = K(1,1); x # optional - sage.rings.padics 1 + O(2) - sage: y = K(1,2); y # optional - sage.rings.padics + sage: y = K(1,2); y # optional - sage.rings.padics 1 + O(2^2) - sage: x == y # optional - sage.rings.padics + sage: x == y # optional - sage.rings.padics True - sage: f(x) is f(x) # optional - sage.rings.padics + sage: f(x) is f(x) # optional - sage.rings.padics True - sage: f(y) is not f(x) # optional - sage.rings.padics + sage: f(y) is not f(x) # optional - sage.rings.padics True """ @@ -1047,14 +1048,14 @@ cdef class CachedFunction(): sage: @cached_function ....: def f(x): return x - sage: K. = Qq(4) # optional - sage.rings.padics - sage: x = K(1,1); x # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: x = K(1,1); x # optional - sage.rings.padics 1 + O(2) - sage: f.is_in_cache(x) # optional - sage.rings.padics + sage: f.is_in_cache(x) # optional - sage.rings.padics False - sage: f(x) # optional - sage.rings.padics + sage: f(x) # optional - sage.rings.padics 1 + O(2) - sage: f.is_in_cache(x) # optional - sage.rings.padics + sage: f.is_in_cache(x) # optional - sage.rings.padics True """ @@ -1073,14 +1074,14 @@ cdef class CachedFunction(): EXAMPLES:: - sage: g = CachedFunction(number_of_partitions) - sage: a = g(5) - sage: g.cache + sage: g = CachedFunction(number_of_partitions) # optional - sage.combinat + sage: a = g(5) # optional - sage.combinat + sage: g.cache # optional - sage.combinat {((5, 'default'), ()): 7} - sage: g.set_cache(17, 5) - sage: g.cache + sage: g.set_cache(17, 5) # optional - sage.combinat + sage: g.cache # optional - sage.combinat {((5, 'default'), ()): 17} - sage: g(5) + sage: g(5) # optional - sage.combinat 17 TESTS: @@ -1091,11 +1092,11 @@ cdef class CachedFunction(): sage: @cached_function ....: def f(x): return x - sage: K. = Qq(4) # optional - sage.rings.padics - sage: x = K(1,1); x # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: x = K(1,1); x # optional - sage.rings.padics 1 + O(2) - sage: f.set_cache(x, x) # optional - sage.rings.padics - sage: f.is_in_cache(x) # optional - sage.rings.padics + sage: f.set_cache(x, x) # optional - sage.rings.padics + sage: f.is_in_cache(x) # optional - sage.rings.padics True DEVELOPER NOTE: @@ -1174,8 +1175,8 @@ cdef class CachedFunction(): """ EXAMPLES:: - sage: g = CachedFunction(number_of_partitions) - sage: g # indirect doctest + sage: g = CachedFunction(number_of_partitions) # optional - sage.combinat + sage: g # indirect doctest # optional - sage.combinat Cached version of """ try: @@ -1189,12 +1190,12 @@ cdef class CachedFunction(): EXAMPLES:: - sage: g = CachedFunction(number_of_partitions) - sage: a = g(5) - sage: g.cache + sage: g = CachedFunction(number_of_partitions) # optional - sage.combinat + sage: a = g(5) # optional - sage.combinat + sage: g.cache # optional - sage.combinat {((5, 'default'), ()): 7} - sage: g.clear_cache() - sage: g.cache + sage: g.clear_cache() # optional - sage.combinat + sage: g.cache # optional - sage.combinat {} """ self.cache.clear() @@ -1317,17 +1318,17 @@ cdef class WeakCachedFunction(CachedFunction): sage: from sage.misc.cachefunc import weak_cached_function sage: @weak_cached_function ....: def f(x): return x+x - sage: K. = Qq(4) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: x = t + K(1,1); x # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: x = t + K(1,1); x # optional - sage.rings.padics (1 + O(2^20))*t + 1 + O(2) - sage: y = t + K(1,2); y # optional - sage.rings.padics + sage: y = t + K(1,2); y # optional - sage.rings.padics (1 + O(2^20))*t + 1 + O(2^2) - sage: x == y # optional - sage.rings.padics + sage: x == y # optional - sage.rings.padics True - sage: f(x) is f(x) # optional - sage.rings.padics + sage: f(x) is f(x) # optional - sage.rings.padics True - sage: f(y) is not f(x) # optional - sage.rings.padics + sage: f(y) is not f(x) # optional - sage.rings.padics True Examples and tests for ``is_in_cache``:: @@ -1361,13 +1362,13 @@ cdef class WeakCachedFunction(CachedFunction): sage: from sage.misc.cachefunc import weak_cached_function sage: @weak_cached_function ....: def f(x): return x - sage: K. = Qq(4) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: f.is_in_cache(t) # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f.is_in_cache(t) # optional - sage.rings.padics False - sage: f(t) # optional - sage.rings.padics + sage: f(t) # optional - sage.rings.padics (1 + O(2^20))*t - sage: f.is_in_cache(t) # optional - sage.rings.padics + sage: f.is_in_cache(t) # optional - sage.rings.padics True Examples and tests for ``set_cache``:: @@ -1387,10 +1388,10 @@ cdef class WeakCachedFunction(CachedFunction): sage: from sage.misc.cachefunc import weak_cached_function sage: @weak_cached_function ....: def f(x): return x - sage: K. = Qq(4) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: f.set_cache(t,t) # optional - sage.rings.padics - sage: f.is_in_cache(t) # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f.set_cache(t,t) # optional - sage.rings.padics + sage: f.is_in_cache(t) # optional - sage.rings.padics True """ def __init__(self, f, *, classmethod=False, name=None, key=None, **kwds): @@ -1902,20 +1903,20 @@ cdef class CachedMethodCaller(CachedFunction): immutable unhashable objects which define :meth:`sage.structure.sage_object.SageObject._cache_key`:: - sage: K. = Qq(4) # optional - sage.rings.padics + sage: K. = Qq(4) # optional - sage.rings.padics sage: class A(): ....: @cached_method ....: def f(self, x): return x+x sage: a = A() - sage: x = K(1,1); x # optional - sage.rings.padics + sage: x = K(1,1); x # optional - sage.rings.padics 1 + O(2) - sage: y = K(1,2); y # optional - sage.rings.padics + sage: y = K(1,2); y # optional - sage.rings.padics 1 + O(2^2) - sage: x == y # optional - sage.rings.padics + sage: x == y # optional - sage.rings.padics True - sage: a.f(x) is a.f(x) # optional - sage.rings.padics + sage: a.f(x) is a.f(x) # optional - sage.rings.padics True - sage: a.f(y) is not a.f(x) # optional - sage.rings.padics + sage: a.f(y) is not a.f(x) # optional - sage.rings.padics True """ @@ -3670,11 +3671,11 @@ class disk_cached_function: sage: dir = tmp_dir() sage: @disk_cached_function(dir) ....: def foo(x): return next_prime(2^x)%x - sage: x = foo(200);x + sage: x = foo(200); x # optional - sage.libs.pari 11 sage: @disk_cached_function(dir) ....: def foo(x): return 1/x - sage: foo(200) + sage: foo(200) # optional - sage.libs.pari 11 sage: foo.clear_cache() sage: foo(200) @@ -3687,12 +3688,12 @@ class disk_cached_function: sage: dir = tmp_dir() sage: @disk_cached_function(dir, memory_cache=True) ....: def foo(x): return next_prime(2^x) - sage: x = foo(200) - sage: x is foo(200) + sage: x = foo(200) # optional - sage.libs.pari + sage: x is foo(200) # optional - sage.libs.pari True sage: @disk_cached_function(dir, memory_cache=False) ....: def foo(x): return next_prime(2^x) - sage: x is foo(200) + sage: x is foo(200) # optional - sage.libs.pari False """ self._dir = dir diff --git a/src/sage/misc/call.py b/src/sage/misc/call.py index ddb48610e59..7234e07863a 100644 --- a/src/sage/misc/call.py +++ b/src/sage/misc/call.py @@ -40,11 +40,11 @@ def __call__(self, x, *args): EXAMPLES:: sage: core = attrcall('core', 3) - sage: core(Partition([4,2])) + sage: core(Partition([4,2])) # optional - sage.combinat [4, 2] - sage: series = attrcall('series', x) - sage: series(sin(x), 4) + sage: series = attrcall('series', x) # optional - sage.symbolic + sage: series(sin(x), 4) # optional - sage.symbolic 1*x + (-1/6)*x^3 + Order(x^4) """ return getattr(x, self.name)(*(self.args + args), **self.kwds) @@ -159,7 +159,7 @@ def attrcall(name, *args, **kwds): sage: f = attrcall('core', 3); f *.core(3) - sage: [f(p) for p in Partitions(5)] + sage: [f(p) for p in Partitions(5)] # optional - sage.combinat [[2], [1, 1], [1, 1], [3, 1, 1], [2], [2], [1, 1]] """ return AttrCallObject(name, args, kwds) diff --git a/src/sage/misc/classcall_metaclass.pyx b/src/sage/misc/classcall_metaclass.pyx index 191534f76ee..2806918309c 100644 --- a/src/sage/misc/classcall_metaclass.pyx +++ b/src/sage/misc/classcall_metaclass.pyx @@ -79,7 +79,7 @@ cdef class ClasscallMetaclass(NestedClassMetaclass): TESTS:: - sage: PerfectMatchings(2).list() + sage: PerfectMatchings(2).list() # optional - sage.combinat [[(1, 2)]] .. NOTE:: @@ -271,12 +271,12 @@ cdef class ClasscallMetaclass(NestedClassMetaclass): The benefit, compared with using a wrapper function, is that the user interface has a single handle for the class:: - sage: x = Partition([3,2,2]) - sage: isinstance(x, Partition) # todo: not implemented + sage: x = Partition([3,2,2]) # optional - sage.combinat + sage: isinstance(x, Partition) # todo: not implemented # optional - sage.combinat instead of:: - sage: isinstance(x, sage.combinat.partition.Partition) + sage: isinstance(x, sage.combinat.partition.Partition) # optional - sage.combinat True Another difference is that ``__classcall__`` is inherited by diff --git a/src/sage/misc/decorators.py b/src/sage/misc/decorators.py index ef22aebb242..dca4427ebf9 100644 --- a/src/sage/misc/decorators.py +++ b/src/sage/misc/decorators.py @@ -67,7 +67,7 @@ def sage_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES): ....: return x sage: g(2) 4 - sage: g(x) + sage: g(x) # optional - sage.symbolic x^2 sage: g.__doc__ 'My little function' @@ -192,9 +192,9 @@ class infix_operator(): ....: def dot(a, b): ....: '''Dot product.''' ....: return a.dot_product(b) - sage: u = vector([1, 2, 3]) - sage: v = vector([5, 4, 3]) - sage: u *dot* v + sage: u = vector([1, 2, 3]) # optional - sage.modules + sage: v = vector([5, 4, 3]) # optional - sage.modules + sage: u *dot* v # optional - sage.modules 22 An infix element-wise addition operator:: @@ -202,11 +202,11 @@ class infix_operator(): sage: @infix_operator('add') ....: def eadd(a, b): ....: return a.parent([i + j for i, j in zip(a, b)]) - sage: u = vector([1, 2, 3]) - sage: v = vector([5, 4, 3]) - sage: u +eadd+ v + sage: u = vector([1, 2, 3]) # optional - sage.modules + sage: v = vector([5, 4, 3]) # optional - sage.modules + sage: u +eadd+ v # optional - sage.modules (6, 6, 6) - sage: 2*u +eadd+ v + sage: 2*u +eadd+ v # optional - sage.modules (7, 8, 9) A hack to simulate a postfix operator:: @@ -214,7 +214,7 @@ class infix_operator(): sage: @infix_operator('or') ....: def thendo(a, b): ....: return b(a) - sage: x |thendo| cos |thendo| (lambda x: x^2) + sage: x |thendo| cos |thendo| (lambda x: x^2) # optional - sage.symbolic cos(x)^2 """ diff --git a/src/sage/misc/derivative.pyx b/src/sage/misc/derivative.pyx index 45ee7a918c5..b260099afcd 100644 --- a/src/sage/misc/derivative.pyx +++ b/src/sage/misc/derivative.pyx @@ -91,20 +91,20 @@ def derivative_parse(args): EXAMPLES:: - sage: x = var("x") - sage: y = var("y") + sage: x = var("x") # optional - sage.symbolic + sage: y = var("y") # optional - sage.symbolic sage: from sage.misc.derivative import derivative_parse Differentiate twice with respect to x, then once with respect to y, then once with respect to x:: - sage: derivative_parse([x, 2, y, x]) + sage: derivative_parse([x, 2, y, x]) # optional - sage.symbolic [x, x, y, x] Differentiate twice with respect to x, then twice with respect to the 'default variable':: - sage: derivative_parse([x, 2, 2]) + sage: derivative_parse([x, 2, 2]) # optional - sage.symbolic [x, x, None, None] Special case with empty input list:: @@ -119,7 +119,7 @@ def derivative_parse(args): Special case with single list argument provided:: - sage: derivative_parse(([x, y], )) + sage: derivative_parse(([x, y], )) # optional - sage.symbolic [x, y] If only the count is supplied:: @@ -135,15 +135,15 @@ def derivative_parse(args): Various other cases:: - sage: derivative_parse([x]) + sage: derivative_parse([x]) # optional - sage.symbolic [x] - sage: derivative_parse([x, x]) + sage: derivative_parse([x, x]) # optional - sage.symbolic [x, x] - sage: derivative_parse([x, 2]) + sage: derivative_parse([x, 2]) # optional - sage.symbolic [x, x] - sage: derivative_parse([x, 0]) + sage: derivative_parse([x, 0]) # optional - sage.symbolic [] - sage: derivative_parse([x, y, x, 2, 2, y]) + sage: derivative_parse([x, y, x, 2, 2, y]) # optional - sage.symbolic [x, y, x, x, None, None, y] """ diff --git a/src/sage/misc/dev_tools.py b/src/sage/misc/dev_tools.py index c18253358ba..68d97f203e5 100644 --- a/src/sage/misc/dev_tools.py +++ b/src/sage/misc/dev_tools.py @@ -221,12 +221,12 @@ def find_objects_from_name(name, module_name=None): sage: dt.find_objects_from_name('FareySymbol') [] - sage: import sympy - sage: dt.find_objects_from_name('RR') + sage: import sympy # optional - sympy + sage: dt.find_objects_from_name('RR') # optional - sympy [Real Field with 53 bits of precision, RR] - sage: dt.find_objects_from_name('RR', 'sage') + sage: dt.find_objects_from_name('RR', 'sage') # optional - sympy [Real Field with 53 bits of precision] - sage: dt.find_objects_from_name('RR', 'sympy') + sage: dt.find_objects_from_name('RR', 'sympy') # optional - sympy [RR] Examples that do not belong to the global namespace but in a loaded module:: diff --git a/src/sage/misc/element_with_label.py b/src/sage/misc/element_with_label.py index 2410851c7de..b490417ed50 100644 --- a/src/sage/misc/element_with_label.py +++ b/src/sage/misc/element_with_label.py @@ -25,20 +25,20 @@ class ElementWithLabel(): EXAMPLES:: - sage: P = Poset({1: [2,3]}) - sage: labs = {i: P.rank(i) for i in range(1, 4)} - sage: print(labs) + sage: P = Poset({1: [2,3]}) # optional - sage.combinat sage.graphs + sage: labs = {i: P.rank(i) for i in range(1, 4)} # optional - sage.combinat sage.graphs + sage: print(labs) # optional - sage.combinat sage.graphs {1: 0, 2: 1, 3: 1} - sage: print(P.plot(element_labels=labs)) + sage: print(P.plot(element_labels=labs)) # optional - sage.combinat sage.graphs sage.plot Graphics object consisting of 6 graphics primitives sage: from sage.misc.element_with_label import ElementWithLabel - sage: W = WeylGroup("A1") - sage: P = W.bruhat_poset(facade=True) - sage: D = W.domain() - sage: v = D.rho() - D.fundamental_weight(1) - sage: nP = P.relabel(lambda w: ElementWithLabel(w, w.action(v))) - sage: list(nP) + sage: W = WeylGroup("A1") # optional - sage.combinat + sage: P = W.bruhat_poset(facade=True) # optional - sage.combinat sage.graphs + sage: D = W.domain() # optional - sage.combinat sage.graphs + sage: v = D.rho() - D.fundamental_weight(1) # optional - sage.combinat sage.graphs + sage: nP = P.relabel(lambda w: ElementWithLabel(w, w.action(v))) # optional - sage.combinat sage.graphs + sage: list(nP) # optional - sage.combinat sage.graphs [(0, 0), (0, 0)] """ def __init__(self, element, label): @@ -65,11 +65,11 @@ def _latex_(self): TESTS:: - sage: var('a_1') + sage: var('a_1') # optional - sage.symbolic a_1 sage: from sage.misc.element_with_label import ElementWithLabel - sage: e = ElementWithLabel(1, a_1) - sage: latex(e) + sage: e = ElementWithLabel(1, a_1) # optional - sage.symbolic + sage: latex(e) # optional - sage.symbolic a_{1} """ return latex(self.label) @@ -81,11 +81,11 @@ def __str__(self): TESTS:: - sage: var('a_1') + sage: var('a_1') # optional - sage.symbolic a_1 sage: from sage.misc.element_with_label import ElementWithLabel - sage: e = ElementWithLabel(1, a_1) - sage: str(e) + sage: e = ElementWithLabel(1, a_1) # optional - sage.symbolic + sage: str(e) # optional - sage.symbolic 'a_1' """ return str(self.label) @@ -97,11 +97,11 @@ def __repr__(self): TESTS:: - sage: var('a_1') + sage: var('a_1') # optional - sage.symbolic a_1 sage: from sage.misc.element_with_label import ElementWithLabel - sage: e = ElementWithLabel(1, a_1) - sage: repr(e) + sage: e = ElementWithLabel(1, a_1) # optional - sage.symbolic + sage: repr(e) # optional - sage.symbolic 'a_1' """ return repr(self.label) diff --git a/src/sage/misc/flatten.py b/src/sage/misc/flatten.py index 8b8a7ce54b2..0a1e68d63a5 100644 --- a/src/sage/misc/flatten.py +++ b/src/sage/misc/flatten.py @@ -23,7 +23,7 @@ def flatten(in_list, ltypes=(list, tuple), max_level=sys.maxsize): [1, 1, 1, 2] sage: flatten([[1,2,3], (4,5), [[[1],[2]]]]) [1, 2, 3, 4, 5, 1, 2] - sage: flatten([[1,2,3], (4,5), [[[1],[2]]]],max_level=1) + sage: flatten([[1,2,3], (4,5), [[[1],[2]]]], max_level=1) [1, 2, 3, 4, 5, [[1], [2]]] sage: flatten([[[3],[]]],max_level=0) [[[3], []]] @@ -35,24 +35,24 @@ def flatten(in_list, ltypes=(list, tuple), max_level=sys.maxsize): In the following example, the vector is not flattened because it is not given in the ``ltypes`` input. :: - sage: flatten((['Hi',2,vector(QQ,[1,2,3])],(4,5,6))) + sage: flatten((['Hi', 2, vector(QQ, [1,2,3])], (4,5,6))) # optional - sage.modules ['Hi', 2, (1, 2, 3), 4, 5, 6] We give the vector type and then even the vector gets flattened:: - sage: tV = sage.modules.vector_rational_dense.Vector_rational_dense - sage: flatten((['Hi',2,vector(QQ,[1,2,3])], (4,5,6)), + sage: tV = sage.modules.vector_rational_dense.Vector_rational_dense # optional - sage.modules + sage: flatten((['Hi', 2, vector(QQ, [1,2,3])], (4,5,6)), # optional - sage.modules ....: ltypes=(list, tuple, tV)) ['Hi', 2, 1, 2, 3, 4, 5, 6] We flatten a finite field. :: - sage: flatten(GF(5)) + sage: flatten(GF(5)) # optional - sage.libs.pari [0, 1, 2, 3, 4] - sage: flatten([GF(5)]) + sage: flatten([GF(5)]) # optional - sage.libs.pari [Finite Field of size 5] - sage: tGF = type(GF(5)) - sage: flatten([GF(5)], ltypes = (list, tuple, tGF)) + sage: tGF = type(GF(5)) # optional - sage.libs.pari + sage: flatten([GF(5)], ltypes=(list, tuple, tGF)) # optional - sage.libs.pari [0, 1, 2, 3, 4] Degenerate cases:: diff --git a/src/sage/misc/function_mangling.pyx b/src/sage/misc/function_mangling.pyx index e1bb7978953..b910cabef0c 100644 --- a/src/sage/misc/function_mangling.pyx +++ b/src/sage/misc/function_mangling.pyx @@ -157,8 +157,8 @@ cdef class ArgumentFixer: EXAMPLES:: sage: from sage.misc.function_mangling import ArgumentFixer - sage: g = ArgumentFixer(number_of_partitions) - sage: g + sage: g = ArgumentFixer(number_of_partitions) # optional - sage.combinat + sage: g # optional - sage.combinat Argument Fixer of """ return "Argument Fixer of %s"%self.f @@ -203,10 +203,10 @@ cdef class ArgumentFixer: EXAMPLES:: sage: from sage.misc.function_mangling import ArgumentFixer - sage: def sum3(a,b,c=3,*args,**kwargs): - ....: return a+b+c + sage: def sum3(a, b, c=3, *args, **kwargs): + ....: return a + b + c sage: AF = ArgumentFixer(sum3) - sage: AF.fix_to_named(1,2,3,4,5,6,f=14,e=16) + sage: AF.fix_to_named(1, 2, 3, 4, 5, 6, f=14, e=16) ((4, 5, 6), (('a', 1), ('b', 2), ('c', 3), ('e', 16), ('f', 14))) sage: AF.fix_to_named(1,2,f=14) ((), (('a', 1), ('b', 2), ('c', 3), ('f', 14))) diff --git a/src/sage/misc/functional.py b/src/sage/misc/functional.py index 6e0e2abde37..838704d4c43 100644 --- a/src/sage/misc/functional.py +++ b/src/sage/misc/functional.py @@ -58,8 +58,8 @@ def base_ring(x): EXAMPLES:: - sage: R = PolynomialRing(GF(7), 'x') - sage: base_ring(R) + sage: R = PolynomialRing(GF(7), 'x') # optional - sage.rings.finite_rings + sage: base_ring(R) # optional - sage.rings.finite_rings Finite Field of size 7 """ return x.base_ring() @@ -71,17 +71,17 @@ def base_field(x): EXAMPLES:: - sage: R = PolynomialRing(GF(7), 'x') - sage: base_ring(R) + sage: R = PolynomialRing(GF(7), 'x') # optional - sage.rings.finite_rings + sage: base_ring(R) # optional - sage.rings.finite_rings Finite Field of size 7 - sage: base_field(R) + sage: base_field(R) # optional - sage.rings.finite_rings Finite Field of size 7 This catches base rings which are fields as well, but does not implement a ``base_field`` method for objects which do not have one:: - sage: R.base_field() + sage: R.base_field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... AttributeError: 'PolynomialRing_dense_mod_p_with_category' object has no attribute 'base_field' @@ -102,9 +102,9 @@ def basis(x): EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: S = V.subspace([[1,2,0],[2,2,-1]]) - sage: basis(S) + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: S = V.subspace([[1,2,0], [2,2,-1]]) # optional - sage.modules + sage: basis(S) # optional - sage.modules [ (1, 0, -1), (0, 1, 1/2) @@ -119,8 +119,8 @@ def category(x): EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: category(V) + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: category(V) # optional - sage.modules Category of finite dimensional vector spaces with basis over (number fields and quotient fields and metric spaces) """ @@ -137,30 +137,30 @@ def characteristic_polynomial(x, var='x'): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,2,3,4,5,6,7,8,9]) - sage: charpoly(A) + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([1,2,3,4,5,6,7,8,9]) # optional - sage.modules + sage: charpoly(A) # optional - sage.libs.pari sage.modules x^3 - 15*x^2 - 18*x - sage: charpoly(A, 't') + sage: charpoly(A, 't') # optional - sage.libs.pari sage.modules t^3 - 15*t^2 - 18*t - sage: k. = GF(7^10); k + sage: k. = GF(7^10); k # optional - sage.rings.finite_rings Finite Field in alpha of size 7^10 - sage: alpha.charpoly('T') + sage: alpha.charpoly('T') # optional - sage.rings.finite_rings T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3 - sage: characteristic_polynomial(alpha, 'T') + sage: characteristic_polynomial(alpha, 'T') # optional - sage.rings.finite_rings T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3 Ensure the variable name of the polynomial does not conflict with variables used within the matrix, and that non-integral powers of variables do not confuse the computation (:trac:`14403`):: - sage: y = var('y') - sage: a = matrix([[x,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) - sage: characteristic_polynomial(a).list() + sage: y = var('y') # optional - sage.libs.pari sage.symbolic + sage: a = matrix([[x,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]) # optional - sage.libs.pari sage.symbolic + sage: characteristic_polynomial(a).list() # optional - sage.libs.pari sage.symbolic [x, -3*x - 1, 3*x + 3, -x - 3, 1] - sage: b = matrix([[y^(1/2),0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) - sage: charpoly(b).list() + sage: b = matrix([[y^(1/2),0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]]) # optional - sage.libs.pari sage.symbolic + sage: charpoly(b).list() # optional - sage.libs.pari sage.symbolic [sqrt(y), -3*sqrt(y) - 1, 3*sqrt(y) + 3, -sqrt(y) - 3, 1] """ try: @@ -215,19 +215,20 @@ def decomposition(x): EXAMPLES:: - sage: M = matrix([[2, 3], [3, 4]]) - sage: M.decomposition() + sage: M = matrix([[2, 3], [3, 4]]) # optional - sage.libs.pari sage.modules + sage: M.decomposition() # optional - sage.libs.pari sage.modules [ (Ambient free module of rank 2 over the principal ideal domain Integer Ring, True) ] - sage: G. = DirichletGroup(20) - sage: c = a*b - sage: d = c.decomposition(); d + sage: G. = DirichletGroup(20) # optional - sage.groups + sage: c = a * b # optional - sage.groups + sage: d = c.decomposition(); d # optional - sage.groups [Dirichlet character modulo 4 of conductor 4 mapping 3 |--> -1, Dirichlet character modulo 5 of conductor 5 mapping 2 |--> zeta4] - sage: d[0].parent() - Group of Dirichlet characters modulo 4 with values in Cyclotomic Field of order 4 and degree 2 + sage: d[0].parent() # optional - sage.groups + Group of Dirichlet characters modulo 4 + with values in Cyclotomic Field of order 4 and degree 2 """ return x.decomposition() @@ -257,9 +258,9 @@ def det(x): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,2,3,4,5,6,7,8,9]) - sage: det(A) + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([1,2,3, 4,5,6, 7,8,9]) # optional - sage.modules + sage: det(A) # optional - sage.modules 0 """ return x.det() @@ -271,9 +272,9 @@ def dimension(x): EXAMPLES:: - sage: V = VectorSpace(QQ,3) - sage: S = V.subspace([[1,2,0],[2,2,-1]]) - sage: dimension(S) + sage: V = VectorSpace(QQ, 3) # optional - sage.modules + sage: S = V.subspace([[1,2,0], [2,2,-1]]) # optional - sage.modules + sage: dimension(S) # optional - sage.modules 2 """ return x.dimension() @@ -289,9 +290,9 @@ def discriminant(x): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^29 - 17*x - 1, 'alpha') - sage: K = S.number_field() - sage: discriminant(K) + sage: S = R.quotient(x^29 - 17*x - 1, 'alpha') # optional - sage.libs.pari + sage: K = S.number_field() # optional - sage.libs.pari sage.rings.number_field + sage: discriminant(K) # optional - sage.libs.pari sage.rings.number_field -15975100446626038280218213241591829458737190477345113376757479850566957249523 """ return x.discriminant() @@ -313,7 +314,7 @@ def eta(x): EXAMPLES:: - sage: eta(1+I) + sage: eta(1 + I) 0.7420487758365647 + 0.1988313702299107*I """ try: @@ -328,9 +329,9 @@ def fcp(x, var='x'): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,2,3,4,5,6,7,8,9]) - sage: fcp(A, 'x') + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([1,2,3, 4,5,6, 7,8,9]) # optional - sage.modules + sage: fcp(A, 'x') # optional - sage.libs.pari sage.modules x * (x^2 - 15*x - 18) """ try: @@ -349,10 +350,10 @@ def gen(x): Univariate Polynomial Ring in x over Rational Field sage: gen(R) x - sage: gen(GF(7)) + sage: gen(GF(7)) # optional - sage.rings.finite_rings 1 - sage: A = AbelianGroup(1, [23]) - sage: gen(A) + sage: A = AbelianGroup(1, [23]) # optional - sage.groups + sage: gen(A) # optional - sage.groups f """ return x.gen() @@ -364,13 +365,13 @@ def gens(x): EXAMPLES:: - sage: R. = SR[] - sage: R + sage: R. = SR[] # optional - sage.symbolic + sage: R # optional - sage.symbolic Multivariate Polynomial Ring in x, y over Symbolic Ring - sage: gens(R) + sage: gens(R) # optional - sage.symbolic (x, y) - sage: A = AbelianGroup(5, [5,5,7,8,9]) - sage: gens(A) + sage: A = AbelianGroup(5, [5,5,7,8,9]) # optional - sage.groups + sage: gens(A) # optional - sage.groups (f0, f1, f2, f3, f4) """ return x.gens() @@ -384,7 +385,8 @@ def hecke_operator(x, n): sage: M = ModularSymbols(1,12) sage: hecke_operator(M,5) - Hecke operator T_5 on Modular Symbols space of dimension 3 for Gamma_0(1) of weight 12 with sign 0 over Rational Field + Hecke operator T_5 on Modular Symbols space of dimension 3 for Gamma_0(1) + of weight 12 with sign 0 over Rational Field """ return x.hecke_operator(n) @@ -395,9 +397,9 @@ def image(x): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,2,3,4,5,6,7,8,9]) - sage: image(A) + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([1,2,3, 4,5,6, 7,8,9]) # optional - sage.modules + sage: image(A) # optional - sage.modules Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -1] @@ -435,18 +437,18 @@ def symbolic_sum(expression, *args, **kwds): EXAMPLES:: - sage: k, n = var('k,n') - sage: sum(k, k, 1, n).factor() + sage: k, n = var('k,n') # optional - sage.symbolic + sage: sum(k, k, 1, n).factor() # optional - sage.symbolic 1/2*(n + 1)*n :: - sage: sum(1/k^4, k, 1, oo) + sage: sum(1/k^4, k, 1, oo) # optional - sage.symbolic 1/90*pi^4 :: - sage: sum(1/k^5, k, 1, oo) + sage: sum(1/k^5, k, 1, oo) # optional - sage.symbolic zeta(5) .. WARNING:: @@ -458,9 +460,9 @@ def symbolic_sum(expression, *args, **kwds): In particular, this does not work:: - sage: n = var('n') + sage: n = var('n') # optional - sage.symbolic sage: mylist = [1,2,3,4,5] - sage: sum(mylist[n], n, 0, 3) + sage: sum(mylist[n], n, 0, 3) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert n to an integer @@ -472,95 +474,95 @@ def symbolic_sum(expression, *args, **kwds): Also, only a limited number of functions are recognized in symbolic sums:: - sage: sum(valuation(n,2),n,1,5) + sage: sum(valuation(n, 2), n, 1, 5) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert n to an integer Again, use python ``sum()``:: - sage: sum(valuation(n+1,2) for n in range(5)) + sage: sum(valuation(n + 1, 2) for n in range(5)) 3 (now back to the Sage ``sum`` examples) A well known binomial identity:: - sage: sum(binomial(n,k), k, 0, n) + sage: sum(binomial(n, k), k, 0, n) # optional - sage.symbolic 2^n The binomial theorem:: - sage: x, y = var('x, y') - sage: sum(binomial(n,k) * x^k * y^(n-k), k, 0, n) + sage: x, y = var('x, y') # optional - sage.symbolic + sage: sum(binomial(n, k) * x^k * y^(n-k), k, 0, n) # optional - sage.symbolic (x + y)^n :: - sage: sum(k * binomial(n, k), k, 1, n) + sage: sum(k * binomial(n, k), k, 1, n) # optional - sage.symbolic 2^(n - 1)*n :: - sage: sum((-1)^k*binomial(n,k), k, 0, n) + sage: sum((-1)^k * binomial(n, k), k, 0, n) # optional - sage.symbolic 0 :: - sage: sum(2^(-k)/(k*(k+1)), k, 1, oo) + sage: sum(2^(-k)/(k*(k+1)), k, 1, oo) # optional - sage.symbolic -log(2) + 1 Another binomial identity (:trac:`7952`):: - sage: t,k,i = var('t,k,i') - sage: sum(binomial(i+t,t),i,0,k) + sage: t, k, i = var('t,k,i') # optional - sage.symbolic + sage: sum(binomial(i + t, t), i, 0, k) # optional - sage.symbolic binomial(k + t + 1, t + 1) Summing a hypergeometric term:: - sage: sum(binomial(n, k) * factorial(k) / factorial(n+1+k), k, 0, n) + sage: sum(binomial(n, k) * factorial(k) / factorial(n+1+k), k, 0, n) # optional - sage.symbolic 1/2*sqrt(pi)/factorial(n + 1/2) We check a well known identity:: - sage: bool(sum(k^3, k, 1, n) == sum(k, k, 1, n)^2) + sage: bool(sum(k^3, k, 1, n) == sum(k, k, 1, n)^2) # optional - sage.symbolic True A geometric sum:: - sage: a, q = var('a, q') - sage: sum(a*q^k, k, 0, n) + sage: a, q = var('a, q') # optional - sage.symbolic + sage: sum(a*q^k, k, 0, n) # optional - sage.symbolic (a*q^(n + 1) - a)/(q - 1) The geometric series:: - sage: assume(abs(q) < 1) - sage: sum(a*q^k, k, 0, oo) + sage: assume(abs(q) < 1) # optional - sage.symbolic + sage: sum(a * q^k, k, 0, oo) # optional - sage.symbolic -a/(q - 1) A divergent geometric series. Don't forget to forget your assumptions:: - sage: forget() - sage: assume(q > 1) - sage: sum(a*q^k, k, 0, oo) + sage: forget() # optional - sage.symbolic + sage: assume(q > 1) # optional - sage.symbolic + sage: sum(a * q^k, k, 0, oo) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Sum is divergent. This summation only Mathematica can perform:: - sage: sum(1/(1+k^2), k, -oo, oo, algorithm = 'mathematica') # optional - mathematica + sage: sum(1/(1+k^2), k, -oo, oo, algorithm='mathematica') # optional - mathematica sage.symbolic pi*coth(pi) Use Maple as a backend for summation:: - sage: sum(binomial(n,k)*x^k, k, 0, n, algorithm = 'maple') # optional - maple + sage: sum(binomial(n, k) * x^k, k, 0, n, algorithm='maple') # optional - maple sage.symbolic (x + 1)^n Python ints should work as limits of summation (:trac:`9393`):: - sage: sum(x, x, 1r, 5r) + sage: sum(x, x, 1r, 5r) # optional - sage.symbolic 15 .. note:: @@ -573,9 +575,9 @@ def symbolic_sum(expression, *args, **kwds): Check that :trac:`34007` is fixed:: - sage: sum([1,2], start=1) + sage: sum([1, 2], start=1) # optional - sage.symbolic 4 - sage: sum([[1],[2]], start=[]) + sage: sum([[1], [2]], start=[]) # optional - sage.symbolic [1, 2] """ @@ -615,22 +617,22 @@ def symbolic_prod(expression, *args, **kwds): EXAMPLES:: - sage: i, k, n = var('i,k,n') - sage: product(k,k,1,n) + sage: i, k, n = var('i,k,n') # optional - sage.symbolic + sage: product(k, k, 1, n) # optional - sage.symbolic factorial(n) - sage: product(x + i*(i+1)/2, i, 1, 4) + sage: product(x + i*(i+1)/2, i, 1, 4) # optional - sage.symbolic x^4 + 20*x^3 + 127*x^2 + 288*x + 180 - sage: product(i^2, i, 1, 7) + sage: product(i^2, i, 1, 7) # optional - sage.symbolic 25401600 - sage: f = function('f') - sage: product(f(i), i, 1, 7) + sage: f = function('f') # optional - sage.symbolic + sage: product(f(i), i, 1, 7) # optional - sage.symbolic f(7)*f(6)*f(5)*f(4)*f(3)*f(2)*f(1) - sage: product(f(i), i, 1, n) + sage: product(f(i), i, 1, n) # optional - sage.symbolic product(f(i), i, 1, n) - sage: assume(k>0) - sage: product(integrate (x^k, x, 0, 1), k, 1, n) + sage: assume(k>0) # optional - sage.symbolic + sage: product(integrate(x^k, x, 0, 1), k, 1, n) # optional - sage.symbolic 1/factorial(n + 1) - sage: product(f(i), i, 1, n).log().log_expand() + sage: product(f(i), i, 1, n).log().log_expand() # optional - sage.symbolic sum(log(f(i)), i, 1, n) """ @@ -663,38 +665,38 @@ def integral(x, *args, **kwds): :: - sage: integral(sin(x),x) + sage: integral(sin(x), x) # optional - sage.symbolic -cos(x) :: - sage: y = var('y') - sage: integral(sin(x),y) + sage: y = var('y') # optional - sage.symbolic + sage: integral(sin(x), y) # optional - sage.symbolic y*sin(x) :: - sage: integral(sin(x), x, 0, pi/2) + sage: integral(sin(x), x, 0, pi/2) # optional - sage.symbolic 1 - sage: sin(x).integral(x, 0,pi/2) + sage: sin(x).integral(x, 0, pi/2) # optional - sage.symbolic 1 - sage: integral(exp(-x), (x, 1, oo)) + sage: integral(exp(-x), (x, 1, oo)) # optional - sage.symbolic e^(-1) Numerical approximation:: - sage: h = integral(tan(x)/x, (x, 1, pi/3)) + sage: h = integral(tan(x)/x, (x, 1, pi/3)) # optional - sage.symbolic ... - sage: h + sage: h # optional - sage.symbolic integrate(tan(x)/x, x, 1, 1/3*pi) - sage: h.n() + sage: h.n() # optional - sage.symbolic 0.07571599101... Specific algorithm can be used for integration:: - sage: integral(sin(x)^2, x, algorithm='maxima') + sage: integral(sin(x)^2, x, algorithm='maxima') # optional - sage.symbolic 1/2*x - 1/4*sin(2*x) - sage: integral(sin(x)^2, x, algorithm='sympy') + sage: integral(sin(x)^2, x, algorithm='sympy') # optional - sage.symbolic -1/2*cos(x)*sin(x) + 1/2*x TESTS: @@ -702,8 +704,8 @@ def integral(x, *args, **kwds): A symbolic integral from :trac:`11445` that was incorrect in earlier versions of Maxima:: - sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) - sage: integrate(f, (x, -Infinity, Infinity)) + sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) # optional - sage.symbolic + sage: integrate(f, (x, -Infinity, Infinity)) # optional - sage.symbolic 2 Another symbolic integral, from :trac:`11238`, that used to return @@ -714,58 +716,60 @@ def integral(x, *args, **kwds): with the default settings, so we temporarily use the Maxima setting ``domain: real``:: - sage: sage.calculus.calculus.maxima('domain: real') + sage: sage.calculus.calculus.maxima('domain: real') # optional - sage.symbolic real - sage: f = exp(-x) * sinh(sqrt(x)) - sage: t = integrate(f, x, 0, Infinity); t # long time + sage: f = exp(-x) * sinh(sqrt(x)) # optional - sage.symbolic + sage: t = integrate(f, x, 0, Infinity); t # long time # optional - sage.symbolic 1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4) - 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4) + 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4) - sage: t.canonicalize_radical() # long time + sage: t.canonicalize_radical() # long time # optional - sage.symbolic 1/2*sqrt(pi)*e^(1/4) - sage: sage.calculus.calculus.maxima('domain: complex') + sage: sage.calculus.calculus.maxima('domain: complex') # optional - sage.symbolic complex An integral which used to return -1 before maxima 5.28. See :trac:`12842`:: - sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) - sage: integrate(f, x, 0, infinity) + sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) # optional - sage.symbolic + sage: integrate(f, x, 0, infinity) # optional - sage.symbolic 1 This integral would cause a stack overflow in earlier versions of Maxima, crashing sage. See :trac:`12377`. We don't care about the result here, just that the computation completes successfully:: - sage: y = (x^2)*exp(x) / (1 + exp(x))^2 - sage: _ = integrate(y, x, -1000, 1000) + sage: y = (x^2)*exp(x) / (1 + exp(x))^2 # optional - sage.symbolic + sage: _ = integrate(y, x, -1000, 1000) # optional - sage.symbolic When SymPy cannot solve an integral it gives it back, so we must be able to convert SymPy's ``Integral`` (:trac:`14723`):: - sage: x, y, z = var('x,y,z') - sage: f = function('f') - sage: integrate(f(x), x, algorithm='sympy') + sage: x, y, z = var('x,y,z') # optional - sage.symbolic + sage: f = function('f') # optional - sage.symbolic + sage: integrate(f(x), x, algorithm='sympy') # optional - sage.symbolic integrate(f(x), x) - sage: integrate(f(x), x, 0, 1,algorithm='sympy') + sage: integrate(f(x), x, 0, 1, algorithm='sympy') # optional - sage.symbolic integrate(f(x), x, 0, 1) - sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'), y, algorithm='sympy'), z, algorithm='sympy') + sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'), # optional - sage.symbolic + ....: y, algorithm='sympy'), + ....: z, algorithm='sympy') integrate(integrate(integrate(f(x, y, z), x), y), z) - sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy') + sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy') # optional - sage.symbolic -integrate(sin(x)*tan(x)/(cos(x) - 1), x) - sage: _ = var('a,b,x') - sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy') + sage: _ = var('a,b,x') # optional - sage.symbolic + sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy') # optional - sage.symbolic -integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b) - sage: import sympy - sage: x, y, z = sympy.symbols('x y z') - sage: f = sympy.Function('f') - sage: SR(sympy.Integral(f(x,y,z), x, y, z)) + sage: import sympy # optional - sympy + sage: x, y, z = sympy.symbols('x y z') # optional - sympy + sage: f = sympy.Function('f') # optional - sympy + sage: SR(sympy.Integral(f(x,y,z), x, y, z)) # optional - sympy sage.symbolic integrate(integrate(integrate(f(x, y, z), x), y), z) Ensure that the following integral containing a signum term from :trac:`11590` can be integrated:: - sage: x = SR.symbol('x', domain='real') - sage: result = integrate(x * sgn(x^2 - 1/4), x, -1, 0) + sage: x = SR.symbol('x', domain='real') # optional - sage.symbolic + sage: result = integrate(x * sgn(x^2 - 1/4), x, -1, 0) # optional - sage.symbolic ... - sage: result + sage: result # optional - sage.symbolic -1/4 """ @@ -787,11 +791,13 @@ def integral_closure(x): sage: integral_closure(QQ) Rational Field - sage: K. = QuadraticField(5) - sage: O2 = K.order(2*a); O2 - Order in Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? - sage: integral_closure(O2) - Maximal Order in Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + sage: K. = QuadraticField(5) # optional - sage.rings.number_field + sage: O2 = K.order(2 * a); O2 # optional - sage.rings.number_field + Order in Number Field in a + with defining polynomial x^2 - 5 with a = 2.236067977499790? + sage: integral_closure(O2) # optional - sage.rings.number_field + Maximal Order in Number Field in a + with defining polynomial x^2 - 5 with a = 2.236067977499790? """ return x.integral_closure() @@ -874,9 +880,9 @@ def is_integrally_closed(x): doctest:...DeprecationWarning: use X.is_integrally_closed() See https://github.com/sagemath/sage/issues/32347 for details. True - sage: K. = NumberField(x^2 + 189*x + 394) - sage: R = K.order(2*a) - sage: is_integrally_closed(R) + sage: K. = NumberField(x^2 + 189*x + 394) # optional - sage.rings.number_field + sage: R = K.order(2*a) # optional - sage.rings.number_field + sage: is_integrally_closed(R) # optional - sage.rings.number_field False """ deprecation(32347, "use X.is_integrally_closed()") @@ -928,26 +934,26 @@ def kernel(x): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,2) - sage: A = M([1,2,3,4,5,6]) - sage: kernel(A) + sage: M = MatrixSpace(QQ, 3, 2) # optional - sage.modules + sage: A = M([1,2, 3,4, 5,6]) # optional - sage.modules + sage: kernel(A) # optional - sage.modules Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 -2 1] - sage: kernel(A.transpose()) + sage: kernel(A.transpose()) # optional - sage.modules Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] Here are two corner cases:: - sage: M = MatrixSpace(QQ,0,3) - sage: A = M([]) - sage: kernel(A) + sage: M = MatrixSpace(QQ, 0, 3) # optional - sage.modules + sage: A = M([]) # optional - sage.modules + sage: kernel(A) # optional - sage.modules Vector space of degree 0 and dimension 0 over Rational Field Basis matrix: [] - sage: kernel(A.transpose()).basis() + sage: kernel(A.transpose()).basis() # optional - sage.modules [ (1, 0, 0), (0, 1, 0), @@ -967,9 +973,9 @@ def krull_dimension(x): 0 sage: krull_dimension(ZZ) 1 - sage: krull_dimension(ZZ[sqrt(5)]) + sage: krull_dimension(ZZ[sqrt(5)]) # optional - sage.rings.number_field sage.symbolic 1 - sage: U. = PolynomialRing(ZZ,3); U + sage: U. = PolynomialRing(ZZ, 3); U Multivariate Polynomial Ring in x, y, z over Integer Ring sage: U.krull_dimension() 4 @@ -991,8 +997,8 @@ def lift(x): We lift an element of a quotient polynomial ring:: sage: R. = QQ['x'] - sage: S. = R.quo(x^2 + 1) - sage: lift(xmod-7) + sage: S. = R.quo(x^2 + 1) # optional - sage.libs.pari + sage: lift(xmod - 7) # optional - sage.libs.pari x - 7 """ try: @@ -1049,24 +1055,24 @@ def log(*args, **kwds): 10 sage: RDF(log(1024, 2)) 10.0 - sage: log(10, 4) + sage: log(10, 4) # optional - sage.symbolic 1/2*log(10)/log(2) - sage: RDF(log(10, 4)) + sage: RDF(log(10, 4)) # optional - sage.symbolic 1.6609640474436813 - sage: log(10, 2) + sage: log(10, 2) # optional - sage.symbolic log(10)/log(2) - sage: n(log(10, 2)) + sage: n(log(10, 2)) # optional - sage.symbolic 3.32192809488736 - sage: log(10, e) + sage: log(10, e) # optional - sage.symbolic log(10) - sage: n(log(10, e)) + sage: n(log(10, e)) # optional - sage.symbolic 2.30258509299405 The log function works for negative numbers, complex numbers, and symbolic numbers too, picking the branch with angle between `-\\pi` and `\\pi`:: - sage: log(-1+0*I) + sage: log(-1+0*I) # optional - sage.symbolic I*pi sage: log(CC(-1)) 3.14159265358979*I @@ -1075,24 +1081,24 @@ def log(*args, **kwds): Small integer powers are factored out immediately:: - sage: log(4) + sage: log(4) # optional - sage.symbolic 2*log(2) - sage: log(1000000000) + sage: log(1000000000) # optional - sage.symbolic 9*log(10) - sage: log(8) - 3*log(2) + sage: log(8) - 3*log(2) # optional - sage.symbolic 0 - sage: bool(log(8) == 3*log(2)) + sage: bool(log(8) == 3*log(2)) # optional - sage.symbolic True The ``hold`` parameter can be used to prevent automatic evaluation:: - sage: log(-1,hold=True) + sage: log(-1, hold=True) # optional - sage.symbolic log(-1) - sage: log(-1) + sage: log(-1) # optional - sage.symbolic I*pi - sage: I.log(hold=True) + sage: I.log(hold=True) # optional - sage.symbolic log(I) - sage: I.log(hold=True).simplify() + sage: I.log(hold=True).simplify() # optional - sage.symbolic 1/2*I*pi For input zero, the following behavior occurs:: @@ -1107,27 +1113,27 @@ def log(*args, **kwds): The log function also works in finite fields as long as the argument lies in the multiplicative group generated by the base:: - sage: F = GF(13); g = F.multiplicative_generator(); g + sage: F = GF(13); g = F.multiplicative_generator(); g # optional - sage.rings.finite_rings 2 - sage: a = F(8) - sage: log(a,g); g^log(a,g) + sage: a = F(8) # optional - sage.rings.finite_rings + sage: log(a, g); g^log(a, g) # optional - sage.rings.finite_rings 3 8 - sage: log(a,3) + sage: log(a, 3) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: no logarithm of 8 found to base 3 modulo 13 - sage: log(F(9), 3) + sage: log(F(9), 3) # optional - sage.rings.finite_rings 2 The log function also works for p-adics (see documentation for p-adics for more information):: - sage: R = Zp(5); R + sage: R = Zp(5); R # optional - sage.rings.padics 5-adic Ring with capped relative precision 20 - sage: a = R(16); a + sage: a = R(16); a # optional - sage.rings.padics 1 + 3*5 + O(5^20) - sage: log(a) + sage: log(a) # optional - sage.rings.padics 3*5 + 3*5^2 + 3*5^4 + 3*5^5 + 3*5^6 + 4*5^7 + 2*5^8 + 5^9 + 5^11 + 2*5^12 + 5^13 + 3*5^15 + 2*5^16 + 4*5^17 + 3*5^18 + 3*5^19 + O(5^20) @@ -1137,26 +1143,26 @@ def log(*args, **kwds): Check if :trac:`10136` is fixed:: - sage: ln(x).operator() is ln + sage: ln(x).operator() is ln # optional - sage.symbolic True - sage: log(x).operator() is ln + sage: log(x).operator() is ln # optional - sage.symbolic True sage: log(1000, 10) 3 - sage: log(3,-1) + sage: log(3, -1) # optional - sage.symbolic -I*log(3)/pi - sage: log(int(8),2) + sage: log(int(8), 2) 3 - sage: log(8,int(2)) + sage: log(8, int(2)) 3 - sage: log(8,2) + sage: log(8, 2) 3 - sage: log(1/8,2) + sage: log(1/8, 2) -3 - sage: log(1/8,1/2) + sage: log(1/8, 1/2) 3 - sage: log(8,1/2) + sage: log(8, 1/2) -3 sage: log(1000, 10, base=5) @@ -1196,14 +1202,14 @@ def minimal_polynomial(x, var='x'): EXAMPLES:: - sage: a = matrix(ZZ, 2, [1..4]) - sage: minpoly(a) + sage: a = matrix(ZZ, 2, [1..4]) # optional - sage.modules + sage: minpoly(a) # optional - sage.libs.pari sage.modules x^2 - 5*x - 2 - sage: minpoly(a,'t') + sage: minpoly(a, 't') # optional - sage.libs.pari sage.modules t^2 - 5*t - 2 - sage: minimal_polynomial(a) + sage: minimal_polynomial(a) # optional - sage.libs.pari sage.modules x^2 - 5*x - 2 - sage: minimal_polynomial(a,'theta') + sage: minimal_polynomial(a, 'theta') # optional - sage.libs.pari sage.modules theta^2 - 5*theta - 2 """ try: @@ -1222,12 +1228,12 @@ def multiplicative_order(x): EXAMPLES:: - sage: a = mod(5,11) - sage: multiplicative_order(a) + sage: a = mod(5, 11) + sage: multiplicative_order(a) # optional - sage.libs.pari 5 - sage: multiplicative_order(mod(2,11)) + sage: multiplicative_order(mod(2, 11)) # optional - sage.libs.pari 10 - sage: multiplicative_order(mod(2,12)) + sage: multiplicative_order(mod(2, 12)) # optional - sage.libs.pari Traceback (most recent call last): ... ArithmeticError: multiplicative order of 2 not defined since it is not a unit modulo 12 @@ -1241,12 +1247,12 @@ def ngens(x): EXAMPLES:: - sage: R. = SR[]; R + sage: R. = SR[]; R # optional - sage.symbolic Multivariate Polynomial Ring in x, y over Symbolic Ring - sage: ngens(R) + sage: ngens(R) # optional - sage.symbolic 2 - sage: A = AbelianGroup(5, [5,5,7,8,9]) - sage: ngens(A) + sage: A = AbelianGroup(5, [5,5,7,8,9]) # optional - sage.groups + sage: ngens(A) # optional - sage.groups 5 sage: ngens(ZZ) 1 @@ -1317,24 +1323,24 @@ def norm(x): The norm of vectors:: - sage: z = 1 + 2*I - sage: norm(vector([z])) + sage: z = 1 + 2*I # optional - sage.modules sage.symbolic + sage: norm(vector([z])) # optional - sage.modules sage.symbolic sqrt(5) - sage: v = vector([-1,2,3]) - sage: norm(v) + sage: v = vector([-1,2,3]) # optional - sage.modules sage.symbolic + sage: norm(v) # optional - sage.modules sage.symbolic sqrt(14) - sage: _ = var("a b c d", domain='real') - sage: v = vector([a, b, c, d]) - sage: norm(v) + sage: _ = var("a b c d", domain='real') # optional - sage.modules sage.symbolic + sage: v = vector([a, b, c, d]) # optional - sage.modules sage.symbolic + sage: norm(v) # optional - sage.modules sage.symbolic sqrt(a^2 + b^2 + c^2 + d^2) The norm of matrices:: - sage: z = 1 + 2*I - sage: norm(matrix([[z]])) + sage: z = 1 + 2*I # optional - sage.modules + sage: norm(matrix([[z]])) # optional - sage.modules 2.23606797749979 - sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]]) - sage: norm(M) # abs tol 1e-14 + sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]]) # optional - sage.modules + sage: norm(M) # abs tol 1e-14 # optional - sage.modules 10.690331129154467 sage: norm(CDF(z)) 5.0 @@ -1354,17 +1360,17 @@ def norm(x): The complex norm of symbolic expressions:: - sage: a, b, c = var("a, b, c") - sage: assume((a, 'real'), (b, 'real'), (c, 'real')) - sage: z = a + b*I - sage: bool(norm(z).simplify() == a^2 + b^2) + sage: a, b, c = var("a, b, c") # optional - sage.symbolic + sage: assume((a, 'real'), (b, 'real'), (c, 'real')) # optional - sage.symbolic + sage: z = a + b*I # optional - sage.symbolic + sage: bool(norm(z).simplify() == a^2 + b^2) # optional - sage.symbolic True - sage: norm(a + b).simplify() + sage: norm(a + b).simplify() # optional - sage.symbolic a^2 + 2*a*b + b^2 - sage: v = vector([a, b, c]) - sage: bool(norm(v).simplify() == sqrt(a^2 + b^2 + c^2)) + sage: v = vector([a, b, c]) # optional - sage.symbolic + sage: bool(norm(v).simplify() == sqrt(a^2 + b^2 + c^2)) # optional - sage.symbolic True - sage: forget() + sage: forget() # optional - sage.symbolic """ return x.norm() @@ -1415,17 +1421,17 @@ def numerical_approx(x, prec=None, digits=None, algorithm=None): EXAMPLES:: - sage: numerical_approx(pi, 10) + sage: numerical_approx(pi, 10) # optional - sage.symbolic 3.1 - sage: numerical_approx(pi, digits=10) + sage: numerical_approx(pi, digits=10) # optional - sage.symbolic 3.141592654 - sage: numerical_approx(pi^2 + e, digits=20) + sage: numerical_approx(pi^2 + e, digits=20) # optional - sage.symbolic 12.587886229548403854 - sage: n(pi^2 + e) + sage: n(pi^2 + e) # optional - sage.symbolic 12.5878862295484 - sage: N(pi^2 + e) + sage: N(pi^2 + e) # optional - sage.symbolic 12.5878862295484 - sage: n(pi^2 + e, digits=50) + sage: n(pi^2 + e, digits=50) # optional - sage.symbolic 12.587886229548403854194778471228813633070946500941 sage: a = CC(-5).n(prec=40) sage: b = ComplexField(40)(-5) @@ -1438,45 +1444,45 @@ def numerical_approx(x, prec=None, digits=None, algorithm=None): You can also usually use method notation:: - sage: (pi^2 + e).n() + sage: (pi^2 + e).n() # optional - sage.symbolic 12.5878862295484 - sage: (pi^2 + e).numerical_approx() + sage: (pi^2 + e).numerical_approx() # optional - sage.symbolic 12.5878862295484 Vectors and matrices may also have their entries approximated:: - sage: v = vector(RDF, [1,2,3]) - sage: v.n() + sage: v = vector(RDF, [1,2,3]) # optional - sage.modules + sage: v.n() # optional - sage.modules (1.00000000000000, 2.00000000000000, 3.00000000000000) - sage: v = vector(CDF, [1,2,3]) - sage: v.n() + sage: v = vector(CDF, [1,2,3]) # optional - sage.modules + sage: v.n() # optional - sage.modules (1.00000000000000, 2.00000000000000, 3.00000000000000) - sage: _.parent() + sage: _.parent() # optional - sage.modules Vector space of dimension 3 over Complex Field with 53 bits of precision - sage: v.n(prec=20) + sage: v.n(prec=20) # optional - sage.modules (1.0000, 2.0000, 3.0000) - sage: u = vector(QQ, [1/2, 1/3, 1/4]) - sage: n(u, prec=15) + sage: u = vector(QQ, [1/2, 1/3, 1/4]) # optional - sage.modules + sage: n(u, prec=15) # optional - sage.modules (0.5000, 0.3333, 0.2500) - sage: n(u, digits=5) + sage: n(u, digits=5) # optional - sage.modules (0.50000, 0.33333, 0.25000) - sage: v = vector(QQ, [1/2, 0, 0, 1/3, 0, 0, 0, 1/4], sparse=True) - sage: u = v.numerical_approx(digits=4) - sage: u.is_sparse() + sage: v = vector(QQ, [1/2, 0, 0, 1/3, 0, 0, 0, 1/4], sparse=True) # optional - sage.modules + sage: u = v.numerical_approx(digits=4) # optional - sage.modules + sage: u.is_sparse() # optional - sage.modules True - sage: u + sage: u # optional - sage.modules (0.5000, 0.0000, 0.0000, 0.3333, 0.0000, 0.0000, 0.0000, 0.2500) - sage: A = matrix(QQ, 2, 3, range(6)) - sage: A.n() + sage: A = matrix(QQ, 2, 3, range(6)) # optional - sage.modules + sage: A.n() # optional - sage.modules [0.000000000000000 1.00000000000000 2.00000000000000] [ 3.00000000000000 4.00000000000000 5.00000000000000] - sage: B = matrix(Integers(12), 3, 8, srange(24)) - sage: N(B, digits=2) + sage: B = matrix(Integers(12), 3, 8, srange(24)) # optional - sage.modules + sage: N(B, digits=2) # optional - sage.modules [0.00 1.0 2.0 3.0 4.0 5.0 6.0 7.0] [ 8.0 9.0 10. 11. 0.00 1.0 2.0 3.0] [ 4.0 5.0 6.0 7.0 8.0 9.0 10. 11.] @@ -1485,13 +1491,13 @@ def numerical_approx(x, prec=None, digits=None, algorithm=None): Therefore, numbers which look the same in their decimal expansion might be different:: - sage: x=N(pi, digits=3); x + sage: x = N(pi, digits=3); x # optional - sage.symbolic 3.14 - sage: y=N(3.14, digits=3); y + sage: y = N(3.14, digits=3); y 3.14 - sage: x==y + sage: x == y # optional - sage.symbolic False - sage: x.str(base=2) + sage: x.str(base=2) # optional - sage.symbolic '11.001001000100' sage: y.str(base=2) '11.001000111101' @@ -1514,23 +1520,23 @@ def numerical_approx(x, prec=None, digits=None, algorithm=None): As an exceptional case, ``digits=1`` usually leads to 2 digits (one significant) in the decimal output (see :trac:`11647`):: - sage: N(pi, digits=1) + sage: N(pi, digits=1) # optional - sage.symbolic 3.2 - sage: N(pi, digits=2) + sage: N(pi, digits=2) # optional - sage.symbolic 3.1 - sage: N(100*pi, digits=1) + sage: N(100*pi, digits=1) # optional - sage.symbolic 320. - sage: N(100*pi, digits=2) + sage: N(100*pi, digits=2) # optional - sage.symbolic 310. In the following example, ``pi`` and ``3`` are both approximated to two bits of precision and then subtracted, which kills two bits of precision:: - sage: N(pi, prec=2) + sage: N(pi, prec=2) # optional - sage.symbolic 3.0 sage: N(3, prec=2) 3.0 - sage: N(pi - 3, prec=2) + sage: N(pi - 3, prec=2) # optional - sage.symbolic 0.00 TESTS:: @@ -1538,8 +1544,8 @@ def numerical_approx(x, prec=None, digits=None, algorithm=None): sage: numerical_approx(I) 1.00000000000000*I sage: x = QQ['x'].gen() - sage: F. = NumberField(x^2+2, embedding=sqrt(CC(2))*CC.0) - sage: numerical_approx(k) + sage: F. = NumberField(x^2 + 2, embedding=sqrt(CC(2))*CC.0) # optional - sage.rings.number_field sage.symbolic + sage: numerical_approx(k) # optional - sage.rings.number_field sage.symbolic 1.41421356237309*I sage: type(numerical_approx(CC(1/2))) @@ -1548,11 +1554,11 @@ def numerical_approx(x, prec=None, digits=None, algorithm=None): The following tests :trac:`10761`, in which ``n()`` would break when called on complex-valued algebraic numbers. :: - sage: E = matrix(3, [3,1,6,5,2,9,7,3,13]).eigenvalues(); E + sage: E = matrix(3, [3,1,6,5,2,9,7,3,13]).eigenvalues(); E # optional - sage.modules sage.rings.number_field [18.16815365088822?, -0.08407682544410650? - 0.2190261484802906?*I, -0.08407682544410650? + 0.2190261484802906?*I] - sage: E[1].parent() + sage: E[1].parent() # optional - sage.modules sage.rings.number_field Algebraic Field - sage: [a.n() for a in E] + sage: [a.n() for a in E] # optional - sage.modules sage.rings.number_field [18.1681536508882, -0.0840768254441065 - 0.219026148480291*I, -0.0840768254441065 + 0.219026148480291*I] Make sure we've rounded up log(10,2) enough to guarantee @@ -1628,11 +1634,11 @@ def order(x): EXAMPLES:: - sage: C = CyclicPermutationGroup(10) - sage: order(C) + sage: C = CyclicPermutationGroup(10) # optional - sage.groups + sage: order(C) # optional - sage.groups 10 - sage: F = GF(7) - sage: order(F) + sage: F = GF(7) # optional - sage.rings.finite_rings + sage: order(F) # optional - sage.rings.finite_rings 7 """ return x.order() @@ -1646,9 +1652,9 @@ def rank(x): We compute the rank of a matrix:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,2,3,4,5,6,7,8,9]) - sage: rank(A) + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([1,2,3, 4,5,6, 7,8,9]) # optional - sage.modules + sage: rank(A) # optional - sage.modules 2 We compute the rank of an elliptic curve:: @@ -1666,7 +1672,7 @@ def regulator(x): EXAMPLES:: - sage: regulator(NumberField(x^2-2, 'a')) + sage: regulator(NumberField(x^2 - 2, 'a')) # optional - sage.rings.number_field 0.881373587019543 sage: regulator(EllipticCurve('11a')) 1.00000000000000 @@ -1684,17 +1690,17 @@ def round(x, ndigits=0): EXAMPLES:: - sage: round(sqrt(2),2) + sage: round(sqrt(2), 2) # optional - sage.symbolic 1.41 - sage: q = round(sqrt(2),5); q + sage: q = round(sqrt(2), 5); q # optional - sage.symbolic 1.41421 - sage: type(q) + sage: type(q) # optional - sage.symbolic - sage: q = round(sqrt(2)); q + sage: q = round(sqrt(2)); q # optional - sage.symbolic 1 - sage: type(q) + sage: type(q) # optional - sage.symbolic - sage: round(pi) + sage: round(pi) # optional - sage.symbolic 3 sage: b = 5.4999999999999999 sage: round(b) @@ -1708,7 +1714,7 @@ def round(x, ndigits=0): Since we use floating-point with a limited range, some roundings can't be performed:: - sage: round(sqrt(Integer('1'*1000)),2) + sage: round(sqrt(Integer('1'*1000)), 2) # optional - sage.symbolic +infinity IMPLEMENTATION: If ndigits is specified, it calls Python's builtin @@ -1746,13 +1752,13 @@ def quotient(x, y, *args, **kwds): EXAMPLES:: - sage: quotient(5,6) + sage: quotient(5, 6) 5/6 - sage: quotient(5.,6.) + sage: quotient(5., 6.) 0.833333333333333 sage: R. = ZZ[]; R Univariate Polynomial Ring in x over Integer Ring - sage: I = Ideal(R, x^2+1) + sage: I = Ideal(R, x^2 + 1) sage: quotient(R, I) Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 """ @@ -1806,7 +1812,7 @@ def squarefree_part(x): sage: x = QQ['x'].0 sage: S = squarefree_part(-9*x*(x-6)^7*(x-3)^2); S -9*x^2 + 54*x - sage: S.factor() + sage: S.factor() # optional - sage.libs.pari (-9) * (x - 6) * x :: @@ -1815,7 +1821,7 @@ def squarefree_part(x): x^10 - x^9 + 3*x^8 + 3*x^5 - 2*x^4 - x^3 - 2*x - 1 sage: g = squarefree_part(f); g x^4 - x^3 + x^2 - 1 - sage: g.factor() + sage: g.factor() # optional - sage.libs.pari (x - 1) * (x^3 + x + 1) """ try: @@ -1861,16 +1867,16 @@ def _do_sqrt(x, prec=None, extend=True, all=False): sage: from sage.misc.functional import _do_sqrt sage: _do_sqrt(3) sqrt(3) - sage: _do_sqrt(3,prec=10) + sage: _do_sqrt(3, prec=10) 1.7 - sage: _do_sqrt(3,prec=100) + sage: _do_sqrt(3, prec=100) 1.7320508075688772935274463415 - sage: _do_sqrt(3,all=True) + sage: _do_sqrt(3, all=True) # optional - sage.symbolic [sqrt(3), -sqrt(3)] Note that the extend parameter is ignored in the symbolic ring:: - sage: _do_sqrt(3,extend=False) + sage: _do_sqrt(3, extend=False) # optional - sage.symbolic sqrt(3) """ if prec: @@ -1916,23 +1922,23 @@ def sqrt(x, *args, **kwds): sage: sqrt(-1) 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:: @@ -1947,9 +1953,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' @@ -1968,9 +1974,9 @@ def sqrt(x, *args, **kwds): One can use numpy input as well:: - sage: import numpy - sage: a = numpy.arange(2,5) - sage: sqrt(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(2,5) # optional - numpy + sage: sqrt(a) # optional - numpy array([1.41421356, 1.73205081, 2. ]) """ if isinstance(x, float): @@ -1994,8 +2000,8 @@ def transpose(x): EXAMPLES:: - sage: M = MatrixSpace(QQ,3,3) - sage: A = M([1,2,3,4,5,6,7,8,9]) + sage: M = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: A = M([1,2,3, 4,5,6, 7,8,9]) # optional - sage.modules sage: transpose(A) [1 4 7] [2 5 8] diff --git a/src/sage/misc/inline_fortran.py b/src/sage/misc/inline_fortran.py index 6e71016c427..b10394630d1 100644 --- a/src/sage/misc/inline_fortran.py +++ b/src/sage/misc/inline_fortran.py @@ -112,10 +112,10 @@ def eval(self, x, globals=None, locals=None): ....: C END FILE FIB1.F ....: ''' sage: fortran(code, globals()) - sage: import numpy - sage: a = numpy.array(range(10), dtype=float) - sage: fib(a, 10) - sage: a + sage: import numpy # optional - numpy + sage: a = numpy.array(range(10), dtype=float) # optional - numpy + sage: fib(a, 10) # optional - numpy + sage: a # optional - numpy array([ 0., 1., 1., 2., 3., 5., 8., 13., 21., 34.]) TESTS:: diff --git a/src/sage/misc/instancedoc.pyx b/src/sage/misc/instancedoc.pyx index 360d3f768b3..85a22a0b792 100644 --- a/src/sage/misc/instancedoc.pyx +++ b/src/sage/misc/instancedoc.pyx @@ -36,7 +36,8 @@ EXAMPLES:: For a Cython ``cdef class``, a decorator cannot be used. Instead, call :func:`instancedoc` as a function after defining the class:: - sage: cython(''' + sage: cython( # optional - sage.misc.cython + ....: ''' ....: from sage.misc.instancedoc import instancedoc ....: cdef class Y: ....: "Class docstring" @@ -44,9 +45,9 @@ For a Cython ``cdef class``, a decorator cannot be used. Instead, call ....: return "Instance docstring" ....: instancedoc(Y) ....: ''') - sage: Y.__doc__ + sage: Y.__doc__ # optional - sage.misc.cython 'File:...\nClass docstring' - sage: Y().__doc__ + sage: Y().__doc__ # optional - sage.misc.cython 'Instance docstring' One can still add a custom ``__doc__`` attribute on a particular @@ -59,7 +60,7 @@ instance:: This normally does not work on extension types:: - sage: Y().__doc__ = "Very special doc" + sage: Y().__doc__ = "Very special doc" # optional - sage.misc.cython Traceback (most recent call last): ... AttributeError: attribute '__doc__' of 'Y' objects is not writable diff --git a/src/sage/misc/latex.py b/src/sage/misc/latex.py index 5dc3fbe5ecd..4f36be67822 100644 --- a/src/sage/misc/latex.py +++ b/src/sage/misc/latex.py @@ -184,7 +184,8 @@ def list_function(x): '\\left[1, 2, 3\\right]' sage: latex([1,2,3]) # indirect doctest \left[1, 2, 3\right] - sage: latex([Matrix(ZZ,3,range(9)), Matrix(ZZ,3,range(9))]) # indirect doctest + sage: latex([Matrix(ZZ, 3, range(9)), # indirect doctest # optional - sage.modules + ....: Matrix(ZZ, 3, range(9))]) \left[\left(\begin{array}{rrr} 0 & 1 & 2 \\ 3 & 4 & 5 \\ @@ -367,11 +368,11 @@ def dict_function(x): EXAMPLES:: sage: from sage.misc.latex import dict_function - sage: x,y,z = var('x,y,z') - sage: print(dict_function({x/2: y^2})) + sage: x,y,z = var('x,y,z') # optional - sage.symbolic + sage: print(dict_function({x/2: y^2})) # optional - sage.symbolic \left\{\frac{1}{2} \, x : y^{2}\right\} - sage: d = {(1,2,x^2): [sin(z^2), y/2]} - sage: latex(d) + sage: d = {(1,2,x^2): [sin(z^2), y/2]} # optional - sage.symbolic + sage: latex(d) # optional - sage.symbolic \left\{\left(1, 2, x^{2}\right) : \left[\sin\left(z^{2}\right), \frac{1}{2} \, y\right]\right\} """ @@ -450,9 +451,9 @@ class LatexExpr(str): EXAMPLES:: - sage: latex(x^20 + 1) + sage: latex(x^20 + 1) # optional - sage.symbolic x^{20} + 1 - sage: LatexExpr(r"\frac{x^2 + 1}{x - 2}") + sage: LatexExpr(r"\frac{x^2 + 1}{x - 2}") # optional - sage.symbolic \frac{x^2 + 1}{x - 2} ``LatexExpr`` simply converts to string without doing anything @@ -465,15 +466,15 @@ class LatexExpr(str): The result of :func:`latex` is of type ``LatexExpr``:: - sage: L = latex(x^20 + 1) - sage: L + sage: L = latex(x^20 + 1) # optional - sage.symbolic + sage: L # optional - sage.symbolic x^{20} + 1 - sage: type(L) + sage: type(L) # optional - sage.symbolic A ``LatexExpr`` can be converted to a plain string:: - sage: str(latex(x^20 + 1)) + sage: str(latex(x^20 + 1)) # optional - sage.symbolic 'x^{20} + 1' """ def __add__(self, other): @@ -558,7 +559,7 @@ def has_latex_attr(x) -> bool: EXAMPLES:: sage: from sage.misc.latex import has_latex_attr - sage: has_latex_attr(identity_matrix(3)) + sage: has_latex_attr(identity_matrix(3)) # optional - sage.modules True sage: has_latex_attr("abc") # strings have no _latex_ method False @@ -566,15 +567,15 @@ def has_latex_attr(x) -> bool: Types inherit the ``_latex_`` method of the class to which they refer, but calling it is broken:: - sage: T = type(identity_matrix(3)); T + sage: T = type(identity_matrix(3)); T # optional - sage.modules - sage: hasattr(T, '_latex_') + sage: hasattr(T, '_latex_') # optional - sage.modules True - sage: T._latex_() + sage: T._latex_() # optional - sage.modules Traceback (most recent call last): ... TypeError: ..._latex_... needs an argument - sage: has_latex_attr(T) + sage: has_latex_attr(T) # optional - sage.modules False """ return hasattr(x, '_latex_') and not isinstance(x, type) @@ -917,12 +918,12 @@ def __call__(self, x, combine_all=False): 3 sage: latex(1==0) \mathrm{False} - sage: print(latex([x,2])) + sage: print(latex([x, 2])) # optional - sage.symbolic \left[x, 2\right] Check that :trac:`11775` is fixed:: - sage: latex((x,2), combine_all=True) + sage: latex((x,2), combine_all=True) # optional - sage.symbolic x 2 """ if has_latex_attr(x): @@ -961,9 +962,9 @@ class Latex(LatexCall): EXAMPLES:: - sage: latex(x^20 + 1) + sage: latex(x^20 + 1) # optional - sage.symbolic x^{20} + 1 - sage: latex(FiniteField(25,'a')) + sage: latex(FiniteField(25,'a')) # optional - sage.libs.pari \Bold{F}_{5^{2}} sage: latex("hello") \text{\texttt{hello}} @@ -973,7 +974,7 @@ class Latex(LatexCall): LaTeX expressions can be added; note that a space is automatically inserted:: - sage: LatexExpr(r"y \neq") + latex(x^20 + 1) + sage: LatexExpr(r"y \neq") + latex(x^20 + 1) # optional - sage.symbolic y \neq x^{20} + 1 """ def __init__(self, debug=False, slide=False, density=150, pdflatex=None, engine=None): @@ -1212,18 +1213,18 @@ def matrix_delimiters(self, left=None, right=None): EXAMPLES:: - sage: a = matrix(1, 1, [17]) - sage: latex(a) + sage: a = matrix(1, 1, [17]) # optional - sage.modules + sage: latex(a) # optional - sage.modules \left(\begin{array}{r} 17 \end{array}\right) sage: latex.matrix_delimiters("[", "]") - sage: latex(a) + sage: latex(a) # optional - sage.modules \left[\begin{array}{r} 17 \end{array}\right] sage: latex.matrix_delimiters(left="\\{") - sage: latex(a) + sage: latex(a) # optional - sage.modules \left\{\begin{array}{r} 17 \end{array}\right] @@ -1273,14 +1274,14 @@ def vector_delimiters(self, left=None, right=None): EXAMPLES:: - sage: a = vector(QQ, [1,2,3]) - sage: latex(a) + sage: a = vector(QQ, [1,2,3]) # optional - sage.modules + sage: latex(a) # optional - sage.modules \left(1,\,2,\,3\right) sage: latex.vector_delimiters("[", "]") - sage: latex(a) + sage: latex(a) # optional - sage.modules \left[1,\,2,\,3\right] sage: latex.vector_delimiters(right="\\}") - sage: latex(a) + sage: latex(a) # optional - sage.modules \left[1,\,2,\,3\right\} sage: latex.vector_delimiters() ['[', '\\}'] @@ -1318,18 +1319,18 @@ def matrix_column_alignment(self, align=None): EXAMPLES:: - sage: a = matrix(1, 1, [42]) - sage: latex(a) + sage: a = matrix(1, 1, [42]) # optional - sage.modules + sage: latex(a) # optional - sage.modules \left(\begin{array}{r} 42 \end{array}\right) sage: latex.matrix_column_alignment('c') - sage: latex(a) + sage: latex(a) # optional - sage.modules \left(\begin{array}{c} 42 \end{array}\right) sage: latex.matrix_column_alignment('l') - sage: latex(a) + sage: latex(a) # optional - sage.modules \left(\begin{array}{l} 42 \end{array}\right) @@ -2019,7 +2020,7 @@ def coeff_repr(c): sage: from sage.misc.latex import coeff_repr sage: coeff_repr(QQ(1/2)) '\\frac{1}{2}' - sage: coeff_repr(-x^2) + sage: coeff_repr(-x^2) # optional - sage.symbolic '\\left(-x^{2}\\right)' """ try: @@ -2198,8 +2199,8 @@ def latex_varify(a, is_fname=False): TESTS: - sage: abc = var('abc') - sage: latex((abc/(abc+1)+42)/(abc-1)) # trac #15870 + sage: abc = var('abc') # optional - sage.symbolic + sage: latex((abc/(abc+1)+42)/(abc-1)) # trac #15870 # optional - sage.symbolic \frac{\frac{\mathit{abc}}{\mathit{abc} + 1} + 42}{\mathit{abc} - 1} """ if a in common_varnames: @@ -2270,12 +2271,12 @@ def latex_variable_name(x, is_fname=False): TESTS:: - sage: latex_variable_name('_C') # trac #16007 + sage: latex_variable_name('_C') # trac #16007 # optional - sage.symbolic 'C' - sage: latex_variable_name('_K1') + sage: latex_variable_name('_K1') # optional - sage.symbolic 'K_{1}' - sage: latex_variable_name('5') + sage: latex_variable_name('5') # optional - sage.symbolic '5' """ # if x is an integer (it might be the case for padics), we return x diff --git a/src/sage/misc/latex_standalone.py b/src/sage/misc/latex_standalone.py index cd42519c5ec..9c5604d379f 100644 --- a/src/sage/misc/latex_standalone.py +++ b/src/sage/misc/latex_standalone.py @@ -156,35 +156,36 @@ tikzpicture code generated by Sage from some polyhedron:: sage: from sage.misc.latex_standalone import TikzPicture - sage: V = [[1,0,1],[1,0,0],[1,1,0],[0,0,-1],[0,1,0],[-1,0,0],[0,1,1],[0,0,1],[0,-1,0]] - sage: P = Polyhedron(vertices=V).polar() - sage: s = P.projection().tikz([674,108,-731],112, output_type='LatexExpr') - sage: t = TikzPicture(s) + sage: V = [[1,0,1], [1,0,0], [1,1,0], [0,0,-1], + ....: [0,1,0], [-1,0,0], [0,1,1], [0,0,1], [0,-1,0]] + sage: P = Polyhedron(vertices=V).polar() # optional - sage.geometry.polyhedron + sage: s = P.projection().tikz([674,108,-731],112, output_type='LatexExpr') # optional - sage.geometry.polyhedron sage.plot + sage: t = TikzPicture(s) # optional - sage.geometry.polyhedron sage.plot Open the image in a viewer (the returned value is a string giving the absolute path to the file in some temporary directory):: - sage: path_to_file = t.pdf() # not tested + sage: path_to_file = t.pdf() # not tested # optional - sage.geometry.polyhedron sage.plot Instead, you may save a pdf of the tikzpicture into a file of your choice (but this does not open the viewer):: - sage: _ = t.pdf('tikz_polytope.pdf') # not tested + sage: _ = t.pdf('tikz_polytope.pdf') # not tested # optional - sage.geometry.polyhedron sage.plot Opening the image in a viewer can be turned off:: - sage: _ = t.pdf(view=False) # long time (2s) # optional latex + sage: _ = t.pdf(view=False) # long time (2s) # optional latex # optional - sage.geometry.polyhedron sage.plot The same can be done with png format (translated from pdf with convert command which needs the installation of imagemagick):: - sage: _ = t.png(view=False) # long time (2s) # optional latex imagemagick + sage: _ = t.png(view=False) # long time (2s) # optional latex imagemagick # optional - sage.geometry.polyhedron sage.plot The string representation gives the header (5 lines) and tail (5 lines) of the tikzpicture. In Jupyter, it will instead use rich representation and show the image directly below the cell in png or svg format:: - sage: t + sage: t # optional - sage.geometry.polyhedron sage.plot \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture}% @@ -201,21 +202,22 @@ Use ``print(t)`` to see the complete content of the file:: - sage: print(t) # not tested + sage: print(t) # not tested # optional - sage.geometry.polyhedron sage.plot Adding a border in the options avoids cropping the vertices of a graph:: - sage: g = graphs.PetersenGraph() # optional - sage.graphs - sage: s = latex(g) # takes 3s but the result is cached # optional latex sage.graphs - sage: t = TikzPicture(s, standalone_config=["border=4mm"], usepackage=['tkz-graph']) # optional latex sage.graphs + sage: g = graphs.PetersenGraph() # optional - sage.graphs + sage: s = latex(g) # takes 3s but the result is cached # optional - latex sage.graphs + sage: t = TikzPicture(s, standalone_config=["border=4mm"], # optional - latex sage.graphs + ....: usepackage=['tkz-graph']) sage: _ = t.pdf() # not tested The current latex representation of a transducer is a tikzpicture using the tikz library automata. The string can be used as input:: - sage: s = latex(transducers.GrayCode()) # optional sage.combinat - sage: t = TikzPicture(s, usetikzlibrary=['automata']) # optional sage.combinat - sage: _ = t.pdf(view=False) # long time (2s) # optional sage.combinat latex + sage: s = latex(transducers.GrayCode()) # optional - sage.combinat + sage: t = TikzPicture(s, usetikzlibrary=['automata']) # optional - sage.combinat + sage: _ = t.pdf(view=False) # long time (2s) # optional - latex sage.combinat AUTHORS: @@ -1467,17 +1469,17 @@ def from_dot_string(cls, dotdata, prog='dot'): :: - sage: W = CoxeterGroup(["A",2]) - sage: G = W.cayley_graph() # optional sage.graphs - sage: dotdata = G.graphviz_string() # optional sage.graphs - sage: tikz = TikzPicture.from_dot_string(dotdata) # optional sage.graphs dot2tex graphviz # long time (3s) - sage: _ = tikz.pdf() # not tested + sage: W = CoxeterGroup(["A",2]) # optional - sage.combinat sage.groups + sage: G = W.cayley_graph() # optional sage.graphs # optional - sage.combinat sage.groups + sage: dotdata = G.graphviz_string() # optional sage.graphs # optional - sage.combinat sage.groups + sage: tikz = TikzPicture.from_dot_string(dotdata) # optional sage.graphs dot2tex graphviz # long time (3s) # optional - sage.combinat sage.groups + sage: _ = tikz.pdf() # not tested # optional - sage.combinat sage.groups :: - sage: dotdata = G.graphviz_string(labels='latex') # optional sage.graphs - sage: tikz = TikzPicture.from_dot_string(dotdata) # optional sage.graphs dot2tex graphviz # long time (3s) - sage: _ = tikz.pdf() # not tested + sage: dotdata = G.graphviz_string(labels='latex') # optional sage.graphs # optional - sage.combinat sage.groups + sage: tikz = TikzPicture.from_dot_string(dotdata) # optional sage.graphs dot2tex graphviz # long time (3s) # optional - sage.combinat sage.groups + sage: _ = tikz.pdf() # not tested # optional - sage.combinat sage.groups """ from sage.features import PythonModule @@ -1558,11 +1560,11 @@ def from_graph(cls, graph, merge_multiedges=True, Using ``merge_multiedges``:: - sage: alpha = var('alpha') - sage: m = matrix(2,range(4)); m.set_immutable() - sage: G = DiGraph([(0,1,alpha), (0,1,0), (0,2,9), (0,2,m)], multiedges=True) # optional sage.graphs - sage: tikz = TikzPicture.from_graph(G, merge_multiedges=True) # optional sage.graphs dot2tex graphviz - sage: _ = tikz.pdf() # not tested + sage: alpha = var('alpha') # optional - sage.symbolic + sage: m = matrix(2, range(4)); m.set_immutable() # optional - sage.symbolic sage.modules + sage: G = DiGraph([(0,1,alpha), (0,1,0), (0,2,9), (0,2,m)], multiedges=True) # optional sage.graphs # optional - sage.symbolic sage.modules + sage: tikz = TikzPicture.from_graph(G, merge_multiedges=True) # optional sage.graphs dot2tex graphviz # optional - sage.symbolic sage.modules + sage: _ = tikz.pdf() # not tested # optional - sage.symbolic sage.modules Using ``merge_multiedges`` with ``merge_label_function``:: @@ -1576,18 +1578,18 @@ def from_graph(cls, graph, merge_multiedges=True, Using subgraphs clusters (broken when using labels, see :trac:`22070`):: - sage: S = FiniteSetMaps(5) - sage: I = S((0,1,2,3,4)) - sage: a = S((0,1,3,0,0)) - sage: b = S((0,2,4,1,0)) - sage: roots = [I] - sage: succ = lambda v:[v*a,v*b,a*v,b*v] - sage: R = RecursivelyEnumeratedSet(roots, succ) - sage: G = R.to_digraph() # optional sage.graphs - sage: G # optional sage.graphs + sage: S = FiniteSetMaps(5) # optional - sage.combinat + sage: I = S((0,1,2,3,4)) # optional - sage.combinat + sage: a = S((0,1,3,0,0)) # optional - sage.combinat + sage: b = S((0,2,4,1,0)) # optional - sage.combinat + sage: roots = [I] # optional - sage.combinat + sage: succ = lambda v: [v*a,v*b,a*v,b*v] # optional - sage.combinat + sage: R = RecursivelyEnumeratedSet(roots, succ) # optional - sage.combinat + sage: G = R.to_digraph() # optional - sage.graphs # optional - sage.combinat + sage: G # optional - sage.graphs # optional - sage.combinat Looped multi-digraph on 27 vertices - sage: C = G.strongly_connected_components() # optional sage.graphs - sage: tikz = TikzPicture.from_graph(G, # optional sage.graphs dot2tex graphviz + sage: C = G.strongly_connected_components() # optional - sage.graphs # optional - sage.combinat + sage: tikz = TikzPicture.from_graph(G, # optional - dot2tex graphviz sage.combinat sage.graphs ....: merge_multiedges=False, subgraph_clusters=C) sage: _ = tikz.pdf() # not tested diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index d4a6c12ed5a..7f2c76b3ffa 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -350,7 +350,7 @@ cdef class LazyImport(): sage: from sage.misc.lazy_import import LazyImport sage: rm = LazyImport('sage.matrix.special', 'random_matrix') - sage: rm._sage_argspec_() + sage: rm._sage_argspec_() # optional - sage.modules FullArgSpec(args=['ring', 'nrows', 'ncols', 'algorithm', 'implementation'], varargs='args', varkw='kwds', defaults=(None, 'randomize', None), kwonlyargs=[], kwonlydefaults=None, annotations={}) @@ -526,12 +526,12 @@ cdef class LazyImport(): We access the ``plot`` method:: - sage: Bar.plot + sage: Bar.plot # optional - sage.plot Now ``plot`` has been replaced in the dictionary of ``Foo``:: - sage: type(Foo.__dict__['plot']) + sage: type(Foo.__dict__['plot']) # optional - sage.plot <... 'function'> """ # Don't use the namespace of the class definition @@ -662,11 +662,11 @@ cdef class LazyImport(): """ TESTS:: - sage: from sympy import Matrix + sage: from sympy import Matrix # optional - sympy sage: import sage.all__sagemath_objects - sage: sage.all__sagemath_objects.foo = Matrix([[1,1],[0,1]]) - sage: lazy_import('sage.all__sagemath_objects', 'foo') - sage: foo.__matmul__(foo) + sage: sage.all__sagemath_objects.foo = Matrix([[1,1], [0,1]]) # optional - sympy + sage: lazy_import('sage.all__sagemath_objects', 'foo') # optional - sympy + sage: foo.__matmul__(foo) # optional - sympy Matrix([ [1, 2], [0, 1]]) @@ -1059,24 +1059,27 @@ def lazy_import(module, names, as_=None, *, ....: pass sage: type(Foo.__dict__['plot']) - sage: 'EXAMPLES' in Bar.plot.__doc__ + sage: 'EXAMPLES' in Bar.plot.__doc__ # optional - sage.plot True sage: type(Foo.__dict__['plot']) <... 'function'> If deprecated then a deprecation warning is issued:: - sage: lazy_import('sage.rings.padics.factory', 'Qp', 'my_Qp', deprecation=14275) - sage: my_Qp(5) + sage: lazy_import('sage.rings.padics.factory', 'Qp', 'my_Qp', + ....: deprecation=14275) + sage: my_Qp(5) # optional - sage.rings.padics doctest:...: DeprecationWarning: - Importing my_Qp from here is deprecated; please use "from sage.rings.padics.factory import Qp as my_Qp" instead. + Importing my_Qp from here is deprecated; + please use "from sage.rings.padics.factory import Qp as my_Qp" instead. See https://github.com/sagemath/sage/issues/14275 for details. 5-adic Field with capped relative precision 20 An example of deprecation with a message:: - sage: lazy_import('sage.rings.padics.factory', 'Qp', 'my_Qp_msg', deprecation=(14275, "This is an example.")) - sage: my_Qp_msg(5) + sage: lazy_import('sage.rings.padics.factory', 'Qp', 'my_Qp_msg', + ....: deprecation=(14275, "This is an example.")) + sage: my_Qp_msg(5) # optional - sage.rings.padics doctest:...: DeprecationWarning: This is an example. See https://github.com/sagemath/sage/issues/14275 for details. 5-adic Field with capped relative precision 20 @@ -1084,13 +1087,16 @@ def lazy_import(module, names, as_=None, *, An example of an import relying on a feature:: sage: from sage.features import PythonModule - sage: lazy_import('ppl', 'equation', feature=PythonModule('ppl', spkg='pplpy')) - sage: equation + sage: lazy_import('ppl', 'equation', + ....: feature=PythonModule('ppl', spkg='pplpy')) + sage: equation # optional - pplpy - sage: lazy_import('PyNormaliz', 'NmzListConeProperties', feature=PythonModule('PyNormaliz', spkg='pynormaliz')) # optional - pynormaliz - sage: NmzListConeProperties # optional - pynormaliz + sage: lazy_import('PyNormaliz', 'NmzListConeProperties', + ....: feature=PythonModule('PyNormaliz', spkg='pynormaliz')) + sage: NmzListConeProperties # optional - pynormaliz - sage: lazy_import('foo', 'not_there', feature=PythonModule('foo', spkg='non-existing-package')) + sage: lazy_import('foo', 'not_there', + ....: feature=PythonModule('foo', spkg='non-existing-package')) sage: not_there Failed lazy import: foo is not available. @@ -1243,15 +1249,15 @@ def clean_namespace(namespace=None): EXAMPLES:: sage: from sage.misc.lazy_import import attributes, clean_namespace - sage: from sage.calculus.calculus import maxima as C - sage: attributes(C)['_as_name'] + sage: from sage.calculus.calculus import maxima as C # optional - sage.symbolic + sage: attributes(C)['_as_name'] # optional - sage.symbolic 'maxima' - sage: attributes(C)['_namespace'] is sage.calculus.calculus.__dict__ + sage: attributes(C)['_namespace'] is sage.calculus.calculus.__dict__ # optional - sage.symbolic True - sage: clean_namespace(globals()) - sage: attributes(C)['_as_name'] + sage: clean_namespace(globals()) # optional - sage.symbolic + sage: attributes(C)['_as_name'] # optional - sage.symbolic 'C' - sage: attributes(C)['_namespace'] is globals() + sage: attributes(C)['_namespace'] is globals() # optional - sage.symbolic True """ cdef LazyImport w diff --git a/src/sage/misc/lazy_list.pyx b/src/sage/misc/lazy_list.pyx index 4e25ee39299..4888db138d0 100644 --- a/src/sage/misc/lazy_list.pyx +++ b/src/sage/misc/lazy_list.pyx @@ -11,11 +11,11 @@ EXAMPLES:: sage: from sage.misc.lazy_list import lazy_list sage: P = lazy_list(Primes()) - sage: P[100] + sage: P[100] # optional - sage.libs.pari 547 - sage: P[10:34] + sage: P[10:34] # optional - sage.libs.pari lazy list [31, 37, 41, ...] - sage: P[12:23].list() + sage: P[12:23].list() # optional - sage.libs.pari [41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83] sage: f = lazy_list((i**2 - 3*i for i in range(10))) @@ -306,23 +306,23 @@ def lazy_list_formatter(L, name='lazy list', :: 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: repr(L) == lazy_list_formatter(L) + sage: repr(L) == lazy_list_formatter(L) # optional - sage.libs.pari True - sage: lazy_list_formatter(L, name='primes') + sage: lazy_list_formatter(L, name='primes') # optional - sage.libs.pari 'primes [2, 3, 5, ...]' - sage: lazy_list_formatter(L, opening_delimiter='(', closing_delimiter=')') + sage: lazy_list_formatter(L, opening_delimiter='(', closing_delimiter=')') # optional - sage.libs.pari 'lazy list (2, 3, 5, ...)' - sage: lazy_list_formatter(L, opening_delimiter='', closing_delimiter='') + sage: lazy_list_formatter(L, opening_delimiter='', closing_delimiter='') # optional - sage.libs.pari 'lazy list 2, 3, 5, ...' - sage: lazy_list_formatter(L, separator='--') + sage: lazy_list_formatter(L, separator='--') # optional - sage.libs.pari 'lazy list [2--3--5--...]' - sage: lazy_list_formatter(L, more='and more') + sage: lazy_list_formatter(L, more='and more') # optional - sage.libs.pari 'lazy list [2, 3, 5, and more]' - sage: lazy_list_formatter(L, preview=10) + sage: lazy_list_formatter(L, preview=10) # optional - sage.libs.pari 'lazy list [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, ...]' - sage: lazy_list_formatter(L, name='primes', + sage: lazy_list_formatter(L, name='primes', # optional - sage.libs.pari ....: opening_delimiter='', closing_delimiter='', ....: separator=' ', more='->', preview=7) 'primes 2 3 5 7 11 13 17 ->' @@ -356,9 +356,9 @@ cdef class lazy_list_generic(): sage: from sage.misc.lazy_list import lazy_list sage: l = lazy_list(Primes()) - sage: l + sage: l # optional - sage.libs.pari lazy list [2, 3, 5, ...] - sage: l[200] + sage: l[200] # optional - sage.libs.pari 1229 """ @@ -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] @@ -430,11 +431,11 @@ cdef class lazy_list_generic(): Check that the cache is immutable:: sage: lazy = lazy_list(iter(Primes()))[:5] - sage: l = lazy.list(); l + sage: l = lazy.list(); l # optional - sage.libs.pari [2, 3, 5, 7, 11] - sage: l[0] = -1; l + sage: l[0] = -1; l # optional - sage.libs.pari [-1, 3, 5, 7, 11] - sage: lazy.list() + sage: lazy.list() # optional - sage.libs.pari [2, 3, 5, 7, 11] """ self._fit(self.stop - self.step) @@ -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/lazy_string.pyx b/src/sage/misc/lazy_string.pyx index 5119775bad6..3cae657a45d 100644 --- a/src/sage/misc/lazy_string.pyx +++ b/src/sage/misc/lazy_string.pyx @@ -520,22 +520,23 @@ cdef class _LazyString(): EXAMPLES:: sage: from sage.misc.lazy_string import lazy_string - sage: f = lambda op,A,B:"unsupported operand parent(s) for %s: '%s' and '%s'"%(op,A,B) - sage: R = GF(5) - sage: S = GF(3) - sage: D = lazy_string(f, '+', R, S) - sage: D + sage: def f(op, A, B): + ....: return "unsupported operand parent(s) for %s: '%s' and '%s'" % (op, A, B) + sage: R = GF(5) # optional - sage.libs.pari + sage: S = GF(3) # optional - sage.libs.pari + sage: D = lazy_string(f, '+', R, S) # optional - sage.libs.pari + sage: D # optional - sage.libs.pari l"unsupported operand parent(s) for +: 'Finite Field of size 5' and 'Finite Field of size 3'" - sage: D.update_lazy_string(('+', S, R), {}) + sage: D.update_lazy_string(('+', S, R), {}) # optional - sage.libs.pari Apparently, the lazy string got changed in-place:: - sage: D + sage: D # optional - sage.libs.pari l"unsupported operand parent(s) for +: 'Finite Field of size 3' and 'Finite Field of size 5'" TESTS:: - sage: D.update_lazy_string(None, None) + sage: D.update_lazy_string(None, None) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Expected tuple, got NoneType diff --git a/src/sage/misc/map_threaded.py b/src/sage/misc/map_threaded.py index c5eba670052..60342c108d7 100644 --- a/src/sage/misc/map_threaded.py +++ b/src/sage/misc/map_threaded.py @@ -10,19 +10,19 @@ def map_threaded(function, sequence): EXAMPLES:: - sage: map_threaded(log, [[1,2], [3,e]]) + sage: map_threaded(log, [[1,2], [3,e]]) # optional - sage.symbolic [[0, log(2)], [log(3), 1]] - sage: map_threaded(log, [(1,2), (3,e)]) + sage: map_threaded(log, [(1,2), (3,e)]) # optional - sage.symbolic [[0, log(2)], [log(3), 1]] - sage: map_threaded(N, [[1,2], [3,e]]) + sage: map_threaded(N, [[1,2], [3,e]]) # optional - sage.symbolic [[1.00000000000000, 2.00000000000000], [3.00000000000000, 2.71828182845905]] - sage: map_threaded((x^2).function(x), [[1,2,3,5], [2,10]]) + sage: map_threaded((x^2).function(x), [[1,2,3,5], [2,10]]) # optional - sage.symbolic [[1, 4, 9, 25], [4, 100]] map_threaded also works on any object with an apply_map method, e.g., on matrices:: - sage: map_threaded(lambda x: x^2, matrix([[1,2], [3,4]])) + sage: map_threaded(lambda x: x^2, matrix([[1,2], [3,4]])) # optional - sage.modules [ 1 4] [ 9 16] diff --git a/src/sage/misc/misc.py b/src/sage/misc/misc.py index f263f53bad3..7fc77390ee2 100644 --- a/src/sage/misc/misc.py +++ b/src/sage/misc/misc.py @@ -723,19 +723,19 @@ def compose(f, g): sage: def g(x): return 3*x sage: def f(x): return x + 1 - sage: h1 = compose(f,g) - sage: h2 = compose(g,f) - sage: _ = var ('x') - sage: h1(x) + sage: h1 = compose(f, g) + sage: h2 = compose(g, f) + sage: _ = var('x') # optional - sage.symbolic + sage: h1(x) # optional - sage.symbolic 3*x + 1 - sage: h2(x) + sage: h2(x) # optional - sage.symbolic 3*x + 3 :: - sage: _ = function('f g') - sage: _ = var ('x') - sage: compose(f,g)(x) + sage: _ = function('f g') # optional - sage.symbolic + sage: _ = var('x') # optional - sage.symbolic + sage: compose(f, g)(x) # optional - sage.symbolic f(g(x)) """ @@ -759,22 +759,22 @@ def nest(f, n, x): EXAMPLES:: sage: def f(x): return x^2 + 1 - sage: x = var('x') - sage: nest(f, 3, x) + sage: x = var('x') # optional - sage.symbolic + sage: nest(f, 3, x) # optional - sage.symbolic ((x^2 + 1)^2 + 1)^2 + 1 :: - sage: _ = function('f') - sage: _ = var('x') - sage: nest(f, 10, x) + sage: _ = function('f') # optional - sage.symbolic + sage: _ = var('x') # optional - sage.symbolic + sage: nest(f, 10, x) # optional - sage.symbolic f(f(f(f(f(f(f(f(f(f(x)))))))))) :: - sage: _ = function('f') - sage: _ = var('x') - sage: nest(f, 0, x) + sage: _ = function('f') # optional - sage.symbolic + sage: _ = var('x') # optional - sage.symbolic + sage: nest(f, 0, x) # optional - sage.symbolic x """ @@ -821,15 +821,15 @@ def __rmul__(self, left): """ EXAMPLES:: - sage: A = random_matrix(ZZ, 4) - sage: while A.rank() != 4: + sage: A = random_matrix(ZZ, 4) # optional - sage.modules + sage: while A.rank() != 4: # optional - sage.modules ....: A = random_matrix(ZZ, 4) - sage: B = random_matrix(ZZ, 4) - sage: temp = A * BackslashOperator() - sage: temp.left is A + sage: B = random_matrix(ZZ, 4) # optional - sage.modules + sage: temp = A * BackslashOperator() # optional - sage.modules + sage: temp.left is A # optional - sage.modules True - sage: X = temp * B - sage: A * X == B + sage: X = temp * B # optional - sage.modules + sage: A * X == B # optional - sage.modules True """ self.left = left @@ -839,16 +839,16 @@ def __mul__(self, right): r""" EXAMPLES:: - sage: A = matrix(RDF, 5, 5, 2) - sage: b = vector(RDF, 5, range(5)) - sage: v = A \ b - sage: v.zero_at(1e-19) # On at least one platform, we get a "negative zero" + sage: A = matrix(RDF, 5, 5, 2) # optional - sage.modules + sage: b = vector(RDF, 5, range(5)) # optional - sage.modules + sage: v = A \ b # optional - sage.modules + sage: v.zero_at(1e-19) # On at least one platform, we get a "negative zero" # optional - sage.modules (0.0, 0.5, 1.0, 1.5, 2.0) - sage: v = A._backslash_(b) - sage: v.zero_at(1e-19) + sage: v = A._backslash_(b) # optional - sage.modules + sage: v.zero_at(1e-19) # optional - sage.modules (0.0, 0.5, 1.0, 1.5, 2.0) - sage: v = A * BackslashOperator() * b - sage: v.zero_at(1e-19) + sage: v = A * BackslashOperator() * b # optional - sage.modules + sage: v.zero_at(1e-19) # optional - sage.modules (0.0, 0.5, 1.0, 1.5, 2.0) """ return self.left._backslash_(right) @@ -893,10 +893,10 @@ def is_iterator(it) -> bool: sage: list(x) [4, 3, 2, 1] - sage: P = Partitions(3) - sage: is_iterator(P) + sage: P = Partitions(3) # optional - sage.combinat + sage: is_iterator(P) # optional - sage.combinat False - sage: is_iterator(iter(P)) + sage: is_iterator(iter(P)) # optional - sage.combinat True """ # see trac #7398 for a discussion diff --git a/src/sage/misc/misc_c.pyx b/src/sage/misc/misc_c.pyx index 20a0fe0016c..d3b65c93434 100644 --- a/src/sage/misc/misc_c.pyx +++ b/src/sage/misc/misc_c.pyx @@ -745,7 +745,7 @@ def cyflush(): EXAMPLES:: sage: R. = QQ[] - sage: t^(sys.maxsize//2) + sage: t^(sys.maxsize//2) # optional - sage.libs.flint Traceback (most recent call last): ... RuntimeError: FLINT exception diff --git a/src/sage/misc/parser.pyx b/src/sage/misc/parser.pyx index 29d7a9cd7a0..d6cc6b9c58e 100644 --- a/src/sage/misc/parser.pyx +++ b/src/sage/misc/parser.pyx @@ -480,18 +480,19 @@ cdef class Parser: sage: p.parse("1+2 == 3") True - sage: p = Parser(make_var=var) - sage: p.parse("a*b^c - 3a") + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.parse("a*b^c - 3a") # optional - sage.symbolic a*b^c - 3*a sage: R. = QQ[] - sage: p = Parser(make_var = {'x': x }) + sage: p = Parser(make_var={'x': x}) sage: p.parse("(x+1)^5-x") x^5 + 5*x^4 + 10*x^3 + 10*x^2 + 4*x + 1 sage: p.parse("(x+1)^5-x").parent() is R True - sage: p = Parser(make_float=RR, make_var=var, make_function={'foo': (lambda x: x*x+x)}) + sage: p = Parser(make_float=RR, make_var=var, + ....: make_function={'foo': (lambda x: x*x+x)}) sage: p.parse("1.5 + foo(b)") b^2 + b + 1.50000000000000 sage: p.parse("1.9").parent() @@ -513,8 +514,8 @@ cdef class Parser: EXAMPLES:: - sage: from sage.calculus.calculus import SR_parser - sage: SR_parser._variable_constructor() + sage: from sage.calculus.calculus import SR_parser # optional - sage.symbolic + sage: SR_parser._variable_constructor() # optional - sage.symbolic b")) + sage: p.p_eqn(Tokenizer("a > b")) # optional - sage.symbolic a > b - sage: p.p_eqn(Tokenizer("a <= b")) + sage: p.p_eqn(Tokenizer("a <= b")) # optional - sage.symbolic a <= b - sage: p.p_eqn(Tokenizer("a >= b")) + sage: p.p_eqn(Tokenizer("a >= b")) # optional - sage.symbolic a >= b - sage: p.p_eqn(Tokenizer("a != b")) + sage: p.p_eqn(Tokenizer("a != b")) # optional - sage.symbolic a != b """ lhs = self.p_expr(tokens) @@ -775,16 +776,16 @@ cdef class Parser: EXAMPLES:: sage: from sage.misc.parser import Parser, Tokenizer - sage: p = Parser(make_var=var) - sage: p.p_expr(Tokenizer("a+b")) + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.p_expr(Tokenizer("a+b")) # optional - sage.symbolic a + b - sage: p.p_expr(Tokenizer("a")) + sage: p.p_expr(Tokenizer("a")) # optional - sage.symbolic a - sage: p.p_expr(Tokenizer("a - b + 4*c - d^2")) + sage: p.p_expr(Tokenizer("a - b + 4*c - d^2")) # optional - sage.symbolic -d^2 + a - b + 4*c - sage: p.p_expr(Tokenizer("a - -3")) + sage: p.p_expr(Tokenizer("a - -3")) # optional - sage.symbolic a + 3 - sage: p.p_expr(Tokenizer("a + 1 == b")) + sage: p.p_expr(Tokenizer("a + 1 == b")) # optional - sage.symbolic a + 1 """ # Note: this is left-recursive, so we can't just recurse @@ -809,16 +810,16 @@ cdef class Parser: EXAMPLES:: sage: from sage.misc.parser import Parser, Tokenizer - sage: p = Parser(make_var=var) - sage: p.p_term(Tokenizer("a*b")) + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.p_term(Tokenizer("a*b")) # optional - sage.symbolic a*b - sage: p.p_term(Tokenizer("a * b / c * d")) + sage: p.p_term(Tokenizer("a * b / c * d")) # optional - sage.symbolic a*b*d/c - sage: p.p_term(Tokenizer("-a * b + c")) + sage: p.p_term(Tokenizer("-a * b + c")) # optional - sage.symbolic -a*b - sage: p.p_term(Tokenizer("a*(b-c)^2")) + sage: p.p_term(Tokenizer("a*(b-c)^2")) # optional - sage.symbolic a*(b - c)^2 - sage: p.p_term(Tokenizer("-3a")) + sage: p.p_term(Tokenizer("-3a")) # optional - sage.symbolic -3*a """ # Note: this is left-recursive, so we can't just recurse @@ -885,12 +886,12 @@ cdef class Parser: sage: p.p_power(Tokenizer("2^3^2")) == 2^9 True - sage: p = Parser(make_var=var) - sage: p.p_factor(Tokenizer('x!')) + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.p_factor(Tokenizer('x!')) # optional - sage.symbolic factorial(x) - sage: p.p_factor(Tokenizer('(x^2)!')) + sage: p.p_factor(Tokenizer('(x^2)!')) # optional - sage.symbolic factorial(x^2) - sage: p.p_factor(Tokenizer('x!^2')) + sage: p.p_factor(Tokenizer('x!^2')) # optional - sage.symbolic factorial(x)^2 """ @@ -920,23 +921,24 @@ cdef class Parser: EXAMPLES:: sage: from sage.misc.parser import Parser, Tokenizer - sage: p = Parser(make_var=var, make_function={'sin': sin}) - sage: p.p_atom(Tokenizer("1")) + sage: p = Parser(make_var=var, make_function={'sin': sin}) # optional - sage.symbolic + sage: p.p_atom(Tokenizer("1")) # optional - sage.symbolic 1 - sage: p.p_atom(Tokenizer("12")) + sage: p.p_atom(Tokenizer("12")) # optional - sage.symbolic 12 - sage: p.p_atom(Tokenizer("12.5")) + sage: p.p_atom(Tokenizer("12.5")) # optional - sage.symbolic 12.5 - sage: p.p_atom(Tokenizer("(1+a)")) + sage: p.p_atom(Tokenizer("(1+a)")) # optional - sage.symbolic a + 1 - sage: p.p_atom(Tokenizer("(1+a)^2")) + sage: p.p_atom(Tokenizer("(1+a)^2")) # optional - sage.symbolic a + 1 - sage: p.p_atom(Tokenizer("sin(1+a)")) + sage: p.p_atom(Tokenizer("sin(1+a)")) # optional - sage.symbolic sin(a + 1) - sage: p = Parser(make_var=var, make_function={'foo': sage.misc.parser.foo}) - sage: p.p_atom(Tokenizer("foo(a, b, key=value)")) + sage: p = Parser(make_var=var, # optional - sage.symbolic + ....: make_function={'foo': sage.misc.parser.foo}) + sage: p.p_atom(Tokenizer("foo(a, b, key=value)")) # optional - sage.symbolic ((a, b), {'key': value}) - sage: p.p_atom(Tokenizer("foo()")) + sage: p.p_atom(Tokenizer("foo()")) # optional - sage.symbolic ((), {}) """ cdef int token = tokens.next() @@ -1007,22 +1009,22 @@ cdef class Parser: Parsing a normal expression:: sage: from sage.misc.parser import Parser, Tokenizer - sage: p = Parser(make_var=var) - sage: p.p_arg(Tokenizer("a+b")) + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.p_arg(Tokenizer("a+b")) # optional - sage.symbolic a + b A keyword expression argument:: sage: from sage.misc.parser import Parser, Tokenizer - sage: p = Parser(make_var=var) - sage: p.p_arg(Tokenizer("val=a+b")) + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.p_arg(Tokenizer("val=a+b")) # optional - sage.symbolic ('val', a + b) A lone list:: sage: from sage.misc.parser import Parser, Tokenizer - sage: p = Parser(make_var=var) - sage: p.p_arg(Tokenizer("[x]")) + sage: p = Parser(make_var=var) # optional - sage.symbolic + sage: p.p_arg(Tokenizer("[x]")) # optional - sage.symbolic [x] """ @@ -1054,12 +1056,12 @@ cdef class LookupNameMaker: EXAMPLES:: sage: from sage.misc.parser import LookupNameMaker - sage: maker = LookupNameMaker({'pi': pi}, var) - sage: maker('pi') + sage: maker = LookupNameMaker({'pi': pi}, var) # optional - sage.symbolic + sage: maker('pi') # optional - sage.symbolic pi - sage: maker('pi') is pi + sage: maker('pi') is pi # optional - sage.symbolic True - sage: maker('a') + sage: maker('a') # optional - sage.symbolic a """ self.names = names @@ -1071,8 +1073,8 @@ cdef class LookupNameMaker: sage: from sage.misc.parser import LookupNameMaker sage: maker = LookupNameMaker({}, str) - sage: maker.set_names({'a': x}) - sage: maker('a') is x + sage: maker.set_names({'a': x}) # optional - sage.symbolic + sage: maker('a') is x # optional - sage.symbolic True """ self.names = new_names @@ -1082,12 +1084,12 @@ cdef class LookupNameMaker: TESTS:: sage: from sage.misc.parser import LookupNameMaker - sage: maker = LookupNameMaker({'a': x}, str) - sage: maker('a') + sage: maker = LookupNameMaker({'a': x}, str) # optional - sage.symbolic + sage: maker('a') # optional - sage.symbolic x - sage: maker('a') is x + sage: maker('a') is x # optional - sage.symbolic True - sage: maker('b') + sage: maker('b') # optional - sage.symbolic 'b' """ try: diff --git a/src/sage/misc/persist.pyx b/src/sage/misc/persist.pyx index ca9b2894469..e221e1ad81a 100644 --- a/src/sage/misc/persist.pyx +++ b/src/sage/misc/persist.pyx @@ -239,22 +239,23 @@ def save(obj, filename, compress=True, **kwargs): sage: import tempfile sage: d = tempfile.TemporaryDirectory() - sage: a = matrix(2, [1,2,3,-5/2]) + sage: a = matrix(2, [1,2, 3,-5/2]) # optional - sage.modules sage: objfile = os.path.join(d.name, 'test.sobj') sage: objfile_short = os.path.join(d.name, 'test') - sage: save(a, objfile) - sage: load(objfile_short) + sage: save(a, objfile) # optional - sage.modules + sage: load(objfile_short) # optional - sage.modules [ 1 2] [ 3 -5/2] - sage: E = EllipticCurve([-1,0]) - sage: P = plot(E) - sage: save(P, objfile_short) # saves the plot to "test.sobj" - sage: save(P, filename=os.path.join(d.name, "sage.png"), xmin=-2) - sage: save(P, os.path.join(d.name, "filename.with.some.wrong.ext")) + sage: E = EllipticCurve([-1,0]) # optional - sage.plot + sage: P = plot(E) # optional - sage.plot + sage: save(P, objfile_short) # saves the plot to "test.sobj" # optional - sage.plot + sage: save(P, filename=os.path.join(d.name, "sage.png"), xmin=-2) # optional - sage.plot + sage: save(P, os.path.join(d.name, "filename.with.some.wrong.ext")) # optional - sage.plot Traceback (most recent call last): ... - ValueError: allowed file extensions for images are '.eps', '.pdf', '.pgf', '.png', '.ps', '.sobj', '.svg'! - sage: print(load(objfile)) + ValueError: allowed file extensions for images are + '.eps', '.pdf', '.pgf', '.png', '.ps', '.sobj', '.svg'! + sage: print(load(objfile)) # optional - sage.plot Graphics object consisting of 2 graphics primitives sage: save("A python string", os.path.join(d.name, 'test')) sage: load(objfile) @@ -397,19 +398,19 @@ def register_unpickle_override(module, name, callable, call_name=None): pickle to play with:: sage: from sage.structure.element import Element - sage: class SourPickle(CombinatorialObject): pass - sage: class SweetPickle(CombinatorialObject, Element): pass - sage: import __main__ - sage: __main__.SourPickle = SourPickle - sage: __main__.SweetPickle = SweetPickle # a hack to allow us to pickle command line classes - sage: gherkin = dumps(SourPickle([1, 2, 3])) + sage: class SourPickle(CombinatorialObject): pass # optional - sage.combinat + sage: class SweetPickle(CombinatorialObject, Element): pass # optional - sage.combinat + sage: import __main__ # optional - sage.combinat + sage: __main__.SourPickle = SourPickle # optional - sage.combinat + sage: __main__.SweetPickle = SweetPickle # a hack to allow us to pickle command line classes # optional - sage.combinat + sage: gherkin = dumps(SourPickle([1, 2, 3])) # optional - sage.combinat Using :func:`register_unpickle_override` we try to sweeten our pickle, but we are unable to eat it:: - sage: from sage.misc.persist import register_unpickle_override - sage: register_unpickle_override('__main__', 'SourPickle', SweetPickle) - sage: loads(gherkin) + sage: from sage.misc.persist import register_unpickle_override # optional - sage.combinat + sage: register_unpickle_override('__main__', 'SourPickle', SweetPickle) # optional - sage.combinat + sage: loads(gherkin) # optional - sage.combinat Traceback (most recent call last): ... KeyError: 0 @@ -420,7 +421,7 @@ def register_unpickle_override(module, name, callable, call_name=None): unpickling for :class:`CombinatorialObject`. We can fix this by explicitly defining a new :meth:`__setstate__` method:: - sage: class SweeterPickle(CombinatorialObject, Element): + sage: class SweeterPickle(CombinatorialObject, Element): # optional - sage.combinat ....: def __setstate__(self, state): ....: # a pickle from CombinatorialObject is just its instance ....: # dictionary @@ -433,11 +434,11 @@ def register_unpickle_override(module, name, callable, call_name=None): ....: if P is not None: ....: self._set_parent(P) ....: self.__dict__ = D - sage: __main__.SweeterPickle = SweeterPickle - sage: register_unpickle_override('__main__', 'SourPickle', SweeterPickle) - sage: loads(gherkin) + sage: __main__.SweeterPickle = SweeterPickle # optional - sage.combinat + sage: register_unpickle_override('__main__', 'SourPickle', SweeterPickle) # optional - sage.combinat + sage: loads(gherkin) # optional - sage.combinat [1, 2, 3] - sage: loads(dumps(SweeterPickle([1, 2, 3]))) # check that pickles work for SweeterPickle + sage: loads(dumps(SweeterPickle([1, 2, 3]))) # check that pickles work for SweeterPickle # optional - sage.combinat [1, 2, 3] The ``state`` passed to :meth:`__setstate__` will usually be something like @@ -574,7 +575,7 @@ def unpickle_global(module, name): Test that :func:`register_unpickle_override` calls in lazily imported modules are respected:: - sage: unpickle_global('sage.combinat.root_system.type_A', 'ambient_space') + sage: unpickle_global('sage.combinat.root_system.type_A', 'ambient_space') # optional - sage.combinat sage.modules """ unpickler = unpickle_override.get((module, name)) @@ -919,9 +920,9 @@ def loads(s, compress=True, **kwargs): EXAMPLES:: - sage: a = matrix(2, [1,2,3,-4/3]) - sage: s = dumps(a) - sage: loads(s) + sage: a = matrix(2, [1,2, 3,-4/3]) # optional - sage.modules + sage: s = dumps(a) # optional - sage.modules + sage: loads(s) # optional - sage.modules [ 1 2] [ 3 -4/3] @@ -1158,7 +1159,7 @@ def make_None(*args, **kwds): EXAMPLES:: sage: from sage.misc.persist import make_None - sage: print(make_None(42, pi, foo='bar')) + sage: print(make_None(42, pi, foo='bar')) # optional - sage.symbolic None """ return None 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 4af9306cb63..4c59c060350 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 @@ -679,8 +680,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 @@ -699,10 +700,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 ] """ @@ -738,8 +739,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: @@ -785,8 +786,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/repr.py b/src/sage/misc/repr.py index 80265ac3cc3..3ab32778840 100644 --- a/src/sage/misc/repr.py +++ b/src/sage/misc/repr.py @@ -20,11 +20,11 @@ def coeff_repr(c, is_latex=False): sage: from sage.misc.repr import coeff_repr sage: coeff_repr(QQ(1/2)) '1/2' - sage: coeff_repr(-x^2) + sage: coeff_repr(-x^2) # optional - sage.symbolic '(-x^2)' sage: coeff_repr(QQ(1/2), is_latex=True) '\\frac{1}{2}' - sage: coeff_repr(-x^2, is_latex=True) + sage: coeff_repr(-x^2, is_latex=True) # optional - sage.symbolic '\\left(-x^{2}\\right)' """ if not is_latex: @@ -131,12 +131,12 @@ def repr_lincomb(terms, is_latex=False, scalar_mult="*", strip_one=False, Verify that :trac:`31672` is fixed:: - sage: alpha = var("alpha") - sage: repr_lincomb([(x, alpha)], is_latex=True) + sage: alpha = var("alpha") # optional - sage.symbolic + sage: repr_lincomb([(x, alpha)], is_latex=True) # optional - sage.symbolic '\\alpha x' - sage: A. = PolynomialRing(QQ) - sage: B. = FreeAlgebra(A) - sage: (psi * t)._latex_() + sage: A. = PolynomialRing(QQ) # optional - sage.symbolic + sage: B. = FreeAlgebra(A) # optional - sage.combinat sage.modules sage.symbolic + sage: (psi * t)._latex_() # optional - sage.combinat sage.modules sage.symbolic '\\psi t' """ # Setting scalar_mult: symbol used for scalar multiplication diff --git a/src/sage/misc/rest_index_of_methods.py b/src/sage/misc/rest_index_of_methods.py index 5efb863ead3..c2ce7b640c2 100644 --- a/src/sage/misc/rest_index_of_methods.py +++ b/src/sage/misc/rest_index_of_methods.py @@ -52,7 +52,7 @@ def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True): EXAMPLES:: sage: from sage.misc.rest_index_of_methods import gen_rest_table_index - sage: print(gen_rest_table_index([graphs.PetersenGraph])) + sage: print(gen_rest_table_index([graphs.PetersenGraph])) # optional - sage.graphs .. csv-table:: :class: contentstable :widths: 30, 70 @@ -77,7 +77,7 @@ def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True): The table of a class:: - sage: print(gen_rest_table_index(Graph)) + sage: print(gen_rest_table_index(Graph)) # optional - sage.graphs .. csv-table:: :class: contentstable :widths: 30, 70 @@ -103,12 +103,12 @@ def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True): The inherited methods do not show up:: - sage: gen_rest_table_index(sage.combinat.posets.lattices.FiniteLatticePoset).count('\n') < 75 + sage: gen_rest_table_index(sage.combinat.posets.lattices.FiniteLatticePoset).count('\n') < 75 # optional - sage.combinat True - sage: from sage.graphs.generic_graph import GenericGraph - sage: A = gen_rest_table_index(Graph).count('\n') - sage: B = gen_rest_table_index(GenericGraph).count('\n') - sage: A < B + sage: from sage.graphs.generic_graph import GenericGraph # optional - sage.graphs + sage: A = gen_rest_table_index(Graph).count('\n') # optional - sage.graphs + sage: B = gen_rest_table_index(GenericGraph).count('\n') # optional - sage.graphs + sage: A < B # optional - sage.graphs True When ``only_local_functions`` is ``False``, we do not include @@ -141,9 +141,9 @@ def gen_rest_table_index(obj, names=None, sort=True, only_local_functions=True): A function that is imported into a class under a different name is listed under its 'new' name:: - sage: 'cliques_maximum' in gen_rest_table_index(Graph) + sage: 'cliques_maximum' in gen_rest_table_index(Graph) # optional - sage.graphs True - sage: 'all_max_cliques`' in gen_rest_table_index(Graph) + sage: 'all_max_cliques`' in gen_rest_table_index(Graph) # optional - sage.graphs False """ if names is None: @@ -223,17 +223,17 @@ def list_of_subfunctions(root, only_local_functions=True): EXAMPLES:: sage: from sage.misc.rest_index_of_methods import list_of_subfunctions - sage: l = list_of_subfunctions(Graph)[0] - sage: Graph.bipartite_color in l + sage: l = list_of_subfunctions(Graph)[0] # optional - sage.graphs + sage: Graph.bipartite_color in l # optional - sage.graphs True TESTS: A ``staticmethod`` is not callable. We must handle them correctly, however:: - sage: class A: + sage: class A: # optional - sage.graphs ....: x = staticmethod(Graph.order) - sage: list_of_subfunctions(A) + sage: list_of_subfunctions(A) # optional - sage.graphs ([], {: 'x'}) @@ -286,8 +286,8 @@ def gen_thematic_rest_table_index(root,additional_categories=None,only_local_fun EXAMPLES:: sage: from sage.misc.rest_index_of_methods import gen_thematic_rest_table_index, list_of_subfunctions - sage: l = list_of_subfunctions(Graph)[0] - sage: Graph.bipartite_color in l + sage: l = list_of_subfunctions(Graph)[0] # optional - sage.graphs + sage: Graph.bipartite_color in l # optional - sage.graphs True """ from collections import defaultdict diff --git a/src/sage/misc/sage_eval.py b/src/sage/misc/sage_eval.py index 8d0416a4cfd..5ff99c2512d 100644 --- a/src/sage/misc/sage_eval.py +++ b/src/sage/misc/sage_eval.py @@ -71,7 +71,7 @@ def sage_eval(source, locals=None, cmds='', preparse=True): 36 sage: eval('bernoulli(6)') 36 - sage: sage_eval('bernoulli(6)') + sage: sage_eval('bernoulli(6)') # optional - sage.libs.flint 1/42 :: @@ -132,13 +132,13 @@ def sage_eval(source, locals=None, cmds='', preparse=True): :: sage: R. = PolynomialRing(RationalField()) - sage: gap.eval('R:=PolynomialRing(Rationals,["x"]);') + sage: gap.eval('R:=PolynomialRing(Rationals,["x"]);') # optional - sage.libs.gap 'Rationals[x]' - sage: ff = gap.eval('x:=IndeterminatesOfPolynomialRing(R);; f:=x^2+1;'); ff + sage: ff = gap.eval('x:=IndeterminatesOfPolynomialRing(R);; f:=x^2+1;'); ff # optional - sage.libs.gap 'x^2+1' - sage: sage_eval(ff, locals={'x':x}) + sage: sage_eval(ff, locals={'x':x}) # optional - sage.libs.gap x^2 + 1 - sage: eval(ff) + sage: eval(ff) # optional - sage.libs.gap Traceback (most recent call last): ... RuntimeError: Use ** for exponentiation, not '^', which means xor @@ -212,7 +212,7 @@ def sageobj(x, vars=None): EXAMPLES:: - sage: type(sageobj(gp('34/56'))) + sage: type(sageobj(gp('34/56'))) # optional - sage.libs.pari sage: n = 5/2 sage: sageobj(n) is n @@ -224,12 +224,12 @@ def sageobj(x, vars=None): This illustrates interfaces:: - sage: f = gp('2/3') - sage: type(f) + sage: f = gp('2/3') # optional - sage.libs.pari + sage: type(f) # optional - sage.libs.pari - sage: f._sage_() + sage: f._sage_() # optional - sage.libs.pari 2/3 - sage: type(f._sage_()) + sage: type(f._sage_()) # optional - sage.libs.pari sage: a = gap(939393/2433) sage: a._sage_() diff --git a/src/sage/misc/sage_input.py b/src/sage/misc/sage_input.py index a50bf15d708..253610a27fb 100644 --- a/src/sage/misc/sage_input.py +++ b/src/sage/misc/sage_input.py @@ -13,7 +13,7 @@ sage: sage_input(3) 3 - sage: sage_input((polygen(RR) + RR(pi))^2, verify=True) + sage: sage_input((polygen(RR) + RR(pi))^2, verify=True) # optional - sage.symbolic # Verified R. = RR[] x^2 + 6.2831853071795862*x + 9.869604401089358 @@ -22,7 +22,7 @@ calling :func:`~sage.misc.sage_eval.sage_eval` on the result and verifying that it is equal to the input.:: - sage: sage_input(GF(2)(1), verify=True) + sage: sage_input(GF(2)(1), verify=True) # optional - sage.libs.pari # Verified GF(2)(1) @@ -202,21 +202,21 @@ def sage_input(x, preparse=True, verify=False, allow_locals=False): EXAMPLES:: - sage: sage_input(GF(2)(1)) + sage: sage_input(GF(2)(1)) # optional - sage.rings.finite_rings GF(2)(1) - sage: sage_input((GF(2)(0), GF(2)(1)), verify=True) + sage: sage_input((GF(2)(0), GF(2)(1)), verify=True) # optional - sage.rings.finite_rings # Verified GF_2 = GF(2) (GF_2(0), GF_2(1)) When the preparser is enabled, we use the \sage generator syntax.:: - sage: K. = GF(5)[] - sage: sage_input(x^3 + 2*x, verify=True) + sage: K. = GF(5)[] # optional - sage.rings.finite_rings + sage: sage_input(x^3 + 2*x, verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(5)[] x^3 + 2*x - sage: sage_input(x^3 + 2*x, preparse=False) + sage: sage_input(x^3 + 2*x, preparse=False) # optional - sage.rings.finite_rings R = GF(5)['x'] x = R.gen() x**3 + 2*x @@ -364,14 +364,14 @@ def __call__(self, x, coerced=False): 3 sage: sib = SageInputBuilder() - sage: sib.result(sib(GF(17)(5))) + sage: sib.result(sib(GF(17)(5))) # optional - sage.rings.finite_rings GF(17)(5) The argument ``coerced=True`` or ``coerced=2`` will get passed to the \method{_sage_input_} method of the argument.:: sage: sib = SageInputBuilder() - sage: sib.result(sib(GF(17)(5), True)) + sage: sib.result(sib(GF(17)(5), True)) # optional - sage.rings.finite_rings 5 sage: sib.result(sib(RealField(200)(1.5), True)) 1.5000000000000000000000000000000000000000000000000000000000000 @@ -626,9 +626,9 @@ def cache(self, x, sie, name): sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: sie42 = sib(GF(101)(42)) - sage: sib.cache(GF(101)(42), sie42, 'the_ultimate_answer') - sage: sib.result(sib(GF(101)(42)) + sib(GF(101)(42))) + sage: sie42 = sib(GF(101)(42)) # optional - sage.rings.finite_rings + sage: sib.cache(GF(101)(42), sie42, 'the_ultimate_answer') # optional - sage.rings.finite_rings + sage: sib.result(sib(GF(101)(42)) + sib(GF(101)(42))) # optional - sage.rings.finite_rings the_ultimate_answer = GF(101)(42) the_ultimate_answer + the_ultimate_answer @@ -636,9 +636,9 @@ def cache(self, x, sie, name): is only used once.:: sage: sib = SageInputBuilder() - sage: sie42 = sib(GF(101)(42)) - sage: sib.cache(GF(101)(42), sie42, 'the_ultimate_answer') - sage: sib.result(sib(GF(101)(42)) + sib(GF(101)(43))) + sage: sie42 = sib(GF(101)(42)) # optional - sage.rings.finite_rings + sage: sib.cache(GF(101)(42), sie42, 'the_ultimate_answer') # optional - sage.rings.finite_rings + sage: sib.result(sib(GF(101)(42)) + sib(GF(101)(43))) # optional - sage.rings.finite_rings GF_101 = GF(101) GF_101(42) + GF_101(43) """ @@ -1262,7 +1262,7 @@ def _sie_is_simple(self): sage: sib = SageInputBuilder() sage: sib.name('QQ')._sie_is_simple() True - sage: sib(GF(2))._sie_is_simple() + sage: sib(GF(2))._sie_is_simple() # optional - sage.rings.finite_rings False """ return False @@ -1276,7 +1276,7 @@ def _sie_referenced(self): sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: len(sib(GF(2))._sie_referenced()) + sage: len(sib(GF(2))._sie_referenced()) # optional - sage.rings.finite_rings 2 sage: sib(5)._sie_referenced() [] @@ -1295,16 +1295,16 @@ def _sie_prepare(self, sif): sage: from sage.misc.sage_input import SageInputBuilder, SageInputFormatter sage: sib = SageInputBuilder() sage: sif = SageInputFormatter() - sage: pair = sib((GF(2), GF(2))) - sage: single = sib(GF(2)) - sage: single._sie_refcount + sage: pair = sib((GF(2), GF(2))) # optional - sage.rings.finite_rings + sage: single = sib(GF(2)) # optional - sage.rings.finite_rings + sage: single._sie_refcount # optional - sage.rings.finite_rings 0 - sage: single._sie_use_var + sage: single._sie_use_var # optional - sage.rings.finite_rings False - sage: sib((GF(2), GF(2)))._sie_prepare(sif) - sage: single._sie_refcount + sage: sib((GF(2), GF(2)))._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: single._sie_refcount # optional - sage.rings.finite_rings 2 - sage: single._sie_use_var + sage: single._sie_use_var # optional - sage.rings.finite_rings True """ if self._sie_context is not sif: @@ -1827,8 +1827,8 @@ class SIE_call(SageInputExpression): sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: sie = sib.name('GF') - sage: sie(49) + sage: sie = sib.name('GF') # optional - sage.rings.finite_rings + sage: sie(49) # optional - sage.rings.finite_rings {call: {atomic:GF}({atomic:49})} """ @@ -1996,8 +1996,8 @@ def _sie_referenced(self): sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: sie = sib.name('GF')(5)['x,y'] - sage: sie._sie_referenced() + sage: sie = sib.name('GF')(5)['x,y'] # optional - sage.rings.finite_rings + sage: sie._sie_referenced() # optional - sage.rings.finite_rings [{call: {atomic:GF}({atomic:5})}, {atomic:'x,y'}] """ refs = [self._sie_coll] @@ -2190,8 +2190,8 @@ def _sie_referenced(self): sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: sie = sib((ZZ, GF(5))) - sage: sie._sie_referenced() + sage: sie = sib((ZZ, GF(5))) # optional - sage.rings.finite_rings + sage: sie._sie_referenced() # optional - sage.rings.finite_rings [{atomic:ZZ}, {call: {atomic:GF}({atomic:5})}] """ return self._sie_values @@ -2812,14 +2812,14 @@ def _sie_add_command(self, sif): We also can't use the preparser syntax if there is a conflict between generator names. For example, this works:: - sage: sage_input((polygen(ZZ), polygen(GF(17), 'y'))) + sage: sage_input((polygen(ZZ), polygen(GF(17), 'y'))) # optional - sage.rings.finite_rings R1. = ZZ[] R2. = GF(17)[] (x, y) but this can't use the preparser syntax.:: - sage: sage_input((polygen(ZZ), polygen(GF(17)))) + sage: sage_input((polygen(ZZ), polygen(GF(17)))) # optional - sage.rings.finite_rings R1 = ZZ['x'] x1 = R1.gen() R2 = GF(17)['x'] @@ -2829,7 +2829,7 @@ def _sie_add_command(self, sif): If we never use the generators, then we don't bother with the preparser syntax.:: - sage: sage_input((ZZ['x'], ZZ['x'], GF(17)['y'])) + sage: sage_input((ZZ['x'], ZZ['x'], GF(17)['y'])) # optional - sage.rings.finite_rings R = ZZ['x'] (R, R, GF(17)['y']) """ @@ -2958,11 +2958,11 @@ def _sie_prepare(self, sif): sage: sib = SageInputBuilder() sage: sif = SageInputFormatter() - sage: sie = sib.gen(GF(13)['z']) - sage: sie._sie_parent._sie_assign_gens + sage: sie = sib.gen(GF(13)['z']) # optional - sage.rings.finite_rings + sage: sie._sie_parent._sie_assign_gens # optional - sage.rings.finite_rings False - sage: sie._sie_prepare(sif) - sage: sie._sie_parent._sie_assign_gens + sage: sie._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: sie._sie_parent._sie_assign_gens # optional - sage.rings.finite_rings True """ super()._sie_prepare(sif) @@ -2982,11 +2982,11 @@ def _sie_format(self, sif): sage: sib = SageInputBuilder() sage: sif = SageInputFormatter() - sage: sie = sib.gen(GF(41)['x']) - sage: sie._sie_prepare(sif) - sage: sie._sie_format(sif) + sage: sie = sib.gen(GF(41)['x']) # optional - sage.rings.finite_rings + sage: sie._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: sie._sie_format(sif) # optional - sage.rings.finite_rings ('x', 42) - sage: sif._commands + sage: sif._commands # optional - sage.rings.finite_rings 'R. = GF(41)[]\n' """ self._sie_parent._sie_add_command(sif) @@ -3007,11 +3007,11 @@ def _sie_got_preferred(self, sif): sage: sib = SageInputBuilder() sage: sif = SageInputFormatter() - sage: v = sib.gen(GF(2)['x']); w = sib.gen(GF(3)['y']) - sage: v._sie_prepare(sif); w._sie_prepare(sif) - sage: v._sie_got_preferred(sif) + sage: v = sib.gen(GF(2)['x']); w = sib.gen(GF(3)['y']) # optional - sage.rings.finite_rings + sage: v._sie_prepare(sif); w._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: v._sie_got_preferred(sif) # optional - sage.rings.finite_rings True - sage: w._sie_got_preferred(sif) + sage: w._sie_got_preferred(sif) # optional - sage.rings.finite_rings True Now, we repeat the experiment, except that the generators now @@ -3021,11 +3021,11 @@ def _sie_got_preferred(self, sif): sage: sib = SageInputBuilder() sage: sif = SageInputFormatter() - sage: v = sib.gen(GF(2)['x']); w = sib.gen(GF(3)['x']) - sage: v._sie_prepare(sif); w._sie_prepare(sif) - sage: v._sie_got_preferred(sif) + sage: v = sib.gen(GF(2)['x']); w = sib.gen(GF(3)['x']) # optional - sage.rings.finite_rings + sage: v._sie_prepare(sif); w._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: v._sie_got_preferred(sif) # optional - sage.rings.finite_rings False - sage: w._sie_got_preferred(sif) + sage: w._sie_got_preferred(sif) # optional - sage.rings.finite_rings False """ return self._sie_get_varname(sif) == self._sie_preferred_varname @@ -3313,18 +3313,18 @@ def format(self, e, prec): sage: sib = SageInputBuilder() sage: sif = SageInputFormatter() - sage: sie = sib(GF(5)) + sage: sie = sib(GF(5)) # optional - sage.rings.finite_rings Here we ``cheat`` by calling \method{_sie_prepare} twice, to make it use a variable.:: - sage: sie._sie_prepare(sif) - sage: sie._sie_prepare(sif) - sage: sif._commands + sage: sie._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: sie._sie_prepare(sif) # optional - sage.rings.finite_rings + sage: sif._commands # optional - sage.rings.finite_rings '' - sage: sif.format(sie, 0) + sage: sif.format(sie, 0) # optional - sage.rings.finite_rings 'GF_5' - sage: sif._commands + sage: sif._commands # optional - sage.rings.finite_rings 'GF_5 = GF(5)\n' We demonstrate the use of commands, by showing how to construct @@ -3459,7 +3459,7 @@ def verify_same(a, b): ... assert(type(a) == type(b)) AssertionError - sage: verify_same(5, GF(7)(5)) + sage: verify_same(5, GF(7)(5)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... assert(a.parent() == b.parent()) diff --git a/src/sage/misc/sage_timeit.py b/src/sage/misc/sage_timeit.py index 8250b461dd4..41728099c39 100644 --- a/src/sage/misc/sage_timeit.py +++ b/src/sage/misc/sage_timeit.py @@ -37,7 +37,7 @@ class SageTimeitResult(): EXAMPLES:: sage: from sage.misc.sage_timeit import SageTimeitResult - sage: SageTimeitResult( (3, 5, int(8), pi, 'ms') ) + sage: SageTimeitResult( (3, 5, int(8), pi, 'ms') ) # optional - sage.symbolic 3 loops, best of 5: 3.1415927 ms per loop :: @@ -47,10 +47,10 @@ class SageTimeitResult(): sage: number = 7 sage: repeat = 13 sage: precision = int(5) - sage: best = pi / 10 ^ 9 + sage: best = pi / 10 ^ 9 # optional - sage.symbolic sage: order = 3 - sage: stats = (number, repeat, precision, best * scaling[order], units[order]) - sage: SageTimeitResult(stats) + sage: stats = (number, repeat, precision, best * scaling[order], units[order]) # optional - sage.symbolic + sage: SageTimeitResult(stats) # optional - sage.symbolic 7 loops, best of 13: 3.1416 ns per loop If the third argument is not a Python integer, a ``TypeError`` is raised:: @@ -69,10 +69,10 @@ def __init__(self, stats, series=None): EXAMPLES:: sage: from sage.misc.sage_timeit import SageTimeitResult - sage: SageTimeitResult( (3, 5, int(8), pi, 'ms') ) + sage: SageTimeitResult( (3, 5, int(8), pi, 'ms') ) # optional - sage.symbolic 3 loops, best of 5: 3.1415927 ms per loop - sage: s = SageTimeitResult( (3, 5, int(8), pi, 'ms'), [1.0,1.1,0.5]) - sage: s.series + sage: s = SageTimeitResult( (3, 5, int(8), pi, 'ms'), [1.0,1.1,0.5]) # optional - sage.symbolic + sage: s.series # optional - sage.symbolic [1.00000000000000, 1.10000000000000, 0.500000000000000] """ self.stats = stats @@ -85,8 +85,8 @@ def __repr__(self): EXAMPLES:: sage: from sage.misc.sage_timeit import SageTimeitResult - sage: stats = (1, 2, int(3), pi, 'ns') - sage: SageTimeitResult(stats) #indirect doctest + sage: stats = (1, 2, int(3), pi, 'ns') # optional - sage.symbolic + sage: SageTimeitResult(stats) #indirect doctest # optional - sage.symbolic 1 loop, best of 2: 3.14 ns per loop """ if self.stats[0] > 1: diff --git a/src/sage/misc/sage_timeit_class.pyx b/src/sage/misc/sage_timeit_class.pyx index d6b038c9de9..557f9725299 100644 --- a/src/sage/misc/sage_timeit_class.pyx +++ b/src/sage/misc/sage_timeit_class.pyx @@ -40,7 +40,7 @@ class SageTimeit: The input can contain newlines:: - sage: timeit("a = 2\nb=131\nfactor(a^b-1)", number=25) + sage: timeit("a = 2\nb=131\nfactor(a^b-1)", number=25) # optional - sage.libs.pari 25 loops, best of 3: ... per loop .. SEEALSO:: :func:`runsnake` diff --git a/src/sage/misc/sagedoc.py b/src/sage/misc/sagedoc.py index 5a69dbcb0cc..d453fb141b2 100644 --- a/src/sage/misc/sagedoc.py +++ b/src/sage/misc/sagedoc.py @@ -20,7 +20,7 @@ sage: from sage.env import SAGE_DOC sage: docfilename = os.path.join(SAGE_DOC, 'html', 'en', 'reference', 'calculus', 'sage', 'symbolic', 'expression.html') - sage: with open(docfilename) as fobj: # optional - sagemath_doc_html + sage: with open(docfilename) as fobj: # optional - sagemath_doc_html ....: for line in fobj: ....: if "#sage.symbolic.expression.Expression.numerical_approx" in line: ....: print(line) @@ -623,10 +623,10 @@ def format(s, embedded=False): EXAMPLES:: sage: from sage.misc.sagedoc import format - sage: identity_matrix(2).rook_vector.__doc__[191:263] + sage: identity_matrix(2).rook_vector.__doc__[191:263] # optional - sage.modules 'Let `A` be an `m` by `n` (0,1)-matrix. We identify `A` with a chessboard' - sage: format(identity_matrix(2).rook_vector.__doc__[191:263]) + sage: format(identity_matrix(2).rook_vector.__doc__[191:263]) # optional - sage.modules 'Let A be an m by n (0,1)-matrix. We identify A with a chessboard\n' If the first line of the string is 'nodetex', remove 'nodetex' but @@ -643,14 +643,14 @@ def format(s, embedded=False): 'identity_matrix>>>\n' sage: format('<<>>') '...Definition: identity_matrix(...' - sage: format('<<>>')[:28] # optional - sphinx + sage: format('<<>>')[:28] # optional - sphinx 'Definition: identity_matrix(' TESTS: We check that the todo Sphinx extension is correctly activated:: - sage: sage.misc.sagedoc.format(sage.combinat.ranker.on_fly.__doc__) # optional - sphinx + sage: sage.misc.sagedoc.format(sage.combinat.ranker.on_fly.__doc__) # optional - sphinx " Returns ... Todo: add tests as in combinat::rankers\n" In the following use case, the ``nodetex`` directive would have been ignored prior @@ -664,9 +664,9 @@ def format(s, embedded=False): ....: " `x \\geq y`", ....: " '''", ....: " return -x"] - sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython + sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython sage: from sage.misc.sageinspect import sage_getdoc - sage: print(sage_getdoc(testfunc)) # optional - sage.misc.cython + sage: print(sage_getdoc(testfunc)) # optional - sage.misc.cython This is a doc string with raw latex @@ -694,7 +694,7 @@ def format(s, embedded=False): Check that backslashes are preserved in code blocks (:trac:`29140`):: - sage: format('::\n' # optional - sphinx + sage: format('::\n' # optional - sphinx ....: '\n' ....: r' sage: print(r"\\\\.")' '\n' ....: r' \\\\.') @@ -1077,7 +1077,8 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='', Note that you can do tab completion on the ``module`` string. Another way to accomplish a similar search:: - sage: len(search_src("matrix", path_re="calc", interact=False).splitlines()) > 15 + sage: len(search_src("matrix", path_re="calc", # optional - sage.modules + ....: interact=False).splitlines()) > 15 True The following produces an error because the string 'fetch(' is a @@ -1106,7 +1107,8 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='', sage: s = search_src('MatRiX', path_re='matrix', interact=False); s.find('x') > 0 True - sage: s = search_src('MatRiX', path_re='matrix', interact=False, ignore_case=False); s.find('x') > 0 + sage: s = search_src('MatRiX', path_re='matrix', + ....: interact=False, ignore_case=False); s.find('x') > 0 False Searches are by default restricted to single lines, but this can @@ -1118,7 +1120,8 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='', sage: len(search_src('log', 'derivative', interact=False).splitlines()) < 40 True - sage: len(search_src('log', 'derivative', interact=False, multiline=True).splitlines()) > 70 + sage: len(search_src('log', 'derivative', + ....: interact=False, multiline=True).splitlines()) > 70 True A little recursive narcissism: let's do a doctest that searches for @@ -1196,13 +1199,13 @@ def search_doc(string, extra1='', extra2='', extra3='', extra4='', counting the length of ``search_doc('tree', interact=False).splitlines()`` gives the number of matches. :: - sage: N = len(search_doc('tree', interact=False).splitlines()) # optional - sagemath_doc_html, long time - sage: L = search_doc('tree', whole_word=True, interact=False).splitlines() # optional - sagemath_doc_html, long time - sage: len(L) < N # optional - sagemath_doc_html, long time + sage: N = len(search_doc('tree', interact=False).splitlines()) # optional - sagemath_doc_html, long time + sage: L = search_doc('tree', whole_word=True, interact=False).splitlines() # optional - sagemath_doc_html, long time + sage: len(L) < N # optional - sagemath_doc_html, long time True sage: import re sage: tree_re = re.compile(r'(^|\W)tree(\W|$)', re.I) - sage: all(tree_re.search(l) for l in L) # optional - sagemath_doc_html, long time + sage: all(tree_re.search(l) for l in L) # optional - sagemath_doc_html, long time True """ return _search_src_or_doc('doc', string, extra1=extra1, extra2=extra2, @@ -1362,8 +1365,8 @@ def my_getsource(obj, oname=''): EXAMPLES:: sage: from sage.misc.sagedoc import my_getsource - sage: s = my_getsource(identity_matrix) - sage: s[15:34] + sage: s = my_getsource(identity_matrix) # optional - sage.modules + sage: s[15:34] # optional - sage.modules 'def identity_matrix' """ try: @@ -1399,9 +1402,9 @@ class _sage_doc: EXAMPLES:: - sage: browse_sage_doc._open("reference", testing=True)[0] # optional - sagemath_doc_html, indirect doctest + sage: browse_sage_doc._open("reference", testing=True)[0] # optional - sagemath_doc_html, indirect doctest 'http://localhost:8000/doc/live/reference/index.html' - sage: browse_sage_doc(identity_matrix, 'rst')[-107:-47] + sage: browse_sage_doc(identity_matrix, 'rst')[-107:-47] # optional - sage.modules 'Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring' """ def __init__(self): @@ -1429,19 +1432,19 @@ def __call__(self, obj, output='html', view=True): EXAMPLES:: - sage: browse_sage_doc(identity_matrix, 'rst') + sage: browse_sage_doc(identity_matrix, 'rst') # optional - sage.modules "...**File:**...**Type:**...**Definition:** identity_matrix..." - sage: identity_matrix.__doc__ in browse_sage_doc(identity_matrix, 'rst') + sage: identity_matrix.__doc__ in browse_sage_doc(identity_matrix, 'rst') # optional - sage.modules True - sage: browse_sage_doc(identity_matrix, 'html', False) # optional - sphinx sagemath_doc_html + sage: browse_sage_doc(identity_matrix, 'html', False) # optional - sphinx sagemath_doc_html '...div...File:...Type:...Definition:...identity_matrix...' In the 'text' version, double colons have been replaced with single ones (among other things):: - sage: '::' in browse_sage_doc(identity_matrix, 'rst') + sage: '::' in browse_sage_doc(identity_matrix, 'rst') # optional - sage.modules True - sage: '::' in browse_sage_doc(identity_matrix, 'text') # optional - sphinx + sage: '::' in browse_sage_doc(identity_matrix, 'text') # optional - sphinx False """ if output != 'html' and view: @@ -1571,9 +1574,9 @@ def _open(self, name, testing=False): EXAMPLES:: - sage: browse_sage_doc._open("reference", testing=True)[0] # optional - sagemath_doc_html + sage: browse_sage_doc._open("reference", testing=True)[0] # optional - sagemath_doc_html 'http://localhost:8000/doc/live/reference/index.html' - sage: browse_sage_doc._open("tutorial", testing=True)[1] # optional - sagemath_doc_html + sage: browse_sage_doc._open("tutorial", testing=True)[1] # optional - sagemath_doc_html '.../html/en/tutorial/index.html' """ url = self._base_url + os.path.join(name, "index.html") diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index 7264d1b697b..fbb399a923d 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -252,16 +252,16 @@ def _extract_embedded_position(docstring): sage: from sage.misc.sageinspect import _extract_embedded_position sage: import inspect - sage: _extract_embedded_position(inspect.getdoc(var))[1][-21:] + sage: _extract_embedded_position(inspect.getdoc(var))[1][-21:] # optional - sage.symbolic 'sage/calculus/var.pyx' TESTS: The following has been fixed in :trac:`13916`:: - sage: cython('''cpdef test_funct(x,y): return''') # optional - sage.misc.cython - sage: func_doc = inspect.getdoc(test_funct) # optional - sage.misc.cython - sage: with open(_extract_embedded_position(func_doc)[1]) as f: # optional - sage.misc.cython + sage: cython('''cpdef test_funct(x,y): return''') # optional - sage.misc.cython + sage: func_doc = inspect.getdoc(test_funct) # optional - sage.misc.cython + sage: with open(_extract_embedded_position(func_doc)[1]) as f: # optional - sage.misc.cython ....: print(f.read()) cpdef test_funct(x,y): return @@ -272,10 +272,10 @@ def _extract_embedded_position(docstring): sage: from sage.env import DOT_SAGE sage: from sage.misc.sage_ostools import restore_cwd - sage: with restore_cwd(DOT_SAGE): # optional - sage.misc.cython + sage: with restore_cwd(DOT_SAGE): # optional - sage.misc.cython ....: cython('''cpdef test_funct(x,y): return''') - sage: func_doc = inspect.getdoc(test_funct) # optional - sage.misc.cython - sage: with open(_extract_embedded_position(func_doc)[1]) as f: # optional - sage.misc.cython + sage: func_doc = inspect.getdoc(test_funct) # optional - sage.misc.cython + sage: with open(_extract_embedded_position(func_doc)[1]) as f: # optional - sage.misc.cython ....: print(f.read()) cpdef test_funct(x,y): return @@ -1118,7 +1118,7 @@ def _sage_getargspec_from_ast(source): FullArgSpec(args=['a', 'b', 'c', 'd'], varargs=None, varkw=None, defaults=(2, {'a': [4, 5.5, False]}, (None, True)), kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: from_ast(s) == inspect.getfullargspec(context['f']) True - sage: set(from_ast(sms.sage_getsource(x)) == inspect.getfullargspec(x) for x in [factor, identity_matrix, Graph.__init__]) + sage: set(from_ast(sms.sage_getsource(x)) == inspect.getfullargspec(x) for x in [factor, identity_matrix, Graph.__init__]) # optional - sage.modules sage.graphs {True} """ ast_args = ast.parse(source.lstrip()).body[0].args @@ -1203,17 +1203,21 @@ def _sage_getargspec_cython(source): sage: def dummy_python(self, *args, x=1): pass sage: sgc("def dummy_python(self, *args, x=1): pass") - FullArgSpec(args=['self', 'x'], varargs='args', varkw=None, defaults=(1,), kwonlyargs=[], kwonlydefaults=None, annotations={}) - sage: cython("def dummy_cython(self, *args, x=1): pass") + FullArgSpec(args=['self', 'x'], varargs='args', varkw=None, defaults=(1,), + kwonlyargs=[], kwonlydefaults=None, annotations={}) + sage: cython("def dummy_cython(self, *args, x=1): pass") # optional - sage.misc.cython sage: sgc("def dummy_cython(self, *args, x=1): pass") - FullArgSpec(args=['self', 'x'], varargs='args', varkw=None, defaults=(1,), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['self', 'x'], varargs='args', varkw=None, defaults=(1,), + kwonlyargs=[], kwonlydefaults=None, annotations={}) In some examples above, a syntax error was raised when a type definition contains a pointer. An exception is made for ``char*``, since C strings are acceptable input in public Cython functions:: sage: sgc('def f(char *x = "a string", z = {(1,2,3): True}): pass') - FullArgSpec(args=['x', 'z'], varargs=None, varkw=None, defaults=('a string', {(1, 2, 3): True}), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['x', 'z'], varargs=None, varkw=None, + defaults=('a string', {(1, 2, 3): True}), + kwonlyargs=[], kwonlydefaults=None, annotations={}) AUTHORS: @@ -1352,34 +1356,34 @@ def sage_getfile(obj): sage: from sage.misc.sageinspect import sage_getfile sage: sage_getfile(sage.rings.rational) '...sage/rings/rational.pyx' - sage: sage_getfile(Sq) + sage: sage_getfile(Sq) # optional - sage.combinat sage.modules '...sage/algebras/steenrod/steenrod_algebra.py' - sage: sage_getfile(x) + sage: sage_getfile(x) # optional - sage.symbolic '...sage/symbolic/expression.pyx' The following tests against some bugs fixed in :trac:`9976`:: - sage: obj = sage.combinat.partition_algebra.SetPartitionsAk - sage: obj = sage.combinat.partition_algebra.SetPartitionsAk - sage: sage_getfile(obj) + sage: obj = sage.combinat.partition_algebra.SetPartitionsAk # optional - sage.combinat + sage: obj = sage.combinat.partition_algebra.SetPartitionsAk # optional - sage.combinat + sage: sage_getfile(obj) # optional - sage.combinat '...sage/combinat/partition_algebra.py' And here is another bug, fixed in :trac:`11298`:: sage: P. = QQ[] - sage: sage_getfile(P) + sage: sage_getfile(P) # optional - sage.libs.singular '...sage/rings/polynomial/multi_polynomial_libsingular...' A problem fixed in :trac:`16309`:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: class Bar: pass ....: cdef class Foo: pass ....: ''') - sage: sage_getfile(Bar) # optional - sage.misc.cython + sage: sage_getfile(Bar) # optional - sage.misc.cython '...pyx' - sage: sage_getfile(Foo) # optional - sage.misc.cython + sage: sage_getfile(Foo) # optional - sage.misc.cython '...pyx' By :trac:`18249`, we return an empty string for Python builtins. In that @@ -1433,9 +1437,9 @@ def sage_getfile_relative(obj): sage: from sage.misc.sageinspect import sage_getfile_relative sage: sage_getfile_relative(sage.rings.rational) 'sage/rings/rational.pyx' - sage: sage_getfile_relative(Sq) + sage: sage_getfile_relative(Sq) # optional - sage.combinat sage.modules 'sage/algebras/steenrod/steenrod_algebra.py' - sage: sage_getfile_relative(x) + sage: sage_getfile_relative(x) # optional - sage.symbolic 'sage/symbolic/expression.pyx' sage: sage_getfile_relative(range) '' @@ -1504,46 +1508,55 @@ def sage_getargspec(obj): We now run sage_getargspec on some functions from the Sage library:: - sage: sage_getargspec(identity_matrix) - FullArgSpec(args=['ring', 'n', 'sparse'], varargs=None, varkw=None, defaults=(0, False), kwonlyargs=[], kwonlydefaults=None, annotations={}) + sage: sage_getargspec(identity_matrix) # optional - sage.modules + FullArgSpec(args=['ring', 'n', 'sparse'], varargs=None, varkw=None, defaults=(0, False), + kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: sage_getargspec(factor) - FullArgSpec(args=['n', 'proof', 'int_', 'algorithm', 'verbose'], varargs=None, varkw='kwds', defaults=(None, False, 'pari', 0), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['n', 'proof', 'int_', 'algorithm', 'verbose'], varargs=None, varkw='kwds', + defaults=(None, False, 'pari', 0), kwonlyargs=[], kwonlydefaults=None, annotations={}) In the case of a class or a class instance, the ``ArgSpec`` of the ``__new__``, ``__init__`` or ``__call__`` method is returned:: sage: P. = QQ[] sage: sage_getargspec(P) - FullArgSpec(args=['base_ring', 'n', 'names', 'order'], varargs=None, varkw=None, defaults=('degrevlex',), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['base_ring', 'n', 'names', 'order'], varargs=None, varkw=None, + defaults=('degrevlex',), kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: sage_getargspec(P.__class__) - FullArgSpec(args=['self', 'x'], varargs='args', varkw='kwds', defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['self', 'x'], varargs='args', varkw='kwds', defaults=(0,), + kwonlyargs=[], kwonlydefaults=None, annotations={}) The following tests against various bugs that were fixed in :trac:`9976`:: sage: from sage.rings.polynomial.real_roots import bernstein_polynomial_factory_ratlist sage: sage_getargspec(bernstein_polynomial_factory_ratlist.coeffs_bitsize) - FullArgSpec(args=['self'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['self'], varargs=None, varkw=None, defaults=None, + kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: from sage.rings.polynomial.pbori.pbori import BooleanMonomialMonoid sage: sage_getargspec(BooleanMonomialMonoid.gen) - FullArgSpec(args=['self', 'i'], varargs=None, varkw=None, defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['self', 'i'], varargs=None, varkw=None, defaults=(0,), + kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: I = P*[x,y] sage: sage_getargspec(I.groebner_basis) FullArgSpec(args=['self', 'algorithm', 'deg_bound', 'mult_bound', 'prot'], - varargs='args', varkw='kwds', defaults=('', None, None, False), kwonlyargs=[], kwonlydefaults=None, annotations={}) - sage: cython("cpdef int foo(x,y) except -1: return 1") - sage: sage_getargspec(foo) - FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) + varargs='args', varkw='kwds', defaults=('', None, None, False), + kwonlyargs=[], kwonlydefaults=None, annotations={}) + sage: cython("cpdef int foo(x,y) except -1: return 1") # optional - sage.misc.cython + sage: sage_getargspec(foo) # optional - sage.misc.cython + FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=None, + kwonlyargs=[], kwonlydefaults=None, annotations={}) If a ``functools.partial`` instance is involved, we see no other meaningful solution than to return the argspec of the underlying function:: - sage: def f(a,b,c,d=1): - ....: return a+b+c+d + sage: def f(a, b, c, d=1): + ....: return a + b + c + d sage: import functools - sage: f1 = functools.partial(f, 1,c=2) + sage: f1 = functools.partial(f, 1, c=2) sage: sage_getargspec(f1) - FullArgSpec(args=['a', 'b', 'c', 'd'], varargs=None, varkw=None, defaults=(1,), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['a', 'b', 'c', 'd'], varargs=None, varkw=None, defaults=(1,), + kwonlyargs=[], kwonlydefaults=None, annotations={}) TESTS: @@ -1564,34 +1577,38 @@ def sage_getargspec(obj): ....: ' def _sage_src_(self):', ....: ' return "def foo(x, a=\\\')\\\"\\\', b={(2+1):\\\'bar\\\', not 1:3, 3<<4:5}): return\\n"', ....: ' def __call__(self, m,n): return "something"'] - sage: cython('\n'.join(cython_code)) - sage: O = MyClass() - sage: print(sage.misc.sageinspect.sage_getsource(O)) + sage: cython('\n'.join(cython_code)) # optional - sage.misc.cython + sage: O = MyClass() # optional - sage.misc.cython + sage: print(sage.misc.sageinspect.sage_getsource(O)) # optional - sage.misc.cython def foo(x, a=')"', b={(2+1):'bar', not 1:3, 3<<4:5}): return - sage: spec = sage.misc.sageinspect.sage_getargspec(O) - sage: spec.args, spec.varargs, spec.varkw + sage: spec = sage.misc.sageinspect.sage_getargspec(O) # optional - sage.misc.cython + sage: spec.args, spec.varargs, spec.varkw # optional - sage.misc.cython (['x', 'a', 'b'], None, None) - sage: spec.defaults[0] + sage: spec.defaults[0] # optional - sage.misc.cython ')"' - sage: sorted(spec.defaults[1].items(), key=lambda x: str(x)) + sage: sorted(spec.defaults[1].items(), key=lambda x: str(x)) # optional - sage.misc.cython [(3, 'bar'), (48, 5), (False, 3)] - sage: sage.misc.sageinspect.sage_getargspec(O.__call__) - FullArgSpec(args=['self', 'm', 'n'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) + sage: sage.misc.sageinspect.sage_getargspec(O.__call__) # optional - sage.misc.cython + FullArgSpec(args=['self', 'm', 'n'], varargs=None, varkw=None, defaults=None, + kwonlyargs=[], kwonlydefaults=None, annotations={}) :: - sage: cython('def foo(x, a=\'\\\')"\', b={not (2+1==3):\'bar\'}): return') - sage: print(sage.misc.sageinspect.sage_getsource(foo)) + sage: cython('def foo(x, a=\'\\\')"\', b={not (2+1==3):\'bar\'}): return') # optional - sage.misc.cython + sage: print(sage.misc.sageinspect.sage_getsource(foo)) # optional - sage.misc.cython def foo(x, a='\')"', b={not (2+1==3):'bar'}): return - sage: sage.misc.sageinspect.sage_getargspec(foo) - FullArgSpec(args=['x', 'a', 'b'], varargs=None, varkw=None, defaults=('\')"', {False: 'bar'}), kwonlyargs=[], kwonlydefaults=None, annotations={}) + sage: sage.misc.sageinspect.sage_getargspec(foo) # optional - sage.misc.cython + FullArgSpec(args=['x', 'a', 'b'], varargs=None, varkw=None, + defaults=('\')"', {False: 'bar'}), + kwonlyargs=[], kwonlydefaults=None, annotations={}) The following produced a syntax error before the patch at :trac:`11913`, see also :trac:`26906`:: - sage: sage.misc.sageinspect.sage_getargspec(r.lm) # optional - rpy2 - FullArgSpec(args=['self'], varargs='args', varkw='kwds', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) + sage: sage.misc.sageinspect.sage_getargspec(r.lm) # optional - rpy2 + FullArgSpec(args=['self'], varargs='args', varkw='kwds', defaults=None, + kwonlyargs=[], kwonlydefaults=None, annotations={}) The following was fixed in :trac:`16309`:: @@ -1605,23 +1622,28 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return ....: cpdef meet(categories, bint as_list = False, tuple ignore_axioms=(), tuple axioms=()): pass ....: ''') sage: sage_getargspec(Foo.join) - FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, + defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: sage_getargspec(Bar.join) - FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, + defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={}) sage: sage_getargspec(Bar.meet) - FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, + defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={}) Test that :trac:`17009` is fixed:: sage: sage_getargspec(gap) - FullArgSpec(args=['self', 'x', 'name'], varargs=None, varkw=None, defaults=(None,), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['self', 'x', 'name'], varargs=None, varkw=None, + defaults=(None,), kwonlyargs=[], kwonlydefaults=None, annotations={}) By :trac:`17814`, the following gives the correct answer (previously, the defaults would have been found ``None``):: sage: from sage.misc.nested_class import MainClass sage: sage_getargspec(MainClass.NestedClass.NestedSubClass.dummy) - FullArgSpec(args=['self', 'x', 'r'], varargs='args', varkw='kwds', defaults=((1, 2, 3.4),), kwonlyargs=[], kwonlydefaults=None, annotations={}) + FullArgSpec(args=['self', 'x', 'r'], varargs='args', varkw='kwds', + defaults=((1, 2, 3.4),), kwonlyargs=[], kwonlydefaults=None, annotations={}) In :trac:`18249` was decided to return a generic signature for Python builtin functions, rather than to raise an error (which is what Python's @@ -1867,9 +1889,9 @@ def sage_getdef(obj, obj_name=''): EXAMPLES:: sage: from sage.misc.sageinspect import sage_getdef - sage: sage_getdef(identity_matrix) + sage: sage_getdef(identity_matrix) # optional - sage.modules '(ring, n=0, sparse=False)' - sage: sage_getdef(identity_matrix, 'identity_matrix') + sage: sage_getdef(identity_matrix, 'identity_matrix') # optional - sage.modules 'identity_matrix(ring, n=0, sparse=False)' Check that :trac:`6848` has been fixed:: @@ -2034,7 +2056,7 @@ def sage_getdoc_original(obj): If an instance of a class does not have its own docstring, the docstring of its class results:: - sage: sage_getdoc_original(sage.plot.colors.aliceblue) == sage_getdoc_original(sage.plot.colors.Color) + sage: sage_getdoc_original(sage.plot.colors.aliceblue) == sage_getdoc_original(sage.plot.colors.Color) # optional - sage.plot True """ @@ -2077,7 +2099,7 @@ def sage_getdoc(obj, obj_name='', embedded=False): EXAMPLES:: sage: from sage.misc.sageinspect import sage_getdoc - sage: sage_getdoc(identity_matrix)[87:124] + sage: sage_getdoc(identity_matrix)[87:124] # optional - sage.modules 'Return the n x n identity matrix over' sage: def f(a,b,c,d=1): return a+b+c+d ... @@ -2130,9 +2152,9 @@ def sage_getsource(obj): EXAMPLES:: sage: from sage.misc.sageinspect import sage_getsource - sage: sage_getsource(identity_matrix)[19:60] + sage: sage_getsource(identity_matrix)[19:60] # optional - sage.modules 'identity_matrix(ring, n=0, sparse=False):' - sage: sage_getsource(identity_matrix)[19:60] + sage: sage_getsource(identity_matrix)[19:60] # optional - sage.modules 'identity_matrix(ring, n=0, sparse=False):' AUTHORS: @@ -2309,9 +2331,9 @@ def sage_getsourcelines(obj): EXAMPLES:: sage: from sage.misc.sageinspect import sage_getsourcelines - sage: sage_getsourcelines(matrix)[1] + sage: sage_getsourcelines(matrix)[1] # optional - sage.modules 21 - sage: sage_getsourcelines(matrix)[0][0] + sage: sage_getsourcelines(matrix)[0][0] # optional - sage.modules 'def matrix(*args, **kwds):\n' Some classes customize this using a ``_sage_src_lines_`` method, @@ -2326,8 +2348,8 @@ def sage_getsourcelines(obj): TESTS:: - sage: cython('''cpdef test_funct(x,y): return''') # optional - sage.misc.cython - sage: sage_getsourcelines(test_funct) # optional - sage.misc.cython + sage: cython('''cpdef test_funct(x,y): return''') # optional - sage.misc.cython + sage: sage_getsourcelines(test_funct) # optional - sage.misc.cython (['cpdef test_funct(x,y): return\n'], 1) The following tests that an instance of ``functools.partial`` is correctly @@ -2548,16 +2570,16 @@ def sage_getvariablename(self, omit_underscore_names=True): EXAMPLES:: sage: from sage.misc.sageinspect import sage_getvariablename - sage: A = random_matrix(ZZ, 100) - sage: sage_getvariablename(A) + sage: A = random_matrix(ZZ, 100) # optional - sage.modules + sage: sage_getvariablename(A) # optional - sage.modules 'A' - sage: B = A - sage: sage_getvariablename(A) + sage: B = A # optional - sage.modules + sage: sage_getvariablename(A) # optional - sage.modules ['A', 'B'] If an object is not assigned to a variable, an empty list is returned:: - sage: sage_getvariablename(random_matrix(ZZ, 60)) + sage: sage_getvariablename(random_matrix(ZZ, 60)) # optional - sage.modules [] """ result = [] diff --git a/src/sage/misc/superseded.py b/src/sage/misc/superseded.py index c158317ca5a..725d524a591 100644 --- a/src/sage/misc/superseded.py +++ b/src/sage/misc/superseded.py @@ -107,7 +107,7 @@ def deprecation_cython(issue_number, message, stacklevel=3): with the same callsite reference as `deprecation` in a python function, whereas `deprecation` in a cython function does not:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.misc.superseded import deprecation_cython, deprecation ....: def foo1(): @@ -117,7 +117,7 @@ def deprecation_cython(issue_number, message, stacklevel=3): ....: ''') sage: def foo3(): ....: deprecation(100, "boo") - sage: if True: # Execute the three "with" blocks as one doctest # optional - sage.misc.cython + sage: if True: # Execute the three "with" blocks as one doctest # optional - sage.misc.cython ....: with warnings.catch_warnings(record=True) as w1: ....: warnings.simplefilter("always") ....: foo1() @@ -127,9 +127,9 @@ def deprecation_cython(issue_number, message, stacklevel=3): ....: with warnings.catch_warnings(record=True) as w3: ....: warnings.simplefilter("always") ....: foo3() - sage: w1[0].filename == w3[0].filename # optional - sage.misc.cython + sage: w1[0].filename == w3[0].filename # optional - sage.misc.cython True - sage: w2[0].filename == w3[0].filename # optional - sage.misc.cython + sage: w2[0].filename == w3[0].filename # optional - sage.misc.cython False """ warning(issue_number, message, DeprecationWarning, stacklevel) @@ -353,9 +353,9 @@ def __init__(self, issue_number, func, module, instance=None, unbound=None): TESTS:: sage: from sage.misc.superseded import deprecated_function_alias - sage: g = deprecated_function_alias(13109, number_of_partitions) + sage: g = deprecated_function_alias(13109, number_of_partitions) # optional - sage.combinat sage: from sage.misc.superseded import deprecated_function_alias - sage: g.__doc__ + sage: g.__doc__ # optional - sage.combinat 'Deprecated: Use :func:`number_of_partitions` instead.\nSee :trac:`13109` for details.\n\n' """ _check_issue_number(issue_number) @@ -383,8 +383,8 @@ def __name__(self): TESTS:: sage: from sage.misc.superseded import deprecated_function_alias - sage: g = deprecated_function_alias(13109, number_of_partitions) - sage: g.__name__ + sage: g = deprecated_function_alias(13109, number_of_partitions) # optional - sage.combinat + sage: g.__name__ # optional - sage.combinat 'g' sage: from sage.misc.superseded import deprecated_function_alias @@ -396,14 +396,14 @@ def __name__(self): sage: cls().old_meth.__name__ 'old_meth' - sage: cython('\n'.join([ # optional - sage.misc.cython + sage: cython('\n'.join([ # optional - sage.misc.cython ....: r"from sage.misc.superseded import deprecated_function_alias", ....: r"cdef class cython_cls():", ....: r" def new_cython_meth(self):", ....: r" return 1", ....: r" old_cython_meth = deprecated_function_alias(13109, new_cython_meth)" ....: ])) - sage: cython_cls().old_cython_meth.__name__ # optional - sage.misc.cython + sage: cython_cls().old_cython_meth.__name__ # optional - sage.misc.cython 'old_cython_meth' """ # first look through variables in stack frames @@ -515,9 +515,10 @@ def deprecated_function_alias(issue_number, func): EXAMPLES:: sage: from sage.misc.superseded import deprecated_function_alias - sage: g = deprecated_function_alias(13109, number_of_partitions) - sage: g(5) - doctest:...: DeprecationWarning: g is deprecated. Please use sage.combinat.partition.number_of_partitions instead. + sage: g = deprecated_function_alias(13109, number_of_partitions) # optional - sage.combinat + sage: g(5) # optional - sage.combinat + doctest:...: DeprecationWarning: g is deprecated. + Please use sage.combinat.partition.number_of_partitions instead. See https://github.com/sagemath/sage/issues/13109 for details. 7 diff --git a/src/sage/misc/table.py b/src/sage/misc/table.py index cbd8b083a6b..4afcd513ce9 100644 --- a/src/sage/misc/table.py +++ b/src/sage/misc/table.py @@ -106,7 +106,8 @@ class table(SageObject): information. The same goes for ``header_column``. Passing lists for both arguments simultaneously is not supported. :: - sage: table([(x,n(sin(x), digits=2)) for x in [0..3]], header_row=["$x$", r"$\sin(x)$"], frame=True) + sage: table([(x,n(sin(x), digits=2)) for x in [0..3]], # optional - sage.symbolic + ....: header_row=["$x$", r"$\sin(x)$"], frame=True) +-----+-----------+ | $x$ | $\sin(x)$ | +=====+===========+ @@ -122,7 +123,9 @@ class table(SageObject): You can create the transpose of this table in several ways, for example, "by hand," that is, changing the data defining the table:: - sage: table(rows=[[x for x in [0..3]], [n(sin(x), digits=2) for x in [0..3]]], header_column=['$x$', r'$\sin(x)$'], frame=True) + sage: table(rows=[[x for x in [0..3]], # optional - sage.symbolic + ....: [n(sin(x), digits=2) for x in [0..3]]], + ....: header_column=['$x$', r'$\sin(x)$'], frame=True) +-----------++------+------+------+------+ | $x$ || 0 | 1 | 2 | 3 | +-----------++------+------+------+------+ @@ -132,7 +135,8 @@ class table(SageObject): or by passing the original data as the ``columns`` of the table and using ``header_column`` instead of ``header_row``:: - sage: table(columns=[(x,n(sin(x), digits=2)) for x in [0..3]], header_column=['$x$', r'$\sin(x)$'], frame=True) + sage: table(columns=[(x, n(sin(x), digits=2)) for x in [0..3]], # optional - sage.symbolic + ....: header_column=['$x$', r'$\sin(x)$'], frame=True) +-----------++------+------+------+------+ | $x$ || 0 | 1 | 2 | 3 | +-----------++------+------+------+------+ @@ -141,7 +145,8 @@ class table(SageObject): or by taking the :meth:`transpose` of the original table:: - sage: table(rows=[(x,n(sin(x), digits=2)) for x in [0..3]], header_row=['$x$', r'$\sin(x)$'], frame=True).transpose() + sage: table(rows=[(x, n(sin(x), digits=2)) for x in [0..3]], # optional - sage.symbolic + ....: header_row=['$x$', r'$\sin(x)$'], frame=True).transpose() +-----------++------+------+------+------+ | $x$ || 0 | 1 | 2 | 3 | +-----------++------+------+------+------+ @@ -170,11 +175,12 @@ 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: output = html(table(data, header_row=True, frame=True)) - sage: type(output) + sage: data = [["$x$", r"$\sin(x)$"]] + [(x, n(sin(x), digits=2)) # optional - sage.symbolic + ....: for x in [0..3]] + sage: output = html(table(data, header_row=True, frame=True)) # optional - sage.symbolic + sage: type(output) # optional - sage.symbolic - sage: print(output) + sage: print(output) # optional - sage.symbolic
@@ -286,15 +292,15 @@ def __eq__(self, other): EXAMPLES:: - sage: rows = [['a', 'b', 'c'], [1,plot(sin(x)),3], [4,5,identity_matrix(2)]] - sage: T = table(rows, header_row=True) - sage: T2 = table(rows, header_row=True) - sage: T is T2 + sage: rows = [['a', 'b', 'c'], [1,plot(sin(x)),3], [4,5,identity_matrix(2)]] # optional - sage.matrix sage.plot + sage: T = table(rows, header_row=True) # optional - sage.matrix sage.plot + sage: T2 = table(rows, header_row=True) # optional - sage.matrix sage.plot + sage: T is T2 # optional - sage.matrix sage.plot False - sage: T == T2 + sage: T == T2 # optional - sage.matrix sage.plot True - sage: T2.options(frame=True) - sage: T == T2 + sage: T2.options(frame=True) # optional - sage.matrix sage.plot + sage: T == T2 # optional - sage.matrix sage.plot False """ return (self._rows == other._rows and self.options() == other.options()) @@ -561,8 +567,9 @@ def _latex_(self): EXAMPLES:: sage: from sage.misc.table import table - sage: a = [[r'$\sin(x)$', '$x$', 'text'], [1,34342,3], [identity_matrix(2),5,6]] - sage: latex(table(a)) # indirect doctest + sage: a = [[r'$\sin(x)$', '$x$', 'text'], # optional - sage.matrix + ....: [1, 34342, 3], [identity_matrix(2), 5, 6]] + sage: latex(table(a)) # indirect doctest # optional - sage.matrix \begin{tabular}{lll} $\sin(x)$ & $x$ & text \\ $1$ & $34342$ & $3$ \\ @@ -571,7 +578,7 @@ def _latex_(self): 0 & 1 \end{array}\right)$ & $5$ & $6$ \\ \end{tabular} - sage: latex(table(a, frame=True, align='center')) + sage: latex(table(a, frame=True, align='center')) # optional - sage.matrix \begin{tabular}{|c|c|c|} \hline $\sin(x)$ & $x$ & text \\ \hline $1$ & $34342$ & $3$ \\ \hline @@ -640,10 +647,11 @@ def _html_(self): EXAMPLES:: - sage: T = table([[r'$\sin(x)$', '$x$', 'text'], [1,34342,3], [identity_matrix(2),5,6]]) - sage: T._html_() + sage: T = table([[r'$\sin(x)$', '$x$', 'text'], # optional - sage.matrix + ....: [1, 34342, 3], [identity_matrix(2), 5, 6]]) + sage: T._html_() # optional - sage.matrix '' - sage: print(T._html_()) + sage: print(T._html_()) # optional - sage.matrix
@@ -672,8 +680,10 @@ def _html_(self): Note that calling ``html(table(...))`` has the same effect as calling ``table(...)._html_()``:: - sage: T = table([["$x$", r"$\sin(x)$"]] + [(x,n(sin(x), digits=2)) for x in [0..3]], header_row=True, frame=True) - sage: T + sage: T = table([["$x$", r"$\sin(x)$"]] # optional - sage.symbolic + ....: + [(x,n(sin(x), digits=2)) for x in [0..3]], + ....: header_row=True, frame=True) + sage: T # optional - sage.symbolic +-----+-----------+ | $x$ | $\sin(x)$ | +=====+===========+ @@ -685,7 +695,7 @@ def _html_(self): +-----+-----------+ | 3 | 0.14 | +-----+-----------+ - sage: print(html(T)) + sage: print(html(T)) # optional - sage.symbolic
diff --git a/src/sage/misc/trace.py b/src/sage/misc/trace.py index 2547426bc0a..c8bee6af80f 100644 --- a/src/sage/misc/trace.py +++ b/src/sage/misc/trace.py @@ -53,17 +53,17 @@ def trace(code, preparse=True): The only real way to test this is via pexpect spawning a sage subprocess that uses IPython:: - sage: import pexpect - sage: s = pexpect.spawn('sage') - sage: _ = s.sendline("trace('print(factor(10))'); print(3+97)") - sage: _ = s.expect('ipdb>', timeout=90) - sage: _ = s.sendline("s"); _ = s.sendline("c") - sage: _ = s.expect('100', timeout=90) + sage: import pexpect # optional - pexpect + sage: s = pexpect.spawn('sage') # optional - pexpect + sage: _ = s.sendline("trace('print(factor(10))'); print(3+97)") # optional - pexpect + sage: _ = s.expect('ipdb>', timeout=90) # optional - pexpect + sage: _ = s.sendline("s"); _ = s.sendline("c") # optional - pexpect + sage: _ = s.expect('100', timeout=90) # optional - pexpect Seeing the ipdb prompt and the 2 \* 5 in the output below is a strong indication that the trace command worked correctly:: - sage: print(s.before[s.before.find(b'--'):].decode()) + sage: print(s.before[s.before.find(b'--'):].decode()) # optional - pexpect --... ...ipdb> c ...2 * 5... diff --git a/src/sage/misc/weak_dict.pyx b/src/sage/misc/weak_dict.pyx index 9202e96c99e..72e13c19b98 100644 --- a/src/sage/misc/weak_dict.pyx +++ b/src/sage/misc/weak_dict.pyx @@ -339,13 +339,13 @@ cdef class WeakValueDictionary(dict): EXAMPLES:: - sage: L = [(p,GF(p)) for p in prime_range(10)] + sage: L = [(p, GF(p)) for p in prime_range(10)] # optional - sage.rings.finite_rings sage: import sage.misc.weak_dict sage: D = sage.misc.weak_dict.WeakValueDictionary() sage: len(D) 0 - sage: D = sage.misc.weak_dict.WeakValueDictionary(L) - sage: len(D) == len(L) + sage: D = sage.misc.weak_dict.WeakValueDictionary(L) # optional - sage.rings.finite_rings + sage: len(D) == len(L) # optional - sage.rings.finite_rings True """ try: @@ -429,29 +429,29 @@ cdef class WeakValueDictionary(dict): EXAMPLES:: sage: import sage.misc.weak_dict - sage: L = [(p,GF(p)) for p in prime_range(10)] - sage: D = sage.misc.weak_dict.WeakValueDictionary(L) - sage: len(D) + sage: L = [(p, GF(p)) for p in prime_range(10)] # optional - sage.rings.finite_rings + sage: D = sage.misc.weak_dict.WeakValueDictionary(L) # optional - sage.rings.finite_rings + sage: len(D) # optional - sage.rings.finite_rings 4 The value for an existing key is returned and not overridden:: - sage: D.setdefault(5, ZZ) + sage: D.setdefault(5, ZZ) # optional - sage.rings.finite_rings Finite Field of size 5 - sage: D[5] + sage: D[5] # optional - sage.rings.finite_rings Finite Field of size 5 For a non-existing key, the default value is stored and returned:: - sage: 4 in D + sage: 4 in D # optional - sage.rings.finite_rings False - sage: D.setdefault(4, ZZ) + sage: D.setdefault(4, ZZ) # optional - sage.rings.finite_rings Integer Ring - sage: 4 in D + sage: 4 in D # optional - sage.rings.finite_rings True - sage: D[4] + sage: D[4] # optional - sage.rings.finite_rings Integer Ring - sage: len(D) + sage: len(D) # optional - sage.rings.finite_rings 5 TESTS: @@ -460,7 +460,7 @@ cdef class WeakValueDictionary(dict): raised for unhashable objects:: sage: D = sage.misc.weak_dict.WeakValueDictionary() - sage: D.setdefault(matrix([]),ZZ) + sage: D.setdefault(matrix([]), ZZ) # optional - sage.modules Traceback (most recent call last): ... TypeError: mutable matrices are unhashable @@ -535,7 +535,7 @@ cdef class WeakValueDictionary(dict): raised for unhashable objects:: sage: D = sage.misc.weak_dict.WeakValueDictionary() - sage: D[matrix([])] = ZZ + sage: D[matrix([])] = ZZ # optional - sage.modules Traceback (most recent call last): ... TypeError: mutable matrices are unhashable @@ -560,15 +560,15 @@ cdef class WeakValueDictionary(dict): EXAMPLES:: sage: import sage.misc.weak_dict - sage: L = [GF(p) for p in prime_range(10^3)] - sage: D = sage.misc.weak_dict.WeakValueDictionary(enumerate(L)) - sage: 20 in D + sage: L = [GF(p) for p in prime_range(10^3)] # optional - sage.rings.finite_rings + sage: D = sage.misc.weak_dict.WeakValueDictionary(enumerate(L)) # optional - sage.rings.finite_rings + sage: 20 in D # optional - sage.rings.finite_rings True - sage: D.pop(20) + sage: D.pop(20) # optional - sage.rings.finite_rings Finite Field of size 73 - sage: 20 in D + sage: 20 in D # optional - sage.rings.finite_rings False - sage: D.pop(20) + sage: D.pop(20) # optional - sage.rings.finite_rings Traceback (most recent call last): ... KeyError: 20 @@ -579,7 +579,7 @@ cdef class WeakValueDictionary(dict): raised for unhashable objects:: sage: D = sage.misc.weak_dict.WeakValueDictionary() - sage: D.pop(matrix([])) + sage: D.pop(matrix([])) # optional - sage.modules Traceback (most recent call last): ... TypeError: mutable matrices are unhashable @@ -636,17 +636,17 @@ cdef class WeakValueDictionary(dict): EXAMPLES:: sage: import sage.misc.weak_dict - sage: L = [GF(p) for p in prime_range(10^3)] - sage: D = sage.misc.weak_dict.WeakValueDictionary(enumerate(L)) - sage: 100 in D + sage: L = [GF(p) for p in prime_range(10^3)] # optional - sage.rings.finite_rings + sage: D = sage.misc.weak_dict.WeakValueDictionary(enumerate(L)) # optional - sage.rings.finite_rings + sage: 100 in D # optional - sage.rings.finite_rings True - sage: 200 in D + sage: 200 in D # optional - sage.rings.finite_rings False - sage: D.get(100, "not found") + sage: D.get(100, "not found") # optional - sage.rings.finite_rings Finite Field of size 547 - sage: D.get(200, "not found") + sage: D.get(200, "not found") # optional - sage.rings.finite_rings 'not found' - sage: D.get(200) is None + sage: D.get(200) is None # optional - sage.rings.finite_rings True TESTS: @@ -655,7 +655,7 @@ cdef class WeakValueDictionary(dict): raised for unhashable objects:: sage: D = sage.misc.weak_dict.WeakValueDictionary() - sage: D.get(matrix([])) + sage: D.get(matrix([])) # optional - sage.modules Traceback (most recent call last): ... TypeError: mutable matrices are unhashable @@ -695,7 +695,7 @@ cdef class WeakValueDictionary(dict): raised for unhashable objects:: sage: D = sage.misc.weak_dict.WeakValueDictionary() - sage: D[matrix([])] + sage: D[matrix([])] # optional - sage.modules Traceback (most recent call last): ... TypeError: mutable matrices are unhashable @@ -739,7 +739,7 @@ cdef class WeakValueDictionary(dict): raised for unhashable objects:: sage: D = sage.misc.weak_dict.WeakValueDictionary() - sage: matrix([]) in D + sage: matrix([]) in D # optional - sage.modules Traceback (most recent call last): ... TypeError: mutable matrices are unhashable @@ -1193,13 +1193,13 @@ cdef class CachedWeakValueDictionary(WeakValueDictionary): EXAMPLES:: - sage: L = [(p,GF(p)) for p in prime_range(10)] + sage: L = [(p, GF(p)) for p in prime_range(10)] # optional - sage.rings.finite_rings sage: from sage.misc.weak_dict import CachedWeakValueDictionary - sage: D = CachedWeakValueDictionary() - sage: len(D) + sage: D = CachedWeakValueDictionary() # optional - sage.rings.finite_rings + sage: len(D) # optional - sage.rings.finite_rings 0 - sage: D = CachedWeakValueDictionary(L) - sage: len(D) == len(L) + sage: D = CachedWeakValueDictionary(L) # optional - sage.rings.finite_rings + sage: len(D) == len(L) # optional - sage.rings.finite_rings True A :class:`CachedWeakValueDictionary` with a cache size of zero diff --git a/src/sage/modules/filtered_vector_space.py b/src/sage/modules/filtered_vector_space.py index a4a32815197..d8e2eaecd95 100644 --- a/src/sage/modules/filtered_vector_space.py +++ b/src/sage/modules/filtered_vector_space.py @@ -83,17 +83,17 @@ Any field can be used as the vector space base. For example a finite field:: - sage: F. = GF(5^3) - sage: r1 = (a, 0, F(5)); r1 + sage: F. = GF(5^3) # optional - sage.rings.finite_rings + sage: r1 = (a, 0, F(5)); r1 # optional - sage.rings.finite_rings (a, 0, 0) - sage: FilteredVectorSpace([r1, r2, r3], {0:[0,1], oo:[1]}, base_ring=F) + sage: FilteredVectorSpace([r1, r2, r3], {0:[0,1], oo:[1]}, base_ring=F) # optional - sage.rings.finite_rings GF(125)^2 >= GF(125)^1 in GF(125)^3 Or the algebraic field:: - sage: r1 = (1, 0, 1+QQbar(I)); r1 + sage: r1 = (1, 0, 1+QQbar(I)); r1 # optional - sage.rings.number_field (1, 0, I + 1) - sage: FilteredVectorSpace([r1, r2, r3], {0:[0,1], oo:[1]}, base_ring=QQbar) + sage: FilteredVectorSpace([r1, r2, r3], {0:[0,1], oo:[1]}, base_ring=QQbar) # optional - sage.rings.number_field Vector space of dimension 2 over Algebraic Field >= Vector space of dimension 1 over Algebraic Field in Vector space of dimension 3 over Algebraic Field @@ -784,11 +784,11 @@ def _repr_field_name(self): sage: FilteredVectorSpace(2, base_ring=QQ)._repr_field_name() 'QQ' - sage: F. = GF(9) - sage: FilteredVectorSpace(2, base_ring=F)._repr_field_name() + sage: F. = GF(9) # optional - sage.rings.finite_rings + sage: FilteredVectorSpace(2, base_ring=F)._repr_field_name() # optional - sage.rings.finite_rings 'GF(9)' - sage: FilteredVectorSpace(2, base_ring=AA)._repr_field_name() + sage: FilteredVectorSpace(2, base_ring=AA)._repr_field_name() # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError @@ -822,11 +822,11 @@ def _repr_vector_space(self, dim): sage: F = FilteredVectorSpace(3, base_ring=RDF) sage: F._repr_vector_space(1234) 'RDF^1234' - sage: F3 = FilteredVectorSpace(3, base_ring=GF(3)) - sage: F3._repr_vector_space(1234) + sage: F3 = FilteredVectorSpace(3, base_ring=GF(3)) # optional - sage.rings.finite_rings + sage: F3._repr_vector_space(1234) # optional - sage.rings.finite_rings 'GF(3)^1234' - sage: F3 = FilteredVectorSpace(3, base_ring=AA) - sage: F3._repr_vector_space(1234) + sage: F3 = FilteredVectorSpace(3, base_ring=AA) # optional - sage.rings.number_field + sage: F3._repr_vector_space(1234) # optional - sage.rings.number_field 'Vector space of dimension 1234 over Algebraic Real Field' """ if dim == 0: @@ -880,9 +880,9 @@ def _repr_(self): QQ^1 in QQ^2 sage: FilteredVectorSpace(rays, {0:[3]}) QQ^1 >= 0 in QQ^2 - sage: FilteredVectorSpace({1:[(1,0), (-1,1)], 3:[(1,0)]}, base_ring=GF(3)) + sage: FilteredVectorSpace({1:[(1,0), (-1,1)], 3:[(1,0)]}, base_ring=GF(3)) # optional - sage.rings.finite_rings GF(3)^2 >= GF(3)^1 >= GF(3)^1 >= 0 - sage: FilteredVectorSpace({1:[(1,0), (-1,1)], 3:[(1,0)]}, base_ring=AA) + sage: FilteredVectorSpace({1:[(1,0), (-1,1)], 3:[(1,0)]}, base_ring=AA) # optional - sage.rings.number_field Vector space of dimension 2 over Algebraic Real Field >= Vector space of dimension 1 over Algebraic Real Field >= Vector space of dimension 1 over Algebraic Real Field >= 0 @@ -926,7 +926,7 @@ def __eq__(self, other): sage: S1._filt[0].is_isomorphic(S2._filt[0]) # known bug True - sage: FilteredVectorSpace(2, base_ring=QQ) == FilteredVectorSpace(2, base_ring=GF(5)) + sage: FilteredVectorSpace(2, base_ring=QQ) == FilteredVectorSpace(2, base_ring=GF(5)) # optional - sage.rings.finite_rings False """ if type(self) != type(other): @@ -1107,7 +1107,7 @@ def _power_operation(self, n, operation): QQ^2 >= QQ^1 >= 0 sage: F._power_operation(2, 'symmetric') QQ^3 >= QQ^2 >= QQ^1 >= 0 - sage: F._power_operation(2, 'antisymmetric') + sage: F._power_operation(2, 'antisymmetric') # optional - sage.groups QQ^1 >= 0 """ from sage.modules.tensor_operations import VectorCollection, TensorOperation @@ -1147,13 +1147,13 @@ def exterior_power(self, n): sage: F = FilteredVectorSpace(1, 1) + FilteredVectorSpace(1, 2); F QQ^2 >= QQ^1 >= 0 - sage: F.exterior_power(1) + sage: F.exterior_power(1) # optional - sage.groups QQ^2 >= QQ^1 >= 0 - sage: F.exterior_power(2) + sage: F.exterior_power(2) # optional - sage.groups QQ^1 >= 0 - sage: F.exterior_power(3) + sage: F.exterior_power(3) # optional - sage.groups 0 - sage: F.wedge(2) + sage: F.wedge(2) # optional - sage.groups QQ^1 >= 0 """ return self._power_operation(n, 'antisymmetric') diff --git a/src/sage/modules/finite_submodule_iter.pyx b/src/sage/modules/finite_submodule_iter.pyx index eb433546f23..54a27eab437 100644 --- a/src/sage/modules/finite_submodule_iter.pyx +++ b/src/sage/modules/finite_submodule_iter.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Iterators over finite submodules of a `\ZZ`-module diff --git a/src/sage/modules/fp_graded/element.py b/src/sage/modules/fp_graded/element.py index e4f288f3264..a4055b3e3b5 100755 --- a/src/sage/modules/fp_graded/element.py +++ b/src/sage/modules/fp_graded/element.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Elements of finitely presented graded modules diff --git a/src/sage/modules/fp_graded/free_module.py b/src/sage/modules/fp_graded/free_module.py index 3f87d6b9c6f..cb1caa3581c 100755 --- a/src/sage/modules/fp_graded/free_module.py +++ b/src/sage/modules/fp_graded/free_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Finitely generated free graded left modules over connected graded algebras diff --git a/src/sage/modules/fp_graded/homspace.py b/src/sage/modules/fp_graded/homspace.py index 08e30a17dba..985cb1d727b 100755 --- a/src/sage/modules/fp_graded/homspace.py +++ b/src/sage/modules/fp_graded/homspace.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Homsets of finitely presented graded modules diff --git a/src/sage/modules/fp_graded/module.py b/src/sage/modules/fp_graded/module.py index 79353e754a9..34787b8d217 100755 --- a/src/sage/modules/fp_graded/module.py +++ b/src/sage/modules/fp_graded/module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Finitely presented graded modules diff --git a/src/sage/modules/fp_graded/morphism.py b/src/sage/modules/fp_graded/morphism.py index fde00303230..75eacd961e7 100755 --- a/src/sage/modules/fp_graded/morphism.py +++ b/src/sage/modules/fp_graded/morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Homomorphisms of finitely presented graded modules diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index b7618475111..c96a7149922 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -18,17 +18,17 @@ EXAMPLES:: - sage: V = VectorSpace(QQ,3) + sage: V = VectorSpace(QQ, 3) sage: W = V.subspace([[1,2,7], [1,1,0]]) sage: W Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -7] [ 0 1 7] - sage: C = VectorSpaces(FiniteField(7)) - sage: C + sage: C = VectorSpaces(FiniteField(7)) # optional - sage.rings.finite_rings + sage: C # optional - sage.rings.finite_rings Category of vector spaces over Finite Field of size 7 - sage: C(W) + sage: C(W) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 2 over Finite Field of size 7 Basis matrix: [1 0 0] @@ -37,11 +37,11 @@ :: sage: M = ZZ^3 - sage: C = VectorSpaces(FiniteField(7)) - sage: C(M) + sage: C = VectorSpaces(FiniteField(7)) # optional - sage.rings.finite_rings + sage: C(M) # optional - sage.rings.finite_rings Vector space of dimension 3 over Finite Field of size 7 - sage: W = M.submodule([[1,2,7], [8,8,0]]) - sage: C(W) + sage: W = M.submodule([[1,2,7], [8,8,0]]) # optional - sage.rings.finite_rings + sage: C(W) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 2 over Finite Field of size 7 Basis matrix: [1 0 0] @@ -75,10 +75,10 @@ sage: print([v for _,v in zip(range(31), ZZ^3)]) [(0, 0, 0), - (1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1), - (1, 1, 0), (-1, 1, 0), (1, -1, 0), (-1, -1, 0), (1, 0, 1), (-1, 0, 1), (1, 0, -1), (-1, 0, -1), (0, 1, 1), (0, -1, 1), (0, 1, -1), (0, -1, -1), - (2, 0, 0), (-2, 0, 0), (0, 2, 0), (0, -2, 0), (0, 0, 2), (0, 0, -2), - (1, 1, 1), (-1, 1, 1), (1, -1, 1), (-1, -1, 1), (1, 1, -1), ...] + (1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1), + (1, 1, 0), (-1, 1, 0), (1, -1, 0), (-1, -1, 0), (1, 0, 1), (-1, 0, 1), (1, 0, -1), (-1, 0, -1), (0, 1, 1), (0, -1, 1), (0, 1, -1), (0, -1, -1), + (2, 0, 0), (-2, 0, 0), (0, 2, 0), (0, -2, 0), (0, 0, 2), (0, 0, -2), + (1, 1, 1), (-1, 1, 1), (1, -1, 1), (-1, -1, 1), (1, 1, -1), ...] For other infinite enumerated base rings (i.e., rings which are objects of the category :class:`InfiniteEnumeratedSets`), @@ -243,11 +243,11 @@ def create_object(self, version, key): sage: R. = QQ[] sage: Q = R.quo(R.ideal([x^2 - y^2 - 1])) - sage: Q.is_integral_domain() + sage: Q.is_integral_domain() # optional - sage.libs.singular True - sage: Q2 = FreeModule(Q, 2) - sage: from sage.modules.free_module import FreeModule_ambient_domain - sage: isinstance(Q2, FreeModule_ambient_domain) + sage: Q2 = FreeModule(Q, 2) # optional - sage.libs.singular + sage: from sage.modules.free_module import FreeModule_ambient_domain # optional - sage.libs.singular + sage: isinstance(Q2, FreeModule_ambient_domain) # optional - sage.libs.singular True """ base_ring, rank, sparse, inner_product_matrix = key @@ -385,14 +385,16 @@ def FreeModule(base_ring, rank_or_basis_keys=None, sparse=False, inner_product_m Vector space of dimension 10 over Rational Field sage: FreeModule(ZZ,10) Ambient free module of rank 10 over the principal ideal domain Integer Ring - sage: FreeModule(FiniteField(5),10) + sage: FreeModule(FiniteField(5), 10) # optional - sage.rings.finite_rings Vector space of dimension 10 over Finite Field of size 5 - sage: FreeModule(Integers(7),10) + sage: FreeModule(Integers(7), 10) Vector space of dimension 10 over Ring of integers modulo 7 - sage: FreeModule(PolynomialRing(QQ,'x'),5) - Ambient free module of rank 5 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: FreeModule(PolynomialRing(ZZ,'x'),5) - Ambient free module of rank 5 over the integral domain Univariate Polynomial Ring in x over Integer Ring + sage: FreeModule(PolynomialRing(QQ,'x'), 5) + Ambient free module of rank 5 over the principal ideal domain + Univariate Polynomial Ring in x over Rational Field + sage: FreeModule(PolynomialRing(ZZ,'x'), 5) + Ambient free module of rank 5 over the integral domain + Univariate Polynomial Ring in x over Integer Ring Of course we can make rank 0 free modules:: @@ -438,8 +440,8 @@ def FreeModule(base_ring, rank_or_basis_keys=None, sparse=False, inner_product_m :: - sage: A = MatrixSpace(ZZ,2)([[1,0],[0,-1]]) - sage: M = FreeModule(ZZ,2,inner_product_matrix=A) + sage: A = MatrixSpace(ZZ, 2)([[1,0], [0,-1]]) + sage: M = FreeModule(ZZ, 2, inner_product_matrix=A) sage: v, w = M.gens() sage: v.inner_product(w) 0 @@ -456,13 +458,13 @@ def FreeModule(base_ring, rank_or_basis_keys=None, sparse=False, inner_product_m :: - sage: FreeModule(ZZ,2,inner_product_matrix=1).inner_product_matrix() + sage: FreeModule(ZZ, 2, inner_product_matrix=1).inner_product_matrix() [1 0] [0 1] - sage: FreeModule(ZZ,2,inner_product_matrix=[1,2,3,4]).inner_product_matrix() + sage: FreeModule(ZZ, 2, inner_product_matrix=[1,2,3,4]).inner_product_matrix() [1 2] [3 4] - sage: FreeModule(ZZ,2,inner_product_matrix=[[1,2],[3,4]]).inner_product_matrix() + sage: FreeModule(ZZ, 2, inner_product_matrix=[[1,2], [3,4]]).inner_product_matrix() [1 2] [3 4] @@ -613,12 +615,13 @@ def span(gens, base_ring=None, check=True, already_echelonized=False): [ 1 0 -3] [ 0 1 4] - sage: span([V.gen(0)], QuadraticField(-7,'a')) - Vector space of degree 3 and dimension 1 over Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I + sage: span([V.gen(0)], QuadraticField(-7,'a')) # optional - sage.rings.number_field + Vector space of degree 3 and dimension 1 over Number Field in a + with defining polynomial x^2 + 7 with a = 2.645751311064591?*I Basis matrix: [ 1 0 -3] - sage: span([[1,2,3], [2,2,2], [1,2,5]], GF(2)) + sage: span([[1,2,3], [2,2,2], [1,2,5]], GF(2)) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 2 Basis matrix: [1 0 1] @@ -1013,8 +1016,8 @@ def some_elements(self): ... (46/103823, -46/103823, 103823/46)) - sage: F = FreeModule(SR, 2) - sage: tuple(F.some_elements()) + sage: F = FreeModule(SR, 2) # optional - sage.symbolic + sage: tuple(F.some_elements()) # optional - sage.symbolic ((1, 0), (some_variable, some_variable)) """ yield self.an_element() @@ -1108,15 +1111,15 @@ def relations_matrix(self): EXAMPLES:: - sage: V = GF(2)^2 - sage: V.relations_matrix() + sage: V = GF(2)^2 # optional - sage.rings.finite_rings + sage: V.relations_matrix() # optional - sage.rings.finite_rings [] - sage: W = V.subspace([[1, 0]]) - sage: W.relations_matrix() + sage: W = V.subspace([[1, 0]]) # optional - sage.rings.finite_rings + sage: W.relations_matrix() # optional - sage.rings.finite_rings [] - sage: Q = V / W - sage: Q.relations_matrix() + sage: Q = V / W # optional - sage.rings.finite_rings + sage: Q.relations_matrix() # optional - sage.rings.finite_rings [1 0] sage: S. = PolynomialRing(QQ) @@ -1187,22 +1190,22 @@ def __richcmp__(self, other, op): More exotic comparisons:: - sage: R1 = ZZ[sqrt(2)] - sage: F1 = R1^3 - sage: V1 = F1.span([[sqrt(2),sqrt(2),0]]) + sage: R1 = ZZ[sqrt(2)] # optional - sage.symbolic + sage: F1 = R1^3 # optional - sage.symbolic + sage: V1 = F1.span([[sqrt(2), sqrt(2), 0]]) # optional - sage.symbolic sage: F2 = ZZ^3 sage: V2 = F2.span([[2,2,0]]) - sage: V2 <= V1 # Different ambient vector spaces + sage: V2 <= V1 # Different ambient vector spaces # optional - sage.symbolic False - sage: V1 <= V2 + sage: V1 <= V2 # optional - sage.symbolic False - sage: R2 = GF(5)[x] - sage: F3 = R2^3 - sage: V3 = F3.span([[x^5-1,1+x+x^2+x^3+x^4,0]]) - sage: W3 = F3.span([[1,1,0],[0,4,0]]) - sage: V3 <= W3 + sage: R2 = GF(5)[x] # optional - sage.rings.finite_rings + sage: F3 = R2^3 # optional - sage.rings.finite_rings + sage: V3 = F3.span([[x^5 - 1, 1 + x + x^2 + x^3 + x^4, 0]]) # optional - sage.rings.finite_rings + sage: W3 = F3.span([[1,1,0], [0,4,0]]) # optional - sage.rings.finite_rings + sage: V3 <= W3 # optional - sage.rings.finite_rings True - sage: W3 <= V3 + sage: W3 <= V3 # optional - sage.rings.finite_rings False We compare a one dimensional space to a two dimensional space:: @@ -1216,7 +1219,7 @@ def __richcmp__(self, other, op): We test that :trac:`5525` is fixed:: - sage: A = (QQ^1).span([[1/3]],ZZ); B = (QQ^1).span([[1]],ZZ) + sage: A = (QQ^1).span([[1/3]], ZZ); B = (QQ^1).span([[1]], ZZ) sage: A.intersection(B) Free module of degree 1 and rank 1 over Integer Ring Echelon basis matrix: @@ -1265,8 +1268,8 @@ def __richcmp__(self, other, op): sage: P. = QQ[] sage: M = P**2 - sage: S1 = M.submodule([(x,y),(y,x)]) - sage: S2 = M.submodule([(x,y),(y-x,x-y)]) + sage: S1 = M.submodule([(x, y), (y, x)]) + sage: S2 = M.submodule([(x, y), (y - x, x - y)]) sage: S1 == S2 False sage: S1 != S2 @@ -1567,12 +1570,12 @@ def span(self, gens, base_ring=None, check=True, already_echelonized=False): EXAMPLES:: - sage: V = VectorSpace(GF(7), 3) - sage: W = V.subspace([[2,3,4]]); W + sage: V = VectorSpace(GF(7), 3) # optional - sage.rings.finite_rings + sage: W = V.subspace([[2, 3, 4]]); W # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 5 2] - sage: W.span([[1,1,1]]) + sage: W.span([[1, 1, 1]]) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 1 1] @@ -1582,14 +1585,15 @@ def span(self, gens, base_ring=None, check=True, already_echelonized=False): sage: S. = PolynomialRing(QQ) sage: M = S**2 sage: M.span([vector([x - y, z]), vector([y*z, x*z])]) - Submodule of Ambient free module of rank 2 over the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field + Submodule of Ambient free module of rank 2 over the integral domain + Multivariate Polynomial Ring in x, y, z over Rational Field Generated by the rows of the matrix: [x - y z] [ y*z x*z] Over a PID:: - sage: V = FreeModule(ZZ,3) + sage: V = FreeModule(ZZ, 3) sage: W = V.submodule([V.gen(0)]) sage: W.span([V.gen(1)]) Free module of degree 3 and rank 1 over Integer Ring @@ -1599,7 +1603,7 @@ def span(self, gens, base_ring=None, check=True, already_echelonized=False): Traceback (most recent call last): ... ArithmeticError: argument gens (= [(0, 1, 0)]) does not generate a submodule of self - sage: V.span([[1,0,0],[1/5,4,0],[6,3/4,0]]) + sage: V.span([[1,0,0], [1/5,4,0], [6,3/4,0]]) Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: [1/5 0 0] @@ -1607,19 +1611,21 @@ def span(self, gens, base_ring=None, check=True, already_echelonized=False): It also works with other things than integers:: - sage: R.=QQ[] - sage: L=R^1 - sage: a=L.span([(1/x,)]) + sage: R. = QQ[] + sage: L = R^1 + sage: a = L.span([(1/x,)]) sage: a - Free module of degree 1 and rank 1 over Univariate Polynomial Ring in x over Rational Field + Free module of degree 1 and rank 1 + over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: [1/x] sage: b=L.span([(1/x,)]) sage: a(b.gens()[0]) (1/x) sage: L2 = R^2 - sage: L2.span([[(x^2+x)/(x^2-3*x+2),1/5],[(x^2+2*x)/(x^2-4*x+3),x]]) - Free module of degree 2 and rank 2 over Univariate Polynomial Ring in x over Rational Field + sage: L2.span([[(x^2+x)/(x^2-3*x+2), 1/5], [(x^2+2*x)/(x^2-4*x+3), x]]) + Free module of degree 2 and rank 2 + over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: [x/(x^3 - 6*x^2 + 11*x - 6) 2/15*x^2 - 17/75*x - 1/75] [ 0 x^3 - 11/5*x^2 - 3*x + 4/5] @@ -1628,28 +1634,30 @@ def span(self, gens, base_ring=None, check=True, already_echelonized=False): repeat the previous example over the fraction field of R and get a simpler vector space. :: - sage: L2.span([[(x^2+x)/(x^2-3*x+2),1/5],[(x^2+2*x)/(x^2-4*x+3),x]],base_ring=R.fraction_field()) - Vector space of degree 2 and dimension 2 over Fraction Field of Univariate Polynomial Ring in x over Rational Field + sage: L2.span([[(x^2+x)/(x^2-3*x+2), 1/5], [(x^2+2*x)/(x^2-4*x+3), x]], + ....: base_ring=R.fraction_field()) + Vector space of degree 2 and dimension 2 over + Fraction Field of Univariate Polynomial Ring in x over Rational Field Basis matrix: [1 0] [0 1] TESTS:: - sage: V = FreeModule(RDF,3) + sage: V = FreeModule(RDF, 3) sage: W = V.submodule([V.gen(0)]) - sage: W.span([V.gen(1)], base_ring=GF(7)) + sage: W.span([V.gen(1)], base_ring=GF(7)) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [0 1 0] sage: v = V((1, pi, log(2))); v (1.0, 3.141592653589793, 0.6931471805599453) - sage: W.span([v], base_ring=GF(7)) + sage: W.span([v], base_ring=GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: argument gens (= [(1.0, 3.141592653589793, 0.6931471805599453)]) is not compatible with base_ring (= Finite Field of size 7) sage: W = V.submodule([v]) - sage: W.span([V.gen(2)], base_ring=GF(7)) + sage: W.span([V.gen(2)], base_ring=GF(7)) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [0 0 1] @@ -1694,7 +1702,7 @@ def submodule(self, gens, check=True, already_echelonized=False): sage: M = FreeModule(ZZ, 3) sage: B = M.basis() - sage: W = M.submodule([B[0]+B[1], 2*B[1]-B[2]]) + sage: W = M.submodule([B[0] + B[1], 2*B[1] - B[2]]) sage: W Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: @@ -1722,20 +1730,23 @@ def submodule(self, gens, check=True, already_echelonized=False): sage: R = PolynomialRing(QQ, 'x'); x = R.gen() sage: M = FreeModule(R, 3) sage: B = M.basis() - sage: W = M.submodule([x*B[0], 2*B[1]- x*B[2]]); W - Free module of degree 3 and rank 2 over Univariate Polynomial Ring in x over Rational Field + sage: W = M.submodule([x*B[0], 2*B[1] - x*B[2]]); W + Free module of degree 3 and rank 2 + over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: [ x 0 0] [ 0 2 -x] sage: W.ambient_module() - Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + Ambient free module of rank 3 over the principal ideal domain + Univariate Polynomial Ring in x over Rational Field Over a generic ring:: sage: S. = PolynomialRing(QQ) sage: A = S**2 sage: A.submodule([vector([x - y,z]), vector([y*z, x*z])]) - Submodule of Ambient free module of rank 2 over the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field + Submodule of Ambient free module of rank 2 over the integral domain + Multivariate Polynomial Ring in x, y, z over Rational Field Generated by the rows of the matrix: [x - y z] [ y*z x*z] @@ -1810,10 +1821,10 @@ def free_resolution(self, *args, **kwds): sage: S. = PolynomialRing(QQ) sage: M = S**2 sage: N = M.submodule([vector([x - y, z]), vector([y * z, x * z])]) - sage: res = N.free_resolution() - sage: res + sage: res = N.free_resolution() # optional - sage.libs.singular + sage: res # optional - sage.libs.singular S^2 <-- S^2 <-- 0 - sage: ascii_art(res.chain_complex()) + sage: ascii_art(res.chain_complex()) # optional - sage.libs.singular [x - y y*z] [ z x*z] 0 <-- C_0 <-------------- C_1 <-- 0 @@ -1842,13 +1853,13 @@ def graded_free_resolution(self, *args, **kwds): sage: S. = PolynomialRing(QQ) sage: M = S**2 sage: N = M.submodule([vector([x - y, z]), vector([y * z, x * z])]) - sage: N.graded_free_resolution(shifts=[1, -1]) + sage: N.graded_free_resolution(shifts=[1, -1]) # optional - sage.libs.singular S(-1)⊕S(1) <-- S(-2)⊕S(-3) <-- 0 - sage: N.graded_free_resolution(shifts=[2, 3]) + sage: N.graded_free_resolution(shifts=[2, 3]) # optional - sage.libs.singular S(-2)⊕S(-3) <-- S(-3)⊕S(-4) <-- 0 sage: N = M.submodule([vector([x^3 - y^6, z^2]), vector([y * z, x])]) - sage: N.graded_free_resolution(degrees=[2, 1, 3], shifts=[2, 3]) + sage: N.graded_free_resolution(degrees=[2, 1, 3], shifts=[2, 3]) # optional - sage.libs.singular S(-2)⊕S(-3) <-- S(-6)⊕S(-8) <-- 0 """ from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular @@ -1893,17 +1904,19 @@ class FreeModule_generic(Module_free_ambient): EXAMPLES:: sage: PolynomialRing(QQ,3,'x')^3 - Ambient free module of rank 3 over the integral domain Multivariate Polynomial Ring in x0, x1, x2 over Rational Field + Ambient free module of rank 3 over the integral domain + Multivariate Polynomial Ring in x0, x1, x2 over Rational Field - sage: FreeModule(GF(7),3).category() + sage: FreeModule(GF(7), 3).category() # optional - sage.rings.finite_rings Category of enumerated finite dimensional vector spaces with basis over (finite enumerated fields and subquotients of monoids and quotients of semigroups) sage: V = QQ^4; V.category() Category of finite dimensional vector spaces with basis over (number fields and quotient fields and metric spaces) - sage: V = GF(5)**20; V.category() - Category of enumerated finite dimensional vector spaces with basis over (finite enumerated fields and subquotients of monoids and quotients of semigroups) - sage: FreeModule(ZZ,3).category() + sage: V = GF(5)**20; V.category() # optional - sage.rings.finite_rings + Category of enumerated finite dimensional vector spaces with basis over + (finite enumerated fields and subquotients of monoids and quotients of semigroups) + sage: FreeModule(ZZ, 3).category() Category of finite dimensional modules with basis over (euclidean domains and infinite enumerated sets and metric spaces) @@ -1928,14 +1941,14 @@ def __init__(self, base_ring, rank, degree, sparse=False, TESTS:: - sage: M = FreeModule(ZZ,20,sparse=False) + sage: M = FreeModule(ZZ, 20, sparse=False) sage: x = M.random_element() sage: type(x) sage: M.element_class - sage: N = FreeModule(ZZ,20,sparse=True) + sage: N = FreeModule(ZZ, 20, sparse=True) sage: y = N.random_element() sage: type(y) @@ -1972,7 +1985,7 @@ def construction(self): EXAMPLES:: - sage: R = PolynomialRing(QQ,3,'x') + sage: R = PolynomialRing(QQ, 3, 'x') sage: V = R^5 sage: V.construction() (VectorFunctor, Multivariate Polynomial Ring in x0, x1, x2 over Rational Field) @@ -1997,8 +2010,8 @@ def dense_module(self): We first illustrate conversion with ambient spaces:: - sage: M = FreeModule(QQ,3) - sage: S = FreeModule(QQ,3, sparse=True) + sage: M = FreeModule(QQ, 3) + sage: S = FreeModule(QQ, 3, sparse=True) sage: M.sparse_module() Sparse vector space of dimension 3 over Rational Field sage: S.dense_module() @@ -2014,7 +2027,7 @@ def dense_module(self): Next we create a subspace:: - sage: M = FreeModule(QQ,3, sparse=True) + sage: M = FreeModule(QQ, 3, sparse=True) sage: V = M.span([ [1,2,3] ] ); V Sparse vector space of degree 3 and dimension 1 over Rational Field Basis matrix: @@ -2037,8 +2050,8 @@ def _dense_module(self): EXAMPLES:: - sage: M = FreeModule(Integers(8),3) - sage: S = FreeModule(Integers(8),3, sparse=True) + sage: M = FreeModule(Integers(8), 3) + sage: S = FreeModule(Integers(8), 3, sparse=True) sage: M is S._dense_module() True """ @@ -2054,8 +2067,8 @@ def sparse_module(self): We first illustrate conversion with ambient spaces:: - sage: M = FreeModule(Integers(8),3) - sage: S = FreeModule(Integers(8),3, sparse=True) + sage: M = FreeModule(Integers(8), 3) + sage: S = FreeModule(Integers(8), 3, sparse=True) sage: M.sparse_module() Ambient sparse free module of rank 3 over Ring of integers modulo 8 sage: S.dense_module() @@ -2094,8 +2107,8 @@ def _sparse_module(self): EXAMPLES:: - sage: M = FreeModule(Integers(8),3) - sage: S = FreeModule(Integers(8),3, sparse=True) + sage: M = FreeModule(Integers(8), 3) + sage: S = FreeModule(Integers(8), 3, sparse=True) sage: M._sparse_module() is S True """ @@ -2234,9 +2247,9 @@ def is_submodule(self, other): EXAMPLES:: - sage: M = FreeModule(ZZ,3) + sage: M = FreeModule(ZZ, 3) sage: V = M.ambient_vector_space() - sage: X = V.span([[1/2,1/2,0],[1/2,0,1/2]], ZZ) + sage: X = V.span([[1/2,1/2,0], [1/2,0,1/2]], ZZ) sage: Y = V.span([[1,1,1]], ZZ) sage: N = X + Y sage: M.is_submodule(X) @@ -2250,7 +2263,7 @@ def is_submodule(self, other): sage: M.is_submodule(N) True - sage: M = FreeModule(ZZ,2) + sage: M = FreeModule(ZZ, 2) sage: M.is_submodule(M) True sage: N = M.scale(2) @@ -2268,9 +2281,9 @@ def is_submodule(self, other): testing does not work for all PID's. However, trivial cases are already used (and useful) for coercion, e.g.:: - sage: QQ(1/2) * vector(ZZ['x']['y'],[1,2,3,4]) + sage: QQ(1/2) * vector(ZZ['x']['y'], [1,2,3,4]) (1/2, 1, 3/2, 2) - sage: vector(ZZ['x']['y'],[1,2,3,4]) * QQ(1/2) + sage: vector(ZZ['x']['y'], [1,2,3,4]) * QQ(1/2) (1/2, 1, 3/2, 2) TESTS:: @@ -2281,7 +2294,7 @@ def is_submodule(self, other): False sage: M1 = QQ^3 / [[1,2,3]] - sage: V1 = span(QQ,[(1,0,0)]) + M1.relations() + sage: V1 = span(QQ, [(1,0,0)]) + M1.relations() sage: M2 = V1 / M1.relations() sage: M2.is_submodule(M1) # Different ambient vector spaces False @@ -2355,14 +2368,16 @@ def __iter__(self): EXAMPLES:: - sage: V = VectorSpace(GF(4,'a'),2) - sage: [x for x in V] - [(0, 0), (a, 0), (a + 1, 0), (1, 0), (0, a), (a, a), (a + 1, a), (1, a), (0, a + 1), (a, a + 1), (a + 1, a + 1), (1, a + 1), (0, 1), (a, 1), (a + 1, 1), (1, 1)] + sage: V = VectorSpace(GF(4, 'a'), 2) # optional - sage.rings.finite_rings + sage: [x for x in V] # optional - sage.rings.finite_rings + [(0, 0), (a, 0), (a + 1, 0), (1, 0), (0, a), (a, a), (a + 1, a), (1, a), + (0, a + 1), (a, a + 1), (a + 1, a + 1), (1, a + 1), (0, 1), (a, 1), + (a + 1, 1), (1, 1)] :: - sage: W = V.subspace([V([1,1])]) - sage: [x for x in W] + sage: W = V.subspace([V([1, 1])]) # optional - sage.rings.finite_rings + sage: [x for x in W] # optional - sage.rings.finite_rings [(0, 0), (a, a), (a + 1, a + 1), (1, 1)] Free modules over enumerated infinite rings (i.e., those in the @@ -2379,8 +2394,8 @@ def __iter__(self): TESTS:: - sage: V = VectorSpace(GF(2,'a'),2) - sage: V.list() + sage: V = VectorSpace(GF(2, 'a'), 2) # optional - sage.rings.finite_rings + sage: V.list() # optional - sage.rings.finite_rings [(0, 0), (1, 0), (0, 1), (1, 1)] Test ``iter(ZZ^n)`` and the like:: @@ -2462,15 +2477,15 @@ def cardinality(self): EXAMPLES:: - sage: k. = FiniteField(9) - sage: V = VectorSpace(k,3) - sage: V.cardinality() + sage: k. = FiniteField(9) # optional - sage.rings.finite_rings + sage: V = VectorSpace(k, 3) # optional - sage.rings.finite_rings + sage: V.cardinality() # optional - sage.rings.finite_rings 729 - sage: W = V.span([[1,2,1],[0,1,1]]) - sage: W.cardinality() + sage: W = V.span([[1,2,1], [0,1,1]]) # optional - sage.rings.finite_rings + sage: W.cardinality() # optional - sage.rings.finite_rings 81 sage: R = IntegerModRing(12) - sage: M = FreeModule(R,2) + sage: M = FreeModule(R, 2) sage: M.cardinality() 144 sage: (QQ^3).cardinality() @@ -2526,32 +2541,32 @@ def basis_matrix(self, ring=None): EXAMPLES:: - sage: FreeModule(Integers(12),3).basis_matrix() + sage: FreeModule(Integers(12), 3).basis_matrix() [1 0 0] [0 1 0] [0 0 1] :: - sage: M = FreeModule(GF(7),3).span([[2,3,4],[1,1,1]]); M + sage: M = FreeModule(GF(7), 3).span([[2,3,4], [1,1,1]]); M # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 2 over Finite Field of size 7 Basis matrix: [1 0 6] [0 1 2] - sage: M.basis_matrix() + sage: M.basis_matrix() # optional - sage.rings.finite_rings [1 0 6] [0 1 2] :: - sage: M = FreeModule(GF(7),3).span_of_basis([[2,3,4],[1,1,1]]) - sage: M.basis_matrix() + sage: M = FreeModule(GF(7), 3).span_of_basis([[2,3,4], [1,1,1]]) # optional - sage.rings.finite_rings + sage: M.basis_matrix() # optional - sage.rings.finite_rings [2 3 4] [1 1 1] :: - sage: M = FreeModule(QQ,2).span_of_basis([[1,-1],[1,0]]); M + sage: M = FreeModule(QQ, 2).span_of_basis([[1,-1], [1,0]]); M Vector space of degree 2 and dimension 2 over Rational Field User basis matrix: [ 1 -1] @@ -2615,7 +2630,7 @@ def echelonized_basis_matrix(self): sage: R = IntegerModRing(12) sage: S. = R[] - sage: M = FreeModule(S,3) + sage: M = FreeModule(S, 3) sage: M.echelonized_basis_matrix() [1 0 0] [0 1 0] @@ -2700,9 +2715,9 @@ def coordinates(self, v, check=True): EXAMPLES:: - sage: M = FreeModule(ZZ, 2); M0,M1=M.gens() + sage: M = FreeModule(ZZ, 2); M0, M1 = M.gens() sage: W = M.submodule([M0 + M1, M0 - 2*M1]) - sage: W.coordinates(2*M0-M1) + sage: W.coordinates(2*M0 - M1) [2, -1] """ return self.coordinate_vector(v, check=check).list() @@ -2723,7 +2738,7 @@ def coordinate_vector(self, v, check=True): EXAMPLES:: - sage: M = FreeModule(ZZ, 2); M0,M1=M.gens() + sage: M = FreeModule(ZZ, 2); M0, M1 = M.gens() sage: W = M.submodule([M0 + M1, M0 - 2*M1]) sage: W.coordinate_vector(2*M0 - M1) (2, -1) @@ -2806,9 +2821,9 @@ def dimension(self): EXAMPLES:: - sage: M = FreeModule(FiniteField(19), 100) - sage: W = M.submodule([M.gen(50)]) - sage: W.dimension() + sage: M = FreeModule(FiniteField(19), 100) # optional - sage.rings.finite_rings + sage: W = M.submodule([M.gen(50)]) # optional - sage.rings.finite_rings + sage: W.dimension() # optional - sage.rings.finite_rings 1 """ return self.rank() @@ -2863,12 +2878,13 @@ def base_field(self): EXAMPLES:: - sage: FreeModule(GF(3), 2).base_field() + sage: FreeModule(GF(3), 2).base_field() # optional - sage.rings.finite_rings Finite Field of size 3 - sage: FreeModule(ZZ, 2).base_field() + sage: FreeModule(ZZ, 2).base_field() # optional - sage.rings.finite_rings Rational Field - sage: FreeModule(PolynomialRing(GF(7),'x'), 2).base_field() - Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 7 + sage: FreeModule(PolynomialRing(GF(7), 'x'), 2).base_field() # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in x + over Finite Field of size 7 """ return self.base_ring().fraction_field() @@ -3366,7 +3382,7 @@ def _magma_init_(self, magma): Inner product matrix: [ 1 0] [ 0 -1] - sage: m.sage() is M # optional - magma + sage: m.sage() is M # optional - magma True Now over a field:: @@ -3527,11 +3543,12 @@ def _mul_(self, other, switch_sides=False): Check that :trac:`17705` is fixed:: - sage: V = GF(2)^2 - sage: W = V.subspace([[1, 0]]) - sage: x = matrix(GF(2), [[1, 1], [0, 1]]) - sage: W*x - Vector space of degree 2 and dimension 1 over Finite Field of size 2 + sage: V = GF(2)^2 # optional - sage.rings.finite_rings + sage: W = V.subspace([[1, 0]]) # optional - sage.rings.finite_rings + sage: x = matrix(GF(2), [[1, 1], [0, 1]]) # optional - sage.rings.finite_rings + sage: W*x # optional - sage.rings.finite_rings + Vector space of degree 2 and dimension 1 + over Finite Field of size 2 Basis matrix: [1 1] @@ -3546,15 +3563,15 @@ def relations(self): EXAMPLES:: - sage: V = GF(2)^2 - sage: V.relations() == V.zero_submodule() + sage: V = GF(2)^2 # optional - sage.rings.finite_rings + sage: V.relations() == V.zero_submodule() # optional - sage.rings.finite_rings True - sage: W = V.subspace([[1, 0]]) - sage: W.relations() == V.zero_submodule() + sage: W = V.subspace([[1, 0]]) # optional - sage.rings.finite_rings + sage: W.relations() == V.zero_submodule() # optional - sage.rings.finite_rings True - sage: Q = V / W - sage: Q.relations() == W + sage: Q = V / W # optional - sage.rings.finite_rings + sage: Q.relations() == W # optional - sage.rings.finite_rings True """ return self.zero_submodule() @@ -3571,9 +3588,12 @@ def __init__(self, base_ring, rank, degree, sparse=False, coordinate_ring=None, EXAMPLES:: sage: FreeModule(ZZ, 2) - Ambient free module of rank 2 over the principal ideal domain Integer Ring - sage: FreeModule(PolynomialRing(GF(7),'x'), 2) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Finite Field of size 7 + Ambient free module of rank 2 + over the principal ideal domain Integer Ring + sage: FreeModule(PolynomialRing(GF(7), 'x'), 2) # optional - sage.rings.finite_rings + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x + over Finite Field of size 7 """ FreeModule_generic.__init__(self, base_ring, rank, degree, sparse, coordinate_ring, category=category) @@ -3665,9 +3685,12 @@ def __init__(self, base_ring, rank, degree, sparse=False, coordinate_ring=None, EXAMPLES:: sage: FreeModule(ZZ, 2) - Ambient free module of rank 2 over the principal ideal domain Integer Ring - sage: FreeModule(PolynomialRing(GF(7),'x'), 2) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Finite Field of size 7 + Ambient free module of rank 2 + over the principal ideal domain Integer Ring + sage: FreeModule(PolynomialRing(GF(7), 'x'), 2) # optional - sage.rings.finite_rings + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x + over Finite Field of size 7 """ super().__init__(base_ring, rank, degree, sparse, coordinate_ring, category=category) @@ -4193,10 +4216,11 @@ def vector_space_span(self, gens, check=True): :: sage: R. = QQ[] - sage: K = NumberField(x^2 + 1, 'a'); a = K.gen() - sage: V = VectorSpace(K, 3) - sage: V.vector_space_span([2*V.gen(0) + 3*V.gen(2)]) - Vector space of degree 3 and dimension 1 over Number Field in a with defining polynomial x^2 + 1 + sage: K = NumberField(x^2 + 1, 'a'); a = K.gen() # optional - sage.rings.number_field + sage: V = VectorSpace(K, 3) # optional - sage.rings.number_field + sage: V.vector_space_span([2*V.gen(0) + 3*V.gen(2)]) # optional - sage.rings.number_field + Vector space of degree 3 and dimension 1 + over Number Field in a with defining polynomial x^2 + 1 Basis matrix: [ 1 0 3/2] @@ -4206,7 +4230,7 @@ def vector_space_span(self, gens, check=True): :: - sage: M = FreeModule(ZZ,3) + sage: M = FreeModule(ZZ, 3) sage: W = M.submodule([M([1,2,3])]) sage: W.vector_space_span([M([2,3,4])]) Vector space of degree 3 and dimension 1 over Rational Field @@ -4235,7 +4259,7 @@ def vector_space_span_of_basis(self, basis, check=True): sage: V = VectorSpace(QQ, 3) sage: B = V.basis() - sage: W = V.vector_space_span_of_basis([B[0]+B[1], 2*B[1]-B[2]]) + sage: W = V.vector_space_span_of_basis([B[0] + B[1], 2*B[1] - B[2]]) sage: W Vector space of degree 3 and dimension 2 over Rational Field User basis matrix: @@ -4291,7 +4315,7 @@ def __init__(self, base_field, dimension, degree, sparse=False, category=None): sage: FreeModule(QQ, 2) Vector space of dimension 2 over Rational Field - sage: FreeModule(FiniteField(2), 7) + sage: FreeModule(FiniteField(2), 7) # optional - sage.rings.finite_rings Vector space of dimension 7 over Finite Field of size 2 We test that objects of this type are initialised correctly; @@ -4336,7 +4360,9 @@ def _Hom_(self, Y, category): sage: type(H) sage: H - Set of Morphisms (Linear Transformations) from Vector space of dimension 2 over Rational Field to Vector space of dimension 3 over Rational Field + Set of Morphisms (Linear Transformations) + from Vector space of dimension 2 over Rational Field + to Vector space of dimension 3 over Rational Field sage: V = QQ^2 sage: W = ZZ^3 @@ -4581,12 +4607,12 @@ def span_of_basis(self, basis, base_ring=None, check=True, already_echelonized=F EXAMPLES:: - sage: V = VectorSpace(GF(7), 3) - sage: W = V.subspace([[2,3,4]]); W + sage: V = VectorSpace(GF(7), 3) # optional - sage.rings.finite_rings + sage: W = V.subspace([[2,3,4]]); W # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 5 2] - sage: W.span_of_basis([[2,2,2], [3,3,0]]) + sage: W.span_of_basis([[2,2,2], [3,3,0]]) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 2 over Finite Field of size 7 User basis matrix: [2 2 2] @@ -4595,7 +4621,7 @@ def span_of_basis(self, basis, base_ring=None, check=True, already_echelonized=F The basis vectors must be linearly independent or a ``ValueError`` exception is raised:: - sage: W.span_of_basis([[2,2,2], [3,3,3]]) + sage: W.span_of_basis([[2,2,2], [3,3,3]]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: The given basis vectors must be linearly independent. @@ -4636,8 +4662,8 @@ def subspace(self, gens, check=True, already_echelonized=False): ambient `3`-dimensional space over the finite field of order `7`:: - sage: V = VectorSpace(GF(7), 3) - sage: W = V.subspace([[2,3,4]]); W + sage: V = VectorSpace(GF(7), 3) # optional - sage.rings.finite_rings + sage: W = V.subspace([[2,3,4]]); W # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 5 2] @@ -4646,7 +4672,7 @@ def subspace(self, gens, check=True, already_echelonized=False): ``check=False``. This is just equivalent to computing the span of the element:: - sage: W.subspace([[1,1,0]], check=False) + sage: W.subspace([[1,1,0]], check=False) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 1 0] @@ -4654,7 +4680,7 @@ def subspace(self, gens, check=True, already_echelonized=False): With ``check=True`` (the default) the mistake is correctly detected and reported with an ``ArithmeticError`` exception:: - sage: W.subspace([[1,1,0]], check=True) + sage: W.subspace([[1,1,0]], check=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: argument gens (= [[1, 1, 0]]) does not generate a submodule of self @@ -4671,25 +4697,25 @@ def subspaces(self, dim): EXAMPLES:: - sage: V = VectorSpace(GF(3), 5) - sage: len(list(V.subspaces(0))) + sage: V = VectorSpace(GF(3), 5) # optional - sage.rings.finite_rings + sage: len(list(V.subspaces(0))) # optional - sage.rings.finite_rings 1 - sage: len(list(V.subspaces(1))) + sage: len(list(V.subspaces(1))) # optional - sage.rings.finite_rings 121 - sage: len(list(V.subspaces(2))) + sage: len(list(V.subspaces(2))) # optional - sage.rings.finite_rings 1210 - sage: len(list(V.subspaces(3))) + sage: len(list(V.subspaces(3))) # optional - sage.rings.finite_rings 1210 - sage: len(list(V.subspaces(4))) + sage: len(list(V.subspaces(4))) # optional - sage.rings.finite_rings 121 - sage: len(list(V.subspaces(5))) + sage: len(list(V.subspaces(5))) # optional - sage.rings.finite_rings 1 :: - sage: V = VectorSpace(GF(3), 5) - sage: V = V.subspace([V([1,1,0,0,0]),V([0,0,1,1,0])]) - sage: list(V.subspaces(1)) + sage: V = VectorSpace(GF(3), 5) # optional - sage.rings.finite_rings + sage: V = V.subspace([V([1,1,0,0,0]), V([0,0,1,1,0])]) # optional - sage.rings.finite_rings + sage: list(V.subspaces(1)) # optional - sage.rings.finite_rings [Vector space of degree 5 and dimension 1 over Finite Field of size 3 Basis matrix: [1 1 0 0 0], @@ -4720,8 +4746,8 @@ def subspace_with_basis(self, gens, check=True, already_echelonized=False): :: - sage: V = VectorSpace(GF(7), 3) - sage: W = V.subspace_with_basis([[2,2,2], [1,2,3]]); W + sage: V = VectorSpace(GF(7), 3) # optional - sage.rings.finite_rings + sage: W = V.subspace_with_basis([[2,2,2], [1,2,3]]); W # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 2 over Finite Field of size 7 User basis matrix: [2 2 2] @@ -4731,7 +4757,7 @@ def subspace_with_basis(self, gens, check=True, already_echelonized=False): :: - sage: W1 = W.subspace_with_basis([[3,4,5]]); W1 + sage: W1 = W.subspace_with_basis([[3,4,5]]); W1 # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 User basis matrix: [3 4 5] @@ -4741,14 +4767,14 @@ def subspace_with_basis(self, gens, check=True, already_echelonized=False): :: - sage: W2 = W.subspace([[3,4,5]]); W2 + sage: W2 = W.subspace([[3,4,5]]); W2 # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 6 4] Nonetheless the two subspaces are equal (as mathematical objects):: - sage: W1 == W2 + sage: W1 == W2 # optional - sage.rings.finite_rings True """ return self.submodule_with_basis(gens, check=check, already_echelonized=already_echelonized) @@ -4796,14 +4822,14 @@ def complement(self): we can get complements which are only isomorphic to a vector space decomposition complement. :: - sage: F2 = GF(2,x) - sage: V = F2^6 - sage: W = V.span([[1,1,0,0,0,0]]) - sage: W + sage: F2 = GF(2, x) # optional - sage.rings.finite_rings + sage: V = F2^6 # optional - sage.rings.finite_rings + sage: W = V.span([[1,1,0,0,0,0]]) # optional - sage.rings.finite_rings + sage: W # optional - sage.rings.finite_rings Vector space of degree 6 and dimension 1 over Finite Field of size 2 Basis matrix: [1 1 0 0 0 0] - sage: W.complement() + sage: W.complement() # optional - sage.rings.finite_rings Vector space of degree 6 and dimension 5 over Finite Field of size 2 Basis matrix: [1 1 0 0 0 0] @@ -4811,7 +4837,7 @@ def complement(self): [0 0 0 1 0 0] [0 0 0 0 1 0] [0 0 0 0 0 1] - sage: W.intersection(W.complement()) + sage: W.intersection(W.complement()) # optional - sage.rings.finite_rings Vector space of degree 6 and dimension 1 over Finite Field of size 2 Basis matrix: [1 1 0 0 0 0] @@ -4973,23 +4999,23 @@ def linear_dependence(self, vectors, zeros='left', check=True): linearly independent vectors and add in two linear combinations to make a linearly dependent set of five vectors. :: - sage: F = FiniteField(17) - sage: v1 = vector(F, [1, 2, 3, 4, 5]) - sage: v2 = vector(F, [2, 4, 8, 16, 15]) - sage: v3 = vector(F, [1, 0, 0, 0, 1]) - sage: (F^5).linear_dependence([v1, v2, v3]) == [] + sage: F = FiniteField(17) # optional - sage.rings.finite_rings + sage: v1 = vector(F, [1, 2, 3, 4, 5]) # optional - sage.rings.finite_rings + sage: v2 = vector(F, [2, 4, 8, 16, 15]) # optional - sage.rings.finite_rings + sage: v3 = vector(F, [1, 0, 0, 0, 1]) # optional - sage.rings.finite_rings + sage: (F^5).linear_dependence([v1, v2, v3]) == [] # optional - sage.rings.finite_rings True - sage: L = [v1, v2, v3, 2*v1+v2, 3*v2+6*v3] - sage: (F^5).linear_dependence(L) + sage: L = [v1, v2, v3, 2*v1+v2, 3*v2+6*v3] # optional - sage.rings.finite_rings + sage: (F^5).linear_dependence(L) # optional - sage.rings.finite_rings [ (1, 0, 16, 8, 3), (0, 1, 2, 0, 11) ] - sage: v1 + 16*v3 + 8*(2*v1+v2) + 3*(3*v2+6*v3) + sage: v1 + 16*v3 + 8*(2*v1+v2) + 3*(3*v2+6*v3) # optional - sage.rings.finite_rings (0, 0, 0, 0, 0) - sage: v2 + 2*v3 + 11*(3*v2+6*v3) + sage: v2 + 2*v3 + 11*(3*v2+6*v3) # optional - sage.rings.finite_rings (0, 0, 0, 0, 0) - sage: (F^5).linear_dependence(L, zeros='right') + sage: (F^5).linear_dependence(L, zeros='right') # optional - sage.rings.finite_rings [ (15, 16, 0, 1, 0), (0, 14, 11, 0, 1) @@ -5005,7 +5031,8 @@ def linear_dependence(self, vectors, zeros='left', check=True): sage: (RR^3).linear_dependence([v1,v2], check=True) Traceback (most recent call last): ... - ValueError: vector (1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000) is not an element of Vector space of dimension 3 over Real Field with 53 bits of precision + ValueError: vector (1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000) + is not an element of Vector space of dimension 3 over Real Field with 53 bits of precision The ``zeros`` keyword is checked. :: @@ -5134,7 +5161,7 @@ def __quotient_matrices(self, sub): An example in characteristic 5:: - sage: A = GF(5)^2; B = A.span([[1,3]]); A / B + sage: A = GF(5)^2; B = A.span([[1,3]]); A / B # optional - sage.rings.finite_rings Vector space quotient V/W of dimension 1 over Finite Field of size 5 where V: Vector space of dimension 2 over Finite Field of size 5 W: Vector space of degree 2 and dimension 1 over Finite Field of size 5 @@ -5224,19 +5251,19 @@ def quotient_abstract(self, sub, check=True, **kwds): EXAMPLES:: - sage: V = GF(19)^3 - sage: W = V.span_of_basis([ [1,2,3], [1,0,1] ]) - sage: U,pi,lift = V.quotient_abstract(W) - sage: pi(V.2) + sage: V = GF(19)^3 # optional - sage.rings.finite_rings + sage: W = V.span_of_basis([[1,2,3], [1,0,1]]) # optional - sage.rings.finite_rings + sage: U, pi, lift = V.quotient_abstract(W) # optional - sage.rings.finite_rings + sage: pi(V.2) # optional - sage.rings.finite_rings (18) - sage: pi(V.0) + sage: pi(V.0) # optional - sage.rings.finite_rings (1) - sage: pi(V.0 + V.2) + sage: pi(V.0 + V.2) # optional - sage.rings.finite_rings (0) Another example involving a quotient of one subspace by another:: - sage: A = matrix(QQ,4,4,[0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0,0]) + sage: A = matrix(QQ, 4,4, [0,1,0,0, 0,0,1,0, 0,0,0,1, 0,0,0,0]) sage: V = (A^3).kernel() sage: W = A.kernel() sage: U, pi, lift = V.quotient_abstract(W) @@ -5296,14 +5323,14 @@ def __init__(self, base_ring, rank, sparse=False, coordinate_ring=None, category We check that the creation of a submodule does not trigger the construction of a basis of the ambient space. See :trac:`15953`:: - sage: F. = GF(4) - sage: V = VectorSpace(F, 1) - sage: v = V.random_element() - sage: _ = V.subspace([v]) - sage: hasattr(V, '_FreeModule_ambient__basis') + sage: F. = GF(4) # optional - sage.rings.finite_rings + sage: V = VectorSpace(F, 1) # optional - sage.rings.finite_rings + sage: v = V.random_element() # optional - sage.rings.finite_rings + sage: _ = V.subspace([v]) # optional - sage.rings.finite_rings + sage: hasattr(V, '_FreeModule_ambient__basis') # optional - sage.rings.finite_rings False - sage: _ = V.basis() - sage: hasattr(V, '_FreeModule_ambient__basis') + sage: _ = V.basis() # optional - sage.rings.finite_rings + sage: hasattr(V, '_FreeModule_ambient__basis') # optional - sage.rings.finite_rings True """ FreeModule_generic.__init__(self, base_ring, rank=rank, @@ -5586,14 +5613,14 @@ def _latex_(self): :: - sage: A = GF(5)^20 - sage: latex(A) # indirect doctest + sage: A = GF(5)^20 # optional - sage.rings.finite_rings + sage: latex(A) # indirect doctest # optional - sage.rings.finite_rings \Bold{F}_{5}^{20} :: - sage: A = PolynomialRing(QQ,3,'x') ^ 20 - sage: latex(A) #indirect doctest + sage: A = PolynomialRing(QQ, 3, 'x')^20 + sage: latex(A) # indirect doctest (\Bold{Q}[x_{0}, x_{1}, x_{2}])^{20} """ t = "%s" % latex.latex(self.base_ring()) @@ -5688,12 +5715,12 @@ def change_ring(self, R): sage: A = ZZ^3; A.change_ring(QQ) Vector space of dimension 3 over Rational Field - sage: A = ZZ^3; A.change_ring(GF(5)) + sage: A = ZZ^3; A.change_ring(GF(5)) # optional - sage.rings.finite_rings Vector space of dimension 3 over Finite Field of size 5 For ambient modules any change of rings is defined:: - sage: A = GF(5)**3; A.change_ring(QQ) + sage: A = GF(5)**3; A.change_ring(QQ) # optional - sage.rings.finite_rings Vector space of dimension 3 over Rational Field TESTS: @@ -5958,9 +5985,9 @@ def _sympy_(self): EXAMPLES:: - sage: sZZ3 = (ZZ^3)._sympy_(); sZZ3 + sage: sZZ3 = (ZZ^3)._sympy_(); sZZ3 # optional - sympy ProductSet(Integers, Integers, Integers) - sage: (1, 2, 3) in sZZ3 + sage: (1, 2, 3) in sZZ3 # optional - sympy True """ from sympy import ProductSet @@ -5981,9 +6008,9 @@ class FreeModule_ambient_domain(FreeModule_generic_domain, FreeModule_ambient): EXAMPLES:: - sage: FreeModule(PolynomialRing(GF(5),'x'), 3) + sage: FreeModule(PolynomialRing(GF(5), 'x'), 3) # optional - sage.rings.finite_rings Ambient free module of rank 3 over the principal ideal domain - Univariate Polynomial Ring in x over Finite Field of size 5 + Univariate Polynomial Ring in x over Finite Field of size 5 """ def __init__(self, base_ring, rank, sparse=False, coordinate_ring=None, category=None): """ @@ -5992,8 +6019,8 @@ def __init__(self, base_ring, rank, sparse=False, coordinate_ring=None, category TESTS:: - sage: A = FreeModule(PolynomialRing(GF(5),'x'), 3) - sage: TestSuite(A).run() + sage: A = FreeModule(PolynomialRing(GF(5),'x'), 3) # optional - sage.rings.finite_rings + sage: TestSuite(A).run() # optional - sage.rings.finite_rings """ FreeModule_ambient.__init__(self, base_ring, rank, sparse, coordinate_ring, category=category) @@ -6004,7 +6031,7 @@ def _repr_(self): EXAMPLES:: sage: R = PolynomialRing(ZZ,'x') - sage: M = FreeModule(R,7) + sage: M = FreeModule(R, 7) sage: M Ambient free module of rank 7 over the integral domain Univariate Polynomial Ring in x over Integer Ring sage: print(M._repr_()) @@ -6024,7 +6051,7 @@ def _repr_(self): :: - sage: N = FreeModule(R,7,sparse=True) + sage: N = FreeModule(R, 7, sparse=True) sage: N Ambient sparse free module of rank 7 over the integral domain Univariate Polynomial Ring in x over Integer Ring @@ -6340,9 +6367,9 @@ def _element_constructor_(self, e, *args, **kwds): EXAMPLES:: - sage: k. = GF(3^4) - sage: VS = k.vector_space(map=False) - sage: VS(a) + sage: k. = GF(3^4) # optional - sage.rings.finite_rings + sage: VS = k.vector_space(map=False) # optional - sage.rings.finite_rings + sage: VS(a) # optional - sage.rings.finite_rings (0, 1, 0, 0) """ try: @@ -6409,7 +6436,7 @@ class FreeModule_submodule_with_basis_pid(FreeModule_generic_pid): EXAMPLES:: sage: M = ZZ^3 - sage: W = M.span_of_basis([[1,2,3],[4,5,6]]); W + sage: W = M.span_of_basis([[1,2,3], [4,5,6]]); W Free module of degree 3 and rank 2 over Integer Ring User basis matrix: [1 2 3] @@ -6418,7 +6445,7 @@ class FreeModule_submodule_with_basis_pid(FreeModule_generic_pid): Now we create a submodule of the ambient vector space, rather than ``M`` itself:: - sage: W = M.span_of_basis([[1,2,3/2],[4,5,6]]); W + sage: W = M.span_of_basis([[1,2,3/2], [4,5,6]]); W Free module of degree 3 and rank 2 over Integer Ring User basis matrix: [ 1 2 3/2] @@ -6453,8 +6480,8 @@ def __init__(self, ambient, basis, check=True, :trac:`10250` is solved as well:: sage: V = (QQ^2).span_of_basis([[1,1]]) - sage: w = sqrt(2) * V([1,1]) - sage: 3 * w + sage: w = sqrt(2) * V([1,1]) # optional - sage.symbolic + sage: 3 * w # optional - sage.symbolic (3*sqrt(2), 3*sqrt(2)) TESTS: @@ -6674,9 +6701,9 @@ def _echelonized_basis(self, ambient, basis): sage: W = V.submodule_with_basis([[1,1,0],[0,2,1]]) sage: W._echelonized_basis(V,W.basis()) [(1, 0, -1/2), (0, 1, 1/2)] - sage: V = SR^3 - sage: W = V.submodule_with_basis([[1,0,1]]) - sage: W._echelonized_basis(V,W.basis()) + sage: V = SR^3 # optional - sage.symbolic + sage: W = V.submodule_with_basis([[1,0,1]]) # optional - sage.symbolic + sage: W._echelonized_basis(V, W.basis()) # optional - sage.symbolic [(1, 0, 1)] """ # Return the first rank rows (i.e., the nonzero rows). @@ -6704,7 +6731,7 @@ def _denominator(self, B): EXAMPLES:: sage: V = QQ^3 - sage: L = V.span([[1,1/2,1/3], [-1/5,2/3,3]],ZZ) + sage: L = V.span([[1,1/2,1/3], [-1/5,2/3,3]], ZZ) sage: L Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: @@ -6924,15 +6951,15 @@ def relations(self): EXAMPLES:: - sage: V = GF(2)^2 - sage: W = V.subspace([[1, 0]]) - sage: W.relations() == V.zero_submodule() + sage: V = GF(2)^2 # optional - sage.rings.finite_rings + sage: W = V.subspace([[1, 0]]) # optional - sage.rings.finite_rings + sage: W.relations() == V.zero_submodule() # optional - sage.rings.finite_rings True - sage: Q = V / W - sage: Q.relations() == W + sage: Q = V / W # optional - sage.rings.finite_rings + sage: Q.relations() == W # optional - sage.rings.finite_rings True - sage: Q.zero_submodule().relations() == W + sage: Q.zero_submodule().relations() == W # optional - sage.rings.finite_rings True """ return self.__ambient_module.relations() @@ -7333,7 +7360,7 @@ def change_ring(self, R): sage: V = QQ^3 sage: W = V.subspace([[2, 1/2, 1]]) - sage: W.change_ring(GF(7)) + sage: W.change_ring(GF(7)) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 2 4] @@ -7349,7 +7376,8 @@ def change_ring(self, R): [0 1] sage: N = M.change_ring(QQ['x']) sage: N - Free module of degree 2 and rank 2 over Univariate Polynomial Ring in x over Rational Field + Free module of degree 2 and rank 2 + over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: [1/2 0] [ 0 1/2] @@ -7361,7 +7389,8 @@ def change_ring(self, R): sage: M.change_ring(ZZ['x']) Traceback (most recent call last): ... - TypeError: the new ring Univariate Polynomial Ring in x over Integer Ring should be a principal ideal domain + TypeError: the new ring Univariate Polynomial Ring in x over Integer Ring + should be a principal ideal domain """ if self.base_ring() is R: return self @@ -8129,8 +8158,8 @@ def element_class(R, is_sparse): EXAMPLES:: - sage: FF = FiniteField(2) - sage: P = PolynomialRing(FF,'x') + sage: FF = FiniteField(2) # optional - sage.rings.finite_rings + sage: P = PolynomialRing(FF,'x') # optional - sage.rings.finite_rings sage: sage.modules.free_module.element_class(QQ, is_sparse=True) sage: sage.modules.free_module.element_class(QQ, is_sparse=False) @@ -8139,15 +8168,15 @@ def element_class(R, is_sparse): sage: sage.modules.free_module.element_class(ZZ, is_sparse=False) - sage: sage.modules.free_module.element_class(FF, is_sparse=True) + sage: sage.modules.free_module.element_class(FF, is_sparse=True) # optional - sage.rings.finite_rings - sage: sage.modules.free_module.element_class(FF, is_sparse=False) + sage: sage.modules.free_module.element_class(FF, is_sparse=False) # optional - sage.rings.finite_rings - sage: sage.modules.free_module.element_class(GF(7), is_sparse=False) + sage: sage.modules.free_module.element_class(GF(7), is_sparse=False) # optional - sage.rings.finite_rings - sage: sage.modules.free_module.element_class(P, is_sparse=True) + sage: sage.modules.free_module.element_class(P, is_sparse=True) # optional - sage.rings.finite_rings - sage: sage.modules.free_module.element_class(P, is_sparse=False) + sage: sage.modules.free_module.element_class(P, is_sparse=False) # optional - sage.rings.finite_rings """ import sage.rings.integer_ring @@ -8158,14 +8187,21 @@ def element_class(R, is_sparse): from .vector_rational_dense import Vector_rational_dense return Vector_rational_dense elif isinstance(R, sage.rings.abc.IntegerModRing) and not is_sparse: - from .vector_mod2_dense import Vector_mod2_dense if R.order() == 2: - return Vector_mod2_dense - from .vector_modn_dense import Vector_modn_dense, MAX_MODULUS - if R.order() < MAX_MODULUS: - return Vector_modn_dense + try: + from .vector_mod2_dense import Vector_mod2_dense + except ImportError: + pass + else: + return Vector_mod2_dense + try: + from .vector_modn_dense import Vector_modn_dense, MAX_MODULUS + except ImportError: + pass else: - return free_module_element.FreeModuleElement_generic_dense + if R.order() < MAX_MODULUS: + return Vector_modn_dense + return free_module_element.FreeModuleElement_generic_dense elif isinstance(R, sage.rings.abc.RealDoubleField) and not is_sparse: try: from sage.modules.vector_real_double_dense import Vector_real_double_dense @@ -8228,7 +8264,7 @@ def __init__(self, obj): EXAMPLES:: sage: R. = QQ[] - sage: V = span(R,[[x,1+x],[x^2,2+x]]) + sage: V = span(R, [[x, 1 + x], [x^2, 2 + x]]) sage: W = R^2 sage: from sage.modules.free_module import EchelonMatrixKey sage: V = EchelonMatrixKey(V) diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index 65cd226a941..a790ab4f428 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -43,7 +43,7 @@ field. :: sage: K = ZZ^5 - sage: M = GF(7)^5 + sage: M = GF(7)^5 # optional - sage.rings.finite_rings Arithmetic between the `\QQ` and `\ZZ` modules is defined, and the result is always @@ -60,10 +60,12 @@ to `\QQ`. Since there is no canonical coercion map to the finite field from `\QQ` the following arithmetic is not defined:: - sage: V.0 + M.0 + sage: V.0 + M.0 # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Vector space of dimension 5 over Rational Field' and 'Vector space of dimension 5 over Finite Field of size 7' + TypeError: unsupported operand parent(s) for +: + 'Vector space of dimension 5 over Rational Field' and + 'Vector space of dimension 5 over Finite Field of size 7' However, there is a map from `\ZZ` to the finite field, so the following is defined, and the result is in the finite @@ -71,16 +73,16 @@ field. :: - sage: w = K.0 + M.0; w + sage: w = K.0 + M.0; w # optional - sage.rings.finite_rings (2, 0, 0, 0, 0) - sage: parent(w) + sage: parent(w) # optional - sage.rings.finite_rings Vector space of dimension 5 over Finite Field of size 7 - sage: parent(M.0 + K.0) + sage: parent(M.0 + K.0) # optional - sage.rings.finite_rings Vector space of dimension 5 over Finite Field of size 7 Matrix vector multiply:: - sage: MS = MatrixSpace(QQ,3) + sage: MS = MatrixSpace(QQ, 3) sage: A = MS([0,1,0,1,0,0,0,0,1]) sage: V = QQ^3 sage: v = V([1,2,3]) @@ -214,20 +216,20 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): All entries must *canonically* coerce to some common ring:: - sage: v = vector([17, GF(11)(5), 19/3]); v + sage: v = vector([17, GF(11)(5), 19/3]); v # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unable to find a common ring for all elements :: - sage: v = vector([17, GF(11)(5), 19]); v + sage: v = vector([17, GF(11)(5), 19]); v # optional - sage.rings.finite_rings (6, 5, 8) - sage: v.parent() + sage: v.parent() # optional - sage.rings.finite_rings Vector space of dimension 3 over Finite Field of size 11 - sage: v = vector([17, GF(11)(5), 19], QQ); v + sage: v = vector([17, GF(11)(5), 19], QQ); v # optional - sage.rings.finite_rings (17, 5, 19) - sage: v.parent() + sage: v.parent() # optional - sage.rings.finite_rings Vector space of dimension 3 over Rational Field sage: v = vector((1,2,3), QQ); v (1, 2, 3) @@ -250,7 +252,7 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): We make a vector mod 3 out of a vector over `\ZZ`. :: - sage: vector(vector([1,2,3]), GF(3)) + sage: vector(vector([1,2,3]), GF(3)) # optional - sage.rings.finite_rings (1, 2, 0) The degree of a vector may be specified:: @@ -270,9 +272,9 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): you must specify the degree since it is not implied. Here we use a finite field as the base ring. :: - sage: w = vector(FiniteField(7), 4); w + sage: w = vector(FiniteField(7), 4); w # optional - sage.rings.finite_rings (0, 0, 0, 0) - sage: w.parent() + sage: w.parent() # optional - sage.rings.finite_rings Vector space of dimension 4 over Finite Field of size 7 The fastest method to construct a zero vector is to call the @@ -346,27 +348,27 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): must be contiguous, so column-wise slices of numpy matrices will raise an exception. :: - sage: import numpy - sage: x = numpy.random.randn(10) - sage: y = vector(x) - sage: parent(y) + sage: import numpy # optional - numpy + sage: x = numpy.random.randn(10) # optional - numpy + sage: y = vector(x) # optional - numpy + sage: parent(y) # optional - numpy Vector space of dimension 10 over Real Double Field - sage: parent(vector(RDF, x)) + sage: parent(vector(RDF, x)) # optional - numpy Vector space of dimension 10 over Real Double Field - sage: parent(vector(CDF, x)) + sage: parent(vector(CDF, x)) # optional - numpy Vector space of dimension 10 over Complex Double Field - sage: parent(vector(RR, x)) + sage: parent(vector(RR, x)) # optional - numpy Vector space of dimension 10 over Real Field with 53 bits of precision - sage: v = numpy.random.randn(10) * complex(0,1) - sage: w = vector(v) - sage: parent(w) + sage: v = numpy.random.randn(10) * complex(0,1) # optional - numpy + sage: w = vector(v) # optional - numpy + sage: parent(w) # optional - numpy Vector space of dimension 10 over Complex Double Field Multi-dimensional arrays are not supported:: - sage: import numpy as np - sage: a = np.array([[1, 2, 3], [4, 5, 6]], np.float64) - sage: vector(a) + sage: import numpy as np # optional - numpy + sage: a = np.array([[1, 2, 3], [4, 5, 6]], np.float64) # optional - numpy + sage: vector(a) # optional - numpy Traceback (most recent call last): ... TypeError: cannot convert 2-dimensional array to a vector @@ -391,21 +393,21 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): If the argument is a vector, it doesn't change the base ring. This fixes :trac:`6643`:: - sage: K. = QuadraticField(3) - sage: u = vector(K, (1/2, sqrt3/2) ) - sage: vector(u).base_ring() + sage: K. = QuadraticField(3) # optional - sage.rings.number_field + sage: u = vector(K, (1/2, sqrt3/2)) # optional - sage.rings.number_field + sage: vector(u).base_ring() # optional - sage.rings.number_field Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878? - sage: v = vector(K, (0, 1) ) - sage: vector(v).base_ring() + sage: v = vector(K, (0, 1)) # optional - sage.rings.number_field + sage: vector(v).base_ring() # optional - sage.rings.number_field Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878? Constructing a vector from a numpy array behaves as expected:: - sage: import numpy - sage: a=numpy.array([1,2,3]) - sage: v=vector(a); v + sage: import numpy # optional - numpy + sage: a = numpy.array([1,2,3]) # optional - numpy + sage: v = vector(a); v # optional - numpy (1, 2, 3) - sage: parent(v) + sage: parent(v) # optional - numpy Ambient free module of rank 3 over the principal ideal domain Integer Ring Complex numbers can be converted naturally to a sequence of length 2. And @@ -451,23 +453,23 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): sage: v = vector(QQ, w, immutable=True) sage: v.is_immutable() True - sage: import numpy as np - sage: w = np.array([1, 2, pi], float) - sage: v = vector(w, immutable=True) - sage: v.is_immutable() + sage: import numpy as np # optional - numpy + sage: w = np.array([1, 2, pi], float) # optional - numpy + sage: v = vector(w, immutable=True) # optional - numpy + sage: v.is_immutable() # optional - numpy True - sage: w = np.array([i, 2, 3], complex) - sage: v = vector(w, immutable=True) - sage: v.is_immutable() + sage: w = np.array([i, 2, 3], complex) # optional - numpy + sage: v = vector(w, immutable=True) # optional - numpy + sage: v.is_immutable() # optional - numpy True TESTS: We check that :trac:`31470` is fixed:: - sage: k. = GF(5^3) - sage: S. = k['x', k.frobenius_endomorphism()] - sage: vector(S, 3) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = k['x', k.frobenius_endomorphism()] # optional - sage.rings.finite_rings + sage: vector(S, 3) # optional - sage.rings.finite_rings ... (0, 0, 0) """ @@ -844,11 +846,11 @@ def random_vector(ring, degree=None, *args, **kwds): Any ring with a ``random_element()`` method may be used. :: - sage: F = FiniteField(23) - sage: hasattr(F, 'random_element') + sage: F = FiniteField(23) # optional - sage.rings.finite_rings + sage: hasattr(F, 'random_element') # optional - sage.rings.finite_rings True - sage: v = random_vector(F, 10) - sage: v.parent() + sage: v = random_vector(F, 10) # optional - sage.rings.finite_rings + sage: v.parent() # optional - sage.rings.finite_rings Vector space of dimension 10 over Finite Field of size 23 The default implementation is a dense representation, equivalent to @@ -870,15 +872,19 @@ def random_vector(ring, degree=None, *args, **kwds): sage: v1 = random_vector(ZZ, 20, distribution="1/n") sage: v2 = random_vector(ZZ, 15, x=-1000, y=1000) sage: v3 = random_vector(QQ, 10) - sage: v4 = random_vector(FiniteField(17), 10) + sage: v4 = random_vector(FiniteField(17), 10) # optional - sage.rings.finite_rings sage: v5 = random_vector(RR, 10) sage: set_random_seed(seed) sage: w1 = vector(ZZ.random_element(distribution="1/n") for _ in range(20)) sage: w2 = vector(ZZ.random_element(x=-1000, y=1000) for _ in range(15)) sage: w3 = vector(QQ.random_element() for _ in range(10)) - sage: w4 = vector(FiniteField(17).random_element() for _ in range(10)) + sage: [v1, v2, v3] == [w1, w2, w3] + True + sage: w4 = vector(FiniteField(17).random_element() for _ in range(10)) # optional - sage.rings.finite_rings + sage: v4 == w4 # optional - sage.rings.finite_rings + True sage: w5 = vector(RR.random_element() for _ in range(10)) - sage: [v1, v2, v3, v4, v5] == [w1, w2, w3, w4, w5] + sage: v5 == w5 True Inputs get checked before constructing the vector. :: @@ -939,20 +945,20 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: sage: v = vector(ZZ, 4, range(4)) - sage: giac(v)+v + sage: giac(v) + v # optional - sage.libs.giac [0,2,4,6] :: sage: v = vector(QQ, 3, [2/3, 0, 5/4]) - sage: giac(v) + sage: giac(v) # optional - sage.libs.giac [2/3,0,5/4] :: sage: P. = ZZ[] sage: v = vector(P, 3, [x^2 + 2, 2*x + 1, -2*x^2 + 4*x]) - sage: giac(v) + sage: giac(v) # optional - sage.libs.giac [sageVARx^2+2,2*sageVARx+1,-2*sageVARx^2+4*sageVARx] """ return self.list() @@ -968,15 +974,15 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: sage: v = vector(range(4)) - sage: v.__pari__() + sage: v.__pari__() # optional - sage.libs.pari [0, 1, 2, 3] - sage: v.__pari__().type() + sage: v.__pari__().type() # optional - sage.libs.pari 't_VEC' A list of vectors:: sage: L = [vector(i^n for i in range(4)) for n in [1,3,5]] - sage: pari(L) + sage: pari(L) # optional - sage.libs.pari [[0, 1, 2, 3], [0, 1, 8, 27], [0, 1, 32, 243]] """ from sage.libs.pari.all import pari @@ -994,16 +1000,16 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: sage: v = vector(range(4)) - sage: v._pari_init_() + sage: v._pari_init_() # optional - sage.libs.pari '[0,1,2,3]' Create the multiplication table of `GF(4)` using GP:: - sage: k. = GF(4, impl="pari_ffelt") - sage: v = gp(vector(list(k))) - sage: v + sage: k. = GF(4, impl="pari_ffelt") # optional - sage.libs.pari + sage: v = gp(vector(list(k))) # optional - sage.libs.pari + sage: v # optional - sage.libs.pari [0, 1, a, a + 1] - sage: v.mattranspose() * v + sage: v.mattranspose() * v # optional - sage.libs.pari [0, 0, 0, 0; 0, 1, a, a + 1; 0, a, a + 1, 1; 0, a + 1, 1, a] """ # Elements in vectors are always Sage Elements, so they should @@ -1019,36 +1025,36 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: F = FreeModule(ZZ, 2, inner_product_matrix=matrix(ZZ, 2, 2, [1, 0, 0, -1])) sage: v = F([1, 2]) - sage: M = magma(v); M # optional - magma + sage: M = magma(v); M # optional - magma (1 2) - sage: M.Type() # optional - magma + sage: M.Type() # optional - magma ModTupRngElt - sage: M.Parent() # optional - magma + sage: M.Parent() # optional - magma Full RSpace of degree 2 over Integer Ring Inner Product Matrix: [ 1 0] [ 0 -1] - sage: M.sage() # optional - magma + sage: M.sage() # optional - magma (1, 2) - sage: M.sage() == v # optional - magma + sage: M.sage() == v # optional - magma True - sage: M.sage().parent() is v.parent() # optional - magma + sage: M.sage().parent() is v.parent() # optional - magma True :: sage: v = vector(QQ, [1, 2, 5/6]) - sage: M = magma(v); M # optional - magma + sage: M = magma(v); M # optional - magma ( 1 2 5/6) - sage: M.Type() # optional - magma + sage: M.Type() # optional - magma ModTupFldElt - sage: M.Parent() # optional - magma + sage: M.Parent() # optional - magma Full Vector space of degree 3 over Rational Field - sage: M.sage() # optional - magma + sage: M.sage() # optional - magma (1, 2, 5/6) - sage: M.sage() == v # optional - magma + sage: M.sage() == v # optional - magma True - sage: M.sage().parent() is v.parent() # optional - magma + sage: M.sage().parent() is v.parent() # optional - magma True """ # Get a reference to Magma version of parent. @@ -1069,48 +1075,48 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: sage: v = vector([1,2,3]) - sage: v.numpy() + sage: v.numpy() # optional - numpy array([1, 2, 3], dtype=object) - sage: v.numpy() * v.numpy() + sage: v.numpy() * v.numpy() # optional - numpy array([1, 4, 9], dtype=object) - sage: vector(QQ, [1, 2, 5/6]).numpy() + sage: vector(QQ, [1, 2, 5/6]).numpy() # optional - numpy array([1, 2, 5/6], dtype=object) By default the ``object`` `dtype `_ is used. Alternatively, the desired dtype can be passed in as a parameter:: sage: v = vector(QQ, [1, 2, 5/6]) - sage: v.numpy() + sage: v.numpy() # optional - numpy array([1, 2, 5/6], dtype=object) - sage: v.numpy(dtype=float) + sage: v.numpy(dtype=float) # optional - numpy array([1. , 2. , 0.83333333]) - sage: v.numpy(dtype=int) + sage: v.numpy(dtype=int) # optional - numpy array([1, 2, 0]) - sage: import numpy - sage: v.numpy(dtype=numpy.uint8) + sage: import numpy # optional - numpy + sage: v.numpy(dtype=numpy.uint8) # optional - numpy array([1, 2, 0], dtype=uint8) Passing a dtype of None will let numpy choose a native type, which can be more efficient but may have unintended consequences:: - sage: v.numpy(dtype=None) + sage: v.numpy(dtype=None) # optional - numpy array([1. , 2. , 0.83333333]) sage: w = vector(ZZ, [0, 1, 2^63 -1]); w (0, 1, 9223372036854775807) - sage: wn = w.numpy(dtype=None); wn + sage: wn = w.numpy(dtype=None); wn # optional - numpy array([ 0, 1, 9223372036854775807]...) - sage: wn.dtype + sage: wn.dtype # optional - numpy dtype('int64') - sage: w.dot_product(w) + sage: w.dot_product(w) # optional - numpy 85070591730234615847396907784232501250 - sage: wn.dot(wn) # overflow + sage: wn.dot(wn) # overflow # optional - numpy 2 Numpy can give rather obscure errors; we wrap these to give a bit of context:: - sage: vector([1, 1/2, QQ['x'].0]).numpy(dtype=float) + sage: vector([1, 1/2, QQ['x'].0]).numpy(dtype=float) # optional - numpy Traceback (most recent call last): ... ValueError: Could not convert vector over Univariate Polynomial Ring in x over Rational Field to numpy array of type <... 'float'>: setting an array element with a sequence. @@ -1128,13 +1134,13 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector([1,2/3,pi]) - sage: v.__hash__() + sage: v = vector([1,2/3,pi]) # optional - sage.symbolic + sage: v.__hash__() # optional - sage.symbolic Traceback (most recent call last): ... TypeError: mutable vectors are unhashable - sage: v.set_immutable() - sage: v.__hash__() # random output + sage: v.set_immutable() # optional - sage.symbolic + sage: v.__hash__() # random output # optional - sage.symbolic """ if not self._is_immutable: raise TypeError("mutable vectors are unhashable") @@ -1149,14 +1155,14 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: v = vector(ZZ, [2, 12, 22]) sage: vector(v) (2, 12, 22) - sage: vector(GF(7), v) + sage: vector(GF(7), v) # optional - sage.rings.finite_rings (2, 5, 1) sage: vector(v, ZZ['x', 'y']) (2, 12, 22) sage: vector(vector((1, 6.8))) (1.00000000000000, 6.80000000000000) - sage: vector(vector(SR, (1, sqrt(2)) ) ) + sage: vector(vector(SR, (1, sqrt(2)) ) ) # optional - sage.symbolic (1, sqrt(2)) """ if R is None: @@ -1169,10 +1175,10 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: sage_input(vector(RR, [pi, e, 0.5]), verify=True) + sage: sage_input(vector(RR, [pi, e, 0.5]), verify=True) # optional - sage.symbolic # Verified vector(RR, [3.1415926535897931, 2.7182818284590451, 0.5]) - sage: sage_input(vector(GF(5), [1, 2, 3, 4, 5]), verify=True) + sage: sage_input(vector(GF(5), [1, 2, 3, 4, 5]), verify=True) # optional - sage.rings.finite_rings # Verified vector(GF(5), [1, 2, 3, 4, 0]) sage: sage_input(vector([0, 0, 0, 1, 0, 0, 0], sparse=True), verify=True) @@ -1323,14 +1329,14 @@ cdef class FreeModuleElement(Vector): # abstract base class :: - sage: v = vector(GF(2), [1,2,3]) - sage: v.n() + sage: v = vector(GF(2), [1,2,3]) # optional - sage.rings.finite_rings + sage: v.n() # optional - sage.rings.finite_rings (1.00000000000000, 0.000000000000000, 1.00000000000000) - sage: _.parent() + sage: _.parent() # optional - sage.rings.finite_rings Vector space of dimension 3 over Real Field with 53 bits of precision - sage: v.n(prec=75) + sage: v.n(prec=75) # optional - sage.rings.finite_rings (1.000000000000000000000, 0.0000000000000000000000, 1.000000000000000000000) - sage: _.parent() + sage: _.parent() # optional - sage.rings.finite_rings Vector space of dimension 3 over Real Field with 75 bits of precision TESTS: @@ -1367,8 +1373,8 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: w.parent() Full MatrixSpace of 1 by 3 dense matrices over Integer Ring - sage: x = vector(FiniteField(13), [2,4,8,16]) - sage: x.row() + sage: x = vector(FiniteField(13), [2,4,8,16]) # optional - sage.rings.finite_rings + sage: x.row() # optional - sage.rings.finite_rings [2 4 8 3] There is more than one way to get one-row matrix from a vector, @@ -1376,10 +1382,10 @@ cdef class FreeModuleElement(Vector): # abstract base class then taking a transpose. Notice that supplying a vector to the matrix constructor demonstrates Sage's preference for rows. :: - sage: x = vector(RDF, [sin(i*pi/20) for i in range(10)]) - sage: x.row() == matrix(x) + sage: x = vector(RDF, [sin(i*pi/20) for i in range(10)]) # optional - sage.symbolic + sage: x.row() == matrix(x) # optional - sage.symbolic True - sage: x.row() == x.column().transpose() + sage: x.row() == x.column().transpose() # optional - sage.symbolic True Sparse or dense implementations are preserved. :: @@ -1436,8 +1442,8 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: w.parent() Full MatrixSpace of 3 by 1 dense matrices over Integer Ring - sage: x = vector(FiniteField(13), [2,4,8,16]) - sage: x.column() + sage: x = vector(FiniteField(13), [2,4,8,16]) # optional - sage.rings.finite_rings + sage: x.column() # optional - sage.rings.finite_rings [2] [4] [8] @@ -1457,7 +1463,7 @@ cdef class FreeModuleElement(Vector): # abstract base class Sparse or dense implementations are preserved. :: sage: d = vector(RR, [1.0, 2.0, 3.0]) - sage: s = vector(CDF, {2:5.0+6.0*I}) + sage: s = vector(CDF, {2: 5.0+6.0*I}) sage: dm = d.column() sage: sm = s.column() sage: all([d.is_dense(), dm.is_dense(), s.is_sparse(), sm.is_sparse()]) @@ -1518,12 +1524,12 @@ cdef class FreeModuleElement(Vector): # abstract base class """ EXAMPLES:: - sage: var('a,b,d,e') + sage: var('a,b,d,e') # optional - sage.symbolic (a, b, d, e) - sage: v = vector([a, b, d, e]) - sage: v.substitute(a=1) + sage: v = vector([a, b, d, e]) # optional - sage.symbolic + sage: v.substitute(a=1) # optional - sage.symbolic (1, b, d, e) - sage: v.subs(a=b, b=d) + sage: v.subs(a=b, b=d) # optional - sage.symbolic (b, d, d, e) """ return self.parent()([ a.subs(in_dict, **kwds) for a in self.list() ]) @@ -1534,7 +1540,7 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector(QQ['x,y'], [1..5]); v.change_ring(GF(3)) + sage: v = vector(QQ['x,y'], [1..5]); v.change_ring(GF(3)) # optional - sage.rings.finite_rings (1, 2, 0, 1, 2) TESTS: @@ -1542,7 +1548,7 @@ cdef class FreeModuleElement(Vector): # abstract base class Check for :trac:`29630`:: sage: v = vector(QQ, 4, {0:1}, sparse=True) - sage: v.change_ring(AA).is_sparse() + sage: v.change_ring(AA).is_sparse() # optional - sage.rings.number_field True """ if self.base_ring() is R: @@ -1611,17 +1617,17 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector([1,2/3,pi]) - sage: v.items() + sage: v = vector([1,2/3,pi]) # optional - sage.symbolic + sage: v.items() # optional - sage.symbolic - sage: list(v.items()) + sage: list(v.items()) # optional - sage.symbolic [(0, 1), (1, 2/3), (2, pi)] TESTS: Using iteritems as an alias:: - sage: list(v.iteritems()) + sage: list(v.iteritems()) # optional - sage.symbolic [(0, 1), (1, 2/3), (2, pi)] """ cdef dict d = self.dict(copy=False) @@ -1636,7 +1642,7 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector([1..5]); abs(v) + sage: v = vector([1..5]); abs(v) # optional - sage.symbolic sqrt(55) sage: v = vector(RDF, [1..5]); abs(v) 7.416198487095663 @@ -1663,14 +1669,14 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: sage: v = vector([1,2,-3]) - sage: v.norm(5) + sage: v.norm(5) # optional - sage.symbolic 276^(1/5) The default is the usual Euclidean norm. :: - sage: v.norm() + sage: v.norm() # optional - sage.symbolic sqrt(14) - sage: v.norm(2) + sage: v.norm(2) # optional - sage.symbolic sqrt(14) The infinity norm is the maximum size (in absolute value) @@ -1686,10 +1692,10 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: v=vector(RDF,[1,2,3]) sage: v.norm(5) 3.077384885394063 - sage: v.norm(pi/2) #abs tol 1e-15 + sage: v.norm(pi/2) #abs tol 1e-15 # optional - sage.symbolic 4.216595864704748 - sage: _=var('a b c d p'); v=vector([a, b, c, d]) - sage: v.norm(p) + sage: _=var('a b c d p'); v=vector([a, b, c, d]) # optional - sage.symbolic + sage: v.norm(p) # optional - sage.symbolic (abs(a)^p + abs(b)^p + abs(c)^p + abs(d)^p)^(1/p) Notice that the result may be a symbolic expression, owing to @@ -1703,13 +1709,13 @@ cdef class FreeModuleElement(Vector): # abstract base class Rational Field sage: v = vector(QQ, [3, 5]) - sage: nrm = v.norm(); nrm + sage: nrm = v.norm(); nrm # optional - sage.symbolic sqrt(34) - sage: nrm.parent() + sage: nrm.parent() # optional - sage.symbolic Symbolic Ring - sage: numeric = N(nrm); numeric + sage: numeric = N(nrm); numeric # optional - sage.symbolic 5.83095189484... - sage: numeric.parent() + sage: numeric.parent() # optional - sage.symbolic Real Field with 53 bits of precision TESTS: @@ -1726,7 +1732,7 @@ cdef class FreeModuleElement(Vector): # abstract base class Norm works with Python integers (see :trac:`13502`). :: sage: v = vector(QQ, [1,2]) - sage: v.norm(int(2)) + sage: v.norm(int(2)) # optional - sage.symbolic sqrt(5) """ abs_self = [abs(x) for x in self] @@ -1742,17 +1748,17 @@ cdef class FreeModuleElement(Vector): # abstract base class """ EXAMPLES:: - sage: v = vector(SR, [0,0,0,0]) - sage: v == 0 + sage: v = vector(SR, [0,0,0,0]) # optional - sage.symbolic + sage: v == 0 # optional - sage.symbolic True - sage: v == 1 + sage: v == 1 # optional - sage.symbolic False - sage: v == v + sage: v == v # optional - sage.symbolic True - sage: w = vector(SR, [-1,x,pi,0]) - sage: bool(w < v) + sage: w = vector(SR, [-1,x,pi,0]) # optional - sage.symbolic + sage: bool(w < v) # optional - sage.symbolic True - sage: bool(w > v) + sage: bool(w > v) # optional - sage.symbolic False TESTS:: @@ -1767,14 +1773,14 @@ cdef class FreeModuleElement(Vector): # abstract base class Verify that :trac:`33697` is fixed:: - sage: v = vector(SR, [x]) - sage: w = vector(SR, [1]) - sage: v == w + sage: v = vector(SR, [x]) # optional - sage.symbolic + sage: w = vector(SR, [1]) # optional - sage.symbolic + sage: v == w # optional - sage.symbolic False - sage: assume(x > 0) - sage: v == w + sage: assume(x > 0) # optional - sage.symbolic + sage: v == w # optional - sage.symbolic False - sage: forget() + sage: forget() # optional - sage.symbolic """ cdef Py_ssize_t i for i in range(left._degree): @@ -1831,7 +1837,7 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: vector(SR, [1/2,2/5,0]).get(0) + sage: vector(SR, [1/2,2/5,0]).get(0) # optional - sage.symbolic 1/2 """ return self.get_unsafe(i) @@ -1894,9 +1900,9 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector(SR, [1/2,2/5,0]); v + sage: v = vector(SR, [1/2,2/5,0]); v # optional - sage.symbolic (1/2, 2/5, 0) - sage: v.set(2, pi); v + sage: v.set(2, pi); v # optional - sage.symbolic (1/2, 2/5, pi) """ assert value.parent() is self.coordinate_ring() @@ -1909,7 +1915,7 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: vector([1,2/3,pi]).__invert__() + sage: vector([1,2/3,pi]).__invert__() # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError @@ -1991,8 +1997,8 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector([1,2/3,pi]) - sage: v.list_from_positions([0,0,0,2,1]) + sage: v = vector([1, 2/3, pi]) # optional - sage.symbolic + sage: v.list_from_positions([0,0,0,2,1]) # optional - sage.symbolic [1, 1, 1, pi, 2/3] """ cdef Py_ssize_t i @@ -2106,10 +2112,10 @@ cdef class FreeModuleElement(Vector): # abstract base class :: - sage: x = var('x') - sage: v = vector([x/(2*x)+sqrt(2)+var('theta')^3,x/(2*x)]); v + sage: x = var('x') # optional - sage.symbolic + sage: v = vector([x/(2*x)+sqrt(2)+var('theta')^3,x/(2*x)]); v # optional - sage.symbolic (theta^3 + sqrt(2) + 1/2, 1/2) - sage: v._repr_() + sage: v._repr_() # optional - sage.symbolic '(theta^3 + sqrt(2) + 1/2, 1/2)' """ cdef Py_ssize_t d = self._degree @@ -2191,9 +2197,9 @@ cdef class FreeModuleElement(Vector): # abstract base class The following was fixed in :trac:`8800`:: - sage: M = GF(5)^3 - sage: v = M((4,0,2)) - sage: v.denominator() + sage: M = GF(5)^3 # optional - sage.rings.finite_rings + sage: v = M((4,0,2)) # optional - sage.rings.finite_rings + sage: v.denominator() # optional - sage.rings.finite_rings 1 """ # It may be that the coordinates do not have a denominator @@ -2283,84 +2289,84 @@ cdef class FreeModuleElement(Vector): # abstract base class The following both plot the given vector:: sage: v = vector(RDF, (1,2)) - sage: A = plot(v) - sage: B = v.plot() - sage: A+B # should just show one vector + sage: A = plot(v) # optional - sage.plot + sage: B = v.plot() # optional - sage.plot + sage: A+B # should just show one vector # optional - sage.plot Graphics object consisting of 2 graphics primitives Examples of the plot types:: - sage: A = plot(v, plot_type='arrow') - sage: B = plot(v, plot_type='point', color='green', size=20) - sage: C = plot(v, plot_type='step') # calls v.plot_step() - sage: A+B+C + sage: A = plot(v, plot_type='arrow') # optional - sage.plot + sage: B = plot(v, plot_type='point', color='green', size=20) # optional - sage.plot + sage: C = plot(v, plot_type='step') # calls v.plot_step() # optional - sage.plot + sage: A+B+C # optional - sage.plot Graphics object consisting of 3 graphics primitives You can use the optional arguments for :meth:`plot_step`:: - sage: eps = 0.1 - sage: plot(v, plot_type='step', eps=eps, xmax=5, hue=0) + sage: eps = 0.1 # optional - sage.plot + sage: plot(v, plot_type='step', eps=eps, xmax=5, hue=0) # optional - sage.plot Graphics object consisting of 1 graphics primitive Three-dimensional examples:: sage: v = vector(RDF, (1,2,1)) - sage: plot(v) # defaults to an arrow plot + sage: plot(v) # defaults to an arrow plot # optional - sage.plot Graphics3d Object :: - sage: plot(v, plot_type='arrow') + sage: plot(v, plot_type='arrow') # optional - sage.plot Graphics3d Object :: - sage: from sage.plot.plot3d.shapes2 import frame3d - sage: plot(v, plot_type='point')+frame3d((0,0,0), v.list()) + sage: from sage.plot.plot3d.shapes2 import frame3d # optional - sage.plot + sage: plot(v, plot_type='point')+frame3d((0,0,0), v.list()) # optional - sage.plot Graphics3d Object :: - sage: plot(v, plot_type='step') # calls v.plot_step() + sage: plot(v, plot_type='step') # calls v.plot_step() # optional - sage.plot Graphics object consisting of 1 graphics primitive :: - sage: plot(v, plot_type='step', eps=eps, xmax=5, hue=0) + sage: plot(v, plot_type='step', eps=eps, xmax=5, hue=0) # optional - sage.plot Graphics object consisting of 1 graphics primitive With greater than three coordinates, it defaults to a step plot:: sage: v = vector(RDF, (1,2,3,4)) - sage: plot(v) + sage: plot(v) # optional - sage.plot Graphics object consisting of 1 graphics primitive One dimensional vectors are plotted along the horizontal axis of the coordinate plane:: - sage: plot(vector([1])) + sage: plot(vector([1])) # optional - sage.plot Graphics object consisting of 1 graphics primitive An optional start argument may also be specified by a tuple, list, or vector:: sage: u = vector([1,2]); v = vector([2,5]) - sage: plot(u, start=v) + sage: plot(u, start=v) # optional - sage.plot Graphics object consisting of 1 graphics primitive TESTS:: - sage: u = vector([1,1]); v = vector([2,2,2]); z=(3,3,3) - sage: plot(u) #test when start=None + sage: u = vector([1,1]); v = vector([2,2,2]); z=(3,3,3) # optional - sage.plot + sage: plot(u) #test when start=None # optional - sage.plot Graphics object consisting of 1 graphics primitive :: - sage: plot(u, start=v) #test when coordinate dimension mismatch exists + sage: plot(u, start=v) #test when coordinate dimension mismatch exists # optional - sage.plot Traceback (most recent call last): ... ValueError: vector coordinates are not of the same dimension - sage: P = plot(v, start=z) #test when start coordinates are passed as a tuple - sage: P = plot(v, start=list(z)) #test when start coordinates are passed as a list + sage: P = plot(v, start=z) # test when start coordinates are passed as a tuple # optional - sage.plot + sage: P = plot(v, start=list(z)) # test when start coordinates are passed as a list # optional - sage.plot """ # Give sensible defaults based on the vector length if plot_type is None: @@ -2431,9 +2437,9 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: eps=0.1 - sage: v = vector(RDF, [sin(n*eps) for n in range(100)]) - sage: v.plot_step(eps=eps, xmax=5, hue=0) + sage: eps = 0.1 + sage: v = vector(RDF, [sin(n*eps) for n in range(100)]) # optional - sage.plot + sage: v.plot_step(eps=eps, xmax=5, hue=0) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ import math @@ -2545,21 +2551,21 @@ cdef class FreeModuleElement(Vector): # abstract base class arguments is reversed.:: sage: v = vector(ZZ, [1,2,3]) - sage: w = vector(FiniteField(3), [0,1,2]) - sage: ip = w.dot_product(v); ip + sage: w = vector(FiniteField(3), [0,1,2]) # optional - sage.rings.finite_rings + sage: ip = w.dot_product(v); ip # optional - sage.rings.finite_rings 2 - sage: ip.parent() + sage: ip.parent() # optional - sage.rings.finite_rings Finite Field of size 3 - sage: ip = v.dot_product(w); ip + sage: ip = v.dot_product(w); ip # optional - sage.rings.finite_rings 2 - sage: ip.parent() + sage: ip.parent() # optional - sage.rings.finite_rings Finite Field of size 3 The dot product of a vector with itself is the 2-norm, squared. :: sage: v = vector(QQ, [3, 4, 7]) - sage: v.dot_product(v) - v.norm()^2 + sage: v.dot_product(v) - v.norm()^2 # optional - sage.symbolic 0 TESTS: @@ -2755,26 +2761,26 @@ cdef class FreeModuleElement(Vector): # abstract base class TESTS:: - sage: F = GF(previous_prime(2^32)) - sage: v = random_vector(F, 3) - sage: w = random_vector(F, 3) - sage: vh = v.cross_product_matrix() - sage: vh*w == v.cross_product(w) + sage: F = GF(previous_prime(2^32)) # optional - sage.rings.finite_rings + sage: v = random_vector(F, 3) # optional - sage.rings.finite_rings + sage: w = random_vector(F, 3) # optional - sage.rings.finite_rings + sage: vh = v.cross_product_matrix() # optional - sage.rings.finite_rings + sage: vh*w == v.cross_product(w) # optional - sage.rings.finite_rings True - sage: w*vh == w.cross_product(v) + sage: w*vh == w.cross_product(v) # optional - sage.rings.finite_rings True - sage: vh.is_alternating() + sage: vh.is_alternating() # optional - sage.rings.finite_rings True - sage: v = random_vector(F, 7) - sage: w = random_vector(F, 7) - sage: vh = v.cross_product_matrix() - sage: vh*w == v.cross_product(w) + sage: v = random_vector(F, 7) # optional - sage.rings.finite_rings + sage: w = random_vector(F, 7) # optional - sage.rings.finite_rings + sage: vh = v.cross_product_matrix() # optional - sage.rings.finite_rings + sage: vh*w == v.cross_product(w) # optional - sage.rings.finite_rings True - sage: w*vh == w.cross_product(v) + sage: w*vh == w.cross_product(v) # optional - sage.rings.finite_rings True - sage: vh.is_alternating() + sage: vh.is_alternating() # optional - sage.rings.finite_rings True - sage: random_vector(F, 5).cross_product_matrix() + sage: random_vector(F, 5).cross_product_matrix() # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: Cross product only defined for vectors of length three or seven, not 5 @@ -2829,11 +2835,11 @@ cdef class FreeModuleElement(Vector): # abstract base class :: - sage: W = VectorSpace(GF(3),3) - sage: w = W([0,1,2]) - sage: w.pairwise_product(v) + sage: W = VectorSpace(GF(3), 3) # optional - sage.rings.finite_rings + sage: w = W([0,1,2]) # optional - sage.rings.finite_rings + sage: w.pairwise_product(v) # optional - sage.rings.finite_rings (0, 2, 0) - sage: w.pairwise_product(v).parent() + sage: w.pairwise_product(v).parent() # optional - sage.rings.finite_rings Vector space of dimension 3 over Finite Field of size 3 Implicit coercion is well defined (regardless of order), so we @@ -2841,13 +2847,11 @@ cdef class FreeModuleElement(Vector): # abstract base class :: - sage: v.pairwise_product(w).parent() + sage: v.pairwise_product(w).parent() # optional - sage.rings.finite_rings Vector space of dimension 3 over Finite Field of size 3 TESTS:: - sage: x, y = var('x, y') - :: sage: parent(vector(ZZ,[1,2]).pairwise_product(vector(ZZ,[1,2]))) @@ -2927,12 +2931,12 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: R. = QQ[] sage: vector([x, y, 3])._variables() [x, y, z] - sage: vector(SR, [x, y, 3])._variables() + sage: vector(SR, [x, y, 3])._variables() # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Unable to determine ordered variable names for Symbolic Ring - sage: v(x, y, z) = (-y, x, 0) - sage: v._variables() + sage: v(x, y, z) = (-y, x, 0) # optional - sage.symbolic + sage: v._variables() # optional - sage.symbolic [(x, y, z) |--> x, (x, y, z) |--> y, (x, y, z) |--> z] """ R = self._parent.base_ring() @@ -2965,11 +2969,11 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: vector([x*y, y*z, z*x]).div([x, y, w]) y + z - sage: vector(SR, [x*y, y*z, z*x]).div() + sage: vector(SR, [x*y, y*z, z*x]).div() # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Unable to determine ordered variable names for Symbolic Ring - sage: vector(SR, [x*y, y*z, z*x]).div([x, y, z]) + sage: vector(SR, [x*y, y*z, z*x]).div([x, y, z]) # optional - sage.symbolic x + y + z .. SEEALSO:: @@ -3006,18 +3010,18 @@ cdef class FreeModuleElement(Vector): # abstract base class For rings where the variable order is not well defined, it must be defined explicitly:: - sage: v = vector(SR, [-y, x, 0]) - sage: v.curl() + sage: v = vector(SR, [-y, x, 0]) # optional - sage.symbolic + sage: v.curl() # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Unable to determine ordered variable names for Symbolic Ring - sage: v.curl([x, y, z]) + sage: v.curl([x, y, z]) # optional - sage.symbolic (0, 0, 2) Note that callable vectors have well defined variable orderings:: - sage: v(x, y, z) = (-y, x, 0) - sage: v.curl() + sage: v(x, y, z) = (-y, x, 0) # optional - sage.symbolic + sage: v.curl() # optional - sage.symbolic (x, y, z) |--> (0, 0, 2) In two-dimensions, this returns a scalar value:: @@ -3102,14 +3106,14 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: sage: v = vector(QQ, [4, 1, 3, 2]) - sage: v.normalized() + sage: v.normalized() # optional - sage.symbolic (2/15*sqrt(30), 1/30*sqrt(30), 1/10*sqrt(30), 1/15*sqrt(30)) sage: sum(v.normalized(1)) 1 Note that normalizing the vector may change the base ring:: - sage: v.base_ring() == v.normalized().base_ring() + sage: v.base_ring() == v.normalized().base_ring() # optional - sage.symbolic False sage: u = vector(RDF, [-3, 4, 6, 9]) sage: u.base_ring() == u.normalized().base_ring() @@ -3147,11 +3151,11 @@ cdef class FreeModuleElement(Vector): # abstract base class such as the cyclotomic fields. This example uses such a field containing a primitive 7-th root of unity named ``a``. :: - sage: F. = CyclotomicField(7) - sage: v = vector(F, [a^i for i in range(7)]) - sage: v + sage: F. = CyclotomicField(7) # optional - sage.rings.number_field + sage: v = vector(F, [a^i for i in range(7)]) # optional - sage.rings.number_field + sage: v # optional - sage.rings.number_field (1, a, a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1) - sage: v.conjugate() + sage: v.conjugate() # optional - sage.rings.number_field (1, -a^5 - a^4 - a^3 - a^2 - a - 1, a^5, a^4, a^3, a^2, a) Sparse vectors are returned as such. :: @@ -3402,9 +3406,9 @@ cdef class FreeModuleElement(Vector): # abstract base class But some inputs are not compatible, even if vectors. :: - sage: w = vector(GF(5), [1,2]) - sage: v = vector(GF(7), [1,2,3,4]) - sage: z = w.outer_product(v) + sage: w = vector(GF(5), [1,2]) # optional - sage.rings.finite_rings + sage: v = vector(GF(7), [1,2,3,4]) # optional - sage.rings.finite_rings + sage: z = w.outer_product(v) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 2 by 1 dense matrices over Finite Field of size 5' and 'Full MatrixSpace of 1 by 4 dense matrices over Finite Field of size 7' @@ -3579,7 +3583,7 @@ cdef class FreeModuleElement(Vector): # abstract base class :: sage: R. = QQ[] - sage: macaulay2(vector(R, [1, x+y])) # optional - macaulay2 + sage: macaulay2(vector(R, [1, x + y])) # optional - macaulay2 | 1 | | x+y | @@ -3628,16 +3632,16 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: v = vector([1, 2, 3]); v (1, 2, 3) - sage: sv = v._sympy_(); sv + sage: sv = v._sympy_(); sv # optional - sympy Matrix([ [1], [2], [3]]) - sage: type(sv) + sage: type(sv) # optional - sympy sage: w = vector({1: 1, 5: -1}, sparse=True) - sage: sw = w._sympy_(); sw + sage: sw = w._sympy_(); sw # optional - sympy Matrix([ [ 0], [ 1], @@ -3645,26 +3649,26 @@ cdef class FreeModuleElement(Vector): # abstract base class [ 0], [ 0], [-1]]) - sage: type(sw) + sage: type(sw) # optional - sympy If ``self`` was immutable, then converting the result to Sage gives back ``self``:: sage: immv = vector([1, 2, 3], immutable=True) - sage: immv._sympy_()._sage_() is immv + sage: immv._sympy_()._sage_() is immv # optional - sympy True If ``self`` was mutable, then converting back to Sage creates a new matrix (column vector):: - sage: sv._sage_() + sage: sv._sage_() # optional - sympy [1] [2] [3] - sage: sv._sage_() is v + sage: sv._sage_() is v # optional - sympy False - sage: sv._sage_() == v + sage: sv._sage_() == v # optional - sympy False """ from sage.interfaces.sympy import sympy_init @@ -3817,28 +3821,28 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: m = vector([1,x,sin(x+1)]) - sage: m.apply_map(lambda x: x^2) + sage: m = vector([1,x,sin(x+1)]) # optional - sage.symbolic + sage: m.apply_map(lambda x: x^2) # optional - sage.symbolic (1, x^2, sin(x + 1)^2) - sage: m.apply_map(sin) + sage: m.apply_map(sin) # optional - sage.symbolic (sin(1), sin(x), sin(sin(x + 1))) :: sage: m = vector(ZZ, 9, range(9)) - sage: k. = GF(9) - sage: m.apply_map(k) + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: m.apply_map(k) # optional - sage.rings.finite_rings (0, 1, 2, 0, 1, 2, 0, 1, 2) In this example, we explicitly specify the codomain. :: - sage: s = GF(3) - sage: f = lambda x: s(x) - sage: n = m.apply_map(f, k); n + sage: s = GF(3) # optional - sage.rings.finite_rings + sage: f = lambda x: s(x) # optional - sage.rings.finite_rings + sage: n = m.apply_map(f, k); n # optional - sage.rings.finite_rings (0, 1, 2, 0, 1, 2, 0, 1, 2) - sage: n.parent() + sage: n.parent() # optional - sage.rings.finite_rings Vector space of dimension 9 over Finite Field in a of size 3^2 If your map sends 0 to a non-zero value, then your resulting @@ -3873,7 +3877,7 @@ cdef class FreeModuleElement(Vector): # abstract base class TESTS:: - sage: m = vector(SR,[]) + sage: m = vector(SR,[]) # optional - sage.symbolic sage: m.apply_map(lambda x: x*x) == m True @@ -3894,10 +3898,10 @@ cdef class FreeModuleElement(Vector): # abstract base class Check that the bug in :trac:`14558` has been fixed:: - sage: F. = GF(9) - sage: v = vector([a, 0,0,0], sparse=True) - sage: f = F.hom([a**3]) - sage: v.apply_map(f) + sage: F. = GF(9) # optional - sage.rings.finite_rings + sage: v = vector([a, 0, 0, 0], sparse=True) # optional - sage.rings.finite_rings + sage: f = F.hom([a**3]) # optional - sage.rings.finite_rings + sage: v.apply_map(f) # optional - sage.rings.finite_rings (2*a + 1, 0, 0, 0) """ if sparse is None: @@ -3951,31 +3955,31 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector([1,x,x^2]) - sage: v._derivative(x) + sage: v = vector([1,x,x^2]) # optional - sage.symbolic + sage: v._derivative(x) # optional - sage.symbolic (0, 1, 2*x) - sage: type(v._derivative(x)) == type(v) + sage: type(v._derivative(x)) == type(v) # optional - sage.symbolic True - sage: v = vector([1,x,x^2], sparse=True) - sage: v._derivative(x) + sage: v = vector([1,x,x^2], sparse=True) # optional - sage.symbolic + sage: v._derivative(x) # optional - sage.symbolic (0, 1, 2*x) - sage: type(v._derivative(x)) == type(v) + sage: type(v._derivative(x)) == type(v) # optional - sage.symbolic True If no variables are specified and the vector contains callable symbolic expressions, then calculate the matrix derivative (i.e., the Jacobian matrix):: - sage: T(r,theta)=[r*cos(theta),r*sin(theta)] - sage: T + sage: T(r,theta) = [r*cos(theta), r*sin(theta)] # optional - sage.symbolic + sage: T # optional - sage.symbolic (r, theta) |--> (r*cos(theta), r*sin(theta)) - sage: T.diff() # matrix derivative + sage: T.diff() # matrix derivative # optional - sage.symbolic [ (r, theta) |--> cos(theta) (r, theta) |--> -r*sin(theta)] [ (r, theta) |--> sin(theta) (r, theta) |--> r*cos(theta)] - sage: diff(T) # matrix derivative again + sage: diff(T) # matrix derivative again # optional - sage.symbolic [ (r, theta) |--> cos(theta) (r, theta) |--> -r*sin(theta)] [ (r, theta) |--> sin(theta) (r, theta) |--> r*cos(theta)] - sage: T.diff().det() # Jacobian + sage: T.diff().det() # Jacobian # optional - sage.symbolic (r, theta) |--> r*cos(theta)^2 + r*sin(theta)^2 """ if var is None: @@ -3999,17 +4003,17 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: v = vector([1,x,x^2]) - sage: v.derivative(x) + sage: v = vector([1,x,x^2]) # optional - sage.symbolic + sage: v.derivative(x) # optional - sage.symbolic (0, 1, 2*x) - sage: type(v.derivative(x)) == type(v) + sage: type(v.derivative(x)) == type(v) # optional - sage.symbolic True - sage: v = vector([1,x,x^2], sparse=True) - sage: v.derivative(x) + sage: v = vector([1,x,x^2], sparse=True) # optional - sage.symbolic + sage: v.derivative(x) # optional - sage.symbolic (0, 1, 2*x) - sage: type(v.derivative(x)) == type(v) + sage: type(v.derivative(x)) == type(v) # optional - sage.symbolic True - sage: v.derivative(x,x) + sage: v.derivative(x,x) # optional - sage.symbolic (0, 0, 2) """ from sage.misc.derivative import multi_derivative @@ -4025,13 +4029,13 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: t=var('t') - sage: r=vector([t,t^2,sin(t)]) - sage: r.integral(t) + sage: t = var('t') # optional - sage.symbolic + sage: r = vector([t,t^2,sin(t)]) # optional - sage.symbolic + sage: r.integral(t) # optional - sage.symbolic (1/2*t^2, 1/3*t^3, -cos(t)) - sage: integrate(r,t) + sage: integrate(r, t) # optional - sage.symbolic (1/2*t^2, 1/3*t^3, -cos(t)) - sage: r.integrate(t,0,1) + sage: r.integrate(t, 0, 1) # optional - sage.symbolic (1/2, 1/3, -cos(1) + 1) """ @@ -4051,19 +4055,23 @@ cdef class FreeModuleElement(Vector): # abstract base class EXAMPLES:: - sage: t=var('t') - sage: r=vector([t,t^2,sin(t)]) - sage: vec,answers=r.nintegral(t,0,1) - sage: vec + sage: t = var('t') # optional - sage.symbolic + sage: r = vector([t,t^2,sin(t)]) # optional - sage.symbolic + sage: vec, answers = r.nintegral(t,0,1) # optional - sage.symbolic + sage: vec # optional - sage.symbolic (0.5, 0.3333333333333334, 0.4596976941318602) - sage: type(vec) + sage: type(vec) # optional - sage.symbolic - sage: answers - [(0.5, 5.55111512312578...e-15, 21, 0), (0.3333333333333..., 3.70074341541719...e-15, 21, 0), (0.45969769413186..., 5.10366964392284...e-15, 21, 0)] + sage: answers # optional - sage.symbolic + [(0.5, 5.55111512312578...e-15, 21, 0), + (0.3333333333333..., 3.70074341541719...e-15, 21, 0), + (0.45969769413186..., 5.10366964392284...e-15, 21, 0)] - sage: r=vector([t,0,1], sparse=True) - sage: r.nintegral(t,0,1) - ((0.5, 0.0, 1.0), {0: (0.5, 5.55111512312578...e-15, 21, 0), 2: (1.0, 1.11022302462515...e-14, 21, 0)}) + sage: r = vector([t,0,1], sparse=True) # optional - sage.symbolic + sage: r.nintegral(t, 0, 1) # optional - sage.symbolic + ((0.5, 0.0, 1.0), + {0: (0.5, 5.55111512312578...e-15, 21, 0), + 2: (1.0, 1.11022302462515...e-14, 21, 0)}) """ # If Cython supported lambda functions, we would just do @@ -4151,15 +4159,15 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): :: - sage: v = vector([1,2/3,pi]) - sage: v == v + sage: v = vector([1,2/3,pi]) # optional - sage.symbolic + sage: v == v # optional - sage.symbolic True :: - sage: v = vector(RR, [1,2/3,pi]) - sage: v.set_immutable() - sage: isinstance(hash(v), int) + sage: v = vector(RR, [1,2/3,pi]) # optional - sage.symbolic + sage: v.set_immutable() # optional - sage.symbolic + sage: isinstance(hash(v), int) # optional - sage.symbolic True """ cdef _new_c(self, object v): @@ -4192,19 +4200,19 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): EXAMPLES:: - sage: v = vector([-1,0,3,pi]) - sage: type(v) + sage: v = vector([-1,0,3,pi]) # optional - sage.symbolic + sage: type(v) # optional - sage.symbolic - sage: v.__copy__() + sage: v.__copy__() # optional - sage.symbolic (-1, 0, 3, pi) - sage: v.__copy__() is v + sage: v.__copy__() is v # optional - sage.symbolic False - sage: copy(v) + sage: copy(v) # optional - sage.symbolic (-1, 0, 3, pi) - sage: copy(v) == v + sage: copy(v) == v # optional - sage.symbolic True - sage: copy(v) is v + sage: copy(v) is v # optional - sage.symbolic False """ return self._new_c(list(self._entries)) @@ -4219,11 +4227,11 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): We can initialize with lists, tuples and derived types:: sage: from sage.modules.free_module_element import FreeModuleElement_generic_dense - sage: FreeModuleElement_generic_dense(RR^5, [-1,0,2/3,pi,oo]) + sage: FreeModuleElement_generic_dense(RR^5, [-1,0,2/3,pi,oo]) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) - sage: FreeModuleElement_generic_dense(RR^5, (-1,0,2/3,pi,oo)) + sage: FreeModuleElement_generic_dense(RR^5, (-1,0,2/3,pi,oo)) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) - sage: FreeModuleElement_generic_dense(RR^5, Sequence([-1,0,2/3,pi,oo])) + sage: FreeModuleElement_generic_dense(RR^5, Sequence([-1,0,2/3,pi,oo])) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) sage: FreeModuleElement_generic_dense(RR^0, 0) () @@ -4232,26 +4240,26 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): Disabling coercion can lead to illegal objects:: - sage: FreeModuleElement_generic_dense(RR^5, [-1,0,2/3,pi,oo], coerce=False) + sage: FreeModuleElement_generic_dense(RR^5, [-1,0,2/3,pi,oo], coerce=False) # optional - sage.symbolic (-1, 0, 2/3, pi, +Infinity) We test the ``copy`` flag:: sage: from sage.modules.free_module_element import FreeModuleElement_generic_dense - sage: L = [RR(x) for x in (-1,0,2/3,pi,oo)] - sage: FreeModuleElement_generic_dense(RR^5, tuple(L), coerce=False, copy=False) + sage: L = [RR(x) for x in (-1,0,2/3,pi,oo)] # optional - sage.symbolic + sage: FreeModuleElement_generic_dense(RR^5, tuple(L), coerce=False, copy=False) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) - sage: v = FreeModuleElement_generic_dense(RR^5, L, coerce=False, copy=False) - sage: L[4] = 42.0 - sage: v # last entry changed since we didn't copy + sage: v = FreeModuleElement_generic_dense(RR^5, L, coerce=False, copy=False) # optional - sage.symbolic + sage: L[4] = 42.0 # optional - sage.symbolic + sage: v # last entry changed since we didn't copy # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, 42.0000000000000) :: - sage: L = [RR(x) for x in (-1,0,2/3,pi,oo)] - sage: v = FreeModuleElement_generic_dense(RR^5, L, coerce=False, copy=True) - sage: L[4] = 42.0 - sage: v # last entry did not change + sage: L = [RR(x) for x in (-1,0,2/3,pi,oo)] # optional - sage.symbolic + sage: v = FreeModuleElement_generic_dense(RR^5, L, coerce=False, copy=True) # optional - sage.symbolic + sage: L[4] = 42.0 # optional - sage.symbolic + sage: v # last entry did not change # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) Check that :trac:`11751` is fixed:: @@ -4309,8 +4317,8 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): EXAMPLES:: - sage: v = vector([1,2/3,pi]); w = vector([-2/3,pi^2,1]) - sage: v._add_(w) + sage: v = vector([1,2/3,pi]); w = vector([-2/3,pi^2,1]) # optional - sage.symbolic + sage: v._add_(w) # optional - sage.symbolic (1/3, pi^2 + 2/3, pi + 1) """ cdef list a = left._entries @@ -4356,10 +4364,10 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([-1,0,3,pi]) - sage: v._lmul_(2/3) + sage: v = vector([-1,0,3,pi]) # optional - sage.symbolic + sage: v._lmul_(2/3) # optional - sage.symbolic (-2/3, 0, 2, 2/3*pi) - sage: v * (2/3) + sage: v * (2/3) # optional - sage.symbolic (-2/3, 0, 2, 2/3*pi) """ if right._parent is self._parent._base: @@ -4392,9 +4400,10 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([-1,0,3,pi]) - sage: v.__reduce__() - (, (Vector space of dimension 4 over Symbolic Ring, [-1, 0, 3, pi], 4, True)) + sage: v = vector([-1,0,3,pi]) # optional - sage.symbolic + sage: v.__reduce__() # optional - sage.symbolic + (, + (Vector space of dimension 4 over Symbolic Ring, [-1, 0, 3, pi], 4, True)) """ return (make_FreeModuleElement_generic_dense_v1, (self._parent, self._entries, self._degree, not self._is_immutable)) @@ -4405,8 +4414,8 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): """ EXAMPLES:: - sage: v = vector(RR, [-1,0,2/3,pi]) - sage: v.get(3) + sage: v = vector(RR, [-1,0,2/3,pi]) # optional - sage.symbolic + sage: v.get(3) # optional - sage.symbolic 3.14159265358979 :: @@ -4485,20 +4494,20 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): EXAMPLES:: - sage: x, y = var('x,y') - sage: f = x^2 + y^2 - sage: g = f.gradient() - sage: g + sage: x, y = var('x,y') # optional - sage.symbolic + sage: f = x^2 + y^2 # optional - sage.symbolic + sage: g = f.gradient() # optional - sage.symbolic + sage: g # optional - sage.symbolic (2*x, 2*y) - sage: type(g) + sage: type(g) # optional - sage.symbolic - sage: g(y=2, x=3) + sage: g(y=2, x=3) # optional - sage.symbolic (6, 4) - sage: f(x,y) = x^2 + y^2 - sage: g = f.gradient() - sage: g(3,2) + sage: f(x,y) = x^2 + y^2 # optional - sage.symbolic + sage: g = f.gradient() # optional - sage.symbolic + sage: g(3,2) # optional - sage.symbolic (6, 4) - sage: g(x=3, y=2) + sage: g(x=3, y=2) # optional - sage.symbolic (6, 4) """ return vector([e(*args, **kwargs) for e in self]) @@ -4509,28 +4518,28 @@ cdef class FreeModuleElement_generic_dense(FreeModuleElement): EXAMPLES:: - sage: x,y=var('x,y') - sage: v=vector([x,y,x*sin(y)]) - sage: w=v.function([x,y]); w + sage: x, y = var('x,y') # optional - sage.symbolic + sage: v = vector([x, y, x*sin(y)]) # optional - sage.symbolic + sage: w = v.function([x,y]); w # optional - sage.symbolic (x, y) |--> (x, y, x*sin(y)) - sage: w.coordinate_ring() + sage: w.coordinate_ring() # optional - sage.symbolic Callable function ring with arguments (x, y) - sage: w(1,2) + sage: w(1,2) # optional - sage.symbolic (1, 2, sin(2)) - sage: w(2,1) + sage: w(2,1) # optional - sage.symbolic (2, 1, 2*sin(1)) - sage: w(y=1,x=2) + sage: w(y=1,x=2) # optional - sage.symbolic (2, 1, 2*sin(1)) :: - sage: x,y=var('x,y') - sage: v=vector([x,y,x*sin(y)]) - sage: w=v.function([x]); w + sage: x,y = var('x,y') # optional - sage.symbolic + sage: v = vector([x, y, x*sin(y)]) # optional - sage.symbolic + sage: w = v.function([x]); w # optional - sage.symbolic x |--> (x, y, x*sin(y)) - sage: w.coordinate_ring() + sage: w.coordinate_ring() # optional - sage.symbolic Callable function ring with argument x - sage: w(4) + sage: w(4) # optional - sage.symbolic (4, y, 4*sin(y)) """ from sage.symbolic.callable import CallableSymbolicExpressionRing @@ -4582,9 +4591,9 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): TESTS:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v.set_immutable() - sage: isinstance(hash(v), int) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v.set_immutable() # optional - sage.symbolic + sage: isinstance(hash(v), int) # optional - sage.symbolic True Pickling works:: @@ -4634,8 +4643,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v.__copy__() + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v.__copy__() # optional - sage.symbolic (1, 2/3, pi) """ return self._new_c(dict(self._entries)) @@ -4654,13 +4663,13 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): sage: from sage.modules.free_module_element import FreeModuleElement_generic_sparse sage: def S(R,n): ....: return FreeModule(R, n, sparse=True) - sage: FreeModuleElement_generic_sparse(S(RR,5), {0:-1, 2:2/3, 3:pi, 4:oo}) + sage: FreeModuleElement_generic_sparse(S(RR,5), {0:-1, 2:2/3, 3:pi, 4:oo}) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) - sage: FreeModuleElement_generic_sparse(S(RR,5), [-1,0,2/3,pi,oo]) + sage: FreeModuleElement_generic_sparse(S(RR,5), [-1,0,2/3,pi,oo]) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) - sage: FreeModuleElement_generic_sparse(S(RR,5), (-1,0,2/3,pi,oo)) + sage: FreeModuleElement_generic_sparse(S(RR,5), (-1,0,2/3,pi,oo)) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) - sage: FreeModuleElement_generic_sparse(S(RR,5), Sequence([-1,0,2/3,pi,oo])) + sage: FreeModuleElement_generic_sparse(S(RR,5), Sequence([-1,0,2/3,pi,oo])) # optional - sage.symbolic (-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity) sage: FreeModuleElement_generic_sparse(S(RR,0), 0) () @@ -4705,8 +4714,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): We correctly initialize values which become 0 only after coercion:: - sage: v = FreeModuleElement_generic_sparse(S(GF(3),6), [1,2,3,4,5,6]) - sage: v.nonzero_positions() + sage: v = FreeModuleElement_generic_sparse(S(GF(3), 6), [1,2,3,4,5,6]) # optional - sage.rings.finite_rings + sage: v.nonzero_positions() # optional - sage.rings.finite_rings [0, 1, 3, 4] """ #WARNING: In creation, we do not check that the indices i satisfy @@ -4758,8 +4767,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v._add_(v) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v._add_(v) # optional - sage.symbolic (2, 4/3, 2*pi) """ cdef dict v = dict((right)._entries) @@ -4778,8 +4787,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v._sub_(v) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v._sub_(v) # optional - sage.symbolic (0, 0, 0) """ cdef dict v = dict(left._entries) # dict to make a copy @@ -4798,8 +4807,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v._lmul_(SR(3)) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v._lmul_(SR(3)) # optional - sage.symbolic (3, 2, 3*pi) """ cdef dict v = {} @@ -4814,8 +4823,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v._rmul_(SR(3)) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v._rmul_(SR(3)) # optional - sage.symbolic (3, 2, 3*pi) """ cdef dict v = {} @@ -4882,8 +4891,8 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True); w = vector([-2/3,pi^2,1],sparse=True) - sage: v._pairwise_product_(w) + sage: v = vector([1,2/3,pi], sparse=True); w = vector([-2/3,pi^2,1],sparse=True) # optional - sage.symbolic + sage: v._pairwise_product_(w) # optional - sage.symbolic (-2/3, 2/3*pi^2, pi) """ # Component wise vector * vector multiplication. @@ -4907,17 +4916,17 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): TESTS:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: w = vector([1,2/3,pi], sparse=True) - sage: w == v + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: w = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: w == v # optional - sage.symbolic True Check that the bug in :trac:`13929` has been fixed:: - sage: V = FreeModule( GF(3), 2, sparse=True) - sage: a = V([0,1]) - sage: b = V([1,0]) - sage: a < b + sage: V = FreeModule(GF(3), 2, sparse=True) # optional - sage.rings.finite_rings + sage: a = V([0,1]) # optional - sage.rings.finite_rings + sage: b = V([1,0]) # optional - sage.rings.finite_rings + sage: a < b # optional - sage.rings.finite_rings True """ a = sorted((left)._entries.iteritems()) @@ -4931,17 +4940,17 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: next(v.items()) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: next(v.items()) # optional - sage.symbolic (0, 1) - sage: list(v.items()) + sage: list(v.items()) # optional - sage.symbolic [(0, 1), (1, 2/3), (2, pi)] TESTS: Using iteritems as an alias:: - sage: list(v.iteritems()) + sage: list(v.iteritems()) # optional - sage.symbolic [(0, 1), (1, 2/3), (2, pi)] """ return iter(self._entries.iteritems()) @@ -4952,9 +4961,10 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v.__reduce__() - (, (Sparse vector space of dimension 3 over Symbolic Ring, {0: 1, 1: 2/3, 2: pi}, 3, True)) + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v.__reduce__() # optional - sage.symbolic + (, + (Sparse vector space of dimension 3 over Symbolic Ring, {0: 1, 1: 2/3, 2: pi}, 3, True)) """ return (make_FreeModuleElement_generic_sparse_v1, (self._parent, self._entries, self._degree, not self._is_immutable)) @@ -5030,15 +5040,15 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: v = vector([-1,0,2/3,pi], sparse=True) - sage: v.get(1) + sage: v = vector([-1,0,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v.get(1) # optional - sage.symbolic 0 - sage: v.get(2) + sage: v.get(2) # optional - sage.symbolic 2/3 For this class, 0 is returned if the access is out of bounds:: - sage: v.get(10) + sage: v.get(10) # optional - sage.symbolic 0 """ try: @@ -5050,38 +5060,39 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): """ EXAMPLES:: - sage: V = VectorSpace(GF(17), 10000000, sparse=True) - sage: w = V(0) - sage: w[39893] = 20 - sage: w[39893] + sage: V = VectorSpace(GF(17), 10000000, sparse=True) # optional - sage.rings.finite_rings + sage: w = V(0) # optional - sage.rings.finite_rings + sage: w[39893] = 20 # optional - sage.rings.finite_rings + sage: w[39893] # optional - sage.rings.finite_rings 3 - sage: w[39000:39003] = [4, 5, 6]; w[39000:39003] + sage: w[39000:39003] = [4, 5, 6]; w[39000:39003] # optional - sage.rings.finite_rings (4, 5, 6) - sage: parent(w[39893]) + sage: parent(w[39893]) # optional - sage.rings.finite_rings Finite Field of size 17 - sage: w[39893] = sqrt(2) + sage: w[39893] = sqrt(2) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: self must be a numeric expression :: - sage: v = vector([1,2/3,pi], sparse=True) - sage: v.set(1, pi^3) - sage: v + sage: v = vector([1,2/3,pi], sparse=True) # optional - sage.symbolic + sage: v.set(1, pi^3) # optional - sage.symbolic + sage: v # optional - sage.symbolic (1, pi^3, pi) - sage: v.set(2, SR(0)) - sage: v + sage: v.set(2, SR(0)) # optional - sage.symbolic + sage: v # optional - sage.symbolic (1, pi^3, 0) This assignment is illegal:: - sage: v.set(10, pi) + sage: v.set(10, pi) # optional - sage.symbolic This lack of bounds checking causes trouble later:: - sage: v - ) failed: IndexError: list assignment index out of range> + sage: v # optional - sage.symbolic + ) + failed: IndexError: list assignment index out of range> """ if value: self._entries[i] = value diff --git a/src/sage/modules/free_module_homspace.py b/src/sage/modules/free_module_homspace.py index 4d99c5f4223..1887985955e 100644 --- a/src/sage/modules/free_module_homspace.py +++ b/src/sage/modules/free_module_homspace.py @@ -5,7 +5,7 @@ We create `\mathrm{End}(\ZZ^2)` and compute a basis. :: - sage: M = FreeModule(IntegerRing(),2) + sage: M = FreeModule(IntegerRing(), 2) sage: E = End(M) sage: B = E.basis() sage: len(B) @@ -14,21 +14,20 @@ Free module morphism defined by the matrix [1 0] [0 0] - Domain: Ambient free module of rank 2 over the principal ideal domain ... + Domain: Ambient free module of rank 2 over the principal ideal domain ... Codomain: Ambient free module of rank 2 over the principal ideal domain ... We create `\mathrm{Hom}(\ZZ^3, \ZZ^2)` and compute a basis. :: - sage: V3 = FreeModule(IntegerRing(),3) - sage: V2 = FreeModule(IntegerRing(),2) - sage: H = Hom(V3,V2) + sage: V3 = FreeModule(IntegerRing(), 3) + sage: V2 = FreeModule(IntegerRing(), 2) + sage: H = Hom(V3, V2) sage: H - Set of Morphisms from Ambient free module of rank 3 over - the principal ideal domain Integer Ring - to Ambient free module of rank 2 - over the principal ideal domain Integer Ring - in Category of finite dimensional modules with basis over - (euclidean domains and infinite enumerated sets and metric spaces) + Set of Morphisms + from Ambient free module of rank 3 over the principal ideal domain Integer Ring + to Ambient free module of rank 2 over the principal ideal domain Integer Ring + in Category of finite dimensional modules with basis over + (euclidean domains and infinite enumerated sets and metric spaces) sage: B = H.basis() sage: len(B) 6 @@ -54,7 +53,7 @@ See :trac:`13321`:: - sage: (GF(7)^2).hom([[20,0],[0,21]],ZZ^2) + sage: (GF(7)^2).hom([[20, 0], [0, 21]], ZZ^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: nontrivial morphisms require a coercion map from the base ring @@ -167,10 +166,10 @@ def __call__(self, A, **kwds): [0 0 0] [0 0 0] [0 0 0] - Domain: Free module of degree 3 and rank 3 over Integer Ring - Echelon ... + Domain: Free module of degree 3 and rank 3 over Integer Ring + Echelon ... Codomain: Free module of degree 3 and rank 3 over Integer Ring - Echelon ... + Echelon ... The following tests the bug fixed in :trac:`31818`. If there is no coercion between base rings, one can only define the zero morphism, @@ -188,7 +187,7 @@ def __call__(self, A, **kwds): Free module morphism defined by the matrix [0 0] [0 0] - Domain: Vector space of dimension 2 over Rational Field + Domain: Vector space of dimension 2 over Rational Field Codomain: Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: [h(v) for v in V.gens()] [(0, 0), (0, 0)] @@ -236,7 +235,7 @@ def zero(self, side="left"): Free module morphism defined by the matrix [0 0 0] [0 0 0] - Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring + Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Ambient free module of rank 3 over the principal ideal domain Integer Ring sage: f(E.an_element()) (0, 0, 0) @@ -247,7 +246,7 @@ def zero(self, side="left"): [0 0] [0 0] [0 0] - Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring + Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Ambient free module of rank 3 over the principal ideal domain Integer Ring @@ -259,7 +258,7 @@ def zero(self, side="left"): Free module morphism defined by the matrix [0 0 0] [0 0 0] - Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring + Domain: Ambient free module of rank 2 over the principal ideal domain Integer Ring Codomain: Ambient free module of rank 3 over the principal ideal domain Integer Ring """ return self(lambda x: self.codomain().zero(), side=side) @@ -310,24 +309,24 @@ def basis(self, side="left"): sage: H = Hom(ZZ^2, ZZ^1) sage: H.basis() (Free module morphism defined by the matrix - [1] - [0] - Domain: Ambient free module of rank 2 over the principal ideal domain ... - Codomain: Ambient free module of rank 1 over the principal ideal domain ..., - Free module morphism defined by the matrix - [0] - [1] - Domain: Ambient free module of rank 2 over the principal ideal domain ... - Codomain: Ambient free module of rank 1 over the principal ideal domain ...) + [1] + [0] + Domain: Ambient free module of rank 2 over the principal ideal domain ... + Codomain: Ambient free module of rank 1 over the principal ideal domain ..., + Free module morphism defined by the matrix + [0] + [1] + Domain: Ambient free module of rank 2 over the principal ideal domain ... + Codomain: Ambient free module of rank 1 over the principal ideal domain ...) sage: H.basis("right") (Free module morphism defined as left-multiplication by the matrix - [1 0] - Domain: Ambient free module of rank 2 over the principal ideal domain ... - Codomain: Ambient free module of rank 1 over the principal ideal domain ..., + [1 0] + Domain: Ambient free module of rank 2 over the principal ideal domain ... + Codomain: Ambient free module of rank 1 over the principal ideal domain ..., Free module morphism defined as left-multiplication by the matrix - [0 1] - Domain: Ambient free module of rank 2 over the principal ideal domain ... - Codomain: Ambient free module of rank 1 over the principal ideal domain ...) + [0 1] + Domain: Ambient free module of rank 2 over the principal ideal domain ... + Codomain: Ambient free module of rank 1 over the principal ideal domain ...) """ M = self._matrix_space(side) B = M.basis() @@ -352,7 +351,7 @@ def identity(self, side="left"): [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1] - Domain: Ambient free module of rank 5 over the principal ideal domain ... + Domain: Ambient free module of rank 5 over the principal ideal domain ... Codomain: Ambient free module of rank 5 over the principal ideal domain ... """ if self.is_endomorphism_set(): diff --git a/src/sage/modules/free_module_integer.py b/src/sage/modules/free_module_integer.py index ddd8a25c92a..cf36c8960ee 100644 --- a/src/sage/modules/free_module_integer.py +++ b/src/sage/modules/free_module_integer.py @@ -109,7 +109,8 @@ def IntegerLattice(basis, lll_reduce=True): sage: K. = CyclotomicField(17) sage: O = K.ring_of_integers() - sage: f = O(-a^15 + a^13 + 4*a^12 - 12*a^11 - 256*a^10 + a^9 - a^7 - 4*a^6 + a^5 + 210*a^4 + 2*a^3 - 2*a^2 + 2*a - 2) + sage: f = O(-a^15 + a^13 + 4*a^12 - 12*a^11 - 256*a^10 + a^9 - a^7 + ....: - 4*a^6 + a^5 + 210*a^4 + 2*a^3 - 2*a^2 + 2*a - 2) sage: from sage.modules.free_module_integer import IntegerLattice sage: IntegerLattice(f) Free module of degree 16 and rank 16 over Integer Ring @@ -152,10 +153,10 @@ def IntegerLattice(basis, lll_reduce=True): Sage also interfaces with fpylll's lattice generator:: sage: from sage.modules.free_module_integer import IntegerLattice - sage: from fpylll import IntegerMatrix - sage: A = IntegerMatrix.random(8, "simdioph", bits=20, bits2=10) - sage: A = A.to_matrix(matrix(ZZ, 8, 8)) - sage: IntegerLattice(A, lll_reduce=False) + sage: from fpylll import IntegerMatrix # optional - fpylll + sage: A = IntegerMatrix.random(8, "simdioph", bits=20, bits2=10) # optional - fpylll + sage: A = A.to_matrix(matrix(ZZ, 8, 8)) # optional - fpylll + sage: IntegerLattice(A, lll_reduce=False) # optional - fpylll Free module of degree 8 and rank 8 over Integer Ring User basis matrix: [ 1024 829556 161099 11567 521155 769480 639201 689979] @@ -197,7 +198,8 @@ class FreeModule_submodule_with_basis_integer(FreeModule_submodule_with_basis_pi EXAMPLES:: sage: from sage.modules.free_module_integer import IntegerLattice - sage: L = IntegerLattice(sage.crypto.gen_lattice(type='modular', m=10, seed=1337, dual=True)); L + sage: L = IntegerLattice(sage.crypto.gen_lattice(type='modular', m=10, + ....: seed=1337, dual=True)); L Free module of degree 10 and rank 10 over Integer Ring User basis matrix: [-1 1 2 -2 0 1 0 -1 2 1] @@ -364,10 +366,10 @@ def LLL(self, *args, **kwds): ... sage: L.reduced_basis == A True - sage: old = L.reduced_basis[0].norm().n() + sage: old = L.reduced_basis[0].norm().n() # optional - sage.symbolic sage: _ = L.LLL() - sage: new = L.reduced_basis[0].norm().n() - sage: new <= old + sage: new = L.reduced_basis[0].norm().n() # optional - sage.symbolic + sage: new <= old # optional - sage.symbolic True """ basis = self.reduced_basis @@ -648,20 +650,24 @@ def voronoi_cell(self, radius=None): sage: L = IntegerLattice([[1, 0], [0, 1]]) sage: V = L.voronoi_cell() sage: V.Vrepresentation() - (A vertex at (1/2, -1/2), A vertex at (1/2, 1/2), A vertex at (-1/2, 1/2), A vertex at (-1/2, -1/2)) + (A vertex at (1/2, -1/2), + A vertex at (1/2, 1/2), + A vertex at (-1/2, 1/2), + A vertex at (-1/2, -1/2)) The volume of the Voronoi cell is the square root of the discriminant of the lattice:: - sage: L = IntegerLattice(Matrix(ZZ, 4, 4, [[0,0,1,-1],[1,-1,2,1],[-6,0,3,3,],[-6,-24,-6,-5]])); L + sage: L = IntegerLattice(Matrix(ZZ, 4, 4, [[0,0,1,-1], [1,-1,2,1], + ....: [-6,0,3,3,], [-6,-24,-6,-5]])); L Free module of degree 4 and rank 4 over Integer Ring User basis matrix: [ 0 0 1 -1] [ 1 -1 2 1] [ -6 0 3 3] [ -6 -24 -6 -5] - sage: V = L.voronoi_cell() # long time - sage: V.volume() # long time + sage: V = L.voronoi_cell() # long time + sage: V.volume() # long time 678 sage: sqrt(L.discriminant()) 678 @@ -671,7 +677,10 @@ def voronoi_cell(self, radius=None): sage: L = IntegerLattice([[2, 0, 0], [0, 2, 0]]) sage: V = L.voronoi_cell() sage: V.Hrepresentation() - (An inequality (-1, 0, 0) x + 1 >= 0, An inequality (0, -1, 0) x + 1 >= 0, An inequality (1, 0, 0) x + 1 >= 0, An inequality (0, 1, 0) x + 1 >= 0) + (An inequality (-1, 0, 0) x + 1 >= 0, + An inequality (0, -1, 0) x + 1 >= 0, + An inequality (1, 0, 0) x + 1 >= 0, + An inequality (0, 1, 0) x + 1 >= 0) ALGORITHM: diff --git a/src/sage/modules/free_module_morphism.py b/src/sage/modules/free_module_morphism.py index f7508ebeb97..37dd2614098 100644 --- a/src/sage/modules/free_module_morphism.py +++ b/src/sage/modules/free_module_morphism.py @@ -53,7 +53,7 @@ def is_FreeModuleMorphism(x): """ EXAMPLES:: - sage: V = ZZ^2; f = V.hom([V.1,-2*V.0]) + sage: V = ZZ^2; f = V.hom([V.1, -2*V.0]) sage: sage.modules.free_module_morphism.is_FreeModuleMorphism(f) True sage: sage.modules.free_module_morphism.is_FreeModuleMorphism(0) @@ -75,8 +75,8 @@ def __init__(self, parent, A, side="left"): EXAMPLES:: - sage: V = ZZ^3; W = span([[1,2,3],[-1,2,8]], ZZ) - sage: phi = V.hom(matrix(ZZ,3,[1..9])) + sage: V = ZZ^3; W = span([[1,2,3], [-1,2,8]], ZZ) + sage: phi = V.hom(matrix(ZZ, 3, [1..9])) sage: type(phi) """ @@ -93,8 +93,8 @@ def pushforward(self, x): EXAMPLES:: - sage: V = QQ^3; W = span([[1,2,3],[-1,2,5/3]], QQ) - sage: phi = V.hom(matrix(QQ,3,[1..9])) + sage: V = QQ^3; W = span([[1,2,3], [-1,2,5/3]], QQ) + sage: phi = V.hom(matrix(QQ, 3, [1..9])) sage: phi.rank() 2 sage: phi(V) #indirect doctest @@ -106,12 +106,12 @@ def pushforward(self, x): We compute the image of a submodule of a ZZ-module embedded in a rational vector space:: - sage: V = QQ^3; W = V.span_of_basis([[2,2,3],[-1,2,5/3]], ZZ) - sage: phi = W.hom([W.0, W.0-W.1]); phi + sage: V = QQ^3; W = V.span_of_basis([[2,2,3], [-1,2,5/3]], ZZ) + sage: phi = W.hom([W.0, W.0 - W.1]); phi Free module morphism defined by the matrix [ 1 0] [ 1 -1]... - sage: phi(span([2*W.1],ZZ)) + sage: phi(span([2*W.1], ZZ)) Free module of degree 3 and rank 1 over Integer Ring Echelon basis matrix: [ 6 0 8/3] @@ -129,8 +129,8 @@ def _repr_(self): EXAMPLES:: - sage: V = ZZ^3; W = span([[1,2,3],[-1,2,8]], ZZ) - sage: phi = V.hom(matrix(ZZ,3,[1..9])) + sage: V = ZZ^3; W = span([[1,2,3], [-1,2,8]], ZZ) + sage: phi = V.hom(matrix(ZZ, 3, [1..9])) sage: phi._repr_() 'Free module morphism defined by the matrix\n[1 2 3]\n[4 5 6]\n[7 8 9]\nDomain: Ambient free module of rank 3 over the principal ideal domain Integer Ring\nCodomain: Ambient free module of rank 3 over the principal ideal domain Integer Ring' @@ -192,8 +192,10 @@ def change_ring(self, R): EXAMPLES:: - sage: V0 = span([[0,0,1],[0,2,0]],ZZ); V1 = span([[1/2,0],[0,2]],ZZ); W = span([[1,0],[0,6]],ZZ) - sage: h = V0.hom([-3*V1.0-3*V1.1, -3*V1.0-3*V1.1]) + sage: V0 = span([[0,0,1], [0,2,0]], ZZ) + sage: V1 = span([[1/2,0], [0,2]], ZZ) + sage: W = span([[1,0], [0,6]], ZZ) + sage: h = V0.hom([-3*V1.0 - 3*V1.1, -3*V1.0 - 3*V1.1]) sage: h.base_ring() Integer Ring sage: h @@ -206,26 +208,26 @@ def change_ring(self, R): Vector space morphism represented by the matrix: [-3 -3] [-3 -3] - Domain: Vector space of degree 3 and dimension 2 over Rational Field - Basis matrix: - [0 1 0] - [0 0 1] + Domain: Vector space of degree 3 and dimension 2 over Rational Field + Basis matrix: + [0 1 0] + [0 0 1] Codomain: Vector space of degree 2 and dimension 2 over Rational Field - Basis matrix: - [1 0] - [0 1] - sage: f = h.change_ring(GF(7)); f + Basis matrix: + [1 0] + [0 1] + sage: f = h.change_ring(GF(7)); f # optional - sage.libs.pari Vector space morphism represented by the matrix: [4 4] [4 4] - Domain: Vector space of degree 3 and dimension 2 over Finite Field of size 7 - Basis matrix: - [0 1 0] - [0 0 1] + Domain: Vector space of degree 3 and dimension 2 over Finite Field of size 7 + Basis matrix: + [0 1 0] + [0 0 1] Codomain: Vector space of degree 2 and dimension 2 over Finite Field of size 7 - Basis matrix: - [1 0] - [0 1] + Basis matrix: + [1 0] + [0 1] """ D = self.domain().change_ring(R) C = self.codomain().change_ring(R) @@ -242,8 +244,8 @@ def inverse_image(self, V): We test computing inverse images over a field:: - sage: V = QQ^3; W = span([[1,2,3],[-1,2,5/3]], QQ) - sage: phi = V.hom(matrix(QQ,3,[1..9])) + sage: V = QQ^3; W = span([[1,2,3], [-1,2,5/3]], QQ) + sage: phi = V.hom(matrix(QQ, 3, [1..9])) sage: phi.rank() 2 sage: I = phi.inverse_image(W); I @@ -262,8 +264,10 @@ def inverse_image(self, V): We test computing inverse images between two spaces embedded in different ambient spaces.:: - sage: V0 = span([[0,0,1],[0,2,0]],ZZ); V1 = span([[1/2,0],[0,2]],ZZ); W = span([[1,0],[0,6]],ZZ) - sage: h = V0.hom([-3*V1.0-3*V1.1, -3*V1.0-3*V1.1]) + sage: V0 = span([[0,0,1], [0,2,0]], ZZ) + sage: V1 = span([[1/2,0], [0,2]], ZZ) + sage: W = span([[1,0], [0,6]], ZZ) + sage: h = V0.hom([-3*V1.0 - 3*V1.1, -3*V1.0 - 3*V1.1]) sage: h.inverse_image(W) Free module of degree 3 and rank 2 over Integer Ring Echelon basis matrix: @@ -281,8 +285,8 @@ def inverse_image(self, V): We test computing inverse images over the integers:: - sage: V = QQ^3; W = V.span_of_basis([[2,2,3],[-1,2,5/3]], ZZ) - sage: phi = W.hom([W.0, W.0-W.1]) + sage: V = QQ^3; W = V.span_of_basis([[2,2,3], [-1,2,5/3]], ZZ) + sage: phi = W.hom([W.0, W.0 - W.1]) sage: Z = W.span([2*W.1]); Z Free module of degree 3 and rank 1 over Integer Ring Echelon basis matrix: @@ -296,7 +300,7 @@ def inverse_image(self, V): We test that :trac:`24590` is resolved:: - sage: A = FreeQuadraticModule(ZZ,1,matrix([2])) + sage: A = FreeQuadraticModule(ZZ, 1, matrix([2])) sage: f = A.Hom(A).an_element() sage: f.inverse_image(A) Free module of degree 1 and rank 1 over Integer Ring @@ -414,17 +418,17 @@ def lift(self, x): This works for vector spaces, too:: - sage: V = VectorSpace(GF(3), 2) - sage: W = VectorSpace(GF(3), 3) - sage: f = V.hom([W.1, W.1 - W.0]) - sage: f.lift(W.1) + sage: V = VectorSpace(GF(3), 2) # optional - sage.libs.pari + sage: W = VectorSpace(GF(3), 3) # optional - sage.libs.pari + sage: f = V.hom([W.1, W.1 - W.0]) # optional - sage.libs.pari + sage: f.lift(W.1) # optional - sage.libs.pari (1, 0) - sage: f.lift(W.2) + sage: f.lift(W.2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: element is not in the image - sage: w = W((17, -2, 0)) - sage: f(f.lift(w)) == w + sage: w = W((17, -2, 0)) # optional - sage.libs.pari + sage: f(f.lift(w)) == w # optional - sage.libs.pari True This example illustrates the use of the ``preimage_representative`` @@ -440,9 +444,9 @@ def lift(self, x): :: sage: V = QQ^2; m = matrix(2, [1, 1, 0, 1]) - sage: V.hom(m, side="right").lift(V.0+V.1) + sage: V.hom(m, side="right").lift(V.0 + V.1) (0, 1) - sage: V.hom(m).lift(V.0+V.1) + sage: V.hom(m).lift(V.0 + V.1) (1, 0) """ from .free_module_element import vector @@ -473,7 +477,7 @@ def lift(self, x): preimage_representative = lift - def eigenvalues(self,extend=True): + def eigenvalues(self, extend=True): r""" Returns a list with the eigenvalues of the endomorphism of vector spaces. @@ -486,18 +490,18 @@ def eigenvalues(self,extend=True): We compute the eigenvalues of an endomorphism of `\QQ^3`:: - sage: V=QQ^3 - sage: H=V.endomorphism_ring()([[1,-1,0],[-1,1,1],[0,3,1]]) - sage: H.eigenvalues() + sage: V = QQ^3 + sage: H = V.endomorphism_ring()([[1,-1,0], [-1,1,1], [0,3,1]]) + sage: H.eigenvalues() # optional - sage.rings.number_field [3, 1, -1] Note the effect of the ``extend`` option:: - sage: V=QQ^2 - sage: H=V.endomorphism_ring()([[0,-1],[1,0]]) - sage: H.eigenvalues() + sage: V = QQ^2 + sage: H = V.endomorphism_ring()([[0,-1], [1,0]]) + sage: H.eigenvalues() # optional - sage.rings.number_field [-1*I, 1*I] - sage: H.eigenvalues(extend=False) + sage: H.eigenvalues(extend=False) # optional - sage.libs.pari [] """ if self.base_ring().is_field(): @@ -508,7 +512,7 @@ def eigenvalues(self,extend=True): else: raise NotImplementedError("module must be a vector space") - def eigenvectors(self,extend=True): + def eigenvectors(self, extend=True): """ Computes the subspace of eigenvectors of a given eigenvalue. @@ -525,50 +529,30 @@ def eigenvectors(self,extend=True): EXAMPLES:: - sage: V=(QQ^4).subspace([[0,2,1,4],[1,2,5,0],[1,1,1,1]]) - sage: H=(V.Hom(V))(matrix(QQ, [[0,1,0],[-1,0,0],[0,0,3]])) - sage: H.eigenvectors() - [(3, [ - (0, 0, 1, -6/7) - ], 1), (-1*I, [ - (1, 1*I, 0, -0.571428571428572? + 2.428571428571429?*I) - ], 1), (1*I, [ - (1, -1*I, 0, -0.571428571428572? - 2.428571428571429?*I) - ], 1)] - sage: H.eigenvectors(extend=False) - [(3, [ - (0, 0, 1, -6/7) - ], 1)] - sage: H1=(V.Hom(V))(matrix(QQ, [[2,1,0],[0,2,0],[0,0,3]])) - sage: H1.eigenvectors() - [(3, [ - (0, 0, 1, -6/7) - ], 1), (2, [ - (0, 1, 0, 17/7) - ], 2)] - sage: H1.eigenvectors(extend=False) - [(3, [ - (0, 0, 1, -6/7) - ], 1), (2, [ - (0, 1, 0, 17/7) - ], 2)] + sage: V = (QQ^4).subspace([[0,2,1,4], [1,2,5,0], [1,1,1,1]]) + sage: H = (V.Hom(V))(matrix(QQ, [[0,1,0], [-1,0,0], [0,0,3]])) + sage: H.eigenvectors() # optional - sage.rings.number_field + [(3, [ (0, 0, 1, -6/7) ], 1), + (-1*I, [ (1, 1*I, 0, -0.571428571428572? + 2.428571428571429?*I) ], 1), + (1*I, [ (1, -1*I, 0, -0.571428571428572? - 2.428571428571429?*I) ], 1)] + sage: H.eigenvectors(extend=False) # optional - sage.rings.number_field + [(3, [ (0, 0, 1, -6/7) ], 1)] + sage: H1 = (V.Hom(V))(matrix(QQ, [[2,1,0],[0,2,0],[0,0,3]])) + sage: H1.eigenvectors() # optional - sage.rings.number_field + [(3, [ (0, 0, 1, -6/7) ], 1), + (2, [ (0, 1, 0, 17/7) ], 2)] + sage: H1.eigenvectors(extend=False) # optional - sage.rings.number_field + [(3, [ (0, 0, 1, -6/7) ], 1), + (2, [ (0, 1, 0, 17/7) ], 2)] :: sage: V = QQ^2 sage: m = matrix(2, [1, 1, 0, 1]) - sage: V.hom(m, side="right").eigenvectors() - [(1, - [ - (1, 0) - ], - 2)] - sage: V.hom(m).eigenvectors() - [(1, - [ - (0, 1) - ], - 2)] + sage: V.hom(m, side="right").eigenvectors() # optional - sage.rings.number_field + [(1, [ (1, 0) ], 2)] + sage: V.hom(m).eigenvectors() # optional - sage.rings.number_field + [(1, [ (0, 1) ], 2)] """ if self.base_ring().is_field(): if self.is_endomorphism(): @@ -587,7 +571,7 @@ def eigenvectors(self,extend=True): else: raise NotImplementedError("module must be a vector space") - def eigenspaces(self,extend=True): + def eigenspaces(self, extend=True): """ Compute a list of subspaces formed by eigenvectors of ``self``. @@ -603,56 +587,51 @@ def eigenspaces(self,extend=True): EXAMPLES:: sage: V = QQ^3 - sage: h = V.hom([[1,0,0],[0,0,1],[0,-1,0]], V) - sage: h.eigenspaces() - [(1, - Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [1 0 0]), - (-1*I, - Vector space of degree 3 and dimension 1 over Algebraic Field - Basis matrix: - [ 0 1 1*I]), - (1*I, - Vector space of degree 3 and dimension 1 over Algebraic Field - Basis matrix: - [ 0 1 -1*I])] - - sage: h.eigenspaces(extend=False) + sage: h = V.hom([[1,0,0], [0,0,1], [0,-1,0]], V) + sage: h.eigenspaces() # optional - sage.rings.number_field + [(1, Vector space of degree 3 and dimension 1 over Rational Field + Basis matrix: + [1 0 0]), + (-1*I, Vector space of degree 3 and dimension 1 over Algebraic Field + Basis matrix: + [ 0 1 1*I]), + (1*I, Vector space of degree 3 and dimension 1 over Algebraic Field + Basis matrix: + [ 0 1 -1*I])] + + sage: h.eigenspaces(extend=False) # optional - sage.rings.number_field [(1, Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [1 0 0])] sage: h = V.hom([[2,1,0], [0,2,0], [0,0,-1]], V) - sage: h.eigenspaces() + sage: h.eigenspaces() # optional - sage.rings.number_field [(-1, Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [0 0 1]), - (2, Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [0 1 0])] + Basis matrix: + [0 0 1]), + (2, Vector space of degree 3 and dimension 1 over Rational Field + Basis matrix: + [0 1 0])] sage: h = V.hom([[2,1,0], [0,2,0], [0,0,2]], V) - sage: h.eigenspaces() + sage: h.eigenspaces() # optional - sage.rings.number_field [(2, Vector space of degree 3 and dimension 2 over Rational Field - Basis matrix: - [0 1 0] - [0 0 1])] + Basis matrix: + [0 1 0] + [0 0 1])] :: sage: V = QQ^2; m = matrix(2, [1, 1, 0, 1]) - sage: V.hom(m, side="right").eigenspaces() - [(1, - Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [1 0])] - sage: V.hom(m).eigenspaces() - [(1, - Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [0 1])] + sage: V.hom(m, side="right").eigenspaces() # optional - sage.rings.number_field + [(1, Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: + [1 0])] + sage: V.hom(m).eigenspaces() # optional - sage.rings.number_field + [(1, Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: + [0 1])] """ ev = self.eigenvectors(extend) return [(vec[0], Sequence(vec[1]).universe().subspace(vec[1])) @@ -676,9 +655,9 @@ def minimal_polynomial(self,var='x'): Compute the minimal polynomial, and check it. :: - sage: V=GF(7)^3 - sage: H=V.Hom(V)([[0,1,2],[-1,0,3],[2,4,1]]) - sage: H + sage: V = GF(7)^3 # optional - sage.libs.pari + sage: H = V.Hom(V)([[0,1,2], [-1,0,3], [2,4,1]]) # optional - sage.libs.pari + sage: H # optional - sage.libs.pari Vector space morphism represented by the matrix: [0 1 2] [6 0 3] @@ -686,13 +665,13 @@ def minimal_polynomial(self,var='x'): Domain: Vector space of dimension 3 over Finite Field of size 7 Codomain: Vector space of dimension 3 over Finite Field of size 7 - sage: H.minpoly() + sage: H.minpoly() # optional - sage.libs.pari x^3 + 6*x^2 + 6*x + 1 - sage: H.minimal_polynomial() + sage: H.minimal_polynomial() # optional - sage.libs.pari x^3 + 6*x^2 + 6*x + 1 - sage: H^3 + (H^2)*6 + H*6 + 1 + sage: H^3 + (H^2)*6 + H*6 + 1 # optional - sage.libs.pari Vector space morphism represented by the matrix: [0 0 0] [0 0 0] @@ -717,7 +696,8 @@ class BaseIsomorphism1D(Morphism): sage: V, from_V, to_V = R.free_module(R) sage: from_V Isomorphism morphism: - From: Ambient free module of rank 1 over the integral domain Multivariate Polynomial Ring in x, y over Rational Field + From: Ambient free module of rank 1 over the integral domain + Multivariate Polynomial Ring in x, y over Rational Field To: Multivariate Polynomial Ring in x, y over Rational Field """ def _repr_type(self): diff --git a/src/sage/modules/free_quadratic_module.py b/src/sage/modules/free_quadratic_module.py index b512db6ffbc..25f794b4054 100644 --- a/src/sage/modules/free_quadratic_module.py +++ b/src/sage/modules/free_quadratic_module.py @@ -18,8 +18,8 @@ EXAMPLES:: - sage: M = Matrix(QQ,[[2,1,0],[1,2,1],[0,1,2]]) - sage: V = VectorSpace(QQ,3,inner_product_matrix=M) + sage: M = Matrix(QQ, [[2,1,0], [1,2,1], [0,1,2]]) + sage: V = VectorSpace(QQ, 3, inner_product_matrix=M) sage: type(V) sage: V.inner_product_matrix() @@ -44,11 +44,11 @@ TESTS:: - sage: M = Matrix(QQ,[[2,1,0],[1,2,1],[0,1,2]]) - sage: V = VectorSpace(QQ,3,inner_product_matrix = M) + sage: M = Matrix(QQ, [[2,1,0], [1,2,1], [0,1,2]]) + sage: V = VectorSpace(QQ, 3, inner_product_matrix=M) sage: V == loads(dumps(V)) True - sage: W = QuadraticSpace(QQ,3,M) + sage: W = QuadraticSpace(QQ, 3, M) sage: W == V True @@ -110,13 +110,13 @@ def FreeQuadraticModule(base_ring, rank, inner_product_matrix, EXAMPLES:: - sage: M2 = FreeQuadraticModule(ZZ,2,inner_product_matrix=[1,2,3,4]) - sage: M2 is FreeQuadraticModule(ZZ,2,inner_product_matrix=[1,2,3,4]) + sage: M2 = FreeQuadraticModule(ZZ, 2, inner_product_matrix=[1,2,3,4]) + sage: M2 is FreeQuadraticModule(ZZ, 2, inner_product_matrix=[1,2,3,4]) True sage: M2.inner_product_matrix() [1 2] [3 4] - sage: M3 = FreeModule(ZZ,2,inner_product_matrix=[[1,2],[3,4]]) + sage: M3 = FreeModule(ZZ, 2, inner_product_matrix=[[1,2],[3,4]]) sage: M3 is M2 True @@ -124,9 +124,9 @@ def FreeQuadraticModule(base_ring, rank, inner_product_matrix, Check for :trac:`10577`:: - sage: m = matrix.diagonal(GF(2), [1,1]) - sage: V2 = VectorSpace(GF(2), 2, inner_product_matrix=m) - sage: deepcopy(V2) + sage: m = matrix.diagonal(GF(2), [1,1]) # optional - sage.rings.finite_rings + sage: V2 = VectorSpace(GF(2), 2, inner_product_matrix=m) # optional - sage.rings.finite_rings + sage: deepcopy(V2) # optional - sage.rings.finite_rings Ambient quadratic space of dimension 2 over Finite Field of size 2 Inner product matrix: [1 0] @@ -192,10 +192,11 @@ def QuadraticSpace(K, dimension, inner_product_matrix, sparse=False): The base can be complicated, as long as it is a field:: sage: F. = FractionField(PolynomialRing(ZZ,'x')) - sage: D = diagonal_matrix([x,x-1,x+1]) - sage: V = QuadraticSpace(F,3,D) + sage: D = diagonal_matrix([x, x - 1, x + 1]) + sage: V = QuadraticSpace(F, 3, D) sage: V - Ambient quadratic space of dimension 3 over Fraction Field of Univariate Polynomial Ring in x over Integer Ring + Ambient quadratic space of dimension 3 over + Fraction Field of Univariate Polynomial Ring in x over Integer Ring Inner product matrix: [ x 0 0] [ 0 x - 1 0] @@ -209,7 +210,7 @@ def QuadraticSpace(K, dimension, inner_product_matrix, sparse=False): The base must be a field or a ``TypeError`` is raised:: - sage: QuadraticSpace(ZZ,5,identity_matrix(ZZ,2)) + sage: QuadraticSpace(ZZ, 5, identity_matrix(ZZ,2)) Traceback (most recent call last): ... TypeError: argument K (= Integer Ring) must be a field @@ -702,7 +703,7 @@ def __init__(self, base_field, dimension, degree, inner_product_matrix, sparse=F Inner product matrix: [2 1] [1 2] - sage: FreeModule(FiniteField(2), 7, inner_product_matrix=1) + sage: FreeModule(FiniteField(2), 7, inner_product_matrix=1) # optional - sage.rings.finite_rings Ambient quadratic space of dimension 7 over Finite Field of size 2 Inner product matrix: [1 0 0 0 0 0 0] @@ -739,12 +740,12 @@ def span(self, gens, check=True, already_echelonized=False): EXAMPLES:: - sage: V = VectorSpace(GF(7), 3) - sage: W = V.subspace([[2,3,4]]); W + sage: V = VectorSpace(GF(7), 3) # optional - sage.rings.finite_rings + sage: W = V.subspace([[2,3,4]]); W # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 5 2] - sage: W.span([[1,1,1]]) + sage: W.span([[1,1,1]]) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 1 1] @@ -779,12 +780,12 @@ def span_of_basis(self, basis, check=True, already_echelonized=False): EXAMPLES:: - sage: V = VectorSpace(GF(7), 3) - sage: W = V.subspace([[2,3,4]]); W + sage: V = VectorSpace(GF(7), 3) # optional - sage.rings.finite_rings + sage: W = V.subspace([[2,3,4]]); W # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 5 2] - sage: W.span_of_basis([[2,2,2], [3,3,0]]) + sage: W.span_of_basis([[2,2,2], [3,3,0]]) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 2 over Finite Field of size 7 User basis matrix: [2 2 2] @@ -793,7 +794,7 @@ def span_of_basis(self, basis, check=True, already_echelonized=False): The basis vectors must be linearly independent or a ``ValueError`` exception is raised:: - sage: W.span_of_basis([[2,2,2], [3,3,3]]) + sage: W.span_of_basis([[2,2,2], [3,3,3]]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: The given basis vectors must be linearly independent. @@ -876,7 +877,7 @@ def _latex_(self): sage: latex(QQ^3) # indirect doctest \Bold{Q}^{3} - sage: A = GF(5)^20; latex(A) + sage: A = GF(5)^20; latex(A) # optional - sage.rings.finite_rings \Bold{F}_{5}^{20} sage: A = PolynomialRing(QQ,3,'x')^20; latex(A) @@ -943,7 +944,7 @@ def __init__(self, base_ring, rank, inner_product_matrix, sparse=False): """ EXAMPLES:: - sage: FreeModule(PolynomialRing(GF(5),'x'), 3) + sage: FreeModule(PolynomialRing(GF(5),'x'), 3) # optional - sage.rings.finite_rings Ambient free module of rank 3 over the principal ideal domain Univariate Polynomial Ring in x over Finite Field of size 5 """ @@ -1141,8 +1142,8 @@ def __init__(self, base_field, dimension, inner_product_matrix, sparse=False): Check for :trac:`10606`:: sage: D = matrix.diagonal(ZZ, [1,1]) - sage: V = VectorSpace(GF(46349), 2, inner_product_matrix=D) - sage: deepcopy(V) + sage: V = VectorSpace(GF(46349), 2, inner_product_matrix=D) # optional - sage.rings.finite_rings + sage: deepcopy(V) # optional - sage.rings.finite_rings Ambient quadratic space of dimension 2 over Finite Field of size 46349 Inner product matrix: @@ -1356,17 +1357,17 @@ def change_ring(self, R): Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: [ 1 1/4 1/2] - sage: W.change_ring(GF(7)) + sage: W.change_ring(GF(7)) # optional - sage.rings.finite_rings Vector space of degree 3 and dimension 1 over Finite Field of size 7 Basis matrix: [1 2 4] - sage: N = FreeModule(ZZ, 2, inner_product_matrix=[[1,-1],[2,5]]) + sage: N = FreeModule(ZZ, 2, inner_product_matrix=[[1,-1], [2,5]]) sage: N.inner_product_matrix() [ 1 -1] [ 2 5] - sage: Np = N.change_ring(RDF) - sage: Np.inner_product_matrix() + sage: Np = N.change_ring(RDF) # optional - sage.rings.finite_rings + sage: Np.inner_product_matrix() # optional - sage.rings.finite_rings [ 1.0 -1.0] [ 2.0 5.0] """ @@ -1391,7 +1392,7 @@ class FreeQuadraticModule_submodule_pid(free_module.FreeModule_submodule_pid, EXAMPLES:: sage: M = ZZ^3 - sage: W = M.span_of_basis([[1,2,3],[4,5,19]]); W + sage: W = M.span_of_basis([[1,2,3], [4,5,19]]); W Free module of degree 3 and rank 2 over Integer Ring User basis matrix: [ 1 2 3] @@ -1509,14 +1510,14 @@ def __init__(self, ambient, basis, inner_product_matrix, EXAMPLES:: sage: V = QQ^3 - sage: W = V.span_of_basis([[1,2,3],[4,5,6]]) + sage: W = V.span_of_basis([[1,2,3], [4,5,6]]) sage: W Vector space of degree 3 and dimension 2 over Rational Field User basis matrix: [1 2 3] [4 5 6] sage: V = VectorSpace(QQ, 3, inner_product_matrix=1) - sage: V.span_of_basis([[1,2,3],[4,5,6]]) + sage: V.span_of_basis([[1,2,3], [4,5,6]]) Quadratic space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 2 3] @@ -1603,7 +1604,7 @@ class FreeQuadraticModule_submodule_field(free_module.FreeModule_submodule_field coordinates:: sage: V = QQ^3 - sage: W = V.span([[1,2,3],[4,5,6]]) + sage: W = V.span([[1,2,3], [4,5,6]]) sage: W Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: @@ -1629,7 +1630,7 @@ def __init__(self, ambient, gens, inner_product_matrix, check=True, already_eche EXAMPLES:: sage: V = QQ^3 - sage: W = V.span([[1,2,3],[4,5,6]]) + sage: W = V.span([[1,2,3], [4,5,6]]) sage: W Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: @@ -1646,7 +1647,7 @@ def _repr_(self): EXAMPLES:: - sage: V = VectorSpace(QQ,5) + sage: V = VectorSpace(QQ, 5) sage: U = V.submodule([ V.gen(i) - V.gen(0) for i in range(1,5) ]) sage: U # indirect doctest Vector space of degree 5 and dimension 4 over Rational Field @@ -1679,7 +1680,7 @@ def _repr_(self): Sparse vector spaces print this fact:: - sage: V = VectorSpace(QQ,5,sparse=True) + sage: V = VectorSpace(QQ, 5, sparse=True) sage: U = V.submodule([ V.gen(i) - V.gen(0) for i in range(1,5) ]) sage: U # indirect doctest Sparse vector space of degree 5 and dimension 4 over Rational Field diff --git a/src/sage/modules/free_quadratic_module_integer_symmetric.py b/src/sage/modules/free_quadratic_module_integer_symmetric.py index cc1576ab626..12927d76fcd 100644 --- a/src/sage/modules/free_quadratic_module_integer_symmetric.py +++ b/src/sage/modules/free_quadratic_module_integer_symmetric.py @@ -155,7 +155,7 @@ def IntegralLattice(data, basis=None): (see :mod:`Cartan types ` and :class:`CartanMatrix`):: - sage: IntegralLattice(["E", 7]) + sage: IntegralLattice(["E", 7]) # optional - sage.combinat Lattice of degree 7 and rank 7 over Integer Ring Standard basis Inner product matrix: @@ -166,20 +166,20 @@ def IntegralLattice(data, basis=None): [ 0 0 0 -1 2 -1 0] [ 0 0 0 0 -1 2 -1] [ 0 0 0 0 0 -1 2] - sage: IntegralLattice(["A", 2]) + sage: IntegralLattice(["A", 2]) # optional - sage.combinat Lattice of degree 2 and rank 2 over Integer Ring Standard basis Inner product matrix: [ 2 -1] [-1 2] - sage: IntegralLattice("D3") + sage: IntegralLattice("D3") # optional - sage.combinat Lattice of degree 3 and rank 3 over Integer Ring Standard basis Inner product matrix: [ 2 -1 -1] [-1 2 0] [-1 0 2] - sage: IntegralLattice(["D", 4]) + sage: IntegralLattice(["D", 4]) # optional - sage.combinat Lattice of degree 4 and rank 4 over Integer Ring Standard basis Inner product matrix: @@ -199,7 +199,7 @@ def IntegralLattice(data, basis=None): Inner product matrix: [0 1] [1 0] - sage: IntegralLattice(["A", 3], [[1,1,1]]) + sage: IntegralLattice(["A", 3], [[1,1,1]]) # optional - sage.combinat Lattice of degree 3 and rank 1 over Integer Ring Basis matrix: [1 1 1] @@ -212,7 +212,7 @@ def IntegralLattice(data, basis=None): Basis matrix: [1 1 1 1] Standard scalar product - sage: IntegralLattice("A2", [[1,1]]) + sage: IntegralLattice("A2", [[1,1]]) # optional - sage.combinat Lattice of degree 2 and rank 1 over Integer Ring Basis matrix: [1 1] @@ -222,11 +222,11 @@ def IntegralLattice(data, basis=None): TESTS:: - sage: IntegralLattice(["A", 1, 1]) + sage: IntegralLattice(["A", 1, 1]) # optional - sage.combinat Traceback (most recent call last): ... ValueError: lattices must be nondegenerate; use FreeQuadraticModule instead - sage: IntegralLattice(["D", 3, 1]) + sage: IntegralLattice(["D", 3, 1]) # optional - sage.combinat Traceback (most recent call last): ... ValueError: lattices must be nondegenerate; use FreeQuadraticModule instead @@ -272,11 +272,11 @@ def IntegralLatticeDirectSum(Lattices, return_embeddings=False): EXAMPLES:: sage: from sage.modules.free_quadratic_module_integer_symmetric import IntegralLatticeDirectSum - sage: L1 = IntegralLattice("D4") - sage: L2 = IntegralLattice("A3", [[1, 1, 2]]) - sage: L3 = IntegralLattice("A4", [[0, 1, 1, 2], [1, 2, 3, 1]]) - sage: Lattices = [L1, L2, L3] - sage: IntegralLatticeDirectSum([L1, L2, L3]) + sage: L1 = IntegralLattice("D4") # optional - sage.combinat + sage: L2 = IntegralLattice("A3", [[1, 1, 2]]) # optional - sage.combinat + sage: L3 = IntegralLattice("A4", [[0, 1, 1, 2], [1, 2, 3, 1]]) # optional - sage.combinat + sage: Lattices = [L1, L2, L3] # optional - sage.combinat + sage: IntegralLatticeDirectSum([L1, L2, L3]) # optional - sage.combinat Lattice of degree 11 and rank 7 over Integer Ring Basis matrix: [1 0 0 0 0 0 0 0 0 0 0] @@ -298,17 +298,17 @@ def IntegralLatticeDirectSum(Lattices, return_embeddings=False): [ 0 0 0 0 0 0 0 -1 2 -1 0] [ 0 0 0 0 0 0 0 0 -1 2 -1] [ 0 0 0 0 0 0 0 0 0 -1 2] - sage: [L, phi] = IntegralLatticeDirectSum([L1, L2, L3], True) - sage: LL3 = L.sublattice(phi[2].image().basis_matrix()) - sage: L3.discriminant() == LL3.discriminant() + sage: [L, phi] = IntegralLatticeDirectSum([L1, L2, L3], True) # optional - sage.combinat + sage: LL3 = L.sublattice(phi[2].image().basis_matrix()) # optional - sage.combinat + sage: L3.discriminant() == LL3.discriminant() # optional - sage.combinat True - sage: x = L3([1, 2, 3, 1]) - sage: phi[2](x).inner_product(phi[2](x)) == x.inner_product(x) + sage: x = L3([1, 2, 3, 1]) # optional - sage.combinat + sage: phi[2](x).inner_product(phi[2](x)) == x.inner_product(x) # optional - sage.combinat True TESTS:: - sage: IntegralLatticeDirectSum([IntegralLattice("D4")]) + sage: IntegralLatticeDirectSum([IntegralLattice("D4")]) # optional - sage.combinat Lattice of degree 4 and rank 4 over Integer Ring Standard basis Inner product matrix: @@ -318,9 +318,9 @@ def IntegralLatticeDirectSum(Lattices, return_embeddings=False): [ 0 -1 0 2] sage: L1 = IntegralLattice(2 * matrix.identity(2), [[1/2, 1/2]]) - sage: L2 = IntegralLattice("A3", [[1, 1, 2]]) - sage: [L, phi] = IntegralLatticeDirectSum([L1, L2], True) - sage: L + sage: L2 = IntegralLattice("A3", [[1, 1, 2]]) # optional - sage.combinat + sage: [L, phi] = IntegralLatticeDirectSum([L1, L2], True) # optional - sage.combinat + sage: L # optional - sage.combinat Lattice of degree 5 and rank 2 over Integer Ring Basis matrix: [1/2 1/2 0 0 0] @@ -416,18 +416,18 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): Inner product matrix: [4]]] - sage: L1 = IntegralLattice([[2]]) - sage: L2 = IntegralLattice([[2]]) - sage: AL1 = L1.discriminant_group() - sage: AL2 = L2.discriminant_group() - sage: AL1 + sage: L1 = IntegralLattice([[2]]) # optional - sage.combinat + sage: L2 = IntegralLattice([[2]]) # optional - sage.combinat + sage: AL1 = L1.discriminant_group() # optional - sage.combinat + sage: AL2 = L2.discriminant_group() # optional - sage.combinat + sage: AL1 # optional - sage.combinat Finite quadratic module over Integer Ring with invariants (2,) Gram matrix of the quadratic form with values in Q/2Z: [1/2] - sage: g1 = L1.discriminant_group().gens()[0] - sage: g2 = L2.discriminant_group().gens()[0] - sage: glue = [[g1, g2]] - sage: IntegralLatticeGluing([L1, L2], glue) + sage: g1 = L1.discriminant_group().gens()[0] # optional - sage.combinat + sage: g2 = L2.discriminant_group().gens()[0] # optional - sage.combinat + sage: glue = [[g1, g2]] # optional - sage.combinat + sage: IntegralLatticeGluing([L1, L2], glue) # optional - sage.combinat Lattice of degree 2 and rank 2 over Integer Ring Basis matrix: [1/2 1/2] @@ -436,13 +436,13 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): [2 0] [0 2] - sage: L1 = IntegralLattice("A4") - sage: L2 = IntegralLattice("A4") - sage: g1 = L1.discriminant_group().gens()[0] - sage: g2 = L2.discriminant_group().gens()[0] - sage: glue = [[g1, 2 * g2]] - sage: [V, phi] = IntegralLatticeGluing([L1, L2], glue, True) - sage: V + sage: L1 = IntegralLattice("A4") # optional - sage.combinat + sage: L2 = IntegralLattice("A4") # optional - sage.combinat + sage: g1 = L1.discriminant_group().gens()[0] # optional - sage.combinat + sage: g2 = L2.discriminant_group().gens()[0] # optional - sage.combinat + sage: glue = [[g1, 2 * g2]] # optional - sage.combinat + sage: [V, phi] = IntegralLatticeGluing([L1, L2], glue, True) # optional - sage.combinat + sage: V # optional - sage.combinat Lattice of degree 8 and rank 8 over Integer Ring Basis matrix: [1/5 2/5 3/5 4/5 2/5 4/5 1/5 3/5] @@ -462,7 +462,7 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): [ 0 0 0 0 -1 2 -1 0] [ 0 0 0 0 0 -1 2 -1] [ 0 0 0 0 0 0 -1 2] - sage: V.sublattice(phi[0].image().basis_matrix()) + sage: V.sublattice(phi[0].image().basis_matrix()) # optional - sage.combinat Lattice of degree 8 and rank 4 over Integer Ring Basis matrix: [1 0 0 0 0 0 0 0] @@ -481,8 +481,8 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): Different gluings can be composed:: - sage: D4 = IntegralLattice("D4") - sage: D4.discriminant_group() + sage: D4 = IntegralLattice("D4") # optional - sage.combinat + sage: D4.discriminant_group() # optional - sage.combinat Finite quadratic module over Integer Ring with invariants (2, 2) Gram matrix of the quadratic form with values in Q/2Z: [ 1 1/2] @@ -493,23 +493,23 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): Gram matrix of the quadratic form with values in Q/2Z: [1/2 0] [ 0 1/2] - sage: g1 = D4.discriminant_group().gens()[0] + sage: g1 = D4.discriminant_group().gens()[0] # optional - sage.combinat sage: g2 = L2.discriminant_group().gens()[0] + L2.discriminant_group().gens()[1] - sage: D6, phi = IntegralLatticeGluing([D4, L2], [[g1, g2]], True) - sage: AD6 = D6.discriminant_group() - sage: AD6.normal_form() + sage: D6, phi = IntegralLatticeGluing([D4, L2], [[g1, g2]], True) # optional - sage.combinat + sage: AD6 = D6.discriminant_group() # optional - sage.combinat + sage: AD6.normal_form() # optional - sage.combinat Finite quadratic module over Integer Ring with invariants (2, 2) Gram matrix of the quadratic form with values in Q/2Z: [3/2 0] [ 0 3/2] - sage: f1, g1 = AD6.normal_form().gens() + sage: f1, g1 = AD6.normal_form().gens() # optional - sage.combinat sage: f2, g2 = L2.discriminant_group().gens() - sage: E8, psi = IntegralLatticeGluing([D6, L2], [[f1, f2], [g1, g2]], True) - sage: D4embed = E8.sublattice(psi[0](phi[0].image()).basis_matrix()) - sage: x = D4([1, 0, 0, 0]) - sage: psi[0](phi[0](x)).inner_product(psi[0](phi[0](x)))==x.inner_product(x) + sage: E8, psi = IntegralLatticeGluing([D6, L2], [[f1, f2], [g1, g2]], True) # optional - sage.combinat + sage: D4embed = E8.sublattice(psi[0](phi[0].image()).basis_matrix()) # optional - sage.combinat + sage: x = D4([1, 0, 0, 0]) # optional - sage.combinat + sage: psi[0](phi[0](x)).inner_product(psi[0](phi[0](x))) == x.inner_product(x) # optional - sage.combinat True - sage: D4embed + sage: D4embed # optional - sage.combinat Lattice of degree 8 and rank 4 over Integer Ring Basis matrix: [1 0 0 0 0 0 0 0] @@ -528,27 +528,28 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): The input may be a list of three or more lattices:: - sage: A7 = IntegralLattice("A7") - sage: D5 = IntegralLattice("D5") - sage: gA7 = A7.discriminant_group().gens()[0] - sage: gD5 = D5.discriminant_group().gens()[0] - sage: [L, phi] = IntegralLatticeGluing([A7, A7, D5, D5], + sage: A7 = IntegralLattice("A7") # optional - sage.combinat + sage: D5 = IntegralLattice("D5") # optional - sage.combinat + sage: gA7 = A7.discriminant_group().gens()[0] # optional - sage.combinat + sage: gD5 = D5.discriminant_group().gens()[0] # optional - sage.combinat + sage: [L, phi] = IntegralLatticeGluing([A7, A7, D5, D5], # optional - sage.combinat ....: [[gA7, gA7, gD5, 2 * gD5], ....: [gA7, 7 * gA7, 2 * gD5, gD5]], True) - sage: L.determinant() + sage: L.determinant() # optional - sage.combinat 1 - sage: B = phi[0].matrix() - sage: B*L.gram_matrix()*B.transpose()==A7.gram_matrix() + sage: B = phi[0].matrix() # optional - sage.combinat + sage: B*L.gram_matrix()*B.transpose() == A7.gram_matrix() # optional - sage.combinat True The gluing takes place in the direct sum of the respective ambient spaces:: - sage: L1 = IntegralLattice("D4", [[1, 1, 0, 0], [0, 1, 1, 0]]) - sage: L2 = IntegralLattice("E6", [[0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1]]) - sage: [f1, f2] = L1.discriminant_group().gens() - sage: [g1, g2] = L2.discriminant_group().gens() - sage: [L, phi] = IntegralLatticeGluing([L1, L2], [[f1, g1], [f2, 2 * g2]], True) - sage: phi[0] + sage: L1 = IntegralLattice("D4", [[1, 1, 0, 0], [0, 1, 1, 0]]) # optional - sage.combinat + sage: L2 = IntegralLattice("E6", [[0, 2, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1]]) # optional - sage.combinat + sage: [f1, f2] = L1.discriminant_group().gens() # optional - sage.combinat + sage: [g1, g2] = L2.discriminant_group().gens() # optional - sage.combinat + sage: [L, phi] = IntegralLatticeGluing([L1, L2], # optional - sage.combinat + ....: [[f1, g1], [f2, 2 * g2]], True) + sage: phi[0] # optional - sage.combinat Free module morphism defined by the matrix [ 2 2 -2 -1] [ 0 2 -1 0] @@ -578,8 +579,8 @@ def IntegralLatticeGluing(Lattices, glue, return_embeddings=False): [ 0 0 0 0 0 -1 -1 2 -1 0] [ 0 0 0 0 0 0 0 -1 2 -1] [ 0 0 0 0 0 0 0 0 -1 2] - sage: B = phi[0].matrix() - sage: B * L.gram_matrix() * B.transpose()==L1.gram_matrix() + sage: B = phi[0].matrix() # optional - sage.combinat + sage: B * L.gram_matrix() * B.transpose() == L1.gram_matrix() # optional - sage.combinat True """ [direct_sum, phi] = IntegralLatticeDirectSum(Lattices, return_embeddings=True) @@ -623,7 +624,7 @@ class FreeQuadraticModule_integer_symmetric(FreeQuadraticModule_submodule_with_b EXAMPLES:: - sage: IntegralLattice("U",basis=[vector([1,1])]) + sage: IntegralLattice("U", basis=[vector([1,1])]) Lattice of degree 2 and rank 1 over Integer Ring Basis matrix: [1 1] @@ -695,8 +696,8 @@ def _repr_(self): EXAMPLES:: - sage: A2 = IntegralLattice("A2") - sage: A2 + sage: A2 = IntegralLattice("A2") # optional - sage.combinat + sage: A2 # optional - sage.combinat Lattice of degree 2 and rank 2 over Integer Ring Standard basis Inner product matrix: @@ -731,7 +732,7 @@ def is_even(self): sage: L = IntegralLattice(G) sage: L.is_even() False - sage: L = IntegralLattice("A2") + sage: L = IntegralLattice("A2") # optional - sage.combinat sage: L.is_even() True """ @@ -759,7 +760,7 @@ def dual_lattice(self): Since our lattices are always integral, a lattice is contained in its dual:: - sage: L.is_submodule(Ldual) + sage: L.is_submodule(Ldual) # optional - sage.combinat True """ return self.span(self.gram_matrix().inverse()*self.basis_matrix()) @@ -811,9 +812,9 @@ def discriminant_group(self, s=0): sage: for k in range(1,500): # long time ....: G = L.twist(k) ....: D = G.discriminant_group() - sage: tmp = gc.collect() - sage: tmp = gc.collect() - sage: len([a for a in gc.get_objects() if type(a)==type(L)])<=300 + sage: tmp = gc.collect() # optional - sage.combinat + sage: tmp = gc.collect() # optional - sage.combinat + sage: len([a for a in gc.get_objects() if type(a) == type(L)]) <= 300 # optional - sage.combinat True sage: gc.unfreeze() """ @@ -1029,12 +1030,12 @@ def maximal_overlattice(self, p=None): EXAMPLES:: - sage: L = IntegralLattice("A4").twist(25*89) - sage: L.maximal_overlattice().determinant() + sage: L = IntegralLattice("A4").twist(25*89) # optional - sage.combinat + sage: L.maximal_overlattice().determinant() # optional - sage.combinat 5 - sage: L.maximal_overlattice(89).determinant().factor() + sage: L.maximal_overlattice(89).determinant().factor() # optional - sage.combinat 5^9 - sage: L.maximal_overlattice(5).determinant().factor() + sage: L.maximal_overlattice(5).determinant().factor() # optional - sage.combinat 5 * 89^4 TESTS:: @@ -1181,24 +1182,24 @@ def orthogonal_group(self, gens=None, is_finite=None): [ 0 0 1 0] [ 0 0 -1 -1] [ 0 1 1 1] - sage: x*g + sage: x*g # optional - sage.combinat (-1, -1, -1, 0) sage: (x*g).parent() == A4 True - sage: (g*x).parent() + sage: (g*x).parent() # optional - sage.combinat Vector space of dimension 4 over Rational Field - sage: y = A4.discriminant_group().an_element() - sage: y*g + sage: y = A4.discriminant_group().an_element() # optional - sage.combinat + sage: y*g # optional - sage.combinat (4) If the group is finite we can compute the usual things:: - sage: Aut.order() + sage: Aut.order() # optional - sage.combinat 240 - sage: conj = Aut.conjugacy_classes_representatives() - sage: len(conj) + sage: conj = Aut.conjugacy_classes_representatives() # optional - sage.combinat + sage: len(conj) # optional - sage.combinat 14 - sage: Aut.structure_description() + sage: Aut.structure_description() # optional - sage.combinat 'C2 x S5' The lattice can live in a larger ambient space:: @@ -1342,7 +1343,7 @@ def tensor_product(self, other, discard_basis=False): [-2 1 1 0 0 0 4 -2 -2] [ 1 -2 0 0 0 0 -2 4 0] [ 1 0 -2 0 0 0 -2 0 4] - sage: L1.gram_matrix() + sage: L1.gram_matrix() # optional - sage.combinat [ 36 -12 -12 4] [-12 24 4 -8] [-12 4 24 -8] @@ -1398,10 +1399,10 @@ def minimum(self): EXAMPLES:: - sage: L = IntegralLattice('A2') - sage: L.minimum() + sage: L = IntegralLattice('A2') # optional - sage.combinat + sage: L.minimum() # optional - sage.combinat 2 - sage: L.twist(-1).minimum() + sage: L.twist(-1).minimum() # optional - sage.combinat -Infinity """ p, n = self.signature_pair() @@ -1424,10 +1425,10 @@ def maximum(self): EXAMPLES:: - sage: L = IntegralLattice('A2') - sage: L.maximum() + sage: L = IntegralLattice('A2') # optional - sage.combinat + sage: L.maximum() # optional - sage.combinat +Infinity - sage: L.twist(-1).maximum() + sage: L.twist(-1).maximum() # optional - sage.combinat -2 """ if self.rank() == 0: @@ -1448,8 +1449,8 @@ def LLL(self): EXAMPLES:: - sage: L = IntegralLattice('A2') - sage: L.lll() == L + sage: L = IntegralLattice('A2') # optional - sage.combinat + sage: L.lll() == L # optional - sage.combinat True sage: G = matrix(ZZ, 3, [0,1,0, 1,0,0, 0,0,7]) sage: V = matrix(ZZ, 3, [-14,-15,-15, -4,1,16, -5,-5,-4]) @@ -1495,10 +1496,10 @@ def short_vectors(self, n, **kwargs): EXAMPLES:: - sage: A2 = IntegralLattice('A2') - sage: A2.short_vectors(3) + sage: A2 = IntegralLattice('A2') # optional - sage.combinat + sage: A2.short_vectors(3) # optional - sage.combinat [[(0, 0)], [], [(1, 1), (-1, -1), (0, 1), (0, -1), (1, 0), (-1, 0)]] - sage: A2.short_vectors(3,up_to_sign_flag=True) + sage: A2.short_vectors(3,up_to_sign_flag=True) # optional - sage.combinat [[(0, 0)], [], [(1, 1), (0, 1), (1, 0)]] """ p, m = self.signature_pair() @@ -1525,8 +1526,8 @@ def twist(self, s, discard_basis=False): EXAMPLES:: - sage: L = IntegralLattice("A4") - sage: L.twist(3) + sage: L = IntegralLattice("A4") # optional - sage.combinat + sage: L.twist(3) # optional - sage.combinat Lattice of degree 4 and rank 4 over Integer Ring Standard basis Inner product matrix: @@ -1588,15 +1589,15 @@ def local_modification(M, G, p, check=True): EXAMPLES:: sage: from sage.modules.free_quadratic_module_integer_symmetric import local_modification - sage: L = IntegralLattice("A3").twist(15) - sage: M = L.maximal_overlattice() - sage: for p in prime_divisors(L.determinant()): + sage: L = IntegralLattice("A3").twist(15) # optional - sage.combinat + sage: M = L.maximal_overlattice() # optional - sage.combinat + sage: for p in prime_divisors(L.determinant()): # optional - sage.combinat ....: M = local_modification(M, L.gram_matrix(), p) - sage: M.genus() == L.genus() + sage: M.genus() == L.genus() # optional - sage.combinat True - sage: L = IntegralLattice("D4").twist(3*4) - sage: M = L.maximal_overlattice() - sage: local_modification(M, L.gram_matrix(), 2) + sage: L = IntegralLattice("D4").twist(3*4) # optional - sage.combinat + sage: M = L.maximal_overlattice() # optional - sage.combinat + sage: local_modification(M, L.gram_matrix(), 2) # optional - sage.combinat Lattice of degree 4 and rank 4 over Integer Ring Basis matrix: [1/3 0 2/3 2/3] diff --git a/src/sage/modules/matrix_morphism.py b/src/sage/modules/matrix_morphism.py index 94069fcc603..4c68b029ec4 100644 --- a/src/sage/modules/matrix_morphism.py +++ b/src/sage/modules/matrix_morphism.py @@ -21,13 +21,13 @@ [0 0 1] sage: is_MatrixMorphism(m) True - sage: m.charpoly('x') + sage: m.charpoly('x') # optional - sage.libs.pari x^3 - 3*x^2 + 3*x - 1 sage: m.base_ring() Rational Field sage: m.det() 1 - sage: m.fcp('x') + sage: m.fcp('x') # optional - sage.libs.pari (x - 1)^3 sage: m.matrix() [1 0 0] @@ -523,9 +523,9 @@ def __mul__(self, right): Composite maps can be formed with matrix morphisms:: - sage: K. = NumberField(x^2 + 23) - sage: V, VtoK, KtoV = K.vector_space() - sage: f = V.hom([V.0 - V.1, V.0 + V.1])*KtoV; f + sage: K. = NumberField(x^2 + 23) # optional - sage.rings.number_field + sage: V, VtoK, KtoV = K.vector_space() # optional - sage.rings.number_field + sage: f = V.hom([V.0 - V.1, V.0 + V.1])*KtoV; f # optional - sage.rings.number_field Composite map: From: Number Field in a with defining polynomial x^2 + 23 To: Vector space of dimension 2 over Rational Field @@ -538,9 +538,9 @@ def __mul__(self, right): [ 1 1] Domain: Vector space of dimension 2 over Rational Field Codomain: Vector space of dimension 2 over Rational Field - sage: f(a) + sage: f(a) # optional - sage.rings.number_field (1, 1) - sage: V.hom([V.0 - V.1, V.0 + V.1], side="right")*KtoV + sage: V.hom([V.0 - V.1, V.0 + V.1], side="right")*KtoV # optional - sage.rings.number_field Composite map: From: Number Field in a with defining polynomial x^2 + 23 To: Vector space of dimension 2 over Rational Field @@ -835,7 +835,7 @@ def decomposition(self, *args, **kwds): EXAMPLES:: sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1]) - sage: phi.decomposition() + sage: phi.decomposition() # optional - sage.libs.pari [ Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: @@ -845,7 +845,7 @@ def decomposition(self, *args, **kwds): [ 1 -1] ] sage: phi2 = V.hom(phi.matrix(), side="right") - sage: phi2.decomposition() + sage: phi2.decomposition() # optional - sage.libs.pari [ Free module of degree 2 and rank 1 over Integer Ring Echelon basis matrix: @@ -878,7 +878,7 @@ def trace(self): EXAMPLES:: - sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1]) + sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.trace() 3 """ @@ -890,7 +890,7 @@ def det(self): EXAMPLES:: - sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1]) + sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi.det() 2 """ @@ -904,10 +904,10 @@ def fcp(self, var='x'): EXAMPLES:: - sage: V = ZZ^2; phi = V.hom([V.0+V.1, 2*V.1]) - sage: phi.fcp() + sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1]) + sage: phi.fcp() # optional - sage.libs.pari (x - 2) * (x - 1) - sage: phi.fcp('T') + sage: phi.fcp('T') # optional - sage.libs.pari (T - 2) * (T - 1) """ return self.charpoly(var).factor() @@ -918,14 +918,14 @@ def kernel(self): EXAMPLES:: - sage: V = VectorSpace(QQ,3) + sage: V = VectorSpace(QQ, 3) sage: id = V.Hom(V)(identity_matrix(QQ,3)) sage: null = V.Hom(V)(0*identity_matrix(QQ,3)) sage: id.kernel() Vector space of degree 3 and dimension 0 over Rational Field Basis matrix: [] - sage: phi = V.Hom(V)(matrix(QQ,3,range(9))) + sage: phi = V.Hom(V)(matrix(QQ, 3, range(9))) sage: phi.kernel() Vector space of degree 3 and dimension 1 over Rational Field Basis matrix: @@ -968,29 +968,29 @@ def image(self): EXAMPLES:: - sage: V = VectorSpace(QQ,3) + sage: V = VectorSpace(QQ, 3) sage: phi = V.Hom(V)(matrix(QQ, 3, range(9))) sage: phi.image() Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2] - sage: hom(GF(7)^3, GF(7)^2, zero_matrix(GF(7), 3, 2)).image() + sage: hom(GF(7)^3, GF(7)^2, zero_matrix(GF(7), 3, 2)).image() # optional - sage.libs.pari Vector space of degree 2 and dimension 0 over Finite Field of size 7 Basis matrix: [] - sage: m = matrix(3, [1, 0, 0, 1, 0, 0, 0, 0, 1]); m + sage: m = matrix(3, [1, 0, 0, 1, 0, 0, 0, 0, 1]); m # optional - sage.libs.pari [1 0 0] [1 0 0] [0 0 1] - sage: f1 = V.hom(m) - sage: f2 = V.hom(m, side="right") - sage: f1.image() + sage: f1 = V.hom(m) # optional - sage.libs.pari + sage: f2 = V.hom(m, side="right") # optional - sage.libs.pari + sage: f1.image() # optional - sage.libs.pari Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 0 0] [0 0 1] - sage: f2.image() + sage: f2.image() # optional - sage.libs.pari Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [1 1 0] @@ -999,7 +999,7 @@ def image(self): Compute the image of the identity map on a ZZ-submodule:: - sage: V = (ZZ^2).span([[1,2],[3,4]]) + sage: V = (ZZ^2).span([[1,2], [3,4]]) sage: phi = V.Hom(V)(identity_matrix(ZZ,2)) sage: phi(V.0) == V.0 True @@ -1520,8 +1520,8 @@ def restrict(self, sub): Codomain: Free module of degree 2 and rank 1 over Integer Ring Echelon ... - sage: V = (QQ^2).span_of_basis([[1,2],[3,4]]) - sage: phi = V.hom([V.0+V.1, 2*V.1]) + sage: V = (QQ^2).span_of_basis([[1,2], [3,4]]) + sage: phi = V.hom([V.0 + V.1, 2*V.1]) sage: phi(V.1) == 2*V.1 True sage: W = span([V.1]) @@ -1532,12 +1532,12 @@ def restrict(self, sub): sage: psi = phi.restrict(W); psi Vector space morphism represented by the matrix: [2] - Domain: Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [ 1 4/3] + Domain: Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: + [ 1 4/3] Codomain: Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [ 1 4/3] + Basis matrix: + [ 1 4/3] sage: psi.domain() == W True sage: psi(W.0) == 2*W.0 @@ -1553,26 +1553,26 @@ def restrict(self, sub): Free module morphism defined by the matrix [ 1 1] [-1 1] - Domain: Free module of degree 3 and rank 2 over Integer Ring - Echelon basis matrix: - [0 2 0] - [0 0 2] + Domain: Free module of degree 3 and rank 2 over Integer Ring + Echelon basis matrix: + [0 2 0] + [0 0 2] Codomain: Free module of degree 3 and rank 2 over Integer Ring - Echelon basis matrix: - [0 2 0] - [0 0 2] + Echelon basis matrix: + [0 2 0] + [0 0 2] sage: h2.restrict(SV) Free module morphism defined as left-multiplication by the matrix [ 1 -1] [ 1 1] - Domain: Free module of degree 3 and rank 2 over Integer Ring - Echelon basis matrix: - [0 2 0] - [0 0 2] + Domain: Free module of degree 3 and rank 2 over Integer Ring + Echelon basis matrix: + [0 2 0] + [0 0 2] Codomain: Free module of degree 3 and rank 2 over Integer Ring - Echelon basis matrix: - [0 2 0] - [0 0 2] + Echelon basis matrix: + [0 2 0] + [0 0 2] """ if not self.is_endomorphism(): raise ArithmeticError("matrix morphism must be an endomorphism") @@ -1617,7 +1617,7 @@ def __init__(self, parent, A, copy_matrix=True, side='left'): sage: from sage.modules.matrix_morphism import MatrixMorphism sage: T = End(ZZ^3) - sage: M = MatrixSpace(ZZ,3) + sage: M = MatrixSpace(ZZ, 3) sage: I = M.identity_matrix() sage: A = MatrixMorphism(T, I) sage: loads(A.dumps()) == A @@ -1706,10 +1706,10 @@ def is_injective(self): sage: V1 = QQ^2 sage: V2 = QQ^3 - sage: phi = V1.hom(Matrix([[1,2,3],[4,5,6]]),V2) + sage: phi = V1.hom(Matrix([[1,2,3], [4,5,6]]),V2) sage: phi.is_injective() True - sage: psi = V2.hom(Matrix([[1,2],[3,4],[5,6]]),V1) + sage: psi = V2.hom(Matrix([[1,2], [3,4], [5,6]]),V1) sage: psi.is_injective() False @@ -1731,19 +1731,19 @@ def is_surjective(self): sage: V1 = QQ^2 sage: V2 = QQ^3 - sage: phi = V1.hom(Matrix([[1,2,3],[4,5,6]]), V2) + sage: phi = V1.hom(Matrix([[1,2,3], [4,5,6]]), V2) sage: phi.is_surjective() False - sage: psi = V2.hom(Matrix([[1,2],[3,4],[5,6]]), V1) + sage: psi = V2.hom(Matrix([[1,2], [3,4], [5,6]]), V1) sage: psi.is_surjective() True An example over a PID that is not `\ZZ`. :: - sage: R = PolynomialRing(QQ, 'x') + sage: R. = PolynomialRing(QQ) sage: A = R^2 sage: B = R^2 - sage: H = A.hom([B([x^2-1, 1]), B([x^2, 1])]) + sage: H = A.hom([B([x^2 - 1, 1]), B([x^2, 1])]) sage: H.image() Free module of degree 2 and rank 2 over Univariate Polynomial Ring in x over Rational Field Echelon basis matrix: @@ -1755,7 +1755,7 @@ def is_surjective(self): This tests if :trac:`11552` is fixed. :: sage: V = ZZ^2 - sage: m = matrix(ZZ, [[1,2],[0,2]]) + sage: m = matrix(ZZ, [[1,2], [0,2]]) sage: phi = V.hom(m, V) sage: phi.lift(vector(ZZ, [0, 1])) Traceback (most recent call last): diff --git a/src/sage/modules/quotient_module.py b/src/sage/modules/quotient_module.py index 10db2189997..59fa0503f44 100644 --- a/src/sage/modules/quotient_module.py +++ b/src/sage/modules/quotient_module.py @@ -47,10 +47,10 @@ class QuotientModule_free_ambient(Module_free_ambient): sage: N = M.submodule([vector([x - y, z]), vector([y*z, x*z])]) sage: M.quotient_module(N) Quotient module by Submodule of Ambient free module of rank 2 over - the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field - Generated by the rows of the matrix: - [x - y z] - [ y*z x*z] + the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field + Generated by the rows of the matrix: + [x - y z] + [ y*z x*z] """ def __init__(self, module, sub): """ @@ -96,10 +96,10 @@ def _repr_(self): sage: N = M.submodule([vector([x - y, z]), vector([y*z , x*z])]) sage: M.quotient_module(N) Quotient module by Submodule of Ambient free module of rank 2 over - the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field - Generated by the rows of the matrix: - [x - y z] - [ y*z x*z] + the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field + Generated by the rows of the matrix: + [x - y z] + [ y*z x*z] """ return "Quotient module by %s" % self._sub @@ -163,12 +163,12 @@ def _coerce_map_from_(self, M): sage: Q.coerce_map_from(M) Coercion map: From: Ambient free module of rank 2 over the integral domain - Multivariate Polynomial Ring in x, y, z over Rational Field - To: Quotient module by Submodule of Ambient free module of rank 2 - over the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field - Generated by the rows of the matrix: - [x - y z] - [ y*z x*z] + Multivariate Polynomial Ring in x, y, z over Rational Field + To: Quotient module by Submodule of Ambient free module of rank 2 over the + integral domain Multivariate Polynomial Ring in x, y, z over Rational Field + Generated by the rows of the matrix: + [x - y z] + [ y*z x*z] """ if isinstance(M, FreeModule_ambient): return (self.base_ring().has_coerce_map_from(M.base_ring()) and @@ -277,11 +277,12 @@ def free_relations(self): sage: NQ = Q.submodule([Q([1, x])]) sage: QNQ = Q / NQ sage: QNQ.free_relations() - Submodule of Ambient free module of rank 2 over the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field - Generated by the rows of the matrix: - [ 1 x] - [x - y z] - [ y*z x*z] + Submodule of Ambient free module of rank 2 over the integral domain + Multivariate Polynomial Ring in x, y, z over Rational Field + Generated by the rows of the matrix: + [ 1 x] + [x - y z] + [ y*z x*z] Note that this is different than the defining relations:: @@ -307,45 +308,54 @@ class FreeModule_ambient_field_quotient(FreeModule_ambient_field): EXAMPLES:: - sage: k. = QuadraticField(-1) - sage: A = k^3; V = A.span([[1,0,i], [2,i,0]]) - sage: W = A.span([[3,i,i]]) - sage: U = V/W; U - Vector space quotient V/W of dimension 1 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I where - V: Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I - Basis matrix: - [ 1 0 i] - [ 0 1 -2] - W: Vector space of degree 3 and dimension 1 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I - Basis matrix: - [ 1 1/3*i 1/3*i] - sage: U.V() - Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I + sage: k. = QuadraticField(-1) # optional - sage.rings.number_field + sage: A = k^3; V = A.span([[1,0,i], [2,i,0]]) # optional - sage.rings.number_field + sage: W = A.span([[3,i,i]]) # optional - sage.rings.number_field + sage: U = V/W; U # optional - sage.rings.number_field + Vector space quotient V/W of dimension 1 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I where + V: Vector space of degree 3 and dimension 2 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + Basis matrix: + [ 1 0 i] + [ 0 1 -2] + W: Vector space of degree 3 and dimension 1 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + Basis matrix: + [ 1 1/3*i 1/3*i] + sage: U.V() # optional - sage.rings.number_field + Vector space of degree 3 and dimension 2 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I Basis matrix: [ 1 0 i] [ 0 1 -2] - sage: U.W() - Vector space of degree 3 and dimension 1 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I + sage: U.W() # optional - sage.rings.number_field + Vector space of degree 3 and dimension 1 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I Basis matrix: [ 1 1/3*i 1/3*i] - sage: U.quotient_map() + sage: U.quotient_map() # optional - sage.rings.number_field Vector space morphism represented by the matrix: [ 1] [3*i] - Domain: Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I - Basis matrix: - [ 1 0 i] - [ 0 1 -2] - Codomain: Vector space quotient V/W of dimension 1 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I where - V: Vector space of degree 3 and dimension 2 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I - Basis matrix: - [ 1 0 i] - [ 0 1 -2] - W: Vector space of degree 3 and dimension 1 over Number Field in i with defining polynomial x^2 + 1 with i = 1*I - Basis matrix: - [ 1 1/3*i 1/3*i] - sage: Z = V.quotient(W) - sage: Z == U + Domain: Vector space of degree 3 and dimension 2 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + Basis matrix: + [ 1 0 i] + [ 0 1 -2] + Codomain: Vector space quotient V/W of dimension 1 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I where + V: Vector space of degree 3 and dimension 2 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + Basis matrix: + [ 1 0 i] + [ 0 1 -2] + W: Vector space of degree 3 and dimension 1 over Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + Basis matrix: + [ 1 1/3*i 1/3*i] + sage: Z = V.quotient(W) # optional - sage.rings.number_field + sage: Z == U # optional - sage.rings.number_field True We create three quotient spaces and compare them:: @@ -406,7 +416,7 @@ def __init__(self, domain, sub, quotient_matrix, lift_matrix, inner_product_matr sage: Q(V.0) (1) - sage: Q( V.0 - 2/3*V.1 ) + sage: Q(V.0 - 2/3*V.1) (0) sage: v = Q.lift(Q.0); v (1, 0, -1, 1, 1) @@ -432,19 +442,19 @@ def _repr_(self): We create a quotient vector space over a finite field:: - sage: k. = GF(9); A = k^3; V = A.span_of_basis([[1,0,a], [a,a,1]]); W = V.span([V.1]) - sage: Q = V/W + sage: k. = GF(9); A = k^3; V = A.span_of_basis([[1,0,a], [a,a,1]]); W = V.span([V.1]) # optional - sage.libs.pari + sage: Q = V/W # optional - sage.libs.pari Note the type:: - sage: type(Q) + sage: type(Q) # optional - sage.libs.pari The string representation mentions that this is a quotient `V/W`, that the quotient has dimension 1 and is over a finite field, and also describes `V` and `W`:: - sage: Q._repr_() + sage: Q._repr_() # optional - sage.libs.pari 'Vector space quotient V/W of dimension 1 over Finite Field in a of size 3^2 where\nV: Vector space of degree 3 and dimension 2 over Finite Field in a of size 3^2\nUser basis matrix:\n[1 0 a]\n[a a 1]\nW: Vector space of degree 3 and dimension 1 over Finite Field in a of size 3^2\nBasis matrix:\n[ 1 1 a + 2]' """ return "%s space quotient V/W of dimension %s over %s where\nV: %s\nW: %s" % ( @@ -539,23 +549,23 @@ def _coerce_map_from_(self, M): Composite map: From: Ambient free module of rank 2 over the principal ideal domain Integer Ring To: Vector space quotient V/W of dimension 1 over Rational Field where - V: Vector space of dimension 2 over Rational Field - W: Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [1 2] + V: Vector space of dimension 2 over Rational Field + W: Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: + [1 2] Defn: Coercion map: From: Ambient free module of rank 2 over the principal ideal domain Integer Ring To: Vector space of dimension 2 over Rational Field then Vector space morphism represented by the matrix: - [ 1] - [-1/2] - Domain: Vector space of dimension 2 over Rational Field - Codomain: Vector space quotient V/W of dimension 1 over Rational Field where - V: Vector space of dimension 2 over Rational Field - W: Vector space of degree 2 and dimension 1 over Rational Field - Basis matrix: - [1 2] + [ 1] + [-1/2] + Domain: Vector space of dimension 2 over Rational Field + Codomain: Vector space quotient V/W of dimension 1 over Rational Field where + V: Vector space of dimension 2 over Rational Field + W: Vector space of degree 2 and dimension 1 over Rational Field + Basis matrix: + [1 2] Make sure :trac:`10513` is fixed (no coercion from an abstract vector space to an isomorphic quotient vector space):: @@ -592,12 +602,12 @@ def quotient_map(self): [ 1 0] [ 0 1] [-1/3 -2/3] - Domain: Vector space of dimension 3 over Rational Field + Domain: Vector space of dimension 3 over Rational Field Codomain: Vector space quotient V/W of dimension 2 over Rational Field where - V: Vector space of dimension 3 over Rational Field - W: Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [1 2 3] + V: Vector space of dimension 3 over Rational Field + W: Vector space of degree 3 and dimension 1 over Rational Field + Basis matrix: + [1 2 3] sage: M.quotient_map()( (QQ^3)([1,2,3]) ) (0, 0) @@ -616,11 +626,11 @@ def lift_map(self): Vector space morphism represented by the matrix: [1 0 0] [0 1 0] - Domain: Vector space quotient V/W of dimension 2 over Rational Field where - V: Vector space of dimension 3 over Rational Field - W: Vector space of degree 3 and dimension 1 over Rational Field - Basis matrix: - [1 2 3] + Domain: Vector space quotient V/W of dimension 2 over Rational Field where + V: Vector space of dimension 3 over Rational Field + W: Vector space of degree 3 and dimension 1 over Rational Field + Basis matrix: + [1 2 3] Codomain: Vector space of dimension 3 over Rational Field """ return self.__lift_map diff --git a/src/sage/modules/tensor_operations.py b/src/sage/modules/tensor_operations.py index fafd5cc3a89..808aa7237eb 100644 --- a/src/sage/modules/tensor_operations.py +++ b/src/sage/modules/tensor_operations.py @@ -119,7 +119,7 @@ def antisymmetrized_coordinate_sums(dim, n): EXAMPLES:: sage: from sage.modules.tensor_operations import antisymmetrized_coordinate_sums - sage: antisymmetrized_coordinate_sums(3, 2) + sage: antisymmetrized_coordinate_sums(3, 2) # optional - sage.groups ((0, 1) - (1, 0), (0, 2) - (2, 0), (1, 2) - (2, 1)) """ from sage.structure.formal_sum import FormalSum @@ -379,8 +379,8 @@ def _init_power_operation_vectors(self, i, linear_combinations): sage: Sym2_R = TensorOperation([R,R], operation='symmetric') sage: Sym2_R.vectors() # indirect doctest ((1, 0, 0), (1, 2, 0), (-1, -2, 0), (1, 4, 4), (-1, -4, -4)) - sage: Alt2_R = TensorOperation([R, R], operation='antisymmetric') - sage: Alt2_R.vectors() # indirect doctest + sage: Alt2_R = TensorOperation([R, R], operation='antisymmetric') # optional - sage.groups + sage: Alt2_R.vectors() # indirect doctest # optional - sage.groups ((2), (-2)) """ rays = [self._V[j].vectors()[k] for j, k in enumerate(i)] @@ -453,8 +453,8 @@ def _init_antisymmetric(self): sage: from sage.modules.tensor_operations import \ ....: VectorCollection, TensorOperation sage: R = VectorCollection([(1,0), (1,2), (-1,-2)], QQ, 2) - sage: Alt2_R = TensorOperation([R, R], operation='antisymmetric') # indirect doctest - sage: sorted(Alt2_R._index_map.items()) + sage: Alt2_R = TensorOperation([R, R], operation='antisymmetric') # indirect doctest # optional - sage.groups + sage: sorted(Alt2_R._index_map.items()) # optional - sage.groups [((0, 1), 0), ((0, 2), 1)] """ n = len(self._V) @@ -517,17 +517,17 @@ def index_map(self, *i): sage: from sage.modules.tensor_operations import \ ....: VectorCollection, TensorOperation sage: R = VectorCollection([(1,0), (0,1), (-2,-3)], QQ, 2) - sage: detR = TensorOperation([R]*2, 'antisymmetric') - sage: detR.index_map(1, 0) + sage: detR = TensorOperation([R]*2, 'antisymmetric') # optional - sage.groups + sage: detR.index_map(1, 0) # optional - sage.groups 0 - sage: detR.index_map(0, 1) + sage: detR.index_map(0, 1) # optional - sage.groups 0 TESTS:: - sage: sorted(detR._index_map.items()) + sage: sorted(detR._index_map.items()) # optional - sage.groups [((0, 1), 0), ((0, 2), 1), ((1, 2), 2)] - sage: detR.vectors() + sage: detR.vectors() # optional - sage.groups ((1), (-3), (2)) """ if len(i) == 1 and isinstance(i[0], (list, tuple)): @@ -553,10 +553,10 @@ def preimage(self): sage: from sage.modules.tensor_operations import \ ....: VectorCollection, TensorOperation sage: R = VectorCollection([(1,0), (0,1), (-2,-3)], QQ, 2) - sage: detR = TensorOperation([R]*2, 'antisymmetric') - sage: sorted(detR.preimage()) + sage: detR = TensorOperation([R]*2, 'antisymmetric') # optional - sage.groups + sage: sorted(detR.preimage()) # optional - sage.groups [(0, 1), (0, 2), (1, 2)] - sage: sorted(detR.codomain()) + sage: sorted(detR.codomain()) # optional - sage.groups [0, 1, 2] """ return self._index_map.keys() @@ -574,10 +574,10 @@ def codomain(self): sage: from sage.modules.tensor_operations import \ ....: VectorCollection, TensorOperation sage: R = VectorCollection([(1,0), (0,1), (-2,-3)], QQ, 2) - sage: detR = TensorOperation([R]*2, 'antisymmetric') - sage: sorted(detR.preimage()) + sage: detR = TensorOperation([R]*2, 'antisymmetric') # optional - sage.groups + sage: sorted(detR.preimage()) # optional - sage.groups [(0, 1), (0, 2), (1, 2)] - sage: sorted(detR.codomain()) + sage: sorted(detR.codomain()) # optional - sage.groups [0, 1, 2] """ return self._index_map.values() diff --git a/src/sage/modules/torsion_quadratic_module.py b/src/sage/modules/torsion_quadratic_module.py index 0f1a92d8c56..72147fe115f 100644 --- a/src/sage/modules/torsion_quadratic_module.py +++ b/src/sage/modules/torsion_quadratic_module.py @@ -165,7 +165,7 @@ def quadratic_product(self): sage: from sage.modules.torsion_quadratic_module import TorsionQuadraticModule sage: W = FreeQuadraticModule(ZZ, 2, 2*matrix.identity(2)) sage: V = (1/2) * W - sage: T = TorsionQuadraticModule(V,W) + sage: T = TorsionQuadraticModule(V, W) sage: x = T.gen(0) sage: x (1, 0) @@ -375,8 +375,8 @@ def all_submodules(self): EXAMPLES:: - sage: D = IntegralLattice("D4").discriminant_group() - sage: D.all_submodules() + sage: D = IntegralLattice("D4").discriminant_group() # optional - sage.combinat + sage: D.all_submodules() # optional - sage.combinat [Finite quadratic module over Integer Ring with invariants () Gram matrix of the quadratic form with values in Q/2Z: [], @@ -429,9 +429,9 @@ def brown_invariant(self): EXAMPLES:: - sage: L = IntegralLattice("D4") - sage: D = L.discriminant_group() - sage: D.brown_invariant() + sage: L = IntegralLattice("D4") # optional - sage.combinat + sage: D = L.discriminant_group() # optional - sage.combinat + sage: D.brown_invariant() # optional - sage.combinat 4 We require the quadratic form to be defined modulo `2 \ZZ`:: @@ -588,7 +588,7 @@ def genus(self, signature_pair): We can also compute the genus of an odd lattice from its discriminant form:: - sage: L = IntegralLattice(matrix.diagonal(range(1,5))) + sage: L = IntegralLattice(matrix.diagonal(range(1, 5))) sage: D = L.discriminant_group() sage: D.genus((4,0)) # optional - sage.libs.pari Genus of @@ -764,9 +764,9 @@ def is_genus(self, signature_pair, even=True): Let us see if there is a lattice in the genus defined by the same discriminant form but with a different signature:: - sage: D.is_genus((4,2)) + sage: D.is_genus((4,2)) # optional - sage.combinat False - sage: D.is_genus((16,2)) + sage: D.is_genus((16,2)) # optional - sage.combinat True """ s_plus = ZZ(signature_pair[0]) @@ -1014,7 +1014,7 @@ def normal_form(self, partial=False): [1/2 0 0] [ 0 1/4 0] [ 0 0 5/4] - sage: AL2.normal_form() + sage: AL2.normal_form() # optional - sage.libs.pari sage.rings.padics Finite quadratic module over Integer Ring with invariants (2, 4, 4) Gram matrix of the quadratic form with values in Q/2Z: [1/2 0 0] @@ -1034,7 +1034,7 @@ def normal_form(self, partial=False): [ 1/12 1/6 1/36 1/9] [ 5/36 1/36 1/36 11/72] [ 1/36 1/9 11/72 1/36] - sage: T.normal_form() + sage: T.normal_form() # optional - sage.libs.pari sage.rings.padics Finite quadratic module over Integer Ring with invariants (6, 6, 12, 12) Gram matrix of the quadratic form with values in Q/(1/3)Z: [ 1/6 1/12 0 0 0 0 0 0] @@ -1051,7 +1051,7 @@ def normal_form(self, partial=False): A degenerate case:: sage: T = TorsionQuadraticModule((1/6)*D4dual, D4, modulus=1/36) - sage: T.normal_form() + sage: T.normal_form() # optional - sage.libs.pari sage.rings.padics Finite quadratic module over Integer Ring with invariants (6, 6, 12, 12) Gram matrix of the quadratic form with values in Q/(1/18)Z: [1/36 1/72 0 0 0 0 0 0] diff --git a/src/sage/modules/vector_integer_dense.pyx b/src/sage/modules/vector_integer_dense.pyx index 8c0f4e2416d..d1b653a59ce 100644 --- a/src/sage/modules/vector_integer_dense.pyx +++ b/src/sage/modules/vector_integer_dense.pyx @@ -7,7 +7,7 @@ AUTHOR: EXAMPLES:: - sage: v = vector(ZZ,[1,2,3,4,5]) + sage: v = vector(ZZ, [1,2,3,4,5]) sage: v (1, 2, 3, 4, 5) sage: 3*v @@ -316,10 +316,10 @@ cdef class Vector_integer_dense(free_module_element.FreeModuleElement): sage: A = random_matrix(ZZ,1,3) sage: v = A.row(0) - sage: vs = singular(v) - sage: vs._repr_() == '{},\n{},\n{}'.format(*v) + sage: vs = singular(v) # optional - sage.libs.singular + sage: vs._repr_() == '{},\n{},\n{}'.format(*v) # optional - sage.libs.singular True - sage: vs.type() + sage: vs.type() # optional - sage.libs.singular 'intvec' """ if singular is None: diff --git a/src/sage/modules/vector_modn_dense.pyx b/src/sage/modules/vector_modn_dense.pyx index 24851fd8b27..72124577e63 100644 --- a/src/sage/modules/vector_modn_dense.pyx +++ b/src/sage/modules/vector_modn_dense.pyx @@ -3,7 +3,7 @@ Vectors with integer mod `n` entries, with small `n` EXAMPLES:: - sage: v = vector(Integers(8),[1,2,3,4,5]) + sage: v = vector(Integers(8), [1,2,3,4,5]) sage: type(v) sage: v @@ -21,8 +21,8 @@ EXAMPLES:: sage: v * v 7 - sage: v = vector(Integers(8),[1,2,3,4,5]) - sage: u = vector(Integers(8),[1,2,3,4,4]) + sage: v = vector(Integers(8), [1,2,3,4,5]) + sage: u = vector(Integers(8), [1,2,3,4,4]) sage: v - u (0, 0, 0, 0, 1) sage: u - v @@ -45,9 +45,9 @@ We make a large zero vector:: We multiply a vector by a matrix:: - sage: a = (GF(97)^5)(range(5)) - sage: m = matrix(GF(97),5,range(25)) - sage: a*m + sage: a = (GF(97)^5)(range(5)) # optional - sage.rings.finite_rings + sage: m = matrix(GF(97), 5, range(25)) # optional - sage.rings.finite_rings + sage: a*m # optional - sage.rings.finite_rings (53, 63, 73, 83, 93) TESTS:: @@ -58,41 +58,41 @@ TESTS:: sage: v = vector(Integers(389), [1,2,3,4,5]) sage: loads(dumps(v)) == v True - sage: v = vector(Integers(next_prime(10^20)), [1,2,3,4,5]) - sage: loads(dumps(v)) == v + sage: v = vector(Integers(next_prime(10^20)), [1,2,3,4,5]) # optional - sage.libs.pari + sage: loads(dumps(v)) == v # optional - sage.libs.pari True - sage: K = GF(previous_prime(2^31)) - sage: v = vector(K, [42]); type(v[0]) + sage: K = GF(previous_prime(2^31)) # optional - sage.rings.finite_rings + sage: v = vector(K, [42]); type(v[0]) # optional - sage.rings.finite_rings - sage: ~v[0] + sage: ~v[0] # optional - sage.rings.finite_rings 2096353084 - sage: K = GF(next_prime(2^31)) - sage: v = vector(K, [42]); type(v[0]) + sage: K = GF(next_prime(2^31)) # optional - sage.rings.finite_rings + sage: v = vector(K, [42]); type(v[0]) # optional - sage.rings.finite_rings - sage: ~v[0] + sage: ~v[0] # optional - sage.rings.finite_rings 1482786336 - sage: w = vector(GF(11), [-1,0,0,0]) - sage: w.set_immutable() - sage: isinstance(hash(w), int) + sage: w = vector(GF(11), [-1,0,0,0]) # optional - sage.rings.finite_rings + sage: w.set_immutable() # optional - sage.rings.finite_rings + sage: isinstance(hash(w), int) # optional - sage.rings.finite_rings True Test that :trac:`28042` is fixed:: sage: p = 193379 - sage: K = GF(p) - sage: a = K(1) - sage: b = K(191495) - sage: c = K(109320) - sage: d = K(167667) - sage: e = 103937 - sage: a*c+b*d-e + sage: K = GF(p) # optional - sage.rings.finite_rings + sage: a = K(1) # optional - sage.rings.finite_rings + sage: b = K(191495) # optional - sage.rings.finite_rings + sage: c = K(109320) # optional - sage.rings.finite_rings + sage: d = K(167667) # optional - sage.rings.finite_rings + sage: e = 103937 # optional - sage.rings.finite_rings + sage: a*c + b*d - e # optional - sage.rings.finite_rings 102041 - sage: vector([a,b]) * vector([c,d]) - e + sage: vector([a,b]) * vector([c,d]) - e # optional - sage.rings.finite_rings 102041 - sage: type(vector([a,b]) * vector([c,d])) + sage: type(vector([a,b]) * vector([c,d])) # optional - sage.rings.finite_rings AUTHOR: @@ -197,15 +197,15 @@ cdef class Vector_modn_dense(free_module_element.FreeModuleElement): """ EXAMPLES:: - sage: v = vector(GF(5), [0,0,0,0]) - sage: v == 0 + sage: v = vector(GF(5), [0,0,0,0]) # optional - sage.rings.finite_rings + sage: v == 0 # optional - sage.rings.finite_rings True - sage: v == 1 + sage: v == 1 # optional - sage.rings.finite_rings False - sage: v == v + sage: v == v # optional - sage.rings.finite_rings True - sage: w = vector(GF(11), [-1,0,0,0]) - sage: w == w + sage: w = vector(GF(11), [-1,0,0,0]) # optional - sage.rings.finite_rings + sage: w == w # optional - sage.rings.finite_rings True """ cdef Py_ssize_t i diff --git a/src/sage/modules/vector_space_homspace.py b/src/sage/modules/vector_space_homspace.py index 13004ea14ce..699827203b2 100644 --- a/src/sage/modules/vector_space_homspace.py +++ b/src/sage/modules/vector_space_homspace.py @@ -38,9 +38,9 @@ a list of matrix representations, where these matrix representatives are relative to the bases of the domain and codomain. :: - sage: K = Hom(GF(3)^2, GF(3)^2) - sage: B = K.basis() - sage: for f in B: + sage: K = Hom(GF(3)^2, GF(3)^2) # optional - sage.rings.finite_rings + sage: B = K.basis() # optional - sage.rings.finite_rings + sage: for f in B: # optional - sage.rings.finite_rings ....: print(f) ....: print("\n") Vector space morphism represented by the matrix: @@ -359,10 +359,10 @@ def __call__(self, A, check=True, **kwds): TESTS:: - sage: V = GF(3)^0 - sage: W = GF(3)^1 - sage: H = V.Hom(W) - sage: H.zero().is_zero() + sage: V = GF(3)^0 # optional - sage.rings.finite_rings + sage: W = GF(3)^1 # optional - sage.rings.finite_rings + sage: H = V.Hom(W) # optional - sage.rings.finite_rings + sage: H.zero().is_zero() # optional - sage.rings.finite_rings True Previously the above code resulted in a TypeError because the diff --git a/src/sage/modules/vector_space_morphism.py b/src/sage/modules/vector_space_morphism.py index 8044ed8dd4c..44b7d169951 100644 --- a/src/sage/modules/vector_space_morphism.py +++ b/src/sage/modules/vector_space_morphism.py @@ -41,12 +41,12 @@ sage: F = Integers(13) sage: D = F^3 sage: C = F^2 - sage: x, y, z = var('x y z') - sage: f(x, y, z) = [2*x + 3*y + 5*z, x + z] - sage: rho = linear_transformation(D, C, f) - sage: f(1, 2, 3) + sage: x, y, z = var('x y z') # optional - sage.symbolic + sage: f(x, y, z) = [2*x + 3*y + 5*z, x + z] # optional - sage.symbolic + sage: rho = linear_transformation(D, C, f) # optional - sage.symbolic + sage: f(1, 2, 3) # optional - sage.symbolic (23, 4) - sage: rho([1, 2, 3]) + sage: rho([1, 2, 3]) # optional - sage.symbolic (10, 4) A "vector space homspace" is the set of all linear transformations @@ -70,19 +70,21 @@ A homomorphism may also be created via a method on the domain. :: - sage: F = QQ[sqrt(3)] - sage: a = F.gen(0) - sage: D = F^2 - sage: C = F^2 - sage: A = matrix(F, [[a, 1], [2*a, 2]]) - sage: psi = D.hom(A, C) - sage: psi + sage: F = QQ[sqrt(3)] # optional - sage.rings.number_field sage.symbolic + sage: a = F.gen(0) # optional - sage.rings.number_field sage.symbolic + sage: D = F^2 # optional - sage.rings.number_field sage.symbolic + sage: C = F^2 # optional - sage.rings.number_field sage.symbolic + sage: A = matrix(F, [[a, 1], [2*a, 2]]) # optional - sage.rings.number_field sage.symbolic + sage: psi = D.hom(A, C) # optional - sage.rings.number_field sage.symbolic + sage: psi # optional - sage.rings.number_field sage.symbolic Vector space morphism represented by the matrix: [ sqrt3 1] [2*sqrt3 2] - Domain: Vector space of dimension 2 over Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878? - Codomain: Vector space of dimension 2 over Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878? - sage: psi([1, 4]) + Domain: Vector space of dimension 2 over Number Field in sqrt3 + with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878? + Codomain: Vector space of dimension 2 over Number Field in sqrt3 + with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878? + sage: psi([1, 4]) # optional - sage.rings.number_field sage.symbolic (9*sqrt3, 9) Properties @@ -149,10 +151,10 @@ matrix representation used to represent linear transformations are relative to the bases of both the domain and codomain. :: - sage: A = graphs.PetersenGraph().adjacency_matrix() + sage: A = graphs.PetersenGraph().adjacency_matrix() # optional - sage.graphs sage: V = QQ^10 - sage: phi = linear_transformation(V, V, A) - sage: phi + sage: phi = linear_transformation(V, V, A) # optional - sage.graphs + sage: phi # optional - sage.graphs Vector space morphism represented by the matrix: [0 1 0 0 1 1 0 0 0 0] [1 0 1 0 0 0 1 0 0 0] @@ -167,13 +169,13 @@ Domain: Vector space of dimension 10 over Rational Field Codomain: Vector space of dimension 10 over Rational Field - sage: B1 = [V.gen(i) + V.gen(i+1) for i in range(9)] + [V.gen(9)] - sage: B2 = [V.gen(0)] + [-V.gen(i-1) + V.gen(i) for i in range(1,10)] - sage: D = V.subspace_with_basis(B1) - sage: C = V.subspace_with_basis(B2) - sage: rho = phi.restrict_codomain(C) - sage: zeta = rho.restrict_domain(D) - sage: zeta + sage: B1 = [V.gen(i) + V.gen(i+1) for i in range(9)] + [V.gen(9)] # optional - sage.graphs + sage: B2 = [V.gen(0)] + [-V.gen(i-1) + V.gen(i) for i in range(1,10)] # optional - sage.graphs + sage: D = V.subspace_with_basis(B1) # optional - sage.graphs + sage: C = V.subspace_with_basis(B2) # optional - sage.graphs + sage: rho = phi.restrict_codomain(C) # optional - sage.graphs + sage: zeta = rho.restrict_domain(D) # optional - sage.graphs + sage: zeta # optional - sage.graphs Vector space morphism represented by the matrix: [6 5 4 3 3 2 1 0 0 0] [6 5 4 3 2 2 2 1 0 0] @@ -215,16 +217,16 @@ matrix that has well-behaved eigenvalues, as part of showing that these do not change as the representation changes. :: - sage: A = graphs.PetersenGraph().adjacency_matrix() + sage: A = graphs.PetersenGraph().adjacency_matrix() # optional - sage.graphs sage: V = QQ^10 - sage: phi = linear_transformation(V, V, A) - sage: phi.eigenvalues() + sage: phi = linear_transformation(V, V, A) # optional - sage.graphs + sage: phi.eigenvalues() # optional - sage.graphs [3, -2, -2, -2, -2, 1, 1, 1, 1, 1] - sage: B1 = [V.gen(i) + V.gen(i+1) for i in range(9)] + [V.gen(9)] - sage: C = V.subspace_with_basis(B1) - sage: zeta = phi.restrict(C) - sage: zeta + sage: B1 = [V.gen(i) + V.gen(i+1) for i in range(9)] + [V.gen(9)] # optional - sage.graphs + sage: C = V.subspace_with_basis(B1) # optional - sage.graphs + sage: zeta = phi.restrict(C) # optional - sage.graphs + sage: zeta # optional - sage.graphs Vector space morphism represented by the matrix: [ 1 0 1 -1 2 -1 2 -2 2 -2] [ 1 0 1 0 0 0 1 0 0 0] @@ -261,7 +263,7 @@ [0 0 0 0 0 0 0 0 1 1] [0 0 0 0 0 0 0 0 0 1] - sage: zeta.eigenvalues() + sage: zeta.eigenvalues() # optional - sage.graphs [3, -2, -2, -2, -2, 1, 1, 1, 1, 1] Equality @@ -495,10 +497,10 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): Domain: Vector space of dimension 3 over Rational Field Codomain: Vector space of dimension 2 over Rational Field - sage: x, y, z = var('x y z') - sage: h(x, y, z) = [2*x + z, 5*y] - sage: zeta = linear_transformation(QQ^3, QQ^2, h) - sage: zeta + sage: x, y, z = var('x y z') # optional - sage.symbolic + sage: h(x, y, z) = [2*x + z, 5*y] # optional - sage.symbolic + sage: zeta = linear_transformation(QQ^3, QQ^2, h) # optional - sage.symbolic + sage: zeta # optional - sage.symbolic Vector space morphism represented by the matrix: [2 0] [0 5] @@ -508,7 +510,7 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): sage: phi == rho True - sage: rho == zeta + sage: rho == zeta # optional - sage.symbolic True @@ -536,10 +538,10 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): [2 5] [3 7] - sage: s, t = var('s t') - sage: h(s, t) = [(-4/5)*s + (1/5)*t, (97/5)*s + (-13/5)*t] - sage: zeta = linear_transformation(D, C, h) - sage: zeta.matrix() + sage: s, t = var('s t') # optional - sage.symbolic + sage: h(s, t) = [(-4/5)*s + (1/5)*t, (97/5)*s + (-13/5)*t] # optional - sage.symbolic + sage: zeta = linear_transformation(D, C, h) # optional - sage.symbolic + sage: zeta.matrix() # optional - sage.symbolic [2 5] [3 7] @@ -547,21 +549,21 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): elements of the domain. :: sage: x = polygen(QQ) - sage: F. = NumberField(x^3+x+1) - sage: u = vector(F, [1, a, a^2]) - sage: v = vector(F, [a, a^2, 2]) - sage: w = u + v - sage: D = F^3 - sage: C = F^3 - sage: rho = linear_transformation(D, C, [u, v, w]) - sage: rho.matrix() + sage: F. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field + sage: u = vector(F, [1, a, a^2]) # optional - sage.rings.number_field + sage: v = vector(F, [a, a^2, 2]) # optional - sage.rings.number_field + sage: w = u + v # optional - sage.rings.number_field + sage: D = F^3 # optional - sage.rings.number_field + sage: C = F^3 # optional - sage.rings.number_field + sage: rho = linear_transformation(D, C, [u, v, w]) # optional - sage.rings.number_field + sage: rho.matrix() # optional - sage.rings.number_field [ 1 a a^2] [ a a^2 2] [ a + 1 a^2 + a a^2 + 2] - sage: C = (F^3).subspace_with_basis([u, v]) - sage: D = (F^3).subspace_with_basis([u, v]) - sage: psi = linear_transformation(C, D, [u+v, u-v]) - sage: psi.matrix() + sage: C = (F^3).subspace_with_basis([u, v]) # optional - sage.rings.number_field + sage: D = (F^3).subspace_with_basis([u, v]) # optional - sage.rings.number_field + sage: psi = linear_transformation(C, D, [u+v, u-v]) # optional - sage.rings.number_field + sage: psi.matrix() # optional - sage.rings.number_field [ 1 1] [ 1 -1] @@ -655,30 +657,30 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'): A Sage symbolic function can come in a variety of forms that are not representative of a linear transformation. :: - sage: x, y = var('x, y') - sage: f(x, y) = [y, x, y] - sage: linear_transformation(QQ^3, QQ^3, f) + sage: x, y = var('x, y') # optional - sage.symbolic + sage: f(x, y) = [y, x, y] # optional - sage.symbolic + sage: linear_transformation(QQ^3, QQ^3, f) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: symbolic function has the wrong number of inputs for domain - sage: linear_transformation(QQ^2, QQ^2, f) + sage: linear_transformation(QQ^2, QQ^2, f) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: symbolic function has the wrong number of outputs for codomain - sage: x, y = var('x y') - sage: f(x, y) = [y, x*y] - sage: linear_transformation(QQ^2, QQ^2, f) + sage: x, y = var('x y') # optional - sage.symbolic + sage: f(x, y) = [y, x*y] # optional - sage.symbolic + sage: linear_transformation(QQ^2, QQ^2, f) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: symbolic function must be linear in all the inputs: unable to convert y to a rational - sage: x, y = var('x y') - sage: f(x, y) = [x, 2*y] + sage: x, y = var('x y') # optional - sage.symbolic + sage: f(x, y) = [x, 2*y] # optional - sage.symbolic sage: C = (QQ^2).span([vector(QQ, [1, 1])]) - sage: linear_transformation(QQ^2, C, f) + sage: linear_transformation(QQ^2, C, f) # optional - sage.symbolic Traceback (most recent call last): ... ArithmeticError: some image of the function is not in the codomain, because @@ -902,15 +904,15 @@ def is_invertible(self): A non-invertible linear transformation, an endomorphism of a vector space over a finite field. :: - sage: F. = GF(11^2) - sage: A = matrix(F, [[6*a + 3, 8*a + 2, 10*a + 3], + sage: F. = GF(11^2) # optional - sage.rings.finite_rings + sage: A = matrix(F, [[6*a + 3, 8*a + 2, 10*a + 3], # optional - sage.rings.finite_rings ....: [2*a + 7, 4*a + 3, 2*a + 3], ....: [9*a + 2, 10*a + 10, 3*a + 3]]) - sage: A.nullity() + sage: A.nullity() # optional - sage.rings.finite_rings 1 - sage: E = End(F^3) - sage: zeta = E(A) - sage: zeta.is_invertible() + sage: E = End(F^3) # optional - sage.rings.finite_rings + sage: zeta = E(A) # optional - sage.rings.finite_rings + sage: zeta.is_invertible() # optional - sage.rings.finite_rings False """ # endomorphism or not, this is equivalent to invertibility of diff --git a/src/sage/modules/with_basis/cell_module.py b/src/sage/modules/with_basis/cell_module.py index c51d43c32b6..8c2fe5a3ac4 100644 --- a/src/sage/modules/with_basis/cell_module.py +++ b/src/sage/modules/with_basis/cell_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.combinat r""" Cell modules """ diff --git a/src/sage/modules/with_basis/indexed_element.pyx b/src/sage/modules/with_basis/indexed_element.pyx index 06947bfb3b0..6a8685f37f9 100644 --- a/src/sage/modules/with_basis/indexed_element.pyx +++ b/src/sage/modules/with_basis/indexed_element.pyx @@ -82,9 +82,9 @@ cdef class IndexedFreeModuleElement(ModuleElement): sage: [i for i in sorted(f)] [('a', 1), ('c', 3)] - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1]) + s([3]) - sage: [i for i in sorted(a)] + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = s([2,1]) + s([3]) # optional - sage.combinat + sage: [i for i in sorted(a)] # optional - sage.combinat [([2, 1], 1), ([3], 1)] """ return iter(self._monomial_coefficients.items()) @@ -107,11 +107,11 @@ cdef class IndexedFreeModuleElement(ModuleElement): sage: 'b' in f False - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1]) + s([3]) - sage: Partition([2,1]) in a + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = s([2,1]) + s([3]) # optional - sage.combinat + sage: Partition([2,1]) in a # optional - sage.combinat True - sage: Partition([1,1,1]) in a + sage: Partition([1,1,1]) in a # optional - sage.combinat False """ deprecation(34509, "using 'index in vector' is deprecated; use 'index in vector.support()' instead") @@ -133,11 +133,11 @@ cdef class IndexedFreeModuleElement(ModuleElement): sage: hash(f) == hash(B['a'] + 4*B['c']) False - sage: F = RootSystem(['A',2]).ambient_space() - sage: f = F.simple_root(0) - sage: hash(f) == hash(F.simple_root(0)) + sage: F = RootSystem(['A',2]).ambient_space() # optional - sage.combinat + sage: f = F.simple_root(0) # optional - sage.combinat + sage: hash(f) == hash(F.simple_root(0)) # optional - sage.combinat True - sage: hash(f) == hash(F.simple_root(1)) + sage: hash(f) == hash(F.simple_root(1)) # optional - sage.combinat False This uses the recipe that was proposed for frozendicts in @@ -264,14 +264,14 @@ cdef class IndexedFreeModuleElement(ModuleElement): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1])+2*s([3,2]) - sage: d = a.monomial_coefficients() - sage: type(d) + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = s([2,1])+2*s([3,2]) # optional - sage.combinat + sage: d = a.monomial_coefficients() # optional - sage.combinat + sage: type(d) # optional - sage.combinat <... 'dict'> - sage: d[ Partition([2,1]) ] + sage: d[ Partition([2,1]) ] # optional - sage.combinat 1 - sage: d[ Partition([3,2]) ] + sage: d[ Partition([3,2]) ] # optional - sage.combinat 2 """ if copy: @@ -347,17 +347,17 @@ cdef class IndexedFreeModuleElement(ModuleElement): """ TESTS:: - sage: M = QuasiSymmetricFunctions(QQ).M() - sage: ascii_art(M[1,3]**2) # indirect doctest + sage: M = QuasiSymmetricFunctions(QQ).M() # optional - sage.combinat + sage: ascii_art(M[1,3]**2) # indirect doctest # optional - sage.combinat 4*M + 2*M + 2*M + 2*M + 2*M + M *** ****** *** *** *** ****** *** * * **** *** ** * * *** * ** * * - sage: ascii_art(M.zero()) + sage: ascii_art(M.zero()) # optional - sage.combinat 0 - sage: DA = DescentAlgebra(QQ, 4) - sage: ascii_art(DA.an_element()) + sage: DA = DescentAlgebra(QQ, 4) # optional - sage.combinat + sage: ascii_art(DA.an_element()) # optional - sage.combinat 2*B + 2*B + 3*B * ** * * * ** @@ -424,8 +424,8 @@ cdef class IndexedFreeModuleElement(ModuleElement): """ TESTS:: - sage: M = QuasiSymmetricFunctions(QQ).M() - sage: unicode_art(M[1,1]**2) # indirect doctest + sage: M = QuasiSymmetricFunctions(QQ).M() # optional - sage.combinat + sage: unicode_art(M[1,1]**2) # indirect doctest # optional - sage.combinat 6*M + 2*M + 2*M + 2*M + M ┌┐ ┌┬┐ ┌┐ ┌┐ ┌┬┐ ├┤ ├┼┘ ┌┼┤ ├┤ ┌┼┼┘ @@ -435,7 +435,7 @@ cdef class IndexedFreeModuleElement(ModuleElement): The following test failed before :trac:`26850`:: - sage: unicode_art([M.zero()]) # indirect doctest + sage: unicode_art([M.zero()]) # indirect doctest # optional - sage.combinat [ 0 ] """ from sage.misc.repr import coeff_repr @@ -506,9 +506,9 @@ cdef class IndexedFreeModuleElement(ModuleElement): :: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) - sage: a = 2 + QS3([2,1,3]) - sage: latex(a) #indirect doctest + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat + sage: a = 2 + QS3([2,1,3]) # optional - sage.combinat + sage: latex(a) #indirect doctest # optional - sage.combinat 2 [1, 2, 3] + [2, 1, 3] :: @@ -568,10 +568,10 @@ cdef class IndexedFreeModuleElement(ModuleElement): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s([2,1]) - sage: b = s([1,1,1]) - sage: a == b + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = s([2,1]) # optional - sage.combinat + sage: b = s([1,1,1]) # optional - sage.combinat + sage: a == b # optional - sage.combinat False .. TODO:: @@ -595,20 +595,20 @@ cdef class IndexedFreeModuleElement(ModuleElement): Traceback (most recent call last): ... TypeError: do not know how to make x (= 0) an element of self (=Free module generated by {1, 2, 3} over Rational Field) - sage: F = AlgebrasWithBasis(QQ).example() - sage: F.one() == 1 + sage: F = AlgebrasWithBasis(QQ).example() # optional - sage.combinat + sage: F.one() == 1 # optional - sage.combinat True - sage: 1 == F.one() + sage: 1 == F.one() # optional - sage.combinat True - sage: 2 * F.one() == int(2) + sage: 2 * F.one() == int(2) # optional - sage.combinat True - sage: int(2) == 2 * F.one() + sage: int(2) == 2 * F.one() # optional - sage.combinat True - sage: S = SymmetricFunctions(QQ); s = S.s(); p = S.p() - sage: p[2] == s[2] - s[1, 1] + sage: S = SymmetricFunctions(QQ); s = S.s(); p = S.p() # optional - sage.combinat + sage: p[2] == s[2] - s[1, 1] # optional - sage.combinat True - sage: p[2] == s[2] + sage: p[2] == s[2] # optional - sage.combinat False This feature is disputable, in particular since it can make @@ -618,19 +618,19 @@ cdef class IndexedFreeModuleElement(ModuleElement): can vary because their indices are incomparable with ``cmp``. The following test did fail before :trac:`12489` :: - sage: F = CombinatorialFreeModule(QQ, Subsets([1,2,3])) - sage: x = F.an_element() - sage: (x+F.zero()).terms() # random + sage: F = CombinatorialFreeModule(QQ, Subsets([1,2,3])) # optional - sage.combinat + sage: x = F.an_element() # optional - sage.combinat + sage: (x+F.zero()).terms() # random # optional - sage.combinat [2*B[{1}], 3*B[{2}], B[{}]] - sage: x.terms() # random + sage: x.terms() # random # optional - sage.combinat [2*B[{1}], B[{}], 3*B[{2}]] - sage: x+F.zero() == x + sage: x+F.zero() == x # optional - sage.combinat True TESTS:: sage: TestSuite(F1).run() - sage: TestSuite(F).run() + sage: TestSuite(F).run() # optional - sage.combinat """ cdef IndexedFreeModuleElement elt = other @@ -658,11 +658,11 @@ cdef class IndexedFreeModuleElement(ModuleElement): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s([2,1]) + s([5,4]) # indirect doctest + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s([2,1]) + s([5,4]) # indirect doctest # optional - sage.combinat s[2, 1] + s[5, 4] - sage: a = s([2,1]) + 0 - sage: len(a.monomial_coefficients()) + sage: a = s([2,1]) + 0 # optional - sage.combinat + sage: len(a.monomial_coefficients()) # optional - sage.combinat 1 """ return type(self)(self._parent, @@ -681,8 +681,8 @@ cdef class IndexedFreeModuleElement(ModuleElement): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: -s([2,1]) # indirect doctest + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: -s([2,1]) # indirect doctest # optional - sage.combinat -s[2, 1] """ return type(self)(self._parent, negate(self._monomial_coefficients)) @@ -698,8 +698,8 @@ cdef class IndexedFreeModuleElement(ModuleElement): :: - sage: s = SymmetricFunctions(QQ).schur() - sage: s([2,1]) - s([5,4]) # indirect doctest + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: s([2,1]) - s([5,4]) # indirect doctest # optional - sage.combinat s[2, 1] - s[5, 4] """ return type(self)(self._parent, @@ -713,15 +713,15 @@ cdef class IndexedFreeModuleElement(ModuleElement): EXAMPLES:: - sage: p = Partition([2,1]) - sage: q = Partition([1,1,1]) - sage: s = SymmetricFunctions(QQ).schur() - sage: a = s(p) - sage: a[p] + sage: p = Partition([2,1]) # optional - sage.combinat + sage: q = Partition([1,1,1]) # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat + sage: a = s(p) # optional - sage.combinat + sage: a[p] # optional - sage.combinat 1 - sage: a[q] + sage: a[q] # optional - sage.combinat 0 - sage: a[[2,1]] + sage: a[[2,1]] # optional - sage.combinat Traceback (most recent call last): ... TypeError: unhashable type: 'list' @@ -770,23 +770,23 @@ cdef class IndexedFreeModuleElement(ModuleElement): More examples:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) - sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) - sage: a._vector_() + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat + sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) # optional - sage.combinat + sage: a._vector_() # optional - sage.combinat (2, 0, 0, 0, 0, 4) - sage: a.to_vector() + sage: a.to_vector() # optional - sage.combinat (2, 0, 0, 0, 0, 4) - sage: vector(a) + sage: vector(a) # optional - sage.combinat (2, 0, 0, 0, 0, 4) - sage: a == QS3.from_vector(a.to_vector()) + sage: a == QS3.from_vector(a.to_vector()) # optional - sage.combinat True - sage: a.to_vector(sparse=True) + sage: a.to_vector(sparse=True) # optional - sage.combinat (2, 0, 0, 0, 0, 4) If ``new_base_ring`` is specified, then a vector over ``new_base_ring`` is returned:: - sage: a._vector_(RDF) + sage: a._vector_(RDF) # optional - sage.combinat (2.0, 0.0, 0.0, 0.0, 0.0, 4.0) .. NOTE:: @@ -864,18 +864,18 @@ cdef class IndexedFreeModuleElement(ModuleElement): example with polynomials or fraction fields (:trac:`8832`):: sage: P. = QQ['q'] - sage: V = CombinatorialFreeModule(P, Permutations()) - sage: el = V(Permutation([3,1,2])) - sage: (3/2)*el + sage: V = CombinatorialFreeModule(P, Permutations()) # optional - sage.combinat + sage: el = V(Permutation([3,1,2])) # optional - sage.combinat + sage: (3/2)*el # optional - sage.combinat 3/2*B[[3, 1, 2]] sage: P. = QQ['q'] sage: F = FractionField(P) - sage: V = CombinatorialFreeModule(F, Words()) - sage: w = Words()('abc') - sage: (1+q)*V(w) + sage: V = CombinatorialFreeModule(F, Words()) # optional - sage.combinat + sage: w = Words()('abc') # optional - sage.combinat + sage: (1+q)*V(w) # optional - sage.combinat (q+1)*B[word: abc] - sage: ((1+q)/q)*V(w) + sage: ((1+q)/q)*V(w) # optional - sage.combinat ((q+1)/q)*B[word: abc] .. TODO:: diff --git a/src/sage/modules/with_basis/invariant.py b/src/sage/modules/with_basis/invariant.py index 12565a411e2..1fa4c20c23f 100644 --- a/src/sage/modules/with_basis/invariant.py +++ b/src/sage/modules/with_basis/invariant.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups r""" Invariant modules """ diff --git a/src/sage/modules/with_basis/representation.py b/src/sage/modules/with_basis/representation.py index 44b9f6115e2..1ee49a740f7 100644 --- a/src/sage/modules/with_basis/representation.py +++ b/src/sage/modules/with_basis/representation.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.groups """ Representations of a semigroup diff --git a/src/sage/numerical/backends/ppl_backend.pyx b/src/sage/numerical/backends/ppl_backend.pyx index 1f50c4bdf11..f58e7729ae2 100644 --- a/src/sage/numerical/backends/ppl_backend.pyx +++ b/src/sage/numerical/backends/ppl_backend.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - pplpy """ PPL Backend @@ -60,7 +61,7 @@ cdef class PPLBackend(GenericBackend): Raise an error if a ``base_ring`` is requested that is not supported:: - sage: p = MixedIntegerLinearProgram(solver = "PPL", base_ring=AA) + sage: p = MixedIntegerLinearProgram(solver="PPL", base_ring=AA) # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: The PPL backend only supports rational data. diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index 26e332cd8d9..dfad93d5712 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -64,7 +64,7 @@ Since it has only two variables, we can solve it graphically:: - sage: P.plot() + sage: P.plot() # optional - sage.plot Graphics object consisting of 19 graphics primitives @@ -298,9 +298,9 @@ def _latex_product(coefficients, variables, sage: from sage.numerical.interactive_simplex_method import \ ....: _latex_product - sage: var("x, y") + sage: var("x, y") # optional - sage.symbolic (x, y) - sage: print(_latex_product([-1, 3], [x, y])) + sage: print(_latex_product([-1, 3], [x, y])) # optional - sage.symbolic - \mspace{-6mu}&\mspace{-6mu} x \mspace{-6mu}&\mspace{-6mu} + \mspace{-6mu}&\mspace{-6mu} 3 y """ entries = [] @@ -1534,19 +1534,19 @@ def plot(self, *args, **kwds): sage: b = (1000, 1500) sage: c = (10, 5) sage: P = InteractiveLPProblem(A, b, c, ["C", "B"], variable_type=">=") - sage: p = P.plot() - sage: p.show() + sage: p = P.plot() # optional - sage.plot + sage: p.show() # optional - sage.plot In this case the plot works better with the following axes ranges:: - sage: p = P.plot(0, 1000, 0, 1500) - sage: p.show() + sage: p = P.plot(0, 1000, 0, 1500) # optional - sage.plot + sage: p.show() # optional - sage.plot TESTS: We check that zero objective can be dealt with:: - sage: InteractiveLPProblem(A, b, (0, 0), ["C", "B"], variable_type=">=").plot() + sage: InteractiveLPProblem(A, b, (0, 0), ["C", "B"], variable_type=">=").plot() # optional - sage.plot Graphics object consisting of 8 graphics primitives """ FP = self.plot_feasible_set(*args, **kwds) @@ -1611,13 +1611,13 @@ def plot_feasible_set(self, xmin=None, xmax=None, ymin=None, ymax=None, sage: b = (1000, 1500) sage: c = (10, 5) sage: P = InteractiveLPProblem(A, b, c, ["C", "B"], variable_type=">=") - sage: p = P.plot_feasible_set() - sage: p.show() + sage: p = P.plot_feasible_set() # optional - sage.plot + sage: p.show() # optional - sage.plot In this case the plot works better with the following axes ranges:: - sage: p = P.plot_feasible_set(0, 1000, 0, 1500) - sage: p.show() + sage: p = P.plot_feasible_set(0, 1000, 0, 1500) # optional - sage.plot + sage: p.show() # optional - sage.plot """ if self.n() != 2: raise ValueError("only problems with 2 variables can be plotted") diff --git a/src/sage/numerical/mip.pyx b/src/sage/numerical/mip.pyx index dae234c15bf..52745c9a0da 100644 --- a/src/sage/numerical/mip.pyx +++ b/src/sage/numerical/mip.pyx @@ -315,13 +315,13 @@ cdef class MixedIntegerLinearProgram(SageObject): Computation of a maximum stable set in Petersen's graph:: - sage: g = graphs.PetersenGraph() - sage: p = MixedIntegerLinearProgram(maximization=True, solver='GLPK') - sage: b = p.new_variable(binary=True) - sage: p.set_objective(sum([b[v] for v in g])) - sage: for (u,v) in g.edges(sort=False, labels=None): + sage: g = graphs.PetersenGraph() # optional - sage.graphs + sage: p = MixedIntegerLinearProgram(maximization=True, solver='GLPK') # optional - sage.graphs + sage: b = p.new_variable(binary=True) # optional - sage.graphs + sage: p.set_objective(sum([b[v] for v in g])) # optional - sage.graphs + sage: for (u,v) in g.edges(sort=False, labels=None): # optional - sage.graphs ....: p.add_constraint(b[u] + b[v], max=1) - sage: p.solve(objective_only=True) + sage: p.solve(objective_only=True) # optional - sage.graphs 4.0 TESTS: @@ -659,13 +659,13 @@ cdef class MixedIntegerLinearProgram(SageObject): sage: p = MixedIntegerLinearProgram(solver='ppl') sage: p.base_ring() Rational Field - sage: from sage.rings.qqbar import AA # optional - sage.rings.number_field - sage: p = MixedIntegerLinearProgram(solver='InteractiveLP', base_ring=AA) # optional - sage.rings.number_field - sage: p.base_ring() # optional - sage.rings.number_field + sage: from sage.rings.qqbar import AA # optional - sage.rings.number_field + sage: p = MixedIntegerLinearProgram(solver='InteractiveLP', base_ring=AA) # optional - sage.rings.number_field + sage: p.base_ring() # optional - sage.rings.number_field Algebraic Real Field - sage: d = polytopes.dodecahedron() # optional - sage.rings.number_field - sage: p = MixedIntegerLinearProgram(base_ring=d.base_ring()) # optional - sage.rings.number_field - sage: p.base_ring() # optional - sage.rings.number_field + sage: d = polytopes.dodecahedron() # optional - sage.rings.number_field + sage: p = MixedIntegerLinearProgram(base_ring=d.base_ring()) # optional - sage.rings.number_field + sage: p.base_ring() # optional - sage.rings.number_field Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? """ return self._backend.base_ring() @@ -2629,14 +2629,14 @@ cdef class MixedIntegerLinearProgram(SageObject): Computation of a maximum stable set in Petersen's graph:: - sage: g = graphs.PetersenGraph() - sage: p = MixedIntegerLinearProgram(maximization=True, solver='GLPK') - sage: b = p.new_variable(nonnegative=True) - sage: p.set_objective(sum([b[v] for v in g])) - sage: for (u,v) in g.edges(sort=False, labels=None): + sage: g = graphs.PetersenGraph() # optional - sage.graphs + sage: p = MixedIntegerLinearProgram(maximization=True, solver='GLPK') # optional - sage.graphs + sage: b = p.new_variable(nonnegative=True) # optional - sage.graphs + sage: p.set_objective(sum([b[v] for v in g])) # optional - sage.graphs + sage: for (u,v) in g.edges(sort=False, labels=None): # optional - sage.graphs ....: p.add_constraint(b[u] + b[v], max=1) - sage: p.set_binary(b) - sage: p.solve(objective_only=True) + sage: p.set_binary(b) # optional - sage.graphs + sage: p.solve(objective_only=True) # optional - sage.graphs 4.0 Constraints in the objective function are respected:: @@ -2847,7 +2847,7 @@ cdef class MixedIntegerLinearProgram(SageObject): The command :: - sage: p = MixedIntegerLinearProgram(solver="CPLEX") # optional - CPLEX + sage: p = MixedIntegerLinearProgram(solver="CPLEX") # optional - CPLEX sage: p.solver_parameter("CPX_PARAM_TILIM", 60) # optional - CPLEX works as intended. @@ -2983,17 +2983,17 @@ cdef class MixedIntegerLinearProgram(SageObject): EXAMPLES:: - sage: g = graphs.CubeGraph(9) - sage: p = MixedIntegerLinearProgram(solver="GLPK") - sage: p.solver_parameter("mip_gap_tolerance",100) - sage: b = p.new_variable(binary=True) - sage: p.set_objective(p.sum(b[v] for v in g)) - sage: for v in g: + sage: g = graphs.CubeGraph(9) # optional - sage.graphs + sage: p = MixedIntegerLinearProgram(solver="GLPK") # optional - sage.graphs + sage: p.solver_parameter("mip_gap_tolerance",100) # optional - sage.graphs + sage: b = p.new_variable(binary=True) # optional - sage.graphs + sage: p.set_objective(p.sum(b[v] for v in g)) # optional - sage.graphs + sage: for v in g: # optional - sage.graphs ....: p.add_constraint(b[v] + p.sum(b[u] for u in g.neighbors(v)) <= 1) - sage: p.add_constraint(b[v] == 1) # Force an easy non-0 solution - sage: p.solve() # rel tol 100 + sage: p.add_constraint(b[v] == 1) # Force an easy non-0 solution # optional - sage.graphs + sage: p.solve() # rel tol 100 # optional - sage.graphs 1.0 - sage: p.best_known_objective_bound() # random + sage: p.best_known_objective_bound() # random # optional - sage.graphs 48.0 """ return self._backend.best_known_objective_bound() @@ -3017,17 +3017,17 @@ cdef class MixedIntegerLinearProgram(SageObject): EXAMPLES:: - sage: g = graphs.CubeGraph(9) - sage: p = MixedIntegerLinearProgram(solver="GLPK") - sage: p.solver_parameter("mip_gap_tolerance",100) - sage: b = p.new_variable(binary=True) - sage: p.set_objective(p.sum(b[v] for v in g)) - sage: for v in g: + sage: g = graphs.CubeGraph(9) # optional - sage.graphs + sage: p = MixedIntegerLinearProgram(solver="GLPK") # optional - sage.graphs + sage: p.solver_parameter("mip_gap_tolerance",100) # optional - sage.graphs + sage: b = p.new_variable(binary=True) # optional - sage.graphs + sage: p.set_objective(p.sum(b[v] for v in g)) # optional - sage.graphs + sage: for v in g: # optional - sage.graphs ....: p.add_constraint(b[v] + p.sum(b[u] for u in g.neighbors(v)) <= 1) - sage: p.add_constraint(b[v] == 1) # Force an easy non-0 solution - sage: p.solve() # rel tol 100 + sage: p.add_constraint(b[v] == 1) # Force an easy non-0 solution # optional - sage.graphs + sage: p.solve() # rel tol 100 # optional - sage.graphs 1.0 - sage: p.get_relative_objective_gap() # random + sage: p.get_relative_objective_gap() # random # optional - sage.graphs 46.99999999999999 TESTS: @@ -3035,7 +3035,7 @@ cdef class MixedIntegerLinearProgram(SageObject): Just make sure that the variable *has* been defined, and is not just undefined:: - sage: p.get_relative_objective_gap() > 1 + sage: p.get_relative_objective_gap() > 1 # optional - sage.graphs True """ return self._backend.get_relative_objective_gap() diff --git a/src/sage/numerical/optimize.py b/src/sage/numerical/optimize.py index 63d47674dbb..e47ffc4bfe8 100644 --- a/src/sage/numerical/optimize.py +++ b/src/sage/numerical/optimize.py @@ -370,9 +370,9 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm="default", sage: def rosen(x): # The Rosenbrock function ....: return sum(100.0r*(x[1r:]-x[:-1r]**2.0r)**2.0r + (1r-x[:-1r])**2.0r) - sage: import numpy - sage: from numpy import zeros - sage: def rosen_der(x): + sage: import numpy # optional - numpy + sage: from numpy import zeros # optional - numpy + sage: def rosen_der(x): # optional - numpy ....: xm = x[1r:-1r] ....: xm_m1 = x[:-2r] ....: xm_p1 = x[2r:] @@ -381,7 +381,8 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm="default", ....: der[0] = -400r*x[0r]*(x[1r]-x[0r]**2r) - 2r*(1r-x[0]) ....: der[-1] = 200r*(x[-1r]-x[-2r]**2r) ....: return der - sage: minimize(rosen, [.1,.3,.4], gradient=rosen_der, algorithm="bfgs") # abs tol 1e-6 + sage: minimize(rosen, [.1,.3,.4], gradient=rosen_der, # abs tol 1e-6 # optional - numpy + ....: algorithm="bfgs") (1.0, 1.0, 1.0) """ from sage.structure.element import Expression diff --git a/src/sage/numerical/sdp.pyx b/src/sage/numerical/sdp.pyx index 77f7fa5254c..dea3ded3942 100644 --- a/src/sage/numerical/sdp.pyx +++ b/src/sage/numerical/sdp.pyx @@ -72,17 +72,17 @@ The following example shows all these steps:: sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) sage: p.add_constraint(c1*x[0] + c2*x[1] >= matrix.zero(2,2,sparse=True)) - sage: p.solver_parameter("show_progress", True) # optional - cvxopt - sage: opt = p.solve() # optional - cvxopt + sage: p.solver_parameter("show_progress", True) # optional - cvxopt + sage: opt = p.solve() # optional - cvxopt pcost dcost gap pres dres k/t 0: ... ... Optimal solution found. - sage: print('Objective Value: {}'.format(N(opt,3))) # optional - cvxopt + sage: print('Objective Value: {}'.format(N(opt,3))) # optional - cvxopt Objective Value: 1.0 - sage: [N(x, 3) for x in sorted(p.get_values(x).values())] # optional - cvxopt + sage: [N(x, 3) for x in sorted(p.get_values(x).values())] # optional - cvxopt [3.0e-8, 1.0] - sage: p.show() # optional - cvxopt + sage: p.show() # optional - cvxopt Maximization: x_0 - x_1 Constraints: @@ -97,46 +97,47 @@ of primal and dual problems. Thus we can get the optimizer `X` of the dual probl as follows, as diagonal blocks, one per each constraint, via :meth:`~SemidefiniteProgram.dual_variable`. E.g.:: - sage: p.dual_variable(1) # rel tol 2e-03 # optional - cvxopt + sage: p.dual_variable(1) # rel tol 2e-03 # optional - cvxopt [ 85555.0 -85555.0] [-85555.0 85555.0] We can see that the optimal value of the dual is equal (up to numerical noise) to `opt`.:: - sage: opt-((p.dual_variable(0)*a3).trace()+(p.dual_variable(1)*b3).trace()) # tol 8e-08 # optional - cvxopt + sage: opt - ((p.dual_variable(0)*a3).trace() # tol 8e-08 # optional - cvxopt + ....: + (p.dual_variable(1)*b3).trace()) 0.0 Dual variable blocks at optimality are orthogonal to "slack variables", that is, matrices `C-\sum_k x_k A_k`, cf. (Primal problem) above, available via :meth:`~SemidefiniteProgram.slack`. E.g.:: - sage: (p.slack(0)*p.dual_variable(0)).trace() # tol 2e-07 # optional - cvxopt + sage: (p.slack(0)*p.dual_variable(0)).trace() # tol 2e-07 # optional - cvxopt 0.0 More interesting example, the :func:`Lovasz theta ` of the 7-gon:: - sage: c=graphs.CycleGraph(7) - sage: c2=c.distance_graph(2).adjacency_matrix() - sage: c3=c.distance_graph(3).adjacency_matrix() - sage: p.=SemidefiniteProgram() - sage: p.add_constraint((1/7)*matrix.identity(7)>=-y[0]*c2-y[1]*c3) - sage: p.set_objective(y[0]*(c2**2).trace()+y[1]*(c3**2).trace()) - sage: x=p.solve(); x+1 # optional - cvxopt + sage: c = graphs.CycleGraph(7) # optional - sage.graphs + sage: c2 = c.distance_graph(2).adjacency_matrix() # optional - sage.graphs + sage: c3 = c.distance_graph(3).adjacency_matrix() # optional - sage.graphs + sage: p. = SemidefiniteProgram() # optional - sage.graphs + sage: p.add_constraint((1/7)*matrix.identity(7)>=-y[0]*c2-y[1]*c3) # optional - sage.graphs + sage: p.set_objective(y[0]*(c2**2).trace()+y[1]*(c3**2).trace()) # optional - sage.graphs + sage: x = p.solve(); x + 1 # optional - cvxopt # optional - sage.graphs 3.31766... Unlike in the previous example, the slack variable is very far from 0:: - sage: p.slack(0).trace() # tol 1e-14 # optional - cvxopt + sage: p.slack(0).trace() # tol 1e-14 # optional - cvxopt # optional - sage.graphs 1.0 The default CVXOPT backend computes with the Real Double Field, for example:: - sage: p = SemidefiniteProgram(solver='cvxopt') # optional - cvxopt - sage: p.base_ring() # optional - cvxopt + sage: p = SemidefiniteProgram(solver='cvxopt') # optional - cvxopt + sage: p.base_ring() # optional - cvxopt Real Double Field - sage: x = p.new_variable() # optional - cvxopt - sage: 0.5 + 3/2*x[1] # optional - cvxopt + sage: x = p.new_variable() # optional - cvxopt + sage: 0.5 + 3/2*x[1] # optional - cvxopt 0.5 + 1.5*x_0 For representing an SDP with exact data, there is another backend:: @@ -285,7 +286,7 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: N(p.solve(), 2) # optional - cvxopt + sage: N(p.solve(), 2) # optional - cvxopt -3.0 """ @@ -724,19 +725,19 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[3] + a2*x[5] <= a3) sage: p.add_constraint(b1*x[3] + b2*x[5] <= b3) - sage: N(p.solve(),3) # optional - cvxopt + sage: N(p.solve(),3) # optional - cvxopt -3.0 To return the optimal value of ``x[3]``:: - sage: N(p.get_values(x[3]),3) # optional - cvxopt + sage: N(p.get_values(x[3]),3) # optional - cvxopt -1.0 To get a dictionary identical to ``x`` containing optimal values for the corresponding variables :: - sage: x_sol = p.get_values(x) # optional - cvxopt - sage: sorted(x_sol) # optional - cvxopt + sage: x_sol = p.get_values(x) # optional - cvxopt + sage: sorted(x_sol) # optional - cvxopt [3, 5] """ @@ -795,10 +796,10 @@ cdef class SemidefiniteProgram(SageObject): sage: a2 = matrix([[1,1],[1,1]]) sage: a3 = matrix([[1,-1],[-1,1]]) sage: p.add_constraint(a1*x[1]+a2*x[2] <= a3) - sage: N(p.solve(),digits=3) # optional - cvxopt + sage: N(p.solve(), digits=3) # optional - cvxopt 16.2 sage: p.set_objective(None) - sage: _ = p.solve() # optional - cvxopt + sage: _ = p.solve() # optional - cvxopt """ cdef list values = [] @@ -854,7 +855,7 @@ cdef class SemidefiniteProgram(SageObject): sage: a2 = matrix([[1,1],[1,1]]) sage: a3 = matrix([[1,-1],[-1,1]]) sage: p.add_constraint(a1*x[1]+a2*x[2] <= a3) - sage: N(p.solve(),digits=3) # optional - cvxopt + sage: N(p.solve(), digits=3) # optional - cvxopt 16.2 One can also define double-bounds or equality using the symbol @@ -867,7 +868,7 @@ cdef class SemidefiniteProgram(SageObject): sage: a2 = matrix([[1,1],[1,1]]) sage: a3 = matrix([[1,-1],[-1,1]]) sage: p.add_constraint(a3 >= a1*x[1] + a2*x[2]) - sage: N(p.solve(),digits=3) # optional - cvxopt + sage: N(p.solve(), digits=3) # optional - cvxopt 16.2 TESTS: @@ -947,12 +948,12 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: N(p.solve(),4) # optional - cvxopt + sage: N(p.solve(),4) # optional - cvxopt -11. - sage: x = p.get_values(x) # optional - cvxopt - sage: N(x[0],4) # optional - cvxopt + sage: x = p.get_values(x) # optional - cvxopt + sage: N(x[0],4) # optional - cvxopt -8.0 - sage: N(x[1],4) # optional - cvxopt + sage: N(x[1],4) # optional - cvxopt 3.0 """ self._backend.solve() @@ -990,7 +991,7 @@ cdef class SemidefiniteProgram(SageObject): sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) sage: p.solve() # tol 1e-08 # optional - cvxopt -3.0 - sage: x = p.get_values(x).values() # optional - cvxopt + sage: x = p.get_values(x).values() # optional - cvxopt sage: -(a3*p.dual_variable(0)).trace()-(b3*p.dual_variable(1)).trace() # tol 1e-07 # optional - cvxopt -3.0 @@ -1001,7 +1002,7 @@ cdef class SemidefiniteProgram(SageObject): TESTS:: - sage: p.dual_variable(7) # optional - cvxopt + sage: p.dual_variable(7) # optional - cvxopt Traceback (most recent call last): ... IndexError: list index out of range @@ -1035,21 +1036,21 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: p.solve() # tol 1e-08 # optional - cvxopt + sage: p.solve() # tol 1e-08 # optional - cvxopt -3.0 - sage: B1 = p.slack(1); B1 # tol 1e-08 # optional - cvxopt + sage: B1 = p.slack(1); B1 # tol 1e-08 # optional - cvxopt [0.0 0.0] [0.0 0.0] - sage: B1.is_positive_definite() # optional - cvxopt + sage: B1.is_positive_definite() # optional - cvxopt True - sage: x = sorted(p.get_values(x).values()) # optional - cvxopt - sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09 # optional - cvxopt + sage: x = sorted(p.get_values(x).values()) # optional - cvxopt + sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09 # optional - cvxopt [0.0 0.0] [0.0 0.0] TESTS:: - sage: p.slack(7) # optional - cvxopt + sage: p.slack(7) # optional - cvxopt Traceback (most recent call last): ... IndexError: list index out of range @@ -1076,20 +1077,21 @@ cdef class SemidefiniteProgram(SageObject): EXAMPLES:: - sage: p. = SemidefiniteProgram(solver = "cvxopt", maximization = False) # optional - cvxopt - sage: p.solver_parameter("show_progress", True) # optional - cvxopt - sage: p.solver_parameter("show_progress") # optional - cvxopt + sage: p. = SemidefiniteProgram(solver="cvxopt", # optional - cvxopt + ....: maximization=False) + sage: p.solver_parameter("show_progress", True) # optional - cvxopt + sage: p.solver_parameter("show_progress") # optional - cvxopt True - sage: p.set_objective(x[0] - x[1]) # optional - cvxopt + sage: p.set_objective(x[0] - x[1]) # optional - cvxopt sage: a1 = matrix([[1, 2.], [2., 3.]]) sage: a2 = matrix([[3, 4.], [4., 2.]]) sage: a3 = matrix([[5, 6.], [6., 7.]]) sage: b1 = matrix([[1, 1.], [1., 1.]]) sage: b2 = matrix([[2, 2.], [2., 1.]]) sage: b3 = matrix([[3, 3.], [3., 3.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - cvxopt - sage: N(p.solve(),4) # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - cvxopt + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - cvxopt + sage: N(p.solve(),4) # optional - cvxopt pcost dcost gap pres dres k/t 0: 1... ... @@ -1177,13 +1179,13 @@ class SDPSolverException(RuntimeError): No solution:: - sage: p = SemidefiniteProgram(solver="cvxopt") # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0]) # optional - cvxopt + sage: p = SemidefiniteProgram(solver="cvxopt") # optional - cvxopt + sage: x = p.new_variable() # optional - cvxopt + sage: p.set_objective(x[0]) # optional - cvxopt sage: a = matrix([[1,2],[2,4]]) sage: b = matrix([[1,9],[9,4]]) - sage: p.add_constraint( a*x[0] == b ) # optional - cvxopt - sage: p.solve() # optional - cvxopt + sage: p.add_constraint( a*x[0] == b ) # optional - cvxopt + sage: p.solve() # optional - cvxopt Traceback (most recent call last): ... SDPSolverException: ... diff --git a/src/sage/parallel/decorate.py b/src/sage/parallel/decorate.py index 97c612b4e45..e64b6ee087b 100644 --- a/src/sage/parallel/decorate.py +++ b/src/sage/parallel/decorate.py @@ -107,8 +107,8 @@ def __call__(self, f): sage: from sage.parallel.decorate import Parallel sage: p = Parallel() - sage: f = x^2-1 - sage: p(f) + sage: f = x^2 - 1 # optional - sage.symbolic + sage: p(f) # optional - sage.symbolic sage: P = sage.parallel.decorate.Parallel() @@ -342,7 +342,7 @@ def parallel(p_iter='fork', ncpus=None, **kwds): sage: @parallel(ncpus=3, timeout=10) ....: def fac(n): return factor(2^n-1) - sage: for X, Y in sorted(list(fac([101,119,151,197,209]))): print((X,Y)) + sage: for X, Y in sorted(list(fac([101,119,151,197,209]))): print((X,Y)) # optional - sage.libs.pari (((101,), {}), 7432339208719 * 341117531003194129) (((119,), {}), 127 * 239 * 20231 * 131071 * 62983048367 * 131105292137) (((151,), {}), 18121 * 55871 * 165799 * 2332951 * 7289088383388253664437433) @@ -531,30 +531,30 @@ def fork(f=None, timeout=0, verbose=False): We illustrate that the state of the pexpect interface is not altered by forked functions (they get their own new pexpect interfaces!):: - sage: gp.eval('a = 5') + sage: gp.eval('a = 5') # optional - sage.libs.pari '5' - sage: @fork() + sage: @fork() # optional - sage.libs.pari ....: def g(): ....: gp.eval('a = 10') ....: return gp.eval('a') - sage: g() + sage: g() # optional - sage.libs.pari '10' - sage: gp.eval('a') + sage: gp.eval('a') # optional - sage.libs.pari '5' We illustrate that the forked function has its own pexpect interface:: - sage: gp.eval('a = 15') + sage: gp.eval('a = 15') # optional - sage.libs.pari '15' - sage: @fork() + sage: @fork() # optional - sage.libs.pari ....: def g(): return gp.eval('a') - sage: g() + sage: g() # optional - sage.libs.pari 'a' We illustrate that segfaulting subprocesses are no trouble at all:: - sage: cython('def f(): print(0)') # optional - sage.misc.cython + sage: cython('def f(): print(0)') # optional - sage.misc.cython sage: @fork ....: def g(): ....: os.environ["CYSIGNALS_CRASH_NDEBUG"]="yes" # skip enhanced backtrace (it is slow) diff --git a/src/sage/plot/complex_plot.pyx b/src/sage/plot/complex_plot.pyx index 0586a96ae55..6c1eb17058d 100644 --- a/src/sage/plot/complex_plot.pyx +++ b/src/sage/plot/complex_plot.pyx @@ -670,11 +670,13 @@ def add_lightness_smoothing_to_rgb(rgb, delta): We can call this on grids of values:: - sage: import numpy as np - sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb - sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 + sage: import numpy as np # optional - numpy + sage: from sage.plot.complex_plot import add_lightness_smoothing_to_rgb # optional - numpy + sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 # optional - numpy + ....: np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) array([[[0.75 , 0.8125, 0.875 ]]]) - sage: add_lightness_smoothing_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 + sage: add_lightness_smoothing_to_rgb( # abs tol 1e-4 # optional - numpy + ....: np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) array([[[0.75 , 0.8125, 0.875 ]]]) """ import numpy as np @@ -732,21 +734,24 @@ def add_contours_to_rgb(rgb, delta, dark_rate=0.5): EXAMPLES:: - sage: import numpy as np - sage: from sage.plot.complex_plot import add_contours_to_rgb - sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), np.array([[0.75]])) # abs tol 1e-4 + sage: import numpy as np # optional - numpy + sage: from sage.plot.complex_plot import add_contours_to_rgb # optional - numpy + sage: add_contours_to_rgb(np.array([[[0, 0.25, 0.5]]]), # abs tol 1e-4 # optional - numpy + ....: np.array([[0.75]])) array([[[0.25 , 0.625, 1. ]]]) - sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), np.array([[1]])) # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[0, 0, 0]]]), # abs tol 1e-4 # optional - numpy + ....: np.array([[1]])) array([[[0.5, 0.5, 0.5]]]) - sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), np.array([[-0.5]])) # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[1, 1, 1]]]), # abs tol 1e-4 # optional - numpy + ....: np.array([[-0.5]])) array([[[0.75, 0.75, 0.75]]]) Raising ``dark_rate`` leads to bigger adjustments:: - sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # optional - numpy ....: np.array([[0.5]]), dark_rate=0.1) array([[[0.55, 0.55, 0.55]]]) - sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 + sage: add_contours_to_rgb(np.array([[[0.5, 0.5, 0.5]]]), # abs tol 1e-4 # optional - numpy ....: np.array([[0.5]]), dark_rate=0.5) array([[[0.75, 0.75, 0.75]]]) """ diff --git a/src/sage/plot/line.py b/src/sage/plot/line.py index 691e3c31307..8c2d8ec0ad1 100644 --- a/src/sage/plot/line.py +++ b/src/sage/plot/line.py @@ -391,14 +391,14 @@ def line2d(points, **options): sage: line([]) #returns an empty plot Graphics object consisting of 0 graphics primitives - sage: import numpy; line(numpy.array([])) + sage: import numpy; line(numpy.array([])) # optional - numpy Graphics object consisting of 0 graphics primitives sage: line([(1,1)]) Graphics object consisting of 1 graphics primitive A line with numpy arrays:: - sage: line(numpy.array([[1,2], [3,4]])) + sage: line(numpy.array([[1,2], [3,4]])) # optional - numpy Graphics object consisting of 1 graphics primitive A line with a legend:: diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index 9e7b72d1fd6..18718db3b82 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -496,8 +496,8 @@ def matrix_plot(mat, xrange=None, yrange=None, **options): As does plotting of NumPy arrays:: - sage: import numpy - sage: matrix_plot(numpy.random.rand(10, 10)) + sage: import numpy # optional - numpy + sage: matrix_plot(numpy.random.rand(10, 10)) # optional - numpy Graphics object consisting of 1 graphics primitive A plot title can be added to the matrix plot.:: diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index ced087a3814..c3b8609d431 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -683,16 +683,17 @@ def SelectiveFormatter(formatter, skip_values): sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt - sage: import numpy - sage: fig=plt.figure() - sage: ax=fig.add_subplot(111) - sage: t = numpy.arange(0.0, 2.0, 0.01) - sage: s = numpy.sin(2*numpy.pi*t) - sage: p = ax.plot(t, s) - sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1]) - sage: ax.xaxis.set_major_formatter(formatter) + sage: import numpy # optional - numpy + sage: fig = plt.figure() + sage: ax = fig.add_subplot(111) + sage: t = numpy.arange(0.0, 2.0, 0.01) # optional - numpy + sage: s = numpy.sin(2*numpy.pi*t) # optional - numpy + sage: p = ax.plot(t, s) # optional - numpy + sage: formatter = SelectiveFormatter(ax.xaxis.get_major_formatter(), # optional - numpy + ....: skip_values=[0,1]) + sage: ax.xaxis.set_major_formatter(formatter) # optional - numpy sage: import tempfile - sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: + sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - numpy ....: fig.savefig(f.name) """ @@ -717,16 +718,16 @@ def __init__(self, formatter, skip_values): sage: from sage.plot.plot import SelectiveFormatter sage: import matplotlib.pyplot as plt - sage: import numpy - sage: fig=plt.figure() - sage: ax=fig.add_subplot(111) - sage: t = numpy.arange(0.0, 2.0, 0.01) - sage: s = numpy.sin(2*numpy.pi*t) - sage: line=ax.plot(t, s) - sage: formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1]) - sage: ax.xaxis.set_major_formatter(formatter) + sage: import numpy # optional - numpy + sage: fig = plt.figure() + sage: ax = fig.add_subplot(111) + sage: t = numpy.arange(0.0, 2.0, 0.01) # optional - numpy + sage: s = numpy.sin(2*numpy.pi*t) # optional - numpy + sage: line = ax.plot(t, s) # optional - numpy + sage: formatter = SelectiveFormatter(ax.xaxis.get_major_formatter(), skip_values=[0,1]) # optional - numpy + sage: ax.xaxis.set_major_formatter(formatter) # optional - numpy sage: from tempfile import NamedTemporaryFile - sage: with NamedTemporaryFile(suffix=".png") as f: + sage: with NamedTemporaryFile(suffix=".png") as f: # optional - numpy ....: fig.savefig(f.name) """ self.formatter=formatter @@ -1139,9 +1140,12 @@ def plot(funcs, *args, **kwds): By default, color will change from one primitive to the next. This may be controlled by modifying ``color`` option:: - sage: g1 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), color='blue', aspect_ratio=.8); g1 + sage: g1 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), + ....: color='blue', aspect_ratio=.8); g1 Graphics object consisting of 3 graphics primitives - sage: g2 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), color=['red','red','green'], linestyle=['-','--','-.'], aspect_ratio=.8); g2 + sage: g2 = plot([x*exp(-n*x^2)/.4 for n in [1..3]], (0, 2), + ....: color=['red','red','green'], linestyle=['-','--','-.'], + ....: aspect_ratio=.8); g2 Graphics object consisting of 3 graphics primitives .. PLOT:: @@ -1601,7 +1605,7 @@ def h2(x): return -abs(sqrt(x**3 - 1)) sage: p2 = plot(sin(x), -pi, pi, fill='min', fillalpha=1) sage: p3 = plot(sin(x), -pi, pi, fill='max') sage: p4 = plot(sin(x), -pi, pi, fill=(1-x)/3, fillcolor='blue', fillalpha=.2) - sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time + sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time .. PLOT:: @@ -1615,11 +1619,15 @@ def h2(x): return -abs(sqrt(x**3 - 1)) The basic options for filling a list of plots:: sage: (f1, f2) = x*exp(-1*x^2)/.35, x*exp(-2*x^2)/.35 - sage: p1 = plot([f1, f2], -pi, pi, fill={1: [0]}, fillcolor='blue', fillalpha=.25, color='blue') - sage: p2 = plot([f1, f2], -pi, pi, fill={0: x/3, 1:[0]}, color=['blue']) - sage: p3 = plot([f1, f2], -pi, pi, fill=[0, [0]], fillcolor=['orange','red'], fillalpha=1, color={1: 'blue'}) - sage: p4 = plot([f1, f2], (x,-pi, pi), fill=[x/3, 0], fillcolor=['grey'], color=['red', 'blue']) - sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time + sage: p1 = plot([f1, f2], -pi, pi, fill={1: [0]}, + ....: fillcolor='blue', fillalpha=.25, color='blue') + sage: p2 = plot([f1, f2], -pi, pi, fill={0: x/3, 1:[0]}, + ....: color=['blue']) + sage: p3 = plot([f1, f2], -pi, pi, fill=[0, [0]], + ....: fillcolor=['orange','red'], fillalpha=1, color={1: 'blue'}) + sage: p4 = plot([f1, f2], (x,-pi, pi), fill=[x/3, 0], + ....: fillcolor=['grey'], color=['red', 'blue']) + sage: graphics_array([[p1, p2], [p3, p4]]).show(frame=True, axes=False) # long time .. PLOT:: @@ -1670,9 +1678,11 @@ def b(n): return lambda x: bessel_J(n, x) like ``i:j`` will fill between the ith function and the line y=j:: sage: def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) - sage: plot([b(c) for c in [1..5]], 0, 20, fill={i:[i-1] for i in [1..4]}, color={i:'blue' for i in [1..5]}, aspect_ratio=3, ymax=3) + sage: plot([b(c) for c in [1..5]], 0, 20, fill={i: [i-1] for i in [1..4]}, + ....: color={i: 'blue' for i in [1..5]}, aspect_ratio=3, ymax=3) Graphics object consisting of 9 graphics primitives - sage: plot([b(c) for c in [1..5]], 0, 20, fill={i:i-1 for i in [1..4]}, color='blue', aspect_ratio=3) # long time + sage: plot([b(c) for c in [1..5]], 0, 20, fill={i: i-1 for i in [1..4]}, # long time + ....: color='blue', aspect_ratio=3) Graphics object consisting of 9 graphics primitives .. PLOT:: @@ -1687,7 +1697,8 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) Extra options will get passed on to :meth:`~sage.plot.graphics.Graphics.show`, as long as they are valid:: - sage: plot(sin(x^2), (x, -3, 3), title=r'Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) # These labels will be nicely typeset + sage: plot(sin(x^2), (x, -3, 3), # These labels will be nicely typeset + ....: title=r'Plot of $\sin(x^2)$', axes_labels=['$x$','$y$']) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1697,7 +1708,8 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(sin(x^2), (x, -3, 3), title='Plot of sin(x^2)', axes_labels=['x','y']) # These will not + sage: plot(sin(x^2), (x, -3, 3), # These will not + ....: title='Plot of sin(x^2)', axes_labels=['x','y']) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1707,7 +1719,8 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(sin(x^2), (x, -3, 3), axes_labels=['x','y'], axes_labels_size=2.5) # Large axes labels (w.r.t. the tick marks) + sage: plot(sin(x^2), (x, -3, 3), # Large axes labels (w.r.t. the tick marks) + ....: axes_labels=['x','y'], axes_labels_size=2.5) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1719,7 +1732,7 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) sage: plot(sin(x^2), (x, -3, 3), figsize=[8,2]) Graphics object consisting of 1 graphics primitive - sage: plot(sin(x^2), (x, -3, 3)).show(figsize=[8,2]) # These are equivalent + sage: plot(sin(x^2), (x, -3, 3)).show(figsize=[8,2]) # These are equivalent .. PLOT:: @@ -1731,17 +1744,19 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]]) + sage: plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7], [-1/2,0,1/2]]) Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]]) + g = plot(sin(pi*x), (x, -8, 8), ticks=[[-7,-3,0,3,7], [-1/2,0,1/2]]) sphinx_plot(g) :: - sage: plot(2*x + 1, (x, 0, 5), ticks=[[0, 1, e, pi, sqrt(20)], [1, 3, 2*e + 1, 2*pi + 1, 2*sqrt(20) + 1]], tick_formatter="latex") + sage: plot(2*x + 1, (x, 0, 5), tick_formatter="latex", + ....: ticks=[[0, 1, e, pi, sqrt(20)], + ....: [1, 3, 2*e + 1, 2*pi + 1, 2*sqrt(20) + 1]]) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1753,7 +1768,7 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) :: - sage: plot(sin(x),(x,0,2*pi),ticks=pi/3,tick_formatter=pi) + sage: plot(sin(x), (x,0,2*pi), ticks=pi/3, tick_formatter=pi) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -1763,12 +1778,13 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) You can even have custom tick labels along with custom positioning. :: - sage: plot(x**2, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) + sage: plot(x**2, (x,0,3), ticks=[[1,2.5], [0.5,1,2]], + ....: tick_formatter=[["$x_1$","$x_2$"], ["$y_1$","$y_2$","$y_3$"]]) Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot(x**2, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]]) + g = plot(x**2, (x,0,3), ticks=[[1,2.5],[0.5,1,2]], tick_formatter=[["$x_1$","$x_2$"], ["$y_1$","$y_2$","$y_3$"]]) sphinx_plot(g) You can force Type 1 fonts in your figures by providing the relevant @@ -1859,7 +1875,7 @@ def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) sage: plot(arcsec(x/2), -2, 2) # plot should be empty; no valid points Graphics object consisting of 0 graphics primitives - sage: plot(sqrt(x^2-1), -2, 2) # [-1, 1] is excluded automatically + sage: plot(sqrt(x^2 - 1), -2, 2) # [-1, 1] is excluded automatically Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -2541,7 +2557,7 @@ def parametric_plot(funcs, *args, **kwargs): is 1, so that circles look like circles. :: sage: t = var('t') - sage: parametric_plot( (cos(t), sin(t)), (t, 0, 2*pi)) + sage: parametric_plot((cos(t), sin(t)), (t, 0, 2*pi)) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2552,7 +2568,7 @@ def parametric_plot(funcs, *args, **kwargs): :: - sage: parametric_plot( (sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6) ) + sage: parametric_plot((sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6) ) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2581,23 +2597,25 @@ def parametric_plot(funcs, *args, **kwargs): .. PLOT:: - t =var('t') + t = var('t') g = parametric_plot((t, t**2), (t, -4, 4), fill=True) sphinx_plot(g) A filled Hypotrochoid:: - sage: parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x,0, 8*pi), fill=True) + sage: parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], + ....: (x, 0, 8*pi), fill=True) Graphics object consisting of 2 graphics primitives .. PLOT:: - g = parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x,0, 8*pi), fill=True) + g = parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x, 0, 8*pi), fill=True) sphinx_plot(g) :: - sage: parametric_plot( (5*cos(x), 5*sin(x), x), (x,-12, 12), plot_points=150, color="red") # long time + sage: parametric_plot((5*cos(x), 5*sin(x), x), (x, -12, 12), # long time + ....: plot_points=150, color="red") Graphics3d Object .. PLOT:: @@ -2608,8 +2626,8 @@ def parametric_plot(funcs, *args, **kwargs): :: - sage: y=var('y') - sage: parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4)) # long time` + sage: y = var('y') + sage: parametric_plot((5*cos(x), x*y, cos(x*y)), (x, -4, 4), (y, -4, 4)) # long time` Graphics3d Object .. PLOT:: @@ -2621,8 +2639,8 @@ def parametric_plot(funcs, *args, **kwargs): :: - sage: t=var('t') - sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time + sage: t = var('t') + sage: parametric_plot(vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green') # long time Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2693,8 +2711,8 @@ def parametric_plot(funcs, *args, **kwargs): One test for :trac:`7165`:: - sage: m = SR.var('m') - sage: parametric_plot([real(exp(i*m)),imaginary(exp(i*m))], (m,0,7)) + sage: m = SR.var('m') # optional - sage.symbolic + sage: parametric_plot([real(exp(i*m)), imaginary(exp(i*m))], (m, 0, 7)) # optional - sage.symbolic Graphics object consisting of 1 graphics primitive """ num_ranges = 0 @@ -2797,7 +2815,8 @@ def polar_plot(funcs, *args, **kwds): Fill the area between two functions:: - sage: polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, fillcolor='orange') + sage: polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, + ....: fillcolor='orange') Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -2807,7 +2826,8 @@ def polar_plot(funcs, *args, **kwds): Fill the area between several spirals:: - sage: polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, fill={0: [1], 2: [3], 4: [5]}) + sage: polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, + ....: fill={0: [1], 2: [3], 4: [5]}) Graphics object consisting of 9 graphics primitives .. PLOT:: @@ -2863,7 +2883,7 @@ def list_plot(data, plotjoined=False, **kwargs): EXAMPLES:: - sage: list_plot([i^2 for i in range(5)]) # long time + sage: list_plot([i^2 for i in range(5)]) # long time Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2896,8 +2916,8 @@ def list_plot(data, plotjoined=False, **kwargs): You can provide a numpy array.:: - sage: import numpy - sage: list_plot(numpy.arange(10)) + sage: import numpy # optional - numpy + sage: list_plot(numpy.arange(10)) # optional - numpy Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2908,7 +2928,7 @@ def list_plot(data, plotjoined=False, **kwargs): :: - sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) + sage: list_plot(numpy.array([[1,2], [2,3], [3,4]])) # optional - numpy Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -2976,7 +2996,9 @@ def list_plot(data, plotjoined=False, **kwargs): sage: list_plot(x_coords, y_coords) Traceback (most recent call last): ... - TypeError: The second argument 'plotjoined' should be boolean (True or False). If you meant to plot two lists 'x' and 'y' against each other, use 'list_plot(list(zip(x,y)))'. + TypeError: The second argument 'plotjoined' should be boolean (True or False). + If you meant to plot two lists 'x' and 'y' against each other, + use 'list_plot(list(zip(x,y)))'. Dictionaries with numeric keys and values can be plotted:: @@ -3023,12 +3045,12 @@ def list_plot(data, plotjoined=False, **kwargs): Instead this will work. We drop the point `(0,1)`.:: - sage: list_plot(list(zip(range(1,len(yl)), yl[1:])), scale='loglog') # long time + sage: list_plot(list(zip(range(1,len(yl)), yl[1:])), scale='loglog') # long time Graphics object consisting of 1 graphics primitive We use :func:`list_plot_loglog` and plot in a different base.:: - sage: list_plot_loglog(list(zip(range(1,len(yl)), yl[1:])), base=2) # long time + sage: list_plot_loglog(list(zip(range(1,len(yl)), yl[1:])), base=2) # long time Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3235,22 +3257,22 @@ def plot_semilogy(funcs, *args, **kwds): EXAMPLES:: - sage: plot_semilogy(exp, (1,10)) # long time # plot in semilogy scale, base 10 + sage: plot_semilogy(exp, (1, 10)) # long time # plot in semilogy scale, base 10 Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot_semilogy(exp, (1,10)) # long time # plot in semilogy scale, base 10 + g = plot_semilogy(exp, (1,10)) # long time # plot in semilogy scale, base 10 sphinx_plot(g) :: - sage: plot_semilogy(exp, (1,10), base=2) # long time # with base 2 + sage: plot_semilogy(exp, (1, 10), base=2) # long time # with base 2 Graphics object consisting of 1 graphics primitive .. PLOT:: - g = plot_semilogy(exp, (1,10), base=2) # long time # with base 2 + g = plot_semilogy(exp, (1,10), base=2) # long time # with base 2 sphinx_plot(g) """ @@ -3274,19 +3296,20 @@ def list_plot_loglog(data, plotjoined=False, **kwds): EXAMPLES:: sage: yl = [5**k for k in range(10)]; xl = [2**k for k in range(10)] - sage: list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 + sage: list_plot_loglog(list(zip(xl, yl))) # long time # use loglog scale with base 10 Graphics object consisting of 1 graphics primitive .. PLOT:: yl = [5**k for k in range(10)] xl = [2**k for k in range(10)] - g = list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 + g = list_plot_loglog(list(zip(xl, yl))) # long time # plot in loglog scale with base 10 sphinx_plot(g) :: - sage: list_plot_loglog(list(zip(xl, yl)), base=2.1) # long time # with base 2.1 on both axes + sage: list_plot_loglog(list(zip(xl, yl)), # long time # with base 2.1 on both axes + ....: base=2.1) Graphics object consisting of 1 graphics primitive .. PLOT:: @@ -3298,7 +3321,8 @@ def list_plot_loglog(data, plotjoined=False, **kwds): :: - sage: list_plot_loglog(list(zip(xl, yl)), base=(2,5)) # long time + sage: list_plot_loglog(list(zip(xl, yl)), # long time + ....: base=(2, 5)) Graphics object consisting of 1 graphics primitive .. warning:: @@ -3472,13 +3496,14 @@ def reshape(v, n, m): :: - sage: M = [[plot(sin(k*x),(x,-pi,pi)) for k in range(3)],[plot(cos(j*x),(x,-pi,pi)) for j in [3..5]]] + sage: M = [[plot(sin(k*x), (x,-pi,pi)) for k in range(3)], + ....: [plot(cos(j*x), (x,-pi,pi)) for j in [3..5]]] sage: graphics_array(M,6,1) # long time (up to 4s on sage.math, 2012) Graphics Array of size 6 x 1 TESTS:: - sage: L = [plot(sin(k*x),(x,-pi,pi)) for k in [1..3]] + sage: L = [plot(sin(k*x), (x,-pi,pi)) for k in [1..3]] sage: graphics_array(L,0,-1) # indirect doctest Traceback (most recent call last): ... @@ -3539,10 +3564,10 @@ def graphics_array(array, nrows=None, ncols=None): sage: f(x) = sin(x) sage: g(x) = sin(2*x) sage: h(x) = sin(4*x) - sage: p1 = plot(f, (-2*pi,2*pi), color=hue(0.5)) # long time - sage: p2 = plot(g, (-2*pi,2*pi), color=hue(0.9)) # long time - sage: p3 = parametric_plot((f,g), (0,2*pi), color=hue(0.6)) # long time - sage: p4 = parametric_plot((f,h), (0,2*pi), color=hue(1.0)) # long time + sage: p1 = plot(f, (-2*pi,2*pi), color=hue(0.5)) # long time + sage: p2 = plot(g, (-2*pi,2*pi), color=hue(0.9)) # long time + sage: p3 = parametric_plot((f,g), (0,2*pi), color=hue(0.6)) # long time + sage: p4 = parametric_plot((f,h), (0,2*pi), color=hue(1.0)) # long time Now make a graphics array out of the plots:: @@ -3570,8 +3595,8 @@ def h(x): return sin(4*x) Here we give only one row:: - sage: p1 = plot(sin,(-4,4)) - sage: p2 = plot(cos,(-4,4)) + sage: p1 = plot(sin, (-4,4)) + sage: p2 = plot(cos, (-4,4)) sage: ga = graphics_array([p1, p2]) sage: ga Graphics Array of size 1 x 2 @@ -3827,7 +3852,8 @@ def adaptive_refinement(f, p1, p2, adaptive_tolerance=0.01, TESTS:: sage: from sage.plot.plot import adaptive_refinement - sage: adaptive_refinement(sin, (0,0), (pi,0), adaptive_tolerance=0.01, adaptive_recursion=0) + sage: adaptive_refinement(sin, (0,0), (pi,0), adaptive_tolerance=0.01, + ....: adaptive_recursion=0) [] sage: adaptive_refinement(sin, (0,0), (pi,0), adaptive_tolerance=0.01) [(0.125*pi, 0.3826834323650898), (0.1875*pi, 0.5555702330196022), (0.25*pi, 0.7071067811865475), (0.3125*pi, 0.8314696123025452), (0.375*pi, 0.9238795325112867), (0.4375*pi, 0.9807852804032304), (0.5*pi, 1.0), (0.5625*pi, 0.9807852804032304), (0.625*pi, 0.9238795325112867), (0.6875*pi, 0.8314696123025455), (0.75*pi, 0.7071067811865476), (0.8125*pi, 0.5555702330196022), (0.875*pi, 0.3826834323650899)] @@ -3843,7 +3869,8 @@ def adaptive_refinement(f, p1, p2, adaptive_tolerance=0.01, sage: f(x) = sin(1/x) sage: n1 = len(adaptive_refinement(f, (0,0), (pi,0), adaptive_tolerance=0.01)); n1 15 - sage: n2 = len(adaptive_refinement(f, (0,0), (pi,0), adaptive_recursion=10, adaptive_tolerance=0.01)); n2 + sage: n2 = len(adaptive_refinement(f, (0,0), (pi,0), adaptive_recursion=10, + ....: adaptive_tolerance=0.01)); n2 79 sage: n3 = len(adaptive_refinement(f, (0,0), (pi,0), adaptive_tolerance=0.001)); n3 26 diff --git a/src/sage/repl/configuration.py b/src/sage/repl/configuration.py index 1890dc207d4..5a1f9c44ca8 100644 --- a/src/sage/repl/configuration.py +++ b/src/sage/repl/configuration.py @@ -7,11 +7,11 @@ the IPython simple prompt is being used:: sage: cmd = 'print([sys.stdin.isatty(), sys.stdout.isatty()])' - sage: import pexpect - sage: output = pexpect.run( + sage: import pexpect # optional - pexpect + sage: output = pexpect.run( # optional - pexpect ....: 'bash -c \'echo "{0}" | sage\''.format(cmd), ....: ).decode('utf-8', 'surrogateescape') - sage: 'sage: [False, True]' in output + sage: 'sage: [False, True]' in output # optional - pexpect True """ diff --git a/src/sage/repl/display/formatter.py b/src/sage/repl/display/formatter.py index 7e06656d880..6b2b6e1a083 100644 --- a/src/sage/repl/display/formatter.py +++ b/src/sage/repl/display/formatter.py @@ -24,17 +24,17 @@ sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.run_cell('%display ascii_art') - sage: shell.run_cell('integral(x^2/pi^x, x)') + sage: shell.run_cell('integral(x^2/pi^x, x)') # optional - sage.symbolic -x / 2 2 \ -pi *\x *log (pi) + 2*x*log(pi) + 2/ -------------------------------------- 3 log (pi) - sage: shell.run_cell("i = var('i')") - sage: shell.run_cell('sum(i*x^i, i, 0, 10)') + sage: shell.run_cell("i = var('i')") # optional - sage.symbolic + sage: shell.run_cell('sum(i*x^i, i, 0, 10)') # optional - sage.symbolic 10 9 8 7 6 5 4 3 2 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x - sage: shell.run_cell('StandardTableaux(4).list()') + sage: shell.run_cell('StandardTableaux(4).list()') # optional - sage.combinat [ [ 1 4 1 3 [ 1 3 4 1 2 4 1 2 3 1 3 1 2 2 2 @@ -132,8 +132,8 @@ def format(self, obj, include=None, exclude=None): sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.run_cell('%display ascii_art') # indirect doctest - sage: shell.run_cell("i = var('i')") - sage: shell.run_cell('sum(i*x^i, i, 0, 10)') + sage: shell.run_cell("i = var('i')") # optional - sage.symbolic + sage: shell.run_cell('sum(i*x^i, i, 0, 10)') # optional - sage.symbolic 10 9 8 7 6 5 4 3 2 10*x + 9*x + 8*x + 7*x + 6*x + 5*x + 4*x + 3*x + 2*x + x sage: shell.run_cell('%display default') diff --git a/src/sage/repl/display/jsmol_iframe.py b/src/sage/repl/display/jsmol_iframe.py index 4775d2a02e7..0a7456ad75c 100644 --- a/src/sage/repl/display/jsmol_iframe.py +++ b/src/sage/repl/display/jsmol_iframe.py @@ -112,7 +112,7 @@ def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'): EXAMPLES:: sage: from sage.repl.display.jsmol_iframe import JSMolHtml - sage: JSMolHtml(sphere(), width=500, height=300) + sage: JSMolHtml(sphere(), width=500, height=300) # optional - sage.plot JSmol Window 500x300 """ from sage.repl.rich_output.output_graphics3d import OutputSceneJmol diff --git a/src/sage/repl/interface_magic.py b/src/sage/repl/interface_magic.py index 856bdcd120d..95e1c90ec7a 100644 --- a/src/sage/repl/interface_magic.py +++ b/src/sage/repl/interface_magic.py @@ -123,7 +123,7 @@ def register_all(cls, shell=None): ('maxima', 'cell') sage: 'gap' in MockShell.magics True - sage: 'maxima' in MockShell.magics + sage: 'maxima' in MockShell.magics # optional - sage.symbolic True """ if shell is None: diff --git a/src/sage/repl/ipython_extension.py b/src/sage/repl/ipython_extension.py index cad6a47ca8b..4d7ee485b29 100644 --- a/src/sage/repl/ipython_extension.py +++ b/src/sage/repl/ipython_extension.py @@ -350,12 +350,13 @@ def cython(self, line, cell): sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() - sage: shell.run_cell(''' + sage: shell.run_cell( # optional - sage.misc.cython + ....: ''' ....: %%cython ....: def f(): ....: print('test') ....: ''') - sage: f() + sage: f() # optional - sage.misc.cython test """ from sage.misc.cython import cython_compile @@ -406,10 +407,10 @@ def fortran(self, line, cell): ....: ''') sage: fib - sage: from numpy import array - sage: a = array(range(10), dtype=float) - sage: fib(a, 10) - sage: a + sage: from numpy import array # optional - numpy + sage: a = array(range(10), dtype=float) # optional - numpy + sage: fib(a, 10) # optional - numpy + sage: a # optional - numpy array([ 0., 1., 1., 2., 3., 5., 8., 13., 21., 34.]) """ from sage.misc.inline_fortran import fortran diff --git a/src/sage/repl/ipython_kernel/interact.py b/src/sage/repl/ipython_kernel/interact.py index 4f96a212ab7..3677a5a8f83 100644 --- a/src/sage/repl/ipython_kernel/interact.py +++ b/src/sage/repl/ipython_kernel/interact.py @@ -182,12 +182,12 @@ def widget_from_single_value(cls, abbrev, *args, **kwds): sage: from sage.repl.ipython_kernel.interact import sage_interactive sage: sage_interactive.widget_from_single_value("sin(x)") ...Text(value='sin(x)') - sage: sage_interactive.widget_from_single_value(sin(x)) + sage: sage_interactive.widget_from_single_value(sin(x)) # optional - sage.symbolic ...EvalText(value='sin(x)') - sage: from sage.plot.colors import Color - sage: sage_interactive.widget_from_single_value(matrix([[1, 2], [3, 4]])) + sage: sage_interactive.widget_from_single_value(matrix([[1, 2], [3, 4]])) # optional - sage.modules ...Grid(value=[[1, 2], [3, 4]], children=(Label(value=''), VBox(children=(EvalText(value='1', layout=Layout(max_width='5em')), EvalText(value='3', layout=Layout(max_width='5em')))), VBox(children=(EvalText(value='2', layout=Layout(max_width='5em')), EvalText(value='4', layout=Layout(max_width='5em')))))) - sage: sage_interactive.widget_from_single_value(Color('cornflowerblue')) + sage: from sage.plot.colors import Color # optional - sage.plot + sage: sage_interactive.widget_from_single_value(Color('cornflowerblue')) # optional - sage.plot ...SageColorPicker(value='#6495ed') """ # Support Sage matrices and colors @@ -226,15 +226,15 @@ def widget_from_tuple(cls, abbrev, *args, **kwds): ...IntSlider(value=3, max=10) sage: sage_interactive.widget_from_tuple((2, [('one', 1), ('two', 2), ('three', 3)])) ...Dropdown(index=1, options=(('one', 1), ('two', 2), ('three', 3)), value=2) - sage: sage_interactive.widget_from_tuple( (sqrt(2), pi) ) + sage: sage_interactive.widget_from_tuple( (sqrt(2), pi) ) # optional - sage.symbolic ...FloatSlider(value=2.277903107981444, max=3.141592653589793, min=1.4142135623730951) TESTS: Symbolic subrings:: - sage: SCR = SR.subring(no_variables=True) - sage: sage_interactive.widget_from_tuple( (SCR(sqrt(2)), SCR(pi)) ) + sage: SCR = SR.subring(no_variables=True) # optional - sage.symbolic + sage: sage_interactive.widget_from_tuple( (SCR(sqrt(2)), SCR(pi)) ) # optional - sage.symbolic ...FloatSlider(value=2.277903107981444, max=3.141592653589793, min=1.4142135623730951) """ # Support (description, abbrev) diff --git a/src/sage/repl/ipython_kernel/widgets.py b/src/sage/repl/ipython_kernel/widgets.py index 3ba45df9b04..1ba03bf4b9b 100644 --- a/src/sage/repl/ipython_kernel/widgets.py +++ b/src/sage/repl/ipython_kernel/widgets.py @@ -100,7 +100,7 @@ class TransformWidget(): sage: from ipywidgets import ToggleButtons sage: from sage.repl.ipython_kernel.widgets import TransformWidget sage: class TransformToggleButtons(TransformWidget, ToggleButtons): pass - sage: w = TransformToggleButtons(options=["pi", "e"], transform=lambda x: x+x) + sage: w = TransformToggleButtons(options=["pi", "e"], transform=lambda x: x + x) sage: w TransformToggleButtons(options=('pi', 'e'), value='pi') sage: w.get_interact_value() @@ -239,7 +239,8 @@ class TransformIntRangeSlider(TransformWidget, IntRangeSlider): EXAMPLES:: sage: from sage.repl.ipython_kernel.widgets import TransformIntRangeSlider - sage: w = TransformIntRangeSlider(min=0, max=100, value=(7,9), transform=lambda x: x[1]-x[0]) + sage: w = TransformIntRangeSlider(min=0, max=100, value=(7, 9), + ....: transform=lambda x: x[1] - x[0]) sage: w TransformIntRangeSlider(value=(7, 9)) sage: w.get_interact_value() @@ -256,7 +257,8 @@ class TransformFloatRangeSlider(TransformWidget, FloatRangeSlider): EXAMPLES:: sage: from sage.repl.ipython_kernel.widgets import TransformFloatRangeSlider - sage: w = TransformFloatRangeSlider(min=0, max=100, value=(7,9), transform=lambda x: x[1]-x[0]) + sage: w = TransformFloatRangeSlider(min=0, max=100, value=(7, 9), + ....: transform=lambda x: x[1] - x[0]) sage: w TransformFloatRangeSlider(value=(7.0, 9.0)) sage: w.get_interact_value() @@ -273,7 +275,7 @@ class TransformText(TransformWidget, Text): EXAMPLES:: sage: from sage.repl.ipython_kernel.widgets import TransformText - sage: w = TransformText(value="hello", transform=lambda x: x+x) + sage: w = TransformText(value="hello", transform=lambda x: x + x) sage: w TransformText(value='hello') sage: w.get_interact_value() @@ -290,7 +292,7 @@ class TransformTextarea(TransformWidget, Textarea): EXAMPLES:: sage: from sage.repl.ipython_kernel.widgets import TransformTextarea - sage: w = TransformTextarea(value="hello", transform=lambda x: x+x) + sage: w = TransformTextarea(value="hello", transform=lambda x: x + x) sage: w TransformTextarea(value='hello') sage: w.get_interact_value() @@ -351,7 +353,7 @@ def get_interact_value(self): EXAMPLES:: sage: from sage.repl.ipython_kernel.widgets import SageColorPicker - sage: SageColorPicker().get_interact_value() + sage: SageColorPicker().get_interact_value() # optional - sage.plot RGB color (0.0, 0.0, 0.0) """ return Color(self.value) @@ -370,7 +372,10 @@ class Grid(TransformWidget, HBox, ValueWidget): sage: from sage.repl.ipython_kernel.widgets import Grid sage: w = Grid(2, 2, lambda i,j: Text(value="%s,%s"%(i,j))) sage: w - Grid(value=[['0,0', '0,1'], ['1,0', '1,1']], children=(Label(value=''), VBox(children=(Text(value='0,0'), Text(value='1,0'))), VBox(children=(Text(value='0,1'), Text(value='1,1'))))) + Grid(value=[['0,0', '0,1'], ['1,0', '1,1']], + children=(Label(value=''), + VBox(children=(Text(value='0,0'), Text(value='1,0'))), + VBox(children=(Text(value='0,1'), Text(value='1,1'))))) sage: w.get_interact_value() [['0,0', '0,1'], ['1,0', '1,1']] """ @@ -398,7 +403,10 @@ def __init__(self, nrows, ncols, make_widget, description=u"", transform=None): sage: w = Grid(2, 2, lambda i,j: EvalText(str(j+4*i)), ....: description="2x2 matrix", transform=matrix) sage: w - Grid(value=[[0, 1], [4, 5]], children=(Label(value='2x2 matrix'), VBox(children=(EvalText(value='0'), EvalText(value='4'))), VBox(children=(EvalText(value='1'), EvalText(value='5'))))) + Grid(value=[[0, 1], [4, 5]], + children=(Label(value='2x2 matrix'), + VBox(children=(EvalText(value='0'), EvalText(value='4'))), + VBox(children=(EvalText(value='1'), EvalText(value='5'))))) sage: w.get_interact_value() [0 1] [4 5] diff --git a/src/sage/repl/load.py b/src/sage/repl/load.py index d43363682b0..8f9519eb095 100644 --- a/src/sage/repl/load.py +++ b/src/sage/repl/load.py @@ -132,7 +132,7 @@ def load(filename, globals, attach=False): sage: with open(t, 'w') as f: ....: _ = f.write("print(('hi', 2^3)); z = -2^7") sage: z = 1 - sage: sage.repl.load.load(t, globals()) + sage: sage.repl.load.load(t, globals()) # optional - sage.misc.cython Compiling ... ('hi', 1) sage: z diff --git a/src/sage/repl/preparse.py b/src/sage/repl/preparse.py index 6c5e15042fb..618fb66fc2a 100644 --- a/src/sage/repl/preparse.py +++ b/src/sage/repl/preparse.py @@ -82,18 +82,18 @@ Symbolic functional notation:: - sage: a=10; f(theta, beta) = theta + beta; b = x^2 + theta # optional - sage.symbolic - sage: f # optional - sage.symbolic + sage: a=10; f(theta, beta) = theta + beta; b = x^2 + theta # optional - sage.symbolic + sage: f # optional - sage.symbolic (theta, beta) |--> beta + theta - sage: a # optional - sage.symbolic + sage: a # optional - sage.symbolic 10 - sage: b # optional - sage.symbolic + sage: b # optional - sage.symbolic x^2 + theta - sage: f(theta,theta) # optional - sage.symbolic + sage: f(theta,theta) # optional - sage.symbolic 2*theta - sage: a = 5; f(x,y) = x*y*sqrt(a) # optional - sage.symbolic - sage: f # optional - sage.symbolic + sage: a = 5; f(x,y) = x*y*sqrt(a) # optional - sage.symbolic + sage: f # optional - sage.symbolic (x, y) |--> sqrt(5)*x*y This involves an =-, but should still be turned into a symbolic @@ -101,8 +101,8 @@ sage: preparse('a(x) =- 5') '__tmp__=var("x"); a = symbolic_expression(- Integer(5)).function(x)' - sage: f(x)=-x # optional - sage.symbolic - sage: f(10) # optional - sage.symbolic + sage: f(x)=-x # optional - sage.symbolic + sage: f(10) # optional - sage.symbolic -10 This involves -=, which should not be turned into a symbolic @@ -1726,7 +1726,7 @@ def preparse(line, reset=True, do_time=False, ignore_prompts=False, "ZZ = ZZ['u,v']; (x, y,) = ZZ._first_ngens(2)" sage: preparse("ZZ. = QQ[2^(1/3)]") 'ZZ = QQ[Integer(2)**(Integer(1)/Integer(3))]; (x,) = ZZ._first_ngens(1)' - sage: QQ[2^(1/3)] + sage: QQ[2^(1/3)] # optional - sage.symbolic sage.rings.number_field Number Field in a with defining polynomial x^3 - 2 with a = 1.259921049894873? sage: preparse("a^b") diff --git a/src/sage/repl/rich_output/backend_base.py b/src/sage/repl/rich_output/backend_base.py index e9ca0b4d3ba..5674f726728 100644 --- a/src/sage/repl/rich_output/backend_base.py +++ b/src/sage/repl/rich_output/backend_base.py @@ -459,11 +459,11 @@ def latex_formatter(self, obj, **kwds): sage: out.html.get_str() '\\(\\displaystyle \\frac{1}{2}\\)' - sage: out = backend.latex_formatter([1/2, x, 3/4, ZZ], concatenate=False) - sage: out.html.get_str() + sage: out = backend.latex_formatter([1/2, x, 3/4, ZZ], concatenate=False) # optional - sage.symbolic + sage: out.html.get_str() # optional - sage.symbolic '\\(\\displaystyle \\newcommand{\\Bold}[1]{\\mathbf{#1}}\\left[\\frac{1}{2}, x, \\frac{3}{4}, \\Bold{Z}\\right]\\)' - sage: out = backend.latex_formatter([1/2, x, 3/4, ZZ], concatenate=True) - sage: out.html.get_str() + sage: out = backend.latex_formatter([1/2, x, 3/4, ZZ], concatenate=True) # optional - sage.symbolic + sage: out.html.get_str() # optional - sage.symbolic '\\(\\displaystyle \\newcommand{\\Bold}[1]{\\mathbf{#1}}\\frac{1}{2} x \\frac{3}{4} \\Bold{Z}\\)' TESTS:: diff --git a/src/sage/repl/rich_output/backend_doctest.py b/src/sage/repl/rich_output/backend_doctest.py index da9cb737a2a..fd532e82fa3 100644 --- a/src/sage/repl/rich_output/backend_doctest.py +++ b/src/sage/repl/rich_output/backend_doctest.py @@ -164,14 +164,14 @@ def displayhook(self, plain_text, rich_output): This ends up calling the displayhook:: - sage: plt = plot(sin) - sage: plt + sage: plt = plot(sin) # optional - sage.plot sage.symbolic + sage: plt # optional - sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive - sage: plt.show() + sage: plt.show() # optional - sage.plot sage.symbolic sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() - sage: dm.displayhook(plt) # indirect doctest + sage: dm.displayhook(plt) # indirect doctest # optional - sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive """ self.validate(rich_output) @@ -198,14 +198,14 @@ def display_immediately(self, plain_text, rich_output): displayhook, the plot is still shown. Nothing is shown during doctests:: - sage: plt = plot(sin) - sage: plt + sage: plt = plot(sin) # optional - sage.plot sage.symbolic + sage: plt # optional - sage.plot sage.symbolic Graphics object consisting of 1 graphics primitive - sage: plt.show() + sage: plt.show() # optional - sage.plot sage.symbolic sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() - sage: dm.display_immediately(plt) # indirect doctest + sage: dm.display_immediately(plt) # indirect doctest # optional - sage.plot sage.symbolic """ self.validate(rich_output) types_to_print = [OutputPlainText, OutputAsciiArt, OutputUnicodeArt, OutputHtml] diff --git a/src/sage/repl/rich_output/display_manager.py b/src/sage/repl/rich_output/display_manager.py index f022335f8e6..80beda0f391 100644 --- a/src/sage/repl/rich_output/display_manager.py +++ b/src/sage/repl/rich_output/display_manager.py @@ -708,13 +708,14 @@ def graphics_from_save(self, save_function, save_kwds, sage: from sage.repl.rich_output import get_display_manager sage: dm = get_display_manager() - sage: plt = plot(sin) - sage: out = dm.graphics_from_save(plt.save, dict(), '.png', dm.types.OutputImagePng) - sage: out + sage: plt = plot(sin) # optional - sage.symbolic sage.plot + sage: out = dm.graphics_from_save(plt.save, dict(), '.png', # optional - sage.symbolic sage.plot + ....: dm.types.OutputImagePng) + sage: out # optional - sage.symbolic sage.plot OutputImagePng container - sage: out.png.get().startswith(b'\x89PNG') + sage: out.png.get().startswith(b'\x89PNG') # optional - sage.symbolic sage.plot True - sage: out.png.filename() # random + sage: out.png.filename() # random # optional - sage.symbolic sage.plot '/home/user/.sage/temp/localhost.localdomain/23903/tmp_pu5woK.png' """ import os diff --git a/src/sage/repl/rich_output/output_basic.py b/src/sage/repl/rich_output/output_basic.py index 2166715d364..29391c90b79 100644 --- a/src/sage/repl/rich_output/output_basic.py +++ b/src/sage/repl/rich_output/output_basic.py @@ -320,7 +320,7 @@ def __init__(self, latex): EXAMPLES:: sage: from sage.repl.rich_output.output_catalog import OutputLatex - sage: OutputLatex(latex(sqrt(x))) + sage: OutputLatex(latex(sqrt(x))) # optional - sage.symbolic OutputLatex container """ self.latex = OutputBuffer(latex) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 4d4e9bfd104..77536d718bb 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -14,13 +14,13 @@ class NumberField_quadratic(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K. = QuadraticField(2) # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.NumberField_quadratic) # optional - sage.rings.number_field + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: isinstance(K, sage.rings.abc.NumberField_quadratic) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.NumberField_quadratic.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.NumberField_quadratic.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_quadratic.__subclasses__()) <= 1 @@ -40,13 +40,13 @@ class NumberField_cyclotomic(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K. = CyclotomicField(15) # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.NumberField_cyclotomic) # optional - sage.rings.number_field + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: isinstance(K, sage.rings.abc.NumberField_cyclotomic) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.NumberField_cyclotomic.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.NumberField_cyclotomic.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_cyclotomic.__subclasses__()) <= 1 @@ -66,16 +66,16 @@ class AlgebraicField_common(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field True - sage: isinstance(AA, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field True By design, other than the abstract subclasses :class:`~sage.rings.abc.AlgebraicField` and :class:`~sage.rings.abc.AlgebraicRealField`, there is only one direct implementation subclass:: - sage: sage.rings.abc.AlgebraicField_common.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicField_common.__subclasses__() # optional - sage.rings.number_field [, , ] @@ -97,14 +97,14 @@ class AlgebraicField(AlgebraicField_common): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field True - sage: isinstance(AA, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field False By design, there is a unique direct subclass:: - sage: sage.rings.abc.AlgebraicField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicField.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.AlgebraicField.__subclasses__()) <= 1 @@ -124,14 +124,14 @@ class AlgebraicRealField(AlgebraicField_common): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field False - sage: isinstance(AA, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.AlgebraicRealField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicRealField.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.AlgebraicRealField.__subclasses__()) <= 1 @@ -376,13 +376,13 @@ class Order: EXAMPLES:: sage: import sage.rings.abc - sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field - sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field + sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.Order.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.Order.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.Order.__subclasses__()) <= 1 @@ -402,14 +402,14 @@ class pAdicRing(EuclideanDomain): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) + sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics True - sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) + sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics False By design, there is a unique direct subclass:: - sage: sage.rings.abc.pAdicRing.__subclasses__() + sage: sage.rings.abc.pAdicRing.__subclasses__() # optional - sage.rings.padics [] sage: len(sage.rings.abc.pAdicRing.__subclasses__()) <= 1 @@ -429,14 +429,14 @@ class pAdicField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(Zp(5), sage.rings.abc.pAdicField) + sage: isinstance(Zp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics False - sage: isinstance(Qp(5), sage.rings.abc.pAdicField) + sage: isinstance(Qp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics True By design, there is a unique direct subclass:: - sage: sage.rings.abc.pAdicField.__subclasses__() + sage: sage.rings.abc.pAdicField.__subclasses__() # optional - sage.rings.padics [] sage: len(sage.rings.abc.pAdicField.__subclasses__()) <= 1 @@ -456,13 +456,13 @@ cdef class SymbolicRing(CommutativeRing): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(SR, sage.rings.abc.SymbolicRing) # optional - sage.symbolic + sage: isinstance(SR, sage.rings.abc.SymbolicRing) # optional - sage.symbolic True By design, other than the abstract subclass :class:`~sage.rings.abc.CallableSymbolicExpressionRing`, there is only one direct implementation subclass:: - sage: sage.rings.abc.SymbolicRing.__subclasses__() # optional - sage.symbolic + sage: sage.rings.abc.SymbolicRing.__subclasses__() # optional - sage.symbolic [, ] @@ -483,13 +483,13 @@ class CallableSymbolicExpressionRing(SymbolicRing): EXAMPLES:: sage: import sage.rings.abc - sage: f = x.function(x).parent() # optional - sage.symbolic - sage: isinstance(f, sage.rings.abc.CallableSymbolicExpressionRing) # optional - sage.symbolic + sage: f = x.function(x).parent() # optional - sage.symbolic + sage: isinstance(f, sage.rings.abc.CallableSymbolicExpressionRing) # optional - sage.symbolic True By design, there is a unique direct subclass:: - sage: sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__() # optional - sage.symbolic + sage: sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__() # optional - sage.symbolic [] sage: len(sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__()) <= 1 diff --git a/src/sage/rings/algebraic_closure_finite_field.py b/src/sage/rings/algebraic_closure_finite_field.py index 6f6b93955cb..fb62627c9dc 100644 --- a/src/sage/rings/algebraic_closure_finite_field.py +++ b/src/sage/rings/algebraic_closure_finite_field.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Algebraic closures of finite fields diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 332977164f4..8315bb078bd 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -473,13 +473,13 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): EXAMPLES:: - sage: CDF._magma_init_(magma) # optional - magma + sage: CDF._magma_init_(magma) # optional - magma 'ComplexField(53 : Bits := true)' - sage: magma(CDF) # optional - magma + sage: magma(CDF) # optional - magma Complex field of precision 15 sage: floor(RR(log(2**53, 10))) 15 - sage: magma(CDF).sage() # optional - magma + sage: magma(CDF).sage() # optional - magma Complex Field with 53 bits of precision """ return "ComplexField(%s : Bits := true)" % self.prec() @@ -2570,11 +2570,11 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: f = CDF.coerce_map_from(numpy.complex_) - sage: f(numpy.complex_(I)) + sage: import numpy # optional - numpy + sage: f = CDF.coerce_map_from(numpy.complex_) # optional - numpy + sage: f(numpy.complex_(I)) # optional - numpy 1.0*I - sage: f(numpy.complex_(I)).parent() + sage: f(numpy.complex_(I)).parent() # optional - numpy Complex Double Field """ def __init__(self, R): @@ -2590,8 +2590,8 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: CDF(numpy.complex_(I)) # indirect doctest + sage: import numpy # optional - numpy + sage: CDF(numpy.complex_(I)) # indirect doctest # optional - numpy 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) @@ -2604,9 +2604,9 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) - sage: f._repr_type() + sage: import numpy # optional - numpy + sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) # optional - numpy + sage: f._repr_type() # optional - numpy 'Native' """ return "Native" diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 4fc6c4c8d35..319d6000b83 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -1039,10 +1039,10 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1.0, 2.5j]).dtype + sage: import numpy # optional - numpy + sage: numpy.array([1.0, 2.5j]).dtype # optional - numpy dtype('complex128') - sage: numpy.array([1.000000000000000000000000000000000000j]).dtype + sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # optional - numpy dtype('O') """ if self._prec <= 53: diff --git a/src/sage/rings/derivation.py b/src/sage/rings/derivation.py index 4c8cb4662b9..74903e6072f 100644 --- a/src/sage/rings/derivation.py +++ b/src/sage/rings/derivation.py @@ -35,7 +35,8 @@ sage: A. = QQ[] sage: M = A.derivation_module() sage: M - Module of derivations over Multivariate Polynomial Ring in x, y, z over Rational Field + Module of derivations over + Multivariate Polynomial Ring in x, y, z over Rational Field The method :meth:`~sage.rings.derivation.RingDerivationModule.gens` returns the generators of this module:: @@ -76,8 +77,10 @@ Sage knows moreover that `M` is a Lie algebra:: sage: M.category() - Join of Category of lie algebras with basis over Rational Field - and Category of modules with basis over Multivariate Polynomial Ring in x, y, z over Rational Field + Join of + Category of lie algebras with basis over Rational Field and + Category of modules with basis over + Multivariate Polynomial Ring in x, y, z over Rational Field Computations of Lie brackets are implemented as well:: @@ -116,7 +119,9 @@ sage: M = A.derivation_module(ev) sage: M - Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Rational Field sage: M.gens() (d/dx, d/dy, d/dz) @@ -138,7 +143,8 @@ sage: theta = B.hom([B(y),B(z),B(x)]) sage: theta - Ring endomorphism of Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field + Ring endomorphism of Fraction Field of + Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> y y |--> z z |--> x @@ -225,25 +231,32 @@ def __init__(self, domain, codomain, twist=None): sage: TestSuite(M).run() sage: from sage.rings.derivation import RingDerivationModule - sage: R5. = GF(5)[] - sage: R25. = GF(25)[] - sage: R7. = GF(7)[] - - sage: RingDerivationModule(R5, R25) - Module of derivations from Univariate Polynomial Ring in x over Finite Field of size 5 to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 - sage: RingDerivationModule(R5, R5^2) + sage: R5. = GF(5)[] # optional - sage.rings.finite_rings + sage: R25. = GF(25)[] # optional - sage.rings.finite_rings + sage: R7. = GF(7)[] # optional - sage.rings.finite_rings + + sage: RingDerivationModule(R5, R25) # optional - sage.rings.finite_rings + Module of derivations + from Univariate Polynomial Ring in x over Finite Field of size 5 + to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 + sage: RingDerivationModule(R5, R5^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - sage: RingDerivationModule(R5, R7) + TypeError: the codomain must be an algebra over the domain + or a morphism with the correct domain + sage: RingDerivationModule(R5, R7) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - - sage: theta = R5.hom([R5.gen()^2]) - sage: RingDerivationModule(R5, R25, twist=theta) - Module of twisted derivations from Univariate Polynomial Ring in x over Finite Field of size 5 to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 (twisting morphism: x |--> x^2) - sage: RingDerivationModule(R7, R7, twist=theta) + TypeError: the codomain must be an algebra over the domain + or a morphism with the correct domain + + sage: theta = R5.hom([R5.gen()^2]) # optional - sage.rings.finite_rings + sage: RingDerivationModule(R5, R25, twist=theta) # optional - sage.rings.finite_rings + Module of twisted derivations + from Univariate Polynomial Ring in x over Finite Field of size 5 + to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 + (twisting morphism: x |--> x^2) + sage: RingDerivationModule(R7, R7, twist=theta) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: the domain of the derivation must coerce to the domain of the twisting homomorphism @@ -460,8 +473,10 @@ def _coerce_map_from_(self, R): sage: M1 = A.derivation_module(); M1 Module of derivations over Univariate Polynomial Ring in x over Rational Field sage: M2 = A.derivation_module(B); M2 - Module of derivations from Univariate Polynomial Ring in x over Rational Field - to Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Module of derivations + from Univariate Polynomial Ring in x over Rational Field + to Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: M1._coerce_map_from_(M2) is None True sage: M1.has_coerce_map_from(M2) @@ -567,7 +582,8 @@ def defining_morphism(self): sage: M.defining_morphism() Polynomial base injection morphism: From: Univariate Polynomial Ring in x over Rational Field - To: Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + To: Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: ev = R.hom([QQ(0)]) sage: M = R.derivation_module(ev) @@ -857,7 +873,8 @@ def codomain(self): sage: S. = R[] sage: M = R.derivation_module(S) sage: M.random_element().codomain() - Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: M.random_element().codomain() is S True @@ -1057,10 +1074,10 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = GF(5)[] - sage: D = sum(v*R.derivation(v) for v in R.gens()); D + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: D = sum(v*R.derivation(v) for v in R.gens()); D # optional - sage.rings.finite_rings x*d/dx + y*d/dy + z*d/dz - sage: D.pth_power() == D + sage: D.pth_power() == D # optional - sage.rings.finite_rings True """ @@ -1132,17 +1149,17 @@ def pth_power(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: Dx = R.derivation(x) - sage: Dx.pth_power() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: Dx = R.derivation(x) # optional - sage.rings.finite_rings + sage: Dx.pth_power() # optional - sage.rings.finite_rings 0 - sage: (x*Dx).pth_power() + sage: (x*Dx).pth_power() # optional - sage.rings.finite_rings x*d/dx - sage: (x^6*Dx).pth_power() + sage: (x^6*Dx).pth_power() # optional - sage.rings.finite_rings x^26*d/dx - sage: Dy = R.derivation(y) - sage: (x*Dx + y*Dy).pth_power() + sage: Dy = R.derivation(y) # optional - sage.rings.finite_rings + sage: (x*Dx + y*Dy).pth_power() # optional - sage.rings.finite_rings x*d/dx + y*d/dy An error is raised if the domain has characteristic zero:: @@ -1165,14 +1182,14 @@ def pth_power(self): TESTS:: - sage: R. = GF(3)[] - sage: D = R.derivation_module().random_element() - sage: Dp = D.pth_power() - sage: f = R.random_element() - sage: Dp(f) == D(D(D(f))) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: D = R.derivation_module().random_element() # optional - sage.rings.finite_rings + sage: Dp = D.pth_power() # optional - sage.rings.finite_rings + sage: f = R.random_element() # optional - sage.rings.finite_rings + sage: Dp(f) == D(D(D(f))) # optional - sage.rings.finite_rings True - sage: D.bracket(Dp) + sage: D.bracket(Dp) # optional - sage.rings.finite_rings 0 """ @@ -1562,14 +1579,14 @@ def __init__(self, parent, arg=None): TESTS:: sage: from sage.rings.derivation import RingDerivationWithoutTwist_wrapper - sage: R. = GF(5)[] - sage: S = R.quo([x^5, y^5]) - sage: M = S.derivation_module() - sage: der = M.random_element() - sage: isinstance(der, RingDerivationWithoutTwist_wrapper) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S = R.quo([x^5, y^5]) # optional - sage.rings.finite_rings + sage: M = S.derivation_module() # optional - sage.rings.finite_rings + sage: der = M.random_element() # optional - sage.rings.finite_rings + sage: isinstance(der, RingDerivationWithoutTwist_wrapper) # optional - sage.rings.finite_rings True - sage: TestSuite(der).run() + sage: TestSuite(der).run() # optional - sage.rings.finite_rings """ if isinstance(arg, list) and len(arg) == 1 and isinstance(arg[0], RingDerivation): @@ -1600,11 +1617,11 @@ def _add_(self, other): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dy = S.derivation(y) - sage: Dx + Dy + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dy = S.derivation(y) # optional - sage.rings.finite_rings + sage: Dx + Dy # optional - sage.rings.finite_rings d/dx + d/dy """ @@ -1616,11 +1633,11 @@ def _sub_(self, other): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dy = S.derivation(y) - sage: Dx - Dy + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dy = S.derivation(y) # optional - sage.rings.finite_rings + sage: Dx - Dy # optional - sage.rings.finite_rings d/dx - d/dy """ @@ -1632,10 +1649,10 @@ def _neg_(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: -Dx + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: -Dx # optional - sage.rings.finite_rings -d/dx """ @@ -1647,12 +1664,12 @@ def _lmul_(self, factor): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dx * 2 + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dx * 2 # optional - sage.rings.finite_rings 2*d/dx - sage: Dx * x^2 + sage: Dx * x^2 # optional - sage.rings.finite_rings x^2*d/dx """ @@ -1664,12 +1681,12 @@ def _rmul_(self, factor): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: 2 * Dx + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: 2 * Dx # optional - sage.rings.finite_rings 2*d/dx - sage: x^2 * Dx + sage: x^2 * Dx # optional - sage.rings.finite_rings x^2*d/dx """ @@ -1682,20 +1699,20 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: M = S.derivation_module() - sage: M.basis() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: M = S.derivation_module() # optional - sage.rings.finite_rings + sage: M.basis() # optional - sage.rings.finite_rings Family (d/dx, d/dy) - sage: S.derivation(x).list() + sage: S.derivation(x).list() # optional - sage.rings.finite_rings [1, 0] - sage: S.derivation(y).list() + sage: S.derivation(y).list() # optional - sage.rings.finite_rings [0, 1] - sage: f = x*S.derivation(x) + y*S.derivation(y); f + sage: f = x*S.derivation(x) + y*S.derivation(y); f # optional - sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [x, y] """ @@ -1889,19 +1906,19 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[[]] - sage: M = R.derivation_module() - sage: M.basis() + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: M = R.derivation_module() # optional - sage.rings.finite_rings + sage: M.basis() # optional - sage.rings.finite_rings Family (d/dx, d/dy) - sage: R.derivation(x).list() + sage: R.derivation(x).list() # optional - sage.rings.finite_rings [1, 0] - sage: R.derivation(y).list() + sage: R.derivation(y).list() # optional - sage.rings.finite_rings [0, 1] - sage: f = x*R.derivation(x) + y*R.derivation(y); f + sage: f = x*R.derivation(x) + y*R.derivation(y); f # optional - sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [x, y] """ @@ -1974,11 +1991,11 @@ def _call_(self, x): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: f = x^3*S.derivation(); f + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: f = x^3*S.derivation(); f # optional - sage.rings.finite_rings x^3*d/dx - sage: f(x^3) + sage: f(x^3) # optional - sage.rings.finite_rings 0 """ @@ -2074,10 +2091,10 @@ def _latex_(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: der = k.derivation(a+1, twist=Frob) - sage: latex(der) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: der = k.derivation(a + 1, twist=Frob) # optional - sage.rings.finite_rings + sage: latex(der) # optional - sage.rings.finite_rings \left(a + 1\right) \left(\left[a \mapsto a^{5}\right] - \text{id}\right) """ scalar = self._scalar diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 77def414b13..fb61d7e801a 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -53,23 +53,23 @@ cpdef aurifeuillian(n, m, F=None, bint check=True): EXAMPLES:: sage: from sage.rings.factorint import aurifeuillian - sage: aurifeuillian(2,2) + sage: aurifeuillian(2, 2) [5, 13] - sage: aurifeuillian(2,2^5) + sage: aurifeuillian(2, 2^5) [1985, 2113] - sage: aurifeuillian(5,3) + sage: aurifeuillian(5, 3) [1471, 2851] - sage: aurifeuillian(15,1) + sage: aurifeuillian(15, 1) [19231, 142111] - sage: aurifeuillian(12,3) + sage: aurifeuillian(12, 3) Traceback (most recent call last): ... ValueError: n has to be square-free - sage: aurifeuillian(1,2) + sage: aurifeuillian(1, 2) Traceback (most recent call last): ... ValueError: n has to be greater than 1 - sage: aurifeuillian(2,0) + sage: aurifeuillian(2, 0) Traceback (most recent call last): ... ValueError: m has to be positive @@ -133,24 +133,24 @@ cpdef factor_aurifeuillian(n, check=True): EXAMPLES:: sage: from sage.rings.factorint import factor_aurifeuillian as fa - sage: fa(2^6+1) + sage: fa(2^6 + 1) # optional - sage.libs.pari [5, 13] - sage: fa(2^58+1) + sage: fa(2^58 + 1) # optional - sage.libs.pari [536838145, 536903681] - sage: fa(3^3+1) + sage: fa(3^3 + 1) # optional - sage.libs.pari [4, 1, 7] - sage: fa(5^5-1) + sage: fa(5^5 - 1) # optional - sage.libs.pari [4, 11, 71] - sage: prod(_) == 5^5-1 + sage: prod(_) == 5^5 - 1 # optional - sage.libs.pari True - sage: fa(2^4+1) + sage: fa(2^4 + 1) # optional - sage.libs.pari [17] - sage: fa((6^2*3)^3+1) + sage: fa((6^2*3)^3 + 1) # optional - sage.libs.pari [109, 91, 127] TESTS:: - sage: for n in [2,3,5,6,30,31,33]: + sage: for n in [2,3,5,6,30,31,33]: # optional - sage.libs.pari ....: for m in [8,96,109201283]: ....: s = -1 if n % 4 == 1 else 1 ....: y = (m^2*n)^n + s @@ -206,9 +206,9 @@ cpdef factor_aurifeuillian(n, check=True): def factor_cunningham(m, proof=None): r""" - Return factorization of self obtained using trial division + Return factorization of ``self`` obtained using trial division for all primes in the so called Cunningham table. This is - efficient if self has some factors of type `b^n+1` or `b^n-1`, + efficient if ``self`` has some factors of type `b^n+1` or `b^n-1`, with `b` in `\{2,3,5,6,7,10,11,12\}`. You need to install an optional package to use this method, @@ -226,7 +226,7 @@ def factor_cunningham(m, proof=None): sage: from sage.rings.factorint import factor_cunningham sage: factor_cunningham(2^257-1) # optional - cunningham_tables 535006138814359 * 1155685395246619182673033 * 374550598501810936581776630096313181393 - sage: factor_cunningham((3^101+1)*(2^60).next_prime(),proof=False) # optional - cunningham_tables + sage: factor_cunningham((3^101+1)*(2^60).next_prime(), proof=False) # optional - cunningham_tables 2^2 * 379963 * 1152921504606847009 * 1017291527198723292208309354658785077827527 """ @@ -249,12 +249,12 @@ def factor_cunningham(m, proof=None): cpdef factor_trial_division(m, long limit=LONG_MAX): r""" - Return partial factorization of self obtained using trial division - for all primes up to limit, where limit must fit in a C signed long. + Return partial factorization of ``self`` obtained using trial division + for all primes up to ``limit``, where ``limit`` must fit in a C ``signed long``. INPUT: - - ``limit`` -- integer (default: ``LONG_MAX``) that fits in a C signed long + - ``limit`` -- integer (default: ``LONG_MAX``) that fits in a C ``signed long`` EXAMPLES:: @@ -298,7 +298,7 @@ def factor_using_pari(n, int_=False, debug_level=0, proof=None): r""" Factor this integer using PARI. - This function returns a list of pairs, not a ``Factorization`` + This function returns a list of pairs, not a :class:`Factorization` object. The first element of each pair is the factor, of type ``Integer`` if ``int_`` is ``False`` or ``int`` otherwise, the second element is the positive exponent, of type ``int``. @@ -321,16 +321,16 @@ def factor_using_pari(n, int_=False, debug_level=0, proof=None): EXAMPLES:: - sage: factor(-2**72 + 3, algorithm='pari') # indirect doctest + sage: factor(-2**72 + 3, algorithm='pari') # indirect doctest # optional - sage.libs.pari -1 * 83 * 131 * 294971519 * 1472414939 Check that PARI's debug level is properly reset (:trac:`18792`):: - sage: alarm(0.5); factor(2^1000 - 1, verbose=5) + sage: alarm(0.5); factor(2^1000 - 1, verbose=5) # optional - sage.libs.pari Traceback (most recent call last): ... AlarmInterrupt - sage: pari.get_debug_level() + sage: pari.get_debug_level() # optional - sage.libs.pari 0 """ from sage.libs.pari.all import pari diff --git a/src/sage/rings/fast_arith.pyx b/src/sage/rings/fast_arith.pyx index df9b592cf97..dfaa7782962 100644 --- a/src/sage/rings/fast_arith.pyx +++ b/src/sage/rings/fast_arith.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari """ Basic arithmetic with C integers """ @@ -58,16 +59,16 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False): - ``algorithm`` -- optional string (default: ``None``), one of: - - ``None``: Use algorithm ``"pari_primes"`` if ``stop`` <= 436273009 - (approximately 4.36E8). Otherwise use algorithm ``"pari_isprime"``. + - ``None``: Use algorithm ``"pari_primes"`` if ``stop`` <= 436273009 + (approximately 4.36E8). Otherwise use algorithm ``"pari_isprime"``. - - ``"pari_primes"``: Use PARI's :pari:`primes` function to generate all - primes from 2 to stop. This is fast but may crash if there is - insufficient memory. Raises an error if ``stop`` > 436273009. + - ``"pari_primes"``: Use PARI's :pari:`primes` function to generate all + primes from 2 to stop. This is fast but may crash if there is + insufficient memory. Raises an error if ``stop`` > 436273009. - - ``"pari_isprime"``: Wrapper for ``list(primes(start, stop))``. Each (odd) - integer in the specified range is tested for primality by applying PARI's - :pari:`isprime` function. This is slower but will work for much larger input. + - ``"pari_isprime"``: Wrapper for ``list(primes(start, stop))``. Each (odd) + integer in the specified range is tested for primality by applying PARI's + :pari:`isprime` function. This is slower but will work for much larger input. - ``py_ints`` -- optional boolean (default ``False``), return Python ints rather than Sage Integers (faster). Ignored unless algorithm ``"pari_primes"`` is being diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index a7e32004002..2eaf497dd2a 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings """ Base class for finite field elements diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 086590a962b..49abe86126f 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings """ Base class for finite fields diff --git a/src/sage/rings/finite_rings/finite_field_constructor.py b/src/sage/rings/finite_rings/finite_field_constructor.py index 048da483147..1690b3cf8dd 100644 --- a/src/sage/rings/finite_rings/finite_field_constructor.py +++ b/src/sage/rings/finite_rings/finite_field_constructor.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Finite fields diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index ec3268dc84e..9f850a12661 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -349,11 +349,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: TestSuite(Zmod(2^10 * 3^5)).run() sage: TestSuite(Zmod(2^30 * 3^50 * 5^20)).run() - sage: GF(29)(SR(1/3)) + sage: GF(29)(SR(1/3)) # optional - sage.rings.finite_rings sage.symbolic 10 sage: Integers(30)(QQ['x'](1/7)) 13 - sage: Integers(30)(SR(1/4)) + sage: Integers(30)(SR(1/4)) # optional - sage.symbolic Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(4, 30) does not exist @@ -505,7 +505,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: a = Integers(90384098234^3) - sage: factor(a.order()) + sage: factor(a.order()) # optional - sage.libs.pari 2^3 * 191^3 * 236607587^3 sage: b = a(2*191) sage: b.is_nilpotent() @@ -546,13 +546,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: a = Mod(2,19) - sage: gap(a) + sage: gap(a) # optional - sage.libs.gap Z(19) - sage: gap(Mod(3, next_prime(10000))) + sage: gap(Mod(3, next_prime(10000))) # optional - sage.libs.gap Z(10007)^6190 - sage: gap(Mod(3, next_prime(100000))) + sage: gap(Mod(3, next_prime(100000))) # optional - sage.libs.gap ZmodpZObj( 3, 100003 ) - sage: gap(Mod(4, 48)) + sage: gap(Mod(4, 48)) # optional - sage.libs.gap ZmodnZObj( 4, 48 ) """ return '%s*One(ZmodnZ(%s))' % (self, self.__modulus.sageInteger) @@ -605,18 +605,18 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: K = GF(7) - sage: sage_input(K(5), verify=True) + sage: K = GF(7) # optional - sage.rings.finite_rings + sage: sage_input(K(5), verify=True) # optional - sage.rings.finite_rings # Verified GF(7)(5) - sage: sage_input(K(5) * polygen(K), verify=True) + sage: sage_input(K(5) * polygen(K), verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] 5*x sage: from sage.misc.sage_input import SageInputBuilder - sage: K(5)._sage_input_(SageInputBuilder(), False) + sage: K(5)._sage_input_(SageInputBuilder(), False) # optional - sage.rings.finite_rings {call: {call: {atomic:GF}({atomic:7})}({atomic:5})} - sage: K(5)._sage_input_(SageInputBuilder(), True) + sage: K(5)._sage_input_(SageInputBuilder(), True) # optional - sage.rings.finite_rings {atomic:5} """ v = sib.int(self.lift()) @@ -653,39 +653,39 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: r = Integers(125) - sage: b = r.multiplicative_generator()^3 - sage: a = b^17 - sage: a.log(b) + sage: b = r.multiplicative_generator()^3 # optional - sage.libs.pari + sage: a = b^17 # optional - sage.libs.pari + sage: a.log(b) # optional - sage.libs.pari 17 - sage: a.log() + sage: a.log() # optional - sage.libs.pari 51 A bigger example:: - sage: FF = FiniteField(2^32+61) - sage: c = FF(4294967356) - sage: x = FF(2) - sage: a = c.log(x) - sage: a + sage: FF = FiniteField(2^32 + 61) # optional - sage.rings.finite_rings + sage: c = FF(4294967356) # optional - sage.rings.finite_rings + sage: x = FF(2) # optional - sage.rings.finite_rings + sage: a = c.log(x) # optional - sage.rings.finite_rings + sage: a # optional - sage.rings.finite_rings 2147483678 - sage: x^a + sage: x^a # optional - sage.rings.finite_rings 4294967356 An example with a highly composite modulus:: sage: m = 2^99 * 77^7 * 123456789 * 13712923537615486607^2 - sage: (Mod(5,m)^5735816763073854953388147237921).log(5) + sage: (Mod(5,m)^5735816763073854953388147237921).log(5) # optional - sage.libs.pari 5735816763073854953388147237921 Errors are generated if the logarithm doesn't exist or the inputs are not units:: - sage: Mod(3, 7).log(Mod(2, 7)) + sage: Mod(3, 7).log(Mod(2, 7)) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no logarithm of 3 found to base 2 modulo 7 - sage: a = Mod(16, 100); b = Mod(4,100) - sage: a.log(b) + sage: a = Mod(16, 100); b = Mod(4, 100) # optional - sage.libs.pari + sage: a.log(b) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: logarithm of 16 is not defined since it is not a unit modulo 100 @@ -694,51 +694,51 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`9205` is fixed:: - sage: Mod(5,9).log(Mod(2, 9)) + sage: Mod(5, 9).log(Mod(2, 9)) # optional - sage.libs.pari 5 We test against a bug (side effect on PARI) fixed in :trac:`9438`:: sage: R. = QQ[] - sage: pari(b) + sage: pari(b) # optional - sage.libs.pari b - sage: GF(7)(5).log() + sage: GF(7)(5).log() # optional - sage.rings.finite_rings 5 - sage: pari(b) + sage: pari(b) # optional - sage.libs.pari b We test that :trac:`23927` is fixed:: sage: x = mod(48475563673907791151, 10^20 + 763)^2 sage: e = 25248843418589594761 - sage: (x^e).log(x)==e + sage: (x^e).log(x) == e # optional - sage.libs.pari True Examples like this took extremely long before :trac:`32375`:: - sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) + sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) # optional - sage.libs.pari 99999999999999999999999999999999999999999999999999 We check that non-existence of solutions is detected: No local solutions:: - sage: Mod(1111, 1234567).log(1111**3) + sage: Mod(1111, 1234567).log(1111**3) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no logarithm of 1111 found to base 961261 modulo 1234567 (no solution modulo 9721) Incompatible local solutions:: - sage: Mod(230, 323).log(173) + sage: Mod(230, 323).log(173) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no logarithm of 230 found to base 173 modulo 323 (incompatible local solutions) We test that :trac:`12419` is fixed:: - sage: R. = GF(2)[] - sage: R(1).factor() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: R(1).factor() # optional - sage.rings.finite_rings 1 AUTHORS: @@ -818,9 +818,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: m = Mod(3, 1568) - sage: v = m.generalised_log(); v + sage: v = m.generalised_log(); v # optional - sage.libs.pari [1, 3, 1] - sage: prod([Zmod(1568).unit_gens()[i] ** v[i] for i in [0..2]]) + sage: prod([Zmod(1568).unit_gens()[i] ** v[i] for i in [0..2]]) # optional - sage.libs.pari 3 .. SEEALSO:: @@ -869,11 +869,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(3) - sage: a = k.gen() - sage: a.charpoly('x') + sage: k = GF(3) # optional - sage.rings.finite_rings + sage: a = k.gen() # optional - sage.rings.finite_rings + sage: a.charpoly('x') # optional - sage.rings.finite_rings x + 2 - sage: a + 2 + sage: a + 2 # optional - sage.rings.finite_rings 0 AUTHORS: @@ -889,7 +889,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(241, 'a')(1).minpoly() + sage: GF(241, 'a')(1).minpoly() # optional - sage.rings.finite_rings x + 240 """ return self.charpoly(var) @@ -900,7 +900,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(241, 'a')(1).minimal_polynomial(var = 'z') + sage: GF(241, 'a')(1).minimal_polynomial(var = 'z') # optional - sage.rings.finite_rings z + 240 """ return self.minpoly(var) @@ -911,12 +911,12 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(7) - sage: a = k.gen(); a + sage: k = GF(7) # optional - sage.rings.finite_rings + sage: a = k.gen(); a # optional - sage.rings.finite_rings 1 - sage: a.polynomial() + sage: a.polynomial() # optional - sage.rings.finite_rings 1 - sage: type(a.polynomial()) + sage: type(a.polynomial()) # optional - sage.rings.finite_rings """ R = self.parent()[var] @@ -929,9 +929,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(691) - sage: a = k(389) - sage: a.norm() + sage: k = GF(691) # optional - sage.rings.finite_rings + sage: a = k(389) # optional - sage.rings.finite_rings + sage: a.norm() # optional - sage.rings.finite_rings 389 AUTHORS: @@ -947,9 +947,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(691) - sage: a = k(389) - sage: a.trace() + sage: k = GF(691) # optional - sage.rings.finite_rings + sage: a = k(389) # optional - sage.rings.finite_rings + sage: a.trace() # optional - sage.rings.finite_rings 389 AUTHORS: @@ -1028,27 +1028,27 @@ cdef class IntegerMod_abstract(FiniteRingElement): r""" EXAMPLES:: - sage: Mod(3,17).is_square() + sage: Mod(3, 17).is_square() False - sage: Mod(9,17).is_square() + sage: Mod(9, 17).is_square() # optional - sage.libs.pari True - sage: Mod(9,17*19^2).is_square() + sage: Mod(9, 17*19^2).is_square() # optional - sage.libs.pari True - sage: Mod(-1,17^30).is_square() + sage: Mod(-1, 17^30).is_square() # optional - sage.libs.pari True - sage: Mod(1/9, next_prime(2^40)).is_square() + sage: Mod(1/9, next_prime(2^40)).is_square() # optional - sage.libs.pari True - sage: Mod(1/25, next_prime(2^90)).is_square() + sage: Mod(1/25, next_prime(2^90)).is_square() # optional - sage.libs.pari True TESTS:: - sage: Mod(1/25, 2^8).is_square() + sage: Mod(1/25, 2^8).is_square() # optional - sage.libs.pari True - sage: Mod(1/25, 2^40).is_square() + sage: Mod(1/25, 2^40).is_square() # optional - sage.libs.pari True - sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time + sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time # optional - sage.libs.pari ....: for ep,eq,er in cartesian_product_iterator([[0,1,2,3],[0,1,2,3],[0,1,2,3]]): ....: for e2 in [0, 1, 2, 3, 4]: ....: n = p^ep * q^eq * r^er * 2^e2 @@ -1126,21 +1126,21 @@ cdef class IntegerMod_abstract(FiniteRingElement): 86 sage: mod(7, 18).sqrt() 5 - sage: a = mod(14, 5^60).sqrt() - sage: a*a + sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari + sage: a*a # optional - sage.libs.pari 14 - sage: mod(15, 389).sqrt(extend=False) + sage: mod(15, 389).sqrt(extend=False) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: self must be a square - sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) + sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari 9 - sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) + sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari 25 :: - sage: a = Mod(3,5); a + sage: a = Mod(3, 5); a 3 sage: x = Mod(-1, 360) sage: x.sqrt(extend=False) @@ -1171,22 +1171,22 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: R = Integers(5*13^3*37); R Ring of integers modulo 406445 - sage: v = R(-1).sqrt(all=True); v + sage: v = R(-1).sqrt(all=True); v # optional - sage.libs.pari [78853, 111808, 160142, 193097, 213348, 246303, 294637, 327592] - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444] - sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) + sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) # optional - sage.libs.pari (13, 13, 104) - sage: all(x^2 == 169 for x in v) + sage: all(x^2 == 169 for x in v) # optional - sage.libs.pari True :: - sage: t = FiniteField(next_prime(2^100))(4) - sage: t.sqrt(extend = False, all = True) + sage: t = FiniteField(next_prime(2^100))(4) # optional - sage.rings.finite_rings + sage: t.sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [2, 1267650600228229401496703205651] - sage: t = FiniteField(next_prime(2^100))(2) - sage: t.sqrt(extend = False, all = True) + sage: t = FiniteField(next_prime(2^100))(2) # optional - sage.rings.finite_rings + sage: t.sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [] Modulo a power of 2:: @@ -1378,38 +1378,39 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: K = GF(31) - sage: a = K(22) - sage: K(22).nth_root(7) + sage: K = GF(31) # optional - sage.rings.finite_rings + sage: a = K(22) # optional - sage.rings.finite_rings + sage: K(22).nth_root(7) # optional - sage.rings.finite_rings 13 - sage: K(25).nth_root(5) + sage: K(25).nth_root(5) # optional - sage.rings.finite_rings 5 - sage: K(23).nth_root(3) + sage: K(23).nth_root(3) # optional - sage.rings.finite_rings 29 - sage: mod(225,2^5*3^2).nth_root(4, all=True) - [225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231] - sage: mod(275,2^5*7^4).nth_root(7, all=True) + sage: mod(225, 2^5*3^2).nth_root(4, all=True) # optional - sage.rings.padics + [225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, + 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231] + sage: mod(275, 2^5*7^4).nth_root(7, all=True) # optional - sage.rings.padics [58235, 25307, 69211, 36283, 3355, 47259, 14331] - sage: mod(1,8).nth_root(2,all=True) + sage: mod(1,8).nth_root(2, all=True) # optional - sage.rings.padics [1, 7, 5, 3] - sage: mod(4,8).nth_root(2,all=True) + sage: mod(4,8).nth_root(2, all=True) # optional - sage.rings.padics [2, 6] - sage: mod(1,16).nth_root(4,all=True) + sage: mod(1,16).nth_root(4, all=True) # optional - sage.rings.padics [1, 15, 13, 3, 9, 7, 5, 11] - sage: (mod(22,31)^200).nth_root(200) + sage: (mod(22,31)^200).nth_root(200) # optional - sage.groups 5 - sage: mod(3,6).nth_root(0,all=True) + sage: mod(3,6).nth_root(0, all=True) # optional - sage.rings.padics [] sage: mod(3,6).nth_root(0) Traceback (most recent call last): ... ValueError - sage: mod(1,6).nth_root(0,all=True) + sage: mod(1,6).nth_root(0, all=True) # optional - sage.rings.padics [1, 2, 3, 4, 5] TESTS:: - sage: for p in [1009,2003,10007,100003]: + sage: for p in [1009,2003,10007,100003]: # optional - sage.rings.finite_rings ....: K = GF(p) ....: for r in (p-1).divisors(): ....: if r == 1: continue @@ -1419,7 +1420,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): ....: if (y^41).nth_root(41*r)**(41*r) != y^41: raise RuntimeError ....: if (y^307).nth_root(307*r)**(307*r) != y^307: raise RuntimeError - sage: for t in range(200): + sage: for t in range(200): # optional - sage.libs.pari ....: n = randint(1,2^63) ....: K = Integers(n) ....: b = K.random_element() @@ -1434,18 +1435,18 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`13172` is resolved:: - sage: mod(-1, 4489).nth_root(2, all=True) + sage: mod(-1, 4489).nth_root(2, all=True) # optional - sage.rings.padics [] We check that :trac:`32084` is fixed:: - sage: mod(24, 25).nth_root(50)^50 + sage: mod(24, 25).nth_root(50)^50 # optional - sage.rings.padics 24 Check that the code path cunningham might be used:: sage: a = Mod(9,11) - sage: a.nth_root(2, False, True, 'Johnston', cunningham = True) # optional - cunningham_tables + sage: a.nth_root(2, False, True, 'Johnston', cunningham=True) # optional - cunningham_tables [3, 8] ALGORITHM: @@ -1626,11 +1627,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): This method is also inherited by prime finite fields elements:: - sage: k = GF(97) - sage: a = k(RationalField()('2/3')) - sage: a + sage: k = GF(97) # optional - sage.rings.finite_rings + sage: a = k(RationalField()('2/3')) # optional - sage.rings.finite_rings + sage: a # optional - sage.rings.finite_rings 33 - sage: a.rational_reconstruction() + sage: a.rational_reconstruction() # optional - sage.rings.finite_rings 2/3 """ return self.lift().rational_reconstruction(self.modulus()) @@ -1645,21 +1646,21 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: a = mod(3,5) - sage: b = mod(2,7) + sage: a = mod(3, 5) + sage: b = mod(2, 7) sage: a.crt(b) 23 :: - sage: a = mod(37,10^8) - sage: b = mod(9,3^8) + sage: a = mod(37, 10^8) + sage: b = mod(9, 3^8) sage: a.crt(b) 125900000037 :: - sage: b = mod(0,1) + sage: b = mod(0, 1) sage: a.crt(b) == a True sage: a.crt(b).modulus() @@ -1667,17 +1668,17 @@ cdef class IntegerMod_abstract(FiniteRingElement): TESTS:: - sage: mod(0,1).crt(mod(4,2^127)) + sage: mod(0, 1).crt(mod(4, 2^127)) 4 - sage: mod(4,2^127).crt(mod(0,1)) + sage: mod(4, 2^127).crt(mod(0, 1)) 4 - sage: mod(4,2^30).crt(mod(0,1)) + sage: mod(4, 2^30).crt(mod(0, 1)) 4 - sage: mod(0,1).crt(mod(4,2^30)) + sage: mod(0, 1).crt(mod(4, 2^30)) 4 - sage: mod(0,1).crt(mod(4,2^15)) + sage: mod(0, 1).crt(mod(4, 2^15)) 4 - sage: mod(4,2^15).crt(mod(0,1)) + sage: mod(4, 2^15).crt(mod(0, 1)) 4 AUTHORS: @@ -1736,20 +1737,20 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: mod(1,2).is_primitive_root() + sage: mod(1, 2).is_primitive_root() True - sage: mod(3,4).is_primitive_root() + sage: mod(3, 4).is_primitive_root() True - sage: mod(2,7).is_primitive_root() + sage: mod(2, 7).is_primitive_root() # optional - sage.libs.pari False - sage: mod(3,98).is_primitive_root() + sage: mod(3, 98).is_primitive_root() # optional - sage.libs.pari True - sage: mod(11,1009^2).is_primitive_root() + sage: mod(11, 1009^2).is_primitive_root() # optional - sage.libs.pari True TESTS:: - sage: for p in prime_range(3,12): + sage: for p in prime_range(3,12): # optional - sage.libs.pari ....: for k in range(1,4): ....: for even in [1,2]: ....: n = even*p^k @@ -1762,14 +1763,14 @@ cdef class IntegerMod_abstract(FiniteRingElement): `0` is not a primitive root mod `n` (:trac:`23624`) except for `n=0`:: - sage: mod(0, 17).is_primitive_root() + sage: mod(0, 17).is_primitive_root() # optional - sage.libs.pari False - sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) + sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) # optional - sage.libs.pari True sage: mod(0, 1).is_primitive_root() True - sage: all(not mod(p^j, p^k).is_primitive_root() + sage: all(not mod(p^j, p^k).is_primitive_root() # optional - sage.libs.pari ....: for p in prime_range(3, 12) ....: for k in srange(1, 4) ....: for j in srange(0, k)) @@ -1824,14 +1825,15 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: Mod(-1,5).multiplicative_order() + sage: Mod(-1, 5).multiplicative_order() # optional - sage.libs.pari 2 - sage: Mod(1,5).multiplicative_order() + sage: Mod(1, 5).multiplicative_order() # optional - sage.libs.pari 1 - sage: Mod(0,5).multiplicative_order() + sage: Mod(0, 5).multiplicative_order() # optional - sage.libs.pari Traceback (most recent call last): ... - ArithmeticError: multiplicative order of 0 not defined since it is not a unit modulo 5 + ArithmeticError: multiplicative order of 0 not defined + since it is not a unit modulo 5 """ try: return sage.rings.integer.Integer(self.__pari__().znorder()) @@ -1841,7 +1843,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): def valuation(self, p): """ - The largest power r such that m is in the ideal generated by p^r or infinity if there is not a largest such power. + The largest power `r` such that `m` is in the ideal generated by `p^r` or infinity if there is not a largest such power. However it is an error to take the valuation with respect to a unit. .. NOTE:: @@ -1850,13 +1852,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES: - This example shows that the (a*b).valuation(n) is not always the same as a.valuation(n) + b.valuation(n) + This example shows that ``(a*b).valuation(n)`` is not always the same as ``a.valuation(n) + b.valuation(n)`` :: - sage: R=ZZ.quo(9) - sage: a=R(3) - sage: b=R(6) + sage: R = ZZ.quo(9) + sage: a = R(3) + sage: b = R(6) sage: a.valuation(3) 1 sage: a.valuation(3) + b.valuation(3) @@ -1875,9 +1877,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): TESTS:: - sage: R=ZZ.quo(12) - sage: a=R(2) - sage: b=R(4) + sage: R = ZZ.quo(12) + sage: a = R(2) + sage: b = R(4) sage: a.valuation(2) 1 sage: b.valuation(2) @@ -1905,7 +1907,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(7)(3) // 5 + sage: GF(7)(3) // 5 # optional - sage.rings.finite_rings 2 """ return self._mul_(~right) @@ -1932,9 +1934,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: F. = GF(13) - sage: V = F.vector_space(map=False) - sage: V(a) + sage: F. = GF(13) # optional - sage.rings.finite_rings + sage: V = F.vector_space(map=False) # optional - sage.rings.finite_rings + sage: V(a) # optional - sage.rings.finite_rings (1) """ return self.parent().vector_space(map=False)([self]) @@ -1977,8 +1979,8 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): r""" EXAMPLES:: - sage: p = next_prime(2^32) - sage: GF(p)(int(p+1)) + sage: p = next_prime(2^32) # optional - sage.libs.pari + sage: GF(p)(int(p + 1)) # optional - sage.rings.finite_rings 1 """ mpz_set_si(self.value, value) @@ -2250,9 +2252,9 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): sage: R = Integers(10^10) sage: R(2)^1000 5668069376 - sage: p = next_prime(11^10) - sage: R = Integers(p) - sage: R(9876)^(p-1) + sage: p = next_prime(11^10) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(9876)^(p-1) # optional - sage.libs.pari 1 sage: mod(3, 10^100)^-2 8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888889 @@ -2265,14 +2267,14 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): We define ``0^0`` to be unity, :trac:`13894`:: - sage: p = next_prime(11^10) - sage: R = Integers(p) - sage: R(0)^0 + sage: p = next_prime(11^10) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(0)^0 # optional - sage.libs.pari 1 The value returned from ``0^0`` should belong to our ring:: - sage: type(R(0)^0) == type(R(0)) + sage: type(R(0)^0) == type(R(0)) # optional - sage.libs.pari True When the modulus is ``1``, the only element in the ring is @@ -2908,16 +2910,16 @@ cdef class IntegerMod_int(IntegerMod_abstract): 86 sage: mod(7, 18).sqrt() 5 - sage: a = mod(14, 5^60).sqrt() - sage: a*a + sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari + sage: a*a # optional - sage.libs.pari 14 sage: mod(15, 389).sqrt(extend=False) Traceback (most recent call last): ... ValueError: self must be a square - sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) + sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari 9 - sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) + sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari 25 :: @@ -2932,7 +2934,8 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: y = x.sqrt(); y sqrt359 sage: y.parent() - Univariate Quotient Polynomial Ring in sqrt359 over Ring of integers modulo 360 with modulus x^2 + 1 + Univariate Quotient Polynomial Ring in sqrt359 + over Ring of integers modulo 360 with modulus x^2 + 1 sage: y^2 359 @@ -2948,20 +2951,20 @@ cdef class IntegerMod_int(IntegerMod_abstract): [1, 19, 71, 89, 91, 109, 161, 179, 181, 199, 251, 269, 271, 289, 341, 359] sage: R(0).sqrt(all=True) [0, 60, 120, 180, 240, 300] - sage: GF(107)(0).sqrt(all=True) + sage: GF(107)(0).sqrt(all=True) # optional - sage.rings.finite_rings [0] :: sage: R = Integers(5*13^3*37); R Ring of integers modulo 406445 - sage: v = R(-1).sqrt(all=True); v + sage: v = R(-1).sqrt(all=True); v # optional - sage.libs.pari [78853, 111808, 160142, 193097, 213348, 246303, 294637, 327592] - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444] - sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) + sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) # optional - sage.libs.pari (13, 13, 104) - sage: all(x^2 == 169 for x in v) + sage: all(x^2 == 169 for x in v) # optional - sage.libs.pari True Modulo a power of 2:: @@ -2980,7 +2983,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): Check for :trac:`30797`:: - sage: GF(103)(-1).sqrt(extend=False, all=True) + sage: GF(103)(-1).sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [] """ cdef int_fast32_t i, n = self.__modulus.int32 @@ -3547,9 +3550,9 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: R = Integers(10) sage: R(2)^10 4 - sage: p = next_prime(10^5) - sage: R = Integers(p) - sage: R(1234)^(p-1) + sage: p = next_prime(10^5) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(1234)^(p - 1) # optional - sage.libs.pari 1 sage: R = Integers(17^5) sage: R(17)^5 @@ -3575,14 +3578,14 @@ cdef class IntegerMod_int64(IntegerMod_abstract): We define ``0^0`` to be unity, :trac:`13894`:: - sage: p = next_prime(10^5) - sage: R = Integers(p) - sage: R(0)^0 + sage: p = next_prime(10^5) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(0)^0 # optional - sage.libs.pari 1 The value returned from ``0^0`` should belong to our ring:: - sage: type(R(0)^0) == type(R(0)) + sage: type(R(0)^0) == type(R(0)) # optional - sage.libs.pari True When the modulus is ``1``, the only element in the ring is @@ -3902,11 +3905,11 @@ def square_root_mod_prime_power(IntegerMod_abstract a, p, e): :: - sage: a = Mod(72,97^10) - sage: b = square_root_mod_prime_power(a,97,10) - sage: b^2 == a + sage: a = Mod(72, 97^10) + sage: b = square_root_mod_prime_power(a, 97, 10) # optional - sage.libs.pari + sage: b^2 == a # optional - sage.libs.pari True - sage: mod(100, 5^7).sqrt()^2 + sage: mod(100, 5^7).sqrt()^2 # optional - sage.libs.pari 100 TESTS: @@ -3914,15 +3917,15 @@ def square_root_mod_prime_power(IntegerMod_abstract a, p, e): A big example for the binary case (:trac:`33961`):: sage: y = Mod(-7, 2^777) - sage: hex(y.sqrt()^2 - y) + sage: hex(y.sqrt()^2 - y) # optional - sage.libs.pari '0x0' Testing with random squares in random rings:: - sage: p = random_prime(999) - sage: e = randrange(1, 999) - sage: x = Zmod(p^e).random_element() - sage: (x^2).sqrt()^2 == x^2 + sage: p = random_prime(999) # optional - sage.libs.pari + sage: e = randrange(1, 999) # optional - sage.libs.pari + sage: x = Zmod(p^e).random_element() # optional - sage.libs.pari + sage: (x^2).sqrt()^2 == x^2 # optional - sage.libs.pari True """ if a.is_zero() or a.is_one(): @@ -4017,7 +4020,7 @@ cpdef square_root_mod_prime(IntegerMod_abstract a, p=None): :: sage: from sage.rings.finite_rings.integer_mod import square_root_mod_prime # sqrt() uses brute force for small p - sage: all(square_root_mod_prime(a*a)^2 == a*a + sage: all(square_root_mod_prime(a*a)^2 == a*a # optional - sage.libs.pari ....: for p in prime_range(100) ....: for a in Integers(p)) True @@ -4103,7 +4106,7 @@ def lucas_q1(mm, IntegerMod_abstract P): TESTS:: sage: from sage.rings.finite_rings.integer_mod import lucas_q1 - sage: all(lucas_q1(k, a) == BinaryRecurrenceSequence(a, -1, 2, a)(k) + sage: all(lucas_q1(k, a) == BinaryRecurrenceSequence(a, -1, 2, a)(k) # optional - sage.combinat ....: for a in Integers(23) ....: for k in range(13)) True @@ -4171,7 +4174,7 @@ def lucas(k, P, Q=1, n=None): sage: p = randint(0,100000) sage: q = randint(0,100000) sage: n = randint(1,100) - sage: all(lucas(k,p,q,n)[0] == Mod(lucas_number2(k,p,q),n) + sage: all(lucas(k, p, q, n)[0] == Mod(lucas_number2(k, p, q), n) # optional - sage.combinat ....: for k in Integers(20)) True sage: from sage.rings.finite_rings.integer_mod import lucas @@ -4179,7 +4182,7 @@ def lucas(k, P, Q=1, n=None): sage: q = randint(0,100000) sage: n = randint(1,100) sage: k = randint(0,100) - sage: lucas(k,p,q,n) == [Mod(lucas_number2(k,p,q),n),Mod(q^(int(k/2)),n)] + sage: lucas(k, p, q, n) == [Mod(lucas_number2(k, p, q), n), Mod(q^(int(k/2)), n)] # optional - sage.combinat True EXAMPLES:: @@ -4317,8 +4320,14 @@ cdef class IntegerMod_to_IntegerMod(IntegerMod_hom): sage: from sage.rings.finite_rings.integer_mod import IntegerMod_to_IntegerMod sage: Rs = [Integers(3**k) for k in range(1,30,5)] sage: [type(R(0)) for R in Rs] - [, , , , , ] - sage: fs = [IntegerMod_to_IntegerMod(S, R) for R in Rs for S in Rs if S is not R and S.order() > R.order()] + [, + , + , + , + , + ] + sage: fs = [IntegerMod_to_IntegerMod(S, R) + ....: for R in Rs for S in Rs if S is not R and S.order() > R.order()] sage: all(f(-1) == f.codomain()(-1) for f in fs) True sage: [f(-1) for f in fs] @@ -4387,7 +4396,9 @@ cdef class Integer_to_IntegerMod(IntegerMod_hom): sage: from sage.rings.finite_rings.integer_mod import Integer_to_IntegerMod sage: Rs = [Integers(10), Integers(10^5), Integers(10^10)] sage: [type(R(0)) for R in Rs] - [, , ] + [, + , + ] sage: fs = [Integer_to_IntegerMod(R) for R in Rs] sage: [f(-1) for f in fs] [9, 99999, 9999999999] @@ -4449,7 +4460,7 @@ cdef class IntegerMod_to_Integer(Map): EXAMPLES:: - sage: ZZ.convert_map_from(GF(2)) + sage: ZZ.convert_map_from(GF(2)) # optional - sage.rings.finite_rings Lifting map: From: Finite Field of size 2 To: Integer Ring @@ -4461,7 +4472,7 @@ cdef class IntegerMod_to_Integer(Map): Lifting maps are morphisms in the category of sets (see :trac:`15618`):: - sage: ZZ.convert_map_from(GF(2)).parent() + sage: ZZ.convert_map_from(GF(2)).parent() # optional - sage.rings.finite_rings Set of Morphisms from Finite Field of size 2 to Integer Ring in Category of sets """ import sage.categories.homset @@ -4493,7 +4504,11 @@ cdef class Int_to_IntegerMod(IntegerMod_hom): sage: from sage.rings.finite_rings.integer_mod import Int_to_IntegerMod sage: Rs = [Integers(2**k) for k in range(1,50,10)] sage: [type(R(0)) for R in Rs] - [, , , , ] + [, + , + , + , + ] sage: fs = [Int_to_IntegerMod(R) for R in Rs] sage: [f(-1) for f in fs] [1, 2047, 2097151, 2147483647, 2199023255551] diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index a10d84aade9..71f392a13cd 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -16,16 +16,16 @@ :: sage: r = Integers(7) - sage: s = GF(7) - sage: r.has_coerce_map_from(s) + sage: s = GF(7) # optional - sage.rings.finite_rings + sage: r.has_coerce_map_from(s) # optional - sage.rings.finite_rings False - sage: s.has_coerce_map_from(r) + sage: s.has_coerce_map_from(r) # optional - sage.rings.finite_rings True - sage: s(1) + r(1) + sage: s(1) + r(1) # optional - sage.rings.finite_rings 2 - sage: parent(s(1) + r(1)) + sage: parent(s(1) + r(1)) # optional - sage.rings.finite_rings Finite Field of size 7 - sage: parent(r(1) + s(1)) + sage: parent(r(1) + s(1)) # optional - sage.rings.finite_rings Finite Field of size 7 We list the elements of `\ZZ/3\ZZ`:: @@ -259,9 +259,9 @@ def is_IntegerModRing(x): Use isinstance(..., sage.rings.abc.IntegerModRing) instead. See https://github.com/sagemath/sage/issues/32606 for details. True - sage: is_IntegerModRing(GF(13)) + sage: is_IntegerModRing(GF(13)) # optional - sage.rings.finite_rings True - sage: is_IntegerModRing(GF(4, 'a')) + sage: is_IntegerModRing(GF(4, 'a')) # optional - sage.rings.finite_rings False sage: is_IntegerModRing(10) False @@ -290,9 +290,9 @@ def _unit_gens_primepowercase(p, r): sage: from sage.rings.finite_rings.integer_mod_ring import _unit_gens_primepowercase sage: _unit_gens_primepowercase(2, 3) [(7, 2), (5, 2)] - sage: _unit_gens_primepowercase(17, 1) + sage: _unit_gens_primepowercase(17, 1) # optional - sage.libs.pari [(3, 16)] - sage: _unit_gens_primepowercase(3, 3) + sage: _unit_gens_primepowercase(3, 3) # optional - sage.libs.pari [(2, 18)] """ pr = p**r @@ -344,14 +344,14 @@ class IntegerModRing_generic(quotient_ring.QuotientRing_generic, sage.rings.abc. 29 sage: FF.order() 29 - sage: gens = FF.unit_gens() - sage: a = gens[0] - sage: a + sage: gens = FF.unit_gens() # optional - sage.groups + sage: a = gens[0] # optional - sage.groups + sage: a # optional - sage.groups 2 - sage: a.is_square() + sage: a.is_square() # optional - sage.groups False - sage: def pow(i): return a**i - sage: [pow(i) for i in range(16)] + sage: def pow(i): return a**i # optional - sage.groups + sage: [pow(i) for i in range(16)] # optional - sage.groups [1, 2, 4, 8, 16, 3, 6, 12, 24, 19, 9, 18, 7, 14, 28, 27] sage: TestSuite(FF).run() @@ -404,23 +404,23 @@ class IntegerModRing_generic(quotient_ring.QuotientRing_generic, sage.rings.abc. 16 sage: Z16.characteristic() 16 - sage: gens = Z16.unit_gens() - sage: gens + sage: gens = Z16.unit_gens() # optional - sage.groups + sage: gens # optional - sage.groups (15, 5) - sage: a = gens[0] - sage: b = gens[1] - sage: def powa(i): return a**i - sage: def powb(i): return b**i - sage: gp_exp = FF.unit_group_exponent() - sage: gp_exp + sage: a = gens[0] # optional - sage.groups + sage: b = gens[1] # optional - sage.groups + sage: def powa(i): return a**i # optional - sage.groups + sage: def powb(i): return b**i # optional - sage.groups + sage: gp_exp = FF.unit_group_exponent() # optional - sage.groups + sage: gp_exp # optional - sage.groups 28 - sage: [powa(i) for i in range(15)] + sage: [powa(i) for i in range(15)] # optional - sage.groups [1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1] - sage: [powb(i) for i in range(15)] + sage: [powb(i) for i in range(15)] # optional - sage.groups [1, 5, 9, 13, 1, 5, 9, 13, 1, 5, 9, 13, 1, 5, 9] - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.groups 2 - sage: b.multiplicative_order() + sage: b.multiplicative_order() # optional - sage.groups 4 sage: TestSuite(Z16).run() @@ -572,7 +572,8 @@ def extension(self, poly, name=None, names=None, **kwds): sage: R. = QQ[] sage: Integers(8).extension(t^2 - 3) - Univariate Quotient Polynomial Ring in t over Ring of integers modulo 8 with modulus t^2 + 5 + Univariate Quotient Polynomial Ring in t + over Ring of integers modulo 8 with modulus t^2 + 5 """ if self.modulus() == 1: return self @@ -638,22 +639,22 @@ def multiplicative_subgroups(self): EXAMPLES:: - sage: Integers(5).multiplicative_subgroups() + sage: Integers(5).multiplicative_subgroups() # optional - sage.groups ((2,), (4,), ()) - sage: Integers(15).multiplicative_subgroups() + sage: Integers(15).multiplicative_subgroups() # optional - sage.groups ((11, 7), (11, 4), (2,), (11,), (14,), (7,), (4,), ()) - sage: Integers(2).multiplicative_subgroups() + sage: Integers(2).multiplicative_subgroups() # optional - sage.groups ((),) - sage: len(Integers(341).multiplicative_subgroups()) + sage: len(Integers(341).multiplicative_subgroups()) # optional - sage.groups 80 TESTS:: - sage: IntegerModRing(1).multiplicative_subgroups() + sage: IntegerModRing(1).multiplicative_subgroups() # optional - sage.groups ((),) - sage: IntegerModRing(2).multiplicative_subgroups() + sage: IntegerModRing(2).multiplicative_subgroups() # optional - sage.groups ((),) - sage: IntegerModRing(3).multiplicative_subgroups() + sage: IntegerModRing(3).multiplicative_subgroups() # optional - sage.groups ((2,), ()) """ return tuple(tuple(g.value() for g in H.gens()) @@ -667,7 +668,7 @@ def is_integral_domain(self, proof=None): sage: Integers(389).is_integral_domain() True - sage: Integers(389^2).is_integral_domain() + sage: Integers(389^2).is_integral_domain() # optional - sage.libs.pari False TESTS: @@ -688,7 +689,7 @@ def is_unique_factorization_domain(self, proof=None): sage: Integers(389).is_unique_factorization_domain() True - sage: Integers(389^2).is_unique_factorization_domain() + sage: Integers(389^2).is_unique_factorization_domain() # optional - sage.libs.pari False """ return self.is_field(proof) @@ -790,10 +791,10 @@ def field(self): sage: R = Integers(7); R Ring of integers modulo 7 - sage: R.field() + sage: R.field() # optional - sage.rings.finite_rings Finite Field of size 7 sage: R = Integers(9) - sage: R.field() + sage: R.field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: self must be a field @@ -827,8 +828,8 @@ def _pseudo_fraction_field(self): This should be very fast:: - sage: R. = Integers(next_prime(10^101)*next_prime(10^100))[] - sage: x / R.base_ring()(2) + sage: R. = Integers(next_prime(10^101)*next_prime(10^100))[] # optional - sage.libs.pari + sage: x / R.base_ring()(2) # optional - sage.libs.pari 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000401*x """ return self @@ -847,18 +848,18 @@ def multiplicative_group_is_cyclic(self): sage: R.multiplicative_group_is_cyclic() True sage: R = Integers(9) - sage: R.multiplicative_group_is_cyclic() + sage: R.multiplicative_group_is_cyclic() # optional - sage.libs.pari True - sage: Integers(8).multiplicative_group_is_cyclic() + sage: Integers(8).multiplicative_group_is_cyclic() # optional - sage.libs.pari False - sage: Integers(4).multiplicative_group_is_cyclic() + sage: Integers(4).multiplicative_group_is_cyclic() # optional - sage.libs.pari True - sage: Integers(25*3).multiplicative_group_is_cyclic() + sage: Integers(25*3).multiplicative_group_is_cyclic() # optional - sage.libs.pari False We test that :trac:`5250` is fixed:: - sage: Integers(162).multiplicative_group_is_cyclic() + sage: Integers(162).multiplicative_group_is_cyclic() # optional - sage.libs.pari True """ n = self.order() @@ -885,24 +886,24 @@ def multiplicative_generator(self): sage: R = Integers(7); R Ring of integers modulo 7 - sage: R.multiplicative_generator() + sage: R.multiplicative_generator() # optional - sage.libs.pari 3 sage: R = Integers(9) - sage: R.multiplicative_generator() + sage: R.multiplicative_generator() # optional - sage.libs.pari 2 - sage: Integers(8).multiplicative_generator() + sage: Integers(8).multiplicative_generator() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: multiplicative group of this ring is not cyclic - sage: Integers(4).multiplicative_generator() + sage: Integers(4).multiplicative_generator() # optional - sage.libs.pari 3 - sage: Integers(25*3).multiplicative_generator() + sage: Integers(25*3).multiplicative_generator() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: multiplicative group of this ring is not cyclic - sage: Integers(25*3).unit_gens() + sage: Integers(25*3).unit_gens() # optional - sage.libs.pari (26, 52) - sage: Integers(162).unit_gens() + sage: Integers(162).unit_gens() # optional - sage.libs.pari (83,) """ try: @@ -927,9 +928,9 @@ def quadratic_nonresidue(self): EXAMPLES:: sage: R = Integers(17) - sage: R.quadratic_nonresidue() + sage: R.quadratic_nonresidue() # optional - sage.libs.pari 3 - sage: R(3).is_square() + sage: R(3).is_square() # optional - sage.libs.pari False """ try: @@ -954,18 +955,18 @@ def square_roots_of_one(self): sage: R = Integers(2^10) sage: [x for x in R if x^2 == 1] [1, 511, 513, 1023] - sage: R.square_roots_of_one() + sage: R.square_roots_of_one() # optional - sage.libs.pari (1, 511, 513, 1023) :: - sage: v = Integers(9*5).square_roots_of_one(); v + sage: v = Integers(9*5).square_roots_of_one(); v # optional - sage.libs.pari (1, 19, 26, 44) - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [1, 1, 1, 1] - sage: v = Integers(9*5*8).square_roots_of_one(); v + sage: v = Integers(9*5*8).square_roots_of_one(); v # optional - sage.libs.pari (1, 19, 71, 89, 91, 109, 161, 179, 181, 199, 251, 269, 271, 289, 341, 359) - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] """ try: @@ -1132,7 +1133,7 @@ def _pari_order(self): EXAMPLES:: - sage: Zmod(87)._pari_order() + sage: Zmod(87)._pari_order() # optional - sage.libs.pari 87 """ try: @@ -1145,14 +1146,14 @@ def _element_constructor_(self, x): """ TESTS:: - sage: K2 = GF(2) - sage: K3 = GF(3) - sage: K8 = GF(8,'a') - sage: K8(5) # indirect doctest + sage: K2 = GF(2) # optional - sage.rings.finite_rings + sage: K3 = GF(3) # optional - sage.rings.finite_rings + sage: K8 = GF(8, 'a') # optional - sage.rings.finite_rings + sage: K8(5) # indirect doctest # optional - sage.rings.finite_rings 1 - sage: K8('a+1') + sage: K8('a+1') # optional - sage.rings.finite_rings a + 1 - sage: K8(K2(1)) + sage: K8(K2(1)) # optional - sage.rings.finite_rings 1 The following test refers to :trac:`6468`:: @@ -1164,7 +1165,7 @@ def _element_constructor_(self, x): ....: raise PariError sage: P = foo_parent() sage: F = foo(P) - sage: GF(2)(F) + sage: GF(2)(F) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: error coercing to finite field @@ -1172,21 +1173,21 @@ def _element_constructor_(self, x): The following test refers to :trac:`8970`:: sage: R = Zmod(13); a = R(2) - sage: a == R(gap(a)) + sage: a == R(gap(a)) # optional - sage.libs.gap True libgap interface (:trac:`23714`):: - sage: a = libgap.eval("Z(13)^2") - sage: a.sage() + sage: a = libgap.eval("Z(13)^2") # optional - sage.libs.gap + sage: a.sage() # optional - sage.libs.gap 4 - sage: libgap(a.sage()) == a + sage: libgap(a.sage()) == a # optional - sage.libs.gap True better syntax for libgap interface:: - sage: a = libgap.Z(13)^2 - sage: libgap(a.sage()) == a + sage: a = libgap.Z(13)^2 # optional - sage.libs.gap + sage: libgap(a.sage()) == a # optional - sage.libs.gap True """ try: @@ -1295,7 +1296,7 @@ def _convert_map_from_(self, other): EXAMPLES:: - sage: Zmod(81).convert_map_from(Qp(3)) + sage: Zmod(81).convert_map_from(Qp(3)) # optional - sage.rings.padics Reduction morphism: From: 3-adic Field with capped relative precision 20 To: Ring of integers modulo 81 @@ -1318,10 +1319,12 @@ def __richcmp__(self, other, op): Ring of integers modulo 12 sage: Z13 = IntegerModRing(13); Z13 Ring of integers modulo 13 - sage: F = GF(11); F + sage: Z11 == Z11, Z11 == Z12, Z11 == Z13 + (True, False, False) + sage: F = GF(11); F # optional - sage.rings.finite_rings Finite Field of size 11 - sage: Z11 == Z11, Z11 == Z12, Z11 == Z13, Z11 == F - (True, False, False, False) + sage: Z11 == F # optional - sage.rings.finite_rings + False In :trac:`15229`, the following was implemented:: @@ -1329,7 +1332,7 @@ def __richcmp__(self, other, op): sage: R2 = IntegerModRing(5, is_field=True) sage: R1 is R2 # used to return False True - sage: R2 == GF(5) + sage: R2 == GF(5) # optional - sage.rings.finite_rings False """ @@ -1363,12 +1366,12 @@ def unit_gens(self, **kwds): EXAMPLES:: sage: R = IntegerModRing(18) - sage: R.unit_gens() + sage: R.unit_gens() # optional - sage.groups (11,) sage: R = IntegerModRing(17) - sage: R.unit_gens() + sage: R.unit_gens() # optional - sage.groups (3,) - sage: IntegerModRing(next_prime(10^30)).unit_gens() + sage: IntegerModRing(next_prime(10^30)).unit_gens() # optional - sage.groups (5,) The choice of generators is affected by the optional keyword @@ -1376,18 +1379,18 @@ def unit_gens(self, **kwds): See :meth:`unit_group` for details. :: sage: A = Zmod(55) - sage: A.unit_gens(algorithm='sage') + sage: A.unit_gens(algorithm='sage') # optional - sage.groups (12, 46) - sage: A.unit_gens(algorithm='pari') + sage: A.unit_gens(algorithm='pari') # optional - sage.groups sage.libs.pari (2, 21) TESTS:: - sage: IntegerModRing(2).unit_gens() + sage: IntegerModRing(2).unit_gens() # optional - sage.groups () - sage: IntegerModRing(4).unit_gens() + sage: IntegerModRing(4).unit_gens() # optional - sage.groups (3,) - sage: IntegerModRing(8).unit_gens() + sage: IntegerModRing(8).unit_gens() # optional - sage.groups (7, 5) """ @@ -1398,10 +1401,10 @@ def unit_group_exponent(self): EXAMPLES:: sage: R = IntegerModRing(17) - sage: R.unit_group_exponent() + sage: R.unit_group_exponent() # optional - sage.groups 16 sage: R = IntegerModRing(18) - sage: R.unit_group_exponent() + sage: R.unit_group_exponent() # optional - sage.groups 6 """ return self.unit_group().exponent() @@ -1413,7 +1416,7 @@ def unit_group_order(self): EXAMPLES:: sage: R = Integers(500) - sage: R.unit_group_order() + sage: R.unit_group_order() # optional - sage.groups 200 """ return self.unit_group().order() @@ -1452,69 +1455,71 @@ def unit_group(self, algorithm='sage'): cyclic factors are computed, but in a different order:: sage: A = Zmod(15) - sage: G = A.unit_group(); G + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C4 - sage: G.gens_values() + sage: G.gens_values() # optional - sage.groups (11, 7) - sage: H = A.unit_group(algorithm='pari'); H + sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C4 x C2 - sage: H.gens_values() + sage: H.gens_values() # optional - sage.groups sage.libs.pari (7, 11) Here are two examples where the cyclic factors are isomorphic, but are ordered differently and have different generators:: sage: A = Zmod(40) - sage: G = A.unit_group(); G + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C2 x C4 - sage: G.gens_values() + sage: G.gens_values() # optional - sage.groups (31, 21, 17) - sage: H = A.unit_group(algorithm='pari'); H + sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C4 x C2 x C2 - sage: H.gens_values() + sage: H.gens_values() # optional - sage.groups sage.libs.pari (17, 31, 21) sage: A = Zmod(192) - sage: G = A.unit_group(); G + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C16 x C2 - sage: G.gens_values() + sage: G.gens_values() # optional - sage.groups (127, 133, 65) - sage: H = A.unit_group(algorithm='pari'); H + sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C16 x C2 x C2 - sage: H.gens_values() + sage: H.gens_values() # optional - sage.groups sage.libs.pari (133, 127, 65) In the following examples, the cyclic factors are not even isomorphic:: sage: A = Zmod(319) - sage: A.unit_group() + sage: A.unit_group() # optional - sage.groups Multiplicative Abelian group isomorphic to C10 x C28 - sage: A.unit_group(algorithm='pari') + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C140 x C2 sage: A = Zmod(30.factorial()) - sage: A.unit_group() - Multiplicative Abelian group isomorphic to C2 x C16777216 x C3188646 x C62500 x C2058 x C110 x C156 x C16 x C18 x C22 x C28 - sage: A.unit_group(algorithm='pari') - Multiplicative Abelian group isomorphic to C20499647385305088000000 x C55440 x C12 x C12 x C4 x C2 x C2 x C2 x C2 x C2 x C2 + sage: A.unit_group() # optional - sage.groups + Multiplicative Abelian group isomorphic to + C2 x C16777216 x C3188646 x C62500 x C2058 x C110 x C156 x C16 x C18 x C22 x C28 + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari + Multiplicative Abelian group isomorphic to + C20499647385305088000000 x C55440 x C12 x C12 x C4 x C2 x C2 x C2 x C2 x C2 x C2 TESTS: We test the cases where the unit group is trivial:: sage: A = Zmod(1) - sage: A.unit_group() + sage: A.unit_group() # optional - sage.groups Trivial Abelian group - sage: A.unit_group(algorithm='pari') + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Trivial Abelian group sage: A = Zmod(2) - sage: A.unit_group() + sage: A.unit_group() # optional - sage.groups Trivial Abelian group - sage: A.unit_group(algorithm='pari') + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Trivial Abelian group - sage: Zmod(3).unit_group(algorithm='bogus') + sage: Zmod(3).unit_group(algorithm='bogus') # optional - sage.groups Traceback (most recent call last): ... ValueError: unknown algorithm 'bogus' for computing the unit group @@ -1578,7 +1583,7 @@ def _gap_init_(self): sage: R = Integers(12345678900) sage: R Ring of integers modulo 12345678900 - sage: gap(R) # indirect doctest + sage: gap(R) # indirect doctest # optional - sage.libs.gap (Integers mod 12345678900) """ return 'ZmodnZ({})'.format(self.order()) @@ -1624,7 +1629,7 @@ def crt(v): EXAMPLES:: sage: from sage.rings.finite_rings.integer_mod_ring import crt - sage: crt([mod(3, 8),mod(1,19),mod(7, 15)]) + sage: crt([mod(3, 8), mod(1,19), mod(7, 15)]) 1027 """ if len(v) == 0: diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 7e5703212bf..388ef3a32d9 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -264,11 +264,11 @@ def _coerce_map_from_(self, S): number fields:: sage: _. = ZZ[] - sage: K. = NumberField(x^5-3*x^4+2424*x^3+2*x-232) - sage: R = K.ring_of_integers() - sage: S. = R[] - sage: F = FractionField(S) - sage: F(1/a) + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: S. = R[] # optional - sage.rings.number_field + sage: F = FractionField(S) # optional - sage.rings.number_field + sage: F(1/a) # optional - sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 Some corner cases have been known to fail in the past (:trac:`5917`):: @@ -394,11 +394,11 @@ def _number_field_to_frac_of_ring_of_integers(self, x): number fields:: sage: _. = ZZ[] - sage: K. = NumberField(x^5-3*x^4+2424*x^3+2*x-232) - sage: R = K.ring_of_integers() - sage: S. = R[] - sage: F = FractionField(S) # indirect doctest - sage: F(1/a) + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: S. = R[] # optional - sage.rings.number_field + sage: F = FractionField(S) # indirect doctest # optional - sage.rings.number_field + sage: F(1/a) # optional - sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 """ f = x.polynomial() # Polynomial over QQ @@ -459,7 +459,7 @@ def characteristic(self): Integer Ring sage: R = Frac(ZZ['t']); R.characteristic() 0 - sage: R = Frac(GF(5)['w']); R.characteristic() + sage: R = Frac(GF(5)['w']); R.characteristic() # optional - sage.rings.finite_rings 5 """ return self._R.characteristic() @@ -481,7 +481,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest + sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest # optional - sage.rings.finite_rings \mathrm{Frac}(\Bold{F}_{7}[x, y, z]) """ return "\\mathrm{Frac}(%s)" % latex.latex(self._R) @@ -494,7 +494,7 @@ def _magma_init_(self, magma): sage: QQ['x'].fraction_field()._magma_init_(magma) # optional - magma 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...),["x"])),["x"])' - sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma + sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...,3,"grevlex"),["x","y","z"])),["x","y","z"])' ``_magma_init_`` gets called implicitly below:: @@ -571,17 +571,17 @@ def _element_constructor_(self, x, y=None, coerce=True): The next example failed before :trac:`4376`:: - sage: K(pari((x + 1)/(x^2 + x + 1))) + sage: K(pari((x + 1)/(x^2 + x + 1))) # optional - sage.libs.pari (x + 1)/(x^2 + x + 1) These examples failed before :trac:`11368`:: sage: R. = PolynomialRing(QQ) sage: S = R.fraction_field() - sage: S(pari((x + y)/y)) + sage: S(pari((x + y)/y)) # optional - sage.libs.pari (x + y)/y - sage: S(pari(x + y + 1/z)) + sage: S(pari(x + y + 1/z)) # optional - sage.libs.pari (x*z + y*z + 1)/z This example failed before :trac:`23664`:: @@ -613,13 +613,13 @@ def _element_constructor_(self, x, y=None, coerce=True): Check that :trac:`24539` is fixed:: sage: tau = polygen(QQ, 'tau') - sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) + sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) # optional - sage.rings.number_field z/(z + 1) Check that :trac:`26150` is fixed:: sage: z = SR.var('z') - sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) + sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) # optional - sage.rings.number_field (8*z + 10)/(z^5 - 3*z^4 + 2*z^3 + 2*z^2 - 3*z + 1) :: @@ -731,11 +731,12 @@ def construction(self): sage: Frac(ZZ['x']).construction() (FractionField, Univariate Polynomial Ring in x over Integer Ring) - sage: K = Frac(GF(3)['t']) - sage: f, R = K.construction() - sage: f(R) - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 3 - sage: f(R) == K + sage: K = Frac(GF(3)['t']) # optional - sage.rings.finite_rings + sage: f, R = K.construction() # optional - sage.rings.finite_rings + sage: f(R) # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 3 + sage: f(R) == K # optional - sage.rings.finite_rings True """ from sage.categories.pushout import FractionField @@ -801,7 +802,8 @@ def ngens(self): EXAMPLES:: sage: R = Frac(PolynomialRing(QQ,'z',10)); R - Fraction Field of Multivariate Polynomial Ring in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field + Fraction Field of Multivariate Polynomial Ring + in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field sage: R.ngens() 10 """ @@ -814,7 +816,8 @@ def gen(self, i=0): EXAMPLES:: sage: R = Frac(PolynomialRing(QQ,'z',10)); R - Fraction Field of Multivariate Polynomial Ring in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field + Fraction Field of Multivariate Polynomial Ring + in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field sage: R.0 z0 sage: R.gen(3) @@ -983,8 +986,8 @@ def ring_of_integers(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) - sage: K.ring_of_integers() + sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings + sage: K.ring_of_integers() # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -995,8 +998,8 @@ def maximal_order(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) - sage: K.maximal_order() + sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings + sage: K.maximal_order() # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -1007,8 +1010,8 @@ def class_number(self): EXAMPLES:: - sage: R. = GF(5)[]; K = R.fraction_field() - sage: K.class_number() + sage: R. = GF(5)[]; K = R.fraction_field() # optional - sage.rings.finite_rings + sage: K.class_number() # optional - sage.rings.finite_rings 1 """ return 1 @@ -1019,11 +1022,11 @@ def _factor_univariate_polynomial(self, f): EXAMPLES:: - sage: k. = GF(9) - sage: K = k['t'].fraction_field() - sage: R. = K[] - sage: f = x^3 + a - sage: f.factor() + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: K = k['t'].fraction_field() # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: f = x^3 + a # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings (x + 2*a + 1)^3 """ @@ -1038,9 +1041,9 @@ def function_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: K = R.fraction_field() - sage: K.function_field() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: K.function_field() # optional - sage.rings.finite_rings Rational function field in t over Finite Field of size 5 .. SEEALSO:: @@ -1057,14 +1060,15 @@ def _coerce_map_from_(self, R): EXAMPLES:: - sage: R. = GF(5)[] - sage: K = R.fraction_field() - sage: L = K.function_field() - sage: f = K.coerce_map_from(L); f # indirect doctest + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: L = K.function_field() # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(L); f # indirect doctest # optional - sage.rings.finite_rings Isomorphism: From: Rational function field in t over Finite Field of size 5 - To: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 - sage: f(~L.gen()) + To: Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 + sage: f(~L.gen()) # optional - sage.rings.finite_rings 1/t """ @@ -1162,12 +1166,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R) - sage: S. = GF(2)[] - sage: g = S.fraction_field().coerce_map_from(S) + sage: S. = GF(2)[] # optional - sage.rings.finite_rings + sage: g = S.fraction_field().coerce_map_from(S) # optional - sage.rings.finite_rings - sage: f == g # indirect doctest + sage: f == g # indirect doctest # optional - sage.rings.finite_rings False - sage: f == f + sage: f == f # optional - sage.rings.finite_rings True """ @@ -1232,19 +1236,19 @@ def _call_(self, x, check=True): Over inexact rings, we have to take the precision of the denominators into account:: - sage: R=ZpCR(2) - sage: S. = R[] - sage: f = x/S(R(3,absprec=2)) - sage: S(f) + sage: R = ZpCR(2) # optional - sage.rings.padics + sage: S. = R[] # optional - sage.rings.padics + sage: f = x/S(R(3, absprec=2)) # optional - sage.rings.padics + sage: S(f) # optional - sage.rings.padics (1 + 2 + O(2^2))*x Test for Localization:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+2*x+ 1) - sage: 1/(x+1) in L # indirect doctest + sage: L = Localization(R, x**2 + 2*x + 1) # optional - sage.libs.pari + sage: 1/(x + 1) in L # indirect doctest # optional - sage.libs.pari True - sage: 1/(x+2) in L # indirect doctest + sage: 1/(x + 2) in L # indirect doctest # optional - sage.libs.pari False """ codom = self.codomain() @@ -1294,12 +1298,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R).section() - sage: S. = GF(2)[] - sage: g = S.fraction_field().coerce_map_from(S).section() + sage: S. = GF(2)[] # optional - sage.rings.finite_rings + sage: g = S.fraction_field().coerce_map_from(S).section() # optional - sage.rings.finite_rings - sage: f == g # indirect doctest + sage: f == g # indirect doctest # optional - sage.rings.finite_rings False - sage: f == f + sage: f == f # optional - sage.rings.finite_rings True """ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index b4d59afbf6d..4e5dabe8b75 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -67,9 +67,9 @@ cdef class FractionFieldElement(FieldElement): Test if :trac:`5451` is fixed:: - sage: A = FiniteField(9,'theta')['t'] - sage: K. = FractionField(A) - sage: f= 2/(t^2+2*t); g =t^9/(t^18 + t^10 + t^2);f+g + sage: A = FiniteField(9,'theta')['t'] # optional - sage.libs.pari + sage: K. = FractionField(A) # optional - sage.libs.pari + sage: f = 2/(t^2 + 2*t); g = t^9/(t^18 + t^10 + t^2); f + g # optional - sage.libs.pari (2*t^15 + 2*t^14 + 2*t^13 + 2*t^12 + 2*t^11 + 2*t^10 + 2*t^9 + t^7 + t^6 + t^5 + t^4 + t^3 + t^2 + t + 1)/(t^17 + t^9 + t) Test if :trac:`8671` is fixed:: @@ -102,8 +102,8 @@ cdef class FractionFieldElement(FieldElement): sage: f.numerator() 'hi' - sage: x = var('x') - sage: K((x + 1)/(x^2 + x + 1)) + sage: x = var('x') # optional - sage.symbolic + sage: K((x + 1)/(x^2 + x + 1)) # optional - sage.symbolic (x + 1)/(x^2 + x + 1) sage: K(355/113) 355/113 @@ -130,31 +130,31 @@ cdef class FractionFieldElement(FieldElement): sage: F = ZZ['x,y'].fraction_field() sage: x,y = F.gens() - sage: K = GF(7)['a,b'].fraction_field() - sage: a,b = K.gens() + sage: K = GF(7)['a,b'].fraction_field() # optional - sage.rings.finite_rings + sage: a,b = K.gens() # optional - sage.rings.finite_rings :: - sage: phi = F.hom([a+b, a*b], K) - sage: phi(x+y) # indirect doctest + sage: phi = F.hom([a + b, a*b], K) # optional - sage.rings.finite_rings + sage: phi(x+y) # indirect doctest # optional - sage.rings.finite_rings a*b + a + b :: - sage: (x^2/y)._im_gens_(K, [a+b, a*b]) + sage: (x^2/y)._im_gens_(K, [a + b, a*b]) # optional - sage.rings.finite_rings (a^2 + 2*a*b + b^2)/(a*b) - sage: (x^2/y)._im_gens_(K, [a, a*b]) + sage: (x^2/y)._im_gens_(K, [a, a*b]) # optional - sage.rings.finite_rings a/b :: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = K[] - sage: F = R.fraction_field() - sage: phi = F.hom([F(b),F(a)], base_map=cc) - sage: phi(i/a) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: F = R.fraction_field() # optional - sage.rings.number_field + sage: phi = F.hom([F(b), F(a)], base_map=cc) # optional - sage.rings.number_field + sage: phi(i/a) # optional - sage.rings.number_field ((-i))/b """ nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) @@ -396,10 +396,10 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25199` is fixed:: - sage: R.=QQbar[] - sage: hash(R.0)==hash(FractionField(R).0) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: hash(R.0) == hash(FractionField(R).0) # optional - sage.rings.number_field True - sage: ((x+1)/(x^2+1)).subs({x:1}) + sage: ((x+1)/(x^2+1)).subs({x: 1}) # optional - sage.rings.number_field 1 """ if self.__denominator.is_one(): @@ -533,7 +533,7 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: sage: R. = ZZ[] - sage: magma((x^2 + x + 1)/(x + 1)) # optional - magma # indirect doctest + sage: magma((x^2 + x + 1)/(x + 1)) # optional - magma # indirect doctest (x^2 + x + 1)/(x + 1) :: @@ -576,8 +576,8 @@ cdef class FractionFieldElement(FieldElement): Subtraction is implemented by adding the negative:: - sage: K. = Frac(GF(7)['t']) - sage: t - 1/t # indirect doctest + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: t - 1/t # indirect doctest # optional - sage.rings.finite_rings (t^2 + 6)/t """ rnum = self.__numerator @@ -649,10 +649,10 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: a = t/(1+t) - sage: b = 3/t - sage: a*b # indirect doctest + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: a = t/(1+t) # optional - sage.rings.finite_rings + sage: b = 3/t # optional - sage.rings.finite_rings + sage: a * b # indirect doctest # optional - sage.rings.finite_rings 3/(t + 1) """ rnum = self.__numerator @@ -778,7 +778,7 @@ cdef class FractionFieldElement(FieldElement): TESTS:: sage: K = Frac(ZZ['x']) - sage: QQ(K(x) / K(2*x)) + sage: QQ(K(x) / K(2*x)) # optional - sage.symbolic 1/2 """ return self._conversion(QQ) @@ -814,15 +814,15 @@ cdef class FractionFieldElement(FieldElement): 3/2 sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) - sage: A((x+3) / (2*x - 1)) + sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A((x+3) / (2*x - 1)) # optional - sage.rings.number_field 14/15*u^2 + 7/15*u + 11/15 - sage: B = A['y'].fraction_field() - sage: A(B(u)) + sage: B = A['y'].fraction_field() # optional - sage.rings.number_field + sage: A(B(u)) # optional - sage.rings.number_field u - sage: C = A['x,y'].fraction_field() - sage: A(C(u)) + sage: C = A['x,y'].fraction_field() # optional - sage.rings.number_field + sage: A(C(u)) # optional - sage.rings.number_field u """ if self.__denominator.is_one(): @@ -900,10 +900,10 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(5)['t']) - sage: f = (t^2+t)/(t+2); f + sage: K. = Frac(GF(5)['t']) # optional - sage.rings.finite_rings + sage: f = (t^2+t)/(t+2); f # optional - sage.rings.finite_rings (t^2 + t)/(t + 2) - sage: -f + sage: -f # optional - sage.rings.finite_rings (4*t^2 + 4*t)/(t + 2) """ return self.__class__(self._parent, @@ -924,9 +924,9 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: f = (t^2+5)/(t-1) - sage: ~f + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: f = (t^2+5)/(t-1) # optional - sage.rings.finite_rings + sage: ~f # optional - sage.rings.finite_rings (t + 6)/(t^2 + 5) """ if self.is_zero(): @@ -938,12 +938,12 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: t/t == 1 + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: t/t == 1 # optional - sage.rings.finite_rings True - sage: t+1/t == (t^2+1)/t + sage: t+1/t == (t^2+1)/t # optional - sage.rings.finite_rings True - sage: t == t/5 + sage: t == t/5 # optional - sage.rings.finite_rings False :: @@ -1042,9 +1042,9 @@ cdef class FractionFieldElement(FieldElement): sage: x,y = F.gens() sage: elt = (2*x + 2*y) / (3*x - 3*y); elt (2*x + 2*y)/(3*x - 3*y) - sage: elt._symbolic_(SR) + sage: elt._symbolic_(SR) # optional - sage.symbolic 2/3*(x + y)/(x - y) - sage: symbolic_expression(elt) + sage: symbolic_expression(elt) # optional - sage.symbolic 2/3*(x + y)/(x - y) """ return ring(self.__numerator)/ring(self.__denominator) @@ -1101,18 +1101,18 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25440` has been resolved:: - sage: R. = GF(2)[] - sage: S. = R.fraction_field()[] - sage: (y+1)(R.one()) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R.fraction_field()[] # optional - sage.rings.finite_rings + sage: (y+1)(R.one()) # optional - sage.rings.finite_rings 0 Check that inexact elements are treated correctly:: - sage: K=Qp(2,5) - sage: R. = K[] - sage: L = R.fraction_field() - sage: S. = L[] - sage: y(K(1,1)/x) + sage: K = Qp(2, 5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: L = R.fraction_field() # optional - sage.rings.padics + sage: S. = L[] # optional - sage.rings.padics + sage: y(K(1,1)/x) # optional - sage.rings.padics (1 + O(2))/((1 + O(2))*x) """ if self.numerator().is_one(): @@ -1205,7 +1205,8 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): EXAMPLES:: sage: R. = QQ[] - sage: h = (t^14 + 2*t^12 - 4*t^11 - 8*t^9 + 6*t^8 + 12*t^6 - 4*t^5 - 8*t^3 + t^2 + 2)/(t^6 + 6*t^5 + 9*t^4 - 2*t^2 - 12*t - 18) + sage: h = (t^14 + 2*t^12 - 4*t^11 - 8*t^9 + 6*t^8 + 12*t^6 - 4*t^5 # optional - sage.libs.pari + ....: - 8*t^3 + t^2 + 2)/(t^6 + 6*t^5 + 9*t^4 - 2*t^2 - 12*t - 18) sage: h.support() [t - 1, t + 3, t^2 + 2, t^2 + t + 1, t^4 - 2] """ diff --git a/src/sage/rings/function_field/drinfeld_modules/action.py b/src/sage/rings/function_field/drinfeld_modules/action.py index 32a00f9ea71..cfa9774058a 100644 --- a/src/sage/rings/function_field/drinfeld_modules/action.py +++ b/src/sage/rings/function_field/drinfeld_modules/action.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" The module action induced by a Drinfeld module @@ -58,7 +59,8 @@ class DrinfeldModuleAction(Action): sage: phi = DrinfeldModule(A, [z, 0, 0, 1]) sage: action = phi.action() sage: action - Action on Finite Field in z of size 11^2 over its base induced by Drinfeld module defined by T |--> t^3 + z + Action on Finite Field in z of size 11^2 over its base + induced by Drinfeld module defined by T |--> t^3 + z The action on elements is computed as follows:: diff --git a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py index b50193c1862..23a992f2ce1 100644 --- a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld modules @@ -171,7 +172,10 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: phi(T) # phi_T, the generator of the Drinfeld module t^2 + t + z sage: phi(T^3 + T + 1) # phi_(T^3 + T + 1) - t^6 + (z^11 + z^9 + 2*z^6 + 2*z^4 + 2*z + 1)*t^4 + (2*z^11 + 2*z^10 + z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^3)*t^3 + (2*z^11 + z^10 + z^9 + 2*z^7 + 2*z^6 + z^5 + z^4 + 2*z^3 + 2*z + 2)*t^2 + (2*z^11 + 2*z^8 + 2*z^6 + z^5 + z^4 + 2*z^2)*t + z^3 + z + 1 + t^6 + (z^11 + z^9 + 2*z^6 + 2*z^4 + 2*z + 1)*t^4 + + (2*z^11 + 2*z^10 + z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^3)*t^3 + + (2*z^11 + z^10 + z^9 + 2*z^7 + 2*z^6 + z^5 + z^4 + 2*z^3 + 2*z + 2)*t^2 + + (2*z^11 + 2*z^8 + 2*z^6 + z^5 + z^4 + 2*z^2)*t + z^3 + z + 1 sage: phi(1) # phi_1 1 @@ -228,7 +232,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): :: sage: phi.ore_polring() # K{t} - Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base twisted by Frob^2 + Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base + twisted by Frob^2 :: @@ -252,7 +257,9 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: phi.morphism() # The Drinfeld module as a morphism Ring morphism: From: Univariate Polynomial Ring in T over Finite Field in z2 of size 3^2 - To: Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base twisted by Frob^2 + To: Ore Polynomial Ring in t + over Finite Field in z of size 3^12 over its base + twisted by Frob^2 Defn: T |--> t^2 + t + z One can compute the rank and height:: @@ -353,7 +360,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: P = (2*z^6 + z^3 + 2*z^2 + z + 2)*t + z^11 + 2*z^10 + 2*z^9 + 2*z^8 + z^7 + 2*z^6 + z^5 + z^3 + z^2 + z sage: psi = phi.velu(P) sage: psi - Drinfeld module defined by T |--> (2*z^11 + 2*z^9 + z^6 + 2*z^5 + 2*z^4 + 2*z^2 + 1)*t^2 + (2*z^11 + 2*z^10 + 2*z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^4 + 2*z^2 + 2*z)*t + z + Drinfeld module defined by T |--> (2*z^11 + 2*z^9 + z^6 + 2*z^5 + 2*z^4 + 2*z^2 + 1)*t^2 + + (2*z^11 + 2*z^10 + 2*z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^4 + 2*z^2 + 2*z)*t + z sage: P in Hom(phi, psi) True sage: P * phi(T) == psi(T) * P @@ -385,7 +393,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: action = phi.action() sage: action - Action on Finite Field in z of size 3^12 over its base induced by Drinfeld module defined by T |--> t^2 + t + z + Action on Finite Field in z of size 3^12 over its base + induced by Drinfeld module defined by T |--> t^2 + t + z The action on elements is computed by calling the action object:: @@ -867,7 +876,9 @@ def action(self): sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: action = phi.action() sage: action - Action on Finite Field in z12 of size 5^12 over its base induced by Drinfeld module defined by T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + Action on Finite Field in z12 of size 5^12 over its base + induced by Drinfeld module defined by T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 The action on elements is computed as follows:: @@ -901,7 +912,8 @@ def coefficient(self, n): sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: phi.coefficient(0) - 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi.coefficient(0) == p_root True sage: phi.coefficient(1) @@ -938,7 +950,8 @@ def coefficients(self, sparse=True): sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: phi.coefficients() - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, z12^3, z12^5] @@ -947,10 +960,12 @@ def coefficients(self, sparse=True): sage: rho = DrinfeldModule(A, [p_root, 0, 0, 0, 1]) sage: rho.coefficients() - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, 1] sage: rho.coefficients(sparse=False) - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, 0, 0, 0, @@ -1120,8 +1135,10 @@ def morphism(self): sage: phi.morphism() Ring morphism: From: Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - To: Ore Polynomial Ring in t over Finite Field in z12 of size 5^12 over its base twisted by Frob^2 - Defn: T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + To: Ore Polynomial Ring in t over Finite Field in z12 of size 5^12 + over its base twisted by Frob^2 + Defn: T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: from sage.rings.morphism import RingHomomorphism sage: isinstance(phi.morphism(), RingHomomorphism) True @@ -1144,7 +1161,8 @@ class the ``__call__`` method of this morphism:: sage: m.codomain() is phi.ore_polring() True sage: m.im_gens() - [z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12] + [z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12] sage: phi(T) == m.im_gens()[0] True """ @@ -1220,7 +1238,10 @@ def velu(self, isog): sage: isog = t + 2*z12^11 + 4*z12^9 + 2*z12^8 + 2*z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + 4*z12^2 + 4*z12 + 4 sage: psi = phi.velu(isog) sage: psi - Drinfeld module defined by T |--> (z12^11 + 3*z12^10 + z12^9 + z12^7 + z12^5 + 4*z12^4 + 4*z12^3 + z12^2 + 1)*t^2 + (2*z12^11 + 4*z12^10 + 2*z12^8 + z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + z12^2 + z12 + 4)*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + Drinfeld module defined by T |--> + (z12^11 + 3*z12^10 + z12^9 + z12^7 + z12^5 + 4*z12^4 + 4*z12^3 + z12^2 + 1)*t^2 + + (2*z12^11 + 4*z12^10 + 2*z12^8 + z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + z12^2 + z12 + 4)*t + + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: isog in Hom(phi, psi) True diff --git a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py index 6cc78a53fb4..9d468dba511 100644 --- a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Finite Drinfeld modules @@ -221,7 +222,8 @@ def frobenius_charpoly(self, var='X'): sage: phi = DrinfeldModule(A, [1, 0, z6]) sage: chi = phi.frobenius_charpoly() sage: chi - X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 + X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 :: diff --git a/src/sage/rings/function_field/drinfeld_modules/homset.py b/src/sage/rings/function_field/drinfeld_modules/homset.py index 84fdc4c6e14..c4f43db19da 100644 --- a/src/sage/rings/function_field/drinfeld_modules/homset.py +++ b/src/sage/rings/function_field/drinfeld_modules/homset.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Set of morphisms between two Drinfeld modules @@ -46,7 +47,9 @@ class DrinfeldModuleHomset(Homset): sage: psi = DrinfeldModule(A, [z6, 2*z6^5 + 2*z6^4 + 2*z6 + 1, 2]) sage: H = Hom(phi, psi) sage: H - Set of Drinfeld module morphisms from (gen) 2*t^2 + z6*t + z6 to (gen) 2*t^2 + (2*z6^5 + 2*z6^4 + 2*z6 + 1)*t + z6 + Set of Drinfeld module morphisms + from (gen) 2*t^2 + z6*t + z6 + to (gen) 2*t^2 + (2*z6^5 + 2*z6^4 + 2*z6 + 1)*t + z6 :: diff --git a/src/sage/rings/function_field/drinfeld_modules/morphism.py b/src/sage/rings/function_field/drinfeld_modules/morphism.py index dab86c43efa..2d5414095f5 100644 --- a/src/sage/rings/function_field/drinfeld_modules/morphism.py +++ b/src/sage/rings/function_field/drinfeld_modules/morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld module morphisms diff --git a/src/sage/rings/homset.py b/src/sage/rings/homset.py index 6f7a2d4b415..77fa3323bc0 100644 --- a/src/sage/rings/homset.py +++ b/src/sage/rings/homset.py @@ -133,25 +133,26 @@ def _element_constructor_(self, x, check=True, base_map=None): You can provide a morphism on the base:: - sage: k = GF(9) - sage: z2 = k.gen() - sage: cc = k.frobenius_endomorphism() - sage: R. = k[] - sage: H = Hom(R, R) - sage: phi = H([x^2], base_map=cc); phi - Ring endomorphism of Univariate Polynomial Ring in x over Finite Field in z2 of size 3^2 + sage: k = GF(9) # optional - sage.rings.finite_rings + sage: z2 = k.gen() # optional - sage.rings.finite_rings + sage: cc = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: H = Hom(R, R) # optional - sage.rings.finite_rings + sage: phi = H([x^2], base_map=cc); phi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Polynomial Ring in x + over Finite Field in z2 of size 3^2 Defn: x |--> x^2 with map of base ring - sage: phi(z2*x) == z2^3 * x^2 + sage: phi(z2 * x) == z2^3 * x^2 # optional - sage.rings.finite_rings True sage: R. = ZZ[] - sage: K. = GF(7^2) - sage: L. = K.extension(x^3 - 3) - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) - sage: phi(u) == u^7 + sage: K. = GF(7^2) # optional - sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: phi(u) == u^7 # optional - sage.rings.finite_rings True - sage: phi(a) == a^7 + sage: phi(a) == a^7 # optional - sage.rings.finite_rings True TESTS:: @@ -247,14 +248,15 @@ class RingHomset_quo_ring(RingHomset_generic): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: phi = S.hom([b,a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.hom([b,a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) Defn: a |--> b b |--> a - sage: phi(a) + sage: phi(a) # optional - sage.libs.singular b - sage: phi(b) + sage: phi(b) # optional - sage.libs.singular a TESTS: @@ -264,15 +266,15 @@ class RingHomset_quo_ring(RingHomset_generic): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: H = S.Hom(R) - sage: H == loads(dumps(H)) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: H = S.Hom(R) # optional - sage.libs.singular + sage: H == loads(dumps(H)) # optional - sage.libs.singular True We test pickling of actual homomorphisms in a quotient:: - sage: phi = S.hom([b,a]) - sage: phi == loads(dumps(phi)) + sage: phi = S.hom([b,a]) # optional - sage.libs.singular + sage: phi == loads(dumps(phi)) # optional - sage.libs.singular True """ @@ -285,17 +287,17 @@ def _element_constructor_(self, x, base_map=None, check=True): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: H = S.Hom(R) - sage: phi = H([b, a]); phi + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: H = S.Hom(R) # optional - sage.libs.singular + sage: phi = H([b, a]); phi # optional - sage.libs.singular Ring morphism: From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: a |--> b b |--> a sage: R2. = PolynomialRing(ZZ, 2) - sage: H2 = Hom(R2, S) - sage: H2(phi) + sage: H2 = Hom(R2, S) # optional - sage.libs.singular + sage: H2(phi) # optional - sage.libs.singular Composite map: From: Multivariate Polynomial Ring in x, y over Integer Ring To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 8c51c69a9ae..4e4a3e5c135 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -125,9 +125,9 @@ def Ideal(*args, **kwds): Note that some rings use different ideal implementations than the standard, even if they are PIDs.:: - sage: R. = GF(5)[] - sage: I = R*(x^2+3) - sage: type(I) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: I = R * (x^2 + 3) # optional - sage.rings.finite_rings + sage: type(I) # optional - sage.rings.finite_rings You can also pass in a specific ideal type:: @@ -163,11 +163,11 @@ def Ideal(*args, **kwds): sage: J = R.ideal([2*x + 2*x^2]) sage: J Principal ideal (x^2 + x) of Univariate Polynomial Ring in x over Rational Field - sage: S = R.quotient_ring(I) - sage: U = R.quotient_ring(J) + sage: S = R.quotient_ring(I) # optional - sage.libs.pari + sage: U = R.quotient_ring(J) # optional - sage.libs.pari sage: I == J True - sage: S == U + sage: S == U # optional - sage.libs.pari True """ if len(args) == 0: @@ -295,8 +295,8 @@ def _repr_short(self): the generators are not represented from left to right but from top to bottom. This is the case, e.g., for matrices:: - sage: MS = MatrixSpace(QQ,2,2) - sage: MS*[MS.1,2] + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: MS * [MS.1, 2] # optional - sage.modules Left Ideal ( [0 1] @@ -337,9 +337,9 @@ def random_element(self, *args, **kwds): EXAMPLES:: - sage: P. = GF(5)[[]] - sage: I = P.ideal([a^2, a*b + c, c^3]) - sage: I.random_element() # random + sage: P. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: I = P.ideal([a^2, a*b + c, c^3]) # optional - sage.rings.finite_rings + sage: I.random_element() # random # optional - sage.rings.finite_rings 2*a^5*c + a^2*b*c^4 + ... + O(a, b, c)^13 """ @@ -376,11 +376,11 @@ def __contains__(self, x): EXAMPLES:: sage: P. = QQ[] - sage: I = P*[a, b] - sage: a + b in I + sage: I = P * [a, b] + sage: a + b in I # optional - sage.libs.singular True sage: P2. = QQ[] - sage: x + 2*y + w*z in I + sage: x + 2*y + w*z in I # optional - sage.libs.singular False """ try: @@ -470,11 +470,11 @@ def base_ring(self): And `p`-adic numbers:: - sage: R = Zp(7, prec=10); R + sage: R = Zp(7, prec=10); R # optional - sage.rings.padics 7-adic Ring with capped relative precision 10 - sage: I = 7*R; I + sage: I = 7*R; I # optional - sage.rings.padics Principal ideal (7 + O(7^11)) of 7-adic Ring with capped relative precision 10 - sage: I.base_ring() + sage: I.base_ring() # optional - sage.rings.padics 7-adic Ring with capped relative precision 10 """ return self.ring().base_ring() @@ -488,11 +488,14 @@ def apply_morphism(self, phi): sage: psi = CC['x'].hom([-CC['x'].0]) sage: J = ideal([CC['x'].0 + 1]); J - Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision + Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x + over Complex Field with 53 bits of precision sage: psi(J) - Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision + Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x + over Complex Field with 53 bits of precision sage: J.apply_morphism(psi) - Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision + Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x + over Complex Field with 53 bits of precision :: @@ -585,12 +588,14 @@ def ring(self): sage: I = R.ideal(x^2 - 3) sage: I.ring() Univariate Polynomial Ring in x over Rational Field - sage: Rbar = R.quotient(I, names='a') - sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S - Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 - sage: J = S.ideal(y^2 + 1) - sage: J.ring() - Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 + sage: Rbar = R.quotient(I, names='a') # optional - sage.libs.pari + sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S # optional - sage.libs.pari + Univariate Polynomial Ring in y over + Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 + sage: J = S.ideal(y^2 + 1) # optional - sage.libs.pari + sage: J.ring() # optional - sage.libs.pari + Univariate Polynomial Ring in y over + Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 """ return self.__ring @@ -693,16 +698,16 @@ def is_maximal(self): sage: R = ZZ sage: I = R.ideal(7) - sage: I.is_maximal() + sage: I.is_maximal() # optional - sage.libs.pari True - sage: R.ideal(16).is_maximal() + sage: R.ideal(16).is_maximal() # optional - sage.libs.pari False sage: S = Integers(8) - sage: S.ideal(0).is_maximal() + sage: S.ideal(0).is_maximal() # optional - sage.libs.pari False - sage: S.ideal(2).is_maximal() + sage: S.ideal(2).is_maximal() # optional - sage.libs.pari True - sage: S.ideal(4).is_maximal() + sage: S.ideal(4).is_maximal() # optional - sage.libs.pari False """ from sage.rings.integer_ring import ZZ @@ -749,17 +754,17 @@ def is_primary(self, P=None): Some examples from the Macaulay2 documentation:: - sage: R. = GF(101)[] - sage: I = R.ideal([y^6]) - sage: I.is_primary() + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: I = R.ideal([y^6]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.rings.finite_rings True - sage: I.is_primary(R.ideal([y])) + sage: I.is_primary(R.ideal([y])) # optional - sage.rings.finite_rings True - sage: I = R.ideal([x^4, y^7]) - sage: I.is_primary() + sage: I = R.ideal([x^4, y^7]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.rings.finite_rings True - sage: I = R.ideal([x*y, y^2]) - sage: I.is_primary() + sage: I = R.ideal([x*y, y^2]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.rings.finite_rings False .. NOTE:: @@ -798,24 +803,24 @@ def is_prime(self): sage: R. = QQ[] sage: I = R.ideal([x, y]) - sage: I.is_prime() # a maximal ideal + sage: I.is_prime() # a maximal ideal # optional - sage.libs.singular True - sage: I = R.ideal([x^2-y]) - sage: I.is_prime() # a non-maximal prime ideal + sage: I = R.ideal([x^2 - y]) + sage: I.is_prime() # a non-maximal prime ideal # optional - sage.libs.singular True sage: I = R.ideal([x^2, y]) - sage: I.is_prime() # a non-prime primary ideal + sage: I.is_prime() # a non-prime primary ideal # optional - sage.libs.singular False sage: I = R.ideal([x^2, x*y]) - sage: I.is_prime() # a non-prime non-primary ideal + sage: I.is_prime() # a non-prime non-primary ideal # optional - sage.libs.singular False sage: S = Integers(8) - sage: S.ideal(0).is_prime() + sage: S.ideal(0).is_prime() # optional - sage.libs.singular False - sage: S.ideal(2).is_prime() + sage: S.ideal(2).is_prime() # optional - sage.libs.singular True - sage: S.ideal(4).is_prime() + sage: S.ideal(4).is_prime() # optional - sage.libs.singular False Note that this method is not implemented for all rings where it @@ -886,7 +891,7 @@ def embedded_primes(self): sage: R. = QQ[] sage: I = R.ideal(x^2, x*y) - sage: I.embedded_primes() + sage: I.embedded_primes() # optional - sage.libs.singular [Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational Field] """ # by definition, embedded primes are associated primes that @@ -915,13 +920,13 @@ def is_principal(self): EXAMPLES:: - sage: R = ZZ['x'] - sage: I = R.ideal(2,x) + sage: R. = ZZ[] + sage: I = R.ideal(2, x) sage: I.is_principal() Traceback (most recent call last): ... NotImplementedError - sage: J = R.base_extend(QQ).ideal(2,x) + sage: J = R.base_extend(QQ).ideal(2, x) sage: J.is_principal() True """ @@ -954,7 +959,7 @@ def is_trivial(self): :: sage: I = QQ['x', 'y'].ideal(-5) - sage: I.is_trivial() + sage: I.is_trivial() # optional - sage.libs.singular True :: @@ -967,7 +972,7 @@ def is_trivial(self): sage: R = QQ['x', 'y'] sage: I = R.ideal(R.gens()) - sage: I.is_trivial() + sage: I.is_trivial() # optional - sage.libs.singular False """ return self.is_zero() or self == self.ring().unit_ideal() @@ -1112,10 +1117,11 @@ def norm(self): EXAMPLES:: - sage: R. = GF(8, names='a')[] - sage: I = R.ideal(t^4 + t + 1) - sage: I.norm() - Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t over Finite Field in a of size 2^3 + sage: R. = GF(8, names='a')[] # optional - sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: I.norm() # optional - sage.rings.finite_rings + Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t + over Finite Field in a of size 2^3 """ return self @@ -1135,9 +1141,9 @@ def absolute_norm(self): EXAMPLES:: - sage: R. = GF(9, names='a')[] - sage: I = R.ideal(t^4 + t + 1) - sage: I.absolute_norm() + sage: R. = GF(9, names='a')[] # optional - sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: I.absolute_norm() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1155,7 +1161,7 @@ def _macaulay2_init_(self, macaulay2=None): sage: R. = PolynomialRing(ZZ, 4) sage: I = R.ideal([x*y-z^2, y^2-w^2]); I Ideal (x*y - z^2, y^2 - w^2) of Multivariate Polynomial Ring in x, y, z, w over Integer Ring - sage: macaulay2(I) # optional - macaulay2 + sage: macaulay2(I) # optional - macaulay2 2 2 2 ideal (x*y - z , y - w ) @@ -1164,28 +1170,28 @@ def _macaulay2_init_(self, macaulay2=None): sage: R. = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]); I Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring - sage: macaulay2(I) # optional - macaulay2 + sage: macaulay2(I) # optional - macaulay2 2 2 ideal (x + 3x + 4, x + 1) Field ideals generated from the polynomial ring over two variables in the finite field of size 2:: - sage: P. = PolynomialRing(GF(2), 2) - sage: I = sage.rings.ideal.FieldIdeal(P); I - Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over - Finite Field of size 2 - sage: macaulay2(I) # optional - macaulay2 + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y + over Finite Field of size 2 + sage: macaulay2(I) # optional - macaulay2 # optional - sage.rings.finite_rings 2 2 ideal (x + x, y + y) Ideals in PIDs:: - sage: macaulay2(ideal(5)) # optional - macaulay2 + sage: macaulay2(ideal(5)) # optional - macaulay2 ideal 5 sage: J = ideal(QQ(5)) ... - sage: macaulay2(J) # optional - macaulay2 + sage: macaulay2(J) # optional - macaulay2 ideal 1 TESTS: @@ -1222,7 +1228,7 @@ def free_resolution(self, *args, **kwds): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^4 + 3*x^2 + 2]) - sage: I.free_resolution() + sage: I.free_resolution() # optional - sage.modules S^1 <-- S^1 <-- 0 """ if not self.is_principal(): @@ -1241,7 +1247,7 @@ def graded_free_resolution(self, *args, **kwds): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^3]) - sage: I.graded_free_resolution() + sage: I.graded_free_resolution() # optional - sage.modules S(0) <-- S(-3) <-- 0 """ from sage.homology.graded_resolution import GradedFiniteFreeResolution_free_module @@ -1568,18 +1574,18 @@ def is_prime(self): EXAMPLES:: - sage: ZZ.ideal(2).is_prime() + sage: ZZ.ideal(2).is_prime() # optional - sage.libs.pari True - sage: ZZ.ideal(-2).is_prime() + sage: ZZ.ideal(-2).is_prime() # optional - sage.libs.pari True - sage: ZZ.ideal(4).is_prime() + sage: ZZ.ideal(4).is_prime() # optional - sage.libs.pari False - sage: ZZ.ideal(0).is_prime() + sage: ZZ.ideal(0).is_prime() # optional - sage.libs.pari True sage: R. = QQ[] - sage: P = R.ideal(x^2+1); P + sage: P = R.ideal(x^2 + 1); P # optional - sage.libs.pari Principal ideal (x^2 + 1) of Univariate Polynomial Ring in x over Rational Field - sage: P.is_prime() + sage: P.is_prime() # optional - sage.libs.pari True In fields, only the zero ideal is prime:: @@ -1609,18 +1615,18 @@ def is_maximal(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: p = R.ideal(t^2 + 2) - sage: p.is_maximal() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: p = R.ideal(t^2 + 2) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings True - sage: p = R.ideal(t^2 + 1) - sage: p.is_maximal() + sage: p = R.ideal(t^2 + 1) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False - sage: p = R.ideal(0) - sage: p.is_maximal() + sage: p = R.ideal(0) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False - sage: p = R.ideal(1) - sage: p.is_maximal() + sage: p = R.ideal(1) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False """ if not self.ring().is_field() and self.is_zero(): @@ -1640,41 +1646,41 @@ def residue_field(self): sage: P = ZZ.ideal(61); P Principal ideal (61) of Integer Ring - sage: F = P.residue_field(); F + sage: F = P.residue_field(); F # optional - sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi + sage: pi = F.reduction_map(); pi # optional - sage.libs.pari Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) + sage: pi(123/234) # optional - sage.libs.pari 6 - sage: pi(1/61) + sage: pi(1/61) # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift + sage: lift = F.lift_map(); lift # optional - sage.libs.pari Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) + sage: lift(F(12345/67890)) # optional - sage.libs.pari 33 sage: (12345/67890) % 61 33 TESTS:: - sage: ZZ.ideal(96).residue_field() + sage: ZZ.ideal(96).residue_field() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: The ideal (Principal ideal (96) of Integer Ring) is not prime :: - sage: R.=QQ[] - sage: I=R.ideal(x^2+1) - sage: I.is_prime() + sage: R. = QQ[] + sage: I = R.ideal(x^2 + 1) + sage: I.is_prime() # optional - sage.libs.pari True - sage: I.residue_field() + sage: I.residue_field() # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: residue fields only supported for polynomial rings over finite fields. @@ -1699,8 +1705,8 @@ def __repr__(self): EXAMPLES:: sage: from sage.rings.ideal import Ideal_fractional - sage: K. = NumberField(x^2 + 1) - sage: Ideal_fractional(K, [a]) # indirect doctest + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: Ideal_fractional(K, [a]) # indirect doctest # optional - sage.rings.number_field Fractional ideal (a) of Number Field in a with defining polynomial x^2 + 1 """ return "Fractional ideal %s of %s"%(self._repr_short(), self.ring()) @@ -1735,21 +1741,20 @@ def Cyclic(R, n=None, homog=False, singular=None): An example from a multivariate polynomial ring over the rationals:: - sage: P. = PolynomialRing(QQ,3,order='lex') - sage: I = sage.rings.ideal.Cyclic(P) - sage: I - Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) of Multivariate Polynomial - Ring in x, y, z over Rational Field - sage: I.groebner_basis() + sage: P. = PolynomialRing(QQ, 3, order='lex') + sage: I = sage.rings.ideal.Cyclic(P); I # optional - sage.libs.singular + Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) + of Multivariate Polynomial Ring in x, y, z over Rational Field + sage: I.groebner_basis() # optional - sage.libs.singular [x + y + z, y^2 + y*z + z^2, z^3 - 1] We compute a Groebner basis for cyclic 6, which is a standard benchmark and test ideal:: sage: R. = QQ['x,y,z,t,u,v'] - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: B = I.groebner_basis() - sage: len(B) + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.libs.singular + sage: B = I.groebner_basis() # optional - sage.libs.singular + sage: len(B) # optional - sage.libs.singular 45 """ from .rational_field import RationalField @@ -1794,15 +1799,15 @@ def Katsura(R, n=None, homog=False, singular=None): EXAMPLES:: - sage: P. = PolynomialRing(QQ,3) - sage: I = sage.rings.ideal.Katsura(P,3); I + sage: P. = PolynomialRing(QQ, 3) + sage: I = sage.rings.ideal.Katsura(P, 3); I # optional - sage.libs.singular Ideal (x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y) of Multivariate Polynomial Ring in x, y, z over Rational Field :: - sage: Q. = PolynomialRing(QQ, implementation="singular") - sage: J = sage.rings.ideal.Katsura(Q,1); J + sage: Q. = PolynomialRing(QQ, implementation="singular") # optional - sage.libs.singular + sage: J = sage.rings.ideal.Katsura(Q,1); J # optional - sage.libs.singular Ideal (x - 1) of Multivariate Polynomial Ring in x over Rational Field """ from .rational_field import RationalField @@ -1842,18 +1847,18 @@ def FieldIdeal(R): The field ideal generated from the polynomial ring over two variables in the finite field of size 2:: - sage: P. = PolynomialRing(GF(2),2) - sage: I = sage.rings.ideal.FieldIdeal(P); I - Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over - Finite Field of size 2 + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + Ideal (x^2 + x, y^2 + y) of + Multivariate Polynomial Ring in x, y over Finite Field of size 2 Another, similar example:: - sage: Q. = PolynomialRing(GF(2^4,name='alpha'), 4) - sage: J = sage.rings.ideal.FieldIdeal(Q); J + sage: Q. = PolynomialRing(GF(2^4, name='alpha'), 4) # optional - sage.rings.finite_rings + sage: J = sage.rings.ideal.FieldIdeal(Q); J # optional - sage.rings.finite_rings Ideal (x1^16 + x1, x2^16 + x2, x3^16 + x3, x4^16 + x4) of - Multivariate Polynomial Ring in x1, x2, x3, x4 over Finite - Field in alpha of size 2^4 + Multivariate Polynomial Ring in x1, x2, x3, x4 + over Finite Field in alpha of size 2^4 """ q = R.base_ring().order() import sage.rings.infinity diff --git a/src/sage/rings/ideal_monoid.py b/src/sage/rings/ideal_monoid.py index b22b7208f6f..01193661aae 100644 --- a/src/sage/rings/ideal_monoid.py +++ b/src/sage/rings/ideal_monoid.py @@ -3,8 +3,8 @@ WARNING: This is used by some rings that are not commutative! :: - sage: MS = MatrixSpace(QQ,3,3) - sage: type(MS.ideal(MS.one()).parent()) + sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: type(MS.ideal(MS.one()).parent()) # optional - sage.modules """ @@ -21,7 +21,8 @@ def IdealMonoid(R): EXAMPLES:: sage: R = QQ['x'] - sage: sage.rings.ideal_monoid.IdealMonoid(R) + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: IdealMonoid(R) Monoid of ideals of Univariate Polynomial Ring in x over Rational Field """ return IdealMonoid_c(R) @@ -34,7 +35,8 @@ class IdealMonoid_c(Parent): TESTS:: sage: R = QQ['x'] - sage: M = sage.rings.ideal_monoid.IdealMonoid(R) + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R) sage: TestSuite(M).run() Failure in _test_category: ... @@ -51,16 +53,18 @@ def __init__(self, R): TESTS:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M # indirect doctest - Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M # indirect doctest # optional - sage.rings.number_field + Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 + with a = 4.795831523312720?*I sage: id = QQ.ideal(6) sage: id.parent().category() Category of commutative monoids - sage: MS = MatrixSpace(QQ,3,3) - sage: MS.ideal(MS.one()).parent().category() + sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: MS.ideal(MS.one()).parent().category() # optional - sage.modules Category of monoids """ self.__R = R @@ -77,9 +81,11 @@ def _repr_(self): TESTS:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M._repr_() - 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I' + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M._repr_() # optional - sage.rings.number_field + 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 + with a = 4.795831523312720?*I' """ return "Monoid of ideals of %s" % self.__R @@ -89,8 +95,9 @@ def ring(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M.ring() is R + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M.ring() is R # optional - sage.rings.number_field True """ return self.__R @@ -101,11 +108,12 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: R. = QuadraticField(-23) - sage: M = sage.rings.ideal_monoid.IdealMonoid(R) - sage: M(a) # indirect doctest + sage: R. = QuadraticField(-23) # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R) # optional - sage.rings.number_field + sage: M(a) # indirect doctest # optional - sage.rings.number_field Fractional ideal (a) - sage: M([a-4, 13]) + sage: M([a-4, 13]) # optional - sage.rings.number_field Fractional ideal (13, 1/2*a + 9/2) """ try: @@ -129,15 +137,15 @@ def _coerce_map_from_(self, x): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M.has_coerce_map_from(R) # indirect doctest + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M.has_coerce_map_from(R) # indirect doctest # optional - sage.rings.number_field True - sage: M.has_coerce_map_from(QQ.ideal_monoid()) + sage: M.has_coerce_map_from(QQ.ideal_monoid()) # optional - sage.rings.number_field True - sage: M.has_coerce_map_from(Zmod(6)) + sage: M.has_coerce_map_from(Zmod(6)) # optional - sage.rings.number_field False - sage: M.has_coerce_map_from(loads(dumps(M))) + sage: M.has_coerce_map_from(loads(dumps(M))) # optional - sage.rings.number_field True """ if isinstance(x, IdealMonoid_c): @@ -151,13 +159,13 @@ def __eq__(self, other): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M == QQ + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M == QQ # optional - sage.rings.number_field False - sage: M == 17 + sage: M == 17 # optional - sage.rings.number_field False - sage: M == R.ideal_monoid() + sage: M == R.ideal_monoid() # optional - sage.rings.number_field True """ if not isinstance(other, IdealMonoid_c): @@ -171,13 +179,13 @@ def __ne__(self, other): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M != QQ + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M != QQ # optional - sage.rings.number_field True - sage: M != 17 + sage: M != 17 # optional - sage.rings.number_field True - sage: M != R.ideal_monoid() + sage: M != R.ideal_monoid() # optional - sage.rings.number_field False """ return not (self == other) @@ -188,13 +196,13 @@ def __hash__(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: hash(M) == hash(QQ) + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: hash(M) == hash(QQ) # optional - sage.rings.number_field False - sage: hash(M) == 17 + sage: hash(M) == 17 # optional - sage.rings.number_field False - sage: hash(M) == hash(R.ideal_monoid()) + sage: hash(M) == hash(R.ideal_monoid()) # optional - sage.rings.number_field True """ # uses a random number, to have a distinct hash diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index aabe2572f31..44f7976fde6 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -203,8 +203,8 @@ We check that :trac:`17990` is fixed:: - sage: m = Matrix([Infinity]) - sage: m.rows() + sage: m = Matrix([Infinity]) # optional - sage.modules + sage: m.rows() # optional - sage.modules [(+Infinity)] """ #***************************************************************************** @@ -288,7 +288,7 @@ def _maxima_init_(self): """ TESTS:: - sage: maxima(-oo) + sage: maxima(-oo) # optional - sage.symbolic minf sage: [x._maxima_init_() for x in [unsigned_infinity, oo, -oo]] ['inf', 'inf', 'minf'] @@ -322,9 +322,9 @@ def __pari__(self): EXAMPLES:: - sage: pari(-oo) + sage: pari(-oo) # optional - sage.libs.pari -oo - sage: pari(oo) + sage: pari(oo) # optional - sage.libs.pari +oo """ # For some reason, it seems problematic to import sage.libs.all.pari, @@ -471,7 +471,7 @@ def _div_(self, other): Traceback (most recent call last): ... ValueError: unsigned oo times smaller number not defined - sage: SR(infinity) / unsigned_infinity + sage: SR(infinity) / unsigned_infinity # optional - sage.symbolic Traceback (most recent call last): ... RuntimeError: indeterminate expression: 0 * infinity encountered. @@ -567,8 +567,8 @@ def __init__(self): Sage can understand SymPy's complex infinity (:trac:`17493`):: - sage: import sympy - sage: SR(sympy.zoo) + sage: import sympy # optional - sympy + sage: SR(sympy.zoo) # optional - sympy Infinity Some equality checks:: @@ -675,7 +675,7 @@ def _element_constructor_(self, x): sage: UnsignedInfinityRing(2) # indirect doctest A number less than infinity - sage: UnsignedInfinityRing(I) + sage: UnsignedInfinityRing(I) # optional - sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(unsigned_infinity) Infinity @@ -683,10 +683,10 @@ def _element_constructor_(self, x): Infinity sage: UnsignedInfinityRing(-oo) Infinity - sage: K. = QuadraticField(3) - sage: UnsignedInfinityRing(a) + sage: K. = QuadraticField(3) # optional - sage.rings.number_field + sage: UnsignedInfinityRing(a) # optional - sage.rings.number_field A number less than infinity - sage: UnsignedInfinityRing(a - 2) + sage: UnsignedInfinityRing(a - 2) # optional - sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(RDF(oo)), UnsignedInfinityRing(RDF(-oo)) (Infinity, Infinity) @@ -700,14 +700,14 @@ def _element_constructor_(self, x): (Infinity, Infinity) sage: UnsignedInfinityRing(float('+inf')), UnsignedInfinityRing(float('-inf')) (Infinity, Infinity) - sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) + sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) # optional - sage.symbolic (Infinity, Infinity) The following rings have a ``is_infinity`` method:: sage: RR(oo).is_infinity() True - sage: SR(oo).is_infinity() + sage: SR(oo).is_infinity() # optional - sage.symbolic True """ # Lazy elements can wrap infinity or not, unwrap first @@ -747,11 +747,11 @@ def _coerce_map_from_(self, R): True sage: UnsignedInfinityRing.has_coerce_map_from(CC) True - sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) + sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) # optional - sage.rings.number_field True - sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) + sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) # optional - sage.modules False - sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) + sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) # optional - sage.groups False """ return isinstance(R, Ring) or R in (int, float, complex) @@ -941,12 +941,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: SR(unsigned_infinity)._sympy_() + sage: import sympy # optional - sympy + sage: SR(unsigned_infinity)._sympy_() # optional - sympy zoo - sage: gamma(-3)._sympy_() is sympy.factorial(-2) + sage: gamma(-3)._sympy_() is sympy.factorial(-2) # optional - sympy True - sage: gamma(-3) is sympy.factorial(-2)._sage_() + sage: gamma(-3) is sympy.factorial(-2)._sage_() # optional - sympy True """ import sympy @@ -1127,11 +1127,12 @@ def _element_constructor_(self, x): sage: InfinityRing(-1.5) A negative finite number sage: [InfinityRing(a) for a in [-2..2]] - [A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number] - sage: K. = QuadraticField(3) - sage: InfinityRing(a) + [A negative finite number, A negative finite number, Zero, + A positive finite number, A positive finite number] + sage: K. = QuadraticField(3) # optional - sage.rings.number_field + sage: InfinityRing(a) # optional - sage.rings.number_field A positive finite number - sage: InfinityRing(a - 2) + sage: InfinityRing(a - 2) # optional - sage.rings.number_field A negative finite number sage: InfinityRing(RDF(oo)), InfinityRing(RDF(-oo)) (+Infinity, -Infinity) @@ -1225,7 +1226,7 @@ def _coerce_map_from_(self, R): sage: InfinityRing.has_coerce_map_from(int) # indirect doctest True - sage: InfinityRing.has_coerce_map_from(AA) + sage: InfinityRing.has_coerce_map_from(AA) # optional - sage.rings.number_field True sage: InfinityRing.has_coerce_map_from(RDF) True @@ -1236,7 +1237,7 @@ def _coerce_map_from_(self, R): infinity ring:: sage: cm = get_coercion_model() - sage: cm.explain(AA(3), oo, operator.lt) + sage: cm.explain(AA(3), oo, operator.lt) # optional - sage.rings.number_field Coercion on left operand via Coercion map: From: Algebraic Real Field @@ -1277,7 +1278,7 @@ def _pushout_(self, other): r""" EXAMPLES:: - sage: QQbar(-2*i)*infinity + sage: QQbar(-2*i)*infinity # optional - sage.rings.number_field (-I)*Infinity """ from sage.symbolic.ring import SR @@ -1478,9 +1479,9 @@ def _latex_(self): TESTS:: - sage: a = InfinityRing(pi); a + sage: a = InfinityRing(pi); a # optional - sage.symbolic A positive finite number - sage: a._latex_() + sage: a._latex_() # optional - sage.symbolic 'A positive finite number' sage: [latex(InfinityRing(a)) for a in [-2..2]] [A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number] @@ -1621,12 +1622,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: bool(-oo == -sympy.oo) + sage: import sympy # optional - sympy + sage: bool(-oo == -sympy.oo) # optional - sympy True - sage: bool(SR(-oo) == -sympy.oo) + sage: bool(SR(-oo) == -sympy.oo) # optional - sympy True - sage: bool((-oo)._sympy_() == -sympy.oo) + sage: bool((-oo)._sympy_() == -sympy.oo) # optional - sympy True """ @@ -1639,9 +1640,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(-Infinity) + sage: gap(-Infinity) # optional - sage.libs.gap -infinity - sage: libgap(-Infinity) + sage: libgap(-Infinity) # optional - sage.libs.gap -infinity """ return '-infinity' @@ -1722,10 +1723,10 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: bool(oo == sympy.oo) # indirect doctest + sage: import sympy # optional - sympy + sage: bool(oo == sympy.oo) # indirect doctest # optional - sympy True - sage: bool(SR(oo) == sympy.oo) + sage: bool(SR(oo) == sympy.oo) # optional - sympy True """ import sympy @@ -1737,9 +1738,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(+Infinity) + sage: gap(+Infinity) # optional - sage.libs.gap infinity - sage: libgap(+Infinity) + sage: libgap(+Infinity) # optional - sage.libs.gap infinity """ return 'infinity' @@ -1767,7 +1768,7 @@ def test_comparison(ring): EXAMPLES:: sage: from sage.rings.infinity import test_comparison - sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, AA, RIF] + sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] sage: for R in rings: ....: print('testing {}'.format(R)) ....: test_comparison(R) @@ -1777,20 +1778,20 @@ def test_comparison(ring): testing Real Field with 200 bits of precision testing Real Double Field testing Real Lazy Field - testing Algebraic Real Field testing Real Interval Field with 53 bits of precision + sage: test_comparison(AA) # optional - sage.rings.number_field Comparison with number fields does not work:: - sage: K. = NumberField(x^2-3) - sage: (-oo < 1+sqrt3) and (1+sqrt3 < oo) # known bug + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: (-oo < 1 + sqrt3) and (1 + sqrt3 < oo) # known bug # optional - sage.rings.number_field False The symbolic ring handles its own infinities, but answers ``False`` (meaning: cannot decide) already for some very elementary comparisons:: - sage: test_comparison(SR) # known bug + sage: test_comparison(SR) # known bug # optional - sage.symbolic Traceback (most recent call last): ... AssertionError: testing -1000.0 in Symbolic Ring: id = ... diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 61c980557ff..08bdf24f7c1 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -25,7 +25,7 @@ Add an integer and a rational number:: Add an integer and a complex number:: sage: b = ComplexField().0 + 1.5 - sage: loads((a+b).dumps()) == a+b + sage: loads((a + b).dumps()) == a + b True sage: z = 32 @@ -354,7 +354,7 @@ cdef class IntegerWrapper(Integer): ``Integers`` (with initialized ``parent`` and ``mpz_t`` fields) into a pool on "deallocation" and then pull them out whenever a new one is needed. Because ``Integers`` are so common, this is - actually a significant savings. However , this does cause issues + actually a significant savings. However, this does cause issues with subclassing a Python class directly from ``Integer`` (but that's ok for a Cython class). @@ -425,9 +425,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Conversion from PARI:: - sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari + sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari -10380104371593008048799446356441519384 - sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari + sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari -3 Conversion from gmpy2:: @@ -463,11 +463,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): -901824309821093821093812093810928309183091832091 sage: ZZ(RR(2.0)^80) 1208925819614629174706176 - sage: ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3))) # optional - sage.rings.number_field, sage.symbolic + sage: ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3))) # optional - sage.rings.number_field sage.symbolic 5 - sage: ZZ(AA(32).nth_root(5)) # optional - sage.rings.number_field + sage: ZZ(AA(32).nth_root(5)) # optional - sage.rings.number_field 2 - sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari + sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari 4 sage: ZZ('sage') Traceback (most recent call last): @@ -479,10 +479,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): '3b' sage: ZZ( ZZ(5).digits(3) , 3) 5 - sage: import numpy - sage: ZZ(numpy.int64(7^7)) + sage: import numpy # optional - numpy + sage: ZZ(numpy.int64(7^7)) # optional - numpy 823543 - sage: ZZ(numpy.ubyte(-7)) + sage: ZZ(numpy.ubyte(-7)) # optional - numpy 249 sage: ZZ(True) 1 @@ -498,8 +498,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: k = GF(2) # optional - sage.libs.pari - sage: ZZ((k(0),k(1)), 2) # optional - sage.libs.pari + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: ZZ((k(0),k(1)), 2) # optional - sage.rings.finite_rings 2 :: @@ -535,72 +535,72 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Test conversion from PARI (:trac:`11685`):: - sage: ZZ(pari(-3)) # optional - sage.libs.pari + sage: ZZ(pari(-3)) # optional - sage.libs.pari -3 - sage: ZZ(pari("-3.0")) # optional - sage.libs.pari + sage: ZZ(pari("-3.0")) # optional - sage.libs.pari -3 - sage: ZZ(pari("-3.5")) # optional - sage.libs.pari + sage: ZZ(pari("-3.5")) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral real number to an Integer - sage: ZZ(pari("1e100")) # optional - sage.libs.pari + sage: ZZ(pari("1e100")) # optional - sage.libs.pari Traceback (most recent call last): ... PariError: precision too low in truncr (precision loss in truncation) - sage: ZZ(pari("10^50")) # optional - sage.libs.pari + sage: ZZ(pari("10^50")) # optional - sage.libs.pari 100000000000000000000000000000000000000000000000000 - sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari + sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari 3 - sage: ZZ(GF(3^20,'t')(1)) # optional - sage.libs.pari + sage: ZZ(GF(3^20,'t')(1)) # optional - sage.rings.finite_rings 1 - sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari + sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari sage.rings.finite_rings 1 sage: x = polygen(QQ) - sage: K. = NumberField(x^2+3) # optional - sage.rings.number_field - sage: ZZ(a^2) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 3) # optional - sage.rings.number_field + sage: ZZ(a^2) # optional - sage.rings.number_field -3 - sage: ZZ(pari(a)^2) # optional - sage.libs.pari, sage.rings.number_field + sage: ZZ(pari(a)^2) # optional - sage.libs.pari sage.rings.number_field -3 - sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # optional - sage.libs.pari + sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Unable to coerce PARI x to an Integer Test coercion of p-adic with negative valuation:: - sage: ZZ(pari(Qp(11)(11^-7))) # optional - sage.libs.pari + sage: ZZ(pari(Qp(11)(11^-7))) # optional - sage.libs.pari sage.rings.padics Traceback (most recent call last): ... TypeError: cannot convert p-adic with negative valuation to an integer Test converting a list with a very large base:: - sage: a=ZZ(randint(0,2^128-1)) + sage: a = ZZ(randint(0, 2^128 - 1)) sage: L = a.digits(2^64) sage: a == sum([x * 2^(64*i) for i,x in enumerate(L)]) True - sage: a == ZZ(L,base=2^64) + sage: a == ZZ(L, base=2^64) True Test comparisons with numpy types (see :trac:`13386` and :trac:`18076`):: - sage: import numpy - sage: numpy.int8('12') == 12 + sage: import numpy # optional - numpy + sage: numpy.int8('12') == 12 # optional - numpy True - sage: 12 == numpy.int8('12') + sage: 12 == numpy.int8('12') # optional - numpy True - sage: float('15') == 15 + sage: float('15') == 15 # optional - numpy True - sage: 15 == float('15') + sage: 15 == float('15') # optional - numpy True Test underscores as digit separators (PEP 515, https://www.python.org/dev/peps/pep-0515/):: - sage: Integer('1_3') + sage: Integer('1_3') # optional - numpy 13 - sage: Integer(b'1_3') + sage: Integer(b'1_3') # optional - numpy 13 """ # TODO: All the code below should somehow be in an external @@ -762,15 +762,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _im_gens_(self, codomain, im_gens, base_map=None): """ - Return the image of self under the map that sends the generators of + Return the image of ``self`` under the map that sends the generators of the parent to im_gens. Since ZZ maps canonically in the category of rings, this is just the natural coercion. EXAMPLES:: sage: n = -10 - sage: R = GF(17) # optional - sage.libs.pari - sage: n._im_gens_(R, [R(1)]) # optional - sage.libs.pari + sage: R = GF(17) # optional - sage.rings.finite_rings + sage: n._im_gens_(R, [R(1)]) # optional - sage.rings.finite_rings 7 """ return codomain.coerce(self) @@ -1007,9 +1007,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: ex = SR(ZZ(7)); ex + sage: ex = SR(ZZ(7)); ex # optional - sage.symbolic 7 - sage: parent(ex) + sage: parent(ex) # optional - sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -1020,9 +1020,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 5; n._sympy_() + sage: n = 5; n._sympy_() # optional - sympy 5 - sage: n = -5; n._sympy_() + sage: n = -5; n._sympy_() # optional - sympy -5 """ import sympy @@ -1077,7 +1077,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: two=Integer(2) + sage: two = Integer(2) sage: two.str(1) Traceback (most recent call last): ... @@ -1364,7 +1364,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Return a list of digits for ``self`` in the given base in little endian order. - The returned value is unspecified if self is a negative number + The returned value is unspecified if ``self`` is a negative number and the digits are given. INPUT: @@ -1695,7 +1695,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ndigits(self, base=10): """ - Return the number of digits of self expressed in the given base. + Return the number of digits of ``self`` expressed in the given base. INPUT: @@ -2008,7 +2008,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Traceback (most recent call last): ... ZeroDivisionError: rational division by zero - sage: 3 / QQbar.zero() # optional - sage.rings.number_field + sage: 3 / QQbar.zero() # optional - sage.rings.number_field Traceback (most recent call last): ... ZeroDivisionError: division by zero in algebraic field @@ -2113,7 +2113,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 1 sage: 2^-0 1 - sage: (-1)^(1/3) # optional - sage.symbolic + sage: (-1)^(1/3) # optional - sage.symbolic (-1)^(1/3) For consistency with Python and MPFR, 0^0 is defined to be 1 in @@ -2140,7 +2140,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We raise 2 to various interesting exponents:: - sage: 2^x # symbolic x # optional - sage.symbolic + sage: 2^x # symbolic x # optional - sage.symbolic 2^x sage: 2^1.5 # real number 2.82842712474619 @@ -2151,19 +2151,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: r = 2 ^ int(-3); r; type(r) 1/8 - sage: f = 2^(sin(x)-cos(x)); f # optional - sage.symbolic + sage: f = 2^(sin(x)-cos(x)); f # optional - sage.symbolic 2^(-cos(x) + sin(x)) sage: f(x=3) 2^(-cos(3) + sin(3)) A symbolic sum:: - sage: x, y, z = var('x,y,z') # optional - sage.symbolic - sage: 2^(x + y + z) # optional - sage.symbolic + sage: x, y, z = var('x,y,z') # optional - sage.symbolic + sage: 2^(x + y + z) # optional - sage.symbolic 2^(x + y + z) - sage: 2^(1/2) # optional - sage.symbolic + sage: 2^(1/2) # optional - sage.symbolic sqrt(2) - sage: 2^(-1/2) # optional - sage.symbolic + sage: 2^(-1/2) # optional - sage.symbolic 1/2*sqrt(2) TESTS:: @@ -2316,25 +2316,25 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def nth_root(self, int n, bint truncate_mode=0): r""" - Returns the (possibly truncated) n'th root of self. + Returns the (possibly truncated) ``n``-th root of ``self``. INPUT: - - ``n`` - integer >= 1 (must fit in C int type). + - ``n`` - integer >= 1 (must fit in the C ``int`` type). - ``truncate_mode`` - boolean, whether to allow truncation if - self is not an n'th power. + ``self`` is not an n'th power. OUTPUT: - If truncate_mode is 0 (default), then returns the exact n'th root - if self is an n'th power, or raises a ValueError if it is not. + If ``truncate_mode`` is 0 (default), then returns the exact n'th root + if ``self`` is an n'th power, or raises a ValueError if it is not. - If truncate_mode is 1, then if either n is odd or self is - positive, returns a pair (root, exact_flag) where root is the - truncated nth root (rounded towards zero) and exact_flag is a + If ``truncate_mode`` is 1, then if either n is odd or ``self`` is + positive, returns a pair ``(root, exact_flag)`` where ``root`` is the + truncated ``n``-th root (rounded towards zero) and ``exact_flag`` is a boolean indicating whether the root extraction was exact; - otherwise raises a ValueError. + otherwise raises a :class:`ValueError`. AUTHORS: @@ -2643,11 +2643,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: # The following are very very fast. sage: # Note that for base m a perfect power of 2, we get the exact log by counting bits. - sage: n=2983579823750185701375109835; m=32 + sage: n = 2983579823750185701375109835; m = 32 sage: n.exact_log(m) 18 sage: # The next is a favorite of mine. The log2 approximate is exact and immediately provable. - sage: n=90153710570912709517902579010793251709257901270941709247901209742124;m=213509721309572 + sage: n = 90153710570912709517902579010793251709257901270941709247901209742124 + sage: m = 213509721309572 sage: n.exact_log(m) 4 @@ -2663,9 +2664,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: x.exact_log(3) 100000 - sage: (x+1).exact_log(3) + sage: (x + 1).exact_log(3) 100000 - sage: (x-1).exact_log(3) + sage: (x - 1).exact_log(3) 99999 :: @@ -2751,23 +2752,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def log(self, m=None, prec=None): r""" Returns symbolic log by default, unless the logarithm is exact (for - an integer argument). When precision is given, the RealField + an integer argument). When ``prec`` is given, the :class:`RealField` approximation to that bit precision is used. This function is provided primarily so that Sage integers may be treated in the same manner as real numbers when convenient. Direct - use of exact_log is probably best for arithmetic log computation. + use of :meth:`exact_log` is probably best for arithmetic log computation. INPUT: - ``m`` - default: natural log base e - - ``prec`` - integer (default: None): if None, returns - symbolic, else to given bits of precision as in RealField + - ``prec`` - integer (default: ``None``): if ``None``, returns + symbolic, else to given bits of precision as in :class:`RealField` EXAMPLES:: - sage: Integer(124).log(5) # optional - sage.symbolic + sage: Integer(124).log(5) # optional - sage.symbolic log(124)/log(5) sage: Integer(124).log(5, 100) 2.9950093311241087454822446806 @@ -2784,8 +2785,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: log(x, 3) 100000 - With the new Pynac symbolic backend, log(x) also - works in a reasonable amount of time for this x:: + Also ``log(x)``, giving a symbolic output, + works in a reasonable amount of time for this ``x``:: sage: x = 3^100000 sage: log(x) @@ -2794,20 +2795,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): But approximations are probably more useful in this case, and work to as high a precision as we desire:: - sage: x.log(3,53) # default precision for RealField + sage: x.log(3, 53) # default precision for RealField 100000.000000000 - sage: (x+1).log(3,53) + sage: (x +1 ).log(3, 53) 100000.000000000 - sage: (x+1).log(3,1000) + sage: (x + 1).log(3, 1000) 100000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 We can use non-integer bases, with default e:: - sage: x.log(2.5,prec=53) + sage: x.log(2.5, prec=53) 119897.784671579 We also get logarithms of negative integers, via the - symbolic ring, using the branch from `-pi` to `pi`:: + symbolic ring, using the branch from `-\pi` to `\pi`:: sage: log(-1) I*pi @@ -2829,7 +2830,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: (-2).log(3) # optional - sage.symbolic + sage: (-2).log(3) # optional - sage.symbolic (I*pi + log(2))/log(3) """ cdef int self_sgn @@ -2872,7 +2873,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def exp(self, prec=None): r""" - Returns the exponential function of self as a real number. + Returns the exponential function of ``self`` as a real number. This function is provided only so that Sage integers may be treated in the same manner as real numbers when convenient. @@ -2886,11 +2887,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: Integer(8).exp() # optional - sage.symbolic + sage: Integer(8).exp() # optional - sage.symbolic e^8 - sage: Integer(8).exp(prec=100) # optional - sage.symbolic + sage: Integer(8).exp(prec=100) # optional - sage.symbolic 2980.9579870417282747435920995 - sage: exp(Integer(8)) # optional - sage.symbolic + sage: exp(Integer(8)) # optional - sage.symbolic e^8 For even fairly large numbers, this may not be useful. @@ -2898,9 +2899,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: sage: y = Integer(145^145) - sage: y.exp() # optional - sage.symbolic + sage: y.exp() # optional - sage.symbolic e^25024207011349079210459585279553675697932183658421565260323592409432707306554163224876110094014450895759296242775250476115682350821522931225499163750010280453185147546962559031653355159703678703793369785727108337766011928747055351280379806937944746847277089168867282654496776717056860661614337004721164703369140625 - sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic + sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic +infinity """ from sage.functions.all import exp @@ -2911,7 +2912,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def prime_to_m_part(self, m): """ - Returns the prime-to-m part of self, i.e., the largest divisor of + Returns the prime-to-m part of ``self``, i.e., the largest divisor of ``self`` that is coprime to ``m``. INPUT: @@ -2980,12 +2981,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Setting the optional ``limit`` argument works as expected:: sage: a = 10^100 + 1 - sage: a.prime_divisors() + sage: a.prime_divisors() # optional - sage.libs.pari [73, 137, 401, 1201, 1601, 1676321, 5964848081, 129694419029057750551385771184564274499075700947656757821537291527196801] - sage: a.prime_divisors(limit=10^3) + sage: a.prime_divisors(limit=10^3) # optional - sage.libs.pari [73, 137, 401] - sage: a.prime_divisors(limit=10^7) + sage: a.prime_divisors(limit=10^7) # optional - sage.libs.pari [73, 137, 401, 1201, 1601, 1676321] """ res = [r[0] for r in self.factor(*args, **kwds)] @@ -3027,32 +3028,32 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): [1, 2, 3, 4, 6, 8, 9, 12, 17, 18, 24, 34, 36, 51, 68, 72, 102, 136, 153, 204, 306, 408, 612, 1224] sage: a = odd_part(factorial(31)) - sage: v = a.divisors() - sage: len(v) + sage: v = a.divisors() # optional - sage.libs.pari + sage: len(v) # optional - sage.libs.pari 172800 - sage: prod(e + 1 for p, e in factor(a)) + sage: prod(e + 1 for p, e in factor(a)) # optional - sage.libs.pari 172800 - sage: all(t.divides(a) for t in v) + sage: all(t.divides(a) for t in v) # optional - sage.libs.pari True :: sage: n = 2^551 - 1 - sage: L = n.divisors() # optional - sage.libs.pari - sage: len(L) # optional - sage.libs.pari + sage: L = n.divisors() # optional - sage.libs.pari + sage: len(L) # optional - sage.libs.pari 256 - sage: L[-1] == n # optional - sage.libs.pari + sage: L[-1] == n # optional - sage.libs.pari True TESTS: Overflow:: - sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large - sage: prod(primes_first_n(58)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(58)).divisors() # optional - sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large # 32-bit @@ -3062,8 +3063,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): (the ``divisors`` call below allocates about 800 MB every time, so a memory leak will not go unnoticed):: - sage: n = prod(primes_first_n(25)) # optional - sage.libs.pari - sage: for i in range(20): # long time # optional - sage.libs.pari + sage: n = prod(primes_first_n(25)) # optional - sage.libs.pari + sage: for i in range(20): # long time # optional - sage.libs.pari ....: try: ....: alarm(RDF.random_element(1e-3, 0.5)) ....: _ = n.divisors() @@ -3345,9 +3346,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): This example caused trouble in :trac:`6083`:: - sage: a = next_prime(2**31) # optional - sage.libs.pari - sage: b = Integers(a)(100) # optional - sage.libs.pari - sage: a % b # optional - sage.libs.pari + sage: a = next_prime(2**31) # optional - sage.libs.pari + sage: b = Integers(a)(100) # optional - sage.libs.pari + sage: a % b # optional - sage.libs.pari Traceback (most recent call last): ... ArithmeticError: reduction modulo 100 not defined @@ -3394,7 +3395,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def quo_rem(Integer self, other): """ - Returns the quotient and the remainder of self divided by other. + Returns the quotient and the remainder of ``self`` divided by other. Note that the remainder returned is always either zero or of the same sign as other. @@ -3443,10 +3444,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: divmod(1, sys.maxsize+1r) # should not raise OverflowError: Python int too large to convert to C long (0, 1) - sage: import mpmath - sage: mpmath.mp.prec = 1000 - sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) - sage: len(str(root)) + sage: import mpmath # optional - mpmath + sage: mpmath.mp.prec = 1000 # optional - mpmath + sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # optional - mpmath + sage: len(str(root)) # optional - mpmath 301 """ cdef Integer q = PY_NEW(Integer) @@ -3484,7 +3485,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def powermod(self, exp, mod): r""" - Compute self\*\*exp modulo mod. + Compute ``self**exp`` modulo ``mod``. EXAMPLES:: @@ -3517,11 +3518,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): return x def rational_reconstruction(self, Integer m): - """ - Return the rational reconstruction of this integer modulo m, i.e., - the unique (if it exists) rational number that reduces to self + r""" + Return the rational reconstruction of this integer modulo `m`, i.e., + the unique (if it exists) rational number that reduces to ``self`` modulo m and whose numerator and denominator is bounded by - sqrt(m/2). + `\sqrt{m/2}`. INPUT: @@ -3687,58 +3688,56 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trial_division(self, long bound=LONG_MAX, long start=2): """ - Return smallest prime divisor of self up to bound, beginning - checking at start, or abs(self) if no such divisor is found. + Return smallest prime divisor of ``self`` up to bound, beginning + checking at ``start``, or ``abs(self)`` if no such divisor is found. INPUT: - - ``bound`` -- a positive integer that fits in a C signed long - - ``start`` -- a positive integer that fits in a C signed long + - ``bound`` -- a positive integer that fits in a C ``signed long`` + - ``start`` -- a positive integer that fits in a C ``signed long`` - OUTPUT: - - - a positive integer + OUTPUT: A positive integer EXAMPLES:: - sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() # optional - sage.libs.pari + sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() # optional - sage.libs.pari 1000003 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() # optional - sage.libs.pari 1000003 - sage: n.trial_division(bound=100) # optional - sage.libs.pari + sage: n.trial_division(bound=100) # optional - sage.libs.pari 10000049000057 - sage: n.trial_division(bound=-10) # optional - sage.libs.pari + sage: n.trial_division(bound=-10) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: bound must be positive - sage: n.trial_division(bound=0) # optional - sage.libs.pari + sage: n.trial_division(bound=0) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: bound must be positive - sage: ZZ(0).trial_division() # optional - sage.libs.pari + sage: ZZ(0).trial_division() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: self must be nonzero - sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 100003 - sage: n.trial_division(bound=10^4) # optional - sage.libs.pari + sage: n.trial_division(bound=10^4) # optional - sage.libs.pari 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari + sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() # optional - sage.libs.pari 100003 - sage: n = 2 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 2 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 2 - sage: n = 3 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 3 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 3 - sage: n = 5 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 5 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 5 - sage: n = 2 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 2 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 2 - sage: n = 3 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 3 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 3 - sage: n = 5 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 5 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 5 You can specify a starting point:: @@ -3864,7 +3863,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 2^100 - 1; n.factor() # optional - sage.libs.pari + sage: n = 2^100 - 1; n.factor() # optional - sage.libs.pari 3 * 5^3 * 11 * 31 * 41 * 101 * 251 * 601 * 1801 * 4051 * 8101 * 268501 This factorization can be converted into a list of pairs `(p, @@ -3887,13 +3886,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: dict(f)[3] 6 - We use proof=False, which doesn't prove correctness of the primes + We use ``proof=False``, which doesn't prove correctness of the primes that appear in the factorization:: sage: n = 920384092842390423848290348203948092384082349082 - sage: n.factor(proof=False) # optional - sage.libs.pari + sage: n.factor(proof=False) # optional - sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 - sage: n.factor(proof=True) # optional - sage.libs.pari + sage: n.factor(proof=True) # optional - sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 We factor using trial division only:: @@ -3909,10 +3908,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We factor using a quadratic sieve algorithm:: - sage: p = next_prime(10^20) # optional - sage.libs.pari - sage: q = next_prime(10^21) # optional - sage.libs.pari - sage: n = p * q # optional - sage.libs.pari - sage: n.factor(algorithm='qsieve') # optional - sage.libs.pari + sage: p = next_prime(10^20) # optional - sage.libs.pari + sage: q = next_prime(10^21) # optional - sage.libs.pari + sage: n = p * q # optional - sage.libs.pari + sage: n.factor(algorithm='qsieve') # optional - sage.libs.pari doctest:... RuntimeWarning: the factorization returned by qsieve may be incomplete (the factors may not be prime) or even wrong; see qsieve? for details @@ -3920,10 +3919,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We factor using the elliptic curve method:: - sage: p = next_prime(10^15) # optional - sage.libs.pari - sage: q = next_prime(10^21) # optional - sage.libs.pari - sage: n = p * q # optional - sage.libs.pari - sage: n.factor(algorithm='ecm') # optional - sage.libs.pari + sage: p = next_prime(10^15) # optional - sage.libs.pari + sage: q = next_prime(10^21) # optional - sage.libs.pari + sage: n = p * q # optional - sage.libs.pari + sage: n.factor(algorithm='ecm') # optional - sage.libs.pari 1000000000000037 * 1000000000000000000117 TESTS:: @@ -4170,7 +4169,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cpdef RingElement _valuation(Integer self, Integer p): r""" - Return the p-adic valuation of self. + Return the p-adic valuation of ``self``. We do not require that p be prime, but it must be at least 2. For more documentation see ``valuation`` @@ -4195,8 +4194,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef object _val_unit(Integer self, Integer p): r""" - Returns a pair: the p-adic valuation of self, and the p-adic unit - of self. + Returns a pair: the p-adic valuation of ``self``, and the p-adic unit + of ``self``. We do not require the p be prime, but it must be at least 2. For more documentation see ``val_unit`` @@ -4220,7 +4219,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def valuation(self, p): """ - Return the p-adic valuation of self. + Return the p-adic valuation of ``self``. INPUT: @@ -4281,8 +4280,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def val_unit(self, p): r""" - Returns a pair: the p-adic valuation of self, and the p-adic unit - of self. + Returns a pair: the p-adic valuation of ``self``, and the p-adic unit + of ``self``. INPUT: @@ -4317,10 +4316,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): IMPLEMENTATION: - Currently returns 0 when self is 0. This behaviour is fairly arbitrary, + Currently returns 0 when ``self`` is 0. This behaviour is fairly arbitrary, and in Sage 4.6 this special case was not handled at all, eventually propagating a TypeError. The caller should not rely on the behaviour - in case self is 0. + in case ``self`` is 0. EXAMPLES:: @@ -4344,10 +4343,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef Integer _divide_knowing_divisible_by(Integer self, Integer right): r""" - Returns the integer self / right when self is divisible by right. + Returns the integer ``self`` / ``right`` when ``self`` is divisible by right. - If self is not divisible by right, the return value is undefined, - and may not even be close to self/right. For more documentation see + If ``self`` is not divisible by right, the return value is undefined, + and may not even be close to ``self`` / ``right``. For more documentation see ``divide_knowing_divisible_by`` AUTHORS: @@ -4370,10 +4369,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def divide_knowing_divisible_by(self, right): r""" - Returns the integer self / right when self is divisible by right. + Returns the integer ``self`` / ``right`` when ``self`` is divisible by ``right``. - If self is not divisible by right, the return value is undefined, - and may not even be close to self/right for multi-word integers. + If ``self`` is not divisible by right, the return value is undefined, + and may not even be close to ``self`` / ``right`` for multi-word integers. EXAMPLES:: @@ -4400,7 +4399,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _lcm(self, Integer n): """ - Returns the least common multiple of self and `n`. + Returns the least common multiple of ``self`` and `n`. EXAMPLES:: @@ -4416,7 +4415,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _gcd(self, Integer n): """ - Return the greatest common divisor of self and `n`. + Return the greatest common divisor of ``self`` and `n`. EXAMPLES:: @@ -4533,7 +4532,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def multifactorial(self, long k): r""" - Compute the k-th factorial `n!^{(k)}` of self. + Compute the k-th factorial `n!^{(k)}` of ``self``. The multifactorial number `n!^{(k)}` is defined for non-negative integers `n` as follows. For `k=1` this is the standard factorial, @@ -4619,13 +4618,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: gamma(5) + sage: gamma(5) # optional - sage.symbolic 24 - sage: gamma(0) + sage: gamma(0) # optional - sage.symbolic Infinity - sage: gamma(-1) + sage: gamma(-1) # optional - sage.symbolic Infinity - sage: gamma(-2^150) + sage: gamma(-2^150) # optional - sage.symbolic Infinity """ if mpz_sgn(self.value) > 0: @@ -4635,7 +4634,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def floor(self): """ - Return the floor of self, which is just self since self is an + Return the floor of ``self``, which is just self since ``self`` is an integer. EXAMPLES:: @@ -4648,7 +4647,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ceil(self): """ - Return the ceiling of self, which is self since self is an + Return the ceiling of ``self``, which is ``self`` since ``self`` is an integer. EXAMPLES:: @@ -4661,8 +4660,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trunc(self): """ - Round this number to the nearest integer, which is self since - self is an integer. + Round this number to the nearest integer, which is ``self`` since + ``self`` is an integer. EXAMPLES:: @@ -4674,8 +4673,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def round(Integer self, mode="away"): """ - Returns the nearest integer to ``self``, which is self since - self is an integer. + Returns the nearest integer to ``self``, which is ``self`` since + ``self`` is an integer. EXAMPLES: @@ -4689,7 +4688,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def real(self): """ - Returns the real part of self, which is self. + Returns the real part of ``self``, which is ``self``. EXAMPLES:: @@ -4700,7 +4699,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def imag(self): """ - Returns the imaginary part of self, which is zero. + Returns the imaginary part of ``self``, which is zero. EXAMPLES:: @@ -4787,7 +4786,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_square(self): r""" - Returns ``True`` if self is a perfect square. + Returns ``True`` if ``self`` is a perfect square. EXAMPLES:: @@ -4815,23 +4814,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 144.perfect_power() # optional - sage.libs.pari + sage: 144.perfect_power() # optional - sage.libs.pari (12, 2) - sage: 1.perfect_power() # optional - sage.libs.pari + sage: 1.perfect_power() # optional - sage.libs.pari (1, 1) - sage: 0.perfect_power() # optional - sage.libs.pari + sage: 0.perfect_power() # optional - sage.libs.pari (0, 1) - sage: (-1).perfect_power() # optional - sage.libs.pari + sage: (-1).perfect_power() # optional - sage.libs.pari (-1, 1) - sage: (-8).perfect_power() # optional - sage.libs.pari + sage: (-8).perfect_power() # optional - sage.libs.pari (-2, 3) - sage: (-4).perfect_power() # optional - sage.libs.pari + sage: (-4).perfect_power() # optional - sage.libs.pari (-4, 1) - sage: (101^29).perfect_power() # optional - sage.libs.pari + sage: (101^29).perfect_power() # optional - sage.libs.pari (101, 29) - sage: (-243).perfect_power() # optional - sage.libs.pari + sage: (-243).perfect_power() # optional - sage.libs.pari (-3, 5) - sage: (-64).perfect_power() # optional - sage.libs.pari + sage: (-64).perfect_power() # optional - sage.libs.pari (-4, 3) """ parians = self.__pari__().ispower() @@ -5038,8 +5037,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): .. NOTE:: - For large integers self, is_power_of() is faster than - is_perfect_power(). The following examples gives some indication of + For large integers ``self``, :meth:`is_power_of` is faster than + :meth:`is_perfect_power`. The following examples give some indication of how much faster. :: @@ -5047,15 +5046,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: b = lcm(range(1,10000)) sage: b.exact_log(2) 14446 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_perfect_power() sage: cputime(t) # random 0.53203299999999976 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_power_of(2) sage: cputime(t) # random 0.0 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_power_of(3) sage: cputime(t) # random 0.032002000000000308 @@ -5065,19 +5064,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: b = lcm(range(1, 1000)) sage: b.exact_log(2) 1437 - sage: t=cputime() - sage: for a in range(2, 10000): k = b.is_perfect_power() # note that we change the range from the example above + sage: t = cputime() + sage: for a in range(2, 10000): # note that we change the range from the example above + ....: k = b.is_perfect_power() sage: cputime(t) # random 0.17201100000000036 - sage: t=cputime(); TWO=int(2) + sage: t = cputime(); TWO = int(2) sage: for a in range(2, 10000): k = b.is_power_of(TWO) sage: cputime(t) # random 0.0040000000000000036 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 10000): k = b.is_power_of(3) sage: cputime(t) # random 0.040003000000000011 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 10000): k = b.is_power_of(a) sage: cputime(t) # random 0.02800199999999986 @@ -5118,55 +5118,55 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 17.is_prime_power() # optional - sage.libs.pari + sage: 17.is_prime_power() # optional - sage.libs.pari True - sage: 10.is_prime_power() # optional - sage.libs.pari + sage: 10.is_prime_power() # optional - sage.libs.pari False - sage: 64.is_prime_power() # optional - sage.libs.pari + sage: 64.is_prime_power() # optional - sage.libs.pari True - sage: (3^10000).is_prime_power() # optional - sage.libs.pari + sage: (3^10000).is_prime_power() # optional - sage.libs.pari True - sage: (10000).is_prime_power() # optional - sage.libs.pari + sage: (10000).is_prime_power() # optional - sage.libs.pari False - sage: (-3).is_prime_power() # optional - sage.libs.pari + sage: (-3).is_prime_power() # optional - sage.libs.pari False - sage: 0.is_prime_power() # optional - sage.libs.pari + sage: 0.is_prime_power() # optional - sage.libs.pari False - sage: 1.is_prime_power() # optional - sage.libs.pari + sage: 1.is_prime_power() # optional - sage.libs.pari False - sage: p = next_prime(10^20); p # optional - sage.libs.pari + sage: p = next_prime(10^20); p # optional - sage.libs.pari 100000000000000000039 - sage: p.is_prime_power() # optional - sage.libs.pari + sage: p.is_prime_power() # optional - sage.libs.pari True - sage: (p^97).is_prime_power() # optional - sage.libs.pari + sage: (p^97).is_prime_power() # optional - sage.libs.pari True - sage: (p+1).is_prime_power() # optional - sage.libs.pari + sage: (p + 1).is_prime_power() # optional - sage.libs.pari False With the ``get_data`` keyword set to ``True``:: - sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari (3, 100) - sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari + sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari (12, 0) - sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari (100000000000000000039, 97) - sage: q = p.next_prime(); q # optional - sage.libs.pari + sage: q = p.next_prime(); q # optional - sage.libs.pari 100000000000000000129 - sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari (10000000000000000016800000000000000005031, 0) - The method works for large entries when `proof=False`:: + The method works for large entries when ``proof=False``:: sage: proof.arithmetic(False) - sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari + sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari True sage: proof.arithmetic(True) We check that :trac:`4777` is fixed:: sage: n = 150607571^14 - sage: n.is_prime_power() # optional - sage.libs.pari + sage: n.is_prime_power() # optional - sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5240,26 +5240,26 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari False sage: z = 7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari True sage: z = -7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari False - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True :: sage: z = 10^80 + 129 - sage: z.is_prime(proof=False) # optional - sage.libs.pari + sage: z.is_prime(proof=False) # optional - sage.libs.pari True - sage: z.is_prime(proof=True) # optional - sage.libs.pari + sage: z.is_prime(proof=True) # optional - sage.libs.pari True When starting Sage the arithmetic proof flag is True. We can change @@ -5268,17 +5268,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: proof.arithmetic() True sage: n = 10^100 + 267 - sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari + sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari 5 loops, best of 3: 163 ms per loop sage: proof.arithmetic(False) sage: proof.arithmetic() False - sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari + sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari 1000 loops, best of 3: 573 us per loop ALGORITHM: - Calls the PARI ``isprime`` function. + Calls the PARI function :pari:`isprime`. TESTS: @@ -5290,7 +5290,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ....: if tab[i]: ....: for j in range(2*i, size, i): ....: tab[j] = 0 - sage: all(ZZ(i).is_prime() == b for i,b in enumerate(tab)) # optional - sage.libs.pari + sage: all(ZZ(i).is_prime() == b for i,b in enumerate(tab)) # optional - sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5347,22 +5347,22 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_irreducible(self): r""" - Returns ``True`` if self is irreducible, i.e. +/- + Returns ``True`` if ``self`` is irreducible, i.e. +/- prime EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari False sage: z = 7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True sage: z = -7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True """ cdef Integer n = self if self >= 0 else -self @@ -5374,7 +5374,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): This uses PARI's Baillie-PSW probabilistic primality test. Currently, there are no known pseudoprimes for - Baillie-PSW that are not actually prime. However it is + Baillie-PSW that are not actually prime. However, it is conjectured that there are infinitely many. See :wikipedia:`Baillie-PSW_primality_test` @@ -5382,10 +5382,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # optional - sage.libs.pari False """ return self.__pari__().ispseudoprime() @@ -5406,17 +5406,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: x = 10^200 + 357 - sage: x.is_pseudoprime() # optional - sage.libs.pari + sage: x.is_pseudoprime() # optional - sage.libs.pari True - sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari True - sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari (1000...000357, 12) - sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari True - sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari False - sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari + sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari True TESTS:: @@ -5425,7 +5425,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): False sage: (-1).is_pseudoprime_power() False - sage: 1.is_pseudoprime_power() # optional - sage.libs.pari + sage: 1.is_pseudoprime_power() # optional - sage.libs.pari False """ return self.is_prime_power(proof=False, get_data=get_data) @@ -5439,7 +5439,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - :meth:`perfect_power`: Finds the minimal base for which this integer is a perfect power. - - :meth:`is_power_of`: If you know the base already this method is + - :meth:`is_power_of`: If you know the base already, this method is the fastest option. - :meth:`is_prime_power`: Checks whether the base is prime. @@ -5492,20 +5492,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field sage: n = 4 - sage: n.is_norm(K) # optional - sage.rings.number_field + sage: n.is_norm(K) # optional - sage.rings.number_field True - sage: 5.is_norm(K) # optional - sage.rings.number_field + sage: 5.is_norm(K) # optional - sage.rings.number_field False sage: 7.is_norm(QQ) True - sage: n.is_norm(K, element=True) # optional - sage.rings.number_field + sage: n.is_norm(K, element=True) # optional - sage.rings.number_field (True, -4*beta + 6) - sage: n.is_norm(K, element=True)[1].norm() # optional - sage.rings.number_field + sage: n.is_norm(K, element=True)[1].norm() # optional - sage.rings.number_field 4 sage: n = 5 - sage: n.is_norm(K, element=True) # optional - sage.rings.number_field + sage: n.is_norm(K, element=True) # optional - sage.rings.number_field (False, None) sage: n = 7 sage: n.is_norm(QQ, element=True) @@ -5521,9 +5521,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field + sage: 3._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field (1, 3) - sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field + sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field (zeta7^5 - zeta7^2, 1) """ from sage.rings.rational_field import QQ @@ -5531,7 +5531,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def jacobi(self, b): r""" - Calculate the Jacobi symbol `\left(\frac{self}{b}\right)`. + Calculate the Jacobi symbol `\left(\frac{\text{self}}{b}\right)`. EXAMPLES:: @@ -5568,9 +5568,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def kronecker(self, b): r""" - Calculate the Kronecker symbol `\left(\frac{self}{b}\right)` - with the Kronecker extension `(self/2)=(2/self)` when `self` is odd, - or `(self/2)=0` when `self` is even. + Calculate the Kronecker symbol `\left(\frac{\text{self}}{b}\right)` + with the Kronecker extension `(\text{self}/2)=(2/\text{self})` when ``self`` is odd, + or `(\text{self}/2)=0` when ``self`` is even. EXAMPLES:: @@ -5605,7 +5605,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - ``proof`` (boolean, default ``True``) -- if ``False`` then for negative discriminants a faster algorithm is used by the PARI library which is known to give incorrect results - when the class group has many cyclic factors. However the + when the class group has many cyclic factors. However, the results are correct for discriminants `D` with `|D|\le 2\cdot10^{10}`. OUTPUT: @@ -5624,11 +5624,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-163).class_number() # optional - sage.libs.pari + sage: (-163).class_number() # optional - sage.libs.pari 1 - sage: (-104).class_number() # optional - sage.libs.pari + sage: (-104).class_number() # optional - sage.libs.pari 6 - sage: [((4*n+1),(4*n+1).class_number()) for n in [21..29]] # optional - sage.libs.pari + sage: [((4*n + 1), (4*n + 1).class_number()) for n in [21..29]] # optional - sage.libs.pari [(85, 2), (89, 1), (93, 1), @@ -5678,7 +5678,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Use ``self.radical()`` for the product of the primes that divide self. - If self is 0, just returns 0. + If ``self`` is 0, just returns 0. EXAMPLES:: @@ -5710,8 +5710,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 2 sage: a.squarefree_part(bound=2**14) 2 - sage: a = 7^3 * next_prime(2^100)^2 * next_prime(2^200) # optional - sage.libs.pari - sage: a / a.squarefree_part(bound=1000) # optional - sage.libs.pari + sage: a = 7^3 * next_prime(2^100)^2 * next_prime(2^200) # optional - sage.libs.pari + sage: a / a.squarefree_part(bound=1000) # optional - sage.libs.pari 49 """ cdef Integer z @@ -5754,30 +5754,30 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_probable_prime(self): """ - Return the next probable prime after self, as determined by PARI. + Return the next probable prime after ``self``, as determined by PARI. EXAMPLES:: - sage: (-37).next_probable_prime() # optional - sage.libs.pari + sage: (-37).next_probable_prime() # optional - sage.libs.pari 2 - sage: (100).next_probable_prime() # optional - sage.libs.pari + sage: (100).next_probable_prime() # optional - sage.libs.pari 101 - sage: (2^512).next_probable_prime() # optional - sage.libs.pari + sage: (2^512).next_probable_prime() # optional - sage.libs.pari 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171 - sage: 0.next_probable_prime() # optional - sage.libs.pari + sage: 0.next_probable_prime() # optional - sage.libs.pari 2 - sage: 126.next_probable_prime() # optional - sage.libs.pari + sage: 126.next_probable_prime() # optional - sage.libs.pari 127 - sage: 144168.next_probable_prime() # optional - sage.libs.pari + sage: 144168.next_probable_prime() # optional - sage.libs.pari 144169 """ return Integer( self.__pari__().nextprime(True) ) def next_prime(self, proof=None): r""" - Return the next prime after self. + Return the next prime after ``self``. - This method calls the PARI ``nextprime`` function. + This method calls the PARI function :pari:`nextprime`. INPUT: @@ -5787,23 +5787,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 100.next_prime() # optional - sage.libs.pari + sage: 100.next_prime() # optional - sage.libs.pari 101 - sage: (10^50).next_prime() # optional - sage.libs.pari + sage: (10^50).next_prime() # optional - sage.libs.pari 100000000000000000000000000000000000000000000000151 Use ``proof=False``, which is way faster since it does not need a primality proof:: - sage: b = (2^1024).next_prime(proof=False) # optional - sage.libs.pari - sage: b - 2^1024 # optional - sage.libs.pari + sage: b = (2^1024).next_prime(proof=False) # optional - sage.libs.pari + sage: b - 2^1024 # optional - sage.libs.pari 643 :: - sage: Integer(0).next_prime() # optional - sage.libs.pari + sage: Integer(0).next_prime() # optional - sage.libs.pari 2 - sage: Integer(1001).next_prime() # optional - sage.libs.pari + sage: Integer(1001).next_prime() # optional - sage.libs.pari 1009 """ # Use PARI to compute the next *pseudo*-prime @@ -5814,9 +5814,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def previous_prime(self, proof=None): r""" - Returns the previous prime before self. + Returns the previous prime before ``self``. - This method calls the PARI ``precprime`` function. + This method calls the PARI function :pari:`precprime`. INPUT: @@ -5832,11 +5832,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 10.previous_prime() # optional - sage.libs.pari + sage: 10.previous_prime() # optional - sage.libs.pari 7 - sage: 7.previous_prime() # optional - sage.libs.pari + sage: 7.previous_prime() # optional - sage.libs.pari 5 - sage: 14376485.previous_prime() # optional - sage.libs.pari + sage: 14376485.previous_prime() # optional - sage.libs.pari 14376463 sage: 2.previous_prime() @@ -5847,8 +5847,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): An example using ``proof=False``, which is way faster since it does not need a primality proof:: - sage: b = (2^1024).previous_prime(proof=False) # optional - sage.libs.pari - sage: 2^1024 - b # optional - sage.libs.pari + sage: b = (2^1024).previous_prime(proof=False) # optional - sage.libs.pari + sage: 2^1024 - b # optional - sage.libs.pari 105 """ if mpz_cmp_ui(self.value, 2) <= 0: @@ -5862,7 +5862,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_prime_power(self, proof=None): r""" - Return the next prime power after self. + Return the next prime power after ``self``. INPUT: @@ -5874,7 +5874,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - The algorithm is naive. It computes the next power of 2 and go through + The algorithm is naive. It computes the next power of 2 and goes through the odd numbers calling :meth:`is_prime_power`. .. SEEALSO:: @@ -5888,23 +5888,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (-1).next_prime_power() 2 - sage: 2.next_prime_power() # optional - sage.libs.pari + sage: 2.next_prime_power() # optional - sage.libs.pari 3 - sage: 103.next_prime_power() # optional - sage.libs.pari + sage: 103.next_prime_power() # optional - sage.libs.pari 107 - sage: 107.next_prime_power() # optional - sage.libs.pari + sage: 107.next_prime_power() # optional - sage.libs.pari 109 - sage: 2044.next_prime_power() # optional - sage.libs.pari + sage: 2044.next_prime_power() # optional - sage.libs.pari 2048 TESTS:: - sage: [(2**k-1).next_prime_power() for k in range(1,10)] # optional - sage.libs.pari + sage: [(2**k - 1).next_prime_power() for k in range(1,10)] # optional - sage.libs.pari [2, 4, 8, 16, 32, 64, 128, 256, 512] - sage: [(2**k).next_prime_power() for k in range(10)] # optional - sage.libs.pari + sage: [(2**k).next_prime_power() for k in range(10)] # optional - sage.libs.pari [2, 3, 5, 9, 17, 37, 67, 131, 257, 521] - sage: for _ in range(10): # optional - sage.libs.pari + sage: for _ in range(10): # optional - sage.libs.pari ....: n = ZZ.random_element(2**256).next_prime_power() ....: m = n.next_prime_power().previous_prime_power() ....: assert m == n, "problem with n = {}".format(n) @@ -5928,7 +5928,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def previous_prime_power(self, proof=None): r""" - Return the previous prime power before self. + Return the previous prime power before ``self``. INPUT: @@ -5940,7 +5940,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - The algorithm is naive. It computes the previous power of 2 and go + The algorithm is naive. It computes the previous power of 2 and goes through the odd numbers calling the method :meth:`is_prime_power`. .. SEEALSO:: @@ -5952,13 +5952,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3.previous_prime_power() # optional - sage.libs.pari + sage: 3.previous_prime_power() # optional - sage.libs.pari 2 - sage: 103.previous_prime_power() # optional - sage.libs.pari + sage: 103.previous_prime_power() # optional - sage.libs.pari 101 - sage: 107.previous_prime_power() # optional - sage.libs.pari + sage: 107.previous_prime_power() # optional - sage.libs.pari 103 - sage: 2044.previous_prime_power() # optional - sage.libs.pari + sage: 2044.previous_prime_power() # optional - sage.libs.pari 2039 sage: 2.previous_prime_power() @@ -5968,12 +5968,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: [(2**k+1).previous_prime_power() for k in range(1,10)] # optional - sage.libs.pari + sage: [(2**k + 1).previous_prime_power() for k in range(1,10)] # optional - sage.libs.pari [2, 4, 8, 16, 32, 64, 128, 256, 512] - sage: [(2**k).previous_prime_power() for k in range(2, 10)] # optional - sage.libs.pari + sage: [(2**k).previous_prime_power() for k in range(2, 10)] # optional - sage.libs.pari [3, 7, 13, 31, 61, 127, 251, 509] - sage: for _ in range(10): # optional - sage.libs.pari + sage: for _ in range(10): # optional - sage.libs.pari ....: n = ZZ.random_element(3,2**256).previous_prime_power() ....: m = n.previous_prime_power().next_prime_power() ....: assert m == n, "problem with n = {}".format(n) @@ -5999,7 +5999,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def additive_order(self): """ - Return the additive order of self. + Return the additive order of ``self``. EXAMPLES:: @@ -6015,7 +6015,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def multiplicative_order(self): r""" - Return the multiplicative order of self. + Return the multiplicative order of ``self``. EXAMPLES:: @@ -6042,11 +6042,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 100.is_squarefree() # optional - sage.libs.pari + sage: 100.is_squarefree() # optional - sage.libs.pari False - sage: 102.is_squarefree() # optional - sage.libs.pari + sage: 102.is_squarefree() # optional - sage.libs.pari True - sage: 0.is_squarefree() # optional - sage.libs.pari + sage: 0.is_squarefree() # optional - sage.libs.pari False """ return self.__pari__().issquarefree() @@ -6125,16 +6125,16 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: n = 9390823 - sage: m = n.__pari__(); m # optional - sage.libs.pari + sage: m = n.__pari__(); m # optional - sage.libs.pari 9390823 - sage: type(m) # optional - sage.libs.pari + sage: type(m) # optional - sage.libs.pari TESTS:: sage: n = 10^10000000 - sage: m = n.__pari__() # crash from trac 875 # optional - sage.libs.pari - sage: m % 1234567 # optional - sage.libs.pari + sage: m = n.__pari__() # crash from trac 875 # optional - sage.libs.pari + sage: m % 1234567 # optional - sage.libs.pari 1041334 """ @@ -6164,19 +6164,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1, 2, 3]) + sage: import numpy # optional - numpy + sage: numpy.array([1, 2, 3]) # optional - numpy array([1, 2, 3]) - sage: numpy.array([1, 2, 3]).dtype + sage: numpy.array([1, 2, 3]).dtype # optional - numpy dtype('int32') # 32-bit dtype('int64') # 64-bit - sage: numpy.array(2**40).dtype + sage: numpy.array(2**40).dtype # optional - numpy dtype('int64') - sage: numpy.array(2**400).dtype + sage: numpy.array(2**400).dtype # optional - numpy dtype('O') - sage: numpy.array([1,2,3,0.1]).dtype + sage: numpy.array([1,2,3,0.1]).dtype # optional - numpy dtype('float64') """ if mpz_fits_slong_p(self.value): @@ -6258,9 +6258,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def sqrtrem(self): r""" - Return (s, r) where s is the integer square root of self and + Return (s, r) where s is the integer square root of ``self`` and r is the remainder such that `\text{self} = s^2 + r`. - Raises ``ValueError`` if self is negative. + Raises ``ValueError`` if ``self`` is negative. EXAMPLES:: @@ -6288,8 +6288,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def isqrt(self): r""" - Returns the integer floor of the square root of self, or raises an - ``ValueError`` if self is negative. + Returns the integer floor of the square root of ``self``, or raises an + ``ValueError`` if ``self`` is negative. EXAMPLES:: @@ -6331,7 +6331,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): is not None. - ``all`` - bool (default: False); if True, return all - square roots of self (a list of length 0, 1 or 2). + square roots of ``self`` (a list of length 0, 1 or 2). EXAMPLES:: @@ -6339,13 +6339,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 12 sage: sqrt(Integer(144)) 12 - sage: Integer(102).sqrt() # optional - sage.symbolic + sage: Integer(102).sqrt() # optional - sage.symbolic sqrt(102) :: sage: n = 2 - sage: n.sqrt(all=True) # optional - sage.symbolic + sage: n.sqrt(all=True) # optional - sage.symbolic [sqrt(2), -sqrt(2)] sage: n.sqrt(prec=10) 1.4 @@ -6368,7 +6368,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: type(5.sqrt()) # optional - sage.symbolic + sage: type(5.sqrt()) # optional - sage.symbolic sage: type(5.sqrt(prec=53)) @@ -6768,7 +6768,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def __invert__(self): """ - Return the multiplicative inverse of self, as a rational number. + Return the multiplicative inverse of ``self``, as a rational number. EXAMPLES:: @@ -6794,8 +6794,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def inverse_of_unit(self): """ - Return inverse of self if self is a unit in the integers, i.e., - self is -1 or 1. Otherwise, raise a ZeroDivisionError. + Return inverse of ``self`` if ``self`` is a unit in the integers, i.e., + ``self`` is -1 or 1. Otherwise, raise a :class:`ZeroDivisionError`. EXAMPLES:: @@ -6819,7 +6819,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def inverse_mod(self, n): r""" - Return the inverse of self modulo `n`, if this inverse exists. + Return the inverse of ``self`` modulo `n`, if this inverse exists. Otherwise, raises a ``ZeroDivisionError`` exception. @@ -6994,7 +6994,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: 10.binomial(2) 45 - sage: 10.binomial(2, algorithm='pari') # optional - sage.libs.pari + sage: 10.binomial(2, algorithm='pari') # optional - sage.libs.pari 45 sage: 10.binomial(-2) 0 @@ -7007,7 +7007,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (2**256).binomial(2**256) 1 - sage: (2**256).binomial(2**256-1) + sage: (2**256).binomial(2**256 - 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936 sage: (2**256).binomial(2**128) Traceback (most recent call last): @@ -7036,7 +7036,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): check for reliable interrupting, see :trac:`18919`:: sage: from cysignals import AlarmInterrupt - sage: for i in [1..10]: # long time (5s) # optional - sage.libs.pari + sage: for i in [1..10]: # long time (5s) # optional - sage.libs.pari ....: try: ....: alarm(i/11) ....: (2^100).binomial(2^22, algorithm='pari') @@ -7287,7 +7287,7 @@ def GCD_list(v): @cython.binding(True) def make_integer(s): """ - Create a Sage integer from the base-32 Python *string* s. This is + Create a Sage integer from the base-32 Python *string* ``s``. This is used in unpickling integers. EXAMPLES:: diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 09b239a7dea..8a307b3988c 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -126,8 +126,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): False sage: Z.category() Join of Category of euclidean domains - and Category of infinite enumerated sets - and Category of metric spaces + and Category of infinite enumerated sets + and Category of metric spaces sage: Z(2^(2^5) + 1) 4294967297 @@ -151,9 +151,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): The lists are interpreted in little-endian order, so that entry ``i`` of the list is the coefficient of ``base^i``:: - sage: Z([4,1,7],base=100) + sage: Z([4,1,7], base=100) 70104 - sage: Z([4,1,7],base=10) + sage: Z([4,1,7], base=10) 714 sage: Z([3, 7], 10) 73 @@ -166,13 +166,13 @@ cdef class IntegerRing_class(PrincipalIdealDomain): ``z`` represent numbers 10 to 36. Letter case does not matter. :: - sage: Z("sage",base=32) + sage: Z("sage", base=32) 928270 - sage: Z("SAGE",base=32) + sage: Z("SAGE", base=32) 928270 - sage: Z("Sage",base=32) + sage: Z("Sage", base=32) 928270 - sage: Z([14, 16, 10, 28],base=32) + sage: Z([14, 16, 10, 28], base=32) 928270 sage: 14 + 16*32 + 10*32^2 + 28*32^3 928270 @@ -248,23 +248,23 @@ cdef class IntegerRing_class(PrincipalIdealDomain): 17 sage: Z(Mod(19,23)) 19 - sage: Z(2 + 3*5 + O(5^3)) + sage: Z(2 + 3*5 + O(5^3)) # optional - sage.rings.padics 17 Arbitrary numeric bases are supported; strings or list of integers are used to provide the digits (more details in :class:`IntegerRing_class`):: - sage: Z("sage",base=32) + sage: Z("sage", base=32) 928270 - sage: Z([14, 16, 10, 28],base=32) + sage: Z([14, 16, 10, 28], base=32) 928270 The :meth:`digits<~sage.rings.integer.Integer.digits>` method allows you to get the list of digits of an integer in a different basis (note that the digits are returned in little-endian order):: - sage: b = Z([4,1,7],base=100) + sage: b = Z([4,1,7], base=100) sage: b 70104 sage: b.digits(base=71) @@ -397,19 +397,19 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ[sqrt(2), sqrt(3)] + sage: ZZ[sqrt(2), sqrt(3)] # optional - sage.rings.number_field sage.symbolic Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field sage: ZZ['x'] Univariate Polynomial Ring in x over Integer Ring sage: ZZ['x,y'] Multivariate Polynomial Ring in x, y over Integer Ring - sage: R = ZZ[sqrt(5) + 1]; R + sage: R = ZZ[sqrt(5) + 1]; R # optional - sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^2 - 2*x - 4 with a = 3.236067977499790? - sage: R.is_maximal() + sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic False - sage: R = ZZ[(1+sqrt(5))/2]; R + sage: R = ZZ[(1 + sqrt(5))/2]; R # optional - sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^2 - x - 1 with a = 1.618033988749895? - sage: R.is_maximal() + sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic True """ if x in self: @@ -433,23 +433,25 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - sage: ZZ.range(-5,5) + sage: ZZ.range(-5, 5) [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4] - sage: ZZ.range(0,50,5) + sage: ZZ.range(0, 50, 5) [0, 5, 10, 15, 20, 25, 30, 35, 40, 45] - sage: ZZ.range(0,50,-5) + sage: ZZ.range(0, 50, -5) [] - sage: ZZ.range(50,0,-5) + sage: ZZ.range(50, 0, -5) [50, 45, 40, 35, 30, 25, 20, 15, 10, 5] - sage: ZZ.range(50,0,5) + sage: ZZ.range(50, 0, 5) [] - sage: ZZ.range(50,-1,-5) + sage: ZZ.range(50, -1, -5) [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0] It uses different code if the step doesn't fit in a long:: - sage: ZZ.range(0,2^83,2^80) - [0, 1208925819614629174706176, 2417851639229258349412352, 3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880, 7253554917687775048237056, 8462480737302404222943232] + sage: ZZ.range(0, 2^83, 2^80) + [0, 1208925819614629174706176, 2417851639229258349412352, + 3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880, + 7253554917687775048237056, 8462480737302404222943232] Make sure :trac:`8818` is fixed:: @@ -532,7 +534,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.coerce(int(5)) # indirect doctest 5 - sage: ZZ.coerce(GF(7)(2)) + sage: ZZ.coerce(GF(7)(2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field of size 7 to Integer Ring @@ -554,14 +556,14 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Coercions are available from numpy integer types:: - sage: import numpy - sage: ZZ.coerce(numpy.int8('1')) + sage: import numpy # optional - numpy + sage: ZZ.coerce(numpy.int8('1')) # optional - numpy 1 - sage: ZZ.coerce(numpy.int32('32')) + sage: ZZ.coerce(numpy.int32('32')) # optional - numpy 32 - sage: ZZ.coerce(numpy.int64('-12')) + sage: ZZ.coerce(numpy.int64('-12')) # optional - numpy -12 - sage: ZZ.coerce(numpy.uint64('11')) + sage: ZZ.coerce(numpy.uint64('11')) # optional - numpy 11 TESTS:: @@ -666,7 +668,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): ....: counter += 1 ....: dic[ZZ.random_element(*args, **kwds)] += 1 - sage: prob = lambda x : 1/5 + sage: def prob(x): + ....: return 1/5 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(distribution="uniform") @@ -690,7 +693,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: -10 <= ZZ.random_element(-10, 10) < 10 True - sage: prob = lambda x : 1/20 + sage: def prob(x): + ....: return 1/20 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(-10, 10) @@ -699,7 +703,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: 0 <= ZZ.random_element(5) < 5 True - sage: prob = lambda x : 1/5 + sage: def prob(x): + ....: return 1/5 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(5) @@ -831,7 +836,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): True sage: ZZ._is_valid_homomorphism_(ZZ,[2]) False - sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8),[ZZ.quotient_ring(8)(1)]) + sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8), [ZZ.quotient_ring(8)(1)]) True """ if base_map is None: @@ -920,11 +925,11 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ.extension(x^2-5, 'a') + sage: ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 - sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') - Relative Order in Number Field in a with defining polynomial - x^2 + 1 over its base field + sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') # optional - sage.rings.number_field + Relative Order in Number Field in a + with defining polynomial x^2 + 1 over its base field """ from sage.rings.number_field.order import EquationOrder return EquationOrder(poly, names=names, **kwds) @@ -976,40 +981,40 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: F = ZZ.residue_field(61); F + sage: F = ZZ.residue_field(61); F # optional - sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi + sage: pi = F.reduction_map(); pi # optional - sage.libs.pari Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) + sage: pi(123/234) # optional - sage.libs.pari 6 - sage: pi(1/61) + sage: pi(1/61) # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift + sage: lift = F.lift_map(); lift # optional - sage.libs.pari Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) + sage: lift(F(12345/67890)) # optional - sage.libs.pari 33 - sage: (12345/67890) % 61 + sage: (12345/67890) % 61 # optional - sage.libs.pari 33 Construction can be from a prime ideal instead of a prime:: - sage: ZZ.residue_field(ZZ.ideal(97)) + sage: ZZ.residue_field(ZZ.ideal(97)) # optional - sage.libs.pari Residue field of Integers modulo 97 TESTS:: - sage: ZZ.residue_field(ZZ.ideal(96)) + sage: ZZ.residue_field(ZZ.ideal(96)) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Principal ideal (96) of Integer Ring is not prime - sage: ZZ.residue_field(96) + sage: ZZ.residue_field(96) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: 96 is not prime @@ -1160,7 +1165,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.completion(infinity, 53) Integer Ring - sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) + sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics 5-adic Ring with capped relative precision 15 """ if p == sage.rings.infinity.Infinity: @@ -1275,41 +1280,41 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] sage: p *= (1 + x^3458645 - 76*x^3435423343 + x^45346567867756556) - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(1, 23), (-1, 23), (100, 1), (-5445, 5)] sage: p *= x^156468451540687043504386074354036574634735074 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(0, 156468451540687043504386074354036574634735074), (1, 23), (-1, 23), (100, 1), (-5445, 5)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari [0, 1, -1, 100, -5445] sage: R. = PolynomialRing(ZZ, sparse=False) sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari [100, -5445, 1, -1] - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") + sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: unknown algorithm 'foobar' sage: p = x^20 * p - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari [(0, 20), (100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari [(100, 1), (-5445, 5), (0, 20), (1, 23), (-1, 23)] """ deg = p.degree() @@ -1462,7 +1467,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: gap(ZZ) # indirect doctest + sage: gap(ZZ) # indirect doctest # optional - sage.libs.gap Integers """ return 'Integers' @@ -1495,7 +1500,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: macaulay2(ZZ) #optional - macaulay2 + sage: macaulay2(ZZ) # optional - macaulay2 ZZ """ return "ZZ" @@ -1518,7 +1523,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ._sympy_() + sage: ZZ._sympy_() # optional - sympy Integers """ from sympy import Integers @@ -1548,9 +1553,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: v = ZZ.valuation(3); v + sage: v = ZZ.valuation(3); v # optional - sage.rings.padics 3-adic valuation - sage: v(3) + sage: v(3) # optional - sage.rings.padics 1 .. SEEALSO:: diff --git a/src/sage/rings/invariants/invariant_theory.py b/src/sage/rings/invariants/invariant_theory.py index 2f6850f97cc..564af30855d 100644 --- a/src/sage/rings/invariants/invariant_theory.py +++ b/src/sage/rings/invariants/invariant_theory.py @@ -140,15 +140,15 @@ def _guess_variables(polynomial, *args): sage: from sage.rings.invariants.invariant_theory import _guess_variables sage: R. = QQ[] - sage: _guess_variables(x^2+y^2) + sage: _guess_variables(x^2 + y^2) (x, y) sage: _guess_variables([x^2, y^2]) (x, y) - sage: _guess_variables(x^2+y^2, x) + sage: _guess_variables(x^2 + y^2, x) (x,) - sage: _guess_variables(x^2+y^2, x,y) + sage: _guess_variables(x^2 + y^2, x, y) (x, y) - sage: _guess_variables(x^2+y^2, [x,y]) + sage: _guess_variables(x^2 + y^2, [x,y]) (x, y) """ if isinstance(polynomial, (list, tuple)): @@ -177,7 +177,7 @@ def transvectant(f, g, h=1, scale='default'): INPUT: - - ``f,g`` -- two homogeneous binary forms in the same polynomial ring. + - ``f``, ``g`` -- two homogeneous binary forms in the same polynomial ring. - ``h`` -- the order of the transvectant. If it is not specified, the first transvectant is returned. @@ -214,14 +214,14 @@ def transvectant(f, g, h=1, scale='default'): factor will not be invertible in that case. The scale argument ``'none'`` can be used to compute the transvectant in this case:: - sage: R. = GF(5)[] - sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5 - sage: f = AlgebraicForm(2, 5, p, x0, x1) - sage: transvectant(f, f, 4) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = AlgebraicForm(2, 5, a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 # optional - sage.rings.finite_rings + ....: + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5, x0, x1) + sage: transvectant(f, f, 4) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError - sage: transvectant(f, f, 4, scale='none') + sage: transvectant(f, f, 4, scale='none') # optional - sage.rings.finite_rings Binary quadratic given by -a3^2*x0^2 + a2*a4*x0^2 + a2*a3*x0*x1 - a1*a4*x0*x1 - a2^2*x1^2 + a1*a3*x1^2 @@ -230,8 +230,8 @@ def transvectant(f, g, h=1, scale='default'): it to the scaled version:: sage: R. = QQ[] - sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5 - sage: f = AlgebraicForm(2, 5, p, x0, x1) + sage: f = AlgebraicForm(2, 5, a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + ....: + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5, x0, x1) sage: transvectant(f, f, 4) Binary quadratic given by 3/50*a3^2*x0^2 - 4/25*a2*a4*x0^2 + 2/5*a1*a5*x0^2 + 1/25*a2*a3*x0*x1 - 6/25*a1*a4*x0*x1 + 2*a0*a5*x0*x1 @@ -247,14 +247,14 @@ def transvectant(f, g, h=1, scale='default'): one variable:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+x^3+2*x^2+y^5, x) + sage: quintic = invariant_theory.binary_quintic(x^5 + x^3 + 2*x^2 + y^5, x) sage: transvectant(quintic, quintic, 2) Traceback (most recent call last): ... ValueError: polynomial is not homogeneous sage: R. = QQ[] sage: S. = R[] - sage: quintic = invariant_theory.binary_quintic(x^5+x^3+2*x^2+y^5, x) + sage: quintic = invariant_theory.binary_quintic(x^5 + x^3 + 2*x^2 + y^5, x) sage: transvectant(quintic, quintic, 2) Binary sextic given by 1/5*x^6 + 6/5*x^5*h - 3/25*x^4*h^2 + (50*y^5 - 8)/25*x^3*h^3 - 12/25*x^2*h^4 + (3*y^5)/5*x*h^5 @@ -385,12 +385,12 @@ def ring(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y]) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4 + t*x^2*y^2, [x,y]) sage: quartic.ring() Multivariate Polynomial Ring in x, y, t over Rational Field sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+1+t*x^2, [x]) + sage: quartic = invariant_theory.binary_quartic(x^4 + 1 + t*x^2, [x]) sage: quartic.ring() Multivariate Polynomial Ring in x, y, t over Rational Field """ @@ -408,12 +408,12 @@ def variables(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y]) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4 + t*x^2*y^2, [x,y]) sage: quartic.variables() (x, y) sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+1+t*x^2, [x]) + sage: quartic = invariant_theory.binary_quartic(x^4 + 1 + t*x^2, [x]) sage: quartic.variables() (x, None) """ @@ -431,14 +431,14 @@ def is_homogeneous(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y]) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4 + t*x^2*y^2, [x,y]) sage: quartic.is_homogeneous() True sage: quartic.form() x^2*y^2*t + x^4 + y^4 sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+1+t*x^2, [x]) + sage: quartic = invariant_theory.binary_quartic(x^4 + 1 + t*x^2, [x]) sage: quartic.is_homogeneous() False sage: quartic.form() @@ -505,7 +505,7 @@ class AlgebraicForm(FormsBase): ... ValueError: polynomial is of the wrong degree - sage: AlgebraicForm(2, 2, x^2+y, [x,y]).variables() + sage: AlgebraicForm(2, 2, x^2 + y, [x,y]).variables() Traceback (most recent call last): ... ValueError: polynomial is not homogeneous @@ -650,7 +650,7 @@ def _repr_(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic._repr_() 'Binary quartic with coefficients (1, 0, 0, 0, 1)' @@ -694,7 +694,7 @@ def form(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic.form() x^4 + y^4 sage: quartic.polynomial() @@ -792,7 +792,7 @@ def _extract_coefficients(self, monomials): (a30, a03, a00, a21, a20, a12, a02, a10, a01, a11) sage: T. = QQ[] - sage: univariate = AlgebraicForm(2, 3, t^3+2*t^2+3*t+4) + sage: univariate = AlgebraicForm(2, 3, t^3 + 2*t^2 + 3*t + 4) sage: m = [t^3, 1, t, t^2] sage: univariate._extract_coefficients(m) (1, 4, 3, 2) @@ -806,7 +806,7 @@ def _extract_coefficients(self, monomials): Check for :trac:`30035`:: sage: R. = QQ[] - sage: f = 3*a**3+b**3+a*b*c + sage: f = 3*a**3 + b**3 + a*b*c sage: T = invariant_theory.ternary_cubic(f) sage: T.S_invariant().parent() Rational Field @@ -905,9 +905,9 @@ def transformed(self, g): sage: R. = QQ[] sage: cubic = invariant_theory.ternary_cubic(x^3 + 2*y^3 + 3*z^3 + 4*x*y*z) - sage: cubic.transformed({x:y, y:z, z:x}).form() + sage: cubic.transformed({x: y, y: z, z: x}).form() 3*x^3 + y^3 + 4*x*y*z + 2*z^3 - sage: cyc = matrix([[0,1,0],[0,0,1],[1,0,0]]) + sage: cyc = matrix([[0,1,0], [0,0,1], [1,0,0]]) sage: cubic.transformed(cyc) == cubic.transformed({x:y, y:z, z:x}) True sage: g = matrix(QQ, [[1, 0, 0], [-1, 1, -3], [-5, -5, 16]]) @@ -973,11 +973,11 @@ def __init__(self, n, d, polynomial, *args): sage: R. = QQ[] sage: from sage.rings.invariants.invariant_theory import QuadraticForm - sage: form = QuadraticForm(2, 2, x^2+2*y^2+3*x*y) + sage: form = QuadraticForm(2, 2, x^2 + 2*y^2 + 3*x*y) sage: form Binary quadratic with coefficients (1, 2, 3) sage: form._check_covariant('discriminant', invariant=True) - sage: QuadraticForm(3, 2, x^2+y^2) + sage: QuadraticForm(3, 2, x^2 + y^2) Ternary quadratic with coefficients (1, 1, 0, 0, 0, 0) """ assert d == 2 @@ -1024,11 +1024,11 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = invariant_theory.quadratic_form(x^2+y^2) + sage: quadratic = invariant_theory.quadratic_form(x^2 + y^2) sage: quadratic.monomials() (x^2, y^2, x*y) - sage: quadratic = invariant_theory.inhomogeneous_quadratic_form(x^2+y^2) + sage: quadratic = invariant_theory.inhomogeneous_quadratic_form(x^2 + y^2) sage: quadratic.monomials() (x^2, y^2, 1, x*y, x, y) """ @@ -1158,7 +1158,7 @@ def discriminant(self): EXAMPLES:: sage: R. = QQ[] - sage: p = a*x^2+b*x*y+c*y^2 + sage: p = a*x^2 + b*x*y + c*y^2 sage: quadratic = invariant_theory.quadratic_form(p, x,y) sage: quadratic.discriminant() b^2 - 4*a*c @@ -1291,7 +1291,7 @@ def as_QuadraticForm(self): EXAMPLES:: sage: R. = QQ[] - sage: p = x^2+y^2+z^2+2*x*y+3*x*z + sage: p = x^2 + y^2 + z^2 + 2*x*y + 3*x*z sage: quadratic = invariant_theory.ternary_quadratic(p) sage: matrix(quadratic) [ 1 1 3/2] @@ -1344,7 +1344,7 @@ def __init__(self, n, d, polynomial, *args): sage: R. = QQ[] sage: from sage.rings.invariants.invariant_theory import BinaryQuartic - sage: BinaryQuartic(2, 4, x^4+y^4) + sage: BinaryQuartic(2, 4, x^4 + y^4) Binary quartic with coefficients (1, 0, 0, 0, 1) """ assert n == 2 and d == 4 @@ -1365,7 +1365,7 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic.monomials() (y^4, x*y^3, x^2*y^2, x^3*y, x^4) """ @@ -1456,7 +1456,7 @@ def EisensteinD(self): EXAMPLES:: sage: R. = QQ[] - sage: f = a0*x1^4+4*a1*x0*x1^3+6*a2*x0^2*x1^2+4*a3*x0^3*x1+a4*x0^4 + sage: f = a0*x1^4 + 4*a1*x0*x1^3 + 6*a2*x0^2*x1^2 + 4*a3*x0^3*x1 + a4*x0^4 sage: inv = invariant_theory.binary_quartic(f, x0, x1) sage: inv.EisensteinD() 3*a2^2 - 4*a1*a3 + a0*a4 @@ -1485,7 +1485,7 @@ def EisensteinE(self): EXAMPLES:: sage: R. = QQ[] - sage: f = a0*x1^4+4*a1*x0*x1^3+6*a2*x0^2*x1^2+4*a3*x0^3*x1+a4*x0^4 + sage: f = a0*x1^4 + 4*a1*x0*x1^3 + 6*a2*x0^2*x1^2 + 4*a3*x0^3*x1 + a4*x0^4 sage: inv = invariant_theory.binary_quartic(f, x0, x1) sage: inv.EisensteinE() a2^3 - 2*a1*a2*a3 + a0*a3^2 + a1^2*a4 - a0*a2*a4 @@ -1517,7 +1517,7 @@ def g_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: p = a0*x^4+4*a1*x^3*y+6*a2*x^2*y^2+4*a3*x*y^3+a4*y^4 + sage: p = a0*x^4 + 4*a1*x^3*y + 6*a2*x^2*y^2 + 4*a3*x*y^3 + a4*y^4 sage: inv = invariant_theory.binary_quartic(p, x, y) sage: g = inv.g_covariant(); g a1^2*x^4 - a0*a2*x^4 + 2*a1*a2*x^3*y - 2*a0*a3*x^3*y + 3*a2^2*x^2*y^2 @@ -1568,7 +1568,7 @@ def h_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: p = a0*x^4+4*a1*x^3*y+6*a2*x^2*y^2+4*a3*x*y^3+a4*y^4 + sage: p = a0*x^4 + 4*a1*x^3*y + 6*a2*x^2*y^2 + 4*a3*x*y^3 + a4*y^4 sage: inv = invariant_theory.binary_quartic(p, x, y) sage: h = inv.h_covariant(); h -2*a1^3*x^6 + 3*a0*a1*a2*x^6 - a0^2*a3*x^6 - 6*a1^2*a2*x^5*y + 9*a0*a2^2*x^5*y @@ -1587,7 +1587,7 @@ def h_covariant(self): + 2*a1*a3*a4*x + a0*a4^2*x + 2*a3^3 - 3*a2*a3*a4 + a1*a4^2 sage: g = inv.g_covariant() - sage: h == 1/8 * (p.derivative(x)*g.derivative(y)-p.derivative(y)*g.derivative(x)) + sage: h == 1/8 * (p.derivative(x)*g.derivative(y) - p.derivative(y)*g.derivative(x)) True """ a0, a1, a2, a3, a4 = self.scaled_coeffs() @@ -1716,7 +1716,7 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+y^5) + sage: quintic = invariant_theory.binary_quintic(x^5 + y^5) sage: quintic.monomials() (y^5, x*y^4, x^2*y^3, x^3*y^2, x^4*y, x^5) """ @@ -2584,7 +2584,7 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = invariant_theory.ternary_quadratic(x^2+y*z) + sage: quadratic = invariant_theory.ternary_quadratic(x^2 + y*z) sage: quadratic.monomials() (x^2, y^2, z^2, x*y, x*z, y*z) """ @@ -2668,8 +2668,8 @@ def covariant_conic(self, other): EXAMPLES:: sage: ring. = QQ[] - sage: Q = invariant_theory.ternary_quadratic(x^2+y^2+z^2) - sage: R = invariant_theory.ternary_quadratic(x*y+x*z+y*z) + sage: Q = invariant_theory.ternary_quadratic(x^2 + y^2 + z^2) + sage: R = invariant_theory.ternary_quadratic(x*y + x*z + y*z) sage: Q.covariant_conic(R) -x*y - x*z - y*z sage: R.covariant_conic(Q) @@ -2716,7 +2716,7 @@ class TernaryCubic(AlgebraicForm): TESTS:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic Ternary cubic with coefficients (1, 1, 1, 0, 0, 0, 0, 0, 0, 0) sage: TestSuite(cubic).run() @@ -2850,7 +2850,7 @@ def S_invariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^2*y+y^3+z^3+x*y*z) + sage: cubic = invariant_theory.ternary_cubic(x^2*y + y^3 + z^3 + x*y*z) sage: cubic.S_invariant() -1/1296 """ @@ -2871,12 +2871,12 @@ def T_invariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.T_invariant() 1 sage: R. = GF(7)[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3+t*x*y*z, [x,y,z]) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3 + t*x*y*z, [x,y,z]) sage: cubic.T_invariant() -t^6 - t^3 + 1 """ @@ -2972,12 +2972,12 @@ def Hessian(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.Hessian() x*y*z sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+1) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + 1) sage: cubic.Hessian() x*y """ @@ -3003,12 +3003,12 @@ def Theta_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.Theta_covariant() -x^3*y^3 - x^3*z^3 - y^3*z^3 sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+1) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + 1) sage: cubic.Theta_covariant() -x^3*y^3 - x^3 - y^3 @@ -3036,12 +3036,12 @@ def J_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.J_covariant() x^6*y^3 - x^3*y^6 - x^6*z^3 + y^6*z^3 + x^3*z^6 - y^3*z^6 sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+1) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + 1) sage: cubic.J_covariant() x^6*y^3 - x^3*y^6 - x^6 + y^6 + x^3 - y^3 """ @@ -3256,7 +3256,7 @@ def homogenized(self, var='h'): EXAMPLES:: sage: R. = QQ[] - sage: q = invariant_theory.quaternary_biquadratic(x^2+1, y^2+1, [x,y,z]) + sage: q = invariant_theory.quaternary_biquadratic(x^2 + 1, y^2 + 1, [x,y,z]) sage: q Joint quaternary quadratic with coefficients (1, 0, 0, 1, 0, 0, 0, 0, 0, 0) and quaternary quadratic with coefficients (0, 1, 0, 1, 0, 0, 0, 0, 0, 0) @@ -3394,7 +3394,8 @@ class TwoTernaryQuadratics(TwoAlgebraicForms): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.ternary_biquadratic(x^2+y^2+z^2, x*y+y*z+x*z, [x, y, z]) + sage: inv = invariant_theory.ternary_biquadratic(x^2 + y^2 + z^2, + ....: x*y + y*z + x*z, [x, y, z]) sage: inv Joint ternary quadratic with coefficients (1, 1, 1, 0, 0, 0) and ternary quadratic with coefficients (0, 0, 0, 1, 1, 1) @@ -3451,7 +3452,7 @@ def _Theta_helper(self, scaled_coeffs_1, scaled_coeffs_2): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.ternary_biquadratic(x^2 + y*z, x*y+z^2, x, y, z) + sage: inv = invariant_theory.ternary_biquadratic(x^2 + y*z, x*y + z^2, x, y, z) sage: inv._Theta_helper([1]*6, [2]*6) 0 """ @@ -3607,7 +3608,7 @@ class TwoQuaternaryQuadratics(TwoAlgebraicForms): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.quaternary_biquadratic(w^2+x^2, y^2+z^2, w, x, y, z) + sage: inv = invariant_theory.quaternary_biquadratic(w^2 + x^2, y^2 + z^2, w, x, y, z) sage: inv Joint quaternary quadratic with coefficients (1, 1, 0, 0, 0, 0, 0, 0, 0, 0) and quaternary quadratic with coefficients (0, 0, 1, 1, 0, 0, 0, 0, 0, 0) @@ -3670,7 +3671,7 @@ def _Theta_helper(self, scaled_coeffs_1, scaled_coeffs_2): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.quaternary_biquadratic(w^2+x^2, y^2+z^2, w, x, y, z) + sage: inv = invariant_theory.quaternary_biquadratic(w^2 + x^2, y^2 + z^2, w, x, y, z) sage: inv._Theta_helper([1]*10, [2]*10) 0 """ @@ -4022,10 +4023,10 @@ class InvariantTheoryFactory(): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: invariant_theory.ternary_cubic(x^3 + y^3 + z^3) Ternary cubic with coefficients (1, 1, 1, 0, 0, 0, 0, 0, 0, 0) - sage: invariant_theory.ternary_cubic(x^3+y^3+z^3).J_covariant() + sage: invariant_theory.ternary_cubic(x^3 + y^3 + z^3).J_covariant() x^6*y^3 - x^3*y^6 - x^6*z^3 + y^6*z^3 + x^3*z^6 - y^3*z^6 """ @@ -4059,7 +4060,7 @@ def quadratic_form(self, polynomial, *args): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = x^2+y^2+z^2 + sage: quadratic = x^2 + y^2 + z^2 sage: inv = invariant_theory.quadratic_form(quadratic) sage: type(inv) @@ -4068,7 +4069,7 @@ def quadratic_form(self, polynomial, *args): you need to specify the polynomial variables:: sage: R. = QQ[] - sage: quadratic = a*x^2+b*y^2+z^2+2*y*z + sage: quadratic = a*x^2 + b*y^2 + z^2 + 2*y*z sage: invariant_theory.quadratic_form(quadratic, x,y,z) Ternary quadratic with coefficients (a, b, 1, 0, 0, 2) sage: invariant_theory.quadratic_form(quadratic, [x,y,z]) # alternate syntax @@ -4103,11 +4104,11 @@ def inhomogeneous_quadratic_form(self, polynomial, *args): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = x^2+2*y^2+3*x*y+4*x+5*y+6 + sage: quadratic = x^2 + 2*y^2 + 3*x*y + 4*x + 5*y + 6 sage: inv3 = invariant_theory.inhomogeneous_quadratic_form(quadratic) sage: type(inv3) - sage: inv4 = invariant_theory.inhomogeneous_quadratic_form(x^2+y^2+z^2) + sage: inv4 = invariant_theory.inhomogeneous_quadratic_form(x^2 + y^2 + z^2) sage: type(inv4) """ @@ -4136,7 +4137,7 @@ def binary_quadratic(self, quadratic, *args): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.binary_quadratic(x^2+y^2) + sage: invariant_theory.binary_quadratic(x^2 + y^2) Binary quadratic with coefficients (1, 1, 0) sage: T. = QQ[] @@ -4164,11 +4165,11 @@ def quaternary_quadratic(self, quadratic, *args): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.quaternary_quadratic(w^2+x^2+y^2+z^2) + sage: invariant_theory.quaternary_quadratic(w^2 + x^2 + y^2 + z^2) Quaternary quadratic with coefficients (1, 1, 1, 1, 0, 0, 0, 0, 0, 0) sage: R. = QQ[] - sage: invariant_theory.quaternary_quadratic(1+x^2+y^2+z^2) + sage: invariant_theory.quaternary_quadratic(1 + x^2 + y^2 + z^2) Quaternary quadratic with coefficients (1, 1, 1, 1, 0, 0, 0, 0, 0, 0) """ return QuadraticForm(4, 2, quadratic, *args) @@ -4212,7 +4213,7 @@ def binary_quartic(self, quartic, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic Binary quartic with coefficients (1, 0, 0, 0, 1) sage: type(quartic) @@ -4251,14 +4252,14 @@ def binary_quintic(self, quintic, *args, **kwds): If no variables are provided, they will be guessed:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+y^5) + sage: quintic = invariant_theory.binary_quintic(x^5 + y^5) sage: quintic Binary quintic with coefficients (1, 0, 0, 0, 0, 1) If only one variable is given, the quintic is the homogenisation of the provided polynomial:: - sage: quintic = invariant_theory.binary_quintic(x^5+y^5, x) + sage: quintic = invariant_theory.binary_quintic(x^5 + y^5, x) sage: quintic Binary quintic with coefficients (y^5, 0, 0, 0, 0, 1) sage: quintic.is_homogeneous() @@ -4268,11 +4269,11 @@ def binary_quintic(self, quintic, *args, **kwds): specified:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+z*y^5) + sage: quintic = invariant_theory.binary_quintic(x^5 + z*y^5) Traceback (most recent call last): ... ValueError: need 2 or 1 variables, got (x, y, z) - sage: quintic = invariant_theory.binary_quintic(x^5+z*y^5, x, y) + sage: quintic = invariant_theory.binary_quintic(x^5 + z*y^5, x, y) sage: quintic Binary quintic with coefficients (z, 0, 0, 0, 0, 1) @@ -4342,12 +4343,13 @@ def binary_form_from_invariants(self, degree, invariants, variables=None, as_for Binary quintic with coefficients (-37725479487783/1048576, 565882192316745/8388608, 0, 1033866765362693115/67108864, 12849486940936328715/268435456, -23129076493685391687/2147483648) - sage: invariant_theory.binary_form_from_invariants(5, invariants, scaling='normalized') + sage: invariant_theory.binary_form_from_invariants(5, invariants, + ....: scaling='normalized') Binary quintic with coefficients (24389/892616806656, 4205/11019960576, 0, 1015/209952, -145/1296, -3/16) - sage: invariant_theory.binary_form_from_invariants(5, invariants, scaling='coprime') - Binary quintic with coefficients (-2048, 3840, 0, 876960, 2724840, - -613089) + sage: invariant_theory.binary_form_from_invariants(5, invariants, + ....: scaling='coprime') + Binary quintic with coefficients (-2048, 3840, 0, 876960, 2724840, -613089) The invariants can also be computed using the invariants of a given binary quintic. The resulting form has the same invariants up to scaling, is @@ -4359,7 +4361,8 @@ def binary_form_from_invariants(self, degree, invariants, variables=None, as_for sage: p = 3*x1^5 + 6*x1^4*x0 + 3*x1^3*x0^2 + 4*x1^2*x0^3 - 5*x1*x0^4 + 4*x0^5 sage: quintic = invariant_theory.binary_quintic(p, x0, x1) sage: invariants = quintic.clebsch_invariants(as_tuple=True) - sage: newquintic = invariant_theory.binary_form_from_invariants(5, invariants, variables=quintic.variables()) + sage: newquintic = invariant_theory.binary_form_from_invariants( + ....: 5, invariants, variables=quintic.variables()) sage: newquintic Binary quintic with coefficients (9592267437341790539005557/244140625000000, 2149296928207625556323004064707/610351562500000000, @@ -4468,14 +4471,14 @@ def ternary_quadratic(self, quadratic, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.ternary_quadratic(x^2+y^2+z^2) + sage: invariant_theory.ternary_quadratic(x^2 + y^2 + z^2) Ternary quadratic with coefficients (1, 1, 1, 0, 0, 0) sage: T. = QQ[] - sage: invariant_theory.ternary_quadratic(1+u^2+v^2) + sage: invariant_theory.ternary_quadratic(1 + u^2 + v^2) Ternary quadratic with coefficients (1, 1, 1, 0, 0, 0) - sage: quadratic = x^2+y^2+z^2 + sage: quadratic = x^2 + y^2 + z^2 sage: inv = invariant_theory.ternary_quadratic(quadratic) sage: type(inv) @@ -4540,7 +4543,7 @@ def ternary_cubic(self, cubic, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: type(cubic) """ @@ -4562,7 +4565,7 @@ def ternary_biquadratic(self, quadratic1, quadratic2, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: q1 = x^2+y^2+z^2 + sage: q1 = x^2 + y^2 + z^2 sage: q2 = x*y + y*z + x*z sage: inv = invariant_theory.ternary_biquadratic(q1, q2) sage: type(inv) @@ -4616,7 +4619,7 @@ def quaternary_biquadratic(self, quadratic1, quadratic2, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: q1 = w^2+x^2+y^2+z^2 + sage: q1 = w^2 + x^2 + y^2 + z^2 sage: q2 = w*x + y*z sage: inv = invariant_theory.quaternary_biquadratic(q1, q2) sage: type(inv) diff --git a/src/sage/rings/invariants/reconstruction.py b/src/sage/rings/invariants/reconstruction.py index 99941d306b8..4619bf777f1 100644 --- a/src/sage/rings/invariants/reconstruction.py +++ b/src/sage/rings/invariants/reconstruction.py @@ -41,7 +41,7 @@ def binary_quadratic_coefficients_from_invariants(discriminant, invariant_choice EXAMPLES:: sage: from sage.rings.invariants.reconstruction import binary_quadratic_coefficients_from_invariants - sage: quadratic = invariant_theory.binary_form_from_invariants(2, [24]) # indirect doctest + sage: quadratic = invariant_theory.binary_form_from_invariants(2, [24]) # indirect doctest sage: quadratic Binary quadratic with coefficients (1, -6, 0) sage: quadratic.discriminant() @@ -142,7 +142,8 @@ def binary_quintic_coefficients_from_invariants(invariants, K=None, invariant_ch sage: p = 3*x1^5 + 6*x1^4*x0 + 3*x1^3*x0^2 + 4*x1^2*x0^3 - 5*x1*x0^4 + 4*x0^5 sage: quintic = invariant_theory.binary_quintic(p, x0, x1) sage: invs = quintic.clebsch_invariants(as_tuple=True) - sage: reconstructed = invariant_theory.binary_form_from_invariants(5, invs, variables=quintic.variables()) # indirect doctest + sage: reconstructed = invariant_theory.binary_form_from_invariants( # indirect doctest + ....: 5, invs, variables=quintic.variables()) sage: reconstructed Binary quintic with coefficients (9592267437341790539005557/244140625000000, 2149296928207625556323004064707/610351562500000000, @@ -167,8 +168,10 @@ def binary_quintic_coefficients_from_invariants(invariants, K=None, invariant_ch sage: alpha = quintic.alpha_covariant() sage: beta = quintic.beta_covariant() - sage: g = matrix([[alpha(x0=1,x1=0),alpha(x0=0,x1=1)],[beta(x0=1,x1=0),beta(x0=0,x1=1)]])^-1 - sage: transformed = tuple([g.determinant()^-5*x for x in quintic.transformed(g).coeffs()]) + sage: g = matrix([[alpha(x0=1,x1=0), alpha(x0=0,x1=1)], + ....: [beta(x0=1,x1=0), beta(x0=0,x1=1)]])^-1 + sage: transformed = tuple([g.determinant()^-5*x + ....: for x in quintic.transformed(g).coeffs()]) sage: transformed == reconstructed.coeffs() True @@ -231,7 +234,8 @@ def binary_quintic_coefficients_from_invariants(invariants, K=None, invariant_ch sage: binary_quintic_coefficients_from_invariants([3,1,2], K=GF(5)) Traceback (most recent call last): ... - NotImplementedError: no reconstruction of binary quintics implemented for fields of characteristic 2, 3 or 5 + NotImplementedError: no reconstruction of binary quintics implemented + for fields of characteristic 2, 3 or 5 TESTS:: diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index 56551b50a55..c7e1c65d26d 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -6,11 +6,11 @@ sage: R = LaurentSeriesRing(QQ, "x") sage: R.base_ring() Rational Field - sage: S = LaurentSeriesRing(GF(17)['x'], 'y') - sage: S - Laurent Series Ring in y over Univariate Polynomial Ring in x over - Finite Field of size 17 - sage: S.base_ring() + sage: S = LaurentSeriesRing(GF(17)['x'], 'y') # optional - sage.rings.finite_rings + sage: S # optional - sage.rings.finite_rings + Laurent Series Ring in y over + Univariate Polynomial Ring in x over Finite Field of size 17 + sage: S.base_ring() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 17 .. SEEALSO:: @@ -74,7 +74,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: R = LaurentSeriesRing(QQ, 'x'); R Laurent Series Ring in x over Rational Field sage: x = R.0 - sage: g = 1 - x + x^2 - x^4 +O(x^8); g + sage: g = 1 - x + x^2 - x^4 + O(x^8); g 1 - x + x^2 - x^4 + O(x^8) sage: g = 10*x^(-3) + 2006 - 19*x + x^2 - x^4 +O(x^8); g 10*x^-3 + 2006 - 19*x + x^2 - x^4 + O(x^8) @@ -84,7 +84,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: Frac(QQ[['x']]) Laurent Series Ring in x over Rational Field - sage: Frac(GF(5)['y']) + sage: Frac(GF(5)['y']) # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in y over Finite Field of size 5 When the base ring is a domain, the fraction field is the @@ -96,17 +96,17 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): Laurent series rings are determined by their variable and the base ring, and are globally unique:: - sage: K = Qp(5, prec = 5) - sage: L = Qp(5, prec = 200) - sage: R. = LaurentSeriesRing(K) - sage: S. = LaurentSeriesRing(L) - sage: R is S + sage: K = Qp(5, prec=5) # optional - sage.rings.padics + sage: L = Qp(5, prec=200) # optional - sage.rings.padics + sage: R. = LaurentSeriesRing(K) # optional - sage.rings.padics + sage: S. = LaurentSeriesRing(L) # optional - sage.rings.padics + sage: R is S # optional - sage.rings.padics False - sage: T. = LaurentSeriesRing(Qp(5,prec=200)) - sage: S is T + sage: T. = LaurentSeriesRing(Qp(5, prec=200)) # optional - sage.rings.padics + sage: S is T # optional - sage.rings.padics True - sage: W. = LaurentSeriesRing(Qp(5,prec=199)) - sage: W is T + sage: W. = LaurentSeriesRing(Qp(5, prec=199)) # optional - sage.rings.padics + sage: W is T # optional - sage.rings.padics False sage: K = LaurentSeriesRing(CC, 'q') @@ -122,11 +122,15 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): a field equipped with a discrete valuation for which it is complete. The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) - sage: R. = k[[]] - sage: F = Frac(R) - sage: F.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets + sage: k = GF(11) # optional - sage.rings.finite_rings + sage: R. = k[[]] # optional - sage.rings.finite_rings + sage: F = Frac(R) # optional - sage.rings.finite_rings + sage: F.category() # optional - sage.rings.finite_rings + Join of + Category of complete discrete valuation fields and + Category of commutative algebras over (finite enumerated fields and + subquotients of monoids and quotients of semigroups) and + Category of infinite sets sage: TestSuite(F).run() TESTS: @@ -147,11 +151,14 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): Check categories (:trac:`24420`):: sage: LaurentSeriesRing(ZZ, 'x').category() - Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces) + Category of infinite commutative no zero divisors algebras + over (euclidean domains and infinite enumerated sets and metric spaces) sage: LaurentSeriesRing(QQ, 'x').category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of complete discrete valuation fields and Category of commutative algebras + over (number fields and quotient fields and metric spaces) and Category of infinite sets sage: LaurentSeriesRing(Zmod(4), 'x').category() - Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of infinite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) Check coercions (:trac:`24431`):: @@ -215,27 +222,34 @@ def __init__(self, power_series): sage: RZZ = LaurentSeriesRing(ZZ, 't') sage: RZZ.category() - Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces) + Category of infinite commutative no zero divisors algebras + over (euclidean domains and infinite enumerated sets and metric spaces) sage: TestSuite(RZZ).run() sage: R1 = LaurentSeriesRing(Zmod(1), 't') sage: R1.category() - Category of finite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of finite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) sage: TestSuite(R1).run() sage: R2 = LaurentSeriesRing(Zmod(2), 't') sage: R2.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets + Join of Category of complete discrete valuation fields + and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) + and Category of infinite sets sage: TestSuite(R2).run() sage: R4 = LaurentSeriesRing(Zmod(4), 't') sage: R4.category() - Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of infinite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) sage: TestSuite(R4).run() sage: RQQ = LaurentSeriesRing(QQ, 't') sage: RQQ.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of complete discrete valuation fields + and Category of commutative algebras over (number fields and quotient fields and metric spaces) + and Category of infinite sets sage: TestSuite(RQQ).run() """ base_ring = power_series.base_ring() @@ -361,9 +375,9 @@ def _repr_(self): """ EXAMPLES:: - sage: LaurentSeriesRing(QQ,'q') # indirect doctest + sage: LaurentSeriesRing(QQ, 'q') # indirect doctest Laurent Series Ring in q over Rational Field - sage: LaurentSeriesRing(ZZ,'t',sparse=True) + sage: LaurentSeriesRing(ZZ, 't', sparse=True) Sparse Laurent Series Ring in t over Integer Ring """ s = "Laurent Series Ring in %s over %s" % (self.variable_name(), self.base_ring()) @@ -386,35 +400,35 @@ def _element_constructor_(self, x, n=0, prec=infinity): EXAMPLES:: - sage: R. = LaurentSeriesRing(Qp(5, 10)) - sage: S. = LaurentSeriesRing(RationalField()) - sage: R(t + t^2 + O(t^3)) + sage: R. = LaurentSeriesRing(Qp(5, 10)) # optional - sage.rings.padics + sage: S. = LaurentSeriesRing(RationalField()) # optional - sage.rings.padics + sage: R(t + t^2 + O(t^3)) # optional - sage.rings.padics (1 + O(5^10))*u + (1 + O(5^10))*u^2 + O(u^3) - sage: R(t + t^2 + O(t^3), prec=2) + sage: R(t + t^2 + O(t^3), prec=2) # optional - sage.rings.padics (1 + O(5^10))*u + O(u^2) Coercing an element into its own parent produces that element again, unless a different ``n`` or ``prec`` is given:: - sage: u is R(u) + sage: u is R(u) # optional - sage.rings.padics True - sage: R(u, n=3, prec=7) + sage: R(u, n=3, prec=7) # optional - sage.rings.padics (1 + O(5^10))*u^4 + O(u^7) Rational functions are accepted:: - sage: I = sqrt(-1) - sage: K. = QQ[I] - sage: P. = PolynomialRing(K) - sage: L. = LaurentSeriesRing(QQ[I]) - sage: L((t*I)/(t^3+I*2*t)) + sage: I = sqrt(-1) # optional - sage.rings.number_field + sage: K. = QQ[I] # optional - sage.rings.number_field + sage: P. = PolynomialRing(K) # optional - sage.rings.number_field + sage: L. = LaurentSeriesRing(QQ[I]) # optional - sage.rings.number_field + sage: L((t*I)/(t^3+I*2*t)) # optional - sage.rings.number_field 1/2 + 1/4*I*u^2 - 1/8*u^4 - 1/16*I*u^6 + 1/32*u^8 + 1/64*I*u^10 - 1/128*u^12 - 1/256*I*u^14 + 1/512*u^16 + 1/1024*I*u^18 + O(u^20) :: - sage: L(t*I) / L(t^3+I*2*t) + sage: L(t*I) / L(t^3+I*2*t) # optional - sage.rings.number_field 1/2 + 1/4*I*u^2 - 1/8*u^4 - 1/16*I*u^6 + 1/32*u^8 + 1/64*I*u^10 - 1/128*u^12 - 1/256*I*u^14 + 1/512*u^16 + 1/1024*I*u^18 + O(u^20) @@ -440,23 +454,23 @@ def _element_constructor_(self, x, n=0, prec=infinity): Various conversions from PARI (see also :trac:`2508`):: sage: L. = LaurentSeriesRing(QQ, default_prec=10) - sage: L(pari('1/x')) + sage: L(pari('1/x')) # optional - sage.libs.pari q^-1 - sage: L(pari('polchebyshev(5)')) + sage: L(pari('polchebyshev(5)')) # optional - sage.libs.pari 5*q - 20*q^3 + 16*q^5 - sage: L(pari('polchebyshev(5) - 1/x^4')) + sage: L(pari('polchebyshev(5) - 1/x^4')) # optional - sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 - sage: L(pari('1/polchebyshev(5)')) + sage: L(pari('1/polchebyshev(5)')) # optional - sage.libs.pari 1/5*q^-1 + 4/5*q + 64/25*q^3 + 192/25*q^5 + 2816/125*q^7 + O(q^9) - sage: L(pari('polchebyshev(5) + O(x^40)')) + sage: L(pari('polchebyshev(5) + O(x^40)')) # optional - sage.libs.pari 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) + sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) # optional - sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('1/polchebyshev(5) + O(x^10)')) + sage: L(pari('1/polchebyshev(5) + O(x^10)')) # optional - sage.libs.pari 1/5*q^-1 + 4/5*q + 64/25*q^3 + 192/25*q^5 + 2816/125*q^7 + 8192/125*q^9 + O(q^10) - sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 + sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 # optional - sage.libs.pari 1/5*q^-11 + 4/5*q^-9 + 64/25*q^-7 + 192/25*q^-5 + 2816/125*q^-3 + 8192/125*q^-1 + O(1) - sage: L(pari('O(x^-10)')) + sage: L(pari('O(x^-10)')) # optional - sage.libs.pari O(q^-10) Check that :trac:`30073` is fixed:: @@ -522,8 +536,8 @@ def random_element(self, algorithm='default'): EXAMPLES:: - sage: S. = LaurentSeriesRing(GF(3)) - sage: S.random_element() # random + sage: S. = LaurentSeriesRing(GF(3)) # optional - sage.rings.finite_rings + sage: S.random_element() # random # optional - sage.rings.finite_rings s^-8 + s^-7 + s^-6 + s^-5 + s^-1 + s + s^3 + s^4 + s^5 + 2*s^6 + s^7 + s^11 + O(s^12) """ @@ -637,14 +651,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: S. = LaurentSeriesRing(GF(19)) - sage: R.hom([y], S) # indirect doctest + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: S. = LaurentSeriesRing(GF(19)) # optional - sage.rings.finite_rings + sage: R.hom([y], S) # indirect doctest # 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: f = R.hom(x+x^3,R) - sage: f(x^2) + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators + sage: f = R.hom(x + x^3,R) # optional - sage.rings.finite_rings + sage: f(x^2) # optional - sage.rings.finite_rings x^2 + 2*x^4 + x^6 The image of the generator needs to be a unit:: @@ -671,8 +686,8 @@ def characteristic(self): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: R.characteristic() + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.characteristic() # optional - sage.rings.finite_rings 17 """ return self.base_ring().characteristic() @@ -686,8 +701,8 @@ def residue_field(self): EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: R.residue_field() + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.residue_field() # optional - sage.rings.finite_rings Finite Field of size 17 sage: R. = LaurentSeriesRing(ZZ) diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index b11989eafbe..af04fe4e7e6 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -3,16 +3,16 @@ Laurent Series EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(7), 't'); R + sage: R. = LaurentSeriesRing(GF(7), 't'); R # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 - sage: f = 1/(1-t+O(t^10)); f + sage: f = 1/(1-t+O(t^10)); f # optional - sage.rings.finite_rings 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) Laurent series are immutable:: - sage: f[2] + sage: f[2] # optional - sage.rings.finite_rings 1 - sage: f[2] = 5 + sage: f[2] = 5 # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: Laurent series are immutable @@ -112,18 +112,18 @@ cdef class LaurentSeries(AlgebraElement): sage: R. = LaurentSeriesRing(ZZ) sage: R([1,2,3]) 1 + 2*q + 3*q^2 - sage: R([1,2,3],-5) + sage: R([1,2,3], -5) q^-5 + 2*q^-4 + 3*q^-3 :: - sage: S. = LaurentSeriesRing(GF(5)) - sage: T. = PowerSeriesRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentSeriesRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PowerSeriesRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Laurent Series Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 """ AlgebraElement.__init__(self, parent) @@ -185,7 +185,7 @@ cdef class LaurentSeries(AlgebraElement): sage: R. = LaurentSeriesRing(ZZ) sage: p = R([1,2,3]); p 1 + 2*q + 3*q^2 - sage: p.change_ring(GF(2)) + sage: p.change_ring(GF(2)) # optional - sage.rings.finite_rings 1 + q^2 """ return self._parent.change_ring(R)(self) @@ -197,9 +197,9 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: R. = LaurentSeriesRing(QQ) - sage: (2+t).is_unit() + sage: (2 + t).is_unit() True - sage: f = 2+t^2+O(t^10); f.is_unit() + sage: f = 2 + t^2 + O(t^10); f.is_unit() True sage: 1/f 1/2 - 1/4*t^2 + 1/8*t^4 - 1/16*t^6 + 1/32*t^8 + O(t^10) @@ -288,16 +288,16 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: R. = LaurentSeriesRing(K) - sage: z = t^-1 + i*t - sage: z._im_gens_(R, [t^2]) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: R. = LaurentSeriesRing(K) # optional - sage.rings.number_field + sage: z = t^-1 + i*t # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2]) # optional - sage.rings.number_field t^-2 + i*t^2 The argument base_map is not yet supported, because it isn't over power series:: - sage: cc = K.hom([i]) - sage: z._im_gens_(R, [t^2], base_map=cc) + sage: cc = K.hom([i]) # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError @@ -442,9 +442,9 @@ cdef class LaurentSeries(AlgebraElement): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentSeriesRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentSeriesRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -616,10 +616,10 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: t = LaurentSeriesRing(ZZ,'t').gen() - sage: f = 1/t**2+2/t+3+4*t + sage: f = 1/t**2 + 2/t + 3 + 4*t sage: f.residue() 2 - sage: f = t+t**2 + sage: f = t + t**2 sage: f.residue() 0 sage: f.residue().parent() @@ -671,11 +671,11 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: - sage: A. = LaurentSeriesRing(GF(5)) - sage: x = t^(-1) + t^2 + O(t^5) - sage: x.lift_to_precision(10) + sage: A. = LaurentSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: x = t^(-1) + t^2 + O(t^5) # optional - sage.rings.finite_rings + sage: x.lift_to_precision(10) # optional - sage.rings.finite_rings t^-1 + t^2 + O(t^10) - sage: x.lift_to_precision() + sage: x.lift_to_precision() # optional - sage.rings.finite_rings t^-1 + t^2 """ if absprec is not None and absprec <= self.precision_absolute(): @@ -1028,7 +1028,8 @@ cdef class LaurentSeries(AlgebraElement): sage: A. = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f - 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) + 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 """ @@ -1046,7 +1047,8 @@ cdef class LaurentSeries(AlgebraElement): sage: A. = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f - 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) + 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate_laurentseries(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10) """ @@ -1489,8 +1491,11 @@ cdef class LaurentSeries(AlgebraElement): ring:: sage: R. = LaurentSeriesRing(QQ, default_prec=20) - sage: (x - x^2).reverse() # get some Catalan numbers - x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + 477638700*x^19 + O(x^20) + sage: (x - x^2).reverse() # get some Catalan numbers + x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + + 477638700*x^19 + O(x^20) sage: (x - x^2).reverse(precision=3) x + x^2 + O(x^3) @@ -1743,10 +1748,10 @@ cdef class LaurentSeries(AlgebraElement): Check whether a polynomial over a Laurent series ring is contained in the polynomial ring over the power series ring (see :trac:`19459`): - sage: L. = LaurentSeriesRing(GF(2)) - sage: R. = PolynomialRing(L) - sage: S. = PolynomialRing(L._power_series_ring) - sage: t**(-1)*x*y in S + sage: L. = LaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(L) # optional - sage.rings.finite_rings + sage: S. = PolynomialRing(L._power_series_ring) # optional - sage.rings.finite_rings + sage: t**(-1)*x*y in S # optional - sage.rings.finite_rings False There used to be an issue with non-canonical representations of zero, @@ -1766,8 +1771,8 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`32440`:: - sage: L. = LaurentSeriesRing(QQ, implementation='pari') - sage: (x + O(x^3)).power_series() + sage: L. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: (x + O(x^3)).power_series() # optional - sage.libs.pari x + O(x^3) """ if self.__n < 0: @@ -1808,13 +1813,13 @@ cdef class LaurentSeries(AlgebraElement): x*t^-2 + O(t^2) sage: f(y=x) x*t^-2 + x*t^2 + O(t^8) - sage: f(t^3, x=2, y=x+x^2) + sage: f(t^3, x=2, y=x + x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) sage: f(t^3, 2, x+x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) - sage: f(x=2, t=t^3, y=x+x^2) + sage: f(x=2, t=t^3, y=x + x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) - sage: f(2, x+x^2, t=t^3) + sage: f(2, x + x^2, t=t^3) Traceback (most recent call last): ... ValueError: must not specify t keyword and positional argument @@ -1828,9 +1833,9 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`23928`:: - sage: R. = LaurentSeriesRing(QQ, implementation='pari') - sage: f = x.add_bigoh(7) - sage: f(x) + sage: R. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = x.add_bigoh(7) # optional - sage.libs.pari + sage: f(x) # optional - sage.libs.pari x + O(x^7) """ if len(kwds) >= 1: @@ -1870,16 +1875,16 @@ cdef class LaurentSeries(AlgebraElement): sage: L. = LaurentSeriesRing(QQ) sage: f = x + 1/x + O(x^2); f x^-1 + x + O(x^2) - sage: f.__pari__() + sage: f.__pari__() # optional - sage.libs.pari x^-1 + x + O(x^2) Check that :trac:`32437` is fixed:: - sage: F. = GF(257^2) - sage: R. = LaurentSeriesRing(F) - sage: g = t + O(t^99) - sage: f = u*t + O(t^99) - sage: g(f) # indirect doctest + sage: F. = GF(257^2) # optional - sage.rings.finite_rings + sage: R. = LaurentSeriesRing(F) # optional - sage.rings.finite_rings + sage: g = t + O(t^99) # optional - sage.rings.finite_rings + sage: f = u*t + O(t^99) # optional - sage.rings.finite_rings + sage: g(f) # indirect doctest # optional - sage.libs.pari sage.rings.finite_rings u*t + O(t^99) """ f = self.__u diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index f31488d5354..0ee2d591177 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -1186,7 +1186,7 @@ def define(self, s): sage: F.define(1 + g*F) sage: F[:16] [1, 1, 1, 2, 1, 3, 1, 4, 2, 3, 1, 8, 1, 3, 3] - sage: oeis(_) # optional, internet + sage: oeis(_) # optional - internet 0: A002033: Number of perfect partitions of n. 1: A074206: Kalmár's [Kalmar's] problem: number of ordered factorizations of n. ... @@ -1275,7 +1275,7 @@ def define(self, s): sage: f 1 + 1/(2^s) - 1/(4^s) + O(1/(8^s)) - sage: oeis(f[:30]) # optional, internet + sage: oeis(f[:30]) # optional - internet 0: A122698: a(1)=a(2)=1 then a(n) = Sum_{d|n, 1 3 u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mFp1 = matrix({k:f(v) for k, v in m1.dict().items()}); mFp1 + sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 # optional - sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mFp1.base_ring() + sage: mFp1.base_ring() # optional - sage.modules sage.rings.finite_rings Finite Field of size 17 - sage: mFp2 = matrix({k:f(v) for k, v in m2.dict().items()}); mFp2 + sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 # optional - sage.modules sage.rings.finite_rings [ 2 3 0] [ 9 8 0] [ 0 0 16] - sage: mFp3 = matrix({k:f(v) for k, v in m3.dict().items()}); mFp3 + sage: mFp3 = matrix({k: f(v) for k, v in m3.dict().items()}); mFp3 # optional - sage.modules sage.rings.finite_rings [16 0 0] [ 0 4 5] [ 0 7 6] Obtain specializations in characteristic 0:: - sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ + sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ # optional - sage.rings.finite_rings Ring morphism: - From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring + localized at (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, + u2*q - u1, u2*q - u0, u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) To: Rational Field Defn: u0 |--> 3 u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mQ1 = matrix({k:fQ(v) for k, v in m1.dict().items()}); mQ1 + sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 # optional - sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mQ1.base_ring() + sage: mQ1.base_ring() # optional - sage.modules sage.rings.finite_rings Rational Field - sage: mQ2 = matrix({k:fQ(v) for k, v in m2.dict().items()}); mQ2 + sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 # optional - sage.modules sage.rings.finite_rings [-15 -14 0] [ 26 25 0] [ 0 0 -1] - sage: mQ3 = matrix({k:fQ(v) for k, v in m3.dict().items()}); mQ3 + sage: mQ3 = matrix({k: fQ(v) for k, v in m3.dict().items()}); mQ3 # optional - sage.modules sage.rings.finite_rings [ -1 0 0] [ 0 -15/26 11/26] [ 0 301/26 275/26] sage: S. = QQ[] - sage: T = S.quo(x+y+z) - sage: F = T.fraction_field() - sage: fF = L.hom((x, y, z, t), codomain=F); fF + sage: T = S.quo(x + y + z) + sage: F = T.fraction_field() # optional - sage.libs.singular + sage: fF = L.hom((x, y, z, t), codomain=F); fF # optional - sage.libs.singular Ring morphism: - From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) - To: Fraction Field of Quotient of Multivariate Polynomial Ring in x, y, z, t over - Rational Field by the ideal (x + y + z) + From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring + localized at (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, + u2*q - u1, u2*q - u0, u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + To: Fraction Field of Quotient of Multivariate Polynomial Ring in x, y, z, t + over Rational Field by the ideal (x + y + z) Defn: u0 |--> -ybar - zbar u1 |--> ybar u2 |--> zbar q |--> tbar - sage: mF1 = matrix({k:fF(v) for k, v in m1.dict().items()}); mF1 + sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # optional - sage.libs.singular sage.modules [ ybar 0 0] [ 0 -ybar - zbar 0] [ 0 0 -ybar - zbar] - sage: mF1.base_ring() == F + sage: mF1.base_ring() == F # optional - sage.libs.singular sage.modules True TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.singular sage.modules AUTHORS: @@ -199,21 +199,21 @@ def normalize_extra_units(base_ring, add_units, warning=True): sage: normalize_extra_units(ZZ, [3, -15, 45, 9, 2, 50]) [2, 3, 5] sage: P. = ZZ[] - sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) + sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) # optional - sage.libs.pari [2, 3, 5, z, y, x] sage: P. = QQ[] - sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) + sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) # optional - sage.libs.pari [z, y, x] sage: R. = ZZ[] - sage: Q. = R.quo(x**2-5) - sage: p = b**2-5 - sage: p == (b-a)*(b+a) + sage: Q. = R.quo(x**2 - 5) # optional - sage.libs.singular + sage: p = b**2 - 5 # optional - sage.libs.singular + sage: p == (b-a)*(b+a) # optional - sage.libs.singular True - sage: normalize_extra_units(Q, [p]) + sage: normalize_extra_units(Q, [p]) # optional - sage.libs.pari doctest:...: UserWarning: Localization may not be represented uniquely [b^2 - 5] - sage: normalize_extra_units(Q, [p], warning=False) + sage: normalize_extra_units(Q, [p], warning=False) # optional - sage.libs.pari [b^2 - 5] """ # convert to base ring @@ -251,11 +251,11 @@ class LocalizationElement(IntegralDomainElement): EXAMPLES:: sage: from sage.rings.localization import LocalizationElement - sage: P. = GF(5)[] - sage: L = P.localization((x, y*z-x)) - sage: LocalizationElement(L, 4/(y*z-x)**2) + sage: P. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = P.localization((x, y*z-x)) # optional - sage.rings.finite_rings + sage: LocalizationElement(L, 4/(y*z-x)**2) # optional - sage.rings.finite_rings (-1)/(y^2*z^2 - 2*x*y*z + x^2) - sage: _.parent() + sage: _.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y, z over Finite Field of size 5 localized at (x, y*z - x) """ @@ -389,10 +389,10 @@ def factor(self, proof=None): EXAMPLES:: sage: P. = QQ['x, y'] - sage: L = P.localization(X-Y) + sage: L = P.localization(X - Y) sage: x, y = L.gens() - sage: p = (x^2 - y^2)/(x-y)^2 - sage: p.factor() + sage: p = (x^2 - y^2)/(x-y)^2 # optional - sage.libs.singular + sage: p.factor() # optional - sage.libs.singular (1/(x - y)) * (x + y) """ num = self._value.numerator() @@ -411,9 +411,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+1) - sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest - sage: f(x/(x**2+1)) + sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari + sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # optional - sage.libs.pari + sage: f(x/(x**2+1)) # optional - sage.libs.pari 5/26 """ return self._value._im_gens_(codomain, im_gens, base_map=base_map) @@ -449,12 +449,12 @@ def is_unit(self): EXAMPLES:: sage: P. = QQ[] - sage: L = P.localization((x, y*z)) - sage: L(y*z).is_unit() + sage: L = P.localization((x, y*z)) # optional - sage.libs.pari + sage: L(y*z).is_unit() # optional - sage.libs.pari True - sage: L(z).is_unit() + sage: L(z).is_unit() # optional - sage.libs.pari True - sage: L(x*y*z).is_unit() + sage: L(x*y*z).is_unit() # optional - sage.libs.pari True """ return self.parent()._cut_off_extra_units_from_base_ring_element(self._value.numerator()).is_unit() @@ -467,9 +467,9 @@ def inverse_of_unit(self): sage: P. = ZZ[] sage: L = Localization(P, x*y*z) - sage: L(x*y*z).inverse_of_unit() + sage: L(x*y*z).inverse_of_unit() # optional - sage.libs.singular 1/(x*y*z) - sage: L(z).inverse_of_unit() + sage: L(z).inverse_of_unit() # optional - sage.libs.singular 1/z """ parent = self.parent() @@ -481,11 +481,11 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: P. = GF(7)[] - sage: L = Localization(P, (x, y, z)) - sage: L(1/x) < L(3/(x*y*z)**3) + sage: P. = GF(7)[] # optional - sage.rings.finite_rings + sage: L = Localization(P, (x, y, z)) # optional - sage.rings.finite_rings + sage: L(1/x) < L(3/(x*y*z)**3) # optional - sage.rings.finite_rings False - sage: ~L(y*z/x) == L(x/(y*z)) + sage: ~L(y*z/x) == L(x/(y*z)) # optional - sage.rings.finite_rings True """ sval = self._value @@ -518,8 +518,8 @@ def _rational_(self): TESTS:: sage: L = ZZ.localization(5) - sage: cp3 = cyclotomic_polynomial(3).change_ring(L) - sage: cp3.splitting_field('t') # indirect doctest + sage: cp3 = cyclotomic_polynomial(3).change_ring(L) # optional - sage.libs.pari + sage: cp3.splitting_field('t') # indirect doctest # optional - sage.libs.pari sage.rings.number_field Number Field in t with defining polynomial x^2 + x + 1 """ from sage.rings.rational_field import QQ @@ -601,40 +601,41 @@ class Localization(IntegralDomain, UniqueRepresentation): ... ValueError: factor 7 of denominator is not a unit - sage: Localization(Zp(7), (3, 5)) + sage: Localization(Zp(7), (3, 5)) # optional - sage.rings.padics Traceback (most recent call last): ... - ValueError: all given elements are invertible in 7-adic Ring with capped relative precision 20 + ValueError: all given elements are invertible in + 7-adic Ring with capped relative precision 20 sage: R. = ZZ[] - sage: L = R.localization(x**2+1) + sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari sage: s = (x+5)/(x**2+1) - sage: s in L + sage: s in L # optional - sage.libs.pari True sage: t = (x+5)/(x**2+2) - sage: t in L + sage: t in L # optional - sage.libs.pari False - sage: L(t) + sage: L(t) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: fraction must have unit denominator - sage: L(s) in R + sage: L(s) in R # optional - sage.libs.pari False - sage: y = L(x) - sage: g = L(s) - sage: g.parent() + sage: y = L(x) # optional - sage.libs.pari + sage: g = L(s) # optional - sage.libs.pari + sage: g.parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) - sage: f = (y+5)/(y**2+1); f + sage: f = (y+5)/(y**2+1); f # optional - sage.libs.pari (x + 5)/(x^2 + 1) - sage: f == g + sage: f == g # optional - sage.libs.pari True - sage: (y+5)/(y**2+2) + sage: (y+5)/(y**2+2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: factor x^2 + 2 of denominator is not a unit sage: Lau. = LaurentPolynomialRing(ZZ) - sage: LauL = Lau.localization(u+1) + sage: LauL = Lau.localization(u + 1) sage: LauL(~u).parent() Multivariate Polynomial Ring in u, v over Integer Ring localized at (v, u, u + 1) @@ -657,12 +658,12 @@ def __init__(self, base_ring, extra_units, names=None, normalize=True, category= TESTS:: - sage: L = Localization(ZZ, (3,5)) + sage: L = Localization(ZZ, (3, 5)) sage: TestSuite(L).run() sage: R. = ZZ[] - sage: L = R.localization(x**2+1) - sage: TestSuite(L).run() + sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari + sage: TestSuite(L).run() # optional - sage.libs.pari """ if type(extra_units) is tuple: extra_units = list(extra_units) @@ -702,9 +703,10 @@ def _repr_(self): EXAMPLES:: - sage: R. = GF(3)[] - sage: Localization(R, a**2-1) - Univariate Polynomial Ring in a over Finite Field of size 3 localized at (a + 1, a + 2) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: Localization(R, a**2 - 1) # optional - sage.rings.finite_rings + Univariate Polynomial Ring in a over Finite Field of size 3 + localized at (a + 1, a + 2) """ return "%s localized at %s" % (self.base(), self._extra_units) @@ -733,37 +735,38 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+1) - sage: L.hom([5]) # indirect doctest + sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari + sage: L.hom([5]) # indirect doctest # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: images of some localized elements fail to be units - sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest + sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # optional - sage.libs.pari Ring morphism: - From: Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) + From: Univariate Polynomial Ring in x over Integer Ring + localized at (x^2 + 1,) To: Integer Ring localized at (2, 13) Defn: x |--> 5 TESTS:: - sage: phi=R.hom([5]) - sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) + sage: phi = R.hom([5]) + sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: given base_map is not compatible with im_gens - sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: images of some localized elements fail to be units - sage: phi=R.hom([5], codomain=QQ) - sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) + sage: phi = R.hom([5], codomain=QQ) + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: codomain of base_map must be Integer Ring - sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) + sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) # optional - sage.libs.pari True """ B = self.base_ring() @@ -795,7 +798,7 @@ def ngens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2+1, y-1)).ngens() + sage: Localization(R, (x**2 + 1, y - 1)).ngens() # optional - sage.libs.pari 2 sage: Localization(ZZ, 2).ngens() @@ -811,7 +814,7 @@ def gen(self, i): EXAMPLES:: sage: R. = ZZ[] - sage: R.localization((x**2+1, y-1)).gen(0) + sage: R.localization((x**2 + 1, y - 1)).gen(0) # optional - sage.libs.pari x sage: ZZ.localization(2).gen(0) @@ -827,7 +830,7 @@ def gens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2+1, y-1)).gens() + sage: Localization(R, (x**2 + 1, y - 1)).gens() # optional - sage.libs.pari (x, y) sage: Localization(ZZ, 2).gens() @@ -851,10 +854,10 @@ def _cut_off_extra_units_from_base_ring_element(self, x): EXAMPLES:: sage: P. = QQ[] - sage: L = Localization(P, (x, y*z)) - sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) + sage: L = Localization(P, (x, y*z)) # optional - sage.libs.pari + sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) # optional - sage.libs.pari 1 - sage: L._cut_off_extra_units_from_base_ring_element(x*z) + sage: L._cut_off_extra_units_from_base_ring_element(x*z) # optional - sage.libs.pari 1 TESTS: @@ -894,16 +897,16 @@ def _fraction_to_element(self, x): EXAMPLES:: sage: P. = QQ[] - sage: d = x**2+y**2+z**2 - sage: L = Localization(P, d) - sage: L._fraction_to_element((x+y+z)/d) + sage: d = x**2 + y**2 + z**2 + sage: L = Localization(P, d) # optional - sage.libs.pari + sage: L._fraction_to_element((x+y+z)/d) # optional - sage.libs.pari (x + y + z)/(x^2 + y^2 + z^2) - sage: _ in L + sage: _ in L # optional - sage.libs.pari True TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.pari """ potential_non_unit_denom = self._cut_off_extra_units_from_base_ring_element(x.denominator()) if potential_non_unit_denom.is_unit(): @@ -932,7 +935,7 @@ def _coerce_map_from_(self, S): True sage: N._coerce_map_from_(M) False - sage: O = Localization(L, x**2+1) + sage: O = Localization(L, x**2 + 1) sage: O._coerce_map_from_(M) False sage: O._coerce_map_from_(L) @@ -951,11 +954,11 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: L = Localization(R, (a**2-3, a)) - sage: L.fraction_field() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = Localization(R, (a**2 - 3, a)) # optional - sage.rings.finite_rings + sage: L.fraction_field() # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in a over Finite Field of size 5 - sage: L.is_subring(_) + sage: L.is_subring(_) # optional - sage.rings.finite_rings True """ return self._fraction_field @@ -966,9 +969,9 @@ def characteristic(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: L = R.localization((a**2-3, a)) - sage: L.characteristic() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = R.localization((a**2 - 3, a)) # optional - sage.rings.finite_rings + sage: L.characteristic() # optional - sage.rings.finite_rings 5 """ return self.base_ring().characteristic() @@ -984,7 +987,7 @@ def krull_dimension(self): EXAMPLES:: - sage: R = ZZ.localization((2,3)) + sage: R = ZZ.localization((2, 3)) sage: R.krull_dimension() 1 """ @@ -1008,7 +1011,7 @@ def is_field(self, proof=True): EXAMPLES:: - sage: R = ZZ.localization((2,3)) + sage: R = ZZ.localization((2, 3)) sage: R.is_field() False """ diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 84f288793d3..929bc55703f 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -17,7 +17,8 @@ Natural inclusion `\ZZ \hookrightarrow \QQ`:: sage: phi(2/3) Traceback (most recent call last): ... - TypeError: 2/3 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 2/3 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented There is no homomorphism in the other direction:: @@ -25,30 +26,31 @@ There is no homomorphism in the other direction:: sage: H([1]) 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 EXAMPLES: Reduction to finite field:: - sage: H = Hom(ZZ, GF(9, 'a')) - sage: phi = H([1]) - sage: phi(5) + sage: H = Hom(ZZ, GF(9, 'a')) # optional - sage.rings.finite_rings + sage: phi = H([1]) # optional - sage.rings.finite_rings + sage: phi(5) # optional - sage.rings.finite_rings 2 - sage: psi = H([4]) - sage: psi(5) + sage: psi = H([4]) # optional - sage.rings.finite_rings + sage: psi(5) # optional - sage.rings.finite_rings 2 Map from single variable polynomial ring:: sage: R. = ZZ[] - sage: phi = R.hom([2], GF(5)) - sage: phi + sage: phi = R.hom([2], GF(5)) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 5 Defn: x |--> 2 - sage: phi(x + 12) + sage: phi(x + 12) # optional - sage.rings.finite_rings 4 Identity map on the real numbers:: @@ -61,7 +63,8 @@ Identity map on the real numbers:: sage: f = RR.hom( [2.0] ) 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 Homomorphism from one precision of field to another. @@ -71,7 +74,8 @@ From smaller to bigger doesn't make sense:: sage: f = RR.hom( R200 ) Traceback (most recent call last): ... - TypeError: natural coercion morphism from Real Field with 53 bits of precision to Real Field with 200 bits of precision not defined + TypeError: natural coercion morphism from Real Field with 53 bits of precision + to Real Field with 200 bits of precision not defined From bigger to small does:: @@ -108,7 +112,8 @@ An endomorphism of a quotient of a multi-variate polynomial ring:: sage: S. = quo(R, ideal(1 + y^2)) sage: phi = S.hom([a^2, -b]) sage: phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (y^2 + 1) + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (y^2 + 1) Defn: a |--> a^2 b |--> -b sage: phi(b) @@ -142,28 +147,28 @@ a quotient ring:: Inclusion of ``GF(2)`` into ``GF(4,'a')``:: - sage: k = GF(2) - sage: i = k.hom(GF(4, 'a')) - sage: i + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: i = k.hom(GF(4, 'a')) # optional - sage.rings.finite_rings + sage: i # optional - sage.rings.finite_rings Ring morphism: From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: i(0) + sage: i(0) # optional - sage.rings.finite_rings 0 - sage: a = i(1); a.parent() + sage: a = i(1); a.parent() # optional - sage.rings.finite_rings Finite Field in a of size 2^2 We next compose the inclusion with reduction from the integers to ``GF(2)``:: - sage: pi = ZZ.hom(k) - sage: pi + sage: pi = ZZ.hom(k) # optional - sage.rings.finite_rings + sage: pi # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 2 - sage: f = i * pi - sage: f + sage: f = i * pi # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings Composite map: From: Integer Ring To: Finite Field in a of size 2^2 @@ -175,27 +180,27 @@ We next compose the inclusion with reduction from the integers to From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: a = f(5); a + sage: a = f(5); a # optional - sage.rings.finite_rings 1 - sage: a.parent() + sage: a.parent() # optional - sage.rings.finite_rings Finite Field in a of size 2^2 Inclusion from `\QQ` to the 3-adic field:: - sage: phi = QQ.hom(Qp(3, print_mode = 'series')) - sage: phi + sage: phi = QQ.hom(Qp(3, print_mode='series')) # optional - sage.rings.padics + sage: phi # optional - sage.rings.padics Ring morphism: From: Rational Field To: 3-adic Field with capped relative precision 20 - sage: phi.codomain() + sage: phi.codomain() # optional - sage.rings.padics 3-adic Field with capped relative precision 20 - sage: phi(394) + sage: phi(394) # optional - sage.rings.padics 1 + 2*3 + 3^2 + 2*3^3 + 3^4 + 3^5 + O(3^20) An automorphism of a quotient of a univariate polynomial ring:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2-2) + sage: S. = R.quo(x^2 - 2) sage: sqrt2^2 2 sage: (3+sqrt2)^10 @@ -227,19 +232,19 @@ Endomorphism of power series ring:: Frobenius on a power series ring over a finite field:: - sage: R. = PowerSeriesRing(GF(5)) - sage: f = R.hom([t^5]); f + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = R.hom([t^5]); f # optional - sage.rings.finite_rings Ring endomorphism of Power Series Ring in t over Finite Field of size 5 Defn: t |--> t^5 - sage: a = 2 + t + 3*t^2 + 4*t^3 + O(t^4) - sage: b = 1 + t + 2*t^2 + t^3 + O(t^5) - sage: f(a) + sage: a = 2 + t + 3*t^2 + 4*t^3 + O(t^4) # optional - sage.rings.finite_rings + sage: b = 1 + t + 2*t^2 + t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f(a) # optional - sage.rings.finite_rings 2 + t^5 + 3*t^10 + 4*t^15 + O(t^20) - sage: f(b) + sage: f(b) # optional - sage.rings.finite_rings 1 + t^5 + 2*t^10 + t^15 + O(t^25) - sage: f(a*b) + sage: f(a*b) # optional - sage.rings.finite_rings 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) - sage: f(a)*f(b) + sage: f(a)*f(b) # optional - sage.rings.finite_rings 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) Homomorphism of Laurent series ring:: @@ -332,44 +337,51 @@ TESTS:: :: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]) - sage: c == loads(dumps(c)) + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]) # optional - sage.rings.number_field + sage: c == loads(dumps(c)) # optional - sage.rings.number_field True :: - sage: R. = PowerSeriesRing(GF(5)) - sage: f = R.hom([t^5]) - sage: f == loads(dumps(f)) + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = R.hom([t^5]) # optional - sage.rings.finite_rings + sage: f == loads(dumps(f)) # optional - sage.rings.finite_rings True We define the identity map in many possible ways. These should all compare equal:: - sage: k = GF(2) - sage: R. = k[] - sage: F4. = R.quo(x^2+x+1) - sage: H = End(F4) + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: F4. = R.quo(x^2+x+1) # optional - sage.rings.finite_rings + sage: H = End(F4) # optional - sage.rings.finite_rings sage: from sage.rings.morphism import * - sage: phi1 = H.identity(); phi1 - Identity endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 - sage: phi2 = H([a]); phi2 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi1 = H.identity(); phi1 # optional - sage.rings.finite_rings + Identity endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi2 = H([a]); phi2 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: a |--> a - sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: Induced from base ring by - Ring endomorphism of Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) + Ring endomorphism of Univariate Polynomial Ring in x + over Finite Field of size 2 (using GF2X) Defn: x |--> x - sage: phi4 = RingHomomorphism_cover(H); phi4 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi4 = RingHomomorphism_cover(H); phi4 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: Natural quotient map - sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 - Frobenius endomorphism x |--> x^(2^2) of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 - sage: maps = [phi1, phi2, phi3, phi4, phi5] - sage: for f in maps: + sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(2^2) of + Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 + sage: maps = [phi1, phi2, phi3, phi4, phi5] # optional - sage.rings.finite_rings + sage: for f in maps: # optional - sage.rings.finite_rings ....: for g in maps: ....: if f != g: ....: print("{} != {}".format(f, g)) @@ -457,13 +469,14 @@ cdef class RingMap_lift(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: S. = R.quo( (x^2 + y^2, y) ) - sage: S.lift() + sage: S. = R.quo( (x^2 + y^2, y) ) # optional - sage.libs.singular + sage: S.lift() # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2, y) + From: Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2, y) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift() == 0 + sage: S.lift() == 0 # optional - sage.libs.singular False Since :trac:`11068`, it is possible to create @@ -473,10 +486,10 @@ cdef class RingMap_lift(RingMap): of :class:`sage.rings.ring.Ring`, as in the following example:: - 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: Q.0*Q.1 # indirect doctest + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.modules sage.rings.finite_rings + sage: I = MS * [MS.0*MS.1, MS.2+MS.3] * MS # optional - sage.modules sage.rings.finite_rings + sage: Q = MS.quo(I) # optional - sage.modules sage.rings.finite_rings + sage: Q.0*Q.1 # indirect doctest # optional - sage.modules sage.rings.finite_rings [0 1] [0 0] """ @@ -496,12 +509,13 @@ cdef class RingMap_lift(RingMap): An invalid example:: - sage: GF9. = GaussianIntegers().quotient(3) - sage: from sage.rings.morphism import RingMap_lift - sage: RingMap_lift(GF9, ZZ) + sage: GF9. = GaussianIntegers().quotient(3) # optional - sage.rings.number_field + sage: from sage.rings.morphism import RingMap_lift # optional - sage.rings.number_field + sage: RingMap_lift(GF9, ZZ) # optional - sage.rings.number_field Traceback (most recent call last): ... - TypeError: no canonical coercion from Number Field in I with defining polynomial x^2 + 1 with I = 1*I to Integer Ring + TypeError: no canonical coercion from Number Field in I + with defining polynomial x^2 + 1 with I = 1*I to Integer Ring """ self.S = S x = R(0).lift() @@ -640,14 +654,14 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: f = ZZ.hom(Zp(3)); f + sage: f = ZZ.hom(Zp(3)); f # optional - sage.rings.padics Ring morphism: From: Integer Ring To: 3-adic Ring with capped relative precision 20 TESTS:: - sage: isinstance(f, sage.rings.morphism.RingHomomorphism) + sage: isinstance(f, sage.rings.morphism.RingHomomorphism) # optional - sage.rings.padics True """ @@ -662,7 +676,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(3))._repr_type() + sage: ZZ.hom(Zp(3))._repr_type() # optional - sage.rings.padics 'Ring' """ @@ -775,18 +789,19 @@ cdef class RingHomomorphism(RingMap): result has the type of a homomorphism between its domain and codomain:: - sage: C = CyclotomicField(24) - sage: f = End(C)[1] - sage: type(f*f) == type(f) + sage: C = CyclotomicField(24) # optional - sage.rings.number_field + sage: f = End(C)[1] # optional - sage.rings.number_field + sage: type(f*f) == type(f) # optional - sage.rings.number_field True An example where the domain of ``right`` is a relative number field:: sage: PQ. = QQ[] - sage: K. = NumberField([X^2 - 2, X^2 - 3]) - sage: e, u, v, w = End(K) - sage: u*v - Relative number field endomorphism of Number Field in a with defining polynomial X^2 - 2 over its base field + sage: K. = NumberField([X^2 - 2, X^2 - 3]) # optional - sage.rings.number_field + sage: e, u, v, w = End(K) # optional - sage.rings.number_field + sage: u*v # optional - sage.rings.number_field + Relative number field endomorphism of + Number Field in a with defining polynomial X^2 - 2 over its base field Defn: a |--> -a b |--> b @@ -804,39 +819,44 @@ cdef class RingHomomorphism(RingMap): then Coercion map: From: Multivariate Polynomial Ring in a, b over Rational Field - To: Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field + To: Fraction Field of + Multivariate Polynomial Ring in a, b over Rational Field We check that composition works when there is a base map:: sage: R. = ZZ[] - sage: K. = GF(7^2) - sage: L. = K.extension(x^3 - 3) - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) - sage: phi - Ring endomorphism of Univariate Quotient Polynomial Ring in u over Finite Field in a of size 7^2 with modulus u^3 + 4 + sage: K. = GF(7^2) # optional - sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in u + over Finite Field in a of size 7^2 with modulus u^3 + 4 Defn: u |--> 2*u with map of base ring - sage: psi = phi^3; psi - Ring endomorphism of Univariate Quotient Polynomial Ring in u over Finite Field in a of size 7^2 with modulus u^3 + 4 + sage: psi = phi^3; psi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in u + over Finite Field in a of size 7^2 with modulus u^3 + 4 Defn: u |--> u with map of base ring - sage: psi(a) == phi(phi(phi(a))) + sage: psi(a) == phi(phi(phi(a))) # optional - sage.rings.finite_rings True It also works when the image of the base map is not contained within the base ring of the codomain:: sage: S. = QQ[] sage: T. = S[] - sage: cc = S.hom([x+y]) - sage: f = T.hom([x-y], base_map=cc) + sage: cc = S.hom([x + y]) + sage: f = T.hom([x - y], base_map=cc) sage: f*f - Ring endomorphism of Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Ring endomorphism of Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field Defn: y |--> 2*y with map of base ring sage: (f*f).base_map() Ring morphism: From: Univariate Polynomial Ring in x over Rational Field - To: Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + To: Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field Defn: x |--> 2*x with map of base ring @@ -887,9 +907,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.cover() - sage: f.pushforward(R.ideal([x,3*x+x*y+y^2])) - Ideal (xx, xx*yy + 3*xx) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.cover() # optional - sage.libs.singular + sage: f.pushforward(R.ideal([x, 3*x + x*y + y^2])) # optional - sage.libs.singular + Ideal (xx, xx*yy + 3*xx) of Quotient of Multivariate Polynomial Ring + in x, y over Rational Field by the ideal (x^2, y^2) """ if not ideal.is_Ideal(I): raise TypeError("I must be an ideal") @@ -920,18 +941,18 @@ cdef class RingHomomorphism(RingMap): sage: S. = QQ[] sage: f = R.hom([u^2, u*v, v^2], S) sage: I = S.ideal([u^6, u^5*v, u^4*v^2, u^3*v^3]) - sage: J = f.inverse_image(I); J + sage: J = f.inverse_image(I); J # optional - sage.libs.singular Ideal (y^2 - x*z, x*y*z, x^2*z, x^2*y, x^3) of Multivariate Polynomial Ring in x, y, z over Rational Field - sage: f(J) == I + sage: f(J) == I # optional - sage.libs.singular True Under the above homomorphism, there exists an inverse image for every element that only involves monomials of even degree:: - sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] + sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] # optional - sage.libs.singular [x, x^2, x*y*z + y] - sage: f.inverse_image(u*v^2) + sage: f.inverse_image(u*v^2) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: element u*v^2 does not have preimage @@ -939,27 +960,27 @@ cdef class RingHomomorphism(RingMap): The image of the inverse image ideal can be strictly smaller than the original ideal:: - sage: S. = QQ['u,v'].quotient('v^2 - 2') - sage: f = QuadraticField(2).hom([v], S) - sage: I = S.ideal(u + v) - sage: J = f.inverse_image(I) - sage: J.is_zero() + sage: S. = QQ['u,v'].quotient('v^2 - 2') # optional - sage.libs.singular + sage: f = QuadraticField(2).hom([v], S) # optional - sage.libs.singular sage.rings.number_field + sage: I = S.ideal(u + v) # optional - sage.libs.singular sage.rings.number_field + sage: J = f.inverse_image(I) # optional - sage.libs.singular sage.rings.number_field + sage: J.is_zero() # optional - sage.libs.singular sage.rings.number_field True - sage: f(J) < I + sage: f(J) < I # optional - sage.libs.singular sage.rings.number_field True Fractional ideals are not yet fully supported:: - sage: K. = NumberField(QQ['x']('x^2+2')) - sage: f = K.hom([-a], K) - sage: I = K.ideal([a + 1]) - sage: f.inverse_image(I) + sage: K. = NumberField(QQ['x']('x^2+2')) # optional - sage.rings.number_field + sage: f = K.hom([-a], K) # optional - sage.rings.number_field + sage: I = K.ideal([a + 1]) # optional - sage.rings.number_field + sage: f.inverse_image(I) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: inverse image not implemented... - sage: f.inverse_image(K.ideal(0)).is_zero() + sage: f.inverse_image(K.ideal(0)).is_zero() # optional - sage.rings.number_field True - sage: f.inverse()(I) + sage: f.inverse()(I) # optional - sage.rings.number_field Fractional ideal (-a + 1) ALGORITHM: @@ -973,7 +994,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(2)).inverse_image(ZZ.ideal(2)) + sage: ZZ.hom(Zp(2)).inverse_image(ZZ.ideal(2)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: not an ideal or element in codomain 2-adic Ring @@ -981,7 +1002,7 @@ cdef class RingHomomorphism(RingMap): :: - sage: ZZ.hom(Zp(2)).inverse_image(Zp(2).ideal(2)) + sage: ZZ.hom(Zp(2)).inverse_image(Zp(2).ideal(2)) # optional - sage.rings.padics Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1001,13 +1022,13 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = QQbar[] - sage: f = R.hom([x, QQbar(i) * x + y^2], R) - sage: I = R.ideal(y^3) - sage: J = f._inverse_image_ideal(I); J + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = R.hom([x, QQbar(i) * x + y^2], R) # optional - sage.rings.number_field + sage: I = R.ideal(y^3) # optional - sage.rings.number_field + sage: J = f._inverse_image_ideal(I); J # optional - sage.rings.number_field Ideal (x^2 + 2*I*x*y - y^2) - of Multivariate Polynomial Ring in x, y over Algebraic Field - sage: f(J) <= I + of Multivariate Polynomial Ring in x, y over Algebraic Field + sage: f(J) <= I # optional - sage.rings.number_field True TESTS: @@ -1015,17 +1036,17 @@ cdef class RingHomomorphism(RingMap): Check that :trac:`31367` is fixed:: sage: A. = QQ[] - sage: B. = QQ['x,y'].quotient('y') - sage: f = A.hom([x], B) - sage: f.kernel() + sage: B. = QQ['x,y'].quotient('y') # optional - sage.libs.singular + sage: f = A.hom([x], B) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Principal ideal (0) of Univariate Polynomial Ring in t over Rational Field :: sage: A. = QQ[] - sage: B. = QQ['x,y,z'].quotient('z') - sage: f = A.hom([x, y], B) - sage: f.kernel() + sage: B. = QQ['x,y,z'].quotient('z') # optional - sage.libs.singular + sage: f = A.hom([x, y], B) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Ideal (0) of Multivariate Polynomial Ring in t, u over Rational Field """ from .polynomial.polynomial_quotient_ring import is_PolynomialQuotientRing @@ -1067,36 +1088,36 @@ cdef class RingHomomorphism(RingMap): A degenerate case:: - sage: R. = QQ['x,y'].quotient(1) - sage: f = R.hom([y, x], R) - sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest + sage: R. = QQ['x,y'].quotient(1) # optional - sage.libs.singular + sage: f = R.hom([y, x], R) # optional - sage.libs.singular + sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest # optional - sage.libs.singular (0, 0) Check cases involving quotient rings in which a generator is constant (:trac:`31178`):: sage: R. = QQ[] - sage: B. = R.quotient(R.ideal(x)) - sage: g = R.hom([d^2, d^3], B) - sage: g.inverse_image(d) + sage: B. = R.quotient(R.ideal(x)) # optional - sage.libs.singular + sage: g = R.hom([d^2, d^3], B) # optional - sage.libs.singular + sage: g.inverse_image(d) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: element d does not have preimage - sage: g.inverse_image(d^2) + sage: g.inverse_image(d^2) # optional - sage.libs.singular x - sage: g.inverse_image(d^3) + sage: g.inverse_image(d^3) # optional - sage.libs.singular y - sage: A. = R.quotient(R.ideal(y^2 - x^3)) - sage: h = A.hom([d^2, d^3], B) - sage: h.inverse_image(d^2) + sage: A. = R.quotient(R.ideal(y^2 - x^3)) # optional - sage.libs.singular + sage: h = A.hom([d^2, d^3], B) # optional - sage.libs.singular + sage: h.inverse_image(d^2) # optional - sage.libs.singular a Check that quotient rings are handled correctly (:trac:`33217`):: - sage: A. = QQ['X,Y,Z'].quotient('X^2+Y^2+Z^2-1') - sage: B. = QQ['T,U,V,W'].quotient(['T^2+U^2-1', 'V^2+W^2-1']) - sage: psi = A.hom([v*u, w*u, t], B) - sage: psi.inverse_image(t^2) == z^2 + sage: A. = QQ['X,Y,Z'].quotient('X^2+Y^2+Z^2-1') # optional - sage.libs.singular + sage: B. = QQ['T,U,V,W'].quotient(['T^2+U^2-1', 'V^2+W^2-1']) # optional - sage.libs.singular + sage: psi = A.hom([v*u, w*u, t], B) # optional - sage.libs.singular + sage: psi.inverse_image(t^2) == z^2 # optional - sage.libs.singular True """ graph, from_B, to_A = self._graph_ideal() @@ -1116,7 +1137,7 @@ cdef class RingHomomorphism(RingMap): sage: A. = QQ[] sage: B. = QQ[] sage: f = A.hom([t^4, t^3 - t^2], B) - sage: f.kernel() + sage: f.kernel() # optional - sage.libs.singular Ideal (y^4 - x^3 + 4*x^2*y - 2*x*y^2 + x^2) of Multivariate Polynomial Ring in x, y over Rational Field @@ -1124,50 +1145,50 @@ cdef class RingHomomorphism(RingMap): sage: A. = QQ[] sage: B. = QQ[] - sage: f = A.hom([u^3, u^2*v, u*v^2, v^3],B) - sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) + sage: f = A.hom([u^3, u^2*v, u*v^2, v^3], B) + sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) # optional - sage.libs.singular True - sage: Q = A.quotient(f.kernel()) - sage: Q.hom(f.im_gens(), B).is_injective() + sage: Q = A.quotient(f.kernel()) # optional - sage.libs.singular + sage: Q.hom(f.im_gens(), B).is_injective() # optional - sage.libs.singular True The Steiner-Roman surface:: sage: R. = QQ[] - sage: S = R.quotient(x^2 + y^2 + z^2 - 1) - sage: f = R.hom([x*y, x*z, y*z], S) - sage: f.kernel() + sage: S = R.quotient(x^2 + y^2 + z^2 - 1) # optional - sage.libs.singular + sage: f = R.hom([x*y, x*z, y*z], S) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Ideal (x^2*y^2 + x^2*z^2 + y^2*z^2 - x*y*z) - of Multivariate Polynomial Ring in x, y, z over Rational Field + of Multivariate Polynomial Ring in x, y, z over Rational Field TESTS: The results are cached:: - sage: f.kernel() is f.kernel() + sage: f.kernel() is f.kernel() # optional - sage.libs.singular True A degenerate case:: sage: R. = QQ[] - sage: f = R.hom([0, 0], R.quotient(1)) - sage: f.kernel().is_one() + sage: f = R.hom([0, 0], R.quotient(1)) # optional - sage.libs.singular + sage: f.kernel().is_one() # optional - sage.libs.singular True :: - sage: K. = QuadraticField(2) - sage: K.hom([-sqrt2], K).kernel().is_zero() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: K.hom([-sqrt2], K).kernel().is_zero() # optional - sage.rings.number_field True :: - sage: A. = QuadraticField(2) - sage: B. = A.extension(A['b']('b^2-3')) - sage: C. = B.absolute_field() - sage: A.hom([B(a)], C).kernel().is_zero() + sage: A. = QuadraticField(2) # optional - sage.rings.number_field + sage: B. = A.extension(A['b']('b^2-3')) # optional - sage.rings.number_field + sage: C. = B.absolute_field() # optional - sage.rings.number_field + sage: A.hom([B(a)], C).kernel().is_zero() # optional - sage.rings.number_field True - sage: A.hom([a], B).kernel() + sage: A.hom([a], B).kernel() # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1242,32 +1263,32 @@ cdef class RingHomomorphism(RingMap): Ideals in quotient rings over ``QQbar`` do not support reduction yet, so the graph is constructed in the ambient ring instead:: - sage: A. = QQbar['z,w'].quotient('z*w - 1') - sage: B. = QQbar['x,y'].quotient('2*x^2 + y^2 - 1') - sage: f = A.hom([QQbar(2).sqrt()*x + QQbar(I)*y, + sage: A. = QQbar['z,w'].quotient('z*w - 1') # optional - sage.rings.number_field + sage: B. = QQbar['x,y'].quotient('2*x^2 + y^2 - 1') # optional - sage.rings.number_field + sage: f = A.hom([QQbar(2).sqrt()*x + QQbar(I)*y, # optional - sage.rings.number_field ....: QQbar(2).sqrt()*x - QQbar(I)*y], B) - sage: f._graph_ideal()[0] + sage: f._graph_ideal()[0] # optional - sage.rings.number_field Ideal (z*w - 1, 2*x^2 + y^2 - 1, 1.414213562373095?*x + I*y - z, 1.414213562373095?*x + (-I)*y - w) of Multivariate Polynomial Ring in x, y, z, w over Algebraic Field - sage: f.inverse()(f(z)), f.inverse()(f(w)) + sage: f.inverse()(f(z)), f.inverse()(f(w)) # optional - sage.rings.number_field (z, w) Non-trivial base maps are not supported:: - sage: K. = QuadraticField(2) - sage: R. = K[] - sage: f = R.hom([x, a*x + y], R, base_map=K.hom([-a], K)) - sage: f._graph_ideal() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = R.hom([x, a*x + y], R, base_map=K.hom([-a], K)) # optional - sage.rings.number_field + sage: f._graph_ideal() # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: base map must be trivial Non-commutative rings are not supported (:trac:`32824`):: - sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') - sage: A.hom(A.gens(), A).kernel() + sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') # optional - sage.combinat sage.modules + sage: A.hom(A.gens(), A).kernel() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: rings are not commutative @@ -1324,7 +1345,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([2*t - 1], R) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Ring endomorphism of Univariate Polynomial Ring in t over Rational Field Defn: t |--> 1/2*t + 1/2 @@ -1333,15 +1354,15 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([y*z, x*z, x*y], R) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: f.is_injective() + sage: f.is_injective() # optional - sage.libs.singular True - sage: Q. = R.quotient(x*y*z - 1) - sage: g = Q.hom([y*z, x*z, x*y], Q) - sage: g.inverse() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: g = Q.hom([y*z, x*z, x*y], Q) # optional - sage.libs.singular + sage: g.inverse() # optional - sage.libs.singular Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x*y*z - 1) Defn: x |--> y*z @@ -1352,24 +1373,24 @@ cdef class RingHomomorphism(RingMap): sage: S. = ZZ[] sage: f = S.hom([x + 2*y, x + 3*y], S) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Ring endomorphism of Multivariate Polynomial Ring in x, y over Integer Ring Defn: x |--> 3*x - 2*y y |--> -x + y - sage: (f.inverse() * f).is_identity() + sage: (f.inverse() * f).is_identity() # optional - sage.libs.singular True The following homomorphism is invertible over the rationals, but not over the integers:: sage: g = S.hom([x + y, x - y - 2], S) - sage: g.inverse() + sage: g.inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective sage: R. = QQ[x,y] sage: h = R.hom([x + y, x - y - 2], R) - sage: (h.inverse() * h).is_identity() + sage: (h.inverse() * h).is_identity() # optional - sage.libs.singular True This example by M. Nagata is a wild automorphism:: @@ -1377,13 +1398,13 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: sigma = R.hom([x - 2*y*(z*x+y^2) - z*(z*x+y^2)^2, ....: y + z*(z*x+y^2), z], R) - sage: tau = sigma.inverse(); tau + sage: tau = sigma.inverse(); tau # optional - sage.libs.singular Ring endomorphism of Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> -y^4*z - 2*x*y^2*z^2 - x^2*z^3 + 2*y^3 + 2*x*y*z + x y |--> -y^2*z - x*z^2 + y z |--> z - sage: (tau * sigma).is_identity() + sage: (tau * sigma).is_identity() # optional - sage.libs.singular True We compute the triangular automorphism that converts moments to @@ -1407,37 +1428,37 @@ cdef class RingHomomorphism(RingMap): x1^5 + 10*x1^3*x2 + 15*x1*x2^2 + 10*x1^2*x3 + 10*x2*x3 + 5*x1*x4 + x5] sage: all(p.is_homogeneous() for p in phi.im_gens()) True - sage: phi.inverse().im_gens()[:5] + sage: phi.inverse().im_gens()[:5] # optional - sage.libs.singular [x1, -x1^2 + x2, 2*x1^3 - 3*x1*x2 + x3, -6*x1^4 + 12*x1^2*x2 - 3*x2^2 - 4*x1*x3 + x4, 24*x1^5 - 60*x1^3*x2 + 30*x1*x2^2 + 20*x1^2*x3 - 10*x2*x3 - 5*x1*x4 + x5] - sage: (phi.inverse() * phi).is_identity() + sage: (phi.inverse() * phi).is_identity() # optional - sage.libs.singular True Automorphisms of number fields as well as Galois fields are supported:: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]) - sage: (c.inverse() * c).is_identity() + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]) # optional - sage.rings.number_field + sage: (c.inverse() * c).is_identity() # optional - sage.rings.number_field True - sage: F. = GF(7^3) - sage: f = F.hom(t^7, F) - sage: (f.inverse() * f).is_identity() + sage: F. = GF(7^3) # optional - sage.rings.finite_rings + sage: f = F.hom(t^7, F) # optional - sage.rings.finite_rings + sage: (f.inverse() * f).is_identity() # optional - sage.rings.finite_rings True An isomorphism between the algebraic torus and the circle over a number field:: - sage: K. = QuadraticField(-1) - sage: A. = K['z,w'].quotient('z*w - 1') - sage: B. = K['x,y'].quotient('x^2 + y^2 - 1') - sage: f = A.hom([x + i*y, x - i*y], B) - sage: g = f.inverse() - sage: g.morphism_from_cover().im_gens() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: A. = K['z,w'].quotient('z*w - 1') # optional - sage.rings.number_field + sage: B. = K['x,y'].quotient('x^2 + y^2 - 1') # optional - sage.rings.number_field + sage: f = A.hom([x + i*y, x - i*y], B) # optional - sage.rings.number_field + sage: g = f.inverse() # optional - sage.rings.number_field + sage: g.morphism_from_cover().im_gens() # optional - sage.rings.number_field [1/2*z + 1/2*w, (-1/2*i)*z + (1/2*i)*w] - sage: all(g(f(z)) == z for z in A.gens()) + sage: all(g(f(z)) == z for z in A.gens()) # optional - sage.rings.number_field True TESTS: @@ -1445,43 +1466,43 @@ cdef class RingHomomorphism(RingMap): Morphisms involving quotient rings:: sage: R. = QQ[] - sage: S. = QQ['s,u,t'].quotient('u-t^2') - sage: f = R.hom([s, -t], S) - sage: (f.inverse() * f).is_identity() + sage: S. = QQ['s,u,t'].quotient('u-t^2') # optional - sage.libs.singular + sage: f = R.hom([s, -t], S) # optional - sage.libs.singular + sage: (f.inverse() * f).is_identity() # optional - sage.libs.singular True - sage: Q. = R.quotient(x-y^2) - sage: g = Q.hom([v, -w], Q) - sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w + sage: Q. = R.quotient(x - y^2) # optional - sage.libs.singular + sage: g = Q.hom([v, -w], Q) # optional - sage.libs.singular + sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w # optional - sage.libs.singular True sage: S. = QQ[] - sage: h = Q.hom([z^2, -z], S) - sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w + sage: h = Q.hom([z^2, -z], S) # optional - sage.libs.singular + sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w # optional - sage.libs.singular True Morphisms between number fields and quotient rings:: - sage: K. = QuadraticField(2) - sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) - sage: (f.inverse() * f).is_identity() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) # optional - sage.rings.number_field + sage: (f.inverse() * f).is_identity() # optional - sage.rings.number_field True - sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) - sage: (g.inverse() * g).is_identity() + sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) # optional - sage.rings.number_field + sage: (g.inverse() * g).is_identity() # optional - sage.rings.number_field True Morphisms involving Galois fields:: - sage: A. = GF(7^3) - sage: R = A.polynomial_ring().quotient(A.polynomial()) - sage: g = A.hom(R.gens(), R) - sage: (g.inverse() * g).is_identity() + sage: A. = GF(7^3) # optional - sage.rings.finite_rings + sage: R = A.polynomial_ring().quotient(A.polynomial()) # optional - sage.rings.finite_rings + sage: g = A.hom(R.gens(), R) # optional - sage.rings.finite_rings + sage: (g.inverse() * g).is_identity() # optional - sage.rings.finite_rings True - sage: B., f = A.extension(3, map=True) - sage: f.inverse() + sage: B., f = A.extension(3, map=True) # optional - sage.rings.finite_rings + sage: f.inverse() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: B., f = A.extension(1, map=True) - sage: f.inverse() + sage: B., f = A.extension(1, map=True) # optional - sage.rings.finite_rings + sage: f.inverse() # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in T of size 7^3 To: Finite Field in t of size 7^3 @@ -1491,7 +1512,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: S. = QQ[] - sage: S.hom([x, y, 0], R).inverse() + sage: S.hom([x, y, 0], R).inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1500,12 +1521,12 @@ cdef class RingHomomorphism(RingMap): Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q. = R.quotient([x^5, y^4]) - sage: R.hom([u, v], Q).inverse() + sage: Q. = R.quotient([x^5, y^4]) # optional - sage.libs.singular + sage: R.hom([u, v], Q).inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q.cover().inverse() + sage: Q.cover().inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1519,23 +1540,23 @@ cdef class RingHomomorphism(RingMap): A homomorphism over ``QQbar``:: - sage: R. = QQbar[] - sage: f = R.hom([x + QQbar(I)*y^2, -y], R) - sage: (f.inverse() * f).is_identity() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = R.hom([x + QQbar(I)*y^2, -y], R) # optional - sage.rings.number_field + sage: (f.inverse() * f).is_identity() # optional - sage.rings.number_field True Check that results are cached:: - sage: R. = GF(823)[] - sage: f = R.hom([x, y+x^2], R) - sage: f.inverse() is f.inverse() + sage: R. = GF(823)[] # optional - sage.rings.finite_rings + sage: f = R.hom([x, y+x^2], R) # optional - sage.rings.finite_rings + sage: f.inverse() is f.inverse() # optional - sage.rings.finite_rings True Some subclasses of ring homomorphisms are not supported:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) - sage: FrobeniusEndomorphism_generic(K).inverse() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K).inverse() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1562,11 +1583,11 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([x + 123*y^2, y], R) - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular False - sage: f.is_injective() + sage: f.is_injective() # optional - sage.libs.singular True - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular True """ if not self.is_injective(): @@ -1586,9 +1607,9 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = GF(17)[] - sage: f = R.hom([3*x, y + x^2 + x^3], R) - sage: (f * ~f).is_identity() + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = R.hom([3*x, y + x^2 + x^3], R) # optional - sage.rings.finite_rings + sage: (f * ~f).is_identity() # optional - sage.rings.finite_rings True """ return self.inverse() @@ -1600,10 +1621,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_surjective() + sage: R.hom([y*z, x*z, x*y], R).is_surjective() # optional - sage.libs.singular False - sage: Q. = R.quotient(x*y*z - 1) - sage: R.hom([y*z, x*z, x*y], Q).is_surjective() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: R.hom([y*z, x*z, x*y], Q).is_surjective() # optional - sage.libs.singular True ALGORITHM: @@ -1624,10 +1645,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_invertible() + sage: R.hom([y*z, x*z, x*y], R).is_invertible() # optional - sage.libs.singular False - sage: Q. = R.quotient(x*y*z - 1) - sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() # optional - sage.libs.singular True ALGORITHM: @@ -1760,7 +1781,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: phi = R.hom([x,x+y]); phi + sage: phi = R.hom([x, x + y]); phi Ring endomorphism of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x y |--> x + y @@ -1769,33 +1790,34 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): Here's another example where the domain isn't free:: - sage: S. = R.quotient(x - y) - sage: phi = S.hom([xx+1,xx+1]) + sage: S. = R.quotient(x - y) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx + 1]) # optional - sage.libs.singular Note that one has to specify valid images:: - sage: phi = S.hom([xx+1,xx-1]) + sage: phi = S.hom([xx + 1, xx - 1]) # optional - sage.libs.singular 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 You can give a map of the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = K[] - sage: z = 1 + i*t + (3+4*i)*t^2 - sage: z._im_gens_(R, [t^2], base_map=cc) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: z = 1 + i*t + (3+4*i)*t^2 # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field (-4*i + 3)*t^4 - i*t^2 + 1 The base map's codomain is extended to the whole codomain:: sage: S. = QQ[] sage: T. = S[] - sage: cc = S.hom([x+1]) - sage: f = T.hom([x-y], base_map=cc) - sage: g = T.hom([x-y], base_map=cc.extend_codomain(T)) + sage: cc = S.hom([x + 1]) + sage: f = T.hom([x - y], base_map=cc) + sage: g = T.hom([x - y], base_map=cc.extend_codomain(T)) sage: f == g True sage: f.base_map() == cc.extend_codomain(T) @@ -1806,11 +1828,12 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): speed up creation of a homomorphism:: sage: R. = QQ[] - sage: S. = R.quotient(x - y) - sage: phi = S.hom([xx+1,xx-1], check=False) + sage: S. = R.quotient(x - y) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx - 1], check=False) # optional - sage.libs.singular 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 """ RingHomomorphism.__init__(self, parent) if not isinstance(im_gens, sage.structure.sequence.Sequence_generic): @@ -1848,7 +1871,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: f.im_gens() [x, x + y] @@ -1869,28 +1892,31 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: phi = S.hom([y^2], base_map=cc) - sage: phi - Ring endomorphism of Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field + sage: phi # optional - sage.rings.number_field + Ring endomorphism of Univariate Polynomial Ring in y + over Number Field in i with defining polynomial x^2 + 1 Defn: y |--> y^2 with map of base ring - sage: phi(y) + sage: phi(y) # optional - sage.rings.number_field y^2 - sage: phi(i*y) + sage: phi(i*y) # optional - sage.rings.number_field -i*y^2 - sage: phi.base_map() + sage: phi.base_map() # optional - sage.rings.number_field Composite map: From: Number Field in i with defining polynomial x^2 + 1 - To: Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + To: Univariate Polynomial Ring in y over Number Field in i + with defining polynomial x^2 + 1 Defn: Ring endomorphism of Number Field in i with defining polynomial x^2 + 1 Defn: i |--> -i then Polynomial base injection morphism: From: Number Field in i with defining polynomial x^2 + 1 - To: Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + To: Univariate Polynomial Ring in y over Number Field in i + with defining polynomial x^2 + 1 """ return self._base_map @@ -1901,7 +1927,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: g = copy(f) # indirect doctest sage: g == f True @@ -1921,7 +1947,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: g = copy(f) # indirect doctest sage: g == f True @@ -1942,51 +1968,51 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A single variate quotient over `\QQ`:: sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) - sage: f1 = R.hom([a]) - sage: f2 = R.hom([a + a^2 + a + 1]) - sage: f1 == f2 + sage: Q. = R.quotient(x^2 + x + 1) # optional - sage.libs.pari + sage: f1 = R.hom([a]) # optional - sage.libs.pari + sage: f2 = R.hom([a + a^2 + a + 1]) # optional - sage.libs.pari + sage: f1 == f2 # optional - sage.libs.pari True - sage: f1 == R.hom([a^2]) + sage: f1 == R.hom([a^2]) # optional - sage.libs.pari False - sage: f1(x^3 + x) + sage: f1(x^3 + x) # optional - sage.libs.pari a + 1 - sage: f2(x^3 + x) + sage: f2(x^3 + x) # optional - sage.libs.pari a + 1 TESTS:: - sage: loads(dumps(f2)) == f2 + sage: loads(dumps(f2)) == f2 # optional - sage.libs.pari True :: - sage: R. = QQ[]; f = R.hom([x,x+y]); g = R.hom([y,x]) - sage: f == g # indirect doctest + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) # optional - sage.libs.pari + sage: f == g # indirect doctest # optional - sage.libs.pari False EXAMPLES: A multivariate quotient over a finite field:: - sage: R. = GF(7)[] - sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) - sage: f1 = R.hom([a, b]) - sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) - sage: f1 == f2 + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) # optional - sage.rings.finite_rings + sage: f1 = R.hom([a, b]) # optional - sage.rings.finite_rings + sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) # optional - sage.rings.finite_rings + sage: f1 == f2 # optional - sage.rings.finite_rings True - sage: f1 == R.hom([b,a]) + sage: f1 == R.hom([b, a]) # optional - sage.rings.finite_rings False - sage: x^3 + x + y^2 + sage: x^3 + x + y^2 # optional - sage.rings.finite_rings x^3 + y^2 + x - sage: f1(x^3 + x + y^2) + sage: f1(x^3 + x + y^2) # optional - sage.rings.finite_rings a - b - sage: f2(x^3 + x + y^2) + sage: f2(x^3 + x + y^2) # optional - sage.rings.finite_rings a - b TESTS:: - sage: loads(dumps(f2)) == f2 + sage: loads(dumps(f2)) == f2 # optional - sage.rings.finite_rings True This was fixed in :trac:`24277`:: @@ -2078,8 +2104,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: Pf = PR.hom(f,PS) sage: Pf Ring morphism: - From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Rational Field + To: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field @@ -2093,44 +2121,54 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): Similarly, we can construct the induced homomorphism on a matrix ring over our polynomial rings:: - sage: MR = MatrixSpace(R,2,2) - sage: MS = MatrixSpace(S,2,2) - sage: M = MR([x^2 + 1/7*x*y - y^2, - 1/2*y^2 + 2*y + 1/6, 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) - sage: Mf = MR.hom(f,MS) - sage: Mf + sage: MR = MatrixSpace(R, 2, 2) # optional - sage.modules + sage: MS = MatrixSpace(S, 2, 2) # optional - sage.modules + sage: M = MR([x^2 + 1/7*x*y - y^2, -1/2*y^2 + 2*y + 1/6, # optional - sage.modules + ....: 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) + sage: Mf = MR.hom(f, MS) # optional - sage.modules + sage: Mf # optional - sage.modules Ring morphism: - From: Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field - To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in z over Rational Field + From: Full MatrixSpace of 2 by 2 dense matrices + over Multivariate Polynomial Ring in x, y over Rational Field + To: Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Univariate Polynomial Ring in z over Rational Field Defn: x |--> 2*z y |--> 3*z - sage: Mf(M) + sage: Mf(M) # optional - sage.modules [ -29/7*z^2 -9/2*z^2 + 6*z + 1/6] [ 16*z^2 - 28*z 9/2*z^2 + 131/22*z] The construction of induced homomorphisms is recursive, and so we have:: - sage: MPR = MatrixSpace(PR, 2) - sage: MPS = MatrixSpace(PS, 2) - sage: M = MPR([(- x + y)*t^2 + 58*t - 3*x^2 + x*y, (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, (x + 6*y + 1)*t^2]) - sage: MPf = MPR.hom(f,MPS); MPf + sage: MPR = MatrixSpace(PR, 2) # optional - sage.modules + sage: MPS = MatrixSpace(PS, 2) # optional - sage.modules + sage: M = MPR([(-x + y)*t^2 + 58*t - 3*x^2 + x*y, # optional - sage.modules + ....: (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, + ....: (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, + ....: (x + 6*y + 1)*t^2]) + sage: MPf = MPR.hom(f, MPS); MPf # optional - sage.modules Ring morphism: - From: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial + Ring in t over Multivariate Polynomial Ring in x, y over Rational Field + To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial + Ring in t over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: - From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Rational Field + To: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Univariate Polynomial Ring in z over Rational Field Defn: x |--> 2*z y |--> 3*z - sage: MPf(M) + sage: MPf(M) # optional - sage.modules [ z*t^2 + 58*t - 6*z^2 (-6/7*z^2 - 1/20*z)*t^2 + 29*z^2*t + 6*z] [ (-z + 1)*t^2 + 11*z^2 + 15/2*z + 1/4 (20*z + 1)*t^2] """ @@ -2142,11 +2180,12 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: from sage.rings.morphism import RingHomomorphism_from_base sage: R. = ZZ[] - sage: f = R.hom([2*x],R) - sage: P = MatrixSpace(R,2).Hom(MatrixSpace(R,2)) - sage: g = RingHomomorphism_from_base(P,f) - sage: g - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + sage: f = R.hom([2*x], R) + sage: P = MatrixSpace(R, 2).Hom(MatrixSpace(R, 2)) # optional - sage.modules + sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules + sage: g # optional - sage.modules + Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring Defn: Induced from base ring by Ring endomorphism of Univariate Polynomial Ring in x over Integer Ring Defn: x |--> 2*x @@ -2155,11 +2194,13 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): codomain are constructed in a compatible way. So, the following results in an error:: - sage: P = MatrixSpace(R,2).Hom(R['t']) - sage: g = RingHomomorphism_from_base(P,f) + sage: P = MatrixSpace(R, 2).Hom(R['t']) # optional - sage.modules + sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules Traceback (most recent call last): ... - ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring) and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring) must have the same functorial construction over their base rings + ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring) + and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring) + must have the same functorial construction over their base rings """ RingHomomorphism.__init__(self, parent) if underlying.domain() != parent.domain().base(): @@ -2178,11 +2219,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([2*z,3*z],S) - sage: MR = MatrixSpace(R,2) - sage: MS = MatrixSpace(S,2) - sage: g = MR.hom(f,MS) - sage: g.underlying_map() == f + sage: f = R.hom([2*z, 3*z], S) + sage: MR = MatrixSpace(R, 2) # optional - sage.modules + sage: MS = MatrixSpace(S, 2) # optional - sage.modules + sage: g = MR.hom(f, MS) # optional - sage.modules + sage: g.underlying_map() == f # optional - sage.modules True """ return self._underlying @@ -2195,10 +2236,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([2*z,3*z],S) + sage: f = R.hom([2*z, 3*z],S) sage: PR. = R[] sage: PS = S['t'] - sage: phi = PR.hom(f,PS) + sage: phi = PR.hom(f, PS) sage: type(phi) sage: psi = copy(phi); psi # indirect doctest @@ -2256,24 +2297,24 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): `\QQ`:: sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) - sage: f1 = R.hom([a]) - sage: f2 = R.hom([a + a^2 + a + 1]) - sage: PR. = R[] - sage: PQ = Q['s','t'] - sage: f1P = PR.hom(f1,PQ) - sage: f2P = PR.hom(f2,PQ) - sage: f1P == f2P + sage: Q. = R.quotient(x^2 + x + 1) # optional - sage.libs.pari sage.modules + sage: f1 = R.hom([a]) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f2 = R.hom([a + a^2 + a + 1]) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: PR. = R[] # optional - sage.libs.pari sage.libs.singular sage.modules + sage: PQ = Q['s','t'] # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P = PR.hom(f1,PQ) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f2P = PR.hom(f2,PQ) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P == f2P # optional - sage.libs.pari sage.libs.singular sage.modules True TESTS:: - sage: f1P == loads(dumps(f1P)) + sage: f1P == loads(dumps(f1P)) # optional - sage.libs.pari sage.libs.singular sage.modules True - sage: R. = QQ[]; f = R.hom([x,x+y]); g = R.hom([y,x]) + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) sage: S. = R[] - sage: fS = S.hom(f,S); gS = S.hom(g,S) + sage: fS = S.hom(f, S); gS = S.hom(g, S) sage: fS != gS # indirect doctest True @@ -2281,20 +2322,20 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A matrix ring over a multivariate quotient over a finite field:: - sage: R. = GF(7)[] - sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) - sage: f1 = R.hom([a, b]) - sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) - sage: MR = MatrixSpace(R,2) - sage: MQ = MatrixSpace(Q,2) - sage: f1M = MR.hom(f1,MQ) - sage: f2M = MR.hom(f2,MQ) - sage: f1M == f2M + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) # optional - sage.rings.finite_rings + sage: f1 = R.hom([a, b]) # optional - sage.rings.finite_rings + sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) # optional - sage.rings.finite_rings + sage: MR = MatrixSpace(R, 2) # optional - sage.rings.finite_rings sage.modules + sage: MQ = MatrixSpace(Q, 2) # optional - sage.rings.finite_rings sage.modules + sage: f1M = MR.hom(f1, MQ) # optional - sage.rings.finite_rings sage.modules + sage: f2M = MR.hom(f2, MQ) # optional - sage.rings.finite_rings sage.modules + sage: f1M == f2M # optional - sage.rings.finite_rings sage.modules True TESTS:: - sage: f1M == loads(dumps(f1M)) + sage: f1M == loads(dumps(f1M)) # optional - sage.rings.finite_rings sage.modules True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2314,11 +2355,12 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): over a multivariate polynomial ring:: sage: R1. = ZZ[] - sage: f = R1.hom([x+y,x-y]) - sage: R2 = MatrixSpace(FractionField(R1)['t'],2) - sage: g = R2.hom(f,R2) - sage: g #indirect doctest - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring + sage: f = R1.hom([x + y, x - y]) + sage: R2 = MatrixSpace(FractionField(R1)['t'], 2) # optional - sage.modules + sage: g = R2.hom(f, R2) # optional - sage.modules + sage: g #indirect doctest # optional - sage.modules + Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by Ring endomorphism of Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by @@ -2364,11 +2406,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([a+b, a-b], S) + sage: f = R.hom([a + b, a - b], S) # optional - sage.libs.singular sage: PR. = R[] sage: PS = S['t'] - sage: Pf = PR.hom(f, PS) - sage: Pf.inverse() + sage: Pf = PR.hom(f, PS) # optional - sage.libs.singular + sage: Pf.inverse() # optional - sage.libs.singular Ring morphism: From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field @@ -2380,7 +2422,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): To: Multivariate Polynomial Ring in x, y over Rational Field Defn: a |--> 1/2*x + 1/2*y b |--> 1/2*x - 1/2*y - sage: Pf.inverse()(Pf(x*t^2 + y*t)) + sage: Pf.inverse()(Pf(x*t^2 + y*t)) # optional - sage.libs.singular x*t^2 + y*t """ return self.parent().reversed()(self._underlying.inverse()) @@ -2394,8 +2436,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([x^2]) - sage: g = f.extend_to_fraction_field() - sage: type(g) + sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular + sage: type(g) # optional - sage.libs.singular """ def __init__(self, parent, morphism): @@ -2404,10 +2446,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: - sage: A. = ZZ.extension(x^2 - 2) - sage: f = A.coerce_map_from(ZZ) - sage: g = f.extend_to_fraction_field() # indirect doctest - sage: g + sage: x = polygen(ZZ, 'x') + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: f = A.coerce_map_from(ZZ) # optional - sage.rings.number_field + sage: g = f.extend_to_fraction_field() # indirect doctest # optional - sage.rings.number_field + sage: g # optional - sage.rings.number_field Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^2 - 2 @@ -2422,11 +2465,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x^2]).extend_to_fraction_field() - sage: f + sage: f = S.hom([x^2]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x^2 - sage: f._repr_defn() + sage: f._repr_defn() # optional - sage.libs.singular 'x |--> x^2' """ return self._morphism._repr_defn() @@ -2442,10 +2485,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() - sage: f(1/x) + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f(1/x) # optional - sage.libs.singular 1/(x + 1) - sage: f(1/(x-1)) + sage: f(1/(x-1)) # optional - sage.libs.singular 1/x """ return self._morphism(x.numerator()) / self._morphism(x.denominator()) @@ -2457,12 +2500,12 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular - sage: g = copy(f) # indirect doctest - sage: f == g + sage: g = copy(f) # indirect doctest # optional - sage.libs.singular + sage: f == g # optional - sage.libs.singular True - sage: f is g + sage: f is g # optional - sage.libs.singular False """ self._morphism = _slots['_morphism'] @@ -2475,8 +2518,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() - sage: loads(dumps(f)) == f + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: loads(dumps(f)) == f # optional - sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2492,10 +2535,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([2*x - 1]) - sage: g = f.extend_to_fraction_field() - sage: g.inverse() + sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular + sage: g.inverse() # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring - in x over Rational Field + in x over Rational Field Defn: x |--> 1/2*x + 1/2 """ return self.parent().reversed()(self._morphism.inverse()) @@ -2508,13 +2551,14 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover(); phi + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover(); phi # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) Defn: Natural quotient map - sage: phi(x+y) + sage: phi(x + y) # optional - sage.libs.singular a + b """ def __init__(self, parent): @@ -2561,7 +2605,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): sage: f(1/2) Traceback (most recent call last): ... - TypeError: 1/2 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 1/2 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented """ return self.codomain()(x) @@ -2599,11 +2644,11 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover() - sage: phi == loads(dumps(phi)) + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover() # optional - sage.libs.singular + sage: phi == loads(dumps(phi)) # optional - sage.libs.singular True - sage: phi == R.quo(x^2 + y^3).cover() + sage: phi == R.quo(x^2 + y^3).cover() # optional - sage.libs.singular False """ if not isinstance(other, RingHomomorphism_cover): @@ -2619,13 +2664,13 @@ cdef class RingHomomorphism_cover(RingHomomorphism): TESTS:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover() - sage: type(phi) + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover() # optional - sage.libs.singular + sage: type(phi) # optional - sage.libs.singular - sage: hash(phi) == hash(phi) + sage: hash(phi) == hash(phi) # optional - sage.libs.singular True - sage: {phi: 1}[phi] + sage: {phi: 1}[phi] # optional - sage.libs.singular 1 """ return hash((self.domain(), self.codomain())) @@ -2640,12 +2685,12 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: R. = QQ['x,y'].quotient('x^2 * y^2') - sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) + sage: R. = QQ['x,y'].quotient('x^2 * y^2') # optional - sage.libs.singular + sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) # optional - sage.libs.singular Ideal (x^2*y^2, x^3, y^3 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: S. = QQbar['u,v'].quotient('u^4 - 1') - sage: S.cover().inverse_image(S.ideal(u^2 - 1)) + sage: S. = QQbar['u,v'].quotient('u^4 - 1') # optional - sage.libs.singular + sage: S.cover().inverse_image(S.ideal(u^2 - 1)) # optional - sage.libs.singular Ideal (u^4 - 1, u^2 - 1) of Multivariate Polynomial Ring in u, v over Algebraic Field """ @@ -2660,8 +2705,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: Q. = QQ['x,y'].quotient('x + y') - sage: Q.cover().inverse_image(u) + sage: Q. = QQ['x,y'].quotient('x + y') # optional - sage.libs.singular + sage: Q.cover().inverse_image(u) # optional - sage.libs.singular -y """ return b.lift() @@ -2690,25 +2735,27 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: loads(dumps(phi)) == phi + sage: loads(dumps(phi)) == phi # optional - sage.libs.singular True Validity of the homomorphism is determined, when possible, and a ``TypeError`` is raised if there is no homomorphism sending the generators to the given images:: - sage: S.hom([b^2, c^2, a^2]) + sage: S.hom([b^2, c^2, a^2]) # optional - sage.libs.singular 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 """ def __init__(self, parent, phi): """ @@ -2716,8 +2763,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2, y^2) Defn: xx |--> yy yy |--> xx """ @@ -2743,20 +2791,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest - sage: psi == phi + sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular + sage: psi == phi # optional - sage.libs.singular True - sage: psi is phi + sage: psi is phi # optional - sage.libs.singular False - sage: psi(a) == phi(a) + sage: psi(a) == phi(a) # optional - sage.libs.singular True """ @@ -2770,20 +2819,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest - sage: psi == phi + sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular + sage: psi == phi # optional - sage.libs.singular True - sage: psi is phi + sage: psi is phi # optional - sage.libs.singular False - sage: psi(a) == phi(a) + sage: psi(a) == phi(a) # optional - sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2797,8 +2847,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.hom([yy,xx]) - sage: f._phi() + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy,xx]) # optional - sage.libs.singular + sage: f._phi() # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) @@ -2814,11 +2864,12 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]) - sage: S.hom([yy,xx]).morphism_from_cover() + sage: R. = QQ[]; S. = R.quo([x^2, y^2]) # optional - sage.libs.singular + sage: S.hom([yy,xx]).morphism_from_cover() # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + To: Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2, y^2) Defn: x |--> yy y |--> xx """ @@ -2830,14 +2881,14 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = PolynomialRing(GF(19), 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]) - sage: psi = S.hom([c, b, a]) - sage: f = S.hom([b, c, a + a^3 + b^3 + c^3]) - sage: phi == psi + sage: R. = PolynomialRing(GF(19), 3) # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.rings.finite_rings + sage: phi = S.hom([b, c, a]) # optional - sage.rings.finite_rings + sage: psi = S.hom([c, b, a]) # optional - sage.rings.finite_rings + sage: f = S.hom([b, c, a + a^3 + b^3 + c^3]) # optional - sage.rings.finite_rings + sage: phi == psi # optional - sage.rings.finite_rings False - sage: phi == f + sage: phi == f # optional - sage.rings.finite_rings True """ if not isinstance(other, RingHomomorphism_from_quotient): @@ -2854,14 +2905,14 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = PolynomialRing(GF(19), 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]) - sage: type(phi) + sage: R. = PolynomialRing(GF(19), 3) # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.rings.finite_rings + sage: phi = S.hom([b, c, a]) # optional - sage.rings.finite_rings + sage: type(phi) # optional - sage.rings.finite_rings - sage: hash(phi) == hash(phi) + sage: hash(phi) == hash(phi) # optional - sage.rings.finite_rings True - sage: {phi: 1}[phi] + sage: {phi: 1}[phi] # optional - sage.rings.finite_rings 1 """ return hash(self.phi) @@ -2872,9 +2923,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]) - sage: f = S.hom([yy,xx]) - sage: print(f._repr_defn()) + sage: R. = QQ[]; S. = R.quo([x^2,y^2]) # optional - sage.libs.singular + sage: f = S.hom([yy, xx]) # optional - sage.libs.singular + sage: print(f._repr_defn()) # optional - sage.libs.singular xx |--> yy yy |--> xx """ @@ -2889,8 +2940,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.hom([yy,xx]) - sage: f(3*x + (1/2)*y) # indirect doctest + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy, xx]) # optional - sage.libs.singular + sage: f(3*x + (1/2)*y) # indirect doctest # optional - sage.libs.singular 1/2*xx + 3*yy """ return self.phi(self.lift(x)) @@ -2917,11 +2968,13 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): TESTS:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) - sage: FrobeniusEndomorphism_generic(K) - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: FrobeniusEndomorphism_generic(K, 2) - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K) # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: FrobeniusEndomorphism_generic(K, 2) # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 """ from .ring import CommutativeRing from sage.categories.homset import Hom @@ -2948,10 +3001,10 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(5)['T']) - sage: phi = K.frobenius_endomorphism() - sage: psi = copy(phi) - sage: phi == psi + sage: K = Frac(GF(5)['T']) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: psi = copy(phi) # optional - sage.rings.finite_rings + sage: phi == psi # optional - sage.rings.finite_rings True """ self._p = _slots['_domain'].characteristic() @@ -2968,14 +3021,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(25)['T']) - sage: phi = K.frobenius_endomorphism(2) - sage: phi - Frobenius endomorphism x |--> x^(5^2) of Fraction Field of Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 + sage: K = Frac(GF(25)['T']) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism(2) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Fraction Field of + Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - sage: psi = loads(dumps(phi)); psi - Frobenius endomorphism x |--> x^(5^2) of Fraction Field of Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - sage: phi == psi + sage: psi = loads(dumps(phi)); psi # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Fraction Field of + Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 + sage: phi == psi # optional - sage.rings.finite_rings True """ slots = RingHomomorphism._extra_slots(self) @@ -2988,12 +3043,14 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 - sage: Frob._repr_() - 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5' + sage: Frob._repr_() # optional - sage.rings.finite_rings + 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5' """ if self._power == 0: s = "Identity endomorphism" @@ -3010,11 +3067,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob._repr_short() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob._repr_short() # optional - sage.rings.finite_rings 'Frob' - sage: (Frob^2)._repr_short() + sage: (Frob^2)._repr_short() # optional - sage.rings.finite_rings 'Frob^2' """ if self._power == 0: @@ -3031,9 +3088,9 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(2) - sage: Frob._latex_() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(2) # optional - sage.rings.finite_rings + sage: Frob._latex_() # optional - sage.rings.finite_rings '\\verb"Frob"^{2}' """ if self._power == 0: @@ -3048,11 +3105,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): """ TESTS:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob(u) + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob(u) # optional - sage.rings.finite_rings u^5 - sage: (Frob^2)(1+u) + sage: (Frob^2)(1 + u) # optional - sage.rings.finite_rings 1 + u^25 """ return x ** self._q @@ -3065,11 +3122,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob.power() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob.power() # optional - sage.rings.finite_rings 1 - sage: (Frob^9).power() + sage: (Frob^9).power() # optional - sage.rings.finite_rings 9 """ return self._power @@ -3080,11 +3137,13 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: Frob^2 - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: Frob^2 # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 """ return self.__class__(self.domain(), self.power()*n) @@ -3094,13 +3153,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: f = K.frobenius_endomorphism(); f - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: g = K.frobenius_endomorphism(2); g - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 - sage: f * g - Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = K.frobenius_endomorphism(); f # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: g = K.frobenius_endomorphism(2); g # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 + sage: f * g # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u + over Finite Field of size 5 """ if isinstance(right, FrobeniusEndomorphism_generic): return self.__class__(self.domain(), self._power + right.power()) @@ -3140,15 +3202,15 @@ def _tensor_product_ring(B, A): sage: from sage.rings.morphism import _tensor_product_ring sage: R. = QQ[] - sage: S. = R.quotient(x^2 + y^2) - sage: Q = _tensor_product_ring(S, R); Q + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: Q = _tensor_product_ring(S, R); Q # optional - sage.libs.singular Quotient of Multivariate Polynomial Ring in u, v, x, y over Rational Field by the ideal (u^2 + v^2) - sage: Q.term_order() + sage: Q.term_order() # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Degree reverse lexicographic term order of length 2) - sage: _tensor_product_ring(R, R) + sage: _tensor_product_ring(R, R) # optional - sage.libs.singular Multivariate Polynomial Ring in y0, y1, x0, x1 over Rational Field TESTS: diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 3ed94af4f02..8b1e862e50a 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -49,9 +49,9 @@ True sage: TestSuite(M).run() - sage: H = PowerSeriesRing(PolynomialRing(ZZ,3,'z'),4,'f'); H - Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate - Polynomial Ring in z0, z1, z2 over Integer Ring + sage: H = PowerSeriesRing(PolynomialRing(ZZ, 3, 'z'), 4, 'f'); H + Multivariate Power Series Ring in f0, f1, f2, f3 + over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: TestSuite(H).run() sage: loads(dumps(H)) is H True @@ -75,21 +75,21 @@ - Use angle-bracket notation:: - sage: S. = PowerSeriesRing(GF(65537)); S + sage: S. = PowerSeriesRing(GF(65537)); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s + sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s # optional - sage.rings.finite_rings -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + O(x, y)^5 - sage: s in S + sage: s in S # optional - sage.rings.finite_rings True - sage: TestSuite(S).run() - sage: loads(dumps(S)) is S + sage: TestSuite(S).run() # optional - sage.rings.finite_rings + sage: loads(dumps(S)) is S # optional - sage.rings.finite_rings True - Use double square bracket notation:: sage: ZZ[['s,t,u']] Multivariate Power Series Ring in s, t, u over Integer Ring - sage: GF(127931)[['x,y']] + sage: GF(127931)[['x,y']] # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 127931 Variable ordering determines how series are displayed. @@ -118,15 +118,15 @@ sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field sage: R.base_extend(RR) - Multivariate Power Series Ring in t, u, v over Real Field with 53 - bits of precision + Multivariate Power Series Ring in t, u, v + over Real Field with 53 bits of precision sage: R.change_ring(IntegerModRing(10)) - Multivariate Power Series Ring in t, u, v over Ring of integers - modulo 10 + Multivariate Power Series Ring in t, u, v + over Ring of integers modulo 10 - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) + sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 Coercion from polynomial ring:: @@ -159,19 +159,19 @@ Coercion from symbolic ring:: - sage: x,y = var('x,y') - sage: S = PowerSeriesRing(GF(11),2,'x,y'); S + sage: x,y = var('x,y') # optional - sage.symbolic + sage: S = PowerSeriesRing(GF(11),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: type(x) + sage: type(x) # optional - sage.symbolic - sage: type(S(x)) + sage: type(S(x)) # optional - sage.rings.finite_rings sage.symbolic - sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f + sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f # optional - sage.rings.finite_rings sage.symbolic 5 - x^2 + 4*x*y + y^2 + O(x, y)^3 - sage: f.parent() + sage: f.parent() # optional - sage.rings.finite_rings sage.symbolic Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: f.parent() == S + sage: f.parent() == S # optional - sage.rings.finite_rings sage.symbolic True The implementation of the multivariate power series ring uses a combination @@ -230,12 +230,12 @@ def is_MPowerSeriesRing(x): sage: from sage.rings.power_series_ring import is_PowerSeriesRing sage: from sage.rings.multi_power_series_ring import is_MPowerSeriesRing - sage: M = PowerSeriesRing(ZZ,4,'v') + sage: M = PowerSeriesRing(ZZ, 4, 'v') sage: is_PowerSeriesRing(M) False sage: is_MPowerSeriesRing(M) True - sage: T = PowerSeriesRing(RR,'v') + sage: T = PowerSeriesRing(RR, 'v') sage: is_PowerSeriesRing(T) True sage: is_MPowerSeriesRing(T) @@ -290,7 +290,7 @@ def __classcall__(cls, base_ring, num_gens, name_list, TESTS:: - sage: P1 = PowerSeriesRing(QQ, ['f0','f1','f2','f3'], order = TermOrder('degrevlex')) + sage: P1 = PowerSeriesRing(QQ, ['f0','f1','f2','f3'], order=TermOrder('degrevlex')) sage: P2 = PowerSeriesRing(QQ,4,'f', order='degrevlex') sage: P1 is P2 # indirect doctest True @@ -390,11 +390,11 @@ def _repr_(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) - sage: R #indirect doctest + sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R #indirect doctest # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 17 - sage: R.rename('my multivariate power series ring') - sage: R + sage: R.rename('my multivariate power series ring') # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings my multivariate power series ring """ if self.ngens() == 0: @@ -479,10 +479,10 @@ def characteristic(self): EXAMPLES:: - sage: H = PowerSeriesRing(GF(65537),4,'f'); H + sage: H = PowerSeriesRing(GF(65537),4,'f'); H # optional - sage.rings.finite_rings Multivariate Power Series Ring in f0, f1, f2, f3 over Finite Field of size 65537 - sage: H.characteristic() + sage: H.characteristic() # optional - sage.rings.finite_rings 65537 """ return self.base_ring().characteristic() @@ -493,12 +493,12 @@ def construction(self): EXAMPLES:: - sage: M = PowerSeriesRing(QQ,4,'f'); M + sage: M = PowerSeriesRing(QQ, 4, 'f'); M Multivariate Power Series Ring in f0, f1, f2, f3 over Rational Field sage: (c,R) = M.construction(); (c,R) (Completion[('f0', 'f1', 'f2', 'f3'), prec=12], - Multivariate Polynomial Ring in f0, f1, f2, f3 over Rational Field) + Multivariate Polynomial Ring in f0, f1, f2, f3 over Rational Field) sage: c Completion[('f0', 'f1', 'f2', 'f3'), prec=12] sage: c(R) @@ -555,10 +555,10 @@ def change_ring(self, R): TypeError: no base extension defined - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) + sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 """ return PowerSeriesRing(R, names = self.variable_names(), default_prec = self.default_prec()) @@ -576,16 +576,16 @@ def remove_var(self, *var): Power Series Ring in u over Integer Ring - sage: M = PowerSeriesRing(GF(5),5,'t'); M - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over - Finite Field of size 5 - sage: M.remove_var(M.gens()[3]) - Multivariate Power Series Ring in t0, t1, t2, t4 over Finite - Field of size 5 + sage: M = PowerSeriesRing(GF(5),5,'t'); M # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 5 + sage: M.remove_var(M.gens()[3]) # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t4 + over Finite Field of size 5 Removing all variables results in the base ring:: - sage: M.remove_var(*M.gens()) + sage: M.remove_var(*M.gens()) # optional - sage.rings.finite_rings Finite Field of size 5 """ @@ -634,10 +634,10 @@ def _coerce_impl(self, f): sage: R(f2) -2*v^2 + 5*u*v^2 + O(t, u, v)^6 - sage: R2 = R.change_ring(GF(2)) - sage: R2(f1) + sage: R2 = R.change_ring(GF(2)) # optional - sage.rings.finite_rings + sage: R2(f1) # optional - sage.rings.finite_rings v + t*v - sage: R2(f2) + sage: R2(f2) # optional - sage.rings.finite_rings u*v^2 + O(t, u, v)^6 TESTS:: @@ -674,8 +674,8 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = PowerSeriesRing(Zmod(8)); R - Multivariate Power Series Ring in a, b, c over Ring of integers - modulo 8 + Multivariate Power Series Ring in a, b, c + over Ring of integers modulo 8 sage: M = PowerSeriesRing(ZZ,3,'x,y,z') sage: M._is_valid_homomorphism_(R,[a,c,b]) True @@ -709,13 +709,13 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): from the base ring to the codomain:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: Q8. = CyclotomicField(8) - sage: X. = PowerSeriesRing(Q8) - sage: M. = PowerSeriesRing(K) - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: Q8. = CyclotomicField(8) # optional - sage.rings.number_field + sage: X. = PowerSeriesRing(Q8) # optional - sage.rings.number_field + sage: M. = PowerSeriesRing(K) # optional - sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion # optional - sage.rings.number_field False - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) # optional - sage.rings.number_field True """ try: @@ -757,32 +757,32 @@ def _coerce_map_from_(self, P): EXAMPLES:: - sage: A = GF(17)[['x','y']] - sage: A.has_coerce_map_from(ZZ) + sage: A = GF(17)[['x','y']] # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x']) + sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['y','x']) + sage: A.has_coerce_map_from(ZZ['y','x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ[['x']]) + sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ[['y','x']]) + sage: A.has_coerce_map_from(ZZ[['y','x']]) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x','z']) + sage: A.has_coerce_map_from(ZZ['x','z']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(GF(3)['x','y']) + sage: A.has_coerce_map_from(GF(3)['x','y']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) + sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) # optional - sage.rings.finite_rings False TESTS:: - sage: M = PowerSeriesRing(ZZ,3,'x,y,z') + sage: M = PowerSeriesRing(ZZ, 3, 'x,y,z') sage: M._coerce_map_from_(M) True - sage: M._coerce_map_from_(M.remove_var(x)) + sage: M._coerce_map_from_(M.remove_var(x)) # optional - sage.symbolic True - sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) + sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) # optional - sage.symbolic True sage: M._coerce_map_from_(PolynomialRing(ZZ,'x,z')) True @@ -800,7 +800,8 @@ def _coerce_map_from_(self, P): sage: P = PolynomialRing(ZZ,3,'z') sage: H = PowerSeriesRing(P,4,'f'); H - Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring + Multivariate Power Series Ring in f0, f1, f2, f3 over + Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: H._coerce_map_from_(P) True sage: H._coerce_map_from_(P.remove_var(P.gen(1))) @@ -919,11 +920,11 @@ def is_sparse(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,3,'s,t,u'); M + sage: M = PowerSeriesRing(ZZ, 3, 's,t,u'); M Multivariate Power Series Ring in s, t, u over Integer Ring sage: M.is_sparse() False - sage: N = PowerSeriesRing(ZZ,3,'s,t,u',sparse=True); N + sage: N = PowerSeriesRing(ZZ, 3, 's,t,u', sparse=True); N Sparse Multivariate Power Series Ring in s, t, u over Integer Ring sage: N.is_sparse() True @@ -936,11 +937,11 @@ def is_dense(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,3,'s,t,u'); M + sage: M = PowerSeriesRing(ZZ, 3, 's,t,u'); M Multivariate Power Series Ring in s, t, u over Integer Ring sage: M.is_dense() True - sage: N = PowerSeriesRing(ZZ,3,'s,t,u',sparse=True); N + sage: N = PowerSeriesRing(ZZ, 3, 's,t,u', sparse=True); N Sparse Multivariate Power Series Ring in s, t, u over Integer Ring sage: N.is_dense() False @@ -953,7 +954,7 @@ def gen(self, n=0): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,10,'v') + sage: M = PowerSeriesRing(ZZ, 10, 'v') sage: M.gen(6) v6 """ @@ -968,7 +969,7 @@ def ngens(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,10,'v') + sage: M = PowerSeriesRing(ZZ, 10, 'v') sage: M.ngens() 10 """ @@ -984,8 +985,8 @@ def prec_ideal(self): sage: A. = PowerSeriesRing(ZZ) sage: A.prec_ideal() - Ideal (s, t, u) of Multivariate Polynomial Ring in s, t, u over - Integer Ring + Ideal (s, t, u) of + Multivariate Polynomial Ring in s, t, u over Integer Ring """ return self._poly_ring().ideal(self._poly_ring().gens()) diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 978de36ce2d..98831b3b947 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -29,7 +29,7 @@ sage: f*g - g 2*s^2*t^2 + O(s, t)^5 - sage: f*=s; f + sage: f *= s; f s + 2*s^2 + 3*s^3 + O(s, t)^8 sage: f%2 s + s^3 + O(s, t)^8 @@ -56,43 +56,43 @@ sage: f = s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + R.O(5); f s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + O(s, t)^5 - sage: f(t,s) + sage: f(t, s) s*t + t^2 + s*t^2 + t^3 + 3*s*t^3 + 3*t^4 + O(s, t)^5 - sage: f(t^2,s^2) + sage: f(t^2, s^2) s^2*t^2 + t^4 + s^2*t^4 + t^6 + 3*s^2*t^6 + 3*t^8 + O(s, t)^10 Substitution is defined only for elements of positive valuation, unless `f` has infinite precision:: - sage: f(t^2,s^2+1) + sage: f(t^2, s^2 + 1) Traceback (most recent call last): ... TypeError: Substitution defined only for elements of positive valuation, unless self has infinite precision. sage: g = f.truncate() - sage: g(t^2,s^2+1) + sage: g(t^2, s^2 + 1) t^2 + s^2*t^2 + 2*t^4 + s^2*t^4 + 4*t^6 + 3*s^2*t^6 + 3*t^8 - sage: g(t^2,(s^2+1).O(3)) + sage: g(t^2, (s^2+1).O(3)) t^2 + s^2*t^2 + 2*t^4 + O(s, t)^5 0 has valuation ``+Infinity``:: - sage: f(t^2,0) + sage: f(t^2, 0) t^4 + t^6 + 3*t^8 + O(s, t)^10 - sage: f(t^2,s^2+s) + sage: f(t^2, s^2 + s) s*t^2 + s^2*t^2 + t^4 + O(s, t)^5 Substitution of power series with finite precision works too:: - sage: f(s.O(2),t) + sage: f(s.O(2), t) s^2 + s*t + O(s, t)^3 - sage: f(f,f) + sage: f(f, f) 2*s^4 + 4*s^3*t + 2*s^2*t^2 + 4*s^5 + 8*s^4*t + 4*s^3*t^2 + 16*s^6 + 34*s^5*t + 20*s^4*t^2 + 2*s^3*t^3 + O(s, t)^7 - sage: t(f,f) + sage: t(f, f) s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + O(s, t)^5 - sage: t(0,f) == s(f,0) + sage: t(0, f) == s(f, 0) True The ``subs`` syntax works as expected:: @@ -100,10 +100,10 @@ sage: r0 = -t^2 - s*t^3 - 2*t^6 + s^7 + s^5*t^2 + R.O(10) sage: r1 = s^4 - s*t^4 + s^6*t - 4*s^2*t^5 - 6*s^3*t^5 + R.O(10) sage: r2 = 2*s^3*t^2 - 2*s*t^4 - 2*s^3*t^4 + s*t^7 + R.O(10) - sage: r0.subs({t:r2,s:r1}) + sage: r0.subs({t: r2, s: r1}) -4*s^6*t^4 + 8*s^4*t^6 - 4*s^2*t^8 + 8*s^6*t^6 - 8*s^4*t^8 - 4*s^4*t^9 + 4*s^2*t^11 - 4*s^6*t^8 + O(s, t)^15 - sage: r0.subs({t:r2,s:r1}) == r0(r1,r2) + sage: r0.subs({t: r2, s: r1}) == r0(r1, r2) True Construct ring homomorphisms from one power series ring to another:: @@ -253,19 +253,19 @@ class MPowerSeries(PowerSeries): 1 + s + t - s*t + O(s, t)^5 - sage: T = PowerSeriesRing(GF(3),5,'t'); T - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite - Field of size 3 - sage: t = T.gens() - sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w + sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 3 + sage: t = T.gens() # optional - sage.rings.finite_rings + sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w # optional - sage.rings.finite_rings t0 + t1*t3 - t4^3 - t0^3*t2^2 - sage: w = w.add_bigoh(5); w + sage: w = w.add_bigoh(5); w # optional - sage.rings.finite_rings t0 + t1*t3 - t4^3 + O(t0, t1, t2, t3, t4)^5 - sage: w in T + sage: w in T # optional - sage.rings.finite_rings True - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) - sage: w + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.rings.finite_rings + sage: w # optional - sage.rings.finite_rings t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 @@ -274,20 +274,20 @@ class MPowerSeries(PowerSeries): sage: S.random_element(4) # random -2*t + t^2 - 12*s^3 + O(s, t)^4 - sage: T.random_element(10) # random + sage: T.random_element(10) # random # optional - sage.rings.finite_rings -t1^2*t3^2*t4^2 + t1^5*t3^3*t4 + O(t0, t1, t2, t3, t4)^10 Convert elements from polynomial rings:: - sage: R = PolynomialRing(ZZ,5,T.variable_names()) - sage: t = R.gens() - sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2 - sage: T(r) + sage: R = PolynomialRing(ZZ, 5, T.variable_names()) # optional - sage.libs.pari + sage: t = R.gens() # optional - sage.libs.pari + sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2 # optional - sage.libs.pari + sage: T(r) # optional - sage.libs.pari -t2*t3 + t3^2 + t4^2 - sage: r.parent() + sage: r.parent() # optional - sage.libs.pari Multivariate Polynomial Ring in t0, t1, t2, t3, t4 over Integer Ring - sage: r in T + sage: r in T # optional - sage.libs.pari True """ @@ -313,10 +313,11 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False): sage: g.parent() Multivariate Power Series Ring in s, t over Rational Field - sage: K = NumberField(x-3,'a') - sage: g = K.random_element()*f - sage: g.parent() - Multivariate Power Series Ring in s, t over Number Field in a with defining polynomial x - 3 + sage: K = NumberField(x - 3,'a') # optional - sage.rings.number_field + sage: g = K.random_element()*f # optional - sage.rings.number_field + sage: g.parent() # optional - sage.rings.number_field + Multivariate Power Series Ring in s, t over + Number Field in a with defining polynomial x - 3 TESTS:: @@ -449,20 +450,20 @@ def __call__(self, *x, **kwds): Checking that :trac:`15059` is fixed:: - sage: M. = PowerSeriesRing(GF(5)) - sage: s = M.hom([u, u+v]) - sage: s(M.one()) + sage: M. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: s = M.hom([u, u+v]) # optional - sage.rings.finite_rings + sage: s(M.one()) # optional - sage.rings.finite_rings 1 Since :trac:`26105` you can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = PowerSeriesRing(K) - sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = PowerSeriesRing(K) # optional - sage.rings.number_field + sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f # optional - sage.rings.number_field s^2 + i*s*t + (4*i + 3)*s^3 + O(s, t)^4 - sage: f(t, s, base_map=cc) + sage: f(t, s, base_map=cc) # optional - sage.rings.number_field (-i)*s*t + t^2 + (-4*i + 3)*t^3 + O(s, t)^4 """ if len(x) != self.parent().ngens(): @@ -565,14 +566,14 @@ def _value(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R + sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.rings.finite_rings Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = 1 + a + b - a*b + R.O(3); f + sage: f = 1 + a + b - a*b + R.O(3); f # optional - sage.rings.finite_rings 1 + a + b - a*b + O(a, b, c)^3 - sage: f._value() + sage: f._value() # optional - sage.rings.finite_rings 1 + a + b - a*b - sage: f._value().parent() + sage: f._value().parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in a, b, c over Finite Field of size 5 """ return self._go_to_fg(self._bg_value) @@ -601,15 +602,15 @@ def _latex_(self): EXAMPLES:: - sage: M = PowerSeriesRing(GF(5),3,'t'); M + sage: M = PowerSeriesRing(GF(5),3,'t'); M # optional - sage.rings.finite_rings Multivariate Power Series Ring in t0, t1, t2 over Finite Field of size 5 - sage: t = M.gens() - sage: f = -t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 \ - + 2*t[1]*t[2]^12 + 2*t[0]^7*t[1]^5*t[2]^2 + M.O(15) - sage: f + sage: t = M.gens() # optional - sage.rings.finite_rings + sage: f = (-t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 # optional - sage.rings.finite_rings + ....: + 2*t[1]*t[2]^12 + 2*t[0]^7*t[1]^5*t[2]^2 + M.O(15)) + sage: f # optional - sage.rings.finite_rings -t0^4*t1^3*t2^4 - 2*t0*t1^4*t2^7 + 2*t1*t2^12 + 2*t0^7*t1^5*t2^2 + O(t0, t1, t2)^15 - sage: f._latex_() + sage: f._latex_() # optional - sage.rings.finite_rings '-t_{0}^{4} t_{1}^{3} t_{2}^{4} + 3 t_{0} t_{1}^{4} t_{2}^{7} + 2 t_{1} t_{2}^{12} + 2 t_{0}^{7} t_{1}^{5} t_{2}^{2} + O(t_{0}, t_{1}, t_{2})^{15}' @@ -707,30 +708,30 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R + sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.rings.finite_rings Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = a + b + c + a^2*c - sage: f == f^2 + sage: f = a + b + c + a^2*c # optional - sage.rings.finite_rings + sage: f == f^2 # optional - sage.rings.finite_rings False - sage: f = f.truncate() - sage: f == f.O(4) + sage: f = f.truncate() # optional - sage.rings.finite_rings + sage: f == f.O(4) # optional - sage.rings.finite_rings True Ordering is determined by underlying polynomial ring:: - sage: a > b + sage: a > b # optional - sage.rings.finite_rings True - sage: a > a^2 + sage: a > a^2 # optional - sage.rings.finite_rings True - sage: b > a^2 + sage: b > a^2 # optional - sage.rings.finite_rings True - sage: (f^2).O(3) + sage: (f^2).O(3) # optional - sage.rings.finite_rings a^2 + 2*a*b + 2*a*c + b^2 + 2*b*c + c^2 + O(a, b, c)^3 - sage: f < f^2 + sage: f < f^2 # optional - sage.rings.finite_rings False - sage: f > f^2 + sage: f > f^2 # optional - sage.rings.finite_rings True - sage: f < 2*f + sage: f < 2*f # optional - sage.rings.finite_rings True """ return richcmp(self._bg_value, other._bg_value, op) @@ -894,22 +895,22 @@ def quo_rem(self, other, precision=None): sage: g = 1 + 2*a - 3*a*b + R.O(3) sage: q, r = f.quo_rem(g); q, r (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^3) - sage: f == q*g+r + sage: f == q*g + r True sage: q, r = (a*f).quo_rem(g); q, r (a - a^2 + a*b + 2*a^3 + O(a, b, c)^4, 0 + O(a, b, c)^4) - sage: a*f == q*g+r + sage: a*f == q*g + r True - sage: q, r = (a*f).quo_rem(a*g); q, r + sage: q, r = (a*f).quo_rem(a*g); q, r # optional - sage.libs.singular (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^4) - sage: a*f == q*(a*g)+r + sage: a*f == q*(a*g) + r # optional - sage.libs.singular True - sage: q, r = (a*f).quo_rem(b*g); q, r + sage: q, r = (a*f).quo_rem(b*g); q, r # optional - sage.libs.singular (a - 3*a^2 + O(a, b, c)^3, a + a^2 + O(a, b, c)^4) - sage: a*f == q*(b*g)+r + sage: a*f == q*(b*g) + r # optional - sage.libs.singular True Trying to divide two polynomials, we run into the issue that @@ -918,59 +919,61 @@ def quo_rem(self, other, precision=None): algorithm would never terminate). Here, default precision comes to our help:: - sage: (1+a^3).quo_rem(a+a^2) - (a^2 - a^3 + a^4 - a^5 + a^6 - a^7 + a^8 - a^9 + a^10 + O(a, b, c)^11, 1 + O(a, b, c)^12) + sage: (1 + a^3).quo_rem(a + a^2) # optional - sage.libs.singular + (a^2 - a^3 + a^4 - a^5 + a^6 - a^7 + a^8 - a^9 + a^10 + O(a, b, c)^11, + 1 + O(a, b, c)^12) - sage: (1+a^3+a*b).quo_rem(b+c) + sage: (1 + a^3 + a*b).quo_rem(b + c) # optional - sage.libs.singular (a + O(a, b, c)^11, 1 - a*c + a^3 + O(a, b, c)^12) - sage: (1+a^3+a*b).quo_rem(b+c, precision=17) + sage: (1 + a^3 + a*b).quo_rem(b + c, precision=17) # optional - sage.libs.singular (a + O(a, b, c)^16, 1 - a*c + a^3 + O(a, b, c)^17) - sage: (a^2+b^2+c^2).quo_rem(a+b+c) + sage: (a^2 + b^2 + c^2).quo_rem(a + b + c) # optional - sage.libs.singular (a - b - c + O(a, b, c)^11, 2*b^2 + 2*b*c + 2*c^2 + O(a, b, c)^12) - sage: (a^2+b^2+c^2).quo_rem(1/(1+a+b+c)) - (a^2 + b^2 + c^2 + a^3 + a^2*b + a^2*c + a*b^2 + a*c^2 + b^3 + b^2*c + b*c^2 + c^3 + O(a, b, c)^14, + sage: (a^2 + b^2 + c^2).quo_rem(1/(1+a+b+c)) # optional - sage.libs.singular + (a^2 + b^2 + c^2 + a^3 + a^2*b + a^2*c + a*b^2 + a*c^2 + + b^3 + b^2*c + b*c^2 + c^3 + O(a, b, c)^14, 0) - sage: (a^2+b^2+c^2).quo_rem(a/(1+a+b+c)) + sage: (a^2 + b^2 + c^2).quo_rem(a/(1+a+b+c)) # optional - sage.libs.singular (a + a^2 + a*b + a*c + O(a, b, c)^13, b^2 + c^2) - sage: (1+a+a^15).quo_rem(a^2) + sage: (1 + a + a^15).quo_rem(a^2) # optional - sage.libs.singular (0 + O(a, b, c)^10, 1 + a + O(a, b, c)^12) - sage: (1+a+a^15).quo_rem(a^2, precision=15) + sage: (1 + a + a^15).quo_rem(a^2, precision=15) # optional - sage.libs.singular (0 + O(a, b, c)^13, 1 + a + O(a, b, c)^15) - sage: (1+a+a^15).quo_rem(a^2, precision=16) + sage: (1 + a + a^15).quo_rem(a^2, precision=16) # optional - sage.libs.singular (a^13 + O(a, b, c)^14, 1 + a + O(a, b, c)^16) Illustrating the dependency on the ordering of variables:: - sage: (1+a+b).quo_rem(b+c) + sage: (1 + a + b).quo_rem(b + c) # optional - sage.libs.singular (1 + O(a, b, c)^11, 1 + a - c + O(a, b, c)^12) - sage: (1+b+c).quo_rem(c+a) + sage: (1 + b + c).quo_rem(c + a) # optional - sage.libs.singular (0 + O(a, b, c)^11, 1 + b + c + O(a, b, c)^12) - sage: (1+c+a).quo_rem(a+b) + sage: (1 + c + a).quo_rem(a + b) # optional - sage.libs.singular (1 + O(a, b, c)^11, 1 - b + c + O(a, b, c)^12) TESTS:: - sage: (f).quo_rem(R.zero()) + sage: (f).quo_rem(R.zero()) # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError - sage: (f).quo_rem(R.zero().add_bigoh(2)) + sage: (f).quo_rem(R.zero().add_bigoh(2)) # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError Coercion is applied on ``other``:: - sage: (a+b).quo_rem(1) + sage: (a + b).quo_rem(1) # optional - sage.libs.singular (a + b + O(a, b, c)^12, 0 + O(a, b, c)^12) sage: R. = PowerSeriesRing(QQ) - sage: R(3).quo_rem(2) + sage: R(3).quo_rem(2) # optional - sage.libs.singular (3/2 + O(a, b, c)^12, 0 + O(a, b, c)^12) """ parent = self.parent() @@ -1034,30 +1037,30 @@ def _div_(self, denom_r): When possible, division by non-units also works:: - sage: a/(a*f) + sage: a/(a*f) # optional - sage.libs.singular 1 - a - b + a^2 + 3*a*b + b^2 + O(a, b, c)^3 - sage: a/(R.zero()) + sage: a/(R.zero()) # optional - sage.libs.singular Traceback (most recent call last): ZeroDivisionError - sage: (a*f)/f + sage: (a*f)/f # optional - sage.libs.singular a + O(a, b, c)^4 - sage: f/(a*f) + sage: f/(a*f) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: not divisible An example where one loses precision:: - sage: ((1+a)*f - f) / a*f + sage: ((1+a)*f - f) / a*f # optional - sage.libs.singular 1 + 2*a + 2*b + O(a, b, c)^2 TESTS:: - sage: ((a+b)*f) / f == (a+b) + sage: ((a+b)*f) / f == (a+b) # optional - sage.libs.singular True - sage: ((a+b)*f) / (a+b) == f + sage: ((a+b)*f) / (a+b) == f # optional - sage.libs.singular True """ if denom_r.is_unit(): # faster if denom_r is a unit @@ -1080,7 +1083,7 @@ def __mod__(self, other): False sage: g in R.base_extend(Zmod(2)) True - sage: g.polynomial() == f.polynomial() % 2 + sage: g.polynomial() == f.polynomial() % 2 # optional - sage.libs.singular True """ if isinstance(other, (int, Integer)): @@ -1155,14 +1158,14 @@ def variables(self): EXAMPLES:: - sage: T = PowerSeriesRing(GF(3),5,'t'); T + sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.rings.finite_rings Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite Field of size 3 - sage: t = T.gens() - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) - sage: w + sage: t = T.gens() # optional - sage.rings.finite_rings + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.rings.finite_rings + sage: w # optional - sage.rings.finite_rings t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 - sage: w.variables() + sage: w.variables() # optional - sage.rings.finite_rings (t0, t2, t4) """ return tuple(self.parent(v) for v in self._value().variables()) @@ -1392,16 +1395,16 @@ def valuation(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(4949717)); R - Multivariate Power Series Ring in a, b over Finite Field of - size 4949717 - sage: f = a^2 + a*b + a^3 + R.O(9) - sage: f.valuation() + sage: R. = PowerSeriesRing(GF(4949717)); R # optional - sage.rings.finite_rings + Multivariate Power Series Ring in a, b + over Finite Field of size 4949717 + sage: f = a^2 + a*b + a^3 + R.O(9) # optional - sage.rings.finite_rings + sage: f.valuation() # optional - sage.rings.finite_rings 2 - sage: g = 1 + a + a^3 - sage: g.valuation() + sage: g = 1 + a + a^3 # optional - sage.rings.finite_rings + sage: g.valuation() # optional - sage.rings.finite_rings 0 - sage: R.zero().valuation() + sage: R.zero().valuation() # optional - sage.rings.finite_rings +Infinity """ try: @@ -1441,8 +1444,7 @@ def is_nilpotent(self): EXAMPLES:: sage: R. = PowerSeriesRing(Zmod(8)); R - Multivariate Power Series Ring in a, b, c over Ring of integers - modulo 8 + Multivariate Power Series Ring in a, b, c over Ring of integers modulo 8 sage: f = a + b + c + a^2*c sage: f.is_nilpotent() False @@ -1535,7 +1537,7 @@ def is_square(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.is_square() Traceback (most recent call last): @@ -1551,7 +1553,7 @@ def square_root(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.square_root() Traceback (most recent call last): @@ -1569,7 +1571,7 @@ def derivative(self, *args): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a^2*b + T.O(5) sage: f.derivative(a) 1 + 2*a*b + O(a, b)^4 @@ -1602,7 +1604,7 @@ def integral(self, *args): EXAMPLES:: - sage: T. = PowerSeriesRing(QQ,2) + sage: T. = PowerSeriesRing(QQ, 2) sage: f = a + b + a^2*b + T.O(5) sage: f.integral(a, 2) 1/6*a^3 + 1/2*a^2*b + 1/12*a^4*b + O(a, b)^7 @@ -1613,7 +1615,7 @@ def integral(self, *args): Only integration with respect to variables works:: - sage: f.integral(a+b) + sage: f.integral(a + b) Traceback (most recent call last): ... ValueError: a + b is not a variable @@ -1626,7 +1628,7 @@ def integral(self, *args): first case, Sage will report that it has not been able to coerce some coefficient to the base ring:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + T.O(5) sage: f.integral(a) Traceback (most recent call last): @@ -1648,7 +1650,7 @@ def integral(self, *args): In non-zero characteristic, Sage will report that a zero division occurred :: - sage: T. = PowerSeriesRing(Zmod(3),2) + sage: T. = PowerSeriesRing(Zmod(3), 2) sage: (a^3).integral(a) a^4 sage: (a^2).integral(a) @@ -1724,7 +1726,7 @@ def ogf(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.ogf() Traceback (most recent call last): @@ -1739,7 +1741,7 @@ def egf(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.egf() Traceback (most recent call last): @@ -1754,7 +1756,7 @@ def __pari__(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__pari__() Traceback (most recent call last): @@ -1773,7 +1775,7 @@ def list(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.list() Traceback (most recent call last): @@ -1790,7 +1792,7 @@ def variable(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.variable() Traceback (most recent call last): @@ -1806,7 +1808,7 @@ def shift(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.shift(3) Traceback (most recent call last): @@ -1821,7 +1823,7 @@ def __lshift__(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__lshift__(3) Traceback (most recent call last): @@ -1836,7 +1838,7 @@ def __rshift__(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__rshift__(3) Traceback (most recent call last): @@ -1852,7 +1854,7 @@ def valuation_zero_part(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.valuation_zero_part() Traceback (most recent call last): @@ -1868,7 +1870,7 @@ def solve_linear_de(self, prec=infinity, b=None, f0=None): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.solve_linear_de() Traceback (most recent call last): @@ -1893,15 +1895,15 @@ def exp(self, prec=infinity): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(3) - sage: exp(f) + sage: exp(f) # optional - sage.symbolic 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 sage: f.exp() 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 sage: f.exp(prec=2) 1 + a + b + O(a, b)^2 - sage: log(exp(f)) - f + sage: log(exp(f)) - f # optional - sage.symbolic 0 + O(a, b)^3 If the power series has a constant coefficient `c` and @@ -1909,8 +1911,8 @@ def exp(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f - sage: exp(g) + sage: g = 2 + f + sage: exp(g) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and @@ -1920,7 +1922,7 @@ def exp(self, prec=infinity): Another workaround for this limitation is to change base ring to one which is closed under exponentiation, such as `\RR` or `\CC`:: - sage: exp(g.change_ring(RDF)) + sage: exp(g.change_ring(RDF)) # optional - sage.symbolic 7.38905609... + 7.38905609...*a + 7.38905609...*b + 3.69452804...*a^2 + 14.7781121...*a*b + 3.69452804...*b^2 + O(a, b)^3 @@ -1928,17 +1930,17 @@ def exp(self, prec=infinity): sage: T.default_prec() 12 - sage: exp(a) + sage: exp(a) # optional - sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + 1/120*a^5 + 1/720*a^6 + 1/5040*a^7 + 1/40320*a^8 + 1/362880*a^9 + 1/3628800*a^10 + 1/39916800*a^11 + O(a, b)^12 sage: a.exp(prec=5) 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 - sage: exp(a + T.O(5)) + sage: exp(a + T.O(5)) # optional - sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: exp(a^2 + T.O(5)) + sage: exp(a^2 + T.O(5)) # optional - sage.symbolic 1 + a^2 + 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1985,7 +1987,7 @@ def log(self, prec=infinity): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = 1 + a + b + a*b + T.O(5) sage: f.log() a + b - 1/2*a^2 - 1/2*b^2 + 1/3*a^3 + 1/3*b^3 - 1/4*a^4 - 1/4*b^4 + O(a, b)^5 @@ -1999,7 +2001,7 @@ def log(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f + sage: g = 2 + f sage: log(g) Traceback (most recent call last): ... @@ -2090,7 +2092,7 @@ class MO(): sage: m^1 0 + O(u, v)^1 - sage: T. = PowerSeriesRing(ZZ,3) + sage: T. = PowerSeriesRing(ZZ, 3) sage: z = O(a, b, c) sage: z^1 0 + O(a, b, c)^1 diff --git a/src/sage/rings/noncommutative_ideals.pyx b/src/sage/rings/noncommutative_ideals.pyx index 0661987be2a..af27882313d 100644 --- a/src/sage/rings/noncommutative_ideals.pyx +++ b/src/sage/rings/noncommutative_ideals.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules """ Ideals of non-commutative rings diff --git a/src/sage/rings/number_field/number_field_base.pyx b/src/sage/rings/number_field/number_field_base.pyx index dd9a8b9d550..852811c132e 100644 --- a/src/sage/rings/number_field/number_field_base.pyx +++ b/src/sage/rings/number_field/number_field_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.number_field """ Base class for all number fields diff --git a/src/sage/rings/number_field/number_field_element_base.pyx b/src/sage/rings/number_field/number_field_element_base.pyx index 5385833f1d4..c4938237a6d 100644 --- a/src/sage/rings/number_field/number_field_element_base.pyx +++ b/src/sage/rings/number_field/number_field_element_base.pyx @@ -20,8 +20,8 @@ cdef class NumberFieldElement_base(FieldElement): EXAMPLES:: - sage: k. = NumberField(x^3 + x + 1) - sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) + sage: k. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field + sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/numbers_abc.py b/src/sage/rings/numbers_abc.py index 478a0b36408..6bbcddccf40 100644 --- a/src/sage/rings/numbers_abc.py +++ b/src/sage/rings/numbers_abc.py @@ -57,10 +57,10 @@ def register_sage_classes(): Because we do this, NumPy's ``isscalar()`` recognizes Sage types:: - sage: from numpy import isscalar - sage: isscalar(3.141) + sage: from numpy import isscalar # optional - numpy + sage: isscalar(3.141) # optional - numpy True - sage: isscalar(4/17) + sage: isscalar(4/17) # optional - numpy True """ from sage.misc.superseded import deprecation diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py index 6db8866aff8..83d77282c2a 100644 --- a/src/sage/rings/padics/local_generic.py +++ b/src/sage/rings/padics/local_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.padics r""" Local Generic diff --git a/src/sage/rings/padics/local_generic_element.pyx b/src/sage/rings/padics/local_generic_element.pyx index e7b9ba76b80..8df39a52363 100644 --- a/src/sage/rings/padics/local_generic_element.pyx +++ b/src/sage/rings/padics/local_generic_element.pyx @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.rings.padics """ Local Generic Element diff --git a/src/sage/rings/padics/misc.py b/src/sage/rings/padics/misc.py index 71f9e80ed99..cac0934df72 100644 --- a/src/sage/rings/padics/misc.py +++ b/src/sage/rings/padics/misc.py @@ -91,25 +91,25 @@ def gauss_sum(a, p, f, prec=20, factored=False, algorithm='pari', parent=None): In this example, we verify that `g_3(0) = -1`:: sage: from sage.rings.padics.misc import gauss_sum - sage: -gauss_sum(0,3,1) + sage: -gauss_sum(0, 3, 1) # optional - sage.rings.padics 1 + O(pi^40) Next, we verify that `g_5(a) g_5(-a) = 5 (-1)^a`:: sage: from sage.rings.padics.misc import gauss_sum - sage: gauss_sum(2,5,1)^2-5 + sage: gauss_sum(2,5,1)^2 - 5 # optional - sage.rings.padics O(pi^84) - sage: gauss_sum(1,5,1)*gauss_sum(3,5,1)+5 + sage: gauss_sum(1,5,1)*gauss_sum(3,5,1) + 5 # optional - sage.rings.padics O(pi^84) Finally, we compute a non-trivial value:: sage: from sage.rings.padics.misc import gauss_sum - sage: gauss_sum(2,13,2) + sage: gauss_sum(2,13,2) # optional - sage.rings.padics 6*pi^2 + 7*pi^14 + 11*pi^26 + 3*pi^62 + 6*pi^74 + 3*pi^86 + 5*pi^98 + pi^110 + 7*pi^134 + 9*pi^146 + 4*pi^158 + 6*pi^170 + 4*pi^194 + pi^206 + 6*pi^218 + 9*pi^230 + O(pi^242) - sage: gauss_sum(2,13,2,prec=5,factored=True) + sage: gauss_sum(2,13,2, prec=5, factored=True) # optional - sage.rings.padics (2, 6 + 6*13 + 10*13^2 + O(13^5)) .. SEEALSO:: diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py index bde23bea380..b7caad54122 100644 --- a/src/sage/rings/padics/padic_generic.py +++ b/src/sage/rings/padics/padic_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.padics r""" `p`-adic Generic diff --git a/src/sage/rings/polynomial/flatten.py b/src/sage/rings/polynomial/flatten.py index 4ffe29f9ebe..84c38e52ee5 100644 --- a/src/sage/rings/polynomial/flatten.py +++ b/src/sage/rings/polynomial/flatten.py @@ -10,7 +10,10 @@ sage: from sage.rings.polynomial.flatten import FlatteningMorphism sage: phi = FlatteningMorphism(R); phi Flattening morphism: - From: Univariate Polynomial Ring in X over Multivariate Polynomial Ring in s, t over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + From: Univariate Polynomial Ring in X + over Multivariate Polynomial Ring in s, t + over Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field To: Multivariate Polynomial Ring in x, y, s, t, X over Rational Field sage: phi('x*y*s + t*X').parent() Multivariate Polynomial Ring in x, y, s, t, X over Rational Field @@ -108,36 +111,36 @@ def __init__(self, domain): :: - sage: K. = NumberField(x^3 - 2) - sage: R = K['x','y']['a','b'] + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: R = K['x','y']['a','b'] # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f(R('v*a*x^2 + b^2 + 1/v*y')) + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f(R('v*a*x^2 + b^2 + 1/v*y')) # optional - sage.rings.number_field v*x^2*a + b^2 + (1/2*v^2)*y :: - sage: R = QQbar['x','y']['a','b'] + sage: R = QQbar['x','y']['a','b'] # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f(R('QQbar(sqrt(2))*a*x^2 + b^2 + QQbar(I)*y')) + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f(R('QQbar(sqrt(2))*a*x^2 + b^2 + QQbar(I)*y')) # optional - sage.rings.number_field 1.414213562373095?*x^2*a + b^2 + I*y :: - sage: R. = PolynomialRing(QQbar,1) + sage: R. = PolynomialRing(QQbar, 1) # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f.domain(), f.codomain() + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f.domain(), f.codomain() # optional - sage.rings.number_field (Multivariate Polynomial Ring in z over Algebraic Field, Multivariate Polynomial Ring in z over Algebraic Field) :: - sage: R. = PolynomialRing(QQbar) + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f.domain(), f.codomain() + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f.domain(), f.codomain() # optional - sage.rings.number_field (Univariate Polynomial Ring in z over Algebraic Field, Univariate Polynomial Ring in z over Algebraic Field) @@ -243,7 +246,8 @@ def section(self): sage: h.section() Unflattening morphism: From: Multivariate Polynomial Ring in a, b, c, x, y, z over Rational Field - To: Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial Ring in a, b, c over Rational Field + To: Multivariate Polynomial Ring in x, y, z + over Multivariate Polynomial Ring in a, b, c over Rational Field :: @@ -252,7 +256,8 @@ def section(self): sage: FlatteningMorphism(R).section() Unflattening morphism: From: Multivariate Polynomial Ring in a, b, c over Integer Ring - To: Univariate Polynomial Ring in c over Univariate Polynomial Ring in b over Univariate Polynomial Ring in a over Integer Ring + To: Univariate Polynomial Ring in c over Univariate Polynomial Ring in b + over Univariate Polynomial Ring in a over Integer Ring """ return UnflatteningMorphism(self.codomain(), self.domain()) @@ -268,7 +273,8 @@ def inverse(self): sage: f.inverse() Unflattening morphism: From: Multivariate Polynomial Ring in x, y, u, v over Rational Field - To: Multivariate Polynomial Ring in u, v over Multivariate Polynomial Ring in x, y over Rational Field + To: Multivariate Polynomial Ring in u, v + over Multivariate Polynomial Ring in x, y over Rational Field """ return self.section() @@ -286,7 +292,8 @@ class UnflatteningMorphism(Morphism): sage: g = f(R('x^2 + c*y^2 - z^2'));g x^2 + c*y^2 - z^2 sage: g.parent() - Multivariate Polynomial Ring in x, y, z over Univariate Polynomial Ring in c over Rational Field + Multivariate Polynomial Ring in x, y, z + over Univariate Polynomial Ring in c over Rational Field :: @@ -296,7 +303,8 @@ class UnflatteningMorphism(Morphism): sage: UnflatteningMorphism(R, S) Unflattening morphism: From: Multivariate Polynomial Ring in a, b, x, y over Rational Field - To: Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Rational Field + To: Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Rational Field """ def __init__(self, domain, codomain): @@ -366,8 +374,10 @@ def _call_(self, p): TESTS:: sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: for R in [ZZ['x']['y']['a,b,c'], GF(4)['x','y']['a','b'], - ....: AA['x']['a','b']['y'], QQbar['a1','a2']['t']['X','Y']]: + sage: rings = [ZZ['x']['y']['a,b,c']] + sage: rings += [GF(4)['x','y']['a','b']] # optional - sage.rings.finite_rings + sage: rings += [AA['x']['a','b']['y'], QQbar['a1','a2']['t']['X','Y']] # optional - sage.rings.number_field + sage: for R in rings: ....: f = FlatteningMorphism(R) ....: g = f.section() ....: for _ in range(10): @@ -423,8 +433,9 @@ class SpecializationMorphism(Morphism): sage: from sage.rings.polynomial.flatten import SpecializationMorphism sage: xi = SpecializationMorphism(S, {c:0}); xi Specialization morphism: - From: Univariate Polynomial Ring in z over Univariate Polynomial Ring in c over Rational Field - To: Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in z + over Univariate Polynomial Ring in c over Rational Field + To: Univariate Polynomial Ring in z over Rational Field sage: xi(z^2+c) z^2 @@ -437,8 +448,11 @@ class SpecializationMorphism(Morphism): sage: from sage.rings.polynomial.flatten import SpecializationMorphism sage: xi = SpecializationMorphism(S, D); xi Specialization morphism: - From: Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial Ring in a, b, c over Multivariate Polynomial Ring in u, v over Rational Field - To: Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in c over Univariate Polynomial Ring in v over Rational Field + From: Multivariate Polynomial Ring in x, y, z + over Multivariate Polynomial Ring in a, b, c + over Multivariate Polynomial Ring in u, v over Rational Field + To: Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in c + over Univariate Polynomial Ring in v over Rational Field sage: xi(a*(x*z+y^2)*u+b*v*u*(x*z+y^2)*y^2*c+c*y^2*z^2) 2*v*c*y^4 + c*y^2*z^2 + y^2 """ @@ -655,8 +669,10 @@ def __init__(self, domain, D): sage: phi = FractionSpecializationMorphism(Frac(S), {c:3}) sage: phi Fraction Specialization morphism: - From: Fraction Field of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, c over Rational Field - To: Fraction Field of Multivariate Polynomial Ring in x, y over Univariate Polynomial Ring in a over Rational Field + From: Fraction Field of Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, c over Rational Field + To: Fraction Field of Multivariate Polynomial Ring in x, y + over Univariate Polynomial Ring in a over Rational Field """ if not is_FractionField(domain): raise TypeError("domain must be a fraction field") diff --git a/src/sage/rings/polynomial/hilbert.pyx b/src/sage/rings/polynomial/hilbert.pyx index 01cb166b7fb..864e2766407 100644 --- a/src/sage/rings/polynomial/hilbert.pyx +++ b/src/sage/rings/polynomial/hilbert.pyx @@ -442,16 +442,16 @@ def first_hilbert_series(I, grading=None, return_grading=False): sage: I = singular.ideal(['x^2','y^2','z^2']) sage: first_hilbert_series(I) -t^6 + 3*t^4 - 3*t^2 + 1 - sage: first_hilbert_series(I,return_grading=True) + sage: first_hilbert_series(I, return_grading=True) (-t^6 + 3*t^4 - 3*t^2 + 1, (1, 1, 1)) - sage: first_hilbert_series(I,grading=(1,2,3)) + sage: first_hilbert_series(I, grading=(1,2,3)) -t^12 + t^10 + t^8 - t^4 - t^2 + 1 TESTS: We test against some corner cases:: - sage: R.=PolynomialRing(QQ) + sage: R. = PolynomialRing(QQ) sage: I = 0*R sage: first_hilbert_series(I) 1 @@ -559,18 +559,19 @@ def hilbert_poincare_series(I, grading=None): sage: from sage.rings.polynomial.hilbert import hilbert_poincare_series sage: R = PolynomialRing(QQ,'x',9) - sage: I = [m.lm() for m in ((matrix(R,3,R.gens())^2).list()*R).groebner_basis()]*R + sage: I = [m.lm() + ....: for m in ((matrix(R, 3, R.gens())^2).list() * R).groebner_basis()] * R sage: hilbert_poincare_series(I) (t^7 - 3*t^6 + 2*t^5 + 2*t^4 - 2*t^3 + 6*t^2 + 5*t + 1)/(t^4 - 4*t^3 + 6*t^2 - 4*t + 1) - sage: hilbert_poincare_series((R*R.gens())^2, grading=range(1,10)) + sage: hilbert_poincare_series((R * R.gens())^2, grading=range(1,10)) t^9 + t^8 + t^7 + t^6 + t^5 + t^4 + t^3 + t^2 + t + 1 The following example is taken from :trac:`20145`:: - sage: n=4;m=11;P = PolynomialRing(QQ,n*m,"x"); x = P.gens(); M = Matrix(n,x) + sage: n=4; m=11; P = PolynomialRing(QQ, n*m, "x"); x = P.gens(); M = Matrix(n, x) sage: from sage.rings.polynomial.hilbert import first_hilbert_series sage: I = P.ideal(M.minors(2)) - sage: J = P*[m.lm() for m in I.groebner_basis()] + sage: J = P * [m.lm() for m in I.groebner_basis()] sage: hilbert_poincare_series(J).numerator() 120*t^3 + 135*t^2 + 30*t + 1 sage: hilbert_poincare_series(J).denominator().factor() @@ -578,7 +579,7 @@ def hilbert_poincare_series(I, grading=None): This example exceeded the capabilities of Singular before version 4.2.1p2. In Singular 4.3.1, it works correctly on 64-bit, but on 32-bit, it prints overflow warnings - and omits some terms. + and omits some terms:: sage: J.hilbert_numerator(algorithm='singular') 120*t^33 - 3465*t^32 + 48180*t^31 - 429374*t^30 + 2753520*t^29 - 13522410*t^28 + 52832780*t^27 - 168384150*t^26 + 445188744*t^25 - 987193350*t^24 + 1847488500*t^23 + 1372406746*t^22 - 403422496*t^21 - 8403314*t^20 - 471656596*t^19 + 1806623746*t^18 + 752776200*t^17 + 752776200*t^16 - 1580830020*t^15 + 1673936550*t^14 - 1294246800*t^13 + 786893250*t^12 - 382391100*t^11 + 146679390*t^10 - 42299400*t^9 + 7837830*t^8 - 172260*t^7 - 468930*t^6 + 183744*t^5 - 39270*t^4 + 5060*t^3 - 330*t^2 + 1 # 64-bit diff --git a/src/sage/rings/polynomial/ideal.py b/src/sage/rings/polynomial/ideal.py index 857718c9a10..858fc505b8d 100644 --- a/src/sage/rings/polynomial/ideal.py +++ b/src/sage/rings/polynomial/ideal.py @@ -32,9 +32,9 @@ def residue_class_degree(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: P = R.ideal(t^4 + t + 1) - sage: P.residue_class_degree() + sage: R. = GF(5)[] # optional - sage.libs.pari + sage: P = R.ideal(t^4 + t + 1) # optional - sage.libs.pari + sage: P.residue_class_degree() # optional - sage.libs.pari 4 """ return self.gen().degree() @@ -45,9 +45,10 @@ def residue_field(self, names=None, check=True): EXAMPLES:: - sage: R. = GF(17)[]; P = R.ideal(t^3 + 2*t + 9) - sage: k. = P.residue_field(); k - Residue field in a of Principal ideal (t^3 + 2*t + 9) of Univariate Polynomial Ring in t over Finite Field of size 17 + sage: R. = GF(17)[]; P = R.ideal(t^3 + 2*t + 9) # optional - sage.libs.pari + sage: k. = P.residue_field(); k # optional - sage.libs.pari + Residue field in a of Principal ideal (t^3 + 2*t + 9) of + Univariate Polynomial Ring in t over Finite Field of size 17 """ if check: if not self.ring().base_ring().is_finite(): @@ -74,11 +75,11 @@ def groebner_basis(self, algorithm=None): sage: R. = QQ[] sage: I = R.ideal([x^2 - 1, x^3 - 1]) - sage: G = I.groebner_basis(); G + sage: G = I.groebner_basis(); G # optional - sage.libs.singular [x - 1] - sage: type(G) + sage: type(G) # optional - sage.libs.singular - sage: list(G) + sage: list(G) # optional - sage.libs.singular [x - 1] """ gb = self.gens_reduced() diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index c7d43e31d1b..cad5877fd0f 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -18,7 +18,7 @@ x_3 sage: b y_4 - sage: c = a*b+a^3-2*b^4 + sage: c = a*b + a^3 - 2*b^4 sage: c x_3^3 + x_3*y_4 - 2*y_4^4 @@ -48,8 +48,8 @@ There is a permutation action on Infinite Polynomial Rings by permuting the indices of the variables:: - sage: P = Permutation(((4,5),(2,3))) - sage: c^P + sage: P = Permutation(((4,5),(2,3))) # optional - sage.combinat + sage: c^P # optional - sage.combinat x_2^3 + x_2*y_5 - 2*y_5^4 Note that ``P(0)==0``, and thus variables of index zero are invariant @@ -80,7 +80,7 @@ sage: C. = InfinitePolynomialRing(B,order='degrevlex') sage: C Infinite polynomial ring in b, c over Infinite polynomial ring in a over Integer Ring - sage: 1/2*b_1*a[4]+c[3] + sage: 1/2*b_1*a[4] + c[3] 1/2*a_4*b_1 + c_3 """ @@ -299,15 +299,16 @@ def polynomial(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(GF(7)) - sage: p = x[2]*y[1]+3*y[0] - sage: p + sage: X. = InfinitePolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: p = x[2]*y[1] + 3*y[0] # optional - sage.rings.finite_rings + sage: p # optional - sage.rings.finite_rings x_2*y_1 + 3*y_0 - sage: p.polynomial() + sage: p.polynomial() # optional - sage.rings.finite_rings x_2*y_1 + 3*y_0 - sage: p.polynomial().parent() - Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 over Finite Field of size 7 - sage: p.parent() + sage: p.polynomial().parent() # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 + over Finite Field of size 7 + sage: p.parent() # optional - sage.rings.finite_rings Infinite polynomial ring in x, y over Finite Field of size 7 """ @@ -402,7 +403,7 @@ def subs(self, fixed=None, **kwargs): INPUT: - - ``fixed`` -- (optional) ``dict`` with ``{variable:value}`` pairs + - ``fixed`` -- (optional) ``dict`` with ``{variable: value}`` pairs - ``**kwargs`` -- named parameters OUTPUT: @@ -439,13 +440,13 @@ def subs(self, fixed=None, **kwargs): The substitution can also handle matrices:: - sage: M = matrix([[1,0],[0,2]]) - sage: N = matrix([[0,3],[4,0]]) - sage: g = x[0]^2 + 3*x[1] - sage: g.subs({'x_0': M}) + sage: M = matrix([[1,0], [0,2]]) # optional - sage.modules + sage: N = matrix([[0,3], [4,0]]) # optional - sage.modules + sage: g = x[0]^2 + 3*x[1] # optional - sage.modules + sage: g.subs({'x_0': M}) # optional - sage.modules [3*x_1 + 1 0] [ 0 3*x_1 + 4] - sage: g.subs({x[0]: M, x[1]: N}) + sage: g.subs({x[0]: M, x[1]: N}) # optional - sage.modules [ 1 9] [12 4] @@ -454,11 +455,11 @@ def subs(self, fixed=None, **kwargs): sage: R. = InfinitePolynomialRing(QQ) sage: f = x[0] - sage: f.subs({x[0]:1}) + sage: f.subs({x[0]: 1}) 1 sage: f.subs(x_0=5) 5 - sage: f.subs({x[0]:1}, x_0=5) + sage: f.subs({x[0]: 1}, x_0=5) 1 TESTS:: @@ -487,7 +488,7 @@ def ring(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(ZZ,implementation='sparse') - sage: p = x[100]*y[1]^3*x[1]^2+2*x[10]*y[30] + sage: p = x[100]*y[1]^3*x[1]^2 + 2*x[10]*y[30] sage: p.ring() Infinite polynomial ring in x, y over Integer Ring @@ -502,7 +503,7 @@ def is_unit(self): sage: R1. = InfinitePolynomialRing(ZZ) sage: R2. = InfinitePolynomialRing(QQ) - sage: (1+x[2]).is_unit() + sage: (1 + x[2]).is_unit() False sage: R1(1).is_unit() True @@ -510,7 +511,7 @@ def is_unit(self): False sage: R2(2).is_unit() True - sage: (1+a[2]).is_unit() + sage: (1 + a[2]).is_unit() False Check that :trac:`22454` is fixed:: @@ -539,10 +540,10 @@ def is_nilpotent(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(QQbar) - sage: (x[0]+x[1]).is_nilpotent() + sage: R. = InfinitePolynomialRing(QQbar) # optional - sage.rings.number_field + sage: (x[0] + x[1]).is_nilpotent() # optional - sage.rings.number_field False - sage: R(0).is_nilpotent() + sage: R(0).is_nilpotent() # optional - sage.rings.number_field True sage: _. = InfinitePolynomialRing(Zmod(4)) sage: (2*x[0]).is_nilpotent() @@ -586,7 +587,7 @@ def max_index(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p=x[1]^2+y[2]^2+x[1]*x[2]*y[3]+x[1]*y[4] + sage: p = x[1]^2 + y[2]^2 + x[1]*x[2]*y[3] + x[1]*y[4] sage: p.max_index() 4 sage: x[0].max_index() @@ -633,7 +634,7 @@ def _div_(self, x): Division by an integer over `\ZZ`:: sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') - sage: p = x[3]+x[2] + sage: p = x[3] + x[2] sage: q = p/2 sage: q 1/2*x_3 + 1/2*x_2 @@ -647,7 +648,7 @@ def _div_(self, x): 1/x_1 sage: (x[0]/x[0]) x_0/x_0 - sage: qt = 1/x[2]+2/x[1]; qt + sage: qt = 1/x[2] + 2/x[1]; qt (2*x_2 + x_1)/(x_2*x_1) sage: qt.parent() Fraction Field of Infinite polynomial ring in x over Rational Field @@ -655,7 +656,7 @@ def _div_(self, x): sage: z = 1/(x[2]*(x[1]+x[2]))+1/(x[1]*(x[1]+x[2])) sage: z.parent() Fraction Field of Infinite polynomial ring in x over Rational Field - sage: factor(z) + sage: factor(z) # optional - sage.libs.singular x_1^-1 * x_2^-1 """ if not x.variables(): @@ -700,7 +701,7 @@ def lm(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + x[10]*y[1]^3*x[1]^2 sage: p.lm() x_10*x_1^2*y_1^3 @@ -722,7 +723,7 @@ def lc(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + 3*x[10]*y[1]^3*x[1]^2 sage: p.lc() 3 @@ -742,7 +743,7 @@ def lt(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + 3*x[10]*y[1]^3*x[1]^2 sage: p.lt() 3*x_10*x_1^2*y_1^3 @@ -762,7 +763,7 @@ def tail(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + 3*x[10]*y[1]^3*x[1]^2 sage: p.tail() 2*x_10*y_30 @@ -811,7 +812,7 @@ def footprint(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = x[30]*y[1]^3*x[1]^2+2*x[10]*y[30] + sage: p = x[30]*y[1]^3*x[1]^2 + 2*x[10]*y[30] sage: sorted(p.footprint().items()) [(1, [2, 3]), (30, [1, 0])] @@ -863,7 +864,7 @@ def symmetric_cancellation_order(self, other): INPUT: - self, other -- two Infinite Polynomials + ``self``, ``other`` -- two Infinite Polynomials ASSUMPTION: @@ -895,11 +896,11 @@ def symmetric_cancellation_order(self, other): sage: X. = InfinitePolynomialRing(QQ) sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]^2) (None, 1, 1) - sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) + sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) # optional - sage.combinat (-1, [2, 3, 1], y_1) - sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) + sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) # optional - sage.combinat (None, 1, 1) - sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[2]) + sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[2]) # optional - sage.combinat (-1, [2, 3, 1], 1) """ @@ -1085,7 +1086,7 @@ def reduce(self, I, tailreduce=False, report=None): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = y[1]^2*y[3]+y[2]*x[3]^3 + sage: p = y[1]^2*y[3] + y[2]*x[3]^3 sage: p.reduce([y[2]*x[1]^2]) x_3^3*y_2 + y_3*y_1^2 @@ -1111,7 +1112,7 @@ def reduce(self, I, tailreduce=False, report=None): Last, we demonstrate the ``report`` option:: - sage: p=x[1]^2+y[2]^2+x[1]*x[2]*y[3]+x[1]*y[4] + sage: p = x[1]^2 + y[2]^2 + x[1]*x[2]*y[3] + x[1]*y[4] sage: p.reduce(I, tailreduce=True, report=True) :T[2]:> > @@ -1200,7 +1201,7 @@ def gcd(self, x): EXAMPLES:: sage: R.=InfinitePolynomialRing(QQ) - sage: p1=x[0]+x[1]**2 + sage: p1=x[0] + x[1]**2 sage: gcd(p1,p1+3) 1 sage: gcd(p1,p1)==p1 @@ -1232,9 +1233,11 @@ class InfinitePolynomial_sparse(InfinitePolynomial): sage: p a*b_100 + 1/2*c_4 sage: p.parent() - Infinite polynomial ring in b, c over Univariate Polynomial Ring in a over Rational Field + Infinite polynomial ring in b, c + over Univariate Polynomial Ring in a over Rational Field sage: p.polynomial().parent() - Multivariate Polynomial Ring in b_100, b_0, c_4, c_0 over Univariate Polynomial Ring in a over Rational Field + Multivariate Polynomial Ring in b_100, b_0, c_4, c_0 + over Univariate Polynomial Ring in a over Rational Field """ @@ -1255,8 +1258,8 @@ def __call__(self, *args, **kwargs): sage: a(x_1=x[100]) x_100 + x_0 - sage: M = matrix([[1,1],[2,0]]) - sage: a(x_1=M) + sage: M = matrix([[1,1], [2,0]]) # optional - sage.modules + sage: a(x_1=M) # optional - sage.modules [x_0 + 1 1] [ 2 x_0] """ @@ -1384,10 +1387,10 @@ def __pow__(self, n): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: p = x[10]*y[2]+2*x[1]*y[3] - sage: P = Permutation(((1,2),(3,4,5))) - sage: p^P # indirect doctest + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: p = x[10]*y[2] + 2*x[1]*y[3] + sage: P = Permutation(((1,2),(3,4,5))) # optional - sage.combinat + sage: p^P # indirect doctest # optional - sage.combinat x_10*y_1 + 2*x_2*y_4 """ @@ -1471,16 +1474,16 @@ def _richcmp_(self, x, op): Two infinite polynomial rings in different implementation and order:: - sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex',implementation='dense') + sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex', implementation='dense') sage: x[2] == Y(x[2]) # indirect doctest True An example in which a previous version had failed:: - sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') - sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') - sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') - sage: p < q # indirect doctest + sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') # optional - sage.rings.finite_rings + sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') # optional - sage.rings.finite_rings + sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') # optional - sage.rings.finite_rings + sage: p < q # indirect doctest # optional - sage.rings.finite_rings False """ @@ -1523,9 +1526,6 @@ class InfinitePolynomial_dense(InfinitePolynomial): Of course, one should not directly invoke this class, but rather construct elements of ``A`` in the usual way. - This class inherits from - :class:`~sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse`. See - there for a description of the methods. """ def __call__(self, *args, **kwargs): @@ -1534,7 +1534,7 @@ def __call__(self, *args, **kwargs): sage: X. = InfinitePolynomialRing(QQ) sage: a = x[0] + x[1] - sage: a(x_0=2,x_1=x[1]) + sage: a(x_0=2, x_1=x[1]) x_1 + 2 sage: _.parent() Infinite polynomial ring in x over Rational Field @@ -1569,7 +1569,7 @@ def _richcmp_(self, x, op): A classical and an infinite polynomial ring:: - sage: X. = InfinitePolynomialRing(ZZ,order='degrevlex') + sage: X. = InfinitePolynomialRing(ZZ, order='degrevlex') sage: Y. = QQ[] sage: x[3] == x_3 True @@ -1577,16 +1577,16 @@ def _richcmp_(self, x, op): Two infinite polynomial rings with different order and implementation:: - sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex',implementation='sparse') + sage: Y = InfinitePolynomialRing(QQ,['x','y'], order='deglex', implementation='sparse') sage: x[2] == Y(x[2]) True An example in which a previous version had failed:: - sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='dense') - sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') - sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') - sage: p < q + sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='dense') # optional - sage.rings.finite_rings + sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') # optional - sage.rings.finite_rings + sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') # optional - sage.rings.finite_rings + sage: p < q # optional - sage.rings.finite_rings False """ @@ -1664,9 +1664,9 @@ def __pow__(self, n): sage: X. = InfinitePolynomialRing(QQ) sage: x[10]^3 x_10^3 - sage: p = x[10]*y[2]+2*x[1]*y[3] - sage: P = Permutation(((1,2),(3,4,5))) - sage: p^P + sage: p = x[10]*y[2] + 2*x[1]*y[3] + sage: P = Permutation(((1,2),(3,4,5))) # optional - sage.combinat + sage: p^P # optional - sage.combinat x_10*y_1 + 2*x_2*y_4 """ diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 8e3ba4156e9..b9318c36d49 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -71,11 +71,12 @@ sage: g2 = 3*beta[1]; g2 3*beta_1 sage: A.polynomial_ring() - Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0, beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field + Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0, + beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field Of course, we provide the usual polynomial arithmetic:: - sage: f+g + sage: f + g x_5 + 3*y_1 + 2 sage: p = x[10]^2*(f+g); p x_10^2*x_5 + 3*x_10^2*y_1 + 2*x_10^2 @@ -85,10 +86,10 @@ There is a permutation action on the variables, by permuting positive variable indices:: - sage: P = Permutation(((10,1))) - sage: p^P + sage: P = Permutation(((10,1))) # optional - sage.combinat + sage: p^P # optional - sage.combinat x_5*x_1^2 + 3*x_1^2*y_10 + 2*x_1^2 - sage: p2^P + sage: p2^P # optional - sage.combinat alpha_5*alpha_1^2 + 3*alpha_1^2*beta_10 + 2*alpha_1^2 Note that `x_0^P = x_0`, since the permutations only change *positive* @@ -101,8 +102,8 @@ multiplication by ring elements and permutation of variables. If the base ring is a field, one can compute Symmetric Groebner Bases:: - sage: J = A*(alpha[1]*beta[2]) - sage: J.groebner_basis() + sage: J = A * (alpha[1]*beta[2]) + sage: J.groebner_basis() # optional - sage.combinat [alpha_1*beta_2, alpha_2*beta_1] For more details, see :class:`~sage.rings.polynomial.symmetric_ideal.SymmetricIdeal`. @@ -126,7 +127,8 @@ sage: A. = ZZ[] sage: B. = InfinitePolynomialRing(A, order='degrevlex') sage: B - Infinite polynomial ring in b, c, d over Multivariate Polynomial Ring in a_3, a_1 over Integer Ring + Infinite polynomial ring in b, c, d over + Multivariate Polynomial Ring in a_3, a_1 over Integer Ring It is no problem if one generator of the Infinite Polynomial Ring is called ``x`` and one variable of the base ring is also called @@ -144,7 +146,8 @@ :: sage: Y - Infinite polynomial ring in x, z over Multivariate Polynomial Ring in x, y_1 over Integer Ring + Infinite polynomial ring in x, z over + Multivariate Polynomial Ring in x, y_1 over Integer Ring The variable ``x`` of ``X`` can still be interpreted in ``Y``, although the first generator of ``Y`` is called ``x`` as well:: @@ -171,7 +174,7 @@ Traceback (most recent call last): ... CoercionException: Overlapping variables (('z', 'y'),['y_1']) are incompatible - sage: X. = PolynomialRing(ZZ,order='lex') + sage: X. = PolynomialRing(ZZ, order='lex') sage: # y_1 and y_2 would be in opposite order in an Infinite Polynomial Ring sage: Y. = InfinitePolynomialRing(X) Traceback (most recent call last): @@ -184,10 +187,10 @@ construction available:: sage: X. = InfinitePolynomialRing(ZZ) - sage: Y. = InfinitePolynomialRing(X,order='degrevlex') + sage: Y. = InfinitePolynomialRing(X, order='degrevlex') sage: Y Infinite polynomial ring in z over Infinite polynomial ring in x, y over Integer Ring - sage: Y. = InfinitePolynomialRing(X,implementation='sparse') + sage: Y. = InfinitePolynomialRing(X, implementation='sparse') sage: Y Infinite polynomial ring in z over Infinite polynomial ring in x, y over Integer Ring @@ -203,18 +206,18 @@ sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 - sage: R. = InfinitePolynomialRing(ZZ,implementation='sparse') + sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') sage: X. = InfinitePolynomialRing(R) sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 - sage: R. = InfinitePolynomialRing(ZZ,implementation='sparse') - sage: X. = InfinitePolynomialRing(R,implementation='sparse') + sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') + sage: X. = InfinitePolynomialRing(R, implementation='sparse') sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 sage: R. = InfinitePolynomialRing(ZZ) - sage: X. = InfinitePolynomialRing(R,implementation='sparse') + sage: X. = InfinitePolynomialRing(R, implementation='sparse') sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 @@ -309,11 +312,13 @@ def create_key(self, R, names=('x',), order='lex', implementation='dense'): (InfPoly{[y1], "lex", "dense"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[y1], "lex", "dense"}] - sage: InfinitePolynomialRing.create_key(QQ, names=['beta'], order='deglex', implementation='sparse') + sage: InfinitePolynomialRing.create_key(QQ, names=['beta'], order='deglex', + ....: implementation='sparse') (InfPoly{[beta], "deglex", "sparse"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[beta], "deglex", "sparse"}] - sage: InfinitePolynomialRing.create_key(QQ, names=['x','y'], implementation='dense') + sage: InfinitePolynomialRing.create_key(QQ, names=['x','y'], + ....: implementation='dense') (InfPoly{[x,y], "lex", "dense"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[x,y], "lex", "dense"}] @@ -805,8 +810,8 @@ def construction(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(5)) - sage: R.construction() + sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: R.construction() # optional - sage.rings.finite_rings [InfPoly{[x,y], "lex", "dense"}, Finite Field of size 5] """ @@ -1104,10 +1109,10 @@ def is_noetherian(self): TESTS:: - sage: R = InfinitePolynomialRing(GF(2)) - sage: R + sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Infinite polynomial ring in x over Finite Field of size 2 - sage: R.is_noetherian() + sage: R.is_noetherian() # optional - sage.rings.finite_rings False sage: R. = InfinitePolynomialRing(QQ) @@ -1131,10 +1136,10 @@ def is_field(self, *args, **kwds): TESTS:: - sage: R = InfinitePolynomialRing(GF(2)) - sage: R + sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Infinite polynomial ring in x over Finite Field of size 2 - sage: R.is_field() + sage: R.is_field() # optional - sage.rings.finite_rings False :trac:`9443`:: @@ -1225,8 +1230,8 @@ def gen(self, i=None): x_1 sage: X.gen() is X.gen(0) True - sage: XX = InfinitePolynomialRing(GF(5)) - sage: XX.gen(0) is XX.gen() + sage: XX = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: XX.gen(0) is XX.gen() # optional - sage.rings.finite_rings True """ if i is not None and i > len(self._names): @@ -1292,10 +1297,10 @@ def characteristic(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(GF(25,'a')) - sage: X + sage: X. = InfinitePolynomialRing(GF(25,'a')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings Infinite polynomial ring in x, y over Finite Field in a of size 5^2 - sage: X.characteristic() + sage: X.characteristic() # optional - sage.rings.finite_rings 5 """ @@ -1344,8 +1349,8 @@ def order(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(2)) - sage: R.order() + sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R.order() # optional - sage.rings.finite_rings +Infinity """ from sage.rings.infinity import Infinity @@ -1358,8 +1363,8 @@ def key_basis(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(2)) - sage: R.key_basis() + sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R.key_basis() # optional - sage.rings.finite_rings Key polynomial basis over Finite Field of size 2 """ from sage.combinat.key_polynomial import KeyPolynomialBasis @@ -1567,8 +1572,8 @@ def construction(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(5)) - sage: R.construction() + sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: R.construction() # optional - sage.rings.finite_rings [InfPoly{[x,y], "lex", "dense"}, Finite Field of size 5] """ return [InfinitePolynomialFunctor(self._names, self._order, 'dense'), self._base] @@ -1641,7 +1646,8 @@ def polynomial_ring(self): Multivariate Polynomial Ring in xx_0, yy_0 over Integer Ring sage: a = yy[3] sage: X.polynomial_ring() - Multivariate Polynomial Ring in xx_3, xx_2, xx_1, xx_0, yy_3, yy_2, yy_1, yy_0 over Integer Ring + Multivariate Polynomial Ring in xx_3, xx_2, xx_1, xx_0, yy_3, yy_2, yy_1, yy_0 + over Integer Ring """ return self._P diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b597397c9e5..b75f9aebc40 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -179,14 +179,14 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): sage: R. = LaurentPolynomialRing(QQ) sage: a = x^2 + 3*x^3 + 5*x^-1 - sage: a.change_ring(GF(3)) + sage: a.change_ring(GF(3)) # optional - sage.rings.finite_rings 2*x^-1 + x^2 Check that :trac:`22277` is fixed:: sage: R. = LaurentPolynomialRing(QQ) sage: a = 2*x^2 + 3*x^3 + 4*x^-1 - sage: a.change_ring(GF(3)) + sage: a.change_ring(GF(3)) # optional - sage.rings.finite_rings -x^2 + x^-1 """ return self._parent.change_ring(R)(self) @@ -255,38 +255,40 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): EXAMPLES:: - sage: k. = GF(9) - sage: R. = LaurentPolynomialRing(k) - sage: f = x*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = LaurentPolynomialRing(k) # optional - sage.rings.finite_rings + sage: f = x*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (a + 1) + (a + 1)*x - sage: R. = LaurentPolynomialRing(k, 2) - sage: f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: R. = LaurentPolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: f = x*a + 2*x^3*y*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (2*a + 1)*x^3*y + (a + 1)*x + a + 1 Examples with different base ring:: - sage: R. = GF(9); S. = GF(81) - sage: h = Hom(R,S)[0]; h + sage: R. = GF(9); S. = GF(81) # optional - sage.rings.finite_rings + sage: h = Hom(R, S)[0]; h # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = LaurentPolynomialRing(R, 2) - sage: f = r*X+Y - sage: g = f.map_coefficients(h); g + sage: T. = LaurentPolynomialRing(R, 2) # optional - sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings (2*s^3 + 2*s^2 + 1)*X + Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() - sage: g = f.map_coefficients(h); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in s of size 3^4 + sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in r of size 3^2 + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -331,13 +333,13 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): :: - sage: S. = LaurentPolynomialRing(GF(5)) - sage: T. = PolynomialRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentPolynomialRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PolynomialRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Univariate Laurent Polynomial Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 :: @@ -387,7 +389,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: Pxy = PolynomialRing(QQ, "x,y") sage: Paxb = PolynomialRing(QQ, "a,x,b") sage: Qx = PolynomialRing(ZZ, "x") - sage: Rx = PolynomialRing(GF(2), "x") + sage: Rx = PolynomialRing(GF(2), "x") # optional - sage.rings.finite_rings sage: p1 = Lx.gen() sage: p2 = Lx.zero() sage: p3 = Lx.one() @@ -395,8 +397,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: p5 = Lx.gen()**3 + 2*Lx.gen()**2 sage: p6 = Lx.gen() >> 2 - sage: for P,x in [(Px, Px.gen()), (Qx, Qx.gen()), (Rx, Rx.gen()), - ....: (Pxy, Pxy.gen(0)), (Paxb, Paxb.gen(1))]: + sage: Pxes = [(Px, Px.gen()), (Qx, Qx.gen()), + ....: (Pxy, Pxy.gen(0)), (Paxb, Paxb.gen(1))] + sage: Pxes += [(Rx, Rx.gen())] # optional - sage.rings.finite_rings + sage: for P, x in Pxes: ....: assert P(p1) == x and parent(P(p1)) is P ....: assert P(p2) == P.zero() and parent(P(p2)) is P ....: assert P(p3) == P.one() and parent(P(p3)) is P @@ -511,12 +515,12 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): You can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = LaurentPolynomialRing(K) - sage: H = Hom(R, R) - sage: phi = H([t^-2], base_map=cc) - sage: phi(i*t) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = LaurentPolynomialRing(K) # optional - sage.rings.number_field + sage: H = Hom(R, R) # optional - sage.rings.number_field + sage: phi = H([t^-2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*t) # optional - sage.rings.number_field -i*t^-2 """ x = im_gens[0] @@ -605,9 +609,9 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentPolynomialRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentPolynomialRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -813,20 +817,20 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + 2/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + 2)/x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 9 Since :trac:`24072` the symbolic ring does not accept positive characteristic:: - sage: R. = LaurentPolynomialRing(GF(7)) - sage: SR(2*w^3 + 1) + sage: R. = LaurentPolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: SR(2*w^3 + 1) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -1046,10 +1050,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): """ EXAMPLES:: - sage: R. = LaurentPolynomialRing(GF(2)) - sage: f = 1/x^3 + x + x^2 + 3*x^4 - sage: g = 1 - x + x^2 - x^4 - sage: f*g + sage: R. = LaurentPolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: f = 1/x^3 + x + x^2 + 3*x^4 # optional - sage.rings.finite_rings + sage: g = 1 - x + x^2 - x^4 # optional - sage.rings.finite_rings + sage: f*g # optional - sage.rings.finite_rings x^-3 + x^-2 + x^-1 + x^8 """ cdef LaurentPolynomial_univariate right = right_r @@ -2076,7 +2080,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): """ TESTS:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R. = LaurentPolynomialRing(QQ) sage: loads(dumps(x1)) == x1 # indirect doctest True @@ -2179,12 +2183,12 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): check compatibility with :trac:`26105`:: - sage: F. = GF(4) - sage: LF. = LaurentPolynomialRing(F) - sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) - sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs + sage: F. = GF(4) # optional - sage.rings.finite_rings + sage: LF. = LaurentPolynomialRing(F) # optional - sage.rings.finite_rings + sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs # optional - sage.rings.finite_rings a + (t + 1)*b^-1 + t*a^-3*b^2 - sage: s == rho(rs) + sage: s == rho(rs) # optional - sage.rings.finite_rings True """ p = self._poly @@ -2670,7 +2674,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: - sage: L. = LaurentPolynomialRing(QQ,order='degrevlex') + sage: L. = LaurentPolynomialRing(QQ, order='degrevlex') sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 sage: f.coefficients() [4, 3, 2, 1] @@ -2980,11 +2984,11 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: R. = LaurentPolynomialRing(QQ) - sage: (s^2-t^2).quo_rem(s-t) + sage: (s^2 - t^2).quo_rem(s - t) (s + t, 0) - sage: (s^-2-t^2).quo_rem(s-t) + sage: (s^-2 - t^2).quo_rem(s - t) (s + t, -s^2 + s^-2) - sage: (s^-2-t^2).quo_rem(s^-1-t) + sage: (s^-2 - t^2).quo_rem(s^-1 - t) (t + s^-1, 0) TESTS: @@ -3059,7 +3063,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: L. = LaurentPolynomialRing(QQ) - sage: a = w^2*z^-1+3; a + sage: a = w^2*z^-1 + 3; a w^2*z^-1 + 3 sage: e = a.exponents() sage: e.sort(); e @@ -3105,7 +3109,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): OUTPUT: - Returns True if self contains a monomial including the inverse of + Returns True if ``self`` contains a monomial including the inverse of ``self.parent().gen(i)``, False otherwise. EXAMPLES:: @@ -3130,7 +3134,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def has_any_inverse(self): """ - Returns True if self contains any monomials with a negative exponent, False otherwise. + Return True if ``self`` contains any monomials with a negative exponent, False otherwise. EXAMPLES:: @@ -3294,13 +3298,13 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + y/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + y)/x - sage: g(x=2,y=2) + sage: g(x=2, y=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2,y=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic 9 """ d = {repr(g): R.var(g) for g in self._parent.gens()} @@ -3323,7 +3327,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: R = LaurentPolynomialRing(ZZ,'x, y') sage: x, y = R.gens() - sage: t = x**4*y+x*y+y+x**(-1)+y**(-3) + sage: t = x**4*y + x*y + y + x**(-1) + y**(-3) sage: t.derivative(x, x) 12*x^2*y + 2*x^-3 sage: t.derivative(y, 2) @@ -3398,7 +3402,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: f = (x^3 + y^-3)*z sage: f.is_univariate() False - sage: g = f(1,y,4) + sage: g = f(1, y, 4) sage: g.is_univariate() True sage: R(1).is_univariate() @@ -3408,7 +3412,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def univariate_polynomial(self, R=None): """ - Returns a univariate polynomial associated to this + Return a univariate polynomial associated to this multivariate polynomial. INPUT: @@ -3428,7 +3432,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable - sage: g = f(10,y); g + sage: g = f(10, y); g 700*y^2 + 305 - 2*y^-1 sage: h = g.univariate_polynomial(); h -2*y^-1 + 305 + 700*y^2 @@ -3465,7 +3469,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def factor(self): """ - Returns a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial. + Return a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial. EXAMPLES:: @@ -3524,7 +3528,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: L. = LaurentPolynomialRing(QQ) - sage: p = (1 + x*y + z^-3) + sage: p = 1 + x*y + z^-3 sage: (p**2).is_square() True sage: (p**2).is_square(root=True) @@ -3578,14 +3582,14 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: p = x^-2*y + x*y^-2 sage: p.rescale_vars({0: 2, 1: 3}) 2/9*x*y^-2 + 3/4*x^-2*y - sage: F = GF(2) - sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) # optional - sage.rings.finite_rings x*y^-2 + x^-2*y Test for :trac:`30331`:: - sage: F. = CyclotomicField(3) - sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) + sage: F. = CyclotomicField(3) # optional - sage.rings.number_field + sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) # optional - sage.rings.number_field 2*z*x*y^-2 + 1/4*z*x^-2*y """ cdef int i @@ -3638,10 +3642,11 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: L. = LaurentPolynomialRing(QQ, 2) sage: p = 2*x^2 + y - x*y - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]])) + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]])) 2*x^2*y^2 - x^-2*y^2 + x^-3*y - sage: F = GF(2) - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]]), new_ring=L.change_ring(F)) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]]), # optional - sage.rings.finite_rings + ....: new_ring=L.change_ring(F)) x^-2*y^2 + x^-3*y """ diff --git a/src/sage/rings/polynomial/laurent_polynomial_ideal.py b/src/sage/rings/polynomial/laurent_polynomial_ideal.py index 0168a56e267..2289b69e111 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ideal.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ideal.py @@ -55,10 +55,12 @@ def __init__(self, ring, gens, coerce=True, hint=None): sage: R. = LaurentPolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) - Ideal (x, y) of Multivariate Laurent Polynomial Ring in x, y over Integer Ring - sage: R. = LaurentPolynomialRing(GF(3), 2) - sage: R.ideal([x0^2, x1^-3]) - Ideal (x0^2, x1^-3) of Multivariate Laurent Polynomial Ring in x0, x1 over Finite Field of size 3 + Ideal (x, y) of Multivariate Laurent Polynomial Ring in x, y + over Integer Ring + sage: R. = LaurentPolynomialRing(GF(3), 2) # optional - sage.rings.finite_rings + sage: R.ideal([x0^2, x1^-3]) # optional - sage.rings.finite_rings + Ideal (x0^2, x1^-3) of Multivariate Laurent Polynomial Ring in x0, x1 + over Finite Field of size 3 sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([~x + ~y - 1]) @@ -70,19 +72,20 @@ def __init__(self, ring, gens, coerce=True, hint=None): True sage: P. = LaurentPolynomialRing(QQ, 3) - sage: I1 = P.ideal([x*y*z+x*y+2*y^2, x+z]) - sage: I2 = P.ideal([x*y*z+x*y+2*y^2+x+z, x+z]) + sage: I1 = P.ideal([x*y*z + x*y + 2*y^2, x + z]) + sage: I2 = P.ideal([x*y*z + x*y + 2*y^2 + x + z, x + z]) sage: I1 == I2 True - sage: I3 = P.ideal([x*y*z+x*y+2*y^2+x+z, x+z, y]) + sage: I3 = P.ideal([x*y*z + x*y + 2*y^2 + x + z, x + z, y]) sage: I1 < I3 True sage: I1.minimal_associated_primes() - (Ideal (-1/2*z^2 + y - 1/2*z, x + z) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field,) + (Ideal (-1/2*z^2 + y - 1/2*z, x + z) of Multivariate + Laurent Polynomial Ring in x, y, z over Rational Field,) - sage: K. = CyclotomicField(4) - sage: J = I1.base_extend(K) - sage: J.base_ring() + sage: K. = CyclotomicField(4) # optional - sage.rings.number_field + sage: J = I1.base_extend(K) # optional - sage.rings.number_field + sage: J.base_ring() # optional - sage.rings.number_field Cyclotomic Field of order 4 and degree 2 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) @@ -207,10 +210,11 @@ def change_ring(self, R, hint=None): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) + sage: I = P.ideal([x + y]) sage: Q. = LaurentPolynomialRing(QQ, 3) sage: I.change_ring(Q) - Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field + Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y, z + over Rational Field """ return R.ideal(self.gens(), hint=hint) @@ -223,10 +227,11 @@ def base_extend(self, F): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) - sage: K. = CyclotomicField(3) - sage: I.base_extend(K) - Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 + sage: I = P.ideal([x + y]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: I.base_extend(K) # optional - sage.rings.number_field + Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y + over Cyclotomic Field of order 3 and degree 2 """ ring = self.ring() return self.change_ring(ring.change_ring(F), hint=self._hint) @@ -241,12 +246,14 @@ def apply_map(self, f, new_ring=None, new_base_ring=None, apply_to_hint=None): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+1, y-1]) - sage: I.apply_map(lambda z: z+2) - Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: K. = CyclotomicField(4) - sage: I.apply_map(lambda z: z+2, new_base_ring=K) - Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 4 and degree 2 + sage: I = P.ideal([x + 1, y - 1]) + sage: I.apply_map(lambda z: z + 2) + Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y + over Rational Field + sage: K. = CyclotomicField(4) # optional - sage.rings.number_field + sage: I.apply_map(lambda z: z + 2, new_base_ring=K) # optional - sage.rings.number_field + Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y + over Cyclotomic Field of order 4 and degree 2 """ ring = self.ring() if new_ring is not None: @@ -269,16 +276,18 @@ def apply_coeff_map(self, f, new_base_ring=None, forward_hint=True): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: P. = LaurentPolynomialRing(K, 2) - sage: I = P.ideal([x+z, y-z]) - sage: h = K.hom([z^2]) - sage: I.apply_coeff_map(h) - Ideal (x - z - 1, y + z + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 - sage: K1. = CyclotomicField(12) - sage: h1 = K.hom([z1^4]) - sage: I.apply_coeff_map(h1, new_base_ring=K1) - Ideal (x + z1^2 - 1, y - z1^2 + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 12 and degree 4 + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: P. = LaurentPolynomialRing(K, 2) # optional - sage.rings.number_field + sage: I = P.ideal([x + z, y - z]) # optional - sage.rings.number_field + sage: h = K.hom([z^2]) # optional - sage.rings.number_field + sage: I.apply_coeff_map(h) # optional - sage.rings.number_field + Ideal (x - z - 1, y + z + 1) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 3 and degree 2 + sage: K1. = CyclotomicField(12) # optional - sage.rings.number_field + sage: h1 = K.hom([z1^4]) # optional - sage.rings.number_field + sage: I.apply_coeff_map(h1, new_base_ring=K1) # optional - sage.rings.number_field + Ideal (x + z1^2 - 1, y - z1^2 + 1) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 12 and degree 4 """ ring = self.ring() if new_base_ring is None: @@ -301,12 +310,13 @@ def toric_coordinate_change(self, M, forward_hint=True): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: P. = LaurentPolynomialRing(K, 2) - sage: I = P.ideal([x+1, y-1]) - sage: M = Matrix([[2,1],[1,-3]]) - sage: I.toric_coordinate_change(M) - Ideal (x^2*y + 1, -1 + x*y^-3) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: P. = LaurentPolynomialRing(K, 2) # optional - sage.rings.number_field + sage: I = P.ideal([x + 1, y - 1]) # optional - sage.rings.number_field + sage: M = Matrix([[2,1], [1,-3]]) # optional - sage.rings.number_field + sage: I.toric_coordinate_change(M) # optional - sage.rings.number_field + Ideal (x^2*y + 1, -1 + x*y^-3) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 3 and degree 2 """ if forward_hint: R = self.ring() @@ -357,10 +367,12 @@ def normalize_gens(self): sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([~x+y]) sage: J = P.ideal([y+1]) - sage: I+J - Ideal (y + x^-1, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: (I+J).normalize_gens() - Ideal (x - 1, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field + sage: I + J + Ideal (y + x^-1, y + 1) of Multivariate Laurent Polynomial Ring + in x, y over Rational Field + sage: (I + J).normalize_gens() + Ideal (x - 1, y + 1) of Multivariate Laurent Polynomial Ring + in x, y over Rational Field """ return self.ring().ideal(self.groebner_basis(), hint=self._hint) @@ -381,7 +393,8 @@ def polynomial_ideal(self, saturate=True): sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([x^2*y + 3*x*y^2]) sage: I.polynomial_ideal() - Ideal (x + 3*y) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x + 3*y) of Multivariate Polynomial Ring in x, y + over Rational Field """ if self._poly_ideal is not None and (self._saturated or not saturate): return self._poly_ideal @@ -416,9 +429,9 @@ def groebner_basis(self, saturate=True): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) - sage: J = P.ideal([y+1]) - sage: (I+J).groebner_basis() + sage: I = P.ideal([x + y]) + sage: J = P.ideal([y + 1]) + sage: (I + J).groebner_basis() (x - 1, y + 1) """ l = self.polynomial_ideal(saturate=saturate).groebner_basis() @@ -470,10 +483,12 @@ def associated_primes(self): sage: P. = LaurentPolynomialRing(QQ, 3) sage: p = z^2 + 1; q = z^3 + 2 - sage: I = P.ideal((p*q^2, y-z^2)) + sage: I = P.ideal((p*q^2, y - z^2)) sage: tuple(sorted(I.associated_primes(), key=str)) - (Ideal (y + 1, z^2 + 1) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, - Ideal (z^2 - y, y*z + 2, y^2 + 2*z) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) + (Ideal (y + 1, z^2 + 1) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, + Ideal (z^2 - y, y*z + 2, y^2 + 2*z) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) """ l = self.polynomial_ideal(saturate=False).associated_primes() l2 = [self.ring().ideal(I.gens(), hint=I) for I in l] @@ -490,10 +505,12 @@ def minimal_associated_primes(self, saturate=False): sage: P. = LaurentPolynomialRing(QQ, 3) sage: p = z^2 + 1; q = z^3 + 2 - sage: I = P.ideal((p*q^2, y-z^2)) + sage: I = P.ideal((p*q^2, y - z^2)) sage: tuple(sorted(I.minimal_associated_primes(), key=str)) - (Ideal (z^2 + 1, -z^2 + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, - Ideal (z^3 + 2, -z^2 + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) + (Ideal (z^2 + 1, -z^2 + y) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, + Ideal (z^3 + 2, -z^2 + y) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) """ l = self.polynomial_ideal(saturate=saturate).minimal_associated_primes() l2 = [self.ring().ideal(I.gens(), hint=I) for I in l] @@ -508,7 +525,8 @@ def radical(self): sage: P. = LaurentPolynomialRing(QQ, 3) sage: I = P.ideal(((x+1)^2, (y+1)^3, ((x+1)*z)^4 + (y+1)^3 + 10*(x+1)^2)) sage: I.radical() - Ideal (y + 1, x + 1) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field + Ideal (y + 1, x + 1) of Multivariate Laurent Polynomial Ring in x, y, z + over Rational Field """ J = self.polynomial_ideal().radical() return self.ring().ideal(J.gens()) diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring.py b/src/sage/rings/polynomial/laurent_polynomial_ring.py index aaa1166b9d2..956d36da106 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring.py @@ -88,7 +88,7 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): 3. ``LaurentPolynomialRing(base_ring, name, n, order='degrevlex')`` 4. ``LaurentPolynomialRing(base_ring, n, name, order='degrevlex')`` - The optional arguments sparse and order *must* be explicitly + The optional arguments ``sparse`` and ``order`` *must* be explicitly named, and the other arguments must be given positionally. INPUT: @@ -101,10 +101,10 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): - ``order`` -- string or :class:`~sage.rings.polynomial.term_order.TermOrder`, e.g., - - ``'degrevlex'`` (default) -- degree reverse lexicographic - - ``'lex'`` -- lexicographic - - ``'deglex'`` -- degree lexicographic - - ``TermOrder('deglex',3) + TermOrder('deglex',3)`` -- block ordering + - ``'degrevlex'`` (default) -- degree reverse lexicographic + - ``'lex'`` -- lexicographic + - ``'deglex'`` -- degree lexicographic + - ``TermOrder('deglex',3) + TermOrder('deglex',3)`` -- block ordering OUTPUT: @@ -120,7 +120,7 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: - sage: R. = LaurentPolynomialRing(QQ,2); R + sage: R. = LaurentPolynomialRing(QQ, 2); R Multivariate Laurent Polynomial Ring in x, y over Rational Field sage: f = x^2 - 2*y^-2 @@ -162,8 +162,9 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): sage: R. = LaurentPolynomialRing(QQ, sparse=True); R Univariate Laurent Polynomial Ring in abc over Rational Field - sage: R. = LaurentPolynomialRing(PolynomialRing(GF(7),'k')); R - Univariate Laurent Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 + sage: R. = LaurentPolynomialRing(PolynomialRing(GF(7),'k')); R # optional - sage.rings.finite_rings + Univariate Laurent Polynomial Ring in w over + Univariate Polynomial Ring in k over Finite Field of size 7 Rings with different variables are different:: @@ -210,10 +211,12 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: sage: LaurentPolynomialRing(QQ, 'x', 10) - Multivariate Laurent Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 over Rational Field + Multivariate Laurent Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 + over Rational Field - sage: LaurentPolynomialRing(GF(7), 'y', 5) - Multivariate Laurent Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7 + sage: LaurentPolynomialRing(GF(7), 'y', 5) # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in y0, y1, y2, y3, y4 + over Finite Field of size 7 sage: LaurentPolynomialRing(QQ, 'y', 3, sparse=True) Multivariate Laurent Polynomial Ring in y0, y1, y2 over Rational Field @@ -222,11 +225,12 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :meth:`~sage.structure.category_object.CategoryObject.inject_variables` method, all those variable names are available for interactive use:: - sage: R = LaurentPolynomialRing(GF(7),15,'w'); R - Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7 - sage: R.inject_variables() + sage: R = LaurentPolynomialRing(GF(7), 15, 'w'); R # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, + w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7 + sage: R.inject_variables() # optional - sage.rings.finite_rings Defining w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 - sage: (w0 + 2*w8 + w13)^2 + sage: (w0 + 2*w8 + w13)^2 # optional - sage.rings.finite_rings w0^2 + 4*w0*w8 + 4*w8^2 + 2*w0*w13 + 4*w8*w13 + w13^2 """ from sage.rings.polynomial.polynomial_ring import is_PolynomialRing diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring_base.py b/src/sage/rings/polynomial/laurent_polynomial_ring_base.py index 82394e3930c..0296dad3455 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring_base.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring_base.py @@ -40,7 +40,10 @@ class LaurentPolynomialRing_generic(CommutativeRing, Parent): sage: R. = LaurentPolynomialRing(QQ) sage: R.category() - Join of Category of unique factorization domains and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of unique factorization domains + and Category of commutative algebras + over (number fields and quotient fields and metric spaces) + and Category of infinite sets sage: TestSuite(R).run() """ @@ -48,7 +51,7 @@ def __init__(self, R): """ EXAMPLES:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R == loads(dumps(R)) True """ @@ -65,9 +68,9 @@ def ngens(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').ngens() + sage: LaurentPolynomialRing(QQ, 2, 'x').ngens() 2 - sage: LaurentPolynomialRing(QQ,1,'x').ngens() + sage: LaurentPolynomialRing(QQ, 1, 'x').ngens() 1 """ return self._n @@ -79,16 +82,16 @@ def gen(self, i=0): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').gen() + sage: LaurentPolynomialRing(QQ, 2, 'x').gen() x0 - sage: LaurentPolynomialRing(QQ,2,'x').gen(0) + sage: LaurentPolynomialRing(QQ, 2, 'x').gen(0) x0 - sage: LaurentPolynomialRing(QQ,2,'x').gen(1) + sage: LaurentPolynomialRing(QQ, 2, 'x').gen(1) x1 TESTS:: - sage: LaurentPolynomialRing(QQ,2,'x').gen(3) + sage: LaurentPolynomialRing(QQ, 2, 'x').gen(3) Traceback (most recent call last): ... ValueError: generator not defined @@ -140,14 +143,15 @@ def is_integral_domain(self, proof=True): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_integral_domain() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_integral_domain() True The following used to fail; see :trac:`7530`:: sage: L = LaurentPolynomialRing(ZZ, 'X') sage: L['Y'] - Univariate Polynomial Ring in Y over Univariate Laurent Polynomial Ring in X over Integer Ring + Univariate Polynomial Ring in Y over + Univariate Laurent Polynomial Ring in X over Integer Ring """ return self.base_ring().is_integral_domain(proof) @@ -157,7 +161,7 @@ def is_noetherian(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_noetherian() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_noetherian() Traceback (most recent call last): ... NotImplementedError @@ -170,9 +174,9 @@ def construction(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x,y').construction() + sage: LaurentPolynomialRing(QQ, 2, 'x,y').construction() (LaurentPolynomialFunctor, - Univariate Laurent Polynomial Ring in x over Rational Field) + Univariate Laurent Polynomial Ring in x over Rational Field) """ from sage.categories.pushout import LaurentPolynomialFunctor @@ -195,11 +199,9 @@ def completion(self, p=None, prec=20, extras=None): EXAMPLES:: - sage: P. = LaurentPolynomialRing(QQ) - sage: P + sage: P. = LaurentPolynomialRing(QQ); P Univariate Laurent Polynomial Ring in x over Rational Field - sage: PP = P.completion(x) - sage: PP + sage: PP = P.completion(x); PP Laurent Series Ring in x over Rational Field sage: f = 1 - 1/x sage: PP(f) @@ -344,7 +346,7 @@ def _latex_(self): r""" EXAMPLES:: - sage: latex(LaurentPolynomialRing(QQ,2,'x')) + sage: latex(LaurentPolynomialRing(QQ, 2, 'x')) \Bold{Q}[x_{0}^{\pm 1}, x_{1}^{\pm 1}] """ from sage.misc.latex import latex @@ -356,7 +358,7 @@ def _ideal_class_(self, n=0): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x')._ideal_class_() + sage: LaurentPolynomialRing(QQ, 2, 'x')._ideal_class_() Traceback (most recent call last): ... NotImplementedError @@ -368,7 +370,7 @@ def ideal(self, *args, **kwds): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').ideal([1]) + sage: LaurentPolynomialRing(QQ, 2, 'x').ideal([1]) Ideal (1) of Multivariate Laurent Polynomial Ring in x0, x1 over Rational Field TESTS: @@ -415,7 +417,7 @@ def term_order(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').term_order() + sage: LaurentPolynomialRing(QQ, 2, 'x').term_order() Degree reverse lexicographic term order """ @@ -425,7 +427,7 @@ def is_finite(self): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_finite() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_finite() False """ @@ -435,7 +437,7 @@ def is_field(self, proof = True): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_field() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_field() False """ return False @@ -446,9 +448,9 @@ def polynomial_ring(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').polynomial_ring() + sage: LaurentPolynomialRing(QQ, 2, 'x').polynomial_ring() Multivariate Polynomial Ring in x0, x1 over Rational Field - sage: LaurentPolynomialRing(QQ,1,'x').polynomial_ring() + sage: LaurentPolynomialRing(QQ, 1, 'x').polynomial_ring() Multivariate Polynomial Ring in x over Rational Field """ return self._R @@ -459,7 +461,7 @@ def characteristic(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').characteristic() + sage: LaurentPolynomialRing(QQ, 2, 'x').characteristic() 0 sage: LaurentPolynomialRing(GF(3), 2, 'x').characteristic() # optional - sage.libs.pari 3 @@ -471,7 +473,7 @@ def krull_dimension(self): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').krull_dimension() + sage: LaurentPolynomialRing(QQ, 2, 'x').krull_dimension() Traceback (most recent call last): ... NotImplementedError @@ -482,7 +484,7 @@ def random_element(self, low_degree = -2, high_degree = 2, terms = 5, choose_deg """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').random_element() + sage: LaurentPolynomialRing(QQ, 2, 'x').random_element() Traceback (most recent call last): ... NotImplementedError @@ -495,9 +497,9 @@ def is_exact(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_exact() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_exact() True - sage: LaurentPolynomialRing(RDF,2,'x').is_exact() + sage: LaurentPolynomialRing(RDF, 2, 'x').is_exact() False """ return self.base_ring().is_exact() @@ -506,7 +508,7 @@ def change_ring(self, base_ring=None, names=None, sparse=False, order=None): """ EXAMPLES:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R.change_ring(ZZ) Multivariate Laurent Polynomial Ring in x0, x1 over Integer Ring diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 28d4265dc82..56dad8b0f55 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -185,13 +185,13 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + y - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic x^3 + y - sage: g(x=2,y=2) + sage: g(x=2, y=2) # optional - sage.symbolic 10 - sage: g = SR(f) - sage: g(x=2,y=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic 10 """ d = dict([(repr(g), R.var(g)) for g in self.parent().gens()]) @@ -214,23 +214,23 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = PolynomialRing(QQ,3,order='degrevlex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(QQ, 3, order='degrevlex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [23, 6, 1] - sage: R. = PolynomialRing(QQ,3,order='lex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(QQ, 3, order='lex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [6, 23, 1] Test the same stuff with base ring `\ZZ` -- different implementation:: - sage: R. = PolynomialRing(ZZ,3,order='degrevlex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(ZZ, 3, order='degrevlex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [23, 6, 1] - sage: R. = PolynomialRing(ZZ,3,order='lex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(ZZ, 3, order='lex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [6, 23, 1] @@ -303,10 +303,10 @@ cdef class MPolynomial(CommutativePolynomial): def derivative(self, *args): r""" The formal derivative of this polynomial, with respect to - variables supplied in args. + variables supplied in ``args``. Multiple variables and iteration counts may be supplied; see - documentation for the global derivative() function for more details. + documentation for the global function :func:`derivative` for more details. .. SEEALSO:: :meth:`._derivative` @@ -314,13 +314,13 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials implemented via Singular:: - sage: R. = PolynomialRing(FiniteField(5)) - sage: f = x^3*y^5 + x^7*y - sage: type(f) + sage: R. = PolynomialRing(FiniteField(5)) # optional - sage.rings.finite_rings + sage: f = x^3*y^5 + x^7*y # optional - sage.rings.finite_rings + sage: type(f) # optional - sage.rings.finite_rings - sage: f.derivative(x) + sage: f.derivative(x) # optional - sage.rings.finite_rings 2*x^6*y - 2*x^2*y^5 - sage: f.derivative(y) + sage: f.derivative(y) # optional - sage.rings.finite_rings x^7 Generic multivariate polynomials:: @@ -347,12 +347,12 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials over the symbolic ring (just for fun....):: - sage: x = var("x") - sage: S. = PolynomialRing(SR) - sage: f = u*v*x - sage: f.derivative(x) == u*v + sage: x = var("x") # optional - sage.symbolic + sage: S. = PolynomialRing(SR) # optional - sage.symbolic + sage: f = u*v*x # optional - sage.symbolic + sage: f.derivative(x) == u*v # optional - sage.symbolic True - sage: f.derivative(u) == v*x + sage: f.derivative(u) == v*x # optional - sage.symbolic True """ return multi_derivative(self, args) @@ -360,8 +360,8 @@ cdef class MPolynomial(CommutativePolynomial): def polynomial(self, var): """ - Let var be one of the variables of the parent of self. This - returns self viewed as a univariate polynomial in var over the + Let ``var`` be one of the variables of the parent of ``self``. This + returns ``self`` viewed as a univariate polynomial in ``var`` over the polynomial ring generated by all the other variables of the parent. EXAMPLES:: @@ -371,7 +371,8 @@ cdef class MPolynomial(CommutativePolynomial): sage: f.polynomial(x) x^3 + (17*w^3 + 3*w)*x + w^5 + z^5 sage: parent(f.polynomial(x)) - Univariate Polynomial Ring in x over Multivariate Polynomial Ring in w, z over Rational Field + Univariate Polynomial Ring in x + over Multivariate Polynomial Ring in w, z over Rational Field sage: f.polynomial(w) w^5 + 17*x*w^3 + 3*x*w + z^5 + x^3 @@ -387,11 +388,11 @@ cdef class MPolynomial(CommutativePolynomial): z^5 + x*w*k*z + w^5 + 17*x*w^3 + x^3 + 3*x*w + 5 sage: f.polynomial(k) x*w*z*k + w^5 + z^5 + 17*x*w^3 + x^3 + 3*x*w + 5 - sage: R.=GF(5)[] - sage: f=x^2+x+y - sage: f.polynomial(x) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = x^2 + x + y # optional - sage.rings.finite_rings + sage: f.polynomial(x) # optional - sage.rings.finite_rings x^2 + x + y - sage: f.polynomial(y) + sage: f.polynomial(y) # optional - sage.rings.finite_rings y + x^2 + x """ cdef int ind @@ -444,8 +445,8 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R = Qp(7)['x,y,z,t,p']; S = ZZ['x,z,t']['p'] - sage: R(S.0) + sage: R = Qp(7)['x,y,z,t,p']; S = ZZ['x,z,t']['p'] # optional - sage.rings.padics + sage: R(S.0) # optional - sage.rings.padics p sage: R = QQ['x,y,z,t,p']; S = ZZ['x']['y,z,t']['p'] sage: z = S.base_ring().gen(1) @@ -455,8 +456,8 @@ cdef class MPolynomial(CommutativePolynomial): sage: z = S.base_ring().gen(1); p = S.0; x = S.base_ring().base_ring().gen() sage: R(z+p) z + p - sage: R = Qp(7)['x,y,z,p']; S = ZZ['x']['y,z,t']['p'] # shouldn't work, but should throw a better error - sage: R(S.0) + sage: R = Qp(7)['x,y,z,p']; S = ZZ['x']['y,z,t']['p'] # shouldn't work, but should throw a better error # optional - sage.rings.padics + sage: R(S.0) # optional - sage.rings.padics p See :trac:`2601`:: @@ -559,9 +560,9 @@ cdef class MPolynomial(CommutativePolynomial): Verify that :trac:`16251` has been resolved, i.e., polynomials with unhashable coefficients are unhashable:: - sage: K. = Qq(9) - sage: R. = K[] - sage: hash(t) + sage: K. = Qq(9) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: hash(t) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' @@ -597,7 +598,7 @@ cdef class MPolynomial(CommutativePolynomial): def args(self): r""" - Returns the named of the arguments of self, in the + Returns the names of the arguments of ``self``, in the order they are accepted from call. EXAMPLES:: @@ -689,9 +690,9 @@ cdef class MPolynomial(CommutativePolynomial): In particular, this can be surprising in positive characteristic:: - sage: R. = GF(2)[] - sage: f = x + 1 - sage: f.homogenize(x) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: f = x + 1 # optional - sage.rings.finite_rings + sage: f.homogenize(x) # optional - sage.rings.finite_rings 0 TESTS:: @@ -738,7 +739,7 @@ cdef class MPolynomial(CommutativePolynomial): def is_homogeneous(self): r""" - Return ``True`` if self is a homogeneous polynomial. + Return ``True`` if ``self`` is a homogeneous polynomial. TESTS:: @@ -814,15 +815,15 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: f = (x^2*y + 2*x - 3) sage: g = (x + 1)*f - sage: g % f + sage: g % f # optional - sage.libs.singular 0 - sage: (g+1) % f + sage: (g+1) % f # optional - sage.libs.singular 1 sage: M = x*y sage: N = x^2*y^3 - sage: M.divides(N) + sage: M.divides(N) # optional - sage.libs.singular True """ try: @@ -846,21 +847,21 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + 3/5*y + 1 - sage: f.change_ring(GF(7)) + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings x^3 + 2*y + 1 :: - sage: R. = GF(9,'a')[] - sage: (x+2*y).change_ring(GF(3)) + sage: R. = GF(9,'a')[] # optional - sage.rings.finite_rings + sage: (x+2*y).change_ring(GF(3)) # optional - sage.rings.finite_rings x - y :: - sage: K. = CyclotomicField(3) - sage: R. = K[] - sage: f = x^2 + z*y - sage: f.change_ring(K.embeddings(CC)[1]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + z*y # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(CC)[1]) # optional - sage.rings.number_field x^2 + (-0.500000000000000 - 0.866025403784438*I)*y TESTS: @@ -868,7 +869,7 @@ cdef class MPolynomial(CommutativePolynomial): Check that :trac:`25022` is fixed:: sage: K. = ZZ[] - sage: (x*y).change_ring(SR).monomials() + sage: (x*y).change_ring(SR).monomials() # optional - sage.rings.number_field [x*y] """ if isinstance(R, Map): @@ -892,47 +893,51 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: p = (x+y+z)**2 - 3 * (x+y)*(x+z)*(y+z) - sage: p.is_symmetric() + sage: p.is_symmetric() # optional - sage.groups True - sage: (x + y - z).is_symmetric() + sage: (x + y - z).is_symmetric() # optional - sage.groups False - sage: R.one().is_symmetric() + sage: R.one().is_symmetric() # optional - sage.groups True sage: p = (x-y)*(y-z)*(z-x) - sage: p.is_symmetric() + sage: p.is_symmetric() # optional - sage.groups False - sage: p.is_symmetric(AlternatingGroup(3)) + sage: p.is_symmetric(AlternatingGroup(3)) # optional - sage.groups True sage: R. = QQ[] - sage: ((x + y)**2).is_symmetric() + sage: ((x + y)**2).is_symmetric() # optional - sage.groups True - sage: R.one().is_symmetric() + sage: R.one().is_symmetric() # optional - sage.groups True - sage: (x + 2*y).is_symmetric() + sage: (x + 2*y).is_symmetric() # optional - sage.groups False An example with a GAP permutation group (here the quaternions):: sage: R = PolynomialRing(QQ, 'x', 8) sage: x = R.gens() - sage: p = sum(prod(x[i] for i in e) for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), (3,4,5), (3,4,6), (3,5,6), (4,5,6)]) - sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) + sage: p = sum(prod(x[i] for i in e) + ....: for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), + ....: (3,4,5), (3,4,6), (3,5,6), (4,5,6)]) + sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) # optional - sage.groups True - sage: p = sum(prod(x[i] for i in e) for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), (3,4,5), (3,4,6), (3,5,6)]) - sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) + sage: p = sum(prod(x[i] for i in e) + ....: for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), + ....: (3,4,5), (3,4,6), (3,5,6)]) + sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) # optional - sage.groups False TESTS:: sage: R = PolynomialRing(QQ, 'x', 3) - sage: R.one().is_symmetric(3) + sage: R.one().is_symmetric(3) # optional - sage.groups Traceback (most recent call last): ... ValueError: argument must be a permutation group - sage: R.one().is_symmetric(SymmetricGroup(4)) + sage: R.one().is_symmetric(SymmetricGroup(4)) # optional - sage.groups Traceback (most recent call last): ... ValueError: invalid data to initialize a permutation @@ -975,39 +980,39 @@ cdef class MPolynomial(CommutativePolynomial): Multivariate polynomial over integers:: sage: R. = ZZ[] - sage: gap(-x*y + 3*z) # indirect doctest + sage: gap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: gap(R.zero()) # indirect doctest + sage: gap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 - sage: (x+y+z)._gap_(libgap) + sage: (x+y+z)._gap_(libgap) # optional - sage.libs.gap x+y+z - sage: g = gap(x - y + 3*x*y*z) - sage: R(g) + sage: g = gap(x - y + 3*x*y*z) # optional - sage.libs.gap + sage: R(g) # optional - sage.libs.gap 3*x*y*z + x - y - sage: g = libgap(5*x - y*z) - sage: R(g) + sage: g = libgap(5*x - y*z) # optional - sage.libs.gap + sage: R(g) # optional - sage.libs.gap -y*z + 5*x Multivariate polynomial over a cyclotomic field:: - sage: F. = CyclotomicField(8) - sage: P. = F[] - sage: p = zeta + zeta^2*x + zeta^3*y + (1+zeta)*x*y - sage: gap(p) # indirect doctest + sage: F. = CyclotomicField(8) # optional - sage.rings.number_field + sage: P. = F[] # optional - sage.rings.number_field + sage: p = zeta + zeta^2*x + zeta^3*y + (1+zeta)*x*y # optional - sage.rings.number_field + sage: gap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field (1+E(8))*x*y+E(4)*x+E(8)^3*y+E(8) - sage: libgap(p) # indirect doctest + sage: libgap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field (1+E(8))*x*y+E(4)*x+E(8)^3*y+E(8) Multivariate polynomial over a polynomial ring over a cyclotomic field:: - sage: S. = F[] - sage: P. = S[] - sage: p = zeta + zeta^2*x*z + zeta^3*y*z^2 + (1+zeta)*x*y*z - sage: gap(p) # indirect doctest + sage: S. = F[] # optional - sage.rings.number_field + sage: P. = S[] # optional - sage.rings.number_field + sage: p = zeta + zeta^2*x*z + zeta^3*y*z^2 + (1+zeta)*x*y*z # optional - sage.rings.number_field + sage: gap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field ((1+E(8))*z)*x*y+E(4)*z*x+E(8)^3*z^2*y+E(8) - sage: libgap(p) # indirect doctest + sage: libgap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field ((1+E(8))*z)*x*y+E(4)*z*x+E(8)^3*z^2*y+E(8) """ R = gap(self.parent()) @@ -1019,9 +1024,9 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x*y + 3*z) # indirect doctest + sage: libgap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: libgap(R.zero()) # indirect doctest + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -1029,17 +1034,17 @@ cdef class MPolynomial(CommutativePolynomial): def _magma_init_(self, magma): """ - Returns a Magma string representation of self valid in the + Returns a Magma string representation of ``self`` valid in the given magma session. EXAMPLES:: - sage: k. = GF(25); R. = k[] - sage: f = y*x^2*b + x*(b+1) + 1 - sage: magma = Magma() # so var names same below - sage: magma(f) # optional - magma + sage: k. = GF(25); R. = k[] # optional - sage.rings.finite_rings + sage: f = y*x^2*b + x*(b+1) + 1 # optional - sage.rings.finite_rings + sage: magma = Magma() # so var names same below # optional - sage.rings.finite_rings + sage: magma(f) # optional - magma # optional - sage.rings.finite_rings b*x^2*y + b^22*x + 1 - sage: f._magma_init_(magma) # optional - magma + sage: f._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings '_sage_[...]!((_sage_[...]!(_sage_[...]))*_sage_[...]^2*_sage_[...]+(_sage_[...]!(_sage_[...] + 1))*_sage_[...]+(_sage_[...]!(1))*1)' A more complicated nested example:: @@ -1069,13 +1074,13 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] - sage: f = R('e*i') * x + y^2 - sage: f._giac_init_() + sage: R. = GF(101)['e,i'][] # optional - sage.rings.finite_rings + sage: f = R('e*i') * x + y^2 # optional - sage.rings.finite_rings + sage: f._giac_init_() # optional - sage.rings.finite_rings '((1)*1)*sageVARy^2+((1)*sageVARe*sageVARi)*sageVARx' - sage: giac(f) + sage: giac(f) # optional - sage.rings.finite_rings sageVARy^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) + sage: giac(R.zero()) # optional - sage.rings.finite_rings 0 """ g = ['sageVAR' + x for x in self.parent().variable_names()] @@ -1091,7 +1096,7 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: P. = PolynomialRing(ZZ,3) + sage: P. = PolynomialRing(ZZ, 3) sage: f = x*y + 1 sage: f.gradient() [y, x, 0] @@ -1119,20 +1124,20 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = 1 + x*y + x^3 + y^3 - sage: P = f.newton_polytope() - sage: P + sage: P = f.newton_polytope() # optional - sage.geometry.polyhedron + sage: P # optional - sage.geometry.polyhedron A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices - sage: P.is_simple() + sage: P.is_simple() # optional - sage.geometry.polyhedron True TESTS:: sage: R. = QQ[] - sage: R(0).newton_polytope() + sage: R(0).newton_polytope() # optional - sage.geometry.polyhedron The empty polyhedron in ZZ^0 - sage: R(1).newton_polytope() + sage: R(1).newton_polytope() # optional - sage.geometry.polyhedron A 0-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex - sage: R(x^2+y^2).newton_polytope().integral_points() + sage: R(x^2+y^2).newton_polytope().integral_points() # optional - sage.geometry.polyhedron ((0, 2), (1, 1), (2, 0)) """ from sage.geometry.polyhedron.constructor import Polyhedron @@ -1142,7 +1147,7 @@ cdef class MPolynomial(CommutativePolynomial): def __iter__(self): """ - Facilitates iterating over the monomials of self, + Facilitates iterating over the monomials of ``self``, returning tuples of the form ``(coeff, mon)`` for each non-zero monomial. @@ -1266,7 +1271,7 @@ cdef class MPolynomial(CommutativePolynomial): def map_coefficients(self, f, new_base_ring=None): """ Returns the polynomial obtained by applying ``f`` to the non-zero - coefficients of self. + coefficients of ``self``. If ``f`` is a :class:`sage.categories.map.Map`, then the resulting polynomial will be defined over the codomain of ``f``. Otherwise, the @@ -1275,39 +1280,39 @@ cdef class MPolynomial(CommutativePolynomial): INPUT: - - ``f`` -- a callable that will be applied to the coefficients of self. + - ``f`` -- a callable that will be applied to the coefficients of ``self``. - ``new_base_ring`` (optional) -- if given, the resulting polynomial will be defined over this ring. EXAMPLES:: - sage: k. = GF(9); R. = k[]; f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: k. = GF(9); R. = k[]; f = x*a + 2*x^3*y*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (-a + 1)*x^3*y + (a + 1)*x + (a + 1) Examples with different base ring:: - sage: R. = GF(9); S. = GF(81) - sage: h = Hom(R,S)[0]; h + sage: R. = GF(9); S. = GF(81) # optional - sage.rings.finite_rings + sage: h = Hom(R,S)[0]; h # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = R[] - sage: f = r*X+Y - sage: g = f.map_coefficients(h); g + sage: T. = R[] # optional - sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings (-s^3 - s^2 + 1)*X + Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() - sage: g = f.map_coefficients(h); g + sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -1331,10 +1336,10 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: k. = GF(9) - sage: R. = PolynomialRing(k) - sage: f = (x-a)*(y-a) - sage: f._norm_over_nonprime_finite_field() + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: f = (x-a) * (y-a) # optional - sage.rings.finite_rings + sage: f._norm_over_nonprime_finite_field() # optional - sage.rings.finite_rings x^2*y^2 - x^2*y - x*y^2 - x^2 + x*y - y^2 + x + y + 1 """ P = self.parent() @@ -1348,7 +1353,7 @@ cdef class MPolynomial(CommutativePolynomial): def sylvester_matrix(self, right, variable = None): """ - Given two nonzero polynomials self and right, returns the Sylvester + Given two nonzero polynomials ``self`` and ``right``, return the Sylvester matrix of the polynomials with respect to a given variable. Note that the Sylvester matrix is not defined if one of the polynomials @@ -1356,22 +1361,22 @@ cdef class MPolynomial(CommutativePolynomial): INPUT: - - self , right: multivariate polynomials - - variable: optional, compute the Sylvester matrix with respect to this - variable. If variable is not provided, the first variable of the + - ``self``, ``right``: multivariate polynomials + - ``variable``: optional, compute the Sylvester matrix with respect to this + variable. If ``variable`` is not provided, the first variable of the polynomial ring is used. OUTPUT: - - The Sylvester matrix of self and right. + - The Sylvester matrix of ``self`` and ``right``. EXAMPLES:: sage: R. = PolynomialRing(ZZ) sage: f = (y + 1)*x + 3*x**2 sage: g = (y + 2)*x + 4*x**2 - sage: M = f.sylvester_matrix(g, x) - sage: M + sage: M = f.sylvester_matrix(g, x) # optional - sage.modules + sage: M # optional - sage.modules [ 3 y + 1 0 0] [ 0 3 y + 1 0] [ 4 y + 2 0 0] @@ -1380,13 +1385,13 @@ cdef class MPolynomial(CommutativePolynomial): If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will be zero:: - sage: M.determinant() + sage: M.determinant() # optional - sage.modules 0 - sage: f.sylvester_matrix(1 + g, x).determinant() + sage: f.sylvester_matrix(1 + g, x).determinant() # optional - sage.modules y^2 - y + 7 - If both polynomials are of positive degree with respect to variable, the + If both polynomials are of positive degree with respect to ``variable``, the determinant of the Sylvester matrix is the resultant:: sage: f = R.random_element(4) or (x^2 * y^2) @@ -1400,7 +1405,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: f = x + y sage: g = x + y - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules [1 y] [1 y] @@ -1412,45 +1417,47 @@ cdef class MPolynomial(CommutativePolynomial): sage: g = x + y sage: R. = GF(25, 'a')[] sage: h = x + y - sage: f.sylvester_matrix(g, 'x') + sage: f.sylvester_matrix(g, 'x') # optional - sage.modules [1 y] [1 y] - sage: g.sylvester_matrix(h, 'x') + sage: g.sylvester_matrix(h, 'x') # optional - sage.modules [1 y] [1 y] - sage: f.sylvester_matrix(h, 'x') + sage: f.sylvester_matrix(h, 'x') # optional - sage.modules 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 x, y over Finite Field in a of size 5^2' + TypeError: no common canonical parent for objects with parents: + 'Multivariate Polynomial Ring in x, y over Rational Field' and + 'Multivariate Polynomial Ring in x, y over Finite Field in a of size 5^2' sage: K. = QQ[] sage: f = x + y sage: L. = QQ[] sage: g = x + z - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules [1 y] [1 z] Corner cases:: - sage: K.=QQ[] - sage: f = x^2+1 + sage: K.=QQ[] + sage: f = x^2 + 1 sage: g = K(0) - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(f) + sage: g.sylvester_matrix(f) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(g) + sage: g.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: K(3).sylvester_matrix(x^2) + sage: K(3).sylvester_matrix(x^2) # optional - sage.modules [3 0] [0 3] - sage: K(3).sylvester_matrix(K(4)) + sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules [] """ @@ -1501,52 +1508,48 @@ cdef class MPolynomial(CommutativePolynomial): def discriminant(self,variable): """ - Returns the discriminant of self with respect to the given variable. + Returns the discriminant of ``self`` with respect to the given variable. INPUT: - - ``variable`` - The variable with respect to which we compute - the discriminant - - OUTPUT: - - - An element of the base ring of the polynomial ring. + - ``variable`` - The variable with respect to which we compute + the discriminant + OUTPUT: An element of the base ring of the polynomial ring. EXAMPLES:: - sage: R.=QQ[] - sage: f=4*x*y^2 + 1/4*x*y*z + 3/2*x*z^2 - 1/2*z^2 - sage: f.discriminant(x) + sage: R. = QQ[] + sage: f = 4*x*y^2 + 1/4*x*y*z + 3/2*x*z^2 - 1/2*z^2 + sage: f.discriminant(x) # optional - sage.libs.singular 1 - sage: f.discriminant(y) + sage: f.discriminant(y) # optional - sage.libs.singular -383/16*x^2*z^2 + 8*x*z^2 - sage: f.discriminant(z) + sage: f.discriminant(z) # optional - sage.libs.singular -383/16*x^2*y^2 + 8*x*y^2 Note that, unlike the univariate case, the result lives in the same ring as the polynomial:: - sage: R.=QQ[] - sage: f=x^5*y+3*x^2*y^2-2*x+y-1 - sage: f.discriminant(y) + sage: R. = QQ[] + sage: f = x^5*y+3*x^2*y^2-2*x+y-1 + sage: f.discriminant(y) # optional - sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - sage: f.polynomial(y).discriminant() + sage: f.polynomial(y).discriminant() # optional - sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - sage: f.discriminant(y).parent()==f.polynomial(y).discriminant().parent() + sage: f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # optional - sage.libs.singular False TESTS: Test polynomials over QQbar (:trac:`25265`):: - sage: R.=QQbar[] - sage: f=x^5*y+3*x^2*y^2-2*x+y-1 - sage: f.discriminant(y) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 # optional - sage.rings.number_field + sage: f.discriminant(y) # optional - sage.rings.number_field x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - AUTHOR: - Miguel Marco + AUTHOR: Miguel Marco """ if self.is_zero(): return self.parent().zero() @@ -1595,7 +1598,7 @@ cdef class MPolynomial(CommutativePolynomial): def macaulay_resultant(self, *args): r""" - This is an implementation of the Macaulay Resultant. It computes + This is an implementation of the Macaulay resultant. It computes the resultant of universal polynomials as well as polynomials with constant coefficients. This is a project done in sage days 55. It's based on the implementation in Maple by @@ -1610,36 +1613,36 @@ cdef class MPolynomial(CommutativePolynomial): INPUT: - ``args`` -- a list of `n-1` homogeneous polynomials in `n` variables. - works when ``args[0]`` is the list of polynomials, - or ``args`` is itself the list of polynomials + works when ``args[0]`` is the list of polynomials, + or ``args`` is itself the list of polynomials OUTPUT: - - the macaulay resultant + - the Macaulay resultant EXAMPLES: The number of polynomials has to match the number of variables:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant(x+z) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant(x + z) # optional - sage.modules Traceback (most recent call last): ... TypeError: number of polynomials(= 2) must equal number of variables (= 3) The polynomials need to be all homogeneous:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant([x+z, z+x^3]) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant([x + z, z + x^3]) # optional - sage.modules Traceback (most recent call last): ... TypeError: resultant for non-homogeneous polynomials is not supported All polynomials must be in the same ring:: - sage: R. = PolynomialRing(QQ,3) + sage: R. = PolynomialRing(QQ, 3) sage: S. = PolynomialRing(QQ, 2) - sage: y.macaulay_resultant(z+x,z) + sage: y.macaulay_resultant(z + x, z) # optional - sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring @@ -1647,15 +1650,15 @@ cdef class MPolynomial(CommutativePolynomial): The following example recreates Proposition 2.10 in Ch.3 of Using Algebraic Geometry:: sage: K. = PolynomialRing(ZZ, 2) - sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,2]) - sage: flist[0].macaulay_resultant(flist[1:]) + sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) + sage: flist[0].macaulay_resultant(flist[1:]) # optional - sage.modules u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - 2*u0*u2*u3*u5*u9 + u0^2*u5^2*u9 - u1*u2*u3^2*u10 + u0*u2*u3*u4*u10 + u0*u1*u3*u5*u10 - u0^2*u4*u5*u10 + u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11 The following example degenerates into the determinant of a `3*3` matrix:: sage: K. = PolynomialRing(ZZ, 2) - sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,1]) - sage: flist[0].macaulay_resultant(flist[1:]) + sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,1]) + sage: flist[0].macaulay_resultant(flist[1:]) # optional - sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8 The following example is by Patrick Ingram (:arxiv:`1310.4114`):: @@ -1665,56 +1668,56 @@ cdef class MPolynomial(CommutativePolynomial): sage: f0 = y0*x2^2 - x0^2 + 2*x1*x2 sage: f1 = y1*x2^2 - x1^2 + 2*x0*x2 sage: f2 = x0*x1 - x2^2 - sage: f0.macaulay_resultant(f1,f2) + sage: f0.macaulay_resultant(f1, f2) # optional - sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27 a simple example with constant rational coefficients:: - sage: R. = PolynomialRing(QQ,4) - sage: w.macaulay_resultant([z,y,x]) + sage: R. = PolynomialRing(QQ, 4) + sage: w.macaulay_resultant([z, y, x]) # optional - sage.modules 1 an example where the resultant vanishes:: - sage: R. = PolynomialRing(QQ,3) - sage: (x+y).macaulay_resultant([y^2,x]) + sage: R. = PolynomialRing(QQ, 3) + sage: (x + y).macaulay_resultant([y^2, x]) # optional - sage.modules 0 an example of bad reduction at a prime ``p = 5``:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant([x^3+25*y^2*x,5*z]) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant([x^3 + 25*y^2*x, 5*z]) # optional - sage.modules 125 The input can given as an unpacked list of polynomials:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant(x^3+25*y^2*x,5*z) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant(x^3 + 25*y^2*x, 5*z) # optional - sage.modules 125 an example when the coefficients live in a finite field:: - sage: F = FiniteField(11) - sage: R. = PolynomialRing(F,4) - sage: z.macaulay_resultant([x^3,5*y,w]) + sage: F = FiniteField(11) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(F, 4) # optional - sage.rings.finite_rings + sage: z.macaulay_resultant([x^3, 5*y, w]) # optional - sage.rings.finite_rings sage.modules 4 example when the denominator in the algorithm vanishes(in this case the resultant is the constant term of the quotient of char polynomials of numerator/denominator):: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant([x+z, z^2]) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant([x + z, z^2]) # optional - sage.modules -1 - when there are only 2 polynomials, macaulay resultant degenerates to the traditional resultant:: + When there are only 2 polynomials, the Macaulay resultant degenerates to the traditional resultant:: - sage: R. = PolynomialRing(QQ,1) - sage: f = x^2+1; g = x^5+1 + sage: R. = PolynomialRing(QQ, 1) + sage: f = x^2 + 1; g = x^5 + 1 sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() - sage: f.resultant(g) == fh.macaulay_resultant(gh) + sage: f.resultant(g) == fh.macaulay_resultant(gh) # optional - sage.modules True """ @@ -1724,11 +1727,11 @@ cdef class MPolynomial(CommutativePolynomial): def denominator(self): """ - Return a denominator of self. + Return a denominator of ``self``. - First, the lcm of the denominators of the entries of self + First, the lcm of the denominators of the entries of ``self`` is computed and returned. If this computation fails, the - unit of the parent of self is returned. + unit of the parent of ``self`` is returned. Note that some subclasses may implement its own denominator function. @@ -1755,10 +1758,10 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: R. = NumberField(symbolic_expression(x^2+3) ,'a')['x,y'] - sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f + sage: R. = NumberField(symbolic_expression(x^2+3),'a')['x,y'] # optional - sage.rings.number_field sage.symbolic + sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f # optional - sage.rings.number_field sage.symbolic 1/17*x^19 - 2/3*x + 1/6*y + 1/3 - sage: f.denominator() + sage: f.denominator() # optional - sage.rings.number_field sage.symbolic 102 Finally, we try to compute the denominator of a polynomial with @@ -1776,18 +1779,18 @@ cdef class MPolynomial(CommutativePolynomial): Check that the denominator is an element over the base whenever the base has no denominator function. This closes :trac:`9063`:: - sage: R. = GF(5)[] - sage: x = R(0) - sage: x.denominator() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: x = R(0) # optional - sage.rings.finite_rings + sage: x.denominator() # optional - sage.rings.finite_rings 1 - sage: type(x.denominator()) + sage: type(x.denominator()) # optional - sage.rings.finite_rings - sage: type(a.denominator()) + sage: type(a.denominator()) # optional - sage.rings.finite_rings sage: from sage.rings.polynomial.multi_polynomial_element import MPolynomial - sage: isinstance(a / b, MPolynomial) + sage: isinstance(a / b, MPolynomial) # optional - sage.rings.finite_rings False - sage: isinstance(a.numerator() / a.denominator(), MPolynomial) + sage: isinstance(a.numerator() / a.denominator(), MPolynomial) # optional - sage.rings.finite_rings True """ if self.degree() == -1: @@ -1803,7 +1806,7 @@ cdef class MPolynomial(CommutativePolynomial): def numerator(self): """ - Return a numerator of self computed as self * self.denominator() + Return a numerator of ``self``, computed as ``self * self.denominator()``. Note that some subclasses may implement its own numerator function. @@ -1811,13 +1814,13 @@ cdef class MPolynomial(CommutativePolynomial): .. warning:: This is not the numerator of the rational function - defined by self, which would always be self since self is a + defined by ``self``, which would always be self since ``self`` is a polynomial. EXAMPLES: First we compute the numerator of a polynomial with - integer coefficients, which is of course self. + integer coefficients, which is of course ``self``. :: @@ -1832,12 +1835,12 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: R. = NumberField(symbolic_expression(x^2+3) ,'a')['x,y'] - sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f + sage: R. = NumberField(symbolic_expression(x^2+3), 'a')['x,y'] # optional - sage.rings.number_field sage.symbolic + sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f # optional - sage.rings.number_field sage.symbolic 1/17*y^19 - 2/3*x + 1/3 - sage: f.numerator() + sage: f.numerator() # optional - sage.rings.number_field sage.symbolic 3*y^19 - 34*x + 17 - sage: f == f.numerator() + sage: f == f.numerator() # optional - sage.rings.number_field sage.symbolic False We try to compute the numerator of a polynomial with coefficients in @@ -1845,23 +1848,23 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: K. = GF(3)['x, y, z'] - sage: f = 2*x*z + 2*z^2 + 2*y + 1; f + sage: K. = GF(3)['x, y, z'] # optional - sage.rings.finite_rings + sage: f = 2*x*z + 2*z^2 + 2*y + 1; f # optional - sage.rings.finite_rings -x*z - z^2 - y + 1 - sage: f.numerator() + sage: f.numerator() # optional - sage.rings.finite_rings -x*z - z^2 - y + 1 We check that the computation the numerator and denominator - are valid + are valid. :: - sage: K=NumberField(symbolic_expression('x^3+2'),'a')['x']['s,t'] - sage: f=K.random_element() - sage: f.numerator() / f.denominator() == f + sage: K = NumberField(symbolic_expression('x^3+2'), 'a')['x']['s,t'] # optional - sage.rings.number_field sage.symbolic + sage: f = K.random_element() # optional - sage.rings.number_field sage.symbolic + sage: f.numerator() / f.denominator() == f # optional - sage.rings.number_field sage.symbolic True - sage: R=RR['x,y,z'] - sage: f=R.random_element() + sage: R = RR['x,y,z'] + sage: f = R.random_element() sage: f.numerator() / f.denominator() == f True """ @@ -1887,12 +1890,13 @@ cdef class MPolynomial(CommutativePolynomial): def inverse_mod(self, I): """ - Returns an inverse of self modulo the polynomial ideal `I`, + Returns an inverse of ``self`` modulo the polynomial ideal `I`, namely a multivariate polynomial `f` such that ``self * f - 1`` belongs to `I`. INPUT: - - ``I`` -- an ideal of the polynomial ring in which self lives + + - ``I`` -- an ideal of the polynomial ring in which ``self`` lives OUTPUT: @@ -1902,9 +1906,9 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) - sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g + sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g # optional - sage.libs.singular 1/16*x1 + 3/16 - sage: (f*g).reduce(I) + sage: (f*g).reduce(I) # optional - sage.libs.singular 1 Test a non-invertible element:: @@ -1912,7 +1916,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) sage: f = x1 + x2 - sage: f.inverse_mod(I) + sage: f.inverse_mod(I) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -1945,38 +1949,38 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = GF(7)[] - sage: p = x^3 + y + x*z^2 - sage: p.weighted_degree({z:0, x:1, y:2}) + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: p = x^3 + y + x*z^2 # optional - sage.rings.finite_rings + sage: p.weighted_degree({z:0, x:1, y:2}) # optional - sage.rings.finite_rings 3 - sage: p.weighted_degree(1, 2, 0) + sage: p.weighted_degree(1, 2, 0) # optional - sage.rings.finite_rings 3 - sage: p.weighted_degree((1, 4, 2)) + sage: p.weighted_degree((1, 4, 2)) # optional - sage.rings.finite_rings 5 - sage: p.weighted_degree((1, 4, 1)) + sage: p.weighted_degree((1, 4, 1)) # optional - sage.rings.finite_rings 4 - sage: p.weighted_degree(2**64, 2**50, 2**128) + sage: p.weighted_degree(2**64, 2**50, 2**128) # optional - sage.rings.finite_rings 680564733841876926945195958937245974528 - sage: q = R.random_element(100, 20) #random - sage: q.weighted_degree(1, 1, 1) == q.total_degree() + sage: q = R.random_element(100, 20) #random # optional - sage.rings.finite_rings + sage: q.weighted_degree(1, 1, 1) == q.total_degree() # optional - sage.rings.finite_rings True You may also work with negative weights :: - sage: p.weighted_degree(-1, -2, -1) + sage: p.weighted_degree(-1, -2, -1) # optional - sage.rings.finite_rings -2 Note that only integer weights are allowed :: - sage: p.weighted_degree(x,1,1) + sage: p.weighted_degree(x, 1, 1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to Integer Ring - sage: p.weighted_degree(2/1,1,1) + sage: p.weighted_degree(2/1, 1, 1) # optional - sage.rings.finite_rings 6 The ``weighted_degree`` coincides with the ``degree`` of a weighted @@ -2062,15 +2066,17 @@ cdef class MPolynomial(CommutativePolynomial): sage: gcd(p,q) z*t*x*y + 1 sage: _.parent() - Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in z, t over Integer Ring + Multivariate Polynomial Ring in x, y over + Multivariate Polynomial Ring in z, t over Integer Ring Some multivariate polynomial rings have no gcd implementation:: - sage: R. =GaussianIntegers()[] + sage: R. = GaussianIntegers()[] sage: x.gcd(x) Traceback (most recent call last): ... - NotImplementedError: GCD is not implemented for multivariate polynomials over Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I + NotImplementedError: GCD is not implemented for multivariate polynomials over + Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I TESTS:: @@ -2159,11 +2165,11 @@ cdef class MPolynomial(CommutativePolynomial): def is_square(self, root=False): r""" - Test whether this polynomial is a square root. + Test whether this polynomial is a square. INPUT: - - ``root`` - if set to ``True`` return a pair ``(True, root)`` + - ``root`` - if set to ``True``, return a pair ``(True, root)`` where ``root`` is a square root or ``(False, None)`` if it is not a square. @@ -2196,7 +2202,7 @@ cdef class MPolynomial(CommutativePolynomial): - ``D`` -- dictionary (optional) - - ``phi`` -- SpecializationMorphism (optional) + - ``phi`` -- :class:`SpecializationMorphism` (optional) OUTPUT: a new polynomial @@ -2273,11 +2279,11 @@ cdef class MPolynomial(CommutativePolynomial): keywords: - - ``prec`` -- integer, sets the precision (default:300) + - ``prec`` -- integer, sets the precision (default: 300) - - ``return_conjugation`` -- boolean. Returns element of `SL(2, \ZZ)` (default:True) + - ``return_conjugation`` -- boolean. Returns element of `SL(2, \ZZ)` (default: True) - - ``error_limit`` -- sets the error tolerance (default:0.000001) + - ``error_limit`` -- sets the error tolerance (default: 0.000001) - ``smallest_coeffs`` -- (default: True), boolean, whether to find the model with smallest coefficients @@ -2285,15 +2291,17 @@ cdef class MPolynomial(CommutativePolynomial): - ``norm_type`` -- either ``'norm'`` or ``'height'``. What type of norm to use for smallest coefficients - - ``emb`` -- (optional) embedding of based field into CC + - ``emb`` -- (optional) embedding of based field into ``CC`` OUTPUT: - - a polynomial (reduced binary form) + - a polynomial (reduced binary form) + + - a matrix (element of `SL(2, \ZZ)`) - - a matrix (element of `SL(2, \ZZ)`) + .. TODO:: - TODO: When Newton's Method doesn't converge to a root in the upper half plane. + When Newton's Method doesn't converge to a root in the upper half plane. Now we just return z0. It would be better to modify and find the unique root in the upper half plane. @@ -2302,7 +2310,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: f = 19*x^8 - 262*x^7*h + 1507*x^6*h^2 - 4784*x^5*h^3 + 9202*x^4*h^4\ -10962*x^3*h^5 + 7844*x^2*h^6 - 3040*x*h^7 + 475*h^8 - sage: f.reduced_form(prec=200, smallest_coeffs=False) + sage: f.reduced_form(prec=200, smallest_coeffs=False) # optional - sage.modules ( -x^8 - 2*x^7*h + 7*x^6*h^2 + 16*x^5*h^3 + 2*x^4*h^4 - 2*x^3*h^5 + 4*x^2*h^6 - 5*h^8, @@ -2315,7 +2323,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: f = x^3 + 378666*x^2*y - 12444444*x*y^2 + 1234567890*y^3 sage: j = f * (x-545*y)^9 - sage: j.reduced_form(prec=200, smallest_coeffs=False) + sage: j.reduced_form(prec=200, smallest_coeffs=False) # optional - sage.modules Traceback (most recent call last): ... ValueError: cannot have a root with multiplicity >= 12/2 @@ -2324,7 +2332,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = x^6 + 3*x^5*y - 8*x^4*y^2 - 2*x^3*y^3 - 44*x^2*y^4 - 8*x*y^5 - sage: F.reduced_form(smallest_coeffs=False, prec=400) + sage: F.reduced_form(smallest_coeffs=False, prec=400) # optional - sage.modules Traceback (most recent call last): ... ArithmeticError: Newton's method converged to z not in the upper half plane @@ -2333,7 +2341,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = 5*x^2*y - 5*x*y^2 - 30*y^3 - sage: F.reduced_form(smallest_coeffs=False) + sage: F.reduced_form(smallest_coeffs=False) # optional - sage.modules ( [1 1] 5*x^2*y + 5*x*y^2 - 30*y^3, [0 1] @@ -2342,12 +2350,12 @@ cdef class MPolynomial(CommutativePolynomial): An example where precision needs to be increased:: sage: R. = PolynomialRing(QQ) - sage: F=-16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7 - sage: F.reduced_form(prec=50, smallest_coeffs=False) + sage: F = -16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7 + sage: F.reduced_form(prec=50, smallest_coeffs=False) # optional - sage.modules Traceback (most recent call last): ... ValueError: accuracy of Newton's root not within tolerance(0.000012... > 1e-06), increase precision - sage: F.reduced_form(prec=100, smallest_coeffs=False) + sage: F.reduced_form(prec=100, smallest_coeffs=False) # optional - sage.modules ( [-1 -1] -x^5*y^2 - 24*x^3*y^4 - 3*x^2*y^5 - 2*x*y^6 + 16*y^7, [ 1 0] @@ -2357,14 +2365,14 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = - 8*x^4 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 1825511633*y^4 - sage: F.reduced_form(return_conjugation=False) + sage: F.reduced_form(return_conjugation=False) # optional - sage.modules x^4 + 9*x^3*y - 3*x*y^3 - 8*y^4 :: sage: R. = QQ[] sage: F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 - sage: F.reduced_form() + sage: F.reduced_form() # optional - sage.modules ( [1 4] -2*x^3 - 22*x^2*y - 77*x*y^2 + 43*y^3, [0 1] @@ -2374,7 +2382,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 - sage: F.reduced_form(norm_type='height') + sage: F.reduced_form(norm_type='height') # optional - sage.modules ( [5 4] -58*x^3 - 47*x^2*y + 52*x*y^2 + 43*y^3, [1 1] @@ -2384,7 +2392,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = x^4 + x^3*y*z + y^2*z - sage: F.reduced_form() + sage: F.reduced_form() # optional - sage.modules Traceback (most recent call last): ... ValueError: (=x^3*y*z + x^4 + y^2*z) must have two variables @@ -2393,7 +2401,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: F = - 8*x^6 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 99*y^6 - sage: F.reduced_form(return_conjugation=False) + sage: F.reduced_form(return_conjugation=False) # optional - sage.modules Traceback (most recent call last): ... ValueError: (=-8*x^6 - 99*y^6 - 3933*x^3*y - 725085*x^2*y^2 - @@ -2404,7 +2412,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(RR) sage: F = 217.992172373276*x^3 + 96023.1505442490*x^2*y + 1.40987971253579e7*x*y^2\ + 6.90016027113216e8*y^3 - sage: F.reduced_form(smallest_coeffs=False) # tol 1e-8 + sage: F.reduced_form(smallest_coeffs=False) # tol 1e-8 # optional - sage.modules ( -39.5673942565918*x^3 + 111.874026298523*x^2*y + 231.052762985229*x*y^2 - 138.380829811096*y^3, @@ -2417,7 +2425,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(CC) sage: F = (0.759099196558145 + 0.845425869641446*CC.0)*x^3 + (84.8317207268542 + 93.8840848648033*CC.0)*x^2*y\ + (3159.07040755858 + 3475.33037377779*CC.0)*x*y^2 + (39202.5965389079 + 42882.5139724962*CC.0)*y^3 - sage: F.reduced_form(smallest_coeffs=False) # tol 1e-11 + sage: F.reduced_form(smallest_coeffs=False) # tol 1e-11 # optional - sage.modules ( (-0.759099196558145 - 0.845425869641446*I)*x^3 + (-0.571709908900118 - 0.0418133346027929*I)*x^2*y + (0.856525964330103 - 0.0721403997649759*I)*x*y^2 + (-0.965531044130330 + 0.754252314465703*I)*y^3, @@ -2507,16 +2515,16 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x+y).is_unit() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_unit() # optional - sage.rings.number_field False - sage: R(0).is_unit() + sage: R(0).is_unit() # optional - sage.rings.number_field False - sage: R(-1).is_unit() + sage: R(-1).is_unit() # optional - sage.rings.number_field True - sage: R(-1 + x).is_unit() + sage: R(-1 + x).is_unit() # optional - sage.rings.number_field False - sage: R(2).is_unit() + sage: R(2).is_unit() # optional - sage.rings.number_field True Check that :trac:`22454` is fixed:: @@ -2553,10 +2561,10 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x+y).is_nilpotent() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_nilpotent() # optional - sage.rings.number_field False - sage: R(0).is_nilpotent() + sage: R(0).is_nilpotent() # optional - sage.rings.number_field True sage: _. = Zmod(4)[] sage: (2*x).is_nilpotent() @@ -2585,8 +2593,8 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R. = QQbar[] - sage: (x + y)._test_subs() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y)._test_subs() # optional - sage.rings.number_field """ if tester is None: tester = self._tester(**options) diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index 08cc3dee4d0..826e2843fb5 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -31,8 +31,10 @@ We verify Lagrange's four squares identity:: - sage: R. = QQbar[] - sage: (a0^2 + a1^2 + a2^2 + a3^2)*(b0^2 + b1^2 + b2^2 + b3^2) == (a0*b0 - a1*b1 - a2*b2 - a3*b3)^2 + (a0*b1 + a1*b0 + a2*b3 - a3*b2)^2 + (a0*b2 - a1*b3 + a2*b0 + a3*b1)^2 + (a0*b3 + a1*b2 - a2*b1 + a3*b0)^2 + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: ((a0^2 + a1^2 + a2^2 + a3^2) * (b0^2 + b1^2 + b2^2 + b3^2) == # optional - sage.rings.number_field + ....: (a0*b0 - a1*b1 - a2*b2 - a3*b3)^2 + (a0*b1 + a1*b0 + a2*b3 - a3*b2)^2 + ....: + (a0*b2 - a1*b3 + a2*b0 + a3*b1)^2 + (a0*b3 + a1*b2 - a2*b1 + a3*b0)^2) True """ #***************************************************************************** @@ -92,12 +94,12 @@ def __init__(self, parent, x): """ EXAMPLES:: - sage: K. = NumberField(x^3 - 2) - sage: L. = K.extension(x^3 - 3) - sage: S. = L.extension(x^2 - 2) - sage: S + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.number_field + sage: S. = L.extension(x^2 - 2) # optional - sage.rings.number_field + sage: S # optional - sage.rings.number_field Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field - sage: P. = PolynomialRing(S) # indirect doctest + sage: P. = PolynomialRing(S) # indirect doctest # optional - sage.rings.number_field """ CommutativeRingElement.__init__(self, parent) self.__element = x @@ -106,8 +108,8 @@ def _repr_(self): """ EXAMPLES:: - sage: P. = PolynomialRing(QQbar) - sage: x + QQbar(sqrt(2) - 1/2*I) # indirect doctest + sage: P. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: x + QQbar(sqrt(2) - 1/2*I) # indirect doctest # optional - sage.rings.number_field x + 1.414213562373095? - 0.50000000000000000?*I """ return "%s"%self.__element @@ -184,10 +186,10 @@ def _richcmp_(self, right, op): EXAMPLES:: - sage: R.=PolynomialRing(QQbar,3,order='lex') - sage: x^1*y^2 > y^3*z^4 + sage: R. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: x^1*y^2 > y^3*z^4 # optional - sage.rings.number_field True - sage: x^3*y^2*z^4 < x^3*y^2*z^1 + sage: x^3*y^2*z^4 < x^3*y^2*z^1 # optional - sage.rings.number_field False :: @@ -200,10 +202,10 @@ def _richcmp_(self, right, op): :: - sage: R.=PolynomialRing(QQbar,3,order='degrevlex') - sage: x^1*y^5*z^2 > x^4*y^1*z^3 + sage: R. = PolynomialRing(QQbar, 3, order='degrevlex') # optional - sage.rings.number_field + sage: x^1*y^5*z^2 > x^4*y^1*z^3 # optional - sage.rings.number_field True - sage: x^4*y^7*z^1 < x^4*y^2*z^3 + sage: x^4*y^7*z^1 < x^4*y^2*z^3 # optional - sage.rings.number_field False """ return self.__element.rich_compare(right.__element, op, @@ -213,9 +215,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = R.hom([y,x], R) - sage: f(x^2 + 3*y^5) # indirect doctest + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = R.hom([y, x], R) # optional - sage.rings.number_field + sage: f(x^2 + 3*y^5) # indirect doctest # optional - sage.rings.number_field 3*x^5 + y^2 You can specify a map on the base ring:: @@ -272,10 +274,10 @@ def __neg__(self): EXAMPLES:: - sage: R. = QQbar[] - sage: -x + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: -x # optional - sage.rings.number_field -x - sage: -(y-1) + sage: -(y-1) # optional - sage.rings.number_field -y + 1 """ return self.__class__(self.parent(), -self.__element) @@ -334,9 +336,9 @@ def _lmul_(self, a): :: - sage: R. = QQbar[] - sage: f = (x + y) - sage: 3*f + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = (x + y) # optional - sage.rings.number_field + sage: 3 * f # optional - sage.rings.number_field 3*x + 3*y """ elt = self.__element.scalar_lmult(a) @@ -355,9 +357,9 @@ def _rmul_(self, a): :: - sage: R. = QQbar[] - sage: f = (x + y) - sage: f*3 + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = (x + y) # optional - sage.rings.number_field + sage: f * 3 # optional - sage.rings.number_field 3*x + 3*y """ elt = self.__element.scalar_rmult(a) @@ -420,15 +422,15 @@ def change_ring(self, R): sage: R. = QQ[] sage: f = x^2 + 5*y - sage: f.change_ring(GF(5)) + sage: f.change_ring(GF(5)) # optional - sage.libs.pari x^2 :: - sage: K. = CyclotomicField(5) - sage: R. = K[] - sage: f = x^2 + w*y - sage: f.change_ring(K.embeddings(QQbar)[1]) + sage: K. = CyclotomicField(5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + w*y # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(QQbar)[1]) # optional - sage.rings.number_field x^2 + (-0.8090169943749474? + 0.5877852522924731?*I)*y """ if isinstance(R, Morphism): @@ -449,10 +451,10 @@ def __init__(self, parent, x): """ EXAMPLES:: - sage: R, x = PolynomialRing(QQbar, 10, 'x').objgens() - sage: x + sage: R, x = PolynomialRing(QQbar, 10, 'x').objgens() # optional - sage.rings.number_field + sage: x # optional - sage.rings.number_field (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) - sage: loads(dumps(x)) == x + sage: loads(dumps(x)) == x # optional - sage.rings.number_field True """ if not isinstance(x, polydict.PolyDict): @@ -482,12 +484,12 @@ def _repr_(self): """ EXAMPLES:: - sage: R.=QQbar[] - sage: repr(-x^2-y+1) # indirect doc-test + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: repr(-x^2 - y + 1) # indirect doctest # optional - sage.rings.number_field '-x^2 - y + 1' - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: repr(-I*y-x^2) # indirect doc-test + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: repr(-I*y - x^2) # indirect doctest # optional - sage.rings.number_field '-x^2 + (-I)*y' """ try: @@ -503,12 +505,12 @@ def _latex_(self): r""" EXAMPLES:: - sage: R.=QQbar[] - sage: latex(-x^2-y+1) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: latex(-x^2 - y + 1) # optional - sage.rings.number_field -x^{2} - y + 1 - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: latex(-I*y+I*x^2) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: latex(-I*y + I*x^2) # optional - sage.rings.number_field \left(\sqrt{-1}\right) x^{2} + \left(-\sqrt{-1}\right) y """ try: @@ -523,9 +525,9 @@ def _repr_with_changed_varnames(self, varnames): """ EXAMPLES:: - sage: R.=QQbar[] - sage: f=-x^2-y+1 - sage: f._repr_with_changed_varnames(['jack','jill']) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = -x^2 - y + 1 # optional - sage.rings.number_field + sage: f._repr_with_changed_varnames(['jack', 'jill']) # optional - sage.rings.number_field '-jack^2 - jill + 1' """ try: @@ -540,8 +542,8 @@ def _macaulay2_(self, macaulay2=None): """ EXAMPLES:: - sage: R = GF(13)['a,b']['c,d'] - sage: macaulay2(R('a^2 + c')) # optional - macaulay2 + sage: R = GF(13)['a,b']['c,d'] # optional - sage.libs.pari + sage: macaulay2(R('a^2 + c')) # optional - macaulay2 sage.libs.pari 2 c + a @@ -550,7 +552,7 @@ def _macaulay2_(self, macaulay2=None): Elements of the base ring are coerced to the polynomial ring correctly:: - sage: macaulay2(R('a^2')).ring()._operator('===', R) # optional - macaulay2 + sage: macaulay2(R('a^2')).ring()._operator('===', R) # optional - macaulay2 sage.libs.pari true """ if macaulay2 is None: @@ -568,20 +570,20 @@ def degrees(self): EXAMPLES:: - sage: R.=PolynomialRing(QQbar) - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.degrees() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.degrees() # optional - sage.rings.number_field (2, 2, 0) - sage: f = x^2+z^2 - sage: f.degrees() + sage: f = x^2 + z^2 # optional - sage.rings.number_field + sage: f.degrees() # optional - sage.rings.number_field (2, 0, 2) - sage: f.total_degree() # this simply illustrates that total degree is not the sum of the degrees + sage: f.total_degree() # this simply illustrates that total degree is not the sum of the degrees # optional - sage.rings.number_field 2 - sage: R.=PolynomialRing(QQbar) - sage: f=(1-x)*(1+y+z+x^3)^5 - sage: f.degrees() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = (1-x) * (1+y+z+x^3)^5 # optional - sage.rings.number_field + sage: f.degrees() # optional - sage.rings.number_field (16, 5, 5, 0) - sage: R(0).degrees() + sage: R(0).degrees() # optional - sage.rings.number_field (0, 0, 0, 0) """ if not self: @@ -591,17 +593,17 @@ def degrees(self): def degree(self, x=None, std_grading=False): """ - Return the degree of self in x, where x must be one of the - generators for the parent of self. + Return the degree of ``self`` in ``x``, where ``x`` must be one of the + generators for the parent of ``self``. INPUT: - ``x`` - multivariate polynomial (a generator of the parent - of self). If ``x`` is not specified (or is None), return - the total degree, which is the maximum degree of any - monomial. Note that a weighted term ordering alters the - grading of the generators of the ring; see the tests below. - To avoid this behavior, set the optional argument ``std_grading=True``. + of ``self``). If ``x`` is not specified (or is None), return + the total degree, which is the maximum degree of any + monomial. Note that a weighted term ordering alters the + grading of the generators of the ring; see the tests below. + To avoid this behavior, set the optional argument ``std_grading=True``. OUTPUT: integer @@ -629,9 +631,9 @@ def degree(self, x=None, std_grading=False): 2 sage: y.degree() 3 - sage: x.degree(y),x.degree(x),y.degree(x),y.degree(y) + sage: x.degree(y), x.degree(x), y.degree(x), y.degree(y) (0, 1, 0, 1) - sage: f = (x^2*y+x*y^2) + sage: f = x^2*y + x*y^2 sage: f.degree(x) 2 sage: f.degree(y) @@ -641,7 +643,7 @@ def degree(self, x=None, std_grading=False): sage: f.degree(std_grading=True) 3 - Note that if ``x`` is not a generator of the parent of self, + Note that if ``x`` is not a generator of the parent of ``self``, for example if it is a generator of a polynomial algebra which maps naturally to this one, then it is converted to an element of this algebra. (This fixes the problem reported in @@ -659,37 +661,37 @@ def degree(self, x=None, std_grading=False): ... TypeError: x must canonically coerce to parent - sage: GF(3037000453)['x','y'].gen(0).degree(x^2) + sage: GF(3037000453)['x','y'].gen(0).degree(x^2) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: x must be one of the generators of the parent TESTS:: - sage: R = PolynomialRing(GF(2)['t'],'x,y',order=TermOrder('wdeglex',(2,3))) - sage: x,y = R.gens() - sage: x.degree() + sage: R = PolynomialRing(GF(2)['t'], 'x,y', order=TermOrder('wdeglex', (2,3))) # optional - sage.libs.pari + sage: x, y = R.gens() # optional - sage.libs.pari + sage: x.degree() # optional - sage.libs.pari 2 - sage: y.degree() + sage: y.degree() # optional - sage.libs.pari 3 - sage: x.degree(y),x.degree(x),y.degree(x),y.degree(y) + sage: x.degree(y), x.degree(x), y.degree(x), y.degree(y) # optional - sage.libs.pari (0, 1, 0, 1) - sage: f = (x^2*y+x*y^2) - sage: f.degree(x) + sage: f = (x^2*y + x*y^2) # optional - sage.libs.pari + sage: f.degree(x) # optional - sage.libs.pari 2 - sage: f.degree(y) + sage: f.degree(y) # optional - sage.libs.pari 2 - sage: f.degree() + sage: f.degree() # optional - sage.libs.pari 8 - sage: f.degree(std_grading=True) + sage: f.degree(std_grading=True) # optional - sage.libs.pari 3 - sage: R(0).degree() + sage: R(0).degree() # optional - sage.libs.pari -1 Degree of zero polynomial for other implementation :trac:`20048` :: - sage: R. = GF(3037000453)[] - sage: R.zero().degree(x) + sage: R. = GF(3037000453)[] # optional - sage.libs.pari + sage: R.zero().degree(x) # optional - sage.libs.pari -1 """ if x is None: @@ -710,37 +712,37 @@ def degree(self, x=None, std_grading=False): def total_degree(self): """ - Return the total degree of self, which is the maximum degree of any - monomial in self. + Return the total degree of ``self``, which is the maximum degree of any + monomial in ``self``. EXAMPLES:: - sage: R. = QQbar[] - sage: f=2*x*y^3*z^2 - sage: f.total_degree() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2*x*y^3*z^2 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 6 - sage: f=4*x^2*y^2*z^3 - sage: f.total_degree() + sage: f = 4*x^2*y^2*z^3 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 7 - sage: f=99*x^6*y^3*z^9 - sage: f.total_degree() + sage: f = 99*x^6*y^3*z^9 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 18 - sage: f=x*y^3*z^6+3*x^2 - sage: f.total_degree() + sage: f = x*y^3*z^6 + 3*x^2 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 10 - sage: f=z^3+8*x^4*y^5*z - sage: f.total_degree() + sage: f = z^3 + 8*x^4*y^5*z # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 10 - sage: f=z^9+10*x^4+y^8*x^2 - sage: f.total_degree() + sage: f = z^9 + 10*x^4 + y^8*x^2 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 10 """ return self.degree() def monomial_coefficient(self, mon): """ - Return the coefficient in the base ring of the monomial mon in - self, where mon must have the same parent as self. + Return the coefficient in the base ring of the monomial ``mon`` in + ``self``, where ``mon`` must have the same parent as ``self``. This function contrasts with the function ``coefficient`` which returns the coefficient of a @@ -761,43 +763,35 @@ def monomial_coefficient(self, mon): EXAMPLES: - The parent of the return is a member of the base ring. - :: - sage: R.=QQbar[] - - The parent of the return is a member of the base ring. - - :: - - sage: f = 2 * x * y - sage: c = f.monomial_coefficient(x*y); c + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2 * x * y # optional - sage.rings.number_field + sage: c = f.monomial_coefficient(x*y); c # optional - sage.rings.number_field 2 - sage: c.parent() + sage: c.parent() # optional - sage.rings.number_field Algebraic Field :: - sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y - sage: f.monomial_coefficient(y^2) + sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y # optional - sage.rings.number_field + sage: f.monomial_coefficient(y^2) # optional - sage.rings.number_field 1 - sage: f.monomial_coefficient(x*y) + sage: f.monomial_coefficient(x*y) # optional - sage.rings.number_field 5 - sage: f.monomial_coefficient(x^9) + sage: f.monomial_coefficient(x^9) # optional - sage.rings.number_field -1 - sage: f.monomial_coefficient(x^10) + sage: f.monomial_coefficient(x^10) # optional - sage.rings.number_field 0 :: - sage: var('a') - a - sage: K. = NumberField(a^2+a+1) - sage: P. = K[] - sage: f=(a*x-1)*((a+1)*y-1); f + sage: a = polygen(ZZ, 'a') + sage: K. = NumberField(a^2 + a + 1) # optional - sage.rings.number_field + sage: P. = K[] # optional - sage.rings.number_field + sage: f = (a*x - 1) * ((a+1)*y - 1); f # optional - sage.rings.number_field -x*y + (-a)*x + (-a - 1)*y + 1 - sage: f.monomial_coefficient(x) + sage: f.monomial_coefficient(x) # optional - sage.rings.number_field -a """ if parent(mon) is not self.parent(): @@ -819,23 +813,23 @@ def __iter__(self): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, order='lex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f) + sage: R. = PolynomialRing(QQbar, order='lex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f) # optional - sage.rings.number_field [(1, x^4*y*z^3), (1, x^2*z), (1, x*y^5*z^2)] :: - sage: R. = PolynomialRing(QQbar, order='deglex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f) + sage: R. = PolynomialRing(QQbar, order='deglex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f) # optional - sage.rings.number_field [(1, x^4*y*z^3), (1, x*y^5*z^2), (1, x^2*z)] :: - sage: R. = PolynomialRing(QQbar, order='degrevlex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f) + sage: R. = PolynomialRing(QQbar, order='degrevlex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f) # optional - sage.rings.number_field [(1, x*y^5*z^2), (1, x^4*y*z^3), (1, x^2*z)] :: @@ -866,22 +860,22 @@ def __getitem__(self, x): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = -10*x^3*y + 17*x*y - sage: f[3,1] + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = -10*x^3*y + 17*x*y # optional - sage.rings.number_field + sage: f[3,1] # optional - sage.rings.number_field -10 - sage: f[1,1] + sage: f[1,1] # optional - sage.rings.number_field 17 - sage: f[0,1] + sage: f[0,1] # optional - sage.rings.number_field 0 :: - sage: R. = PolynomialRing(QQbar,1); R + sage: R. = PolynomialRing(QQbar, 1); R # optional - sage.rings.number_field Multivariate Polynomial Ring in x over Algebraic Field - sage: f = 5*x^2 + 3; f + sage: f = 5*x^2 + 3; f # optional - sage.rings.number_field 5*x^2 + 3 - sage: f[2] + sage: f[2] # optional - sage.rings.number_field 5 """ if isinstance(x, MPolynomial): @@ -907,14 +901,14 @@ def iterator_exp_coeff(self, as_ETuples=True): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, order='lex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f.iterator_exp_coeff()) + sage: R. = PolynomialRing(QQbar, order='lex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f.iterator_exp_coeff()) # optional - sage.rings.number_field [((4, 1, 3), 1), ((2, 0, 1), 1), ((1, 5, 2), 1)] - sage: R. = PolynomialRing(QQbar, order='deglex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f.iterator_exp_coeff(as_ETuples=False)) + sage: R. = PolynomialRing(QQbar, order='deglex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f.iterator_exp_coeff(as_ETuples=False)) # optional - sage.rings.number_field [((4, 1, 3), 1), ((1, 5, 2), 1), ((2, 0, 1), 1)] """ elt = self.element() @@ -959,31 +953,31 @@ def coefficient(self, degrees): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 2 * x * y - sage: c = f.coefficient({x:1,y:1}); c + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2 * x * y # optional - sage.rings.number_field + sage: c = f.coefficient({x: 1, y: 1}); c # optional - sage.rings.number_field 2 - sage: c.parent() + sage: c.parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y over Algebraic Field - sage: c in PolynomialRing(QQbar, 2, names = ['x','y']) + sage: c in PolynomialRing(QQbar, 2, names=['x', 'y']) # optional - sage.rings.number_field True - sage: f = y^2 - x^9 - 7*x + 5*x*y - sage: f.coefficient({y:1}) + sage: f = y^2 - x^9 - 7*x + 5*x*y # optional - sage.rings.number_field + sage: f.coefficient({y: 1}) # optional - sage.rings.number_field 5*x - sage: f.coefficient({y:0}) + sage: f.coefficient({y: 0}) # optional - sage.rings.number_field -x^9 + (-7)*x - sage: f.coefficient({x:0,y:0}) + sage: f.coefficient({x: 0, y: 0}) # optional - sage.rings.number_field 0 - sage: f=(1+y+y^2)*(1+x+x^2) - sage: f.coefficient({x:0}) + sage: f = (1+y+y^2) * (1+x+x^2) # optional - sage.rings.number_field + sage: f.coefficient({x: 0}) # optional - sage.rings.number_field y^2 + y + 1 - sage: f.coefficient([0,None]) + sage: f.coefficient([0, None]) # optional - sage.rings.number_field y^2 + y + 1 - sage: f.coefficient(x) + sage: f.coefficient(x) # optional - sage.rings.number_field y^2 + y + 1 sage: # Be aware that this may not be what you think! sage: # The physical appearance of the variable x is deceiving -- particularly if the exponent would be a variable. - sage: f.coefficient(x^0) # outputs the full polynomial + sage: f.coefficient(x^0) # outputs the full polynomial # optional - sage.rings.number_field x^2*y^2 + x^2*y + x*y^2 + x^2 + x*y + y^2 + x + y + 1 :: @@ -1025,7 +1019,7 @@ def global_height(self, prec=None): INPUT: - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1033,28 +1027,28 @@ def global_height(self, prec=None): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = QQbar(i)*x^2 + 3*x*y - sage: f.global_height() + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = QQbar(i)*x^2 + 3*x*y # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 1.09861228866811 Scaling should not change the result:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = 1/25*x^2 + 25/3*x + 1 + QQbar(sqrt(2))*y^2 - sage: f.global_height() + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = 1/25*x^2 + 25/3*x + 1 + QQbar(sqrt(2))*y^2 # optional - sage.rings.number_field sage.symbolic + sage: f.global_height() # optional - sage.rings.number_field sage.symbolic 6.43775164973640 - sage: g = 100 * f - sage: g.global_height() + sage: g = 100 * f # optional - sage.rings.number_field sage.symbolic + sage: g.global_height() # optional - sage.rings.number_field sage.symbolic 6.43775164973640 :: sage: R. = QQ[] - sage: K. = NumberField(x^2 + 1) - sage: Q. = PolynomialRing(K, implementation='generic') - sage: f = 12*q - sage: f.global_height() + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: Q. = PolynomialRing(K, implementation='generic') # optional - sage.rings.number_field + sage: f = 12 * q # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 0.000000000000000 :: @@ -1121,11 +1115,11 @@ def local_height(self, v, prec=None): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = PolynomialRing(K, implementation='generic') - sage: I = K.ideal(3) - sage: f = 1/3*t*w + 3 - sage: f.local_height(I) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K, implementation='generic') # optional - sage.rings.number_field + sage: I = K.ideal(3) # optional - sage.rings.number_field + sage: f = 1/3*t*w + 3 # optional - sage.rings.number_field + sage: f.local_height(I) # optional - sage.rings.number_field sage.symbolic 1.09861228866811 :: @@ -1157,7 +1151,7 @@ def local_height_arch(self, i, prec=None): - ``i`` -- an integer. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1173,10 +1167,10 @@ def local_height_arch(self, i, prec=None): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = PolynomialRing(K, implementation='generic') - sage: f = 1/2*t*w + 3 - sage: f.local_height_arch(1, prec=52) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K, implementation='generic') # optional - sage.rings.number_field + sage: f = 1/2*t*w + 3 # optional - sage.rings.number_field + sage: f.local_height_arch(1, prec=52) # optional - sage.rings.number_field 1.09861228866811 :: @@ -1208,9 +1202,9 @@ def _exponents(self): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 3) - sage: f = a^3 + b + 2*b^2 - sage: f._exponents + sage: R. = PolynomialRing(QQbar, 3) # optional - sage.rings.number_field + sage: f = a^3 + b + 2*b^2 # optional - sage.rings.number_field + sage: f._exponents # optional - sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)] """ return sorted(self.element().dict(), key=self.parent().term_order().sortkey, reverse=True) @@ -1230,29 +1224,29 @@ def exponents(self, as_ETuples=True): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 3) - sage: f = a^3 + b + 2*b^2 - sage: f.exponents() + sage: R. = PolynomialRing(QQbar, 3) # optional - sage.rings.number_field + sage: f = a^3 + b + 2*b^2 # optional - sage.rings.number_field + sage: f.exponents() # optional - sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)] By default the list of exponents is a list of ETuples:: - sage: type(f.exponents()[0]) + sage: type(f.exponents()[0]) # optional - sage.rings.number_field - sage: type(f.exponents(as_ETuples=False)[0]) + sage: type(f.exponents(as_ETuples=False)[0]) # optional - sage.rings.number_field <... 'tuple'> TESTS: Check that we can mutate the list and not change the result:: - sage: R. = PolynomialRing(QQbar, 3) - sage: f = a^3 + b + 2*b^2 - sage: E = f.exponents(); E + sage: R. = PolynomialRing(QQbar, 3) # optional - sage.rings.number_field + sage: f = a^3 + b + 2*b^2 # optional - sage.rings.number_field + sage: E = f.exponents(); E # optional - sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)] - sage: E.pop() + sage: E.pop() # optional - sage.rings.number_field (0, 1, 0) - sage: E != f.exponents() + sage: E != f.exponents() # optional - sage.rings.number_field True """ if as_ETuples: @@ -1284,18 +1278,18 @@ def is_homogeneous(self): EXAMPLES:: - sage: R. = QQbar[] - sage: (x+y).is_homogeneous() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_homogeneous() # optional - sage.rings.number_field True - sage: (x.parent()(0)).is_homogeneous() + sage: (x.parent()(0)).is_homogeneous() # optional - sage.rings.number_field True - sage: (x+y^2).is_homogeneous() + sage: (x + y^2).is_homogeneous() # optional - sage.rings.number_field False - sage: (x^2 + y^2).is_homogeneous() + sage: (x^2 + y^2).is_homogeneous() # optional - sage.rings.number_field True - sage: (x^2 + y^2*x).is_homogeneous() + sage: (x^2 + y^2*x).is_homogeneous() # optional - sage.rings.number_field False - sage: (x^2*y + y^2*x).is_homogeneous() + sage: (x^2*y + y^2*x).is_homogeneous() # optional - sage.rings.number_field True """ return self.element().is_homogeneous() @@ -1317,11 +1311,11 @@ def _homogenize(self, var): EXAMPLES:: - sage: P. = QQbar[] - sage: f = x^2 + y + 1 + 5*x*y^1 - sage: g = f.homogenize('z'); g # indirect doctest + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: f = x^2 + y + 1 + 5*x*y^1 # optional - sage.rings.number_field + sage: g = f.homogenize('z'); g # indirect doctest # optional - sage.rings.number_field x^2 + 5*x*y + y*z + z^2 - sage: g.parent() + sage: g.parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y, z over Algebraic Field SEE: ``self.homogenize`` @@ -1339,12 +1333,12 @@ def is_generator(self): EXAMPLES:: - sage: R.=QQbar[] - sage: x.is_generator() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_generator() # optional - sage.rings.number_field True - sage: (x+y-y).is_generator() + sage: (x + y - y).is_generator() # optional - sage.rings.number_field True - sage: (x*y).is_generator() + sage: (x*y).is_generator() # optional - sage.rings.number_field False """ elt = self.element() @@ -1362,21 +1356,21 @@ def is_monomial(self): EXAMPLES:: - sage: R.=QQbar[] - sage: x.is_monomial() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_monomial() # optional - sage.rings.number_field True - sage: (x+2*y).is_monomial() + sage: (x + 2*y).is_monomial() # optional - sage.rings.number_field False - sage: (2*x).is_monomial() + sage: (2*x).is_monomial() # optional - sage.rings.number_field False - sage: (x*y).is_monomial() + sage: (x*y).is_monomial() # optional - sage.rings.number_field True - To allow a non-1 leading coefficient, use is_term():: + To allow a non-1 leading coefficient, use :meth:`is_term`:: - sage: (2*x*y).is_term() + sage: (2*x*y).is_term() # optional - sage.rings.number_field True - sage: (2*x*y).is_monomial() + sage: (2*x*y).is_monomial() # optional - sage.rings.number_field False """ return len(self.element()) == 1 and self.element().coefficients()[0] == 1 @@ -1391,31 +1385,31 @@ def is_term(self): EXAMPLES:: - sage: R.=QQbar[] - sage: x.is_term() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_term() # optional - sage.rings.number_field True - sage: (x+2*y).is_term() + sage: (x + 2*y).is_term() # optional - sage.rings.number_field False - sage: (2*x).is_term() + sage: (2*x).is_term() # optional - sage.rings.number_field True - sage: (7*x^5*y).is_term() + sage: (7*x^5*y).is_term() # optional - sage.rings.number_field True - To require leading coefficient 1, use is_monomial():: + To require leading coefficient 1, use :meth:`is_monomial`:: - sage: (2*x*y).is_monomial() + sage: (2*x*y).is_monomial() # optional - sage.rings.number_field False - sage: (2*x*y).is_term() + sage: (2*x*y).is_term() # optional - sage.rings.number_field True """ return len(self.element()) == 1 def subs(self, fixed=None, **kw): """ - Fixes some given variables in a given multivariate polynomial and - returns the changed multivariate polynomials. The polynomial itself - is not affected. The variable,value pairs for fixing are to be - provided as a dictionary of the form {variable:value}. + Fix some given variables in a given multivariate polynomial and + return the changed multivariate polynomials. The polynomial itself + is not affected. The variable, value pairs for fixing are to be + provided as a dictionary of the form ``{variable: value}``. This is a special case of evaluating the polynomial with some of the variables constants and the others the original variables. @@ -1428,15 +1422,15 @@ def subs(self, fixed=None, **kw): - ``**kw`` - named parameters - OUTPUT: new MPolynomial + OUTPUT: new :class:`MPolynomial` EXAMPLES:: - sage: R. = QQbar[] - sage: f = x^2 + y + x^2*y^2 + 5 - sage: f((5,y)) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = x^2 + y + x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f((5, y)) # optional - sage.rings.number_field 25*y^2 + y + 30 - sage: f.subs({x:5}) + sage: f.subs({x: 5}) # optional - sage.rings.number_field 25*y^2 + y + 30 """ variables = list(self.parent().gens()) @@ -1449,29 +1443,28 @@ def subs(self, fixed=None, **kw): def monomials(self): """ - Returns the list of monomials in self. The returned list is - decreasingly ordered by the term ordering of self.parent(). + Return the list of monomials in ``self``. The returned list is + decreasingly ordered by the term ordering of ``self.parent()``. - OUTPUT: list of MPolynomials representing Monomials + OUTPUT: list of :class:`MPolynomial` instances, representing monomials EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.monomials() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.monomials() # optional - sage.rings.number_field [x^2*y^2, x^2, y, 1] :: - sage: R. = QQbar[] - sage: F = ((fx*gy - fy*gx)^3) - sage: F + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: F = (fx*gy - fy*gx)^3; F # optional - sage.rings.number_field -fy^3*gx^3 + 3*fx*fy^2*gx^2*gy + (-3)*fx^2*fy*gx*gy^2 + fx^3*gy^3 - sage: F.monomials() + sage: F.monomials() # optional - sage.rings.number_field [fy^3*gx^3, fx*fy^2*gx^2*gy, fx^2*fy*gx*gy^2, fx^3*gy^3] - sage: F.coefficients() + sage: F.coefficients() # optional - sage.rings.number_field [-1, 3, -3, 1] - sage: sum(map(mul,zip(F.coefficients(),F.monomials()))) == F + sage: sum(map(mul, zip(F.coefficients(), F.monomials()))) == F # optional - sage.rings.number_field True """ ring = self.parent() @@ -1485,12 +1478,12 @@ def constant_coefficient(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.constant_coefficient() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.constant_coefficient() # optional - sage.rings.number_field 5 - sage: f = 3*x^2 - sage: f.constant_coefficient() + sage: f = 3*x^2 # optional - sage.rings.number_field + sage: f.constant_coefficient() # optional - sage.rings.number_field 0 """ #v = (0,)*int(self.parent().ngens()) @@ -1507,16 +1500,16 @@ def is_univariate(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.is_univariate() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.is_univariate() # optional - sage.rings.number_field False - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.is_univariate() + sage: g.is_univariate() # optional - sage.rings.number_field True - sage: f = x^0 - sage: f.is_univariate() + sage: f = x^0 # optional - sage.rings.number_field + sage: f.is_univariate() # optional - sage.rings.number_field True """ mons = self.element().dict() @@ -1539,27 +1532,27 @@ def univariate_polynomial(self, R=None): INPUT: - - ``R`` - (default: None) PolynomialRing + - ``R`` - (default: None) :class:`PolynomialRing` If this polynomial is not in at most one variable, then a - ValueError exception is raised. This is checked using the - is_univariate() method. The new Polynomial is over the same base - ring as the given MPolynomial. + :class:`ValueError` exception is raised. This is checked using the + method :meth:`is_univariate`. The new :class:`Polynomial` is over the same base + ring as the given :class:`MPolynomial`. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.univariate_polynomial() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.univariate_polynomial() # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.univariate_polynomial () + sage: g.univariate_polynomial() # optional - sage.rings.number_field 700*y^2 - 2*y + 305 - sage: g.univariate_polynomial(PolynomialRing(QQ,'z')) + sage: g.univariate_polynomial(PolynomialRing(QQ, 'z')) # optional - sage.rings.number_field 700*z^2 - 2*z + 305 TESTS:: @@ -1614,13 +1607,13 @@ def variables(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.variables() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.variables() # optional - sage.rings.number_field (x, y) - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.variables() + sage: g.variables() # optional - sage.rings.number_field (y,) TESTS: @@ -1635,32 +1628,32 @@ def variables(self): def variable(self,i): """ - Returns `i`-th variable occurring in this polynomial. + Return the `i`-th variable occurring in this polynomial. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.variable(0) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.variable(0) # optional - sage.rings.number_field x - sage: f.variable(1) + sage: f.variable(1) # optional - sage.rings.number_field y """ return self.variables()[int(i)] def nvariables(self): """ - Number of variables in this polynomial + Return the number of variables in this polynomial. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.nvariables () + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.nvariables() # optional - sage.rings.number_field 2 - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.nvariables () + sage: g.nvariables() # optional - sage.rings.number_field 1 """ return len(self.degrees().nonzero_positions()) @@ -1671,27 +1664,27 @@ def is_constant(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.is_constant() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.is_constant() # optional - sage.rings.number_field False - sage: g = 10*x^0 - sage: g.is_constant() + sage: g = 10*x^0 # optional - sage.rings.number_field + sage: g.is_constant() # optional - sage.rings.number_field True """ return self.element().is_constant() def lm(self): """ - Returns the lead monomial of self with respect to the term order of - self.parent(). + Return the lead monomial of ``self`` with respect to the term order of + ``self.parent()``. EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: (x^1*y^2 + y^3*z^4).lm() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.libs.pari + sage: (x^1*y^2 + y^3*z^4).lm() # optional - sage.libs.pari x*y^2 - sage: (x^3*y^2*z^4 + x^3*y^2*z^1).lm() + sage: (x^3*y^2*z^4 + x^3*y^2*z^1).lm() # optional - sage.libs.pari x^3*y^2*z^4 :: @@ -1704,18 +1697,18 @@ def lm(self): :: - sage: R.=PolynomialRing(QQbar,3,order='degrevlex') - sage: (x^1*y^5*z^2 + x^4*y^1*z^3).lm() + sage: R.=PolynomialRing(QQbar,3,order='degrevlex') # optional - sage.rings.number_field + sage: (x^1*y^5*z^2 + x^4*y^1*z^3).lm() # optional - sage.rings.number_field x*y^5*z^2 - sage: (x^4*y^7*z^1 + x^4*y^2*z^3).lm() + sage: (x^4*y^7*z^1 + x^4*y^2*z^3).lm() # optional - sage.rings.number_field x^4*y^7*z TESTS:: sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict - sage: R.=MPolynomialRing_polydict(GF(2),2,order='lex') - sage: f=x+y - sage: f.lm() + sage: R. = MPolynomialRing_polydict(GF(2), 2, order='lex') # optional - sage.libs.pari + sage: f = x + y # optional - sage.libs.pari + sage: f.lm() # optional - sage.libs.pari x """ @@ -1732,14 +1725,14 @@ def lm(self): def lc(self): """ - Returns the leading coefficient of self i.e., - self.coefficient(self.lm()) + Returns the leading coefficient of ``self``, i.e., + ``self.coefficient(self.lm())`` EXAMPLES:: - sage: R.=QQbar[] - sage: f=3*x^2-y^2-x*y - sage: f.lc() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - y^2 - x*y # optional - sage.rings.number_field + sage: f.lc() # optional - sage.rings.number_field 3 """ try: @@ -1754,27 +1747,27 @@ def lc(self): def lt(self): r""" - Returns the leading term of self i.e., self.lc()\*self.lm(). The + Return the leading term of ``self`` i.e., ``self.lc()*self.lm()``. The notion of "leading term" depends on the ordering defined in the parent ring. EXAMPLES:: - sage: R.=PolynomialRing(QQbar) - sage: f=3*x^2-y^2-x*y - sage: f.lt() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = 3*x^2 - y^2 - x*y # optional - sage.rings.number_field + sage: f.lt() # optional - sage.rings.number_field 3*x^2 - sage: R.=PolynomialRing(QQbar,order="invlex") - sage: f=3*x^2-y^2-x*y - sage: f.lt() + sage: R. = PolynomialRing(QQbar, order="invlex") # optional - sage.rings.number_field + sage: f = 3*x^2 - y^2 - x*y # optional - sage.rings.number_field + sage: f.lt() # optional - sage.rings.number_field -y^2 TESTS:: sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict - sage: R.=MPolynomialRing_polydict(GF(2),2,order='lex') - sage: f=x+y - sage: f.lt() + sage: R. = MPolynomialRing_polydict(GF(2), 2, order='lex') # optional - sage.libs.pari + sage: f = x + y # optional - sage.libs.pari + sage: f.lt() # optional - sage.libs.pari x """ try: @@ -1828,14 +1821,14 @@ def _floordiv_(self, right): EXAMPLES:: - sage: R.=QQbar[] - sage: 2*x*y//y + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: 2*x*y//y # optional - sage.rings.number_field 2*x - sage: 2*x//y + sage: 2*x//y # optional - sage.rings.number_field 0 - sage: 2*x//4 + sage: 2*x//4 # optional - sage.rings.number_field 1/2*x - sage: type(0//y) + sage: type(0//y) # optional - sage.rings.number_field """ # handle division by monomials without using Singular @@ -1856,7 +1849,7 @@ def _derivative(self, var=None): r""" Differentiates ``self`` with respect to variable ``var``. - If ``var`` is not one of the generators of this ring, _derivative(var) + If ``var`` is not one of the generators of this ring, ``_derivative(var)`` is called recursively on each coefficient of this polynomial. .. SEEALSO:: @@ -1865,24 +1858,26 @@ def _derivative(self, var=None): EXAMPLES:: - sage: R. = PowerSeriesRing(QQbar) - sage: S. = PolynomialRing(R) - sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 - sage: f.parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field - sage: f._derivative(x) # with respect to x + sage: R. = PowerSeriesRing(QQbar) # optional - sage.rings.number_field + sage: S. = PolynomialRing(R) # optional - sage.rings.number_field + sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 # optional - sage.rings.number_field + sage: f.parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field + sage: f._derivative(x) # with respect to x # optional - sage.rings.number_field (2*t^2 + O(t^3))*x*y^3 + (111*t^4 + O(t^5))*x^2 - sage: f._derivative(x).parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field - sage: f._derivative(y) # with respect to y + sage: f._derivative(x).parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field + sage: f._derivative(y) # with respect to y # optional - sage.rings.number_field (3*t^2 + O(t^3))*x^2*y^2 - sage: f._derivative(t) # with respect to t (recurses into base ring) + sage: f._derivative(t) # with respect to t (recurses into base ring) # optional - sage.rings.number_field (2*t + O(t^2))*x^2*y^3 + (148*t^3 + O(t^4))*x^3 - sage: f._derivative(x)._derivative(y) # with respect to x and then y + sage: f._derivative(x)._derivative(y) # with respect to x and then y # optional - sage.rings.number_field (6*t^2 + O(t^3))*x*y^2 - sage: f.derivative(y, 3) # with respect to y three times + sage: f.derivative(y, 3) # with respect to y three times # optional - sage.rings.number_field (6*t^2 + O(t^3))*x^2 - sage: f._derivative() # can't figure out the variable + sage: f._derivative() # can't figure out the variable # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: must specify which variable to differentiate with respect to @@ -1915,7 +1910,7 @@ def integral(self, var=None): The integral is always chosen so the constant term is 0. - If ``var`` is not one of the generators of this ring, integral(var) + If ``var`` is not one of the generators of this ring, ``integral(var)`` is called recursively on each coefficient of this polynomial. EXAMPLES: @@ -1932,28 +1927,31 @@ def integral(self, var=None): sage: R = ZZ['x']['y, z'] sage: y, z = R.gens() sage: R.an_element().integral(y).parent() - Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in x over Rational Field + Multivariate Polynomial Ring in y, z + over Univariate Polynomial Ring in x over Rational Field On polynomials with coefficients in power series:: - sage: R. = PowerSeriesRing(QQbar) - sage: S. = PolynomialRing(R) - sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 - sage: f.parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field - sage: f.integral(x) # with respect to x + sage: R. = PowerSeriesRing(QQbar) # optional - sage.rings.number_field + sage: S. = PolynomialRing(R) # optional - sage.rings.number_field + sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 # optional - sage.rings.number_field + sage: f.parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field + sage: f.integral(x) # with respect to x # optional - sage.rings.number_field (1/3*t^2 + O(t^3))*x^3*y^3 + (37/4*t^4 + O(t^5))*x^4 - sage: f.integral(x).parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field + sage: f.integral(x).parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field - sage: f.integral(y) # with respect to y + sage: f.integral(y) # with respect to y # optional - sage.rings.number_field (1/4*t^2 + O(t^3))*x^2*y^4 + (37*t^4 + O(t^5))*x^3*y - sage: f.integral(t) # with respect to t (recurses into base ring) + sage: f.integral(t) # with respect to t (recurses into base ring) # optional - sage.rings.number_field (1/3*t^3 + O(t^4))*x^2*y^3 + (37/5*t^5 + O(t^6))*x^3 TESTS:: - sage: f.integral() # can't figure out the variable + sage: f.integral() # can't figure out the variable # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: must specify which variable to integrate with respect to @@ -2005,7 +2003,7 @@ def factor(self, proof=None): INPUT: - - ``proof'' - insist on provably correct results (default: ``True`` + - ``proof`` - insist on provably correct results (default: ``True`` unless explicitly disabled for the ``"polynomial"`` subsystem with :class:`sage.structure.proof.proof.WithProof`.) @@ -2044,8 +2042,8 @@ def factor(self, proof=None): Check that we can factor over the algebraic field (:trac:`25390`):: - sage: R. = PolynomialRing(QQbar) - sage: factor(x^2 + y^2) + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: factor(x^2 + y^2) # optional - sage.rings.number_field (x + (-1*I)*y) * (x + 1*I*y) Check that the global proof flag for polynomials is honored:: @@ -2095,12 +2093,12 @@ def factor(self, proof=None): We check a case that failed with an exception at some point:: - sage: k. = GF(4) - sage: R. = k[] - sage: l. = R.quo(v^3 + v + 1) - sage: R. = l[] - sage: f = y^3 + x^3 + (u + 1)*x - sage: f.factor() + sage: k. = GF(4) # optional - sage.libs.pari + sage: R. = k[] # optional - sage.libs.pari + sage: l. = R.quo(v^3 + v + 1) # optional - sage.libs.pari + sage: R. = l[] # optional - sage.libs.pari + sage: f = y^3 + x^3 + (u + 1)*x # optional - sage.libs.pari + sage: f.factor() # optional - sage.libs.pari x^3 + y^3 + (u + 1)*x """ @@ -2159,15 +2157,15 @@ def factor(self, proof=None): @handle_AA_and_QQbar def lift(self,I): """ - given an ideal I = (f_1,...,f_r) and some g (== self) in I, find - s_1,...,s_r such that g = s_1 f_1 + ... + s_r f_r + Given an ideal `I = (f_1,...,f_r)` and some `g` (= ``self``) in `I`, find + `s_1,...,s_r` such that `g = s_1 f_1 + ... + s_r f_r`. ALGORITHM: Use Singular. EXAMPLES:: - sage: A. = PolynomialRing(CC,2,order='degrevlex') - sage: I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7 ]) + sage: A. = PolynomialRing(CC, 2, order='degrevlex') + sage: I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7]) sage: f = x*y^13 + y^12 sage: M = f.lift(I) sage: M @@ -2177,13 +2175,13 @@ def lift(self,I): TESTS: - Check that this method works over QQbar (:trac:`25351`):: + Check that this method works over ``QQbar`` (:trac:`25351`):: - sage: A. = QQbar[] - sage: I = A.ideal([x^2 + y^2 - 1, x^2 - y^2]) - sage: f = 2*x^2 - 1 - sage: M = f.lift(I) - sage: sum( map( mul , zip( M, I.gens() ) ) ) == f + sage: A. = QQbar[] # optional - sage.rings.number_field + sage: I = A.ideal([x^2 + y^2 - 1, x^2 - y^2]) # optional - sage.rings.number_field + sage: f = 2*x^2 - 1 # optional - sage.rings.number_field + sage: M = f.lift(I) # optional - sage.rings.number_field + sage: sum(map(mul, zip(M, I.gens()))) == f # optional - sage.rings.number_field True """ fs = self._singular_() @@ -2226,9 +2224,9 @@ def quo_rem(self, right): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: f = y*x^2 + x + 1 - sage: f.quo_rem(x) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = y*x^2 + x + 1 # optional - sage.rings.number_field + sage: f.quo_rem(x) # optional - sage.rings.number_field (x*y + 1, 1) """ R = self.parent() @@ -2270,9 +2268,9 @@ def resultant(self, other, variable=None): sage: P. = PolynomialRing(QQ, 2) sage: a = x + y sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: a.resultant(b) # optional - sage.libs.singular -2*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.libs.singular 2*x^3 TESTS:: @@ -2281,15 +2279,15 @@ def resultant(self, other, variable=None): sage: P. = MPolynomialRing_polydict_domain(QQ, 2, order='degrevlex') sage: a = x + y sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: a.resultant(b) # optional - sage.libs.singular -2*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.libs.singular 2*x^3 Check that :trac:`15061` is fixed:: - sage: R. = AA[] - sage: (x^2 + 1).resultant(x^2 - y) + sage: R. = AA[] # optional - sage.rings.number_field + sage: (x^2 + 1).resultant(x^2 - y) # optional - sage.rings.number_field y^2 + 2*y + 1 Test for :trac:`2693`:: @@ -2297,17 +2295,17 @@ def resultant(self, other, variable=None): sage: R. = RR[] sage: p = x + y sage: q = x*y - sage: p.resultant(q) + sage: p.resultant(q) # optional - sage.libs.singular -y^2 Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: a = x + y - sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: a = x + y # optional - sage.rings.number_field + sage: b = x^3 - y^3 # optional - sage.rings.number_field + sage: a.resultant(b) # optional - sage.rings.number_field (-2)*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.rings.number_field 2*x^3 """ R = self.parent() @@ -2337,13 +2335,13 @@ def subresultants(self, other, variable=None): EXAMPLES:: - sage: R. = QQbar[] - sage: p = (y^2 + 6)*(x - 1) - y*(x^2 + 1) - sage: q = (x^2 + 6)*(y - 1) - x*(y^2 + 1) - sage: p.subresultants(q, y) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = (y^2 + 6)*(x - 1) - y*(x^2 + 1) # optional - sage.rings.number_field + sage: q = (x^2 + 6)*(y - 1) - x*(y^2 + 1) # optional - sage.rings.number_field + sage: p.subresultants(q, y) # optional - sage.rings.number_field [2*x^6 + (-22)*x^5 + 102*x^4 + (-274)*x^3 + 488*x^2 + (-552)*x + 288, -x^3 - x^2*y + 6*x^2 + 5*x*y + (-11)*x + (-6)*y + 6] - sage: p.subresultants(q, x) + sage: p.subresultants(q, x) # optional - sage.rings.number_field [2*y^6 + (-22)*y^5 + 102*y^4 + (-274)*y^3 + 488*y^2 + (-552)*y + 288, x*y^2 + y^3 + (-5)*x*y + (-6)*y^2 + 6*x + 11*y - 6] @@ -2367,48 +2365,48 @@ def reduce(self, I): EXAMPLES:: - sage: P. = QQbar[] - sage: f1 = -2 * x^2 + x^3 - sage: f2 = -2 * y + x* y - sage: f3 = -x^2 + y^2 - sage: F = Ideal([f1,f2,f3]) - sage: g = x*y - 3*x*y^2 - sage: g.reduce(F) + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: f1 = -2 * x^2 + x^3 # optional - sage.rings.number_field + sage: f2 = -2 * y + x * y # optional - sage.rings.number_field + sage: f3 = -x^2 + y^2 # optional - sage.rings.number_field + sage: F = Ideal([f1, f2, f3]) # optional - sage.rings.number_field + sage: g = x*y - 3*x*y^2 # optional - sage.rings.number_field + sage: g.reduce(F) # optional - sage.rings.number_field (-6)*y^2 + 2*y - sage: g.reduce(F.gens()) + sage: g.reduce(F.gens()) # optional - sage.rings.number_field (-6)*y^2 + 2*y :: - sage: f = 3*x - sage: f.reduce([2*x,y]) + sage: f = 3*x # optional - sage.rings.number_field + sage: f.reduce([2*x, y]) # optional - sage.rings.number_field 0 :: - sage: k. = CyclotomicField(3) - sage: A. = PolynomialRing(k) - sage: J = [ y9 + y12] - sage: f = y9 - y12; f.reduce(J) + sage: k. = CyclotomicField(3) # optional - sage.rings.number_field + sage: A. = PolynomialRing(k) # optional - sage.rings.number_field + sage: J = [y9 + y12] # optional - sage.rings.number_field + sage: f = y9 - y12; f.reduce(J) # optional - sage.rings.number_field -2*y12 - sage: f = y13*y15; f.reduce(J) + sage: f = y13*y15; f.reduce(J) # optional - sage.rings.number_field y13*y15 - sage: f = y13*y15 + y9 - y12; f.reduce(J) + sage: f = y13*y15 + y9 - y12; f.reduce(J) # optional - sage.rings.number_field y13*y15 - 2*y12 Make sure the remainder returns the correct type, fixing :trac:`13903`:: - sage: R.=PolynomialRing(Qp(5),2, order='lex') - sage: G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3] - sage: type((y2^3).reduce(G)) + sage: R. = PolynomialRing(Qp(5), 2, order='lex') # optional - sage.rings.padics + sage: G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3] # optional - sage.rings.padics + sage: type((y2^3).reduce(G)) # optional - sage.rings.padics TESTS: Verify that :trac:`34105` is fixed:: - sage: R. = AA[] - sage: x.reduce(R.zero_ideal()) + sage: R. = AA[] # optional - sage.rings.number_field + sage: x.reduce(R.zero_ideal()) # optional - sage.rings.number_field x """ from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal @@ -2455,30 +2453,30 @@ def reduce(self, I): def degree_lowest_rational_function(r, x): r""" - Return the difference of valuations of r with respect to variable x. + Return the difference of valuations of ``r`` with respect to variable ``x``. INPUT: - ``r`` -- a multivariate rational function - - ``x`` -- a multivariate polynomial ring generator x + - ``x`` -- a multivariate polynomial ring generator OUTPUT: - - ``integer`` -- the difference val_x(p) - val_x(q) where r = p/q + - ``integer`` -- the difference `val_x(p) - val_x(q)` where `r = p/q` .. NOTE:: This function should be made a method of the - FractionFieldElement class. + :class:`FractionFieldElement` class. EXAMPLES:: - sage: R1 = PolynomialRing(FiniteField(5), 3, names = ["a","b","c"]) - sage: F = FractionField(R1) - sage: a,b,c = R1.gens() - sage: f = 3*a*b^2*c^3+4*a*b*c - sage: g = a^2*b*c^2+2*a^2*b^4*c^7 + sage: R1 = PolynomialRing(FiniteField(5), 3, names=["a", "b", "c"]) # optional - sage.libs.pari + sage: F = FractionField(R1) # optional - sage.libs.pari + sage: a,b,c = R1.gens() # optional - sage.libs.pari + sage: f = 3*a*b^2*c^3 + 4*a*b*c # optional - sage.libs.pari + sage: g = a^2*b*c^2 + 2*a^2*b^4*c^7 # optional - sage.libs.pari Consider the quotient `f/g = \frac{4 + 3 bc^{2}}{ac + 2 ab^{3}c^{6}}` (note the @@ -2486,13 +2484,13 @@ def degree_lowest_rational_function(r, x): :: - sage: r = f/g; r + sage: r = f/g; r # optional - sage.libs.pari (-2*b*c^2 - 1)/(2*a*b^3*c^6 + a*c) - sage: degree_lowest_rational_function(r,a) + sage: degree_lowest_rational_function(r, a) # optional - sage.libs.pari -1 - sage: degree_lowest_rational_function(r,b) + sage: degree_lowest_rational_function(r, b) # optional - sage.libs.pari 0 - sage: degree_lowest_rational_function(r,c) + sage: degree_lowest_rational_function(r, c) # optional - sage.libs.pari -1 """ from sage.rings.fraction_field import FractionField diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index 49d603599e3..e8c4ac45d3b 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.singular r""" Ideals in multivariate polynomial rings @@ -11,7 +12,7 @@ EXAMPLES: We compute a Groebner basis for some given ideal. The type returned by -the ``groebner_basis`` method is ``PolynomialSequence``, i.e. it is not a +the ``groebner_basis`` method is ``PolynomialSequence``, i.e., it is not a :class:`MPolynomialIdeal`:: sage: x,y,z = QQ['x,y,z'].gens() @@ -149,7 +150,7 @@ sage: I.change_ring(P.change_ring(QQ)).groebner_basis() [1] - However, when we compute the Groebner basis of I (defined over + However, when we compute the Groebner basis of `I` (defined over `\ZZ`), we note that there is a certain integer in the ideal which is not 1. :: @@ -157,29 +158,29 @@ [x + y + 57119*z + 4, y^2 + 3*y + 17220, y*z + ..., 2*y + 158864, z^2 + 17223, 2*z + 41856, 164878] Now for each prime `p` dividing this integer 164878, the Groebner - basis of I modulo `p` will be non-trivial and will thus give a + basis of `I` modulo `p` will be non-trivial and will thus give a solution of the original system modulo `p`. :: sage: factor(164878) 2 * 7 * 11777 - sage: I.change_ring(P.change_ring( GF(2) )).groebner_basis() + sage: I.change_ring(P.change_ring(GF(2))).groebner_basis() # optional - sage.rings.finite_rings [x + y + z, y^2 + y, y*z + y, z^2 + 1] - sage: I.change_ring(P.change_ring( GF(7) )).groebner_basis() + sage: I.change_ring(P.change_ring(GF(7))).groebner_basis() # optional - sage.rings.finite_rings [x - 1, y + 3, z - 2] - sage: I.change_ring(P.change_ring( GF(11777 ))).groebner_basis() + sage: I.change_ring(P.change_ring(GF(11777))).groebner_basis() # optional - sage.rings.finite_rings [x + 5633, y - 3007, z - 2626] The Groebner basis modulo any product of the prime factors is also non-trivial:: - sage: I.change_ring(P.change_ring( IntegerModRing(2*7) )).groebner_basis() + sage: I.change_ring(P.change_ring(IntegerModRing(2 * 7))).groebner_basis() [x + 9*y + 13*z, y^2 + 3*y, y*z + 7*y + 6, 2*y + 6, z^2 + 3, 2*z + 10] Modulo any other prime the Groebner basis is trivial so there are no other solutions. For example:: - sage: I.change_ring( P.change_ring( GF(3) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(3))).groebner_basis() # optional - sage.rings.finite_rings [1] TESTS:: @@ -301,7 +302,7 @@ def __call__(self, *args, **kwds): def is_MPolynomialIdeal(x): """ - Return ``True`` if the provided argument ``x`` is an ideal in the + Return ``True`` if the provided argument ``x`` is an ideal in a multivariate polynomial ring. INPUT: @@ -341,9 +342,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,4) # indirect doctest - sage: magma(I) # optional - magma + sage: R. = PolynomialRing(GF(127),10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R,4) # indirect doctest # optional - sage.rings.finite_rings + sage: magma(I) # optional - magma # optional - sage.rings.finite_rings Ideal of Polynomial ring of rank 10 over GF(127) Order: Graded Reverse Lexicographical Variables: a, b, c, d, e, f, g, h, i, j @@ -378,18 +379,18 @@ def _groebner_basis_magma(self, deg_bound=None, prot=False, magma=magma_default) EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: gb = I.groebner_basis('magma:GroebnerBasis') # indirect doctest; optional - magma - sage: len(gb) # optional - magma + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.rings.finite_rings + sage: gb = I.groebner_basis('magma:GroebnerBasis') # indirect doctest; optional - magma sage.rings.finite_rings + sage: len(gb) # optional - magma # optional - sage.rings.finite_rings 45 We may also pass a degree bound to Magma:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: gb = I.groebner_basis('magma:GroebnerBasis', deg_bound=4) # indirect doctest; optional - magma - sage: len(gb) # optional - magma + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.rings.finite_rings + sage: gb = I.groebner_basis('magma:GroebnerBasis', deg_bound=4) # indirect doctest; optional - magma # optional - sage.rings.finite_rings + sage: len(gb) # optional - magma # optional - sage.rings.finite_rings 5 """ R = self.ring() @@ -726,7 +727,7 @@ def complete_primary_decomposition(self, algorithm="sy"): `b^n \in Q` for some `n \in \ZZ`. If `Q` is a primary ideal of the ring `R`, then the radical - ideal `P` of `Q` (i.e. the ideal consisting of all `a \in R` + ideal `P` of `Q` (i.e., the ideal consisting of all `a \in R` with a^n \in Q` for some `n \in \ZZ`), is called the associated prime of `Q`. @@ -760,7 +761,7 @@ def complete_primary_decomposition(self, algorithm="sy"): sage: R. = PolynomialRing(QQ, 3, order='lex') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: pd = I.complete_primary_decomposition(); sorted(pd, key=str) [(Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field, Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field), @@ -839,8 +840,8 @@ def primary_decomposition(self, algorithm='sy'): `b^n \in Q` for some `n \in \ZZ`. If `Q` is a primary ideal of the ring `R`, then the radical - ideal `P` of `Q` (i.e. the ideal consisting of all `a \in R` - with a^n \in Q` for some `n \in \ZZ`), is called the + ideal `P` of `Q` (i.e., the ideal consisting of all `a \in R` + with `a^n \in Q` for some `n \in \ZZ`), is called the associated prime of `Q`. If `I` is a proper ideal of a Noetherian ring `R`, then there @@ -872,15 +873,17 @@ def primary_decomposition(self, algorithm='sy'): sage: R. = PolynomialRing(QQ, 3, order='lex') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: pd = I.primary_decomposition(); sorted(pd, key=str) - [Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field, - Ideal (z^6 + 4*z^3 + 4, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field] + [Ideal (z^2 + 1, y + 1) + of Multivariate Polynomial Ring in x, y, z over Rational Field, + Ideal (z^6 + 4*z^3 + 4, y - z^2) + of Multivariate Polynomial Ring in x, y, z over Rational Field] :: sage: from functools import reduce - sage: reduce(lambda Qi,Qj: Qi.intersection(Qj), pd) == I + sage: reduce(lambda Qi, Qj: Qi.intersection(Qj), pd) == I True ALGORITHM: @@ -944,7 +947,7 @@ def associated_primes(self, algorithm='sy'): sage: R. = PolynomialRing(QQ, 3, order='lex') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: pd = I.associated_primes(); sorted(pd, key=str) [Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field, Ideal (z^3 + 2, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field] @@ -974,13 +977,13 @@ def is_prime(self, **kwds): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: I = (x^2 - y^2 - 1)*R + sage: I = (x^2 - y^2 - 1) * R sage: I.is_prime() True sage: (I^2).is_prime() False - sage: J = (x^2 - y^2)*R + sage: J = (x^2 - y^2) * R sage: J.is_prime() False sage: (J^3).is_prime() @@ -994,9 +997,12 @@ def is_prime(self, **kwds): fraction field is not the quotient ring itself:: sage: Q = R.quotient(I); Q - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1) + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 - y^2 - 1) sage: Q.fraction_field() - Fraction Field of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1) + Fraction Field of + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 - y^2 - 1) """ if not self.ring().base_ring().is_field(): raise NotImplementedError @@ -1016,7 +1022,7 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): sets. This requires that the given basis is reduced w.r.t. to the - lexicographical monomial ordering. If the basis of self does + lexicographical monomial ordering. If the basis of ``self`` does not have this property, the required Groebner basis is computed implicitly. @@ -1026,14 +1032,14 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): ALGORITHMS: - - ``singular:triangL`` - decomposition of self into triangular + - ``"singular:triangL"`` - decomposition of ``self`` into triangular systems (Lazard). - - ``singular:triangLfak`` - decomp. of self into tri. systems + - ``"singular:triangLfak"`` - decomposition of ``self`` into triangular systems plus factorization. - - ``singular:triangM`` - decomposition of self into - triangular systems (Moeller). + - ``"singular:triangM"`` - decomposition of ``self`` into + triangular systems (Moeller). OUTPUT: a list `T` of lists `t` such that the variety of ``self`` is the union of the varieties of `t` in `L` and each @@ -1041,23 +1047,38 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(QQ,5,order='lex') + sage: P. = PolynomialRing(QQ, 5, order='lex'); P.rename("P") sage: I = sage.rings.ideal.Cyclic(P) sage: GB = Ideal(I.groebner_basis('libsingular:stdfglm')) sage: GB.triangular_decomposition('singular:triangLfak') - [Ideal (a - 1, b - 1, c - 1, d^2 + 3*d + 1, e + d + 3) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a - 1, b - 1, c^2 + 3*c + 1, d + c + 3, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a - 1, b^2 + 3*b + 1, c + b + 3, d - 1, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a - 1, b^4 + b^3 + b^2 + b + 1, -c + b^2, -d + b^3, e + b^3 + b^2 + b + 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^2 + 3*a + 1, b - 1, c - 1, d - 1, e + a + 3) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^2 + 3*a + 1, b + a + 3, c - 1, d - 1, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 - 4*a^3 + 6*a^2 + a + 1, -11*b^2 + 6*b*a^3 - 26*b*a^2 + 41*b*a - 4*b - 8*a^3 + 31*a^2 - 40*a - 24, 11*c + 3*a^3 - 13*a^2 + 26*a - 2, 11*d + 3*a^3 - 13*a^2 + 26*a - 2, -11*e - 11*b + 6*a^3 - 26*a^2 + 41*a - 4) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b - 1, c + a^3 + a^2 + a + 1, -d + a^3, -e + a^2) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b - a, c - a, d^2 + 3*d*a + a^2, e + d + 3*a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b - a, c^2 + 3*c*a + a^2, d + c + 3*a, e - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b^2 + 3*b*a + a^2, c + b + 3*a, d - a, e - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b^3 + b^2*a + b^2 + b*a^2 + b*a + b + a^3 + a^2 + a + 1, c + b^2*a^3 + b^2*a^2 + b^2*a + b^2, -d + b^2*a^2 + b^2*a + b^2 + b*a^2 + b*a + a^2, -e + b^2*a^3 - b*a^2 - b*a - b - a^2 - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + 6*a^2 - 4*a + 1, -11*b^2 + 6*b*a^3 + 10*b*a^2 + 39*b*a + 2*b + 16*a^3 + 23*a^2 + 104*a - 24, 11*c + 3*a^3 + 5*a^2 + 25*a + 1, 11*d + 3*a^3 + 5*a^2 + 25*a + 1, -11*e - 11*b + 6*a^3 + 10*a^2 + 39*a + 2) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field] + [Ideal (a - 1, b - 1, c - 1, d^2 + 3*d + 1, e + d + 3) of P, + Ideal (a - 1, b - 1, c^2 + 3*c + 1, d + c + 3, e - 1) of P, + Ideal (a - 1, b^2 + 3*b + 1, c + b + 3, d - 1, e - 1) of P, + Ideal (a - 1, b^4 + b^3 + b^2 + b + 1, -c + b^2, -d + b^3, + e + b^3 + b^2 + b + 1) of P, + Ideal (a^2 + 3*a + 1, b - 1, c - 1, d - 1, e + a + 3) of P, + Ideal (a^2 + 3*a + 1, b + a + 3, c - 1, d - 1, e - 1) of P, + Ideal (a^4 - 4*a^3 + 6*a^2 + a + 1, + -11*b^2 + 6*b*a^3 - 26*b*a^2 + 41*b*a - 4*b - 8*a^3 + 31*a^2 - 40*a - 24, + 11*c + 3*a^3 - 13*a^2 + 26*a - 2, 11*d + 3*a^3 - 13*a^2 + 26*a - 2, + -11*e - 11*b + 6*a^3 - 26*a^2 + 41*a - 4) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b - 1, c + a^3 + a^2 + a + 1, -d + a^3, -e + a^2) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b - a, c - a, d^2 + 3*d*a + a^2, e + d + 3*a) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b - a, c^2 + 3*c*a + a^2, d + c + 3*a, e - a) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b^2 + 3*b*a + a^2, c + b + 3*a, d - a, e - a) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b^3 + b^2*a + b^2 + b*a^2 + b*a + b + a^3 + a^2 + a + 1, + c + b^2*a^3 + b^2*a^2 + b^2*a + b^2, + -d + b^2*a^2 + b^2*a + b^2 + b*a^2 + b*a + a^2, + -e + b^2*a^3 - b*a^2 - b*a - b - a^2 - a) of P, + Ideal (a^4 + a^3 + 6*a^2 - 4*a + 1, + -11*b^2 + 6*b*a^3 + 10*b*a^2 + 39*b*a + 2*b + 16*a^3 + 23*a^2 + 104*a - 24, + 11*c + 3*a^3 + 5*a^2 + 25*a + 1, 11*d + 3*a^3 + 5*a^2 + 25*a + 1, + -11*e - 11*b + 6*a^3 + 10*a^2 + 39*a + 2) of P] sage: R. = PolynomialRing(QQ, 2, order='lex') sage: f1 = 1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2) @@ -1067,7 +1088,8 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): [Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field, Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field, Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field, - Ideal (x2^4 + 4*x2^3 - 6*x2^2 - 20*x2 + 5, 8*x1 - x2^3 + x2^2 + 13*x2 - 5) of Multivariate Polynomial Ring in x1, x2 over Rational Field] + Ideal (x2^4 + 4*x2^3 - 6*x2^2 - 20*x2 + 5, 8*x1 - x2^3 + x2^2 + 13*x2 - 5) + of Multivariate Polynomial Ring in x1, x2 over Rational Field] TESTS:: @@ -1078,9 +1100,9 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: J = Ideal(x^2+y^2-2, y^2-1) - sage: J.triangular_decomposition() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: J = Ideal(x^2 + y^2 - 2, y^2 - 1) # optional - sage.rings.number_field + sage: J.triangular_decomposition() # optional - sage.rings.number_field [Ideal (y^2 - 1, x^2 - 1) of Multivariate Polynomial Ring in x, y over Algebraic Field] """ P = self.ring() @@ -1136,9 +1158,9 @@ def dimension(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(32003),order='degrevlex') - sage: I = ideal(x^2-y,x^3) - sage: I.dimension() + sage: P. = PolynomialRing(GF(32003), order='degrevlex') # optional - sage.rings.finite_rings + sage: I = ideal(x^2 - y, x^3) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings 1 If the ideal is the total ring, the dimension is `-1` by convention. @@ -1150,22 +1172,22 @@ def dimension(self, singular=singular_default): EXAMPLES:: - sage: R. = PolynomialRing(GF(2147483659^2),order='lex') - sage: I = R.ideal([x*y,x*y+1]) - sage: I.dimension() + sage: R. = PolynomialRing(GF(2147483659^2), order='lex') # optional - sage.rings.finite_rings + sage: I = R.ideal([x*y, x*y + 1]) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. -1 - sage: I=ideal([x*(x*y+1),y*(x*y+1)]) - sage: I.dimension() + sage: I=ideal([x*(x*y+1), y*(x*y+1)]) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. 1 - sage: I = R.ideal([x^3*y,x*y^2]) - sage: I.dimension() + sage: I = R.ideal([x^3*y, x*y^2]) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. 1 - sage: R. = PolynomialRing(GF(2147483659^2),order='lex') - sage: I = R.ideal(0) - sage: I.dimension() + sage: R. = PolynomialRing(GF(2147483659^2), order='lex') # optional - sage.rings.finite_rings + sage: I = R.ideal(0) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. 2 @@ -1177,9 +1199,9 @@ def dimension(self, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = ideal(x^2-y,x^3-QQbar(-1)) - sage: I.dimension() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(x^2-y, x^3-QQbar(-1)) # optional - sage.rings.number_field + sage: I.dimension() # optional - sage.rings.number_field 1 .. NOTE:: @@ -1251,7 +1273,7 @@ def dimension(self, singular=singular_default): def vector_space_dimension(self): """ Return the vector space dimension of the ring modulo this ideal. If - the ideal is not zero-dimensional, a TypeError is raised. + the ideal is not zero-dimensional, a :class:`TypeError` is raised. ALGORITHM: @@ -1278,19 +1300,19 @@ def vector_space_dimension(self): Due to integer overflow, the result is correct only modulo ``2^32``, see :trac:`8586`:: - sage: P. = PolynomialRing(GF(32003),3) - sage: sage.rings.ideal.FieldIdeal(P).vector_space_dimension() # known bug + sage: P. = PolynomialRing(GF(32003),3) # optional - sage.rings.finite_rings + sage: sage.rings.ideal.FieldIdeal(P).vector_space_dimension() # known bug # optional - sage.rings.finite_rings 32777216864027 TESTS: Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = ideal(x^2-y,x^3-QQbar(-1),z-y) - sage: I.dimension() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(x^2-y,x^3-QQbar(-1),z-y) # optional - sage.rings.number_field + sage: I.dimension() # optional - sage.rings.number_field 0 - sage: I.vector_space_dimension() + sage: I.vector_space_dimension() # optional - sage.rings.number_field 3 """ @@ -1327,12 +1349,12 @@ def _groebner_basis_ginv(self, algorithm="TQ", criteria='CritPartially', divisio sage: P. = PolynomialRing(QQ,order='degrevlex') sage: I = sage.rings.ideal.Katsura(P) - sage: I.groebner_basis(algorithm='ginv') # optional - ginv + sage: I.groebner_basis(algorithm='ginv') # optional - ginv [z^3 - 79/210*z^2 + 1/30*y + 1/70*z, y^2 - 3/5*z^2 - 1/5*y + 1/5*z, y*z + 6/5*z^2 - 1/10*y - 2/5*z, x + 2*y + 2*z - 1] - sage: P. = PolynomialRing(GF(127),order='degrevlex') - sage: I = sage.rings.ideal.Katsura(P) - sage: I.groebner_basis(algorithm='ginv') # optional - ginv + sage: P. = PolynomialRing(GF(127), order='degrevlex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: I.groebner_basis(algorithm='ginv') # optional - ginv # optional - sage.rings.finite_rings ... [z^3 + 22*z^2 - 55*y + 49*z, y^2 - 26*z^2 - 51*y + 51*z, y*z + 52*z^2 + 38*y + 25*z, x + 2*y + 2*z - 1] @@ -1575,9 +1597,9 @@ def genus(self): Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = ideal(y^3*z + x^3*y + x*z^3) - sage: I.genus() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(y^3*z + x^3*y + x*z^3) # optional - sage.rings.number_field + sage: I.genus() # optional - sage.rings.number_field 3 """ from sage.libs.singular.function_factory import ff @@ -1601,22 +1623,23 @@ def intersection(self, *others): The following simple example illustrates that the product need not equal the intersection. :: - sage: I = (x^2, y)*R - sage: J = (y^2, x)*R + sage: I = (x^2, y) * R + sage: J = (y^2, x) * R sage: K = I.intersection(J); K Ideal (y^2, x*y, x^2) of Multivariate Polynomial Ring in x, y over Rational Field sage: IJ = I*J; IJ - Ideal (x^2*y^2, x^3, y^3, x*y) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x^2*y^2, x^3, y^3, x*y) + of Multivariate Polynomial Ring in x, y over Rational Field sage: IJ == K False Intersection of several ideals:: sage: R. = PolynomialRing(QQ, 3, order='lex') - sage: I1 = x*R - sage: I2 = y*R - sage: I3 = (x, y)*R - sage: I4 = (x^2 + x*y*z, y^2 - z^3*y, z^3 + y^5*x*z)*R + sage: I1 = x * R + sage: I2 = y * R + sage: I3 = (x, y) * R + sage: I4 = (x^2 + x*y*z, y^2 - z^3*y, z^3 + y^5*x*z) * R sage: I1.intersection(I2, I3, I4).groebner_basis() [x^2*y + x*y*z^4, x*y^2 - x*y*z^3, x*y*z^20 - x*y*z^3] @@ -1635,10 +1658,10 @@ def intersection(self, *others): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = x*R - sage: J = y*R - sage: I.intersection(J) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = x*R # optional - sage.rings.number_field + sage: J = y*R # optional - sage.rings.number_field + sage: I.intersection(J) # optional - sage.rings.number_field Ideal (x*y) of Multivariate Polynomial Ring in x, y over Algebraic Field """ R = self.ring() @@ -1665,10 +1688,12 @@ def minimal_associated_primes(self): sage: R. = PolynomialRing(QQ, 3, 'xyz') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: sorted(I.minimal_associated_primes(), key=str) - [Ideal (z^2 + 1, -z^2 + y) of Multivariate Polynomial Ring in x, y, z over Rational Field, - Ideal (z^3 + 2, -z^2 + y) of Multivariate Polynomial Ring in x, y, z over Rational Field] + [Ideal (z^2 + 1, -z^2 + y) + of Multivariate Polynomial Ring in x, y, z over Rational Field, + Ideal (z^3 + 2, -z^2 + y) + of Multivariate Polynomial Ring in x, y, z over Rational Field] ALGORITHM: @@ -1692,7 +1717,7 @@ def radical(self): This is an obviously not radical ideal:: sage: R. = PolynomialRing(QQ, 3) - sage: I = (x^2, y^3, (x*z)^4 + y^3 + 10*x^2)*R + sage: I = (x^2, y^3, (x*z)^4 + y^3 + 10*x^2) * R sage: I.radical() Ideal (y, x) of Multivariate Polynomial Ring in x, y, z over Rational Field @@ -1704,9 +1729,10 @@ def radical(self): This is the example from the Singular manual:: sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: I.radical() - Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) of Multivariate Polynomial Ring in x, y, z over Rational Field + Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) + of Multivariate Polynomial Ring in x, y, z over Rational Field .. NOTE:: @@ -1716,11 +1742,12 @@ def radical(self): :: - sage: R. = PolynomialRing(GF(37), 3) - sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y - z^2)*R - sage: I.radical() - Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 37 + sage: R. = PolynomialRing(GF(37), 3) # optional - sage.rings.finite_rings + sage: p = z^2 + 1; q = z^3 + 2 # optional - sage.rings.finite_rings + sage: I = (p*q^2, y - z^2) * R # optional - sage.rings.finite_rings + sage: I.radical() # optional - sage.rings.finite_rings + Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) + of Multivariate Polynomial Ring in x, y, z over Finite Field of size 37 """ from sage.libs.singular.function_factory import ff radical = ff.primdec__lib.radical @@ -1803,16 +1830,16 @@ def syzygy_module(self): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: f = 2*x^2 + y - sage: g = y - sage: h = 2*f + g - sage: I = Ideal([f,g,h]) - sage: M = I.syzygy_module(); M + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2*x^2 + y # optional - sage.rings.number_field + sage: g = y # optional - sage.rings.number_field + sage: h = 2*f + g # optional - sage.rings.number_field + sage: I = Ideal([f,g,h]) # optional - sage.rings.number_field + sage: M = I.syzygy_module(); M # optional - sage.rings.number_field [ -2 -1 1] [ -y 2*x^2 + y 0] - sage: G = vector(I.gens()) - sage: M*G + sage: G = vector(I.gens()) # optional - sage.rings.number_field + sage: M*G # optional - sage.rings.number_field (0, 0) """ from sage.libs.singular.function_factory import ff @@ -1904,50 +1931,50 @@ def graded_free_resolution(self, *args, **kwds): @libsingular_gb_standard_options def interreduced_basis(self): r""" - If this ideal is spanned by `(f_1, ..., f_n)` this method - returns `(g_1, ..., g_s)` such that: + If this ideal is spanned by `(f_1, ..., f_n)`, + return `(g_1, ..., g_s)` such that: - `(f_1,...,f_n) = (g_1,...,g_s)` - - `LT(g_i) != LT(g_j)` for all `i != j` + - `LT(g_i) \neq LT(g_j)` for all `i \neq j` - `LT(g_i)` does not divide `m` for all monomials `m` of - `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` + `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` - - `LC(g_i) == 1` for all `i` if the coefficient ring is a field. + - `LC(g_i) = 1` for all `i` if the coefficient ring is a field. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: I = Ideal([z*x+y^3,z+y^3,z+x*y]) + sage: I = Ideal([z*x + y^3, z + y^3, z + x*y]) sage: I.interreduced_basis() [y^3 + z, x*y + z, x*z - z] Note that tail reduction for local orderings is not well-defined:: sage: R. = PolynomialRing(QQ,order='negdegrevlex') - sage: I = Ideal([z*x+y^3,z+y^3,z+x*y]) + sage: I = Ideal([z*x + y^3, z + y^3, z + x*y]) sage: I.interreduced_basis() [z + x*y, x*y - y^3, x^2*y - y^3] A fixed error with nonstandard base fields:: - sage: R.=QQ['t'] - sage: K.=R.fraction_field()['x,y'] - sage: I=t*x*K + sage: R. = QQ['t'] + sage: K. = R.fraction_field()['x,y'] + sage: I = t*x * K sage: I.interreduced_basis() [x] The interreduced basis of 0 is 0:: - sage: P. = GF(2)[] - sage: Ideal(P(0)).interreduced_basis() + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: Ideal(P(0)).interreduced_basis() # optional - sage.rings.finite_rings [0] ALGORITHM: - Uses Singular's interred command or + Uses Singular's ``interred`` command or :func:`sage.rings.polynomial.toy_buchberger.inter_reduction` if conversion to Singular fails. @@ -1955,9 +1982,9 @@ def interreduced_basis(self): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = Ideal([z*x+y^3,z+y^3,z+x*y]) - sage: I.interreduced_basis() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([z*x + y^3, z + y^3, z + x*y]) # optional - sage.rings.number_field + sage: I.interreduced_basis() # optional - sage.rings.number_field [y^3 + z, x*y + z, x*z - z] """ return self.basis.reduced() @@ -1985,44 +2012,63 @@ def basis_is_groebner(self, singular=singular_default): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,4) - sage: I.basis_is_groebner() + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 4) # optional - sage.rings.finite_rings + sage: I.basis_is_groebner() # optional - sage.rings.finite_rings False - sage: I2 = Ideal(I.groebner_basis()) - sage: I2.basis_is_groebner() + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.finite_rings + sage: I2.basis_is_groebner() # optional - sage.rings.finite_rings True A more complicated example:: - sage: R. = PolynomialRing(GF(7583)) - sage: l = [u6 + u5 + u4 + u3 + u2 - 3791*h, \ - U6 + U5 + U4 + U3 + U2 - 3791*h, \ - U2*u2 - h^2, U3*u3 - h^2, U4*u4 - h^2, \ - U5*u4 + U5*u3 + U4*u3 + U5*u2 + U4*u2 + U3*u2 - 3791*U5*h - 3791*U4*h - 3791*U3*h - 3791*U2*h - 2842*h^2, \ - U4*u5 + U3*u5 + U2*u5 + U3*u4 + U2*u4 + U2*u3 - 3791*u5*h - 3791*u4*h - 3791*u3*h - 3791*u2*h - 2842*h^2, \ - U5*u5 - h^2, U4*U2*u3 + U5*U3*u2 + U4*U3*u2 + U3^2*u2 - 3791*U5*U3*h - 3791*U4*U3*h - 3791*U3^2*h - 3791*U5*U2*h \ - - 3791*U4*U2*h + U3*U2*h - 3791*U2^2*h - 3791*U4*u3*h - 3791*U4*u2*h - 3791*U3*u2*h - 2843*U5*h^2 + 1897*U4*h^2 - 946*U3*h^2 - 947*U2*h^2 + 2370*h^3, \ - U3*u5*u4 + U2*u5*u4 + U3*u4^2 + U2*u4^2 + U2*u4*u3 - 3791*u5*u4*h - 3791*u4^2*h - 3791*u4*u3*h - 3791*u4*u2*h + u5*h^2 - 2842*u4*h^2, \ - U2*u5*u4*u3 + U2*u4^2*u3 + U2*u4*u3^2 - 3791*u5*u4*u3*h - 3791*u4^2*u3*h - 3791*u4*u3^2*h - 3791*u4*u3*u2*h + u5*u4*h^2 + u4^2*h^2 + u5*u3*h^2 - 2842*u4*u3*h^2, \ - U5^2*U4*u3 + U5*U4^2*u3 + U5^2*U4*u2 + U5*U4^2*u2 + U5^2*U3*u2 + 2*U5*U4*U3*u2 + U5*U3^2*u2 - 3791*U5^2*U4*h - 3791*U5*U4^2*h - 3791*U5^2*U3*h \ - + U5*U4*U3*h - 3791*U5*U3^2*h - 3791*U5^2*U2*h + U5*U4*U2*h + U5*U3*U2*h - 3791*U5*U2^2*h - 3791*U5*U3*u2*h - 2842*U5^2*h^2 + 1897*U5*U4*h^2 \ - - U4^2*h^2 - 947*U5*U3*h^2 - U4*U3*h^2 - 948*U5*U2*h^2 - U4*U2*h^2 - 1422*U5*h^3 + 3791*U4*h^3, \ - u5*u4*u3*u2*h + u4^2*u3*u2*h + u4*u3^2*u2*h + u4*u3*u2^2*h + 2*u5*u4*u3*h^2 + 2*u4^2*u3*h^2 + 2*u4*u3^2*h^2 + 2*u5*u4*u2*h^2 + 2*u4^2*u2*h^2 \ - + 2*u5*u3*u2*h^2 + 1899*u4*u3*u2*h^2, \ - U5^2*U4*U3*u2 + U5*U4^2*U3*u2 + U5*U4*U3^2*u2 - 3791*U5^2*U4*U3*h - 3791*U5*U4^2*U3*h - 3791*U5*U4*U3^2*h - 3791*U5*U4*U3*U2*h \ - + 3791*U5*U4*U3*u2*h + U5^2*U4*h^2 + U5*U4^2*h^2 + U5^2*U3*h^2 - U4^2*U3*h^2 - U5*U3^2*h^2 - U4*U3^2*h^2 - U5*U4*U2*h^2 \ - - U5*U3*U2*h^2 - U4*U3*U2*h^2 + 3791*U5*U4*h^3 + 3791*U5*U3*h^3 + 3791*U4*U3*h^3, \ - u4^2*u3*u2*h^2 + 1515*u5*u3^2*u2*h^2 + u4*u3^2*u2*h^2 + 1515*u5*u4*u2^2*h^2 + 1515*u5*u3*u2^2*h^2 + u4*u3*u2^2*h^2 \ - + 1521*u5*u4*u3*h^3 - 3028*u4^2*u3*h^3 - 3028*u4*u3^2*h^3 + 1521*u5*u4*u2*h^3 - 3028*u4^2*u2*h^3 + 1521*u5*u3*u2*h^3 + 3420*u4*u3*u2*h^3, \ - U5^2*U4*U3*U2*h + U5*U4^2*U3*U2*h + U5*U4*U3^2*U2*h + U5*U4*U3*U2^2*h + 2*U5^2*U4*U3*h^2 + 2*U5*U4^2*U3*h^2 + 2*U5*U4*U3^2*h^2 \ - + 2*U5^2*U4*U2*h^2 + 2*U5*U4^2*U2*h^2 + 2*U5^2*U3*U2*h^2 - 2*U4^2*U3*U2*h^2 - 2*U5*U3^2*U2*h^2 - 2*U4*U3^2*U2*h^2 \ - - 2*U5*U4*U2^2*h^2 - 2*U5*U3*U2^2*h^2 - 2*U4*U3*U2^2*h^2 - U5*U4*U3*h^3 - U5*U4*U2*h^3 - U5*U3*U2*h^3 - U4*U3*U2*h^3] - - sage: Ideal(l).basis_is_groebner() + sage: R. = PolynomialRing(GF(7583)) # optional - sage.rings.finite_rings + sage: l = [u6 + u5 + u4 + u3 + u2 - 3791*h, # optional - sage.rings.finite_rings + ....: U6 + U5 + U4 + U3 + U2 - 3791*h, + ....: U2*u2 - h^2, U3*u3 - h^2, U4*u4 - h^2, + ....: U5*u4 + U5*u3 + U4*u3 + U5*u2 + U4*u2 + U3*u2 - 3791*U5*h + ....: - 3791*U4*h - 3791*U3*h - 3791*U2*h - 2842*h^2, + ....: U4*u5 + U3*u5 + U2*u5 + U3*u4 + U2*u4 + U2*u3 - 3791*u5*h + ....: - 3791*u4*h - 3791*u3*h - 3791*u2*h - 2842*h^2, + ....: U5*u5 - h^2, U4*U2*u3 + U5*U3*u2 + U4*U3*u2 + U3^2*u2 - 3791*U5*U3*h + ....: - 3791*U4*U3*h - 3791*U3^2*h - 3791*U5*U2*h- 3791*U4*U2*h + U3*U2*h + ....: - 3791*U2^2*h - 3791*U4*u3*h - 3791*U4*u2*h - 3791*U3*u2*h + ....: - 2843*U5*h^2 + 1897*U4*h^2 - 946*U3*h^2 - 947*U2*h^2 + 2370*h^3, + ....: U3*u5*u4 + U2*u5*u4 + U3*u4^2 + U2*u4^2 + U2*u4*u3 - 3791*u5*u4*h + ....: - 3791*u4^2*h - 3791*u4*u3*h - 3791*u4*u2*h + u5*h^2 - 2842*u4*h^2, + ....: U2*u5*u4*u3 + U2*u4^2*u3 + U2*u4*u3^2 - 3791*u5*u4*u3*h + ....: - 3791*u4^2*u3*h - 3791*u4*u3^2*h - 3791*u4*u3*u2*h + u5*u4*h^2 + ....: + u4^2*h^2 + u5*u3*h^2 - 2842*u4*u3*h^2, + ....: U5^2*U4*u3 + U5*U4^2*u3 + U5^2*U4*u2 + U5*U4^2*u2 + U5^2*U3*u2 + ....: + 2*U5*U4*U3*u2 + U5*U3^2*u2 - 3791*U5^2*U4*h - 3791*U5*U4^2*h + ....: - 3791*U5^2*U3*h + U5*U4*U3*h - 3791*U5*U3^2*h - 3791*U5^2*U2*h + ....: + U5*U4*U2*h+ U5*U3*U2*h - 3791*U5*U2^2*h - 3791*U5*U3*u2*h + ....: - 2842*U5^2*h^2 + 1897*U5*U4*h^2 - U4^2*h^2 - 947*U5*U3*h^2 + ....: - U4*U3*h^2 - 948*U5*U2*h^2 - U4*U2*h^2 - 1422*U5*h^3 + 3791*U4*h^3, + ....: u5*u4*u3*u2*h + u4^2*u3*u2*h + u4*u3^2*u2*h + u4*u3*u2^2*h + ....: + 2*u5*u4*u3*h^2 + 2*u4^2*u3*h^2 + 2*u4*u3^2*h^2 + 2*u5*u4*u2*h^2 + ....: + 2*u4^2*u2*h^2 + 2*u5*u3*u2*h^2 + 1899*u4*u3*u2*h^2, + ....: U5^2*U4*U3*u2 + U5*U4^2*U3*u2 + U5*U4*U3^2*u2 - 3791*U5^2*U4*U3*h + ....: - 3791*U5*U4^2*U3*h - 3791*U5*U4*U3^2*h - 3791*U5*U4*U3*U2*h + ....: + 3791*U5*U4*U3*u2*h + U5^2*U4*h^2 + U5*U4^2*h^2 + U5^2*U3*h^2 + ....: - U4^2*U3*h^2 - U5*U3^2*h^2 - U4*U3^2*h^2 - U5*U4*U2*h^2 - U5*U3*U2*h^2 + ....: - U4*U3*U2*h^2 + 3791*U5*U4*h^3 + 3791*U5*U3*h^3 + 3791*U4*U3*h^3, + ....: u4^2*u3*u2*h^2 + 1515*u5*u3^2*u2*h^2 + u4*u3^2*u2*h^2 + ....: + 1515*u5*u4*u2^2*h^2 + 1515*u5*u3*u2^2*h^2 + u4*u3*u2^2*h^2 + ....: + 1521*u5*u4*u3*h^3 - 3028*u4^2*u3*h^3 - 3028*u4*u3^2*h^3 + ....: + 1521*u5*u4*u2*h^3 - 3028*u4^2*u2*h^3 + 1521*u5*u3*u2*h^3 + ....: + 3420*u4*u3*u2*h^3, + ....: U5^2*U4*U3*U2*h + U5*U4^2*U3*U2*h + U5*U4*U3^2*U2*h + U5*U4*U3*U2^2*h + ....: + 2*U5^2*U4*U3*h^2 + 2*U5*U4^2*U3*h^2 + 2*U5*U4*U3^2*h^2 + ....: + 2*U5^2*U4*U2*h^2 + 2*U5*U4^2*U2*h^2 + 2*U5^2*U3*U2*h^2 + ....: - 2*U4^2*U3*U2*h^2 - 2*U5*U3^2*U2*h^2 - 2*U4*U3^2*U2*h^2 + ....: - 2*U5*U4*U2^2*h^2 - 2*U5*U3*U2^2*h^2 - 2*U4*U3*U2^2*h^2 + ....: - U5*U4*U3*h^3 - U5*U4*U2*h^3 - U5*U3*U2*h^3 - U4*U3*U2*h^3] + + sage: Ideal(l).basis_is_groebner() # optional - sage.rings.finite_rings False - sage: gb = Ideal(l).groebner_basis() - sage: Ideal(gb).basis_is_groebner() + sage: gb = Ideal(l).groebner_basis() # optional - sage.rings.finite_rings + sage: Ideal(gb).basis_is_groebner() # optional - sage.rings.finite_rings True .. NOTE:: @@ -2040,12 +2086,12 @@ def basis_is_groebner(self, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = sage.rings.ideal.Cyclic(R,4) - sage: I.basis_is_groebner() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = sage.rings.ideal.Cyclic(R,4) # optional - sage.rings.number_field + sage: I.basis_is_groebner() # optional - sage.rings.number_field False - sage: I2 = Ideal(I.groebner_basis()) - sage: I2.basis_is_groebner() + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.number_field + sage: I2.basis_is_groebner() # optional - sage.rings.number_field True """ from sage.matrix.constructor import matrix @@ -2095,25 +2141,25 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula - ``algorithm`` - see below for options. - - ``other_ring`` - only valid for algorithm 'fglm', if - provided conversion will be performed to this + - ``other_ring`` - only valid for ``algorithm='fglm'``; if + provided, conversion will be performed to this ring. Otherwise a lex Groebner basis will be returned. ALGORITHMS: - - ``fglm`` - FGLM algorithm. The input ideal must be given with a reduced + - ``"fglm"`` - FGLM algorithm. The input ideal must be given with a reduced Groebner Basis of a zero-dimensional ideal - - ``gwalk`` - Groebner Walk algorithm (*default*) + - ``"gwalk"`` - Groebner Walk algorithm (*default*) - - ``awalk1`` - 'first alternative' algorithm + - ``"awalk1"`` - 'first alternative' algorithm - - ``awalk2`` - 'second alternative' algorithm + - ``"awalk2"`` - 'second alternative' algorithm - - ``twalk`` - Tran algorithm + - ``"twalk"`` - Tran algorithm - - ``fwalk`` - Fractal Walk algorithm + - ``"fwalk"`` - Fractal Walk algorithm EXAMPLES:: @@ -2124,21 +2170,22 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula sage: J = Ideal(I.transformed_basis('fglm',S)) sage: J Ideal (z^4 + y^3 - y, x^2 + y^3, x*y^3 - y^3, y^4 + y^3) - of Multivariate Polynomial Ring in z, x, y over Rational Field + of Multivariate Polynomial Ring in z, x, y over Rational Field :: - sage: R.=PolynomialRing(GF(32003),3,order='lex') - sage: I=Ideal([y^3+x*y*z+y^2*z+x*z^3,3+x*y+x^2*y+y^2*z]) - sage: I.transformed_basis('gwalk') + sage: R. = PolynomialRing(GF(32003), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([y^3 + x*y*z + y^2*z + x*z^3, 3 + x*y + x^2*y + y^2*z]) # optional - sage.rings.finite_rings + sage: I.transformed_basis('gwalk') # optional - sage.rings.finite_rings [z*y^2 + y*x^2 + y*x + 3, - z*x + 8297*y^8*x^2 + 8297*y^8*x + 3556*y^7 - 8297*y^6*x^4 + 15409*y^6*x^3 - 8297*y^6*x^2 - - 8297*y^5*x^5 + 15409*y^5*x^4 - 8297*y^5*x^3 + 3556*y^5*x^2 + 3556*y^5*x + 3556*y^4*x^3 - + 3556*y^4*x^2 - 10668*y^4 - 10668*y^3*x - 8297*y^2*x^9 - 1185*y^2*x^8 + 14224*y^2*x^7 - - 1185*y^2*x^6 - 8297*y^2*x^5 - 14223*y*x^7 - 10666*y*x^6 - 10666*y*x^5 - 14223*y*x^4 - + x^5 + 2*x^4 + x^3, - y^9 - y^7*x^2 - y^7*x - y^6*x^3 - y^6*x^2 - 3*y^6 - 3*y^5*x - y^3*x^7 - 3*y^3*x^6 - - 3*y^3*x^5 - y^3*x^4 - 9*y^2*x^5 - 18*y^2*x^4 - 9*y^2*x^3 - 27*y*x^3 - 27*y*x^2 - 27*x] + z*x + 8297*y^8*x^2 + 8297*y^8*x + 3556*y^7 - 8297*y^6*x^4 + 15409*y^6*x^3 + - 8297*y^6*x^2 - 8297*y^5*x^5 + 15409*y^5*x^4 - 8297*y^5*x^3 + 3556*y^5*x^2 + + 3556*y^5*x + 3556*y^4*x^3 + 3556*y^4*x^2 - 10668*y^4 - 10668*y^3*x + - 8297*y^2*x^9 - 1185*y^2*x^8 + 14224*y^2*x^7 - 1185*y^2*x^6 - 8297*y^2*x^5 + - 14223*y*x^7 - 10666*y*x^6 - 10666*y*x^5 - 14223*y*x^4 + x^5 + 2*x^4 + x^3, + y^9 - y^7*x^2 - y^7*x - y^6*x^3 - y^6*x^2 - 3*y^6 - 3*y^5*x - y^3*x^7 + - 3*y^3*x^6 - 3*y^3*x^5 - y^3*x^4 - 9*y^2*x^5 - 18*y^2*x^4 - 9*y^2*x^3 + - 27*y*x^3 - 27*y*x^2 - 27*x] ALGORITHM: @@ -2149,12 +2196,12 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula Check that this method works over QQbar (:trac:`25351`). We are not currently able to specify other_ring, due to the limitations of @handle_AA_and_QQbar:: - sage: R. = QQbar[] - sage: I = Ideal([y^3+x^2,x^2*y+x^2, x^3-x^2, z^4-x^2-y]) - sage: I = Ideal(I.groebner_basis()) - sage: S. = PolynomialRing(QQbar,3,order='lex') - sage: J = Ideal(I.transformed_basis('fglm',other_ring=S)) # known bug - sage: J # known bug + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([y^3 + x^2, x^2*y + x^2, x^3 - x^2, z^4 - x^2 - y]) # optional - sage.rings.number_field + sage: I = Ideal(I.groebner_basis()) # optional - sage.rings.number_field + sage: S. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: J = Ideal(I.transformed_basis('fglm', other_ring=S)) # known bug # optional - sage.rings.number_field + sage: J # known bug # optional - sage.rings.number_field """ from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence R = self.ring() @@ -2199,7 +2246,7 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): - ``variables`` -- a list or tuple of variables in ``self.ring()`` - ``algorithm`` - determines the algorithm to use, see below - for available algorithms. + for available algorithms. ALGORITHMS: @@ -2214,10 +2261,10 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): EXAMPLES:: sage: R. = PolynomialRing(QQ,5) - sage: I = R * [x-t,y-t^2,z-t^3,s-x+y^3] - sage: J = I.elimination_ideal([t,s]); J - Ideal (y^2 - x*z, x*y - z, x^2 - y) of Multivariate - Polynomial Ring in x, y, t, s, z over Rational Field + sage: I = R * [x - t, y - t^2, z - t^3, s - x + y^3] + sage: J = I.elimination_ideal([t, s]); J + Ideal (y^2 - x*z, x*y - z, x^2 - y) + of Multivariate Polynomial Ring in x, y, t, s, z over Rational Field You can use Giac to compute the elimination ideal:: @@ -2241,12 +2288,12 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = R * [x-t,y-t^2,z-t^3,s-x+y^3] - sage: J = I.elimination_ideal([t,s]); J + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = R * [x - t, y - t^2, z - t^3, s - x + y^3] # optional - sage.rings.number_field + sage: J = I.elimination_ideal([t, s]); J # optional - sage.rings.number_field Ideal (y^2 - x*z, x*y - z, x^2 - y) of Multivariate Polynomial Ring in x, y, t, s, z over Algebraic Field - sage: print("possible output from giac", flush=True); I.elimination_ideal([t, s], algorithm="giac") == J + sage: print("possible output from giac", flush=True); I.elimination_ideal([t, s], algorithm="giac") == J # optional - sage.rings.number_field possible output... True @@ -2316,15 +2363,15 @@ def quotient(self, J): EXAMPLES:: - sage: R. = PolynomialRing(GF(181),3) - sage: I = Ideal([x^2+x*y*z,y^2-z^3*y,z^3+y^5*x*z]) - sage: J = Ideal([x]) - sage: Q = I.quotient(J) - sage: y*z + x in I + sage: R. = PolynomialRing(GF(181), 3) # optional - sage.rings.finite_rings + sage: I = Ideal([x^2 + x*y*z, y^2 - z^3*y, z^3 + y^5*x*z]) # optional - sage.rings.finite_rings + sage: J = Ideal([x]) # optional - sage.rings.finite_rings + sage: Q = I.quotient(J) # optional - sage.rings.finite_rings + sage: y*z + x in I # optional - sage.rings.finite_rings False - sage: x in J + sage: x in J # optional - sage.rings.finite_rings True - sage: x * (y*z + x) in I + sage: x * (y*z + x) in I # optional - sage.rings.finite_rings True TESTS: @@ -2339,10 +2386,10 @@ def quotient(self, J): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = ideal(x,z) - sage: J = ideal(R(1)) - sage: I.quotient(J) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(x, z) # optional - sage.rings.number_field + sage: J = ideal(R(1)) # optional - sage.rings.number_field + sage: I.quotient(J) # optional - sage.rings.number_field Ideal (z, x) of Multivariate Polynomial Ring in x, y, z over Algebraic Field Check that :trac:`12803` is fixed:: @@ -2395,10 +2442,10 @@ def saturation(self, other): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = R.ideal(x^5*z^3, x*y*z, y*z^4) - sage: J = R.ideal(z) - sage: I.saturation(other = J) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = R.ideal(x^5*z^3, x*y*z, y*z^4) # optional - sage.rings.number_field + sage: J = R.ideal(z) # optional - sage.rings.number_field + sage: I.saturation(other = J) # optional - sage.rings.number_field (Ideal (y, x^5) of Multivariate Polynomial Ring in x, y, z over Algebraic Field, 4) """ from sage.libs.singular.function_factory import ff @@ -2412,7 +2459,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True r""" Return the variety of this ideal. - Given a zero-dimensional ideal `I` (== ``self``) of a + Given a zero-dimensional ideal `I` (= ``self``) of a polynomial ring `P` whose order is lexicographic, return the variety of `I` as a list of dictionaries with ``(variable, value)`` pairs. By default, the variety of the ideal over its @@ -2448,41 +2495,41 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True EXAMPLES:: - sage: K. = GF(27) # this example is from the MAGMA handbook - sage: P. = PolynomialRing(K, 2, order='lex') - sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) - sage: I = Ideal(I.groebner_basis()); I - Ideal (x - y^47 - y^45 + y^44 - y^43 + y^41 - y^39 - y^38 - - y^37 - y^36 + y^35 - y^34 - y^33 + y^32 - y^31 + y^30 + - y^28 + y^27 + y^26 + y^25 - y^23 + y^22 + y^21 - y^19 - - y^18 - y^16 + y^15 + y^13 + y^12 - y^10 + y^9 + y^8 + y^7 - - y^6 + y^4 + y^3 + y^2 + y - 1, y^48 + y^41 - y^40 + y^37 - - y^36 - y^33 + y^32 - y^29 + y^28 - y^25 + y^24 + y^2 + y - + 1) of Multivariate Polynomial Ring in x, y over Finite - Field in w of size 3^3 - - sage: V = I.variety(); - sage: sorted(V, key=str) + sage: K. = GF(27) # this example is from the MAGMA handbook # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(K, 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([x^8 + y + 2, y^6 + x*y^5 + x^2]) # optional - sage.rings.finite_rings + sage: I = Ideal(I.groebner_basis()); I # optional - sage.rings.finite_rings + Ideal (x - y^47 - y^45 + y^44 - y^43 + y^41 - y^39 - y^38 - y^37 - y^36 + + y^35 - y^34 - y^33 + y^32 - y^31 + y^30 + y^28 + y^27 + y^26 + + y^25 - y^23 + y^22 + y^21 - y^19 - y^18 - y^16 + y^15 + y^13 + + y^12 - y^10 + y^9 + y^8 + y^7 - y^6 + y^4 + y^3 + y^2 + y - 1, + y^48 + y^41 - y^40 + y^37 - y^36 - y^33 + y^32 - y^29 + y^28 + - y^25 + y^24 + y^2 + y + 1) + of Multivariate Polynomial Ring in x, y over Finite Field in w of size 3^3 + + sage: V = I.variety(); # optional - sage.rings.finite_rings + sage: sorted(V, key=str) # optional - sage.rings.finite_rings [{y: w^2 + 2*w, x: 2*w + 2}, {y: w^2 + 2, x: 2*w}, {y: w^2 + w, x: 2*w + 1}] - sage: [f.subs(v) for f in I.gens() for v in V] # check that all polynomials vanish + sage: [f.subs(v) # check that all polynomials vanish # optional - sage.rings.finite_rings + ....: for f in I.gens() for v in V] [0, 0, 0, 0, 0, 0] - sage: [I.subs(v).is_zero() for v in V] # same test, but nicer syntax + sage: [I.subs(v).is_zero() for v in V] # same test, but nicer syntax # optional - sage.rings.finite_rings [True, True, True] However, we only account for solutions in the ground field and not in the algebraic closure:: - sage: I.vector_space_dimension() + sage: I.vector_space_dimension() # optional - sage.rings.finite_rings 48 Here we compute the points of intersection of a hyperbola and a circle, in several fields:: sage: K. = PolynomialRing(QQ, 2, order='lex') - sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) + sage: I = Ideal([x*y - 1, (x-2)^2 + (y-1)^2 - 1]) sage: I = Ideal(I.groebner_basis()); I Ideal (x + y^3 - 2*y^2 + 4*y - 4, y^4 - 2*y^3 + 4*y^2 - 4*y + 1) - of Multivariate Polynomial Ring in x, y over Rational Field + of Multivariate Polynomial Ring in x, y over Rational Field These two curves have one rational intersection:: @@ -2494,7 +2541,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True sage: sorted(I.variety(ring=RR), key=str) [{y: 0.361103080528647, x: 2.76929235423863}, {y: 1.00000000000000, x: 1.00000000000000}] - sage: I.variety(ring=AA) + sage: I.variety(ring=AA) # optional - sage.rings.number_field [{y: 1, x: 1}, {y: 0.3611030805286474?, x: 2.769292354238632?}] @@ -2507,7 +2554,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True x: 0.11535382288068... + 0.58974280502220...*I}, {y: 0.36110308052864..., x: 2.7692923542386...}, {y: 1.00000000000000, x: 1.00000000000000}] - sage: sorted(I.variety(ring=QQbar), key=str) + sage: sorted(I.variety(ring=QQbar), key=str) # optional - sage.rings.number_field [{y: 0.3194484597356763? + 1.633170240915238?*I, x: 0.11535382288068429? - 0.5897428050222055?*I}, {y: 0.3194484597356763? - 1.633170240915238?*I, @@ -2519,7 +2566,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True to compute the variety. See :mod:`~sage.rings.polynomial.msolve` for more information. :: - sage: I.variety(RBF, algorithm='msolve', proof=False) # optional - msolve + sage: I.variety(RBF, algorithm='msolve', proof=False) # optional - msolve [{x: [2.76929235423863 +/- 2.08e-15], y: [0.361103080528647 +/- 4.53e-16]}, {x: 1.000000000000000, y: 1.000000000000000}] @@ -2542,9 +2589,9 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True If the ground field's characteristic is too large for Singular, we resort to a toy implementation:: - sage: R. = PolynomialRing(GF(2147483659^3),order='lex') - sage: I=ideal([x^3-2*y^2,3*x+y^4]) - sage: I.variety() + sage: R. = PolynomialRing(GF(2147483659^3), order='lex') # optional - sage.rings.finite_rings + sage: I = ideal([x^3 - 2*y^2, 3*x + y^4]) # optional - sage.rings.finite_rings + sage: I.variety() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation. verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. verbose 0 (...: multi_polynomial_ideal.py, variety) Warning: falling back to very slow toy implementation. @@ -2556,21 +2603,23 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True or even generator names as strings, when provided as keys:: sage: K. = QQ[] - sage: I = ideal([x^2+2*y-5,x+y+3]) - sage: v = I.variety(AA)[0]; v[x], v[y] + sage: I = ideal([x^2 + 2*y - 5, x + y + 3]) + sage: v = I.variety(AA)[0]; v[x], v[y] # optional - sage.rings.number_field (4.464101615137755?, -7.464101615137755?) - sage: list(v)[0].parent() + sage: list(v)[0].parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y over Algebraic Real Field - sage: v[x] + sage: v[x] # optional - sage.rings.number_field 4.464101615137755? - sage: v["y"] + sage: v["y"] # optional - sage.rings.number_field -7.464101615137755? - msolve also works over finite fields:: + ``msolve`` also works over finite fields:: - sage: R. = PolynomialRing(GF(536870909), 2, order='lex') - sage: I = Ideal([ x^2 - 1, y^2 - 1 ]) - sage: sorted(I.variety(algorithm='msolve', proof=False), key=str) # optional - msolve + sage: R. = PolynomialRing(GF(536870909), 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([x^2 - 1, y^2 - 1]) # optional - sage.rings.finite_rings + sage: sorted(I.variety(algorithm='msolve', # optional - msolve # optional - sage.rings.finite_rings + ....: proof=False), + ....: key=str) [{x: 1, y: 1}, {x: 1, y: 536870908}, {x: 536870908, y: 1}, @@ -2579,9 +2628,9 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True but may fail in small characteristic, especially with ideals of high degree with respect to the characteristic:: - sage: R. = PolynomialRing(GF(3), 2, order='lex') - sage: I = Ideal([ x^2 - 1, y^2 - 1 ]) - sage: I.variety(algorithm='msolve', proof=False) # optional - msolve + sage: R. = PolynomialRing(GF(3), 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([x^2 - 1, y^2 - 1]) # optional - sage.rings.finite_rings + sage: I.variety(algorithm='msolve', proof=False) # optional - msolve # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: characteristic 3 too small @@ -2616,20 +2665,20 @@ def _variety_triangular_decomposition(self, ring): TESTS:: - sage: K. = GF(27) - sage: P. = PolynomialRing(K, 2, order='lex') - sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) + sage: K. = GF(27) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(K, 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) # optional - sage.rings.finite_rings Testing the robustness of the Singular interface:: - sage: T = I.triangular_decomposition('singular:triangLfak') - sage: sorted(I.variety(), key=str) + sage: T = I.triangular_decomposition('singular:triangLfak') # optional - sage.rings.finite_rings + sage: sorted(I.variety(), key=str) # optional - sage.rings.finite_rings [{y: w^2 + 2*w, x: 2*w + 2}, {y: w^2 + 2, x: 2*w}, {y: w^2 + w, x: 2*w + 1}] Testing that a bug is indeed fixed :: - sage: R = PolynomialRing(GF(2), 30, ['x%d'%(i+1) for i in range(30)], order='lex') - sage: R.inject_variables() + sage: R = PolynomialRing(GF(2), 30, ['x%d'%(i+1) for i in range(30)], order='lex') # optional - sage.rings.finite_rings + sage: R.inject_variables() # optional - sage.rings.finite_rings Defining... sage: I = Ideal([x1 + 1, x2, x3 + 1, x5*x10 + x10 + x18, x5*x11 + x11, \ x5*x18, x6, x7 + 1, x9, x10*x11 + x10 + x18, x10*x18 + x18, \ @@ -2640,10 +2689,10 @@ def _variety_triangular_decomposition(self, ring): x11^2 + x11, x12^2 + x12, x13^2 + x13, x14^2 + x14, x15^2 + x15, \ x16^2 + x16, x17^2 + x17, x18^2 + x18, x19^2 + x19, x20^2 + x20, \ x21^2 + x21, x22^2 + x22, x23^2 + x23, x24^2 + x24, x25^2 + x25, \ - x26^2 + x26, x27^2 + x27, x28^2 + x28, x29^2 + x29, x30^2 + x30]) + x26^2 + x26, x27^2 + x27, x28^2 + x28, x29^2 + x29, x30^2 + x30]) # optional - sage.rings.finite_rings sage: I.basis_is_groebner() True - sage: sorted("".join(str(V[g]) for g in R.gens()) for V in I.variety()) # long time (6s on sage.math, 2011) + sage: sorted("".join(str(V[g]) for g in R.gens()) for V in I.variety()) # long time (6s on sage.math, 2011) # optional - sage.rings.finite_rings ['101000100000000110001000100110', '101000100000000110001000101110', '101000100100000101001000100110', @@ -2696,7 +2745,7 @@ def _variety_triangular_decomposition(self, ring): sage: R. = PolynomialRing(QQ, order='lex') sage: I = R.ideal(c^2-2, b-c, a) - sage: I.variety(QQbar) + sage: I.variety(QQbar) # optional - sage.rings.number_field [...a: 0...] An early version of :trac:`25351` broke this method by adding the @@ -2704,13 +2753,13 @@ def _variety_triangular_decomposition(self, ring): that this circle and this hyperbola have two real intersections and two more complex ones:: - sage: K. = PolynomialRing(AA) - sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) - sage: len(I.variety()) + sage: K. = PolynomialRing(AA) # optional - sage.rings.number_field + sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) # optional - sage.rings.number_field + sage: len(I.variety()) # optional - sage.rings.number_field 2 - sage: K. = PolynomialRing(QQbar) - sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) - sage: len(I.variety()) + sage: K. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) # optional - sage.rings.number_field + sage: len(I.variety()) # optional - sage.rings.number_field 4 """ @@ -2796,31 +2845,33 @@ def hilbert_polynomial(self, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint 5*t - 5 Of course, the Hilbert polynomial of a zero-dimensional ideal is zero:: - sage: J0 = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5, y^3-2*x*z^2+x*y,x^4+x*y-y*z^2]) + sage: J0 = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5, + ....: y^3 - 2*x*z^2 + x*y, x^4 + x*y - y*z^2]) sage: J = P*[m.lm() for m in J0.groebner_basis()] sage: J.dimension() 0 - sage: J.hilbert_polynomial() + sage: J.hilbert_polynomial() # optional - sage.libs.flint 0 It is possible to request a computation using the Singular library:: - sage: I.hilbert_polynomial(algorithm = 'singular') == I.hilbert_polynomial() + sage: I.hilbert_polynomial(algorithm='singular') == I.hilbert_polynomial() # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_polynomial(algorithm = 'singular') == J.hilbert_polynomial() + sage: J.hilbert_polynomial(algorithm='singular') == J.hilbert_polynomial() # optional - sage.libs.flint sage.libs.singular True Here is a bigger examples:: - sage: n = 4; m = 11; P = PolynomialRing(QQ, n * m, "x"); x = P.gens(); M = Matrix(n, x) + sage: n = 4; m = 11; P = PolynomialRing(QQ, n * m, "x"); x = P.gens() + sage: M = Matrix(n, x) sage: Minors = P.ideal(M.minors(2)) - sage: hp = Minors.hilbert_polynomial(); hp + sage: hp = Minors.hilbert_polynomial(); hp # optional - sage.libs.flint 1/21772800*t^13 + 61/21772800*t^12 + 1661/21772800*t^11 + 26681/21772800*t^10 + 93841/7257600*t^9 + 685421/7257600*t^8 + 1524809/3110400*t^7 + 39780323/21772800*t^6 + 6638071/1360800*t^5 @@ -2831,7 +2882,7 @@ def hilbert_polynomial(self, algorithm='sage'): with Singular. We don't test it here, as it has a side-effect on other tests that is not understood yet (see :trac:`26300`):: - sage: Minors.hilbert_polynomial(algorithm = 'singular') # not tested + sage: Minors.hilbert_polynomial(algorithm='singular') # not tested # optional - sage.libs.singular Traceback (most recent call last): ... RuntimeError: error in Singular function call 'hilbPoly': @@ -2842,9 +2893,10 @@ def hilbert_polynomial(self, algorithm='sage'): Note that in this example, the Hilbert polynomial gives the coefficients of the Hilbert-Poincaré series in all degrees:: - sage: P = PowerSeriesRing(QQ, 't', default_prec = 50) - sage: hs = Minors.hilbert_series() - sage: list(P(hs.numerator()) / P(hs.denominator())) == [hp(t = k) for k in range(50)] + sage: P = PowerSeriesRing(QQ, 't', default_prec=50) + sage: hs = Minors.hilbert_series() # optional - sage.libs.flint + sage: list(P(hs.numerator()) / P(hs.denominator())) == [hp(t = k) + ....: for k in range(50)] True TESTS: @@ -2853,23 +2905,23 @@ def hilbert_polynomial(self, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3, x*y^2, y^4, x^2*y*z, y^3*z, x^2*z^2, x*y*z^2, x*z^3]) - sage: I.hilbert_polynomial(algorithm='singular') + sage: I.hilbert_polynomial(algorithm='singular') # optional - sage.libs.singular 3 - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint 3 Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_polynomial() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) # optional - sage.rings.number_field + sage: I.hilbert_polynomial() # optional - sage.rings.number_field 5*t - 5 Check for :trac:`33597`:: sage: R. = QQ[] sage: I = R.ideal([X^2*Y^3, X*Z]) - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint t + 5 """ if not self.is_homogeneous(): @@ -2932,48 +2984,48 @@ def hilbert_series(self, grading=None, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series() + sage: I.hilbert_series() # optional - sage.libs.flint (t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1) sage: R. = PolynomialRing(QQ) - sage: J = R.ideal([a^2*b,a*b^2]) - sage: J.hilbert_series() + sage: J = R.ideal([a^2*b, a*b^2]) + sage: J.hilbert_series() # optional - sage.libs.flint (t^3 - t^2 - t - 1)/(t - 1) - sage: J.hilbert_series(grading=(10,3)) + sage: J.hilbert_series(grading=(10,3)) # optional - sage.libs.flint (t^25 + t^24 + t^23 - t^15 - t^14 - t^13 - t^12 - t^11 - t^10 - t^9 - t^8 - t^7 - t^6 - t^5 - t^4 - t^3 - t^2 - t - 1)/(t^12 + t^11 + t^10 - t^2 - t - 1) sage: K = R.ideal([a^2*b^3, a*b^4 + a^3*b^2]) - sage: K.hilbert_series(grading=[1,2]) + sage: K.hilbert_series(grading=[1,2]) # optional - sage.libs.flint (t^11 + t^8 - t^6 - t^5 - t^4 - t^3 - t^2 - t - 1)/(t^2 - 1) - sage: K.hilbert_series(grading=[2,1]) + sage: K.hilbert_series(grading=[2,1]) # optional - sage.libs.flint (2*t^7 - t^6 - t^4 - t^2 - 1)/(t - 1) TESTS:: - sage: I.hilbert_series() == I.hilbert_series(algorithm = 'singular') + sage: I.hilbert_series() == I.hilbert_series(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_series() == J.hilbert_series(algorithm = 'singular') + sage: J.hilbert_series() == J.hilbert_series(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_series(grading = (10,3)) == J.hilbert_series(grading = (10,3), algorithm = 'singular') + sage: J.hilbert_series(grading=(10,3)) == J.hilbert_series(grading=(10,3), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: K.hilbert_series(grading = (1,2)) == K.hilbert_series(grading = (1,2), algorithm = 'singular') + sage: K.hilbert_series(grading=(1,2)) == K.hilbert_series(grading=(1,2), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: K.hilbert_series(grading = (2,1)) == K.hilbert_series(grading = (2,1), algorithm = 'singular') + sage: K.hilbert_series(grading=(2,1)) == K.hilbert_series(grading=(2,1), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series(grading=5) + sage: I.hilbert_series(grading=5) # optional - sage.libs.flint Traceback (most recent call last): ... TypeError: grading must be a list or a tuple of integers Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) # optional - sage.rings.number_field + sage: I.hilbert_series() # optional - sage.rings.number_field (t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1) """ if not self.is_homogeneous(): @@ -3031,29 +3083,29 @@ def hilbert_numerator(self, grading = None, algorithm = 'sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_numerator() + sage: I.hilbert_numerator() # optional - sage.libs.flint -t^5 + 1 sage: R. = PolynomialRing(QQ) - sage: J = R.ideal([a^2*b,a*b^2]) - sage: J.hilbert_numerator() + sage: J = R.ideal([a^2*b, a*b^2]) + sage: J.hilbert_numerator() # optional - sage.libs.flint t^4 - 2*t^3 + 1 - sage: J.hilbert_numerator(grading=(10,3)) + sage: J.hilbert_numerator(grading=(10,3)) # optional - sage.libs.flint t^26 - t^23 - t^16 + 1 TESTS:: - sage: I.hilbert_numerator() == I.hilbert_numerator(algorithm = 'singular') + sage: I.hilbert_numerator() == I.hilbert_numerator(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_numerator() == J.hilbert_numerator(algorithm = 'singular') + sage: J.hilbert_numerator() == J.hilbert_numerator(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_numerator(grading=(10,3)) == J.hilbert_numerator(grading=(10,3), algorithm = 'singular') + sage: J.hilbert_numerator(grading=(10,3)) == J.hilbert_numerator(grading=(10,3), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_numerator() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) # optional - sage.rings.number_field + sage: I.hilbert_numerator() # optional - sage.rings.number_field -t^5 + 1 Our two algorithms should always agree; not tested until @@ -3191,7 +3243,7 @@ def normal_basis(self, degree=None, algorithm='libsingular', EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: I = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1) + sage: I = R.ideal(x^2 + y^2 + z^2 - 4, x^2 + 2*y^2 - 5, x*z - 1) sage: I.normal_basis() [y*z^2, z^2, y*z, z, x*y, y, x, 1] sage: I.normal_basis(algorithm='singular') @@ -3201,7 +3253,7 @@ def normal_basis(self, degree=None, algorithm='libsingular', particularly useful when the quotient ring is not finite-dimensional as a vector space. :: - sage: J = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5) + sage: J = R.ideal(x^2 + y^2 + z^2 - 4, x^2 + 2*y^2 - 5) sage: J.dimension() 1 sage: [J.normal_basis(d) for d in (0..3)] @@ -3223,19 +3275,19 @@ def normal_basis(self, degree=None, algorithm='libsingular', Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1) - sage: I.normal_basis() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1) # optional - sage.rings.number_field + sage: I.normal_basis() # optional - sage.rings.number_field [y*z^2, z^2, y*z, z, x*y, y, x, 1] - sage: J = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5) - sage: [J.normal_basis(d) for d in (0..3)] + sage: J = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5) # optional - sage.rings.number_field + sage: [J.normal_basis(d) for d in (0..3)] # optional - sage.rings.number_field [[1], [z, y, x], [z^2, y*z, x*z, x*y], [z^3, y*z^2, x*z^2, x*y*z]] Check the option ``algorithm="singular"`` with a weighted term order:: sage: T = TermOrder('wdegrevlex', (1, 2, 3)) - sage: S. = PolynomialRing(GF(2), order=T) - sage: S.ideal(x^6 + y^3 + z^2).normal_basis(6, algorithm='singular') + sage: S. = PolynomialRing(GF(2), order=T) # optional - sage.rings.finite_rings + sage: S.ideal(x^6 + y^3 + z^2).normal_basis(6, algorithm='singular') # optional - sage.rings.finite_rings [x^4*y, x^2*y^2, y^3, x^3*z, x*y*z, z^2] """ from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence @@ -3315,14 +3367,14 @@ def _groebner_basis_macaulay2(self, strategy=None): Over finite fields, Macaulay2 supports different algorithms to compute Gröbner bases:: - sage: R = PolynomialRing(GF(101), 'x', 4) - sage: I = sage.rings.ideal.Cyclic(R) - sage: gb1 = I.groebner_basis('macaulay2:gb') # optional - macaulay2 - sage: I = sage.rings.ideal.Cyclic(R) - sage: gb2 = I.groebner_basis('macaulay2:mgb') # optional - macaulay2 - sage: I = sage.rings.ideal.Cyclic(R) - sage: gb3 = I.groebner_basis('macaulay2:f4') # optional - macaulay2 - sage: gb1 == gb2 == gb3 # optional - macaulay2 + sage: R = PolynomialRing(GF(101), 'x', 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.rings.finite_rings + sage: gb1 = I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.rings.finite_rings + sage: gb2 = I.groebner_basis('macaulay2:mgb') # optional - macaulay2 # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.rings.finite_rings + sage: gb3 = I.groebner_basis('macaulay2:f4') # optional - macaulay2 # optional - sage.rings.finite_rings + sage: gb1 == gb2 == gb3 # optional - macaulay2 # optional - sage.rings.finite_rings True TESTS:: @@ -3380,26 +3432,32 @@ def __init__(self, ring, gens, coerce=True, side = "left"): - ``gens`` - the generators of this ideal - ``coerce`` (optional - default True) - generators are coerced into the ring before creating the ideal - - ``side`` - optional string, either "left" (default) - or "twosided"; defines whether this ideal is left + - ``side`` - optional string, either ``"left"`` (default) + or ``"twosided"``; defines whether this ideal is left of two-sided. EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) # indirect doctest - sage: I #random - Left Ideal (y^2, x^2, z^2 - 1) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(I.gens(),key=str) + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], # indirect doctest # optional - sage.combinat sage.modules + ....: coerce=False) + sage: I # random # optional - sage.combinat sage.modules + Left Ideal (y^2, x^2, z^2 - 1) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(I.gens(), key=str) # optional - sage.combinat sage.modules [x^2, y^2, z^2 - 1] - sage: H.ideal([y^2, x^2, z^2-H.one()], side="twosided") #random - Twosided Ideal (y^2, x^2, z^2 - 1) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(H.ideal([y^2, x^2, z^2-H.one()], side="twosided").gens(),key=str) + sage: H.ideal([y^2, x^2, z^2 - H.one()], side="twosided") # random # optional - sage.combinat sage.modules + Twosided Ideal (y^2, x^2, z^2 - 1) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(H.ideal([y^2, x^2, z^2 - H.one()], side="twosided").gens(), # optional - sage.combinat sage.modules + ....: key=str) [x^2, y^2, z^2 - 1] - sage: H.ideal([y^2, x^2, z^2-H.one()], side="right") + sage: H.ideal([y^2, x^2, z^2 - H.one()], side="right") # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: Only left and two-sided ideals are allowed. @@ -3424,14 +3482,15 @@ def __call_singular(self, cmd, arg = None): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: id = H.ideal(x + y, y + z) - sage: id.std() # indirect doctest # random - Left Ideal (z, y, x) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(id.std().gens(),key=str) + sage: id = H.ideal(x + y, y + z) # optional - sage.combinat sage.modules + sage: id.std() # indirect doctest # random # optional - sage.combinat sage.modules + Left Ideal (z, y, x) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(id.std().gens(), key=str) # optional - sage.combinat sage.modules [x, y, z] """ from sage.libs.singular.function import singular_function @@ -3448,43 +3507,57 @@ def std(self): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.std() #random - Left Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(I.std().gens(),key=str) + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.std() #random # optional - sage.combinat sage.modules + Left Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(I.std().gens(), key=str) # optional - sage.combinat sage.modules [2*x*y - z - 1, x*z + x, x^2, y*z - y, y^2, z^2 - 1] - If the ideal is a left ideal, then std returns a left + If the ideal is a left ideal, then :meth:`std` returns a left Groebner basis. But if it is a two-sided ideal, then - the output of std and :meth:`twostd` coincide:: - - sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) - sage: JL #random - Left Ideal (x^3, y^3, z^3 - 4*z) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JL.gens(),key=str) + the output of :meth:`std` and :meth:`twostd` coincide:: + + sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) # optional - sage.combinat sage.modules + sage: JL #random # optional - sage.combinat sage.modules + Left Ideal (x^3, y^3, z^3 - 4*z) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JL.gens(), key=str) # optional - sage.combinat sage.modules [x^3, y^3, z^3 - 4*z] - sage: JL.std() #random - Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JL.std().gens(),key=str) + sage: JL.std() # random # optional - sage.combinat sage.modules + Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, + x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JL.std().gens(), key=str) # optional - sage.combinat sage.modules [2*x*y*z - z^2 - 2*z, x*z^2 + 2*x*z, x^3, y*z^2 - 2*y*z, y^3, z^3 - 4*z] - sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') - sage: JT #random - Twosided Ideal (x^3, y^3, z^3 - 4*z) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JT.gens(),key=str) + sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') # optional - sage.combinat sage.modules + sage: JT #random # optional - sage.combinat sage.modules + Twosided Ideal (x^3, y^3, z^3 - 4*z) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JT.gens(), key=str) # optional - sage.combinat sage.modules [x^3, y^3, z^3 - 4*z] - sage: JT.std() #random - Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, x^2*z + 2*x^2, y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JT.std().gens(),key=str) - [2*x*y*z - z^2 - 2*z, x*y^2 - y*z, x*z^2 + 2*x*z, x^2*y - x*z - 2*x, x^2*z + 2*x^2, x^3, y*z^2 - 2*y*z, y^2*z - 2*y^2, y^3, z^3 - 4*z] - sage: JT.std() == JL.twostd() + sage: JT.std() #random # optional - sage.combinat sage.modules + Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, + y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, x^2*z + 2*x^2, + y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JT.std().gens(), key=str) # optional - sage.combinat sage.modules + [2*x*y*z - z^2 - 2*z, x*y^2 - y*z, x*z^2 + 2*x*z, x^2*y - x*z - 2*x, + x^2*z + 2*x^2, x^3, y*z^2 - 2*y*z, y^2*z - 2*y^2, y^3, z^3 - 4*z] + sage: JT.std() == JL.twostd() # optional - sage.combinat sage.modules True - ALGORITHM: Uses Singular's std command + ALGORITHM: Uses Singular's ``std`` command """ if self.side() == 'twosided': return self.twostd() @@ -3494,25 +3567,30 @@ def std(self): def elimination_ideal(self, variables): r""" Return the elimination ideal of this ideal with respect to the - variables given in "variables". + variables given in ``variables``. EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.elimination_ideal([x, z]) - Left Ideal (y^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: J = I.twostd() - sage: J - Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: J.elimination_ideal([x, z]) - Twosided Ideal (y^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - - - ALGORITHM: Uses Singular's eliminate command + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.elimination_ideal([x, z]) # optional - sage.combinat sage.modules + Left Ideal (y^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {...} + sage: J = I.twostd(); J # optional - sage.combinat sage.modules + Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {...} + sage: J.elimination_ideal([x, z]) # optional - sage.combinat sage.modules + Twosided Ideal (y^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {...} + + + ALGORITHM: Uses Singular's ``eliminate`` command """ from sage.misc.misc_c import prod if self.side() == 'twosided': @@ -3529,17 +3607,18 @@ def twostd(self): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.twostd() #random - Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field... - sage: sorted(I.twostd().gens(),key=str) + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.twostd() #random # optional - sage.combinat sage.modules + Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field... + sage: sorted(I.twostd().gens(), key=str) # optional - sage.combinat sage.modules [2*x*y - z - 1, x*z + x, x^2, y*z - y, y^2, z^2 - 1] - ALGORITHM: Uses Singular's twostd command + ALGORITHM: Uses Singular's ``twostd`` command """ return self.ring().ideal( self.__call_singular('twostd'), side='twosided') # return self.__call_singular('twostd') @@ -3555,13 +3634,13 @@ def _groebner_strategy(self): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H. = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I._groebner_strategy() #random + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H. = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: I = H.ideal([y^2, x^2, z^2-H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I._groebner_strategy() # random # optional - sage.combinat sage.modules Groebner Strategy for ideal generated by 6 elements over - Noncommutative Multivariate Polynomial Ring in x, y, z over Rational - Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} .. NOTE:: @@ -3577,31 +3656,29 @@ def reduce(self,p): It returns 0 if and only if the element is in this ideal. In any case, this reduction is unique up to monomial orders. - NOTE: - - There are left and two-sided ideals. Hence, - EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H. = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False, side='twosided') - sage: Q = H.quotient(I); Q #random - Quotient of Noncommutative Multivariate Polynomial Ring in x, y, z - over Rational Field, nc-relations: {z*x: x*z + 2*x, - z*y: y*z - 2*y, y*x: x*y - z} by the ideal (y^2, x^2, z^2 - 1) - sage: Q.2^2 == Q.one() # indirect doctest + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H. = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], # optional - sage.combinat sage.modules + ....: coerce=False, side='twosided') + sage: Q = H.quotient(I); Q #random # optional - sage.combinat sage.modules + Quotient of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + by the ideal (y^2, x^2, z^2 - 1) + sage: Q.2^2 == Q.one() # indirect doctest # optional - sage.combinat sage.modules True Here, we see that the relation that we just found in the quotient is actually a consequence of the given relations:: - sage: H.2^2-H.one() in I.std().gens() + sage: H.2^2 - H.one() in I.std().gens() # optional - sage.combinat sage.modules True Here is the corresponding direct test:: - sage: I.reduce(z^2) + sage: I.reduce(z^2) # optional - sage.combinat sage.modules 1 """ @@ -3613,21 +3690,26 @@ def _contains_(self,p): We define a left and a two-sided ideal:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H. = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) - sage: JL.std() #random - Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') - sage: JT.std() #random - Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, x^2*z + 2*x^2, y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H. = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) # optional - sage.combinat sage.modules + sage: JL.std() #random # optional - sage.combinat sage.modules + Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') # optional - sage.combinat sage.modules + sage: JT.std() #random # optional - sage.combinat sage.modules + Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, + x^2*z + 2*x^2, y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} Apparently, ``x*y^2-y*z`` should be in the two-sided, but not in the left ideal:: - sage: x*y^2-y*z in JL #indirect doctest + sage: x*y^2-y*z in JL #indirect doctest # optional - sage.combinat sage.modules False - sage: x*y^2-y*z in JT + sage: x*y^2-y*z in JT # optional - sage.combinat sage.modules True """ @@ -3647,12 +3729,12 @@ def syzygy_module(self): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: G = vector(I.gens()); G + sage: I = H.ideal([y^2, x^2, z^2-H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: G = vector(I.gens()); G # optional - sage.combinat sage.modules d...: UserWarning: You are constructing a free module over a noncommutative ring. Sage does not have a concept of left/right and both sided modules, so be careful. @@ -3664,7 +3746,7 @@ def syzygy_module(self): It's also not guaranteed that all multiplications are done from the right side. (y^2, x^2, z^2 - 1) - sage: M = I.syzygy_module(); M + sage: M = I.syzygy_module(); M # optional - sage.combinat sage.modules [ -z^2 - 8*z - 15 0 y^2] [ 0 -z^2 + 8*z - 15 x^2] [ x^2*z^2 + 8*x^2*z + 15*x^2 -y^2*z^2 + 8*y^2*z - 15*y^2 -4*x*y*z + 2*z^2 + 2*z] @@ -3675,10 +3757,10 @@ def syzygy_module(self): [ x^4*z + 4*x^4 -x^2*y^2*z + 4*x^2*y^2 - 4*x*y*z^2 + 32*x*y*z - 6*z^3 - 64*x*y + 66*z^2 - 240*z + 288 0] [x^3*y^2*z + 4*x^3*y^2 + 18*x^2*y*z - 36*x*z^3 + 66*x^2*y - 432*x*z^2 - 1656*x*z - 2052*x -x*y^4*z + 4*x*y^4 - 8*y^3*z^2 + 62*y^3*z - 114*y^3 48*y*z^2 - 36*y*z] - sage: M*G + sage: M*G # optional - sage.combinat sage.modules (0, 0, 0, 0, 0, 0, 0, 0, 0) - ALGORITHM: Uses Singular's syz command + ALGORITHM: Uses Singular's ``syz`` command """ if self.side() == 'twosided': warn("The result of this Syzygy computation is one-sided (left)!") @@ -3702,12 +3784,12 @@ def res(self, length): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.res(3) + sage: I = H.ideal([y^2, x^2, z^2-H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.res(3) # optional - sage.combinat sage.modules """ if self.side() == 'twosided': @@ -3730,15 +3812,15 @@ def __init__(self, ring, gens, coerce=True): - ``gens`` - a list of generators for the ideal - - ``coerce`` - coerce elements to the ring ``ring``? + - ``coerce`` - whether to coerce elements to the ring ``ring`` EXAMPLES:: sage: R. = PolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) Ideal (x, y) of Multivariate Polynomial Ring in x, y over Integer Ring - sage: R. = GF(3)[] - sage: R.ideal([x0^2, x1^3]) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: R.ideal([x0^2, x1^3]) # optional - sage.rings.finite_rings Ideal (x0^2, x1^3) of Multivariate Polynomial Ring in x0, x1 over Finite Field of size 3 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) @@ -3824,22 +3906,22 @@ def __richcmp__(self, other, op): :: - sage: R. = GF(32003)[] - sage: I = R*[x^2 + x, y] - sage: J = R*[x + 1, y] - sage: J < I + sage: R. = GF(32003)[] # optional - sage.rings.finite_rings + sage: I = R*[x^2 + x, y] # optional - sage.rings.finite_rings + sage: J = R*[x + 1, y] # optional - sage.rings.finite_rings + sage: J < I # optional - sage.rings.finite_rings False - sage: I < J + sage: I < J # optional - sage.rings.finite_rings True :: - sage: R. = GF(32003)[] - sage: I = R*[x^2 + x, y] - sage: J = R*[x + 1, y] - sage: J > I + sage: R. = GF(32003)[] # optional - sage.rings.finite_rings + sage: I = R*[x^2 + x, y] # optional - sage.rings.finite_rings + sage: J = R*[x + 1, y] # optional - sage.rings.finite_rings + sage: J > I # optional - sage.rings.finite_rings True - sage: I > J + sage: I > J # optional - sage.rings.finite_rings False :: @@ -3858,8 +3940,8 @@ def __richcmp__(self, other, op): :: sage: R. = QQ[] - sage: I = (x^3 + y, y)*R - sage: J = (x^3 + y, y, y*x^3 + y^2)*R + sage: I = (x^3 + y, y) * R + sage: J = (x^3 + y, y, y*x^3 + y^2) * R sage: I == J True @@ -3877,15 +3959,15 @@ def __richcmp__(self, other, op): We test to make sure that pickling works with the cached Groebner basis:: - sage: R. = GF(32003)[] - sage: I = R*[x^2 + x, y] - sage: J = R*[x + 1, y] - sage: J >= I + sage: R. = GF(32003)[] # optional - sage.rings.finite_rings + sage: I = R*[x^2 + x, y] # optional - sage.rings.finite_rings + sage: J = R*[x + 1, y] # optional - sage.rings.finite_rings + sage: J >= I # optional - sage.rings.finite_rings True - sage: I >= J + sage: I >= J # optional - sage.rings.finite_rings False - sage: loads(dumps(I)).__getstate__() + sage: loads(dumps(I)).__getstate__() # optional - sage.rings.finite_rings (Monoid of ideals of Multivariate Polynomial Ring in x, y over Finite Field of size 32003, {'_Ideal_generic__gens': (x^2 + x, y), '_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Finite Field of size 32003, @@ -4059,7 +4141,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal INPUT: - ``algorithm`` - determines the algorithm to use, see below - for available algorithms. + for available algorithms. - ``deg_bound`` - only compute to degree ``deg_bound``, that is, ignore all S-polynomials of higher degree. (default: @@ -4079,78 +4161,78 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal :func:`set_verbose`. - ``*args`` - additional parameters passed to the respective - implementations + implementations - ``**kwds`` - additional keyword parameters passed to the - respective implementations + respective implementations ALGORITHMS: - '' + ``''`` autoselect (default) - 'singular:groebner' + ``'singular:groebner'`` Singular's ``groebner`` command - 'singular:std' + ``'singular:std'`` Singular's ``std`` command - 'singular:stdhilb' + ``'singular:stdhilb'`` Singular's ``stdhib`` command - 'singular:stdfglm' + ``'singular:stdfglm'`` Singular's ``stdfglm`` command - 'singular:slimgb' + ``'singular:slimgb'`` Singular's ``slimgb`` command - 'libsingular:groebner' + ``'libsingular:groebner'`` libSingular's ``groebner`` command - 'libsingular:std' + ``'libsingular:std'`` libSingular's ``std`` command - 'libsingular:slimgb' + ``'libsingular:slimgb'`` libSingular's ``slimgb`` command - 'libsingular:stdhilb' + ``'libsingular:stdhilb'`` libSingular's ``stdhib`` command - 'libsingular:stdfglm' + ``'libsingular:stdfglm'`` libSingular's ``stdfglm`` command - 'toy:buchberger' + ``'toy:buchberger'`` Sage's toy/educational buchberger without Buchberger criteria - 'toy:buchberger2' + ``'toy:buchberger2'`` Sage's toy/educational buchberger with Buchberger criteria - 'toy:d_basis' + ``'toy:d_basis'`` Sage's toy/educational algorithm for computation over PIDs - 'macaulay2:gb' + ``'macaulay2:gb'`` Macaulay2's ``gb`` command (if available) - 'macaulay2:f4' + ``'macaulay2:f4'`` Macaulay2's ``GroebnerBasis`` command with the strategy "F4" (if available) - 'macaulay2:mgb' + ``'macaulay2:mgb'`` Macaulay2's ``GroebnerBasis`` command with the strategy "MGB" (if available) - 'msolve' + ``'msolve'`` `optional package msolve <../spkg/msolve.html>`_ (degrevlex order, prime fields) - 'magma:GroebnerBasis' + ``'magma:GroebnerBasis'`` Magma's ``Groebnerbasis`` command (if available) - 'ginv:TQ', 'ginv:TQBlockHigh', 'ginv:TQBlockLow' and 'ginv:TQDegree' + ``'ginv:TQ'``, ``'ginv:TQBlockHigh'``, ``'ginv:TQBlockLow'`` and ``'ginv:TQDegree'`` One of GINV's implementations (if available) - 'giac:gbasis' + ``'giac:gbasis'`` Giac's ``gbasis`` command (if available) - If only a system is given - e.g. 'magma' - the default algorithm is + If only a system is given - e.g. ``'magma`` - the default algorithm is chosen for that system. .. NOTE:: @@ -4158,7 +4240,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal The Singular and libSingular versions of the respective algorithms are identical, but the former calls an external Singular process while the latter calls a C function, - i.e. the calling overhead is smaller. However, the + and thus the calling overhead is smaller. However, the libSingular interface does not support pretty printing of computation protocols. @@ -4222,9 +4304,9 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Giac's gbasis over `\QQ` can benefit from a probabilistic lifting and multi threaded operations:: - sage: A9=PolynomialRing(QQ,9,'x') - sage: I9=sage.rings.ideal.Katsura(A9) - sage: print("possible output from giac", flush=True); I9.groebner_basis("giac",proba_epsilon=1e-7) # long time (3s) + sage: A9 = PolynomialRing(QQ, 9, 'x') + sage: I9 = sage.rings.ideal.Katsura(A9) + sage: print("possible output from giac", flush=True); I9.groebner_basis("giac", proba_epsilon=1e-7) # long time (3s) possible output... Polynomial Sequence with 143 Polynomials in 9 Variables @@ -4251,41 +4333,41 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Here we use Macaulay2 with three different strategies over a finite field. :: - sage: R. = PolynomialRing(GF(101), 3) - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 + sage: R. = PolynomialRing(GF(101), 3) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.rings.finite_rings [c^3 + 28*c^2 - 37*b + 13*c, b^2 - 41*c^2 + 20*b - 20*c, b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:f4') # optional - macaulay2 + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('macaulay2:f4') # optional - macaulay2 # optional - sage.rings.finite_rings [c^3 + 28*c^2 - 37*b + 13*c, b^2 - 41*c^2 + 20*b - 20*c, b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:mgb') # optional - macaulay2 + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('macaulay2:mgb') # optional - macaulay2 # optional - sage.rings.finite_rings [c^3 + 28*c^2 - 37*b + 13*c, b^2 - 41*c^2 + 20*b - 20*c, b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] Over prime fields of small characteristic, we can also use the `optional package msolve <../spkg/msolve.html>`_:: - sage: R. = PolynomialRing(GF(101), 3) - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('msolve') # optional - msolve + sage: R. = PolynomialRing(GF(101), 3) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('msolve') # optional - msolve # optional - sage.rings.finite_rings [a + 2*b + 2*c - 1, b*c - 19*c^2 + 10*b + 40*c, b^2 - 41*c^2 + 20*b - 20*c, c^3 + 28*c^2 - 37*b + 13*c] :: - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma # optional - sage.rings.finite_rings [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c] Singular and libSingular can compute Groebner basis with degree restrictions. :: sage: R. = QQ[] - sage: I = R*[x^3+y^2,x^2*y+1] + sage: I = R*[x^3 + y^2, x^2*y + 1] sage: I.groebner_basis(algorithm='singular') [x^3 + y^2, x^2*y + 1, y^3 - x] - sage: I.groebner_basis(algorithm='singular',deg_bound=2) + sage: I.groebner_basis(algorithm='singular', deg_bound=2) [x^3 + y^2, x^2*y + 1] sage: I.groebner_basis() [x^3 + y^2, x^2*y + 1, y^3 - x] @@ -4367,7 +4449,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Sage also supports local orderings:: - sage: P. = PolynomialRing(QQ,3,order='negdegrevlex') + sage: P. = PolynomialRing(QQ, 3, order='negdegrevlex') sage: I = P * ( x*y*z + z^5, 2*x^2 + y^3 + z^7, 3*z^5 +y ^5 ) sage: I.groebner_basis() [x^2 + 1/2*y^3, x*y*z + z^5, y^5 + 3*z^5, y^4*z - 2*x*z^5, z^6] @@ -4375,7 +4457,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal We can represent every element in the ideal as a combination of the generators using the :meth:`~sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict.lift` method:: - sage: P. = PolynomialRing(QQ,3) + sage: P. = PolynomialRing(QQ, 3) sage: I = P * ( x*y*z + z^5, 2*x^2 + y^3 + z^7, 3*z^5 +y ^5 ) sage: J = Ideal(I.groebner_basis()) sage: f = sum(P.random_element(terms=2)*f for f in I.gens()) @@ -4448,54 +4530,54 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Check that this method works over QQbar (:trac:`25351`):: - sage: P. = PolynomialRing(QQbar,3, order='lex') - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis() + sage: P. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis() # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:groebner') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:groebner') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:std') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:std') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:stdhilb') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:stdhilb') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:stdfglm') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:stdfglm') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:slimgb') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:slimgb') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: J = I.change_ring(P.change_ring(order='degrevlex')) - sage: gb = J.groebner_basis('giac') # random - sage: gb + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: J = I.change_ring(P.change_ring(order='degrevlex')) # optional - sage.rings.number_field + sage: gb = J.groebner_basis('giac') # random # optional - sage.rings.number_field + sage: gb # optional - sage.rings.number_field [c^3 + (-79/210)*c^2 + 1/30*b + 1/70*c, b^2 + (-3/5)*c^2 + (-1/5)*b + 1/5*c, b*c + 6/5*c^2 + (-1/10)*b + (-2/5)*c, a + 2*b + 2*c - 1] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('toy:buchberger2') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('toy:buchberger2') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] msolve currently supports the degrevlex order only:: - sage: R. = PolynomialRing(GF(101), 3, order='lex') - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('msolve') # optional - msolve + sage: R. = PolynomialRing(GF(101), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('msolve') # optional - msolve # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: msolve only supports the degrevlex order (use transformed_basis()) @@ -4717,27 +4799,32 @@ def subs(self, in_dict=None, **kwds): OUTPUT: A new ideal with modified generators. If possible, in the same - polynomial ring. Raises a ``TypeError`` if no common + polynomial ring. Raises a :class:`TypeError` if no common polynomial ring of the substituted generators can be found. EXAMPLES:: - sage: R. = PolynomialRing(ZZ,2,'xy') - sage: I = R.ideal(x^5+y^5, x^2 + y + x^2*y^2 + 5); I - Ideal (x^5 + y^5, x^2*y^2 + x^2 + y + 5) of Multivariate Polynomial Ring in x, y over Integer Ring + sage: R. = PolynomialRing(ZZ, 2, 'xy') + sage: I = R.ideal(x^5 + y^5, x^2 + y + x^2*y^2 + 5); I + Ideal (x^5 + y^5, x^2*y^2 + x^2 + y + 5) + of Multivariate Polynomial Ring in x, y over Integer Ring sage: I.subs(x=y) - Ideal (2*y^5, y^4 + y^2 + y + 5) of Multivariate Polynomial Ring in x, y over Integer Ring - sage: I.subs({x:y}) # same substitution but with dictionary - Ideal (2*y^5, y^4 + y^2 + y + 5) of Multivariate Polynomial Ring in x, y over Integer Ring + Ideal (2*y^5, y^4 + y^2 + y + 5) + of Multivariate Polynomial Ring in x, y over Integer Ring + sage: I.subs({x: y}) # same substitution but with dictionary + Ideal (2*y^5, y^4 + y^2 + y + 5) + of Multivariate Polynomial Ring in x, y over Integer Ring The new ideal can be in a different ring:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = PolynomialRing(QQ,2) - sage: I = R.ideal(a^2+b^2+a-b+2); I - Ideal (a^2 + b^2 + a - b + 2) of Multivariate Polynomial Ring in a, b over Rational Field + sage: R. = PolynomialRing(QQ, 2) + sage: S. = PolynomialRing(QQ, 2) + sage: I = R.ideal(a^2 + b^2 + a - b + 2); I + Ideal (a^2 + b^2 + a - b + 2) + of Multivariate Polynomial Ring in a, b over Rational Field sage: I.subs(a=x, b=y) - Ideal (x^2 + y^2 + x - y + 2) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x^2 + y^2 + x - y + 2) + of Multivariate Polynomial Ring in x, y over Rational Field The resulting ring need not be a multivariate polynomial ring:: @@ -4751,9 +4838,10 @@ def subs(self, in_dict=None, **kwds): Variables that are not substituted remain unchanged:: - sage: R. = PolynomialRing(QQ,2) - sage: I = R.ideal(x^2+y^2+x-y+2); I - Ideal (x^2 + y^2 + x - y + 2) of Multivariate Polynomial Ring in x, y over Rational Field + sage: R. = PolynomialRing(QQ, 2) + sage: I = R.ideal(x^2 + y^2 + x - y + 2); I + Ideal (x^2 + y^2 + x - y + 2) + of Multivariate Polynomial Ring in x, y over Rational Field sage: I.subs(x=1) Ideal (y^2 - y + 4) of Multivariate Polynomial Ring in x, y over Rational Field """ @@ -4775,7 +4863,7 @@ def reduce(self, f): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: I = (x^3 + y, y)*R + sage: I = (x^3 + y, y) * R sage: I.reduce(y) 0 sage: I.reduce(x^3) @@ -4783,7 +4871,7 @@ def reduce(self, f): sage: I.reduce(x - y) x - sage: I = (y^2 - (x^3 + x))*R + sage: I = (y^2 - (x^3 + x)) * R sage: I.reduce(x^3) y^2 - x sage: I.reduce(x^6) @@ -4813,7 +4901,7 @@ def _contains_(self, f): EXAMPLES:: sage: R. = QQ[] - sage: I = (x^3 + y, y)*R + sage: I = (x^3 + y, y) * R sage: x in I # indirect doctest False sage: y in I @@ -4842,28 +4930,28 @@ def homogenize(self, var='h'): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: I = Ideal([x^2*y + z + 1, x + y^2 + 1]); I + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: I = Ideal([x^2*y + z + 1, x + y^2 + 1]); I # optional - sage.rings.finite_rings Ideal (x^2*y + z + 1, y^2 + x + 1) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 :: - sage: I.homogenize() + sage: I.homogenize() # optional - sage.rings.finite_rings Ideal (x^2*y + z*h^2 + h^3, y^2 + x*h + h^2) of Multivariate Polynomial Ring in x, y, z, h over Finite Field of size 2 :: - sage: I.homogenize(y) + sage: I.homogenize(y) # optional - sage.rings.finite_rings Ideal (x^2*y + y^3 + y^2*z, x*y) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 :: - sage: I = Ideal([x^2*y + z^3 + y^2*x, x + y^2 + 1]) - sage: I.homogenize() + sage: I = Ideal([x^2*y + z^3 + y^2*x, x + y^2 + 1]) # optional - sage.rings.finite_rings + sage: I.homogenize() # optional - sage.rings.finite_rings Ideal (x^2*y + x*y^2 + z^3, y^2 + x*h + h^2) of Multivariate Polynomial Ring in x, y, z, h over Finite Field of size 2 @@ -4875,7 +4963,7 @@ def homogenize(self, var='h'): def is_homogeneous(self): r""" Return ``True`` if this ideal is spanned by homogeneous - polynomials, i.e. if it is a homogeneous ideal. + polynomials, i.e., if it is a homogeneous ideal. EXAMPLES:: @@ -4939,51 +5027,51 @@ def degree_of_semi_regularity(self): We consider a homogeneous example:: sage: n = 8 - sage: K = GF(127) - sage: P = PolynomialRing(K,n,'x') - sage: s = [K.random_element() for _ in range(n)] - sage: L = [] - sage: for i in range(2*n): - ....: f = P.random_element(degree=2, terms=binomial(n,2)) + sage: K = GF(127) # optional - sage.rings.finite_rings + sage: P = PolynomialRing(K, n, 'x') # optional - sage.rings.finite_rings + sage: s = [K.random_element() for _ in range(n)] # optional - sage.rings.finite_rings + sage: L = [] # optional - sage.rings.finite_rings + sage: for i in range(2 * n): # optional - sage.rings.finite_rings + ....: f = P.random_element(degree=2, terms=binomial(n, 2)) ....: f -= f(*s) ....: L.append(f.homogenize()) - sage: I = Ideal(L) - sage: I.degree_of_semi_regularity() + sage: I = Ideal(L) # optional - sage.rings.finite_rings + sage: I.degree_of_semi_regularity() # optional - sage.rings.finite_rings 4 From this, we expect a Groebner basis computation to reach at most degree 4. For homogeneous systems this is equivalent to the largest degree in the Groebner basis:: - sage: max(f.degree() for f in I.groebner_basis()) + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 4 We increase the number of polynomials and observe a decrease the degree of regularity:: - sage: for i in range(2*n): - ....: f = P.random_element(degree=2, terms=binomial(n,2)) + sage: for i in range(2 * n): # optional - sage.rings.finite_rings + ....: f = P.random_element(degree=2, terms=binomial(n, 2)) ....: f -= f(*s) ....: L.append(f.homogenize()) - sage: I = Ideal(L) - sage: I.degree_of_semi_regularity() + sage: I = Ideal(L) # optional - sage.rings.finite_rings + sage: I.degree_of_semi_regularity() # optional - sage.rings.finite_rings 3 - sage: max(f.degree() for f in I.groebner_basis()) + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 3 The degree of regularity approaches 2 for quadratic systems as the number of polynomials approaches `n^2`:: - sage: for i in range((n-4)*n): - ....: f = P.random_element(degree=2, terms=binomial(n,2)) + sage: for i in range((n-4) * n): # optional - sage.rings.finite_rings + ....: f = P.random_element(degree=2, terms=binomial(n, 2)) ....: f -= f(*s) ....: L.append(f.homogenize()) - sage: I = Ideal(L) - sage: I.degree_of_semi_regularity() + sage: I = Ideal(L) # optional - sage.rings.finite_rings + sage: I.degree_of_semi_regularity() # optional - sage.rings.finite_rings 2 - sage: max(f.degree() for f in I.groebner_basis()) + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 2 .. NOTE:: @@ -5018,59 +5106,59 @@ def plot(self, *args, **kwds): - ``self`` - a principal ideal in 2 variables - ``algorithm`` - set this to 'surf' if you want 'surf' to - plot the ideal (default: None) + plot the ideal (default: None) - ``*args`` - optional tuples ``(variable, minimum, maximum)`` - for plotting dimensions + for plotting dimensions - ``**kwds`` - optional keyword arguments passed on to - ``implicit_plot`` + ``implicit_plot`` EXAMPLES: Implicit plotting in 2-d:: - sage: R. = PolynomialRing(QQ,2) + sage: R. = PolynomialRing(QQ, 2) sage: I = R.ideal([y^3 - x^2]) - sage: I.plot() # cusp + sage: I.plot() # cusp # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2 - x^2 - 1]) - sage: I.plot((x,-3, 3), (y, -2, 2)) # hyperbola + sage: I.plot((x,-3, 3), (y, -2, 2)) # hyperbola # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2 + x^2*(1/4) - 1]) - sage: I.plot() # ellipse + sage: I.plot() # ellipse # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2-(x^2-1)*(x-2)]) - sage: I.plot() # elliptic curve + sage: I.plot() # elliptic curve # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: f = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2) sage: I = R.ideal(f) - sage: I.plot() # the Singular logo + sage: I.plot() # the Singular logo # optional - sage.plot Graphics object consisting of 1 graphics primitive :: - sage: R. = PolynomialRing(QQ,2) + sage: R. = PolynomialRing(QQ, 2) sage: I = R.ideal([x - 1]) - sage: I.plot((y, -2, 2)) # vertical line + sage: I.plot((y, -2, 2)) # vertical line # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([-x^2*y + 1]) - sage: I.plot() # blow up + sage: I.plot() # blow up # optional - sage.plot Graphics object consisting of 1 graphics primitive """ @@ -5149,12 +5237,12 @@ def random_element(self, degree, compute_gb=False, *args, **kwds): We compute a uniformly random element up to the provided degree. :: - sage: P. = GF(127)[] - sage: I = sage.rings.ideal.Katsura(P) - sage: f = I.random_element(degree=4, compute_gb=True, terms=infinity) - sage: f.degree() <= 4 + sage: P. = GF(127)[] # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: f = I.random_element(degree=4, compute_gb=True, terms=infinity) # optional - sage.rings.finite_rings + sage: f.degree() <= 4 # optional - sage.rings.finite_rings True - sage: len(list(f)) <= 35 + sage: len(list(f)) <= 35 # optional - sage.rings.finite_rings True Note that sampling uniformly at random from the ideal at some large enough degree is @@ -5162,42 +5250,45 @@ def random_element(self, degree, compute_gb=False, *args, **kwds): basis if we can sample uniformly at random from an ideal:: sage: n = 3; d = 4 - sage: P = PolynomialRing(GF(127), n, 'x') - sage: I = sage.rings.ideal.Cyclic(P) + sage: P = PolynomialRing(GF(127), n, 'x') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(P) # optional - sage.rings.finite_rings 1. We sample `n^d` uniformly random elements in the ideal:: - sage: F = Sequence(I.random_element(degree=d, compute_gb=True, terms=infinity) for _ in range(n^d)) + sage: F = Sequence(I.random_element(degree=d, compute_gb=True, # optional - sage.rings.finite_rings + ....: terms=infinity) + ....: for _ in range(n^d)) 2. We linearize and compute the echelon form:: - sage: A,v = F.coefficient_matrix() - sage: A.echelonize() + sage: A, v = F.coefficient_matrix() # optional - sage.rings.finite_rings + sage: A.echelonize() # optional - sage.rings.finite_rings 3. The result is the desired Gröbner basis:: - sage: G = Sequence((A*v).list()) - sage: G.is_groebner() - True - sage: Ideal(G) == I - True + sage: G = Sequence((A * v).list()) # optional - sage.rings.finite_rings + sage: G.is_groebner() # optional - sage.rings.finite_rings + True + sage: Ideal(G) == I # optional - sage.rings.finite_rings + True We return some element in the ideal with no guarantee on the distribution:: - sage: P = PolynomialRing(GF(127), 10, 'x') - sage: I = sage.rings.ideal.Katsura(P) - sage: f = I.random_element(degree=3) - sage: f # random + sage: P = PolynomialRing(GF(127), 10, 'x') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: f = I.random_element(degree=3) # optional - sage.rings.finite_rings + sage: f # random # optional - sage.rings.finite_rings -25*x0^2*x1 + 14*x1^3 + 57*x0*x1*x2 + ... + 19*x7*x9 + 40*x8*x9 + 49*x1 - sage: f.degree() + sage: f.degree() # optional - sage.rings.finite_rings 3 We show that the default method does not sample uniformly at random from the ideal:: - sage: P. = GF(127)[] - sage: G = Sequence([x+7, y-2, z+110]) - sage: I = Ideal([sum(P.random_element() * g for g in G) for _ in range(4)]) - sage: all(I.random_element(degree=1) == 0 for _ in range(100)) + sage: P. = GF(127)[] # optional - sage.rings.finite_rings + sage: G = Sequence([x + 7, y - 2, z + 110]) # optional - sage.rings.finite_rings + sage: I = Ideal([sum(P.random_element() * g for g in G) # optional - sage.rings.finite_rings + ....: for _ in range(4)]) + sage: all(I.random_element(degree=1) == 0 for _ in range(100)) # optional - sage.rings.finite_rings True If degree equals the degree of the generators a random linear @@ -5262,114 +5353,126 @@ def weil_restriction(self): EXAMPLES:: - sage: k. = GF(2^2) - sage: P. = PolynomialRing(k,2) - sage: I = Ideal([x*y + 1, a*x + 1]) - sage: I.variety() + sage: k. = GF(2^2) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: I = Ideal([x*y + 1, a*x + 1]) # optional - sage.rings.finite_rings + sage: I.variety() # optional - sage.rings.finite_rings [{y: a, x: a + 1}] - sage: J = I.weil_restriction() - sage: J + sage: J = I.weil_restriction() # optional - sage.rings.finite_rings + sage: J # optional - sage.rings.finite_rings Ideal (x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1) of - Multivariate Polynomial Ring in x0, x1, y0, y1 over Finite Field of size - 2 - sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal - sage: J.variety() + Multivariate Polynomial Ring in x0, x1, y0, y1 over Finite Field of size 2 + sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal # optional - sage.rings.finite_rings + sage: J.variety() # optional - sage.rings.finite_rings [{y1: 1, y0: 0, x1: 1, x0: 1}] - sage: J.weil_restriction() # returns J - Ideal (x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1, x0^2 + - x0, x1^2 + x1, y0^2 + y0, y1^2 + y1) of Multivariate Polynomial Ring in - x0, x1, y0, y1 over Finite Field of size 2 + sage: J.weil_restriction() # returns J # optional - sage.rings.finite_rings + Ideal (x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1, + x0^2 + x0, x1^2 + x1, y0^2 + y0, y1^2 + y1) of Multivariate + Polynomial Ring in x0, x1, y0, y1 over Finite Field of size 2 - sage: k. = GF(3^5) - sage: P. = PolynomialRing(k) - sage: I = sage.rings.ideal.Katsura(P) - sage: I.dimension() + sage: k. = GF(3^5) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings 0 - sage: I.variety() + sage: I.variety() # optional - sage.rings.finite_rings [{z: 0, y: 0, x: 1}] - sage: J = I.weil_restriction(); J - Ideal (x0 - y0 - z0 - 1, x1 - y1 - z1, x2 - y2 - z2, x3 - y3 - z3, x4 - - y4 - z4, x0^2 + x2*x3 + x1*x4 - y0^2 - y2*y3 - y1*y4 - z0^2 - z2*z3 - - z1*z4 - x0, -x0*x1 - x2*x3 - x3^2 - x1*x4 + x2*x4 + y0*y1 + y2*y3 + y3^2 - + y1*y4 - y2*y4 + z0*z1 + z2*z3 + z3^2 + z1*z4 - z2*z4 - x1, x1^2 - - x0*x2 + x3^2 - x2*x4 + x3*x4 - y1^2 + y0*y2 - y3^2 + y2*y4 - y3*y4 - - z1^2 + z0*z2 - z3^2 + z2*z4 - z3*z4 - x2, -x1*x2 - x0*x3 - x3*x4 - x4^2 - + y1*y2 + y0*y3 + y3*y4 + y4^2 + z1*z2 + z0*z3 + z3*z4 + z4^2 - x3, x2^2 - - x1*x3 - x0*x4 + x4^2 - y2^2 + y1*y3 + y0*y4 - y4^2 - z2^2 + z1*z3 + - z0*z4 - z4^2 - x4, -x0*y0 + x4*y1 + x3*y2 + x2*y3 + x1*y4 - y0*z0 + - y4*z1 + y3*z2 + y2*z3 + y1*z4 - y0, -x1*y0 - x0*y1 - x4*y1 - x3*y2 + - x4*y2 - x2*y3 + x3*y3 - x1*y4 + x2*y4 - y1*z0 - y0*z1 - y4*z1 - y3*z2 + - y4*z2 - y2*z3 + y3*z3 - y1*z4 + y2*z4 - y1, -x2*y0 - x1*y1 - x0*y2 - - x4*y2 - x3*y3 + x4*y3 - x2*y4 + x3*y4 - y2*z0 - y1*z1 - y0*z2 - y4*z2 - - y3*z3 + y4*z3 - y2*z4 + y3*z4 - y2, -x3*y0 - x2*y1 - x1*y2 - x0*y3 - - x4*y3 - x3*y4 + x4*y4 - y3*z0 - y2*z1 - y1*z2 - y0*z3 - y4*z3 - y3*z4 + - y4*z4 - y3, -x4*y0 - x3*y1 - x2*y2 - x1*y3 - x0*y4 - x4*y4 - y4*z0 - - y3*z1 - y2*z2 - y1*z3 - y0*z4 - y4*z4 - y4) of Multivariate Polynomial - Ring in x0, x1, x2, x3, x4, y0, y1, y2, y3, y4, z0, z1, z2, z3, z4 over - Finite Field of size 3 - sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal + sage: J = I.weil_restriction(); J # optional - sage.rings.finite_rings + Ideal (x0 - y0 - z0 - 1, + x1 - y1 - z1, x2 - y2 - z2, x3 - y3 - z3, x4 - y4 - z4, + x0^2 + x2*x3 + x1*x4 - y0^2 - y2*y3 - y1*y4 - z0^2 - z2*z3 - z1*z4 - x0, + -x0*x1 - x2*x3 - x3^2 - x1*x4 + x2*x4 + y0*y1 + y2*y3 + + y3^2 + y1*y4 - y2*y4 + z0*z1 + z2*z3 + z3^2 + z1*z4 - z2*z4 - x1, + x1^2 - x0*x2 + x3^2 - x2*x4 + x3*x4 - y1^2 + y0*y2 + - y3^2 + y2*y4 - y3*y4 - z1^2 + z0*z2 - z3^2 + z2*z4 - z3*z4 - x2, + -x1*x2 - x0*x3 - x3*x4 - x4^2 + + y1*y2 + y0*y3 + y3*y4 + y4^2 + z1*z2 + z0*z3 + z3*z4 + z4^2 - x3, + x2^2 - x1*x3 - x0*x4 + x4^2 - y2^2 + + y1*y3 + y0*y4 - y4^2 - z2^2 + z1*z3 + z0*z4 - z4^2 - x4, + -x0*y0 + x4*y1 + x3*y2 + x2*y3 + + x1*y4 - y0*z0 + y4*z1 + y3*z2 + y2*z3 + y1*z4 - y0, + -x1*y0 - x0*y1 - x4*y1 - x3*y2 + x4*y2 - x2*y3 + x3*y3 + - x1*y4 + x2*y4 - y1*z0 - y0*z1 - y4*z1 - y3*z2 + + y4*z2 - y2*z3 + y3*z3 - y1*z4 + y2*z4 - y1, + -x2*y0 - x1*y1 - x0*y2 - x4*y2 - x3*y3 + x4*y3 - x2*y4 + x3*y4 + - y2*z0 - y1*z1 - y0*z2 - y4*z2 - y3*z3 + y4*z3 - y2*z4 + y3*z4 - y2, + -x3*y0 - x2*y1 - x1*y2 - x0*y3 - x4*y3 - x3*y4 + x4*y4 + - y3*z0 - y2*z1 - y1*z2 - y0*z3 - y4*z3 - y3*z4 + y4*z4 - y3, + -x4*y0 - x3*y1 - x2*y2 - x1*y3 - x0*y4 - x4*y4 + - y4*z0 - y3*z1 - y2*z2 - y1*z3 - y0*z4 - y4*z4 - y4) + of Multivariate Polynomial Ring in x0, x1, x2, x3, x4, y0, y1, y2, y3, y4, + z0, z1, z2, z3, z4 over Finite Field of size 3 + sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal # optional - sage.rings.finite_rings sage: from sage.doctest.fixtures import reproducible_repr - sage: print(reproducible_repr(J.variety())) - [{x0: 1, x1: 0, x2: 0, x3: 0, x4: 0, y0: 0, y1: 0, y2: 0, y3: 0, y4: 0, z0: 0, z1: 0, z2: 0, z3: 0, z4: 0}] + sage: print(reproducible_repr(J.variety())) # optional - sage.rings.finite_rings + [{x0: 1, x1: 0, x2: 0, x3: 0, x4: 0, + y0: 0, y1: 0, y2: 0, y3: 0, y4: 0, + z0: 0, z1: 0, z2: 0, z3: 0, z4: 0}] Weil restrictions are often used to study elliptic curves over extension fields so we give a simple example involving those:: - sage: K. = QuadraticField(1/3) - sage: E = EllipticCurve(K,[1,2,3,4,5]) + sage: K. = QuadraticField(1/3) # optional - sage.rings.number_field + sage: E = EllipticCurve(K, [1,2,3,4,5]) # optional - sage.rings.number_field We pick a point on ``E``:: - sage: p = E.lift_x(1); p + sage: p = E.lift_x(1); p # optional - sage.rings.number_field (1 : 2 : 1) - sage: I = E.defining_ideal(); I - Ideal (-x^3 - 2*x^2*z + x*y*z + y^2*z - 4*x*z^2 + 3*y*z^2 - 5*z^3) of Multivariate Polynomial Ring in x, y, z over Number Field in a with defining polynomial x^2 - 1/3 with a = 0.5773502691896258? + sage: I = E.defining_ideal(); I # optional - sage.rings.number_field + Ideal (-x^3 - 2*x^2*z + x*y*z + y^2*z - 4*x*z^2 + 3*y*z^2 - 5*z^3) + of Multivariate Polynomial Ring in x, y, z + over Number Field in a with defining polynomial x^2 - 1/3 + with a = 0.5773502691896258? Of course, the point ``p`` is a root of all generators of ``I``:: - sage: I.subs(x=1,y=2,z=1) - Ideal (0) of Multivariate Polynomial Ring in x, y, z over Number Field in a with defining polynomial x^2 - 1/3 with a = 0.5773502691896258? + sage: I.subs(x=1, y=2, z=1) # optional - sage.rings.number_field + Ideal (0) of Multivariate Polynomial Ring in x, y, z + over Number Field in a with defining polynomial x^2 - 1/3 + with a = 0.5773502691896258? ``I`` is also radical:: - sage: I.radical() == I + sage: I.radical() == I # optional - sage.rings.number_field True So we compute its Weil restriction:: - sage: J = I.weil_restriction() - sage: J - Ideal (-x0^3 - x0*x1^2 - 2*x0^2*z0 - 2/3*x1^2*z0 + x0*y0*z0 + y0^2*z0 + - 1/3*x1*y1*z0 + 1/3*y1^2*z0 - 4*x0*z0^2 + 3*y0*z0^2 - 5*z0^3 - - 4/3*x0*x1*z1 + 1/3*x1*y0*z1 + 1/3*x0*y1*z1 + 2/3*y0*y1*z1 - 8/3*x1*z0*z1 - + 2*y1*z0*z1 - 4/3*x0*z1^2 + y0*z1^2 - 5*z0*z1^2, -3*x0^2*x1 - 1/3*x1^3 - - 4*x0*x1*z0 + x1*y0*z0 + x0*y1*z0 + 2*y0*y1*z0 - 4*x1*z0^2 + 3*y1*z0^2 - - 2*x0^2*z1 - 2/3*x1^2*z1 + x0*y0*z1 + y0^2*z1 + 1/3*x1*y1*z1 + - 1/3*y1^2*z1 - 8*x0*z0*z1 + 6*y0*z0*z1 - 15*z0^2*z1 - 4/3*x1*z1^2 + - y1*z1^2 - 5/3*z1^3) of Multivariate Polynomial Ring in x0, x1, y0, y1, - z0, z1 over Rational Field + sage: J = I.weil_restriction() # optional - sage.rings.number_field + sage: J # optional - sage.rings.number_field + Ideal (-x0^3 - x0*x1^2 - 2*x0^2*z0 - 2/3*x1^2*z0 + x0*y0*z0 + y0^2*z0 + + 1/3*x1*y1*z0 + 1/3*y1^2*z0 - 4*x0*z0^2 + 3*y0*z0^2 - 5*z0^3 + - 4/3*x0*x1*z1 + 1/3*x1*y0*z1 + 1/3*x0*y1*z1 + 2/3*y0*y1*z1 + - 8/3*x1*z0*z1 + 2*y1*z0*z1 - 4/3*x0*z1^2 + y0*z1^2 - 5*z0*z1^2, + -3*x0^2*x1 - 1/3*x1^3 - 4*x0*x1*z0 + x1*y0*z0 + x0*y1*z0 + + 2*y0*y1*z0 - 4*x1*z0^2 + 3*y1*z0^2 - 2*x0^2*z1 - 2/3*x1^2*z1 + + x0*y0*z1 + y0^2*z1 + 1/3*x1*y1*z1 + 1/3*y1^2*z1 - 8*x0*z0*z1 + + 6*y0*z0*z1 - 15*z0^2*z1 - 4/3*x1*z1^2 + y1*z1^2 - 5/3*z1^3) + of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 over Rational Field We can check that the point ``p`` is still a root of all generators of ``J``:: - sage: J.subs(x0=1,y0=2,z0=1,x1=0,y1=0,z1=0) - Ideal (0, 0) of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 over Rational Field + sage: J.subs(x0=1, y0=2, z0=1, x1=0, y1=0, z1=0) # optional - sage.rings.number_field + Ideal (0, 0) of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 + over Rational Field Example for relative number fields:: sage: R. = QQ[] - sage: K. = NumberField(x^5-2) - sage: R. = K[] - sage: L. = K.extension(x^2+1) - sage: S. = L[] - sage: I = S.ideal([y^2-x^3-1]) - sage: I.weil_restriction() - Ideal (-x0^3 + 3*x0*x1^2 + y0^2 - y1^2 - 1, -3*x0^2*x1 + x1^3 + 2*y0*y1) - of Multivariate Polynomial Ring in x0, x1, y0, y1 over Number Field in w - with defining polynomial x^5 - 2 + sage: K. = NumberField(x^5 - 2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: L. = K.extension(x^2 + 1) # optional - sage.rings.number_field + sage: S. = L[] # optional - sage.rings.number_field + sage: I = S.ideal([y^2 - x^3 - 1]) # optional - sage.rings.number_field + sage: I.weil_restriction() # optional - sage.rings.number_field + Ideal (-x0^3 + 3*x0*x1^2 + y0^2 - y1^2 - 1, -3*x0^2*x1 + x1^3 + 2*y0*y1) of + Multivariate Polynomial Ring in x0, x1, y0, y1 + over Number Field in w with defining polynomial x^5 - 2 .. NOTE:: @@ -5442,8 +5545,9 @@ class MPolynomialIdeal_quotient(MPolynomialIdeal): sage: Q. = QQ['x,y,z,w'].quotient(['x*y-z^2', 'y^2-w^2']) sage: I = ideal(x + y^2 + z - 1) sage: I - Ideal (w^2 + x + z - 1) of Quotient of Multivariate Polynomial Ring - in x, y, z, w over Rational Field by the ideal (x*y - z^2, y^2 - w^2) + Ideal (w^2 + x + z - 1) of Quotient + of Multivariate Polynomial Ring in x, y, z, w over Rational Field + by the ideal (x*y - z^2, y^2 - w^2) """ def reduce(self, f): r""" @@ -5454,9 +5558,9 @@ def reduce(self, f): EXAMPLES:: sage: R. = PolynomialRing(QQ, order='lex') - sage: I = R.ideal([T^2+U^2-1, V^2+W^2-1, X^2+Y^2+Z^2-1]) + sage: I = R.ideal([T^2 + U^2 - 1, V^2 + W^2 - 1, X^2 + Y^2 + Z^2 - 1]) sage: Q. = R.quotient(I) - sage: J = Q.ideal([u*v-x, u*w-y, t-z]) + sage: J = Q.ideal([u*v - x, u*w - y, t - z]) sage: J.reduce(t^2 - z^2) 0 sage: J.reduce(u^2) diff --git a/src/sage/rings/polynomial/multi_polynomial_ring.py b/src/sage/rings/polynomial/multi_polynomial_ring.py index 239737eb500..da8aaf0545f 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring.py +++ b/src/sage/rings/polynomial/multi_polynomial_ring.py @@ -27,13 +27,13 @@ We construct the Frobenius morphism on `\GF{5}[x,y,z]` over `\GF{5}`:: - sage: R. = GF(5)[] - sage: frob = R.hom([x^5, y^5, z^5]) - sage: frob(x^2 + 2*y - z^4) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: frob = R.hom([x^5, y^5, z^5]) # optional - sage.rings.finite_rings + sage: frob(x^2 + 2*y - z^4) # optional - sage.rings.finite_rings -z^20 + x^10 + 2*y^5 - sage: frob((x + 2*y)^3) + sage: frob((x + 2*y)^3) # optional - sage.rings.finite_rings x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15 - sage: (x^5 + 2*y^5)^3 + sage: (x^5 + 2*y^5)^3 # optional - sage.rings.finite_rings x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15 We make a polynomial ring in one variable over a polynomial ring in @@ -46,7 +46,7 @@ TESTS:: - sage: PolynomialRing(GF(5), 3, 'xyz').objgens() + sage: PolynomialRing(GF(5), 3, 'xyz').objgens() # optional - sage.rings.finite_rings (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5, (x, y, z)) """ @@ -203,7 +203,7 @@ def __call__(self, x=0, check=True): sage: R. = QQ[] sage: S. = ZZ[] - sage: T. = GF(7)[] + sage: T. = GF(7)[] # optional - sage.rings.finite_rings We convert from integer polynomials to rational polynomials, and back:: @@ -219,9 +219,9 @@ def __call__(self, x=0, check=True): :: - sage: f = R(T.0^2 - 4*T.1^3); f + sage: f = R(T.0^2 - 4*T.1^3); f # optional - sage.rings.finite_rings 3*y^3 + x^2 - sage: parent(f) + sage: parent(f) # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y over Rational Field We dump and load the polynomial ring S:: @@ -241,24 +241,24 @@ def __call__(self, x=0, check=True): variable names:: sage: R. = PolynomialRing(QQ,2) - sage: S. = PolynomialRing(GF(7),2) + sage: S. = PolynomialRing(GF(7),2) # optional - sage.rings.finite_rings sage: f = x^2 + 2/3*y^3 - sage: S(f) + sage: S(f) # optional - sage.rings.finite_rings 3*b^3 + a^2 Conversion from symbolic variables:: - sage: x,y,z = var('x,y,z') - sage: R = QQ['x,y,z'] - sage: type(x) + sage: x,y,z = var('x,y,z') # optional - sage.symbolic + sage: R = QQ['x,y,z'] # optional - sage.symbolic + sage: type(x) # optional - sage.symbolic - sage: type(R(x)) + sage: type(R(x)) # optional - sage.symbolic - sage: f = R(x^3 + y^3 - z^3); f + sage: f = R(x^3 + y^3 - z^3); f # optional - sage.symbolic x^3 + y^3 - z^3 - sage: type(f) + sage: type(f) # optional - sage.symbolic - sage: parent(f) + sage: parent(f) # optional - sage.symbolic Multivariate Polynomial Ring in x, y, z over Rational Field A more complicated symbolic and computational mix. Behind the @@ -267,11 +267,11 @@ def __call__(self, x=0, check=True): :: sage: R = QQ['x,y,z'] - sage: f = (x^3 + y^3 - z^3)^10; f + sage: f = (x^3 + y^3 - z^3)^10; f # optional - sage.symbolic (x^3 + y^3 - z^3)^10 - sage: g = R(f); parent(g) + sage: g = R(f); parent(g) # optional - sage.symbolic Multivariate Polynomial Ring in x, y, z over Rational Field - sage: (f - g).expand() + sage: (f - g).expand() # optional - sage.symbolic 0 It intelligently handles conversions from polynomial rings in a subset @@ -279,12 +279,12 @@ def __call__(self, x=0, check=True): :: - sage: R = GF(5)['x,y,z'] + sage: R = GF(5)['x,y,z'] # optional - sage.rings.finite_rings sage: S = ZZ['y'] - sage: R(7*S.0) + sage: R(7*S.0) # optional - sage.rings.finite_rings 2*y sage: T = ZZ['x,z'] - sage: R(2*T.0 + 6*T.1 + T.0*T.1^2) + sage: R(2*T.0 + 6*T.1 + T.0*T.1^2) # optional - sage.rings.finite_rings x*z^2 + 2*x + z :: diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index 70e1e7c861b..ce12783d73b 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -74,10 +74,10 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): Check that :trac:`26958` is fixed:: - sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular - sage: class Foo(MPolynomialRing_libsingular): + sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular # optional - sage.libs.singular + sage: class Foo(MPolynomialRing_libsingular): # optional - sage.libs.singular ....: pass - sage: Foo(QQ, 2, ['x','y'], 'degrevlex') + sage: Foo(QQ, 2, ['x','y'], 'degrevlex') # optional - sage.libs.singular Multivariate Polynomial Ring in x, y over Rational Field """ if base_ring not in _CommutativeRings: @@ -133,14 +133,13 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: QQ['a','b']['x','y'].flattening_morphism() Flattening morphism: - From: Multivariate Polynomial Ring in x, y over Multivariate - Polynomial Ring in a, b over Rational Field - To: Multivariate Polynomial Ring in a, b, x, y over Rational - Field + From: Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Rational Field + To: Multivariate Polynomial Ring in a, b, x, y over Rational Field sage: QQ['x,y'].flattening_morphism() - Identity endomorphism of Multivariate Polynomial Ring in x, y - over Rational Field + Identity endomorphism of + Multivariate Polynomial Ring in x, y over Rational Field """ base = self.base_ring() if is_MPolynomialRing(base) or polynomial_ring.is_PolynomialRing(base): @@ -151,7 +150,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def construction(self): """ - Returns a functor F and base ring R such that F(R) == self. + Returns a functor ``F`` and base ring ``R`` such that ``F(R) == self``. EXAMPLES:: @@ -238,7 +237,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: P. = PolynomialRing(ZZ) sage: P.completion([]) is P True - sage: P.completion(SR.var('x')) + sage: P.completion(SR.var('x')) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: x is not an element of Multivariate Polynomial Ring @@ -284,7 +283,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def remove_var(self, *var, order=None): """ - Remove a variable or sequence of variables from self. + Remove a variable or sequence of variables from ``self``. If ``order`` is not specified, then the subring inherits the term order of the original ring, if possible. @@ -294,14 +293,14 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: P. = PolynomialRing(ZZ) sage: P.remove_var(z) Multivariate Polynomial Ring in x, y, w over Integer Ring - sage: P.remove_var(z,x) + sage: P.remove_var(z, x) Multivariate Polynomial Ring in y, w over Integer Ring - sage: P.remove_var(y,z,x) + sage: P.remove_var(y, z, x) Univariate Polynomial Ring in w over Integer Ring Removing all variables results in the base ring:: - sage: P.remove_var(y,z,x,w) + sage: P.remove_var(y, z, x, w) Integer Ring If possible, the term order is kept:: @@ -317,7 +316,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): Be careful with block orders when removing variables:: sage: R. = PolynomialRing(ZZ, order='deglex(2),lex(3)') - sage: R.remove_var(x,y,z) + sage: R.remove_var(x, y, z) Traceback (most recent call last): ... ValueError: impossible to use the original term order (most @@ -345,18 +344,18 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def univariate_ring(self, x): """ Return a univariate polynomial ring whose base ring comprises all - but one variables of self. + but one variables of ``self``. INPUT: - - ``x`` -- a variable of self. + - ``x`` -- a variable of ``self``. EXAMPLES:: sage: P. = QQ[] sage: P.univariate_ring(y) - Univariate Polynomial Ring in y over Multivariate Polynomial - Ring in x, z over Rational Field + Univariate Polynomial Ring in y + over Multivariate Polynomial Ring in x, z over Rational Field """ return self.remove_var(x)[str(x)] @@ -368,9 +367,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): This function can be called in two ways: - 1. interpolation(bound, points, values) + 1. ``interpolation(bound, points, values)`` - 2. interpolation(bound, function) + 2. ``interpolation(bound, function)`` INPUT: @@ -399,18 +398,16 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): ....: return a^3*b + b + c^2 + 25 ....: sage: R. = PolynomialRing(QQ) - sage: R.interpolation(4, F) + sage: R.interpolation(4, F) # optional - sage.modules x^3*y + z^2 + y + 25 - sage: def F(a,b,c): ....: return a^3*b + b + c^2 + 25 ....: sage: R. = PolynomialRing(QQ) - sage: R.interpolation([3,1,2], F) + sage: R.interpolation([3,1,2], F) # optional - sage.modules x^3*y + z^2 + y + 25 - sage: def F(a,b,c): ....: return a^3*b + b + c^2 + 25 ....: @@ -419,7 +416,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): ....: (2,7,0),(1,10,13),(0,0,1),(-1,1,0),(2,5,3),(1,1,1),(7,4,11), ....: (12,1,9),(1,1,3),(4,-1,2),(0,1,5),(5,1,3),(3,1,-2),(2,11,3), ....: (4,12,19),(3,1,1),(5,2,-3),(12,1,1),(2,3,4)] - sage: R.interpolation([3,1,2], points, [F(*x) for x in points]) + sage: R.interpolation([3,1,2], points, [F(*x) for x in points]) # optional - sage.modules x^3*y + z^2 + y + 25 ALGORITHM: @@ -438,7 +435,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): without any notice that there are more. Lastly, the interpolation function for univariate polynomial rings - is called ``lagrange_polynomial()``. + is called :meth:`lagrange_polynomial`. .. WARNING:: @@ -447,14 +444,14 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): the given bounds. In particular it will *not* notice or check whether the result yields the correct evaluation for other points as well. So if you give wrong bounds, you will get a wrong answer - without any warning. + without any warning. :: - sage: def F(a,b,c): - ....: return a^3*b + b + c^2 + 25 - ....: - sage: R. = PolynomialRing(QQ) - sage: R.interpolation(3,F) - 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25 + sage: def F(a,b,c): + ....: return a^3*b + b + c^2 + 25 + ....: + sage: R. = PolynomialRing(QQ) + sage: R.interpolation(3, F) # optional - sage.modules + 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25 .. SEEALSO:: @@ -583,13 +580,13 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): implicitly calling ``_coerce_c_impl``:: sage: z = polygen(QQ, 'z') - sage: W.=NumberField(z^2+1) - sage: Q. = W[] - sage: W1 = FractionField (Q) - sage: S. = W1[] - sage: u + x + sage: W. = NumberField(z^2 + 1) # optional - sage.rings.number_field + sage: Q. = W[] # optional - sage.rings.number_field + sage: W1 = FractionField(Q) # optional - sage.rings.number_field + sage: S. = W1[] # optional - sage.rings.number_field + sage: u + x # optional - sage.rings.number_field x + u - sage: x + 1/u + sage: x + 1/u # optional - sage.rings.number_field x + 1/u """ try: @@ -679,7 +676,8 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: P. = PolynomialRing(QQ,order=TermOrder('degrevlex',1)+TermOrder('lex',2)) + sage: P. = PolynomialRing(QQ, order=TermOrder('degrevlex',1) + ....: + TermOrder('lex',2)) sage: print(P.repr_long()) Polynomial Ring Base Ring : Rational Field @@ -718,12 +716,12 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: R. = K[] - sage: Q5 = Qp(5); i5 = Q5(-1).sqrt() - sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()]) # no coercion + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: Q5 = Qp(5); i5 = Q5(-1).sqrt() # optional - sage.rings.number_field + sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()]) # no coercion # optional - sage.rings.number_field False - sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()], base_map=K.hom([i5])) + sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()], base_map=K.hom([i5])) # optional - sage.rings.number_field True """ if base_map is None: @@ -740,33 +738,33 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: R._magma_init_(magma) # optional - magma + sage: R. = PolynomialRing(GF(127),10) # optional - sage.rings.finite_rings + sage: R._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings 'SageCreateWithNames(PolynomialRing(_sage_ref...,10,"grevlex"),["a","b","c","d","e","f","g","h","i","j"])' - sage: R. = PolynomialRing(QQ,3) - sage: magma(R) # optional - magma + sage: R. = PolynomialRing(QQ, 3) # optional - sage.rings.finite_rings + sage: magma(R) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 3 over Rational Field Order: Graded Reverse Lexicographical Variables: y, z, w A complicated nested example:: - sage: R. = PolynomialRing(GF(9,'a')); S. = R[]; S + sage: R. = PolynomialRing(GF(9,'a')); S. = R[]; S # optional - sage.rings.finite_rings Multivariate Polynomial Ring in T, W over Multivariate Polynomial Ring in a, b, c over Finite Field in a of size 3^2 - sage: magma(S) # optional - magma + sage: magma(S) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 2 over Polynomial ring of rank 3 over GF(3^2) Order: Graded Reverse Lexicographical Variables: T, W - sage: magma(PolynomialRing(GF(7),4, 'x')) # optional - magma + sage: magma(PolynomialRing(GF(7),4, 'x')) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 4 over GF(7) Order: Graded Reverse Lexicographical Variables: x0, x1, x2, x3 - sage: magma(PolynomialRing(GF(49,'a'),10, 'x')) # optional - magma + sage: magma(PolynomialRing(GF(49,'a'),10, 'x')) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 10 over GF(7^2) Order: Graded Reverse Lexicographical Variables: x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 @@ -800,11 +798,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: F = CyclotomicField(8) - sage: P. = F[] - sage: gap(P) # indirect doctest + sage: F = CyclotomicField(8) # optional - sage.rings.number_field + sage: P. = F[] # optional - sage.rings.number_field + sage: gap(P) # indirect doctest # optional - sage.rings.number_field PolynomialRing( CF(8), ["x", "y"] ) - sage: libgap(P) + sage: libgap(P) # optional - sage.rings.number_field [x,y] """ L = ['"%s"' % t for t in self.variable_names()] @@ -862,8 +860,8 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: R = PolynomialRing(QQ, 'x', 3) sage: R.characteristic() 0 - sage: R = PolynomialRing(GF(7),'x', 20) - sage: R.characteristic() + sage: R = PolynomialRing(GF(7), 'x', 20) # optional - sage.rings.finite_rings + sage: R.characteristic() # optional - sage.rings.finite_rings 7 """ return self.base_ring().characteristic() @@ -1335,9 +1333,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def change_ring(self, base_ring=None, names=None, order=None): """ - Return a new multivariate polynomial ring which isomorphic to - self, but has a different ordering given by the parameter - 'order' or names given by the parameter 'names'. + Return a new multivariate polynomial ring which is isomorphic to + ``self``, but has a different ordering given by the parameter + ``order`` or names given by the parameter ``names``. INPUT: @@ -1347,11 +1345,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: P. = PolynomialRing(GF(127),3,order='lex') - sage: x > y^2 + sage: P. = PolynomialRing(GF(127), 3, order='lex') # optional - sage.rings.finite_rings + sage: x > y^2 # optional - sage.rings.finite_rings True - sage: Q. = P.change_ring(order='degrevlex') - sage: x > y^2 + sage: Q. = P.change_ring(order='degrevlex') # optional - sage.rings.finite_rings + sage: x > y^2 # optional - sage.rings.finite_rings False """ if base_ring is None: @@ -1406,7 +1404,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The number of such monomials equals `\binom{n+k-1}{k}` where `n` is the number of variables and `k` the degree:: - sage: len(mons) == binomial(3+2-1,2) + sage: len(mons) == binomial(3 + 2 - 1, 2) True """ deg_of_gens = [x.degree() for x in self.gens()] @@ -1527,7 +1525,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def macaulay_resultant(self, *args, **kwds): r""" - This is an implementation of the Macaulay Resultant. It computes + This is an implementation of the Macaulay resultant. It computes the resultant of universal polynomials as well as polynomials with constant coefficients. This is a project done in sage days 55. It's based on the implementation in Maple by @@ -1550,17 +1548,17 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): INPUT: - ``args`` -- a list of `n` homogeneous polynomials in `n` variables. - works when ``args[0]`` is the list of polynomials, - or ``args`` is itself the list of polynomials + works when ``args[0]`` is the list of polynomials, + or ``args`` is itself the list of polynomials kwds: - ``sparse`` -- boolean (optional - default: ``False``) - if ``True`` function creates sparse matrices. + if ``True``, the function creates sparse matrices. OUTPUT: - - the macaulay resultant, an element of the base ring of ``self`` + - the Macaulay resultant, an element of the base ring of ``self`` .. TODO:: Working with sparse matrices should usually give faster results, @@ -1571,27 +1569,25 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The number of polynomials has to match the number of variables:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y,x+z]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x + z]) # optional - sage.modules Traceback (most recent call last): ... - TypeError: number of polynomials(= 2) must equal number of - variables (= 3) + TypeError: number of polynomials(= 2) must equal number of variables (= 3) The polynomials need to be all homogeneous:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y, x+z, z+x^3]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x + z, z + x^3]) # optional - sage.modules Traceback (most recent call last): ... - TypeError: resultant for non-homogeneous polynomials is - not supported + TypeError: resultant for non-homogeneous polynomials is not supported All polynomials must be in the same ring:: sage: S. = PolynomialRing(QQ, 2) sage: R. = PolynomialRing(QQ,3) - sage: S.macaulay_resultant([y, z+x]) + sage: S.macaulay_resultant([y, z+x]) # optional - sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring @@ -1599,8 +1595,8 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The following example recreates Proposition 2.10 in Ch.3 in [CLO2005]:: sage: K. = PolynomialRing(ZZ, 2) - sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,2]) - sage: R.macaulay_resultant(flist) + sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) + sage: R.macaulay_resultant(flist) # optional - sage.modules u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - @@ -1609,11 +1605,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11 The following example degenerates into the determinant of - a `3*3` matrix:: + a `3\times 3` matrix:: sage: K. = PolynomialRing(ZZ, 2) sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,1]) - sage: R.macaulay_resultant(flist) + sage: R.macaulay_resultant(flist) # optional - sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8 The following example is by Patrick Ingram (:arxiv:`1310.4114`):: @@ -1624,57 +1620,57 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: f1 = y1*x2^2 - x1^2 + 2*x0*x2 sage: f2 = x0*x1 - x2^2 sage: flist = [f0,f1,f2] - sage: R.macaulay_resultant([f0,f1,f2]) + sage: R.macaulay_resultant([f0,f1,f2]) # optional - sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27 A simple example with constant rational coefficients:: - sage: R. = PolynomialRing(QQ,4) - sage: R.macaulay_resultant([w,z,y,x]) + sage: R. = PolynomialRing(QQ, 4) + sage: R.macaulay_resultant([w, z, y, x]) # optional - sage.modules 1 An example where the resultant vanishes:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([x+y,y^2,x]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([x + y, y^2, x]) # optional - sage.modules 0 An example of bad reduction at a prime `p = 5`:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y,x^3+25*y^2*x,5*z]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x^3 + 25*y^2*x, 5*z]) # optional - sage.modules 125 The input can given as an unpacked list of polynomials:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant(y,x^3+25*y^2*x,5*z) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant(y, x^3 + 25*y^2*x, 5*z) # optional - sage.modules 125 An example when the coefficients live in a finite field:: - sage: F = FiniteField(11) - sage: R. = PolynomialRing(F,4) - sage: R.macaulay_resultant([z,x^3,5*y,w]) + sage: F = FiniteField(11) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(F, 4) # optional - sage.rings.finite_rings + sage: R.macaulay_resultant([z, x^3, 5*y, w]) # optional - sage.modules sage.rings.finite_rings 4 Example when the denominator in the algorithm vanishes(in this case the resultant is the constant term of the quotient of char polynomials of numerator/denominator):: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y, x+z, z^2]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x + z, z^2]) # optional - sage.modules -1 - When there are only 2 polynomials, macaulay resultant degenerates + When there are only 2 polynomials, the Macaulay resultant degenerates to the traditional resultant:: - sage: R. = PolynomialRing(QQ,1) - sage: f = x^2+1; g = x^5+1 + sage: R. = PolynomialRing(QQ, 1) + sage: f = x^2 + 1; g = x^5 + 1 sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() - sage: f.resultant(g) == RH.macaulay_resultant([fh,gh]) + sage: f.resultant(g) == RH.macaulay_resultant([fh, gh]) # optional - sage.modules True """ @@ -1754,9 +1750,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: sage: R = QQ['x,y,z'] - sage: W = R.weyl_algebra(); W + sage: W = R.weyl_algebra(); W # optional - sage.combinat sage.modules Differential Weyl algebra of polynomials in x, y, z over Rational Field - sage: W.polynomial_ring() == R + sage: W.polynomial_ring() == R # optional - sage.combinat sage.modules True """ from sage.algebras.weyl_algebra import DifferentialWeylAlgebra @@ -1773,8 +1769,8 @@ cdef class BooleanPolynomialRing_base(MPolynomialRing_base): EXAMPLES:: sage: from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base - sage: R. = BooleanPolynomialRing() - sage: isinstance(R, BooleanPolynomialRing_base) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: isinstance(R, BooleanPolynomialRing_base) # optional - sage.rings.polynomial.pbori True By design, there is only one direct implementation subclass:: diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index c4ad2530b58..f370b094c12 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -23,24 +23,24 @@ As an example consider a small scale variant of the AES:: - sage: sr = mq.SR(2,1,2,4,gf2=True,polybori=True) - sage: sr + sage: sr = mq.SR(2, 1, 2, 4, gf2=True, polybori=True) # optional - sage.rings.polynomial.pbori + sage: sr # optional - sage.rings.polynomial.pbori SR(2,1,2,4) We can construct a polynomial sequence for a random plaintext-ciphertext pair and study it:: - sage: set_random_seed(1) - sage: while True: # workaround (see :trac:`31891`) + sage: set_random_seed(1) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: F + sage: F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 112 Polynomials in 64 Variables - sage: r2 = F.part(2); r2 + sage: r2 = F.part(2); r2 # optional - sage.rings.polynomial.pbori (w200 + k100 + x100 + x102 + x103, w201 + k101 + x100 + x101 + x103 + 1, w202 + k102 + x100 + x101 + x102 + 1, @@ -114,32 +114,32 @@ and compute the coefficient matrix:: - sage: A,v = Sequence(r2).coefficient_matrix() - sage: A.rank() + sage: A,v = Sequence(r2).coefficient_matrix() # optional - sage.rings.polynomial.pbori + sage: A.rank() # optional - sage.rings.polynomial.pbori 32 Using these building blocks we can implement a simple XL algorithm easily:: - sage: sr = mq.SR(1,1,1,4, gf2=True, polybori=True, order='lex') - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(1,1,1,4, gf2=True, polybori=True, order='lex') # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: monomials = [a*b for a in F.variables() for b in F.variables() if a = PolynomialRing(GF(127),4) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127), 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings If a list of tuples is provided, those form the parts:: - sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest + sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -234,12 +234,12 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F.nparts() + sage: F.nparts() # optional - sage.rings.finite_rings 2 If an ideal is provided, the generators are used:: - sage: Sequence(I) + sage: Sequence(I) # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -247,22 +247,22 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): If a list of polynomials is provided, the system has only one part:: - sage: F = Sequence(I.gens(), I.ring()); F + sage: F = Sequence(I.gens(), I.ring()); F # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F.nparts() + sage: F.nparts() # optional - sage.rings.finite_rings 1 We test that the ring is inferred correctly:: - sage: P. = GF(2)[] + sage: P. = GF(2)[] # optional - sage.rings.finite_rings sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence - sage: PolynomialSequence([1,x,y]).ring() + sage: PolynomialSequence([1,x,y]).ring() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 - sage: PolynomialSequence([[1,x,y], [0]]).ring() + sage: PolynomialSequence([[1,x,y], [0]]).ring() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 TESTS: @@ -271,10 +271,10 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): characteristic 2 (see :trac:`19452`):: sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence - sage: F = GF(2) - sage: L. = PowerSeriesRing(F,'t') - sage: R. = PolynomialRing(L,'x,y') - sage: PolynomialSequence([0], R) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: L. = PowerSeriesRing(F,'t') # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(L,'x,y') # optional - sage.rings.finite_rings + sage: PolynomialSequence([0], R) # optional - sage.rings.finite_rings [0] A PolynomialSequence can be created from an iterator (see :trac:`25989`):: @@ -386,22 +386,25 @@ def __init__(self, parts, ring, immutable=False, cr=False, cr_str=None): EXAMPLES:: - sage: P. = PolynomialRing(GF(127),4) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127), 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings - sage: Sequence([I.gens()], I.ring()) # indirect doctest - [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] + sage: Sequence([I.gens()], I.ring()) # indirect doctest # optional - sage.rings.finite_rings + [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, + 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] If an ideal is provided, the generators are used.:: - sage: Sequence(I) - [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] + sage: Sequence(I) # optional - sage.rings.finite_rings + [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, + 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] If a list of polynomials is provided, the system has only one part.:: - sage: Sequence(I.gens(), I.ring()) - [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] + sage: Sequence(I.gens(), I.ring()) # optional - sage.rings.finite_rings + [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, + 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] """ Sequence_generic.__init__(self, sum(parts,tuple()), ring, check=False, immutable=immutable, @@ -415,11 +418,11 @@ def __copy__(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: copy(F) # indirect doctest + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: copy(F) # indirect doctest # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: type(F) == type(copy(F)) + sage: type(F) == type(copy(F)) # optional - sage.rings.polynomial.pbori True """ return self.__class__(self._parts, self._ring, immutable=self.is_immutable()) @@ -430,9 +433,9 @@ def ring(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block') - sage: F,s = sr.polynomial_system() - sage: print(F.ring().repr_long()) + sage: sr = mq.SR(allow_zero_inversions=True, gf2=True, order='block') # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: print(F.ring().repr_long()) # optional - sage.rings.polynomial.pbori Polynomial Ring Base Ring : Finite Field of size 2 Size : 20 Variables @@ -451,9 +454,9 @@ def nparts(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.nparts() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.nparts() # optional - sage.rings.polynomial.pbori 4 """ return len(self._parts) @@ -464,10 +467,10 @@ def parts(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: l = F.parts() - sage: len(l) + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: l = F.parts() # optional - sage.rings.polynomial.pbori + sage: len(l) # optional - sage.rings.polynomial.pbori 4 """ return tuple(self._parts) @@ -478,10 +481,10 @@ def part(self, i): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: R0 = F.part(1) - sage: R0 + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: R0 = F.part(1) # optional - sage.rings.polynomial.pbori + sage: R0 # optional - sage.rings.polynomial.pbori (k000^2 + k001, k001^2 + k002, k002^2 + k003, k003^2 + k000) """ return self._parts[i] @@ -492,14 +495,14 @@ def ideal(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: P = F.ring() - sage: I = F.ideal() - sage: J = I.elimination_ideal(P.gens()[4:-4]) - sage: J <= I + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: P = F.ring() # optional - sage.rings.polynomial.pbori + sage: I = F.ideal() # optional - sage.rings.polynomial.pbori + sage: J = I.elimination_ideal(P.gens()[4:-4]) # optional - sage.rings.polynomial.pbori + sage: J <= I # optional - sage.rings.polynomial.pbori True - sage: set(J.gens().variables()).issubset(P.gens()[:4] + P.gens()[-4:]) + sage: set(J.gens().variables()).issubset(P.gens()[:4] + P.gens()[-4:]) # optional - sage.rings.polynomial.pbori True """ return self._ring.ideal(tuple(self)) @@ -519,10 +522,10 @@ def groebner_basis(self, *args, **kwargs): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: gb = F.groebner_basis() - sage: Ideal(gb).basis_is_groebner() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: gb = F.groebner_basis() # optional - sage.rings.polynomial.pbori + sage: Ideal(gb).basis_is_groebner() # optional - sage.rings.polynomial.pbori True TESTS: @@ -530,12 +533,12 @@ def groebner_basis(self, *args, **kwargs): Check that this method also works for boolean polynomials (:trac:`10680`):: - sage: B. = BooleanPolynomialRing() - sage: F0 = Sequence(map(lambda f: f.lm(),[a,b,c,d])) - sage: F0.groebner_basis() + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F0 = Sequence(map(lambda f: f.lm(), [a,b,c,d])) # optional - sage.rings.polynomial.pbori + sage: F0.groebner_basis() # optional - sage.rings.polynomial.pbori [a, b, c, d] - sage: F1 = Sequence([a,b,c*d,d^2]) - sage: F1.groebner_basis() + sage: F1 = Sequence([a,b,c*d,d^2]) # optional - sage.rings.polynomial.pbori + sage: F1.groebner_basis() # optional - sage.rings.polynomial.pbori [a, b, d] """ return self.ideal().groebner_basis(*args, **kwargs) @@ -546,9 +549,9 @@ def monomials(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: len(F.monomials()) + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: len(F.monomials()) # optional - sage.rings.polynomial.pbori 49 """ M = set() @@ -563,9 +566,9 @@ def nmonomials(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.nmonomials() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.nmonomials() # optional - sage.rings.polynomial.pbori 49 """ return len(self.monomials()) @@ -577,9 +580,9 @@ def variables(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.variables()[:10] + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.variables()[:10] # optional - sage.rings.polynomial.pbori (k003, k002, k001, k000, s003, s002, s001, s000, w103, w102) """ V = set() @@ -594,9 +597,9 @@ def nvariables(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.nvariables() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.nvariables() # optional - sage.rings.polynomial.pbori 20 """ return len(self.variables()) @@ -637,11 +640,13 @@ def algebraic_dependence(self): :: - sage: R. = PolynomialRing(GF(7)) - sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) - sage: I = S.algebraic_dependence(); I - Ideal (2 - 3*T2 - T0^2 + 3*T2^2 - T0^2*T2 + T2^3 + 2*T0^4 - 2*T0^2*T2^2 + T2^4 - T0^4*T1 + T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) of Multivariate Polynomial Ring in T0, T1, T2 over Finite Field of size 7 - sage: [F(S) for F in I.gens()] + sage: R. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) # optional - sage.rings.finite_rings + sage: I = S.algebraic_dependence(); I # optional - sage.rings.finite_rings + Ideal (2 - 3*T2 - T0^2 + 3*T2^2 - T0^2*T2 + T2^3 + 2*T0^4 - 2*T0^2*T2^2 + + T2^4 - T0^4*T1 + T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) + of Multivariate Polynomial Ring in T0, T1, T2 over Finite Field of size 7 + sage: [F(S) for F in I.gens()] # optional - sage.rings.finite_rings [0] .. NOTE:: @@ -702,23 +707,23 @@ def coefficient_matrix(self, sparse=True): EXAMPLES:: - sage: P. = PolynomialRing(GF(127),4) - sage: I = sage.rings.ideal.Katsura(P) - sage: I.gens() + sage: P. = PolynomialRing(GF(127), 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: I.gens() # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F = Sequence(I) - sage: A,v = F.coefficient_matrix() - sage: A + sage: F = Sequence(I) # optional - sage.rings.finite_rings + sage: A,v = F.coefficient_matrix() # optional - sage.rings.finite_rings + sage: A # optional - sage.rings.finite_rings [ 0 0 0 0 0 0 0 0 0 1 2 2 2 126] [ 1 0 2 0 0 2 0 0 2 126 0 0 0 0] [ 0 2 0 0 2 0 0 2 0 0 126 0 0 0] [ 0 0 1 2 0 0 2 0 0 0 0 126 0 0] - sage: v + sage: v # optional - sage.rings.finite_rings [a^2] [a*b] [b^2] @@ -734,7 +739,7 @@ def coefficient_matrix(self, sparse=True): [ d] [ 1] - sage: A*v + sage: A*v # optional - sage.rings.finite_rings [ a + 2*b + 2*c + 2*d - 1] [a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a] [ 2*a*b + 2*b*c + 2*c*d - b] @@ -764,20 +769,20 @@ def coefficient_matrix(self, sparse=True): def subs(self, *args, **kwargs): """ Substitute variables for every polynomial in this system and - return a new system. See ``MPolynomial.subs`` for calling + return a new system. See :meth:`MPolynomial.subs` for calling convention. INPUT: - - ``args`` - arguments to be passed to ``MPolynomial.subs`` - - ``kwargs`` - keyword arguments to be passed to ``MPolynomial.subs`` + - ``args`` - arguments to be passed to :meth:`MPolynomial.subs` + - ``kwargs`` - keyword arguments to be passed to :meth:`MPolynomial.subs` EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system(); F + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system(); F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: F = F.subs(s); F + sage: F = F.subs(s); F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 16 Variables """ return PolynomialSequence(self._ring, [tuple([f.subs(*args,**kwargs) for f in r]) for r in self._parts]) @@ -788,14 +793,14 @@ def _singular_(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) - sage: F = Sequence(I); F + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: F = Sequence(I); F # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F._singular_() + sage: F._singular_() # optional - sage.rings.finite_rings a+2*b+2*c+2*d-1, a^2+2*b^2+2*c^2+2*d^2-a, 2*a*b+2*b*c+2*c*d-b, @@ -810,10 +815,10 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) - sage: F,s = sr.polynomial_system() - sage: F.set_immutable() - sage: magma(F) # indirect doctest; optional - magma + sage: sr = mq.SR(allow_zero_inversions=True, gf2=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.set_immutable() # optional - sage.rings.polynomial.pbori + sage: magma(F) # indirect doctest; optional - magma # optional - sage.rings.polynomial.pbori Ideal of Boolean polynomial ring of rank 20 over GF(2) Order: Graded Lexicographical (bit vector word) Variables: k100, k101, k102, k103, x100, x101, x102, x103, w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, k003 @@ -832,9 +837,9 @@ def _repr_(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) - sage: F = Sequence(I); F # indirect doctest + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: F = Sequence(I); F # indirect doctest # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -843,8 +848,8 @@ def _repr_(self): If the system contains 20 or more polynomials, a short summary is printed:: - sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) - sage: F,s = sr.polynomial_system(); F + sage: sr = mq.SR(allow_zero_inversions=True, gf2=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system(); F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 36 Polynomials in 20 Variables """ @@ -860,24 +865,24 @@ def __add__(self, right): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) - sage: F = Sequence(I) - sage: F + [a^127 + a] + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: F = Sequence(I) # optional - sage.rings.finite_rings + sage: F + [a^127 + a] # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c, a^127 + a] - sage: F + P.ideal([a^127 + a]) + sage: F + P.ideal([a^127 + a]) # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c, a^127 + a] - sage: F + Sequence([a^127 + a], P) + sage: F + Sequence([a^127 + a], P) # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -951,15 +956,15 @@ def connected_components(self): As an example consider one part of AES, which naturally splits into four subsystems which are independent:: - sage: sr = mq.SR(2,4,4,8,gf2=True,polybori=True) - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(2, 4, 4, 8, gf2=True, polybori=True) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: Fz = Sequence(F.part(2)) - sage: Fz.connected_components() + sage: Fz = Sequence(F.part(2)) # optional - sage.rings.polynomial.pbori + sage: Fz.connected_components() # optional - sage.rings.polynomial.pbori [Polynomial Sequence with 128 Polynomials in 128 Variables, Polynomial Sequence with 128 Polynomials in 128 Variables, Polynomial Sequence with 128 Polynomials in 128 Variables, @@ -1005,9 +1010,9 @@ def _groebner_strategy(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: F = Sequence([x*y + z, y + z + 1]) - sage: F._groebner_strategy() + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.finite_rings + sage: F._groebner_strategy() # optional - sage.rings.finite_rings Groebner Strategy for ideal generated by 2 elements over Multivariate Polynomial Ring in x, y, z over Finite Field of size 127 """ @@ -1020,13 +1025,13 @@ def maximal_degree(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(7)) - sage: F = Sequence([x*y + x, x]) - sage: F.maximal_degree() + sage: P. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + x, x]) # optional - sage.rings.finite_rings + sage: F.maximal_degree() # optional - sage.rings.finite_rings 2 - sage: P. = PolynomialRing(GF(7)) - sage: F = Sequence([], universe=P) - sage: F.maximal_degree() + sage: P. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: F = Sequence([], universe=P) # optional - sage.rings.finite_rings + sage: F.maximal_degree() # optional - sage.rings.finite_rings -1 """ @@ -1039,15 +1044,15 @@ def __reduce__(self): """ TESTS:: - sage: P. = PolynomialRing(GF(127)) - sage: F = Sequence([x*y + z, y + z + 1]) - sage: loads(dumps(F)) == F # indirect doctest + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.finite_rings + sage: loads(dumps(F)) == F # indirect doctest # optional - sage.rings.finite_rings True We check that :trac:`26354` is fixed:: - sage: f = P.hom([y,z,x]) - sage: hash(f) == hash(loads(dumps(f))) + sage: f = P.hom([y,z,x]) # optional - sage.rings.finite_rings + sage: hash(f) == hash(loads(dumps(f))) # optional - sage.rings.finite_rings True """ @@ -1063,12 +1068,12 @@ def reduced(self): - `(f_1,...,f_n) = (g_1,...,g_s)` - - `LT(g_i) != LT(g_j)` for all `i != j` + - `LT(g_i) \neq LT(g_j)` for all `i \neq j` - `LT(g_i)` does not divide `m` for all monomials `m` of - `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` + `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` - - `LC(g_i) == 1` for all `i` if the coefficient ring is a field. + - `LC(g_i) = 1` for all `i` if the coefficient ring is a field. EXAMPLES:: @@ -1166,12 +1171,12 @@ def is_groebner(self, singular=singular): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,4) - sage: I.basis.is_groebner() + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 4) # optional - sage.rings.finite_rings + sage: I.basis.is_groebner() # optional - sage.rings.finite_rings False - sage: I2 = Ideal(I.groebner_basis()) - sage: I2.basis.is_groebner() + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.finite_rings + sage: I2.basis.is_groebner() # optional - sage.rings.finite_rings True """ @@ -1203,64 +1208,64 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc with linear leading terms which were used for reduction is also returned (default: ``False``). - - ```use_polybori`` - if ``True`` then ``polybori.ll.eliminate`` is - called. While this is typically faster what is implemented here, it + - ``use_polybori`` - if ``True`` then ``polybori.ll.eliminate`` is + called. While this is typically faster than what is implemented here, it is less flexible (``skip`` is not supported) and may increase the degree (default: ``False``) OUTPUT: - When ``return_reductors==True``, then a pair of sequences of + With ``return_reductors=True``, a pair of sequences of boolean polynomials are returned, along with the promises that: - 1. The union of the two sequences spans the - same boolean ideal as the argument of the method + 1. The union of the two sequences spans the + same boolean ideal as the argument of the method - 2. The second sequence only contains linear polynomials, and - it forms a reduced groebner basis (they all have pairwise - distinct leading variables, and the leading variable of a - polynomial does not occur anywhere in other polynomials). + 2. The second sequence only contains linear polynomials, and + it forms a reduced groebner basis (they all have pairwise + distinct leading variables, and the leading variable of a + polynomial does not occur anywhere in other polynomials). - 3. The leading variables of the second sequence do not occur - anywhere in the first sequence (these variables have been - eliminated). + 3. The leading variables of the second sequence do not occur + anywhere in the first sequence (these variables have been + eliminated). - When ``return_reductors==False``, only the first sequence is + With ``return_reductors=False``, only the first sequence is returned. EXAMPLES:: - sage: B. = BooleanPolynomialRing() - sage: F = Sequence([c + d + b + 1, a + c + d, a*b + c, b*c*d + c]) - sage: F.eliminate_linear_variables() # everything vanishes + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([c + d + b + 1, a + c + d, a*b + c, b*c*d + c]) # optional - sage.rings.polynomial.pbori + sage: F.eliminate_linear_variables() # everything vanishes # optional - sage.rings.polynomial.pbori [] - sage: F.eliminate_linear_variables(maxlength=2) + sage: F.eliminate_linear_variables(maxlength=2) # optional - sage.rings.polynomial.pbori [b + c + d + 1, b*c + b*d + c, b*c*d + c] - sage: F.eliminate_linear_variables(skip=lambda lm,tail: str(lm)=='a') + sage: F.eliminate_linear_variables(skip=lambda lm,tail: str(lm)=='a') # optional - sage.rings.polynomial.pbori [a + c + d, a*c + a*d + a + c, c*d + c] - The list of reductors can be requested by setting 'return_reductors' to ``True``:: + The list of reductors can be requested by setting ``return_reductors`` to ``True``:: - sage: B. = BooleanPolynomialRing() - sage: F = Sequence([a + b + d, a + b + c]) - sage: F,R = F.eliminate_linear_variables(return_reductors=True) - sage: F + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([a + b + d, a + b + c]) # optional - sage.rings.polynomial.pbori + sage: F, R = F.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori + sage: F # optional - sage.rings.polynomial.pbori [] - sage: R + sage: R # optional - sage.rings.polynomial.pbori [a + b + d, c + d] - If the input system is detected to be inconsistent then [1] is returned + If the input system is detected to be inconsistent then ``[1]`` is returned, and the list of reductors is empty:: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y+z]) - sage: S.eliminate_linear_variables() + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables() # optional - sage.rings.polynomial.pbori [1] - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y+z]) - sage: S.eliminate_linear_variables(return_reductors=True) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori ([1], []) @@ -1268,30 +1273,30 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc The function should really dispose of linear equations (:trac:`13968`):: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x+y+z+1, y+z]) - sage: S.eliminate_linear_variables(return_reductors=True) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x + y + z + 1, y + z]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori ([], [x + 1, y + z]) The function should take care of linear variables created by previous substitution of linear variables :: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y]) - sage: S.eliminate_linear_variables(return_reductors=True) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori ([], [x + y, z + 1]) We test a case which would increase the degree with ``polybori=True``:: - sage: B. = BooleanPolynomialRing() - sage: f = a*d + a + b*d + c*d + 1 - sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables() + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: f = a*d + a + b*d + c*d + 1 # optional - sage.rings.polynomial.pbori + sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables() # optional - sage.rings.polynomial.pbori [a*d + a + b*d + c*d + 1, a + b*c + c + d + 1] - sage: B. = BooleanPolynomialRing() - sage: f = a*d + a + b*d + c*d + 1 - sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables(use_polybori=True) + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: f = a*d + a + b*d + c*d + 1 # optional - sage.rings.polynomial.pbori + sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables(use_polybori=True) # optional - sage.rings.polynomial.pbori [b*c*d + b*c + b*d + c + d] .. NOTE:: @@ -1372,15 +1377,15 @@ def _groebner_strategy(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: F = Sequence([x*y + z, y + z + 1]) - sage: F._groebner_strategy() + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.finite_rings + sage: F._groebner_strategy() # optional - sage.rings.finite_rings Groebner Strategy for ideal generated by 2 elements over Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 - sage: P. = BooleanPolynomialRing() - sage: F = Sequence([x*y + z, y + z + 1]) - sage: F._groebner_strategy() + sage: P. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.polynomial.pbori + sage: F._groebner_strategy() # optional - sage.rings.polynomial.pbori """ from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base @@ -1436,63 +1441,63 @@ def solve(self, algorithm='polybori', n=1, eliminate_linear_variables=True, ver Without argument, a single arbitrary solution is returned:: sage: from sage.doctest.fixtures import reproducible_repr - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y+z, y*z+x, x+y+z+1]) - sage: sol = S.solve() - sage: print(reproducible_repr(sol)) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y + z, y*z + x, x + y + z + 1]) # optional - sage.rings.polynomial.pbori + sage: sol = S.solve() # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sol)) # optional - sage.rings.polynomial.pbori [{x: 0, y: 1, z: 0}] We check that it is actually a solution:: - sage: S.subs( sol[0] ) + sage: S.subs(sol[0]) # optional - sage.rings.polynomial.pbori [0, 0, 0] We obtain all solutions:: - sage: sols = S.solve(n=Infinity) - sage: print(reproducible_repr(sols)) + sage: sols = S.solve(n=Infinity) # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sols)) # optional - sage.rings.polynomial.pbori [{x: 0, y: 1, z: 0}, {x: 1, y: 1, z: 1}] - sage: [S.subs(x) for x in sols] + sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori [[0, 0, 0], [0, 0, 0]] We can force the use of exhaustive search if the optional package ``FES`` is present:: - sage: sol = S.solve(algorithm='exhaustive_search') # optional - FES - sage: print(reproducible_repr(sol)) # optional - FES + sage: sol = S.solve(algorithm='exhaustive_search') # optional - FES # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sol)) # optional - FES # optional - sage.rings.polynomial.pbori [{x: 1, y: 1, z: 1}] - sage: S.subs( sol[0] ) + sage: S.subs(sol[0]) # optional - FES # optional - sage.rings.polynomial.pbori [0, 0, 0] And we may use SAT-solvers if they are available:: - sage: sol = S.solve(algorithm='sat') # optional - pycryptosat - sage: print(reproducible_repr(sol)) # optional - pycryptosat + sage: sol = S.solve(algorithm='sat') # optional - pycryptosat # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sol)) # optional - pycryptosat # optional - sage.rings.polynomial.pbori [{x: 0, y: 1, z: 0}] - sage: S.subs( sol[0] ) + sage: S.subs(sol[0]) # optional - sage.rings.polynomial.pbori [0, 0, 0] TESTS: Make sure that variables not occurring in the equations are no problem:: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y+z, y*z+x, x+y+z+1]) - sage: sols = S.solve(n=Infinity) - sage: [S.subs(x) for x in sols] + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y + z, y*z + x, x + y + z + 1]) # optional - sage.rings.polynomial.pbori + sage: sols = S.solve(n=Infinity) # optional - sage.rings.polynomial.pbori + sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] Not eliminating linear variables:: - sage: sols = S.solve(n=Infinity, eliminate_linear_variables=False) - sage: [S.subs(x) for x in sols] + sage: sols = S.solve(n=Infinity, eliminate_linear_variables=False) # optional - sage.rings.polynomial.pbori + sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] A tricky case where the linear equations are insatisfiable:: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y+z]) - sage: S.solve() + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # optional - sage.rings.polynomial.pbori + sage: S.solve() # optional - sage.rings.polynomial.pbori [] """ @@ -1560,27 +1565,27 @@ def solve(self, algorithm='polybori', n=1, eliminate_linear_variables=True, ver return solutions def reduced(self): - """ - If this sequence is `(f_1, ..., f_n)` this method returns `(g_1, ..., g_s)` such that: + r""" + If this sequence is `f_1, ..., f_n`, return `g_1, ..., g_s` such that: - - ` = ` - - `LT(g_i) != LT(g_j)` for all `i != j`` + - `(f_1,...,f_n) = (g_1,...,g_s)` + - `LT(g_i) \neq LT(g_j)` for all `i \neq j` - `LT(g_i)` does not divide `m` for all monomials `m` of `{g_1,...,g_{i-1},g_{i+1},...,g_s}` EXAMPLES:: - sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True) - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: g = F.reduced() - sage: len(g) == len(set(gi.lt() for gi in g)) + sage: g = F.reduced() # optional - sage.rings.polynomial.pbori + sage: len(g) == len(set(gi.lt() for gi in g)) # optional - sage.rings.polynomial.pbori True - sage: for i in range(len(g)): + sage: for i in range(len(g)): # optional - sage.rings.polynomial.pbori ....: for j in range(len(g)): ....: if i == j: ....: continue @@ -1618,27 +1623,27 @@ def weil_restriction(self): EXAMPLES:: - sage: k. = GF(2^2) - sage: P. = PolynomialRing(k,2) - sage: a = P.base_ring().gen() - sage: F = Sequence([x*y + 1, a*x + 1], P) - sage: F2 = F.weil_restriction() - sage: F2 + sage: k. = GF(2^2) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: a = P.base_ring().gen() # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + 1, a*x + 1], P) # optional - sage.rings.finite_rings + sage: F2 = F.weil_restriction() # optional - sage.rings.finite_rings + sage: F2 # optional - sage.rings.finite_rings [x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1, x0^2 + x0, - x1^2 + x1, y0^2 + y0, y1^2 + y1] + x1^2 + x1, y0^2 + y0, y1^2 + y1] Another bigger example for a small scale AES:: - sage: sr = mq.SR(1,1,1,4,gf2=False) - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(1, 1, 1, 4, gf2=False) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: F + sage: F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: F2 = F.weil_restriction(); F2 + sage: F2 = F.weil_restriction(); F2 # optional - sage.rings.polynomial.pbori Polynomial Sequence with 240 Polynomials in 80 Variables """ from sage.rings.ideal import FieldIdeal diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 4db1a1652ff..d30478b4f48 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -164,48 +164,48 @@ cdef class OrePolynomial(AlgebraElement): Here is another example over a finite field:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^4 + (4*t + 1)*x^3 + (t^2 + 3*t + 3)*x^2 + (3*t^2 + 2*t + 2)*x + (3*t^2 + 3*t + 1) - sage: b = (2*t^2 + 3)*x^2 + (3*t^2 + 1)*x + 4*t + 2 - sage: q,r = a.left_quo_rem(b) - sage: q + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^4 + (4*t + 1)*x^3 + (t^2 + 3*t + 3)*x^2 + (3*t^2 + 2*t + 2)*x + (3*t^2 + 3*t + 1) # optional - sage.rings.finite_rings + sage: b = (2*t^2 + 3)*x^2 + (3*t^2 + 1)*x + 4*t + 2 # optional - sage.rings.finite_rings + sage: q, r = a.left_quo_rem(b) # optional - sage.rings.finite_rings + sage: q # optional - sage.rings.finite_rings (4*t^2 + t + 1)*x^2 + (2*t^2 + 2*t + 2)*x + 2*t^2 + 4*t + 3 - sage: r + sage: r # optional - sage.rings.finite_rings (t + 2)*x + 3*t^2 + 2*t + 4 - sage: a == b*q + r + sage: a == b*q + r # optional - sage.rings.finite_rings True Once we have euclidean divisions, we have for free gcd and lcm (at least if the base ring is a field):: - sage: a = (x + t) * (x + t^2)^2 - sage: b = (x + t) * (t*x + t + 1) * (x + t^2) - sage: a.right_gcd(b) + sage: a = (x + t) * (x + t^2)^2 # optional - sage.rings.finite_rings + sage: b = (x + t) * (t*x + t + 1) * (x + t^2) # optional - sage.rings.finite_rings + sage: a.right_gcd(b) # optional - sage.rings.finite_rings x + t^2 - sage: a.left_gcd(b) + sage: a.left_gcd(b) # optional - sage.rings.finite_rings x + t The left lcm has the following meaning: given Ore polynomials `a` and `b`, their left lcm is the least degree polynomial `c = ua = vb` for some Ore polynomials `u, v`. Such a `c` always exist if the base ring is a field:: - sage: c = a.left_lcm(b); c + sage: c = a.left_lcm(b); c # optional - sage.rings.finite_rings x^5 + (4*t^2 + t + 3)*x^4 + (3*t^2 + 4*t)*x^3 + 2*t^2*x^2 + (2*t^2 + t)*x + 4*t^2 + 4 - sage: c.is_right_divisible_by(a) + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_right_divisible_by(b) + sage: c.is_right_divisible_by(b) # optional - sage.rings.finite_rings True The right lcm is defined similarly as the least degree polynomial `c = au = bv` for some `u,v`:: - sage: d = a.right_lcm(b); d + sage: d = a.right_lcm(b); d # optional - sage.rings.finite_rings x^5 + (t^2 + 1)*x^4 + (3*t^2 + 3*t + 3)*x^3 + (3*t^2 + t + 2)*x^2 + (4*t^2 + 3*t)*x + 4*t + 4 - sage: d.is_left_divisible_by(a) + sage: d.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: d.is_left_divisible_by(b) + sage: d.is_left_divisible_by(b) # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -291,10 +291,10 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: OrePolynomialBaseringInjection(k, k['x', Frob]) #indirect doctest + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: OrePolynomialBaseringInjection(k, k['x', Frob]) #indirect doctest # optional - sage.rings.finite_rings Ore Polynomial base injection morphism: From: Finite Field in t of size 5^3 To: Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 @@ -313,10 +313,10 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x + t - sage: a[1] = t + 1 + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x + t # optional - sage.rings.finite_rings + sage: a[1] = t + 1 # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: Ore polynomials are immutable @@ -484,26 +484,26 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 - sage: b = a.left_monic(); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 # optional - sage.rings.finite_rings + sage: b = a.left_monic(); b # optional - sage.rings.finite_rings x^3 + (4*t^2 + 3*t)*x^2 + (4*t + 2)*x + 2*t^2 + 4*t + 3 Check list:: - sage: b.degree() == a.degree() + sage: b.degree() == a.degree() # optional - sage.rings.finite_rings True - sage: b.is_left_divisible_by(a) + sage: b.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: twist = S.twisting_morphism(-a.degree()) - sage: a == b * twist(a.leading_coefficient()) + sage: twist = S.twisting_morphism(-a.degree()) # optional - sage.rings.finite_rings + sage: a == b * twist(a.leading_coefficient()) # optional - sage.rings.finite_rings True Note that `b` does not divide `a` on the right:: - sage: a.is_right_divisible_by(b) + sage: a.is_right_divisible_by(b) # optional - sage.rings.finite_rings False This function does not work if the leading coefficient is not a @@ -537,25 +537,25 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 - sage: b = a.right_monic(); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 # optional - sage.rings.finite_rings + sage: b = a.right_monic(); b # optional - sage.rings.finite_rings x^3 + (2*t^2 + 3*t + 4)*x^2 + (3*t^2 + 4*t + 1)*x + 2*t^2 + 4*t + 3 Check list:: - sage: b.degree() == a.degree() + sage: b.degree() == a.degree() # optional - sage.rings.finite_rings True - sage: b.is_right_divisible_by(a) + sage: b.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: a == a.leading_coefficient() * b + sage: a == a.leading_coefficient() * b # optional - sage.rings.finite_rings True Note that `b` does not divide `a` on the right:: - sage: a.is_left_divisible_by(b) + sage: a.is_left_divisible_by(b) # optional - sage.rings.finite_rings False This function does not work if the leading coefficient is not a @@ -635,14 +635,15 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: R. = GF(11)[] - sage: der = R.derivation() - sage: S. = R['x', der] - sage: f = t/x - sage: f + sage: R. = GF(11)[] # optional - sage.rings.finite_rings + sage: der = R.derivation() # optional - sage.rings.finite_rings + sage: S. = R['x', der] # optional - sage.rings.finite_rings + sage: f = t/x # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings (x + 10/t)^(-1) * t - sage: f.parent() - Ore Function Field in x over Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 11 twisted by d/dt + sage: f.parent() # optional - sage.rings.finite_rings + Ore Function Field in x over + Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 11 twisted by d/dt """ parent = self.parent().fraction_field() return parent(self) / parent(right) @@ -696,20 +697,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^2 + t*x + t^2 + 3 - sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b - sage: c.is_right_divisible_by(a) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^2 + t*x + t^2 + 3 # optional - sage.rings.finite_rings + sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.rings.finite_rings + sage: c = a*b # optional - sage.rings.finite_rings + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings False - sage: c.is_right_divisible_by(b) + sage: c.is_right_divisible_by(b) # optional - sage.rings.finite_rings True Divisibility by `0` does not make sense:: - sage: c.is_right_divisible_by(S(0)) + sage: c.is_right_divisible_by(S(0)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -745,20 +746,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^2 + t*x + t^2 + 3 - sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b - sage: a.left_divides(c) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^2 + t*x + t^2 + 3 # optional - sage.rings.finite_rings + sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.rings.finite_rings + sage: c = a*b # optional - sage.rings.finite_rings + sage: a.left_divides(c) # optional - sage.rings.finite_rings True - sage: b.left_divides(c) + sage: b.left_divides(c) # optional - sage.rings.finite_rings False Divisibility by `0` does not make sense:: - sage: S(0).left_divides(c) + sage: S(0).left_divides(c) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -780,20 +781,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^2 + t*x + t^2 + 3 - sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b - sage: a.right_divides(c) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^2 + t*x + t^2 + 3 # optional - sage.rings.finite_rings + sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.rings.finite_rings + sage: c = a*b # optional - sage.rings.finite_rings + sage: a.right_divides(c) # optional - sage.rings.finite_rings False - sage: b.right_divides(c) + sage: b.right_divides(c) # optional - sage.rings.finite_rings True Divisibility by `0` does not make sense:: - sage: S(0).right_divides(c) + sage: S(0).right_divides(c) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -858,21 +859,21 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t) * (x^2 + t*x + 1) - sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) - sage: g,u,v = a.left_xgcd(b); g + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t) * (x^2 + t*x + 1) # optional - sage.rings.finite_rings + sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) # optional - sage.rings.finite_rings + sage: g,u,v = a.left_xgcd(b); g # optional - sage.rings.finite_rings x + t - sage: a*u + b*v == g + sage: a*u + b*v == g # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: g,u,v = a.left_xgcd(b, monic=False); g + sage: g,u,v = a.left_xgcd(b, monic=False); g # optional - sage.rings.finite_rings 2*t*x + 4*t + 2 - sage: a*u + b*v == g + sage: a*u + b*v == g # optional - sage.rings.finite_rings True The base ring must be a field:: @@ -961,13 +962,13 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 - sage: b = (3*t^2 + 4*t + 2)*x^2 + (2*t^2 + 4*t + 3)*x + 2*t^2 + t + 1 - sage: q,r = a.left_quo_rem(b) - sage: a == b*q + r + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 # optional - sage.rings.finite_rings + sage: b = (3*t^2 + 4*t + 2)*x^2 + (2*t^2 + 4*t + 3)*x + 2*t^2 + t + 1 # optional - sage.rings.finite_rings + sage: q,r = a.left_quo_rem(b) # optional - sage.rings.finite_rings + sage: a == b*q + r # optional - sage.rings.finite_rings True In the following example, Sage does not know the inverse @@ -1090,21 +1091,21 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x^2 + t*x + 1) * (x + t) - sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) - sage: g,u,v = a.right_xgcd(b); g + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x^2 + t*x + 1) * (x + t) # optional - sage.rings.finite_rings + sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: g,u,v = a.right_xgcd(b); g # optional - sage.rings.finite_rings x + t - sage: u*a + v*b == g + sage: u*a + v*b == g # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: g,u,v = a.right_xgcd(b,monic=False); g + sage: g,u,v = a.right_xgcd(b, monic=False); g # optional - sage.rings.finite_rings (4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3 - sage: u*a + v*b == g + sage: u*a + v*b == g # optional - sage.rings.finite_rings True The base ring must be a field:: @@ -1173,17 +1174,17 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x^2 + t*x + 1) * (x + t) - sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) - sage: a.right_gcd(b) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x^2 + t*x + 1) * (x + t) # optional - sage.rings.finite_rings + sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: a.right_gcd(b) # optional - sage.rings.finite_rings x + t Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.right_gcd(b,monic=False) + sage: a.right_gcd(b,monic=False) # optional - sage.rings.finite_rings (4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3 The base ring need to be a field:: @@ -1240,22 +1241,22 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t) * (x^2 + t*x + 1) - sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) - sage: a.left_gcd(b) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t) * (x^2 + t*x + 1) # optional - sage.rings.finite_rings + sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) # optional - sage.rings.finite_rings + sage: a.left_gcd(b) # optional - sage.rings.finite_rings x + t Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.left_gcd(b,monic=False) + sage: a.left_gcd(b,monic=False) # optional - sage.rings.finite_rings 2*t*x + 4*t + 2 The base ring needs to be a field:: - sage: R. = QQ[] + sage: R. = QQ[] # optional - sage.rings.finite_rings sage: sigma = R.hom([t+1]) sage: S. = R['x',sigma] sage: a = (x + t) * (x^2 + t*x + 1) @@ -1301,23 +1302,23 @@ cdef class OrePolynomial(AlgebraElement): TESTS:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.rings.polynomial.ore_polynomial_element cimport OrePolynomial ....: def left_lcm_cofactor(OrePolynomial P, OrePolynomial Q): ....: return P._left_lcm_cofactor(Q) ....: ''') - sage: k. = GF(7^5) - sage: Frob = k.frobenius_endomorphism(3) - sage: S. = k['x', Frob] + sage: k. = GF(7^5) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism(3) # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: D = S.random_element(degree=2) - sage: P = S.random_element(degree=2) * D - sage: Q = S.random_element(degree=2) * D - sage: L = P.left_lcm(Q) - sage: U = left_lcm_cofactor(P, Q) # optional - sage.misc.cython - sage: (U*P).right_monic() == L # optional - sage.misc.cython + sage: D = S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: P = S.random_element(degree=2) * D # optional - sage.rings.finite_rings + sage: Q = S.random_element(degree=2) * D # optional - sage.rings.finite_rings + sage: L = P.left_lcm(Q) # optional - sage.rings.finite_rings + sage: U = left_lcm_cofactor(P, Q) # optional - sage.misc.cython sage.rings.finite_rings + sage: (U*P).right_monic() == L # optional - sage.misc.cython sage.rings.finite_rings True """ cdef OrePolynomial Q, R, T @@ -1344,18 +1345,18 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: P = (x + t^2) * (x + t) - sage: Q = 2 * (x^2 + t + 1) * (x * t) - sage: L, U, V = P.left_xlcm(Q) - sage: L + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: P = (x + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: Q = 2 * (x^2 + t + 1) * (x * t) # optional - sage.rings.finite_rings + sage: L, U, V = P.left_xlcm(Q) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings x^5 + (2*t^2 + t + 4)*x^4 + (3*t^2 + 4)*x^3 + (3*t^2 + 3*t + 2)*x^2 + (t^2 + t + 2)*x - sage: U*P == L + sage: U*P == L # optional - sage.rings.finite_rings True - sage: V*Q == L + sage: V*Q == L # optional - sage.rings.finite_rings True """ if self.base_ring() not in _Fields: @@ -1379,23 +1380,23 @@ cdef class OrePolynomial(AlgebraElement): TESTS:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.rings.polynomial.ore_polynomial_element cimport OrePolynomial ....: def right_lcm_cofactor(OrePolynomial P, OrePolynomial Q): ....: return P._right_lcm_cofactor(Q) ....: ''') - sage: k. = GF(7^5) - sage: Frob = k.frobenius_endomorphism(3) - sage: S. = k['x', Frob] + sage: k. = GF(7^5) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism(3) # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: D = S.random_element(degree=2) - sage: P = D * S.random_element(degree=2) - sage: Q = D * S.random_element(degree=2) - sage: L = P.right_lcm(Q) - sage: U = right_lcm_cofactor(P, Q) # optional - sage.misc.cython - sage: (P*U).left_monic() == L # optional - sage.misc.cython + sage: D = S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: P = D * S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: Q = D * S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: L = P.right_lcm(Q) # optional - sage.rings.finite_rings + sage: U = right_lcm_cofactor(P, Q) # optional - sage.misc.cython sage.rings.finite_rings + sage: (P*U).left_monic() == L # optional - sage.misc.cython sage.rings.finite_rings True """ cdef OrePolynomial Q, R, T @@ -1429,17 +1430,17 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: P = (x + t) * (x + t^2) - sage: Q = 2 * (x + t) * (x^2 + t + 1) - sage: L, U, V = P.right_xlcm(Q) - sage: L + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: P = (x + t) * (x + t^2) # optional - sage.rings.finite_rings + sage: Q = 2 * (x + t) * (x^2 + t + 1) # optional - sage.rings.finite_rings + sage: L, U, V = P.right_xlcm(Q) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings x^4 + (2*t^2 + t + 2)*x^3 + (3*t^2 + 4*t + 1)*x^2 + (3*t^2 + 4*t + 1)*x + t^2 + 4 - sage: P*U == L + sage: P*U == L # optional - sage.rings.finite_rings True - sage: Q*V == L + sage: Q*V == L # optional - sage.rings.finite_rings True """ if self.base_ring() not in _Fields: @@ -1484,23 +1485,23 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t^2) * (x + t) - sage: b = 2 * (x^2 + t + 1) * (x * t) - sage: c = a.left_lcm(b); c + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: b = 2 * (x^2 + t + 1) * (x * t) # optional - sage.rings.finite_rings + sage: c = a.left_lcm(b); c # optional - sage.rings.finite_rings x^5 + (2*t^2 + t + 4)*x^4 + (3*t^2 + 4)*x^3 + (3*t^2 + 3*t + 2)*x^2 + (t^2 + t + 2)*x - sage: c.is_right_divisible_by(a) + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_right_divisible_by(b) + sage: c.is_right_divisible_by(b) # optional - sage.rings.finite_rings True - sage: a.degree() + b.degree() == c.degree() + a.right_gcd(b).degree() + sage: a.degree() + b.degree() == c.degree() + a.right_gcd(b).degree() # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.left_lcm(b,monic=False) + sage: a.left_lcm(b,monic=False) # optional - sage.rings.finite_rings (t^2 + t)*x^5 + (4*t^2 + 4*t + 1)*x^4 + (t + 1)*x^3 + (t^2 + 2)*x^2 + (3*t + 4)*x The base ring needs to be a field:: @@ -1554,23 +1555,23 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t) * (x + t^2) - sage: b = 2 * (x + t) * (x^2 + t + 1) - sage: c = a.right_lcm(b); c + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t) * (x + t^2) # optional - sage.rings.finite_rings + sage: b = 2 * (x + t) * (x^2 + t + 1) # optional - sage.rings.finite_rings + sage: c = a.right_lcm(b); c # optional - sage.rings.finite_rings x^4 + (2*t^2 + t + 2)*x^3 + (3*t^2 + 4*t + 1)*x^2 + (3*t^2 + 4*t + 1)*x + t^2 + 4 - sage: c.is_left_divisible_by(a) + sage: c.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_left_divisible_by(b) + sage: c.is_left_divisible_by(b) # optional - sage.rings.finite_rings True - sage: a.degree() + b.degree() == c.degree() + a.left_gcd(b).degree() + sage: a.degree() + b.degree() == c.degree() + a.left_gcd(b).degree() # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.right_lcm(b,monic=False) + sage: a.right_lcm(b,monic=False) # optional - sage.rings.finite_rings 2*t*x^4 + (3*t + 1)*x^3 + (4*t^2 + 4*t + 3)*x^2 + (3*t^2 + 4*t + 2)*x + 3*t^2 + 2*t + 3 @@ -2052,12 +2053,12 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = 1 + t*x^2 - sage: b = x + 1 - sage: a.left_mod(b) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = 1 + t*x^2 # optional - sage.rings.finite_rings + sage: b = x + 1 # optional - sage.rings.finite_rings + sage: a.left_mod(b) # optional - sage.rings.finite_rings 2*t^2 + 4*t """ _, r = self.left_quo_rem(other) @@ -2853,54 +2854,55 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): EXAMPLES:: - sage: R. = GF(7)[] - sage: der = R.derivation() - sage: A. = R['d', der] + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: der = R.derivation() # optional - sage.rings.finite_rings + sage: A. = R['d', der] # optional - sage.rings.finite_rings - sage: L = d^3 + t*d^2 - sage: L.hilbert_shift(t) + sage: L = d^3 + t*d^2 # optional - sage.rings.finite_rings + sage: L.hilbert_shift(t) # optional - sage.rings.finite_rings d^3 + 4*t*d^2 + (5*t^2 + 3)*d + 2*t^3 + 4*t - sage: (d+t)^3 + t*(d+t)^2 + sage: (d+t)^3 + t*(d+t)^2 # optional - sage.rings.finite_rings d^3 + 4*t*d^2 + (5*t^2 + 3)*d + 2*t^3 + 4*t One can specify another variable name:: - sage: L.hilbert_shift(t, var='x') + sage: L.hilbert_shift(t, var='x') # optional - sage.rings.finite_rings x^3 + 4*t*x^2 + (5*t^2 + 3)*x + 2*t^3 + 4*t When the twisting morphism is not trivial, the output lies in a different Ore polynomial ring:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob] + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: P = x^2 + a*x + a^2 - sage: Q = P.hilbert_shift(a); Q + sage: P = x^2 + a*x + a^2 # optional - sage.rings.finite_rings + sage: Q = P.hilbert_shift(a); Q # optional - sage.rings.finite_rings x^2 + (2*a^2 + a + 4)*x + a^2 + 3*a + 4 - sage: Q.parent() - Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 and a*([a |--> a^5] - id) - sage: Q.parent() is S + sage: Q.parent() # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over + Finite Field in a of size 5^3 twisted by a |--> a^5 and a*([a |--> a^5] - id) + sage: Q.parent() is S # optional - sage.rings.finite_rings False This behavior ensures that the Hilbert shift by a fixed element defines an homomorphism of rings:: - sage: U = S.random_element(degree=5) - sage: V = S.random_element(degree=5) - sage: s = k.random_element() - sage: (U+V).hilbert_shift(s) == U.hilbert_shift(s) + V.hilbert_shift(s) + sage: U = S.random_element(degree=5) # optional - sage.rings.finite_rings + sage: V = S.random_element(degree=5) # optional - sage.rings.finite_rings + sage: s = k.random_element() # optional - sage.rings.finite_rings + sage: (U+V).hilbert_shift(s) == U.hilbert_shift(s) + V.hilbert_shift(s) # optional - sage.rings.finite_rings True - sage: (U*V).hilbert_shift(s) == U.hilbert_shift(s) * V.hilbert_shift(s) + sage: (U*V).hilbert_shift(s) == U.hilbert_shift(s) * V.hilbert_shift(s) # optional - sage.rings.finite_rings True We check that shifting by an element and then by its opposite gives back the initial Ore polynomial:: - sage: P = S.random_element(degree=10) - sage: s = k.random_element() - sage: P.hilbert_shift(s).hilbert_shift(-s) == P + sage: P = S.random_element(degree=10) # optional - sage.rings.finite_rings + sage: s = k.random_element() # optional - sage.rings.finite_rings + sage: P.hilbert_shift(s).hilbert_shift(-s) == P # optional - sage.rings.finite_rings True """ from sage.rings.polynomial.ore_polynomial_ring import OrePolynomialRing @@ -3002,7 +3004,8 @@ cdef class OrePolynomialBaseringInjection(Morphism): sage: S.coerce_map_from(S.base_ring()) #indirect doctest Ore Polynomial base injection morphism: From: Univariate Polynomial Ring in t over Rational Field - To: Ore Polynomial Ring in x over Univariate Polynomial Ring in t over Rational Field twisted by t |--> t + 1 + To: Ore Polynomial Ring in x over Univariate Polynomial Ring in t + over Rational Field twisted by t |--> t + 1 """ def __init__(self, domain, codomain): r""" @@ -3018,10 +3021,10 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: OrePolynomialBaseringInjection(k, k['x', Frob]) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings Ore Polynomial base injection morphism: From: Finite Field in t of size 5^3 To: Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 @@ -3045,11 +3048,11 @@ cdef class OrePolynomialBaseringInjection(Morphism): EXAMPLES:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) - sage: m.an_element() + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings + sage: m.an_element() # optional - sage.rings.finite_rings x """ return self._an_element @@ -3070,13 +3073,13 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) - sage: m(4) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings + sage: m(4) # optional - sage.rings.finite_rings 4 - sage: parent(m(4)) + sage: parent(m(4)) # optional - sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 """ try: @@ -3092,11 +3095,11 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) - sage: m.section() + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings + sage: m.section() # optional - sage.rings.finite_rings Generic map: From: Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 To: Finite Field in t of size 5^3 diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index 3db1bb6c531..5bb858aa2df 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -782,7 +782,7 @@ cdef class PolyDict: Check that :trac:`29604` is fixed:: - sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) + sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) # optional - sage.rings.finite_rings 'x' """ if not self: @@ -1004,9 +1004,9 @@ cdef class PolyDict: sage: f + g PolyDict with representation {(1, 1): 3, (1, 2): 3, (1, 5): -3, (2, 1): 4, (2, 3): 0} - sage: K = GF(2) - sage: f = PolyDict({(1, 1): K(1)}) - sage: f + f + sage: K = GF(2) # optional - sage.rings.finite_rings + sage: f = PolyDict({(1, 1): K(1)}) # optional - sage.rings.finite_rings + sage: f + f # optional - sage.rings.finite_rings PolyDict with representation {(1, 1): 0} """ cdef dict D = self.__repn @@ -1074,9 +1074,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2, 3): x}) - sage: f.scalar_rmult(y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2, 3): x}) # optional - sage.groups + sage: f.scalar_rmult(y) # optional - sage.groups PolyDict with representation {(2, 3): x*y} sage: f = PolyDict({(2,3):2, (1, 2): 3, (2, 1): 4}) sage: f.scalar_rmult(-2) @@ -1096,9 +1096,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2,3):x}) - sage: f.scalar_lmult(y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2,3):x}) # optional - sage.groups + sage: f.scalar_lmult(y) # optional - sage.groups PolyDict with representation {(2, 3): y*x} sage: f = PolyDict({(2,3):2, (1,2):3, (2,1):4}) sage: f.scalar_lmult(-2) @@ -1125,9 +1125,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import ETuple, PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2, 3): x}) - sage: f.term_lmult(ETuple((1, 2)), y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2, 3): x}) # optional - sage.groups + sage: f.term_lmult(ETuple((1, 2)), y) # optional - sage.groups PolyDict with representation {(3, 5): y*x} sage: f = PolyDict({(2,3): 2, (1,2): 3, (2,1): 4}) @@ -1154,9 +1154,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import ETuple, PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2, 3): x}) - sage: f.term_rmult(ETuple((1, 2)), y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2, 3): x}) # optional - sage.groups + sage: f.term_rmult(ETuple((1, 2)), y) # optional - sage.groups PolyDict with representation {(3, 5): x*y} sage: f = PolyDict({(2, 3): 2, (1, 2): 3, (2, 1): 4}) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index b8ecbb7a14b..136b380d2ab 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -152,7 +152,8 @@ cpdef is_Polynomial(f): sage: from sage.rings.polynomial.polynomial_element import is_Polynomial sage: R. = ZZ[] sage: is_Polynomial(x^3 + x + 1) - doctest:...: DeprecationWarning: the function is_Polynomial is deprecated; use isinstance(x, sage.structure.element.Polynomial) instead + doctest:...: DeprecationWarning: the function is_Polynomial is deprecated; + use isinstance(x, sage.structure.element.Polynomial) instead See https://github.com/sagemath/sage/issues/32709 for details. True sage: S. = R[] @@ -170,11 +171,11 @@ cpdef is_Polynomial(f): y^3 + x*y - 3*x sage: is_Polynomial(f) False - sage: var('x,y') + sage: var('x,y') # optional - sage.symbolic (x, y) - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y -3*x; f # optional - sage.symbolic y^3 + x*y - 3*x - sage: is_Polynomial(f) + sage: is_Polynomial(f) # optional - sage.symbolic False """ from sage.misc.superseded import deprecation @@ -296,12 +297,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R = GF(2)['x']['y'] - sage: R([0,1]).is_zero() + sage: R = GF(2)['x']['y'] # optional - sage.rings.finite_rings + sage: R([0,1]).is_zero() # optional - sage.rings.finite_rings False - sage: R([0]).is_zero() + sage: R([0]).is_zero() # optional - sage.rings.finite_rings True - sage: R([-1]).is_zero() + sage: R([-1]).is_zero() # optional - sage.rings.finite_rings False """ return self.degree() < 0 @@ -313,7 +314,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = QQ[] - sage: (x-3).is_one() + sage: (x - 3).is_one() False sage: R(1).is_one() True @@ -346,11 +347,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: x = polygen(GF(389)) - sage: plot(x^2 + 1, rgbcolor=(0,0,1)) + sage: x = polygen(GF(389)) # optional - sage.rings.finite_rings + sage: plot(x^2 + 1, rgbcolor=(0,0,1)) # optional - sage.rings.finite_rings sage.plot Graphics object consisting of 1 graphics primitive sage: x = polygen(QQ) - sage: plot(x^2 + 1, rgbcolor=(1,0,0)) + sage: plot(x^2 + 1, rgbcolor=(1,0,0)) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ R = self.base_ring() @@ -412,9 +413,9 @@ cdef class Polynomial(CommutativePolynomial): def subs(self, *x, **kwds): r""" - Identical to self(\*x). + Identical to ``self(*x)``. - See the docstring for ``self.__call__``. + See the docstring for :meth:`__call__`. EXAMPLES:: @@ -486,12 +487,12 @@ cdef class Polynomial(CommutativePolynomial): We evaluate a polynomial over a quaternion algebra:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A,sparse=True) - sage: f = i*j*w^5 - 13*i*w^2 + (i+j)*w + i - sage: f(i+j+1) + sage: A. = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A, sparse=True) # optional - sage.combinat sage.modules + sage: f = i*j*w^5 - 13*i*w^2 + (i+j)*w + i # optional - sage.combinat sage.modules + sage: f(i+j+1) # optional - sage.combinat sage.modules 24 + 26*i - 10*j - 25*k - sage: w = i+j+1; i*j*w^5 - 13*i*w^2 + (i+j)*w + i + sage: w = i+j+1; i*j*w^5 - 13*i*w^2 + (i+j)*w + i # optional - sage.combinat sage.modules 24 + 26*i - 10*j - 25*k The parent ring of the answer always "starts" with the parent of @@ -502,28 +503,28 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = R(2/3) - sage: a = matrix(ZZ,2) - sage: b = f(a); b + sage: a = matrix(ZZ, 2) # optional - sage.combinat sage.modules + sage: b = f(a); b # optional - sage.combinat sage.modules [2/3 0] [ 0 2/3] - sage: b.parent() + sage: b.parent() # optional - sage.combinat sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: f = R(1) - sage: b = f(a); b + sage: b = f(a); b # optional - sage.combinat sage.modules [1 0] [0 1] - sage: b.parent() + sage: b.parent() # optional - sage.combinat sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field :: - sage: R. = GF(17)[] - sage: f = w^3 + 3*w +2 - sage: f(5) + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = w^3 + 3*w +2 # optional - sage.rings.finite_rings + sage: f(5) # optional - sage.rings.finite_rings 6 - sage: f(w=5) + sage: f(w=5) # optional - sage.rings.finite_rings 6 - sage: f(x=10) # x isn't mentioned + sage: f(x=10) # x isn't mentioned # optional - sage.rings.finite_rings w^3 + 3*w + 2 Nested polynomial ring elements can be called like multivariate @@ -572,7 +573,7 @@ cdef class Polynomial(CommutativePolynomial): The following results in an element of the symbolic ring. :: - sage: f(x=sqrt(2)) + sage: f(x=sqrt(2)) # optional - sage.symbolic y^2 + sqrt(2)*y + sqrt(2) :: @@ -598,7 +599,7 @@ cdef class Polynomial(CommutativePolynomial): 3 sage: parent(f(0)) Rational Field - sage: parent(f(Qp(5)(0))) + sage: parent(f(Qp(5)(0))) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 TESTS: @@ -677,8 +678,8 @@ cdef class Polynomial(CommutativePolynomial): sage: one(1, 1.).parent() Real Field with 53 bits of precision - sage: zero = GF(2)['x'](0) - sage: zero(1.).parent() # should raise an error + sage: zero = GF(2)['x'](0) # optional - sage.rings.finite_rings + sage: zero(1.).parent() # should raise an error # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: @@ -707,37 +708,37 @@ cdef class Polynomial(CommutativePolynomial): These were drastically slower prior to :trac:`33165`:: - sage: R. = GF(31337)[] - sage: f = R(list(range(100,201))) - sage: g = R(list(range(1,1001))) - sage: S. = R.quotient(f) - sage: g(y) + sage: R. = GF(31337)[] # optional - sage.rings.finite_rings + sage: f = R(list(range(100, 201))) # optional - sage.rings.finite_rings + sage: g = R(list(range(1, 1001))) # optional - sage.rings.finite_rings + sage: S. = R.quotient(f) # optional - sage.rings.finite_rings + sage: g(y) # optional - sage.rings.finite_rings 22537*y^99 + 4686*y^98 + 13285*y^97 + 4216*y^96 + ... + 6389*y^3 + 30062*y^2 + 13755*y + 11875 :: - sage: T. = GF(31337)[] - sage: g(z) + sage: T. = GF(31337)[] # optional - sage.rings.finite_rings + sage: g(z) # optional - sage.rings.finite_rings 1000*z^999 + 999*z^998 + 998*z^997 + 997*z^996 + ... + 5*z^4 + 4*z^3 + 3*z^2 + 2*z + 1 - sage: g(z^2) + sage: g(z^2) # optional - sage.rings.finite_rings 1000*z^1998 + 999*z^1996 + 998*z^1994 + 997*z^1992 + ... + 5*z^8 + 4*z^6 + 3*z^4 + 2*z^2 + 1 - sage: g(T([0,1])) + sage: g(T([0, 1])) # optional - sage.rings.finite_rings 1000*z^999 + 999*z^998 + 998*z^997 + 997*z^996 + ... + 5*z^4 + 4*z^3 + 3*z^2 + 2*z + 1 - sage: g(T.zero()) + sage: g(T.zero()) # optional - sage.rings.finite_rings 1 - sage: g(T(2)) + sage: g(T(2)) # optional - sage.rings.finite_rings 23069 :: - sage: U. = GF(31337)[] - sage: g(u) + sage: U. = GF(31337)[] # optional - sage.rings.finite_rings + sage: g(u) # optional - sage.rings.finite_rings 1000*u^999 + 999*u^998 + 998*u^997 + 997*u^996 + ... + 5*u^4 + 4*u^3 + 3*u^2 + 2*u + 1 - sage: g(u*v^2) + sage: g(u*v^2) # optional - sage.rings.finite_rings 1000*u^999*v^1998 + 999*u^998*v^1996 + 998*u^997*v^1994 + ... + 4*u^3*v^6 + 3*u^2*v^4 + 2*u*v^2 + 1 - sage: g(U.zero()) + sage: g(U.zero()) # optional - sage.rings.finite_rings 1 - sage: g(U(2)) + sage: g(U(2)) # optional - sage.rings.finite_rings -8268 Sparse tests for :trac:`33165`:: @@ -1188,21 +1189,21 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: K. = Qq(4) - sage: R. = K[] - sage: f = x - sage: hash(f) + sage: K. = Qq(4) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = x # optional - sage.rings.padics + sage: hash(f) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' - sage: f._cache_key() + sage: f._cache_key() # optional - sage.rings.padics (Univariate Polynomial Ring in x over 2-adic Unramified Extension Field in u defined by x^2 + x + 1, 0, 1 + O(2^20)) sage: @cached_function ....: def foo(t): return t ....: - sage: foo(x) + sage: foo(x) # optional - sage.rings.padics (1 + O(2^20))*x """ return (self._parent,) + tuple(self) @@ -1239,9 +1240,9 @@ cdef class Polynomial(CommutativePolynomial): Verify that :trac:`16251` has been resolved, i.e., polynomials with unhashable coefficients are unhashable:: - sage: K. = Qq(9) - sage: R. = K[] - sage: hash(t) + sage: K. = Qq(9) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: hash(t) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' @@ -1295,11 +1296,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f(x^2 + 3) # indirect doctest 28 - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: phi = S.hom([y^2], base_map=cc) - sage: phi(i*y) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*y) # optional - sage.rings.number_field -i*y^2 """ a = im_gens[0] @@ -1328,9 +1329,9 @@ cdef class Polynomial(CommutativePolynomial): sage: a = QQ['x'](1/5) sage: QQ(a) 1/5 - sage: AA(a) + sage: AA(a) # optional - sage.rings.number_field 1/5 - sage: QQbar(a) + sage: QQbar(a) # optional - sage.rings.number_field 1/5 sage: RDF(a) 0.2 @@ -1353,30 +1354,30 @@ cdef class Polynomial(CommutativePolynomial): sage: complex(a) (0.2+0j) - sage: b = AA['x'](AA(2/3).sqrt()) - sage: AA(b) + sage: b = AA['x'](AA(2/3).sqrt()) # optional - sage.rings.number_field + sage: AA(b) # optional - sage.rings.number_field 0.8164965809277260? - sage: RR(b) + sage: RR(b) # optional - sage.rings.number_field 0.816496580927726 - sage: RBF(b) + sage: RBF(b) # optional - sage.rings.number_field [0.816496580927726 +/- 2.44e-16] - sage: RIF(b) + sage: RIF(b) # optional - sage.rings.number_field 0.8164965809277260? - sage: float(b) + sage: float(b) # optional - sage.rings.number_field 0.816496580927726 - sage: c = QQbar['x'](QQbar(-2/5).sqrt()) - sage: QQbar(c) + sage: c = QQbar['x'](QQbar(-2/5).sqrt()) # optional - sage.rings.number_field + sage: QQbar(c) # optional - sage.rings.number_field 0.6324555320336758?*I - sage: CDF(c) + sage: CDF(c) # optional - sage.rings.number_field 0.6324555320336758*I - sage: CC(c) + sage: CC(c) # optional - sage.rings.number_field 0.632455532033676*I - sage: CBF(c) # abs tol 1e-16 + sage: CBF(c) # abs tol 1e-16 # optional - sage.rings.number_field [0.6324555320336759 +/- 3.38e-17]*I - sage: CIF(c) + sage: CIF(c) # optional - sage.rings.number_field 0.6324555320336758?*I - sage: complex(c) + sage: complex(c) # optional - sage.rings.number_field 0.6324555320336758j sage: K. = Frac(RR['x']) @@ -1388,8 +1389,8 @@ cdef class Polynomial(CommutativePolynomial): TypeError: cannot convert nonconstant polynomial sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) - sage: A(A['x'](u)) + sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A(A['x'](u)) # optional - sage.rings.number_field u """ if self.degree() > 0: @@ -1431,8 +1432,8 @@ cdef class Polynomial(CommutativePolynomial): r""" EXAMPLES:: - sage: p = PolynomialRing(QQbar, 'x')(1+I) - sage: complex(p) + sage: p = PolynomialRing(QQbar, 'x')(1+I) # optional - sage.rings.number_field + sage: complex(p) # optional - sage.rings.number_field (1+1j) """ return self._scalar_conversion(complex) @@ -1457,20 +1458,20 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic x^3 + x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 10 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 10 The polynomial has to be over a field of characteristic 0 (see :trac:`24072`):: - sage: R. = GF(7)[] - sage: f = SR(2*w^3 + 1); f + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: f = SR(2*w^3 + 1); f # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -1526,10 +1527,11 @@ cdef class Polynomial(CommutativePolynomial): def inverse_mod(a, m): """ - Inverts the polynomial a with respect to m, or raises a ValueError - if no such inverse exists. The parameter m may be either a single - polynomial or an ideal (for consistency with inverse_mod in other - rings). + Invert the polynomial ``a`` with respect to ``m``, or raise a :class:`ValueError` + if no such inverse exists. + + The parameter ``m`` may be either a single polynomial or an ideal + (for consistency with :meth:`inverse_mod` in other rings). .. SEEALSO:: @@ -1557,28 +1559,30 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = RDF[] sage: epsilon = RDF(1).ulp()*50 # Allow an error of up to 50 ulp - sage: f = inverse_mod(x^2 + 1, x^5 + x + 1); f # abs tol 1e-14 + sage: f = inverse_mod(x^2 + 1, x^5 + x + 1); f # abs tol 1e-14 # optional - sage.modules 0.4*x^4 - 0.2*x^3 - 0.4*x^2 + 0.2*x + 0.8 - sage: poly = f * (x^2 + 1) % (x^5 + x + 1) + sage: poly = f * (x^2 + 1) % (x^5 + x + 1) # optional - sage.modules sage: # Remove noisy zero terms: - sage: parent(poly)([ 0.0 if abs(c)<=epsilon else c for c in poly.coefficients(sparse=False) ]) + sage: parent(poly)([0.0 if abs(c) <= epsilon else c # optional - sage.modules + ....: for c in poly.coefficients(sparse=False)]) 1.0 - sage: f = inverse_mod(x^3 - x + 1, x - 2); f + sage: f = inverse_mod(x^3 - x + 1, x - 2); f # optional - sage.modules 0.14285714285714285 - sage: f * (x^3 - x + 1) % (x - 2) + sage: f * (x^3 - x + 1) % (x - 2) # optional - sage.modules 1.0 - sage: g = 5*x^3+x-7; m = x^4-12*x+13; f = inverse_mod(g, m); f + sage: g = 5*x^3 + x - 7; m = x^4 - 12*x + 13; f = inverse_mod(g, m); f # optional - sage.modules -0.0319636125...*x^3 - 0.0383269759...*x^2 - 0.0463050900...*x + 0.346479687... - sage: poly = f*g % m + sage: poly = f*g % m # optional - sage.modules sage: # Remove noisy zero terms: - sage: parent(poly)([ 0.0 if abs(c)<=epsilon else c for c in poly.coefficients(sparse=False) ]) # abs tol 1e-14 + sage: parent(poly)([0.0 if abs(c) <= epsilon else c # abs tol 1e-14 # optional - sage.modules + ....: for c in poly.coefficients(sparse=False)]) 1.0000000000000004 - ALGORITHM: Solve the system as + mt = 1, returning s as the inverse - of a mod m. + ALGORITHM: Solve the system `as + mt = 1`, returning `s` as the inverse + of `a` mod `m`. Uses the Euclidean algorithm for exact rings, and solves a linear - system for the coefficients of s and t for inexact rings (as the + system for the coefficients of `s` and `t` for inexact rings (as the Euclidean algorithm may not converge in that case). AUTHORS: @@ -1678,14 +1682,14 @@ cdef class Polynomial(CommutativePolynomial): Even noncommutative ones:: - sage: M = MatrixSpace(ZZ,2) - sage: x = polygen(M) - sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one() - sage: q = p.inverse_series_trunc(5) - sage: (p*q).truncate(5) == M.one() + sage: M = MatrixSpace(ZZ,2) # optional - sage.modules + sage: x = polygen(M) # optional - sage.modules + sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one() # optional - sage.modules + sage: q = p.inverse_series_trunc(5) # optional - sage.modules + sage: (p*q).truncate(5) == M.one() # optional - sage.modules True - sage: q = p.inverse_series_trunc(13) - sage: (p*q).truncate(13) == M.one() + sage: q = p.inverse_series_trunc(13) # optional - sage.modules + sage: (p*q).truncate(13) == M.one() # optional - sage.modules True TESTS:: @@ -1769,20 +1773,20 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: Pol. = MatrixSpace(ZZ, 2)[] - sage: a = matrix([[1,0],[0,0]]) - sage: b = matrix([[1,2],[3,4]]) - sage: list((a*x)*(b*x + 1)) + sage: Pol. = MatrixSpace(ZZ, 2)[] # optional - sage.modules + sage: a = matrix([[1,0], [0,0]]) # optional - sage.modules + sage: b = matrix([[1,2], [3,4]]) # optional - sage.modules + sage: list((a*x)*(b*x + 1)) # optional - sage.modules [ [0 0] [1 0] [1 2] [0 0], [0 0], [0 0] ] - sage: list((b*x + 1)*(a*x)) + sage: list((b*x + 1)*(a*x)) # optional - sage.modules [ [0 0] [1 0] [1 0] [0 0], [0 0], [3 0] ] - sage: list((a*x + 1)*(b*x)) + sage: list((a*x + 1)*(b*x)) # optional - sage.modules [ [0 0] [1 2] [1 2] [0 0], [3 4], [0 0] @@ -1914,11 +1918,11 @@ cdef class Polynomial(CommutativePolynomial): sage: p = 37 * (x-2/3)^2 sage: p.squarefree_decomposition() (37) * (x - 2/3)^2 - sage: x = polygen(GF(3)) - sage: x.squarefree_decomposition() + sage: x = polygen(GF(3)) # optional - sage.rings.finite_rings + sage: x.squarefree_decomposition() # optional - sage.rings.finite_rings x - sage: f = QQbar['x'](1) - sage: f.squarefree_decomposition() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.squarefree_decomposition() # optional - sage.rings.number_field 1 """ @@ -2026,75 +2030,89 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = GF(11)[] - sage: f = 7*x^7 + 8*x^6 + 4*x^5 + x^4 + 6*x^3 + 10*x^2 + 8*x + 5 - sage: f.any_root() + sage: R. = GF(11)[] # optional - sage.rings.finite_rings + sage: f = 7*x^7 + 8*x^6 + 4*x^5 + x^4 + 6*x^3 + 10*x^2 + 8*x + 5 # optional - sage.rings.finite_rings + sage: f.any_root() # optional - sage.rings.finite_rings 2 - sage: f.factor() + sage: f.factor() # optional - sage.rings.finite_rings (7) * (x + 9) * (x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2) - sage: f = x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2 - sage: f.any_root(GF(11^6, 'a')) + sage: f = x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2 # optional - sage.rings.finite_rings + sage: f.any_root(GF(11^6, 'a')) # optional - sage.rings.finite_rings a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a - sage: sorted(f.roots(GF(11^6, 'a'))) - [(10*a^5 + 2*a^4 + 8*a^3 + 9*a^2 + a, 1), (a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a, 1), (9*a^5 + 5*a^4 + 10*a^3 + 8*a^2 + 3*a + 1, 1), (2*a^5 + 8*a^4 + 3*a^3 + 6*a + 2, 1), (a^5 + 3*a^4 + 8*a^3 + 2*a^2 + 3*a + 4, 1), (10*a^5 + 3*a^4 + 8*a^3 + a^2 + 10*a + 4, 1)] - sage: f.any_root(GF(11^6, 'a')) + sage: sorted(f.roots(GF(11^6, 'a'))) # optional - sage.rings.finite_rings + [(10*a^5 + 2*a^4 + 8*a^3 + 9*a^2 + a, 1), + (a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a, 1), + (9*a^5 + 5*a^4 + 10*a^3 + 8*a^2 + 3*a + 1, 1), + (2*a^5 + 8*a^4 + 3*a^3 + 6*a + 2, 1), + (a^5 + 3*a^4 + 8*a^3 + 2*a^2 + 3*a + 4, 1), + (10*a^5 + 3*a^4 + 8*a^3 + a^2 + 10*a + 4, 1)] + sage: f.any_root(GF(11^6, 'a')) # optional - sage.rings.finite_rings a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a - sage: g = (x-1)*(x^2 + 3*x + 9) * (x^5 + 5*x^4 + 8*x^3 + 5*x^2 + 3*x + 5) - sage: g.any_root(ring=GF(11^10, 'b'), degree=1) + sage: g = (x-1)*(x^2 + 3*x + 9) * (x^5 + 5*x^4 + 8*x^3 + 5*x^2 + 3*x + 5) # optional - sage.rings.finite_rings + sage: g.any_root(ring=GF(11^10, 'b'), degree=1) # optional - sage.rings.finite_rings 1 - sage: g.any_root(ring=GF(11^10, 'b'), degree=2) + sage: g.any_root(ring=GF(11^10, 'b'), degree=2) # optional - sage.rings.finite_rings 5*b^9 + 4*b^7 + 4*b^6 + 8*b^5 + 10*b^2 + 10*b + 5 - sage: g.any_root(ring=GF(11^10, 'b'), degree=5) + sage: g.any_root(ring=GF(11^10, 'b'), degree=5) # optional - sage.rings.finite_rings 5*b^9 + b^8 + 3*b^7 + 2*b^6 + b^5 + 4*b^4 + 3*b^3 + 7*b^2 + 10*b TESTS:: - sage: R. = GF(5)[] - sage: K. = GF(5^12) - sage: for _ in range(40): + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K. = GF(5^12) # optional - sage.rings.finite_rings + sage: for _ in range(40): # optional - sage.rings.finite_rings ....: f = R.random_element(degree=4) ....: assert f(f.any_root(K)) == 0 Check that our Cantor-Zassenhaus implementation does not loop over finite fields of even characteristic (see :trac:`16162`):: - sage: K. = GF(2**8) - sage: x = polygen(K) - sage: r = (x**2+x+1).any_root() # used to loop - sage: r**2 + r + sage: K. = GF(2**8) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: r = (x**2+x+1).any_root() # used to loop # optional - sage.rings.finite_rings + sage: r**2 + r # optional - sage.rings.finite_rings 1 - sage: (x**2+a+1).any_root() + sage: (x**2+a+1).any_root() # optional - sage.rings.finite_rings a^7 + a^2 Also check that such computations can be interrupted:: - sage: K. = GF(2^8) - sage: x = polygen(K) - sage: pol = x^1000000 + x + a - sage: alarm(0.5); pol.any_root() + sage: K. = GF(2^8) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: pol = x^1000000 + x + a # optional - sage.rings.finite_rings + sage: alarm(0.5); pol.any_root() # optional - sage.rings.finite_rings Traceback (most recent call last): ... AlarmInterrupt Check root computation over large finite fields:: - sage: K. = GF(2**50) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a - sage: K. = GF(2**150) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + a^8 + a^6 + a^5 + a^4 + a + 1 + sage: K. = GF(2**50) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: (x**10+x+a).any_root() # optional - sage.rings.finite_rings + a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a + sage: K. = GF(2**150) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: (x**10+x+a).any_root() # optional - sage.rings.finite_rings + a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + + a^8 + a^6 + a^5 + a^4 + a + 1 Check that :trac:`21998` has been resolved:: - sage: K. = GF(2^4) - sage: R. = K[] - sage: f = x^2 + x + a^2 + a - sage: r = f.any_root() - sage: r^2 + r + sage: K. = GF(2^4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: f = x^2 + x + a^2 + a # optional - sage.rings.finite_rings + sage: r = f.any_root() # optional - sage.rings.finite_rings + sage: r^2 + r # optional - sage.rings.finite_rings a^2 + a """ if self.base_ring().is_finite() and self.base_ring().is_field(): @@ -2288,9 +2306,9 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') - sage: f = x^3 + 4*x - sage: f / (x - 1) + sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') # optional - sage.rings.finite_rings + sage: f = x^3 + 4*x # optional - sage.rings.finite_rings + sage: f / (x - 1) # optional - sage.rings.finite_rings x^2 + x Be careful about coercions (this used to be broken):: @@ -2305,21 +2323,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`12217` is fixed:: - sage: P. = GF(5)[] - sage: x/0 + sage: P. = GF(5)[] # optional - sage.rings.finite_rings + sage: x/0 # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(0, 5) does not exist - sage: P. = GF(25, 'a')[] - sage: x/5 + sage: P. = GF(25, 'a')[] # optional - sage.rings.finite_rings + sage: x/5 # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero in finite field Check that :trac:`23611` is fixed:: - sage: int(1) / x + sage: int(1) / x # optional - sage.rings.finite_rings 1/x """ # Same parents => bypass coercion @@ -2352,10 +2370,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f^3 x^3 - 3*x^2 + 3*x - 1 - sage: R = PolynomialRing(GF(2), 'x') - sage: f = R(x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x) - sage: h = R(x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1) - sage: pow(f, 2, h) + sage: R = PolynomialRing(GF(2), 'x') # optional - sage.rings.finite_rings + sage: f = R(x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x) # optional - sage.rings.finite_rings + sage: h = R(x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1) # optional - sage.rings.finite_rings + sage: pow(f, 2, h) # optional - sage.rings.finite_rings x^9 + x^8 + x^7 + x^5 + x^3 TESTS:: @@ -2382,46 +2400,46 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: k = GF(5) - sage: D. = k[] - sage: l. = k.extension(x^2 + 2) - sage: R. = l[] - sage: f = t^4 + (2*x - 1)*t^3 + (2*x + 1)*t^2 + 3 - sage: h = t^4 - x*t^3 + (3*x + 1)*t^2 + 2*t + 2*x - 1 - sage: pow(f, 2, h) + sage: k = GF(5) # optional - sage.rings.finite_rings + sage: D. = k[] # optional - sage.rings.finite_rings + sage: l. = k.extension(x^2 + 2) # optional - sage.rings.finite_rings + sage: R. = l[] # optional - sage.rings.finite_rings + sage: f = t^4 + (2*x - 1)*t^3 + (2*x + 1)*t^2 + 3 # optional - sage.rings.finite_rings + sage: h = t^4 - x*t^3 + (3*x + 1)*t^2 + 2*t + 2*x - 1 # optional - sage.rings.finite_rings + sage: pow(f, 2, h) # optional - sage.rings.finite_rings 3*t^3 + (2*x + 3)*t^2 + (2*x + 2)*t + 2*x + 2 - sage: pow(f, 10**7, h) + sage: pow(f, 10**7, h) # optional - sage.rings.finite_rings 4*x*t^3 + 2*x*t^2 + 4*x*t + 4 Check that :trac:`18457` is fixed:: - sage: R. = PolynomialRing(GF(5), sparse=True) - sage: (1+x)^(5^10) # used to hang forever + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings + sage: (1+x)^(5^10) # used to hang forever # optional - sage.rings.finite_rings x^9765625 + 1 - sage: S. = GF(3)[] - sage: R1. = PolynomialRing(S, sparse=True) - sage: (1+x+t)^(3^10) + sage: S. = GF(3)[] # optional - sage.rings.finite_rings + sage: R1. = PolynomialRing(S, sparse=True) # optional - sage.rings.finite_rings + sage: (1+x+t)^(3^10) # optional - sage.rings.finite_rings x^59049 + t^59049 + 1 - sage: R2. = PolynomialRing(S, sparse=False) - sage: (1+x+t)^(3^10) + sage: R2. = PolynomialRing(S, sparse=False) # optional - sage.rings.finite_rings + sage: (1+x+t)^(3^10) # optional - sage.rings.finite_rings x^59049 + t^59049 + 1 Check that the algorithm used is indeed correct:: sage: from sage.arith.power import generic_power - sage: R1 = PolynomialRing(GF(8,'a'), 'x') - sage: R2 = PolynomialRing(GF(9,'b'), 'x', sparse=True) - sage: R3 = PolynomialRing(R2, 'y') - sage: R4 = PolynomialRing(R1, 'y', sparse=True) - sage: for d in range(20,40): # long time + sage: R1 = PolynomialRing(GF(8,'a'), 'x') # optional - sage.rings.finite_rings + sage: R2 = PolynomialRing(GF(9,'b'), 'x', sparse=True) # optional - sage.rings.finite_rings + sage: R3 = PolynomialRing(R2, 'y') # optional - sage.rings.finite_rings + sage: R4 = PolynomialRing(R1, 'y', sparse=True) # optional - sage.rings.finite_rings + sage: for d in range(20,40): # long time # optional - sage.rings.finite_rings ....: for R in [R1, R2, R3, R3]: ....: a = R.random_element() ....: assert a^d == generic_power(a, d) Test the powering modulo ``x^n`` (calling :meth:`power_trunc`):: - sage: R. = GF(3)[] - sage: pow(x + 1, 51, x^7) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: pow(x + 1, 51, x^7) # optional - sage.rings.finite_rings x^6 + 2*x^3 + 1 sage: S. = QQ[] @@ -2432,10 +2450,10 @@ cdef class Polynomial(CommutativePolynomial): Check that fallback method is used when it is not possible to compute the characteristic of the base ring (:trac:`24308`):: - sage: kk. = GF(2)[] - sage: k. = kk.quo(a^2+a+1) - sage: K. = k[] - sage: (T*y)^21 + sage: kk. = GF(2)[] # optional - sage.rings.finite_rings + sage: k. = kk.quo(a^2+a+1) # optional - sage.rings.finite_rings + sage: K. = k[] # optional - sage.rings.finite_rings + sage: (T*y)^21 # optional - sage.rings.finite_rings T^21 """ if not isinstance(left, Polynomial): @@ -2527,20 +2545,20 @@ cdef class Polynomial(CommutativePolynomial): sage: ((x+y)^5).truncate(5) 5*x*y^4 + 10*x^2*y^3 + 10*x^3*y^2 + 5*x^4*y + x^5 - sage: R. = GF(3)[] - sage: p = x^2 - x + 1 - sage: q = p.power_trunc(80, 20) - sage: q + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: p = x^2 - x + 1 # optional - sage.rings.finite_rings + sage: q = p.power_trunc(80, 20) # optional - sage.rings.finite_rings + sage: q # optional - sage.rings.finite_rings x^19 + x^18 + ... + 2*x^4 + 2*x^3 + x + 1 - sage: (p^80).truncate(20) == q + sage: (p^80).truncate(20) == q # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] - sage: p = (x^2 + x + 1).power_trunc(2^100, 100) - sage: p + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: p = (x^2 + x + 1).power_trunc(2^100, 100) # optional - sage.rings.finite_rings + sage: p # optional - sage.rings.finite_rings 2*x^99 + x^98 + x^95 + 2*x^94 + ... + 3*x^2 + 2*x + 1 - sage: for i in range(100): + sage: for i in range(100): # optional - sage.rings.finite_rings ....: q1 = (x^2 + x + 1).power_trunc(2^100 + i, 100) ....: q2 = p * (x^2 + x + 1).power_trunc(i, 100) ....: q2 = q2.truncate(100) @@ -2630,10 +2648,10 @@ cdef class Polynomial(CommutativePolynomial): elements in the Sage library yet that do not implement ``__bool__``, so we have to create one artificially.):: - sage: class PatchedAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): + sage: class PatchedAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): # optional - sage.rings.number_field ....: def __bool__(self): raise NotImplementedError() - sage: R. = QQbar[] - sage: R([PatchedAlgebraicNumber(0), 1]) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R([PatchedAlgebraicNumber(0), 1]) # optional - sage.rings.number_field x + 0 """ if name is None: @@ -2708,10 +2726,10 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: C3. = CyclotomicField(3) - sage: R. = C3[] - sage: f = X^3 - omega*X - sage: latex(f) + sage: C3. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = C3[] # optional - sage.rings.number_field + sage: f = X^3 - omega*X # optional - sage.rings.number_field + sage: latex(f) # optional - sage.rings.number_field X^{3} - \omega X sage: R. = RDF[] sage: latex(x+2) @@ -2724,9 +2742,9 @@ cdef class Polynomial(CommutativePolynomial): The following illustrates a (non-intentional) superfluity of parentheses - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: latex(I*x^2-I*x) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: latex(I*x^2 - I*x) # optional - sage.rings.number_field \left(\sqrt{-1}\right) x^{2} + \left(-\sqrt{-1}\right) x """ s = " " @@ -2799,7 +2817,7 @@ cdef class Polynomial(CommutativePolynomial): # Verified R. = RR[] 3.1415926535897931*x - sage: sage_input(polygen(GF(7)) + 12, verify=True) + sage: sage_input(polygen(GF(7)) + 12, verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] x + 5 @@ -2855,7 +2873,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _floordiv_(self, right): r""" - Quotient of division of self by other. This is denoted //. + Quotient of division of ``self`` by ``other``. This is denoted //. If self = quotient \* right + remainder, this function returns quotient. @@ -2878,7 +2896,7 @@ cdef class Polynomial(CommutativePolynomial): def __mod__(self, other): """ - Remainder of division of self by other. + Remainder of division of ``self`` by ``other``. EXAMPLES:: @@ -2893,7 +2911,7 @@ cdef class Polynomial(CommutativePolynomial): def mod(self, other): """ - Remainder of division of self by other. + Remainder of division of ``self`` by ``other``. EXAMPLES:: @@ -2908,14 +2926,14 @@ cdef class Polynomial(CommutativePolynomial): Check the problem reported at :trac:`12529` is fixed:: sage: gens = 'y a0 a1 a2 b0 b1 b2 c1 c2 d0 d1 d2 d3 d4 d5 d6 d7'.split() - sage: R = PolynomialRing(GF(8), 17, gens) - sage: R.inject_variables(verbose=False) - sage: A, B, C = a0 + a1*y + a2*y^2, b0 + b1*y + b2*y^2, c1*y + c2*y^2 - sage: D = d0 + d1*y + d2*y^2 + d3*y^3 + d4*y^4 + d5*y^5 + d6*y^6 + d7*y^7 - sage: F = D.subs({y: B}) - sage: G = A.subs({y: F}) + C - sage: g = G.mod(y^8 + y) - sage: g.degree(y) + sage: R = PolynomialRing(GF(8), 17, gens) # optional - sage.rings.finite_rings + sage: R.inject_variables(verbose=False) # optional - sage.rings.finite_rings + sage: A, B, C = a0 + a1*y + a2*y^2, b0 + b1*y + b2*y^2, c1*y + c2*y^2 # optional - sage.rings.finite_rings + sage: D = d0 + d1*y + d2*y^2 + d3*y^3 + d4*y^4 + d5*y^5 + d6*y^6 + d7*y^7 # optional - sage.rings.finite_rings + sage: F = D.subs({y: B}) # optional - sage.rings.finite_rings + sage: G = A.subs({y: F}) + C # optional - sage.rings.finite_rings + sage: g = G.mod(y^8 + y) # optional - sage.rings.finite_rings + sage: g.degree(y) # optional - sage.rings.finite_rings 7 """ return self % other @@ -2938,7 +2956,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _mul_generic(self, right): """ - Compute the product of self and right using the classical quadratic + Compute the product of ``self`` and ``right`` using the classical quadratic algorithm. This method is the default for inexact rings. For two polynomials of degree n and m this method needs @@ -2954,21 +2972,21 @@ cdef class Polynomial(CommutativePolynomial): Show the product in the symbolic ring:: - sage: L = SR['x'] - sage: var('a0,a1,b0,b1') + sage: L = SR['x'] # optional - sage.symbolic + sage: var('a0,a1,b0,b1') # optional - sage.symbolic (a0, a1, b0, b1) - sage: L([a0,a1])._mul_generic(L([b0,b1])) + sage: L([a0, a1])._mul_generic(L([b0, b1])) # optional - sage.symbolic a1*b1*x^2 + (a1*b0 + a0*b1)*x + a0*b0 A non-commutative example:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A) - sage: f = i*w + j - sage: g = k*w + 1 - sage: f._mul_generic(g) + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A) # optional - sage.combinat sage.modules + sage: f = i*w + j # optional - sage.combinat sage.modules + sage: g = k*w + 1 # optional - sage.combinat sage.modules + sage: f._mul_generic(g) # optional - sage.combinat sage.modules -j*w^2 + 2*i*w + j - sage: g._mul_generic(f) + sage: g._mul_generic(f) # optional - sage.combinat sage.modules j*w^2 + j @@ -3098,7 +3116,7 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``self`` - Polynomial - - ``right`` - Polynomial (over same base ring as self) + - ``right`` - Polynomial (over same base ring as ``self``) - ``K_threshold`` - (optional) Integer. A threshold to fall back to schoolbook algorithm. In the recursion, if one of the polynomials is of degree less that K_threshold then the classic quadratic @@ -3172,23 +3190,23 @@ cdef class Polynomial(CommutativePolynomial): Show the product in the symbolic ring:: - sage: L = SR['x'] - sage: var('a0,a1,b0,b1') + sage: L = SR['x'] # optional - sage.symbolic + sage: var('a0,a1,b0,b1') # optional - sage.symbolic (a0, a1, b0, b1) - sage: L([a0,a1])._mul_karatsuba(L([b0,b1]),0) + sage: L([a0, a1])._mul_karatsuba(L([b0, b1]), 0) # optional - sage.symbolic a1*b1*x^2 + ((a0 + a1)*(b0 + b1) - a0*b0 - a1*b1)*x + a0*b0 - sage: L([a0,a1])._mul_karatsuba(L([b0,b1]),2) + sage: L([a0, a1])._mul_karatsuba(L([b0, b1]), 2) # optional - sage.symbolic a1*b1*x^2 + (a1*b0 + a0*b1)*x + a0*b0 A noncommutative example:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A) - sage: f = i*w + j - sage: g = k*w + 1 - sage: f._mul_karatsuba(g,0) + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A) # optional - sage.combinat sage.modules + sage: f = i*w + j # optional - sage.combinat sage.modules + sage: g = k*w + 1 # optional - sage.combinat sage.modules + sage: f._mul_karatsuba(g,0) # optional - sage.combinat sage.modules -j*w^2 + 2*i*w + j - sage: g._mul_karatsuba(f,0) + sage: g._mul_karatsuba(f,0) # optional - sage.combinat sage.modules j*w^2 + j TESTS:: @@ -3214,28 +3232,28 @@ cdef class Polynomial(CommutativePolynomial): Random tests for noncommutative rings:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A) - sage: f = R.random_element(randint(10,100)) - sage: g = R.random_element(randint(10,100)) - sage: f._mul_generic(g) == f._mul_karatsuba(g,0) + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A) # optional - sage.combinat sage.modules + sage: f = R.random_element(randint(10,100)) # optional - sage.combinat sage.modules + sage: g = R.random_element(randint(10,100)) # optional - sage.combinat sage.modules + sage: f._mul_generic(g) == f._mul_karatsuba(g,0) # optional - sage.combinat sage.modules True - sage: f._mul_generic(g) == f._mul_karatsuba(g,16) + sage: f._mul_generic(g) == f._mul_karatsuba(g,16) # optional - sage.combinat sage.modules True - sage: g = R.random_element(0) - sage: f._mul_karatsuba(g,0) == f._mul_generic(g) + sage: g = R.random_element(0) # optional - sage.combinat sage.modules + sage: f._mul_karatsuba(g,0) == f._mul_generic(g) # optional - sage.combinat sage.modules True - sage: g._mul_karatsuba(f,0) == g._mul_generic(f) + sage: g._mul_karatsuba(f,0) == g._mul_generic(f) # optional - sage.combinat sage.modules True Polynomials over matrices:: - sage: K = PolynomialRing(MatrixSpace(QQ,2),'x') - sage: f = K.random_element(randint(5,10)) - sage: g = K.random_element(randint(5,10)) - sage: h1 = f._mul_generic(g) - sage: h2 = f._mul_karatsuba(g,randint(0,10)) - sage: h1 == h2 + sage: K = PolynomialRing(MatrixSpace(QQ, 2), 'x') # optional - sage.modules + sage: f = K.random_element(randint(5, 10)) # optional - sage.modules + sage: g = K.random_element(randint(5, 10)) # optional - sage.modules + sage: h1 = f._mul_generic(g) # optional - sage.modules + sage: h2 = f._mul_karatsuba(g,randint(0, 10)) # optional - sage.modules + sage: h1 == h2 # optional - sage.modules True """ if self.is_zero(): @@ -3284,32 +3302,32 @@ cdef class Polynomial(CommutativePolynomial): def base_ring(self): """ - Return the base ring of the parent of self. + Return the base ring of the parent of ``self``. EXAMPLES:: sage: R. = ZZ[] sage: x.base_ring() Integer Ring - sage: (2*x+3).base_ring() + sage: (2*x + 3).base_ring() Integer Ring """ return self._parent.base_ring() cpdef base_extend(self, R): """ - Return a copy of this polynomial but with coefficients in R, if - there is a natural map from coefficient ring of self to R. + Return a copy of this polynomial but with coefficients in ``R``, if + there is a natural map from the coefficient ring of ``self`` to ``R``. EXAMPLES:: sage: R. = QQ[] sage: f = x^3 - 17*x + 3 - sage: f.base_extend(GF(7)) + sage: f.base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no such base extension - sage: f.change_ring(GF(7)) + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings x^3 + 4*x + 3 """ S = self._parent.base_extend(R) @@ -3342,17 +3360,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: f = K.defining_polynomial() - sage: f.change_ring(GF(7)) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: f = K.defining_polynomial() # optional - sage.rings.number_field + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings # optional - sage.rings.number_field x^2 + x + 1 :: - sage: K. = CyclotomicField(3) - sage: R. = K[] - sage: f = x^2 + z - sage: f.change_ring(K.embeddings(CC)[1]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + z # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(CC)[1]) # optional - sage.rings.number_field x^2 - 0.500000000000000 - 0.866025403784438*I :: @@ -3374,10 +3392,10 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28541` is fixed:: - sage: F. = GF(7^2) - sage: S. = F[] - sage: P = x^2 + a*x + a^2 - sage: P.change_ring(F.frobenius_endomorphism()) + sage: F. = GF(7^2) # optional - sage.rings.finite_rings + sage: S. = F[] # optional - sage.rings.finite_rings + sage: P = x^2 + a*x + a^2 # optional - sage.rings.finite_rings + sage: P.change_ring(F.frobenius_endomorphism()) # optional - sage.rings.finite_rings x^2 + (6*a + 1)*x + 6*a + 5 """ if isinstance(R, Map): @@ -3442,8 +3460,9 @@ cdef class Polynomial(CommutativePolynomial): def __copy__(self): """ - Return a "copy" of self. This is just self, since in Sage - polynomials are immutable this just returns self again. + Return a "copy" of ``self``. + + This is just ``self``, since in Sage polynomials are immutable. EXAMPLES: @@ -3521,20 +3540,20 @@ cdef class Polynomial(CommutativePolynomial): def denominator(self): """ - Return a denominator of self. + Return a denominator of ``self``. - First, the lcm of the denominators of the entries of self + First, the lcm of the denominators of the entries of ``self`` is computed and returned. If this computation fails, the - unit of the parent of self is returned. + unit of the parent of ``self`` is returned. Note that some subclasses may implement their own - denominator function. For example, see + :meth:`denominator` method. For example, see :class:`sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint` .. warning:: This is not the denominator of the rational function - defined by self, which would always be 1 since self is a + defined by ``self``, which would always be 1 since ``self`` is a polynomial. EXAMPLES: @@ -3562,7 +3581,7 @@ cdef class Polynomial(CommutativePolynomial): Finally, we try to compute the denominator of a polynomial with coefficients in the real numbers, which is a ring whose elements do - not have a denominator method. + not have a :meth:`denominator` method. :: @@ -3573,17 +3592,17 @@ cdef class Polynomial(CommutativePolynomial): 1.00000000000000 Check that the denominator is an element over the base whenever the base - has no denominator function. This closes :trac:`9063`. :: + has no :meth:`denominator` method. This closes :trac:`9063`. :: - sage: R. = GF(5)[] - sage: x = R(0) - sage: x.denominator() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: x = R(0) # optional - sage.rings.finite_rings + sage: x.denominator() # optional - sage.rings.finite_rings 1 - sage: type(x.denominator()) + sage: type(x.denominator()) # optional - sage.rings.finite_rings - sage: isinstance(x.numerator() / x.denominator(), Polynomial) + sage: isinstance(x.numerator() / x.denominator(), Polynomial) # optional - sage.rings.finite_rings True - sage: isinstance(x.numerator() / R(1), Polynomial) + sage: isinstance(x.numerator() / R(1), Polynomial) # optional - sage.rings.finite_rings False TESTS: @@ -3609,7 +3628,7 @@ cdef class Polynomial(CommutativePolynomial): def numerator(self): """ - Return a numerator of self computed as self * self.denominator() + Return a numerator of ``self``, computed as ``self * self.denominator()`` Note that some subclasses may implement its own numerator function. For example, see @@ -3618,13 +3637,13 @@ cdef class Polynomial(CommutativePolynomial): .. warning:: This is not the numerator of the rational function - defined by self, which would always be self since self is a + defined by ``self``, which would always be ``self`` since ``self`` is a polynomial. EXAMPLES: First we compute the numerator of a polynomial with - integer coefficients, which is of course self. + integer coefficients, which is of course ``self``. :: @@ -3660,17 +3679,17 @@ cdef class Polynomial(CommutativePolynomial): sage: f.numerator() x + 0.300000000000000 - We check that the computation the numerator and denominator - are valid + We check that the computation of the numerator and denominator + are valid. :: - sage: K=NumberField(symbolic_expression('x^3+2'),'a')['s,t']['x'] - sage: f=K.random_element() - sage: f.numerator() / f.denominator() == f + sage: K = NumberField(symbolic_expression('x^3+2'), 'a')['s,t']['x'] # optional - sage.rings.number_field sage.symbolic + sage: f = K.random_element() # optional - sage.rings.number_field sage.symbolic + sage: f.numerator() / f.denominator() == f # optional - sage.rings.number_field sage.symbolic True - sage: R=RR['x'] - sage: f=R.random_element() + sage: R = RR['x'] + sage: f = R.random_element() sage: f.numerator() / f.denominator() == f True """ @@ -3679,10 +3698,10 @@ cdef class Polynomial(CommutativePolynomial): def derivative(self, *args): r""" The formal derivative of this polynomial, with respect to variables - supplied in args. + supplied in ``args``. Multiple variables and iteration counts may be supplied; see - documentation for the global derivative() function for more + documentation for the global :func:`derivative` function for more details. .. SEEALSO:: @@ -3780,17 +3799,17 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28147` is fixed:: - sage: R. = GF(65537)[] - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 - sage: p.derivative() + sage: R. = GF(65537)[] # optional - sage.rings.finite_rings + sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 # optional - sage.rings.finite_rings + sage: p.derivative() # optional - sage.rings.finite_rings 4*x^3 + 65486*x^2 + 4*x + 65536 - sage: R. = GF(19^2)[] - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 - sage: p.derivative() + sage: R. = GF(19^2)[] # optional - sage.rings.finite_rings + sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 # optional - sage.rings.finite_rings + sage: p.derivative() # optional - sage.rings.finite_rings 4*x^3 + 6*x^2 + 4*x + 18 - sage: R. = GF(2)[] - sage: p = x^4 + x^2 + x - sage: p.derivative() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: p = x^4 + x^2 + x # optional - sage.rings.finite_rings + sage: p.derivative() # optional - sage.rings.finite_rings 1 sage: R. = Integers(77)[] @@ -3805,8 +3824,8 @@ cdef class Polynomial(CommutativePolynomial): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var("y") - sage: f._derivative(y) + sage: y = var("y") # optional - sage.symbolic + sage: f._derivative(y) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -3814,21 +3833,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`26844` is fixed by :trac:`28147`:: - sage: A = PolynomialRing(GF(3), name='t') - sage: K = A.fraction_field() - sage: t = K.gen() - sage: t.derivative(t) + sage: A = PolynomialRing(GF(3), name='t') # optional - sage.rings.finite_rings + sage: K = A.fraction_field() # optional - sage.rings.finite_rings + sage: t = K.gen() # optional - sage.rings.finite_rings + sage: t.derivative(t) # optional - sage.rings.finite_rings 1 Check that :trac:`28187` is fixed:: - sage: R. = GF(65537)[] - sage: x._derivative(2*x) + sage: R. = GF(65537)[] # optional - sage.rings.finite_rings + sage: x._derivative(2*x) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var('y') - sage: R.gen()._derivative(y) + sage: y = var('y') # optional - sage.symbolic + sage: R.gen()._derivative(y) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -3905,16 +3924,16 @@ cdef class Polynomial(CommutativePolynomial): This shows that the issue at :trac:`7711` is resolved:: - sage: P. = PolynomialRing(GF(2147483647)) - sage: Q. = PolynomialRing(P) - sage: p=x+y+z - sage: p.integral() + sage: P. = PolynomialRing(GF(2147483647)) # optional - sage.rings.finite_rings + sage: Q. = PolynomialRing(P) # optional - sage.rings.finite_rings + sage: p = x + y + z # optional - sage.rings.finite_rings + sage: p.integral() # optional - sage.rings.finite_rings -1073741823*y^2 + (x + z)*y - sage: P. = PolynomialRing(GF(next_prime(2147483647))) - sage: Q. = PolynomialRing(P) - sage: p=x+y+z - sage: p.integral() + sage: P. = PolynomialRing(GF(next_prime(2147483647))) # optional - sage.rings.finite_rings + sage: Q. = PolynomialRing(P) # optional - sage.rings.finite_rings + sage: p = x + y + z # optional - sage.rings.finite_rings + sage: p.integral() # optional - sage.rings.finite_rings 1073741830*y^2 + (x + z)*y A truly convoluted example:: @@ -3946,7 +3965,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: t = PolynomialRing(R,'t').gen() - sage: f = x*t +5*t^2 + sage: f = x*t + 5*t^2 sage: f.integral(x) 5*x*t^2 + 1/2*x^2*t @@ -4047,38 +4066,39 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = (x^3 - 1)^2 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (x - 1)^2 * (x^2 + x + 1)^2 Since `\QQ` is a field, the irreducible factors are monic:: sage: f = 10*x^5 - 1 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (10) * (x^5 - 1/10) sage: f = 10*x^5 - 10 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) Over `\ZZ` the irreducible factors need not be monic:: sage: x = ZZ['x'].0 sage: f = 10*x^5 - 1 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari 10*x^5 - 1 We factor a non-monic polynomial over a finite field of 25 elements:: - sage: k. = GF(25) - sage: R. = k[] - sage: f = 2*x^10 + 2*x + 2*a - sage: F = f.factor(); F - (2) * (x + a + 2) * (x^2 + 3*x + 4*a + 4) * (x^2 + (a + 1)*x + a + 2) * (x^5 + (3*a + 4)*x^4 + (3*a + 3)*x^3 + 2*a*x^2 + (3*a + 1)*x + 3*a + 1) + sage: k. = GF(25) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: f = 2*x^10 + 2*x + 2*a # optional - sage.rings.finite_rings + sage: F = f.factor(); F # optional - sage.rings.finite_rings + (2) * (x + a + 2) * (x^2 + 3*x + 4*a + 4) * (x^2 + (a + 1)*x + a + 2) + * (x^5 + (3*a + 4)*x^4 + (3*a + 3)*x^3 + 2*a*x^2 + (3*a + 1)*x + 3*a + 1) Notice that the unit factor is included when we multiply `F` back out:: - sage: expand(F) + sage: expand(F) # optional - sage.rings.finite_rings 2*x^10 + 2*x + 2*a A new ring. In the example below, we set the special method @@ -4087,15 +4107,18 @@ cdef class Polynomial(CommutativePolynomial): used to easily extend polynomial factorization to work over new rings you introduce:: - sage: R. = PolynomialRing(IntegerModRing(4),implementation="NTL") - sage: (x^2).factor() + sage: R. = PolynomialRing(IntegerModRing(4), implementation="NTL") # optional - sage.libs.ntl + sage: (x^2).factor() # optional - sage.libs.ntl Traceback (most recent call last): ... - NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented - sage: R.base_ring()._factor_univariate_polynomial = lambda f: f.change_ring(ZZ).factor() - sage: (x^2).factor() + NotImplementedError: factorization of polynomials over rings with + composite characteristic is not implemented + sage: def my_factor(f): + ....: return f.change_ring(ZZ).factor() + sage: R.base_ring()._factor_univariate_polynomial = my_factor # optional - sage.libs.ntl + sage: (x^2).factor() # optional - sage.libs.ntl sage.libs.pari x^2 - sage: del R.base_ring()._factor_univariate_polynomial # clean up + sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl Arbitrary precision real and complex factorization:: @@ -4123,24 +4146,26 @@ cdef class Polynomial(CommutativePolynomial): Over a number field:: - sage: K. = CyclotomicField(15) - sage: x = polygen(K) - sage: ((x^3 + z*x + 1)^3*(x - z)).factor() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: ((x^3 + z*x + 1)^3 * (x - z)).factor() # optional - sage.rings.number_field (x - z) * (x^3 + z*x + 1)^3 - sage: cyclotomic_polynomial(12).change_ring(K).factor() + sage: cyclotomic_polynomial(12).change_ring(K).factor() # optional - sage.rings.number_field (x^2 - z^5 - 1) * (x^2 + z^5) - sage: ((x^3 + z*x + 1)^3*(x/(z+2) - 1/3)).factor() - (-1/331*z^7 + 3/331*z^6 - 6/331*z^5 + 11/331*z^4 - 21/331*z^3 + 41/331*z^2 - 82/331*z + 165/331) * (x - 1/3*z - 2/3) * (x^3 + z*x + 1)^3 + sage: ((x^3 + z*x + 1)^3 * (x/(z+2) - 1/3)).factor() # optional - sage.rings.number_field + (-1/331*z^7 + 3/331*z^6 - 6/331*z^5 + 11/331*z^4 + - 21/331*z^3 + 41/331*z^2 - 82/331*z + 165/331) + * (x - 1/3*z - 2/3) * (x^3 + z*x + 1)^3 Over a relative number field:: sage: x = polygen(QQ) - sage: K. = CyclotomicField(3) - sage: L. = K.extension(x^3 - 2) - sage: t = polygen(L, 't') - sage: f = (t^3 + t + a)*(t^5 + t + z); f + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 2) # optional - sage.rings.number_field + sage: t = polygen(L, 't') # optional - sage.rings.number_field + sage: f = (t^3 + t + a) * (t^5 + t + z); f # optional - sage.rings.number_field t^8 + t^6 + a*t^5 + t^4 + z*t^3 + t^2 + (a + z)*t + z*a - sage: f.factor() + sage: f.factor() # optional - sage.rings.number_field (t^3 + t + a) * (t^5 + t + z) Over the real double field:: @@ -4168,9 +4193,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = (x^2 + 2*R(I))^3 sage: F = f.factor() sage: F # abs tol 3e-5 - (x - 1.0000138879287663 + 1.0000013435286879*I) * (x - 0.9999942196864997 + 0.9999873009803959*I) * (x - 0.9999918923847313 + 1.0000113554909125*I) * (x + 0.9999908759550227 - 1.0000069659624138*I) * (x + 0.9999985293216753 - 0.9999886153831807*I) * (x + 1.0000105947233 - 1.0000044186544053*I) + (x - 1.0000138879287663 + 1.0000013435286879*I) * (x - 0.9999942196864997 + 0.9999873009803959*I) * (x - 0.9999918923847313 + 1.0000113554909125*I) + * (x + 0.9999908759550227 - 1.0000069659624138*I) * (x + 0.9999985293216753 - 0.9999886153831807*I) * (x + 1.0000105947233 - 1.0000044186544053*I) sage: [f(t[0][0]).abs() for t in F] # abs tol 1e-13 - [1.979365054e-14, 1.97936298566e-14, 1.97936990747e-14, 3.6812407475e-14, 3.65211563729e-14, 3.65220890052e-14] + [1.979365054e-14, 1.97936298566e-14, 1.97936990747e-14, + 3.6812407475e-14, 3.65211563729e-14, 3.65220890052e-14] Factoring polynomials over `\ZZ/n\ZZ` for composite `n` is not implemented:: @@ -4185,16 +4212,22 @@ cdef class Polynomial(CommutativePolynomial): Factoring polynomials over the algebraic numbers (see :trac:`8544`):: - sage: R. = QQbar[] - sage: (x^8-1).factor() - (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) * (x + 0.7071067811865475? - 0.7071067811865475?*I) * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^8 - 1).factor() # optional - sage.rings.number_field + (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) + * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) + * (x + 0.7071067811865475? - 0.7071067811865475?*I) + * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1) Factoring polynomials over the algebraic reals (see :trac:`8544`):: - sage: R. = AA[] - sage: (x^8+1).factor() - (x^2 - 1.847759065022574?*x + 1.000000000000000?) * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 1.847759065022574?*x + 1.000000000000000?) + sage: R. = AA[] # optional - sage.rings.number_field + sage: (x^8 + 1).factor() # optional - sage.rings.number_field + (x^2 - 1.847759065022574?*x + 1.000000000000000?) + * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) + * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) + * (x^2 + 1.847759065022574?*x + 1.000000000000000?) TESTS: @@ -4215,91 +4248,94 @@ cdef class Polynomial(CommutativePolynomial): sage: f = 8*x^9 + 42*x^6 + 6*x^3 - 1 sage: g = x^24 - 12*x^23 + 72*x^22 - 286*x^21 + 849*x^20 - 2022*x^19 + 4034*x^18 - 6894*x^17 + 10182*x^16 - 13048*x^15 + 14532*x^14 - 13974*x^13 + 11365*x^12 - 7578*x^11 + 4038*x^10 - 1766*x^9 + 762*x^8 - 408*x^7 + 236*x^6 - 126*x^5 + 69*x^4 - 38*x^3 + 18*x^2 - 6*x + 1 sage: assert g.is_irreducible() - sage: K. = NumberField(g) - sage: len(f.roots(K)) + sage: K. = NumberField(g) # optional - sage.rings.number_field + sage: len(f.roots(K)) # optional - sage.rings.number_field 9 sage: f.factor() (8) * (x^3 + 1/4) * (x^6 + 5*x^3 - 1/2) - sage: f.change_ring(K).factor() + sage: f.change_ring(K).factor() # optional - sage.rings.number_field (8) * (x - 3260097/3158212*a^22 + 35861067/3158212*a^21 - 197810817/3158212*a^20 + 722970825/3158212*a^19 - 1980508347/3158212*a^18 + 4374189477/3158212*a^17 - 4059860553/1579106*a^16 + 6442403031/1579106*a^15 - 17542341771/3158212*a^14 + 20537782665/3158212*a^13 - 20658463789/3158212*a^12 + 17502836649/3158212*a^11 - 11908953451/3158212*a^10 + 6086953981/3158212*a^9 - 559822335/789553*a^8 + 194545353/789553*a^7 - 505969453/3158212*a^6 + 338959407/3158212*a^5 - 155204647/3158212*a^4 + 79628015/3158212*a^3 - 57339525/3158212*a^2 + 26692783/3158212*a - 1636338/789553) * ... - sage: f = QQbar['x'](1) - sage: f.factor() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.factor() # optional - sage.rings.number_field 1 Factorization also works even if the variable of the finite field is nefariously labeled `x`:: - sage: R. = GF(3^2, 'x')[] - sage: f = x^10 +7*x -13 - sage: G = f.factor(); G - (x + x) * (x + 2*x + 1) * (x^4 + (x + 2)*x^3 + (2*x + 2)*x + 2) * (x^4 + 2*x*x^3 + (x + 1)*x + 2) + sage: R. = GF(3^2, 'x')[] # optional - sage.rings.finite_rings + sage: f = x^10 +7*x -13 # optional - sage.rings.finite_rings + sage: G = f.factor(); G # optional - sage.rings.finite_rings + (x + x) * (x + 2*x + 1) * (x^4 + (x + 2)*x^3 + (2*x + 2)*x + 2) + * (x^4 + 2*x*x^3 + (x + 1)*x + 2) sage: prod(G) == f True :: - sage: R. = GF(9,'x')[] # purposely calling it x to test robustness - sage: f = x0^3 + x0 + 1 - sage: f.factor() + sage: R. = GF(9,'x')[] # purposely calling it x to test robustness # optional - sage.rings.finite_rings + sage: f = x0^3 + x0 + 1 # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings (x0 + 2) * (x0 + x) * (x0 + 2*x + 1) - sage: f = 0*x0 - sage: f.factor() + sage: f = 0*x0 # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined :: - sage: f = x0^0 - sage: f.factor() + sage: f = x0^0 # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings 1 Over a complicated number field:: sage: x = polygen(QQ, 'x') sage: f = x^6 + 10/7*x^5 - 867/49*x^4 - 76/245*x^3 + 3148/35*x^2 - 25944/245*x + 48771/1225 - sage: K. = NumberField(f) - sage: S. = K[] - sage: ff = S(f); ff + sage: K. = NumberField(f) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: ff = S(f); ff # optional - sage.rings.number_field T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/1225 - sage: F = ff.factor() - sage: len(F) + sage: F = ff.factor() # optional - sage.rings.number_field + sage: len(F) # optional - sage.rings.number_field 4 - sage: F[:2] - [(T - a, 1), (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^4 + 527617096480/924556084127*a^3 + 1289745809920/924556084127*a^2 - 3227142391585/924556084127*a - 401502691578/924556084127, 1)] - sage: expand(F) + sage: F[:2] # optional - sage.rings.number_field + [(T - a, 1), + (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^4 + 527617096480/924556084127*a^3 + + 1289745809920/924556084127*a^2 - 3227142391585/924556084127*a - 401502691578/924556084127, 1)] + sage: expand(F) # optional - sage.rings.number_field T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/1225 :: sage: f = x^2 - 1/3 - sage: K. = NumberField(f) - sage: A. = K[] - sage: A(x^2 - 1).factor() + sage: K. = NumberField(f) # optional - sage.rings.number_field + sage: A. = K[] # optional - sage.rings.number_field + sage: A(x^2 - 1).factor() # optional - sage.rings.number_field (T - 1) * (T + 1) :: - sage: A(3*x^2 - 1).factor() + sage: A(3*x^2 - 1).factor() # optional - sage.rings.number_field (3) * (T - a) * (T + a) :: - sage: A(x^2 - 1/3).factor() + sage: A(x^2 - 1/3).factor() # optional - sage.rings.number_field (T - a) * (T + a) Test that :trac:`10279` is fixed:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(t^4 - t^2 + 1) - sage: pol = t^3 + (-4*a^3 + 2*a)*t^2 - 11/3*a^2*t + 2/3*a^3 - 4/3*a - sage: pol.factor() + sage: K. = NumberField(t^4 - t^2 + 1) # optional - sage.rings.number_field + sage: pol = t^3 + (-4*a^3 + 2*a)*t^2 - 11/3*a^2*t + 2/3*a^3 - 4/3*a # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (t - 2*a^3 + a) * (t - 4/3*a^3 + 2/3*a) * (t - 2/3*a^3 + 1/3*a) Test that this factorization really uses ``nffactor()`` internally:: sage: pari.default("debug", 3) - sage: F = pol.factor() + sage: F = pol.factor() # optional - sage.rings.number_field Entering nffactor: ... @@ -4308,55 +4344,55 @@ cdef class Polynomial(CommutativePolynomial): Test that :trac:`10369` is fixed:: sage: x = polygen(QQ) - sage: K. = NumberField(x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) - sage: R. = PolynomialRing(K) + sage: K. = NumberField(x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field - sage: pol = (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7)*t^10 + (4/7*a^5 - 2/7*a^4 - 2/7*a^3 - 2/7*a^2 - 2/7*a - 6/7)*t^9 + (90/49*a^5 + 152/49*a^4 + 18/49*a^3 + 24/49*a^2 + 30/49*a + 36/49)*t^8 + (-10/49*a^5 + 10/7*a^4 + 198/49*a^3 - 102/49*a^2 - 60/49*a - 26/49)*t^7 + (40/49*a^5 + 45/49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49)*t^6 + (90/49*a^5 + 110/49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 + 250/49*a^3 + 232/49*a^2 + 32/7*a + 8)*t^4 + (-184/49*a^5 - 58/49*a^4 - 52/49*a^3 - 66/49*a^2 - 72/49*a - 72/49)*t^3 + (18/49*a^5 - 32/49*a^4 + 10/49*a^3 + 4/49*a^2)*t^2 + (2/49*a^4 - 4/49*a^3 + 2/49*a^2)*t - sage: pol.factor() + sage: pol = (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7)*t^10 + (4/7*a^5 - 2/7*a^4 - 2/7*a^3 - 2/7*a^2 - 2/7*a - 6/7)*t^9 + (90/49*a^5 + 152/49*a^4 + 18/49*a^3 + 24/49*a^2 + 30/49*a + 36/49)*t^8 + (-10/49*a^5 + 10/7*a^4 + 198/49*a^3 - 102/49*a^2 - 60/49*a - 26/49)*t^7 + (40/49*a^5 + 45/49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49)*t^6 + (90/49*a^5 + 110/49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 + 250/49*a^3 + 232/49*a^2 + 32/7*a + 8)*t^4 + (-184/49*a^5 - 58/49*a^4 - 52/49*a^3 - 66/49*a^2 - 72/49*a - 72/49)*t^3 + (18/49*a^5 - 32/49*a^4 + 10/49*a^3 + 4/49*a^2)*t^2 + (2/49*a^4 - 4/49*a^3 + 2/49*a^2)*t # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7) * t * (t - a^5 - a^4 - a^3 - a^2 - a - 1)^4 * (t^5 + (-12/7*a^5 - 10/7*a^4 - 8/7*a^3 - 6/7*a^2 - 4/7*a - 2/7)*t^4 + (12/7*a^5 - 8/7*a^3 + 16/7*a^2 + 2/7*a + 20/7)*t^3 + (-20/7*a^5 - 20/7*a^3 - 20/7*a^2 + 4/7*a - 2)*t^2 + (12/7*a^5 + 12/7*a^3 + 2/7*a + 16/7)*t - 4/7*a^5 - 4/7*a^3 - 4/7*a - 2/7) - sage: pol = (1/7*a^2 - 1/7*a)*t^10 + (4/7*a - 6/7)*t^9 + (102/49*a^5 + 99/49*a^4 + 96/49*a^3 + 93/49*a^2 + 90/49*a + 150/49)*t^8 + (-160/49*a^5 - 36/49*a^4 - 48/49*a^3 - 8/7*a^2 - 60/49*a - 60/49)*t^7 + (30/49*a^5 - 55/49*a^4 + 20/49*a^3 + 5/49*a^2)*t^6 + (6/49*a^4 - 12/49*a^3 + 6/49*a^2)*t^5 - sage: pol.factor() + sage: pol = (1/7*a^2 - 1/7*a)*t^10 + (4/7*a - 6/7)*t^9 + (102/49*a^5 + 99/49*a^4 + 96/49*a^3 + 93/49*a^2 + 90/49*a + 150/49)*t^8 + (-160/49*a^5 - 36/49*a^4 - 48/49*a^3 - 8/7*a^2 - 60/49*a - 60/49)*t^7 + (30/49*a^5 - 55/49*a^4 + 20/49*a^3 + 5/49*a^2)*t^6 + (6/49*a^4 - 12/49*a^3 + 6/49*a^2)*t^5 # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (1/7*a^2 - 1/7*a) * t^5 * (t^5 + (-40/7*a^5 - 38/7*a^4 - 36/7*a^3 - 34/7*a^2 - 32/7*a - 30/7)*t^4 + (60/7*a^5 - 30/7*a^4 - 18/7*a^3 - 9/7*a^2 - 3/7*a)*t^3 + (60/7*a^4 - 40/7*a^3 - 16/7*a^2 - 4/7*a)*t^2 + (30/7*a^3 - 25/7*a^2 - 5/7*a)*t + 6/7*a^2 - 6/7*a) - sage: pol = x^10 + (4/7*a - 6/7)*x^9 + (9/49*a^2 - 3/7*a + 15/49)*x^8 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^7 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x^6 + (-6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807)*x^5 - sage: pol.factor() + sage: pol = x^10 + (4/7*a - 6/7)*x^9 + (9/49*a^2 - 3/7*a + 15/49)*x^8 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^7 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x^6 + (-6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807)*x^5 # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field x^5 * (x^5 + (4/7*a - 6/7)*x^4 + (9/49*a^2 - 3/7*a + 15/49)*x^3 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^2 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x - 6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807) Factoring over a number field over which we cannot factor the discriminant by trial division:: sage: x = polygen(QQ) - sage: K. = NumberField(x^16 - x - 6) - sage: R. = PolynomialRing(K) - sage: f = (x+a)^50 - (a-1)^50 - sage: len(factor(f)) + sage: K. = NumberField(x^16 - x - 6) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = (x+a)^50 - (a-1)^50 # optional - sage.rings.number_field + sage: len(factor(f)) # optional - sage.rings.number_field 6 - sage: pari(K.discriminant()).factor(limit=10^6) + sage: pari(K.discriminant()).factor(limit=10^6) # optional - sage.rings.number_field [-1, 1; 3, 15; 23, 1; 887, 1; 12583, 1; 2354691439917211, 1] - sage: factor(K.discriminant()) + sage: factor(K.discriminant()) # optional - sage.rings.number_field -1 * 3^15 * 23 * 887 * 12583 * 6335047 * 371692813 Factoring over a number field over which we cannot factor the discriminant and over which `nffactor()` fails:: sage: p = next_prime(10^50); q = next_prime(10^51); n = p*q - sage: K. = QuadraticField(p*q) - sage: R. = PolynomialRing(K) - sage: K.pari_polynomial('a').nffactor("x^2+1") + sage: K. = QuadraticField(p*q) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: K.pari_polynomial('a').nffactor("x^2+1") # optional - sage.rings.number_field Mat([x^2 + 1, 1]) - sage: factor(x^2 + 1) + sage: factor(x^2 + 1) # optional - sage.rings.number_field x^2 + 1 - sage: factor( (x - a) * (x + 2*a) ) + sage: factor((x - a) * (x + 2*a)) # optional - sage.rings.number_field (x - a) * (x + 2*a) A test where nffactor used to fail without a nf structure:: sage: x = polygen(QQ) - sage: K = NumberField([x^2-1099511627777, x^3-3],'a') - sage: x = polygen(K) - sage: f = x^3 - 3 - sage: factor(f) + sage: K = NumberField([x^2-1099511627777, x^3-3], 'a') # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: f = x^3 - 3 # optional - sage.rings.number_field + sage: factor(f) # optional - sage.rings.number_field (x - a1) * (x^2 + a1*x + a1^2) We check that :trac:`7554` is fixed:: @@ -4538,31 +4574,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R.=PolynomialRing(ZZ) sage: f = (2*x + 1) * (3*x^2 - 5)^2 - sage: f._factor_pari_helper(pari(f).factor()) + sage: f._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (2*x + 1) * (3*x^2 - 5)^2 - sage: f._factor_pari_helper(pari(f).factor(), unit=11) + sage: f._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari 11 * (2*x + 1) * (3*x^2 - 5)^2 - sage: (8*f)._factor_pari_helper(pari(f).factor()) + sage: (8*f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari 8 * (2*x + 1) * (3*x^2 - 5)^2 - sage: (8*f)._factor_pari_helper(pari(f).factor(), unit=11) + sage: (8*f)._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari 88 * (2*x + 1) * (3*x^2 - 5)^2 - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor(), unit=11) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari (198) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) - sage: F = f._factor_pari_helper(pari(f).factor()); F + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari + sage: F = f._factor_pari_helper(pari(f).factor()); F # optional - sage.libs.pari 1323551250 * (2*x^2 + 1) * (3*x^3 + 1)^2 * (5*x^5 + 1)^4 * (7*x^7 + 1)^6 - sage: F.prod() == f + sage: F.prod() == f # optional - sage.libs.pari True - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: g = GF(19)['x'](f) - sage: G = g._factor_pari_helper(pari(g).factor()); G - (4) * (x + 3) * (x + 16)^5 * (x + 11)^6 * (x^2 + 7*x + 9)^4 * (x^2 + 15*x + 9)^4 * (x^3 + 13)^2 * (x^6 + 8*x^5 + 7*x^4 + 18*x^3 + 11*x^2 + 12*x + 1)^6 - sage: G.prod() == g + sage: g = GF(19)['x'](f) # optional - sage.libs.pari + sage: G = g._factor_pari_helper(pari(g).factor()); G # optional - sage.libs.pari + (4) * (x + 3) * (x + 16)^5 * (x + 11)^6 * (x^2 + 7*x + 9)^4 + * (x^2 + 15*x + 9)^4 * (x^3 + 13)^2 + * (x^6 + 8*x^5 + 7*x^4 + 18*x^3 + 11*x^2 + 12*x + 1)^6 + sage: G.prod() == g # optional - sage.libs.pari True """ pols, exps = G @@ -4623,25 +4661,25 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: K. = (x^3 + 2).splitting_field(); K + sage: K. = (x^3 + 2).splitting_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^6 + 3*x^5 + 6*x^4 + 11*x^3 + 12*x^2 - 3*x + 1 - sage: K. = (x^3 - 3*x + 1).splitting_field(); K + sage: K. = (x^3 - 3*x + 1).splitting_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - 3*x + 1 Relative situation:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^3 + 2) - sage: S. = PolynomialRing(K) - sage: L. = (t^2 - a).splitting_field() - sage: L + sage: K. = NumberField(x^3 + 2) # optional - sage.rings.number_field + sage: S. = PolynomialRing(K) # optional - sage.rings.number_field + sage: L. = (t^2 - a).splitting_field() # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field Number Field in b with defining polynomial t^6 + 2 With ``map=True``, we also get the embedding of the base field into the splitting field:: - sage: L., phi = (t^2 - a).splitting_field(map=True) - sage: phi + sage: L., phi = (t^2 - a).splitting_field(map=True) # optional - sage.rings.number_field + sage: phi # optional - sage.rings.number_field Ring morphism: From: Number Field in a with defining polynomial x^3 + 2 To: Number Field in b with defining polynomial t^6 + 2 @@ -4649,14 +4687,14 @@ cdef class Polynomial(CommutativePolynomial): An example over a finite field:: - sage: P. = PolynomialRing(GF(7)) - sage: t = x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: t = x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 7^2 - sage: P. = PolynomialRing(GF(7^3, 'a')) - sage: t = x^2 + 1 - sage: t.splitting_field('b', map=True) + sage: P. = PolynomialRing(GF(7^3, 'a')) # optional - sage.rings.finite_rings + sage: t = x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b', map=True) # optional - sage.rings.finite_rings (Finite Field in b of size 7^6, Ring morphism: From: Finite Field in a of size 7^3 @@ -4666,13 +4704,13 @@ cdef class Polynomial(CommutativePolynomial): If the extension is trivial and the generators have the same name, the map will be the identity:: - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('a', map=True) + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('a', map=True) # optional - sage.rings.finite_rings (Finite Field in a of size 7^3, Identity endomorphism of Finite Field in a of size 7^3) - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b', map=True) + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b', map=True) # optional - sage.rings.finite_rings (Finite Field in b of size 7^3, Ring morphism: From: Finite Field in a of size 7^3 @@ -4694,48 +4732,48 @@ cdef class Polynomial(CommutativePolynomial): ... NotImplementedError: splitting_field() is only implemented over number fields and finite fields - sage: P. = PolynomialRing(GF(11^5, 'a')) - sage: t = x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(11^5, 'a')) # optional - sage.rings.finite_rings + sage: t = x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 11^10 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 11^30 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 11^130 - sage: P. = PolynomialRing(GF(19^6, 'a')) - sage: t = -x^6 + x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(19^6, 'a')) # optional - sage.rings.finite_rings + sage: t = -x^6 + x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 19^6 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 19^18 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 19^156 - sage: P. = PolynomialRing(GF(83^6, 'a')) - sage: t = 2*x^14 - 5 + 6*x - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(83^6, 'a')) # optional - sage.rings.finite_rings + sage: t = 2*x^14 - 5 + 6*x # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 83^84 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 83^78 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 83^12 - sage: P. = PolynomialRing(GF(401^13, 'a')) - sage: t = 2*x^14 - 5 + 6*x - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(401^13, 'a')) # optional - sage.rings.finite_rings + sage: t = 2*x^14 - 5 + 6*x # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 401^104 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 401^156 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 401^52 sage: R. = QQ[] @@ -4848,7 +4886,7 @@ cdef class Polynomial(CommutativePolynomial): The actual algorithm for computing greatest common divisors depends on the base ring underlying the polynomial ring. If the base ring - defines a method ``_gcd_univariate_polynomial``, then this method + defines a method :meth:`_gcd_univariate_polynomial`, then this method will be called (see examples below). EXAMPLES:: @@ -4864,20 +4902,22 @@ cdef class Polynomial(CommutativePolynomial): One can easily add gcd functionality to new rings by providing a method ``_gcd_univariate_polynomial``:: - sage: O = ZZ[-sqrt(5)] - sage: R. = O[] - sage: a = O.1 - sage: p = x + a - sage: q = x^2 - 5 - sage: p.gcd(q) + sage: O = ZZ[-sqrt(5)] # optional - sage.rings.number_field sage.symbolic + sage: R. = O[] # optional - sage.rings.number_field sage.symbolic + sage: a = O.1 # optional - sage.rings.number_field sage.symbolic + sage: p = x + a # optional - sage.rings.number_field sage.symbolic + sage: q = x^2 - 5 # optional - sage.rings.number_field sage.symbolic + sage: p.gcd(q) # optional - sage.rings.number_field sage.symbolic Traceback (most recent call last): ... - NotImplementedError: Order in Number Field in a with defining polynomial x^2 - 5 with a = -2.236067977499790? does not provide a gcd implementation for univariate polynomials - sage: S. = O.number_field()[] - sage: O._gcd_univariate_polynomial = lambda f,g : R(S(f).gcd(S(g))) - sage: p.gcd(q) + NotImplementedError: Order in Number Field in a + with defining polynomial x^2 - 5 with a = -2.236067977499790? does not + provide a gcd implementation for univariate polynomials + sage: S. = O.number_field()[] # optional - sage.rings.number_field sage.symbolic + sage: O._gcd_univariate_polynomial = lambda f,g : R(S(f).gcd(S(g))) # optional - sage.rings.number_field sage.symbolic + sage: p.gcd(q) # optional - sage.rings.number_field sage.symbolic x + a - sage: del O._gcd_univariate_polynomial + sage: del O._gcd_univariate_polynomial # optional - sage.rings.number_field sage.symbolic Use multivariate implementation for polynomials over polynomials rings:: @@ -4887,7 +4927,7 @@ cdef class Polynomial(CommutativePolynomial): sage: r = 2*x*y + z sage: p = r * (3*x*y*z - 1) sage: q = r * (x + y + z - 2) - sage: p.gcd(q) + sage: p.gcd(q) # optional - sage.libs.singular z + 2*x*y sage: R. = QQ[] @@ -4895,13 +4935,13 @@ cdef class Polynomial(CommutativePolynomial): sage: r = 2*x*y + 1 sage: p = r * (x - 1/2 * y) sage: q = r * (x*y^2 - x + 1/3) - sage: p.gcd(q) + sage: p.gcd(q) # optional - sage.libs.singular 2*x*y + 1 TESTS:: sage: Pol = QQ['x','y']['x'] - sage: Pol.one().gcd(1) + sage: Pol.one().gcd(1) # optional - sage.libs.singular 1 """ cdef Polynomial _other = other @@ -4931,8 +4971,8 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`32033` has been fixed:: - sage: R. = GF(3)[] - sage: lcm(R(0), R(0)) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: lcm(R(0), R(0)) # optional - sage.rings.finite_rings 0 :: @@ -4975,7 +5015,7 @@ cdef class Polynomial(CommutativePolynomial): - (ring theory) A polynomial over a ring is primitive if its coefficients generate the unit ideal. - Calling `is_primitive` on a polynomial over an infinite field will + Calling :meth:`is_primitive` on a polynomial over an infinite field will raise an error. The additional inputs to this function are to speed up computation for @@ -4983,50 +5023,50 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - - ``n`` (default: ``None``) - if provided, should equal - `q-1` where ``self.parent()`` is the field with `q` - elements; otherwise it will be computed. + - ``n`` (default: ``None``) - if provided, should equal + `q-1` where ``self.parent()`` is the field with `q` + elements; otherwise it will be computed. - - ``n_prime_divs`` (default: ``None``) - if provided, should - be a list of the prime divisors of ``n``; otherwise it - will be computed. + - ``n_prime_divs`` (default: ``None``) - if provided, should + be a list of the prime divisors of ``n``; otherwise it + will be computed. .. NOTE:: Computation of the prime divisors of ``n`` can dominate the running time of this method, so performing this computation externally - (e.g. ``pdivs=n.prime_divisors()``) is a good idea for repeated calls + (e.g., ``pdivs = n.prime_divisors()``) is a good idea for repeated calls to is_primitive for polynomials of the same degree. Results may be incorrect if the wrong ``n`` and/or factorization are provided. - EXAMPLES:: + EXAMPLES: - Field semantics examples. + Field semantics examples. - :: + :: - sage: R. = GF(2)['x'] - sage: f = x^4+x^3+x^2+x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: R. = GF(2)['x'] # optional - sage.rings.finite_rings + sage: f = x^4+x^3+x^2+x+1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, False) - sage: f = x^3+x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: f = x^3+x+1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, True) - sage: R. = GF(3)[] - sage: f = x^3-x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: f = x^3-x+1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, True) - sage: f = x^2+1 - sage: f.is_irreducible(), f.is_primitive() + sage: f = x^2+1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, False) - sage: R. = GF(5)[] - sage: f = x^2+x+1 - sage: f.is_primitive() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = x^2+x+1 # optional - sage.rings.finite_rings + sage: f.is_primitive() # optional - sage.rings.finite_rings False - sage: f = x^2-x+2 - sage: f.is_primitive() + sage: f = x^2-x+2 # optional - sage.rings.finite_rings + sage: f.is_primitive() # optional - sage.rings.finite_rings True sage: x=polygen(QQ); f=x^2+1 sage: f.is_primitive() @@ -5034,9 +5074,9 @@ cdef class Polynomial(CommutativePolynomial): ... NotImplementedError: is_primitive() not defined for polynomials over infinite fields. - Ring semantics examples. + Ring semantics examples. - :: + :: sage: x=polygen(ZZ) sage: f = 5*x^2+2 @@ -5046,16 +5086,16 @@ cdef class Polynomial(CommutativePolynomial): sage: f.is_primitive() False - sage: K=NumberField(x^2+5,'a') - sage: R=K.ring_of_integers() - sage: a=R.gen(1) - sage: a^2 + sage: K = NumberField(x^2 + 5, 'a') # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: a = R.gen(1) # optional - sage.rings.number_field + sage: a^2 # optional - sage.rings.number_field -5 - sage: f=a*x+2 - sage: f.is_primitive() + sage: f = a*x + 2 # optional - sage.rings.number_field + sage: f.is_primitive() # optional - sage.rings.number_field True - sage: f=(1+a)*x+2 - sage: f.is_primitive() + sage: f = (1+a)*x + 2 # optional - sage.rings.number_field + sage: f.is_primitive() # optional - sage.rings.number_field False sage: x = polygen(Integers(10)) @@ -5066,33 +5106,33 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(2)['x'] - sage: f = x^4+x^3+x^2+x+1 - sage: f.is_primitive(15) + sage: R. = GF(2)['x'] # optional - sage.rings.finite_rings + sage: f = x^4+x^3+x^2+x+1 # optional - sage.rings.finite_rings + sage: f.is_primitive(15) # optional - sage.rings.finite_rings False - sage: f.is_primitive(15, [3,5]) + sage: f.is_primitive(15, [3,5]) # optional - sage.rings.finite_rings False - sage: f.is_primitive(n_prime_divs=[3,5]) + sage: f.is_primitive(n_prime_divs=[3,5]) # optional - sage.rings.finite_rings False - sage: f = x^3+x+1 - sage: f.is_primitive(7, [7]) + sage: f = x^3+x+1 # optional - sage.rings.finite_rings + sage: f.is_primitive(7, [7]) # optional - sage.rings.finite_rings True - sage: R. = GF(3)[] - sage: f = x^3-x+1 - sage: f.is_primitive(26, [2,13]) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: f = x^3-x+1 # optional - sage.rings.finite_rings + sage: f.is_primitive(26, [2,13]) # optional - sage.rings.finite_rings True - sage: f = x^2+1 - sage: f.is_primitive(8, [2]) + sage: f = x^2+1 # optional - sage.rings.finite_rings + sage: f.is_primitive(8, [2]) # optional - sage.rings.finite_rings False - sage: R. = GF(5)[] - sage: f = x^2+x+1 - sage: f.is_primitive(24, [2,3]) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = x^2+x+1 # optional - sage.rings.finite_rings + sage: f.is_primitive(24, [2,3]) # optional - sage.rings.finite_rings False - sage: f = x^2-x+2 - sage: f.is_primitive(24, [2,3]) + sage: f = x^2-x+2 # optional - sage.rings.finite_rings + sage: f.is_primitive(24, [2,3]) # optional - sage.rings.finite_rings True - sage: x=polygen(Integers(103)); f=x^2+1 - sage: f.is_primitive() + sage: x = polygen(Integers(103)); f = x^2 + 1 + sage: f.is_primitive() # optional - sage.rings.finite_rings False """ R = self.base_ring() @@ -5139,14 +5179,14 @@ cdef class Polynomial(CommutativePolynomial): def is_monomial(self): """ - Return True if self is a monomial, i.e., a power of the generator. + Return True if ``self`` is a monomial, i.e., a power of the generator. EXAMPLES:: sage: R. = QQ[] sage: x.is_monomial() True - sage: (x+1).is_monomial() + sage: (x + 1).is_monomial() False sage: (x^2).is_monomial() True @@ -5187,7 +5227,7 @@ cdef class Polynomial(CommutativePolynomial): True sage: (3*x^5).is_term() True - sage: (1+3*x^5).is_term() + sage: (1 + 3*x^5).is_term() False To require that the coefficient is 1, use :meth:`is_monomial()` @@ -5201,7 +5241,7 @@ cdef class Polynomial(CommutativePolynomial): def root_field(self, names, check_irreducible=True): """ Return the field generated by the roots of the irreducible - polynomial self. The output is either a number field, relative + polynomial ``self``. The output is either a number field, relative number field, a quotient of a polynomial ring over a field, or the fraction field of the base ring. @@ -5209,55 +5249,56 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('a') + sage: f.root_field('a') # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + x + 17 :: sage: R. = QQ['x'] sage: f = x - 3 - sage: f.root_field('b') + sage: f.root_field('b') # optional - sage.rings.number_field Rational Field :: sage: R. = ZZ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('b') + sage: f.root_field('b') # optional - sage.rings.number_field Number Field in b with defining polynomial x^3 + x + 17 :: sage: y = QQ['x'].0 - sage: L. = NumberField(y^3-2) - sage: R. = L['x'] - sage: f = x^3 + x + 17 - sage: f.root_field('c') + sage: L. = NumberField(y^3 - 2) # optional - sage.rings.number_field + sage: R. = L['x'] # optional - sage.rings.number_field + sage: f = x^3 + x + 17 # optional - sage.rings.number_field + sage: f.root_field('c') # optional - sage.rings.number_field Number Field in c with defining polynomial x^3 + x + 17 over its base field :: - sage: R. = PolynomialRing(GF(9,'a')) - sage: f = x^3 + x^2 + 8 - sage: K. = f.root_field(); K - Univariate Quotient Polynomial Ring in alpha over Finite Field in a of size 3^2 with modulus x^3 + x^2 + 2 - sage: alpha^2 + 1 + sage: R. = PolynomialRing(GF(9, 'a')) # optional - sage.rings.finite_rings + sage: f = x^3 + x^2 + 8 # optional - sage.rings.finite_rings + sage: K. = f.root_field(); K # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in alpha + over Finite Field in a of size 3^2 with modulus x^3 + x^2 + 2 + sage: alpha^2 + 1 # optional - sage.rings.finite_rings alpha^2 + 1 - sage: alpha^3 + alpha^2 + sage: alpha^3 + alpha^2 # optional - sage.rings.finite_rings 1 :: sage: R. = QQ[] sage: f = x^2 - sage: K. = f.root_field() + sage: K. = f.root_field() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: polynomial must be irreducible TESTS:: - sage: (PolynomialRing(Integers(31),name='x').0+5).root_field('a') + sage: (PolynomialRing(Integers(31), name='x').0 + 5).root_field('a') # optional - sage.rings.finite_rings Ring of integers modulo 31 """ R = self.base_ring() @@ -5284,15 +5325,15 @@ cdef class Polynomial(CommutativePolynomial): def sylvester_matrix(self, right, variable = None): """ - Return the Sylvester matrix of self and right. + Return the Sylvester matrix of ``self`` and ``right``. Note that the Sylvester matrix is not defined if one of the polynomials is zero. INPUT: - - right: a polynomial in the same ring as self. - - variable: optional, included for compatibility with the multivariate + - ``right``: a polynomial in the same ring as ``self``. + - ``variable``: optional, included for compatibility with the multivariate case only. The variable of the polynomials. EXAMPLES:: @@ -5300,8 +5341,8 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) - sage: M = f.sylvester_matrix(g) - sage: M + sage: M = f.sylvester_matrix(g) # optional - sage.modules + sage: M # optional - sage.modules [ 42 317 134 1786 0 0 0] [ 0 42 317 134 1786 0 0] [ 0 0 42 317 134 1786 0] @@ -5313,24 +5354,24 @@ cdef class Polynomial(CommutativePolynomial): If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will be zero:: - sage: M.determinant() + sage: M.determinant() # optional - sage.modules 0 - If self and right are polynomials of positive degree, the determinant + If ``self`` and ``right`` are polynomials of positive degree, the determinant of the Sylvester matrix is the resultant of the polynomials.:: sage: h1 = R._random_nonzero_element() sage: h2 = R._random_nonzero_element() - sage: M1 = h1.sylvester_matrix(h2) - sage: M1.determinant() == h1.resultant(h2) + sage: M1 = h1.sylvester_matrix(h2) # optional - sage.modules + sage: M1.determinant() == h1.resultant(h2) # optional - sage.libs.pari sage.modules True The rank of the Sylvester matrix is related to the degree of the - gcd of self and right:: + gcd of ``self`` and ``right``:: - sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() + sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() # optional - sage.modules True - sage: h1.gcd(h2).degree() == h1.degree() + h2.degree() - M1.rank() + sage: h1.gcd(h2).degree() == h1.degree() + h2.degree() - M1.rank() # optional - sage.modules True TESTS: @@ -5338,65 +5379,69 @@ cdef class Polynomial(CommutativePolynomial): The variable is optional, but must be the same in both rings:: sage: K. = QQ['x'] - sage: f = x+1 + sage: f = x + 1 sage: g = QQ['y']([1, 0, 1]) - sage: f.sylvester_matrix(f, x) + sage: f.sylvester_matrix(f, x) # optional - sage.modules [1 1] [1 1] - sage: f.sylvester_matrix(g, x) + sage: f.sylvester_matrix(g, x) # optional - sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Rational Field' + TypeError: no common canonical parent for objects with parents: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in y over Rational Field' Polynomials must be defined over compatible base rings:: sage: f = QQ['x']([1, 0, 1]) sage: g = ZZ['x']([1, 0, 1]) - sage: h = GF(25, 'a')['x']([1, 0, 1]) - sage: f.sylvester_matrix(g) + sage: h = GF(25, 'a')['x']([1, 0, 1]) # optional - sage.rings.finite_rings + sage: f.sylvester_matrix(g) # optional - sage.modules [1 0 1 0] [0 1 0 1] [1 0 1 0] [0 1 0 1] - sage: g.sylvester_matrix(h) + sage: g.sylvester_matrix(h) # optional - sage.rings.finite_rings sage.modules [1 0 1 0] [0 1 0 1] [1 0 1 0] [0 1 0 1] - sage: f.sylvester_matrix(h) + sage: f.sylvester_matrix(h) # optional - sage.rings.finite_rings sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in x over Finite Field in a of size 5^2' + TypeError: no common canonical parent for objects with parents: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in x over Finite Field in a of size 5^2' We can compute the sylvester matrix of a univariate and multivariate polynomial:: sage: K. = QQ['x,y'] sage: g = K.random_element() - sage: f.sylvester_matrix(g) == K(f).sylvester_matrix(g,x) + sage: f.sylvester_matrix(g) == K(f).sylvester_matrix(g, x) # optional - sage.modules True Corner cases:: - sage: K.=QQ[] - sage: f = x^2+1 + sage: K. = QQ[] + sage: f = x^2 + 1 sage: g = K(0) - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(f) + sage: g.sylvester_matrix(f) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(g) + sage: g.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: K(3).sylvester_matrix(x^2) + sage: K(3).sylvester_matrix(x^2) # optional - sage.modules [3 0] [0 3] - sage: K(3).sylvester_matrix(K(4)) + sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules [] """ @@ -5468,10 +5513,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = PolynomialRing(GF(9,'a'), sparse=True) - sage: a = w._new_constant_poly(0, R); a + sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.rings.finite_rings + sage: a = w._new_constant_poly(0, R); a # optional - sage.rings.finite_rings 0 - sage: a.coefficients() + sage: a.coefficients() # optional - sage.rings.finite_rings [] """ t = type(self) @@ -5514,12 +5559,12 @@ cdef class Polynomial(CommutativePolynomial): sage: b = a(2*191*236607587) sage: b.is_nilpotent() True - sage: R. = a[] - sage: f = 3 + b*x + b^2*x^2 - sage: f.is_unit() + sage: R. = a[] # optional - sage.libs.pari + sage: f = 3 + b*x + b^2*x^2 # optional - sage.libs.pari + sage: f.is_unit() # optional - sage.libs.pari True - sage: f = 3 + b*x + b^2*x^2 + 17*x^3 - sage: f.is_unit() + sage: f = 3 + b*x + b^2*x^2 + 17*x^3 # optional - sage.libs.pari + sage: f.is_unit() # optional - sage.libs.pari False EXERCISE (Atiyah-McDonald, Ch 1): Let `A[x]` be a @@ -5599,8 +5644,8 @@ cdef class Polynomial(CommutativePolynomial): sage: R(x).is_gen() True - Important - this function doesn't return True if self equals the - generator; it returns True if self *is* the generator. + Important - this function doesn't return True if ``self`` equals the + generator; it returns True if ``self`` *is* the generator. :: @@ -5771,7 +5816,7 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -5796,18 +5841,18 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(QQbar) - sage: f = QQbar(i)*x^2 + 3*x - sage: f.global_height() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = QQbar(i)*x^2 + 3*x # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 1.09861228866811 :: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^2 + 5) - sage: T. = PolynomialRing(K) - sage: f = 1/1331 * t^2 + 5 * t + 7 - sage: f.global_height() + sage: K. = NumberField(x^2 + 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = 1/1331 * t^2 + 5 * t + 7 # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 9.13959596745043 :: @@ -5857,7 +5902,7 @@ cdef class Polynomial(CommutativePolynomial): - ``v`` -- a prime or prime ideal of the base ring. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -5873,11 +5918,11 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = K[] - sage: I = K.ideal(3) - sage: f = 1/3*t^2 + 3 - sage: f.local_height(I) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = K[] # optional - sage.rings.number_field + sage: I = K.ideal(3) # optional - sage.rings.number_field + sage: f = 1/3*t^2 + 3 # optional - sage.rings.number_field + sage: f.local_height(I) # optional - sage.rings.number_field 1.09861228866811 :: @@ -5909,7 +5954,7 @@ cdef class Polynomial(CommutativePolynomial): - ``i`` -- an integer. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -5925,10 +5970,10 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = K[] - sage: f = 1/2*t^2 + 3 - sage: f.local_height_arch(1, prec=52) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = K[] # optional - sage.rings.number_field + sage: f = 1/2*t^2 + 3 # optional - sage.rings.number_field + sage: f.local_height_arch(1, prec=52) # optional - sage.rings.number_field 1.09861228866811 :: @@ -5983,7 +6028,7 @@ cdef class Polynomial(CommutativePolynomial): sage: v = f.list(); v [-1/3, 2, 0, -2/5] - Note that v is a list, it is mutable, and each call to the list + Note that ``v`` is a list, it is mutable, and each call to the :meth:`list` method returns a new list:: sage: type(v) @@ -6145,11 +6190,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = - 1/2*x^2 + x^9 + 7*x + 5/11 sage: f.monomials() [x^9, x^2, x, 1] - sage: x = var('x') - sage: K. = NumberField(x**2 + 1) - sage: R. = QQ[] - sage: p = rho*y - sage: p.monomials() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x**2 + 1) # optional - sage.rings.number_field + sage: R. = QQ[] # optional - sage.rings.number_field + sage: p = rho * y # optional - sage.rings.number_field + sage: p.monomials() # optional - sage.rings.number_field [y] """ if self.is_zero(): @@ -6165,7 +6210,7 @@ cdef class Polynomial(CommutativePolynomial): polynomial, computed using the Newton-Raphson method. The Newton-Raphson method is an iterative root-finding algorithm. - For f(x) a polynomial, as is the case here, this is essentially the + For `f(x)` a polynomial, as is the case here, this is essentially the same as Horner's method. INPUT: @@ -6177,10 +6222,10 @@ cdef class Polynomial(CommutativePolynomial): OUTPUT: A list of numbers hopefully approximating a root of - f(x)=0. + `f(x)=0`. - If one of the iterates is a critical point of f then a - ZeroDivisionError exception is raised. + If one of the iterates is a critical point of `f`, a + :class:`ZeroDivisionError` exception is raised. EXAMPLES:: @@ -6233,31 +6278,31 @@ cdef class Polynomial(CommutativePolynomial): def newton_slopes(self, p, lengths=False): """ - Return the `p`-adic slopes of the Newton polygon of self, + Return the `p`-adic slopes of the Newton polygon of ``self``, when this makes sense. OUTPUT: - If `lengths` is `False`, a list of rational numbers. If `lengths` is - `True`, a list of couples `(s,l)` where `s` is the slope and `l` the + If ``lengths`` is False, a list of rational numbers. If ``lengths`` is + True, a list of couples `(s,l)` where `s` is the slope and `l` the length of the corresponding segment in the Newton polygon. EXAMPLES:: sage: x = QQ['x'].0 sage: f = x^3 + 2 - sage: f.newton_slopes(2) + sage: f.newton_slopes(2) # optional - sage.libs.pari [1/3, 1/3, 1/3] sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = x^5 + 6*x^2 + 4 - sage: p.newton_slopes(2) + sage: p.newton_slopes(2) # optional - sage.libs.pari [1/2, 1/2, 1/3, 1/3, 1/3] sage: p.newton_slopes(2, lengths=True) [(1/2, 2), (1/3, 3)] sage: (x^2^100 + 27).newton_slopes(3, lengths=True) [(3/1267650600228229401496703205376, 1267650600228229401496703205376)] - ALGORITHM: Uses PARI if `lengths` is `False`. + ALGORITHM: Uses PARI if ``lengths`` is ``False``. """ if not lengths: f = self.__pari__() @@ -6307,13 +6352,13 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: Pol. = QQ[] - sage: x.dispersion_set(x + 1) + sage: x.dispersion_set(x + 1) # optional - sage.libs.pari [1] - sage: (x + 1).dispersion_set(x) + sage: (x + 1).dispersion_set(x) # optional - sage.libs.pari [] sage: pol = x^3 + x - 7 - sage: (pol*pol(x+3)^2).dispersion_set() + sage: (pol*pol(x+3)^2).dispersion_set() # optional - sage.libs.pari [0, 3] """ other = self if other is None else self._parent.coerce(other) @@ -6354,16 +6399,16 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: Pol. = QQ[] - sage: x.dispersion(x + 1) + sage: x.dispersion(x + 1) # optional - sage.libs.pari 1 - sage: (x + 1).dispersion(x) + sage: (x + 1).dispersion(x) # optional - sage.libs.pari -Infinity - sage: Pol. = QQbar[] - sage: pol = Pol([sqrt(5), 1, 3/2]) - sage: pol.dispersion() + sage: Pol. = QQbar[] # optional - sage.libs.pari sage.rings.number_field + sage: pol = Pol([sqrt(5), 1, 3/2]) # optional - sage.libs.pari sage.rings.number_field sage.symbolic + sage: pol.dispersion() # optional - sage.libs.pari sage.rings.number_field sage.symbolic 0 - sage: (pol*pol(x+3)).dispersion() + sage: (pol*pol(x+3)).dispersion() # optional - sage.libs.pari sage.rings.number_field sage.symbolic 3 """ dispersions = self.dispersion_set(other) @@ -6384,7 +6429,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: f = QQ['x']([0,1,2/3,3]) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari 3*x^3 + 2/3*x^2 + x :: @@ -6392,19 +6437,20 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = QQ['a'] sage: R. = S['x'] sage: f = R([0, a]) + R([0, 0, 2/3]) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari 2/3*x^2 + a*x Polynomials over a number field work, provided that the variable is called 'x':: sage: x = polygen(QQ) - sage: K. = NumberField(x^2 + x + 1) - sage: R. = PolynomialRing(K) - sage: pol = (b + x)^3; pol + sage: K. = NumberField(x^2 + x + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: pol = (b + x)^3; pol # optional - sage.rings.number_field x^3 + 3*b*x^2 + (-3*b - 3)*x + 1 - sage: pari(pol) - Mod(1, y^2 + y + 1)*x^3 + Mod(3*y, y^2 + y + 1)*x^2 + Mod(-3*y - 3, y^2 + y + 1)*x + Mod(1, y^2 + y + 1) + sage: pari(pol) # optional - sage.libs.pari sage.rings.number_field + Mod(1, y^2 + y + 1)*x^3 + Mod(3*y, y^2 + y + 1)*x^2 + + Mod(-3*y - 3, y^2 + y + 1)*x + Mod(1, y^2 + y + 1) TESTS: @@ -6413,7 +6459,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = y^3 + a - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari Traceback (most recent call last): ... PariError: incorrect priority in gtopoly: variable x <= a @@ -6423,9 +6469,9 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = QQ['a'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 2*x^3) + sage: pari(a*x + 2*x^3) # optional - sage.libs.pari 2*x^3 + a*x Stacked polynomial rings, second with a multivariate ring on the @@ -6433,27 +6479,27 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = ZZ['a', 'b'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 2*b*x^3) + sage: pari(a*x + 2*b*x^3) # optional - sage.libs.pari 2*b*x^3 + a*x Stacked polynomial rings with exotic base rings:: - sage: S. = GF(7)['a', 'b'] - sage: R. = S['x'] - sage: pari(x^2 + 9*x) + sage: S. = GF(7)['a', 'b'] # optional - sage.rings.finite_rings + sage: R. = S['x'] # optional - sage.rings.finite_rings + sage: pari(x^2 + 9*x) # optional - sage.rings.finite_rings x^2 + 2*x - sage: pari(a*x + 9*b*x^3) + sage: pari(a*x + 9*b*x^3) # optional - sage.rings.finite_rings 2*b*x^3 + a*x :: sage: S. = Integers(8)['a'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari Mod(1, 8)*x^2 + Mod(2, 8)*x - sage: pari(a*x + 10*x^3) + sage: pari(a*x + 10*x^3) # optional - sage.libs.pari Mod(2, 8)*x^3 + Mod(1, 8)*a*x """ return self._pari_with_name(self._parent.variable_name()) @@ -6474,18 +6520,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = 2*x^2 + 7*x - 5 - sage: pol._pari_or_constant() + sage: pol._pari_or_constant() # optional - sage.libs.pari 2*x^2 + 7*x - 5 - sage: pol._pari_or_constant('a') + sage: pol._pari_or_constant('a') # optional - sage.libs.pari 2*a^2 + 7*a - 5 sage: pol = R(7) - sage: pol._pari_or_constant() + sage: pol._pari_or_constant() # optional - sage.libs.pari 7 - sage: pol._pari_or_constant().type() + sage: pol._pari_or_constant().type() # optional - sage.libs.pari 't_INT' - sage: pol.__pari__().type() + sage: pol.__pari__().type() # optional - sage.libs.pari 't_POL' - sage: PolynomialRing(IntegerModRing(101), 't')()._pari_or_constant() + sage: PolynomialRing(IntegerModRing(101), 't')()._pari_or_constant() # optional - sage.libs.pari Mod(0, 101) """ if self.is_constant(): @@ -6504,9 +6550,9 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: (2*a^2 + a)._pari_with_name() + sage: (2*a^2 + a)._pari_with_name() # optional - sage.libs.pari 2*x^2 + x - sage: (2*a^2 + a)._pari_with_name('y') + sage: (2*a^2 + a)._pari_with_name('y') # optional - sage.libs.pari 2*y^2 + y """ vals = [x.__pari__() for x in self.list()] @@ -6521,7 +6567,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: magma = Magma() # new session + sage: magma = Magma() # new session # optional - magma sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 sage: f._magma_init_(magma) # optional - magma @@ -6547,8 +6593,8 @@ cdef class Polynomial(CommutativePolynomial): A more complicated nested example:: - sage: k. = GF(9); R. = k[]; S. = R[] - sage: magma(a*W^20 + s*t/a) # optional - magma + sage: k. = GF(9); R. = k[]; S. = R[] # optional - sage.rings.finite_rings + sage: magma(a*W^20 + s*t/a) # optional - magma # optional - sage.rings.finite_rings a*W^20 + a^7*s*t """ # Get a reference to Magma version of parent. @@ -6569,33 +6615,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g # indirect doctest + sage: g = gap(f); g # indirect doctest # optional - sage.libs.gap y^3-17*y+5 - sage: f._gap_init_() + sage: f._gap_init_() # optional - sage.libs.gap 'y^3 - 17*y + 5' sage: R. = ZZ[] - sage: gap(R) + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: g + sage: g # optional - sage.libs.gap y^3-17*y+5 - sage: gap(z^2 + z) + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z - sage: libgap(z^2 + z) + sage: libgap(z^2 + z) # optional - sage.libs.gap z^2+z Coefficients in a finite field:: - sage: R. = GF(7)[] - sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: f = y^3 - 17*y + 5 # optional - sage.rings.finite_rings + sage: g = gap(f); g # optional - sage.libs.gap sage.rings.finite_rings y^3+Z(7)^4*y+Z(7)^5 - sage: h = libgap(f); h + sage: h = libgap(f); h # optional - sage.libs.gap sage.rings.finite_rings y^3+Z(7)^4*y+Z(7)^5 - sage: g.Factors() + sage: g.Factors() # optional - sage.libs.gap sage.rings.finite_rings [ y+Z(7)^0, y+Z(7)^0, y+Z(7)^5 ] - sage: h.Factors() + sage: h.Factors() # optional - sage.libs.gap sage.rings.finite_rings [ y+Z(7)^0, y+Z(7)^0, y+Z(7)^5 ] - sage: f.factor() + sage: f.factor() # optional - sage.libs.gap sage.rings.finite_rings (y + 5) * (y + 1)^2 """ R = gap(self._parent) @@ -6607,9 +6653,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x^3 + 3*x) # indirect doctest + sage: libgap(-x^3 + 3*x) # indirect doctest # optional - sage.libs.gap -x^3+3*x - sage: libgap(R.zero()) # indirect doctest + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -6621,13 +6667,13 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] - sage: f = R('e*i') * x + x^2 - sage: f._giac_init_() + sage: R. = GF(101)['e,i'][] # optional - sage.rings.finite_rings + sage: f = R('e*i') * x + x^2 # optional - sage.rings.finite_rings + sage: f._giac_init_() # optional - sage.rings.finite_rings '((1)*1)*sageVARx^2+((1)*sageVARe*sageVARi)*sageVARx' - sage: giac(f) + sage: giac(f) # optional - sage.rings.finite_rings sageVARx^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) + sage: giac(R.zero()) # optional - sage.rings.finite_rings 0 """ g = 'sageVAR' + self.variable_name() @@ -6650,7 +6696,7 @@ cdef class Polynomial(CommutativePolynomial): ALGORITHM: - Uses PARI's ``polresultant`` function. For base rings that + Uses PARI's function :pari:`polresultant`. For base rings that are not supported by PARI, the resultant is computed as the determinant of the Sylvester matrix. @@ -6658,9 +6704,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + x + 1; g = x^3 - x - 1 - sage: r = f.resultant(g); r + sage: r = f.resultant(g); r # optional - sage.libs.pari -8 - sage: r.parent() is QQ + sage: r.parent() is QQ # optional - sage.libs.pari True We can compute resultants over univariate and multivariate @@ -6669,9 +6715,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = x^3 + a - sage: r = f.resultant(g); r + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + a^2 - sage: r.parent() is R + sage: r.parent() is R # optional - sage.libs.pari True :: @@ -6679,9 +6725,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = x^3 + b - sage: r = f.resultant(g); r + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + b^2 - sage: r.parent() is R + sage: r.parent() is R # optional - sage.libs.pari True TESTS:: @@ -6689,18 +6735,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = y^3 + a - sage: h = f.resultant(g); h + sage: h = f.resultant(g); h # optional - sage.libs.pari y^3 - x^2 - sage: h.parent() is R + sage: h.parent() is R # optional - sage.libs.pari True Check that :trac:`13672` is fixed:: - sage: R. = GF(2)[] - sage: S. = R[] - sage: f = (t^2 + t)*x + t^2 + t - sage: g = (t + 1)*x + t^2 - sage: f.resultant(g) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: f = (t^2 + t)*x + t^2 + t # optional - sage.rings.finite_rings + sage: g = (t + 1)*x + t^2 # optional - sage.rings.finite_rings + sage: f.resultant(g) # optional - sage.rings.finite_rings t^4 + t Check that :trac:`15061` is fixed:: @@ -6709,23 +6755,23 @@ cdef class Polynomial(CommutativePolynomial): sage: F = R([1,1],2) sage: RP. = PolynomialRing(R) sage: P = x^2 - F - sage: P.resultant(P.derivative()) + sage: P.resultant(P.derivative()) # optional - sage.libs.pari -4 - 4*T + O(T^2) Check that :trac:`16360` is fixed:: sage: K. = FunctionField(QQ) sage: R. = K[] - sage: y.resultant(y+x) + sage: y.resultant(y + x) # optional - sage.libs.pari x sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(b^2-a) - sage: R. = L[] - sage: f=x^2-a - sage: g=x-b - sage: f.resultant(g) + sage: L. = K.extension(b^2 - a) # optional - sage.libs.singular + sage: R. = L[] # optional - sage.libs.singular + sage: f = x^2 - a # optional - sage.libs.singular + sage: g = x - b # optional - sage.libs.singular + sage: f.resultant(g) # optional - sage.libs.pari sage.libs.singular 0 Check that :trac:`17817` is fixed:: @@ -6736,7 +6782,7 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = PolynomialRing(R,'y') sage: p = ((1/b^2*d^2+1/a)*x*y^2+a*b/c*y+e+x^2) sage: q = -4*c^2*y^3+1 - sage: p.resultant(q) + sage: p.resultant(q) # optional - sage.libs.pari (16*c^4)*x^6 + (48*c^4)*e*x^4 + (1/(b^6)*d^6 + 3/(a*b^4)*d^4 + (-12*a^3*b*c + 3)/(a^2*b^2)*d^2 + (-12*a^3*b*c + 1)/(a^3))*x^3 + (48*c^4)*e^2*x^2 + ((-12*a*c)/b*d^2*e + (-12*b*c)*e)*x + (16*c^4)*e^3 + (4*a^3*b^3)/c @@ -6745,7 +6791,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(CDF) sage: f = R(1 - I*x + (0.5)*x^2 + (1.7)*x^3) sage: g = f.derivative() - sage: f.resultant(g) + sage: f.resultant(g) # optional - sage.libs.pari 133.92599999999996 + 37.56999999999999*I """ variable = self.variable_name() @@ -6848,8 +6894,8 @@ cdef class Polynomial(CommutativePolynomial): where the roots `a` and `b` are to be considered in the algebraic closure of the fraction field of the coefficients and counted with multiplicities. If the polynomials are not monic this quantity is - multiplied by `\\alpha_1^{deg(p_2)} \\alpha_2^{deg(p_1)}` where - `\\alpha_1` and `\\alpha_2` are the leading coefficients of `p_1` and + multiplied by `\alpha_1^{deg(p_2)} \alpha_2^{deg(p_1)}` where + `\alpha_1` and `\alpha_2` are the leading coefficients of `p_1` and `p_2` respectively. INPUT: @@ -6860,7 +6906,7 @@ cdef class Polynomial(CommutativePolynomial): - ``op`` -- ``operator.OP`` where ``OP=add`` or ``sub`` or ``mul`` or ``truediv``. - - ``algorithm`` -- can be "resultant" or "BFSS"; + - ``algorithm`` -- can be ``"resultant"`` or ``"BFSS"``; by default the former is used when the polynomials have few nonzero coefficients and small degrees or if the base ring is not `\ZZ` or `\QQ`. Otherwise the latter is used. @@ -6872,7 +6918,7 @@ cdef class Polynomial(CommutativePolynomial): ALGORITHM: The computation is straightforward using resultants. Indeed for the - composed sum it would be `Res_y(p1(x-y), p2(y))`. However, the method + composed sum it would be `Res_y(p_1(x-y), p_2(y))`. However, the method from [BFSS2006]_ using series expansions is asymptotically much faster. Note that the algorithm ``BFSS`` with polynomials with coefficients in @@ -6895,48 +6941,49 @@ cdef class Polynomial(CommutativePolynomial): sage: x = polygen(ZZ) sage: p1 = x^2 - 1 sage: p2 = x^4 - 1 - sage: p1.composed_op(p2, operator.add) + sage: p1.composed_op(p2, operator.add) # optional - sage.libs.singular x^8 - 4*x^6 + 4*x^4 - 16*x^2 - sage: p1.composed_op(p2, operator.mul) + sage: p1.composed_op(p2, operator.mul) # optional - sage.libs.singular x^8 - 2*x^4 + 1 - sage: p1.composed_op(p2, operator.truediv) + sage: p1.composed_op(p2, operator.truediv) # optional - sage.libs.singular x^8 - 2*x^4 + 1 This function works over any field. However for base rings other than `\ZZ` and `\QQ` only the resultant algorithm is available:: - sage: x = polygen(QQbar) - sage: p1 = x**2 - AA(2).sqrt() - sage: p2 = x**3 - AA(3).sqrt() - sage: r1 = p1.roots(multiplicities=False) - sage: r2 = p2.roots(multiplicities=False) - sage: p = p1.composed_op(p2, operator.add) - sage: p - x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 - 14.69693845669907?*x + 0.1715728752538099? - sage: all(p(x+y).is_zero() for x in r1 for y in r2) - True - - sage: x = polygen(GF(2)) - sage: p1 = x**2 + x - 1 - sage: p2 = x**3 + x - 1 - sage: p_add = p1.composed_op(p2, operator.add) - sage: p_add + sage: x = polygen(QQbar) # optional - sage.rings.number_field + sage: p1 = x**2 - AA(2).sqrt() # optional - sage.rings.number_field + sage: p2 = x**3 - AA(3).sqrt() # optional - sage.rings.number_field + sage: r1 = p1.roots(multiplicities=False) # optional - sage.rings.number_field + sage: r2 = p2.roots(multiplicities=False) # optional - sage.rings.number_field + sage: p = p1.composed_op(p2, operator.add) # optional - sage.rings.number_field + sage: p # optional - sage.rings.number_field + x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 + - 14.69693845669907?*x + 0.1715728752538099? + sage: all(p(x+y).is_zero() for x in r1 for y in r2) # optional - sage.rings.number_field + True + + sage: x = polygen(GF(2)) # optional - sage.rings.finite_rings + sage: p1 = x**2 + x - 1 # optional - sage.rings.finite_rings + sage: p2 = x**3 + x - 1 # optional - sage.rings.finite_rings + sage: p_add = p1.composed_op(p2, operator.add) # optional - sage.rings.finite_rings + sage: p_add # optional - sage.rings.finite_rings x^6 + x^5 + x^3 + x^2 + 1 - sage: p_mul = p1.composed_op(p2, operator.mul) - sage: p_mul + sage: p_mul = p1.composed_op(p2, operator.mul) # optional - sage.rings.finite_rings + sage: p_mul # optional - sage.rings.finite_rings x^6 + x^4 + x^2 + x + 1 - sage: p_div = p1.composed_op(p2, operator.truediv) - sage: p_div + sage: p_div = p1.composed_op(p2, operator.truediv) # optional - sage.rings.finite_rings + sage: p_div # optional - sage.rings.finite_rings x^6 + x^5 + x^4 + x^2 + 1 - sage: K = GF(2**6, 'a') - sage: r1 = p1.roots(K, multiplicities=False) - sage: r2 = p2.roots(K, multiplicities=False) - sage: all(p_add(x1+x2).is_zero() for x1 in r1 for x2 in r2) + sage: K = GF(2**6, 'a') # optional - sage.rings.finite_rings + sage: r1 = p1.roots(K, multiplicities=False) # optional - sage.rings.finite_rings + sage: r2 = p2.roots(K, multiplicities=False) # optional - sage.rings.finite_rings + sage: all(p_add(x1+x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True - sage: all(p_mul(x1*x2).is_zero() for x1 in r1 for x2 in r2) + sage: all(p_mul(x1*x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True - sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) + sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True TESTS: @@ -6944,7 +6991,7 @@ cdef class Polynomial(CommutativePolynomial): :: sage: y = polygen(ZZ) - sage: for p1 in [2*y^3 - y + 3, -y^5 - 2, 4*y - 3]: + sage: for p1 in [2*y^3 - y + 3, -y^5 - 2, 4*y - 3]: # optional - sage.libs.singular ....: for p2 in [5*y^2 - 7, -3*y - 1]: ....: for monic in [True,False]: ....: for op in [operator.add, operator.sub, operator.mul, operator.truediv]: @@ -7092,21 +7139,21 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: x = polygen(R) sage: f = (x-a)*(x-b)*(x-c) - sage: f.compose_power(2).factor() + sage: f.compose_power(2).factor() # optional - sage.libs.singular sage.modules (x - c^2) * (x - b^2) * (x - a^2) * (x - b*c)^2 * (x - a*c)^2 * (x - a*b)^2 sage: x = polygen(QQ) - sage: f = x^2-2*x+2 + sage: f = x^2 - 2*x + 2 sage: f2 = f.compose_power(2); f2 x^4 - 4*x^3 + 8*x^2 - 16*x + 16 - sage: f2 == f.composed_op(f,operator.mul) + sage: f2 == f.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True - sage: f3 = f.compose_power(3); f3 + sage: f3 = f.compose_power(3); f3 # optional - sage.libs.singular sage.modules x^8 - 8*x^7 + 32*x^6 - 64*x^5 + 128*x^4 - 512*x^3 + 2048*x^2 - 4096*x + 4096 - sage: f3 == f2.composed_op(f,operator.mul) + sage: f3 == f2.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True - sage: f4 = f.compose_power(4) - sage: f4 == f3.composed_op(f,operator.mul) + sage: f4 = f.compose_power(4) # optional - sage.libs.singular sage.modules + sage: f4 == f3.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True """ try: @@ -7146,21 +7193,21 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: f = cyclotomic_polynomial(30) - sage: f.adams_operator(7)==f + sage: f = cyclotomic_polynomial(30) # optional - sage.libs.pari + sage: f.adams_operator(7)==f # optional - sage.libs.pari True - sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 + sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 # optional - sage.libs.pari True - sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4 + sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4 # optional - sage.libs.pari True - sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8 + sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8 # optional - sage.libs.pari True - sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8 + sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8 # optional - sage.libs.pari True sage: x = polygen(QQ) - sage: f = x^2-2*x+2 - sage: f.adams_operator(10) + sage: f = x^2 - 2*x + 2 + sage: f.adams_operator(10) # optional - sage.libs.singular x^2 + 1024 When f is monic the output will have leading coefficient @@ -7170,9 +7217,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: x = polygen(R) sage: f = (x-a)*(x-b)*(x-c) - sage: f.adams_operator(3).factor() + sage: f.adams_operator(3).factor() # optional - sage.libs.singular (-1) * (x - c^3) * (x - b^3) * (x - a^3) - sage: f.adams_operator(3,monic=True).factor() + sage: f.adams_operator(3, monic=True).factor() # optional - sage.libs.singular (x - c^3) * (x - b^3) * (x - a^3) """ @@ -7191,12 +7238,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(QQ) - sage: f = x^4-x+2 - sage: [f.symmetric_power(k) for k in range(5)] + sage: f = x^4 - x + 2 + sage: [f.symmetric_power(k) for k in range(5)] # optional - sage.libs.singular [x - 1, x^4 - x + 2, x^6 - 2*x^4 - x^3 - 4*x^2 + 8, x^4 - x^3 + 8, x - 2] - sage: f = x^5-2*x+2 - sage: [f.symmetric_power(k) for k in range(6)] + sage: f = x^5 - 2*x + 2 + sage: [f.symmetric_power(k) for k in range(6)] # optional - sage.libs.singular [x - 1, x^5 - 2*x + 2, x^10 + 2*x^8 - 4*x^6 - 8*x^5 - 8*x^4 - 8*x^3 + 16, @@ -7207,7 +7254,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: x = polygen(R) sage: f = (x-a)*(x-b)*(x-c)*(x-d) - sage: [f.symmetric_power(k).factor() for k in range(5)] + sage: [f.symmetric_power(k).factor() for k in range(5)] # optional - sage.libs.singular [x - 1, (-x + d) * (-x + c) * (-x + b) * (-x + a), (x - c*d) * (x - b*d) * (x - a*d) * (x - b*c) * (x - a*c) * (x - a*b), @@ -7282,8 +7329,8 @@ cdef class Polynomial(CommutativePolynomial): R_n := a_n^{2 n-2} \prod_{1 = QQ[] sage: f = x^3 + x + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -31 - sage: d.parent() is QQ + sage: d.parent() is QQ # optional - sage.libs.pari True - sage: EllipticCurve([1, 1]).discriminant()/16 + sage: EllipticCurve([1, 1]).discriminant()/16 # optional - sage.libs.pari -31 :: sage: R. = QQ[] sage: f = 2*x^3 + x + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -116 We can compute discriminants over univariate and multivariate @@ -7322,9 +7369,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = a*x + x + a + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari 1 - sage: d.parent() is R + sage: d.parent() is R # optional - sage.libs.pari True :: @@ -7332,9 +7379,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a + b - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -4*a - 4*b - sage: d.parent() is R + sage: d.parent() is R # optional - sage.libs.pari True TESTS:: @@ -7342,41 +7389,41 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a - sage: f.discriminant() + sage: f.discriminant() # optional - sage.libs.pari 1 Check that :trac:`13672` is fixed:: - sage: R. = GF(5)[] - sage: S. = R[] - sage: f = x^10 + 2*x^6 + 2*x^5 + x + 2 - sage: (f-t).discriminant() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: f = x^10 + 2*x^6 + 2*x^5 + x + 2 # optional - sage.rings.finite_rings + sage: (f - t).discriminant() # optional - sage.rings.finite_rings 4*t^5 The following examples show that :trac:`11782` has been fixed:: - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: ZZ.quo(81)['x'](3*x^2 + 3*x + 3).discriminant() + sage: ZZ.quo(81)['x'](3*x^2 + 3*x + 3).discriminant() # optional - sage.libs.pari sage.symbolic 54 - sage: ZZ.quo(9)['x'](2*x^3 + x^2 + x).discriminant() + sage: ZZ.quo(9)['x'](2*x^3 + x^2 + x).discriminant() # optional - sage.libs.pari sage.symbolic 2 This was fixed by :trac:`15422`:: - sage: R. = PolynomialRing(Qp(2)) - sage: (s^2).discriminant() + sage: R. = PolynomialRing(Qp(2)) # optional - sage.rings.padics + sage: (s^2).discriminant() # optional - sage.rings.padics 0 This was fixed by :trac:`16014`:: sage: PR. = QQ[] sage: PRmu. = PR[] - sage: E1 = diagonal_matrix(PR, [1, b^2, -b^2]) - sage: M = matrix(PR, [[1,-t1,x1-t1*y1],[t1,1,y1+t1*x1],[0,0,1]]) - sage: E1 = M.transpose()*E1*M - sage: E2 = E1.subs(t1=t2, x1=x2, y1=y2) - sage: det(mu*E1 + E2).discriminant().degrees() + sage: E1 = diagonal_matrix(PR, [1, b^2, -b^2]) # optional - sage.modules + sage: M = matrix(PR, [[1,-t1,x1-t1*y1], [t1,1,y1+t1*x1], [0,0,1]]) # optional - sage.modules + sage: E1 = M.transpose()*E1*M # optional - sage.modules + sage: E2 = E1.subs(t1=t2, x1=x2, y1=y2) # optional - sage.modules + sage: det(mu*E1 + E2).discriminant().degrees() # optional - sage.modules sage.libs.pari (24, 12, 12, 8, 8, 8, 8) This addresses an issue raised by :trac:`15061`:: @@ -7385,7 +7432,7 @@ cdef class Polynomial(CommutativePolynomial): sage: F = R([1,1],2) sage: RP. = PolynomialRing(R) sage: P = x^2 - F - sage: P.discriminant() + sage: P.discriminant() # optional - sage.libs.pari 4 + 4*T + O(T^2) """ # Late import to avoid cyclic dependencies: @@ -7424,7 +7471,7 @@ cdef class Polynomial(CommutativePolynomial): """ Return polynomial but with the coefficients reversed. - If an optional degree argument is given the coefficient list will be + If an optional ``degree`` argument is given, the coefficient list will be truncated or zero padded as necessary before reversing it. Assuming that the constant coefficient of ``self`` is nonzero, the reverse polynomial will have the specified degree. @@ -7514,7 +7561,7 @@ cdef class Polynomial(CommutativePolynomial): always ill-conditioned; there's a footnote at the end of the docstring about this. - If the output ring is a RealIntervalField or ComplexIntervalField + If the output ring is a :class:`RealIntervalField` or :class:`ComplexIntervalField` of a given precision, then the answer will always be correct (or an exception will be raised, if a case is not implemented). Each root will be contained in one of the returned intervals, and the @@ -7523,53 +7570,56 @@ cdef class Polynomial(CommutativePolynomial): At the end of this docstring (after the examples) is a description of all the cases implemented in this function, and the algorithms - used. That section also describes the possibilities for - "algorithm=", for the cases where multiple algorithms exist. + used. That section also describes the possibilities for the + ``algorithm`` keyword, for the cases where multiple algorithms exist. EXAMPLES:: sage: x = QQ['x'].0 sage: f = x^3 - 1 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(1, 1)] - sage: f.roots(ring=CC) # note -- low order bits slightly different on ppc. - [(1.00000000000000, 1), (-0.500000000000000 - 0.86602540378443...*I, 1), (-0.500000000000000 + 0.86602540378443...*I, 1)] + sage: f.roots(ring=CC) # ... - low order bits slightly different on ppc # optional - sage.libs.pari + [(1.00000000000000, 1), + (-0.500000000000000 - 0.86602540378443...*I, 1), + (-0.500000000000000 + 0.86602540378443...*I, 1)] sage: f = (x^3 - 1)^2 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(1, 2)] :: sage: f = -19*x + 884736 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(884736/19, 1)] - sage: (f^20).roots() + sage: (f^20).roots() # optional - sage.libs.pari [(884736/19, 20)] :: - sage: K. = CyclotomicField(3) - sage: f = K.defining_polynomial() - sage: f.roots(ring=GF(7)) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: f = K.defining_polynomial() # optional - sage.rings.number_field + sage: f.roots(ring=GF(7)) # optional - sage.rings.finite_rings sage.rings.number_field [(4, 1), (2, 1)] - sage: g = f.change_ring(GF(7)) - sage: g.roots() + sage: g = f.change_ring(GF(7)) # optional - sage.rings.finite_rings sage.rings.number_field + sage: g.roots() # optional - sage.rings.finite_rings sage.rings.number_field [(4, 1), (2, 1)] - sage: g.roots(multiplicities=False) + sage: g.roots(multiplicities=False) # optional - sage.rings.finite_rings sage.rings.number_field [4, 2] A new ring. In the example below, we add the special method - _roots_univariate_polynomial to the base ring, and observe + :meth:`_roots_univariate_polynomial` to the base ring, and observe that this method is called instead to find roots of polynomials over this ring. This facility can be used to easily extend root finding to work over new rings you introduce:: sage: R. = QQ[] - sage: (x^2 + 1).roots() + sage: (x^2 + 1).roots() # optional - sage.libs.pari [] - sage: g = lambda f, *args, **kwds: f.change_ring(CDF).roots() - sage: QQ._roots_univariate_polynomial = g + sage: def my_roots(f, *args, **kwds): + ....: return f.change_ring(CDF).roots() + sage: QQ._roots_univariate_polynomial = my_roots sage: (x^2 + 1).roots() # abs tol 1e-14 [(2.7755575615628914e-17 - 1.0*I, 1), (0.9999999999999997*I, 1)] sage: del QQ._roots_univariate_polynomial @@ -7591,11 +7641,15 @@ cdef class Polynomial(CommutativePolynomial): :: sage: x = CC['x'].0 - sage: f = x^3 -2 + sage: f = x^3 - 2 sage: f.roots() - [(1.25992104989487, 1), (-0.62996052494743... - 1.09112363597172*I, 1), (-0.62996052494743... + 1.09112363597172*I, 1)] - sage: f.roots(algorithm='pari') - [(1.25992104989487, 1), (-0.629960524947437 - 1.09112363597172*I, 1), (-0.629960524947437 + 1.09112363597172*I, 1)] + [(1.25992104989487, 1), + (-0.62996052494743... - 1.09112363597172*I, 1), + (-0.62996052494743... + 1.09112363597172*I, 1)] + sage: f.roots(algorithm='pari') # optional - sage.libs.pari + [(1.25992104989487, 1), + (-0.629960524947437 - 1.09112363597172*I, 1), + (-0.629960524947437 + 1.09112363597172*I, 1)] Another example showing that only roots in the base ring are returned:: @@ -7640,15 +7694,15 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = x^2 + 2 - sage: f.roots(SR) + sage: f.roots(SR) # optional - sage.symbolic [(-I*sqrt(2), 1), (I*sqrt(2), 1)] - sage: f.roots(SR, multiplicities=False) + sage: f.roots(SR, multiplicities=False) # optional - sage.symbolic [-I*sqrt(2), I*sqrt(2)] The roots of some polynomials cannot be described using radical expressions:: - sage: (x^5 - x + 1).roots(SR) + sage: (x^5 - x + 1).roots(SR) # optional - sage.symbolic [] For some other polynomials, no roots can be found at the moment @@ -7656,27 +7710,29 @@ cdef class Polynomial(CommutativePolynomial): these defects. Until that gets implemented, one such example is the following:: - sage: f = x^6-300*x^5+30361*x^4-1061610*x^3+1141893*x^2-915320*x+101724 + sage: f = x^6 - 300*x^5 + 30361*x^4 - 1061610*x^3 + 1141893*x^2 - 915320*x + 101724 sage: f.roots() [] A purely symbolic roots example:: - sage: X = var('X') - sage: f = expand((X-1)*(X-I)^3*(X^2 - sqrt(2))); f - X^6 - (3*I + 1)*X^5 - sqrt(2)*X^4 + (3*I - 3)*X^4 + (3*I + 1)*sqrt(2)*X^3 + (I + 3)*X^3 - (3*I - 3)*sqrt(2)*X^2 - I*X^2 - (I + 3)*sqrt(2)*X + I*sqrt(2) - sage: f.roots() + sage: X = var('X') # optional - sage.symbolic + sage: f = expand((X-1)*(X-I)^3*(X^2 - sqrt(2))); f # optional - sage.symbolic + X^6 - (3*I + 1)*X^5 - sqrt(2)*X^4 + (3*I - 3)*X^4 + (3*I + 1)*sqrt(2)*X^3 + + (I + 3)*X^3 - (3*I - 3)*sqrt(2)*X^2 - I*X^2 - (I + 3)*sqrt(2)*X + I*sqrt(2) + sage: f.roots() # optional - sage.symbolic [(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)] The same operation, performed over a polynomial ring with symbolic coefficients:: - sage: X = SR['X'].0 - sage: f = (X-1)*(X-I)^3*(X^2 - sqrt(2)); f - X^6 + (-3*I - 1)*X^5 + (-sqrt(2) + 3*I - 3)*X^4 + ((3*I + 1)*sqrt(2) + I + 3)*X^3 + (-(3*I - 3)*sqrt(2) - I)*X^2 + (-(I + 3)*sqrt(2))*X + I*sqrt(2) - sage: f.roots() + sage: X = SR['X'].0 # optional - sage.symbolic + sage: f = (X-1)*(X-I)^3*(X^2 - sqrt(2)); f # optional - sage.symbolic + X^6 + (-3*I - 1)*X^5 + (-sqrt(2) + 3*I - 3)*X^4 + ((3*I + 1)*sqrt(2) + I + 3)*X^3 + + (-(3*I - 3)*sqrt(2) - I)*X^2 + (-(I + 3)*sqrt(2))*X + I*sqrt(2) + sage: f.roots() # optional - sage.symbolic [(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)] - sage: f.roots(multiplicities=False) + sage: f.roots(multiplicities=False) # optional - sage.symbolic [I, -2^(1/4), 2^(1/4), 1] A couple of examples where the base ring does not have a @@ -7685,11 +7741,12 @@ cdef class Polynomial(CommutativePolynomial): sage: R = Integers(6) sage: S. = R['x'] - sage: p = x^2-1 + sage: p = x^2 - 1 sage: p.roots() Traceback (most recent call last): ... - NotImplementedError: root finding with multiplicities for this polynomial not implemented (try the multiplicities=False option) + NotImplementedError: root finding with multiplicities for this polynomial + not implemented (try the multiplicities=False option) sage: p.roots(multiplicities=False) [5, 1] sage: R = Integers(9) @@ -7706,9 +7763,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = R.cyclotomic_polynomial(5); f x^4 + x^3 + x^2 + x + 1.0 sage: f.roots(multiplicities=False) # abs tol 1e-9 - [-0.8090169943749469 - 0.5877852522924724*I, -0.8090169943749473 + 0.5877852522924724*I, 0.30901699437494773 - 0.951056516295154*I, 0.30901699437494756 + 0.9510565162951525*I] + [-0.8090169943749469 - 0.5877852522924724*I, -0.8090169943749473 + 0.5877852522924724*I, + 0.30901699437494773 - 0.951056516295154*I, 0.30901699437494756 + 0.9510565162951525*I] sage: [z^5 for z in f.roots(multiplicities=False)] # abs tol 2e-14 - [0.9999999999999957 - 1.2864981197413038e-15*I, 0.9999999999999976 + 3.062854959141552e-15*I, 1.0000000000000024 + 1.1331077795295987e-15*I, 0.9999999999999953 - 2.0212861992297117e-15*I] + [0.9999999999999957 - 1.2864981197413038e-15*I, 0.9999999999999976 + 3.062854959141552e-15*I, + 1.0000000000000024 + 1.1331077795295987e-15*I, 0.9999999999999953 - 2.0212861992297117e-15*I] sage: f = CDF['x']([1,2,3,4]); f 4.0*x^3 + 3.0*x^2 + 2.0*x + 1.0 sage: r = f.roots(multiplicities=False) @@ -7730,7 +7789,9 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^3 + 2*i; f x^3 + 2.0*I sage: f.roots() - [(-1.09112363597172... - 0.62996052494743...*I, 1), (...1.25992104989487...*I, 1), (1.09112363597172... - 0.62996052494743...*I, 1)] + [(-1.09112363597172... - 0.62996052494743...*I, 1), + (...1.25992104989487...*I, 1), + (1.09112363597172... - 0.62996052494743...*I, 1)] sage: f.roots(multiplicities=False) [-1.09112363597172... - 0.62996052494743...*I, ...1.25992104989487...*I, 1.09112363597172... - 0.62996052494743...*I] sage: [abs(f(z)) for z in f.roots(multiplicities=False)] # abs tol 1e-14 @@ -7738,7 +7799,9 @@ cdef class Polynomial(CommutativePolynomial): sage: f = i*x^3 + 2; f I*x^3 + 2.0 sage: f.roots() - [(-1.09112363597172... + 0.62996052494743...*I, 1), (...1.25992104989487...*I, 1), (1.09112363597172... + 0.62996052494743...*I, 1)] + [(-1.09112363597172... + 0.62996052494743...*I, 1), + (...1.25992104989487...*I, 1), + (1.09112363597172... + 0.62996052494743...*I, 1)] sage: abs(f(f.roots()[0][0])) # abs tol 1e-13 1.1102230246251565e-16 @@ -7753,14 +7816,19 @@ cdef class Polynomial(CommutativePolynomial): sage: f.roots(ring=RIF, multiplicities=False) [-0.6180339887498948482045868343657?, 1.6180339887498948482045868343657?] sage: f.roots(ring=RealIntervalField(150)) - [(-0.6180339887498948482045868343656381177203091798057628621354486227?, 1), (1.618033988749894848204586834365638117720309179805762862135448623?, 1)] - sage: f.roots(ring=AA) + [(-0.6180339887498948482045868343656381177203091798057628621354486227?, 1), + (1.618033988749894848204586834365638117720309179805762862135448623?, 1)] + sage: f.roots(ring=AA) # optional - sage.rings.number_field [(-0.618033988749895?, 1), (1.618033988749895?, 1)] sage: f = f^2 * (x - 1) sage: f.roots(ring=RIF) - [(-0.6180339887498948482045868343657?, 2), (1.0000000000000000000000000000000?, 1), (1.6180339887498948482045868343657?, 2)] + [(-0.6180339887498948482045868343657?, 2), + (1.0000000000000000000000000000000?, 1), + (1.6180339887498948482045868343657?, 2)] sage: f.roots(ring=RIF, multiplicities=False) - [-0.6180339887498948482045868343657?, 1.0000000000000000000000000000000?, 1.6180339887498948482045868343657?] + [-0.6180339887498948482045868343657?, + 1.0000000000000000000000000000000?, + 1.6180339887498948482045868343657?] Examples using complex root isolation:: @@ -7769,15 +7837,19 @@ cdef class Polynomial(CommutativePolynomial): sage: p.roots() [] sage: p.roots(ring=CIF) - [(1.167303978261419?, 1), (-0.764884433600585? - 0.352471546031727?*I, 1), (-0.764884433600585? + 0.352471546031727?*I, 1), (0.181232444469876? - 1.083954101317711?*I, 1), (0.181232444469876? + 1.083954101317711?*I, 1)] + [(1.167303978261419?, 1), + (-0.764884433600585? - 0.352471546031727?*I, 1), + (-0.764884433600585? + 0.352471546031727?*I, 1), + (0.181232444469876? - 1.083954101317711?*I, 1), + (0.181232444469876? + 1.083954101317711?*I, 1)] sage: p.roots(ring=ComplexIntervalField(200)) [(1.167303978261418684256045899854842180720560371525489039140082?, 1), (-0.76488443360058472602982318770854173032899665194736756700778? - 0.35247154603172624931794709140258105439420648082424733283770?*I, 1), (-0.76488443360058472602982318770854173032899665194736756700778? + 0.35247154603172624931794709140258105439420648082424733283770?*I, 1), (0.18123244446987538390180023778112063996871646618462304743774? - 1.08395410131771066843034449298076657427364024315511565430114?*I, 1), (0.18123244446987538390180023778112063996871646618462304743774? + 1.08395410131771066843034449298076657427364024315511565430114?*I, 1)] - sage: rts = p.roots(ring=QQbar); rts + sage: rts = p.roots(ring=QQbar); rts # optional - sage.rings.number_field [(1.167303978261419?, 1), (-0.7648844336005847? - 0.3524715460317263?*I, 1), (-0.7648844336005847? + 0.3524715460317263?*I, 1), (0.1812324444698754? - 1.083954101317711?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(1.167303978261419?, 1)] sage: p = (x - rts[4][0])^2 * (3*x^2 + x + 1) - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)] sage: p.roots(ring=CIF) [(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)] @@ -7803,14 +7875,21 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: K. = QuadraticField(-1) - sage: y = polygen(K) - sage: p = y^4 - 2 - im - sage: p.roots(ring=CC) - [(-1.2146389322441... - 0.14142505258239...*I, 1), (-0.14142505258239... + 1.2146389322441...*I, 1), (0.14142505258239... - 1.2146389322441...*I, 1), (1.2146389322441... + 0.14142505258239...*I, 1)] - sage: p = p^2 * (y^2 - 2) - sage: p.roots(ring=CIF) - [(-1.414213562373095?, 1), (1.414213562373095?, 1), (-1.214638932244183? - 0.141425052582394?*I, 2), (-0.141425052582394? + 1.214638932244183?*I, 2), (0.141425052582394? - 1.214638932244183?*I, 2), (1.214638932244183? + 0.141425052582394?*I, 2)] + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: p = y^4 - 2 - im # optional - sage.rings.number_field + sage: p.roots(ring=CC) # optional - sage.rings.number_field + [(-1.2146389322441... - 0.14142505258239...*I, 1), + (-0.14142505258239... + 1.2146389322441...*I, 1), + (0.14142505258239... - 1.2146389322441...*I, 1), + (1.2146389322441... + 0.14142505258239...*I, 1)] + sage: p = p^2 * (y^2 - 2) # optional - sage.rings.number_field + sage: p.roots(ring=CIF) # optional - sage.rings.number_field + [(-1.414213562373095?, 1), (1.414213562373095?, 1), + (-1.214638932244183? - 0.141425052582394?*I, 2), + (-0.141425052582394? + 1.214638932244183?*I, 2), + (0.141425052582394? - 1.214638932244183?*I, 2), + (1.214638932244183? + 0.141425052582394?*I, 2)] Note that one should not use NumPy when wanting high precision output as it does not support any of the high precision types:: @@ -7818,16 +7897,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = RealField(200)[] sage: f = x^2 - R(pi) sage: f.roots() - [(-1.7724538509055160272981674833411451827975494561223871282138, 1), (1.7724538509055160272981674833411451827975494561223871282138, 1)] + [(-1.7724538509055160272981674833411451827975494561223871282138, 1), + (1.7724538509055160272981674833411451827975494561223871282138, 1)] sage: f.roots(algorithm='numpy') - doctest... UserWarning: NumPy does not support arbitrary precision arithmetic. The roots found will likely have less precision than you expect. + doctest... UserWarning: NumPy does not support arbitrary precision arithmetic. + The roots found will likely have less precision than you expect. [(-1.77245385090551..., 1), (1.77245385090551..., 1)] We can also find roots over number fields:: - sage: K. = CyclotomicField(15) - sage: R. = PolynomialRing(K) - sage: (x^2 + x + 1).roots() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: (x^2 + x + 1).roots() # optional - sage.rings.number_field [(z^5, 1), (-z^5 - 1, 1)] There are many combinations of floating-point input and output @@ -7863,17 +7944,18 @@ cdef class Polynomial(CommutativePolynomial): Note that we can find the roots of a polynomial with algebraic coefficients:: - sage: rt2 = sqrt(AA(2)) - sage: rt3 = sqrt(AA(3)) - sage: x = polygen(AA) - sage: f = (x - rt2) * (x - rt3); f + sage: rt2 = sqrt(AA(2)) # optional - sage.rings.number_field + sage: rt3 = sqrt(AA(3)) # optional - sage.rings.number_field + sage: x = polygen(AA) # optional - sage.rings.number_field + sage: f = (x - rt2) * (x - rt3); f # optional - sage.rings.number_field x^2 - 3.146264369941973?*x + 2.449489742783178? - sage: rts = f.roots(); rts + sage: rts = f.roots(); rts # optional - sage.rings.number_field [(1.414213562373095?, 1), (1.732050807568878?, 1)] - sage: rts[0][0] == rt2 + sage: rts[0][0] == rt2 # optional - sage.rings.number_field True - sage: f.roots(ring=RealIntervalField(150)) - [(1.414213562373095048801688724209698078569671875376948073176679738?, 1), (1.732050807568877293527446341505872366942805253810380628055806980?, 1)] + sage: f.roots(ring=RealIntervalField(150)) # optional - sage.rings.number_field + [(1.414213562373095048801688724209698078569671875376948073176679738?, 1), + (1.732050807568877293527446341505872366942805253810380628055806980?, 1)] We can handle polynomials with huge coefficients. @@ -7897,21 +7979,21 @@ cdef class Polynomial(CommutativePolynomial): LinAlgError: Array must not contain infs or NaNs sage: p.roots(ring=RR, algorithm='pari') [(-3.50746621104340e451, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] sage: p = bigc*x + 1 sage: p.roots(ring=RR) [(-2.85106096489671e-452, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] sage: p = x^2 - bigc sage: p.roots(ring=RR) [(-5.92238652153286e225, 1), (5.92238652153286e225, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-5.9223865215328558?e225, 1), (5.9223865215328558?e225, 1)] Check that :trac:`30522` is fixed:: @@ -7924,29 +8006,29 @@ cdef class Polynomial(CommutativePolynomial): sage: PolynomialRing(SR, names="x")("x^2 + q").roots() [(-sqrt(-q), 1), (sqrt(-q), 1)] - Algorithms used: + ALGORITHM: - For brevity, we will use RR to mean any RealField of any precision; - similarly for RIF, CC, and CIF. Since Sage has no specific + For brevity, we will use ``RR`` to mean any :class:`RealField` of any precision; + similarly for ``RIF``, ``CC``, and ``CIF``. Since Sage has no specific implementation of Gaussian rationals (or of number fields with embedding, at all), when we refer to Gaussian rationals below we will accept any number field with defining polynomial `x^2+1`, mapping the field generator to +I. - We call the base ring of the polynomial K, and the ring given by - the ring= argument L. (If ring= is not specified, then L is the - same as K.) - - If K and L are floating-point (RDF, CDF, RR, or CC), then a - floating-point root-finder is used. If L is RDF or CDF then we - default to using NumPy's roots(); otherwise, we use PARI's - polroots(). This choice can be overridden with - algorithm='pari' or algorithm='numpy'. If the algorithm is - unspecified and NumPy's roots() algorithm fails, then we fall - back to pari (numpy will fail if some coefficient is infinite, + We call the base ring of the polynomial `K`, and the ring given by + the ``ring`` argument `L`. (If ``ring`` is not specified, then `L` is the + same as `K`.) + + If `K` and `L` are floating-point (``RDF``, ``CDF``, ``RR``, or ``CC``), then a + floating-point root-finder is used. If `L` is ``RDF`` or ``CDF``, then we + default to using NumPy's :func:`roots`; otherwise, we use PARI's + function :pari:`polroots`. This choice can be overridden with + ``algorithm='pari'`` or ``algorithm='numpy'``. If the algorithm is + unspecified and NumPy's :func:`roots` algorithm fails, then we fall + back to PARI (NumPy will fail if some coefficient is infinite, for instance). - If L is SR (or one of its subrings), then the roots will be radical + If `L` is ``SR`` (or one of its subrings), then the roots will be radical expressions, computed as the solutions of a symbolic polynomial expression. At the moment this delegates to :meth:`sage.symbolic.expression.Expression.solve` @@ -7955,47 +8037,47 @@ cdef class Polynomial(CommutativePolynomial): Once :trac:`17516` gets implemented, all possible radical solutions should become available. - If L is AA or RIF, and K is ZZ, QQ, or AA, then the root isolation - algorithm sage.rings.polynomial.real_roots.real_roots() is used. - (You can call real_roots() directly to get more control than this + If `L` is ``AA`` or ``RIF``, and `K` is ``ZZ``, ``QQ``, or ``AA``, then the root isolation + algorithm :func:`sage.rings.polynomial.real_roots.real_roots` is used. + (You can call :func:`real_roots` directly to get more control than this method gives.) - If L is QQbar or CIF, and K is ZZ, QQ, AA, QQbar, or the Gaussian + If `L` is ``QQbar`` or ``CIF``, and `K` is ``ZZ``, ``QQ``, ``AA``, ``QQbar``, or the Gaussian rationals, then the root isolation algorithm - sage.rings.polynomial.complex_roots.complex_roots() is used. (You - can call complex_roots() directly to get more control than this + :func:`sage.rings.polynomial.complex_roots.complex_roots` is used. (You + can call :func:`complex_roots` directly to get more control than this method gives.) - If L is AA and K is QQbar or the Gaussian rationals, then - complex_roots() is used (as above) to find roots in QQbar, then + If `L` is ``AA`` and `K` is ``QQbar`` or the Gaussian rationals, then + :func:`complex_roots` is used (as above) to find roots in ``QQbar``, then these roots are filtered to select only the real roots. - If L is floating-point and K is not, then we attempt to change the - polynomial ring to L (using .change_ring()) (or, if L is complex - and K is not, to the corresponding real field). Then we use either - PARI or numpy as specified above. + If `L` is floating-point and `K` is not, then we attempt to change the + polynomial ring to `L` (using :meth:`change_ring`) (or, if `L` is complex + and `K` is not, to the corresponding real field). Then we use either + PARI or NumPy as specified above. - For all other cases where K is different than L, we attempt to use - .change_ring(L). When that fails but L is a subring of K, we also - attempt to compute the roots over K and filter the ones belonging - to L. + For all other cases where `K` is different from `L`, we attempt to use + ``.change_ring(L)``. When that fails but `L` is a subring of `K`, we also + attempt to compute the roots over `K` and filter the ones belonging + to `L`. - The next method, which is used if K is an integral domain, is to + The next method, which is used if `K` is an integral domain, is to attempt to factor the polynomial. If this succeeds, then for every - degree-one factor a\*x+b, we add -b/a as a root (as long as this + degree-one factor `ax+b`, we add `-b/a` as a root (as long as this quotient is actually in the desired ring). - If factoring over K is not implemented (or K is not an integral - domain), and K is finite, then we find the roots by enumerating all - elements of K and checking whether the polynomial evaluates to zero + If factoring over `K` is not implemented (or `K` is not an integral + domain), and `K` is finite, then we find the roots by enumerating all + elements of `K` and checking whether the polynomial evaluates to zero at that value. .. NOTE:: We mentioned above that polynomials with multiple roots are - always ill-conditioned; if your input is given to n bits of - precision, you should not expect more than n/k good bits - for a k-fold root. (You can get solutions that make the + always ill-conditioned; if your input is given to `n` bits of + precision, you should not expect more than `n/k` good bits + for a `k`-fold root. (You can get solutions that make the polynomial evaluate to a number very close to zero; basically the problem is that with a multiple root, there are many such numbers, and it's difficult to choose between @@ -8013,9 +8095,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: K. = CyclotomicField(2) - sage: R. = K[] - sage: factor(x^3-1) + sage: K. = CyclotomicField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: factor(x^3 - 1) # optional - sage.rings.number_field (x - 1) * (x^2 + x + 1) This shows that the issue from :trac:`6237` is fixed:: @@ -8023,9 +8105,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: g = -27*u^14 - 32*u^9 sage: g.roots(CDF, multiplicities=False) # abs tol 2e-15 - [-1.0345637159435719, 0.0, -0.3196977699902601 - 0.9839285635706636*I, -0.3196977699902601 + 0.9839285635706636*I, 0.8369796279620465 - 0.6081012947885318*I, 0.8369796279620465 + 0.6081012947885318*I] + [-1.0345637159435719, 0.0, -0.3196977699902601 - 0.9839285635706636*I, -0.3196977699902601 + 0.9839285635706636*I, + 0.8369796279620465 - 0.6081012947885318*I, 0.8369796279620465 + 0.6081012947885318*I] sage: g.roots(CDF) # abs tol 2e-15 - [(-1.0345637159435719, 1), (0.0, 9), (-0.3196977699902601 - 0.9839285635706636*I, 1), (-0.3196977699902601 + 0.9839285635706636*I, 1), (0.8369796279620465 - 0.6081012947885318*I, 1), (0.8369796279620465 + 0.6081012947885318*I, 1)] + [(-1.0345637159435719, 1), (0.0, 9), (-0.3196977699902601 - 0.9839285635706636*I, 1), (-0.3196977699902601 + 0.9839285635706636*I, 1), + (0.8369796279620465 - 0.6081012947885318*I, 1), (0.8369796279620465 + 0.6081012947885318*I, 1)] This shows that the issue at :trac:`2418` is fixed:: @@ -8054,19 +8138,19 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = (x - 1)^2 - sage: pol.roots(Qp(3,5)) + sage: pol.roots(Qp(3, 5)) # optional - sage.rings.padics [(1 + O(3^5), 2)] We lose precision if we first change coefficients to `\QQ_p`:: - sage: pol.change_ring(Qp(3,5)).roots() + sage: pol.change_ring(Qp(3, 5)).roots() # optional - sage.rings.padics [(1 + O(3^3), 2)] - sage: (pol - 3^6).roots(Qp(3,5)) + sage: (pol - 3^6).roots(Qp(3, 5)) # optional - sage.rings.padics [(1 + 2*3^3 + 2*3^4 + O(3^5), 1), (1 + 3^3 + O(3^5), 1)] - sage: r = pol.roots(Zp(3,5), multiplicities=False); r + sage: r = pol.roots(Zp(3, 5), multiplicities=False); r # optional - sage.rings.padics [1 + O(3^5)] - sage: parent(r[0]) + sage: parent(r[0]) # optional - sage.rings.padics 3-adic Ring with capped relative precision 5 Spurious crash with pari-2.5.5, see :trac:`16165`:: @@ -8095,7 +8179,7 @@ cdef class Polynomial(CommutativePolynomial): Test that roots in fixed modulus p-adic fields work (:trac:`17598`):: - sage: len(cyclotomic_polynomial(3).roots(ZpFM(739, 566))) + sage: len(cyclotomic_polynomial(3).roots(ZpFM(739, 566))) # optional - sage.rings.padics 2 Check that :trac:`26421` is fixed:: @@ -8109,8 +8193,8 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`31040` is fixed:: sage: R. = QQ[] - sage: K. = Qq(3).extension(x^2 + 1) - sage: (x^2 + 1).roots(K) + sage: K. = Qq(3).extension(x^2 + 1) # optional - sage.rings.padics + sage: (x^2 + 1).roots(K) # optional - sage.rings.padics [(a + O(3^20), 1), (2*a + 2*a*3 + 2*a*3^2 + 2*a*3^3 + 2*a*3^4 + 2*a*3^5 + 2*a*3^6 + 2*a*3^7 + 2*a*3^8 + 2*a*3^9 + 2*a*3^10 + 2*a*3^11 + 2*a*3^12 + 2*a*3^13 + 2*a*3^14 + 2*a*3^15 + 2*a*3^16 + 2*a*3^17 + 2*a*3^18 + 2*a*3^19 + O(3^20), 1)] @@ -8395,11 +8479,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = 20*x^3 - 50*x^2 + 20*x - sage: F = pol.factor(); F + sage: F = pol.factor(); F # optional - sage.libs.pari 2 * 5 * (x - 2) * x * (2*x - 1) - sage: pol._roots_from_factorization(F, multiplicities=True) + sage: pol._roots_from_factorization(F, multiplicities=True) # optional - sage.libs.pari [(2, 1), (0, 1)] - sage: pol.change_ring(QQ)._roots_from_factorization(F, multiplicities=False) + sage: pol.change_ring(QQ)._roots_from_factorization(F, multiplicities=False) # optional - sage.libs.pari [2, 0, 1/2] """ seq = [] @@ -8428,15 +8512,15 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: Pols. = QQ[] - sage: pol = (n - 1/2)^2*(n - 1)^2*(n-2) - sage: rts = pol.roots(ZZ, multiplicities=False); rts + sage: pol = (n - 1/2)^2 * (n - 1)^2 * (n - 2) + sage: rts = pol.roots(ZZ, multiplicities=False); rts # optional - sage.libs.pari [2, 1] - sage: rts[0].parent() + sage: rts[0].parent() # optional - sage.libs.pari Integer Ring sage: Pols_x. = QQ[] sage: Pols_xy. = Pols_x[] - sage: ((y - 1)*(y - x))._roots_in_subring(QQ, True, None) + sage: ((y - 1)*(y - x))._roots_in_subring(QQ, True, None) # optional - sage.libs.singular [(1, 1)] """ K = self._parent.base_ring() @@ -8462,9 +8546,9 @@ cdef class Polynomial(CommutativePolynomial): """ Return the real roots of this polynomial, without multiplicities. - Calls self.roots(ring=RR), unless this is a polynomial with + Calls ``self.roots(ring=RR)``, unless this is a polynomial with floating-point real coefficients, in which case it calls - self.roots(). + ``self.roots()``. EXAMPLES:: @@ -8496,7 +8580,7 @@ cdef class Polynomial(CommutativePolynomial): Return the complex roots of this polynomial, without multiplicities. - Calls self.roots(ring=CC), unless this is a polynomial with + Calls ``self.roots(ring=CC)``, unless this is a polynomial with floating-point coefficients, in which case it is uses the appropriate precision from the input coefficients. @@ -8540,50 +8624,50 @@ cdef class Polynomial(CommutativePolynomial): def number_of_roots_in_interval(self, a=None, b=None): r""" Return the number of roots of this polynomial in the interval - [a,b], counted without multiplicity. The endpoints a, b default to - -Infinity, Infinity (which are also valid input values). + `[a,b]`, counted without multiplicity. The endpoints `a`, `b` default to + ``-Infinity``, ``Infinity`` (which are also valid input values). Calls the PARI routine :pari:`polsturm`. Note that as of version 2.8, PARI includes the left endpoint of the interval (and no longer uses Sturm's algorithm on exact - inputs). polsturm requires a polynomial with real + inputs). :pari:`polsturm` requires a polynomial with real coefficients; in case PARI returns an error, we try again - after taking the GCD of `self` with its complex conjugate. + after taking the GCD of ``self`` with its complex conjugate. EXAMPLES:: sage: R. = PolynomialRing(ZZ) sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_roots_in_interval(1, 2) + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1.01, 2) + sage: pol.number_of_roots_in_interval(1.01, 2) # optional - sage.libs.pari 1 - sage: pol.number_of_roots_in_interval(None, 2) + sage: pol.number_of_roots_in_interval(None, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1, Infinity) + sage: pol.number_of_roots_in_interval(1, Infinity) # optional - sage.libs.pari 3 - sage: pol.number_of_roots_in_interval() + sage: pol.number_of_roots_in_interval() # optional - sage.libs.pari 3 - sage: pol = (x-1)*(x-2)*(x-3) + sage: pol = (x-1) * (x-2) * (x-3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_roots_in_interval() + sage: pol2.number_of_roots_in_interval() # optional - sage.libs.pari 3 sage: R. = PolynomialRing(CC) - sage: pol = (x-1)*(x-CC(I)) - sage: pol.number_of_roots_in_interval(0,2) + sage: pol = (x-1) * (x-CC(I)) + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 1 TESTS:: sage: R. = PolynomialRing(ZZ) sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_roots_in_interval(1, 2) + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 sage: pol = chebyshev_T(5,x) - sage: pol.number_of_roots_in_interval(-1,2) + sage: pol.number_of_roots_in_interval(-1, 2) # optional - sage.libs.pari 5 - sage: pol.number_of_roots_in_interval(0,2) + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 3 """ @@ -8613,15 +8697,15 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_real_roots() + sage: pol.number_of_real_roots() # optional - sage.libs.pari 3 - sage: pol = (x-1)*(x-2)*(x-3) + sage: pol = (x-1) * (x-2) * (x-3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_real_roots() + sage: pol2.number_of_real_roots() # optional - sage.libs.pari 3 sage: R. = PolynomialRing(CC) - sage: pol = (x-1)*(x-CC(I)) - sage: pol.number_of_real_roots() + sage: pol = (x-1) * (x-CC(I)) + sage: pol.number_of_real_roots() # optional - sage.libs.pari 1 """ return self.number_of_roots_in_interval() @@ -8635,17 +8719,17 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.all_roots_in_interval(1, 3) + sage: pol.all_roots_in_interval(1, 3) # optional - sage.libs.pari True - sage: pol.all_roots_in_interval(1.01, 3) + sage: pol.all_roots_in_interval(1.01, 3) # optional - sage.libs.pari False - sage: pol = chebyshev_T(5,x) - sage: pol.all_roots_in_interval(-1,1) + sage: pol = chebyshev_T(5, x) + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari True - sage: pol = chebyshev_T(5,x/2) - sage: pol.all_roots_in_interval(-1,1) + sage: pol = chebyshev_T(5, x/2) + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari False - sage: pol.all_roots_in_interval() + sage: pol.all_roots_in_interval() # optional - sage.libs.pari True """ pol = self // self.gcd(self.derivative()) @@ -8659,10 +8743,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = chebyshev_T(5, x) - sage: pol.is_real_rooted() + sage: pol.is_real_rooted() # optional - sage.libs.pari True sage: pol = x^2 + 1 - sage: pol.is_real_rooted() + sage: pol.is_real_rooted() # optional - sage.libs.pari False """ return self.all_roots_in_interval() @@ -8743,22 +8827,22 @@ cdef class Polynomial(CommutativePolynomial): We check that this function works for rings that have a coercion to the reals:: - sage: K. = NumberField(x^2-2,embedding=1.4) - sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4 - sage: u.trace_polynomial() + sage: K. = NumberField(x^2 - 2, embedding=1.4) # optional - sage.rings.number_field + sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4 # optional - sage.rings.number_field + sage: u.trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 1, 1, 2) - sage: (u*(x^2-2)).trace_polynomial() + sage: (u*(x^2-2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 1, x^2 - 2, 2) - sage: (u*(x^2-2)^2).trace_polynomial() + sage: (u*(x^2-2)^2).trace_polynomial() # optional - sage.rings.number_field (x^4 + a*x^3 - 9*x^2 - 8*a*x + 8, 1, 2) - sage: (u*(x^2-2)^3).trace_polynomial() + sage: (u*(x^2-2)^3).trace_polynomial() # optional - sage.rings.number_field (x^4 + a*x^3 - 9*x^2 - 8*a*x + 8, x^2 - 2, 2) - sage: u = x^4 + a*x^3 + 3*x^2 + 4*a*x + 16 - sage: u.trace_polynomial() + sage: u = x^4 + a*x^3 + 3*x^2 + 4*a*x + 16 # optional - sage.rings.number_field + sage: u.trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, 1, 4) - sage: (u*(x-2)).trace_polynomial() + sage: (u*(x-2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x - 2, 4) - sage: (u*(x+2)).trace_polynomial() + sage: (u*(x+2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x + 2, 4) TESTS: @@ -8814,8 +8898,8 @@ cdef class Polynomial(CommutativePolynomial): - ``self`` -- polynomial with rational or integer coefficients - ``return_q`` -- (default ``False``) if ``True``, return a second value `q` - which is the prime power with respect to which this is `q`-Weil, - or 0 if there is no such value. + which is the prime power with respect to which this is `q`-Weil, + or 0 if there is no such value. EXAMPLES:: @@ -8823,20 +8907,20 @@ cdef class Polynomial(CommutativePolynomial): sage: P0 = x^4 + 5*x^3 + 15*x^2 + 25*x + 25 sage: P1 = x^4 + 25*x^3 + 15*x^2 + 5*x + 25 sage: P2 = x^4 + 5*x^3 + 25*x^2 + 25*x + 25 - sage: P0.is_weil_polynomial(return_q=True) + sage: P0.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (True, 5) - sage: P0.is_weil_polynomial(return_q=False) + sage: P0.is_weil_polynomial(return_q=False) # optional - sage.libs.pari True - sage: P1.is_weil_polynomial(return_q=True) + sage: P1.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (False, 0) - sage: P1.is_weil_polynomial(return_q=False) + sage: P1.is_weil_polynomial(return_q=False) # optional - sage.libs.pari False - sage: P2.is_weil_polynomial() + sage: P2.is_weil_polynomial() # optional - sage.libs.pari False .. SEEALSO:: - Polynomial rings have a method `weil_polynomials` to compute sets of Weil + Polynomial rings have a method :meth:`weil_polynomials` to compute sets of Weil polynomials. This computation uses the iterator :class:`sage.rings.polynomial.weil.weil_polynomials.WeilPolynomials`. @@ -8846,7 +8930,7 @@ cdef class Polynomial(CommutativePolynomial): sage: P. = QQ[] sage: u = t^10 + 4*t^9 + 8*t^8 + 18*t^7 + 81*t^6 + 272*t^5 + 567*t^4 + 882*t^3 + 2744*t^2 + 9604*t + 16807 - sage: u.is_weil_polynomial() + sage: u.is_weil_polynomial() # optional - sage.libs.pari True AUTHORS: @@ -8962,21 +9046,21 @@ cdef class Polynomial(CommutativePolynomial): The actual algorithm for computing the extended gcd depends on the base ring underlying the polynomial ring. If the base ring defines - a method ``_xgcd_univariate_polynomial``, then this method will be + a method :meth:`_xgcd_univariate_polynomial`, then this method will be called (see examples below). EXAMPLES:: - sage: R. = QQbar[] - sage: (2*x^2).gcd(2*x) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (2*x^2).gcd(2*x) # optional - sage.rings.number_field x - sage: R.zero().gcd(0) + sage: R.zero().gcd(0) # optional - sage.rings.number_field 0 - sage: (2*x).gcd(0) + sage: (2*x).gcd(0) # optional - sage.rings.number_field x One can easily add xgcd functionality to new rings by providing a - method ``_xgcd_univariate_polynomial``:: + method :meth:`_xgcd_univariate_polynomial`:: sage: R. = QQ[] sage: S. = R[] @@ -8985,12 +9069,13 @@ cdef class Polynomial(CommutativePolynomial): sage: h1.xgcd(h2) Traceback (most recent call last): ... - NotImplementedError: Univariate Polynomial Ring in x over Rational Field does not provide an xgcd implementation for univariate polynomials + NotImplementedError: Univariate Polynomial Ring in x over Rational Field + does not provide an xgcd implementation for univariate polynomials sage: T. = QQ[] - sage: def poor_xgcd(f,g): + sage: def poor_xgcd(f, g): ....: ret = S(T(f).gcd(g)) - ....: if ret == f: return ret,S.one(),S.zero() - ....: if ret == g: return ret,S.zero(),S.one() + ....: if ret == f: return ret, S.one(), S.zero() + ....: if ret == g: return ret, S.zero(), S.one() ....: raise NotImplementedError sage: R._xgcd_univariate_polynomial = poor_xgcd sage: h1.xgcd(h2) @@ -9028,10 +9113,10 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PolynomialRing(QQ, 'z').gen() sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1 sage: m = z**21 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) - (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: n, d = p.rational_reconstruction(m); n, d + (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, + z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) + sage: ((p*d - n) % m).is_zero() True Over `\ZZ[z]`:: @@ -9039,10 +9124,10 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PolynomialRing(ZZ, 'z').gen() sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1 sage: m = z**21 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) - (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: n, d = p.rational_reconstruction(m); n, d + (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, + z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) + sage: ((p*d - n) % m).is_zero() True Over an integral domain ``d`` might not be monic:: @@ -9051,15 +9136,13 @@ cdef class Polynomial(CommutativePolynomial): sage: x = P.gen() sage: p = 7*x^5 - 10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256 sage: m = x^5 - sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 3, 2); n, d (-32*x^3 + 384*x^2 + 2304*x + 2048, 5*x + 8) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True - sage: n, d = p.rational_reconstruction(m, 4, 0) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 4, 0); n, d (-10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256, 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True Over `\QQ(t)[z]`:: @@ -9071,8 +9154,7 @@ cdef class Polynomial(CommutativePolynomial): sage: # p = (1 + t^2*z + z^4) / (1 - t*z) sage: p = (1 + t^2*z + z^4)*(1 - t*z).inverse_mod(z^9) sage: m = z^9 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m); n, d (-1/t*z^4 - t*z - 1/t, z - 1/t) sage: print(((p*d - n) % m ).is_zero()) True @@ -9080,8 +9162,9 @@ cdef class Polynomial(CommutativePolynomial): sage: n = -10*t^2*z^4 + (-t^2 + t - 1)*z^3 + (-t - 8)*z^2 + z + 2*t^2 - t sage: d = z^4 + (2*t + 4)*z^3 + (-t + 5)*z^2 + (t^2 + 2)*z + t^2 + 2*t + 1 sage: prec = 9 - sage: nc, dc = Pz((n.subs(z = w)/d.subs(z = w) + O(w^prec)).list()).rational_reconstruction(z^prec) - sage: print( (nc, dc) == (n, d) ) + sage: x = n.subs(z=w)/d.subs(z=w) + O(w^prec) + sage: nc, dc = Pz(x.list()).rational_reconstruction(z^prec) + sage: (nc, dc) == (n, d) True Over `\QQ[t][z]`:: @@ -9100,11 +9183,11 @@ cdef class Polynomial(CommutativePolynomial): Over `\QQ_5`:: - sage: x = PolynomialRing(Qp(5),'x').gen() - sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2 - sage: m = x^6 - sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print(((p*d - n) % m ).is_zero()) + sage: x = PolynomialRing(Qp(5), 'x').gen() # optional - sage.rings.padics + sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2 # optional - sage.rings.padics + sage: m = x^6 # optional - sage.rings.padics + sage: n, d = p.rational_reconstruction(m, 3, 2) # optional - sage.rings.padics + sage: print(((p*d - n) % m ).is_zero()) # optional - sage.rings.padics True Can also be used to obtain known Padé approximations:: @@ -9112,37 +9195,37 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PowerSeriesRing(QQ, 'z').gen() sage: P = PolynomialRing(QQ,'x') sage: x = P.gen() - sage: p = P(exp(z).list()) + sage: p = P(z.exp().list()) sage: m = x^5 sage: n, d = p.rational_reconstruction(m, 4, 0) - sage: print((n ,d)) + sage: print((n, d)) (1/24*x^4 + 1/6*x^3 + 1/2*x^2 + x + 1, 1) sage: print(((p*d - n) % m ).is_zero()) True sage: m = x^3 sage: n, d = p.rational_reconstruction(m, 1, 1) - sage: print((n ,d)) + sage: print((n, d)) (-x - 2, x - 2) sage: print(((p*d - n) % m ).is_zero()) True sage: p = P(log(1-z).list()) sage: m = x^9 sage: n, d = p.rational_reconstruction(m, 4, 4) - sage: print((n ,d)) + sage: print((n, d)) (25/6*x^4 - 130/3*x^3 + 105*x^2 - 70*x, x^4 - 20*x^3 + 90*x^2 - 140*x + 70) sage: print(((p*d - n) % m ).is_zero()) True sage: p = P(sqrt(1+z).list()) sage: m = x^6 sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print((n ,d)) + sage: print((n, d)) (1/6*x^3 + 3*x^2 + 8*x + 16/3, x^2 + 16/3*x + 16/3) sage: print(((p*d - n) % m ).is_zero()) True - sage: p = P(exp(2*z).list()) + sage: p = P((2*z).exp().list()) sage: m = x^7 sage: n, d = p.rational_reconstruction(m, 3, 3) - sage: print((n ,d)) + sage: print((n, d)) (-x^3 - 6*x^2 - 15*x - 15, x^3 - 6*x^2 + 15*x - 15) sage: print(((p*d - n) % m ).is_zero()) True @@ -9150,12 +9233,12 @@ cdef class Polynomial(CommutativePolynomial): Over `\RR[z]`:: sage: z = PowerSeriesRing(RR, 'z').gen() - sage: P = PolynomialRing(RR,'x') + sage: P = PolynomialRing(RR, 'x') sage: x = P.gen() - sage: p = P(exp(2*z).list()) + sage: p = P((2*z).exp().list()) sage: m = x^7 sage: n, d = p.rational_reconstruction(m, 3, 3) - sage: print((n ,d)) # absolute tolerance 1e-10 + sage: print((n, d)) # absolute tolerance 1e-10 (-x^3 - 6.0*x^2 - 15.0*x - 15.0, x^3 - 6.0*x^2 + 15.0*x - 15.0) .. SEEALSO:: @@ -9266,9 +9349,9 @@ cdef class Polynomial(CommutativePolynomial): `\infty`. If a prime (or non-prime) `p` is given, then the valuation - is the largest power of `p` which divides self. + is the largest power of `p` which divides ``self``. - The valuation at `\infty` is -self.degree(). + The valuation at `\infty` is ``-self.degree()``. EXAMPLES:: @@ -9358,11 +9441,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = ZZ[] - sage: (x^3 + 1).is_irreducible() + sage: (x^3 + 1).is_irreducible() # optional - sage.libs.pari False - sage: (x^2 - 1).is_irreducible() + sage: (x^2 - 1).is_irreducible() # optional - sage.libs.pari False - sage: (x^3 + 2).is_irreducible() + sage: (x^3 + 2).is_irreducible() # optional - sage.libs.pari True sage: R(0).is_irreducible() False @@ -9371,31 +9454,31 @@ cdef class Polynomial(CommutativePolynomial): polynomial in `\QQ[x]`, but not in `\ZZ[x]`:: sage: R. = ZZ[] - sage: R(2*x).is_irreducible() + sage: R(2*x).is_irreducible() # optional - sage.libs.pari False sage: R. = QQ[] - sage: R(2*x).is_irreducible() + sage: R(2*x).is_irreducible() # optional - sage.libs.pari True TESTS:: - sage: F. = NumberField(x^2-5) - sage: Fx. = PolynomialRing(F) - sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) - sage: f.is_irreducible() + sage: F. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: Fx. = PolynomialRing(F) # optional - sage.rings.number_field + sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) # optional - sage.rings.number_field + sage: f.is_irreducible() # optional - sage.rings.number_field False - sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) - sage: f.is_irreducible() + sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) # optional - sage.rings.number_field + sage: f.is_irreducible() # optional - sage.rings.number_field True If the base ring implements `_is_irreducible_univariate_polynomial`, then this method gets used instead of the generic algorithm which just factors the input:: - sage: R. = QQbar[] - sage: hasattr(QQbar, "_is_irreducible_univariate_polynomial") + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: hasattr(QQbar, "_is_irreducible_univariate_polynomial") # optional - sage.rings.number_field True - sage: (x^2 + 1).is_irreducible() + sage: (x^2 + 1).is_irreducible() # optional - sage.rings.number_field False Constants can be irreducible if they are not units:: @@ -9403,17 +9486,17 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: R(1).is_irreducible() False - sage: R(4).is_irreducible() + sage: R(4).is_irreducible() # optional - sage.libs.pari False - sage: R(5).is_irreducible() + sage: R(5).is_irreducible() # optional - sage.libs.pari True Check that caching works:: sage: R. = ZZ[] - sage: x.is_irreducible() + sage: x.is_irreducible() # optional - sage.libs.pari True - sage: x.is_irreducible.cache + sage: x.is_irreducible.cache # optional - sage.libs.pari True @@ -9513,13 +9596,13 @@ cdef class Polynomial(CommutativePolynomial): cpdef Polynomial truncate(self, long n): r""" - Return the polynomial of degree ` < n` which is equivalent + Return the polynomial of degree `< n` which is equivalent to self modulo `x^n`. EXAMPLES:: sage: R. = ZZ[]; S. = PolynomialRing(R, sparse=True) - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: f.truncate(2) x*y - 3*x @@ -9561,55 +9644,55 @@ cdef class Polynomial(CommutativePolynomial): computations:: sage: R. = ZZ[] - sage: (2*x).is_squarefree() + sage: (2*x).is_squarefree() # optional - sage.libs.pari True - sage: (4*x).is_squarefree() + sage: (4*x).is_squarefree() # optional - sage.libs.pari False - sage: (2*x^2).is_squarefree() + sage: (2*x^2).is_squarefree() # optional - sage.libs.pari False - sage: R(0).is_squarefree() + sage: R(0).is_squarefree() # optional - sage.libs.pari False - sage: S. = QQ[] - sage: R. = S[] - sage: (2*x*y).is_squarefree() + sage: S. = QQ[] # optional - sage.libs.pari + sage: R. = S[] # optional - sage.libs.pari + sage: (2*x*y).is_squarefree() # optional - sage.libs.pari True - sage: (2*x*y^2).is_squarefree() + sage: (2*x*y^2).is_squarefree() # optional - sage.libs.pari False In positive characteristic, we compute the square-free decomposition or a full factorization, depending on which is available:: - sage: K. = FunctionField(GF(3)) - sage: R. = K[] - sage: (x^3-x).is_squarefree() + sage: K. = FunctionField(GF(3)) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: (x^3 - x).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3-1).is_squarefree() + sage: (x^3 - 1).is_squarefree() # optional - sage.rings.finite_rings False - sage: (x^3+t).is_squarefree() + sage: (x^3 + t).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3+t^3).is_squarefree() + sage: (x^3 + t^3).is_squarefree() # optional - sage.rings.finite_rings False In the following example, `t^2` is a unit in the base field:: - sage: R(t^2).is_squarefree() + sage: R(t^2).is_squarefree() # optional - sage.rings.finite_rings True This method is not consistent with :meth:`.squarefree_decomposition`:: sage: R. = ZZ[] sage: f = 4 * x - sage: f.is_squarefree() + sage: f.is_squarefree() # optional - sage.rings.finite_rings False - sage: f.squarefree_decomposition() + sage: f.squarefree_decomposition() # optional - sage.rings.finite_rings (4) * x If you want this method equally not to consider the content, you can remove it as in the following example:: sage: c = f.content() - sage: (f/c).is_squarefree() + sage: (f/c).is_squarefree() # optional - sage.rings.finite_rings True If the base ring is not an integral domain, the question is not @@ -9638,15 +9721,15 @@ cdef class Polynomial(CommutativePolynomial): then this method gets used instead of the generic algorithm in :meth:`_is_squarefree_generic`:: - sage: R. = QQbar[] - sage: (x^2).is_squarefree() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^2).is_squarefree() # optional - sage.rings.number_field False - sage: hasattr(QQbar, '_is_squarefree_univariate_polynomial') + sage: hasattr(QQbar, '_is_squarefree_univariate_polynomial') # optional - sage.rings.number_field False - sage: QQbar._is_squarefree_univariate_polynomial = lambda self: True - sage: (x^2).is_squarefree() + sage: QQbar._is_squarefree_univariate_polynomial = lambda self: True # optional - sage.rings.number_field + sage: (x^2).is_squarefree() # optional - sage.rings.number_field True - sage: del(QQbar._is_squarefree_univariate_polynomial) + sage: del(QQbar._is_squarefree_univariate_polynomial) # optional - sage.rings.number_field """ B = self._parent.base_ring() @@ -9666,10 +9749,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x^2*(x + 1)).is_squarefree() # indirect doctest + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^2*(x + 1)).is_squarefree() # indirect doctest # optional - sage.rings.number_field False - sage: (x*(x+1)).is_squarefree() # indirect doctest + sage: (x*(x+1)).is_squarefree() # indirect doctest # optional - sage.rings.number_field True """ @@ -9701,12 +9784,12 @@ cdef class Polynomial(CommutativePolynomial): def radical(self): """ - Return the radical of self. + Return the radical of ``self``. Over a field, this is the product of - the distinct irreducible factors of self. (This is also sometimes + the distinct irreducible factors of ``self``. (This is also sometimes called the "square-free part" of self, but that term is ambiguous; - it is sometimes used to mean the quotient of self by its maximal + it is sometimes used to mean the quotient of ``self`` by its maximal square factor.) EXAMPLES:: @@ -9720,8 +9803,8 @@ cdef class Polynomial(CommutativePolynomial): If self has a factor of multiplicity divisible by the characteristic (see :trac:`8736`):: - sage: P. = GF(2)[] - sage: (x^3 + x^2).radical() + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: (x^3 + x^2).radical() # optional - sage.rings.finite_rings x^2 + x """ P = self._parent @@ -9850,10 +9933,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f = (x+1)^100 sage: f.number_of_terms() 101 - sage: S = GF(5)['y'] - sage: S(f).number_of_terms() + sage: S = GF(5)['y'] # optional - sage.rings.finite_rings + sage: S(f).number_of_terms() # optional - sage.rings.finite_rings 5 - sage: cyclotomic_polynomial(105).number_of_terms() + sage: cyclotomic_polynomial(105).number_of_terms() # optional - sage.rings.finite_rings 33 The method :meth:`hamming_weight` is an alias:: @@ -9889,17 +9972,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = SR[] - sage: f = (1+I)*x^2 + 3*x - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = SR[] # optional - sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic (-I + 1)*x^2 + 3*x + I sage: R. = ZZ[] sage: f = x^2 + 2 sage: f.map_coefficients(lambda a: a + 42) 43*x^2 + 44 - sage: R. = PolynomialRing(SR, sparse=True) - sage: f = (1+I)*x^(2^32) - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = PolynomialRing(SR, sparse=True) # optional - sage.symbolic + sage: f = (1+I)*x^(2^32) - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic (-I + 1)*x^4294967296 + I sage: R. = PolynomialRing(ZZ, sparse=True) sage: f = x^(2^32) + 2 @@ -9909,21 +9992,21 @@ cdef class Polynomial(CommutativePolynomial): Examples with different base ring:: sage: R. = ZZ[] - sage: k = GF(2) - sage: residue = lambda x: k(x) - sage: f = 4*x^2+x+3 - sage: g = f.map_coefficients(residue); g + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: residue = lambda x: k(x) # optional - sage.rings.finite_rings + sage: f = 4*x^2+x+3 # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Integer Ring - sage: g = f.map_coefficients(residue, new_base_ring = k); g + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: residue = k.coerce_map_from(ZZ) - sage: g = f.map_coefficients(residue); g + sage: residue = k.coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) """ R = self._parent @@ -9954,9 +10037,9 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``certificate`` -- boolean, default to ``False``. Only works with - ``algorithm`` set to "pari". + ``algorithm`` set to ``"pari"``. - - ``algorithm`` -- either "pari" or "sage" (default is "pari") + - ``algorithm`` -- either ``"pari"`` or ``"sage"`` (default is ``"pari"``) ALGORITHM: @@ -9971,38 +10054,38 @@ cdef class Polynomial(CommutativePolynomial): Quick tests:: sage: P. = ZZ['x'] - sage: (x - 1).is_cyclotomic() + sage: (x - 1).is_cyclotomic() # optional - sage.libs.pari True - sage: (x + 1).is_cyclotomic() + sage: (x + 1).is_cyclotomic() # optional - sage.libs.pari True - sage: (x^2 - 1).is_cyclotomic() + sage: (x^2 - 1).is_cyclotomic() # optional - sage.libs.pari False - sage: (x^2 + x + 1).is_cyclotomic(certificate=True) + sage: (x^2 + x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 3 - sage: (x^2 + 2*x + 1).is_cyclotomic(certificate=True) + sage: (x^2 + 2*x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 0 Test first 100 cyclotomic polynomials:: - sage: all(cyclotomic_polynomial(i).is_cyclotomic() for i in range(1,101)) + sage: all(cyclotomic_polynomial(i).is_cyclotomic() for i in range(1, 101)) # optional - sage.libs.pari True Some more tests:: - sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") + sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") # optional - sage.libs.pari False - sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") + sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") # optional - sage.libs.pari False - sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") + sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") # optional - sage.libs.pari True - sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") + sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") # optional - sage.libs.pari True sage: y = polygen(QQ) - sage: (y/2 - 1/2).is_cyclotomic() + sage: (y/2 - 1/2).is_cyclotomic() # optional - sage.libs.pari False - sage: (2*(y/2 - 1/2)).is_cyclotomic() + sage: (2*(y/2 - 1/2)).is_cyclotomic() # optional - sage.libs.pari True Invalid arguments:: @@ -10014,8 +10097,8 @@ cdef class Polynomial(CommutativePolynomial): Test using other rings:: - sage: z = polygen(GF(5)) - sage: (z - 1).is_cyclotomic() + sage: z = polygen(GF(5)) # optional - sage.rings.finite_rings + sage: (z - 1).is_cyclotomic() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: not implemented in non-zero characteristic @@ -10023,28 +10106,28 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R = ZZ['x'] - sage: for _ in range(20): + sage: for _ in range(20): # optional - sage.libs.pari ....: p = R.random_element(degree=randint(10,20)) ....: ans_pari = p.is_cyclotomic(algorithm="pari") ....: ans_sage = p.is_cyclotomic(algorithm="sage") ....: assert ans_pari == ans_sage, "problem with p={}".format(p) - sage: for d in range(2,20): + sage: for d in range(2, 20): # optional - sage.libs.pari ....: p = cyclotomic_polynomial(d) ....: assert p.is_cyclotomic(algorithm="pari"), "pari problem with p={}".format(p) ....: assert p.is_cyclotomic(algorithm="sage"), "sage problem with p={}".format(p) Test the output type when ``certificate=True``:: - sage: type((x^2 - 2).is_cyclotomic(certificate=True)) + sage: type((x^2 - 2).is_cyclotomic(certificate=True)) # optional - sage.libs.pari - sage: type((x -1).is_cyclotomic(certificate=True)) + sage: type((x - 1).is_cyclotomic(certificate=True)) # optional - sage.libs.pari Check that the arguments are forwarded when the input is not a polynomial with coefficients in `\ZZ`:: sage: x = polygen(QQ) - sage: (x-1).is_cyclotomic(certificate=True) + sage: (x - 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 1 """ S = self.base_ring() @@ -10121,20 +10204,20 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(ZZ) - sage: (x^5 - 1).is_cyclotomic_product() + sage: (x^5 - 1).is_cyclotomic_product() # optional - sage.libs.pari True - sage: (x^5 + x^4 - x^2 + 1).is_cyclotomic_product() + sage: (x^5 + x^4 - x^2 + 1).is_cyclotomic_product() # optional - sage.libs.pari False - sage: p = prod(cyclotomic_polynomial(i) for i in [2,5,7,12]) - sage: p.is_cyclotomic_product() + sage: p = prod(cyclotomic_polynomial(i) for i in [2, 5, 7, 12]) # optional - sage.libs.pari + sage: p.is_cyclotomic_product() # optional - sage.libs.pari True - sage: (x^5 - 1/3).is_cyclotomic_product() + sage: (x^5 - 1/3).is_cyclotomic_product() # optional - sage.libs.pari False sage: x = polygen(Zmod(5)) - sage: (x-1).is_cyclotomic_product() + sage: (x - 1).is_cyclotomic_product() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError: not implemented in non-zero characteristic @@ -10240,7 +10323,7 @@ cdef class Polynomial(CommutativePolynomial): The algorithm assumes that the polynomial has rational coefficients. If the polynomial is known to be irreducible, it may be slightly more - efficient to call `is_cyclotomic` instead. + efficient to call :meth:`is_cyclotomic` instead. .. SEEALSO:: @@ -10251,12 +10334,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: pol. = PolynomialRing(Rationals()) - sage: u = x^5-1; u.has_cyclotomic_factor() + sage: u = x^5 - 1; u.has_cyclotomic_factor() True - sage: u = x^5-2; u.has_cyclotomic_factor() + sage: u = x^5 - 2; u.has_cyclotomic_factor() False - sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() #random - sage: u.has_cyclotomic_factor() # random + sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() # random # optional - sage.libs.pari + sage: u.has_cyclotomic_factor() # random # optional - sage.libs.pari True """ if not QQ.has_coerce_map_from(self.base_ring()): @@ -10347,9 +10430,9 @@ cdef class Polynomial(CommutativePolynomial): In positive characteristic, the degree can drop in this case:: - sage: R. = GF(2)[] - sage: f = x + 1 - sage: f.homogenize(x) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: f = x + 1 # optional - sage.rings.finite_rings + sage: f.homogenize(x) # optional - sage.rings.finite_rings 0 For compatibility with the multivariate case, the parameter ``var`` can @@ -10405,7 +10488,7 @@ cdef class Polynomial(CommutativePolynomial): series. This method works only when the base ring is an integral domain. Moreover, for polynomial whose coefficient of lower degree is different from 1, the elements of the base - ring should have a method ``nth_root`` implemented. + ring should have a method :meth:`nth_root` implemented. EXAMPLES:: @@ -10426,43 +10509,43 @@ cdef class Polynomial(CommutativePolynomial): sage: a.nth_root(2) 1/56*x^3 + 103/336*x^2 + 365/252*x + 25/12 - sage: K. = QuadraticField(2) - sage: R. = K[] - sage: a = (x + sqrt2)^3 * ((1+sqrt2)*x - 1/sqrt2)^6 - sage: b = a.nth_root(3); b + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: a = (x + sqrt2)^3 * ((1+sqrt2)*x - 1/sqrt2)^6 # optional - sage.rings.number_field + sage: b = a.nth_root(3); b # optional - sage.rings.number_field (2*sqrt2 + 3)*x^3 + (2*sqrt2 + 2)*x^2 + (-2*sqrt2 - 3/2)*x + 1/2*sqrt2 - sage: b^3 == a + sage: b^3 == a # optional - sage.rings.number_field True - sage: R. = QQbar[] - sage: p = x**3 + QQbar(2).sqrt() * x - QQbar(3).sqrt() - sage: r = (p**5).nth_root(5) - sage: r * p[0] == p * r[0] + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = x**3 + QQbar(2).sqrt() * x - QQbar(3).sqrt() # optional - sage.rings.number_field + sage: r = (p**5).nth_root(5) # optional - sage.rings.number_field + sage: r * p[0] == p * r[0] # optional - sage.rings.number_field True - sage: p = (x+1)^20 + x^20 - sage: p.nth_root(20) + sage: p = (x+1)^20 + x^20 # optional - sage.rings.number_field + sage: p.nth_root(20) # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: not a 20th power - sage: z = GF(4).gen() - sage: R. = GF(4)[] - sage: p = z*x**4 + 2*x - 1 - sage: r = (p**15).nth_root(15) - sage: r * p[0] == p * r[0] + sage: z = GF(4).gen() # optional - sage.rings.finite_rings + sage: R. = GF(4)[] # optional - sage.rings.finite_rings + sage: p = z*x**4 + 2*x - 1 # optional - sage.rings.finite_rings + sage: r = (p**15).nth_root(15) # optional - sage.rings.finite_rings + sage: r * p[0] == p * r[0] # optional - sage.rings.finite_rings True - sage: ((x+1)**2).nth_root(2) + sage: ((x+1)**2).nth_root(2) # optional - sage.rings.finite_rings x + 1 - sage: ((x+1)**4).nth_root(4) + sage: ((x+1)**4).nth_root(4) # optional - sage.rings.finite_rings x + 1 - sage: ((x+1)**12).nth_root(12) + sage: ((x+1)**12).nth_root(12) # optional - sage.rings.finite_rings x + 1 - sage: (x^4 + x^3 + 1).nth_root(2) + sage: (x^4 + x^3 + 1).nth_root(2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 2nd power - sage: p = (x+1)^17 + x^17 - sage: r = p.nth_root(17) + sage: p = (x+1)^17 + x^17 # optional - sage.rings.finite_rings + sage: r = p.nth_root(17) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 17th power @@ -10479,14 +10562,14 @@ cdef class Polynomial(CommutativePolynomial): example with a non-trivial coefficient of lowest degree raises an error:: sage: R. = QQ[] - sage: R2 = R.quotient(x**2 + 1) - sage: x = R2.gen() - sage: R3. = R2[] - sage: (y**2 - 2*y + 1).nth_root(2) + sage: R2 = R.quotient(x**2 + 1) # optional - sage.libs.pari + sage: x = R2.gen() # optional - sage.libs.pari + sage: R3. = R2[] # optional - sage.libs.pari + sage: (y**2 - 2*y + 1).nth_root(2) # optional - sage.libs.pari -y + 1 - sage: (y**3).nth_root(3) + sage: (y**3).nth_root(3) # optional - sage.libs.pari y - sage: (y**2 + x).nth_root(2) + sage: (y**2 + x).nth_root(2) # optional - sage.libs.pari Traceback (most recent call last): ... AttributeError: ... has no attribute 'nth_root' @@ -10522,7 +10605,7 @@ cdef class Polynomial(CommutativePolynomial): Some random tests:: - sage: for R in [QQ['x'], GF(4)['x']]: + sage: for R in [QQ['x'], GF(4)['x']]: # optional - sage.rings.finite_rings ....: for _ in range(30): ....: p = R.random_element(degree=randint(10,20)) ....: n = ZZ.random_element(2,20) @@ -10606,10 +10689,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R.one()._nth_root_series(3, 5) 1 - sage: R. = QQbar[] - sage: p = 2 + 3*x^2 - sage: q = p._nth_root_series(3, 20) - sage: (q**3).truncate(20) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = 2 + 3*x^2 # optional - sage.rings.number_field + sage: q = p._nth_root_series(3, 20) # optional - sage.rings.number_field + sage: (q**3).truncate(20) # optional - sage.rings.number_field 3*x^2 + 2 The exponent must be invertible in the base ring:: @@ -10631,12 +10714,12 @@ cdef class Polynomial(CommutativePolynomial): Finite characteristic:: - sage: R. = GF(2)[] - sage: (1 + x)._nth_root_series(3, 10) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: (1 + x)._nth_root_series(3, 10) # optional - sage.rings.finite_rings x^9 + x^8 + x^3 + x^2 + x + 1 - sage: (1 + x^2)._nth_root_series(2, 10) + sage: (1 + x^2)._nth_root_series(2, 10) # optional - sage.rings.finite_rings x + 1 - sage: (1 + x)._nth_root_series(2, 10) + sage: (1 + x)._nth_root_series(2, 10) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 2nd power @@ -10715,7 +10798,7 @@ cdef class Polynomial(CommutativePolynomial): @coerce_binop def divides(self, p): r""" - Return `True` if this polynomial divides `p`. + Return ``True`` if this polynomial divides `p`. This method is only implemented for polynomials over an integral domain. @@ -10749,21 +10832,21 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = PolynomialRing(ZZ, implementation="NTL") - sage: (2*x + 1).divides(4*x**2 + 1) + sage: R. = PolynomialRing(ZZ, implementation="NTL") # optional - sage.libs.ntl + sage: (2*x + 1).divides(4*x**2 + 1) # optional - sage.libs.ntl False - sage: K. = GF(4) - sage: R. = K[] - sage: S. = R[] - sage: p = ((3*z + 2)*x + 2*z - 1) * y + 2*x + z - sage: q = y^2 + z*y*x + 2*y + z - sage: p.divides(q), p.divides(p*q) + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = ((3*z + 2)*x + 2*z - 1) * y + 2*x + z # optional - sage.rings.finite_rings + sage: q = y^2 + z*y*x + 2*y + z # optional - sage.rings.finite_rings + sage: p.divides(q), p.divides(p*q) # optional - sage.rings.finite_rings (False, True) - sage: R. = GF(2)[] - sage: S. = R[] - sage: p = (x+y+1) * z + x*y - sage: q = (y^2-x^2) * z^2 + z + x-y - sage: p.divides(q), p.divides(p*q) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = (x+y+1) * z + x*y # optional - sage.rings.finite_rings + sage: q = (y^2-x^2) * z^2 + z + x-y # optional - sage.rings.finite_rings + sage: p.divides(q), p.divides(p*q) # optional - sage.rings.finite_rings (False, True) """ if not self.base_ring().is_integral_domain(): @@ -10799,7 +10882,7 @@ cdef class Polynomial(CommutativePolynomial): - ``D`` -- dictionary (optional) - - ``phi`` -- SpecializationMorphism (optional) + - ``phi`` -- :class:`SpecializationMorphism` (optional) OUTPUT: a new polynomial @@ -11362,14 +11445,14 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = SR[] - sage: R(0).is_term() + sage: R. = SR[] # optional - sage.symbolic + sage: R(0).is_term() # optional - sage.symbolic False - sage: R(1).is_term() + sage: R(1).is_term() # optional - sage.symbolic True - sage: (3*x^5).is_term() + sage: (3*x^5).is_term() # optional - sage.symbolic True - sage: (1+3*x^5).is_term() + sage: (1 + 3*x^5).is_term() # optional - sage.symbolic False """ if not self.__coeffs: @@ -11493,30 +11576,30 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: f = (1+2*x)^3 + 3*x; f + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.number_field 8*x^3 + 12*x^2 + 9*x + 1 - sage: g = f // (1+2*x); g + sage: g = f // (1+2*x); g # optional - sage.rings.number_field 4*x^2 + 4*x + 5/2 - sage: f - g * (1+2*x) + sage: f - g * (1+2*x) # optional - sage.rings.number_field -3/2 - sage: f.quo_rem(1+2*x) + sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field (4*x^2 + 4*x + 5/2, -3/2) TESTS: Check that :trac:`13048` and :trac:`2034` are fixed:: - sage: R. = QQbar[] - sage: x // x + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x // x # optional - sage.rings.number_field 1 - sage: x // 1 + sage: x // 1 # optional - sage.rings.number_field x - sage: x // int(1) + sage: x // int(1) # optional - sage.rings.number_field x - sage: x //= int(1); x + sage: x //= int(1); x # optional - sage.rings.number_field x - sage: int(1) // x # check that this doesn't segfault + sage: int(1) // x # check that this doesn't segfault # optional - sage.rings.number_field Traceback (most recent call last): ... AttributeError: type object 'int' has no attribute 'base_ring' @@ -11609,8 +11692,7 @@ cdef class Polynomial_generic_dense(Polynomial): """ Return the constant coefficient of this polynomial. - OUTPUT: - element of base ring + OUTPUT: element of base ring EXAMPLES:: @@ -11631,10 +11713,10 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = GF(17)[] - sage: f = (1+2*x)^3 + 3*x; f + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.finite_rings 8*x^3 + 12*x^2 + 9*x + 1 - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [1, 9, 12, 8] """ if copy: @@ -11711,8 +11793,8 @@ cdef class Polynomial_generic_dense(Polynomial): Return the quotient and remainder of the Euclidean division of ``self`` and ``other``. - Raises a ``ZerodivisionError`` if ``other`` is zero. Raises an - ``ArithmeticError`` if the division is not exact. + Raises a :class:`ZerodivisionError` if ``other`` is zero. Raises an + :class:`ArithmeticError` if the division is not exact. EXAMPLES:: @@ -11737,12 +11819,12 @@ cdef class Polynomial_generic_dense(Polynomial): Polynomials over noncommutative rings are also allowed (after :trac:`34733`):: - sage: HH = QuaternionAlgebra(QQ, -1, -1) - sage: P. = HH[] - sage: f = P.random_element(5) - sage: g = P.random_element((0, 5)) - sage: q, r = f.quo_rem(g) - sage: f == q*g + r + sage: HH = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: P. = HH[] # optional - sage.combinat sage.modules + sage: f = P.random_element(5) # optional - sage.combinat sage.modules + sage: g = P.random_element((0, 5)) # optional - sage.combinat sage.modules + sage: q, r = f.quo_rem(g) # optional - sage.combinat sage.modules + sage: f == q*g + r # optional - sage.combinat sage.modules True TESTS: @@ -11812,7 +11894,7 @@ cdef class Polynomial_generic_dense(Polynomial): cpdef Polynomial truncate(self, long n): r""" - Return the polynomial of degree ` < n` which is equivalent + Return the polynomial of degree `< n` which is equivalent to self modulo `x^n`. EXAMPLES:: @@ -11874,13 +11956,13 @@ def universal_discriminant(n): EXAMPLES:: sage: from sage.rings.polynomial.polynomial_element import universal_discriminant - sage: universal_discriminant(1) + sage: universal_discriminant(1) # optional - sage.libs.pari 1 - sage: universal_discriminant(2) + sage: universal_discriminant(2) # optional - sage.libs.pari a1^2 - 4*a0*a2 - sage: universal_discriminant(3) + sage: universal_discriminant(3) # optional - sage.libs.pari a1^2*a2^2 - 4*a0*a2^3 - 4*a1^3*a3 + 18*a0*a1*a2*a3 - 27*a0^2*a3^2 - sage: universal_discriminant(4).degrees() + sage: universal_discriminant(4).degrees() # optional - sage.libs.pari (3, 4, 4, 4, 3) .. SEEALSO:: @@ -11910,7 +11992,7 @@ cpdef Polynomial generic_power_trunc(Polynomial p, Integer n, long prec): sage: from sage.rings.polynomial.polynomial_element import generic_power_trunc - sage: for S in [ZZ, GF(3)]: # known bug # not tested (see :trac:`32075`) + sage: for S in [ZZ, GF(3)]: # known bug # not tested (see :trac:`32075`) # optional - sage.rings.finite_rings ....: R = PolynomialRing(S, 'x') ....: for _ in range(100): ....: p = R.random_element() @@ -12010,9 +12092,9 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): Coefficients indistinguishable from 0 are not removed. - sage: R = Zp(5) - sage: S. = R[] - sage: S([1,R(0,20)]) + sage: R = Zp(5) # optional - sage.rings.padics + sage: S. = R[] # optional - sage.rings.padics + sage: S([1, R(0, 20)]) # optional - sage.rings.padics O(5^20)*x + 1 + O(5^20) """ cdef list x = self.__coeffs @@ -12046,27 +12128,27 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): EXAMPLES:: - sage: K = Qp(3,10) - sage: R. = K[] - sage: f = T + 2; f + sage: K = Qp(3, 10) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = T + 2; f # optional - sage.rings.padics (1 + O(3^10))*T + 2 + O(3^10) - sage: f.degree() + sage: f.degree() # optional - sage.rings.padics 1 - sage: (f-T).degree() + sage: (f - T).degree() # optional - sage.rings.padics 0 - sage: (f-T).degree(secure=True) + sage: (f - T).degree(secure=True) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: the leading coefficient is indistinguishable from 0 - sage: x = O(3^5) - sage: li = [3^i * x for i in range(0,5)]; li + sage: x = O(3^5) # optional - sage.rings.padics + sage: li = [3^i * x for i in range(0,5)]; li # optional - sage.rings.padics [O(3^5), O(3^6), O(3^7), O(3^8), O(3^9)] - sage: f = R(li); f + sage: f = R(li); f # optional - sage.rings.padics O(3^9)*T^4 + O(3^8)*T^3 + O(3^7)*T^2 + O(3^6)*T + O(3^5) - sage: f.degree() + sage: f.degree() # optional - sage.rings.padics -1 - sage: f.degree(secure=True) + sage: f.degree(secure=True) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: the leading coefficient is indistinguishable from 0 @@ -12098,20 +12180,20 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): EXAMPLES:: - sage: K = Qp(3,10) - sage: R. = K[] - sage: f = T + 2; f + sage: K = Qp(3, 10) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = T + 2; f # optional - sage.rings.padics (1 + O(3^10))*T + 2 + O(3^10) - sage: f.degree() + sage: f.degree() # optional - sage.rings.padics 1 - sage: f.prec_degree() + sage: f.prec_degree() # optional - sage.rings.padics 1 - sage: g = f - T; g + sage: g = f - T; g # optional - sage.rings.padics O(3^10)*T + 2 + O(3^10) - sage: g.degree() + sage: g.degree() # optional - sage.rings.padics 0 - sage: g.prec_degree() + sage: g.prec_degree() # optional - sage.rings.padics 1 AUTHOR: @@ -12125,25 +12207,25 @@ cdef class ConstantPolynomialSection(Map): """ This class is used for conversion from a polynomial ring to its base ring. - Since :trac:`9944`, it calls the ``constant_coefficient`` method, + Since :trac:`9944`, it calls the :meth:`constant_coefficient` method, which can be optimized for a particular polynomial type. EXAMPLES:: - sage: P0. = GF(3)[] - sage: P1. = GF(3)[] - sage: P0(-y_1) # indirect doctest + sage: P0. = GF(3)[] # optional - sage.rings.finite_rings + sage: P1. = GF(3)[] # optional - sage.rings.finite_rings + sage: P0(-y_1) # indirect doctest # optional - sage.rings.finite_rings 2*y_1 - sage: phi = GF(3).convert_map_from(P0); phi + sage: phi = GF(3).convert_map_from(P0); phi # optional - sage.rings.finite_rings Generic map: From: Univariate Polynomial Ring in y_1 over Finite Field of size 3 To: Finite Field of size 3 - sage: type(phi) + sage: type(phi) # optional - sage.rings.finite_rings - sage: phi(P0.one()) + sage: phi(P0.one()) # optional - sage.rings.finite_rings 1 - sage: phi(y_1) + sage: phi(y_1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: not a constant polynomial @@ -12180,12 +12262,12 @@ cdef class PolynomialBaseringInjection(Morphism): This class is used for conversion from a ring to a polynomial over that ring. - It calls the _new_constant_poly method on the generator, + It calls the :meth:`_new_constant_poly` method on the generator, which should be optimized for a particular polynomial type. Technically, it should be a method of the polynomial ring, but - few polynomial rings are cython classes, and so, as a method - of a cython polynomial class, it is faster. + few polynomial rings are Cython classes, and so, as a method + of a Cython polynomial class, it is faster. EXAMPLES: @@ -12194,16 +12276,18 @@ cdef class PolynomialBaseringInjection(Morphism): supposed to be the fastest maps for that purpose. See :trac:`9944`. :: - sage: R. = Qp(3)[] - sage: R.coerce_map_from(R.base_ring()) + sage: R. = Qp(3)[] # optional - sage.rings.padics + sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics Polynomial base injection morphism: From: 3-adic Field with capped relative precision 20 - To: Univariate Polynomial Ring in x over 3-adic Field with capped relative precision 20 - sage: R. = Qp(3)[] - sage: R.coerce_map_from(R.base_ring()) + To: Univariate Polynomial Ring in x over + 3-adic Field with capped relative precision 20 + sage: R. = Qp(3)[] # optional - sage.rings.padics + sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics Polynomial base injection morphism: From: 3-adic Field with capped relative precision 20 - To: Multivariate Polynomial Ring in x, y over 3-adic Field with capped relative precision 20 + To: Multivariate Polynomial Ring in x, y over + 3-adic Field with capped relative precision 20 sage: R. = QQ[] sage: R.coerce_map_from(R.base_ring()) Polynomial base injection morphism: @@ -12242,11 +12326,11 @@ cdef class PolynomialBaseringInjection(Morphism): :: - sage: R. = Qp(2)[] - sage: f = R.convert_map_from(R.base_ring()) # indirect doctest - sage: f(Qp(2).one()*3) + sage: R. = Qp(2)[] # optional - sage.rings.padics + sage: f = R.convert_map_from(R.base_ring()) # indirect doctest # optional - sage.rings.padics + sage: f(Qp(2).one()*3) # optional - sage.rings.padics 1 + 2 + O(2^20) - sage: (Qp(2).one()*3)*t + sage: (Qp(2).one()*3)*t # optional - sage.rings.padics (1 + 2 + O(2^20))*t """ assert codomain.base_ring() is domain, "domain must be basering" @@ -12310,8 +12394,8 @@ cdef class PolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.polynomial_element import PolynomialBaseringInjection - sage: m = PolynomialBaseringInjection(Qp(5), Qp(5)['x']) - sage: m(1 + O(5^11), absprec = 5) # indirect doctest + sage: m = PolynomialBaseringInjection(Qp(5), Qp(5)['x']) # optional - sage.rings.padics + sage: m(1 + O(5^11), absprec=5) # indirect doctest # optional - sage.rings.padics 1 + O(5^11) """ try: diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index 78692bc93d8..1a02968b547 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -12,12 +12,12 @@ We test coercion in a particularly complicated situation:: - sage: W.=QQ['w'] - sage: WZ.=W['z'] - sage: m = matrix(WZ,2,2,[1,z,z,z^2]) - sage: a = m.charpoly() - sage: R. = WZ[] - sage: R(a) + sage: W. = QQ['w'] + sage: WZ. = W['z'] + sage: m = matrix(WZ, 2, 2, [1, z, z, z^2]) # optional - sage.modules + sage: a = m.charpoly() # optional - sage.modules + sage: R. = WZ[] # optional - sage.modules + sage: R(a) # optional - sage.modules x^2 + (-z^2 - 1)*x """ @@ -65,13 +65,15 @@ class Polynomial_generic_sparse(Polynomial): A more extensive example:: - sage: A. = PolynomialRing(Integers(5),sparse=True) ; f = T^2+1 ; B = A.quo(f) - sage: C. = PolynomialRing(B) - sage: C - Univariate Polynomial Ring in s over Univariate Quotient Polynomial Ring in Tbar over Ring of integers modulo 5 with modulus T^2 + 1 - sage: s + T + sage: A. = PolynomialRing(Integers(5), sparse=True) # optional - sage.libs.pari + sage: f = T^2 + 1; B = A.quo(f) + sage: C. = PolynomialRing(B) # optional - sage.libs.pari + sage: C # optional - sage.libs.pari + Univariate Polynomial Ring in s over Univariate Quotient Polynomial Ring in Tbar + over Ring of integers modulo 5 with modulus T^2 + 1 + sage: s + T # optional - sage.libs.pari s + Tbar - sage: (s + T)**2 + sage: (s + T)**2 # optional - sage.libs.pari s^2 + 2*Tbar*s + 4 """ @@ -188,13 +190,13 @@ def valuation(self, p=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(9,'a'), sparse=True) - sage: f = w^1997 - w^10000 - sage: f.valuation() + sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.rings.finite_rings + sage: f = w^1997 - w^10000 # optional - sage.rings.finite_rings + sage: f.valuation() # optional - sage.rings.finite_rings 1997 - sage: R(19).valuation() + sage: R(19).valuation() # optional - sage.rings.finite_rings 0 - sage: R(0).valuation() + sage: R(0).valuation() # optional - sage.rings.finite_rings +Infinity """ if not self.__coeffs: @@ -243,10 +245,10 @@ def _derivative(self, var=None): Check that :trac:`28187` is fixed:: sage: R = PolynomialRing(ZZ, 't', sparse=True) - sage: t, u = var('t, u') - sage: R.gen()._derivative(t) + sage: t, u = var('t, u') # optional - sage.symbolic + sage: R.gen()._derivative(t) # optional - sage.symbolic 1 - sage: R.gen()._derivative(u) + sage: R.gen()._derivative(u) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to u @@ -417,14 +419,14 @@ def __getitem__(self, n): EXAMPLES:: sage: R. = PolynomialRing(RDF, sparse=True) - sage: e = RDF(e) - sage: f = sum(e^n*w^n for n in range(4)); f # abs tol 1.1e-14 + sage: e = RDF(e) # optional - sage.symbolic + sage: f = sum(e^n*w^n for n in range(4)); f # abs tol 1.1e-14 # optional - sage.symbolic 20.085536923187664*w^3 + 7.3890560989306495*w^2 + 2.718281828459045*w + 1.0 - sage: f[1] # abs tol 5e-16 + sage: f[1] # abs tol 5e-16 # optional - sage.symbolic 2.718281828459045 - sage: f[5] + sage: f[5] # optional - sage.symbolic 0.0 - sage: f[-1] + sage: f[-1] # optional - sage.symbolic 0.0 sage: R. = PolynomialRing(RealField(19), sparse=True) sage: f = (2-3.5*x)^3; f @@ -547,14 +549,14 @@ def __floordiv__(self, right): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, sparse=True) - sage: f = (1+2*x)^3 + 3*x; f + sage: R. = PolynomialRing(QQbar, sparse=True) # optional - sage.rings.number_field + sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.number_field 8*x^3 + 12*x^2 + 9*x + 1 - sage: g = f // (1+2*x); g + sage: g = f // (1+2*x); g # optional - sage.rings.number_field 4*x^2 + 4*x + 5/2 - sage: f - g * (1+2*x) + sage: f - g * (1+2*x) # optional - sage.rings.number_field -3/2 - sage: f.quo_rem(1+2*x) + sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field (4*x^2 + 4*x + 5/2, -3/2) """ @@ -788,9 +790,9 @@ def quo_rem(self, other): Returns the quotient and remainder of the Euclidean division of ``self`` and ``other``. - Raises ZerodivisionError if ``other`` is zero. + Raises :class:`ZerodivisionError` if ``other`` is zero. - Raises ArithmeticError if ``other`` has a nonunit leading coefficient + Raises :class:`ArithmeticError` if ``other`` has a nonunit leading coefficient and this causes the Euclidean division to fail. EXAMPLES:: @@ -808,7 +810,8 @@ def quo_rem(self, other): sage: f.quo_rem(g) Traceback (most recent call last): ... - ArithmeticError: Division non exact (consider coercing to polynomials over the fraction field) + ArithmeticError: Division non exact + (consider coercing to polynomials over the fraction field) sage: g = 0 sage: f.quo_rem(g) Traceback (most recent call last): @@ -824,12 +827,12 @@ def quo_rem(self, other): Polynomials over noncommutative rings are also allowed:: - sage: HH = QuaternionAlgebra(QQ, -1, -1) - sage: P. = PolynomialRing(HH, sparse=True) - sage: f = P.random_element(5) - sage: g = P.random_element((0, 5)) - sage: q, r = f.quo_rem(g) - sage: f == q*g + r + sage: HH = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: P. = PolynomialRing(HH, sparse=True) # optional - sage.combinat sage.modules + sage: f = P.random_element(5) # optional - sage.combinat sage.modules + sage: g = P.random_element((0, 5)) # optional - sage.combinat sage.modules + sage: q, r = f.quo_rem(g) # optional - sage.combinat sage.modules + sage: f == q*g + r # optional - sage.combinat sage.modules True TESTS:: @@ -971,7 +974,7 @@ def reverse(self, degree=None): """ Return this polynomial but with the coefficients reversed. - If an optional degree argument is given the coefficient list will be + If an optional degree argument is given, the coefficient list will be truncated or zero padded as necessary and the reverse polynomial will have the specified degree. @@ -993,7 +996,7 @@ def reverse(self, degree=None): def truncate(self, n): """ - Return the polynomial of degree `< n` equal to `self` modulo `x^n`. + Return the polynomial of degree `< n` equal to ``self`` modulo `x^n`. EXAMPLES:: @@ -1058,17 +1061,17 @@ class Polynomial_generic_field(Polynomial_singular_repr, @coerce_binop def quo_rem(self, other): """ - Returns a tuple (quotient, remainder) where - self = quotient * other + remainder. + Returns a tuple ``(quotient, remainder)`` where + ``self = quotient * other + remainder``. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(y^2 - 2) - sage: P. = PolynomialRing(K) - sage: x.quo_rem(K(1)) + sage: K. = NumberField(y^2 - 2) # optional - sage.rings.number_field + sage: P. = PolynomialRing(K) # optional - sage.rings.number_field + sage: x.quo_rem(K(1)) # optional - sage.rings.number_field (x, 0) - sage: x.xgcd(K(1)) + sage: x.xgcd(K(1)) # optional - sage.rings.number_field (1, 0, 1) """ P = self.parent() @@ -1139,15 +1142,15 @@ def newton_slopes(self, repetition=True): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_polygon() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_polygon() # optional - sage.rings.padics Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) - sage: f.newton_slopes() + sage: f.newton_slopes() # optional - sage.rings.padics [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: f.newton_slopes(repetition=False) + sage: f.newton_slopes(repetition=False) # optional - sage.rings.padics [1, 0, -1/3] AUTHOR: @@ -1167,15 +1170,15 @@ def newton_polygon(self): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_polygon() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_polygon() # optional - sage.rings.padics Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) - sage: g = f + K(0,0)*t^4; g + sage: g = f + K(0,0)*t^4; g # optional - sage.rings.padics (5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21) - sage: g.newton_polygon() + sage: g.newton_polygon() # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: The coefficient of t^4 has not enough precision @@ -1184,10 +1187,10 @@ def newton_polygon(self): Check that :trac:`22936` is fixed:: - sage: S. = PowerSeriesRing(GF(5)) - sage: R. = S[] - sage: p = x^2+y+x*y^2 - sage: p.newton_polygon() + sage: S. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: R. = S[] # optional - sage.rings.finite_rings + sage: p = x^2 + y + x*y^2 # optional - sage.rings.finite_rings + sage: p.newton_polygon() # optional - sage.rings.finite_rings Finite Newton polygon with 3 vertices: (0, 2), (1, 0), (2, 1) AUTHOR: @@ -1222,16 +1225,16 @@ def hensel_lift(self, a): EXAMPLES:: - sage: K = Qp(5, 10) - sage: P. = PolynomialRing(K) - sage: f = x^2 + 1 - sage: root = f.hensel_lift(2); root + sage: K = Qp(5, 10) # optional - sage.rings.padics + sage: P. = PolynomialRing(K) # optional - sage.rings.padics + sage: f = x^2 + 1 # optional - sage.rings.padics + sage: root = f.hensel_lift(2); root # optional - sage.rings.padics 2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10) - sage: f(root) + sage: f(root) # optional - sage.rings.padics O(5^10) - sage: g = (x^2 + 1)*(x - 7) - sage: g.hensel_lift(2) # here, 2 is a multiple root modulo p + sage: g = (x^2 + 1)*(x - 7) # optional - sage.rings.padics + sage: g.hensel_lift(2) # here, 2 is a multiple root modulo p # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: a is not close enough to a root of this polynomial @@ -1270,27 +1273,27 @@ def _factor_of_degree(self, deg): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics - sage: g = f._factor_of_degree(4) - sage: (f % g).is_zero() + sage: g = f._factor_of_degree(4) # optional - sage.rings.padics + sage: (f % g).is_zero() # optional - sage.rings.padics True - sage: g = f._factor_of_degree(3) # not tested + sage: g = f._factor_of_degree(3) # not tested # optional - sage.rings.padics Traceback (most recent call last) ... KeyboardInterrupt: TESTS:: - sage: S. = PowerSeriesRing(GF(5)) - sage: R. = S[] - sage: p = x^2+y+x*y^2 - sage: p._factor_of_degree(1) + sage: S. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: R. = S[] # optional - sage.rings.finite_rings + sage: p = x^2 + y + x*y^2 # optional - sage.rings.finite_rings + sage: p._factor_of_degree(1) # optional - sage.rings.finite_rings (1 + O(x^20))*y + x^2 + x^5 + 2*x^8 + 4*x^14 + 2*x^17 + 2*x^20 + O(x^22) AUTHOR: @@ -1334,30 +1337,30 @@ def factor_of_slope(self, slope=None): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_slopes() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_slopes() # optional - sage.rings.padics [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: g = f.factor_of_slope(0) - sage: g.newton_slopes() + sage: g = f.factor_of_slope(0) # optional - sage.rings.padics + sage: g.newton_slopes() # optional - sage.rings.padics [0, 0, 0] - sage: (f % g).is_zero() + sage: (f % g).is_zero() # optional - sage.rings.padics True - sage: h = f.factor_of_slope() - sage: h.newton_slopes() + sage: h = f.factor_of_slope() # optional - sage.rings.padics + sage: h.newton_slopes() # optional - sage.rings.padics [1] - sage: (f % h).is_zero() + sage: (f % h).is_zero() # optional - sage.rings.padics True If ``slope`` is not a slope of ``self``, the corresponding factor is `1`:: - sage: f.factor_of_slope(-1) + sage: f.factor_of_slope(-1) # optional - sage.rings.padics 1 + O(5^20) AUTHOR: @@ -1403,18 +1406,18 @@ def slope_factorization(self): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_slopes() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_slopes() # optional - sage.rings.padics [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: F = f.slope_factorization() - sage: F.prod() == f + sage: F = f.slope_factorization() # optional - sage.rings.padics + sage: F.prod() == f # optional - sage.rings.padics True - sage: for (f,_) in F: + sage: for (f,_) in F: # optional - sage.rings.padics ....: print(f.newton_slopes()) [-1/3, -1/3, -1/3, -1/3, -1/3, -1/3] [0, 0, 0] @@ -1422,11 +1425,13 @@ def slope_factorization(self): TESTS:: - sage: S. = PowerSeriesRing(GF(5)) - sage: R. = S[] - sage: p = x^2+y+x*y^2 - sage: p.slope_factorization() - (x) * ((x + O(x^22))*y + 1 + 4*x^3 + 4*x^6 + 3*x^9 + x^15 + 3*x^18 + O(x^21)) * ((x^-1 + O(x^20))*y + x + x^4 + 2*x^7 + 4*x^13 + 2*x^16 + 2*x^19 + O(x^22)) + sage: S. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: R. = S[] # optional - sage.rings.finite_rings + sage: p = x^2 + y + x*y^2 # optional - sage.rings.finite_rings + sage: p.slope_factorization() # optional - sage.rings.finite_rings + (x) + * ((x + O(x^22))*y + 1 + 4*x^3 + 4*x^6 + 3*x^9 + x^15 + 3*x^18 + O(x^21)) + * ((x^-1 + O(x^20))*y + x + x^4 + 2*x^7 + 4*x^13 + 2*x^16 + 2*x^19 + O(x^22)) AUTHOR: @@ -1478,11 +1483,11 @@ def _roots(self, secure, minval, hint): TESTS:: - sage: R = Zp(2) - sage: S. = R[] - sage: P = (x-1) * (x-2) * (x-4) * (x-8) * (x-16) - sage: Q = P^2 - sage: Q.roots(algorithm="sage") # indirect doctest + sage: R = Zp(2) # optional - sage.rings.padics + sage: S. = R[] # optional - sage.rings.padics + sage: P = (x-1) * (x-2) * (x-4) * (x-8) * (x-16) # optional - sage.rings.padics + sage: Q = P^2 # optional - sage.rings.padics + sage: Q.roots(algorithm="sage") # indirect doctest # optional - sage.rings.padics [(2^4 + O(2^14), 2), (2^3 + O(2^13), 2), (2^2 + O(2^12), 2), diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index 0c9be09df64..cd981c671a3 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -5,14 +5,14 @@ EXAMPLES:: sage: R. = QQ[] - sage: S = R.quotient(x**3-3*x+1, 'alpha') - sage: S.gen()**2 in S + sage: S = R.quotient(x**3 - 3*x + 1, 'alpha') # optional - sage.libs.pari + sage: S.gen()**2 in S # optional - sage.libs.pari True - sage: x in S + sage: x in S # optional - sage.libs.pari True - sage: S.gen() in R + sage: S.gen() in R # optional - sage.libs.pari False - sage: 1 in S + sage: 1 in S # optional - sage.libs.pari True TESTS:: @@ -80,25 +80,26 @@ class PolynomialQuotientRingFactory(UniqueFactory): demonstrate many basic functions with it:: sage: Z = IntegerRing() - sage: R = PolynomialRing(Z,'x'); x = R.gen() - sage: S = R.quotient(x^3 + 7, 'a'); a = S.gen() - sage: S - Univariate Quotient Polynomial Ring in a over Integer Ring with modulus x^3 + 7 - sage: a^3 + sage: R = PolynomialRing(Z, 'x'); x = R.gen() + sage: S = R.quotient(x^3 + 7, 'a'); a = S.gen() # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a + over Integer Ring with modulus x^3 + 7 + sage: a^3 # optional - sage.libs.pari -7 - sage: S.is_field() + sage: S.is_field() # optional - sage.libs.pari False - sage: a in S + sage: a in S # optional - sage.libs.pari True - sage: x in S + sage: x in S # optional - sage.libs.pari True - sage: a in R + sage: a in R # optional - sage.libs.pari False - sage: S.polynomial_ring() + sage: S.polynomial_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring - sage: S.modulus() + sage: S.modulus() # optional - sage.libs.pari x^3 + 7 - sage: S.degree() + sage: S.degree() # optional - sage.libs.pari 3 We create the "iterated" polynomial ring quotient @@ -109,35 +110,43 @@ class PolynomialQuotientRingFactory(UniqueFactory): :: - sage: A. = PolynomialRing(GF(2)); A + sage: A. = PolynomialRing(GF(2)); A # optional - sage.rings.finite_rings Univariate Polynomial Ring in y over Finite Field of size 2 (using GF2X) - sage: B = A.quotient(y^2 + y + 1, 'y2'); B - Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1 - sage: C = PolynomialRing(B, 'x'); x=C.gen(); C - Univariate Polynomial Ring in x over Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1 - sage: R = C.quotient(x^3 - 5); R - Univariate Quotient Polynomial Ring in xbar over Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1 with modulus x^3 + 1 + sage: B = A.quotient(y^2 + y + 1, 'y2'); B # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 + with modulus y^2 + y + 1 + sage: C = PolynomialRing(B, 'x'); x = C.gen(); C # optional - sage.rings.finite_rings + Univariate Polynomial Ring in x + over Univariate Quotient Polynomial Ring in y2 + over Finite Field of size 2 with modulus y^2 + y + 1 + sage: R = C.quotient(x^3 - 5); R # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in xbar + over Univariate Quotient Polynomial Ring in y2 + over Finite Field of size 2 with modulus y^2 + y + 1 + with modulus x^3 + 1 Next we create a number field, but viewed as a quotient of a polynomial ring over `\QQ`:: sage: R = PolynomialRing(RationalField(), 'x'); x = R.gen() - sage: S = R.quotient(x^3 + 2*x - 5, 'a') - sage: S - Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^3 + 2*x - 5 - sage: S.is_field() + sage: S = R.quotient(x^3 + 2*x - 5, 'a') # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a over Rational Field + with modulus x^3 + 2*x - 5 + sage: S.is_field() # optional - sage.libs.pari True - sage: S.degree() + sage: S.degree() # optional - sage.libs.pari 3 There are conversion functions for easily going back and forth between quotients of polynomial rings over `\QQ` and number fields:: - sage: K = S.number_field(); K + sage: K = S.number_field(); K # optional - sage.libs.pari sage.rings.number_field Number Field in a with defining polynomial x^3 + 2*x - 5 - sage: K.polynomial_quotient_ring() - Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^3 + 2*x - 5 + sage: K.polynomial_quotient_ring() # optional - sage.libs.pari sage.rings.number_field + Univariate Quotient Polynomial Ring in a + over Rational Field with modulus x^3 + 2*x - 5 The leading coefficient must be a unit (but need not be 1). @@ -154,14 +163,14 @@ class PolynomialQuotientRingFactory(UniqueFactory): sage: R. = PolynomialRing(IntegerRing()) sage: f = x^2 + 1 - sage: R.quotient(f) + sage: R.quotient(f) # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 This shows that the issue at :trac:`5482` is solved:: sage: R. = PolynomialRing(QQ) - sage: f = x^2-1 - sage: R.quotient_by_principal_ideal(f) + sage: f = x^2 - 1 + sage: R.quotient_by_principal_ideal(f) # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 1 """ @@ -186,19 +195,19 @@ def create_key(self, ring, polynomial, names=None): Consequently, you get two distinct objects:: - sage: S = PolynomialQuotientRing(R, x + 1); S + sage: S = PolynomialQuotientRing(R, x + 1); S # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x + 1 - sage: T = PolynomialQuotientRing(R, 2*x + 2); T + sage: T = PolynomialQuotientRing(R, 2*x + 2); T # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus 2*x + 2 - sage: S is T + sage: S is T # optional - sage.libs.pari False - sage: S == T + sage: S == T # optional - sage.libs.pari False In most applications this will not be a concern since the calling code takes care of normalizing the generators:: - sage: R.quo(x + 1) is R.quo(2*x + 2) + sage: R.quo(x + 1) is R.quo(2*x + 2) # optional - sage.libs.pari True """ @@ -227,7 +236,8 @@ def create_object(self, version, key): EXAMPLES:: sage: R. = QQ[] - sage: PolynomialQuotientRing.create_object((8, 0, 0), (R, x^2 - 1, ('xbar'))) + sage: PolynomialQuotientRing.create_object((8, 0, 0), # optional - sage.libs.pari + ....: (R, x^2 - 1, ('xbar'))) Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 1 """ @@ -265,7 +275,8 @@ class PolynomialQuotientRing_generic(QuotientRing_generic): sage: R. = PolynomialRing(Integers(8)); R Univariate Polynomial Ring in x over Ring of integers modulo 8 sage: S. = R.quotient(x^2 + 1); S - Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 8 with modulus x^2 + 1 + Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 8 + with modulus x^2 + 1 We demonstrate object persistence. @@ -281,18 +292,19 @@ class PolynomialQuotientRing_generic(QuotientRing_generic): :: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(x^2-4) - sage: f = S.hom([2]) - sage: f + sage: S = R.quo(x^2 - 4) # optional - sage.libs.pari + sage: f = S.hom([2]) # optional - sage.libs.pari + sage: f # optional - sage.libs.pari Ring morphism: - From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 - 4 + From: Univariate Quotient Polynomial Ring in xbar over Integer Ring + with modulus x^2 - 4 To: Integer Ring Defn: xbar |--> 2 - sage: f(x) + sage: f(x) # optional - sage.libs.pari 2 - sage: f(x^2 - 4) + sage: f(x^2 - 4) # optional - sage.libs.pari 0 - sage: f(x^2) + sage: f(x^2) # optional - sage.libs.pari 4 TESTS: @@ -308,8 +320,8 @@ class of the quotient ring and its newly created elements. Thus, in order to document that this works fine, we go into some detail:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.category() + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.category() # optional - sage.libs.pari Category of commutative no zero divisors quotients of algebras over (number fields and quotient fields and metric spaces) @@ -318,23 +330,24 @@ class of the quotient ring and its newly created elements. class of the category, and store the current class of the quotient ring:: - sage: isinstance(Q.an_element(),Q.element_class) + sage: isinstance(Q.an_element(), Q.element_class) # optional - sage.libs.pari True - sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] - ['cartesian_product', 'inverse', 'inverse_of_unit', 'is_idempotent', 'is_one', 'is_unit', 'lift', 'powers'] - sage: first_class = Q.__class__ + sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] # optional - sage.libs.pari + ['cartesian_product', 'inverse', 'inverse_of_unit', 'is_idempotent', + 'is_one', 'is_unit', 'lift', 'powers'] + sage: first_class = Q.__class__ # optional - sage.libs.pari We try to find out whether `Q` is a field. Indeed it is, and thus its category, including its class and element class, is changed accordingly:: - sage: Q in Fields() + sage: Q in Fields() # optional - sage.libs.pari True - sage: Q.category() + sage: Q.category() # optional - sage.libs.pari Category of commutative division no zero divisors quotients of algebras over (number fields and quotient fields and metric spaces) - sage: first_class == Q.__class__ + sage: first_class == Q.__class__ # optional - sage.libs.pari False - sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] + sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] # optional - sage.libs.pari ['cartesian_product', 'euclidean_degree', 'factor', @@ -358,22 +371,22 @@ class of the category, and store the current class of the quotient new methods from the category of fields, thanks to :meth:`Element.__getattr__`:: - sage: e = Q.an_element() - sage: isinstance(e, Q.element_class) + sage: e = Q.an_element() # optional - sage.libs.pari + sage: isinstance(e, Q.element_class) # optional - sage.libs.pari False - sage: e.gcd(e+1) + sage: e.gcd(e + 1) # optional - sage.libs.pari 1 The test suite passes. However, we have to skip the test for its elements, since `an_element` has been cached in the call above and its class does not match the new category's element class anymore:: - sage: TestSuite(Q).run(skip=['_test_elements']) + sage: TestSuite(Q).run(skip=['_test_elements']) # optional - sage.libs.pari Newly created elements are fine, though, and their test suite passes:: - sage: TestSuite(Q(x)).run() - sage: isinstance(Q(x), Q.element_class) + sage: TestSuite(Q(x)).run() # optional - sage.libs.pari + sage: isinstance(Q(x), Q.element_class) # optional - sage.libs.pari True """ Element = PolynomialQuotientRingElement @@ -383,18 +396,18 @@ def __init__(self, ring, polynomial, name=None, category=None): TESTS:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(x^2-4) + sage: S = R.quo(x^2 - 4) # optional - sage.libs.pari sage: from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic - sage: S == PolynomialQuotientRing_generic(R,x^2-4,'xbar') + sage: S == PolynomialQuotientRing_generic(R, x^2 - 4, 'xbar') # optional - sage.libs.pari True Check that :trac:`26161` has been resolved:: - sage: R. = GF(2)[] - sage: S = R.quo(x) - sage: S in FiniteFields() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S = R.quo(x) # optional - sage.rings.finite_rings + sage: S in FiniteFields() # optional - sage.rings.finite_rings True - sage: type(S).mro() + sage: type(S).mro() # optional - sage.rings.finite_rings [, ... , @@ -440,18 +453,18 @@ def _element_constructor_(self, x): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-3*x+1) - sage: S(x) + sage: S. = R.quotient(x^3 - 3*x + 1) # optional - sage.libs.pari + sage: S(x) # optional - sage.libs.pari alpha - sage: S(x^3) + sage: S(x^3) # optional - sage.libs.pari 3*alpha - 1 - sage: S([1,2]) + sage: S([1,2]) # optional - sage.libs.pari 2*alpha + 1 - sage: S([1,2,3,4,5]) + sage: S([1,2,3,4,5]) # optional - sage.libs.pari 18*alpha^2 + 9*alpha - 3 - sage: S(S.gen()+1) + sage: S(S.gen()+1) # optional - sage.libs.pari alpha + 1 - sage: S(S.gen()^10+1) + sage: S(S.gen()^10+1) # optional - sage.libs.pari 90*alpha^2 - 109*alpha + 28 TESTS: @@ -460,53 +473,54 @@ def _element_constructor_(self, x): This was fixed in :trac:`8800`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q = P.quo([(x^2+1)^2]) - sage: Q1.has_coerce_map_from(Q) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q = P.quo([(x^2+1)^2]) # optional - sage.libs.pari + sage: Q1.has_coerce_map_from(Q) # optional - sage.libs.pari False - sage: Q1(Q.gen()) + sage: Q1(Q.gen()) # optional - sage.libs.pari xbar Here we test against several issues discussed in :trac:`8992`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) - sage: p = Q1.gen() + Q2.gen() - sage: p + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) # optional - sage.libs.pari + sage: p = Q1.gen() + Q2.gen() # optional - sage.libs.pari + sage: p # optional - sage.libs.pari 2*xbar - sage: p.parent() - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^4 + 2*x^2 + 1 - sage: p.parent()('xbar') + sage: p.parent() # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^4 + 2*x^2 + 1 + sage: p.parent()('xbar') # optional - sage.libs.pari xbar Note that the result of string conversion has the correct parent, even when the given string suggests an element of the cover ring or the base ring:: - sage: a = Q1('x'); a + sage: a = Q1('x'); a # optional - sage.libs.pari xbar - sage: a.parent() is Q1 + sage: a.parent() is Q1 # optional - sage.libs.pari True - sage: b = Q1('1'); b + sage: b = Q1('1'); b # optional - sage.libs.pari 1 - sage: b.parent() is Q1 + sage: b.parent() is Q1 # optional - sage.libs.pari True Conversion may lift an element of one quotient ring to the base ring of another quotient ring:: - sage: R. = P[] - sage: Q3 = R.quo([(y^2+1)]) - sage: Q3(Q1.gen()) + sage: R. = P[] # optional - sage.libs.pari + sage: Q3 = R.quo([(y^2+1)]) # optional - sage.libs.pari + sage: Q3(Q1.gen()) # optional - sage.libs.pari x - sage: Q3.has_coerce_map_from(Q1) + sage: Q3.has_coerce_map_from(Q1) # optional - sage.libs.pari False String conversion takes into account both the generators of the quotient ring and its base ring:: - sage: Q3('x*ybar^2') + sage: Q3('x*ybar^2') # optional - sage.libs.pari -x """ @@ -548,25 +562,25 @@ def _coerce_map_from_(self, R): TESTS:: - sage: P5. = GF(5)[] - sage: Q = P5.quo([(x^2+1)^2]) + sage: P5. = GF(5)[] # optional - sage.rings.finite_rings + sage: Q = P5.quo([(x^2+1)^2]) # optional - sage.rings.finite_rings sage: P. = ZZ[] sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) - sage: Q.has_coerce_map_from(Q1) #indirect doctest + sage: Q.has_coerce_map_from(Q1) #indirect doctest # optional - sage.rings.finite_rings True - sage: Q1.has_coerce_map_from(Q) + sage: Q1.has_coerce_map_from(Q) # optional - sage.rings.finite_rings False - sage: Q1.has_coerce_map_from(Q2) + sage: Q1.has_coerce_map_from(Q2) # optional - sage.rings.finite_rings False The following tests against a bug fixed in :trac:`8992`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari sage: R. = P[] - sage: Q2 = R.quo([(y^2+1)]) - sage: Q2.has_coerce_map_from(Q1) + sage: Q2 = R.quo([(y^2 + 1)]) # optional - sage.libs.pari + sage: Q2.has_coerce_map_from(Q1) # optional - sage.libs.pari False """ @@ -587,15 +601,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: R. = K[] - sage: S. = R.quotient(x^2 - i) - sage: Q8. = CyclotomicField(8) - sage: S._is_valid_homomorphism_(Q8, [z]) # no coercion from K to Q8 + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x^2 - i) # optional - sage.rings.number_field + sage: Q8. = CyclotomicField(8) # optional - sage.rings.number_field + sage: S._is_valid_homomorphism_(Q8, [z]) # no coercion from K to Q8 # optional - sage.rings.number_field False - sage: S._is_valid_homomorphism_(Q8, [z], K.hom([z^2])) + sage: S._is_valid_homomorphism_(Q8, [z], K.hom([z^2])) # optional - sage.rings.number_field True - sage: S._is_valid_homomorphism_(Q8, [1/z], K.hom([z^-2])) + sage: S._is_valid_homomorphism_(Q8, [1/z], K.hom([z^-2])) # optional - sage.rings.number_field True """ if base_map is None and not codomain.has_coerce_map_from(self.base_ring()): @@ -645,12 +659,12 @@ def lift(self, x): EXAMPLES:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.lift(Q.0^3) + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.lift(Q.0^3) # optional - sage.libs.pari -2*x - sage: Q(-2*x) + sage: Q(-2*x) # optional - sage.libs.pari -2*xbar - sage: Q.0^3 + sage: Q.0^3 # optional - sage.libs.pari -2*xbar """ @@ -666,14 +680,14 @@ def __eq__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx == Ry False - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: Qx == Qy + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: Qx == Qy # optional - sage.libs.pari False - sage: Qx == Qx + sage: Qx == Qx # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2+1) - sage: Qz == Qx + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz == Qx # optional - sage.libs.pari True """ if not isinstance(other, PolynomialQuotientRing_generic): @@ -691,14 +705,14 @@ def __ne__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx != Ry True - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: Qx != Qy + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: Qx != Qy # optional - sage.libs.pari True - sage: Qx != Qx + sage: Qx != Qx # optional - sage.libs.pari False - sage: Qz = Rx.quotient(x^2+1) - sage: Qz != Qx + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz != Qx # optional - sage.libs.pari False """ return not (self == other) @@ -713,14 +727,14 @@ def __hash__(self): sage: Ry. = PolynomialRing(QQ) sage: hash(Rx) == hash(Ry) False - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: hash(Qx) == hash(Qy) + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: hash(Qx) == hash(Qy) # optional - sage.libs.pari False - sage: hash(Qx) == hash(Qx) + sage: hash(Qx) == hash(Qx) # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2+1) - sage: hash(Qz) == hash(Qx) + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: hash(Qz) == hash(Qx) # optional - sage.libs.pari True """ return hash((self.polynomial_ring(), self.modulus())) @@ -732,8 +746,8 @@ def _singular_init_(self, S=None): TESTS:: sage: P. = QQ[] - sage: Q = P.quo([(x^2+1)]) - sage: singular(Q) # indirect doctest + sage: Q = P.quo([(x^2 + 1)]) # optional - sage.libs.pari + sage: singular(Q) # indirect doctest # optional - sage.libs.pari polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 @@ -742,7 +756,7 @@ def _singular_init_(self, S=None): // block 2 : ordering C // quotient ring from ideal _[1]=xbar^2+1 - sage: singular(Q.gen()) + sage: singular(Q.gen()) # optional - sage.libs.pari xbar """ @@ -766,15 +780,15 @@ def construction(self): EXAMPLES:: - sage: P.=ZZ[] - sage: Q = P.quo(5+t^2) + sage: P. = ZZ[] + sage: Q = P.quo(5 + t^2) sage: F, R = Q.construction() sage: F(R) == Q True - sage: P. = GF(3)[] - sage: Q = P.quo([2+t^2]) - sage: F, R = Q.construction() - sage: F(R) == Q + sage: P. = GF(3)[] # optional - sage.rings.finite_rings + sage: Q = P.quo([2 + t^2]) # optional - sage.rings.finite_rings + sage: F, R = Q.construction() # optional - sage.rings.finite_rings + sage: F(R) == Q # optional - sage.rings.finite_rings True AUTHOR: @@ -803,8 +817,8 @@ def base_ring(self): :: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quo(z^3 + z^2 + z + 1) - sage: S.base_ring() + sage: S. = R.quo(z^3 + z^2 + z + 1) # optional - sage.libs.pari + sage: S.base_ring() # optional - sage.libs.pari Integer Ring Next we make a polynomial quotient ring over `S` and ask @@ -812,10 +826,11 @@ def base_ring(self): :: - sage: T. = PolynomialRing(S) - sage: W = T.quotient(t^99 + 99) - sage: W.base_ring() - Univariate Quotient Polynomial Ring in beta over Integer Ring with modulus z^3 + z^2 + z + 1 + sage: T. = PolynomialRing(S) # optional - sage.libs.pari + sage: W = T.quotient(t^99 + 99) # optional - sage.libs.pari + sage: W.base_ring() # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in beta + over Integer Ring with modulus z^3 + z^2 + z + 1 """ return self.__ring.base_ring() @@ -830,22 +845,22 @@ def cardinality(self): sage: R. = ZZ[] sage: R.quo(1).cardinality() 1 - sage: R.quo(x^3-2).cardinality() + sage: R.quo(x^3 - 2).cardinality() # optional - sage.libs.pari +Infinity sage: R.quo(1).order() 1 - sage: R.quo(x^3-2).order() + sage: R.quo(x^3 - 2).order() # optional - sage.libs.pari +Infinity :: - sage: R. = GF(9,'a')[] - sage: R.quo(2*x^3+x+1).cardinality() + sage: R. = GF(9, 'a')[] # optional - sage.rings.finite_rings + sage: R.quo(2*x^3 + x + 1).cardinality() # optional - sage.rings.finite_rings 729 - sage: GF(9,'a').extension(2*x^3+x+1).cardinality() + sage: GF(9, 'a').extension(2*x^3 + x + 1).cardinality() # optional - sage.rings.finite_rings 729 - sage: R.quo(2).cardinality() + sage: R.quo(2).cardinality() # optional - sage.rings.finite_rings 1 TESTS:: @@ -879,21 +894,21 @@ def is_finite(self): sage: R. = ZZ[] sage: R.quo(1).is_finite() True - sage: R.quo(x^3-2).is_finite() + sage: R.quo(x^3 - 2).is_finite() # optional - sage.libs.pari False :: - sage: R. = GF(9,'a')[] - sage: R.quo(2*x^3+x+1).is_finite() + sage: R. = GF(9, 'a')[] # optional - sage.rings.finite_rings + sage: R.quo(2*x^3 + x + 1).is_finite() # optional - sage.rings.finite_rings True - sage: R.quo(2).is_finite() + sage: R.quo(2).is_finite() # optional - sage.rings.finite_rings True :: - sage: P. = GF(2)[] - sage: P.quotient(v^2-v).is_finite() + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: P.quotient(v^2 - v).is_finite() # optional - sage.rings.finite_rings True """ f = self.modulus() @@ -909,9 +924,9 @@ def __iter__(self): r""" EXAMPLES:: - sage: R. = GF(3)[] - sage: Q = R.quo(x^3 - x^2 - x - 1) - sage: list(Q) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: Q = R.quo(x^3 - x^2 - x - 1) # optional - sage.rings.finite_rings + sage: list(Q) # optional - sage.rings.finite_rings [0, 1, 2, @@ -922,7 +937,7 @@ def __iter__(self): ... 2*xbar^2 + 2*xbar + 1, 2*xbar^2 + 2*xbar + 2] - sage: len(_) == Q.cardinality() == 27 + sage: len(_) == Q.cardinality() == 27 # optional - sage.rings.finite_rings True """ if not self.is_finite(): @@ -943,12 +958,12 @@ def characteristic(self): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quo(z - 19) - sage: S.characteristic() + sage: S. = R.quo(z - 19) # optional - sage.libs.pari + sage: S.characteristic() # optional - sage.libs.pari 0 - sage: R. = PolynomialRing(GF(9,'a')) - sage: S = R.quotient(x^3 + 1) - sage: S.characteristic() + sage: R. = PolynomialRing(GF(9, 'a')) # optional - sage.rings.finite_rings + sage: S = R.quotient(x^3 + 1) # optional - sage.rings.finite_rings + sage: S.characteristic() # optional - sage.rings.finite_rings 3 """ return self.base_ring().characteristic() @@ -960,9 +975,9 @@ def degree(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(3)) - sage: S = R.quotient(x^2005 + 1) - sage: S.degree() + sage: R. = PolynomialRing(GF(3)) # optional - sage.rings.finite_rings + sage: S = R.quotient(x^2005 + 1) # optional - sage.rings.finite_rings + sage: S.degree() # optional - sage.rings.finite_rings 2005 """ return self.modulus().degree() @@ -976,11 +991,11 @@ def discriminant(self, v=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^3 + x^2 + x + 1) - sage: S.discriminant() + sage: S = R.quotient(x^3 + x^2 + x + 1) # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari -16 - sage: S = R.quotient((x + 1) * (x + 1)) - sage: S.discriminant() + sage: S = R.quotient((x + 1) * (x + 1)) # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari 0 The discriminant of the quotient polynomial ring need not equal the @@ -988,10 +1003,10 @@ def discriminant(self, v=None): discriminant of a number field is by definition the discriminant of the ring of integers of the number field:: - sage: S = R.quotient(x^2 - 8) - sage: S.number_field().discriminant() + sage: S = R.quotient(x^2 - 8) # optional - sage.libs.pari + sage: S.number_field().discriminant() # optional - sage.libs.pari 8 - sage: S.discriminant() + sage: S.discriminant() # optional - sage.libs.pari 32 """ return self.modulus().discriminant() @@ -1004,8 +1019,8 @@ class of the image of the generator of the polynomial ring. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 8, 'gamma') - sage: S.gen() + sage: S = R.quotient(x^2 - 8, 'gamma') # optional - sage.libs.pari + sage: S.gen() # optional - sage.libs.pari gamma """ if n != 0: @@ -1023,26 +1038,28 @@ def is_field(self, proof = True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(z^2-2) - sage: S.is_field() + sage: S = R.quo(z^2 - 2) # optional - sage.libs.pari + sage: S.is_field() # optional - sage.libs.pari False sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 2) - sage: S.is_field() + sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari + sage: S.is_field() # optional - sage.libs.pari True If proof is ``True``, requires the ``is_irreducible`` method of the modulus to be implemented:: - sage: R1. = Qp(2)[] - sage: F1 = R1.quotient_ring(x^2+x+1) - sage: R2. = F1[] - sage: F2 = R2.quotient_ring(x^2+x+1) - sage: F2.is_field() + sage: R1. = Qp(2)[] # optional - sage.rings.padics + sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.rings.padics + sage: R2. = F1[] # optional - sage.rings.padics + sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.rings.padics + sage: F2.is_field() # optional - sage.rings.padics Traceback (most recent call last): ... - NotImplementedError: cannot rewrite Univariate Quotient Polynomial Ring in xbar over 2-adic Field with capped relative precision 20 with modulus (1 + O(2^20))*x^2 + (1 + O(2^20))*x + 1 + O(2^20) as an isomorphic ring - sage: F2.is_field(proof = False) + NotImplementedError: cannot rewrite Univariate Quotient Polynomial Ring in + xbar over 2-adic Field with capped relative precision 20 with modulus + (1 + O(2^20))*x^2 + (1 + O(2^20))*x + 1 + O(2^20) as an isomorphic ring + sage: F2.is_field(proof = False) # optional - sage.rings.padics False """ @@ -1067,25 +1084,25 @@ def is_integral_domain(self, proof = True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quotient(z^2 - z) - sage: S.is_integral_domain() + sage: S = R.quotient(z^2 - z) # optional - sage.libs.pari + sage: S.is_integral_domain() # optional - sage.libs.pari False - sage: T = R.quotient(z^2 + 1) - sage: T.is_integral_domain() + sage: T = R.quotient(z^2 + 1) # optional - sage.libs.pari + sage: T.is_integral_domain() # optional - sage.libs.pari True sage: U = R.quotient(-1) sage: U.is_integral_domain() False sage: R2. = PolynomialRing(R) - sage: S2 = R2.quotient(z^2 - y^3) - sage: S2.is_integral_domain() + sage: S2 = R2.quotient(z^2 - y^3) # optional - sage.libs.pari + sage: S2.is_integral_domain() # optional - sage.libs.pari True - sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) - sage: S3.is_integral_domain() + sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) # optional - sage.libs.pari + sage: S3.is_integral_domain() # optional - sage.libs.pari False sage: R. = PolynomialRing(ZZ.quotient(4)) - sage: S = R.quotient(z-1) + sage: S = R.quotient(z - 1) sage: S.is_integral_domain() False @@ -1095,6 +1112,7 @@ def is_integral_domain(self, proof = True): domain, even though the base ring is integral and the modulus is irreducible:: + sage: x = polygen(ZZ, 'x') sage: B = ZZ.extension(x^2 - 5, 'a') sage: R. = PolynomialRing(B) sage: S = R.quotient(y^2 - y - 1) @@ -1102,7 +1120,7 @@ def is_integral_domain(self, proof = True): Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof = False) + sage: S.is_integral_domain(proof = False) # optional - sage.libs.pari sage.rings.number_field False The reason that the modulus y^2 - y -1 is not prime is that it @@ -1150,10 +1168,11 @@ def krull_dimension(self): EXAMPLES:: - sage: R = PolynomialRing(ZZ,'x').quotient(x**6-1) + sage: x = polygen(ZZ, 'x') + sage: R = PolynomialRing(ZZ, 'x').quotient(x**6 - 1) sage: R.krull_dimension() 1 - sage: R = PolynomialRing(ZZ,'x').quotient(1) + sage: R = PolynomialRing(ZZ, 'x').quotient(1) sage: R.krull_dimension() -1 """ @@ -1167,9 +1186,9 @@ def modulus(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(3)) - sage: S = R.quotient(x^2 - 2) - sage: S.modulus() + sage: R. = PolynomialRing(GF(3)) # optional - sage.rings.finite_rings + sage: S = R.quotient(x^2 - 2) # optional - sage.rings.finite_rings + sage: S.modulus() # optional - sage.rings.finite_rings x^2 + 1 """ return self.__polynomial @@ -1200,11 +1219,11 @@ def number_field(self): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^29 - 17*x - 1) - sage: K = S.number_field() - sage: K + sage: K = S.number_field() # optional - sage.rings.number_field + sage: K # optional - sage.rings.number_field Number Field in alpha with defining polynomial x^29 - 17*x - 1 - sage: alpha = K.gen() - sage: alpha^29 + sage: alpha = K.gen() # optional - sage.rings.number_field + sage: alpha^29 # optional - sage.rings.number_field 17*alpha + 1 """ if self.characteristic() != 0: @@ -1222,8 +1241,8 @@ def polynomial_ring(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2-2) - sage: S.polynomial_ring() + sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari + sage: S.polynomial_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Rational Field """ return self.__ring @@ -1246,10 +1265,10 @@ def random_element(self, *args, **kwds): EXAMPLES:: - sage: F1. = GF(2^7) - sage: P1. = F1[] - sage: F2 = F1.extension(x^2+x+1, 'u') - sage: F2.random_element().parent() is F2 + sage: F1. = GF(2^7) # optional - sage.rings.finite_rings + sage: P1. = F1[] # optional - sage.rings.finite_rings + sage: F2 = F1.extension(x^2 + x + 1, 'u') # optional - sage.rings.finite_rings + sage: F2.random_element().parent() is F2 # optional - sage.rings.finite_rings True """ return self(self.polynomial_ring().random_element( @@ -1265,22 +1284,22 @@ def _S_decomposition(self, S): EXAMPLES:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: fields, isos, iso_classes = S._S_decomposition(tuple(K.primes_above(3))) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: fields, isos, iso_classes = S._S_decomposition(tuple(K.primes_above(3))) # optional - sage.rings.number_field Representatives of the number fields up to isomorphism that occur in the decomposition:: - sage: fields + sage: fields # optional - sage.rings.number_field [Number Field in x0 with defining polynomial x^2 + 23 over its base field, Number Field in x1 with defining polynomial x^2 + 31 over its base field] In this case, the isomorphisms of these representatives to the components are the identity maps:: - sage: isos + sage: isos # optional - sage.rings.number_field [(Ring endomorphism of Number Field in y0 with defining polynomial x^4 + 56*x^2 + 324 Defn: y0 |--> y0, 0), @@ -1291,9 +1310,9 @@ def _S_decomposition(self, S): There are four primes above 3 in the first component and two in the second component:: - sage: len(iso_classes[0][1]) + sage: len(iso_classes[0][1]) # optional - sage.rings.number_field 4 - sage: len(iso_classes[1][1]) + sage: len(iso_classes[1][1]) # optional - sage.rings.number_field 2 """ from sage.rings.number_field.number_field_base import NumberField @@ -1372,42 +1391,43 @@ def S_class_group(self, S, proof=True): A trivial algebra over `\QQ(\sqrt{-5})` has the same class group as its base:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient(x) - sage: S.S_class_group([]) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x) # optional - sage.rings.number_field + sage: S.S_class_group([]) # optional - sage.rings.number_field [((2, -a + 1), 2)] When we include the prime `(2, -a+1)`, the `S`-class group becomes trivial:: - sage: S.S_class_group([K.ideal(2, -a+1)]) + sage: S.S_class_group([K.ideal(2, -a+1)]) # optional - sage.rings.number_field [] Here is an example where the base and the extension both contribute to the class group:: - sage: K. = QuadraticField(-5) - sage: K.class_group() - Class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I - sage: R. = K[] - sage: S. = R.quotient(x^2 + 23) - sage: S.S_class_group([]) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 2 with structure C2 of Number Field in a + with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x^2 + 23) # optional - sage.rings.number_field + sage: S.S_class_group([]) # optional - sage.rings.number_field [((2, -a + 1, 1/2*xbar + 1/2, -1/2*a*xbar + 1/2*a + 1), 6)] - sage: S.S_class_group([K.ideal(3, a-1)]) + sage: S.S_class_group([K.ideal(3, a-1)]) # optional - sage.rings.number_field [] - sage: S.S_class_group([K.ideal(2, a+1)]) + sage: S.S_class_group([K.ideal(2, a+1)]) # optional - sage.rings.number_field [] - sage: S.S_class_group([K.ideal(a)]) + sage: S.S_class_group([K.ideal(a)]) # optional - sage.rings.number_field [((2, -a + 1, 1/2*xbar + 1/2, -1/2*a*xbar + 1/2*a + 1), 6)] Now we take an example over a nontrivial base with two factors, each contributing to the class group:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: S.S_class_group([]) # representation varies, not tested + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: S.S_class_group([]) # representation varies, not tested # optional - sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, @@ -1428,26 +1448,33 @@ def S_class_group(self, S, proof=True): `x^2 + 31` from 12 to 2, i.e. we lose a generator of order 6 (this was fixed in :trac:`14489`):: - sage: S.S_class_group([K.ideal(a)]) # representation varies, not tested - [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 2)] + sage: S.S_class_group([K.ideal(a)]) # representation varies, not tested # optional - sage.rings.number_field + [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, + 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, + -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), + 6), + ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, + -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, + 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), + 2)] Note that all the returned values live where we expect them to:: - sage: CG = S.S_class_group([]) - sage: type(CG[0][0][1]) + sage: CG = S.S_class_group([]) # optional - sage.rings.number_field + sage: type(CG[0][0][1]) # optional - sage.rings.number_field - sage: type(CG[0][1]) + sage: type(CG[0][1]) # optional - sage.rings.number_field TESTS: We verify the above test, where the representation depends on the PARI version:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: C = S.S_class_group([]) - sage: C[:2] + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: C = S.S_class_group([]) # optional - sage.rings.number_field + sage: C[:2] # optional - sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, @@ -1458,21 +1485,21 @@ def S_class_group(self, S, proof=True): -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 6)] - sage: C[2][1] + sage: C[2][1] # optional - sage.rings.number_field 2 - sage: gens = C[2][0] - sage: expected_gens = ( + sage: gens = C[2][0] # optional - sage.rings.number_field + sage: expected_gens = ( # optional - sage.rings.number_field ....: -5/4*xbar^2 - 115/4, ....: 1/4*a*xbar^2 + 23/4*a, ....: -1/16*xbar^3 - 7/16*xbar^2 - 23/16*xbar - 161/16, ....: 1/16*a*xbar^3 - 1/16*a*xbar^2 + 23/16*a*xbar - 23/16*a) - sage: gens[0] == expected_gens[0] + sage: gens[0] == expected_gens[0] # optional - sage.rings.number_field True - sage: gens[1] in (expected_gens[1], expected_gens[1]/2 + expected_gens[0]/2) + sage: gens[1] in (expected_gens[1], expected_gens[1]/2 + expected_gens[0]/2) # optional - sage.rings.number_field True - sage: gens[2] in (expected_gens[2], expected_gens[2] + expected_gens[0]/2) + sage: gens[2] in (expected_gens[2], expected_gens[2] + expected_gens[0]/2) # optional - sage.rings.number_field True - sage: gens[3] in (expected_gens[3], expected_gens[3] + expected_gens[0]/2) + sage: gens[3] in (expected_gens[3], expected_gens[3] + expected_gens[0]/2) # optional - sage.rings.number_field True """ fields, isos, iso_classes = self._S_decomposition(tuple(S)) @@ -1527,54 +1554,62 @@ def class_group(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.class_group() - Class group of order 1 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: K.class_group() + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 1 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field [] A trivial algebra over `\QQ(\sqrt{-5})` has the same class group as its base:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient(x) - sage: S.class_group() + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x) # optional - sage.rings.number_field + sage: S.class_group() # optional - sage.rings.number_field [((2, -a + 1), 2)] The same algebra constructed in a different way:: + sage: x = polygen(ZZ, 'x') sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.class_group(()) + sage: K.class_group(()) # optional - sage.rings.number_field [((2, a + 1), 2)] Here is an example where the base and the extension both contribute to the class group:: - sage: K. = QuadraticField(-5) - sage: K.class_group() - Class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I - sage: R. = K[] - sage: S. = R.quotient(x^2 + 23) - sage: S.class_group() + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 2 with structure C2 of Number Field in a + with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x^2 + 23) # optional - sage.rings.number_field + sage: S.class_group() # optional - sage.rings.number_field [((2, -a + 1, 1/2*xbar + 1/2, -1/2*a*xbar + 1/2*a + 1), 6)] Here is an example of a product of number fields, both of which contribute to the class group:: - sage: R. = QQ[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 47)) - sage: S.class_group() - [((1/12*xbar^2 + 47/12, 1/48*xbar^3 - 1/48*xbar^2 + 47/48*xbar - 47/48), 3), ((-1/12*xbar^2 - 23/12, -1/48*xbar^3 - 1/48*xbar^2 - 23/48*xbar - 23/48), 5)] + sage: R. = QQ[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 47)) # optional - sage.rings.number_field + sage: S.class_group() # optional - sage.rings.number_field + [((1/12*xbar^2 + 47/12, + 1/48*xbar^3 - 1/48*xbar^2 + 47/48*xbar - 47/48), + 3), + ((-1/12*xbar^2 - 23/12, + -1/48*xbar^3 - 1/48*xbar^2 - 23/48*xbar - 23/48), + 5)] Now we take an example over a nontrivial base with two factors, each contributing to the class group:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: S.class_group() # representation varies, not tested + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: S.class_group() # representation varies, not tested # optional - sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, @@ -1593,10 +1628,10 @@ def class_group(self, proof=True): Note that all the returned values live where we expect them to:: - sage: CG = S.class_group() - sage: type(CG[0][0][1]) + sage: CG = S.class_group() # optional - sage.rings.number_field + sage: type(CG[0][0][1]) # optional - sage.rings.number_field - sage: type(CG[0][1]) + sage: type(CG[0][1]) # optional - sage.rings.number_field """ @@ -1622,35 +1657,40 @@ def S_units(self, S, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: x = polygen(ZZ, 'x') sage: K. = QQ['x'].quotient(x^2 + 3) - sage: u,o = K.S_units([])[0]; o + sage: u, o = K.S_units([])[0]; o 6 - sage: 2*u - 1 in {a, -a} + sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari True - sage: u^6 + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True :: - sage: K. = QuadraticField(-3) - sage: y = polygen(K) - sage: L. = K['y'].quotient(y^3 + 5); L - Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I with modulus y^3 + 5 - sage: [u for u, o in L.S_units([]) if o is Infinity] + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: L. = K['y'].quotient(y^3 + 5); L # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in b over Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + with modulus y^3 + 5 + sage: [u for u, o in L.S_units([]) if o is Infinity] # optional - sage.rings.number_field [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] - sage: [u for u, o in L.S_units([K.ideal(1/2*a - 3/2)]) if o is Infinity] + sage: [u for u, o in L.S_units([K.ideal(1/2*a - 3/2)]) # optional - sage.rings.number_field + ....: if o is Infinity] [(-1/6*a - 1/2)*b^2 + (1/3*a - 1)*b + 4/3*a, (-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] - sage: [u for u, o in L.S_units([K.ideal(2)]) if o is Infinity] + sage: [u for u, o in L.S_units([K.ideal(2)]) if o is Infinity] # optional - sage.rings.number_field [(1/2*a - 1/2)*b^2 + (a + 1)*b + 3, (1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a + 1/2, (1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a - 1/2, @@ -1659,12 +1699,12 @@ def S_units(self, S, proof=True): Note that all the returned values live where we expect them to:: - sage: U = L.S_units([]) - sage: type(U[0][0]) + sage: U = L.S_units([]) # optional - sage.rings.number_field + sage: type(U[0][0]) # optional - sage.rings.number_field - sage: type(U[0][1]) + sage: type(U[0][1]) # optional - sage.rings.number_field - sage: type(U[1][1]) + sage: type(U[1][1]) # optional - sage.rings.number_field """ @@ -1708,49 +1748,55 @@ def units(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 of + Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I sage: K. = QQ['x'].quotient(x^2 + 3) sage: u = K.units()[0][0] sage: 2*u - 1 in {a, -a} True - sage: u^6 + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True - sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.units(()) + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari + sage: K.units(()) # optional - sage.libs.pari [(-1, 2)] :: - sage: K. = QuadraticField(-3) - sage: y = polygen(K) - sage: L. = K['y'].quotient(y^3 + 5); L - Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I with modulus y^3 + 5 - sage: [u for u, o in L.units() if o is Infinity] + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: L. = K['y'].quotient(y^3 + 5); L # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in b over Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + with modulus y^3 + 5 + sage: [u for u, o in L.units() if o is Infinity] # optional - sage.rings.number_field [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] - sage: L. = K.extension(y^3 + 5) - sage: L.unit_group() - Unit group with structure C6 x Z x Z of Number Field in b with defining polynomial x^3 + 5 over its base field - sage: L.unit_group().gens() # abstract generators + sage: L. = K.extension(y^3 + 5) # optional - sage.rings.number_field + sage: L.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 x Z x Z of + Number Field in b with defining polynomial x^3 + 5 over its base field + sage: L.unit_group().gens() # abstract generators # optional - sage.rings.number_field (u0, u1, u2) - sage: L.unit_group().gens_values()[1:] - [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] + sage: L.unit_group().gens_values()[1:] # optional - sage.rings.number_field + [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, + 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] Note that all the returned values live where we expect them to:: - sage: L. = K['y'].quotient(y^3 + 5) - sage: U = L.units() - sage: type(U[0][0]) + sage: L. = K['y'].quotient(y^3 + 5) # optional - sage.libs.pari + sage: U = L.units() # optional - sage.libs.pari + sage: type(U[0][0]) # optional - sage.libs.pari - sage: type(U[0][1]) + sage: type(U[0][1]) # optional - sage.libs.pari - sage: type(U[1][1]) + sage: type(U[1][1]) # optional - sage.libs.pari """ @@ -1779,22 +1825,24 @@ def selmer_generators(self, S, m, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: D. = R.quotient(x) - sage: D.selmer_generators((), 2) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: D. = R.quotient(x) # optional - sage.rings.number_field + sage: D.selmer_generators((), 2) # optional - sage.rings.number_field [-1, 2] - sage: D.selmer_generators([K.ideal(2, -a+1)], 2) + sage: D.selmer_generators([K.ideal(2, -a + 1)], 2) # optional - sage.rings.number_field [2, -1] - sage: D.selmer_generators([K.ideal(2, -a+1), K.ideal(3, a+1)], 2) + sage: D.selmer_generators([K.ideal(2, -a + 1), K.ideal(3, a + 1)], 2) # optional - sage.rings.number_field [2, a + 1, -1] - sage: D.selmer_generators((K.ideal(2, -a+1),K.ideal(3, a+1)), 4) + sage: D.selmer_generators((K.ideal(2, -a + 1), K.ideal(3, a + 1)), 4) # optional - sage.rings.number_field [2, a + 1, -1] - sage: D.selmer_generators([K.ideal(2, -a+1)], 3) + sage: D.selmer_generators([K.ideal(2, -a + 1)], 3) # optional - sage.rings.number_field [2] - sage: D.selmer_generators([K.ideal(2, -a+1), K.ideal(3, a+1)], 3) + sage: D.selmer_generators([K.ideal(2, -a + 1), K.ideal(3, a + 1)], 3) # optional - sage.rings.number_field [2, a + 1] - sage: D.selmer_generators([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3) + sage: D.selmer_generators([K.ideal(2, -a + 1), # optional - sage.rings.number_field + ....: K.ideal(3, a + 1), + ....: K.ideal(a)], 3) [2, a + 1, -a] """ @@ -1829,13 +1877,13 @@ def _factor_multivariate_polynomial(self, f, proof=True): TESTS:: - sage: k. = GF(4) - sage: R. = k[] - sage: l. = k.extension(b^2 + b + a) - sage: K. = FunctionField(l) - sage: R. = K[] - sage: F = t*x - sage: F.factor(proof=False) + sage: k. = GF(4) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: l. = k.extension(b^2 + b + a) # optional - sage.rings.finite_rings + sage: K. = FunctionField(l) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: F = t * x # optional - sage.rings.finite_rings + sage: F.factor(proof=False) # optional - sage.rings.finite_rings (x) * t """ @@ -1856,17 +1904,17 @@ def _factor_univariate_polynomial(self, f): TESTS:: - sage: K = GF(2) - sage: R. = K[] - sage: L. = K.extension(x^2 + x + 1) - sage: R. = L[] - sage: M. = L.extension(y^2 + y + x) - sage: R. = M[] - sage: R(y).factor() # indirect doctest + sage: K = GF(2) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: L. = K.extension(x^2 + x + 1) # optional - sage.rings.finite_rings + sage: R. = L[] # optional - sage.rings.finite_rings + sage: M. = L.extension(y^2 + y + x) # optional - sage.rings.finite_rings + sage: R. = M[] # optional - sage.rings.finite_rings + sage: R(y).factor() # indirect doctest # optional - sage.rings.finite_rings y - sage: (T^2 + T + x).factor() # indirect doctest + sage: (T^2 + T + x).factor() # indirect doctest # optional - sage.rings.finite_rings (T + y) * (T + y + 1) - sage: (y*T^2 + y*T + y*x).factor() # indirect doctest + sage: (y*T^2 + y*T + y*x).factor() # indirect doctest # optional - sage.rings.finite_rings (y) * (T + y) * (T + y + 1) """ @@ -1907,32 +1955,36 @@ def _isomorphic_ring(self): EXAMPLES:: - sage: K. = GF(4) - sage: R. = K[] - sage: L. = K.extension(b^2+b+a); L - Univariate Quotient Polynomial Ring in b over Finite Field in a of size 2^2 with modulus b^2 + b + a - sage: from_M, to_M, M = L._isomorphic_ring(); M + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: L. = K.extension(b^2 + b + a); L # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in b + over Finite Field in a of size 2^2 with modulus b^2 + b + a + sage: from_M, to_M, M = L._isomorphic_ring(); M # optional - sage.rings.finite_rings Finite Field in z4 of size 2^4 - sage: R. = L[] - sage: M. = L.extension(c^2+b*c+b); M - Univariate Quotient Polynomial Ring in c over Univariate Quotient Polynomial Ring in b over Finite Field in a of size 2^2 with modulus b^2 + b + a with modulus c^2 + b*c + b - sage: from_N, to_N, N = M._isomorphic_ring(); N + sage: R. = L[] # optional - sage.rings.finite_rings + sage: M. = L.extension(c^2 + b*c + b); M # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in c + over Univariate Quotient Polynomial Ring in b + over Finite Field in a of size 2^2 with modulus b^2 + b + a + with modulus c^2 + b*c + b + sage: from_N, to_N, N = M._isomorphic_ring(); N # optional - sage.rings.finite_rings Finite Field in z8 of size 2^8 sage: R. = QQ[] - sage: K = R.quo(x^2 + 1) - sage: from_L, to_L, L = K._isomorphic_ring() - sage: L + sage: K = R.quo(x^2 + 1) # optional - sage.libs.pari + sage: from_L, to_L, L = K._isomorphic_ring() # optional - sage.libs.pari sage.rings.number_field + sage: L # optional - sage.libs.pari sage.rings.number_field Number Field in xbar with defining polynomial x^2 + 1 TESTS: Verify that this works for trivial extensions:: - sage: K. = GF(4) - sage: R. = K[] - sage: from_L, to_L, L = R.quo(b)._isomorphic_ring(); L + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: from_L, to_L, L = R.quo(b)._isomorphic_ring(); L # optional - sage.rings.finite_rings Finite Field in a of size 2^2 """ @@ -2049,13 +2101,13 @@ def _test_isomorphic_ring(self, **options): TESTS:: - sage: K. = GF(4) - sage: R. = K[] - sage: L. = K.extension(b^2+b+a) - sage: L._test_isomorphic_ring() - sage: R. = L[] - sage: M. = L.extension(c^2+b*c+b) - sage: M._test_isomorphic_ring() + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: L. = K.extension(b^2 + b + a) # optional - sage.rings.finite_rings + sage: L._test_isomorphic_ring() # optional - sage.rings.finite_rings + sage: R. = L[] # optional - sage.rings.finite_rings + sage: M. = L.extension(c^2 + b*c + b) # optional - sage.rings.finite_rings + sage: M._test_isomorphic_ring() # optional - sage.rings.finite_rings """ tester = self._tester(**options) @@ -2093,25 +2145,27 @@ class PolynomialQuotientRing_coercion(DefaultConvertMap_unique): sage: R. = ZZ[] sage: S. = QQ[] - sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)); f + sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)); f # optional - sage.libs.pari Coercion map: - From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 - To: Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 + From: Univariate Quotient Polynomial Ring in xbar over Integer Ring + with modulus x^2 + 1 + To: Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 + 1 TESTS:: sage: from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_coercion - sage: isinstance(f, PolynomialQuotientRing_coercion) + sage: isinstance(f, PolynomialQuotientRing_coercion) # optional - sage.libs.pari True - sage: TestSuite(f).run(skip=['_test_pickling']) + sage: TestSuite(f).run(skip=['_test_pickling']) # optional - sage.libs.pari Pickling works:: - sage: g = loads(dumps(f)); g + sage: g = loads(dumps(f)); g # optional - sage.libs.pari Coercion map: From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 To: Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 - sage: f == g + sage: f == g # optional - sage.libs.pari True """ @@ -2127,8 +2181,8 @@ def is_injective(self): sage: R. = ZZ[] sage: S. = QQ[] - sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)) - sage: f.is_injective() + sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)) # optional - sage.libs.pari + sage: f.is_injective() # optional - sage.libs.pari True """ @@ -2151,18 +2205,18 @@ def is_surjective(self): domain:: sage: R. = ZZ[] - sage: f = R.quo(x).coerce_map_from(R.quo(x^2)) - sage: f.is_surjective() + sage: f = R.quo(x).coerce_map_from(R.quo(x^2)) # optional - sage.libs.pari + sage: f.is_surjective() # optional - sage.libs.pari True If the modulus of the domain and the codomain is the same, then the map is surjective iff the underlying map on the constants is:: - sage: A. = ZqCA(9) - sage: R. = A[] - sage: S. = A.fraction_field()[] - sage: f = S.quo(x^2 + 2).coerce_map_from(R.quo(x^2 + 2)) - sage: f.is_surjective() + sage: A. = ZqCA(9) # optional - sage.rings.padics + sage: R. = A[] # optional - sage.rings.padics + sage: S. = A.fraction_field()[] # optional - sage.rings.padics + sage: f = S.quo(x^2 + 2).coerce_map_from(R.quo(x^2 + 2)) # optional - sage.rings.padics + sage: f.is_surjective() # optional - sage.rings.padics False """ @@ -2181,11 +2235,11 @@ def _richcmp_(self, other, op): sage: R. = ZZ[] sage: S. = ZZ[] - sage: f = S.quo(x).coerce_map_from(R.quo(x^2)) - sage: g = S.quo(x).coerce_map_from(R.quo(x^3)) - sage: f == g + sage: f = S.quo(x).coerce_map_from(R.quo(x^2)) # optional - sage.libs.pari + sage: g = S.quo(x).coerce_map_from(R.quo(x^3)) # optional - sage.libs.pari + sage: f == g # optional - sage.libs.pari False - sage: f == f + sage: f == f # optional - sage.libs.pari True """ @@ -2193,17 +2247,19 @@ def _richcmp_(self, other, op): return NotImplemented return richcmp(self.parent(), other.parent(), op) + class PolynomialQuotientRing_domain(PolynomialQuotientRing_generic, IntegralDomain): """ EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quotient(x^2 + 1) - sage: S - Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 - sage: loads(S.dumps()) == S + sage: S. = R.quotient(x^2 + 1) # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar + over Integer Ring with modulus x^2 + 1 + sage: loads(S.dumps()) == S # optional - sage.libs.pari True - sage: loads(xbar.dumps()) == xbar + sage: loads(xbar.dumps()) == xbar # optional - sage.libs.pari True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2213,21 +2269,21 @@ def __init__(self, ring, polynomial, name=None, category=None): TESTS:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quotient(x^2 + 1) - sage: TestSuite(S).run() + sage: S. = R.quotient(x^2 + 1) # optional - sage.libs.pari + sage: TestSuite(S).run() # optional - sage.libs.pari Check that :trac:`17450` is fixed:: - sage: S in IntegralDomains() + sage: S in IntegralDomains() # optional - sage.libs.pari True Check that :trac:`29017` is fixed:: sage: R. = ZZ[] - sage: Q = R.quo(x-1) - sage: H = R.Hom(Q) - sage: h = R.hom(Q) - sage: h.parent() is H + sage: Q = R.quo(x - 1) # optional - sage.libs.pari + sage: H = R.Hom(Q) # optional - sage.libs.pari + sage: h = R.hom(Q) # optional - sage.libs.pari + sage: h.parent() is H # optional - sage.libs.pari True """ category = CommutativeAlgebras(ring.base_ring().category()).Quotients().NoZeroDivisors().or_subcategory(category) @@ -2252,21 +2308,21 @@ def field_extension(self, names): EXAMPLES:: sage: R. = PolynomialRing(Rationals()) - sage: S. = R.quotient(x^3-2) - sage: F., f, g = S.field_extension() - sage: F + sage: S. = R.quotient(x^3 - 2) # optional - sage.libs.pari + sage: F., f, g = S.field_extension() # optional - sage.libs.pari sage.rings.number_field + sage: F # optional - sage.libs.pari sage.rings.number_field Number Field in b with defining polynomial x^3 - 2 - sage: a = F.gen() - sage: f(alpha) + sage: a = F.gen() # optional - sage.libs.pari sage.rings.number_field + sage: f(alpha) # optional - sage.libs.pari sage.rings.number_field b - sage: g(a) + sage: g(a) # optional - sage.libs.pari sage.rings.number_field alpha Note that the parent ring must be an integral domain:: - sage: R. = GF(25,'f25')['x'] - sage: S. = R.quo(x^3 - 2) - sage: F, g, h = S.field_extension('b') + sage: R. = GF(25, 'f25')['x'] # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 - 2) # optional - sage.rings.finite_rings + sage: F, g, h = S.field_extension('b') # optional - sage.rings.finite_rings Traceback (most recent call last): ... AttributeError: 'PolynomialQuotientRing_generic_with_category' object has no attribute 'field_extension' @@ -2274,21 +2330,21 @@ def field_extension(self, names): Over a finite field, the corresponding field extension is not a number field:: - sage: R. = GF(25, 'a')['x'] - sage: S. = R.quo(x^3 + 2*x + 1) - sage: F, g, h = S.field_extension('b') - sage: h(F.0^2 + 3) + sage: R. = GF(25, 'a')['x'] # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + 2*x + 1) # optional - sage.rings.finite_rings + sage: F, g, h = S.field_extension('b') # optional - sage.rings.finite_rings + sage: h(F.0^2 + 3) # optional - sage.rings.finite_rings a^2 + 3 - sage: g(x^2 + 2) + sage: g(x^2 + 2) # optional - sage.rings.finite_rings b^2 + 2 We do an example involving a relative number field:: sage: R. = QQ['x'] - sage: K. = NumberField(x^3 - 2) - sage: S. = K['X'] - sage: Q. = S.quo(X^3 + 2*X + 1) - sage: Q.field_extension('b') + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: Q. = S.quo(X^3 + 2*X + 1) # optional - sage.rings.number_field + sage: Q.field_extension('b') # optional - sage.rings.number_field (Number Field in b with defining polynomial X^3 + 2*X + 1 over its base field, ... Defn: b |--> b, Relative number field morphism: From: Number Field in b with defining polynomial X^3 + 2*X + 1 over its base field @@ -2301,19 +2357,19 @@ def field_extension(self, names): :: sage: R. = QQ['x'] - sage: K. = NumberField(x^3 - 2) - sage: S. = K['X'] - sage: f = (X+a)^3 + 2*(X+a) + 1 - sage: f + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: f = (X+a)^3 + 2*(X+a) + 1 # optional - sage.rings.number_field + sage: f # optional - sage.rings.number_field X^3 + 3*a*X^2 + (3*a^2 + 2)*X + 2*a + 3 - sage: Q. = S.quo(f) - sage: F., g, h = Q.field_extension() - sage: c = g(z) - sage: f(c) + sage: Q. = S.quo(f) # optional - sage.rings.number_field + sage: F., g, h = Q.field_extension() # optional - sage.rings.number_field + sage: c = g(z) # optional - sage.rings.number_field + sage: f(c) # optional - sage.rings.number_field 0 - sage: h(g(z)) + sage: h(g(z)) # optional - sage.rings.number_field z - sage: g(h(w)) + sage: g(h(w)) # optional - sage.rings.number_field w AUTHORS: @@ -2331,12 +2387,13 @@ class PolynomialQuotientRing_field(PolynomialQuotientRing_domain, Field): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^2 + 1) - sage: S - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 - sage: loads(S.dumps()) == S + sage: S. = R.quotient(x^2 + 1) # optional - sage.rings.number_field + sage: S # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 + 1 + sage: loads(S.dumps()) == S # optional - sage.rings.number_field True - sage: loads(xbar.dumps()) == xbar + sage: loads(xbar.dumps()) == xbar # optional - sage.rings.number_field True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2357,10 +2414,14 @@ def complex_embeddings(self, prec=53): sage: R. = QQ[] sage: f = x^5 + x + 17 - sage: k = R.quotient(f) - sage: v = k.complex_embeddings(100) - sage: [phi(k.0^2) for phi in v] - [2.9757207403766761469671194565, -2.4088994371613850098316292196 + 1.9025410530350528612407363802*I, -2.4088994371613850098316292196 - 1.9025410530350528612407363802*I, 0.92103906697304693634806949137 - 3.0755331188457794473265418086*I, 0.92103906697304693634806949137 + 3.0755331188457794473265418086*I] + sage: k = R.quotient(f) # optional - sage.rings.number_field + sage: v = k.complex_embeddings(100) # optional - sage.rings.number_field + sage: [phi(k.0^2) for phi in v] # optional - sage.rings.number_field + [2.9757207403766761469671194565, + -2.4088994371613850098316292196 + 1.9025410530350528612407363802*I, + -2.4088994371613850098316292196 - 1.9025410530350528612407363802*I, + 0.92103906697304693634806949137 - 3.0755331188457794473265418086*I, + 0.92103906697304693634806949137 + 3.0755331188457794473265418086*I] """ CC = sage.rings.complex_mpfr.ComplexField(prec) v = self.modulus().roots(multiplicities=False, ring=CC) diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py index be05a312725..0991bc1e44b 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari r""" Elements of Quotients of Univariate Polynomial Rings @@ -7,8 +8,8 @@ :: sage: R. = ZZ[] - sage: S. = R.quotient(x^3 + 3*x -1) - sage: 2 * a^3 + sage: S. = R.quotient(x^3 + 3*x - 1) # optional - sage.libs.pari + sage: 2 * a^3 # optional - sage.libs.pari -6*a + 2 Next we make a univariate polynomial ring over @@ -16,24 +17,24 @@ :: - sage: S1. = S[] + sage: S1. = S[] # optional - sage.libs.pari And, we quotient out that by `y^2 + a`. :: - sage: T. = S1.quotient(y^2+a) + sage: T. = S1.quotient(y^2 + a) # optional - sage.libs.pari In the quotient `z^2` is `-a`. :: - sage: z^2 + sage: z^2 # optional - sage.libs.pari -a And since `a^3 = -3x + 1`, we have:: - sage: z^6 + sage: z^6 # optional - sage.libs.pari 3*a - 1 :: @@ -46,7 +47,7 @@ :: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: a a sage: a^3 @@ -96,7 +97,7 @@ class PolynomialQuotientRingElement(polynomial_singular_interface.Polynomial_sin EXAMPLES:: sage: P. = QQ[] - sage: Q. = P.quo([(x^2+1)]) + sage: Q. = P.quo([(x^2 + 1)]) sage: xi^2 -1 sage: singular(xi) @@ -161,15 +162,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: Q. = S.quotient(y^2*(y-1)*(y-i)) - sage: T. = S.quotient(y*(y+1)) - sage: phi = Q.hom([t+1], base_map=cc) - sage: phi(q) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: Q. = S.quotient(y^2*(y-1)*(y-i)) # optional - sage.rings.number_field + sage: T. = S.quotient(y*(y+1)) # optional - sage.rings.number_field + sage: phi = Q.hom([t+1], base_map=cc) # optional - sage.rings.number_field + sage: phi(q) # optional - sage.rings.number_field t + 1 - sage: phi(i*q) + sage: phi(i*q) # optional - sage.rings.number_field -i*t - i """ return self._polynomial._im_gens_(codomain, im_gens, base_map=base_map) @@ -270,7 +271,7 @@ def _add_(self, right): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: (a^2 - 4) + (a+2) a^2 + a - 2 sage: int(1) + a @@ -286,7 +287,7 @@ def _div_(self, right): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: (a^2 - 4) / (a+2) a - 2 """ @@ -303,7 +304,7 @@ def _richcmp_(self, other, op): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: (a^2 - 4) / (a+2) == a - 2 True sage: a^2 - 4 == a @@ -321,7 +322,7 @@ def __int__(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: int(S(10)) 10 sage: int(a) @@ -468,51 +469,51 @@ def field_extension(self, names): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) - sage: F., f, g = alpha.field_extension() - sage: F + sage: S. = R.quotient(x^3 - 2) + sage: F., f, g = alpha.field_extension() # optional - sage.rings.number_field + sage: F # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - 2 - sage: a = F.gen() - sage: f(alpha) + sage: a = F.gen() # optional - sage.rings.number_field + sage: f(alpha) # optional - sage.rings.number_field a - sage: g(a) + sage: g(a) # optional - sage.rings.number_field alpha Over a finite field, the corresponding field extension is not a number field:: - sage: R. = GF(25,'b')['x'] - sage: S. = R.quo(x^3 + 2*x + 1) - sage: F., g, h = a.field_extension() - sage: h(b^2 + 3) + sage: R. = GF(25,'b')['x'] # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + 2*x + 1) # optional - sage.rings.finite_rings + sage: F., g, h = a.field_extension() # optional - sage.rings.finite_rings + sage: h(b^2 + 3) # optional - sage.rings.finite_rings a^2 + 3 - sage: g(x^2 + 2) + sage: g(x^2 + 2) # optional - sage.rings.finite_rings b^2 + 2 We do an example involving a relative number field:: sage: R. = QQ['x'] - sage: K. = NumberField(x^3-2) - sage: S. = K['X'] - sage: Q. = S.quo(X^3 + 2*X + 1) - sage: F, g, h = b.field_extension('c') + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: Q. = S.quo(X^3 + 2*X + 1) # optional - sage.rings.number_field + sage: F, g, h = b.field_extension('c') # optional - sage.rings.number_field Another more awkward example:: sage: R. = QQ['x'] - sage: K. = NumberField(x^3-2) - sage: S. = K['X'] - sage: f = (X+a)^3 + 2*(X+a) + 1 - sage: f + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: f = (X+a)^3 + 2*(X+a) + 1 # optional - sage.rings.number_field + sage: f # optional - sage.rings.number_field X^3 + 3*a*X^2 + (3*a^2 + 2)*X + 2*a + 3 - sage: Q. = S.quo(f) - sage: F., g, h = z.field_extension() - sage: c = g(z) - sage: f(c) + sage: Q. = S.quo(f) # optional - sage.rings.number_field + sage: F., g, h = z.field_extension() # optional - sage.rings.number_field + sage: c = g(z) # optional - sage.rings.number_field + sage: f(c) # optional - sage.rings.number_field 0 - sage: h(g(z)) + sage: h(g(z)) # optional - sage.rings.number_field z - sage: g(h(w)) + sage: g(h(w)) # optional - sage.rings.number_field w AUTHORS: @@ -693,21 +694,21 @@ def minpoly(self): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^3 + 2*x - 5) - sage: (a+123).minpoly() + sage: (a + 123).minpoly() x^3 - 369*x^2 + 45389*x - 1861118 - sage: (a+123).matrix().minpoly() + sage: (a + 123).matrix().minpoly() x^3 - 369*x^2 + 45389*x - 1861118 One useful application of this function is to compute a minimal polynomial of a finite-field element over an intermediate extension, rather than the absolute minimal polynomial over the prime field:: - sage: F2. = GF((431,2), modulus=[1,0,1]) - sage: F6. = F2.extension(3) - sage: (u+1).minpoly() + sage: F2. = GF((431,2), modulus=[1,0,1]) # optional - sage.rings.finite_rings + sage: F6. = F2.extension(3) # optional - sage.rings.finite_rings + sage: (u + 1).minpoly() # optional - sage.rings.finite_rings x^6 + 425*x^5 + 19*x^4 + 125*x^3 + 189*x^2 + 239*x + 302 - sage: ext = F6.over(F2) - sage: ext(u+1).minpoly() # indirect doctest + sage: ext = F6.over(F2) # optional - sage.rings.finite_rings + sage: ext(u + 1).minpoly() # indirect doctest # optional - sage.rings.finite_rings x^3 + (396*i + 428)*x^2 + (80*i + 39)*x + 9*i + 178 TESTS: @@ -715,15 +716,15 @@ def minpoly(self): We make sure that the previous example works on random examples:: sage: p = random_prime(50) - sage: K. = GF((p, randrange(1,20))) - sage: L. = K.extension(randrange(2,20)) - sage: LK = L.over(K) - sage: a = L.random_element() - sage: poly = LK(a).minpoly() # indirect doctest - sage: poly(a) + sage: K. = GF((p, randrange(1,20))) # optional - sage.rings.finite_rings + sage: L. = K.extension(randrange(2,20)) # optional - sage.rings.finite_rings + sage: LK = L.over(K) # optional - sage.rings.finite_rings + sage: a = L.random_element() # optional - sage.rings.finite_rings + sage: poly = LK(a).minpoly() # indirect doctest # optional - sage.rings.finite_rings + sage: poly(a) # optional - sage.rings.finite_rings 0 - sage: abs_deg = a.minpoly().degree() - sage: poly.degree() == abs_deg // gcd(abs_deg, K.degree()) + sage: abs_deg = a.minpoly().degree() # optional - sage.rings.finite_rings + sage: poly.degree() == abs_deg // gcd(abs_deg, K.degree()) # optional - sage.rings.finite_rings True """ poly = self.lift() @@ -741,7 +742,7 @@ def norm(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3 -389*x^2 + 2*x - 5) + sage: S. = R.quotient(x^3 - 389*x^2 + 2*x - 5) sage: a.norm() 5 """ @@ -771,11 +772,14 @@ def rational_reconstruction(self, *args, **kwargs): EXAMPLES:: - sage: R. = GF(65537)[] - sage: m = x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 + 17496*x^6 + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2 + 54266*x + 47805 - sage: f = 20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 + 63091*x^5 + 15288*x^4 + 32516*x^3 + 2181*x^2 + 45236*x + 2447 - sage: f_mod_m = R.quotient(m)(f) - sage: f_mod_m.rational_reconstruction() + sage: R. = GF(65537)[] # optional - sage.rings.finite_rings + sage: m = (x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 # optional - sage.rings.finite_rings + ....: + 17496*x^6 + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2 + ....: + 54266*x + 47805) + sage: f = (20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 # optional - sage.rings.finite_rings + ....: + 63091*x^5 + 15288*x^4 + 32516*x^3 + 2181*x^2 + 45236*x + 2447) + sage: f_mod_m = R.quotient(m)(f) # optional - sage.rings.finite_rings + sage: f_mod_m.rational_reconstruction() # optional - sage.rings.finite_rings (51388*x^5 + 29141*x^4 + 59341*x^3 + 7034*x^2 + 14152*x + 23746, x^5 + 15208*x^4 + 19504*x^3 + 20457*x^2 + 11180*x + 28352) """ diff --git a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx index c13372dcd25..6f8a19a6ad0 100644 --- a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +++ b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx @@ -6,19 +6,19 @@ TESTS: Check that operations with numpy elements work well (see :trac:`18076` and :trac:`8426`):: - sage: import numpy + sage: import numpy # optional - numpy sage: x = polygen(RR) - sage: x * numpy.int32('1') + sage: x * numpy.int32('1') # optional - numpy x - sage: numpy.int32('1') * x + sage: numpy.int32('1') * x # optional - numpy x - sage: x * numpy.int64('1') + sage: x * numpy.int64('1') # optional - numpy x - sage: numpy.int64('1') * x + sage: numpy.int64('1') * x # optional - numpy x - sage: x * numpy.float32('1.5') + sage: x * numpy.float32('1.5') # optional - numpy 1.50000000000000*x - sage: numpy.float32('1.5') * x + sage: numpy.float32('1.5') * x # optional - numpy 1.50000000000000*x """ diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index ea07c8f5437..3c73ae4469f 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -47,23 +47,23 @@ We create a polynomial ring over a quaternion algebra:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A,sparse=True) - sage: f = w^3 + (i+j)*w + 1 - sage: f + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A, sparse=True) # optional - sage.combinat sage.modules + sage: f = w^3 + (i+j)*w + 1 # optional - sage.combinat sage.modules + sage: f # optional - sage.combinat sage.modules w^3 + (i + j)*w + 1 - sage: f^2 + sage: f^2 # optional - sage.combinat sage.modules w^6 + (2*i + 2*j)*w^4 + 2*w^3 - 2*w^2 + (2*i + 2*j)*w + 1 - sage: f = w + i ; g = w + j - sage: f * g + sage: f = w + i ; g = w + j # optional - sage.combinat sage.modules + sage: f * g # optional - sage.combinat sage.modules w^2 + (i + j)*w + k - sage: g * f + sage: g * f # optional - sage.combinat sage.modules w^2 + (i + j)*w - k :trac:`9944` introduced some changes related with coercion. Previously, a dense and a sparse polynomial ring with the same variable name over the same base ring evaluated equal, but of -course they were not identical.Coercion maps are cached - but if a +course they were not identical. Coercion maps are cached - but if a coercion to a dense ring is requested and a coercion to a sparse ring is returned instead (since the cache keys are equal!), all hell breaks loose. @@ -79,37 +79,37 @@ True sage: R.has_coerce_map_from(S) False - sage: (R.0+S.0).parent() + sage: (R.0 + S.0).parent() Univariate Polynomial Ring in x over Rational Field - sage: (S.0+R.0).parent() + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Rational Field It may be that one has rings of dense or sparse polynomials over different base rings. In that situation, coercion works by means of the :func:`~sage.categories.pushout.pushout` formalism:: - sage: R. = PolynomialRing(GF(5), sparse=True) + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.rings.finite_rings False - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.rings.finite_rings False - sage: S.0 + R.0 + sage: S.0 + R.0 # optional - sage.rings.finite_rings 2*x - sage: (S.0 + R.0).parent() + sage: (S.0 + R.0).parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 - sage: (S.0 + R.0).parent().is_sparse() + sage: (S.0 + R.0).parent().is_sparse() # optional - sage.rings.finite_rings False Similarly, there is a coercion from the (non-default) NTL implementation for univariate polynomials over the integers to the default FLINT implementation, but not vice versa:: - sage: R. = PolynomialRing(ZZ, implementation = 'NTL') - sage: S. = PolynomialRing(ZZ, implementation = 'FLINT') - sage: (S.0+R.0).parent() is S + sage: R. = PolynomialRing(ZZ, implementation='NTL') # optional - sage.libs.ntl + sage: S. = PolynomialRing(ZZ, implementation='FLINT') # optional - sage.libs.flint + sage: (S.0 + R.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True - sage: (R.0+S.0).parent() is S + sage: (R.0 + S.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True TESTS:: @@ -122,9 +122,9 @@ Check that :trac:`5562` has been fixed:: sage: R. = PolynomialRing(RDF, 1) - sage: v1 = vector([u]) - sage: v2 = vector([CDF(2)]) - sage: v1 * v2 + sage: v1 = vector([u]) # optional - sage.modules + sage: v2 = vector([CDF(2)]) # optional - sage.modules + sage: v1 * v2 # optional - sage.modules 2.0*u """ @@ -210,11 +210,11 @@ def is_PolynomialRing(x): :: - sage: R. = PolynomialRing(ZZ, implementation="singular"); R + sage: R. = PolynomialRing(ZZ, implementation="singular"); R # optional - sage.libs.singular Multivariate Polynomial Ring in w over Integer Ring - sage: is_PolynomialRing(R) + sage: is_PolynomialRing(R) # optional - sage.libs.singular False - sage: type(R) + sage: type(R) # optional - sage.libs.singular """ return isinstance(x, PolynomialRing_general) @@ -243,7 +243,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, and Category of commutative algebras over (euclidean domains and infinite enumerated sets and metric spaces) and Category of infinite sets - sage: category(GF(7)['x']) + sage: category(GF(7)['x']) # optional - sage.rings.finite_rings Join of Category of euclidean domains and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets @@ -268,13 +268,13 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: Zmod(1)['x'].is_finite() True - sage: GF(7)['x'].is_finite() + sage: GF(7)['x'].is_finite() # optional - sage.rings.finite_rings False sage: Zmod(1)['x']['y'].is_finite() True - sage: GF(7)['x']['y'].is_finite() + sage: GF(7)['x']['y'].is_finite() # optional - sage.rings.finite_rings False """ @@ -357,9 +357,9 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, Coercing in pari elements:: - sage: QQ['x'](pari('[1,2,3/5]')) + sage: QQ['x'](pari('[1,2,3/5]')) # optional - sage.libs.pari 3/5*x^2 + 2*x + 1 - sage: QQ['x'](pari('(-1/3)*x^10 + (2/3)*x - 1/5')) + sage: QQ['x'](pari('(-1/3)*x^10 + (2/3)*x - 1/5')) # optional - sage.libs.pari -1/3*x^10 + 2/3*x - 1/5 Coercing strings:: @@ -377,10 +377,10 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, This shows that the issue at :trac:`4106` is fixed:: - sage: x = var('x') + sage: x = var('x') # optional - sage.symbolic sage: R = IntegerModRing(4) - sage: S = R['x'] - sage: S(x) + sage: S = R['x'] # optional - sage.symbolic + sage: S(x) # optional - sage.symbolic x Throw a TypeError if any of the coefficients cannot be coerced @@ -393,16 +393,16 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, Check that the bug in :trac:`11239` is fixed:: - sage: K. = GF(5^2, prefix='z') - sage: L. = GF(5^4, prefix='z') - sage: f = K['x'].gen() + a - sage: L['x'](f) + sage: K. = GF(5^2, prefix='z') # optional - sage.rings.finite_rings + sage: L. = GF(5^4, prefix='z') # optional - sage.rings.finite_rings + sage: f = K['x'].gen() + a # optional - sage.rings.finite_rings + sage: L['x'](f) # optional - sage.rings.finite_rings x + b^3 + b^2 + b + 3 A test from :trac:`14485` :: - sage: x = SR.var('x') - sage: QQbar[x](x^6+x^5+x^4-x^3+x^2-x+2/5) + sage: x = SR.var('x') # optional - sage.symbolic + sage: QQbar[x](x^6 + x^5 + x^4 - x^3 + x^2 - x + 2/5) # optional - sage.rings.number_field sage.symbolic x^6 + x^5 + x^4 - x^3 + x^2 - x + 2/5 Check support for unicode characters (:trac:`29280`):: @@ -603,7 +603,8 @@ def flattening_morphism(self): sage: QQ['a','b']['x'].flattening_morphism() Flattening morphism: - From: Univariate Polynomial Ring in x over Multivariate Polynomial Ring in a, b over Rational Field + From: Univariate Polynomial Ring in x over + Multivariate Polynomial Ring in a, b over Rational Field To: Multivariate Polynomial Ring in a, b, x over Rational Field sage: QQ['x'].flattening_morphism() @@ -693,7 +694,7 @@ def _coerce_map_from_base_ring(self): Polynomial base injection morphism: From: Rational Field To: Univariate Polynomial Ring in x over Rational Field - sage: R.coerce_map_from(GF(7)) + sage: R.coerce_map_from(GF(7)) # optional - sage.rings.finite_rings """ from .polynomial_element import PolynomialBaseringInjection @@ -732,9 +733,9 @@ def _coerce_map_from_(self, P): sage: R. = PolynomialRing(QQ, sparse=True) sage: S. = QQ[] - sage: (R.0+S.0).parent() + sage: (R.0 + S.0).parent() Univariate Polynomial Ring in x over Rational Field - sage: (S.0+R.0).parent() + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Rational Field Here we test a feature that was implemented in :trac:`813`:: @@ -743,7 +744,7 @@ def _coerce_map_from_(self, P): sage: Q = Frac(QQ['x'])['y'] sage: Q.has_coerce_map_from(P) True - sage: P.0+Q.0 + sage: P.0 + Q.0 y + x In order to avoid bidirectional coercions (which are generally @@ -761,20 +762,20 @@ def _coerce_map_from_(self, P): Over the integers, there is a coercion from the NTL and generic implementation to the default FLINT implementation:: - sage: R = PolynomialRing(ZZ, 't', implementation="NTL") - sage: S = PolynomialRing(ZZ, 't', implementation="FLINT") + sage: R = PolynomialRing(ZZ, 't', implementation="NTL") # optional - sage.libs.ntl + sage: S = PolynomialRing(ZZ, 't', implementation="FLINT") # optional - sage.libs.flint sage: T = PolynomialRing(ZZ, 't', implementation="generic") - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.libs.flint sage.libs.ntl False - sage: R.has_coerce_map_from(T) + sage: R.has_coerce_map_from(T) # optional - sage.libs.ntl False - sage: S.has_coerce_map_from(T) + sage: S.has_coerce_map_from(T) # optional - sage.libs.flint True - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.libs.flint sage.libs.ntl True - sage: T.has_coerce_map_from(R) + sage: T.has_coerce_map_from(R) # optional - sage.libs.ntl False - sage: T.has_coerce_map_from(S) + sage: T.has_coerce_map_from(S) # optional - sage.libs.flint False """ base_ring = self.base_ring() @@ -843,11 +844,11 @@ def _magma_init_(self, magma): Univariate Polynomial Ring in y over Rational Field sage: S.1 # optional - magma y - sage: magma(PolynomialRing(GF(7), 'x')) # optional - magma + sage: magma(PolynomialRing(GF(7), 'x')) # optional - magma # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over GF(7) - sage: magma(PolynomialRing(GF(49,'a'), 'x')) # optional - magma + sage: magma(PolynomialRing(GF(49,'a'), 'x')) # optional - magma # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over GF(7^2) - sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma + sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma Univariate Polynomial Ring in x over Univariate Polynomial Ring in w over Integer Ring Watch out, Magma has different semantics from Sage, i.e., in Magma @@ -867,9 +868,9 @@ def _magma_init_(self, magma): A nested example over a Givaro finite field:: - sage: k. = GF(9) - sage: R. = k[] - sage: magma(a^2*x^3 + (a+1)*x + a) # optional - magma + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: magma(a^2*x^3 + (a+1)*x + a) # optional - magma # optional - sage.rings.finite_rings a^2*x^3 + a^2*x + a """ B = magma(self.base_ring()) @@ -888,23 +889,23 @@ def _gap_init_(self, gap=None): EXAMPLES:: sage: R. = ZZ[] - sage: gap(R) + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: gap(R) is gap(R) + sage: gap(R) is gap(R) # optional - sage.libs.gap True - sage: gap(z^2 + z) + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z A univariate polynomial ring over a multivariate polynomial ring over a number field:: sage: Q. = QQ[] - sage: K. = NumberField(t^2+t+1) - sage: P. = K[] - sage: S. = P[] - sage: gap(S) + sage: K. = NumberField(t^2 + t + 1) # optional - sage.rings.number_field + sage: P. = K[] # optional - sage.rings.number_field + sage: S. = P[] # optional - sage.rings.number_field + sage: gap(S) # optional - sage.libs.gap sage.rings.number_field PolynomialRing( PolynomialRing( , ["x", "y"] ), ["z"] ) - sage: gap(S) is gap(S) + sage: gap(S) is gap(S) # optional - sage.libs.gap sage.rings.number_field True """ if gap is not None: @@ -920,11 +921,11 @@ def _sage_input_(self, sib, coerced): EXAMPLES:: - sage: sage_input(GF(5)['x']['y'], verify=True) + sage: sage_input(GF(5)['x']['y'], verify=True) # optional - sage.rings.finite_rings # Verified GF(5)['x']['y'] - sage: from sage.misc.sage_input import SageInputBuilder - sage: ZZ['z']._sage_input_(SageInputBuilder(), False) + sage: from sage.misc.sage_input import SageInputBuilder # optional - sage.rings.finite_rings + sage: ZZ['z']._sage_input_(SageInputBuilder(), False) # optional - sage.rings.finite_rings {constr_parent: {subscr: {atomic:ZZ}[{atomic:'z'}]} with gens: ('z',)} """ base = sib(self.base_ring()) @@ -963,9 +964,9 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = QQ[] - sage: R._is_valid_homomorphism_(GF(7), [5]) + sage: R._is_valid_homomorphism_(GF(7), [5]) # optional - sage.rings.finite_rings False - sage: R._is_valid_homomorphism_(Qp(7), [5]) + sage: R._is_valid_homomorphism_(Qp(7), [5]) # optional - sage.rings.padics True """ # Since poly rings are free, any image of the gen @@ -1004,7 +1005,7 @@ def _latex_(self): r""" EXAMPLES:: - sage: S.=ZZ[] + sage: S. = ZZ[] sage: latex(S) \Bold{Z}[\alpha_{12}] """ @@ -1042,7 +1043,7 @@ def change_ring(self, R): sage: R. = RealIntervalField() []; R Univariate Polynomial Ring in ZZZ over Real Interval Field with 53 bits of precision - sage: R.change_ring(GF(19^2,'b')) + sage: R.change_ring(GF(19^2, 'b')) # optional - sage.rings.finite_rings Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2 """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -1067,8 +1068,8 @@ def change_var(self, var): def extend_variables(self, added_names, order = 'degrevlex'): r""" - Returns a multivariate polynomial ring with the same base ring but - with added_names as additional variables. + Return a multivariate polynomial ring with the same base ring but + with ``added_names`` as additional variables. EXAMPLES:: @@ -1146,7 +1147,7 @@ def characteristic(self): Univariate Polynomial Ring in ZZZ over Real Interval Field with 53 bits of precision sage: R.characteristic() 0 - sage: S = R.change_ring(GF(19^2,'b')); S + sage: S = R.change_ring(GF(19^2, 'b')); S # optional - sage.rings.finite_rings Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2 sage: S.characteristic() 19 @@ -1163,23 +1164,23 @@ def cyclotomic_polynomial(self, n): EXAMPLES:: sage: R = ZZ['x'] - sage: R.cyclotomic_polynomial(8) + sage: R.cyclotomic_polynomial(8) # optional - sage.libs.pari x^4 + 1 - sage: R.cyclotomic_polynomial(12) + sage: R.cyclotomic_polynomial(12) # optional - sage.libs.pari x^4 - x^2 + 1 - sage: S = PolynomialRing(FiniteField(7), 'x') - sage: S.cyclotomic_polynomial(12) + sage: S = PolynomialRing(FiniteField(7), 'x') # optional - sage.rings.finite_rings + sage: S.cyclotomic_polynomial(12) # optional - sage.rings.finite_rings x^4 + 6*x^2 + 1 - sage: S.cyclotomic_polynomial(1) + sage: S.cyclotomic_polynomial(1) # optional - sage.rings.finite_rings x + 6 TESTS: Make sure it agrees with other systems for the trivial case:: - sage: ZZ['x'].cyclotomic_polynomial(1) + sage: ZZ['x'].cyclotomic_polynomial(1) # optional - sage.libs.pari x - 1 - sage: gp('polcyclo(1)') + sage: gp('polcyclo(1)') # optional - sage.libs.pari x - 1 """ if n <= 0: @@ -1307,16 +1308,16 @@ def krull_dimension(self): sage: R. = QQ[] sage: R.krull_dimension() 1 - sage: R. = GF(9,'a')[]; R + sage: R. = GF(9, 'a')[]; R # optional - sage.rings.finite_rings Univariate Polynomial Ring in z over Finite Field in a of size 3^2 - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.finite_rings 1 - sage: S. = R[] - sage: S.krull_dimension() + sage: S. = R[] # optional - sage.rings.finite_rings + sage: S.krull_dimension() # optional - sage.rings.finite_rings 2 - sage: for n in range(10): - ....: S = PolynomialRing(S,'w') - sage: S.krull_dimension() + sage: for n in range(10): # optional - sage.rings.finite_rings + ....: S = PolynomialRing(S, 'w') + sage: S.krull_dimension() # optional - sage.rings.finite_rings 12 """ return self.base_ring().krull_dimension() + 1 @@ -1361,7 +1362,7 @@ def random_element(self, degree=(-1,2), *args, **kwds): sage: R.random_element(6).degree() 6 - If a tuple of two integers is given for the degree argument, a degree + If a tuple of two integers is given for the ``degree`` argument, a degree is first uniformly chosen, then a polynomial of that degree is given:: sage: R.random_element(degree=(0, 8)).degree() in range(0, 9) @@ -1373,7 +1374,7 @@ def random_element(self, degree=(-1,2), *args, **kwds): Note that the zero polynomial has degree ``-1``, so if you want to consider it set the minimum degree to ``-1``:: - sage: while R.random_element(degree=(-1,2),x=-1,y=1) != R.zero(): + sage: while R.random_element(degree=(-1,2), x=-1, y=1) != R.zero(): ....: pass TESTS:: @@ -1390,13 +1391,13 @@ def random_element(self, degree=(-1,2), *args, **kwds): Check that :trac:`16682` is fixed:: - sage: R = PolynomialRing(GF(2), 'z') - sage: for _ in range(100): + sage: R = PolynomialRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: for _ in range(100): # optional - sage.rings.finite_rings ....: d = randint(-1,20) ....: P = R.random_element(degree=d) ....: assert P.degree() == d, "problem with {} which has not degree {}".format(P,d) - sage: R.random_element(degree=-2) + sage: R.random_element(degree=-2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: degree should be an integer greater or equal than -1 @@ -1494,12 +1495,12 @@ def _Karatsuba_threshold(self): EXAMPLES:: - sage: R. = QQbar[] - sage: R._Karatsuba_threshold + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R._Karatsuba_threshold # optional - sage.rings.number_field 8 - sage: MS = MatrixSpace(ZZ, 2, 2) - sage: R. = MS[] - sage: R._Karatsuba_threshold + sage: MS = MatrixSpace(ZZ, 2, 2) # optional - sage.modules + sage: R. = MS[] # optional - sage.modules + sage: R._Karatsuba_threshold # optional - sage.modules 0 """ base_ring = self.base_ring() @@ -1560,18 +1561,18 @@ def polynomials( self, of_degree = None, max_degree = None ): - ``max_degree`` - an int; the iterator will generate all polynomials which have degree less than or equal to - max_degree + ``max_degree`` - ``of_degree`` - an int; the iterator will generate - all polynomials which have degree of_degree + all polynomials which have degree ``of_degree`` OUTPUT: an iterator EXAMPLES:: - sage: P = PolynomialRing(GF(3),'y') - sage: for p in P.polynomials( of_degree = 2 ): print(p) + sage: P = PolynomialRing(GF(3), 'y') # optional - sage.rings.finite_rings + sage: for p in P.polynomials(of_degree=2): print(p) # optional - sage.rings.finite_rings y^2 y^2 + 1 y^2 + 2 @@ -1590,7 +1591,7 @@ def polynomials( self, of_degree = None, max_degree = None ): 2*y^2 + 2*y 2*y^2 + 2*y + 1 2*y^2 + 2*y + 2 - sage: for p in P.polynomials( max_degree = 1 ): print(p) + sage: for p in P.polynomials(max_degree=1): print(p) # optional - sage.rings.finite_rings 0 1 2 @@ -1600,7 +1601,7 @@ def polynomials( self, of_degree = None, max_degree = None ): 2*y 2*y + 1 2*y + 2 - sage: for p in P.polynomials( max_degree = 1, of_degree = 3 ): print(p) + sage: for p in P.polynomials(max_degree=1, of_degree=3): print(p) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: you should pass exactly one of of_degree and max_degree @@ -1637,8 +1638,8 @@ def monics( self, of_degree = None, max_degree = None ): EXAMPLES:: - sage: P = PolynomialRing(GF(4,'a'),'y') - sage: for p in P.monics( of_degree = 2 ): print(p) + sage: P = PolynomialRing(GF(4, 'a'), 'y') # optional - sage.rings.finite_rings + sage: for p in P.monics(of_degree=2): print(p) # optional - sage.rings.finite_rings y^2 y^2 + a y^2 + a + 1 @@ -1655,13 +1656,13 @@ def monics( self, of_degree = None, max_degree = None ): y^2 + y + a y^2 + y + a + 1 y^2 + y + 1 - sage: for p in P.monics( max_degree = 1 ): print(p) + sage: for p in P.monics(max_degree=1): print(p) # optional - sage.rings.finite_rings 1 y y + a y + a + 1 y + 1 - sage: for p in P.monics( max_degree = 1, of_degree = 3 ): print(p) + sage: for p in P.monics(max_degree=1, of_degree=3): print(p) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: you should pass exactly one of of_degree and max_degree @@ -1712,25 +1713,27 @@ def quotient_by_principal_ideal(self, f, names=None, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: I = (x^2-1)*R - sage: R.quotient_by_principal_ideal(I) - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 1 + sage: I = (x^2 - 1) * R + sage: R.quotient_by_principal_ideal(I) # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar + over Rational Field with modulus x^2 - 1 The same example, using the polynomial instead of the ideal, and customizing the variable name:: sage: R. = QQ[] - sage: R.quotient_by_principal_ideal(x^2-1, names=('foo',)) - Univariate Quotient Polynomial Ring in foo over Rational Field with modulus x^2 - 1 + sage: R.quotient_by_principal_ideal(x^2 - 1, names=('foo',)) # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in foo + over Rational Field with modulus x^2 - 1 TESTS: Quotienting by the zero ideal returns ``self`` (:trac:`5978`):: sage: R = QQ['x'] - sage: R.quotient_by_principal_ideal(R.zero_ideal()) is R + sage: R.quotient_by_principal_ideal(R.zero_ideal()) is R # optional - sage.libs.pari True - sage: R.quotient_by_principal_ideal(0) is R + sage: R.quotient_by_principal_ideal(0) is R # optional - sage.libs.pari True """ from sage.rings.ideal import Ideal @@ -1748,9 +1751,9 @@ def weyl_algebra(self): EXAMPLES:: sage: R = QQ['x'] - sage: W = R.weyl_algebra(); W + sage: W = R.weyl_algebra(); W # optional - sage.combinat sage.modules Differential Weyl algebra of polynomials in x over Rational Field - sage: W.polynomial_ring() == R + sage: W.polynomial_ring() == R # optional - sage.combinat sage.modules True """ from sage.algebras.weyl_algebra import DifferentialWeylAlgebra @@ -1813,12 +1816,12 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing sage: R = PRing(ZZ, 'x'); R Univariate Polynomial Ring in x over Integer Ring - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl """ self._implementation_repr = '' @@ -1872,77 +1875,80 @@ def weil_polynomials(self, d, q, sign=1, lead=1): - ``sign`` -- integer (default `1`), the sign `s` of the functional equation - ``lead`` -- integer, list of integers or list of pairs of integers (default `1`), - constraints on the leading few coefficients of the generated polynomials. - If pairs `(a, b)` of integers are given, they are treated as a constraint - of the form `\equiv a \pmod{b}`; the moduli must be in decreasing order by - divisibility, and the modulus of the leading coefficient must be 0. + constraints on the leading few coefficients of the generated polynomials. + If pairs `(a, b)` of integers are given, they are treated as a constraint + of the form `\equiv a \pmod{b}`; the moduli must be in decreasing order by + divisibility, and the modulus of the leading coefficient must be 0. .. SEEALSO:: More documentation and additional options are available using the iterator :class:`sage.rings.polynomial.weil.weil_polynomials.WeilPolynomials` - directly. In addition, polynomials have a method `is_weil_polynomial` to + directly. In addition, polynomials have a method :meth:`is_weil_polynomial` to test whether or not the given polynomial is a Weil polynomial. EXAMPLES:: sage: R. = ZZ[] - sage: L = R.weil_polynomials(4, 2) - sage: len(L) + sage: L = R.weil_polynomials(4, 2) # optional - sage.libs.flint + sage: len(L) # optional - sage.libs.flint 35 - sage: L[9] + sage: L[9] # optional - sage.libs.flint T^4 + T^3 + 2*T^2 + 2*T + 4 - sage: all(p.is_weil_polynomial() for p in L) + sage: all(p.is_weil_polynomial() for p in L) # optional - sage.libs.flint True Setting multiple leading coefficients:: sage: R. = QQ[] - sage: l = R.weil_polynomials(4,2,lead=((1,0),(2,4),(1,2))) - sage: l + sage: l = R.weil_polynomials(4, 2, lead=((1,0), (2,4), (1,2))) # optional - sage.libs.flint + sage: l # optional - sage.libs.flint [T^4 + 2*T^3 + 5*T^2 + 4*T + 4, - T^4 + 2*T^3 + 3*T^2 + 4*T + 4, - T^4 - 2*T^3 + 5*T^2 - 4*T + 4, - T^4 - 2*T^3 + 3*T^2 - 4*T + 4] + T^4 + 2*T^3 + 3*T^2 + 4*T + 4, + T^4 - 2*T^3 + 5*T^2 - 4*T + 4, + T^4 - 2*T^3 + 3*T^2 - 4*T + 4] We do not require Weil polynomials to be monic. This example generates Weil polynomials associated to K3 surfaces over `GF(2)` of Picard number at least 12:: sage: R. = QQ[] - sage: l = R.weil_polynomials(10,1,lead=2) - sage: len(l) + sage: l = R.weil_polynomials(10, 1, lead=2) # optional - sage.libs.flint + sage: len(l) # optional - sage.libs.flint 4865 - sage: l[len(l)//2] + sage: l[len(l)//2] # optional - sage.libs.flint 2*T^10 + T^8 + T^6 + T^4 + T^2 + 2 TESTS: We check that products of Weil polynomials are also listed as Weil polynomials:: - sage: all((f * g) in R.weil_polynomials(6, q) for q in [3,4] for f in R.weil_polynomials(2, q) for g in R.weil_polynomials(4, q)) + sage: all((f * g) in R.weil_polynomials(6, q) for q in [3, 4] # optional - sage.libs.flint + ....: for f in R.weil_polynomials(2, q) for g in R.weil_polynomials(4, q)) True We check that irreducible Weil polynomials of degree 6 are CM:: - sage: simples = [f for f in R.weil_polynomials(6, 3) if f.is_irreducible()] - sage: len(simples) + sage: simples = [f for f in R.weil_polynomials(6, 3) if f.is_irreducible()] # optional - sage.libs.flint + sage: len(simples) # optional - sage.libs.flint 348 - sage: reals = [R([f[3+i] + sum((-3)^j * (i+2*j)/(i+j) * binomial(i+j,j) * f[3+i+2*j] for j in range(1,(3+i)//2+1)) for i in range(4)]) for f in simples] + sage: reals = [R([f[3+i] + sum((-3)^j * (i+2*j)/(i+j) * binomial(i+j,j) * f[3+i+2*j] # optional - sage.libs.flint + ....: for j in range(1, (3+i)//2 + 1)) + ....: for i in range(4)]) for f in simples] Check that every polynomial in this list has 3 real roots between `-2 \sqrt{3}` and `2 \sqrt{3}`:: - sage: roots = [f.roots(RR, multiplicities=False) for f in reals] - sage: all(len(L) == 3 and all(x^2 <= 12 for x in L) for L in roots) + sage: roots = [f.roots(RR, multiplicities=False) for f in reals] # optional - sage.libs.flint + sage: all(len(L) == 3 and all(x^2 <= 12 for x in L) for L in roots) # optional - sage.libs.flint True Finally, check that the original polynomials are reconstructed as CM polynomials:: - sage: all(f == T^3*r(T + 3/T) for (f, r) in zip(simples, reals)) + sage: all(f == T^3*r(T + 3/T) for (f, r) in zip(simples, reals)) # optional - sage.libs.flint True A simple check (not sufficient):: - sage: all(f.number_of_real_roots() == 0 for f in simples) + sage: all(f.number_of_real_roots() == 0 for f in simples) # optional - sage.libs.flint True """ R = self.base_ring() @@ -1981,7 +1987,7 @@ def _repr_(self): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) """ s = PolynomialRing_commutative._repr_(self) @@ -2001,11 +2007,11 @@ def construction(self): sage: functor.implementation is None True - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: functor, arg = R.construction(); functor, arg + sage: functor, arg = R.construction(); functor, arg # optional - sage.libs.ntl (Poly[x], Integer Ring) - sage: functor.implementation + sage: functor.implementation # optional - sage.libs.ntl 'NTL' """ implementation = None @@ -2030,7 +2036,7 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_field as PRing sage: R = PRing(QQ, 'x'); R Univariate Polynomial Ring in x over Rational Field - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint sage: R = PRing(QQ, 'x', sparse=True); R Sparse Univariate Polynomial Ring in x over Rational Field @@ -2043,7 +2049,7 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, Demonstrate that :trac:`8762` is fixed:: - sage: R. = PolynomialRing(GF(next_prime(10^20)), sparse=True) + sage: R. = PolynomialRing(GF(next_prime(10^20)), sparse=True) # optional - sage.rings.finite_rings sage: x^(10^20) # this should be fast x^100000000000000000000 """ @@ -2090,8 +2096,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: R. = GF(5)[] - sage: R._ideal_class_() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: R._ideal_class_() # optional - sage.rings.finite_rings """ from sage.rings.polynomial.ideal import Ideal_1poly_field @@ -2107,7 +2113,7 @@ def divided_difference(self, points, full_table=False): - ``points`` -- a list of pairs `(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)` of elements of the base ring of ``self``, where `x_i - x_j` is invertible for `i \neq j`. This method - converts the `x_i` and `y_i` into the base ring of `self`. + converts the `x_i` and `y_i` into the base ring of ``self``. - ``full_table`` -- boolean (default: ``False``): If ``True``, return the full divided-difference table. If ``False``, @@ -2131,32 +2137,29 @@ def divided_difference(self, points, full_table=False): Only return the divided-difference coefficients `F_{i,i}`. This example is taken from Example 1, page 121 of [BF2005]_:: - sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), (1.9, 0.2818186), (2.2, 0.1103623)] + sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), + ....: (1.9, 0.2818186), (2.2, 0.1103623)] sage: R = PolynomialRing(RR, "x") sage: R.divided_difference(points) [0.765197700000000, - -0.483705666666666, - -0.108733888888889, - 0.0658783950617283, - 0.00182510288066044] + -0.483705666666666, + -0.108733888888889, + 0.0658783950617283, + 0.00182510288066044] Now return the full divided-difference table:: - sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), (1.9, 0.2818186), (2.2, 0.1103623)] + sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), + ....: (1.9, 0.2818186), (2.2, 0.1103623)] sage: R = PolynomialRing(RR, "x") sage: R.divided_difference(points, full_table=True) [[0.765197700000000], - [0.620086000000000, -0.483705666666666], - [0.455402200000000, -0.548946000000000, -0.108733888888889], - [0.281818600000000, - -0.578612000000000, - -0.0494433333333339, - 0.0658783950617283], - [0.110362300000000, - -0.571520999999999, - 0.0118183333333349, - 0.0680685185185209, - 0.00182510288066044]] + [0.620086000000000, -0.483705666666666], + [0.455402200000000, -0.548946000000000, -0.108733888888889], + [0.281818600000000, -0.578612000000000, + -0.0494433333333339, 0.0658783950617283], + [0.110362300000000, -0.571520999999999, 0.0118183333333349, + 0.0680685185185209, 0.00182510288066044]] The following example is taken from Example 4.12, page 225 of [MF1999]_:: @@ -2167,11 +2170,11 @@ def divided_difference(self, points, full_table=False): [-3, 3, 6, 1, 0, 0] sage: R.divided_difference(points, full_table=True) [[-3], - [0, 3], - [15, 15, 6], - [48, 33, 9, 1], - [105, 57, 12, 1, 0], - [192, 87, 15, 1, 0, 0]] + [0, 3], + [15, 15, 6], + [48, 33, 9, 1], + [105, 57, 12, 1, 0], + [192, 87, 15, 1, 0, 0]] """ to_base_ring = self.base_ring() points = [tuple(to_base_ring(c) for c in p) for p in points] @@ -2197,7 +2200,7 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r - ``points`` -- a list of pairs `(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)` of elements of the base ring of ``self``, where `x_i - x_j` is invertible for `i \neq j`. This method - converts the `x_i` and `y_i` into the base ring of `self`. + converts the `x_i` and `y_i` into the base ring of ``self``. - ``algorithm`` -- (default: ``'divided_difference'``): one of the following: @@ -2236,7 +2239,7 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r By default, we use the method of divided differences:: sage: R = PolynomialRing(QQ, 'x') - sage: f = R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)]); f + sage: f = R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)]); f -23/84*x^3 - 11/84*x^2 + 13/7*x + 1 sage: f(0) 1 @@ -2246,41 +2249,45 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r -2 sage: f(-4) 9 - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: f = R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)]); f + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.rings.finite_rings + sage: a = R.base_ring().gen() # optional - sage.rings.finite_rings + sage: f = R.lagrange_polynomial([(a^2+a, a), (a, 1), (a^2, a^2+a+1)]); f # optional - sage.rings.finite_rings a^2*x^2 + a^2*x + a^2 - sage: f(a^2+a) + sage: f(a^2 + a) # optional - sage.rings.finite_rings a - sage: f(a) + sage: f(a) # optional - sage.rings.finite_rings 1 - sage: f(a^2) + sage: f(a^2) # optional - sage.rings.finite_rings a^2 + a + 1 Now use a memory efficient version of Neville's method:: sage: R = PolynomialRing(QQ, 'x') - sage: R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)], algorithm="neville") + sage: R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)], + ....: algorithm="neville") [9, -11/7*x + 19/7, -17/42*x^2 - 83/42*x + 53/7, -23/84*x^3 - 11/84*x^2 + 13/7*x + 1] - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)], algorithm="neville") + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.rings.finite_rings + sage: a = R.base_ring().gen() # optional - sage.rings.finite_rings + sage: R.lagrange_polynomial([(a^2+a, a), (a, 1), (a^2, a^2+a+1)], # optional - sage.rings.finite_rings + ....: algorithm="neville") [a^2 + a + 1, x + a + 1, a^2*x^2 + a^2*x + a^2] Repeated use of Neville's method to get better Lagrange interpolation polynomials:: sage: R = PolynomialRing(QQ, 'x') - sage: p = R.lagrange_polynomial([(0,1),(2,2)], algorithm="neville") - sage: R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)], algorithm="neville", previous_row=p)[-1] + sage: p = R.lagrange_polynomial([(0,1), (2,2)], algorithm="neville") + sage: R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)], + ....: algorithm="neville", previous_row=p)[-1] -23/84*x^3 - 11/84*x^2 + 13/7*x + 1 - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: p = R.lagrange_polynomial([(a^2+a,a),(a,1)], algorithm="neville") - sage: R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)], algorithm="neville", previous_row=p)[-1] + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.rings.finite_rings + sage: a = R.base_ring().gen() # optional - sage.rings.finite_rings + sage: p = R.lagrange_polynomial([(a^2+a, a), (a, 1)], algorithm="neville") # optional - sage.rings.finite_rings + sage: R.lagrange_polynomial([(a^2+a, a), (a, 1), (a^2, a^2+a+1)], # optional - sage.rings.finite_rings + ....: algorithm="neville", previous_row=p)[-1] a^2*x^2 + a^2*x + a^2 TESTS: @@ -2322,10 +2329,10 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r Check that base fields of positive characteristic are treated correctly (see :trac:`9787`):: - sage: R. = GF(101)[] - sage: R.lagrange_polynomial([[1, 0], [2, 0]]) + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: R.lagrange_polynomial([[1, 0], [2, 0]]) # optional - sage.rings.finite_rings 0 - sage: R.lagrange_polynomial([[1, 0], [2, 0], [3, 0]]) + sage: R.lagrange_polynomial([[1, 0], [2, 0], [3, 0]]) # optional - sage.rings.finite_rings 0 """ # Perhaps we should be slightly stricter on the input and use @@ -2411,24 +2418,25 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: R.fraction_field() - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: R.fraction_field() # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 TESTS: Check that :trac:`25449` has been resolved:: - sage: k = GF(25453) - sage: F. = FunctionField(k) - sage: R. = k[] - sage: t(x) + sage: k = GF(25453) # optional - sage.rings.finite_rings + sage: F. = FunctionField(k) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: t(x) # optional - sage.rings.finite_rings x - sage: k = GF(55667) - sage: F. = FunctionField(k) - sage: R. = k[] - sage: t(x) + sage: k = GF(55667) # optional - sage.rings.finite_rings + sage: F. = FunctionField(k) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: t(x) # optional - sage.rings.finite_rings x """ @@ -2448,24 +2456,24 @@ class PolynomialRing_dense_finite_field(PolynomialRing_field): EXAMPLES:: - sage: R = PolynomialRing(GF(27, 'a'), 'x') - sage: type(R) + sage: R = PolynomialRing(GF(27, 'a'), 'x') # optional - sage.rings.finite_rings + sage: type(R) # optional - sage.rings.finite_rings """ def __init__(self, base_ring, name="x", element_class=None, implementation=None): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field - sage: R = PolynomialRing_dense_finite_field(GF(5), implementation='generic') - sage: type(R(0)) + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.rings.finite_rings + sage: R = PolynomialRing_dense_finite_field(GF(5), implementation='generic') # optional - sage.rings.finite_rings + sage: type(R(0)) # optional - sage.rings.finite_rings - sage: S = PolynomialRing_dense_finite_field(GF(25, 'a'), implementation='NTL') - sage: type(S(0)) + sage: S = PolynomialRing_dense_finite_field(GF(25, 'a'), implementation='NTL') # optional - sage.rings.finite_rings + sage: type(S(0)) # optional - sage.rings.finite_rings - sage: S = PolynomialRing_dense_finite_field(GF(64), implementation='superfast') + sage: S = PolynomialRing_dense_finite_field(GF(64), implementation='superfast') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: unknown implementation 'superfast' for dense polynomial rings over Finite Field in z6 of size 2^6 @@ -2494,16 +2502,16 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field - sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.rings.finite_rings + sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) # optional - sage.rings.finite_rings ['NTL', None] - sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), False) # optional - sage.rings.finite_rings ['NTL', None] - sage: PolynomialRing_dense_finite_field._implementation_names_impl("generic", GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl("generic", GF(4), False) # optional - sage.rings.finite_rings ['generic'] - sage: PolynomialRing_dense_finite_field._implementation_names_impl("FLINT", GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl("FLINT", GF(4), False) # optional - sage.rings.finite_rings NotImplemented - sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) # optional - sage.rings.finite_rings NotImplemented """ if sparse: @@ -2538,14 +2546,16 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: f = GF(5^3, 'a')['x'].irreducible_element(2) - sage: f.degree() + sage: f = GF(5^3, 'a')['x'].irreducible_element(2) # optional - sage.rings.finite_rings + sage: f.degree() # optional - sage.rings.finite_rings 2 - sage: f.is_irreducible() + sage: f.is_irreducible() # optional - sage.rings.finite_rings True - sage: GF(19)['x'].irreducible_element(21, algorithm="first_lexicographic") + sage: R = GF(19)['x'] # optional - sage.rings.finite_rings + sage: R.irreducible_element(21, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^21 + x + 5 - sage: GF(5**2, 'a')['x'].irreducible_element(17, algorithm="first_lexicographic") + sage: R = GF(5**2, 'a')['x'] # optional - sage.rings.finite_rings + sage: R.irreducible_element(17, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^17 + a*x + 4*a + 3 AUTHORS: @@ -2606,15 +2616,15 @@ def _roth_ruckenstein(self, p, degree_bound, precision): EXAMPLES:: - sage: F = GF(17) - sage: Px. = F[] - sage: Pxy. = Px[] - sage: p = (y - (x**2 + x + 1)) * (y**2 - x + 1) * (y - (x**3 + 4*x + 16)) - sage: Px._roth_ruckenstein(p, 3, None) + sage: F = GF(17) # optional - sage.rings.finite_rings + sage: Px. = F[] # optional - sage.rings.finite_rings + sage: Pxy. = Px[] # optional - sage.rings.finite_rings + sage: p = (y - (x**2 + x + 1)) * (y**2 - x + 1) * (y - (x**3 + 4*x + 16)) # optional - sage.rings.finite_rings + sage: Px._roth_ruckenstein(p, 3, None) # optional - sage.rings.finite_rings [x^3 + 4*x + 16, x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 2, None) + sage: Px._roth_ruckenstein(p, 2, None) # optional - sage.rings.finite_rings [x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 1, 2) + sage: Px._roth_ruckenstein(p, 1, 2) # optional - sage.rings.finite_rings [(4*x + 16, 2), (2*x + 13, 2), (15*x + 4, 2), (x + 1, 2)] """ def roth_rec(p, lam, k, g): @@ -2705,28 +2715,29 @@ def _alekhnovich(self, p, degree_bound, precision=None, dc_threshold=None): EXAMPLES:: - sage: R. = GF(17)[] - sage: S. = R[] - sage: p = (y - 2*x^2 - 3*x - 14) * (y - 3*x + 2) * (y - 1) - sage: R._alekhnovich(p, 2) + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = (y - 2*x^2 - 3*x - 14) * (y - 3*x + 2) * (y - 1) # optional - sage.rings.finite_rings + sage: R._alekhnovich(p, 2) # optional - sage.rings.finite_rings [3*x + 15, 2*x^2 + 3*x + 14, 1] - sage: R._alekhnovich(p, 1) + sage: R._alekhnovich(p, 1) # optional - sage.rings.finite_rings [3*x + 15, 1] - sage: R._alekhnovich(p, 1, precision = 2) + sage: R._alekhnovich(p, 1, precision=2) # optional - sage.rings.finite_rings [(3*x + 15, 2), (3*x + 14, 2), (1, 2)] Example of benchmark to check that `dc_threshold = None` is better:: - sage: p = prod(y - R.random_element(20) for _ in range(10)) * S.random_element(10,10) # not tested - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = None) # not tested + sage: p = prod(y - R.random_element(20) # not tested # optional - sage.rings.finite_rings + ....: for _ in range(10)) * S.random_element(10,10) + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = None) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 418 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 1) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 1) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 416 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 2) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 2) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 418 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 3) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 3) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 454 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 4) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 4) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 519 ms per loop AUTHORS: @@ -2816,24 +2827,24 @@ def _roots_univariate_polynomial(self, p, ring=None, multiplicities=False, algor EXAMPLES:: - sage: R. = GF(13)[] - sage: S. = R[] - sage: p = y^2 + (12*x^2 + x + 11)*y + x^3 + 12*x^2 + 12*x + 1 - sage: p.roots(multiplicities=False) + sage: R. = GF(13)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = y^2 + (12*x^2 + x + 11)*y + x^3 + 12*x^2 + 12*x + 1 # optional - sage.rings.finite_rings + sage: p.roots(multiplicities=False) # optional - sage.rings.finite_rings [x^2 + 11*x + 1, x + 1] - sage: p.roots(multiplicities=False, degree_bound=1) + sage: p.roots(multiplicities=False, degree_bound=1) # optional - sage.rings.finite_rings [x + 1] - sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") + sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") # optional - sage.rings.finite_rings [x^2 + 11*x + 1, x + 1] TESTS: Check that :trac:`23639` is fixed:: - sage: R = GF(3)['x']['y'] - sage: R.one().roots(multiplicities=False) + sage: R = GF(3)['x']['y'] # optional - sage.rings.finite_rings + sage: R.one().roots(multiplicities=False) # optional - sage.rings.finite_rings [] - sage: R.zero().roots(multiplicities=False) + sage: R.zero().roots(multiplicities=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: roots of 0 are not defined @@ -2878,7 +2889,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: isinstance(S, PolynomialRing_cdvr) False - sage: S. = Zp(5)[] + sage: S. = Zp(5)[] # optional - sage.rings.padics sage: isinstance(S, PolynomialRing_cdvr) True """ @@ -2909,8 +2920,8 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: isinstance(S, PolynomialRing_cdvf) False - sage: S. = Qp(5)[] - sage: isinstance(S, PolynomialRing_cdvf) + sage: S. = Qp(5)[] # optional - sage.rings.padics + sage: isinstance(S, PolynomialRing_cdvf) # optional - sage.rings.padics True """ if element_class is None: @@ -2942,11 +2953,11 @@ def _implementation_names_impl(implementation, base_ring, sparse): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_generic - sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), False) + sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), False) # optional - sage.rings.padics [None] - sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), True) + sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), True) # optional - sage.rings.padics NotImplemented - sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl("generic", Zp(2), False) + sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl("generic", Zp(2), False) # optional - sage.rings.padics NotImplemented """ if implementation is None and not sparse: @@ -2971,11 +2982,11 @@ def _implementation_names_impl(implementation, base_ring, sparse): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_field_generic - sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), False) + sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), False) # optional - sage.rings.padics [None] - sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), True) + sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), True) # optional - sage.rings.padics NotImplemented - sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl("generic", Qp(2), False) + sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl("generic", Qp(2), False) # optional - sage.rings.padics NotImplemented """ if implementation is None and not sparse: @@ -2989,9 +3000,9 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_capped_relative as PRing - sage: R = PRing(Zp(13), name='t'); R + sage: R = PRing(Zp(13), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Ring with capped relative precision 20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3010,9 +3021,9 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_capped_absolute as PRing - sage: R = PRing(Zp(13, type='capped-abs'), name='t'); R + sage: R = PRing(Zp(13, type='capped-abs'), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Ring with capped absolute precision 20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3030,10 +3041,10 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_fixed_mod as PRing - sage: R = PRing(Zp(13, type='fixed-mod'), name='t'); R + sage: R = PRing(Zp(13, type='fixed-mod'), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Ring of fixed modulus 13^20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3051,9 +3062,9 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_field_capped_relative as PRing - sage: R = PRing(Qp(13), name='t'); R + sage: R = PRing(Qp(13), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Field with capped relative precision 20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3075,27 +3086,27 @@ def __init__(self, base_ring, name=None, element_class=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_n as PRing sage: R = PRing(Zmod(15), 'x'); R Univariate Polynomial Ring in x over Ring of integers modulo 15 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R + sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 15 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl - sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R + sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl - sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT') + sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT') # optional - sage.libs.flint Traceback (most recent call last): ... ValueError: FLINT does not support modulus 27670116110564327424 - sage: R = PRing(Zmod(2**63*3), 'x'); R + sage: R = PRing(Zmod(2**63*3), 'x'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl """ if element_class is None: @@ -3186,7 +3197,7 @@ def _repr_(self): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) """ s = PolynomialRing_commutative._repr_(self) @@ -3198,32 +3209,38 @@ def residue_field(self, ideal, names=None): EXAMPLES:: - sage: R. = GF(2)[] - sage: k. = R.residue_field(t^3+t+1); k - Residue field in a of Principal ideal (t^3 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k.list() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: k. = R.residue_field(t^3 + t + 1); k # optional - sage.rings.finite_rings + Residue field in a + of Principal ideal (t^3 + t + 1) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: k.list() # optional - sage.rings.finite_rings [0, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1, 1] - sage: R.residue_field(t) - Residue field of Principal ideal (t) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: P = R.irreducible_element(8) * R - sage: P - Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k. = R.residue_field(P); k - Residue field in a of Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k.cardinality() + sage: R.residue_field(t) # optional - sage.rings.finite_rings + Residue field of Principal ideal (t) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: P = R.irreducible_element(8) * R # optional - sage.rings.finite_rings + sage: P # optional - sage.rings.finite_rings + Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: k. = R.residue_field(P); k # optional - sage.rings.finite_rings + Residue field in a + of Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: k.cardinality() # optional - sage.rings.finite_rings 256 Non-maximal ideals are not accepted:: - sage: R.residue_field(t^2 + 1) + sage: R.residue_field(t^2 + 1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal - sage: R.residue_field(0) + sage: R.residue_field(0) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal - sage: R.residue_field(1) + sage: R.residue_field(1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal @@ -3241,36 +3258,36 @@ def __init__(self, base_ring, name="x", implementation=None, element_class=None, """ TESTS:: - sage: P = GF(2)['x']; P + sage: P = GF(2)['x']; P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p # optional - sage.rings.finite_rings + sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P + sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 (using NTL) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') - sage: P + sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') # optional - sage.rings.finite_rings + sage: P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 9223372036854775837 (using NTL) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings This caching bug was fixed in :trac:`24264`:: sage: p = 2^64 + 13 - sage: A = GF(p^2) - sage: B = GF(p^3) - sage: R = A.modulus().parent() - sage: S = B.modulus().parent() - sage: R is S + sage: A = GF(p^2) # optional - sage.rings.finite_rings + sage: B = GF(p^3) # optional - sage.rings.finite_rings + sage: R = A.modulus().parent() # optional - sage.rings.finite_rings + sage: S = B.modulus().parent() # optional - sage.rings.finite_rings + sage: R is S # optional - sage.rings.finite_rings True """ if element_class is None: @@ -3312,15 +3329,15 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: PolynomialRing(GF(2), 'x', implementation="GF2X") + sage: PolynomialRing(GF(2), 'x', implementation="GF2X") # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation="NTL") + sage: PolynomialRing(GF(2), 'x', implementation="NTL") # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation=None) + sage: PolynomialRing(GF(2), 'x', implementation=None) # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation="FLINT") + sage: PolynomialRing(GF(2), 'x', implementation="FLINT") # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 - sage: PolynomialRing(GF(3), 'x', implementation="GF2X") + sage: PolynomialRing(GF(3), 'x', implementation="GF2X") # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: GF2X only supports modulus 2 @@ -3356,13 +3373,13 @@ def irreducible_element(self, n, algorithm=None): Currently available options are: - ``'adleman-lenstra'``: a variant of the Adleman--Lenstra - algorithm as implemented in PARI. + algorithm as implemented in PARI. - ``'conway'``: look up the Conway polynomial of degree `n` over the field of `p` elements in the database; raise a ``RuntimeError`` if it is not found. - - ``'ffprimroot'``: use the ``ffprimroot()`` function from + - ``'ffprimroot'``: use the :pari:`ffprimroot` function from PARI. - ``'first_lexicographic'``: return the lexicographically @@ -3375,7 +3392,7 @@ def irreducible_element(self, n, algorithm=None): - ``'primitive'``: return a polynomial `f` such that a root of `f` generates the multiplicative group of the finite field extension defined by `f`. This uses the Conway polynomial if - possible, otherwise it uses ``ffprimroot``. + possible, otherwise it uses ``'ffprimroot'``. - ``'random'``: try random polynomials until an irreducible one is found. @@ -3383,7 +3400,7 @@ def irreducible_element(self, n, algorithm=None): If ``algorithm`` is ``None``, use `x - 1` in degree 1. In degree > 1, the Conway polynomial is used if it is found in the database. Otherwise, the algorithm ``minimal_weight`` - is used if `p = 2`, and the algorithm ``adleman-lenstra`` if + is used if `p = 2`, and the algorithm ``'adleman-lenstra'`` if `p > 2`. OUTPUT: @@ -3392,35 +3409,35 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: GF(5)['x'].irreducible_element(2) + sage: GF(5)['x'].irreducible_element(2) # optional - sage.rings.finite_rings x^2 + 4*x + 2 - sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra") + sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra") # optional - sage.rings.finite_rings x^2 + x + 1 - sage: GF(5)['x'].irreducible_element(2, algorithm="primitive") + sage: GF(5)['x'].irreducible_element(2, algorithm="primitive") # optional - sage.rings.finite_rings x^2 + 4*x + 2 - sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic") + sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^32 + 2 - sage: GF(5)['x'].irreducible_element(32, algorithm="conway") + sage: GF(5)['x'].irreducible_element(32, algorithm="conway") # optional - sage.rings.finite_rings Traceback (most recent call last): ... RuntimeError: requested Conway polynomial not in database. - sage: GF(5)['x'].irreducible_element(32, algorithm="primitive") + sage: GF(5)['x'].irreducible_element(32, algorithm="primitive") # optional - sage.rings.finite_rings x^32 + ... In characteristic 2:: - sage: GF(2)['x'].irreducible_element(33) + sage: GF(2)['x'].irreducible_element(33) # optional - sage.rings.finite_rings x^33 + x^13 + x^12 + x^11 + x^10 + x^8 + x^6 + x^3 + 1 - sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight") + sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight") # optional - sage.rings.finite_rings x^33 + x^10 + 1 In degree 1:: - sage: GF(97)['x'].irreducible_element(1) + sage: GF(97)['x'].irreducible_element(1) # optional - sage.rings.finite_rings x + 96 - sage: GF(97)['x'].irreducible_element(1, algorithm="conway") + sage: GF(97)['x'].irreducible_element(1, algorithm="conway") # optional - sage.rings.finite_rings x + 92 - sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") + sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") # optional - sage.rings.finite_rings x AUTHORS: @@ -3489,9 +3506,9 @@ def polygen(ring_or_element, name="x"): INPUT: - - polygen(base_ring, name="x") + - ``polygen(base_ring, name="x")`` - - polygen(ring_element, name="x") + - ``polygen(ring_element, name="x")`` If the first input is a ring, return a polynomial generator over that ring. If it is a ring element, return a polynomial generator @@ -3499,7 +3516,7 @@ def polygen(ring_or_element, name="x"): EXAMPLES:: - sage: z = polygen(QQ,'z') + sage: z = polygen(QQ, 'z') sage: z^3 + z +1 z^3 + z + 1 sage: parent(z) @@ -3507,9 +3524,9 @@ def polygen(ring_or_element, name="x"): .. note:: - If you give a list or comma separated string to polygen, you'll + If you give a list or comma-separated string to :func:`polygen`, you'll get a tuple of indeterminates, exactly as if you called - polygens. + :func:`polygens`. """ if is_RingElement(ring_or_element): base_ring = ring_or_element.parent() @@ -3536,7 +3553,7 @@ def polygens(base_ring, names="x", *args): x^2 + 2*x*y + y^2 + 2*x*z + 2*y*z + z^2 sage: parent(x) Multivariate Polynomial Ring in x, y, z over Rational Field - sage: t = polygens(QQ,['x','yz','abc']) + sage: t = polygens(QQ, ['x','yz','abc']) sage: t (x, yz, abc) diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index 5f823ec7205..452e47415d8 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -144,8 +144,9 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R. = PolynomialRing(QQ, sparse=True); R Sparse Univariate Polynomial Ring in abc over Rational Field - sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); R - Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 + sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); R # optional - sage.rings.finite_rings + Univariate Polynomial Ring in w over + Univariate Polynomial Ring in k over Finite Field of size 7 The square bracket notation:: @@ -179,32 +180,32 @@ def PolynomialRing(base_ring, *args, **kwds): like 2^1000000 * x^1000000 in FLINT may be unwise. :: - sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL + sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT + sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT # optional - sage.libs.flint Univariate Polynomial Ring in x over Integer Ring - sage: ZxFLINT is ZZ['x'] + sage: ZxFLINT is ZZ['x'] # optional - sage.libs.flint True - sage: ZxFLINT is PolynomialRing(ZZ, 'x') + sage: ZxFLINT is PolynomialRing(ZZ, 'x') # optional - sage.libs.flint True - sage: xNTL = ZxNTL.gen() - sage: xFLINT = ZxFLINT.gen() - sage: xNTL.parent() + sage: xNTL = ZxNTL.gen() # optional - sage.libs.ntl + sage: xFLINT = ZxFLINT.gen() # optional - sage.libs.flint + sage: xNTL.parent() # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: xFLINT.parent() + sage: xFLINT.parent() # optional - sage.libs.flint Univariate Polynomial Ring in x over Integer Ring There is a coercion from the non-default to the default implementation, so the values can be mixed in a single expression:: - sage: (xNTL + xFLINT^2) + sage: (xNTL + xFLINT^2) # optional - sage.libs.flint sage.libs.ntl x^2 + x The result of such an expression will use the default, i.e., the FLINT implementation:: - sage: (xNTL + xFLINT^2).parent() + sage: (xNTL + xFLINT^2).parent() # optional - sage.libs.flint sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring The generic implementation uses neither NTL nor FLINT:: @@ -259,9 +260,9 @@ def PolynomialRing(base_ring, *args, **kwds): The Singular implementation always returns a multivariate ring, even for 1 variable:: - sage: PolynomialRing(QQ, "x", implementation="singular") + sage: PolynomialRing(QQ, "x", implementation="singular") # optional - sage.libs.singular Multivariate Polynomial Ring in x over Rational Field - sage: P. = PolynomialRing(QQ, implementation="singular"); P + sage: P. = PolynomialRing(QQ, implementation="singular"); P # optional - sage.libs.singular Multivariate Polynomial Ring in x over Rational Field **3. PolynomialRing(base_ring, n, names, ...)** (where the arguments @@ -278,7 +279,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: PolynomialRing(QQ, 2, 'alpha0') Multivariate Polynomial Ring in alpha00, alpha01 over Rational Field - sage: PolynomialRing(GF(7), 'y', 5) + sage: PolynomialRing(GF(7), 'y', 5) # optional - sage.rings.finite_rings Multivariate Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7 sage: PolynomialRing(QQ, 'y', 3, sparse=True) @@ -298,16 +299,19 @@ def PolynomialRing(base_ring, *args, **kwds): example, here is a ring with generators labeled by the primes less than 100:: - sage: R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)]); R - Multivariate Polynomial Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring + sage: R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)]); R # optional - sage.libs.pari + Multivariate Polynomial Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, + x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 + over Integer Ring By calling the :meth:`~sage.structure.category_object.CategoryObject.inject_variables` method, all those variable names are available for interactive use:: - sage: R.inject_variables() - Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 - sage: (x2 + x41 + x71)^2 + sage: R.inject_variables() # optional - sage.libs.pari + Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, + x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 + sage: (x2 + x41 + x71)^2 # optional - sage.libs.pari x2^2 + 2*x2*x41 + x41^2 + 2*x2*x71 + 2*x41*x71 + x71^2 **4. PolynomialRing(base_ring, n, ..., var_array=var_array, ...)** @@ -323,9 +327,13 @@ def PolynomialRing(base_ring, *args, **kwds): It is possible to create higher-dimensional arrays:: sage: PolynomialRing(ZZ, 2, 3, var_array=('p', 'q')) - Multivariate Polynomial Ring in p00, q00, p01, q01, p02, q02, p10, q10, p11, q11, p12, q12 over Integer Ring + Multivariate Polynomial Ring + in p00, q00, p01, q01, p02, q02, p10, q10, p11, q11, p12, q12 + over Integer Ring sage: PolynomialRing(ZZ, 2, 3, 4, var_array='m') - Multivariate Polynomial Ring in m000, m001, m002, m003, m010, m011, m012, m013, m020, m021, m022, m023, m100, m101, m102, m103, m110, m111, m112, m113, m120, m121, m122, m123 over Integer Ring + Multivariate Polynomial Ring in m000, m001, m002, m003, m010, m011, + m012, m013, m020, m021, m022, m023, m100, m101, m102, m103, m110, + m111, m112, m113, m120, m121, m122, m123 over Integer Ring The array is always at least 2-dimensional. So, if ``var_array`` is a single string and only a single number `n` @@ -418,9 +426,9 @@ def PolynomialRing(base_ring, *args, **kwds): The generic implementation is different in some cases:: - sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) + sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) # optional - sage.rings.finite_rings - sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) + sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) # optional - sage.rings.finite_rings sage: R = PolynomialRing(ZZ, 'x,y', implementation="generic"); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R) @@ -433,7 +441,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R = PolynomialRing(ZZ, 'j', sparse=True); TestSuite(R).run(); type(R) - sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) + sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) # optional - sage.rings.finite_rings If the requested implementation is not known or not supported for @@ -443,7 +451,7 @@ def PolynomialRing(base_ring, *args, **kwds): Traceback (most recent call last): ... ValueError: unknown implementation 'Foo' for dense polynomial rings over Integer Ring - sage: R. = PolynomialRing(GF(2), implementation='GF2X', sparse=True) + sage: R. = PolynomialRing(GF(2), implementation='GF2X', sparse=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: unknown implementation 'GF2X' for sparse polynomial rings over Finite Field of size 2 @@ -555,7 +563,7 @@ def PolynomialRing(base_ring, *args, **kwds): We run the testsuite for various polynomial rings, skipping tests that currently fail:: - sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R + sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R # optional - sage.rings.finite_rings Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL Univariate Polynomial Ring in x over Integer Ring (using NTL) @@ -577,9 +585,9 @@ def PolynomialRing(base_ring, *args, **kwds): Multivariate Polynomial Ring in x over Rational Field sage: Q0 = PolynomialRing(QQ,"x",0); TestSuite(Q0).run(skip=['_test_elements', '_test_elements_eq_transitive', '_test_gcd_vs_xgcd', '_test_quo_rem']); Q0 Multivariate Polynomial Ring in no variables over Rational Field - sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) + sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) # optional - sage.rings.finite_rings - sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) + sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) # optional - sage.rings.finite_rings sage: R = PolynomialRing(ZZ, 'x,y', implementation="generic"); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R) @@ -587,7 +595,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R = PolynomialRing(ZZ, 'j', sparse=True); TestSuite(R).run(); type(R) - sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) + sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) # optional - sage.rings.finite_rings sage: P. = PolynomialRing(RealIntervalField(2)) sage: TestSuite(P).run(skip=['_test_elements', '_test_elements_eq_transitive']) @@ -934,43 +942,43 @@ def BooleanPolynomialRing_constructor(n=None, names=None, order="lex"): EXAMPLES:: - sage: R. = BooleanPolynomialRing() # indirect doctest - sage: R + sage: R. = BooleanPolynomialRing() # indirect doctest # optional - sage.rings.polynomial.pbori + sage: R # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y, z - sage: p = x*y + x*z + y*z - sage: x*p + sage: p = x*y + x*z + y*z # optional - sage.rings.polynomial.pbori + sage: x*p # optional - sage.rings.polynomial.pbori x*y*z + x*y + x*z - sage: R.term_order() + sage: R.term_order() # optional - sage.rings.polynomial.pbori Lexicographic term order - sage: R = BooleanPolynomialRing(5,'x',order='deglex(3),deglex(2)') - sage: R.term_order() + sage: R = BooleanPolynomialRing(5, 'x', order='deglex(3),deglex(2)') # optional - sage.rings.polynomial.pbori + sage: R.term_order() # optional - sage.rings.polynomial.pbori Block term order with blocks: (Degree lexicographic term order of length 3, Degree lexicographic term order of length 2) - sage: R = BooleanPolynomialRing(3,'x',order='degneglex') - sage: R.term_order() + sage: R = BooleanPolynomialRing(3, 'x', order='degneglex') # optional - sage.rings.polynomial.pbori + sage: R.term_order() # optional - sage.rings.polynomial.pbori Degree negative lexicographic term order - sage: BooleanPolynomialRing(names=('x','y')) + sage: BooleanPolynomialRing(names=('x','y')) # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y - sage: BooleanPolynomialRing(names='x,y') + sage: BooleanPolynomialRing(names='x,y') # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y TESTS:: - sage: P. = BooleanPolynomialRing(2,order='deglex') - sage: x > y + sage: P. = BooleanPolynomialRing(2, order='deglex') # optional - sage.rings.polynomial.pbori + sage: x > y # optional - sage.rings.polynomial.pbori True - sage: P. = BooleanPolynomialRing(4,order='deglex(2),deglex(2)') - sage: x0 > x1 + sage: P. = BooleanPolynomialRing(4, order='deglex(2),deglex(2)') # optional - sage.rings.polynomial.pbori + sage: x0 > x1 # optional - sage.rings.polynomial.pbori True - sage: x2 > x3 + sage: x2 > x3 # optional - sage.rings.polynomial.pbori True """ if isinstance(n, str): diff --git a/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx b/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx index 18140a24981..4b55fa8c778 100644 --- a/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx +++ b/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx @@ -73,18 +73,18 @@ cdef class PolynomialRingHomomorphism_from_base(RingHomomorphism_from_base): sage: from sage.rings.polynomial.polynomial_ring_homomorphism import PolynomialRingHomomorphism_from_base sage: R. = ZZ[] - sage: S = GF(5)['x'] - sage: f = ZZ.hom(GF(5)) - sage: F = PolynomialRingHomomorphism_from_base(R.Hom(S), f) - sage: F(2*x, check=True) + sage: S = GF(5)['x'] # optional - sage.rings.finite_rings + sage: f = ZZ.hom(GF(5)) # optional - sage.rings.finite_rings + sage: F = PolynomialRingHomomorphism_from_base(R.Hom(S), f) # optional - sage.rings.finite_rings + sage: F(2 * x, check=True) # optional - sage.rings.finite_rings 2*x - sage: k = GF(49, 'z') - sage: A = PolynomialRing(GF(7), 'x', sparse=True) - sage: B = PolynomialRing(k, 'x', sparse=True) - sage: g = GF(7).hom(k) - sage: G = PolynomialRingHomomorphism_from_base(A.Hom(B), g) - sage: G(A.gen()^1000000, True, construct=False) + sage: k = GF(49, 'z') # optional - sage.rings.finite_rings + sage: A = PolynomialRing(GF(7), 'x', sparse=True) # optional - sage.rings.finite_rings + sage: B = PolynomialRing(k, 'x', sparse=True) # optional - sage.rings.finite_rings + sage: g = GF(7).hom(k) # optional - sage.rings.finite_rings + sage: G = PolynomialRingHomomorphism_from_base(A.Hom(B), g) # optional - sage.rings.finite_rings + sage: G(A.gen()^1000000, True, construct=False) # optional - sage.rings.finite_rings x^1000000 """ diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 254d908a592..0f2f7d619fd 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -10,11 +10,11 @@ TESTS:: - sage: R = PolynomialRing(GF(2**8,'a'),10,'x', order='invlex') - sage: R == loads(dumps(R)) + sage: R = PolynomialRing(GF(2**8,'a'), 10, 'x', order='invlex') # optional - sage.rings.finite_rings + sage: R == loads(dumps(R)) # optional - sage.rings.finite_rings True - sage: P. = PolynomialRing(GF(7), 2) - sage: f = (a^3 + 2*b^2*a)^7; f + sage: P. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: f = (a^3 + 2*b^2*a)^7; f # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 """ @@ -61,7 +61,7 @@ def _do_singular_init_(singular, base_ring, char, _vars, order): TESTS:: sage: from sage.rings.polynomial.polynomial_singular_interface import _do_singular_init_ - sage: _do_singular_init_(singular, ZZ, 0, 'X', 'dp') + sage: _do_singular_init_(singular, ZZ, 0, 'X', 'dp') # optional - sage.libs.singular (polynomial ring, over a domain, global ordering // coefficients: ZZ // number of vars : 1 @@ -214,8 +214,8 @@ def _singular_(self, singular=singular): sage: w = var('w') - sage: R. = PolynomialRing(NumberField(w^2+1,'s')) - sage: singular(R) + sage: R. = PolynomialRing(NumberField(w^2 + 1, 's')) # optional - sage.rings.number_field + sage: singular(R) # optional - sage.rings.number_field polynomial ring, over a field, global ordering // coefficients: QQ[s]/(s^2+1) // number of vars : 1 @@ -223,8 +223,8 @@ def _singular_(self, singular=singular): // : names x // block 2 : ordering C - sage: R = PolynomialRing(GF(127), 'x', implementation="singular") - sage: singular(R) + sage: R = PolynomialRing(GF(127), 'x', implementation="singular") # optional - sage.rings.finite_rings + sage: singular(R) # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 1 @@ -250,8 +250,8 @@ def _singular_(self, singular=singular): // : names x // block 2 : ordering C - sage: R = PolynomialRing(GF(127),'x') - sage: singular(R) + sage: R = PolynomialRing(GF(127), 'x') # optional - sage.rings.finite_rings + sage: singular(R) # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 1 @@ -305,11 +305,11 @@ def _singular_(self, singular=singular): // : names x // block 2 : ordering C - sage: k. = FiniteField(25) - sage: R = k['x'] - sage: K = R.fraction_field() - sage: S = K['y'] - sage: singular(S) + sage: k. = FiniteField(25) # optional - sage.rings.finite_rings + sage: R = k['x'] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: S = K['y'] # optional - sage.rings.finite_rings + sage: singular(S) # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/5(x) // number of vars : 2 @@ -350,7 +350,7 @@ def _singular_init_(self, singular=singular): EXAMPLES:: - sage: PolynomialRing(QQ,'u_ba')._singular_init_() + sage: PolynomialRing(QQ,'u_ba')._singular_init_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 @@ -399,23 +399,23 @@ def can_convert_to_singular(R): Avoid non absolute number fields (see :trac:`23535`):: - sage: K. = NumberField([x^2-2,x^2-5]) - sage: can_convert_to_singular(K['s,t']) + sage: K. = NumberField([x^2 - 2, x^2 - 5]) # optional - sage.rings.number_field + sage: can_convert_to_singular(K['s,t']) # optional - sage.rings.number_field False Check for :trac:`33319`:: - sage: R. = GF((2^31-1)^3)[] - sage: R._has_singular + sage: R. = GF((2^31-1)^3)[] # optional - sage.rings.finite_rings + sage: R._has_singular # optional - sage.rings.finite_rings True - sage: R. = GF((2^31+11)^2)[] - sage: R._has_singular + sage: R. = GF((2^31+11)^2)[] # optional - sage.rings.finite_rings + sage: R._has_singular # optional - sage.rings.finite_rings False - sage: R. = GF(10^20-11)[] - sage: R._has_singular + sage: R. = GF(10^20 - 11)[] # optional - sage.rings.finite_rings + sage: R._has_singular # optional - sage.rings.finite_rings True - sage: R. = Zmod(10^20+1)[] - sage: R._has_singular + sage: R. = Zmod(10^20 + 1)[] # optional - sage.libs.pari + sage: R._has_singular # optional - sage.libs.pari True """ if R.ngens() == 0: @@ -470,25 +470,25 @@ def _singular_func(self, singular=singular): EXAMPLES:: - sage: P. = PolynomialRing(GF(7), 2) - sage: f = (a^3 + 2*b^2*a)^7; f + sage: P. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: f = (a^3 + 2*b^2*a)^7; f # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 - sage: h = f._singular_(); h + sage: h = f._singular_(); h # optional - sage.rings.finite_rings a^21+2*a^7*b^14 - sage: P(h) + sage: P(h) # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 - sage: P(h^20) == f^20 + sage: P(h^20) == f^20 # optional - sage.rings.finite_rings True - sage: R. = PolynomialRing(GF(7)) - sage: f = (x^3 + 2*x^2*x)^7 - sage: f + sage: R. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*x^2*x)^7 # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings 3*x^21 - sage: h = f._singular_(); h + sage: h = f._singular_(); h # optional - sage.rings.finite_rings 3*x^21 - sage: R(h) + sage: R(h) # optional - sage.rings.finite_rings 3*x^21 - sage: R(h^20) == f^20 + sage: R(h^20) == f^20 # optional - sage.rings.finite_rings True """ self.parent()._singular_(singular).set_ring() # this is expensive diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx index f3ff0617484..7acfec8c97f 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Univariate dense skew polynomials over a field with a finite order automorphism diff --git a/src/sage/rings/polynomial/skew_polynomial_ring.py b/src/sage/rings/polynomial/skew_polynomial_ring.py index a71a217719b..9f499430d59 100644 --- a/src/sage/rings/polynomial/skew_polynomial_ring.py +++ b/src/sage/rings/polynomial/skew_polynomial_ring.py @@ -78,7 +78,7 @@ def _base_ring_to_fraction_field(S): sage: from sage.rings.polynomial.skew_polynomial_ring import _base_ring_to_fraction_field sage: R. = ZZ[] - sage: sigma = R.hom([t+1]) + sage: sigma = R.hom([t + 1]) sage: S. = R['x', sigma] sage: _base_ring_to_fraction_field(S) Ore Polynomial Ring in x over Fraction Field of Univariate Polynomial Ring in t over Integer Ring twisted by t |--> t + 1 @@ -117,11 +117,11 @@ def _minimal_vanishing_polynomial(R, eval_pts): EXAMPLES:: sage: from sage.rings.polynomial.skew_polynomial_ring import _minimal_vanishing_polynomial - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: eval_pts = [1, t, t^2] - sage: b = _minimal_vanishing_polynomial(S, eval_pts); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: eval_pts = [1, t, t^2] # optional - sage.rings.finite_rings + sage: b = _minimal_vanishing_polynomial(S, eval_pts); b # optional - sage.rings.finite_rings doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See https://github.com/sagemath/sage/issues/13215 for details. @@ -172,23 +172,23 @@ def _lagrange_polynomial(R, eval_pts, values): EXAMPLES:: sage: from sage.rings.polynomial.skew_polynomial_ring import _lagrange_polynomial - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: eval_pts = [ t , t^2 ] - sage: values = [ 3*t^2 + 4*t + 4 , 4*t ] - sage: d = _lagrange_polynomial(S, eval_pts, values); d + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings + sage: eval_pts = [t , t^2] # optional - sage.rings.finite_rings + sage: values = [3*t^2 + 4*t + 4, 4*t] # optional - sage.rings.finite_rings + sage: d = _lagrange_polynomial(S, eval_pts, values); d # optional - sage.rings.finite_rings x + t - sage: d.multi_point_evaluation(eval_pts) == values + sage: d.multi_point_evaluation(eval_pts) == values # optional - sage.rings.finite_rings True The following restrictions are impossible to satisfy because the evaluation points are linearly dependent over the fixed field of the twisting morphism, and the corresponding values do not match:: - sage: eval_pts = [ t, 2*t ] - sage: values = [ 1, 3 ] - sage: _lagrange_polynomial(S, eval_pts, values) + sage: eval_pts = [t, 2*t] # optional - sage.rings.finite_rings + sage: values = [1, 3] # optional - sage.rings.finite_rings + sage: _lagrange_polynomial(S, eval_pts, values) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the given evaluation points are linearly dependent over the fixed field of the twisting morphism, @@ -240,7 +240,7 @@ def __init__(self, base_ring, morphism, derivation, name, sparse, category=None) EXAMPLES:: sage: R. = ZZ[] - sage: sigma = R.hom([t+1]) + sage: sigma = R.hom([t + 1]) sage: S. = SkewPolynomialRing(R,sigma) sage: S.category() Category of algebras over Univariate Polynomial Ring in t over Integer Ring @@ -275,26 +275,26 @@ def minimal_vanishing_polynomial(self, eval_pts): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: eval_pts = [1, t, t^2] - sage: b = S.minimal_vanishing_polynomial(eval_pts); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings + sage: eval_pts = [1, t, t^2] # optional - sage.rings.finite_rings + sage: b = S.minimal_vanishing_polynomial(eval_pts); b # optional - sage.rings.finite_rings x^3 + 4 The minimal vanishing polynomial evaluates to 0 at each of the evaluation points:: - sage: eval = b.multi_point_evaluation(eval_pts); eval + sage: eval = b.multi_point_evaluation(eval_pts); eval # optional - sage.rings.finite_rings [0, 0, 0] If the evaluation points are linearly dependent over the fixed field of the twisting morphism, then the returned polynomial has lower degree than the number of evaluation points:: - sage: S.minimal_vanishing_polynomial([t]) + sage: S.minimal_vanishing_polynomial([t]) # optional - sage.rings.finite_rings x + 3*t^2 + 3*t - sage: S.minimal_vanishing_polynomial([t, 3*t]) + sage: S.minimal_vanishing_polynomial([t, 3*t]) # optional - sage.rings.finite_rings x + 3*t^2 + 3*t """ return _minimal_vanishing_polynomial(_base_ring_to_fraction_field(self), eval_pts) @@ -328,26 +328,27 @@ def lagrange_polynomial(self, points): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: points = [(t, 3*t^2 + 4*t + 4), (t^2, 4*t)] - sage: d = S.lagrange_polynomial(points); d + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings + sage: points = [(t, 3*t^2 + 4*t + 4), (t^2, 4*t)] # optional - sage.rings.finite_rings + sage: d = S.lagrange_polynomial(points); d # optional - sage.rings.finite_rings x + t sage: R. = ZZ[] - sage: sigma = R.hom([t+1]) + sage: sigma = R.hom([t + 1]) sage: T. = R['x', sigma] - sage: points = [ (1, t^2 + 3*t + 4), (t, 2*t^2 + 3*t + 1), (t^2, t^2 + 3*t + 4) ] + sage: points = [(1, t^2 + 3*t + 4), (t, 2*t^2 + 3*t + 1), (t^2, t^2 + 3*t + 4)] sage: p = T.lagrange_polynomial(points); p - ((-t^4 - 2*t - 3)/-2)*x^2 + (-t^4 - t^3 - t^2 - 3*t - 2)*x + (-t^4 - 2*t^3 - 4*t^2 - 10*t - 9)/-2 - sage: p.multi_point_evaluation([1, t, t^2]) == [ t^2 + 3*t + 4, 2*t^2 + 3*t + 1, t^2 + 3*t + 4 ] + ((-t^4 - 2*t - 3)/-2)*x^2 + (-t^4 - t^3 - t^2 - 3*t - 2)*x + + (-t^4 - 2*t^3 - 4*t^2 - 10*t - 9)/-2 + sage: p.multi_point_evaluation([1, t, t^2]) == [t^2 + 3*t + 4, 2*t^2 + 3*t + 1, t^2 + 3*t + 4] True If the `x_i` are linearly dependent over the fixed field of ``self.twisting_morphism()``, then an error is raised:: - sage: T.lagrange_polynomial([ (t, 1), (2*t, 3) ]) + sage: T.lagrange_polynomial([(t, 1), (2*t, 3)]) Traceback (most recent call last): ... ValueError: the given evaluation points are linearly dependent over the fixed field of the twisting morphism, @@ -378,12 +379,12 @@ class SectionSkewPolynomialCenterInjection(Section): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() - sage: TestSuite(sigma).run(skip=['_test_category']) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings + sage: TestSuite(sigma).run(skip=['_test_category']) # optional - sage.rings.finite_rings """ def _call_(self, x): r""" @@ -391,14 +392,14 @@ def _call_(self, x): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() - sage: sigma(x^3) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings + sage: sigma(x^3) # optional - sage.rings.finite_rings z - sage: sigma(x^2) + sage: sigma(x^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: x^2 is not in the center @@ -425,18 +426,18 @@ def _richcmp_(self, right, op): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings - sage: s = loads(dumps(sigma)) - sage: s == sigma + sage: s = loads(dumps(sigma)) # optional - sage.rings.finite_rings + sage: s == sigma # optional - sage.rings.finite_rings True - sage: s != sigma + sage: s != sigma # optional - sage.rings.finite_rings False - sage: s is sigma + sage: s is sigma # optional - sage.rings.finite_rings False """ if op == op_EQ: @@ -453,11 +454,11 @@ class SkewPolynomialCenterInjection(RingHomomorphism): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: TestSuite(iota).run(skip=['_test_category']) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: TestSuite(iota).run(skip=['_test_category']) # optional - sage.rings.finite_rings """ def __init__(self, domain, codomain, embed, order): r""" @@ -465,10 +466,10 @@ def __init__(self, domain, codomain, embed, order): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: S.convert_map_from(Z) # indirect doctest + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: S.convert_map_from(Z) # indirect doctest # optional - sage.rings.finite_rings Embedding of the center of Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 into this ring """ RingHomomorphism.__init__(self, Hom(domain, codomain)) @@ -483,13 +484,13 @@ def _repr_(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: iota + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: iota # optional - sage.rings.finite_rings Embedding of the center of Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 into this ring - sage: iota._repr_() + sage: iota._repr_() # optional - sage.rings.finite_rings 'Embedding of the center of Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 into this ring' """ return "Embedding of the center of %s into this ring" % self._codomain @@ -500,12 +501,12 @@ def _call_(self, x): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z. = S.center() - sage: iota = S.convert_map_from(Z) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z. = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings - sage: iota(z) + sage: iota(z) # optional - sage.rings.finite_rings x^3 """ k = self._codomain.base_ring() @@ -521,17 +522,17 @@ def _richcmp_(self, right, op): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings - sage: i = loads(dumps(iota)) - sage: i == iota + sage: i = loads(dumps(iota)) # optional - sage.rings.finite_rings + sage: i == iota # optional - sage.rings.finite_rings True - sage: i != iota + sage: i != iota # optional - sage.rings.finite_rings False - sage: i is iota + sage: i is iota # optional - sage.rings.finite_rings False """ if op == op_EQ: @@ -546,12 +547,12 @@ def section(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() - sage: sigma(x^3) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings + sage: sigma(x^3) # optional - sage.rings.finite_rings z """ return self._section @@ -573,26 +574,26 @@ def __init__(self, base_ring, morphism, derivation, name, sparse, category=None) TESTS:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob]; S + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob]; S # optional - sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 - sage: S.category() + sage: S.category() # optional - sage.rings.finite_rings Category of algebras over Finite Field in t of size 5^3 - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.rings.finite_rings We check that a call to the method :meth:`sage.rings.polynomial.skew_polynomial_finite_order.SkewPolynomial_finite_order.is_central` does not affect the behaviour of default central variable names:: - sage: k. = GF(7^4) - sage: phi = k.frobenius_endomorphism() - sage: S. = k['x', phi] - sage: (x^4).is_central() + sage: k. = GF(7^4) # optional - sage.rings.finite_rings + sage: phi = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', phi] # optional - sage.rings.finite_rings + sage: (x^4).is_central() # optional - sage.rings.finite_rings True - sage: Z. = S.center() - sage: S.center() is Z + sage: Z. = S.center() # optional - sage.rings.finite_rings + sage: S.center() is Z # optional - sage.rings.finite_rings True """ if self.Element is None: @@ -638,55 +639,57 @@ def center(self, name=None, names=None, default=False): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob]; S - Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob]; S # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over Finite Field in t of size 5^3 + twisted by t |--> t^5 - sage: Z = S.center(); Z + sage: Z = S.center(); Z # optional - sage.rings.finite_rings Univariate Polynomial Ring in z over Finite Field of size 5 - sage: Z.gen() + sage: Z.gen() # optional - sage.rings.finite_rings z We can pass in another variable name:: - sage: S.center(name='y') + sage: S.center(name='y') # optional - sage.rings.finite_rings Univariate Polynomial Ring in y over Finite Field of size 5 or use the bracket notation:: - sage: Zy. = S.center(); Zy + sage: Zy. = S.center(); Zy # optional - sage.rings.finite_rings Univariate Polynomial Ring in y over Finite Field of size 5 - sage: y.parent() is Zy + sage: y.parent() is Zy # optional - sage.rings.finite_rings True A coercion map from the center to the skew polynomial ring is set:: - sage: S.has_coerce_map_from(Zy) + sage: S.has_coerce_map_from(Zy) # optional - sage.rings.finite_rings True - sage: P = y + x; P + sage: P = y + x; P # optional - sage.rings.finite_rings x^3 + x - sage: P.parent() - Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 - sage: P.parent() is S + sage: P.parent() # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over Finite Field in t of size 5^3 + twisted by t |--> t^5 + sage: P.parent() is S # optional - sage.rings.finite_rings True together with a conversion map in the reverse direction:: - sage: Zy(x^6 + 2*x^3 + 3) + sage: Zy(x^6 + 2*x^3 + 3) # optional - sage.rings.finite_rings y^2 + 2*y + 3 - sage: Zy(x^2) + sage: Zy(x^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: x^2 is not in the center Two different skew polynomial rings can share the same center:: - sage: S1. = k['x1', Frob] - sage: S2. = k['x2', Frob] - sage: S1.center() is S2.center() + sage: S1. = k['x1', Frob] # optional - sage.rings.finite_rings + sage: S2. = k['x2', Frob] # optional - sage.rings.finite_rings + sage: S1.center() is S2.center() # optional - sage.rings.finite_rings True .. RUBRIC:: About the default name of the central variable @@ -696,32 +699,32 @@ def center(self, name=None, names=None, default=False): However, a variable name is given the first time this method is called, the given name become the default for the next calls:: - sage: K. = GF(11^3) - sage: phi = K.frobenius_endomorphism() - sage: A. = K['X', phi] + sage: K. = GF(11^3) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: A. = K['X', phi] # optional - sage.rings.finite_rings - sage: C. = A.center() # first call - sage: C + sage: C. = A.center() # first call # optional - sage.rings.finite_rings + sage: C # optional - sage.rings.finite_rings Univariate Polynomial Ring in u over Finite Field of size 11 - sage: A.center() # second call: the variable name is still u + sage: A.center() # second call: the variable name is still u # optional - sage.rings.finite_rings Univariate Polynomial Ring in u over Finite Field of size 11 - sage: A.center() is C + sage: A.center() is C # optional - sage.rings.finite_rings True We can update the default variable name by passing in the argument ``default=True``:: - sage: D. = A.center(default=True) - sage: D + sage: D. = A.center(default=True) # optional - sage.rings.finite_rings + sage: D # optional - sage.rings.finite_rings Univariate Polynomial Ring in v over Finite Field of size 11 - sage: A.center() + sage: A.center() # optional - sage.rings.finite_rings Univariate Polynomial Ring in v over Finite Field of size 11 - sage: A.center() is D + sage: A.center() is D # optional - sage.rings.finite_rings True TESTS:: - sage: C. = S.center() + sage: C. = S.center() # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: the number of names must equal the number of generators @@ -793,9 +796,9 @@ def __init__(self, base_ring, morphism, derivation, names, sparse, category=None EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: T. = k['x', Frob]; T + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: T. = k['x', Frob]; T # optional - sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 """ if self.Element is None: @@ -820,21 +823,21 @@ def _new_retraction_map(self, seed=None): TESTS:: - sage: k. = GF(11^4) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob] + sage: k. = GF(11^4) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: S._new_retraction_map() - sage: S._matrix_retraction # random + sage: S._new_retraction_map() # optional - sage.rings.finite_rings + sage: S._matrix_retraction # random # optional - sage.rings.finite_rings [ 9 4 10 4] We can specify a seed:: - sage: S._new_retraction_map(seed=a) - sage: S._matrix_retraction + sage: S._new_retraction_map(seed=a) # optional - sage.rings.finite_rings + sage: S._matrix_retraction # optional - sage.rings.finite_rings [ 0 6 3 10] - sage: S._new_retraction_map(seed=a) - sage: S._matrix_retraction + sage: S._new_retraction_map(seed=a) # optional - sage.rings.finite_rings + sage: S._matrix_retraction # optional - sage.rings.finite_rings [ 0 6 3 10] """ k = self.base_ring() @@ -872,27 +875,27 @@ def _retraction(self, x, newmap=False, seed=None): TESTS:: - sage: k. = GF(11^4) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob] + sage: k. = GF(11^4) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: S._retraction(a) # random + sage: S._retraction(a) # random # optional - sage.rings.finite_rings 6 Note that a retraction map has been automatically created:: - sage: S._matrix_retraction # random + sage: S._matrix_retraction # random # optional - sage.rings.finite_rings [ 0 6 3 10] If we call again the method :meth:`_retraction`, the same retraction map is used:: - sage: S._retraction(a) # random + sage: S._retraction(a) # random # optional - sage.rings.finite_rings 6 We can specify a seed:: - sage: S._retraction(a^2, seed=a) # random + sage: S._retraction(a^2, seed=a) # random # optional - sage.rings.finite_rings 10 """ # Better to return the retraction map but more difficult diff --git a/src/sage/rings/polynomial/symmetric_ideal.py b/src/sage/rings/polynomial/symmetric_ideal.py index dfe66e9f2f5..2ff0381ad60 100644 --- a/src/sage/rings/polynomial/symmetric_ideal.py +++ b/src/sage/rings/polynomial/symmetric_ideal.py @@ -23,12 +23,13 @@ Note that ``I`` is not a symmetric Groebner basis:: - sage: G = R*I.groebner_basis() - sage: G - Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of Infinite polynomial ring in x over Rational Field - sage: Q = R.quotient(G) - sage: p = x[3]*x[1]+x[2]^2+3 - sage: Q(p) + sage: G = R * I.groebner_basis() # optional - sage.combinat + sage: G # optional - sage.combinat + Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of + Infinite polynomial ring in x over Rational Field + sage: Q = R.quotient(G) # optional - sage.combinat + sage: p = x[3]*x[1] + x[2]^2 + 3 # optional - sage.combinat + sage: Q(p) # optional - sage.combinat -2*x_1 + 3 By the second generator of ``G``, variable `x_n` is equal to `x_1` for @@ -36,7 +37,7 @@ equal to `x_1` in ``Q``. Indeed, we have :: - sage: Q(p)*x[2] == Q(p)*x[1]*x[3]*x[5] + sage: Q(p)*x[2] == Q(p)*x[1]*x[3]*x[5] # optional - sage.combinat True """ @@ -109,7 +110,7 @@ class SymmetricIdeal(Ideal_generic): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = [x[1]*y[2]*y[1] + 2*x[1]*y[2]]*X + sage: I = [x[1]*y[2]*y[1] + 2*x[1]*y[2]] * X sage: I == loads(dumps(I)) True sage: latex(I) @@ -117,25 +118,26 @@ class SymmetricIdeal(Ideal_generic): The default ordering is lexicographic. We now compute a Groebner basis:: - sage: J = I.groebner_basis() ; J # about 3 seconds - [x_1*y_2*y_1 + 2*x_1*y_2, x_2*y_2*y_1 + 2*x_2*y_1, x_2*x_1*y_1^2 + 2*x_2*x_1*y_1, x_2*x_1*y_2 - x_2*x_1*y_1] + sage: J = I.groebner_basis(); J # about 3 seconds # optional - sage.combinat + [x_1*y_2*y_1 + 2*x_1*y_2, x_2*y_2*y_1 + 2*x_2*y_1, + x_2*x_1*y_1^2 + 2*x_2*x_1*y_1, x_2*x_1*y_2 - x_2*x_1*y_1] Note that even though the symmetric ideal can be generated by a single polynomial, its reduced symmetric Groebner basis comprises four elements. Ideal membership in ``I`` can now be tested by commuting symmetric reduction modulo ``J``:: - sage: I.reduce(J) + sage: I.reduce(J) # optional - sage.combinat Symmetric Ideal (0) of Infinite polynomial ring in x, y over Rational Field The Groebner basis is not point-wise invariant under permutation:: - sage: P=Permutation([2, 1]) - sage: J[2] + sage: P = Permutation([2, 1]) # optional - sage.combinat + sage: J[2] # optional - sage.combinat x_2*x_1*y_1^2 + 2*x_2*x_1*y_1 - sage: J[2]^P + sage: J[2]^P # optional - sage.combinat x_2*x_1*y_2^2 + 2*x_2*x_1*y_2 - sage: J[2]^P in J + sage: J[2]^P in J # optional - sage.combinat False However, any element of ``J`` has symmetric reduction zero even @@ -143,13 +145,13 @@ class SymmetricIdeal(Ideal_generic): permutations involve higher variable indices than the ones occurring in ``J``:: - sage: [[(p^P).reduce(J) for p in J] for P in Permutations(3)] + sage: [[(p^P).reduce(J) for p in J] for P in Permutations(3)] # optional - sage.combinat [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] Since ``I`` is not a Groebner basis, it is no surprise that it cannot detect ideal membership:: - sage: [p.reduce(I) for p in J] + sage: [p.reduce(I) for p in J] # optional - sage.combinat [0, x_2*y_2*y_1 + 2*x_2*y_1, x_2*x_1*y_1^2 + 2*x_2*x_1*y_1, x_2*x_1*y_2 - x_2*x_1*y_1] Note that we give no guarantee that the computation of a symmetric @@ -161,12 +163,14 @@ class SymmetricIdeal(Ideal_generic): product is indeed the product of ideals in the mathematical sense. :: - sage: I=X*(x[1]) - sage: I*I - Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I^3 - Symmetric Ideal (x_1^3, x_2*x_1^2, x_2^2*x_1, x_3*x_2*x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I*I == X*(x[1]^2) + sage: I = X * (x[1]) + sage: I * I # optional - sage.combinat + Symmetric Ideal (x_1^2, x_2*x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I^3 # optional - sage.combinat + Symmetric Ideal (x_1^3, x_2*x_1^2, x_2^2*x_1, x_3*x_2*x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I * I == X * (x[1]^2) # optional - sage.combinat False """ @@ -182,12 +186,12 @@ def __init__(self, ring, gens, coerce=True): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]^2+y[2]^2,x[1]*x[2]*y[3]+x[1]*y[4]) # indirect doctest + sage: I = X * (x[1]^2 + y[2]^2, x[1]*x[2]*y[3] + x[1]*y[4]) # indirect doctest sage: I Symmetric Ideal (x_1^2 + y_2^2, x_2*x_1*y_3 + x_1*y_4) of Infinite polynomial ring in x, y over Rational Field sage: from sage.rings.polynomial.symmetric_ideal import SymmetricIdeal - sage: J=SymmetricIdeal(X,[x[1]^2+y[2]^2,x[1]*x[2]*y[3]+x[1]*y[4]]) - sage: I==J + sage: J = SymmetricIdeal(X, [x[1]^2 + y[2]^2, x[1]*x[2]*y[3] + x[1]*y[4]]) + sage: I == J True """ @@ -198,7 +202,7 @@ def __repr__(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]^2+y[2]^2,x[1]*x[2]*y[3]+x[1]*y[4]) + sage: I = X * (x[1]^2 + y[2]^2, x[1]*x[2]*y[3] + x[1]*y[4]) sage: I # indirect doctest Symmetric Ideal (x_1^2 + y_2^2, x_2*x_1*y_3 + x_1*y_4) of Infinite polynomial ring in x, y over Rational Field @@ -211,7 +215,7 @@ def _latex_(self): sage: from sage.misc.latex import latex sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]*y[2]) + sage: I = X * (x[1]*y[2]) sage: latex(I) # indirect doctest \left(x_{1} y_{2}\right)\Bold{Q}[x_{\ast}, y_{\ast}][\mathfrak{S}_{\infty}] @@ -231,10 +235,11 @@ def _contains_(self, p): sage: R. = InfinitePolynomialRing(QQ) sage: I = R.ideal([x[1]*x[2] + x[3]]) - sage: I = R*I.groebner_basis() - sage: I - Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of Infinite polynomial ring in x over Rational Field - sage: x[2]^2 + x[3] in I # indirect doctest + sage: I = R * I.groebner_basis() # optional - sage.combinat + sage: I # optional - sage.combinat + Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of + Infinite polynomial ring in x over Rational Field + sage: x[2]^2 + x[3] in I # indirect doctest # optional - sage.combinat True """ try: @@ -254,8 +259,8 @@ def __mul__(self, other): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]) - sage: I*I # indirect doctest + sage: I = X * (x[1]) + sage: I*I # indirect doctest # optional - sage.combinat Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x over Rational Field """ @@ -294,8 +299,8 @@ def __pow__(self, n): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]) - sage: I^2 # indirect doctest + sage: I = X * (x[1]) + sage: I^2 # indirect doctest # optional - sage.combinat Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x over Rational Field """ @@ -323,21 +328,23 @@ def is_maximal(self): EXAMPLES:: sage: R. = InfinitePolynomialRing(QQ) - sage: I = R.ideal([x[1]+y[2], x[2]-y[1]]) - sage: I = R*I.groebner_basis() - sage: I - Symmetric Ideal (y_1, x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I = R.ideal([x[1]+y[2], x[2]-y[1]]) - sage: I.is_maximal() + sage: I = R.ideal([x[1] + y[2], x[2] - y[1]]) + sage: I = R * I.groebner_basis() # optional - sage.combinat + sage: I # optional - sage.combinat + Symmetric Ideal (y_1, x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I = R.ideal([x[1] + y[2], x[2] - y[1]]) # optional - sage.combinat + sage: I.is_maximal() # optional - sage.combinat False The preceding answer is wrong, since it is not the case that ``I`` is given by a symmetric Groebner basis:: - sage: I = R*I.groebner_basis() - sage: I - Symmetric Ideal (y_1, x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I.is_maximal() + sage: I = R * I.groebner_basis() # optional - sage.combinat + sage: I # optional - sage.combinat + Symmetric Ideal (y_1, x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I.is_maximal() # optional - sage.combinat True """ @@ -353,7 +360,7 @@ def is_maximal(self): def reduce(self, I, tailreduce=False): r""" - Symmetric reduction of self by another Symmetric Ideal or list of Infinite Polynomials, + Symmetric reduction of ``self`` by another Symmetric Ideal or list of Infinite Polynomials, or symmetric reduction of a given Infinite Polynomial by self. INPUT: @@ -382,9 +389,10 @@ def reduce(self, I, tailreduce=False): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(y[1]^2*y[3]+y[1]*x[3]^2) + sage: I = X * (y[1]^2*y[3] + y[1]*x[3]^2) sage: I.reduce([x[1]^2*y[2]]) - Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field + Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field The preceding is correct, since any permutation that turns ``x[1]^2*y[2]`` into a factor of ``x[3]^2*y[2]`` interchanges @@ -392,18 +400,21 @@ def reduce(self, I, tailreduce=False): reduction by ``x[2]^2*y[1]`` works, since one can change variable index 1 into 2 and 2 into 3:: - sage: I.reduce([x[2]^2*y[1]]) - Symmetric Ideal (y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field + sage: I.reduce([x[2]^2*y[1]]) # optional - sage.combinat + Symmetric Ideal (y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field The next example shows that tail reduction is not done, unless it is explicitly advised. The input can also be a symmetric ideal:: - sage: J = (y[2])*X + sage: J = (y[2]) * X sage: I.reduce(J) - Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field - sage: I.reduce(J, tailreduce=True) - Symmetric Ideal (x_3^2*y_1) of Infinite polynomial ring in x, y over Rational Field + Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field + sage: I.reduce(J, tailreduce=True) # optional - sage.combinat + Symmetric Ideal (x_3^2*y_1) of + Infinite polynomial ring in x, y over Rational Field """ if I in self.ring(): # we want to reduce a polynomial by self @@ -419,14 +430,14 @@ def reduce(self, I, tailreduce=False): def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None): """ - Return symmetrically interreduced form of self + Return symmetrically interreduced form of ``self`` INPUT: - ``tailreduce`` -- (bool, default ``True``) If True, the interreduction is also performed on the non-leading monomials. - ``sorted`` -- (bool, default ``False``) If True, it is assumed that the - generators of self are already increasingly sorted. + generators of ``self`` are already increasingly sorted. - ``report`` -- (object, default ``None``) If not None, some information on the progress of computation is printed - ``RStrat`` -- (:class:`~sage.rings.polynomial.symmetric_reduction.SymmetricReductionStrategy`, @@ -445,20 +456,22 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]+x[2],x[1]*x[2]) + sage: I = X * (x[1] + x[2], x[1]*x[2]) sage: I.interreduction() - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field Here, we show the ``report`` option:: - sage: I.interreduction(report=True) + sage: I.interreduction(report=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> [1/2] > [2/2] T[1]> > - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field ``[m/n]`` indicates that polynomial number ``m`` is considered and the total number of polynomials under consideration is @@ -472,13 +485,14 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None sage: R = SymmetricReductionStrategy(X) sage: R Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational Field - sage: I.interreduction(RStrat=R) - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + sage: I.interreduction(RStrat=R) # optional - sage.combinat + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field sage: R Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational Field, modulo x_1^2, x_2 + x_1 - sage: R = SymmetricReductionStrategy(X,[x[1]^2]) + sage: R = SymmetricReductionStrategy(X, [x[1]^2]) sage: I.interreduction(RStrat=R) Symmetric Ideal (x_2 + x_1) of Infinite polynomial ring in x over Rational Field @@ -560,8 +574,8 @@ def interreduced_basis(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]+x[2],x[1]*x[2]) - sage: I.interreduced_basis() + sage: I = X * (x[1] + x[2], x[1]*x[2]) + sage: I.interreduced_basis() # optional - sage.combinat [-x_1^2, x_2 + x_1] """ @@ -569,7 +583,7 @@ def interreduced_basis(self): def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=False): """ - Apply permutations to the generators of self and interreduce + Apply permutations to the generators of ``self`` and interreduce INPUT: @@ -582,7 +596,7 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F - ``report`` -- (object, default ``None``) If not ``None``, report on the progress of computations. - ``use_full_group`` (optional) -- If True, apply *all* elements of - `Sym(N)` to the generators of self (this is what [AB2008]_ + `Sym(N)` to the generators of ``self`` (this is what [AB2008]_ originally suggests). The default is to apply all elementary transpositions to the generators of ``self.squeezed()``, interreduce, and repeat until the result stabilises, which is @@ -592,7 +606,7 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F OUTPUT: A symmetrically interreduced symmetric ideal with respect to - which any `Sym(N)`-translate of a generator of self is + which any `Sym(N)`-translate of a generator of ``self`` is symmetrically reducible, where by default ``N`` is the maximal variable index that occurs in the generators of ``self.interreduction().squeezed()``. @@ -607,12 +621,13 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(x[1]+x[2], x[1]*x[2]) - sage: I.symmetrisation() - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field - sage: I.symmetrisation(N=3) + sage: I = X * (x[1] + x[2], x[1]*x[2]) + sage: I.symmetrisation() # optional - sage.combinat + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field + sage: I.symmetrisation(N=3) # optional - sage.combinat Symmetric Ideal (-2*x_1) of Infinite polynomial ring in x over Rational Field - sage: I.symmetrisation(N=3, use_full_group=True) + sage: I.symmetrisation(N=3, use_full_group=True) # optional - sage.combinat Symmetric Ideal (-2*x_1) of Infinite polynomial ring in x over Rational Field """ @@ -656,7 +671,7 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F def symmetric_basis(self): """ - A symmetrised generating set (type :class:`~sage.structure.sequence.Sequence`) of self. + A symmetrised generating set (type :class:`~sage.structure.sequence.Sequence`) of ``self``. This does essentially the same as :meth:`symmetrisation` with the option 'tailreduce', and it returns a @@ -666,8 +681,8 @@ def symmetric_basis(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(x[1]+x[2], x[1]*x[2]) - sage: I.symmetric_basis() + sage: I = X * (x[1] + x[2], x[1]*x[2]) + sage: I.symmetric_basis() # optional - sage.combinat [x_1^2, x_2 + x_1] """ @@ -682,9 +697,10 @@ def normalisation(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(1/2*x[1]+2/3*x[2], 0, 4/5*x[1]*x[2]) + sage: I = X*(1/2*x[1] + 2/3*x[2], 0, 4/5*x[1]*x[2]) sage: I.normalisation() - Symmetric Ideal (x_2 + 3/4*x_1, x_2*x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (x_2 + 3/4*x_1, x_2*x_1) of + Infinite polynomial ring in x over Rational Field """ return SymmetricIdeal(self.ring(), [X/X.lc() for X in self.gens() if X._p!=0]) @@ -705,10 +721,11 @@ def squeezed(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: I = X*(x[1000]*y[100],x[50]*y[1000]) + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: I = X * (x[1000]*y[100], x[50]*y[1000]) sage: I.squeezed() - Symmetric Ideal (x_2*y_1, x_1*y_2) of Infinite polynomial ring in x, y over Rational Field + Symmetric Ideal (x_2*y_1, x_1*y_2) of + Infinite polynomial ring in x, y over Rational Field """ return SymmetricIdeal(self.ring(), [X.squeezed() for X in self.gens()]) @@ -791,11 +808,11 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I1 = X*(x[1]+x[2],x[1]*x[2]) - sage: I1.groebner_basis() + sage: I1 = X * (x[1] + x[2], x[1]*x[2]) + sage: I1.groebner_basis() # optional - sage.combinat [x_1] - sage: I2 = X*(y[1]^2*y[3]+y[1]*x[3]) - sage: I2.groebner_basis() + sage: I2 = X * (y[1]^2*y[3] + y[1]*x[3]) + sage: I2.groebner_basis() # optional - sage.combinat [x_1*y_2 + y_2^2*y_1, x_2*y_1 + y_2*y_1^2] Note that a symmetric Groebner basis of a principal ideal is @@ -805,13 +822,13 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= and Hillar, the result is the same, but the computation takes much longer:: - sage: I2.groebner_basis(use_full_group=True) + sage: I2.groebner_basis(use_full_group=True) # optional - sage.combinat [x_1*y_2 + y_2^2*y_1, x_2*y_1 + y_2*y_1^2] Last, we demonstrate how the report on the progress of computations looks like:: - sage: I1.groebner_basis(report=True, reduced=True) + sage: I1.groebner_basis(report=True, reduced=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> @@ -883,8 +900,8 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= is not the case:: sage: R. = InfinitePolynomialRing(ZZ) - sage: I = R*[x[1]+x[2],y[1]] - sage: I.groebner_basis() + sage: I = R * [x[1] + x[2], y[1]] + sage: I.groebner_basis() # optional - sage.combinat Traceback (most recent call last): ... TypeError: The base ring (= Integer Ring) must be a field @@ -893,14 +910,17 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= In an earlier version, the following examples failed:: - sage: X. = InfinitePolynomialRing(GF(5),order='degrevlex') - sage: I = ['-2*y_0^2 + 2*z_0^2 + 1', '-y_0^2 + 2*y_0*z_0 - 2*z_0^2 - 2*z_0 - 1', 'y_0*z_0 + 2*z_0^2 - 2*z_0 - 1', 'y_0^2 + 2*y_0*z_0 - 2*z_0^2 + 2*z_0 - 2', '-y_0^2 - 2*y_0*z_0 - z_0^2 + y_0 - 1']*X - sage: I.groebner_basis() + sage: X. = InfinitePolynomialRing(GF(5), order='degrevlex') # optional - sage.libs.pari + sage: I = ['-2*y_0^2 + 2*z_0^2 + 1', '-y_0^2 + 2*y_0*z_0 - 2*z_0^2 - 2*z_0 - 1', + ....: 'y_0*z_0 + 2*z_0^2 - 2*z_0 - 1', 'y_0^2 + 2*y_0*z_0 - 2*z_0^2 + 2*z_0 - 2', + ....: '-y_0^2 - 2*y_0*z_0 - z_0^2 + y_0 - 1'] * X + sage: I.groebner_basis() # optional - sage.combinat sage.libs.pari [1] - sage: Y. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') - sage: I = ['-y_3']*Y - sage: I.groebner_basis() + sage: Y. = InfinitePolynomialRing(GF(3), order='degrevlex', # optional - sage.libs.pari + ....: implementation='sparse') + sage: I = ['-y_3'] * Y + sage: I.groebner_basis() # optional - sage.libs.pari [y_1] """ diff --git a/src/sage/rings/polynomial/symmetric_reduction.pyx b/src/sage/rings/polynomial/symmetric_reduction.pyx index 25213e1318a..c8384b72977 100644 --- a/src/sage/rings/polynomial/symmetric_reduction.pyx +++ b/src/sage/rings/polynomial/symmetric_reduction.pyx @@ -51,7 +51,7 @@ EXAMPLES: First, we create an infinite polynomial ring and one of its elements:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = y[1]*y[3]+y[1]^2*x[3] + sage: p = y[1]*y[3] + y[1]^2*x[3] We want to symmetrically reduce it by another polynomial. So, we put this other polynomial into a list and create a Symmetric Reduction @@ -60,7 +60,8 @@ Strategy object:: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: S = SymmetricReductionStrategy(X, [y[2]^2*x[1]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_1*y_2^2 sage: S.reduce(p) x_3*y_1^2 + y_3*y_1 @@ -74,18 +75,19 @@ change variable index 1 into 2 and 2 into 3. So, we add this to sage: S.add_generator(y[1]^2*x[2]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_2*y_1^2, x_1*y_2^2 - sage: S.reduce(p) + sage: S.reduce(p) # optional - sage.combinat y_3*y_1 The next example shows that tail reduction is not done, unless it is explicitly advised:: - sage: S.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) + sage: S.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 + 2*x_2*y_1^2 + 3*x_1*y_2^2 - sage: S.tailreduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) + sage: S.tailreduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 However, it is possible to ask for tailreduction already when the @@ -93,11 +95,12 @@ Symmetric Reduction Strategy is created:: sage: S2 = SymmetricReductionStrategy(X, [y[2]^2*x[1],y[1]^2*x[2]], tailreduce=True) sage: S2 - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_2*y_1^2, x_1*y_2^2 with tailreduction - sage: S2.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) + sage: S2.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 """ @@ -144,7 +147,7 @@ cdef class SymmetricReductionStrategy: sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]], good_input=True) sage: S.reduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) y_3 + 3*y_2^2*y_1 + 2*y_2*y_1^2 - sage: S.tailreduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) + sage: S.tailreduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) # optional - sage.combinat y_3 """ @@ -265,7 +268,8 @@ cdef class SymmetricReductionStrategy: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in y over Rational Field, modulo y_2*y_1^2, y_2^2*y_1 sage: S.gens() @@ -295,7 +299,8 @@ cdef class SymmetricReductionStrategy: sage: R = SymmetricReductionStrategy(X) sage: R.setgens(S.gens()) sage: R - Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in y over Rational Field, modulo y_2*y_1^2, y_2^2*y_1 sage: R.gens() is S.gens() @@ -316,7 +321,8 @@ cdef class SymmetricReductionStrategy: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in y over Rational Field, modulo y_2*y_1^2, y_2^2*y_1 sage: S.reset() @@ -336,7 +342,7 @@ cdef class SymmetricReductionStrategy: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: X. = InfinitePolynomialRing(QQ) - sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]], tailreduce=True) + sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1], y[1]^2*y[2]], tailreduce=True) sage: S # indirect doctest Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo y_2*y_1^2, @@ -424,18 +430,21 @@ cdef class SymmetricReductionStrategy: sage: X. = InfinitePolynomialRing(QQ) sage: S = SymmetricReductionStrategy(X) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field sage: S.add_generator(y[3] + y[1]*(x[3]+x[1])) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_3*y_1 + x_1*y_1 + y_3 Note that the first added polynomial will be simplified when adding a suitable second polynomial:: - sage: S.add_generator(x[2]+x[1]) - sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + sage: S.add_generator(x[2] + x[1]) # optional - sage.combinat + sage: S # optional - sage.combinat + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3, x_2 + x_1 @@ -443,17 +452,19 @@ cdef class SymmetricReductionStrategy: polynomial. This can be avoided by specifying the optional parameter 'good_input':: - sage: S.add_generator(y[2]+y[1]*x[2]) - sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + sage: S.add_generator(y[2] + y[1]*x[2]) # optional - sage.combinat + sage: S # optional - sage.combinat + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3, x_1*y_1 - y_2, x_2 + x_1 - sage: S.reduce(x[3]+x[2]) + sage: S.reduce(x[3] + x[2]) # optional - sage.combinat -2*x_1 - sage: S.add_generator(x[3]+x[2], good_input=True) - sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + sage: S.add_generator(x[3] + x[2], good_input=True) # optional - sage.combinat + sage: S # optional - sage.combinat + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3, x_3 + x_2, x_1*y_1 - y_2, @@ -528,7 +539,7 @@ cdef class SymmetricReductionStrategy: .. NOTE:: - If tail reduction shall be forced, use :meth:`.tailreduce`. + If tail reduction shall be forced, use :meth:`tailreduce`. EXAMPLES:: @@ -540,15 +551,18 @@ cdef class SymmetricReductionStrategy: sage: S.reduce(y[4]*x[1] + y[1]*x[4], notail=True) x_4*y_1 + x_1*y_4 - Last, we demonstrate the 'report' option:: + Last, we demonstrate the ``report`` option:: - sage: S = SymmetricReductionStrategy(X, [x[2]+y[1],x[2]*y[3]+x[1]*y[2]+y[4],y[3]+y[2]]) + sage: S = SymmetricReductionStrategy(X, [x[2] + y[1], + ....: x[2]*y[3] + x[1]*y[2] + y[4], + ....: y[3] + y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3 + y_2, x_2 + y_1, x_1*y_2 + y_4 - y_3*y_1 - sage: S.reduce(x[3] + x[1]*y[3] + x[1]*y[1],report=True) + sage: S.reduce(x[3] + x[1]*y[3] + x[1]*y[1], report=True) :::> x_1*y_1 + y_4 - y_3*y_1 - y_1 @@ -625,18 +639,21 @@ cdef class SymmetricReductionStrategy: sage: S = SymmetricReductionStrategy(X, [y[3]]) sage: S.reduce(y[4]*x[1] + y[1]*x[4]) x_4*y_1 + x_1*y_4 - sage: S.tailreduce(y[4]*x[1] + y[1]*x[4]) + sage: S.tailreduce(y[4]*x[1] + y[1]*x[4]) # optional - sage.combinat x_4*y_1 Last, we demonstrate the 'report' option:: - sage: S = SymmetricReductionStrategy(X, [x[2]+y[1],x[2]*x[3]+x[1]*y[2]+y[4],y[3]+y[2]]) + sage: S = SymmetricReductionStrategy(X, [x[2] + y[1], + ....: x[2]*x[3] + x[1]*y[2] + y[4], + ....: y[3] + y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3 + y_2, x_2 + y_1, x_1*y_2 + y_4 + y_1^2 - sage: S.tailreduce(x[3] + x[1]*y[3] + x[1]*y[1],report=True) + sage: S.tailreduce(x[3] + x[1]*y[3] + x[1]*y[1], report=True) # optional - sage.combinat T[3]:::> T[3]:> x_1*y_1 - y_2 + y_1^2 - y_1 diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index bda1ec75a10..cd0238eceb9 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -272,22 +272,22 @@ EXAMPLES:: - sage: m = matrix(2,[2,3,0,1]); m + sage: m = matrix(2, [2,3,0,1]); m # optional - sage.modules [2 3] [0 1] - sage: T = TermOrder(m); T + sage: T = TermOrder(m); T # optional - sage.modules Matrix term order with matrix [2 3] [0 1] - sage: P. = PolynomialRing(QQ,2,order=T) - sage: P + sage: P. = PolynomialRing(QQ, 2, order=T) # optional - sage.modules + sage: P # optional - sage.modules Multivariate Polynomial Ring in a, b over Rational Field - sage: a > b + sage: a > b # optional - sage.modules False - sage: a^3 < b^2 + sage: a^3 < b^2 # optional - sage.modules True - sage: S = TermOrder('M(2,3,0,1)') - sage: T == S + sage: S = TermOrder('M(2,3,0,1)') # optional - sage.modules + sage: T == S # optional - sage.modules True Additionally all these monomial orders may be combined to product or block @@ -313,7 +313,7 @@ :: - sage: P. = PolynomialRing(QQ, 6,order='degrevlex(4),neglex(2)') + sage: P. = PolynomialRing(QQ, 6, order='degrevlex(4),neglex(2)') sage: a > c^4 False sage: a > e^4 @@ -341,7 +341,7 @@ Traceback (most recent call last): ... ValueError: unknown term order 'royalorder' - sage: T = TermOrder("royalorder",force=True) + sage: T = TermOrder("royalorder", force=True) sage: T royalorder term order sage: T.singular_str() @@ -647,7 +647,7 @@ def __init__(self, name='lex', n=0, force=False): :trac:`12748`):: sage: T = TermOrder('degrevlex', 6) + TermOrder('degrevlex',10) - sage: R. = PolynomialRing(QQ,order=T) + sage: R. = PolynomialRing(QQ, order=T) Traceback (most recent call last): ... ValueError: the length of the given term order (16) differs from the number of variables (15) @@ -657,7 +657,7 @@ def __init__(self, name='lex', n=0, force=False): sage: T = TermOrder('degrevlex') sage: R. = PolynomialRing(QQ, order=T) - sage: R._singular_() + sage: R._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 @@ -673,7 +673,7 @@ def __init__(self, name='lex', n=0, force=False): sage: S = R.change_ring(order=T2) sage: S == T False - sage: S._singular_() + sage: S._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 @@ -683,10 +683,11 @@ def __init__(self, name='lex', n=0, force=False): Check that :trac:`29635` is fixed:: - sage: T = PolynomialRing(GF(101^5), 'u,v,w', order=TermOrder('degneglex')).term_order() - sage: T.singular_str() + sage: T = PolynomialRing(GF(101^5), 'u,v,w', # optional - sage.rings.finite_rings + ....: order=TermOrder('degneglex')).term_order() + sage: T.singular_str() # optional - sage.rings.finite_rings '(a(1:3),ls(3))' - sage: (T + T).singular_str() + sage: (T + T).singular_str() # optional - sage.rings.finite_rings '(a(1:3),ls(3),a(1:3),ls(3))' """ if isinstance(name, TermOrder): @@ -929,10 +930,10 @@ def sortkey_matrix(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') - sage: y > x^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') # optional - sage.rings.number_field + sage: y > x^2 # indirect doctest # optional - sage.rings.number_field True - sage: y > x^3 + sage: y > x^3 # optional - sage.rings.number_field False """ return tuple(sum(l * r for l, r in zip(row, f)) @@ -949,10 +950,10 @@ def sortkey_lex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='lex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='lex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ return f @@ -968,10 +969,10 @@ def sortkey_invlex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='invlex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='invlex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ return f.reversed() @@ -987,10 +988,10 @@ def sortkey_deglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='deglex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='deglex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ @@ -1007,10 +1008,10 @@ def sortkey_degrevlex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='degrevlex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='degrevlex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ @@ -1029,10 +1030,10 @@ def sortkey_neglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='neglex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='neglex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field False """ return tuple(-v for v in f) @@ -1048,10 +1049,10 @@ def sortkey_negdegrevlex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='negdegrevlex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='negdegrevlex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field False """ return (-sum(f.nonzero_values(sort=False)), @@ -1068,10 +1069,10 @@ def sortkey_negdeglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='negdeglex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='negdeglex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field False """ return (-sum(f.nonzero_values(sort=False)), f) @@ -1087,10 +1088,10 @@ def sortkey_degneglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='degneglex') - sage: x*y > y*z # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='degneglex') # optional - sage.rings.number_field + sage: x*y > y*z # indirect doctest # optional - sage.rings.number_field False - sage: x*y > x + sage: x*y > x # optional - sage.rings.number_field True """ return (sum(f.nonzero_values(sort=False)), tuple(-v for v in f)) @@ -1107,10 +1108,10 @@ def sortkey_wdegrevlex(self, f): EXAMPLES:: sage: t = TermOrder('wdegrevlex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x^2 > y^3 + sage: x^2 > y^3 # optional - sage.rings.number_field True """ return (sum(l * r for (l, r) in zip(f, self._weights)), @@ -1128,10 +1129,10 @@ def sortkey_wdeglex(self, f): EXAMPLES:: sage: t = TermOrder('wdeglex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > y + sage: x > y # optional - sage.rings.number_field True """ return (sum(l * r for (l, r) in zip(f, self._weights)), f) @@ -1148,10 +1149,10 @@ def sortkey_negwdeglex(self, f): EXAMPLES:: sage: t = TermOrder('negwdeglex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x^2 > y^3 + sage: x^2 > y^3 # optional - sage.rings.number_field True """ return (-sum(l * r for (l, r) in zip(f, self._weights)), f) @@ -1168,10 +1169,10 @@ def sortkey_negwdegrevlex(self, f): EXAMPLES:: sage: t = TermOrder('negwdegrevlex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x^2 > y^3 + sage: x^2 > y^3 # optional - sage.rings.number_field True """ return (-sum(l * r for (l, r) in zip(f, self._weights)), @@ -1188,18 +1189,19 @@ def sortkey_block(self, f): EXAMPLES:: - sage: P.=PolynomialRing(QQbar, 6, order='degrevlex(3),degrevlex(3)') - sage: a > c^4 # indirect doctest + sage: P. = PolynomialRing(QQbar, 6, # optional - sage.rings.number_field + ....: order='degrevlex(3),degrevlex(3)') + sage: a > c^4 # indirect doctest # optional - sage.rings.number_field False - sage: a > e^4 + sage: a > e^4 # optional - sage.rings.number_field True TESTS: Check that the issue in :trac:`27139` is fixed:: - sage: R. = PolynomialRing(AA, order='lex(2),lex(2)') - sage: x > y + sage: R. = PolynomialRing(AA, order='lex(2),lex(2)') # optional - sage.rings.number_field + sage: x > y # optional - sage.rings.number_field True """ key = tuple() @@ -1223,10 +1225,10 @@ def greater_tuple_matrix(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') - sage: y > x^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') # optional - sage.rings.number_field + sage: y > x^2 # indirect doctest # optional - sage.rings.number_field True - sage: y > x^3 + sage: y > x^3 # optional - sage.rings.number_field False """ for row in self._matrix: @@ -1252,8 +1254,8 @@ def greater_tuple_lex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='lex') - sage: f = x + y^2; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: f = x + y^2; f.lm() # indirect doctest # optional - sage.rings.number_field x This method is called by the lm/lc/lt methods of @@ -1274,10 +1276,10 @@ def greater_tuple_invlex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='invlex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='invlex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = y + x^2; f.lm() + sage: f = y + x^2; f.lm() # optional - sage.rings.number_field y This method is called by the lm/lc/lt methods of @@ -1298,10 +1300,10 @@ def greater_tuple_deglex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='deglex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='deglex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1324,10 +1326,10 @@ def greater_tuple_degrevlex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='degrevlex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='degrevlex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1350,12 +1352,12 @@ def greater_tuple_negdegrevlex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='negdegrevlex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='negdegrevlex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^2*y*z^2 + x*y^3*z; f.lm() + sage: f = x^2*y*z^2 + x*y^3*z; f.lm() # optional - sage.rings.number_field x*y^3*z This method is called by the lm/lc/lt methods of @@ -1378,12 +1380,12 @@ def greater_tuple_negdeglex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='negdeglex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='negdeglex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^2*y*z^2 + x*y^3*z; f.lm() + sage: f = x^2*y*z^2 + x*y^3*z; f.lm() # optional - sage.rings.number_field x^2*y*z^2 This method is called by the lm/lc/lt methods of @@ -1406,10 +1408,10 @@ def greater_tuple_degneglex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='degneglex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='degneglex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1435,10 +1437,11 @@ def greater_tuple_neglex(self,f,g): EXAMPLES:: - sage: P.=PolynomialRing(QQbar, 6, order='degrevlex(3),degrevlex(3)') - sage: f = a + c^4; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 6, # optional - sage.rings.number_field + ....: order='degrevlex(3),degrevlex(3)') + sage: f = a + c^4; f.lm() # indirect doctest # optional - sage.rings.number_field c^4 - sage: g = a + e^4; g.lm() + sage: g = a + e^4; g.lm() # optional - sage.rings.number_field a """ return (f < g) and f or g @@ -1457,10 +1460,10 @@ def greater_tuple_wdeglex(self,f,g): EXAMPLES:: sage: t = TermOrder('wdeglex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = x*y + z; f.lm() + sage: f = x*y + z; f.lm() # optional - sage.rings.number_field x*y This method is called by the lm/lc/lt methods of @@ -1484,10 +1487,10 @@ def greater_tuple_wdegrevlex(self,f,g): EXAMPLES:: sage: t = TermOrder('wdegrevlex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1511,12 +1514,12 @@ def greater_tuple_negwdeglex(self,f,g): EXAMPLES:: sage: t = TermOrder('negwdeglex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^3 + z; f.lm() + sage: f = x^3 + z; f.lm() # optional - sage.rings.number_field x^3 This method is called by the lm/lc/lt methods of @@ -1540,12 +1543,12 @@ def greater_tuple_negwdegrevlex(self,f,g): EXAMPLES:: sage: t = TermOrder('negwdegrevlex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^3 + z; f.lm() + sage: f = x^3 + z; f.lm() # optional - sage.rings.number_field x^3 This method is called by the lm/lc/lt methods of @@ -1571,10 +1574,11 @@ def greater_tuple_block(self, f,g): EXAMPLES:: - sage: P.=PolynomialRing(QQbar, 6, order='degrevlex(3),degrevlex(3)') - sage: f = a + c^4; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 6, # optional - sage.rings.number_field + ....: order='degrevlex(3),degrevlex(3)') + sage: f = a + c^4; f.lm() # indirect doctest # optional - sage.rings.number_field c^4 - sage: g = a + e^4; g.lm() + sage: g = a + e^4; g.lm() # optional - sage.rings.number_field a """ n = 0 @@ -1600,9 +1604,9 @@ def tuple_weight(self, f): EXAMPLES:: - sage: t=TermOrder('wdeglex',(1,2,3)) - sage: P.=PolynomialRing(QQbar, order=t) - sage: P.term_order().tuple_weight([3,2,1]) + sage: t = TermOrder('wdeglex',(1,2,3)) + sage: P. = PolynomialRing(QQbar, order=t) # optional - sage.rings.number_field + sage: P.term_order().tuple_weight([3,2,1]) # optional - sage.rings.number_field 10 """ return sum(l*r for (l,r) in zip(f,self._weights)) @@ -1647,11 +1651,12 @@ def singular_str(self): EXAMPLES:: - sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),deglex(5),lex(2)') - sage: T = P.term_order() - sage: T.singular_str() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='lex(3),deglex(5),lex(2)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_str() # optional - sage.rings.finite_rings '(lp(3),Dp(5),lp(2))' - sage: P._singular_() + sage: P._singular_() # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 10 @@ -1677,7 +1682,7 @@ def singular_str(self): sage: T = P.term_order() sage: T.singular_str() '(a(1:2),ls(2),a(1:2),ls(2))' - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1699,7 +1704,7 @@ def singular_str(self): sage: T = TermOrder("degneglex", 2) + TermOrder("degneglex", 2) sage: T._singular_ringorder_column = 0 sage: P = PolynomialRing(QQ, 4, names='x', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1717,7 +1722,7 @@ def singular_str(self): sage: T._singular_ringorder_column = 1 sage: P = PolynomialRing(QQ, 4, names='y', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1735,7 +1740,7 @@ def singular_str(self): sage: T._singular_ringorder_column = 2 sage: P = PolynomialRing(QQ, 4, names='z', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1774,17 +1779,20 @@ def singular_moreblocks(self): EXAMPLES:: - sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),deglex(5),lex(2)') - sage: T = P.term_order() - sage: T.singular_moreblocks() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='lex(3),deglex(5),lex(2)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_moreblocks() # optional - sage.rings.finite_rings 0 - sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),degneglex(5),lex(2)') - sage: T = P.term_order() - sage: T.singular_moreblocks() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='lex(3),degneglex(5),lex(2)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_moreblocks() # optional - sage.rings.finite_rings 1 - sage: P = PolynomialRing(GF(127),10,names='x',order='degneglex(5),degneglex(5)') - sage: T = P.term_order() - sage: T.singular_moreblocks() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='degneglex(5),degneglex(5)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_moreblocks() # optional - sage.rings.finite_rings 2 TESTS: @@ -1814,11 +1822,12 @@ def macaulay2_str(self): EXAMPLES:: - sage: P = PolynomialRing(GF(127), 8,names='x',order='degrevlex(3),lex(5)') - sage: T = P.term_order() - sage: T.macaulay2_str() + sage: P = PolynomialRing(GF(127), 8, names='x', # optional - sage.rings.finite_rings + ....: order='degrevlex(3),lex(5)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.macaulay2_str() # optional - sage.rings.finite_rings '{GRevLex => 3,Lex => 5}' - sage: P._macaulay2_().options()['MonomialOrder'] # optional - macaulay2 + sage: P._macaulay2_().options()['MonomialOrder'] # optional - macaulay2 # optional - sage.rings.finite_rings {MonomialSize => 16 } {GRevLex => {1, 1, 1}} {Lex => 5 } @@ -1834,16 +1843,16 @@ def magma_str(self): EXAMPLES:: - sage: P = PolynomialRing(GF(127), 10,names='x',order='degrevlex') - sage: magma(P) # optional - magma + sage: P = PolynomialRing(GF(127), 10, names='x', order='degrevlex') # optional - sage.rings.finite_rings + sage: magma(P) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 10 over GF(127) Order: Graded Reverse Lexicographical Variables: x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 :: - sage: T = P.term_order() - sage: T.magma_str() + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.magma_str() # optional - sage.rings.finite_rings '"grevlex"' """ return self._magma_str @@ -1860,7 +1869,7 @@ def blocks(self): EXAMPLES:: - sage: t=TermOrder('deglex',2)+TermOrder('lex',2) + sage: t = TermOrder('deglex',2) + TermOrder('lex',2) sage: t.blocks() (Degree lexicographic term order, Lexicographic term order) """ @@ -1875,8 +1884,8 @@ def matrix(self): EXAMPLES:: - sage: t = TermOrder("M(1,2,0,1)") - sage: t.matrix() + sage: t = TermOrder("M(1,2,0,1)") # optional - sage.modules + sage: t.matrix() # optional - sage.modules [1 2] [0 1] @@ -2138,7 +2147,7 @@ def is_weighted_degree_order(self): EXAMPLES:: - sage: t=TermOrder('wdeglex',(2,3)) + sage: t = TermOrder('wdeglex',(2,3)) sage: t.is_weighted_degree_order() True """ @@ -2156,13 +2165,13 @@ def termorder_from_singular(S): EXAMPLES:: sage: from sage.rings.polynomial.term_order import termorder_from_singular - sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') + sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') # optional - sage.libs.singular '' - sage: termorder_from_singular(singular) + sage: termorder_from_singular(singular) # optional - sage.libs.singular Block term order with blocks: (Matrix term order with matrix - [1 2] - [3 0], + [1 2] + [3 0], Weighted degree reverse lexicographic term order with weights (2, 3), Lexicographic term order of length 2) @@ -2170,7 +2179,7 @@ def termorder_from_singular(S): This information is reflected in ``_singular_ringorder_column`` attribute of the term order. :: - sage: singular.ring(0, '(x,y,z,w)', '(C,dp(2),lp(2))') + sage: singular.ring(0, '(x,y,z,w)', '(C,dp(2),lp(2))') # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2179,15 +2188,15 @@ def termorder_from_singular(S): // : names x y // block 3 : ordering lp // : names z w - sage: T = termorder_from_singular(singular) - sage: T + sage: T = termorder_from_singular(singular) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Lexicographic term order of length 2) - sage: T._singular_ringorder_column + sage: T._singular_ringorder_column # optional - sage.libs.singular 0 - sage: singular.ring(0, '(x,y,z,w)', '(c,dp(2),lp(2))') + sage: singular.ring(0, '(x,y,z,w)', '(c,dp(2),lp(2))') # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2196,12 +2205,12 @@ def termorder_from_singular(S): // : names x y // block 3 : ordering lp // : names z w - sage: T = termorder_from_singular(singular) - sage: T + sage: T = termorder_from_singular(singular) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Lexicographic term order of length 2) - sage: T._singular_ringorder_column + sage: T._singular_ringorder_column # optional - sage.libs.singular 1 TESTS: @@ -2209,16 +2218,16 @@ def termorder_from_singular(S): Check that ``degneglex`` term orders are converted correctly (:trac:`29635`):: - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:4),ls(4))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:4),ls(4))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:4),ls(4))' - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),a(1:2),ls(2))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),a(1:2),ls(2))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:2),ls(2),a(1:2),ls(2))' - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),C,a(1:2),ls(2))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),C,a(1:2),ls(2))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:2),ls(2),C,a(1:2),ls(2))' - sage: PolynomialRing(QQ, 'x,y', order='degneglex')('x^2')._singular_().sage() + sage: PolynomialRing(QQ, 'x,y', order='degneglex')('x^2')._singular_().sage() # optional - sage.libs.singular x^2 """ from sage.rings.integer_ring import ZZ diff --git a/src/sage/rings/polynomial/toy_buchberger.py b/src/sage/rings/polynomial/toy_buchberger.py index 2f02ca65e05..c70cf1f90aa 100644 --- a/src/sage/rings/polynomial/toy_buchberger.py +++ b/src/sage/rings/polynomial/toy_buchberger.py @@ -24,39 +24,40 @@ Consider Katsura-6 with respect to a ``degrevlex`` ordering. :: sage: from sage.rings.polynomial.toy_buchberger import * - sage: P. = PolynomialRing(GF(32003)) - sage: I = sage.rings.ideal.Katsura(P, 6) + sage: P. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P, 6) # optional - sage.rings.finite_rings - sage: g1 = buchberger(I) - sage: g2 = buchberger_improved(I) - sage: g3 = I.groebner_basis() + sage: g1 = buchberger(I) # optional - sage.rings.finite_rings + sage: g2 = buchberger_improved(I) # optional - sage.rings.finite_rings + sage: g3 = I.groebner_basis() # optional - sage.rings.finite_rings All algorithms actually compute a Groebner basis:: - sage: Ideal(g1).basis_is_groebner() + sage: Ideal(g1).basis_is_groebner() # optional - sage.rings.finite_rings True - sage: Ideal(g2).basis_is_groebner() + sage: Ideal(g2).basis_is_groebner() # optional - sage.rings.finite_rings True - sage: Ideal(g3).basis_is_groebner() + sage: Ideal(g3).basis_is_groebner() # optional - sage.rings.finite_rings True The results are correct:: - sage: Ideal(g1) == Ideal(g2) == Ideal(g3) + sage: Ideal(g1) == Ideal(g2) == Ideal(g3) # optional - sage.rings.finite_rings True If ``get_verbose()`` is `\ge 1`, a protocol is provided:: sage: from sage.misc.verbose import set_verbose sage: set_verbose(1) - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings // sage... ideal - sage: I - Ideal (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a, 2*a*b + 2*b*c - b) of Multivariate Polynomial Ring in a, b, c over Finite Field of size 127 + sage: I # optional - sage.rings.finite_rings + Ideal (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a, 2*a*b + 2*b*c - b) + of Multivariate Polynomial Ring in a, b, c over Finite Field of size 127 - sage: buchberger(I) # random + sage: buchberger(I) # random # optional - sage.rings.finite_rings (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a) => -2*b^2 - 6*b*c - 6*c^2 + b + 2*c G: set([a + 2*b + 2*c - 1, 2*a*b + 2*b*c - b, a^2 + 2*b^2 + 2*c^2 - a, -2*b^2 - 6*b*c - 6*c^2 + b + 2*c]) @@ -117,18 +118,19 @@ The original Buchberger algorithm performs 15 useless reductions to zero for this example:: - sage: gb = buchberger(I) + sage: gb = buchberger(I) # optional - sage.rings.finite_rings ... 15 reductions to zero. The 'improved' Buchberger algorithm in contrast only performs 1 reduction to zero:: - sage: gb = buchberger_improved(I) + sage: gb = buchberger_improved(I) # optional - sage.rings.finite_rings ... 1 reductions to zero. - sage: sorted(gb) - [a + 2*b + 2*c - 1, b*c + 52*c^2 + 38*b + 25*c, b^2 - 26*c^2 - 51*b + 51*c, c^3 + 22*c^2 - 55*b + 49*c] + sage: sorted(gb) # optional - sage.rings.finite_rings + [a + 2*b + 2*c - 1, b*c + 52*c^2 + 38*b + 25*c, + b^2 - 26*c^2 - 51*b + 51*c, c^3 + 22*c^2 - 55*b + 49*c] AUTHORS: @@ -191,10 +193,10 @@ def buchberger(F): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^2 - z - 1, z^2 - y - 1, x*y^2 - x - 1]) sage: set_verbose(0) - sage: gb = buchberger(I) - sage: gb.is_groebner() + sage: gb = buchberger(I) # optional - sage.libs.singular + sage: gb.is_groebner() # optional - sage.libs.singular True - sage: gb.ideal() == I + sage: gb.ideal() == I # optional - sage.libs.singular True """ G = set(F.gens()) @@ -249,7 +251,7 @@ def buchberger_improved(F): sage: from sage.rings.polynomial.toy_buchberger import buchberger_improved sage: R. = PolynomialRing(QQ) sage: set_verbose(0) - sage: sorted(buchberger_improved(R.ideal([x^4 - y - z, x*y*z - 1]))) + sage: sorted(buchberger_improved(R.ideal([x^4 - y - z, x*y*z - 1]))) # optional - sage.libs.singular [x*y*z - 1, x^3 - y^2*z - y*z^2, y^3*z^2 + y^2*z^3 - x^2] """ F = inter_reduction(F.gens()) @@ -382,8 +384,8 @@ def select(P): sage: from sage.rings.polynomial.toy_buchberger import select sage: R. = PolynomialRing(QQ, order='lex') - sage: ps = [x^3 - z -1, z^3 - y - 1, x^5 - y - 2] - sage: pairs = [[ps[i], ps[j]] for i in range(3) for j in range(i+1, 3)] + sage: ps = [x^3 - z - 1, z^3 - y - 1, x^5 - y - 2] + sage: pairs = [[ps[i], ps[j]] for i in range(3) for j in range(i + 1, 3)] sage: select(pairs) [x^3 - z - 1, -y + z^3 - 1] """ @@ -401,10 +403,10 @@ def inter_reduction(Q): OUTPUT: - if ``Q`` is the set `(f_1, ..., f_n)`, this method returns `(g_1, - ..., g_s)` such that: + if ``Q`` is the set `f_1, ..., f_n`, this method returns `g_1, + ..., g_s` such that: - - ` = ` + - `(f_1,...,f_n) = (g_1,...,g_s)` - `LM(g_i) \neq LM(g_j)` for all `i \neq j` - `LM(g_i)` does not divide `m` for all monomials `m` of `\{g_1,...,g_{i-1}, g_{i+1},...,g_s\}` @@ -419,10 +421,10 @@ def inter_reduction(Q): :: sage: P. = QQ[] - sage: reduced = inter_reduction(set([x^2 - 5*y^2, x^3])) - sage: reduced == set([x*y^2, x^2-5*y^2]) + sage: reduced = inter_reduction(set([x^2 - 5*y^2, x^3])) # optional - sage.libs.singular + sage: reduced == set([x*y^2, x^2 - 5*y^2]) # optional - sage.libs.singular True - sage: reduced == inter_reduction(set([2*(x^2 - 5*y^2), x^3])) + sage: reduced == inter_reduction(set([2*(x^2 - 5*y^2), x^3])) # optional - sage.libs.singular True """ if not Q: diff --git a/src/sage/rings/polynomial/toy_d_basis.py b/src/sage/rings/polynomial/toy_d_basis.py index 07f83100df7..660922aaf64 100644 --- a/src/sage/rings/polynomial/toy_d_basis.py +++ b/src/sage/rings/polynomial/toy_d_basis.py @@ -20,12 +20,12 @@ First, consider an example from arithmetic geometry:: sage: A. = PolynomialRing(ZZ, 2) - sage: B. = PolynomialRing(Rationals(),2) + sage: B. = PolynomialRing(Rationals(), 2) sage: f = -y^2 - y + x^3 + 7*x + 1 sage: fx = f.derivative(x) sage: fy = f.derivative(y) - sage: I = B.ideal([B(f),B(fx),B(fy)]) - sage: I.groebner_basis() + sage: I = B.ideal([B(f), B(fx), B(fy)]) + sage: I.groebner_basis() # optional - sage.libs.singular [1] Since the output is 1, we know that there are no generic @@ -34,7 +34,7 @@ To look at the singularities of the arithmetic surface, we need to do the corresponding computation over `\ZZ`:: - sage: I = A.ideal([f,fx,fy]) + sage: I = A.ideal([f, fx, fy]) sage: gb = d_basis(I); gb [x - 2020, y - 11313, 22627] @@ -52,7 +52,7 @@ Another example. This one is from the Magma Handbook:: sage: P. = PolynomialRing(IntegerRing(), 3, order='lex') - sage: I = ideal( x^2 - 1, y^2 - 1, 2*x*y - z) + sage: I = ideal(x^2 - 1, y^2 - 1, 2*x*y - z) sage: I = Ideal(d_basis(I)) sage: x.reduce(I) x @@ -61,7 +61,7 @@ To compute modulo 4, we can add the generator 4 to our basis.:: - sage: I = ideal( x^2 - 1, y^2 - 1, 2*x*y - z, 4) + sage: I = ideal(x^2 - 1, y^2 - 1, 2*x*y - z, 4) sage: gb = d_basis(I) sage: R = P.change_ring(IntegerModRing(4)) sage: gb = [R(f) for f in gb if R(f)]; gb @@ -79,7 +79,7 @@ there are 4 equations in 3 unknowns). :: sage: P. = PolynomialRing(IntegerRing(), 3, order='degneglex') - sage: I = ideal( x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1 ) + sage: I = ideal(x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1) sage: I.change_ring(P.change_ring(RationalField())).groebner_basis() [1] @@ -96,19 +96,19 @@ sage: factor(282687803443) 101 * 103 * 27173681 - sage: I.change_ring( P.change_ring( GF(101) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(101))).groebner_basis() [z - 33, y + 48, x + 19] - sage: I.change_ring( P.change_ring( GF(103) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(103))).groebner_basis() [z - 18, y + 8, x + 39] - sage: I.change_ring( P.change_ring( GF(27173681) ) ).groebner_basis() + sage: I.change_ring( P.change_ring(GF(27173681))).groebner_basis() [z + 10380032, y + 3186055, x - 536027] Of course, modulo any other prime the Groebner basis is trivial so there are no other solutions. For example:: - sage: I.change_ring( P.change_ring( GF(3) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(3))).groebner_basis() [1] AUTHOR: diff --git a/src/sage/rings/polynomial/toy_variety.py b/src/sage/rings/polynomial/toy_variety.py index 3f2a1705989..16ccfb6cf8c 100644 --- a/src/sage/rings/polynomial/toy_variety.py +++ b/src/sage/rings/polynomial/toy_variety.py @@ -100,7 +100,7 @@ def coefficient_matrix(polys): sage: from sage.rings.polynomial.toy_variety import coefficient_matrix sage: R. = PolynomialRing(QQ) - sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1]) + sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1]) # optional - sage.modules [1 0 0 1] [0 0 1 1] [0 1 0 1] @@ -159,12 +159,12 @@ def is_linearly_dependent(polys) -> bool: sage: R. = PolynomialRing(QQ) sage: B = [x^2 + 1, y^2 + 1, x*y + 1] sage: p = 3*B[0] - 2*B[1] + B[2] - sage: is_linearly_dependent(B + [p]) + sage: is_linearly_dependent(B + [p]) # optional - sage.modules True - sage: p = x*B[0] - sage: is_linearly_dependent(B + [p]) + sage: p = x*B[0] # optional - sage.modules + sage: is_linearly_dependent(B + [p]) # optional - sage.modules False - sage: is_linearly_dependent([]) + sage: is_linearly_dependent([]) # optional - sage.modules False """ if not polys: @@ -204,10 +204,10 @@ def linear_representation(p, polys): EXAMPLES:: sage: from sage.rings.polynomial.toy_variety import linear_representation - sage: R. = PolynomialRing(GF(32003)) - sage: B = [x^2 + 1, y^2 + 1, x*y + 1] - sage: p = 3*B[0] - 2*B[1] + B[2] - sage: linear_representation(p, B) + sage: R. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: B = [x^2 + 1, y^2 + 1, x*y + 1] # optional - sage.rings.finite_rings + sage: p = 3*B[0] - 2*B[1] + B[2] # optional - sage.rings.finite_rings + sage: linear_representation(p, B) # optional - sage.rings.finite_rings [3, 32001, 1] """ from sage.matrix.constructor import diagonal_matrix @@ -243,12 +243,12 @@ def triangular_factorization(B, n=-1): sage: from sage.misc.verbose import set_verbose sage: set_verbose(0) sage: from sage.rings.polynomial.toy_variety import triangular_factorization - sage: R. = PolynomialRing(GF(32003)) - sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 - sage: p2 = z^2 - z - sage: p3 = (x-2)^2*(y-1)^3 - sage: I = R.ideal(p1,p2,p3) - sage: triangular_factorization(I.groebner_basis()) + sage: R. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 # optional - sage.rings.finite_rings + sage: p2 = z^2 - z # optional - sage.rings.finite_rings + sage: p3 = (x-2)^2*(y-1)^3 # optional - sage.rings.finite_rings + sage: I = R.ideal(p1,p2,p3) # optional - sage.rings.finite_rings + sage: triangular_factorization(I.groebner_basis()) # optional - sage.rings.finite_rings [[x^2 - 4*x + 4, y, z], [x^5 - 3*x^4 + 3*x^3 - x^2, y - 1, z], [x^2 - 4*x + 4, y, z - 1], @@ -317,12 +317,12 @@ def elim_pol(B, n=-1): sage: from sage.misc.verbose import set_verbose sage: set_verbose(0) sage: from sage.rings.polynomial.toy_variety import elim_pol - sage: R. = PolynomialRing(GF(32003)) - sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 - sage: p2 = z^2 - z - sage: p3 = (x-2)^2*(y-1)^3 - sage: I = R.ideal(p1,p2,p3) - sage: elim_pol(I.groebner_basis()) + sage: R. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 # optional - sage.rings.finite_rings + sage: p2 = z^2 - z # optional - sage.rings.finite_rings + sage: p3 = (x-2)^2*(y-1)^3 # optional - sage.rings.finite_rings + sage: I = R.ideal(p1,p2,p3) # optional - sage.rings.finite_rings + sage: elim_pol(I.groebner_basis()) # optional - sage.rings.finite_rings z^2 - z """ # type checking in a probably vain attempt to avoid stupid errors diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index d3546fc0c72..43a64db2fdf 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -105,9 +105,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = 3 - t^3 + O(t^5) - sage: f.polynomial() + sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f = 3 - t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f.polynomial() # optional - sage.rings.finite_rings 6*t^3 + 3 """ return self.__f @@ -159,12 +159,12 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] - sage: bool(1 + t + O(t^18)) + sage: R. = GF(11)[[]] # optional - sage.rings.finite_rings + sage: bool(1 + t + O(t^18)) # optional - sage.rings.finite_rings True - sage: bool(R(0)) + sage: bool(R(0)) # optional - sage.rings.finite_rings False - sage: bool(O(t^18)) + sage: bool(O(t^18)) # optional - sage.rings.finite_rings False """ return not not self.__f @@ -225,17 +225,17 @@ cdef class PowerSeries_poly(PowerSeries): A series defined over another ring can be substituted:: - sage: S. = GF(7)[[]] - sage: f(2*u + u^3 + O(u^5)) + sage: S. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f(2*u + u^3 + O(u^5)) # optional - sage.rings.finite_rings 4*u^2 + u^3 + 4*u^4 + 5*u^5 + O(u^6) As can a p-adic integer as long as the coefficient ring is compatible:: - sage: f(100 + O(5^7)) + sage: f(100 + O(5^7)) # optional - sage.rings.padics 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: f.change_ring(Zp(5))(100 + O(5^7)) + sage: f.change_ring(Zp(5))(100 + O(5^7)) # optional - sage.rings.padics 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: f.change_ring(Zp(5))(100 + O(2^7)) + sage: f.change_ring(Zp(5))(100 + O(2^7)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: Cannot substitute this value @@ -248,7 +248,7 @@ cdef class PowerSeries_poly(PowerSeries): Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation - sage: f(2 + O(5^3)) + sage: f(2 + O(5^3)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation @@ -268,18 +268,18 @@ cdef class PowerSeries_poly(PowerSeries): Arguments beyond the first can refer to the base ring:: - sage: P. = GF(5)[] - sage: Q. = P[[]] - sage: h = (1 - x*y)^-1 + O(y^7); h + sage: P. = GF(5)[] # optional - sage.rings.finite_rings + sage: Q. = P[[]] # optional - sage.rings.finite_rings + sage: h = (1 - x*y)^-1 + O(y^7); h # optional - sage.rings.finite_rings 1 + x*y + x^2*y^2 + x^3*y^3 + x^4*y^4 + x^5*y^5 + x^6*y^6 + O(y^7) - sage: h(y^2, 3) + sage: h(y^2, 3) # optional - sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) These secondary values can also be specified using keywords:: - sage: h(y=y^2, x=3) + sage: h(y=y^2, x=3) # optional - sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) - sage: h(y^2, x=3) + sage: h(y^2, x=3) # optional - sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) """ P = self.parent() @@ -375,27 +375,27 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = 3 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(0, 5) - sage: f + sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f = 3 + 6*t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f._unsafe_mutate(0, 5) # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings 5 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(2, 1) ; f + sage: f._unsafe_mutate(2, 1) ; f # optional - sage.rings.finite_rings 5 + t^2 + 6*t^3 + O(t^5) - Mutating can even bump up the precision:: - sage: f._unsafe_mutate(6, 1) ; f + sage: f._unsafe_mutate(6, 1) ; f # optional - sage.rings.finite_rings 5 + t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(0, 0) ; f + sage: f._unsafe_mutate(0, 0) ; f # optional - sage.rings.finite_rings t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(1, 0) ; f + sage: f._unsafe_mutate(1, 0) ; f # optional - sage.rings.finite_rings t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(11,0) ; f + sage: f._unsafe_mutate(11,0) ; f # optional - sage.rings.finite_rings t^2 + 6*t^3 + t^6 + O(t^12) - sage: g = t + O(t^7) - sage: g._unsafe_mutate(1,0) ; g + sage: g = t + O(t^7) # optional - sage.rings.finite_rings + sage: g._unsafe_mutate(1,0) ; g # optional - sage.rings.finite_rings O(t^7) """ self.__f._unsafe_mutate(i, value) @@ -554,9 +554,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = t + 3*t^4 + O(t^11) - sage: f * GF(7)(3) + sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f = t + 3*t^4 + O(t^11) # optional - sage.rings.finite_rings + sage: f * GF(7)(3) # optional - sage.rings.finite_rings 3*t + 2*t^4 + O(t^11) """ return PowerSeries_poly(self._parent, self.__f * c, self._prec, check=False) @@ -567,9 +567,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] - sage: f = 1 + 3*t^4 + O(t^120) - sage: 2 * f + sage: R. = GF(11)[[]] # optional - sage.rings.finite_rings + sage: f = 1 + 3*t^4 + O(t^120) # optional - sage.rings.finite_rings + sage: 2 * f # optional - sage.rings.finite_rings 2 + 6*t^4 + O(t^120) """ return PowerSeries_poly(self._parent, c * self.__f, self._prec, check=False) @@ -597,11 +597,11 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = t + t^4 + O(t^7) - sage: f >> 1 + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = t + t^4 + O(t^7) # optional - sage.rings.finite_rings + sage: f >> 1 # optional - sage.rings.finite_rings 1 + t^3 + O(t^6) - sage: f >> 10 + sage: f >> 10 # optional - sage.rings.finite_rings O(t^0) """ if n: @@ -733,10 +733,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) + sage: f.truncate(5) # optional - sage.rings.finite_rings I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -764,10 +764,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate_powerseries(5) + sage: f.truncate_powerseries(5) # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + O(I^5) """ return PowerSeries_poly(self._parent, self.__f.truncate(prec), @@ -845,8 +845,8 @@ cdef class PowerSeries_poly(PowerSeries): TESTS:: sage: R. = PowerSeriesRing(QQ, sparse=True) - sage: x = var('x') - sage: t.derivative(x) + sage: x = var('x') # optional - sage.symbolic + sage: t.derivative(x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to x @@ -1195,19 +1195,19 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: sage: R. = PowerSeriesRing(QQ) - sage: s = R([1,2,3,4,5],prec=10); s + sage: s = R([1,2,3,4,5], prec=10); s 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^10) - sage: SR(s) + sage: SR(s) # optional - sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + Order(x^10) - sage: SR(s).is_terminating_series() + sage: SR(s).is_terminating_series() # optional - sage.symbolic False - sage: SR(s).variables() + sage: SR(s).variables() # optional - sage.symbolic (x,) sage: s = R([1,2,3,4,5]); s 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: SR(s) + sage: SR(s) # optional - sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: _.is_terminating_series() + sage: _.is_terminating_series() # optional - sage.symbolic True TESTS: @@ -1215,7 +1215,7 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`18094` is fixed:: sage: R. = PolynomialRing(ZZ) - sage: SR(R(0).add_bigoh(20)) + sage: SR(R(0).add_bigoh(20)) # optional - sage.symbolic Order(x^20) """ from sage.symbolic.ring import SR diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index a65af81d061..88b80166a37 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -59,13 +59,13 @@ :: - sage: K. = PowerSeriesRing(SR, default_prec=5) - sage: a, b, c = var('a,b,c') - sage: f = a + b*t + c*t^2 + O(t^3) - sage: f*f + sage: K. = PowerSeriesRing(SR, default_prec=5) # optional - sage.symbolic + sage: a, b, c = var('a,b,c') # optional - sage.symbolic + sage: f = a + b*t + c*t^2 + O(t^3) # optional - sage.symbolic + sage: f*f # optional - sage.symbolic a^2 + 2*a*b*t + (b^2 + 2*a*c)*t^2 + O(t^3) - sage: f = sqrt(2) + sqrt(3)*t + O(t^3) - sage: f^2 + sage: f = sqrt(2) + sqrt(3)*t + O(t^3) # optional - sage.symbolic + sage: f^2 # optional - sage.symbolic 2 + 2*sqrt(3)*sqrt(2)*t + 3*t^2 + O(t^3) Elements are first coerced to constants in ``base_ring``, then coerced @@ -258,13 +258,13 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, Power series ring over finite field:: - sage: S = PowerSeriesRing(GF(65537),'x,y'); S + sage: S = PowerSeriesRing(GF(65537),'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 Power series ring with many variables:: - sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R + sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R # optional - sage.libs.pari Multivariate Power Series Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring @@ -274,12 +274,12 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, :: - sage: R.inject_variables() + sage: R.inject_variables() # optional - sage.libs.pari Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 - sage: f = x47 + 3*x11*x29 - x19 + R.O(3) - sage: f in R + sage: f = x47 + 3*x11*x29 - x19 + R.O(3) # optional - sage.libs.pari + sage: f in R # optional - sage.libs.pari True @@ -519,11 +519,11 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, commutative ring, but also a complete discrete valuation ring (CDVR). The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) - sage: R. = k[[]] - sage: R.category() + sage: k = GF(11) # optional - sage.rings.finite_rings + sage: R. = k[[]] # optional - sage.rings.finite_rings + sage: R.category() # optional - sage.rings.finite_rings Category of complete discrete valuation rings - sage: TestSuite(R).run() + sage: TestSuite(R).run() # optional - sage.rings.finite_rings It is checked that the default precision is non-negative (see :trac:`19409`):: @@ -615,13 +615,13 @@ def _repr_(self): EXAMPLES:: - sage: R = GF(17)[['y']] - sage: R + sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Power Series Ring in y over Finite Field of size 17 - sage: R.__repr__() + sage: R.__repr__() # optional - sage.rings.finite_rings 'Power Series Ring in y over Finite Field of size 17' - sage: R.rename('my power series ring') - sage: R + sage: R.rename('my power series ring') # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings my power series ring """ s = "Power Series Ring in %s over %s"%(self.variable_name(), self.base_ring()) @@ -661,11 +661,11 @@ def _latex_(self): EXAMPLES:: - sage: R = GF(17)[['y']] - sage: latex(R) # indirect doctest + sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings + sage: latex(R) # indirect doctest # optional - sage.rings.finite_rings \Bold{F}_{17}[[y]] - sage: R = GF(17)[['y12']] - sage: latex(R) + sage: R = GF(17)[['y12']] # optional - sage.rings.finite_rings + sage: latex(R) # optional - sage.rings.finite_rings \Bold{F}_{17}[[y_{12}]] """ return "%s[[%s]]"%(latex.latex(self.base_ring()), self.latex_variable_names()[0]) @@ -679,14 +679,14 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: A = GF(17)[['x']] - sage: A.has_coerce_map_from(ZZ) # indirect doctest + sage: A = GF(17)[['x']] # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ) # indirect doctest # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x']) + sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['y']) + sage: A.has_coerce_map_from(ZZ['y']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(ZZ[['x']]) + sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings True """ @@ -891,18 +891,20 @@ def _coerce_impl(self, x): We illustrate canonical coercion between power series rings with compatible base rings:: - sage: R. = PowerSeriesRing(GF(7)['w']) + sage: R. = PowerSeriesRing(GF(7)['w']) # optional - sage.rings.finite_rings sage: S = PowerSeriesRing(ZZ, 't') sage: f = S([1,2,3,4]); f 1 + 2*t + 3*t^2 + 4*t^3 - sage: g = R.coerce(f); g + sage: g = R.coerce(f); g # optional - sage.rings.finite_rings 1 + 2*t + 3*t^2 + 4*t^3 - sage: parent(g) + sage: parent(g) # optional - sage.rings.finite_rings Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 - sage: S.coerce(g) + sage: S.coerce(g) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: no canonical coercion from Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 to Power Series Ring in t over Integer Ring + TypeError: no canonical coercion + from Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 + to Power Series Ring in t over Integer Ring """ try: P = x.parent() @@ -978,11 +980,11 @@ def base_extend(self, R): EXAMPLES:: - sage: R. = GF(7)[[]]; R + sage: R. = GF(7)[[]]; R # optional - sage.rings.finite_rings Power Series Ring in T over Finite Field of size 7 - sage: R.change_ring(ZZ) + sage: R.change_ring(ZZ) # optional - sage.rings.finite_rings Power Series Ring in T over Integer Ring - sage: R.base_extend(ZZ) + sage: R.base_extend(ZZ) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined @@ -1000,14 +1002,15 @@ def change_ring(self, R): sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field - sage: R.change_ring(GF(7)) + sage: R.change_ring(GF(7)) # optional - sage.rings.finite_rings Power Series Ring in T over Finite Field of size 7 - sage: R.base_extend(GF(7)) + sage: R.base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined - sage: R.base_extend(QuadraticField(3,'a')) - Power Series Ring in T over Number Field in a with defining polynomial x^2 - 3 with a = 1.732050807568878? + sage: R.base_extend(QuadraticField(3,'a')) # optional - sage.rings.number_field + Power Series Ring in T over Number Field in a + with defining polynomial x^2 - 3 with a = 1.732050807568878? """ return PowerSeriesRing(R, name = self.variable_name(), default_prec = self.default_prec()) @@ -1229,11 +1232,11 @@ def residue_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) - sage: R.residue_field() + sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.residue_field() # optional - sage.rings.finite_rings Finite Field of size 17 - sage: R. = PowerSeriesRing(Zp(5)) - sage: R.residue_field() + sage: R. = PowerSeriesRing(Zp(5)) # optional - sage.rings.padics + sage: R.residue_field() # optional - sage.rings.padics Finite Field of size 5 """ if self.base_ring().is_field(): @@ -1326,10 +1329,10 @@ def fraction_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(7)) - sage: R.fraction_field() + sage: R. = PowerSeriesRing(GF(7)) # optional - sage.rings.finite_rings + sage: R.fraction_field() # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 - sage: Frac(R) + sage: Frac(R) # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 """ return self.laurent_series_ring() @@ -1343,7 +1346,7 @@ def unpickle_power_series_ring_v0(base_ring, name, default_prec, sparse): EXAMPLES:: sage: P. = PowerSeriesRing(QQ) - sage: loads(dumps(P)) == P # indirect doctest + sage: loads(dumps(P)) == P # indirect doctest True """ return PowerSeriesRing(base_ring, name=name, default_prec = default_prec, sparse=sparse) diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 2422521fba8..936cf6b8485 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -133,15 +133,15 @@ def is_PowerSeries(x): sage: R. = PowerSeriesRing(ZZ) sage: from sage.rings.power_series_ring_element import is_PowerSeries - sage: is_PowerSeries(1+x^2) + sage: is_PowerSeries(1 + x^2) True - sage: is_PowerSeries(x-x) + sage: is_PowerSeries(x - x) True sage: is_PowerSeries(0) False - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: is_PowerSeries(1+x^2) + sage: is_PowerSeries(1 + x^2) # optional - sage.symbolic False """ return isinstance(x, PowerSeries) @@ -163,9 +163,9 @@ cdef class PowerSeries(AlgebraElement): sage: PowerSeriesRing(CC, 'q') Power Series Ring in q over Complex Field with 53 bits of precision - sage: T = PowerSeriesRing(GF(3),5,'t'); T - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite - Field of size 3 + sage: T = PowerSeriesRing(GF(3), 5, 't'); T # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 3 """ AlgebraElement.__init__(self, parent) self.__is_gen = is_gen @@ -285,13 +285,13 @@ cdef class PowerSeries(AlgebraElement): sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field sage: f = 1 - 1/2*T + 1/3*T^2 + O(T^3) - sage: f.base_extend(GF(5)) + sage: f.base_extend(GF(5)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined - sage: f.change_ring(GF(5)) + sage: f.change_ring(GF(5)) # optional - sage.rings.finite_rings 1 + 2*T + 2*T^2 + O(T^3) - sage: f.change_ring(GF(3)) + sage: f.change_ring(GF(3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(0, 3) does not exist @@ -301,18 +301,18 @@ cdef class PowerSeries(AlgebraElement): :: - sage: K. = NumberField(cyclotomic_polynomial(3), 'a') - sage: R. = K[['t']] - sage: (4*t).change_ring(ZZ) + sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # optional - sage.rings.number_field + sage: R. = K[['t']] # optional - sage.rings.number_field + sage: (4*t).change_ring(ZZ) # optional - sage.rings.number_field 4*t This does not succeed because ``ZZ(K(a+1))`` is not defined. :: - sage: K. = NumberField(cyclotomic_polynomial(3), 'a') - sage: R. = K[['t']] - sage: ((a+1)*t).change_ring(ZZ) + sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # optional - sage.rings.number_field + sage: R. = K[['t']] # optional - sage.rings.number_field + sage: ((a+1)*t).change_ring(ZZ) # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce a + 1 to an integer @@ -492,11 +492,11 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: A. = PowerSeriesRing(GF(5)) - sage: x = t + t^2 + O(t^5) - sage: x.lift_to_precision(10) + sage: A. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: x = t + t^2 + O(t^5) # optional - sage.rings.finite_rings + sage: x.lift_to_precision(10) # optional - sage.rings.finite_rings t + t^2 + O(t^10) - sage: x.lift_to_precision() + sage: x.lift_to_precision() # optional - sage.rings.finite_rings t + t^2 """ @@ -530,8 +530,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = GF(49,'alpha')[[]] - sage: (t^2 + O(t^3)).base_ring() + sage: R. = GF(49,'alpha')[[]] # optional - sage.rings.finite_rings + sage: (t^2 + O(t^3)).base_ring() # optional - sage.rings.finite_rings Finite Field in alpha of size 7^2 """ return self._parent.base_ring() @@ -808,10 +808,10 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) + sage: f.truncate(5) # optional - sage.rings.finite_rings I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -1113,9 +1113,9 @@ cdef class PowerSeries(AlgebraElement): """ EXAMPLES:: - sage: R. = Qp(7)[[]] - sage: f = (48*67 + 46*67^2)*T + (1 + 42*67 + 5*67^3)*T^2 + O(T^3) - sage: f % 67 + sage: R. = Qp(7)[[]] # optional - sage.rings.padics + sage: f = (48*67 + 46*67^2)*T + (1 + 42*67 + 5*67^3)*T^2 + O(T^3) # optional - sage.rings.padics + sage: f % 67 # optional - sage.rings.padics T^2 + O(T^3) """ from sage.rings.power_series_ring import PowerSeriesRing @@ -1203,12 +1203,12 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') - sage: f = exp(x) + O(x^7); f + sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = exp(x) + O(x^7); f # optional - sage.libs.pari 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) - sage: f << 2 + sage: f << 2 # optional - sage.libs.pari x^2 + x^3 + 1/2*x^4 + 1/6*x^5 + 1/24*x^6 + 1/120*x^7 + 1/720*x^8 + O(x^9) - sage: (f << 99) >> 99 + sage: (f << 99) >> 99 # optional - sage.libs.pari 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) """ return self.shift(n) @@ -1221,15 +1221,15 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') - sage: f = exp(x) + O(x^7) - sage: f >> 3 + sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = exp(x) + O(x^7) # optional - sage.libs.pari + sage: f >> 3 # optional - sage.libs.pari 1/6 + 1/24*x + 1/120*x^2 + 1/720*x^3 + O(x^4) - sage: f >> 7 + sage: f >> 7 # optional - sage.libs.pari O(x^0) - sage: f >> 99 + sage: f >> 99 # optional - sage.libs.pari O(x^0) - sage: (f >> 99) << 99 + sage: (f >> 99) << 99 # optional - sage.libs.pari O(x^99) """ return self.shift(-n) @@ -1275,9 +1275,9 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = SR[[]] - sage: f = (1+I)*x^2 + 3*x - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = SR[[]] # optional - sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic I + 3*x + (-I + 1)*x^2 sage: R. = ZZ[[]] sage: f = x^2 + 2 @@ -1287,28 +1287,28 @@ cdef class PowerSeries(AlgebraElement): Examples with different base ring:: sage: R. = ZZ[[]] - sage: k = GF(2) - sage: residue = lambda x: k(x) - sage: f = 4*x^2+x+3 - sage: g = f.map_coefficients(residue); g + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: residue = lambda x: k(x) # optional - sage.rings.finite_rings + sage: f = 4*x^2+x+3 # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Power Series Ring in x over Integer Ring - sage: g = f.map_coefficients(residue, new_base_ring = k); g + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Power Series Ring in x over Finite Field of size 2 - sage: residue = k.coerce_map_from(ZZ) - sage: g = f.map_coefficients(residue); g + sage: residue = k.coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Power Series Ring in x over Finite Field of size 2 Tests other implementations:: - sage: R. = PowerSeriesRing(GF(11), implementation='pari') - sage: f = q - q^3 + O(q^10) - sage: f.map_coefficients(lambda c: c - 2) + sage: R. = PowerSeriesRing(GF(11), implementation='pari') # optional - sage.rings.finite_rings + sage: f = q - q^3 + O(q^10) # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda c: c - 2) # optional - sage.rings.finite_rings 10*q + 8*q^3 + O(q^10) """ pol = self.polynomial() @@ -1351,7 +1351,7 @@ cdef class PowerSeries(AlgebraElement): Another example:: - sage: (log(1+t)/t).jacobi_continued_fraction() + sage: (log(1+t)/t).jacobi_continued_fraction() # optional - sage.symbolic ((1/2, -1/12), (1/2, -1/15), (1/2, -9/140), @@ -1410,8 +1410,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: t = PowerSeriesRing(QQ, 't').gen() - sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) - sage: s.stieltjes_continued_fraction() + sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) # optional - sage.combinat + sage: s.stieltjes_continued_fraction() # optional - sage.combinat (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) Another example:: @@ -1773,11 +1773,11 @@ cdef class PowerSeries(AlgebraElement): Positive characteristic:: - sage: R. = GF(3)[[]] - sage: p = 1 + 2 * u^2 - sage: p.nth_root(4) + sage: R. = GF(3)[[]] # optional - sage.rings.finite_rings + sage: p = 1 + 2 * u^2 # optional - sage.rings.finite_rings + sage: p.nth_root(4) # optional - sage.rings.finite_rings 1 + 2*u^2 + u^6 + 2*u^8 + u^12 + 2*u^14 + O(u^20) - sage: p.nth_root(4)**4 + sage: p.nth_root(4)**4 # optional - sage.rings.finite_rings 1 + 2*u^2 + O(u^20) TESTS: @@ -1848,14 +1848,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cos(f) + sage: cos(f) # optional - sage.symbolic 1 - 1/2*t^2 - t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cos(f) + sage: cos(f) # optional - sage.symbolic 1 - 1/2*a^2 - a*b - 1/2*b^2 + O(a, b)^3 sage: f.cos() 1 - 1/2*a^2 - a*b - 1/2*b^2 + O(a, b)^3 @@ -1875,16 +1875,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cos(a) + sage: cos(a) # optional - sage.symbolic 1 - 1/2*a^2 + 1/24*a^4 - 1/720*a^6 + 1/40320*a^8 - 1/3628800*a^10 + O(a, b)^12 sage: a.cos(prec=5) 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cos(a + T.O(5)) + sage: cos(a + T.O(5)) # optional - sage.symbolic 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cos(a^2 + T.O(5)) + sage: cos(a^2 + T.O(5)) # optional - sage.symbolic 1 - 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1933,14 +1933,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sin(f) + sage: sin(f) # optional - sage.symbolic t + t^2 - 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) + sage: sin(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.sin() a + b + a*b + O(a, b)^3 @@ -1960,16 +1960,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sin(a) + sage: sin(a) # optional - sage.symbolic a - 1/6*a^3 + 1/120*a^5 - 1/5040*a^7 + 1/362880*a^9 - 1/39916800*a^11 + O(a, b)^12 sage: a.sin(prec=5) a - 1/6*a^3 + O(a, b)^5 - sage: sin(a + T.O(5)) + sage: sin(a + T.O(5)) # optional - sage.symbolic a - 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sin(a^2 + T.O(5)) + sage: sin(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ R = self.parent() @@ -2019,14 +2019,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tan(f) + sage: tan(f) # optional - sage.symbolic t + t^2 + 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tan(f) + sage: tan(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.tan() a + b + a*b + O(a, b)^3 @@ -2036,8 +2036,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: tan(g) + sage: g = 2 + f + sage: tan(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply tan to formal power series with zero constant term @@ -2046,16 +2046,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tan(a) + sage: tan(a) # optional - sage.symbolic a + 1/3*a^3 + 2/15*a^5 + 17/315*a^7 + 62/2835*a^9 + 1382/155925*a^11 + O(a, b)^12 sage: a.tan(prec=5) a + 1/3*a^3 + O(a, b)^5 - sage: tan(a + T.O(5)) + sage: tan(a + T.O(5)) # optional - sage.symbolic a + 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tan(a^2 + T.O(5)) + sage: tan(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ if not self[0].is_zero(): @@ -2083,14 +2083,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sinh(f) + sage: sinh(f) # optional - sage.symbolic t + t^2 + 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) + sage: sinh(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.sinh() a + b + a*b + O(a, b)^3 @@ -2100,8 +2100,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: sinh(g) + sage: g = 2 + f + sage: sinh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply sinh to formal power series with zero @@ -2111,17 +2111,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sinh(a) + sage: sinh(a) # optional - sage.symbolic a + 1/6*a^3 + 1/120*a^5 + 1/5040*a^7 + 1/362880*a^9 + 1/39916800*a^11 + O(a, b)^12 sage: a.sinh(prec=5) a + 1/6*a^3 + O(a, b)^5 - sage: sinh(a + T.O(5)) + sage: sinh(a + T.O(5)) # optional - sage.symbolic a + 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sinh(a^2 + T.O(5)) + sage: sinh(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ @@ -2172,14 +2172,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cosh(f) + sage: cosh(f) # optional - sage.symbolic 1 + 1/2*t^2 + t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cosh(f) + sage: cosh(f) # optional - sage.symbolic 1 + 1/2*a^2 + a*b + 1/2*b^2 + O(a, b)^3 sage: f.cosh() 1 + 1/2*a^2 + a*b + 1/2*b^2 + O(a, b)^3 @@ -2189,8 +2189,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: cosh(g) + sage: g = 2 + f + sage: cosh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply cosh to formal power series with zero @@ -2200,17 +2200,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cosh(a) + sage: cosh(a) # optional - sage.symbolic 1 + 1/2*a^2 + 1/24*a^4 + 1/720*a^6 + 1/40320*a^8 + 1/3628800*a^10 + O(a, b)^12 sage: a.cosh(prec=5) 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cosh(a + T.O(5)) + sage: cosh(a + T.O(5)) # optional - sage.symbolic 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cosh(a^2 + T.O(5)) + sage: cosh(a^2 + T.O(5)) # optional - sage.symbolic 1 + 1/2*a^4 + O(a, b)^5 """ @@ -2260,14 +2260,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tanh(f) + sage: tanh(f) # optional - sage.symbolic t + t^2 - 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tanh(f) + sage: tanh(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.tanh() a + b + a*b + O(a, b)^3 @@ -2277,8 +2277,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: tanh(g) + sage: g = 2 + f + sage: tanh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply tanh to formal power series with zero @@ -2288,17 +2288,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tanh(a) + sage: tanh(a) # optional - sage.symbolic a - 1/3*a^3 + 2/15*a^5 - 17/315*a^7 + 62/2835*a^9 - 1382/155925*a^11 + O(a, b)^12 sage: a.tanh(prec=5) a - 1/3*a^3 + O(a, b)^5 - sage: tanh(a + T.O(5)) + sage: tanh(a + T.O(5)) # optional - sage.symbolic a - 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tanh(a^2 + T.O(5)) + sage: tanh(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ @@ -2527,8 +2527,8 @@ cdef class PowerSeries(AlgebraElement): :: - sage: R. = PowerSeriesRing(GF(5)) - sage: (1 + x + O(x^2)).exp() + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: (1 + x + O(x^2)).exp() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: constant term of power series does not support exponentiation @@ -2578,7 +2578,7 @@ cdef class PowerSeries(AlgebraElement): sage: t.exp().log() t + O(t^10) - sage: (1+t).log().exp() + sage: (1 + t).log().exp() 1 + t + O(t^10) sage: (-1 + t + O(t^10)).log() @@ -2617,7 +2617,7 @@ cdef class PowerSeries(AlgebraElement): 1 + x^2 + x^10 sage: p.V(3) 1 + x^6 + x^30 - sage: (p+O(x^20)).V(3) + sage: (p + O(x^20)).V(3) 1 + x^6 + x^30 + O(x^60) """ v = self.list() @@ -2652,7 +2652,7 @@ cdef class PowerSeries(AlgebraElement): Dense examples:: sage: R. = PowerSeriesRing(ZZ) - sage: f = 17*t^100 +O(t^110) + sage: f = 17*t^100 + O(t^110) sage: f.valuation() 100 sage: t.valuation() @@ -2744,7 +2744,7 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: k. = QQ[[]] - sage: f = 1+17*w+15*w^3+O(w^5) + sage: f = 1 + 17*w + 15*w^3 + O(w^5) sage: parent(f) Power Series Ring in w over Rational Field sage: g = f.laurent_series(); g @@ -2790,27 +2790,27 @@ cdef class PowerSeries(AlgebraElement): There are currently limits to the possible base rings over which this function works. See the documentation for - ``sage.rings.polynomial.polynomial_element.Polynomial.__pari__`` + :meth:`~sage.rings.polynomial.polynomial_element.Polynomial.__pari__` EXAMPLES:: sage: k. = QQ[[]] - sage: f = 1+17*w+15*w^3+O(w^5) - sage: pari(f) # indirect doctest + sage: f = 1 + 17*w + 15*w^3 + O(w^5) + sage: pari(f) # indirect doctest # optional - sage.libs.pari 1 + 17*w + 15*w^3 + O(w^5) - sage: pari(1 - 19*w + w^5) # indirect doctest + sage: pari(1 - 19*w + w^5) # indirect doctest # optional - sage.libs.pari w^5 - 19*w + 1 sage: R. = Zmod(6)[[]] - sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest + sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest # optional - sage.libs.pari Mod(1, 6) + Mod(1, 6)*x + Mod(2, 6)*x^3 + O(x^8) TESTS:: - sage: pari(1 + O(x^1)) + sage: pari(1 + O(x^1)) # optional - sage.libs.pari Mod(1, 6) + O(x) - sage: pari(O(x^1)) + sage: pari(O(x^1)) # optional - sage.libs.pari O(x) - sage: pari(O(x^0)) + sage: pari(O(x^0)) # optional - sage.libs.pari O(x^0) """ n = self.prec() diff --git a/src/sage/rings/qqbar_decorators.py b/src/sage/rings/qqbar_decorators.py index 0f7a19bed50..27448c2def6 100644 --- a/src/sage/rings/qqbar_decorators.py +++ b/src/sage/rings/qqbar_decorators.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.number_field """ QQbar decorators diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 33df6cf2e37..b683889b79a 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -38,8 +38,8 @@ ....: def reduce(self,x): ....: R = self.ring() ....: return add([c*R(m) for m,c in x if len(m) = FreeAlgebra(QQ, 3) - sage: I3 = PowerIdeal(F,3); I3 + sage: F. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: I3 = PowerIdeal(F,3); I3 # optional - sage.combinat sage.modules Twosided Ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) of @@ -49,33 +49,33 @@ finite dimensional quotients defined by multiplication matrices. We are bypassing it, so that we obtain the default quotient:: - sage: Q3. = F.quotient(I3) - sage: Q3 + sage: Q3. = F.quotient(I3) # optional - sage.combinat sage.modules + sage: Q3 # optional - sage.combinat sage.modules Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) - sage: (a+b+2)^4 + sage: (a+b+2)^4 # optional - sage.combinat sage.modules 16 + 32*a + 32*b + 24*a^2 + 24*a*b + 24*b*a + 24*b^2 - sage: Q3.is_commutative() + sage: Q3.is_commutative() # optional - sage.combinat sage.modules False Even though `Q_3` is not commutative, there is commutativity for products of degree three:: - sage: a*(b*c)-(b*c)*a==F.zero() + sage: a*(b*c)-(b*c)*a==F.zero() # optional - sage.combinat sage.modules True If we quotient out all terms of degree two then of course the resulting quotient ring is commutative:: - sage: I2 = PowerIdeal(F,2); I2 + sage: I2 = PowerIdeal(F,2); I2 # optional - sage.combinat sage.modules Twosided Ideal (x^2, x*y, x*z, y*x, y^2, y*z, z*x, z*y, z^2) of Free Algebra on 3 generators (x, y, z) over Rational Field - sage: Q2. = F.quotient(I2) - sage: Q2.is_commutative() + sage: Q2. = F.quotient(I2) # optional - sage.combinat sage.modules + sage: Q2.is_commutative() # optional - sage.combinat sage.modules True - sage: (a+b+2)^4 + sage: (a+b+2)^4 # optional - sage.combinat sage.modules 16 + 32*a + 32*b Since :trac:`7797`, there is an implementation of free algebras @@ -84,16 +84,17 @@ easily:: sage: from itertools import product - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) - sage: Q3 - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) - sage: Q3.0*Q3.1-Q3.1*Q3.0 + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) # optional - sage.combinat sage.modules + sage: Q3 # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) + sage: Q3.0*Q3.1 - Q3.1*Q3.0 # optional - sage.combinat sage.modules xbar*ybar - ybar*xbar - sage: Q3.0*(Q3.1*Q3.2)-(Q3.1*Q3.2)*Q3.0 + sage: Q3.0*(Q3.1*Q3.2) - (Q3.1*Q3.2)*Q3.0 # optional - sage.combinat sage.modules 0 - sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) - sage: Q2.is_commutative() + sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) # optional - sage.combinat sage.modules + sage: Q2.is_commutative() # optional - sage.combinat sage.modules True """ @@ -157,7 +158,7 @@ def QuotientRing(R, I, names=None, **kwds): Some simple quotient rings with the integers:: - sage: R = QuotientRing(ZZ,7*ZZ); R + sage: R = QuotientRing(ZZ, 7*ZZ); R Quotient of Integer Ring by the ideal (7) sage: R.gens() (1,) @@ -177,13 +178,14 @@ def QuotientRing(R, I, names=None, **kwds): ring can be specified as shown below):: sage: P. = QQ[] - sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) - sage: R - Univariate Quotient Polynomial Ring in xx over Rational Field with modulus x^2 + 1 - sage: R.gens(); R.gen() + sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) # optional - sage.libs.pari + sage: R # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xx over Rational Field + with modulus x^2 + 1 + sage: R.gens(); R.gen() # optional - sage.libs.pari (xx,) xx - sage: for n in range(4): xx^n + sage: for n in range(4): xx^n # optional - sage.libs.pari 1 xx -1 @@ -192,13 +194,13 @@ def QuotientRing(R, I, names=None, **kwds): :: sage: P. = QQ[] - sage: S = QuotientRing(P, P.ideal(x^2 - 2)) - sage: S - Univariate Quotient Polynomial Ring in xbar over Rational Field with - modulus x^2 - 2 - sage: xbar = S.gen(); S.gen() + sage: S = QuotientRing(P, P.ideal(x^2 - 2)) # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 - 2 + sage: xbar = S.gen(); S.gen() # optional - sage.libs.pari xbar - sage: for n in range(3): xbar^n + sage: for n in range(3): xbar^n # optional - sage.libs.pari 1 xbar 2 @@ -206,25 +208,26 @@ def QuotientRing(R, I, names=None, **kwds): Sage coerces objects into ideals when possible:: sage: P. = QQ[] - sage: R = QuotientRing(P, x^2 + 1); R - Univariate Quotient Polynomial Ring in xbar over Rational Field with - modulus x^2 + 1 + sage: R = QuotientRing(P, x^2 + 1); R # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 + 1 By Noether's homomorphism theorems, the quotient of a quotient ring of `R` is just the quotient of `R` by the sum of the ideals. In this example, we end up modding out the ideal `(x)` from the ring `\QQ[x,y]`:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.pari + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.pari + sage: T # optional - sage.libs.pari + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.pari (x, y) (a, b) (0, d) - sage: for n in range(4): d^n + sage: for n in range(4): d^n # optional - sage.libs.pari 1 d -1 @@ -243,20 +246,23 @@ def QuotientRing(R, I, names=None, **kwds): Here is an example of the quotient of a free algebra by a twosided homogeneous ideal (see :trac:`7797`):: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c - sage: J = Q*[a^3-b^3]*Q - sage: R. = Q.quo(J); R - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal + (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) + sage: i^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 + sage: j^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k Check that :trac:`5978` is fixed by if we quotient by the zero ideal `(0)` @@ -342,12 +348,12 @@ def is_QuotientRing(x): :: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: is_QuotientRing(Q) + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: is_QuotientRing(Q) # optional - sage.combinat sage.modules True - sage: is_QuotientRing(F) + sage: is_QuotientRing(F) # optional - sage.combinat sage.modules False """ return isinstance(x, QuotientRing_nc) @@ -370,24 +376,26 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): Here is a quotient of a free algebra by a twosided homogeneous ideal:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2]*F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c A quotient of a quotient is just the quotient of the original top ring by the sum of two ideals:: - sage: J = Q*[a^3-b^3]*Q - sage: R. = Q.quo(J); R - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) + sage: i^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 + sage: j^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k For rings that *do* inherit from :class:`~sage.rings.ring.CommutativeRing`, @@ -399,15 +407,16 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): sage: R. = PolynomialRing(ZZ,'x') sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: S = R.quotient_ring(I); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) :: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2 + y^2) - sage: a^2 + b^2 == 0 + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: a^2 + b^2 == 0 # optional - sage.libs.singular True - sage: S(0) == a^2 + b^2 + sage: S(0) == a^2 + b^2 # optional - sage.libs.singular True Again, a quotient of a quotient is just the quotient of the original top @@ -415,12 +424,13 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: - sage: R. = PolynomialRing(QQ,2) - sage: S. = R.quo(1 + y^2) - sage: T. = S.quo(a) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: T.gens() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = R.quo(1 + y^2) # optional - sage.libs.singular + sage: T. = S.quo(a) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: T.gens() # optional - sage.libs.singular (0, d) """ Element = quotient_ring_element.QuotientRingElement @@ -438,13 +448,15 @@ def __init__(self, R, I, names, category=None): EXAMPLES:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of + Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c """ @@ -491,19 +503,20 @@ def construction(self): sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: R.quotient_ring(I).construction() (QuotientFunctor, Univariate Polynomial Ring in x over Integer Ring) - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.construction() - (QuotientFunctor, Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: Q.construction() # optional - sage.combinat sage.modules + (QuotientFunctor, + Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) TESTS:: sage: F, R = Integers(5).construction() sage: F(R) Ring of integers modulo 5 - sage: F, R = GF(5).construction() - sage: F(R) + sage: F, R = GF(5).construction() # optional - sage.rings.finite_rings + sage: F(R) # optional - sage.rings.finite_rings Finite Field of size 5 """ from sage.categories.pushout import QuotientFunctor @@ -575,19 +588,19 @@ def is_commutative(self): The non-commutative case is more interesting:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.is_commutative() + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: Q.is_commutative() # optional - sage.combinat sage.modules False - sage: Q.1*Q.2==Q.2*Q.1 + sage: Q.1*Q.2 == Q.2*Q.1 # optional - sage.combinat sage.modules False In the next example, the generators apparently commute:: - sage: J = F*[x*y-y*x,x*z-z*x,y*z-z*y,x^3-y^3]*F - sage: R = F.quo(J) - sage: R.is_commutative() + sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # optional - sage.combinat sage.modules + sage: R = F.quo(J) # optional - sage.combinat sage.modules + sage: R.is_commutative() # optional - sage.combinat sage.modules True """ @@ -610,12 +623,11 @@ def is_commutative(self): @cached_method def cover(self): r""" - The covering ring homomorphism `R \to R/I`, equipped with a - section. + The covering ring homomorphism `R \to R/I`, equipped with a section. EXAMPLES:: - sage: R = ZZ.quo(3*ZZ) + sage: R = ZZ.quo(3 * ZZ) sage: pi = R.cover() sage: pi Ring morphism: @@ -629,19 +641,20 @@ def cover(self): :: sage: R. = PolynomialRing(QQ) - sage: Q = R.quo( (x^2,y^2) ) - sage: pi = Q.cover() - sage: pi(x^3+y) + sage: Q = R.quo((x^2, y^2)) + sage: pi = Q.cover() # optional - sage.libs.singular + sage: pi(x^3 + y) # optional - sage.libs.singular ybar - sage: l = pi.lift(x+y^3) - sage: l + sage: l = pi.lift(x + y^3) # optional - sage.libs.singular + sage: l # optional - sage.libs.singular x - sage: l = pi.lift(); l + sage: l = pi.lift(); l # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: l(x+y^3) + sage: l(x + y^3) # optional - sage.libs.singular x """ try: @@ -663,40 +676,43 @@ def lifting_map(self): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: pi = S.cover(); pi + sage: pi = S.cover(); pi # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) Defn: Natural quotient map - sage: L = S.lifting_map(); L + sage: L = S.lifting_map(); L # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: L(S.0) + sage: L(S.0) # optional - sage.libs.singular x - sage: L(S.1) + sage: L(S.1) # optional - sage.libs.singular y Note that some reduction may be applied so that the lift of a reduction need not equal the original element:: - sage: z = pi(x^3 + 2*y^2); z + sage: z = pi(x^3 + 2*y^2); z # optional - sage.libs.singular -xbar*ybar^2 + 2*ybar^2 - sage: L(z) + sage: L(z) # optional - sage.libs.singular -x*y^2 + 2*y^2 - sage: L(z) == x^3 + 2*y^2 + sage: L(z) == x^3 + 2*y^2 # optional - sage.libs.singular False Test that there also is a lift for rings that are no instances of :class:`~sage.rings.ring.Ring` (see :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: Q.lift() + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.modules sage.rings.finite_rings + sage: I = MS * [MS.0*MS.1, MS.2 + MS.3] * MS # optional - sage.modules sage.rings.finite_rings + sage: Q = MS.quo(I) # optional - sage.modules sage.rings.finite_rings + sage: Q.lift() # optional - sage.modules sage.rings.finite_rings Set-theoretic ring morphism: - From: Quotient of Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 5 by the ideal + From: Quotient of Full MatrixSpace of 2 by 2 dense matrices + over Finite Field of size 5 by the ideal ( [0 1] [0 0], @@ -719,7 +735,7 @@ def lifting_map(self): return m # The following is to make the category framework happy. - def lift(self,x=None): + def lift(self, x=None): """ Return the lifting map to the cover, or the image of an element under the lifting map. @@ -735,12 +751,13 @@ def lift(self,x=None): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.lift() + sage: S.lift() # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift(S.0) == x + sage: S.lift(S.0) == x # optional - sage.libs.singular True """ @@ -764,7 +781,7 @@ def retract(self,x): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.retract((x+y)^2) + sage: S.retract((x+y)^2) # optional - sage.libs.singular 2*xbar*ybar """ @@ -804,12 +821,12 @@ def defining_ideal(self): homomorphism theorems, this is actually a quotient by a sum of two ideals:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: S.defining_ideal() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: S.defining_ideal() # optional - sage.libs.singular Ideal (y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: T.defining_ideal() + sage: T.defining_ideal() # optional - sage.libs.singular Ideal (x, y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field """ return self.__I @@ -822,15 +839,15 @@ def is_field(self, proof = True): TESTS:: - sage: Q = QuotientRing(ZZ,7*ZZ) - sage: Q.is_field() + sage: Q = QuotientRing(ZZ, 7*ZZ) + sage: Q.is_field() # optional - sage.libs.pari True Requires the ``is_maximal`` method of the defining ideal to be implemented:: sage: R. = ZZ[] - sage: R.quotient_ring(R.ideal([2, 4 +x])).is_field() + sage: R.quotient_ring(R.ideal([2, 4 + x])).is_field() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError @@ -857,19 +874,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = QQ[] - sage: R.quo(x^2 - y).is_integral_domain() + sage: R.quo(x^2 - y).is_integral_domain() # optional - sage.singular True - sage: R.quo(x^2 - y^2).is_integral_domain() + sage: R.quo(x^2 - y^2).is_integral_domain() # optional - sage.singular False - sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) + sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # optional - sage.singular False - sage: R. = ZZ[] - sage: Q = R.quotient_ring([a, b]) - sage: Q.is_integral_domain() + sage: R. = ZZ[] # optional - sage.singular + sage: Q = R.quotient_ring([a, b]) # optional - sage.singular + sage: Q.is_integral_domain() # optional - sage.singular Traceback (most recent call last): ... NotImplementedError - sage: Q.is_integral_domain(proof=False) + sage: Q.is_integral_domain(proof=False) # optional - sage.singular False """ if proof: @@ -886,13 +903,13 @@ def is_noetherian(self): EXAMPLES:: - sage: R = QuotientRing(ZZ, 102*ZZ) + sage: R = QuotientRing(ZZ, 102 * ZZ) sage: R.is_noetherian() True sage: P. = QQ[] - sage: R = QuotientRing(P, x^2+1) - sage: R.is_noetherian() + sage: R = QuotientRing(P, x^2 + 1) # optional - sage.libs.pari + sage: R.is_noetherian() # optional - sage.libs.pari True If the cover ring of ``self`` is not Noetherian, we currently @@ -903,8 +920,8 @@ def is_noetherian(self): sage: R.is_noetherian() False sage: I = R.ideal([x[1]^2, x[2]]) - sage: S = R.quotient(I) - sage: S.is_noetherian() + sage: S = R.quotient(I) # optional - sage.libs.pari + sage: S.is_noetherian() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError @@ -923,15 +940,15 @@ def cover_ring(self): EXAMPLES:: - sage: Q = QuotientRing(ZZ,7*ZZ) + sage: Q = QuotientRing(ZZ, 7 * ZZ) sage: Q.cover_ring() Integer Ring :: sage: P. = QQ[] - sage: Q = QuotientRing(P, x^2 + 1) - sage: Q.cover_ring() + sage: Q = QuotientRing(P, x^2 + 1) # optional - sage.libs.pari + sage: Q.cover_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Rational Field """ return self.__R @@ -946,11 +963,13 @@ def ideal(self, *gens, **kwds): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S.ideal() - Ideal (0) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: S.ideal(x+y+1) - Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + sage: S = R.quotient_ring(x^2 + y^2) + sage: S.ideal() # optional - sage.libs.pari + Ideal (0) of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) + sage: S.ideal(x + y + 1) # optional - sage.libs.pari + Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) TESTS: @@ -986,10 +1005,10 @@ def _element_constructor_(self, x, coerce=True): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S(x) # indirect doctest + sage: S = R.quotient_ring(x^2 + y^2) + sage: S(x) # indirect doctest # optional - sage.libs.singular xbar - sage: S(x^2 + y^2) + sage: S(x^2 + y^2) # optional - sage.libs.singular 0 The rings that coerce into the quotient ring canonically, are: @@ -1002,21 +1021,22 @@ def _element_constructor_(self, x, coerce=True): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: S.coerce(0) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: S.coerce(0) # optional - sage.libs.singular 0 - sage: S.coerce(2/3) + sage: S.coerce(2/3) # optional - sage.libs.singular 2/3 - sage: S.coerce(a^2 - b) + sage: S.coerce(a^2 - b) # optional - sage.libs.singular -b^2 - b - sage: S.coerce(GF(7)(3)) + sage: S.coerce(GF(7)(3)) # optional - sage.rings.finite_rings sage.libs.singular Traceback (most recent call last): ... - TypeError: no canonical coercion from Finite Field of size 7 to Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + TypeError: no canonical coercion from Finite Field of size 7 + to Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) TESTS:: - sage: S(x, coerce=False) + sage: S(x, coerce=False) # optional - sage.libs.singular a """ if isinstance(x, quotient_ring_element.QuotientRingElement): @@ -1039,15 +1059,15 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) + sage: S = R.quotient_ring(x^2 + y^2) sage: S.has_coerce_map_from(R) # indirect doctest True sage: S.has_coerce_map_from(QQ) True - sage: T = S.quotient_ring(x^3 - y) - sage: S.has_coerce_map_from(T) + sage: T = S.quotient_ring(x^3 - y) # optional - sage.libs.singular + sage: S.has_coerce_map_from(T) # optional - sage.libs.singular False - sage: T.has_coerce_map_from(R) + sage: T.has_coerce_map_from(R) # optional - sage.libs.singular True TESTS: @@ -1055,33 +1075,33 @@ def _coerce_map_from_(self, R): We check that :trac:`13682` is fixed:: sage: R. = PolynomialRing(QQ) - sage: I = R.ideal(x^2+y^2) - sage: J = R.ideal(x^2+y^2, x^3 - y) - sage: I < J + sage: I = R.ideal(x^2 + y^2) + sage: J = R.ideal(x^2 + y^2, x^3 - y) + sage: I < J # optional - sage.libs.singular True - sage: S = R.quotient(I) - sage: T = R.quotient(J) - sage: T.has_coerce_map_from(S) + sage: S = R.quotient(I) # optional - sage.libs.singular + sage: T = R.quotient(J) # optional - sage.libs.singular + sage: T.has_coerce_map_from(S) # optional - sage.libs.singular True - sage: S.quotient_ring(x^4-x*y+1).has_coerce_map_from(S) + sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) # optional - sage.libs.singular True - sage: S.has_coerce_map_from(T) + sage: S.has_coerce_map_from(T) # optional - sage.libs.singular False We also allow coercions with the cover rings:: sage: Rp. = PolynomialRing(ZZ) - sage: Ip = Rp.ideal(x^2+y^2) - sage: Jp = Rp.ideal(x^2+y^2, x^3 - y) - sage: Sp = Rp.quotient(Ip) - sage: Tp = Rp.quotient(Jp) - sage: R.has_coerce_map_from(Rp) + sage: Ip = Rp.ideal(x^2 + y^2) + sage: Jp = Rp.ideal(x^2 + y^2, x^3 - y) + sage: Sp = Rp.quotient(Ip) # optional - sage.libs.singular + sage: Tp = Rp.quotient(Jp) # optional - sage.libs.singular + sage: R.has_coerce_map_from(Rp) # optional - sage.libs.singular True - sage: Sp.has_coerce_map_from(Sp) + sage: Sp.has_coerce_map_from(Sp) # optional - sage.libs.singular True - sage: T.has_coerce_map_from(Sp) + sage: T.has_coerce_map_from(Sp) # optional - sage.libs.singular True - sage: Sp.has_coerce_map_from(T) + sage: Sp.has_coerce_map_from(T) # optional - sage.libs.singular False """ C = self.cover_ring() @@ -1113,9 +1133,9 @@ def __richcmp__(self, other, op): equal, but since the generators are different, the corresponding quotient rings are not equal:: - sage: R.ideal(x^2+y^2) == R.ideal(-x^2 - y^2) + sage: R.ideal(x^2 + y^2) == R.ideal(-x^2 - y^2) # optional - sage.libs.singular True - sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) + sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) # optional - sage.libs.singular False """ if not isinstance(other, QuotientRing_nc): @@ -1137,7 +1157,7 @@ def ngens(self): EXAMPLES:: - sage: R = QuotientRing(ZZ,7*ZZ) + sage: R = QuotientRing(ZZ, 7*ZZ) sage: R.gens(); R.ngens() (1,) 1 @@ -1145,15 +1165,16 @@ def ngens(self): :: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.singular (x, y) (a, b) (0, d) - sage: R.ngens(); S.ngens(); T.ngens() + sage: R.ngens(); S.ngens(); T.ngens() # optional - sage.libs.singular 2 2 2 @@ -1166,24 +1187,25 @@ def gen(self, i=0): EXAMPLES:: - sage: R = QuotientRing(ZZ,7*ZZ) + sage: R = QuotientRing(ZZ, 7*ZZ) sage: R.gen(0) 1 :: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gen(0); R.gen(1) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gen(0); R.gen(1) # optional - sage.libs.singular x y - sage: S.gen(0); S.gen(1) + sage: S.gen(0); S.gen(1) # optional - sage.libs.singular a b - sage: T.gen(0); T.gen(1) + sage: T.gen(0); T.gen(1) # optional - sage.libs.singular 0 d """ @@ -1209,8 +1231,8 @@ def _singular_(self, singular=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S._singular_() + sage: S = R.quotient_ring(x^2 + y^2) + sage: S._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 @@ -1243,11 +1265,11 @@ def _singular_init_(self, singular=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: T = S._singular_init_() - sage: parent(S) + sage: S = R.quotient_ring(x^2 + y^2) + sage: T = S._singular_init_() # optional - sage.libs.singular + sage: parent(S) # optional - sage.libs.singular - sage: parent(T) + sage: parent(T) # optional - sage.libs.singular Singular """ if singular is None: @@ -1267,9 +1289,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: magma(Q) # optional - magma # indirect doctest + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings + sage: magma(Q) # optional - magma # indirect doctest # optional - sage.rings.finite_rings Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y @@ -1307,7 +1329,8 @@ class QuotientRing_generic(QuotientRing_nc, ring.CommutativeRing): sage: R. = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: S = R.quotient_ring(I); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) """ def __init__(self, R, I, names, category=None): @@ -1361,11 +1384,12 @@ def _macaulay2_init_(self, macaulay2=None): 2 2 2 (x*y - z , y - w ) - sage: R. = PolynomialRing(GF(101), 2) - sage: I = R.ideal([x^2 + x, y^2 + y]) - sage: Q = R.quotient_ring(I); Q - Quotient of Multivariate Polynomial Ring in x, y over Finite Field of size 101 by the ideal (x^2 + x, y^2 + y) - sage: Q._macaulay2_init_() # optional - macaulay2 + sage: R. = PolynomialRing(GF(101), 2) # optional - sage.rings.finite_rings + sage: I = R.ideal([x^2 + x, y^2 + y]) # optional - sage.rings.finite_rings + sage: Q = R.quotient_ring(I); Q # optional - sage.rings.finite_rings + Quotient of Multivariate Polynomial Ring in x, y over + Finite Field of size 101 by the ideal (x^2 + x, y^2 + y) + sage: Q._macaulay2_init_() # optional - macaulay2 # optional - sage.rings.finite_rings ZZ ---[x...y] 101 @@ -1439,12 +1463,12 @@ def _contains_(self, other): :: sage: R. = QQ[] - sage: S. = R.quotient(T^3-1) - sage: 1 in S.ideal(t^2-1) + sage: S. = R.quotient(T^3 - 1) # optional - sage.libs.pari + sage: 1 in S.ideal(t^2 - 1) # optional - sage.libs.pari False - sage: 7 in S.ideal(t^2+1) + sage: 7 in S.ideal(t^2 + 1) # optional - sage.libs.pari True - sage: 5-5*t in S.ideal(t^2-1) + sage: 5-5*t in S.ideal(t^2 - 1) # optional - sage.libs.pari True """ R = self.ring() diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 05cc52e7681..67adb330e23 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -45,7 +45,8 @@ class QuotientRingElement(RingElement): sage: R. = PolynomialRing(ZZ) sage: S. = R.quo((4 + 3*x + x^2, 1 + x^2)); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) sage: v = S.gens(); v (xbar,) @@ -58,24 +59,25 @@ class QuotientRingElement(RingElement): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quo(x^2 + y^2); S - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: S.gens() + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) + sage: S.gens() # optional - sage.libs.singular (xbar, ybar) We name each of the generators. :: - sage: S. = R.quotient(x^2 + y^2) - sage: a + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: a # optional - sage.libs.singular a - sage: b + sage: b # optional - sage.libs.singular b - sage: a^2 + b^2 == 0 + sage: a^2 + b^2 == 0 # optional - sage.libs.singular True - sage: b.lift() + sage: b.lift() # optional - sage.libs.singular y - sage: (a^3 + b^2).lift() + sage: (a^3 + b^2).lift() # optional - sage.libs.singular -x*y^2 + y^2 """ def __init__(self, parent, rep, reduce=True): @@ -87,7 +89,8 @@ def __init__(self, parent, rep, reduce=True): sage: R. = PolynomialRing(ZZ) sage: S. = R.quo((4 + 3*x + x^2, 1 + x^2)); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) sage: v = S.gens(); v (xbar,) """ @@ -106,10 +109,10 @@ def _reduce_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a._reduce_() - sage: a._QuotientRingElement__rep + sage: a._reduce_() # optional - sage.libs.singular + sage: a._QuotientRingElement__rep # optional - sage.libs.singular x """ I = self.parent().defining_ideal() @@ -122,11 +125,11 @@ def lift(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.lift() + sage: a.lift() # optional - sage.libs.singular x - sage: (3/5*(a + a^2 + b^2)).lift() + sage: (3/5*(a + a^2 + b^2)).lift() # optional - sage.libs.singular 3/5*x """ return self.__rep @@ -139,16 +142,16 @@ def __bool__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: bool(a) # indirect doctest + sage: bool(a) # indirect doctest # optional - sage.libs.singular True - sage: bool(S(0)) + sage: bool(S(0)) # optional - sage.libs.singular False TESTS:: - sage: bool(a - a) + sage: bool(a - a) # optional - sage.libs.singular False """ return self.__rep not in self.parent().defining_ideal() @@ -159,18 +162,18 @@ def is_unit(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) + sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) # optional - sage.libs.singular - sage: a*b + sage: a*b # optional - sage.libs.singular 1 - sage: S(2).is_unit() + sage: S(2).is_unit() # optional - sage.libs.singular True Check that :trac:`29469` is fixed:: - sage: a.is_unit() + sage: a.is_unit() # optional - sage.libs.singular True - sage: (a+b).is_unit() + sage: (a+b).is_unit() # optional - sage.libs.singular False """ if self.__rep.is_unit(): @@ -191,18 +194,18 @@ def _repr_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a-2*a*b # indirect doctest + sage: a-2*a*b # indirect doctest # optional - sage.libs.singular -2*a*b + a In :trac:`11068`, the case of quotient rings without assigned names has been covered as well:: - sage: S = SteenrodAlgebra(2) - sage: I = S*[S.0+S.1]*S - sage: Q = S.quo(I) - sage: Q.0 + sage: S = SteenrodAlgebra(2) # optional - sage.libs.singular + sage: I = S * [S.0 + S.1] * S # optional - sage.libs.singular + sage: Q = S.quo(I) # optional - sage.libs.singular + sage: Q.0 # optional - sage.libs.singular Sq(1) """ @@ -232,8 +235,8 @@ def _latex_(self): sage: a = R.gen(0) sage: I = R.ideal(a**2 + a + 1) sage: S = R.quotient(I, names=R.variable_names()) - sage: a = S.gen(0) - sage: latex(a) + sage: a = S.gen(0) # optional - sage.libs.singular + sage: latex(a) # optional - sage.libs.singular a """ from sage.structure.parent_gens import localvars @@ -257,20 +260,20 @@ def __pari__(self): EXAMPLES:: sage: R. = QQ[] - sage: I = R.ideal(x^3,y^3) - sage: S. = R.quo(I) - sage: pari(xb) + sage: I = R.ideal(x^3, y^3) + sage: S. = R.quo(I) # optional - sage.libs.singular + sage: pari(xb) # optional - sage.libs.pari sage.libs.singular Traceback (most recent call last): ... ValueError: Pari does not support quotients by non-principal ideals Note that the quotient does work in the case that the ideal is principal:: - sage: I = R.ideal(x^3+y^3) - sage: S. = R.quo(I) - sage: pari(xb)^4 + sage: I = R.ideal(x^3 + y^3) + sage: S. = R.quo(I) # optional - sage.libs.singular + sage: pari(xb)^4 # optional - sage.libs.pari sage.libs.singular Mod(-y^3*x, x^3 + y^3) - sage: pari(yb)^4 + sage: pari(yb)^4 # optional - sage.libs.pari sage.libs.singular Mod(y^4, x^3 + y^3) """ gens = self.parent().defining_ideal().gens() @@ -286,14 +289,14 @@ def _add_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a + b + sage: a + b # optional - sage.libs.singular a + b TESTS:: - sage: a._add_(b) + sage: a._add_(b) # optional - sage.libs.singular a + b """ return self.__class__(self.parent(), self.__rep + right.__rep) @@ -306,14 +309,14 @@ def _sub_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a - b + sage: a - b # optional - sage.libs.singular a - b TESTS:: - sage: a._sub_(b) + sage: a._sub_(b) # optional - sage.libs.singular a - b """ return self.__class__(self.parent(), self.__rep - right.__rep) @@ -326,16 +329,16 @@ def _mul_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a * b + sage: a * b # optional - sage.libs.singular a*b TESTS:: - sage: a._mul_(b) + sage: a._mul_(b) # optional - sage.libs.singular a*b - sage: a._mul_(a) + sage: a._mul_(a) # optional - sage.libs.singular -b^2 """ return self.__class__(self.parent(), self.__rep * right.__rep) @@ -350,30 +353,30 @@ def _div_(self, right): sage: R. = QQ[] sage: I = R.ideal([x^2 + 1, y^3 - 2]) - sage: S. = R.quotient(I) - sage: 1/(1+i) + sage: S. = R.quotient(I) # optional - sage.libs.singular + sage: 1/(1+i) # optional - sage.libs.singular -1/2*i + 1/2 Confirm via symbolic computation:: - sage: 1/(1+sqrt(-1)) + sage: 1/(1+sqrt(-1)) # optional - sage.symbolic -1/2*I + 1/2 Another more complicated quotient:: - sage: b = 1/(i+cuberoot); b + sage: b = 1/(i+cuberoot); b # optional - sage.libs.singular 1/5*i*cuberoot^2 - 2/5*i*cuberoot + 2/5*cuberoot^2 - 1/5*i + 1/5*cuberoot - 2/5 - sage: b*(i+cuberoot) + sage: b*(i+cuberoot) # optional - sage.libs.singular 1 Another really easy example:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a / S(2) + sage: a / S(2) # optional - sage.libs.singular 1/2*a - sage: (a*b)._div_(b) + sage: (a*b)._div_(b) # optional - sage.libs.singular a An example in which we try to divide in a ring that is not a @@ -381,18 +384,18 @@ def _div_(self, right): sage: R. = QQ[] sage: I = R.ideal([x^2 - 1, y^3 - 2]) - sage: S. = R.quotient(I) - sage: 1/cuberoot + sage: S. = R.quotient(I) # optional - sage.libs.singular + sage: 1/cuberoot # optional - sage.libs.singular 1/2*cuberoot^2 - sage: 1/a + sage: 1/a # optional - sage.libs.singular a Check that :trac:`13670` is fixed (i.e. that the error message actually describes what happens when the result of division is not defined):: sage: R. = QQ[] - sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) - sage: 1 / S(x1 + x2) + sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) # optional - sage.libs.singular + sage: 1 / S(x1 + x2) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: Division failed. The numerator is not a multiple of the denominator. @@ -404,7 +407,7 @@ def _div_(self, right): sage: R. = QQ[] sage: S. = R[] - sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) + sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: Can only reduce polynomials over fields. @@ -472,15 +475,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None): quotient ring work correctly (see :trac:`16135`):: sage: R. = QQ[] - sage: K = R.quotient(x^2 - y^3).fraction_field() + sage: K = R.quotient(x^2 - y^3).fraction_field() # optional - sage.libs.singular sage: L. = FunctionField(QQ) - sage: f = K.hom((t^3, t^2)) - sage: list(map(f, K.gens())) + sage: f = K.hom((t^3, t^2)) # optional - sage.libs.singular + sage: list(map(f, K.gens())) # optional - sage.libs.singular [t^3, t^2] - sage: xbar, ybar = K.gens() - sage: f(1/ybar) + sage: xbar, ybar = K.gens() # optional - sage.libs.singular + sage: f(1/ybar) # optional - sage.libs.singular 1/t^2 - sage: f(xbar/ybar) + sage: f(xbar/ybar) # optional - sage.libs.singular t """ return self.lift()._im_gens_(codomain, im_gens, base_map=base_map) @@ -493,13 +496,13 @@ def __int__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: int(S(-3)) # indirect doctest + sage: int(S(-3)) # indirect doctest # optional - sage.libs.singular -3 - sage: type(int(S(-3))) + sage: type(int(S(-3))) # optional - sage.libs.singular <... 'int'> - sage: int(a) + sage: int(a) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -510,14 +513,14 @@ def _integer_(self, Z): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: ZZ(S(-3)) + sage: ZZ(S(-3)) # optional - sage.libs.singular -3 TESTS:: - sage: type(ZZ(S(-3))) + sage: type(ZZ(S(-3))) # optional - sage.libs.singular """ return Z(self.lift()) @@ -526,14 +529,14 @@ def _rational_(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: QQ(S(-2/3)) + sage: QQ(S(-2/3)) # optional - sage.libs.singular -2/3 TESTS:: - sage: type(S(-2/3)._rational_()) + sage: type(S(-2/3)._rational_()) # optional - sage.libs.singular """ from sage.rings.rational_field import QQ @@ -543,11 +546,11 @@ def __neg__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: -a # indirect doctest + sage: -a # indirect doctest # optional - sage.libs.singular -a - sage: -(a+b) + sage: -(a+b) # optional - sage.libs.singular -a - b """ return self.__class__(self.parent(), -self.__rep) @@ -556,11 +559,11 @@ def __pos__(self): """ TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+b).__pos__() + sage: (a+b).__pos__() # optional - sage.libs.singular a + b - sage: c = a+b; c.__pos__() is c + sage: c = a+b; c.__pos__() is c # optional - sage.libs.singular True """ return self @@ -569,19 +572,19 @@ def __invert__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: ~S(2/3) + sage: ~S(2/3) # optional - sage.libs.singular 3/2 TESTS:: - sage: S(2/3).__invert__() + sage: S(2/3).__invert__() # optional - sage.libs.singular 3/2 Note that a is not invertible as an element of R:: - sage: a.__invert__() + sage: a.__invert__() # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -596,11 +599,11 @@ def __float__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: float(S(2/3)) + sage: float(S(2/3)) # optional - sage.libs.singular 0.6666666666666666 - sage: float(a) + sage: float(a) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -611,10 +614,10 @@ def __hash__(self): r""" TESTS:: - sage: R. = QQ[] - sage: S. = R.quo(x^2 + y^2) - sage: c = a*a + b - sage: hash(a) != hash(b) + sage: R. = QQ[] # optional - sage.libs.singular + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: c = a*a + b # optional - sage.libs.singular + sage: hash(a) != hash(b) # optional - sage.libs.singular True """ return hash(self.__rep) @@ -623,38 +626,38 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a > b # indirect doctest + sage: a > b # indirect doctest # optional - sage.libs.singular True - sage: b > a + sage: b > a # optional - sage.libs.singular False - sage: a == loads(dumps(a)) + sage: a == loads(dumps(a)) # optional - sage.libs.singular True TESTS:: - sage: a == (a+1-1) + sage: a == (a+1-1) # optional - sage.libs.singular True - sage: a > b + sage: a > b # optional - sage.libs.singular True See :trac:`7797`:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.0^4 # indirect doctest + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular + sage: Q.0^4 # indirect doctest # optional - sage.combinat sage.libs.singular ybar*zbar*zbar*xbar + ybar*zbar*zbar*ybar + ybar*zbar*zbar*zbar The issue from :trac:`8005` was most likely fixed as part of :trac:`9138`:: - sage: F = GF(5) - sage: R.=F[] - sage: I=Ideal(R, [x, y]) - sage: S.=QuotientRing(R,I) - sage: x1^4 + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: R. = F[] # optional - sage.rings.finite_rings + sage: I = Ideal(R, [x, y]) # optional - sage.rings.finite_rings + sage: S. = QuotientRing(R, I) # optional - sage.rings.finite_rings + sage: x1^4 # optional - sage.rings.finite_rings 0 """ # A containment test is not implemented for univariate polynomial @@ -677,18 +680,18 @@ def lt(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lt() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings + sage: Q = R.quo(I) # optional - sage.rings.finite_rings + sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings + sage: f.lt() # optional - sage.rings.finite_rings 2*xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lt() + sage: (a + 3*a*b + b).lt() # optional - sage.libs.singular 3*a*b """ return self.__class__(self.parent(), self.__rep.lt()) @@ -699,18 +702,18 @@ def lm(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lm() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings + sage: Q = R.quo(I) # optional - sage.rings.finite_rings + sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings + sage: f.lm() # optional - sage.rings.finite_rings xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lm() + sage: (a+3*a*b+b).lm() # optional - sage.libs.singular a*b """ @@ -722,18 +725,18 @@ def lc(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lc() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings + sage: Q = R.quo(I) # optional - sage.rings.finite_rings + sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings + sage: f.lc() # optional - sage.rings.finite_rings 2 TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lc() + sage: (a + 3*a*b + b).lc() # optional - sage.libs.singular 3 """ return self.__rep.lc() @@ -749,17 +752,17 @@ def variables(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.variables() + sage: a.variables() # optional - sage.libs.singular (a,) - sage: b.variables() + sage: b.variables() # optional - sage.libs.singular (b,) - sage: s = a^2 + b^2 + 1; s + sage: s = a^2 + b^2 + 1; s # optional - sage.libs.singular 1 - sage: s.variables() + sage: s.variables() # optional - sage.libs.singular () - sage: (a+b).variables() + sage: (a + b).variables() # optional - sage.libs.singular (a, b) """ return tuple(self.__class__(self.parent(), v) for v in self.__rep.variables()) @@ -774,13 +777,13 @@ def monomials(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.monomials() + sage: a.monomials() # optional - sage.libs.singular [a] - sage: (a+a*b).monomials() + sage: (a + a*b).monomials() # optional - sage.libs.singular [a*b, a] - sage: R.zero().monomials() + sage: R.zero().monomials() # optional - sage.libs.singular [] """ return [self.__class__(self.parent(), m) for m in self.__rep.monomials()] @@ -796,10 +799,10 @@ def _singular_(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(2),2) - sage: I = sage.rings.ideal.FieldIdeal(P) - sage: Q = P.quo(I) - sage: Q._singular_() + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P) # optional - sage.rings.finite_rings + sage: Q = P.quo(I) # optional - sage.rings.finite_rings + sage: Q._singular_() # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/2 // number of vars : 2 @@ -809,20 +812,20 @@ def _singular_(self, singular=singular_default): // quotient ring from ideal _[1]=x2+x _[2]=y2+y - sage: xbar = Q(x); xbar + sage: xbar = Q(x); xbar # optional - sage.rings.finite_rings xbar - sage: xbar._singular_() + sage: xbar._singular_() # optional - sage.rings.finite_rings x - sage: Q(xbar._singular_()) # a round-trip + sage: Q(xbar._singular_()) # a round-trip # optional - sage.rings.finite_rings xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a-2/3*b)._singular_() + sage: (a - 2/3*b)._singular_() # optional - sage.libs.singular x-2/3*y - sage: S((a-2/3*b)._singular_()) + sage: S((a - 2/3*b)._singular_()) # optional - sage.libs.singular a - 2/3*b """ if singular is None: @@ -835,12 +838,12 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: xbar, ybar = Q.gens() - sage: magma(xbar) # optional -- magma + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings + sage: xbar, ybar = Q.gens() # optional - sage.rings.finite_rings + sage: magma(xbar) # optional - magma # optional - sage.rings.finite_rings x - sage: xbar._magma_init_(magma) # optional -- magma + sage: xbar._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings '_sage_[...]!_sage_ref...' """ g = magma(self.__rep) @@ -853,19 +856,19 @@ def _macaulay2_(self, macaulay2=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y]) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7; f + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: Q = R.quotient([x^2 - y]) # optional - sage.rings.finite_rings + sage: x, y = Q.gens() # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.rings.finite_rings 2*xbar*ybar^17 + xbar*ybar^10 - sage: mf = macaulay2(f); mf # optional - macaulay2 + sage: mf = macaulay2(f); mf # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: mf.sage() # optional - macaulay2 + sage: mf.sage() # optional - macaulay2 # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 - sage: mf.sage() == f # optional - macaulay2 + sage: mf.sage() == f # optional - macaulay2 # optional - sage.rings.finite_rings True - sage: Q(mf) # optional - macaulay2 + sage: Q(mf) # optional - macaulay2 # optional - sage.rings.finite_rings 2*xbar*ybar^17 + xbar*ybar^10 In Macaulay2, the variable names for a quotient ring are inherited from @@ -877,15 +880,15 @@ def _macaulay2_(self, macaulay2=None): :: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y], names=R.gens()) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7; f + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.rings.finite_rings + sage: x, y = Q.gens() # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 - sage: macaulay2(f) # optional - macaulay2 + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: _.sage() # optional - macaulay2 + sage: _.sage() # optional - macaulay2 # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 TESTS: @@ -893,15 +896,15 @@ def _macaulay2_(self, macaulay2=None): Check that changing the currently defined global variables (`x`, `y`, ...) in Macaulay2 does not affect the result of this conversion:: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y], names=R.gens()) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7 - sage: macaulay2(f) # optional - macaulay2 + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.rings.finite_rings + sage: x, y = Q.gens() # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*y^2*x)^7 # optional - sage.rings.finite_rings + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 - sage: macaulay2(f) # optional - macaulay2 + sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 # optional - sage.rings.finite_rings + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y """ @@ -930,17 +933,18 @@ def reduce(self, G): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 5, order='lex') - sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, a*b*e + c*e, b*c + c*d*e + 1]) - sage: Q = P.quotient( sage.rings.ideal.FieldIdeal(P) ) - sage: I2 = ideal([Q(f) for f in I1.gens()]) - sage: f = Q((a*b + c*d + 1)^2 + e) - sage: f.reduce(I2.gens()) + sage: P. = PolynomialRing(GF(2), 5, order='lex') # optional - sage.rings.finite_rings + sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, # optional - sage.rings.finite_rings + ....: a*b*e + c*e, b*c + c*d*e + 1]) + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings + sage: I2 = ideal([Q(f) for f in I1.gens()]) # optional - sage.rings.finite_rings + sage: f = Q((a*b + c*d + 1)^2 + e) # optional - sage.rings.finite_rings + sage: f.reduce(I2.gens()) # optional - sage.rings.finite_rings ebar Notice that the result above is not minimal:: - sage: I2.reduce(f) + sage: I2.reduce(f) # optional - sage.rings.finite_rings 0 """ try: diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 0e9d1f35f47..08eda1849a0 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -300,30 +300,31 @@ cpdef rational_power_parts(a, Rational b, factor_limit=10**5): sage: rational_power_parts(3/4, -1/2) (2, 3) - sage: t = (3/4)^(-1/2); t + sage: t = (3/4)^(-1/2); t # optional - sage.symbolic 2/3*sqrt(3) - sage: t^2 + sage: t^2 # optional - sage.symbolic 4/3 Check if :trac:`15605` is fixed:: sage: rational_power_parts(-1, -1/3) (1, -1) - sage: (-1)^(-1/3) + sage: (-1)^(-1/3) # optional - sage.symbolic -(-1)^(2/3) - sage: 1 / ((-1)^(1/3)) + sage: 1 / ((-1)^(1/3)) # optional - sage.symbolic -(-1)^(2/3) sage: rational_power_parts(-1, 2/3) (1, -1) - sage: (-1)^(2/3) + sage: (-1)^(2/3) # optional - sage.symbolic (-1)^(2/3) sage: all(rational_power_parts(-1, i/77) == (1,-1) for i in range(1,9)) True - sage: (-1)^(1/3)*(-1)^(1/5) + sage: (-1)^(1/3)*(-1)^(1/5) # optional - sage.symbolic (-1)^(8/15) - sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) + sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) # optional - sage.symbolic True - sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) for p in srange(1,6) for q in srange(1,6)) + sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) # optional - sage.symbolic + ....: for p in srange(1, 6) for q in srange(1, 6)) True A few more tests added in :trac:`26414`:: @@ -422,9 +423,10 @@ cdef class Rational(sage.structure.element.FieldElement): 1/2 sage: Rational(("2", "10"), 16) 1/8 - sage: Rational(QQbar(125/8).nth_root(3)) + sage: Rational(QQbar(125/8).nth_root(3)) # optional - sage.rings.number_field 5/2 - sage: Rational(AA(209735/343 - 17910/49*golden_ratio).nth_root(3) + 3*AA(golden_ratio)) + sage: Rational(AA(209735/343 - 17910/49*golden_ratio).nth_root(3) # optional - sage.rings.number_field + ....: + 3*AA(golden_ratio)) 53/7 sage: QQ(float(1.5)) 3/2 @@ -440,24 +442,24 @@ cdef class Rational(sage.structure.element.FieldElement): Conversion from PARI:: - sage: Rational(pari('-939082/3992923')) + sage: Rational(pari('-939082/3992923')) # optional - sage.libs.pari -939082/3992923 - sage: Rational(pari('Pol([-1/2])')) #9595 + sage: Rational(pari('Pol([-1/2])')) #9595 # optional - sage.libs.pari -1/2 Conversions from numpy:: - sage: import numpy as np - sage: QQ(np.int8('-15')) + sage: import numpy as np # optional - numpy + sage: QQ(np.int8('-15')) # optional - numpy -15 - sage: QQ(np.int16('-32')) + sage: QQ(np.int16('-32')) # optional - numpy -32 - sage: QQ(np.int32('-19')) + sage: QQ(np.int32('-19')) # optional - numpy -19 - sage: QQ(np.uint32('1412')) + sage: QQ(np.uint32('1412')) # optional - numpy 1412 - sage: QQ(np.float16('12')) + sage: QQ(np.float16('12')) # optional - numpy 12 Conversions from gmpy2:: @@ -512,7 +514,7 @@ cdef class Rational(sage.structure.element.FieldElement): 7 sage: a.__init__('70', base=8); a 56 - sage: a.__init__(pari('2/3')); a + sage: a.__init__(pari('2/3')); a # optional - sage.libs.pari 2/3 sage: a.__init__('-h/3ki', 32); a -17/3730 @@ -963,9 +965,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: ex = SR(QQ(7)/3); ex + sage: ex = SR(QQ(7)/3); ex # optional - sage.symbolic 7/3 - sage: parent(ex) + sage: parent(ex) # optional - sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -976,12 +978,12 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: n = 1/2; n._sympy_() + sage: n = 1/2; n._sympy_() # optional - sympy 1/2 - sage: n = -1/5; n._sympy_() + sage: n = -1/5; n._sympy_() # optional - sympy -1/5 - sage: from sympy import Symbol - sage: QQ(1)+Symbol('x')*QQ(2) + sage: from sympy import Symbol # optional - sympy + sage: QQ(1) + Symbol('x')*QQ(2) # optional - sympy 2*x + 1 """ import sympy @@ -1035,7 +1037,7 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: n = -485/82847 - sage: n._magma_init_(magma) # optional - magma + sage: n._magma_init_(magma) # optional - magma '-485/82847' """ return self.numerator()._magma_init_(magma) + '/' + self.denominator()._magma_init_(magma) @@ -1049,16 +1051,16 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1, 2, 3/1]) + sage: import numpy # optional - numpy + sage: numpy.array([1, 2, 3/1]) # optional - numpy array([1, 2, 3]) - sage: numpy.array(QQ(2**40)).dtype + sage: numpy.array(QQ(2**40)).dtype # optional - numpy dtype('int64') - sage: numpy.array(QQ(2**400)).dtype + sage: numpy.array(QQ(2**400)).dtype # optional - numpy dtype('O') - sage: numpy.array([1, 1/2, 3/4]) + sage: numpy.array([1, 1/2, 3/4]) # optional - numpy array([1. , 0.5 , 0.75]) """ if mpz_cmp_ui(mpq_denref(self.value), 1) == 0: @@ -1114,7 +1116,7 @@ cdef class Rational(sage.structure.element.FieldElement): def content(self, other): """ - Return the content of ``self`` and ``other``, i.e. the unique positive + Return the content of ``self`` and ``other``, i.e., the unique positive rational number `c` such that ``self/c`` and ``other/c`` are coprime integers. @@ -1191,7 +1193,7 @@ cdef class Rational(sage.structure.element.FieldElement): - ``p`` -- a prime number - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1228,7 +1230,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1264,7 +1266,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1307,7 +1309,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1402,11 +1404,11 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - - ``L`` -- a number field - - ``element`` -- (default: ``False``) boolean whether to also output - an element of which ``self`` is a norm - - proof -- If ``True``, then the output is correct unconditionally. - If ``False``, then the output assumes GRH. + - ``L`` -- a number field + - ``element`` -- (default: ``False``) boolean whether to also output + an element of which ``self`` is a norm + - ``proof`` -- If ``True``, then the output is correct unconditionally. + If ``False``, then the output assumes GRH. OUTPUT: @@ -1418,46 +1420,47 @@ cdef class Rational(sage.structure.element.FieldElement): ALGORITHM: - Uses PARI's bnfisnorm. See ``_bnfisnorm()``. + Uses the PARI function :pari:`bnfisnorm`. See :meth:`_bnfisnorm()`. EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') - sage: (1/7).is_norm(K) + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: (1/7).is_norm(K) # optional - sage.rings.number_field True - sage: (1/10).is_norm(K) + sage: (1/10).is_norm(K) # optional - sage.rings.number_field False - sage: 0.is_norm(K) + sage: 0.is_norm(K) # optional - sage.rings.number_field True - sage: (1/7).is_norm(K, element=True) + sage: (1/7).is_norm(K, element=True) # optional - sage.rings.number_field (True, 1/7*beta + 3/7) - sage: (1/10).is_norm(K, element=True) + sage: (1/10).is_norm(K, element=True) # optional - sage.rings.number_field (False, None) - sage: (1/691).is_norm(QQ, element=True) + sage: (1/691).is_norm(QQ, element=True) # optional - sage.rings.number_field (True, 1/691) The number field doesn't have to be defined by an integral polynomial:: - sage: B, e = (1/5).is_norm(QuadraticField(5/4, 'a'), element=True) - sage: B + sage: B, e = (1/5).is_norm(QuadraticField(5/4, 'a'), element=True) # optional - sage.rings.number_field + sage: B # optional - sage.rings.number_field True - sage: e.norm() + sage: e.norm() # optional - sage.rings.number_field 1/5 A non-Galois number field:: - sage: K. = NumberField(x^3-2) - sage: B, e = (3/5).is_norm(K, element=True); B + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: B, e = (3/5).is_norm(K, element=True); B # optional - sage.rings.number_field True - sage: e.norm() + sage: e.norm() # optional - sage.rings.number_field 3/5 - sage: 7.is_norm(K) + sage: 7.is_norm(K) # optional - sage.rings.number_field Traceback (most recent call last): ... - NotImplementedError: is_norm is not implemented unconditionally for norms from non-Galois number fields - sage: 7.is_norm(K, proof=False) + NotImplementedError: is_norm is not implemented unconditionally + for norms from non-Galois number fields + sage: 7.is_norm(K, proof=False) # optional - sage.rings.number_field False AUTHORS: @@ -1540,9 +1543,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) + sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field (i + 1, 1) - sage: 7._bnfisnorm(NumberField(x^3-2, 'b')) + sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # optional - sage.rings.number_field (1, 7) AUTHORS: @@ -1609,9 +1612,9 @@ cdef class Rational(sage.structure.element.FieldElement): This test makes sure we workaround a bug in GMP (see :trac:`4612`):: - sage: [ -a for a in srange(100) if not QQ(-a^3).is_perfect_power() ] + sage: [-a for a in srange(100) if not QQ(-a^3).is_perfect_power()] [] - sage: [ -a for a in srange(100) if not QQ(-a^3).is_perfect_power(True) ] + sage: [-a for a in srange(100) if not QQ(-a^3).is_perfect_power(True)] [] """ cdef int s @@ -1901,16 +1904,16 @@ cdef class Rational(sage.structure.element.FieldElement): sage: x.sqrt(all=True) [10, -10] sage: x = 81/5 - sage: x.sqrt() + sage: x.sqrt() # optional - sage.symbolic 9*sqrt(1/5) sage: x = -81/3 - sage: x.sqrt() + sage: x.sqrt() # optional - sage.symbolic 3*sqrt(-3) :: sage: n = 2/3 - sage: n.sqrt() + sage: n.sqrt() # optional - sage.symbolic sqrt(2/3) sage: n.sqrt(prec=10) 0.82 @@ -1924,7 +1927,7 @@ cdef class Rational(sage.structure.element.FieldElement): Traceback (most recent call last): ... ValueError: square root of 2/3 not a rational number - sage: sqrt(-2/3, all=True) + sage: sqrt(-2/3, all=True) # optional - sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] sage: sqrt(-2/3, prec=53) 0.816496580927726*I @@ -1990,20 +1993,20 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1/7).period() + sage: (1/7).period() # optional - sage.libs.pari 6 sage: RR(1/7) 0.142857142857143 - sage: (1/8).period() + sage: (1/8).period() # optional - sage.libs.pari 1 sage: RR(1/8) 0.125000000000000 sage: RR(1/6) 0.166666666666667 - sage: (1/6).period() + sage: (1/6).period() # optional - sage.libs.pari 1 sage: x = 333/106 - sage: x.period() + sage: x.period() # optional - sage.libs.pari 13 sage: RealField(200)(x) 3.1415094339622641509433962264150943396226415094339622641509 @@ -2515,9 +2518,9 @@ cdef class Rational(sage.structure.element.FieldElement): sage: (2/3)^5 32/243 - sage: (-1/1)^(1/3) + sage: (-1/1)^(1/3) # optional - sage.symbolic (-1)^(1/3) - sage: (2/3)^(3/4) + sage: (2/3)^(3/4) # optional - sage.symbolic (2/3)^(3/4) sage: (-1/3)^0 1 @@ -2532,18 +2535,18 @@ cdef class Rational(sage.structure.element.FieldElement): 2/3 sage: parent(a) Rational Field - sage: (-27/125)^(1/3) + sage: (-27/125)^(1/3) # optional - sage.symbolic 3/5*(-1)^(1/3) - sage: (-27/125)^(1/2) + sage: (-27/125)^(1/2) # optional - sage.symbolic 3/5*sqrt(-3/5) The result is normalized to have the rational power in the numerator:: - sage: 2^(-1/2) + sage: 2^(-1/2) # optional - sage.symbolic 1/2*sqrt(2) - sage: 8^(-1/5) + sage: 8^(-1/5) # optional - sage.symbolic 1/8*8^(4/5) - sage: 3^(-3/2) + sage: 3^(-3/2) # optional - sage.symbolic 1/9*sqrt(3) TESTS:: @@ -2555,7 +2558,7 @@ cdef class Rational(sage.structure.element.FieldElement): This works even if the base is a Python integer:: - sage: int(2)^(1/2) + sage: int(2)^(1/2) # optional - sage.symbolic sqrt(2) sage: a = int(2)^(3/1); a 8 @@ -2574,7 +2577,7 @@ cdef class Rational(sage.structure.element.FieldElement): ... OverflowError: exponent must be at most 2147483647 # 32-bit OverflowError: exponent must be at most 9223372036854775807 # 64-bit - sage: QQ(-1)^(2^100) + sage: QQ(-1)^(2^100) # optional - sage.symbolic 1 """ n = other @@ -2968,7 +2971,7 @@ cdef class Rational(sage.structure.element.FieldElement): def numerator(self): """ Return the numerator of this rational number. - numer is an alias of numerator. + ``numer`` is an alias of ``numerator``. EXAMPLES:: @@ -3018,7 +3021,7 @@ cdef class Rational(sage.structure.element.FieldElement): def denominator(self): """ Return the denominator of this rational number. - denom is an alias of denominator. + ``denom`` is an alias of ``denominator``. EXAMPLES:: @@ -3121,15 +3124,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (124/345).log(5) + sage: (124/345).log(5) # optional - sage.symbolic log(124/345)/log(5) - sage: (124/345).log(5,100) + sage: (124/345).log(5, 100) -0.63578895682825611710391773754 - sage: log(QQ(125)) + sage: log(QQ(125)) # optional - sage.symbolic 3*log(5) sage: log(QQ(125), 5) 3 - sage: log(QQ(125), 3) + sage: log(QQ(125), 3) # optional - sage.symbolic 3*log(5)/log(3) sage: QQ(8).log(1/2) -3 @@ -3149,14 +3152,14 @@ cdef class Rational(sage.structure.element.FieldElement): -4/3 sage: (125/8).log(5/2) 3 - sage: (125/8).log(5/2,prec=53) + sage: (125/8).log(5/2, prec=53) 3.00000000000000 TESTS:: - sage: (25/2).log(5/2) + sage: (25/2).log(5/2) # optional - sage.symbolic log(25/2)/log(5/2) - sage: (-1/2).log(3) + sage: (-1/2).log(3) # optional - sage.symbolic (I*pi + log(1/2))/log(3) """ cdef int self_sgn @@ -3225,15 +3228,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: gamma(1/2) + sage: gamma(1/2) # optional - sage.symbolic sqrt(pi) - sage: gamma(7/2) + sage: gamma(7/2) # optional - sage.symbolic 15/8*sqrt(pi) - sage: gamma(-3/2) + sage: gamma(-3/2) # optional - sage.symbolic 4/3*sqrt(pi) - sage: gamma(6/1) + sage: gamma(6/1) # optional - sage.symbolic 120 - sage: gamma(1/3) + sage: gamma(1/3) # optional - sage.symbolic gamma(1/3) This function accepts an optional precision argument:: @@ -3341,7 +3344,7 @@ cdef class Rational(sage.structure.element.FieldElement): def round(Rational self, mode="away"): """ Return the nearest integer to ``self``, rounding away from 0 by - default, for consistency with the builtin Python round. + default, for consistency with the builtin Python :func:`round`. INPUT: @@ -3554,7 +3557,7 @@ cdef class Rational(sage.structure.element.FieldElement): def is_integral(self): r""" - Determine if a rational number is integral (i.e is in + Determine if a rational number is integral (i.e., is in `\ZZ`). OUTPUT: bool @@ -3768,11 +3771,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: n = 9390823/17 - sage: m = n.__pari__(); m + sage: m = n.__pari__(); m # optional - sage.libs.pari 9390823/17 - sage: type(m) + sage: type(m) # optional - sage.libs.pari - sage: m.type() + sage: m.type() # optional - sage.libs.pari 't_FRAC' """ global new_gen_from_rational diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index ca704238181..100bd6a602b 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -11,7 +11,7 @@ Rational Field Values of various types can be converted to rational numbers by using the -``__call__`` method of ``RationalField`` (that is, by treating ``QQ`` as a +:meth:`__call__` method of :class:`RationalField` (that is, by treating ``QQ`` as a function). :: @@ -86,7 +86,7 @@ class RationalField(Singleton, number_field_base.NumberField): -930482/9320842317 sage: QQ([9320842317]) 9320842317 - sage: QQ(pari(39029384023840928309482842098430284398243982394)) + sage: QQ(pari(39029384023840928309482842098430284398243982394)) # optional - sage.libs.pari 39029384023840928309482842098430284398243982394 sage: QQ('sage') Traceback (most recent call last): @@ -304,7 +304,7 @@ def __len__(self): def construction(self): r""" - Returns a pair ``(functor, parent)`` such that ``functor(parent)`` + Return a pair ``(functor, parent)`` such that ``functor(parent)`` returns ``self``. This is the construction of `\QQ` as the fraction field of `\ZZ`. @@ -441,7 +441,7 @@ def __truediv__(self, I): EXAMPLES:: - sage: QQ / ZZ + sage: QQ / ZZ # optional - sage.groups Q/Z """ from sage.rings.ideal import Ideal_generic @@ -459,7 +459,7 @@ def range_by_height(self, start, end=None): Returns a Python generator for the list of rational numbers with heights in ``range(start, end)``. Follows the same - convention as Python range, see ``range?`` for details. + convention as Python :func:`range`, type ``range?`` for details. See also ``__iter__()``. @@ -526,9 +526,9 @@ def primes_of_bounded_norm_iter(self, B): EXAMPLES:: sage: it = QQ.primes_of_bounded_norm_iter(10) - sage: list(it) + sage: list(it) # optional - sage.libs.pari [2, 3, 5, 7] - sage: list(QQ.primes_of_bounded_norm_iter(1)) + sage: list(QQ.primes_of_bounded_norm_iter(1)) # optional - sage.libs.pari [] """ try: @@ -607,14 +607,14 @@ def embeddings(self, K): sage: QQ.embeddings(QQ) [Identity endomorphism of Rational Field] - sage: QQ.embeddings(CyclotomicField(5)) + sage: QQ.embeddings(CyclotomicField(5)) # optional - sage.rings.number_field [Coercion map: From: Rational Field To: Cyclotomic Field of order 5 and degree 4] `K` must have characteristic 0:: - sage: QQ.embeddings(GF(3)) + sage: QQ.embeddings(GF(3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: no embeddings of the rational field into K. @@ -740,7 +740,7 @@ def residue_field(self, p, check=True): def hilbert_symbol_negative_at_S(self, S, b, check=True): r""" - Returns an integer that has a negative Hilbert symbol with respect + Return an integer that has a negative Hilbert symbol with respect to a given rational number and a given set of primes (or places). The function is algorithm 3.4.1 in [Kir2016]_. It finds an integer `a` @@ -763,37 +763,37 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): EXAMPLES:: - sage: QQ.hilbert_symbol_negative_at_S([-1,5,3,2,7,11,13,23], -10/7) + sage: QQ.hilbert_symbol_negative_at_S([-1,5,3,2,7,11,13,23], -10/7) # optional - sage.rings.padics -9867 - sage: QQ.hilbert_symbol_negative_at_S([3, 5, QQ.places()[0], 11], -15) + sage: QQ.hilbert_symbol_negative_at_S([3, 5, QQ.places()[0], 11], -15) # optional - sage.rings.padics -33 - sage: QQ.hilbert_symbol_negative_at_S([3, 5], 2) + sage: QQ.hilbert_symbol_negative_at_S([3, 5], 2) # optional - sage.rings.padics 15 TESTS:: - sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) + sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: first argument must be a list or integer :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be nonzero :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) + sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: list should be of even cardinality :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: all entries in list must be prime or -1 for @@ -801,7 +801,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) + sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be a nonsquare with @@ -809,14 +809,14 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: second argument must be a rational number :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) + sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: if the infinite place is in the list, the second @@ -913,7 +913,7 @@ def phi(x): def gens(self): r""" - Return a tuple of generators of `\QQ` which is only ``(1,)``. + Return a tuple of generators of `\QQ`, which is only ``(1,)``. EXAMPLES:: @@ -926,7 +926,7 @@ def gen(self, n=0): r""" Return the ``n``-th generator of `\QQ`. - There is only the 0-th generator which is 1. + There is only the 0-th generator, which is 1. EXAMPLES:: @@ -940,7 +940,7 @@ def gen(self, n=0): def degree(self): r""" - Return the degree of `\QQ` which is 1. + Return the degree of `\QQ`, which is 1. EXAMPLES:: @@ -951,7 +951,7 @@ def degree(self): def absolute_degree(self): r""" - Return the absolute degree of `\QQ` which is 1. + Return the absolute degree of `\QQ`, which is 1. EXAMPLES:: @@ -962,7 +962,7 @@ def absolute_degree(self): def ngens(self): r""" - Return the number of generators of `\QQ` which is 1. + Return the number of generators of `\QQ`, which is 1. EXAMPLES:: @@ -1056,16 +1056,16 @@ def extension(self, poly, names, **kwds): We make a single absolute extension:: - sage: K. = QQ.extension(x^3 + 5); K + sage: K. = QQ.extension(x^3 + 5); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 We make an extension generated by roots of two polynomials:: - sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K + sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 over its base field - sage: b^2 + sage: b^2 # optional - sage.rings.number_field -3 - sage: a^3 + sage: a^3 # optional - sage.rings.number_field -5 """ from sage.rings.number_field.number_field import NumberField @@ -1077,7 +1077,7 @@ def algebraic_closure(self): EXAMPLES:: - sage: QQ.algebraic_closure() + sage: QQ.algebraic_closure() # optional - sage.rings.number_field Algebraic Field """ from sage.rings.qqbar import QQbar @@ -1085,7 +1085,7 @@ def algebraic_closure(self): def order(self): r""" - Return the order of `\QQ` which is `\infty`. + Return the order of `\QQ`, which is `\infty`. EXAMPLES:: @@ -1412,45 +1412,47 @@ def selmer_space(self, S, p, proof=None): When `S` is empty, `\QQ(S,p)` is only nontrivial for `p=2`:: - sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([], 2) - sage: QS2 + sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([], 2) # optional - sage.rings.number_field + sage: QS2 # optional - sage.rings.number_field Vector space of dimension 1 over Finite Field of size 2 - sage: QS2gens + sage: QS2gens # optional - sage.rings.number_field [-1] - sage: all(QQ.selmer_space([], p)[0].dimension() == 0 for p in primes(3,10)) + sage: all(QQ.selmer_space([], p)[0].dimension() == 0 # optional - sage.libs.pari + ....: for p in primes(3, 10)) True In general there is one generator for each `p\in S`, and an additional generator of `-1` when `p=2`:: - sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([5,7], 2) - sage: QS2 + sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([5,7], 2) # optional - sage.modules + sage: QS2 # optional - sage.modules Vector space of dimension 3 over Finite Field of size 2 - sage: QS2gens + sage: QS2gens # optional - sage.modules [5, 7, -1] - sage: toQS2(-7) + sage: toQS2(-7) # optional - sage.modules (0, 1, 1) - sage: fromQS2((0,1,1)) + sage: fromQS2((0,1,1)) # optional - sage.modules -7 The map ``fromQS2`` is only well-defined modulo `p`'th powers (in this case, modulo squares):: - sage: toQS2(-5/7) + sage: toQS2(-5/7) # optional - sage.modules (1, 1, 1) - sage: fromQS2((1,1,1)) + sage: fromQS2((1,1,1)) # optional - sage.modules -35 - sage: ((-5/7)/(-35)).is_square() + sage: ((-5/7)/(-35)).is_square() # optional - sage.modules True The map ``toQS2`` is not defined on all of `\QQ^*`, only on those numbers which are squares away from `5` and `7`:: - sage: toQS2(210) + sage: toQS2(210) # optional - sage.modules Traceback (most recent call last): ... - ValueError: argument 210 should have valuations divisible by 2 at all primes in [5, 7] + ValueError: argument 210 should have valuations divisible by 2 + at all primes in [5, 7] """ from sage.rings.number_field.selmer_group import pSelmerGroup @@ -1516,7 +1518,7 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(QQ) # indirect doctest + sage: gap(QQ) # indirect doctest # optional - sage.libs.gap Rationals """ return 'Rationals' @@ -1584,7 +1586,7 @@ def _sympy_(self): EXAMPLES:: - sage: QQ._sympy_() + sage: QQ._sympy_() # optional - sympy Rationals """ from sympy import Rationals @@ -1630,20 +1632,20 @@ def _factor_univariate_polynomial(self, f): TESTS:: sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial( x ) + sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari x - sage: QQ._factor_univariate_polynomial( 2*x ) + sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari (2) * x - sage: QQ._factor_univariate_polynomial( (x^2 - 1/4)^4 ) + sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # optional - sage.libs.pari (x - 1/2)^4 * (x + 1/2)^4 - sage: QQ._factor_univariate_polynomial( (2*x + 1) * (3*x^2 - 5)^2 ) + sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) # optional - sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) - sage: QQ._factor_univariate_polynomial(f) + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(f) # optional - sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: QQ._factor_univariate_polynomial( 10*x^5 - 1 ) + sage: QQ._factor_univariate_polynomial(10*x^5 - 1) # optional - sage.libs.pari (10) * (x^5 - 1/10) - sage: QQ._factor_univariate_polynomial( 10*x^5 - 10 ) + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ @@ -1661,9 +1663,9 @@ def valuation(self, p): EXAMPLES:: - sage: v = QQ.valuation(3); v + sage: v = QQ.valuation(3); v # optional - sage.rings.padics 3-adic valuation - sage: v(1/3) + sage: v(1/3) # optional - sage.rings.padics -1 .. SEEALSO:: diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 72bb242078d..5080a96a702 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -5,21 +5,21 @@ EXAMPLES: We create the real double vector space of dimension `3`:: - sage: V = RDF^3; V + sage: V = RDF^3; V # optional - sage.modules Vector space of dimension 3 over Real Double Field Notice that this space is unique:: - sage: V is RDF^3 + sage: V is RDF^3 # optional - sage.modules True - sage: V is FreeModule(RDF, 3) + sage: V is FreeModule(RDF, 3) # optional - sage.modules True - sage: V is VectorSpace(RDF, 3) + sage: V is VectorSpace(RDF, 3) # optional - sage.modules True Also, you can instantly create a space of large dimension:: - sage: V = RDF^10000 + sage: V = RDF^10000 # optional - sage.modules TESTS: @@ -27,8 +27,8 @@ Test NumPy conversions:: sage: RDF(1).__array_interface__ {'typestr': '=f8'} - sage: import numpy - sage: numpy.array([RDF.pi()]).dtype + sage: import numpy # optional - numpy + sage: numpy.array([RDF.pi()]).dtype # optional - numpy dtype('float64') """ @@ -332,10 +332,10 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): sage: RLF(2/3) + RDF(1) 1.6666666666666665 - sage: import numpy - sage: RDF.coerce(numpy.int8('1')) + sage: import numpy # optional - numpy + sage: RDF.coerce(numpy.int8('1')) # optional - numpy 1.0 - sage: RDF.coerce(numpy.float64('1')) + sage: RDF.coerce(numpy.float64('1')) # optional - numpy 1.0 sage: RDF.coerce(pi) @@ -793,20 +793,20 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(pi) - sage: a.ulp() + sage: a = RDF(pi) # optional - sage.symbolic + sage: a.ulp() # optional - sage.symbolic 4.440892098500626e-16 - sage: b = a + a.ulp() + sage: b = a + a.ulp() # optional - sage.symbolic Adding or subtracting an ulp always gives a different number:: - sage: a + a.ulp() == a + sage: a + a.ulp() == a # optional - sage.symbolic False - sage: a - a.ulp() == a + sage: a - a.ulp() == a # optional - sage.symbolic False - sage: b + b.ulp() == b + sage: b + b.ulp() == b # optional - sage.symbolic False - sage: b - b.ulp() == b + sage: b - b.ulp() == b # optional - sage.symbolic False Since the default rounding mode is round-to-nearest, adding or @@ -815,13 +815,13 @@ cdef class RealDoubleElement(FieldElement): can only happen if the input number is (up to sign) exactly a power of 2:: - sage: a - a.ulp()/3 == a + sage: a - a.ulp()/3 == a # optional - sage.symbolic True - sage: a + a.ulp()/3 == a + sage: a + a.ulp()/3 == a # optional - sage.symbolic True - sage: b - b.ulp()/3 == b + sage: b - b.ulp()/3 == b # optional - sage.symbolic True - sage: b + b.ulp()/3 == b + sage: b + b.ulp()/3 == b # optional - sage.symbolic True sage: c = RDF(1) sage: c - c.ulp()/3 == c @@ -980,11 +980,11 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: s1 = RDF(sin(1)); s1 + sage: s1 = RDF(sin(1)); s1 # optional - sage.symbolic 0.8414709848078965 - sage: s1._interface_init_() + sage: s1._interface_init_() # optional - sage.symbolic '0.8414709848078965' - sage: s1 == RDF(gp(s1)) + sage: s1 == RDF(gp(s1)) # optional - sage.libs.pari sage.symbolic True """ return repr(self._value) @@ -1009,7 +1009,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: sage_input(RDF(NaN)) + sage: sage_input(RDF(NaN)) # optional - sage.symbolic RDF(NaN) sage: sage_input(RDF(-infinity), verify=True) # Verified @@ -1268,12 +1268,12 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(exp(1.0)); a + sage: a = RDF(exp(1.0)); a # optional - sage.symbolic 2.718281828459045 - sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() - sage: sign,mantissa,exponent + sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() # optional - sage.symbolic + sage: sign,mantissa,exponent # optional - sage.symbolic (1, 6121026514868073, -51) - sage: sign*mantissa*(2**exponent) == a + sage: sign*mantissa*(2**exponent) == a # optional - sage.symbolic True The mantissa is always a nonnegative number:: @@ -1687,7 +1687,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF(1.5).__pari__() + sage: RDF(1.5).__pari__() # optional - sage.libs.pari 1.50000000000000 """ global new_gen_from_real_double_element @@ -1975,7 +1975,7 @@ cdef class RealDoubleElement(FieldElement): sage: r = sqrt(RDF(2)); r 1.4142135623730951 - sage: r.algebraic_dependency(5) + sage: r.algebraic_dependency(5) # optional - sage.libs.pari x^2 - 2 """ return sage.arith.all.algdep(self,n) diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 33e94b93094..1904bbff3e7 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -230,10 +230,10 @@ specified if given a non-interval and an interval:: TESTS:: - sage: import numpy - sage: RIF(2) == numpy.int8('2') + sage: import numpy # optional - numpy + sage: RIF(2) == numpy.int8('2') # optional - numpy True - sage: numpy.int8('2') == RIF(2) + sage: numpy.int8('2') == RIF(2) # optional - numpy True sage: RIF(0,1) < float('2') Traceback (most recent call last): diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 0dd8adb3040..0bd02790fb3 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -1438,12 +1438,12 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: import numpy - sage: numpy.arange(10.0) + sage: import numpy # optional - numpy + sage: numpy.arange(10.0) # optional - numpy array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) - sage: numpy.array([1.0, 1.1, 1.2]).dtype + sage: numpy.array([1.0, 1.1, 1.2]).dtype # optional - numpy dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype + sage: numpy.array([1.000000000000000000000000000000000000]).dtype # optional - numpy dtype('O') """ if (self._parent).__prec <= 53: diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index e806637c38a..ae6cc32d4bc 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -165,13 +165,13 @@ cdef class Ring(ParentWithGens): sage: QQ.is_finite() False - sage: GF(2^10,'a').is_finite() + sage: GF(2^10, 'a').is_finite() # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] - sage: R.is_finite() + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: R.is_finite() # optional - sage.rings.finite_rings False - sage: S. = R.quo(x^2+1) - sage: S.is_finite() + sage: S. = R.quo(x^2 + 1) # optional - sage.rings.finite_rings + sage: S.is_finite() # optional - sage.rings.finite_rings True sage: Integers(7).cardinality() @@ -255,11 +255,11 @@ cdef class Ring(ParentWithGens): """ EXAMPLES:: - sage: QQ.base_extend(GF(7)) + sage: QQ.base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined - sage: ZZ.base_extend(GF(7)) + sage: ZZ.base_extend(GF(7)) # optional - sage.rings.finite_rings Finite Field of size 7 """ if R.has_coerce_map_from(self): @@ -280,7 +280,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! + sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! # optional - sage.combinat sage.modules Category of algebras with basis over Rational Field Since a quotient of the integers is its own base ring, and during @@ -310,16 +310,19 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: F. = FreeAlgebra(ZZ, 3) - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quotient(I) - sage: Q.ideal_monoid() - Monoid of ideals of Quotient of Free Algebra on 3 generators (x, y, z) over Integer Ring by the ideal (x*y + y*z, x^2 + x*y - y*x - y^2) - sage: F. = FreeAlgebra(ZZ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.ideal_monoid() - Monoid of ideals of Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Integer Ring by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: F. = FreeAlgebra(ZZ, 3) # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quotient(I) # optional - sage.combinat sage.modules + sage: Q.ideal_monoid() # optional - sage.combinat sage.modules + Monoid of ideals of Quotient of Free Algebra on 3 generators (x, y, z) + over Integer Ring by the ideal (x*y + y*z, x^2 + x*y - y*x - y^2) + sage: F. = FreeAlgebra(ZZ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: Q.ideal_monoid() # optional - sage.combinat sage.modules + Monoid of ideals of Quotient of Free Associative Unital Algebra + on 3 generators (x, y, z) over Integer Ring + by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) """ if self.__ideal_monoid is not None: @@ -363,10 +366,10 @@ cdef class Ring(ParentWithGens): Here is an example over a non-commutative ring:: - sage: A = SteenrodAlgebra(2) - sage: A.ideal(A.1,A.2^2) + sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules + sage: A.ideal(A.1, A.2^2) # optional - sage.combinat sage.modules Twosided Ideal (Sq(2), Sq(2,2)) of mod 2 Steenrod algebra, milnor basis - sage: A.ideal(A.1,A.2^2,side='left') + sage: A.ideal(A.1, A.2^2, side='left') # optional - sage.combinat sage.modules Left Ideal (Sq(2), Sq(2,2)) of mod 2 Steenrod algebra, milnor basis TESTS: @@ -445,20 +448,22 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: R. = GF(7)[] - sage: (x+y)*R - Ideal (x + y) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 7 - sage: (x+y,z+y^3)*R - Ideal (x + y, y^3 + z) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 7 + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: (x + y) * R # optional - sage.rings.finite_rings + Ideal (x + y) of Multivariate Polynomial Ring in x, y, z + over Finite Field of size 7 + sage: (x + y, z + y^3) * R # optional - sage.rings.finite_rings + Ideal (x + y, y^3 + z) of Multivariate Polynomial Ring in x, y, z + over Finite Field of size 7 The following was implemented in :trac:`7797`:: - sage: A = SteenrodAlgebra(2) - sage: A*[A.1+A.2,A.1^2] + sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules + sage: A * [A.1 + A.2, A.1^2] # optional - sage.combinat sage.modules Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: [A.1+A.2,A.1^2]*A + sage: [A.1 + A.2, A.1^2] * A # optional - sage.combinat sage.modules Right Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: A*[A.1+A.2,A.1^2]*A + sage: A * [A.1 + A.2, A.1^2] * A # optional - sage.combinat sage.modules Twosided Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis """ @@ -516,18 +521,18 @@ cdef class Ring(ParentWithGens): sage: RR._ideal_class_() - sage: R. = GF(5)[] - sage: R._ideal_class_(1) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: R._ideal_class_(1) # optional - sage.rings.finite_rings - sage: S = R.quo(x^3-y^2) - sage: S._ideal_class_(1) + sage: S = R.quo(x^3 - y^2) # optional - sage.rings.finite_rings + sage: S._ideal_class_(1) # optional - sage.rings.finite_rings - sage: S._ideal_class_(2) + sage: S._ideal_class_(2) # optional - sage.rings.finite_rings - sage: T. = S[] - sage: T._ideal_class_(5) + sage: T. = S[] # optional - sage.rings.finite_rings + sage: T._ideal_class_(5) # optional - sage.rings.finite_rings - sage: T._ideal_class_(1) + sage: T._ideal_class_(1) # optional - sage.rings.finite_rings Since :trac:`7797`, non-commutative rings have ideals as well:: @@ -571,7 +576,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: Zp(7).unit_ideal() + sage: Zp(7).unit_ideal() # optional - sage.rings.padics Principal ideal (1 + O(7^20)) of 7-adic Ring with capped relative precision 20 """ if self._unit_ideal is None: @@ -602,10 +607,10 @@ cdef class Ring(ParentWithGens): Make sure that :trac:`13644` is fixed:: - sage: K = Qp(3) - sage: R. = K[] - sage: L. = K.extension(a^2-3) - sage: L.ideal(a) + sage: K = Qp(3) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: L. = K.extension(a^2-3) # optional - sage.rings.padics + sage: L.ideal(a) # optional - sage.rings.padics Principal ideal (1 + O(a^40)) of 3-adic Eisenstein Extension Field in a defined by a^2 - 3 """ @@ -673,8 +678,8 @@ cdef class Ring(ParentWithGens): True sage: QQ['x,y,z'].is_commutative() True - sage: Q. = QuaternionAlgebra(QQ, -1,-1) - sage: Q.is_commutative() + sage: Q. = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: Q.is_commutative() # optional - sage.combinat sage.modules False """ if self.is_zero(): @@ -701,7 +706,7 @@ cdef class Ring(ParentWithGens): sage: QQ.is_field() True - sage: GF(9,'a').is_field() + sage: GF(9, 'a').is_field() # optional - sage.rings.finite_rings True sage: ZZ.is_field() False @@ -713,12 +718,12 @@ cdef class Ring(ParentWithGens): This illustrates the use of the ``proof`` parameter:: sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: S.is_field(proof = True) + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_field(proof=True) # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_field(proof = False) + sage: S.is_field(proof=False) # optional - sage.libs.singular False """ if self.is_zero(): @@ -745,9 +750,9 @@ cdef class Ring(ParentWithGens): 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 @@ -763,30 +768,30 @@ cdef class Ring(ParentWithGens): sage: ZZ.is_subring(QQ) True - sage: ZZ.is_subring(GF(19)) + sage: ZZ.is_subring(GF(19)) # optional - sage.rings.finite_rings False TESTS:: sage: QQ.is_subring(QQ['x']) True - sage: QQ.is_subring(GF(7)) + sage: QQ.is_subring(GF(7)) # optional - sage.rings.finite_rings False - sage: QQ.is_subring(CyclotomicField(7)) + sage: QQ.is_subring(CyclotomicField(7)) # optional - sage.rings.number_field True sage: QQ.is_subring(ZZ) False Every ring is a subring of itself, :trac:`17287`:: - sage: QQbar.is_subring(QQbar) + sage: QQbar.is_subring(QQbar) # optional - sage.rings.number_field True sage: RR.is_subring(RR) True sage: CC.is_subring(CC) True - sage: K. = NumberField(x^3-x+1/10) - sage: K.is_subring(K) + sage: K. = NumberField(x^3 - x + 1/10) # optional - sage.rings.number_field + sage: K.is_subring(K) # optional - sage.rings.number_field True sage: R. = RR[] sage: R.is_subring(R) @@ -808,15 +813,15 @@ cdef class Ring(ParentWithGens): sage: QQ.is_prime_field() True - sage: GF(3).is_prime_field() + sage: GF(3).is_prime_field() # optional - sage.rings.finite_rings True - sage: GF(9,'a').is_prime_field() + sage: GF(9, 'a').is_prime_field() # optional - sage.rings.finite_rings False sage: ZZ.is_prime_field() False sage: QQ['x'].is_prime_field() False - sage: Qp(19).is_prime_field() + sage: Qp(19).is_prime_field() # optional - sage.rings.padics False """ return False @@ -847,33 +852,32 @@ cdef class Ring(ParentWithGens): True sage: Integers(8).is_integral_domain() False - sage: Zp(7).is_integral_domain() + sage: Zp(7).is_integral_domain() # optional - sage.rings.padics True - sage: Qp(7).is_integral_domain() + sage: Qp(7).is_integral_domain() # optional - sage.rings.padics True sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: S.is_integral_domain() + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_integral_domain() # optional - sage.libs.singular False This illustrates the use of the ``proof`` parameter:: sage: R. = ZZ[] - sage: S. = R.quo((b^3)) - sage: S.is_integral_domain(proof = True) + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_integral_domain(proof=True) # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof = False) + sage: S.is_integral_domain(proof=False) # optional - sage.libs.singular False TESTS: Make sure :trac:`10481` is fixed:: - sage: var('x') - x - sage: R. = ZZ['x'].quo(x^2) + sage: x = polygen(ZZ, 'x') + sage: R. = ZZ['x'].quo(x^2) # optional - sage.libs.pari sage: R.fraction_field() Traceback (most recent call last): ... @@ -883,11 +887,11 @@ cdef class Ring(ParentWithGens): Forward the proof flag to ``is_field``, see :trac:`22910`:: - sage: R1. = GF(5)[] - sage: F1 = R1.quotient_ring(x^2+x+1) - sage: R2. = F1[] - sage: F2 = R2.quotient_ring(x^2+x+1) - sage: F2.is_integral_domain(False) + sage: R1. = GF(5)[] # optional - sage.rings.finite_rings + sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.rings.finite_rings + sage: R2. = F1[] # optional - sage.rings.finite_rings + sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.rings.finite_rings + sage: F2.is_integral_domain(False) # optional - sage.rings.finite_rings False """ if self.is_field(proof): @@ -920,7 +924,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: GF(19).order() + sage: GF(19).order() # optional - sage.rings.finite_rings 19 sage: QQ.order() +Infinity @@ -952,29 +956,29 @@ cdef class Ring(ParentWithGens): -1 sage: QQ.zeta(1) 1 - sage: CyclotomicField(6).zeta(6) + sage: CyclotomicField(6).zeta(6) # optional - sage.rings.number_field zeta6 - sage: CyclotomicField(3).zeta(3) + sage: CyclotomicField(3).zeta(3) # optional - sage.rings.number_field zeta3 - sage: CyclotomicField(3).zeta(3).multiplicative_order() + sage: CyclotomicField(3).zeta(3).multiplicative_order() # optional - sage.rings.number_field 3 - sage: a = GF(7).zeta(); a + sage: a = GF(7).zeta(); a # optional - sage.rings.finite_rings 3 - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 6 - sage: a = GF(49,'z').zeta(); a + sage: a = GF(49,'z').zeta(); a # optional - sage.rings.finite_rings z - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 48 - sage: a = GF(49,'z').zeta(2); a + sage: a = GF(49,'z').zeta(2); a # optional - sage.rings.finite_rings 6 - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 2 sage: QQ.zeta(3) Traceback (most recent call last): ... ValueError: no n-th root of unity in rational field - sage: Zp(7, prec=8).zeta() + sage: Zp(7, prec=8).zeta() # optional - sage.rings.padics 3 + 4*7 + 6*7^2 + 3*7^3 + 2*7^5 + 6*7^6 + 2*7^7 + O(7^8) TESTS:: @@ -984,7 +988,7 @@ cdef class Ring(ParentWithGens): 1 sage: Ring.zeta(QQ, 2) -1 - sage: Ring.zeta(QQ, 3) + sage: Ring.zeta(QQ, 3) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no 3rd root of unity in Rational Field @@ -1021,13 +1025,13 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: CyclotomicField(19).zeta_order() + sage: CyclotomicField(19).zeta_order() # optional - sage.rings.number_field 38 - sage: GF(19).zeta_order() + sage: GF(19).zeta_order() # optional - sage.rings.finite_rings 18 - sage: GF(5^3,'a').zeta_order() + sage: GF(5^3,'a').zeta_order() # optional - sage.rings.finite_rings 124 - sage: Zp(7, prec=8).zeta_order() + sage: Zp(7, prec=8).zeta_order() # optional - sage.rings.padics 6 """ return self.zeta().multiplicative_order() @@ -1195,10 +1199,11 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: R. = GF(3)[] - sage: R.localization((x*y, x**2+y**2)) - Multivariate Polynomial Ring in x, y over Finite Field of size 3 localized at (y, x, x^2 + y^2) - sage: ~y in _ + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: R.localization((x*y, x**2+y**2)) # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x, y over Finite Field of size 3 + localized at (y, x, x^2 + y^2) + sage: ~y in _ # optional - sage.rings.finite_rings True """ if not self.is_integral_domain(): @@ -1272,11 +1277,11 @@ cdef class CommutativeRing(Ring): sage: QQ.is_commutative() True - sage: ZpCA(7).is_commutative() + sage: ZpCA(7).is_commutative() # optional - sage.rings.padics True - sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A + sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # optional - sage.combinat sage.modules Quaternion Algebra (-1, -3) with base ring Rational Field - sage: A.is_commutative() + sage: A.is_commutative() # optional - sage.combinat sage.modules False """ return True @@ -1312,16 +1317,18 @@ cdef class CommutativeRing(Ring): All orders in number fields have Krull dimension 1, including non-maximal orders:: - sage: K. = QuadraticField(-1) - sage: R = K.maximal_order(); R - Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.krull_dimension() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R = K.maximal_order(); R # optional - sage.rings.number_field + Gaussian Integers in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.krull_dimension() # optional - sage.rings.number_field 1 - sage: R = K.order(2*i); R - Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.is_maximal() + sage: R = K.order(2*i); R # optional - sage.rings.number_field + Order in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ raise NotImplementedError @@ -1366,16 +1373,18 @@ cdef class CommutativeRing(Ring): sage: R = QQ['x'] sage: y = polygen(R) - sage: R.extension(y^2 - 5, 'a') - Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 + sage: R.extension(y^2 - 5, 'a') # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a over + Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 :: - sage: P. = PolynomialRing(GF(5)) - sage: F. = GF(5).extension(x^2 - 2) - sage: P. = F[] - sage: R. = F.extension(t^2 - a); R - Univariate Quotient Polynomial Ring in b over Finite Field in a of size 5^2 with modulus b^2 + 4*a + sage: P. = PolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: F. = GF(5).extension(x^2 - 2) # optional - sage.rings.finite_rings + sage: P. = F[] # optional - sage.rings.finite_rings + sage: R. = F.extension(t^2 - a); R # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in b over + Finite Field in a of size 5^2 with modulus b^2 + 4*a """ from sage.rings.polynomial.polynomial_element import Polynomial if not isinstance(poly, Polynomial): @@ -1411,17 +1420,19 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: Frob(u) + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: Frob(u) # optional - sage.rings.finite_rings u^5 We can specify a power:: - sage: f = K.frobenius_endomorphism(2); f - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 - sage: f(1+u) + sage: f = K.frobenius_endomorphism(2); f # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 + sage: f(1+u) # optional - sage.rings.finite_rings 1 + u^25 """ from .morphism import FrobeniusEndomorphism_generic @@ -1456,18 +1467,21 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: M = R.derivation_module(); M - Module of derivations over Multivariate Polynomial Ring in x, y, z over Rational Field - sage: M.gens() + sage: M = R.derivation_module(); M # optional - sage.modules + Module of derivations over + Multivariate Polynomial Ring in x, y, z over Rational Field + sage: M.gens() # optional - sage.modules (d/dx, d/dy, d/dz) We can specify a different codomain:: sage: K = R.fraction_field() - sage: M = R.derivation_module(K); M - Module of derivations from Multivariate Polynomial Ring in x, y, z over - Rational Field to Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field - sage: M.gen() / x + sage: M = R.derivation_module(K); M # optional - sage.modules + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Fraction Field of + Multivariate Polynomial Ring in x, y, z over Rational Field + sage: M.gen() / x # optional - sage.modules 1/x*d/dx Here is an example with a non-canonical defining morphism:: @@ -1480,30 +1494,32 @@ cdef class CommutativeRing(Ring): Defn: x |--> 0 y |--> 1 z |--> 2 - sage: M = R.derivation_module(ev) - sage: M - Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field + sage: M = R.derivation_module(ev) # optional - sage.modules + sage: M # optional - sage.modules + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Rational Field Elements in `M` acts as derivations at `(0,1,2)`:: - sage: Dx = M.gen(0); Dx + sage: Dx = M.gen(0); Dx # optional - sage.modules d/dx - sage: Dy = M.gen(1); Dy + sage: Dy = M.gen(1); Dy # optional - sage.modules d/dy - sage: Dz = M.gen(2); Dz + sage: Dz = M.gen(2); Dz # optional - sage.modules d/dz sage: f = x^2 + y^2 + z^2 - sage: Dx(f) # = 2*x evaluated at (0,1,2) + sage: Dx(f) # = 2*x evaluated at (0,1,2) # optional - sage.modules 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) + sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) + sage: Dz(f) # = 2*z evaluated at (0,1,2) # optional - sage.modules 4 An example with a twisting homomorphism:: sage: theta = R.hom([x^2, y^2, z^2]) - sage: M = R.derivation_module(twist=theta); M + sage: M = R.derivation_module(twist=theta); M # optional - sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) @@ -1542,23 +1558,23 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: R.derivation() + sage: R.derivation() # optional - sage.modules d/dx In that case, ``arg`` could be a generator:: - sage: R.derivation(y) + sage: R.derivation(y) # optional - sage.modules d/dy or a list of coefficients:: - sage: R.derivation([1,2,3]) + sage: R.derivation([1,2,3]) # optional - sage.modules d/dx + 2*d/dy + 3*d/dz It is not possible to define derivations with respect to a polynomial which is not a variable:: - sage: R.derivation(x^2) + sage: R.derivation(x^2) # optional - sage.modules Traceback (most recent call last): ... ValueError: unable to create the derivation @@ -1567,18 +1583,18 @@ cdef class CommutativeRing(Ring): sage: R. = QQ[] sage: theta = R.hom([x^2, y^2, z^2]) - sage: f = R.derivation(twist=theta); f + sage: f = R.derivation(twist=theta); f # optional - sage.modules 0 - sage: f.parent() + sage: f.parent() # optional - sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) Specifying a scalar, the returned twisted derivation is the corresponding multiple of `\theta - id`:: - sage: R.derivation(1, twist=theta) + sage: R.derivation(1, twist=theta) # optional - sage.modules [x |--> x^2, y |--> y^2, z |--> z^2] - id - sage: R.derivation(x, twist=theta) + sage: R.derivation(x, twist=theta) # optional - sage.modules x*([x |--> x^2, y |--> y^2, z |--> z^2] - id) """ @@ -1696,9 +1712,9 @@ cdef class IntegralDomain(CommutativeRing): True sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() + sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field True - sage: GF(5).is_integrally_closed() + sage: GF(5).is_integrally_closed() # optional - sage.rings.finite_rings True sage: Z5 = Integers(5); Z5 Ring of integers modulo 5 @@ -1715,7 +1731,7 @@ cdef class IntegralDomain(CommutativeRing): EXAMPLES:: - sage: GF(7).is_field() + sage: GF(7).is_field() # optional - sage.rings.finite_rings True The following examples have their own ``is_field`` implementations:: @@ -1785,9 +1801,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.krull_dimension() 1 - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.krull_dimension() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.krull_dimension() # optional - sage.rings.number_field 1 The following are not Dedekind domains but have @@ -1804,12 +1820,13 @@ cdef class DedekindDomain(IntegralDomain): sage: U.krull_dimension() 4 - sage: K. = QuadraticField(-1) - sage: R = K.order(2*i); R - Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.is_maximal() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R = K.order(2*i); R # optional - sage.rings.number_field + Order in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ return 1 @@ -1828,18 +1845,18 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_integrally_closed() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_integrally_closed() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_integrally_closed() # optional - sage.rings.number_field True These, however, are not Dedekind domains:: sage: QQ.is_integrally_closed() True - sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() + sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() # optional - sage.rings.number_field sage.symbolic False - sage: T. = PolynomialRing(QQ,2); T + sage: T. = PolynomialRing(QQ, 2); T Multivariate Polynomial Ring in x, y over Rational Field sage: T.is_integral_domain() True @@ -1852,11 +1869,12 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.integral_closure() - Gaussian Integers in Number Field in s with defining polynomial x^2 + 1 - sage: OK.integral_closure() == OK + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.integral_closure() # optional - sage.rings.number_field + Gaussian Integers in Number Field in s + with defining polynomial x^2 + 1 + sage: OK.integral_closure() == OK # optional - sage.rings.number_field True sage: QQ.integral_closure() == QQ @@ -1875,9 +1893,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_noetherian() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_noetherian() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_noetherian() # optional - sage.rings.number_field True sage: QQ.is_noetherian() True @@ -1901,7 +1919,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: Zp(5).is_noetherian() + sage: Zp(5).is_noetherian() # optional - sage.rings.padics True """ return True @@ -1912,7 +1930,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: QQ.class_group() + sage: QQ.class_group() # optional - sage.groups Trivial Abelian group """ from sage.groups.abelian_gps.abelian_group import AbelianGroup @@ -1958,22 +1976,22 @@ cdef class PrincipalIdealDomain(IntegralDomain): coercible:: sage: R. = PolynomialRing(QQ) - sage: S. = NumberField(x^2 - 2, 'a') - sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) - sage: print(f); print(g) + sage: S. = NumberField(x^2 - 2, 'a') # optional - sage.rings.number_field + sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) # optional - sage.rings.number_field + sage: print(f); print(g) # optional - sage.rings.number_field x^2 - 2 x^3 - a*x^2 - 2*x + 2*a - sage: f in R + sage: f in R # optional - sage.rings.number_field True - sage: g in R + sage: g in R # optional - sage.rings.number_field False - sage: R.gcd(f,g) + sage: R.gcd(f, g) # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce 2*a to a rational - sage: R.base_extend(S).gcd(f,g) + sage: R.base_extend(S).gcd(f,g) # optional - sage.rings.number_field x^2 - 2 - sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # optional - sage.rings.number_field x - a """ if coerce: @@ -2066,7 +2084,7 @@ cpdef bint _is_Field(x) except -2: True sage: _is_Field(ZZ) False - sage: _is_Field(pAdicField(2)) + sage: _is_Field(pAdicField(2)) # optional - sage.rings.padics True sage: _is_Field(5) False @@ -2113,8 +2131,8 @@ cdef class Field(PrincipalIdealDomain): sage: CC.fraction_field() Complex Field with 53 bits of precision - sage: F = NumberField(x^2 + 1, 'i') - sage: F.fraction_field() + sage: F = NumberField(x^2 + 1, 'i') # optional - sage.rings.number_field + sage: F.fraction_field() # optional - sage.rings.number_field Number Field in i with defining polynomial x^2 + 1 """ return self @@ -2127,10 +2145,10 @@ cdef class Field(PrincipalIdealDomain): sage: QQ._pseudo_fraction_field() Rational Field - sage: K = GF(5) - sage: K._pseudo_fraction_field() + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: K._pseudo_fraction_field() # optional - sage.rings.finite_rings Finite Field of size 5 - sage: K._pseudo_fraction_field() is K + sage: K._pseudo_fraction_field() is K # optional - sage.rings.finite_rings True """ return self @@ -2242,8 +2260,8 @@ cdef class Field(PrincipalIdealDomain): EXAMPLES:: - sage: k = GF(9, 'a') - sage: k.prime_subfield() + sage: k = GF(9, 'a') # optional - sage.rings.finite_rings + sage: k.prime_subfield() # optional - sage.rings.finite_rings Finite Field of size 3 """ if self.characteristic() == 0: @@ -2283,7 +2301,7 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A + sage: A = Algebra(ZZ); A # optional - sage.modules """ # This is a low-level class. For performance, we trust that the category @@ -2303,12 +2321,12 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A + sage: A = Algebra(ZZ); A # optional - sage.modules - sage: A.characteristic() + sage: A.characteristic() # optional - sage.modules 0 - sage: A = Algebra(GF(7^3, 'a')) - sage: A.characteristic() + sage: A = Algebra(GF(7^3, 'a')) # optional - sage.rings.finite_rings sage.modules + sage: A.characteristic() # optional - sage.rings.finite_rings sage.modules 7 """ return self.base_ring().characteristic() @@ -2323,16 +2341,16 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: B = QuaternionAlgebra(2) - sage: B.has_standard_involution() + sage: B = QuaternionAlgebra(2) # optional - sage.combinat sage.modules + sage: B.has_standard_involution() # optional - sage.combinat sage.modules True sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x**2 - 2) - sage: A = QuaternionAlgebra(K,-2,5) - sage: A.has_standard_involution() + sage: K. = NumberField(x**2 - 2) # optional - sage.rings.number_field + sage: A = QuaternionAlgebra(K, -2, 5) # optional - sage.rings.number_field sage.combinat sage.modules + sage: A.has_standard_involution() # optional - sage.rings.number_field sage.combinat sage.modules True - sage: L. = FreeAlgebra(QQ,2) - sage: L.has_standard_involution() + sage: L. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: L.has_standard_involution() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: has_standard_involution is not implemented for this algebra @@ -2386,7 +2404,7 @@ cdef class CommutativeAlgebra(CommutativeRing): sage: sage.rings.ring.CommutativeAlgebra(QQ) - sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ,-1,-1)) + sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ, -1, -1)) # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: base ring must be a commutative ring @@ -2433,8 +2451,8 @@ def is_Ring(x): sage: from sage.rings.ring import is_Ring sage: is_Ring(ZZ) True - sage: MS = MatrixSpace(QQ,2) - sage: is_Ring(MS) + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: is_Ring(MS) # optional - sage.modules True """ return x in _Rings diff --git a/src/sage/rings/semirings/non_negative_integer_semiring.py b/src/sage/rings/semirings/non_negative_integer_semiring.py index ea3bce495d9..9c73b3ede34 100644 --- a/src/sage/rings/semirings/non_negative_integer_semiring.py +++ b/src/sage/rings/semirings/non_negative_integer_semiring.py @@ -37,15 +37,15 @@ class NonNegativeIntegerSemiring(NonNegativeIntegers): Here is a piece of the Cayley graph for the multiplicative structure:: - sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) - sage: G + sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) # optional - sage.graphs + sage: G # optional - sage.graphs Looped multi-digraph on 9 vertices - sage: G.plot() + sage: G.plot() # optional - sage.graphs Graphics object consisting of 48 graphics primitives This is the Hasse diagram of the divisibility order on ``NN``. - sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() + sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() # optional - sage.graphs Note: as for :class:`NonNegativeIntegers `, ``NN`` is diff --git a/src/sage/rings/sum_of_squares.pyx b/src/sage/rings/sum_of_squares.pyx index a1d3edcedef..7e19380441e 100644 --- a/src/sage/rings/sum_of_squares.pyx +++ b/src/sage/rings/sum_of_squares.pyx @@ -140,7 +140,7 @@ def two_squares_pyx(uint32_t n): .. SEEALSO:: - :func:`~sage.arith.all.two_squares` is much more suited for large inputs + :func:`~sage.arith.misc.two_squares` is much more suited for large inputs EXAMPLES:: @@ -166,7 +166,7 @@ def two_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ij in Subsets(Subsets(45000,15).random_element(),2): + sage: for ij in Subsets(Subsets(45000, 15).random_element(), 2): # optional - sage.combinat ....: if s(two_squares_pyx(s(ij))) != s(ij): ....: print("hey") @@ -254,7 +254,7 @@ def three_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): + sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): # optional - sage.combinat ....: if s(three_squares_pyx(s(ijk))) != s(ijk): ....: print("hey") """ @@ -278,7 +278,7 @@ def four_squares_pyx(uint32_t n): .. SEEALSO:: - :func:`~sage.arith.all.four_squares` is much more suited for large input + :func:`~sage.arith.misc.four_squares` is much more suited for large input EXAMPLES:: diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 2c4ab8ec988..f829d2364d1 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -23,9 +23,9 @@ def prime_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.prime_finite_field(); K + sage: K = sage.rings.tests.prime_finite_field(); K # optional - sage.rings.finite_rings Finite Field of size ... - sage: K.cardinality().is_prime() + sage: K.cardinality().is_prime() # optional - sage.rings.finite_rings True """ from sage.rings.integer_ring import ZZ @@ -42,11 +42,11 @@ def finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.finite_field(); K + sage: K = sage.rings.tests.finite_field(); K # optional - sage.rings.finite_rings Finite Field...of size ... - sage: K.cardinality().is_prime_power() + sage: K.cardinality().is_prime_power() # optional - sage.rings.finite_rings True - sage: while K.cardinality().is_prime(): + sage: while K.cardinality().is_prime(): # optional - sage.rings.finite_rings ....: K = sage.rings.tests.finite_field() """ from sage.rings.integer_ring import ZZ @@ -65,12 +65,12 @@ def small_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.small_finite_field(); K + sage: K = sage.rings.tests.small_finite_field(); K # optional - sage.rings.finite_rings Finite Field...of size ... - sage: q = K.cardinality() - sage: q.is_prime_power() + sage: q = K.cardinality() # optional - sage.rings.finite_rings + sage: q.is_prime_power() # optional - sage.rings.finite_rings True - sage: q <= 2^16 + sage: q <= 2^16 # optional - sage.rings.finite_rings True """ from sage.rings.integer_ring import ZZ @@ -107,7 +107,7 @@ def padic_field(): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.padic_field() + sage: sage.rings.tests.padic_field() # optional - sage.rings.padics ...-adic Field with capped relative precision ... """ from sage.rings.integer_ring import ZZ @@ -124,7 +124,7 @@ def quadratic_number_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.quadratic_number_field(); K + sage: K = sage.rings.tests.quadratic_number_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 ... with a = ... """ from sage.rings.integer_ring import ZZ @@ -142,9 +142,9 @@ def absolute_number_field(maxdeg=10): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.absolute_number_field(); K + sage: K = sage.rings.tests.absolute_number_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial ... - sage: K.degree() <= 10 + sage: K.degree() <= 10 # optional - sage.rings.number_field True """ from sage.rings.integer_ring import ZZ @@ -167,26 +167,26 @@ def relative_number_field(n=2, maxdeg=2): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.relative_number_field(3); K + sage: K = sage.rings.tests.relative_number_field(3); K # optional - sage.rings.number_field Number Field in aaa with defining polynomial x^2 ... over its base field - sage: K.relative_degree() + sage: K.relative_degree() # optional - sage.rings.number_field 2 - sage: L = K.base_ring() - sage: L.relative_degree() + sage: L = K.base_ring() # optional - sage.rings.number_field + sage: L.relative_degree() # optional - sage.rings.number_field 2 - sage: M = L.base_ring() - sage: M.relative_degree() + sage: M = L.base_ring() # optional - sage.rings.number_field + sage: M.relative_degree() # optional - sage.rings.number_field 2 - sage: M.base_ring() is QQ + sage: M.base_ring() is QQ # optional - sage.rings.number_field True TESTS: Check that :trac:`32117` is fixed:: - sage: set_random_seed(3030) - sage: from sage.rings.tests import relative_number_field - sage: _ = relative_number_field(3) + sage: set_random_seed(3030) # optional - sage.rings.number_field + sage: from sage.rings.tests import relative_number_field # optional - sage.rings.number_field + sage: _ = relative_number_field(3) # optional - sage.rings.number_field """ from sage.rings.integer_ring import ZZ K = absolute_number_field(maxdeg) @@ -333,7 +333,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.test_random_elements(trials=2, seed=0) + sage: sage.rings.tests.test_random_elements(trials=2, seed=0) # optional - sage.rings.number_field survived 0 tests Rational Field -1/2 @@ -382,7 +382,7 @@ def test_random_arith(level=MAX_LEVEL, trials=1): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.test_random_arith(trials=2, seed=0) + sage: sage.rings.tests.test_random_arith(trials=2, seed=0) # optional - sage.rings.number_field survived 0 tests Rational Field -1/2 -1/95 diff --git a/src/sage/sets/cartesian_product.py b/src/sage/sets/cartesian_product.py index cc2ce557bd0..fb67c6738a8 100644 --- a/src/sage/sets/cartesian_product.py +++ b/src/sage/sets/cartesian_product.py @@ -36,14 +36,14 @@ class CartesianProduct(UniqueRepresentation, Parent): EXAMPLES:: - sage: G = cartesian_product([GF(5), Permutations(10)]) - sage: G.cartesian_factors() + sage: G = cartesian_product([GF(5), Permutations(10)]) # optional - sage.rings.finite_rings + sage: G.cartesian_factors() # optional - sage.rings.finite_rings (Finite Field of size 5, Standard permutations of 10) - sage: G.cardinality() + sage: G.cardinality() # optional - sage.rings.finite_rings 18144000 - sage: G.random_element() # random + sage: G.random_element() # random # optional - sage.rings.finite_rings (1, [4, 7, 6, 5, 10, 1, 3, 2, 8, 9]) - sage: G.category() + sage: G.category() # optional - sage.rings.finite_rings Join of Category of finite monoids and Category of Cartesian products of monoids and Category of Cartesian products of finite enumerated sets @@ -92,24 +92,24 @@ def _element_constructor_(self,x): EXAMPLES:: - sage: C = cartesian_product([GF(5), GF(3)]) - sage: x = C((1,3)); x + sage: C = cartesian_product([GF(5), GF(3)]) # optional - sage.rings.finite_rings + sage: x = C((1,3)); x # optional - sage.rings.finite_rings (1, 0) - sage: x.parent() + sage: x.parent() # optional - sage.rings.finite_rings The Cartesian product of (Finite Field of size 5, Finite Field of size 3) - sage: x[0].parent() + sage: x[0].parent() # optional - sage.rings.finite_rings Finite Field of size 5 - sage: x[1].parent() + sage: x[1].parent() # optional - sage.rings.finite_rings Finite Field of size 3 An iterable is also accepted as input:: - sage: C(i for i in range(2)) + sage: C(i for i in range(2)) # optional - sage.rings.finite_rings (0, 1) TESTS:: - sage: C((1,3,4)) + sage: C((1,3,4)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: (1, 3, 4) should be of length 2 diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 34265775dd3..e84e01e60a2 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -62,28 +62,28 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope sage: 7/2 in EvensAndOdds False - sage: var('y') + sage: var('y') # optional - sage.symbolic y - sage: SmallOdds = ConditionSet(ZZ, is_odd, abs(y) <= 11, vars=[y]); SmallOdds + sage: SmallOdds = ConditionSet(ZZ, is_odd, abs(y) <= 11, vars=[y]); SmallOdds # optional - sage.symbolic { y ∈ Integer Ring : abs(y) <= 11, (y) } - sage: P = polytopes.cube(); P + sage: P = polytopes.cube(); P # optional - sage.geometry.polyhedron A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices - sage: P.rename("P") - sage: P_inter_B = ConditionSet(P, lambda x: x.norm() < 1.2); P_inter_B + sage: P.rename("P") # optional - sage.geometry.polyhedron + sage: P_inter_B = ConditionSet(P, lambda x: x.norm() < 1.2); P_inter_B # optional - sage.geometry.polyhedron { x ∈ P : at 0x...>(x) } - sage: vector([1, 0, 0]) in P_inter_B + sage: vector([1, 0, 0]) in P_inter_B # optional - sage.geometry.polyhedron True - sage: vector([1, 1, 1]) in P_inter_B + sage: vector([1, 1, 1]) in P_inter_B # optional - sage.geometry.polyhedron False - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 1.2; predicate + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 1.2; predicate # optional - sage.symbolic (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 1.20000000000000 - sage: P_inter_B_again = ConditionSet(P, predicate); P_inter_B_again + sage: P_inter_B_again = ConditionSet(P, predicate); P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic { (x, y, z) ∈ P : sqrt(x^2 + y^2 + z^2) < 1.20000000000000 } - sage: vector([1, 0, 0]) in P_inter_B_again + sage: vector([1, 0, 0]) in P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic True - sage: vector([1, 1, 1]) in P_inter_B_again + sage: vector([1, 1, 1]) in P_inter_B_again # optional - sage.geometry.polyhedron sage.symbolic False Iterating over subsets determined by predicates:: @@ -104,24 +104,25 @@ class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_ope Using ``ConditionSet`` without predicates provides a way of attaching variable names to a set:: - sage: Z3 = ConditionSet(ZZ^3, vars=['x', 'y', 'z']); Z3 - { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring } - sage: Z3.variable_names() + sage: Z3 = ConditionSet(ZZ^3, vars=['x', 'y', 'z']); Z3 # optional - sage.modules + { (x, y, z) ∈ Ambient free module of rank 3 + over the principal ideal domain Integer Ring } + sage: Z3.variable_names() # optional - sage.modules ('x', 'y', 'z') - sage: Z3.arguments() + sage: Z3.arguments() # optional - sage.modules (x, y, z) - sage: Q4. = ConditionSet(QQ^4); Q4 + sage: Q4. = ConditionSet(QQ^4); Q4 # optional - sage.modules { (a, b, c, d) ∈ Vector space of dimension 4 over Rational Field } - sage: Q4.variable_names() + sage: Q4.variable_names() # optional - sage.modules ('a', 'b', 'c', 'd') - sage: Q4.arguments() + sage: Q4.arguments() # optional - sage.modules (a, b, c, d) TESTS:: - sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas - sage: TestSuite(P_inter_B_again).run() + sage: TestSuite(P_inter_B).run(skip='_test_pickling') # cannot pickle lambdas # optional - sage.geometry.polyhedron + sage: TestSuite(P_inter_B_again).run() # optional - sage.geometry.polyhedron sage.symbolic """ @staticmethod def __classcall_private__(cls, universe, *predicates, vars=None, names=None, category=None): @@ -130,9 +131,9 @@ def __classcall_private__(cls, universe, *predicates, vars=None, names=None, cat TESTS:: - sage: ConditionSet(ZZ, names=["x"]) is ConditionSet(ZZ, names=x) + sage: ConditionSet(ZZ, names=["x"]) is ConditionSet(ZZ, names=x) # optional - sage.symbolic True - sage: ConditionSet(RR, x > 0, names=x) is ConditionSet(RR, (x > 0).function(x)) + sage: ConditionSet(RR, x > 0, names=x) is ConditionSet(RR, (x > 0).function(x)) # optional - sage.symbolic True """ if category is None: @@ -224,10 +225,10 @@ def _repr_(self): EXAMPLES:: - sage: var('t') # parameter + sage: var('t') # parameter # optional - sage.symbolic t - sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) - sage: ZeroDimButNotNullary._repr_() + sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) # optional - sage.symbolic + sage: ZeroDimButNotNullary._repr_() # optional - sage.symbolic '{ q ∈ Ambient free module of rank 0 over the principal ideal domain Integer Ring : t > 0 }' """ @@ -257,13 +258,13 @@ def _repr_condition(self, predicate): sage: Evens = ConditionSet(ZZ, is_even) sage: Evens._repr_condition(is_even) '(x)' - sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) - sage: BigSin._repr_condition(BigSin._predicates[0]) + sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) # optional - sage.symbolic + sage: BigSin._repr_condition(BigSin._predicates[0]) # optional - sage.symbolic 'sin(x) > 0.900000000000000' - sage: var('t') # parameter + sage: var('t') # parameter # optional - sage.symbolic t - sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) - sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) + sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) # optional - sage.symbolic + sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) # optional - sage.symbolic 't > 0' """ if isinstance(predicate, Expression) and predicate.is_callable(): @@ -285,9 +286,9 @@ def arguments(self): sage: Odds = ConditionSet(ZZ, is_odd); Odds { x ∈ Integer Ring : (x) } - sage: args = Odds.arguments(); args + sage: args = Odds.arguments(); args # optional - sage.symbolic (x,) - sage: args[0].parent() + sage: args[0].parent() # optional - sage.symbolic Symbolic Ring """ from sage.symbolic.ring import SR @@ -339,24 +340,24 @@ def _call_predicate(self, predicate, element): TESTS:: - sage: TripleDigits = ZZ^3 - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate + sage: TripleDigits = ZZ^3 # optional - sage.modules + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # optional - sage.symbolic (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # optional - sage.symbolic { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: predicate = SmallTriples._predicates[0] - sage: element = TripleDigits((1, 2, 3)) - sage: SmallTriples._call_predicate(predicate, element) + sage: predicate = SmallTriples._predicates[0] # optional - sage.symbolic + sage: element = TripleDigits((1, 2, 3)) # optional - sage.symbolic + sage: SmallTriples._call_predicate(predicate, element) # optional - sage.symbolic sqrt(14) < 12 - sage: var('t') + sage: var('t') # optional - sage.symbolic t - sage: TinyUniverse = ZZ^0 - sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) - sage: predicate = Nullary._predicates[0] - sage: element = TinyUniverse(0) - sage: Nullary._call_predicate(predicate, element) + sage: TinyUniverse = ZZ^0 # optional - sage.modules + sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) # optional - sage.symbolic + sage: predicate = Nullary._predicates[0] # optional - sage.symbolic + sage: element = TinyUniverse(0) # optional - sage.symbolic + sage: Nullary._call_predicate(predicate, element) # optional - sage.symbolic t > 0 """ if isinstance(predicate, Expression) and predicate.is_callable(): @@ -372,13 +373,13 @@ def _an_element_(self): TESTS:: - sage: TripleDigits = ZZ^3 - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate + sage: TripleDigits = ZZ^3 # optional - sage.modules + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # optional - sage.symbolic (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # optional - sage.symbolic { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: SmallTriples.an_element() # indirect doctest + sage: SmallTriples.an_element() # indirect doctest # optional - sage.symbolic (1, 0, 0) """ for element in self._universe.some_elements(): @@ -406,17 +407,17 @@ def _sympy_(self): EXAMPLES:: - sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate + sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # optional - sage.symbolic (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 - sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples + sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # optional - sage.symbolic { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } - sage: ST = SmallTriples._sympy_(); ST + sage: ST = SmallTriples._sympy_(); ST # optional - sage.symbolic ConditionSet((x, y, z), sqrt(x**2 + y**2 + z**2) < 12, ProductSet(Integers, Integers, Integers)) - sage: (1, 3, 5) in ST + sage: (1, 3, 5) in ST # optional - sage.symbolic True - sage: (5, 7, 9) in ST + sage: (5, 7, 9) in ST # optional - sage.symbolic False sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval @@ -463,15 +464,16 @@ def intersection(self, X): EXAMPLES:: - sage: in_small_oblong(x, y) = x^2 + 3 * y^2 <= 42 - sage: SmallOblongUniverse = ConditionSet(QQ^2, in_small_oblong) - sage: SmallOblongUniverse - { (x, y) ∈ Vector space of dimension 2 over Rational Field : x^2 + 3*y^2 <= 42 } - sage: parity_check(x, y) = abs(sin(pi/2*(x + y))) < 1/1000 - sage: EvenUniverse = ConditionSet(ZZ^2, parity_check); EvenUniverse + sage: in_small_oblong(x, y) = x^2 + 3 * y^2 <= 42 # optional - sage.symbolic + sage: SmallOblongUniverse = ConditionSet(QQ^2, in_small_oblong) # optional - sage.symbolic + sage: SmallOblongUniverse # optional - sage.symbolic + { (x, y) ∈ Vector space of dimension 2 + over Rational Field : x^2 + 3*y^2 <= 42 } + sage: parity_check(x, y) = abs(sin(pi/2*(x + y))) < 1/1000 # optional - sage.symbolic + sage: EvenUniverse = ConditionSet(ZZ^2, parity_check); EvenUniverse # optional - sage.symbolic { (x, y) ∈ Ambient free module of rank 2 over the principal ideal domain Integer Ring : abs(sin(1/2*pi*x + 1/2*pi*y)) < (1/1000) } - sage: SmallOblongUniverse & EvenUniverse + sage: SmallOblongUniverse & EvenUniverse # optional - sage.symbolic { (x, y) ∈ Free module of degree 2 and rank 2 over Integer Ring Echelon basis matrix: [1 0] @@ -480,13 +482,17 @@ def intersection(self, X): Combining two ``ConditionSet``s with different formal variables works correctly. The formal variables of the intersection are taken from ``self``:: - sage: SmallMirrorUniverse = ConditionSet(QQ^2, in_small_oblong, vars=(y, x)) - sage: SmallMirrorUniverse - { (y, x) ∈ Vector space of dimension 2 over Rational Field : 3*x^2 + y^2 <= 42 } - sage: SmallOblongUniverse & SmallMirrorUniverse - { (x, y) ∈ Vector space of dimension 2 over Rational Field : x^2 + 3*y^2 <= 42 } - sage: SmallMirrorUniverse & SmallOblongUniverse - { (y, x) ∈ Vector space of dimension 2 over Rational Field : 3*x^2 + y^2 <= 42 } + sage: SmallMirrorUniverse = ConditionSet(QQ^2, in_small_oblong, # optional - sage.symbolic + ....: vars=(y, x)) + sage: SmallMirrorUniverse # optional - sage.symbolic + { (y, x) ∈ Vector space of dimension 2 + over Rational Field : 3*x^2 + y^2 <= 42 } + sage: SmallOblongUniverse & SmallMirrorUniverse # optional - sage.symbolic + { (x, y) ∈ Vector space of dimension 2 + over Rational Field : x^2 + 3*y^2 <= 42 } + sage: SmallMirrorUniverse & SmallOblongUniverse # optional - sage.symbolic + { (y, x) ∈ Vector space of dimension 2 + over Rational Field : 3*x^2 + y^2 <= 42 } """ if isinstance(X, ConditionSet): return ConditionSet(self.ambient().intersection(X.ambient()), diff --git a/src/sage/sets/disjoint_union_enumerated_sets.py b/src/sage/sets/disjoint_union_enumerated_sets.py index 8e272984619..c8497e3d9b4 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -89,30 +89,32 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): In general the input can be any family:: - sage: U3 = DisjointUnionEnumeratedSets( + sage: U3 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([2,3,4], Permutations, lazy=True)) - sage: U3 - Disjoint union of Lazy family ((i))_{i in [2, 3, 4]} - sage: U3.cardinality() + sage: U3 # optional - sage.combinat + Disjoint union of Lazy family + ((i))_{i in [2, 3, 4]} + sage: U3.cardinality() # optional - sage.combinat 32 - sage: it = iter(U3) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U3) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [[1, 2], [2, 1], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1]] - sage: U3.unrank(18) + sage: U3.unrank(18) # optional - sage.combinat [2, 4, 1, 3] This allows for infinite unions:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations)) - sage: U4 - Disjoint union of Lazy family ((i))_{i in Non negative integers} - sage: U4.cardinality() + sage: U4 # optional - sage.combinat + Disjoint union of Lazy family + ((i))_{i in Non negative integers} + sage: U4.cardinality() # optional - sage.combinat +Infinity - sage: it = iter(U4) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U4) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: U4.unrank(18) + sage: U4.unrank(18) # optional - sage.combinat [2, 3, 1, 4] .. WARNING:: @@ -125,41 +127,41 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): We demonstrate the ``keepkey`` option:: - sage: Ukeep = DisjointUnionEnumeratedSets( + sage: Ukeep = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(list(range(4)), Permutations), keepkey=True) - sage: it = iter(Ukeep) - sage: [next(it) for i in range(6)] + sage: it = iter(Ukeep) # optional - sage.combinat + sage: [next(it) for i in range(6)] # optional - sage.combinat [(0, []), (1, [1]), (2, [1, 2]), (2, [2, 1]), (3, [1, 2, 3]), (3, [1, 3, 2])] - sage: type(next(it)[1]) + sage: type(next(it)[1]) # optional - sage.combinat We now demonstrate the ``facade`` option:: - sage: UNoFacade = DisjointUnionEnumeratedSets( + sage: UNoFacade = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(list(range(4)), Permutations), facade=False) - sage: it = iter(UNoFacade) - sage: [next(it) for i in range(6)] + sage: it = iter(UNoFacade) # optional - sage.combinat + sage: [next(it) for i in range(6)] # optional - sage.combinat [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: el = next(it); el + sage: el = next(it); el # optional - sage.combinat [2, 1, 3] - sage: type(el) + sage: type(el) # optional - sage.combinat <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: el.parent() == UNoFacade + sage: el.parent() == UNoFacade # optional - sage.combinat True - sage: elv = el.value; elv + sage: elv = el.value; elv # optional - sage.combinat [2, 1, 3] - sage: type(elv) + sage: type(elv) # optional - sage.combinat The elements ``el`` of the disjoint union are simple wrapped elements. So to access the methods, you need to do ``el.value``:: - sage: el[0] + sage: el[0] # optional - sage.combinat Traceback (most recent call last): ... TypeError: 'sage.structure.element_wrapper.ElementWrapper' object is not subscriptable - sage: el.value[0] + sage: el.value[0] # optional - sage.combinat 2 Possible extensions: the current enumeration order is not suitable @@ -181,12 +183,12 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): :class:`DisjointUnionEnumeratedSets`. Then, one simply writes the ``__init__`` method as usual:: - sage: class MyUnion(DisjointUnionEnumeratedSets): + sage: class MyUnion(DisjointUnionEnumeratedSets): # optional - sage.combinat ....: def __init__(self): ....: DisjointUnionEnumeratedSets.__init__(self, ....: Family([1,2], Permutations)) - sage: pp = MyUnion() - sage: pp.list() + sage: pp = MyUnion() # optional - sage.combinat + sage: pp.list() # optional - sage.combinat [[1], [1, 2], [2, 1]] In case the :meth:`__init__` method takes optional arguments, @@ -201,19 +203,21 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): sage: class UnionOfSpecialSets(DisjointUnionEnumeratedSets): ....: __classcall_private__ = staticmethod(DisjointUnionEnumeratedSets.__classcall_private__) - sage: psp = UnionOfSpecialSets(Family([1,2], Permutations)) - sage: psp.list() + sage: psp = UnionOfSpecialSets(Family([1,2], Permutations)) # optional - sage.combinat + sage: psp.list() # optional - sage.combinat [[1], [1, 2], [2, 1]] TESTS:: sage: TestSuite(U1).run() sage: TestSuite(U2).run() - sage: TestSuite(U3).run() - sage: TestSuite(U4).run() - doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union + sage: TestSuite(U3).run() # optional - sage.combinat + sage: TestSuite(U4).run() # optional - sage.combinat + doctest:...: UserWarning: Disjoint union of Lazy family + ((i))_{i in Non negative integers} + is an infinite union The default implementation of __contains__ can loop forever. Please overload it. - sage: TestSuite(UNoFacade).run() + sage: TestSuite(UNoFacade).run() # optional - sage.combinat We skip ``_test_an_element`` because the coercion framework does not currently allow a tuple to be returned for facade parents:: @@ -225,11 +229,11 @@ class DisjointUnionEnumeratedSets(UniqueRepresentation, Parent): been defined interactively:: sage: import __main__ - sage: __main__.MyUnion = MyUnion + sage: __main__.MyUnion = MyUnion # optional - sage.combinat sage: __main__.UnionOfSpecialSets = UnionOfSpecialSets - sage: TestSuite(pp).run() - sage: TestSuite(psp).run() + sage: TestSuite(pp).run() # optional - sage.combinat + sage: TestSuite(psp).run() # optional - sage.combinat """ @@ -322,10 +326,12 @@ def _is_a(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Compositions)) - sage: U4._is_a(Composition([3,2,1,1])) - doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union + sage: U4._is_a(Composition([3,2,1,1])) # optional - sage.combinat + doctest:...: UserWarning: Disjoint union of Lazy family + ((i))_{i in Non negative integers} + is an infinite union The default implementation of __contains__ can loop forever. Please overload it. True """ @@ -351,17 +357,19 @@ def __contains__(self, x): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Partitions)) - sage: Partition([]) in U4 - doctest:...: UserWarning: Disjoint union of Lazy family ((i))_{i in Non negative integers} is an infinite union + sage: Partition([]) in U4 # optional - sage.combinat + doctest:...: UserWarning: Disjoint union of Lazy family + ((i))_{i in Non negative integers} + is an infinite union The default implementation of __contains__ can loop forever. Please overload it. True Note: one has to use a different family from the previous one in this file otherwise the warning is not re-issued:: - sage: Partition([3,2,1,1]) in U4 + sage: Partition([3,2,1,1]) in U4 # optional - sage.combinat True The following call will loop forever:: @@ -380,21 +388,21 @@ def __iter__(self): """ TESTS:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations)) - sage: it = iter(U4) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U4) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2]] - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations), ....: keepkey=True, facade=False) - sage: it = iter(U4) - sage: [next(it), next(it), next(it), next(it), next(it), next(it)] + sage: it = iter(U4) # optional - sage.combinat + sage: [next(it), next(it), next(it), next(it), next(it), next(it)] # optional - sage.combinat [(0, []), (1, [1]), (2, [1, 2]), (2, [2, 1]), (3, [1, 2, 3]), (3, [1, 3, 2])] - sage: el = next(it); el.parent() == U4 + sage: el = next(it); el.parent() == U4 # optional - sage.combinat True - sage: el.value == (3, Permutation([2,1,3])) + sage: el.value == (3, Permutation([2,1,3])) # optional - sage.combinat True """ for k in self._family.keys(): @@ -413,7 +421,7 @@ def an_element(self): EXAMPLES:: - sage: U4 = DisjointUnionEnumeratedSets( + sage: U4 = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([3, 5, 7], Permutations)) sage: U4.an_element() [1, 2, 3] @@ -430,16 +438,16 @@ def cardinality(self): For finite disjoint unions, the cardinality is computed by summing the cardinalities of the enumerated sets:: - sage: U = DisjointUnionEnumeratedSets(Family([0,1,2,3], Permutations)) - sage: U.cardinality() + sage: U = DisjointUnionEnumeratedSets(Family([0,1,2,3], Permutations)) # optional - sage.combinat + sage: U.cardinality() # optional - sage.combinat 10 For infinite disjoint unions, this makes the assumption that the result is infinite:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family(NonNegativeIntegers(), Permutations)) - sage: U.cardinality() + sage: U.cardinality() # optional - sage.combinat +Infinity .. WARNING:: @@ -462,14 +470,14 @@ def _element_constructor_(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=False) - sage: U._element_constructor_ + sage: U._element_constructor_ # optional - sage.combinat - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=True) - sage: U._element_constructor_ + sage: U._element_constructor_ # optional - sage.combinat """ @@ -482,13 +490,13 @@ def _element_constructor_default(self, el): r""" TESTS:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=False) - sage: U([1]) # indirect doctest + sage: U([1]) # indirect doctest # optional - sage.combinat [1] - sage: U([2,1]) # indirect doctest + sage: U([2,1]) # indirect doctest # optional - sage.combinat [2, 1] - sage: U([1,3,2]) # indirect doctest + sage: U([1,3,2]) # indirect doctest # optional - sage.combinat Traceback (most recent call last): ... ValueError: value [1, 3, 2] does not belong to Disjoint union of @@ -496,13 +504,13 @@ def _element_constructor_default(self, el): 2: Partitions of the integer 2, 3: Partitions of the integer 3} - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), keepkey=True, facade=False) - sage: U((1, [1])) # indirect doctest + sage: U((1, [1])) # indirect doctest # optional - sage.combinat (1, [1]) - sage: U((3,[2,1])) # indirect doctest + sage: U((3,[2,1])) # indirect doctest # optional - sage.combinat (3, [2, 1]) - sage: U((4,[2,1])) # indirect doctest + sage: U((4,[2,1])) # indirect doctest # optional - sage.combinat Traceback (most recent call last): ... ValueError: value (4, [2, 1]) does not belong to Disjoint union of @@ -521,12 +529,12 @@ def _element_constructor_facade(self, el): """ TESTS:: - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) - sage: X([1]).parent() + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}) # optional - sage.combinat + sage: X([1]).parent() # optional - sage.combinat Partitions of the integer 1 - sage: X([2,1,1]).parent() # indirect doctest + sage: X([2,1,1]).parent() # indirect doctest # optional - sage.combinat Partitions of the integer 4 - sage: X([6]) + sage: X([6]) # optional - sage.combinat Traceback (most recent call last): ... ValueError: cannot coerce `[6]` in any parent in `Finite family {...}` @@ -535,23 +543,23 @@ def _element_constructor_facade(self, el): because this returns a `tuple`, where the coercion framework requires an :class:`Element` be returned. - sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}, + sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)}, # optional - sage.combinat ....: keepkey=True) - sage: p = X._element_constructor_((0, [])) # indirect doctest - sage: p[1].parent() + sage: p = X._element_constructor_((0, [])) # indirect doctest # optional - sage.combinat + sage: p[1].parent() # optional - sage.combinat Partitions of the integer 0 Test that facade parents can create and properly access elements that are tuples (fixed by :trac:`22382`):: - sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), + sage: f = lambda mu: cartesian_product([mu.standard_tableaux(), # optional - sage.combinat ....: mu.standard_tableaux()]) - sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) - sage: s = StandardTableau([[1,3],[2,4]]) - sage: (s,s) in tabs + sage: tabs = DisjointUnionEnumeratedSets(Family(Partitions(4), f)) # optional - sage.combinat + sage: s = StandardTableau([[1,3],[2,4]]) # optional - sage.combinat + sage: (s,s) in tabs # optional - sage.combinat True - sage: ss = tabs( (s,s) ) - sage: ss[0] + sage: ss = tabs( (s,s) ) # optional - sage.combinat + sage: ss[0] # optional - sage.combinat [[1, 3], [2, 4]] We do not coerce when one of the elements is already in the set:: @@ -587,13 +595,13 @@ def Element(self): """ TESTS:: - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=False) - sage: U.Element + sage: U.Element # optional - sage.combinat <... 'sage.structure.element_wrapper.ElementWrapper'> - sage: U = DisjointUnionEnumeratedSets( + sage: U = DisjointUnionEnumeratedSets( # optional - sage.combinat ....: Family([1,2,3], Partitions), facade=True) - sage: U.Element + sage: U.Element # optional - sage.combinat Traceback (most recent call last): ... AttributeError: 'DisjointUnionEnumeratedSets_with_category' object has no attribute 'Element' diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index 10c59a02490..bd4052a58e6 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -1064,7 +1064,7 @@ def _repr_(self): Check that using a class as the function is correctly handled:: - sage: Family(NonNegativeIntegers(), PerfectMatchings) + sage: Family(NonNegativeIntegers(), PerfectMatchings) # optional - sage.combinat Lazy family ((i))_{i in Non negative integers} """ if self.function_name is not None: diff --git a/src/sage/sets/image_set.py b/src/sage/sets/image_set.py index 54b78eede7a..65676989403 100644 --- a/src/sage/sets/image_set.py +++ b/src/sage/sets/image_set.py @@ -73,12 +73,12 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve EXAMPLES:: - sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) + sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) # optional - sage.modules sage: R. = QQ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) - sage: Im = f.image() - sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', # optional - sage.modules ....: '_test_some_elements', '_test_elements']) """ if not is_Parent(domain_subset): @@ -173,20 +173,20 @@ def ambient(self): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) - sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) - sage: Im = f.image() - sage: Im.ambient() is R + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules + sage: R. = ZZ[] # optional - sage.modules + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: Im.ambient() is R # optional - sage.modules True - sage: P = Partitions(3).map(attrcall('conjugate')) - sage: P.ambient() is None + sage: P = Partitions(3).map(attrcall('conjugate')) # optional - sage.combinat + sage: P.ambient() is None # optional - sage.combinat True - sage: R = Permutations(10).map(attrcall('reduced_word')) - sage: R.ambient() is None + sage: R = Permutations(10).map(attrcall('reduced_word')) # optional - sage.combinat + sage: R.ambient() is None # optional - sage.combinat True """ return self._map.codomain() @@ -197,14 +197,14 @@ def lift(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) - sage: Im = f.image() - sage: p = Im.lift(Im.an_element()); p + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: p = Im.lift(Im.an_element()); p # optional - sage.modules 2*x - 4 - sage: p.parent() is R + sage: p.parent() is R # optional - sage.modules True """ return x @@ -219,13 +219,13 @@ def retract(self, x): EXAMPLES:: - sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) - sage: R. = ZZ[] - sage: H = Hom(M, R, category=Sets()) - sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) - sage: Im = f.image() - sage: p = 2 * x - 4 - sage: Im.retract(p).parent() + sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # optional - sage.modules + sage: R. = ZZ[] # optional - sage.modules + sage: H = Hom(M, R, category=Sets()) # optional - sage.modules + sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # optional - sage.modules + sage: Im = f.image() # optional - sage.modules + sage: p = 2 * x - 4 # optional - sage.modules + sage: Im.retract(p).parent() # optional - sage.modules Multivariate Polynomial Ring in x, y over Integer Ring """ return x @@ -234,7 +234,7 @@ def _repr_(self) -> str: r""" TESTS:: - sage: Partitions(3).map(attrcall('conjugate')) + sage: Partitions(3).map(attrcall('conjugate')) # optional - sage.combinat Image of Partitions of the integer 3 by The map *.conjugate() from Partitions of the integer 3 """ @@ -251,8 +251,8 @@ def cardinality(self) -> Integer: :meth:`~sage.categories.enumerated_sets.EnumeratedSets.ParentMethods.map` defaults to ``is_injective=True``): - sage: R = Permutations(10).map(attrcall('reduced_word')) - sage: R.cardinality() + sage: R = Permutations(10).map(attrcall('reduced_word')) # optional - sage.combinat + sage: R.cardinality() # optional - sage.combinat 3628800 sage: Evens = ZZ.map(lambda x: 2 * x) @@ -294,12 +294,12 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: P = Partitions() - sage: H = Hom(P, ZZ) - sage: f = H(ZZ.sum) - sage: X = f.image() - sage: it = iter(X) - sage: [next(it) for _ in range(5)] + sage: P = Partitions() # optional - sage.combinat + sage: H = Hom(P, ZZ) # optional - sage.combinat + sage: f = H(ZZ.sum) # optional - sage.combinat + sage: X = f.image() # optional - sage.combinat + sage: it = iter(X) # optional - sage.combinat + sage: [next(it) for _ in range(5)] # optional - sage.combinat [0, 1, 2, 3, 4] """ if self._is_injective and self._is_injective != 'check': @@ -322,8 +322,8 @@ def _an_element_(self): EXAMPLES:: - sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) - sage: R.an_element() + sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) # optional - sage.groups + sage: R.an_element() # optional - sage.groups [9, 8, 7, 6, 5, 4, 3, 2] """ domain_element = self._domain_subset.an_element() @@ -336,9 +336,9 @@ def _sympy_(self): EXAMPLES:: sage: from sage.sets.image_set import ImageSet - sage: S = ImageSet(sin, RealSet.open(0, pi/4)); S + sage: S = ImageSet(sin, RealSet.open(0, pi/4)); S # optional - sage.symbolic Image of (0, 1/4*pi) by The map sin from (0, 1/4*pi) - sage: S._sympy_() + sage: S._sympy_() # optional - sage.symbolic ImageSet(Lambda(x, sin(x)), Interval.open(0, pi/4)) """ from sympy import imageset @@ -360,23 +360,23 @@ class ImageSet(ImageSubobject, Set_base, Set_add_sub_operators, Set_boolean_oper Symbolics:: - sage: ImageSet(sin, RealSet.open(0, pi/4)) + sage: ImageSet(sin, RealSet.open(0, pi/4)) # optional - sage.symbolic Image of (0, 1/4*pi) by The map sin from (0, 1/4*pi) - sage: _.an_element() + sage: _.an_element() # optional - sage.symbolic 1/2*sqrt(-sqrt(2) + 2) - sage: sos(x,y) = x^2 + y^2; sos + sage: sos(x,y) = x^2 + y^2; sos # optional - sage.symbolic (x, y) |--> x^2 + y^2 - sage: ImageSet(sos, ZZ^2) + sage: ImageSet(sos, ZZ^2) # optional - sage.symbolic Image of Ambient free module of rank 2 over the principal ideal domain Integer Ring by The map (x, y) |--> x^2 + y^2 from Vector space of dimension 2 over Symbolic Ring - sage: _.an_element() + sage: _.an_element() # optional - sage.symbolic 1 - sage: ImageSet(sos, Set([(3, 4), (3, -4)])) + sage: ImageSet(sos, Set([(3, 4), (3, -4)])) # optional - sage.symbolic Image of {...(3, -4)...} by The map (x, y) |--> x^2 + y^2 from Vector space of dimension 2 over Symbolic Ring - sage: _.an_element() + sage: _.an_element() # optional - sage.symbolic 25 """ pass diff --git a/src/sage/sets/non_negative_integers.py b/src/sage/sets/non_negative_integers.py index 29edc3a11a1..8caf33deacb 100644 --- a/src/sage/sets/non_negative_integers.py +++ b/src/sage/sets/non_negative_integers.py @@ -100,15 +100,15 @@ def __contains__(self, elt): True sage: -1 in NN False - sage: x in NN + sage: x in NN # optional - sage.symbolic False sage: None in NN False - sage: QQbar(sqrt(2)) in NN + sage: QQbar(sqrt(2)) in NN # optional - sage.symbolic sage.rings.number_field False sage: RIF(1,2) in NN False - sage: QQbar(2) in NN + sage: QQbar(2) in NN # optional - sage.rings.number_field True sage: RIF(2) in NN True @@ -133,7 +133,7 @@ def _element_constructor_(self, i): Traceback (most recent call last): ... ValueError: Value -5 in not in Non negative integers. - sage: NN._element_constructor_(x) + sage: NN._element_constructor_(x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Value x in not in Non negative integers. @@ -230,7 +230,7 @@ def _sympy_(self): EXAMPLES:: sage: NN = NonNegativeIntegers() - sage: NN._sympy_() + sage: NN._sympy_() # optional - sympy Naturals0 """ from sympy import Naturals0 diff --git a/src/sage/sets/positive_integers.py b/src/sage/sets/positive_integers.py index 7ed7d9657e9..34e1d77b05e 100644 --- a/src/sage/sets/positive_integers.py +++ b/src/sage/sets/positive_integers.py @@ -82,7 +82,7 @@ def _sympy_(self): EXAMPLES:: - sage: PositiveIntegers()._sympy_() + sage: PositiveIntegers()._sympy_() # optional - sympy Naturals """ from sympy import Naturals diff --git a/src/sage/sets/primes.py b/src/sage/sets/primes.py index 96558ba9215..d2fa00f4a44 100644 --- a/src/sage/sets/primes.py +++ b/src/sage/sets/primes.py @@ -123,7 +123,7 @@ def __contains__(self, x): False sage: 1.5 in P False - sage: e in P + sage: e in P # optional - sage.symbolic False """ try: diff --git a/src/sage/sets/real_set.py b/src/sage/sets/real_set.py index 47a0505de6b..b27c14e6a7f 100644 --- a/src/sage/sets/real_set.py +++ b/src/sage/sets/real_set.py @@ -48,24 +48,24 @@ Relations containing symbols and numeric values or constants:: - sage: RealSet(x != 0) + sage: RealSet(x != 0) # optional - sage.symbolic (-oo, 0) ∪ (0, +oo) - sage: RealSet(x == pi) + sage: RealSet(x == pi) # optional - sage.symbolic {pi} - sage: RealSet(x < 1/2) + sage: RealSet(x < 1/2) # optional - sage.symbolic (-oo, 1/2) - sage: RealSet(1/2 < x) + sage: RealSet(1/2 < x) # optional - sage.symbolic (1/2, +oo) - sage: RealSet(1.5 <= x) + sage: RealSet(1.5 <= x) # optional - sage.symbolic [1.50000000000000, +oo) Note that multiple arguments are combined as union:: - sage: RealSet(x >= 0, x < 1) + sage: RealSet(x >= 0, x < 1) # optional - sage.symbolic (-oo, +oo) - sage: RealSet(x >= 0, x > 1) + sage: RealSet(x >= 0, x > 1) # optional - sage.symbolic [0, +oo) - sage: RealSet(x >= 0, x > -1) + sage: RealSet(x >= 0, x > -1) # optional - sage.symbolic (-1, +oo) AUTHORS: @@ -406,9 +406,9 @@ def _latex_(self): EXAMPLES:: - sage: RealSet.open_closed(1/2, pi)._latex_() + sage: RealSet.open_closed(1/2, pi)._latex_() # optional - sage.symbolic '(\\frac{1}{2}, \\pi]' - sage: (RealSet.point(sqrt(2)))._latex_() + sage: (RealSet.point(sqrt(2)))._latex_() # optional - sage.symbolic '\\{\\sqrt{2}\\}' """ from sage.misc.latex import latex @@ -435,7 +435,7 @@ def _sympy_condition_(self, variable): EXAMPLES:: - sage: RealSet(0, 4)._sympy_condition_(x) + sage: RealSet(0, 4)._sympy_condition_(x) # optional - sage.symbolic (0 < x) & (x < 4) """ x = variable @@ -494,7 +494,7 @@ def _giac_condition_(self, variable): EXAMPLES:: - sage: RealSet(0, 4)._giac_condition_(x) + sage: RealSet(0, 4)._giac_condition_(x) # optional - sage.symbolic '((0 < sageVARx) and (sageVARx < 4))' """ x = variable @@ -985,30 +985,32 @@ class RealSet(UniqueRepresentation, Parent, Set_base, sage: i1, i2 = s1[0], s2[0] sage: RealSet(i2, i1) # union of intervals (1, 2) ∪ [3, 4] - sage: RealSet((-oo, 0), x > 6, i1, RealSet.point(5), RealSet.closed_open(4, 3)) + sage: RealSet((-oo, 0), x > 6, i1, RealSet.point(5), # optional - sage.symbolic + ....: RealSet.closed_open(4, 3)) (-oo, 0) ∪ (1, 2) ∪ [3, 4) ∪ {5} ∪ (6, +oo) Initialization from manifold objects:: - sage: R = manifolds.RealLine(); R + sage: R = manifolds.RealLine(); R # optional - sage.symbolic Real number line ℝ - sage: RealSet(R) + sage: RealSet(R) # optional - sage.symbolic (-oo, +oo) - sage: I02 = manifolds.OpenInterval(0, 2); I + sage: I02 = manifolds.OpenInterval(0, 2); I # optional - sage.symbolic I - sage: RealSet(I02) + sage: RealSet(I02) # optional - sage.symbolic (0, 2) - sage: I01_of_R = manifolds.OpenInterval(0, 1, ambient_interval=R); I01_of_R + sage: I01_of_R = manifolds.OpenInterval(0, 1, ambient_interval=R); I01_of_R # optional - sage.symbolic Real interval (0, 1) - sage: RealSet(I01_of_R) + sage: RealSet(I01_of_R) # optional - sage.symbolic (0, 1) - sage: RealSet(I01_of_R.closure()) + sage: RealSet(I01_of_R.closure()) # optional - sage.symbolic [0, 1] - sage: I01_of_I02 = manifolds.OpenInterval(0, 1, ambient_interval=I02); I01_of_I02 + sage: I01_of_I02 = manifolds.OpenInterval(0, 1, # optional - sage.symbolic + ....: ambient_interval=I02); I01_of_I02 Real interval (0, 1) - sage: RealSet(I01_of_I02) + sage: RealSet(I01_of_I02) # optional - sage.symbolic (0, 1) - sage: RealSet(I01_of_I02.closure()) + sage: RealSet(I01_of_I02.closure()) # optional - sage.symbolic (0, 1] Real sets belong to a subcategory of topological spaces:: @@ -1038,23 +1040,23 @@ class RealSet(UniqueRepresentation, Parent, Set_base, Constructing real sets as manifolds or manifold subsets by passing ``structure='differentiable'``:: - sage: RealSet(-oo, oo, structure='differentiable') + sage: RealSet(-oo, oo, structure='differentiable') # optional - sage.symbolic Real number line ℝ - sage: RealSet([0, 1], structure='differentiable') + sage: RealSet([0, 1], structure='differentiable') # optional - sage.symbolic Subset [0, 1] of the Real number line ℝ - sage: _.category() + sage: _.category() # optional - sage.symbolic Category of subobjects of sets - sage: RealSet.open_closed(0, 5, structure='differentiable') + sage: RealSet.open_closed(0, 5, structure='differentiable') # optional - sage.symbolic Subset (0, 5] of the Real number line ℝ This is implied when a coordinate name is given using the keywords ``coordinate`` or ``names``:: - sage: RealSet(0, 1, coordinate='λ') + sage: RealSet(0, 1, coordinate='λ') # optional - sage.symbolic Open subset (0, 1) of the Real number line ℝ - sage: _.category() + sage: _.category() # optional - sage.symbolic Join of Category of smooth manifolds over Real Field with 53 bits of precision and Category of connected manifolds over Real Field with 53 bits of precision and @@ -1062,44 +1064,44 @@ class RealSet(UniqueRepresentation, Parent, Set_base, It is also implied by assigning a coordinate name using generator notation:: - sage: R_xi.<ξ> = RealSet.real_line(); R_xi + sage: R_xi.<ξ> = RealSet.real_line(); R_xi # optional - sage.symbolic Real number line ℝ - sage: R_xi.canonical_chart() + sage: R_xi.canonical_chart() # optional - sage.symbolic Chart (ℝ, (ξ,)) With the keyword ``ambient``, we can construct a subset of a previously constructed manifold:: - sage: P_xi = RealSet(0, oo, ambient=R_xi); P_xi + sage: P_xi = RealSet(0, oo, ambient=R_xi); P_xi # optional - sage.symbolic Open subset (0, +oo) of the Real number line ℝ - sage: P_xi.default_chart() + sage: P_xi.default_chart() # optional - sage.symbolic Chart ((0, +oo), (ξ,)) - sage: B_xi = RealSet(0, 1, ambient=P_xi); B_xi + sage: B_xi = RealSet(0, 1, ambient=P_xi); B_xi # optional - sage.symbolic Open subset (0, 1) of the Real number line ℝ - sage: B_xi.default_chart() + sage: B_xi.default_chart() # optional - sage.symbolic Chart ((0, 1), (ξ,)) - sage: R_xi.subset_family() + sage: R_xi.subset_family() # optional - sage.symbolic Set {(0, +oo), (0, 1), ℝ} of open subsets of the Real number line ℝ - sage: F = RealSet.point(0).union(RealSet.point(1)).union(RealSet.point(2)); F + sage: F = RealSet.point(0).union(RealSet.point(1)).union(RealSet.point(2)); F # optional - sage.symbolic {0} ∪ {1} ∪ {2} - sage: F_tau = RealSet(F, names="τ"); F_tau + sage: F_tau = RealSet(F, names="τ"); F_tau # optional - sage.symbolic Subset {0} ∪ {1} ∪ {2} of the Real number line ℝ - sage: F_tau.manifold().canonical_chart() + sage: F_tau.manifold().canonical_chart() # optional - sage.symbolic Chart (ℝ, (τ,)) TESTS:: - sage: TestSuite(R_xi).run() - sage: TestSuite(P_xi).run() - sage: R_xi.point((1,)) in P_xi + sage: TestSuite(R_xi).run() # optional - sage.symbolic + sage: TestSuite(P_xi).run() # optional - sage.symbolic + sage: R_xi.point((1,)) in P_xi # optional - sage.symbolic True - sage: R_xi.point((-1,)) in P_xi + sage: R_xi.point((-1,)) in P_xi # optional - sage.symbolic False - sage: TestSuite(B_xi).run() - sage: p = B_xi.an_element(); p + sage: TestSuite(B_xi).run() # optional - sage.symbolic + sage: p = B_xi.an_element(); p # optional - sage.symbolic Point on the Real number line ℝ - sage: p.coordinates() + sage: p.coordinates() # optional - sage.symbolic (1/2,) """ @@ -1123,48 +1125,48 @@ def __classcall__(cls, *args, **kwds): TESTS:: - sage: RealSet(x != 0) + sage: RealSet(x != 0) # optional - sage.symbolic (-oo, 0) ∪ (0, +oo) - sage: RealSet(x == pi) + sage: RealSet(x == pi) # optional - sage.symbolic {pi} - sage: RealSet(x < 1/2) + sage: RealSet(x < 1/2) # optional - sage.symbolic (-oo, 1/2) - sage: RealSet(1/2 < x) + sage: RealSet(1/2 < x) # optional - sage.symbolic (1/2, +oo) - sage: RealSet(1.5 <= x) + sage: RealSet(1.5 <= x) # optional - sage.symbolic [1.50000000000000, +oo) - sage: RealSet(x >= -1) + sage: RealSet(x >= -1) # optional - sage.symbolic [-1, +oo) - sage: RealSet(x > oo) + sage: RealSet(x > oo) # optional - sage.symbolic {} - sage: RealSet(x >= oo) + sage: RealSet(x >= oo) # optional - sage.symbolic {} - sage: RealSet(x <= -oo) + sage: RealSet(x <= -oo) # optional - sage.symbolic {} - sage: RealSet(x < oo) + sage: RealSet(x < oo) # optional - sage.symbolic (-oo, +oo) - sage: RealSet(x > -oo) + sage: RealSet(x > -oo) # optional - sage.symbolic (-oo, +oo) - sage: RealSet(x != oo) + sage: RealSet(x != oo) # optional - sage.symbolic (-oo, +oo) - sage: RealSet(x <= oo) + sage: RealSet(x <= oo) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: interval cannot be closed at +oo - sage: RealSet(x == oo) + sage: RealSet(x == oo) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: interval cannot be closed at +oo - sage: RealSet(x >= -oo) + sage: RealSet(x >= -oo) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: interval cannot be closed at -oo - sage: r = RealSet(2,10) - sage: RealSet((2, 6), (4, 10)) is r + sage: r = RealSet(2,10) # optional - sage.symbolic + sage: RealSet((2, 6), (4, 10)) is r # optional - sage.symbolic True - sage: RealSet(x > 2).intersection(RealSet(x < 10)) is RealSet(r[0], normalized=True) + sage: RealSet(x > 2).intersection(RealSet(x < 10)) is RealSet(r[0], normalized=True) # optional - sage.symbolic True - sage: RealSet(x > 0, normalized=True) + sage: RealSet(x > 0, normalized=True) # optional - sage.symbolic Traceback (most recent call last): ... AttributeError: ... @@ -1628,20 +1630,20 @@ def _sympy_condition_(self, variable): EXAMPLES:: - sage: RealSet(0, 1)._sympy_condition_(x) + sage: RealSet(0, 1)._sympy_condition_(x) # optional - sage.symbolic (0 < x) & (x < 1) - sage: RealSet((0,1), [2,3])._sympy_condition_(x) + sage: RealSet((0,1), [2,3])._sympy_condition_(x) # optional - sage.symbolic ((2 <= x) & (x <= 3)) | ((0 < x) & (x < 1)) - sage: RealSet.unbounded_below_open(0)._sympy_condition_(x) + sage: RealSet.unbounded_below_open(0)._sympy_condition_(x) # optional - sage.symbolic x < 0 - sage: RealSet.unbounded_above_closed(2)._sympy_condition_(x) + sage: RealSet.unbounded_above_closed(2)._sympy_condition_(x) # optional - sage.symbolic 2 <= x TESTS:: - sage: RealSet(6,6)._sympy_condition_(x) + sage: RealSet(6,6)._sympy_condition_(x) # optional - sage.symbolic False - sage: RealSet([6,6])._sympy_condition_(x) + sage: RealSet([6,6])._sympy_condition_(x) # optional - sage.symbolic Eq(x, 6) """ x = variable @@ -1664,20 +1666,20 @@ def _giac_condition_(self, variable): EXAMPLES:: - sage: RealSet(0, 1)._giac_condition_(x) + sage: RealSet(0, 1)._giac_condition_(x) # optional - sage.symbolic '((0 < sageVARx) and (sageVARx < 1))' - sage: RealSet((0,1), [2,3])._giac_condition_(x) + sage: RealSet((0,1), [2,3])._giac_condition_(x) # optional - sage.symbolic '((0 < sageVARx) and (sageVARx < 1)) or ((2 <= sageVARx) and (sageVARx <= 3))' - sage: RealSet.unbounded_below_open(0)._giac_condition_(x) + sage: RealSet.unbounded_below_open(0)._giac_condition_(x) # optional - sage.symbolic '((true) and (sageVARx < 0))' - sage: RealSet.unbounded_above_closed(2)._giac_condition_(x) + sage: RealSet.unbounded_above_closed(2)._giac_condition_(x) # optional - sage.symbolic '((2 <= sageVARx) and (true))' TESTS:: - sage: RealSet(6,6)._giac_condition_(x) + sage: RealSet(6,6)._giac_condition_(x) # optional - sage.symbolic 'false' - sage: RealSet([6,6])._giac_condition_(x) + sage: RealSet([6,6])._giac_condition_(x) # optional - sage.symbolic 'sageVARx == 6' """ x = variable @@ -2170,7 +2172,7 @@ def intersection(self, *real_set_collection): [1, 10) sage: s5.intersection(-oo, +oo) [1, 10) - sage: s5.intersection(x != 2, (-oo, 3), RealSet.real_line()[0]) + sage: s5.intersection(x != 2, (-oo, 3), RealSet.real_line()[0]) # optional - sage.symbolic [1, 2) ∪ (2, 3) TESTS:: @@ -2284,7 +2286,7 @@ def complement(self): TESTS:: - sage: RealSet(x != 0).complement() + sage: RealSet(x != 0).complement() # optional - sage.symbolic {0} sage: RealSet.real_line().complement() {} @@ -2638,7 +2640,7 @@ def is_connected(self): (-oo, -10] ∪ (1, 3) sage: s3.is_connected() False - sage: RealSet(x != 0).is_connected() + sage: RealSet(x != 0).is_connected() # optional - sage.symbolic False sage: RealSet(-oo, oo).is_connected() True @@ -2795,7 +2797,7 @@ def __rmul__(self, other): sage: A = RealSet([0, 1/2], RealSet.unbounded_above_closed(2)); A [0, 1/2] ∪ [2, +oo) - sage: pi * A + sage: pi * A # optional - sage.symbolic [0, 1/2*pi] ∪ [2*pi, +oo) """ return self * other @@ -2806,21 +2808,21 @@ def _sympy_(self): EXAMPLES:: - sage: RealSet()._sympy_() + sage: RealSet()._sympy_() # optional - sympy EmptySet - sage: RealSet.point(5)._sympy_() # random - this output format is sympy >= 1.9 + sage: RealSet.point(5)._sympy_() # random - this format is sympy >= 1.9 # optional - sympy {5} - sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random + sage: (RealSet.point(1).union(RealSet.point(2)))._sympy_() # random # optional - sympy {1, 2} - sage: (RealSet(1, 2).union(RealSet.closed(3, 4)))._sympy_() + sage: (RealSet(1, 2).union(RealSet.closed(3, 4)))._sympy_() # optional - sympy Union(Interval.open(1, 2), Interval(3, 4)) - sage: RealSet(-oo, oo)._sympy_() + sage: RealSet(-oo, oo)._sympy_() # optional - sympy Reals Infinities are not elements:: - sage: import sympy - sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) + sage: import sympy # optional - sympy + sage: RealSet(-oo, oo)._sympy_().contains(sympy.oo) # optional - sympy False """ from sympy import Reals, Union diff --git a/src/sage/sets/recursively_enumerated_set.pyx b/src/sage/sets/recursively_enumerated_set.pyx index 2ee74cbae1c..5acfbc4655c 100644 --- a/src/sage/sets/recursively_enumerated_set.pyx +++ b/src/sage/sets/recursively_enumerated_set.pyx @@ -33,9 +33,9 @@ help with the enumeration. In this example, the seed is 0 and the successor function is either ``+2`` or ``+3``. This is the set of non negative linear combinations of 2 and 3:: - sage: succ = lambda a:[a+2,a+3] - sage: C = RecursivelyEnumeratedSet([0], succ) - sage: C + sage: def succ(a): + ....: return [a + 2, a + 3] + sage: C = RecursivelyEnumeratedSet([0], succ); C A recursively enumerated set (breadth first search) Breadth first search:: @@ -57,9 +57,12 @@ The origin ``(0, 0)`` as seed and the upper, lower, left and right lattice point as successor function. This function is symmetric since `p` is a successor of `q` if and only if `q` is a successor or `p`:: - sage: succ = lambda a: [(a[0]-1,a[1]), (a[0],a[1]-1), (a[0]+1,a[1]), (a[0],a[1]+1)] + sage: def succ(a): + ....: return [(a[0] - 1, a[1]), (a[0], a[1] - 1), + ....: (a[0] + 1, a[1]), (a[0], a[1] + 1)] sage: seeds = [(0,0)] - sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric', enumeration='depth') + sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric', + ....: enumeration='depth') sage: C A recursively enumerated set with a symmetric structure (depth first search) @@ -93,15 +96,15 @@ Identity permutation as seed and ``permutohedron_succ`` as successor function:: sage: succ = attrcall("permutohedron_succ") - sage: seed = [Permutation([1..5])] - sage: R = RecursivelyEnumeratedSet(seed, succ, structure='graded') - sage: R + sage: seed = [Permutation([1..5])] # optional - sage.combinat + sage: R = RecursivelyEnumeratedSet(seed, succ, structure='graded') # optional - sage.combinat + sage: R # optional - sage.combinat A recursively enumerated set with a graded structure (breadth first search) Depth first search iterator:: - sage: it_depth = R.depth_first_search_iterator() - sage: [next(it_depth) for _ in range(5)] + sage: it_depth = R.depth_first_search_iterator() # optional - sage.combinat + sage: [next(it_depth) for _ in range(5)] # optional - sage.combinat [[1, 2, 3, 4, 5], [1, 2, 3, 5, 4], [1, 2, 5, 3, 4], @@ -110,8 +113,8 @@ Depth first search iterator:: Breadth first search iterator:: - sage: it_breadth = R.breadth_first_search_iterator() - sage: [next(it_breadth) for _ in range(5)] + sage: it_breadth = R.breadth_first_search_iterator() # optional - sage.combinat + sage: [next(it_breadth) for _ in range(5)] # optional - sage.combinat [[1, 2, 3, 4, 5], [2, 1, 3, 4, 5], [1, 3, 2, 4, 5], @@ -120,20 +123,20 @@ Breadth first search iterator:: Elements of given depth iterator:: - sage: sorted(R.elements_of_depth_iterator(9)) + sage: sorted(R.elements_of_depth_iterator(9)) # optional - sage.combinat [[4, 5, 3, 2, 1], [5, 3, 4, 2, 1], [5, 4, 2, 3, 1], [5, 4, 3, 1, 2]] - sage: list(R.elements_of_depth_iterator(10)) + sage: list(R.elements_of_depth_iterator(10)) # optional - sage.combinat [[5, 4, 3, 2, 1]] Graded components (set of elements of the same depth):: - sage: sorted(R.graded_component(0)) + sage: sorted(R.graded_component(0)) # optional - sage.combinat [[1, 2, 3, 4, 5]] - sage: sorted(R.graded_component(1)) + sage: sorted(R.graded_component(1)) # optional - sage.combinat [[1, 2, 3, 5, 4], [1, 2, 4, 3, 5], [1, 3, 2, 4, 5], [2, 1, 3, 4, 5]] - sage: sorted(R.graded_component(9)) + sage: sorted(R.graded_component(9)) # optional - sage.combinat [[4, 5, 3, 2, 1], [5, 3, 4, 2, 1], [5, 4, 2, 3, 1], [5, 4, 3, 1, 2]] - sage: sorted(R.graded_component(10)) + sage: sorted(R.graded_component(10)) # optional - sage.combinat [[5, 4, 3, 2, 1]] Forest structure @@ -144,7 +147,8 @@ empty word by appending letter `a` or `b` as a successor function. This set has a forest structure:: sage: seeds = [''] - sage: succ = lambda w: [w+'a', w+'b'] + sage: def succ(w): + ....: return [w + 'a', w + 'b'] sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='forest') sage: C An enumerated set with a forest structure @@ -233,7 +237,7 @@ or even:: We can then create the :class:`RecursivelyEnumeratedSet` object with either:: sage: S = RecursivelyEnumeratedSet([''], - ....: lambda x: [x+letter for letter in ['a', 'b', 'c']] + ....: lambda x: [x + letter for letter in ['a', 'b', 'c']] ....: if len(x) < 2 else [], ....: structure='forest', enumeration='depth', ....: category=FiniteEnumeratedSets()) @@ -273,8 +277,8 @@ convention is that the generated elements are the ``s := f(n)``, except when ....: st = set(st) # make a copy ....: if st: ....: el = st.pop() - ....: for i in range(len(lst)+1): - ....: yield (lst[0:i]+[el]+lst[i:], st) + ....: for i in range(len(lst) + 1): + ....: yield (lst[0:i] + [el] + lst[i:], st) sage: list(children(([1,2], {3,7,9}))) [([9, 1, 2], {3, 7}), ([1, 9, 2], {3, 7}), ([1, 2, 9], {3, 7})] sage: def post_process(node): @@ -361,9 +365,9 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, A recursive set with no other information:: - sage: f = lambda a: [a+3, a+5] - sage: C = RecursivelyEnumeratedSet([0], f) - sage: C + sage: def f(a): + ....: return [a + 3, a + 5] + sage: C = RecursivelyEnumeratedSet([0], f); C A recursively enumerated set (breadth first search) sage: it = iter(C) sage: [next(it) for _ in range(10)] @@ -372,8 +376,7 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, A recursive set with a forest structure:: sage: f = lambda a: [2*a,2*a+1] - sage: C = RecursivelyEnumeratedSet([1], f, structure='forest') - sage: C + sage: C = RecursivelyEnumeratedSet([1], f, structure='forest'); C An enumerated set with a forest structure sage: it = C.depth_first_search_iterator() sage: [next(it) for _ in range(7)] @@ -384,9 +387,9 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, A recursive set given by a symmetric relation:: - sage: f = lambda a: [a-1,a+1] - sage: C = RecursivelyEnumeratedSet([10, 15], f, structure='symmetric') - sage: C + sage: def f(a): + ....: return [a - 1, a + 1] + sage: C = RecursivelyEnumeratedSet([10, 15], f, structure='symmetric'); C A recursively enumerated set with a symmetric structure (breadth first search) sage: it = iter(C) sage: [next(it) for _ in range(7)] @@ -394,9 +397,9 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, A recursive set given by a graded relation:: - sage: f = lambda a: [a+1, a+I] - sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') - sage: C + sage: def f(a): + ....: return [a + 1, a + I] + sage: C = RecursivelyEnumeratedSet([0], f, structure='graded'); C A recursively enumerated set with a graded structure (breadth first search) sage: it = iter(C) sage: [next(it) for _ in range(7)] @@ -407,7 +410,8 @@ def RecursivelyEnumeratedSet(seeds, successors, structure=None, If you do not set the good structure, you might obtain bad results, like elements generated twice:: - sage: f = lambda a: [a-1,a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') sage: it = iter(C) sage: [next(it) for _ in range(7)] @@ -462,7 +466,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a:[a+1] + sage: def f(a): + ....: return [a + 1] Different structure for the sets:: @@ -490,7 +495,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): r""" TESTS:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: C A recursively enumerated set (breadth first search) @@ -580,7 +586,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: len(C) Traceback (most recent call last): @@ -598,7 +605,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: it_naive = iter(RecursivelyEnumeratedSet([0], f, enumeration='naive')) sage: it_depth = iter(RecursivelyEnumeratedSet([0], f, enumeration='depth')) sage: it_breadth = iter(RecursivelyEnumeratedSet([0], f, enumeration='breadth')) @@ -632,7 +640,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a:[a+3,a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: R = RecursivelyEnumeratedSet([0], f) sage: R A recursively enumerated set (breadth first search) @@ -656,7 +665,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): r""" TESTS:: - sage: f = lambda x: [x-1, x+1] + sage: def f(x): + ....: return [x - 1, x + 1] sage: RecursivelyEnumeratedSet([1], f, structure=None) A recursively enumerated set (breadth first search) @@ -700,7 +710,7 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: R = RecursivelyEnumeratedSet([1], lambda x: [x+1, x-1]) + sage: R = RecursivelyEnumeratedSet([1], lambda x: [x + 1, x - 1]) sage: R.seeds() [1] """ @@ -737,7 +747,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: it = C.graded_component_iterator() # todo: not implemented """ @@ -765,7 +776,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: C.graded_component(0) Traceback (most recent call last): @@ -792,7 +804,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a-1, a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: S = RecursivelyEnumeratedSet([5, 10], f, structure='symmetric') sage: it = S.elements_of_depth_iterator(2) sage: sorted(it) @@ -816,7 +829,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: it = C.breadth_first_search_iterator() sage: [next(it) for _ in range(10)] @@ -853,7 +867,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: it = C._breadth_first_search_iterator_using_queue() sage: [next(it) for _ in range(10)] @@ -912,7 +927,8 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: f = lambda a: [a+3, a+5] + sage: def f(a): + ....: return [a + 3, a + 5] sage: C = RecursivelyEnumeratedSet([0], f) sage: it = C.depth_first_search_iterator() sage: [next(it) for _ in range(10)] @@ -953,31 +969,36 @@ cdef class RecursivelyEnumeratedSet_generic(Parent): EXAMPLES:: - sage: child = lambda i: [(i+3) % 10, (i+8) % 10] + sage: def child(i): + ....: return [(i+3) % 10, (i+8) % 10] sage: R = RecursivelyEnumeratedSet([0], child) - sage: R.to_digraph() + sage: R.to_digraph() # optional - sage.graphs Looped multi-digraph on 10 vertices Digraph of an recursively enumerated set with a symmetric structure of infinite cardinality using ``max_depth`` argument:: - sage: succ = lambda a: [(a[0]-1,a[1]), (a[0],a[1]-1), (a[0]+1,a[1]), (a[0],a[1]+1)] - sage: seeds = [(0,0)] + sage: def succ(a): + ....: return [(a[0] - 1, a[1]), (a[0], a[1] - 1), + ....: (a[0] + 1, a[1]), (a[0], a[1] + 1)] + sage: seeds = [(0, 0)] sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric') - sage: C.to_digraph(max_depth=3) + sage: C.to_digraph(max_depth=3) # optional - sage.graphs Looped multi-digraph on 41 vertices The ``max_depth`` argument can be given at the creation of the set:: - sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric', max_depth=2) - sage: C.to_digraph() + sage: C = RecursivelyEnumeratedSet(seeds, succ, structure='symmetric', + ....: max_depth=2) + sage: C.to_digraph() # optional - sage.graphs Looped multi-digraph on 25 vertices Digraph of an recursively enumerated set with a graded structure:: - sage: f = lambda a: [a+1, a+I] + sage: def f(a): + ....: return [a + 1, a + I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') - sage: C.to_digraph(max_depth=4) + sage: C.to_digraph(max_depth=4) # optional - sage.graphs Looped multi-digraph on 21 vertices """ successors = self.successors @@ -1001,7 +1022,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a-1,a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: C A recursively enumerated set with a symmetric structure (breadth first search) @@ -1013,7 +1035,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Do not use lambda functions for saving purposes:: - sage: f = lambda a: [a-1,a+1] + sage: f = lambda a: [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: loads(dumps(C)) Traceback (most recent call last): @@ -1022,7 +1044,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): This works in the command line but apparently not as a doctest:: - sage: def f(a): return [a-1,a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: loads(dumps(C)) Traceback (most recent call last): @@ -1047,7 +1070,9 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [(a[0]-1,a[1]), (a[0],a[1]-1), (a[0]+1,a[1]), (a[0],a[1]+1)] + sage: def f(a): + ....: return [(a[0] - 1, a[1]), (a[0], a[1] - 1), + ....: (a[0] + 1, a[1]), (a[0], a[1] + 1)] sage: C = RecursivelyEnumeratedSet([(0,0)], f, structure='symmetric') sage: s = list(C.breadth_first_search_iterator(max_depth=2)); s [(0, 0), @@ -1111,7 +1136,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a-1, a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: S = RecursivelyEnumeratedSet([10], f, structure='symmetric') sage: it = S.graded_component_iterator() sage: [sorted(next(it)) for _ in range(5)] @@ -1119,7 +1145,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Starting with two generators:: - sage: f = lambda a: [a-1, a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: S = RecursivelyEnumeratedSet([5, 10], f, structure='symmetric') sage: it = S.graded_component_iterator() sage: [sorted(next(it)) for _ in range(5)] @@ -1127,7 +1154,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): Gaussian integers:: - sage: f = lambda a: [a+1, a+I] + sage: def f(a): + ....: return [a + 1, a + I] sage: S = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: it = S.graded_component_iterator() sage: [sorted(next(it)) for _ in range(7)] @@ -1146,7 +1174,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): sage: def f(a): ....: sleep(0.05r) - ....: return [a-1,a+1] + ....: return [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: it = C.graded_component_iterator() sage: next(it) @@ -1191,7 +1219,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a-1,a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([10, 15], f, structure='symmetric') sage: for i in range(5): sorted(C.graded_component(i)) [10, 15] @@ -1206,7 +1235,7 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): sage: def f(a): ....: sleep(0.1r) - ....: return [a-1,a+1] + ....: return [a - 1, a + 1] sage: C = RecursivelyEnumeratedSet([0], f, structure='symmetric') sage: from cysignals.alarm import alarm sage: alarm(0.45); C.graded_component(10) @@ -1257,7 +1286,8 @@ cdef class RecursivelyEnumeratedSet_symmetric(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a-1, a+1] + sage: def f(a): + ....: return [a - 1, a + 1] sage: S = RecursivelyEnumeratedSet([5, 10], f, structure='symmetric') sage: it = S.graded_component_iterator() sage: [sorted(next(it)) for _ in range(3)] # indirect doctest @@ -1286,7 +1316,8 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [(a[0]+1,a[1]), (a[0],a[1]+1)] + sage: def f(a): + ....: return [(a[0] + 1, a[1]), (a[0], a[1] + 1)] sage: C = RecursivelyEnumeratedSet([(0,0)], f, structure='graded', max_depth=3) sage: C A recursively enumerated set with a graded structure (breadth first @@ -1314,7 +1345,8 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [(a[0]+1,a[1]), (a[0],a[1]+1)] + sage: def f(a): + ....: return [(a[0] + 1, a[1]), (a[0], a[1] + 1)] sage: C = RecursivelyEnumeratedSet([(0,0)], f, structure='graded') sage: list(C.breadth_first_search_iterator(max_depth=3)) [(0, 0), @@ -1361,7 +1393,8 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [(a[0]+1,a[1]), (a[0],a[1]+1)] + sage: def f(a): + ....: return [(a[0] + 1, a[1]), (a[0], a[1] + 1)] sage: C = RecursivelyEnumeratedSet([(0,0)], f, structure='graded', max_depth=3) sage: it = C.graded_component_iterator() sage: for _ in range(4): sorted(next(it)) @@ -1414,7 +1447,8 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [a+1, a+I] + sage: def f(a): + ....: return [a + 1, a + I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') sage: for i in range(5): sorted(C.graded_component(i)) [0] @@ -1429,7 +1463,7 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): sage: def f(a): ....: sleep(0.1r) - ....: return [a+1, a+I] + ....: return [a + 1, a + I] sage: C = RecursivelyEnumeratedSet([0], f, structure='graded') sage: from cysignals.alarm import alarm sage: alarm(0.45); C.graded_component(10) @@ -1472,7 +1506,8 @@ cdef class RecursivelyEnumeratedSet_graded(RecursivelyEnumeratedSet_generic): EXAMPLES:: - sage: f = lambda a: [(a[0]+1,a[1]), (a[0],a[1]+1)] + sage: def f(a): + ....: return [(a[0] + 1, a[1]), (a[0], a[1] + 1)] sage: C = RecursivelyEnumeratedSet([(0,0)], f, structure='graded') sage: it = C.graded_component_iterator() sage: [sorted(next(it)) for _ in range(2)] # indirect doctest @@ -1500,7 +1535,7 @@ def _imap_and_filter_none(function, iterable): sage: p = _imap_and_filter_none(lambda x: x if is_prime(x) else None, range(15)) sage: [next(p), next(p), next(p), next(p), next(p), next(p)] [2, 3, 5, 7, 11, 13] - sage: p = _imap_and_filter_none(lambda x: x+x, ['a','b','c','d','e']) + sage: p = _imap_and_filter_none(lambda x: x + x, ['a','b','c','d','e']) sage: [next(p), next(p), next(p), next(p), next(p)] ['aa', 'bb', 'cc', 'dd', 'ee'] """ @@ -1528,7 +1563,7 @@ def search_forest_iterator(roots, children, algorithm='depth'): three, and enumerate its nodes:: sage: from sage.sets.recursively_enumerated_set import search_forest_iterator - sage: list(search_forest_iterator([[]], lambda l: [l+[0], l+[1]] + sage: list(search_forest_iterator([[]], lambda l: [l + [0], l + [1]] ....: if len(l) < 3 else [])) [[], [0], [0, 0], [0, 0, 0], [0, 0, 1], [0, 1], [0, 1, 0], [0, 1, 1], [1], [1, 0], [1, 0, 0], [1, 0, 1], [1, 1], [1, 1, 0], [1, 1, 1]] @@ -1536,7 +1571,7 @@ def search_forest_iterator(roots, children, algorithm='depth'): By default, the nodes are iterated through by depth first search. We can instead use a breadth first search (increasing depth):: - sage: list(search_forest_iterator([[]], lambda l: [l+[0], l+[1]] + sage: list(search_forest_iterator([[]], lambda l: [l + [0], l + [1]] ....: if len(l) < 3 else [], ....: algorithm='breadth')) [[], @@ -1547,7 +1582,8 @@ def search_forest_iterator(roots, children, algorithm='depth'): This allows for iterating trough trees of infinite depth:: - sage: it = search_forest_iterator([[]], lambda l: [l+[0], l+[1]], algorithm='breadth') + sage: it = search_forest_iterator([[]], lambda l: [l + [0], l + [1]], + ....: algorithm='breadth') sage: [ next(it) for i in range(16) ] [[], [0], [1], [0, 0], [0, 1], [1, 0], [1, 1], @@ -1559,7 +1595,9 @@ def search_forest_iterator(roots, children, algorithm='depth'): letters in `0,1,2` without repetitions, sorted by length; the leaves are therefore permutations:: - sage: list(search_forest_iterator([[]], lambda l: [l + [i] for i in range(3) if i not in l], + sage: def f(l): + ....: return [l + [i] for i in range(3) if i not in l] + sage: list(search_forest_iterator([[]], f, ....: algorithm='breadth')) [[], [0], [1], [2], @@ -1626,7 +1664,7 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest sage: S = RecursivelyEnumeratedSet_forest( [[]], - ....: lambda l: [l+[0], l+[1]] if len(l) < 3 else [], + ....: lambda l: [l + [0], l + [1]] if len(l) < 3 else [], ....: category=FiniteEnumeratedSets()) sage: S.list() [[], @@ -1665,10 +1703,13 @@ class RecursivelyEnumeratedSet_forest(Parent): builds the set of all ordered pairs `(i,j)` of nonnegative integers such that `j\leq 1`:: + sage: def f(l): + ....: if l[1] == 0: + ....: return [(l[0] + 1, l[1]), (l[0], 1)] + ....: else: + ....: return [(l[0], l[1] + 1)] sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: I = RecursivelyEnumeratedSet_forest([(0,0)], - ....: lambda l: [(l[0]+1, l[1]), (l[0], 1)] - ....: if l[1] == 0 else [(l[0], l[1]+1)]) + sage: I = RecursivelyEnumeratedSet_forest([(0, 0)], f) With a depth first search, only the elements of the form `(i,0)` are generated:: @@ -1710,9 +1751,10 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: class A(UniqueRepresentation, RecursivelyEnumeratedSet_forest): ....: def __init__(self): ....: RecursivelyEnumeratedSet_forest.__init__(self, [()], - ....: lambda x : [x+(0,), x+(1,)] if sum(x) < 3 else [], - ....: lambda x : sum(x[i]*2^i for i in range(len(x))) if sum(x) != 0 and x[-1] != 0 else None, - ....: algorithm = 'breadth', + ....: lambda x: [x + (0,), x + (1,)] if sum(x) < 3 else [], + ....: lambda x: sum(x[i]*2^i for i in range(len(x))) + ....: if sum(x) != 0 and x[-1] != 0 else None, + ....: algorithm='breadth', ....: category=InfiniteEnumeratedSets()) sage: MyForest = A(); MyForest An enumerated set with a forest structure @@ -1720,7 +1762,8 @@ class RecursivelyEnumeratedSet_forest(Parent): Category of infinite enumerated sets sage: p = iter(MyForest) sage: [next(p) for i in range(30)] - [1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 16, 24, 20, 28, 18, 26, 22, 17, 25, 21, 19, 32, 48, 40, 56, 36] + [1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 16, 24, + 20, 28, 18, 26, 22, 17, 25, 21, 19, 32, 48, 40, 56, 36] An alternative approach is to implement ``roots`` and ``children`` as methods of the subclass (in fact they could also be attributes @@ -1733,13 +1776,13 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest sage: class A(UniqueRepresentation, RecursivelyEnumeratedSet_forest): ....: def __init__(self): - ....: RecursivelyEnumeratedSet_forest.__init__(self, algorithm = 'breadth', + ....: RecursivelyEnumeratedSet_forest.__init__(self, algorithm='breadth', ....: category=InfiniteEnumeratedSets()) ....: def roots(self): ....: return [()] ....: def children(self, x): ....: if sum(x) < 3: - ....: return [x+(0,), x+(1,)] + ....: return [x + (0,), x + (1,)] ....: else: ....: return [] ....: def post_process(self, x): @@ -1753,7 +1796,8 @@ class RecursivelyEnumeratedSet_forest(Parent): Category of infinite enumerated sets sage: p = iter(MyForest) sage: [next(p) for i in range(30)] - [1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 16, 24, 20, 28, 18, 26, 22, 17, 25, 21, 19, 32, 48, 40, 56, 36] + [1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 16, 24, + 20, 28, 18, 26, 22, 17, 25, 21, 19, 32, 48, 40, 56, 36] .. warning:: @@ -1762,8 +1806,8 @@ class RecursivelyEnumeratedSet_forest(Parent): anonymous or interactively defined functions:: sage: def children(x): - ....: return [x+1] - sage: S = RecursivelyEnumeratedSet_forest( [1], children, category=InfiniteEnumeratedSets()) + ....: return [x + 1] + sage: S = RecursivelyEnumeratedSet_forest([1], children, category=InfiniteEnumeratedSets()) sage: dumps(S) Traceback (most recent call last): ... @@ -1773,7 +1817,7 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: import __main__ sage: __main__.children = children - sage: S = RecursivelyEnumeratedSet_forest( [1], children, category=InfiniteEnumeratedSets()) + sage: S = RecursivelyEnumeratedSet_forest([1], children, category=InfiniteEnumeratedSets()) sage: loads(dumps(S)) An enumerated set with a forest structure """ @@ -1783,7 +1827,7 @@ class RecursivelyEnumeratedSet_forest(Parent): TESTS:: sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: S = RecursivelyEnumeratedSet_forest(NN, lambda x : [], lambda x: x^2 if x.is_prime() else None) + sage: S = RecursivelyEnumeratedSet_forest(NN, lambda x: [], lambda x: x^2 if x.is_prime() else None) sage: S.category() Category of enumerated sets """ @@ -1815,10 +1859,15 @@ class RecursivelyEnumeratedSet_forest(Parent): EXAMPLES:: sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: I = RecursivelyEnumeratedSet_forest([(0,0)], lambda l: [(l[0]+1, l[1]), (l[0], 1)] if l[1] == 0 else [(l[0], l[1]+1)]) + sage: def f(l): + ....: if l[1] == 0: + ....: return [(l[0] + 1, l[1]), (l[0], 1)] + ....: else: + ....: return [(l[0], l[1] + 1)] + sage: I = RecursivelyEnumeratedSet_forest([(0, 0)], f) sage: [i for i in I.roots()] [(0, 0)] - sage: I = RecursivelyEnumeratedSet_forest([(0,0),(1,1)], lambda l: [(l[0]+1, l[1]), (l[0], 1)] if l[1] == 0 else [(l[0], l[1]+1)]) + sage: I = RecursivelyEnumeratedSet_forest([(0, 0), (1, 1)], f) sage: [i for i in I.roots()] [(0, 0), (1, 1)] """ @@ -1835,7 +1884,12 @@ class RecursivelyEnumeratedSet_forest(Parent): EXAMPLES:: sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: I = RecursivelyEnumeratedSet_forest([(0,0)], lambda l: [(l[0]+1, l[1]), (l[0], 1)] if l[1] == 0 else [(l[0], l[1]+1)]) + sage: def f(l): + ....: if l[1] == 0: + ....: return [(l[0] + 1, l[1]), (l[0], 1)] + ....: else: + ....: return [(l[0], l[1] + 1)] + sage: I = RecursivelyEnumeratedSet_forest([(0, 0)], f) sage: [i for i in I.children((0,0))] [(1, 0), (0, 1)] sage: [i for i in I.children((1,0))] @@ -1856,7 +1910,7 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest sage: def children(l): - ....: return [l+[0], l+[1]] + ....: return [l + [0], l + [1]] sage: C = RecursivelyEnumeratedSet_forest(([],), children) sage: f = C.__iter__() sage: next(f) @@ -1881,9 +1935,10 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest sage: f = RecursivelyEnumeratedSet_forest([[]], - ....: lambda l: [l+[0], l+[1]] if len(l) < 3 else []) + ....: lambda l: [l + [0], l + [1]] if len(l) < 3 else []) sage: list(f.depth_first_search_iterator()) - [[], [0], [0, 0], [0, 0, 0], [0, 0, 1], [0, 1], [0, 1, 0], [0, 1, 1], [1], [1, 0], [1, 0, 0], [1, 0, 1], [1, 1], [1, 1, 0], [1, 1, 1]] + [[], [0], [0, 0], [0, 0, 0], [0, 0, 1], [0, 1], [0, 1, 0], [0, 1, 1], + [1], [1, 0], [1, 0, 0], [1, 0, 1], [1, 1], [1, 1, 0], [1, 1, 1]] """ return iter(self) @@ -1895,12 +1950,21 @@ class RecursivelyEnumeratedSet_forest(Parent): sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest sage: f = RecursivelyEnumeratedSet_forest([[]], - ....: lambda l: [l+[0], l+[1]] if len(l) < 3 else []) + ....: lambda l: [l + [0], l + [1]] if len(l) < 3 else []) sage: list(f.breadth_first_search_iterator()) - [[], [0], [1], [0, 0], [0, 1], [1, 0], [1, 1], [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] - sage: S = RecursivelyEnumeratedSet_forest([(0,0)], - ....: lambda x : [(x[0], x[1]+1)] if x[1] != 0 else [(x[0]+1,0), (x[0],1)], - ....: post_process = lambda x: x if ((is_prime(x[0]) and is_prime(x[1])) and ((x[0] - x[1]) == 2)) else None) + [[], [0], [1], [0, 0], [0, 1], [1, 0], [1, 1], + [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] + sage: def f(x): + ....: if x[1] != 0: + ....: return [(x[0], x[1] + 1)] + ....: else: + ....: return [(x[0] + 1, 0), (x[0], 1)] + sage: def post_process(x): + ....: if (is_prime(x[0]) and is_prime(x[1])) and ((x[0] - x[1]) == 2): + ....: return x + ....: return None + sage: S = RecursivelyEnumeratedSet_forest([(0, 0)], f, + ....: post_process=post_process) sage: p = S.breadth_first_search_iterator() sage: [next(p), next(p), next(p), next(p), next(p), next(p), next(p)] [(5, 3), (7, 5), (13, 11), (19, 17), (31, 29), (43, 41), (61, 59)] @@ -1952,14 +2016,21 @@ class RecursivelyEnumeratedSet_forest(Parent): EXAMPLES:: sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: S = RecursivelyEnumeratedSet_forest([(0,0)] , - ....: lambda x : [(x[0], x[1]+1)] if x[1] != 0 else [(x[0]+1,0), (x[0],1)], - ....: post_process = lambda x: x if ((is_prime(x[0]) and is_prime(x[1])) - ....: and ((x[0] - x[1]) == 2)) else None) + sage: def f(x): + ....: if x[1] != 0: + ....: return [(x[0], x[1] + 1)] + ....: else: + ....: return [(x[0] + 1, 0), (x[0], 1)] + sage: def post_process(x): + ....: if (is_prime(x[0]) and is_prime(x[1])) and ((x[0] - x[1]) == 2): + ....: return x + ....: return None + sage: S = RecursivelyEnumeratedSet_forest([(0, 0)], f, + ....: post_process=post_process) sage: p = S.elements_of_depth_iterator(8) sage: next(p) (5, 3) - sage: S = RecursivelyEnumeratedSet_forest(NN, lambda x : [], + sage: S = RecursivelyEnumeratedSet_forest(NN, lambda x: [], ....: lambda x: x^2 if x.is_prime() else None) sage: p = S.elements_of_depth_iterator(0) sage: [next(p), next(p), next(p), next(p), next(p)] @@ -1984,7 +2055,8 @@ class RecursivelyEnumeratedSet_forest(Parent): EXAMPLES:: sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: S = RecursivelyEnumeratedSet_forest( [[]], lambda l: [l+[0], l+[1]] if len(l) < 3 else [], category=FiniteEnumeratedSets()) + sage: S = RecursivelyEnumeratedSet_forest([[]], lambda l: [l + [0], l + [1]] if len(l) < 3 else [], + ....: category=FiniteEnumeratedSets()) sage: [4] in S False sage: [1] in S @@ -1993,12 +2065,12 @@ class RecursivelyEnumeratedSet_forest(Parent): False sage: all(S.__contains__(i) for i in iter(S)) True - sage: S = RecursivelyEnumeratedSet_forest([1], lambda x: [x+1], category=InfiniteEnumeratedSets()) + sage: S = RecursivelyEnumeratedSet_forest([1], lambda x: [x + 1], category=InfiniteEnumeratedSets()) sage: 1 in S True sage: 732 in S True - sage: -1 in S # not tested : Will never stop + sage: -1 in S # not tested : Will never stop The algorithm uses a random enumeration of the nodes of the forest. This choice was motivated by examples in which both @@ -2008,8 +2080,9 @@ class RecursivelyEnumeratedSet_forest(Parent): roots has an infinite number of children:: sage: from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet_forest - sage: S = RecursivelyEnumeratedSet_forest(Family(NN, lambda x : (x, 0)), - ....: lambda x : Family(PositiveIntegers(), lambda y : (x[0], y)) if x[1] == 0 else []) + sage: S = RecursivelyEnumeratedSet_forest( + ....: Family(NN, lambda x: (x, 0)), + ....: lambda x: Family(PositiveIntegers(), lambda y: (x[0], y)) if x[1] == 0 else []) sage: p = S.depth_first_search_iterator() sage: [next(p), next(p), next(p), next(p), next(p), next(p), next(p)] [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)] @@ -2031,7 +2104,8 @@ class RecursivelyEnumeratedSet_forest(Parent): child. From each root starts an infinite branch of breadth `1`:: - sage: S = RecursivelyEnumeratedSet_forest(Family(NN, lambda x : (x, 0)) , lambda x : [(x[0], x[1]+1)]) + sage: S = RecursivelyEnumeratedSet_forest(Family(NN, lambda x: (x, 0)), + ....: lambda x: [(x[0], x[1] + 1)]) sage: p = S.depth_first_search_iterator() sage: [next(p), next(p), next(p), next(p), next(p), next(p), next(p)] [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)] @@ -2086,20 +2160,26 @@ class RecursivelyEnumeratedSet_forest(Parent): EXAMPLES:: - sage: seeds = [([i],i, i) for i in range(1,10)] + sage: seeds = [([i], i, i) for i in range(1, 10)] sage: def succ(t): ....: list, sum, last = t ....: return [(list + [i], sum + i, i) for i in range(1, last)] sage: F = RecursivelyEnumeratedSet(seeds, succ, - ....: structure='forest', enumeration='depth') + ....: structure='forest', enumeration='depth') - sage: y = var('y') + sage: y = var('y') # optional - sage.symbolic sage: def map_function(t): ....: li, sum, _ = t ....: return y ^ sum - sage: reduce_function = lambda x,y: x + y - sage: F.map_reduce(map_function, reduce_function, 0) - y^45 + y^44 + y^43 + 2*y^42 + 2*y^41 + 3*y^40 + 4*y^39 + 5*y^38 + 6*y^37 + 8*y^36 + 9*y^35 + 10*y^34 + 12*y^33 + 13*y^32 + 15*y^31 + 17*y^30 + 18*y^29 + 19*y^28 + 21*y^27 + 21*y^26 + 22*y^25 + 23*y^24 + 23*y^23 + 23*y^22 + 23*y^21 + 22*y^20 + 21*y^19 + 21*y^18 + 19*y^17 + 18*y^16 + 17*y^15 + 15*y^14 + 13*y^13 + 12*y^12 + 10*y^11 + 9*y^10 + 8*y^9 + 6*y^8 + 5*y^7 + 4*y^6 + 3*y^5 + 2*y^4 + 2*y^3 + y^2 + y + sage: def reduce_function(x, y): + ....: return x + y + sage: F.map_reduce(map_function, reduce_function, 0) # optional - sage.symbolic + y^45 + y^44 + y^43 + 2*y^42 + 2*y^41 + 3*y^40 + 4*y^39 + 5*y^38 + 6*y^37 + + 8*y^36 + 9*y^35 + 10*y^34 + 12*y^33 + 13*y^32 + 15*y^31 + 17*y^30 + + 18*y^29 + 19*y^28 + 21*y^27 + 21*y^26 + 22*y^25 + 23*y^24 + 23*y^23 + + 23*y^22 + 23*y^21 + 22*y^20 + 21*y^19 + 21*y^18 + 19*y^17 + 18*y^16 + + 17*y^15 + 15*y^14 + 13*y^13 + 12*y^12 + 10*y^11 + 9*y^10 + 8*y^9 + 6*y^8 + + 5*y^7 + 4*y^6 + 3*y^5 + 2*y^4 + 2*y^3 + y^2 + y Here is an example with the default values:: diff --git a/src/sage/sets/set.py b/src/sage/sets/set.py index a1789c61300..1853d980a15 100644 --- a/src/sage/sets/set.py +++ b/src/sage/sets/set.py @@ -71,7 +71,7 @@ def has_finite_length(obj): True sage: has_finite_length(iter(range(10))) False - sage: has_finite_length(GF(17^127)) + sage: has_finite_length(GF(17^127)) # optional - sage.rings.finite_rings True sage: has_finite_length(ZZ) False @@ -100,22 +100,24 @@ def Set(X=None, category=None): EXAMPLES:: - sage: X = Set(GF(9,'a')) - sage: X + sage: X = Set(GF(9, 'a')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} - sage: type(X) + sage: type(X) # optional - sage.rings.finite_rings - sage: Y = X.union(Set(QQ)) - sage: Y - Set-theoretic union of {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} and Set of elements of Rational Field - sage: type(Y) + sage: Y = X.union(Set(QQ)) # optional - sage.rings.finite_rings + sage: Y # optional - sage.rings.finite_rings + Set-theoretic union of + {0, 1, 2, a, a + 1, a + 2, 2*a, 2*a + 1, 2*a + 2} and + Set of elements of Rational Field + sage: type(Y) # optional - sage.rings.finite_rings Usually sets can be used as dictionary keys. :: - sage: d={Set([2*I,1+I]):10} + sage: d = {Set([2*I, 1 + I]): 10} sage: d # key is randomly ordered {{I + 1, 2*I}: 10} sage: d[Set([1+I,2*I])] @@ -218,18 +220,24 @@ def union(self, X): EXAMPLES:: sage: Set(QQ).union(Set(ZZ)) - Set-theoretic union of Set of elements of Rational Field and Set of elements of Integer Ring + Set-theoretic union of + Set of elements of Rational Field and + Set of elements of Integer Ring sage: Set(QQ) + Set(ZZ) - Set-theoretic union of Set of elements of Rational Field and Set of elements of Integer Ring - sage: X = Set(QQ).union(Set(GF(3))); X - Set-theoretic union of Set of elements of Rational Field and {0, 1, 2} - sage: 2/3 in X + Set-theoretic union of + Set of elements of Rational Field and + Set of elements of Integer Ring + sage: X = Set(QQ).union(Set(GF(3))); X # optional - sage.rings.finite_rings + Set-theoretic union of + Set of elements of Rational Field and + {0, 1, 2} + sage: 2/3 in X # optional - sage.rings.finite_rings True - sage: GF(3)(2) in X + sage: GF(3)(2) in X # optional - sage.rings.finite_rings True - sage: GF(5)(2) in X + sage: GF(5)(2) in X # optional - sage.rings.finite_rings False - sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) + sage: sorted(Set(GF(7)) + Set(GF(3)), key=int) # optional - sage.rings.finite_rings [0, 0, 1, 1, 2, 2, 3, 4, 5, 6] """ if isinstance(X, (Set_generic, Set_base)): @@ -253,12 +261,10 @@ def intersection(self, X): sage: 2/1 in X True - sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))) - sage: X + sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'c'))); X # optional - sage.rings.finite_rings {} - sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))) - sage: X + sage: X = Set(GF(9,'b')).intersection(Set(GF(27,'b'))); X # optional - sage.rings.finite_rings {} """ if isinstance(X, (Set_generic, Set_base)): @@ -282,12 +288,10 @@ def difference(self, X): sage: 4/1 in X True - sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))) - sage: X + sage: X = Set(GF(9,'b')).difference(Set(GF(27,'c'))); X # optional - sage.rings.finite_rings {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2} - sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))) - sage: X + sage: X = Set(GF(9,'b')).difference(Set(GF(27,'b'))); X # optional - sage.rings.finite_rings {0, 1, 2, b, b + 1, b + 2, 2*b, 2*b + 1, 2*b + 2} """ if isinstance(X, (Set_generic, Set_base)): @@ -325,7 +329,7 @@ def _test_as_set_object(self, tester=None, **options): Instances of other subclasses of :class:`Set_base` run this method:: - sage: Polyhedron()._test_as_set_object(verbose=True) + sage: Polyhedron()._test_as_set_object(verbose=True) # optional - sage.geometry.polyhedron Running the test suite of Set(self) running ._test_an_element() . . . pass ... @@ -407,15 +411,15 @@ def __add__(self, X): EXAMPLES:: - sage: Set(RealField()) + Set(QQ^5) + sage: Set(RealField()) + Set(QQ^5) # optional - sage.modules Set-theoretic union of Set of elements of Real Field with 53 bits of precision and Set of elements of Vector space of dimension 5 over Rational Field - sage: Set(GF(3)) + Set(GF(2)) + sage: Set(GF(3)) + Set(GF(2)) # optional - sage.rings.finite_rings {0, 1, 2, 0, 1} - sage: Set(GF(2)) + Set(GF(4,'a')) + sage: Set(GF(2)) + Set(GF(4,'a')) # optional - sage.rings.finite_rings {0, 1, a, a + 1} - sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) + sage: sorted(Set(GF(8,'b')) + Set(GF(4,'a')), key=str) # optional - sage.rings.finite_rings [0, 0, 1, 1, a, a + 1, b, b + 1, b^2, b^2 + 1, b^2 + b, b^2 + b + 1] """ return self.union(X) @@ -441,14 +445,14 @@ class Set_object(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_opera EXAMPLES:: - sage: K = GF(19) - sage: Set(K) + sage: K = GF(19) # optional - sage.rings.finite_rings + sage: Set(K) # optional - sage.rings.finite_rings {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18} - sage: S = Set(K) + sage: S = Set(K) # optional - sage.rings.finite_rings - sage: latex(S) + sage: latex(S) # optional - sage.rings.finite_rings \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\} - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.rings.finite_rings sage: latex(Set(ZZ)) \Bold{Z} @@ -606,7 +610,7 @@ def __contains__(self, x): sage: X = Set(ZZ) sage: 5 in X True - sage: GF(7)(3) in X + sage: GF(7)(3) in X # optional - sage.rings.finite_rings True sage: 2/1 in X True @@ -618,16 +622,16 @@ def __contains__(self, x): Finite fields better illustrate the difference between ``__contains__`` for objects and their underlying sets:: - sage: X = Set(GF(7)) - sage: X + sage: X = Set(GF(7)) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, 2, 3, 4, 5, 6} - sage: 5/3 in X + sage: 5/3 in X # optional - sage.rings.finite_rings False - sage: 5/3 in GF(7) + sage: 5/3 in GF(7) # optional - sage.rings.finite_rings False - sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) + sage: sorted(Set(GF(7)).union(Set(GF(5))), key=int) # optional - sage.rings.finite_rings [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6] - sage: Set(GF(7)).intersection(Set(GF(5))) + sage: Set(GF(7)).intersection(Set(GF(5))) # optional - sage.rings.finite_rings {} """ return x in self.__object @@ -671,9 +675,9 @@ def cardinality(self): +Infinity sage: Primes().cardinality() +Infinity - sage: Set(GF(5)).cardinality() + sage: Set(GF(5)).cardinality() # optional - sage.rings.finite_rings 5 - sage: Set(GF(5^2,'a')).cardinality() + sage: Set(GF(5^2,'a')).cardinality() # optional - sage.rings.finite_rings 25 """ if self in Sets().Infinite(): @@ -711,7 +715,7 @@ def is_empty(self): False sage: Set([1..100]).is_empty() False - sage: Set(SymmetricGroup(2).list()).is_empty() + sage: Set(SymmetricGroup(2).list()).is_empty() # optional - sage.groups False sage: Set(ZZ).is_empty() False @@ -724,7 +728,7 @@ def is_empty(self): False sage: Set([1..100]).is_empty() False - sage: Set(DihedralGroup(4).list()).is_empty() + sage: Set(DihedralGroup(4).list()).is_empty() # optional - sage.groups False sage: Set(QQ).is_empty() False @@ -739,7 +743,7 @@ def is_finite(self): sage: Set(QQ).is_finite() False - sage: Set(GF(250037)).is_finite() + sage: Set(GF(250037)).is_finite() # optional - sage.rings.finite_rings True sage: Set(Integers(2^1000000)).is_finite() True @@ -781,9 +785,9 @@ def subsets(self, size=None): EXAMPLES:: sage: X = Set([1, 2, 3]) - sage: list(X.subsets()) + sage: list(X.subsets()) # optional - sage.combinat [{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}] - sage: list(X.subsets(2)) + sage: list(X.subsets(2)) # optional - sage.combinat [{1, 2}, {1, 3}, {2, 3}] """ from sage.combinat.subset import Subsets @@ -796,10 +800,10 @@ def subsets_lattice(self): EXAMPLES:: sage: X = Set([1,2,3]) - sage: X.subsets_lattice() + sage: X.subsets_lattice() # optional - sage.combinat Finite lattice containing 8 elements sage: Y = Set() - sage: Y.subsets_lattice() + sage: Y.subsets_lattice() # optional - sage.combinat Finite lattice containing 1 elements """ @@ -835,7 +839,7 @@ def _sympy_(self): sage: X = Set(ZZ); X Set of elements of Integer Ring - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Integers """ from sage.interfaces.sympy import sympy_init @@ -853,13 +857,13 @@ def __init__(self, X, category=None): EXAMPLES:: - sage: S = Set(GF(19)); S + sage: S = Set(GF(19)); S # optional - sage.rings.finite_rings {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18} - sage: S.category() + sage: S.category() # optional - sage.rings.finite_rings Category of finite enumerated sets - sage: print(latex(S)) + sage: print(latex(S)) # optional - sage.rings.finite_rings \left\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18\right\} - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.rings.finite_rings """ Set_object.__init__(self, X, category=FiniteEnumeratedSets().or_subcategory(category)) @@ -884,7 +888,7 @@ def is_finite(self): EXAMPLES:: - sage: Set(GF(19)).is_finite() + sage: Set(GF(19)).is_finite() # optional - sage.rings.finite_rings True """ return True @@ -916,15 +920,15 @@ def __iter__(self): EXAMPLES:: - sage: S = Set(GF(19)) - sage: I = iter(S) - sage: next(I) + sage: S = Set(GF(19)) # optional - sage.rings.finite_rings + sage: I = iter(S) # optional - sage.rings.finite_rings + sage: next(I) # optional - sage.rings.finite_rings 0 - sage: next(I) + sage: next(I) # optional - sage.rings.finite_rings 1 - sage: next(I) + sage: next(I) # optional - sage.rings.finite_rings 2 - sage: next(I) + sage: next(I) # optional - sage.rings.finite_rings 3 """ return iter(self.set()) @@ -935,8 +939,8 @@ def _latex_(self): EXAMPLES:: - sage: S = Set(GF(2)) - sage: latex(S) + sage: S = Set(GF(2)) # optional - sage.rings.finite_rings + sage: latex(S) # optional - sage.rings.finite_rings \left\{0, 1\right\} """ return '\\left\\{' + ', '.join(latex(x) for x in self.set()) + '\\right\\}' @@ -947,8 +951,8 @@ def _repr_(self): EXAMPLES:: - sage: S = Set(GF(2)) - sage: S + sage: S = Set(GF(2)) # optional - sage.rings.finite_rings + sage: S # optional - sage.rings.finite_rings {0, 1} TESTS:: @@ -967,12 +971,12 @@ def list(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: X.list() + sage: X.list() # optional - sage.rings.finite_rings [0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1] - sage: type(X.list()) + sage: type(X.list()) # optional - sage.rings.finite_rings <... 'list'> .. TODO:: @@ -995,14 +999,14 @@ def set(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: X.set() + sage: X.set() # optional - sage.rings.finite_rings {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: type(X.set()) + sage: type(X.set()) # optional - sage.rings.finite_rings <... 'set'> - sage: type(X) + sage: type(X) # optional - sage.rings.finite_rings """ return set(self.object()) @@ -1014,22 +1018,22 @@ def frozenset(self): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: s = X.set(); s + sage: s = X.set(); s # optional - sage.rings.finite_rings {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: hash(s) + sage: hash(s) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unhashable type: 'set' - sage: s = X.frozenset(); s + sage: s = X.frozenset(); s # optional - sage.rings.finite_rings frozenset({0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1}) - sage: hash(s) != hash(tuple(X.set())) + sage: hash(s) != hash(tuple(X.set())) # optional - sage.rings.finite_rings True - sage: type(s) + sage: type(s) # optional - sage.rings.finite_rings <... 'frozenset'> """ return frozenset(self.object()) @@ -1040,8 +1044,8 @@ def __hash__(self): EXAMPLES:: - sage: s = Set(GF(8,'c')) - sage: hash(s) == hash(s) + sage: s = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: hash(s) == hash(s) # optional - sage.rings.finite_rings True """ return hash(self.frozenset()) @@ -1052,10 +1056,10 @@ def __richcmp__(self, other, op): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: X == Set(GF(8,'c')) + sage: X = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: X == Set(GF(8,'c')) # optional - sage.rings.finite_rings True - sage: X == Set(GF(4,'a')) + sage: X == Set(GF(4,'a')) # optional - sage.rings.finite_rings False sage: Set(QQ) == Set(ZZ) False @@ -1101,7 +1105,7 @@ def issubset(self, other): TESTS:: - sage: len([Z for Z in Y.subsets() if Z.issubset(X)]) + sage: len([Z for Z in Y.subsets() if Z.issubset(X)]) # optional - sage.combinat 8 """ if not isinstance(other, Set_object_enumerated): @@ -1129,7 +1133,7 @@ def issuperset(self, other): TESTS:: - sage: len([Z for Z in Y.subsets() if Z.issuperset(X)]) + sage: len([Z for Z in Y.subsets() if Z.issuperset(X)]) # optional - sage.combinat 4 """ if not isinstance(other, Set_object_enumerated): @@ -1142,13 +1146,13 @@ def union(self, other): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: Y = Set([GF(8,'c').0, 1, 2, 3]) - sage: X + sage: X = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1} - sage: sorted(Y) + sage: sorted(Y) # optional - sage.rings.finite_rings [1, 2, 3, c] - sage: sorted(X.union(Y), key=str) + sage: sorted(X.union(Y), key=str) # optional - sage.rings.finite_rings [0, 1, 2, 3, c, c + 1, c^2, c^2 + 1, c^2 + c, c^2 + c + 1] """ if not isinstance(other, Set_object_enumerated): @@ -1161,9 +1165,9 @@ def intersection(self, other): EXAMPLES:: - sage: X = Set(GF(8,'c')) - sage: Y = Set([GF(8,'c').0, 1, 2, 3]) - sage: X.intersection(Y) + sage: X = Set(GF(8,'c')) # optional - sage.rings.finite_rings + sage: Y = Set([GF(8,'c').0, 1, 2, 3]) # optional - sage.rings.finite_rings + sage: X.intersection(Y) # optional - sage.rings.finite_rings {1, c} """ if not isinstance(other, Set_object_enumerated): @@ -1227,16 +1231,16 @@ def _sympy_(self): sage: X = Set({1, 2, 3}); X {1, 2, 3} - sage: sX = X._sympy_(); sX + sage: sX = X._sympy_(); sX # optional - sympy Set(1, 2, 3) - sage: sX.is_empty is None + sage: sX.is_empty is None # optional - sympy True sage: Empty = Set([]); Empty {} - sage: sEmpty = Empty._sympy_(); sEmpty + sage: sEmpty = Empty._sympy_(); sEmpty # optional - sympy EmptySet - sage: sEmpty.is_empty + sage: sEmpty.is_empty # optional - sympy True """ from sympy import Set, EmptySet @@ -1264,10 +1268,10 @@ class Set_object_binary(Set_object, metaclass=ClasscallMetaclass): EXAMPLES:: - sage: X = Set(QQ^2) + sage: X = Set(QQ^2) # optional - sage.modules sage: Y = Set(ZZ) sage: from sage.sets.set import Set_object_binary - sage: S = Set_object_binary(X, Y, "union", "\\cup"); S + sage: S = Set_object_binary(X, Y, "union", "\\cup"); S # optional - sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring @@ -1281,9 +1285,9 @@ def __classcall__(cls, X, Y, *args, **kwds): TESTS:: sage: from sage.sets.set import Set_object_binary - sage: X = QQ^2 + sage: X = QQ^2 # optional - sage.modules sage: Y = ZZ - sage: Set_object_binary(X, Y, "union", "\\cup") + sage: Set_object_binary(X, Y, "union", "\\cup") # optional - sage.modules Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring @@ -1301,10 +1305,10 @@ def __init__(self, X, Y, op, latex_op, category=None): TESTS:: sage: from sage.sets.set import Set_object_binary - sage: X = Set(QQ^2) + sage: X = Set(QQ^2) # optional - sage.modules sage: Y = Set(ZZ) - sage: S = Set_object_binary(X, Y, "union", "\\cup") - sage: type(S) + sage: S = Set_object_binary(X, Y, "union", "\\cup") # optional - sage.modules + sage: type(S) # optional - sage.modules """ self._X = X @@ -1319,7 +1323,7 @@ def _repr_(self): EXAMPLES:: - sage: Set(ZZ).union(Set(GF(5))) + sage: Set(ZZ).union(Set(GF(5))) # optional - sage.rings.finite_rings Set-theoretic union of Set of elements of Integer Ring and {0, 1, 2, 3, 4} """ return "Set-theoretic {} of {} and {}".format(self._op, self._X, self._Y) @@ -1330,7 +1334,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Set(ZZ).union(Set(GF(5)))) + sage: latex(Set(ZZ).union(Set(GF(5)))) # optional - sage.rings.finite_rings \Bold{Z} \cup \left\{0, 1, 2, 3, 4\right\} """ return latex(self._X) + self._latex_op + latex(self._Y) @@ -1344,9 +1348,9 @@ def __hash__(self): The hash values of equal sets are in general not equal since it is not decidable whether two sets are equal:: - sage: X = Set(GF(13)).intersection(Set(ZZ)) - sage: Y = Set(ZZ).intersection(Set(GF(13))) - sage: hash(X) == hash(Y) + sage: X = Set(GF(13)).intersection(Set(ZZ)) # optional - sage.rings.finite_rings + sage: Y = Set(ZZ).intersection(Set(GF(13))) # optional - sage.rings.finite_rings + sage: hash(X) == hash(Y) # optional - sage.rings.finite_rings False TESTS: @@ -1371,17 +1375,19 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) + sage: S = Set(QQ^2) # optional - sage.modules sage: T = Set(ZZ) - sage: X = S.union(T); X - Set-theoretic union of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() + sage: X = S.union(T); X # optional - sage.modules + Set-theoretic union of + Set of elements of Vector space of dimension 2 over Rational Field and + Set of elements of Integer Ring + sage: X.category() # optional - sage.modules Category of infinite sets - sage: latex(X) + sage: latex(X) # optional - sage.modules \Bold{Q}^{2} \cup \Bold{Z} - sage: TestSuite(X).run() + sage: TestSuite(X).run() # optional - sage.modules """ if category is None: category = Sets() @@ -1422,11 +1428,11 @@ def __richcmp__(self, right, op): EXAMPLES:: - sage: Y = Set(ZZ^2).union(Set(ZZ^3)) - sage: X = Set(ZZ^3).union(Set(ZZ^2)) - sage: X == Y + sage: Y = Set(ZZ^2).union(Set(ZZ^3)) # optional - sage.modules + sage: X = Set(ZZ^3).union(Set(ZZ^2)) # optional - sage.modules + sage: X == Y # optional - sage.modules True - sage: Y == X + sage: Y == X # optional - sage.modules True This illustrates that equality testing for formal unions @@ -1452,7 +1458,7 @@ def __iter__(self): EXAMPLES:: - sage: [x for x in Set(GF(3)).union(Set(GF(2)))] + sage: [x for x in Set(GF(3)).union(Set(GF(2)))] # optional - sage.rings.finite_rings [0, 1, 2, 0, 1] """ for x in self._X: @@ -1466,14 +1472,14 @@ def __contains__(self, x): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) - sage: GF(5)(1) in X + sage: X = Set(GF(3)).union(Set(GF(2))) # optional - sage.rings.finite_rings + sage: GF(5)(1) in X # optional - sage.rings.finite_rings False - sage: GF(3)(2) in X + sage: GF(3)(2) in X # optional - sage.rings.finite_rings True - sage: GF(2)(0) in X + sage: GF(2)(0) in X # optional - sage.rings.finite_rings True - sage: GF(5)(0) in X + sage: GF(5)(0) in X # optional - sage.rings.finite_rings False """ return x in self._X or x in self._Y @@ -1484,14 +1490,14 @@ def cardinality(self): EXAMPLES:: - sage: X = Set(GF(3)).union(Set(GF(2))) - sage: X + sage: X = Set(GF(3)).union(Set(GF(2))) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings {0, 1, 2, 0, 1} - sage: X.cardinality() + sage: X.cardinality() # optional - sage.rings.finite_rings 5 - sage: X = Set(GF(3)).union(Set(ZZ)) - sage: X.cardinality() + sage: X = Set(GF(3)).union(Set(ZZ)) # optional - sage.rings.finite_rings + sage: X.cardinality() # optional - sage.rings.finite_rings +Infinity """ return self._X.cardinality() + self._Y.cardinality() @@ -1505,7 +1511,7 @@ def _sympy_(self): sage: X = Set(ZZ).union(Set([1/2])); X Set-theoretic union of Set of elements of Integer Ring and {1/2} - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Union(Integers, Set(1/2)) """ from sympy import Union @@ -1524,13 +1530,15 @@ def __init__(self, X, Y, category=None): EXAMPLES:: - sage: S = Set(QQ^2) - sage: T = Set(ZZ) - sage: X = S.intersection(T); X - Set-theoretic intersection of Set of elements of Vector space of dimension 2 over Rational Field and Set of elements of Integer Ring - sage: X.category() + sage: S = Set(QQ^2) # optional - sage.modules + sage: T = Set(ZZ) # optional - sage.modules + sage: X = S.intersection(T); X # optional - sage.modules + Set-theoretic intersection of + Set of elements of Vector space of dimension 2 over Rational Field and + Set of elements of Integer Ring + sage: X.category() # optional - sage.modules Category of enumerated sets - sage: latex(X) + sage: latex(X) # optional - sage.modules \Bold{Q}^{2} \cap \Bold{Z} sage: X = Set(IntegerRange(100)).intersection(Primes()) @@ -1684,7 +1692,7 @@ def _sympy_(self): Set-theoretic intersection of Set of elements of Integer Ring and Set of elements of [3/2, 11/2] - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Range(2, 6, 1) """ from sympy import Intersection @@ -1706,7 +1714,9 @@ def __init__(self, X, Y, category=None): sage: S = Set(QQ) sage: T = Set(ZZ) sage: X = S.difference(T); X - Set-theoretic difference of Set of elements of Rational Field and Set of elements of Integer Ring + Set-theoretic difference of + Set of elements of Rational Field and + Set of elements of Integer Ring sage: X.category() Category of sets sage: latex(X) @@ -1853,7 +1863,7 @@ def _sympy_(self): Set of elements of Integer Ring sage: X.category() Category of sets - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Complement(Rationals, Integers) sage: X = Set(ZZ).difference(Set(QQ)); X @@ -1862,7 +1872,7 @@ def _sympy_(self): Set of elements of Rational Field sage: X.category() Category of enumerated sets - sage: X._sympy_() + sage: X._sympy_() # optional - sympy EmptySet """ from sympy import Complement @@ -2029,7 +2039,7 @@ def _sympy_(self): Set-theoretic symmetric difference of Set of elements of Integer Ring and {0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3} - sage: X._sympy_() + sage: X._sympy_() # optional - sympy Union(Complement(Integers, Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3)), Complement(Set(0, 1, 2, 1/3, 2/3, 4/3, 5/3, 7/3, 8/3), Integers)) """ diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index a99a559b691..fbbbbe4c9a0 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -460,7 +460,7 @@ def _instancedoc_(self): sage: print(sage_getdoc(d)) # indirect doctest Test whether "self" is prime. ... - Calls the PARI "isprime" function. + Calls the PARI ...isprime... """ # Duplicates sage.misc.cachefunc.CachedFunction._instancedoc_ from sage.misc.sageinspect import sage_getsourcelines, sage_getfile_relative, _extract_embedded_position diff --git a/src/sage/sets/totally_ordered_finite_set.py b/src/sage/sets/totally_ordered_finite_set.py index 8a6966a845a..e6138644510 100644 --- a/src/sage/sets/totally_ordered_finite_set.py +++ b/src/sage/sets/totally_ordered_finite_set.py @@ -45,7 +45,7 @@ def __init__(self, parent, data): r""" TESTS:: - sage: T = TotallyOrderedFiniteSet([3,2,1],facade=False) + sage: T = TotallyOrderedFiniteSet([3,2,1], facade=False) sage: TestSuite(T.an_element()).run() """ Element.__init__(self, parent) @@ -173,8 +173,8 @@ class TotallyOrderedFiniteSet(FiniteEnumeratedSet): sage: T1 = TotallyOrderedFiniteSet([3,2,5,1]) sage: T1(3) < T1(1) False - sage: T2 = TotallyOrderedFiniteSet([3,var('x')]) - sage: T2(3) < T2(var('x')) + sage: T2 = TotallyOrderedFiniteSet([3, x]) # optional - sage.symbolic + sage: T2(3) < T2(x) # optional - sage.symbolic 3 < x To make the above example work, you should set the argument facade to diff --git a/src/sage/stats/basic_stats.py b/src/sage/stats/basic_stats.py index d83f08111f0..173f9b614b4 100644 --- a/src/sage/stats/basic_stats.py +++ b/src/sage/stats/basic_stats.py @@ -216,9 +216,9 @@ def std(v, bias=False): + (5*sqrt(2) - 10*I + 3)^2 + (5*sqrt(2) + 5*I - 6)^2) sage: std([RIF(1.0103, 1.0103), RIF(2)]) 0.6998235813403261? - sage: import numpy - sage: x = numpy.array([1,2,3,4,5]) - sage: std(x, bias=False) + sage: import numpy # optional - numpy + sage: x = numpy.array([1,2,3,4,5]) # optional - numpy + sage: std(x, bias=False) # optional - numpy 1.5811388300841898 sage: x = stats.TimeSeries([1..100]) sage: std(x) @@ -295,9 +295,9 @@ def variance(v, bias=False): + 1/450*(5*sqrt(2) + 5*I - 6)^2 sage: variance([RIF(1.0103, 1.0103), RIF(2)]) 0.4897530450000000? - sage: import numpy - sage: x = numpy.array([1,2,3,4,5]) - sage: variance(x, bias=False) + sage: import numpy # optional - numpy + sage: x = numpy.array([1,2,3,4,5]) # optional - numpy + sage: variance(x, bias=False) # optional - numpy 2.5 sage: x = stats.TimeSeries([1..100]) sage: variance(x) diff --git a/src/sage/stats/distributions/discrete_gaussian_polynomial.py b/src/sage/stats/distributions/discrete_gaussian_polynomial.py index 0f4e7e59361..7598f9beb99 100644 --- a/src/sage/stats/distributions/discrete_gaussian_polynomial.py +++ b/src/sage/stats/distributions/discrete_gaussian_polynomial.py @@ -14,11 +14,11 @@ EXAMPLES:: sage: from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler - sage: sigma = 3.0; n=1000 + sage: sigma = 3.0; n = 1000 sage: l = [DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], 64, sigma)() for _ in range(n)] sage: l = [vector(f).norm().n() for f in l] - sage: from numpy import mean - sage: mean(l), sqrt(64)*sigma # abs tol 5e-1 + sage: from numpy import mean # optional - numpy + sage: mean(l), sqrt(64)*sigma # abs tol 5e-1 # optional - numpy (24.0, 24.0) """ @@ -74,7 +74,9 @@ class DiscreteGaussianDistributionPolynomialSampler(SageObject): True sage: gs = DiscreteGaussianDistributionPolynomialSampler(ZZ['x'], 8, 3.0) sage: [gs() for _ in range(3)] # random - [4*x^7 + 4*x^6 - 4*x^5 + 2*x^4 + x^3 - 4*x + 7, -5*x^6 + 4*x^5 - 3*x^3 + 4*x^2 + x, 2*x^7 + 2*x^6 + 2*x^5 - x^4 - 2*x^2 + 3*x + 1] + [4*x^7 + 4*x^6 - 4*x^5 + 2*x^4 + x^3 - 4*x + 7, + -5*x^6 + 4*x^5 - 3*x^3 + 4*x^2 + x, + 2*x^7 + 2*x^6 + 2*x^5 - x^4 - 2*x^2 + 3*x + 1] .. automethod:: __init__ .. automethod:: __call__ diff --git a/src/sage/stats/time_series.pyx b/src/sage/stats/time_series.pyx index 01a735a9679..9d69f200e43 100644 --- a/src/sage/stats/time_series.pyx +++ b/src/sage/stats/time_series.pyx @@ -102,22 +102,22 @@ cdef class TimeSeries: Conversion from a NumPy 1-D array, which is very fast:: sage: v = stats.TimeSeries([1..5]) - sage: w = v.numpy() - sage: stats.TimeSeries(w) + sage: w = v.numpy() # optional - numpy + sage: stats.TimeSeries(w) # optional - numpy [1.0000, 2.0000, 3.0000, 4.0000, 5.0000] Conversion from an n-dimensional NumPy array also works:: - sage: import numpy - sage: v = numpy.array([[1,2], [3,4]], dtype=float); v + sage: import numpy # optional - numpy + sage: v = numpy.array([[1,2], [3,4]], dtype=float); v # optional - numpy array([[1., 2.], [3., 4.]]) - sage: stats.TimeSeries(v) + sage: stats.TimeSeries(v) # optional - numpy [1.0000, 2.0000, 3.0000, 4.0000] - sage: stats.TimeSeries(v[:,0]) + sage: stats.TimeSeries(v[:,0]) # optional - numpy [1.0000, 3.0000] - sage: u = numpy.array([[1,2],[3,4]]) - sage: stats.TimeSeries(u) + sage: u = numpy.array([[1,2],[3,4]]) # optional - numpy + sage: stats.TimeSeries(u) # optional - numpy [1.0000, 2.0000, 3.0000, 4.0000] For speed purposes we don't initialize (so value is garbage):: diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index 52abd7d918b..ce6bc22c52b 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)) """ @@ -271,8 +271,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:: @@ -352,16 +352,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] @@ -389,18 +389,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() @@ -501,10 +501,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] @@ -563,42 +563,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:: @@ -627,7 +627,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. @@ -635,7 +637,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:: @@ -663,7 +665,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 86664258c8c..2c525ffd5ca 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, @@ -124,17 +124,17 @@ cpdef py_scalar_parent(py_type): sage: py_scalar_parent(fractions.Fraction) Rational Field - sage: import numpy - sage: py_scalar_parent(numpy.int16) + sage: import numpy # optional - numpy + sage: py_scalar_parent(numpy.int16) # optional - numpy Integer Ring - sage: py_scalar_parent(numpy.int32) + sage: py_scalar_parent(numpy.int32) # optional - numpy Integer Ring - sage: py_scalar_parent(numpy.uint64) + sage: py_scalar_parent(numpy.uint64) # optional - numpy Integer Ring sage: py_scalar_parent(float) Real Double Field - sage: py_scalar_parent(numpy.double) + sage: py_scalar_parent(numpy.double) # optional - numpy Real Double Field sage: py_scalar_parent(complex) @@ -248,15 +248,15 @@ cpdef py_scalar_to_element(x): sage: for x in elt: ....: assert py_scalar_parent(type(x)) == py_scalar_to_element(x).parent() - sage: import numpy - sage: elt = [numpy.int8('-12'), numpy.uint8('143'), + sage: import numpy # optional - numpy + sage: elt = [numpy.int8('-12'), numpy.uint8('143'), # optional - numpy ....: numpy.int16('-33'), numpy.uint16('122'), ....: numpy.int32('-19'), numpy.uint32('44'), ....: 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'), @@ -323,10 +323,10 @@ cpdef bint parent_is_integers(P) except -1: sage: parent_is_integers(dict) False - sage: import numpy - sage: parent_is_integers(numpy.int16) + sage: import numpy # optional - numpy + sage: parent_is_integers(numpy.int16) # optional - numpy True - sage: parent_is_integers(numpy.uint64) + sage: parent_is_integers(numpy.uint64) # optional - numpy True sage: parent_is_integers(float) False @@ -365,12 +365,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] """ @@ -388,15 +393,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] """ @@ -415,14 +427,14 @@ cpdef bint is_numpy_type(t): EXAMPLES:: sage: from sage.structure.coerce import is_numpy_type - sage: import numpy - sage: is_numpy_type(numpy.int16) + sage: import numpy # optional - numpy + sage: is_numpy_type(numpy.int16) # optional - numpy True - sage: is_numpy_type(numpy.floating) + sage: is_numpy_type(numpy.floating) # optional - numpy True - sage: is_numpy_type(numpy.ndarray) + sage: is_numpy_type(numpy.ndarray) # optional - numpy True - sage: is_numpy_type(numpy.matrix) + sage: is_numpy_type(numpy.matrix) # optional - numpy True sage: is_numpy_type(int) False @@ -465,12 +477,12 @@ cpdef bint is_mpmath_type(t): sage: from sage.structure.coerce import is_mpmath_type sage: is_mpmath_type(int) False - sage: import mpmath - sage: is_mpmath_type(mpmath.mpc(2)) + sage: import mpmath # optional - mpmath + sage: is_mpmath_type(mpmath.mpc(2)) # optional - mpmath False - sage: is_mpmath_type(type(mpmath.mpc(2))) + sage: is_mpmath_type(type(mpmath.mpc(2))) # optional - mpmath True - sage: is_mpmath_type(type(mpmath.mpf(2))) + sage: is_mpmath_type(type(mpmath.mpf(2))) # optional - mpmath True """ return isinstance(t, type) and \ @@ -479,17 +491,18 @@ cpdef bint is_mpmath_type(t): cdef class CoercionModel: """ - See also sage.categories.pushout + See also :mod:`sage.categories.pushout` 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 + sage: MatrixSpace(ZZ['x'], 2, 2)(2) + ~Frac(QQ['x']).0 # optional - sage.modules [(2*x + 1)/x 0] [ 0 (2*x + 1)/x] sage: f = ZZ['x,y,z'].0 + QQ['w,x,z,a'].0; f @@ -503,11 +516,11 @@ cdef class CoercionModel: Check that :trac:`8426` is fixed (see also :trac:`18076`):: - sage: import numpy + sage: import numpy # optional - numpy sage: x = polygen(RR) - sage: numpy.float32('1.5') * x + sage: numpy.float32('1.5') * x # optional - numpy 1.50000000000000*x - sage: x * numpy.float32('1.5') + sage: x * numpy.float32('1.5') # optional - numpy 1.50000000000000*x sage: p = x**3 + 2*x - 1 sage: p(float('1.2')) @@ -517,26 +530,26 @@ cdef class CoercionModel: This used to fail (see :trac:`18076`):: - sage: 1/3 + numpy.int8('12') + sage: 1/3 + numpy.int8('12') # optional - numpy 37/3 - sage: -2/3 + numpy.int16('-2') + sage: -2/3 + numpy.int16('-2') # optional - numpy -8/3 - sage: 2/5 + numpy.uint8('2') + sage: 2/5 + numpy.uint8('2') # optional - numpy 12/5 The numpy types do not interact well with the Sage coercion framework. More precisely, if a numpy type is the first operand in a binary operation then this operation is done in numpy. The result is hence a numpy type:: - sage: numpy.uint8('2') + 3 + sage: numpy.uint8('2') + 3 # optional - numpy 5 - sage: type(_) + sage: type(_) # optional - numpy # 32-bit # 64-bit - sage: numpy.int8('12') + 1/3 + sage: numpy.int8('12') + 1/3 # optional - numpy 12.333333333333334 - sage: type(_) + sage: type(_) # optional - numpy AUTHOR: @@ -549,8 +562,9 @@ cdef class CoercionModel: sage: from sage.structure.coerce import CoercionModel sage: cm = CoercionModel() - sage: K = NumberField(x^2-2, 'a') - sage: A = cm.get_action(ZZ, K, operator.mul) + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 - 2, 'a') # optional - sage.rings.number_field + sage: A = cm.get_action(ZZ, K, operator.mul) # optional - sage.rings.number_field sage: f, g = cm.coercion_maps(QQ, int) sage: f, g = cm.coercion_maps(ZZ, int) """ @@ -591,7 +605,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 +649,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 +700,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 +762,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 +823,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 +893,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 +934,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 +1064,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 +1101,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 +1152,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 +1283,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 +1315,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,35 +1458,35 @@ 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 directions, the parent on the left is used:: - sage: V = QQ^3 - sage: W = V.__class__(QQ, 3) - sage: V == W + sage: V = QQ^3 # optional - sage.modules + sage: W = V.__class__(QQ, 3) # optional - sage.modules + sage: V == W # optional - sage.modules True - sage: V is W + sage: V is W # optional - sage.modules False - sage: cm = sage.structure.element.get_coercion_model() - sage: cm.coercion_maps(V, W) + sage: cm = sage.structure.element.get_coercion_model() # optional - sage.modules + sage: cm.coercion_maps(V, W) # optional - sage.modules (None, (map internal to coercion system -- copy before use) Coercion map: From: Vector space of dimension 3 over Rational Field To: Vector space of dimension 3 over Rational Field) - sage: cm.coercion_maps(W, V) + sage: cm.coercion_maps(W, V) # optional - sage.modules (None, (map internal to coercion system -- copy before use) Coercion map: From: Vector space of dimension 3 over Rational Field To: Vector space of dimension 3 over Rational Field) - sage: v = V([1,2,3]) - sage: w = W([1,2,3]) - sage: parent(v+w) is V + sage: v = V([1,2,3]) # optional - sage.modules + sage: w = W([1,2,3]) # optional - sage.modules + sage: parent(v + w) is V # optional - sage.modules True - sage: parent(w+v) is W + sage: parent(w + v) is W # optional - sage.modules True TESTS: @@ -1473,19 +1495,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 +1575,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 +1640,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:: @@ -1694,18 +1718,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 @@ -1734,7 +1762,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): ... @@ -1743,8 +1772,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 @@ -1799,7 +1829,8 @@ cdef class CoercionModel: sage: P. = ZZ['x'] sage: P.get_action(ZZ) - 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: ZZ.get_action(P) is None True sage: cm = sage.structure.element.get_coercion_model() @@ -1807,43 +1838,48 @@ cdef class CoercionModel: If R or S is a Parent, ask it for an action by/on R:: sage: cm.discover_action(ZZ, P, operator.mul) - Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring + Left scalar multiplication by Integer Ring on + Univariate Polynomial Ring in x over Integer Ring If R or S a type, recursively call get_action with the Sage versions of R and/or S:: sage: cm.discover_action(P, int, operator.mul) - Right scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring - with precomposition on right by Native morphism: + Right scalar multiplication by Integer Ring on + Univariate Polynomial Ring in x over Integer Ring + with precomposition on right by Native morphism: From: Set of Python objects of class 'int' To: Integer Ring If op is division, look for action on right by inverse:: sage: cm.discover_action(P, ZZ, operator.truediv) - 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 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:: - sage: F. = FreeAlgebra(QQ) - sage: x / 2 + sage: F. = FreeAlgebra(QQ) # optional - sage.combinat sage.modules + sage: x / 2 # optional - sage.combinat sage.modules 1/2*x - sage: cm.discover_action(F, ZZ, operator.truediv) - Right inverse action by Rational Field on Free Algebra on 1 generators (x,) over Rational Field - with precomposition on right by Natural morphism: + sage: cm.discover_action(F, ZZ, operator.truediv) # optional - sage.combinat sage.modules + Right inverse action by Rational Field on + Free Algebra on 1 generators (x,) over Rational Field + with precomposition on right by Natural morphism: From: Integer Ring To: Rational Field """ @@ -1933,15 +1969,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..50babb96570 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.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.modules + sage: A.codomain() # optional - sage.modules Set P^1(QQ) of all cusps sage: S3 = SymmetricGroup(3) # optional - sage.groups @@ -123,7 +125,7 @@ cdef class ActOnAction(GenericAction): sage: A = sage.structure.coerce_actions.ActOnAction(G, R, False) # optional - sage.groups sage: A(x^2 + y - z, G((1,2))) # optional - sage.groups y^2 + x - z - sage: A(x+2*y+3*z, G((1,3,2))) # optional - sage.groups + sage: A(x + 2*y + 3*z, G((1,3,2))) # optional - sage.groups 2*x + 3*y + z sage: type(A) # 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.modules + sage: A.act(matrix(ZZ, 2, [1,0,2,-1]), Cusp(1,2)) # optional - 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.modules Infinity - sage: type(A) + sage: type(A) # optional - sage.modules <... 'sage.structure.coerce_actions.ActedUponAction'> """ return (x)._acted_upon_(g, not self._is_left) @@ -166,14 +168,17 @@ def detect_element_action(Parent X, Y, bint X_on_left, X_el=None, Y_el=None): sage: from sage.structure.coerce_actions import detect_element_action sage: ZZx = ZZ['x'] - sage: M = MatrixSpace(ZZ,2) + sage: M = MatrixSpace(ZZ, 2) # optional - sage.modules sage: detect_element_action(ZZx, ZZ, False) - Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring + 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.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.modules (None,) sage: detect_element_action(ZZ, QQ, True), (None,) @@ -295,7 +300,8 @@ cdef class ModuleAction(Action): sage: LeftModuleAction(QQ, ZZx) Left scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring sage: LeftModuleAction(QQ, ZZxy) - Left scalar multiplication by Rational Field on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring + Left scalar multiplication by Rational Field + on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring The following tests against a problem that was relevant during work on :trac:`9944`:: @@ -393,14 +399,16 @@ cdef class ModuleAction(Action): sage: from sage.structure.coerce_actions import LeftModuleAction, RightModuleAction sage: ZZx = ZZ['x'] sage: A = LeftModuleAction(ZZ, ZZx); A - Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring + Left scalar multiplication by Integer Ring + on Univariate Polynomial Ring in x over Integer Ring sage: A._repr_name_() 'scalar multiplication' - sage: GF5 = GF(5) - sage: GF5t = GF5[['t']] - sage: RightModuleAction(GF5, GF5t) - Right scalar multiplication by Finite Field of size 5 on Power Series Ring in t over Finite Field of size 5 + sage: GF5 = GF(5) # optional - sage.rings.finite_rings + sage: GF5t = GF5[['t']] # optional - sage.rings.finite_rings + sage: RightModuleAction(GF5, GF5t) # optional - sage.rings.finite_rings + Right scalar multiplication by Finite Field of size 5 + on Power Series Ring in t over Finite Field of size 5 """ return "scalar multiplication" @@ -481,18 +489,20 @@ cdef class ModuleAction(Action): sage: A(x, 2) 1/2*x - sage: GF5x = GF(5)['x'] - sage: A = ~RightModuleAction(ZZ, GF5x); A - Right inverse action by Finite Field of size 5 on Univariate Polynomial Ring in x over Finite Field of size 5 + sage: GF5x = GF(5)['x'] # optional - sage.rings.finite_rings + sage: A = ~RightModuleAction(ZZ, GF5x); A # 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: A(x, 2) + sage: A(x, 2) # optional - sage.rings.finite_rings 3*x - sage: GF5xy = GF5x['y'] - sage: A = ~RightModuleAction(ZZ, GF5xy); A - Right inverse action by Finite Field of size 5 on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Finite Field of size 5 + sage: GF5xy = GF5x['y'] # optional - sage.rings.finite_rings + sage: A = ~RightModuleAction(ZZ, GF5xy); A # optional - sage.rings.finite_rings + Right inverse action by Finite Field of size 5 + on Univariate Polynomial Ring in y over 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 @@ -516,14 +526,15 @@ cdef class ModuleAction(Action): See :trac:`19521`:: - sage: Q. = SR.subring(no_variables=True)[[]] - sage: (y / 1).parent() + sage: Q. = SR.subring(no_variables=True)[[]] # optional - sage.symbolic + sage: (y / 1).parent() # optional - sage.symbolic Power Series Ring in y over Symbolic Constants Subring - sage: R. = SR.subring(no_variables=True)[] - sage: cm = sage.structure.element.get_coercion_model() - sage: cm.explain(x, 1, operator.truediv) + sage: R. = SR.subring(no_variables=True)[] # optional - sage.symbolic + sage: cm = sage.structure.element.get_coercion_model() # optional - sage.symbolic + sage: cm.explain(x, 1, operator.truediv) # optional - sage.symbolic Action discovered. - Right inverse action by Symbolic Constants Subring on Univariate Polynomial Ring in x over Symbolic Constants Subring + Right inverse action by Symbolic Constants Subring + on Univariate Polynomial Ring in x over Symbolic Constants Subring with precomposition on right by Conversion via _symbolic_ method map: From: Integer Ring To: Symbolic Constants Subring @@ -743,13 +754,13 @@ cdef class IntegerMulAction(IntegerAction): random errors (see :trac:`18157`). :: sage: from sage.structure.coerce_actions import IntegerMulAction - sage: GF101 = GF(101) - sage: act = IntegerMulAction(ZZ, GF101) - sage: act(3, 9) + sage: GF101 = GF(101) # optional - sage.rings.finite_rings + sage: act = IntegerMulAction(ZZ, GF101) # optional - sage.rings.finite_rings + sage: act(3, 9) # optional - sage.rings.finite_rings 27 - sage: act(3^689, 9) + sage: act(3^689, 9) # optional - sage.rings.finite_rings 42 - sage: 3^689 * mod(9, 101) + sage: 3^689 * mod(9, 101) # optional - sage.rings.finite_rings 42 TESTS: @@ -763,14 +774,14 @@ cdef class IntegerMulAction(IntegerAction): This used to hang before :trac:`17844`:: - sage: E = EllipticCurve(GF(5), [4,0]) - sage: P = E.random_element() - sage: (-2^63)*P + sage: E = EllipticCurve(GF(5), [4,0]) # optional - sage.rings.finite_rings + sage: P = E.random_element() # optional - sage.rings.finite_rings + sage: (-2^63)*P # optional - sage.rings.finite_rings (0 : 1 : 0) Check that large multiplications can be interrupted:: - sage: alarm(0.001); 2^(10^7) * P + sage: alarm(0.001); 2^(10^7) * P # optional - sage.rings.finite_rings Traceback (most recent call last): ... AlarmInterrupt @@ -778,8 +789,8 @@ cdef class IntegerMulAction(IntegerAction): Verify that cysignals correctly detects that the above exception has been handled:: - sage: from cysignals.tests import print_sig_occurred - sage: print_sig_occurred() + sage: from cysignals.tests import print_sig_occurred # optional - sage.rings.finite_rings + sage: print_sig_occurred() # optional - sage.rings.finite_rings No current exception """ cdef int err = 0 @@ -800,9 +811,10 @@ cdef class IntegerMulAction(IntegerAction): random errors (see :trac:`18157`). :: sage: from sage.structure.coerce_actions import IntegerMulAction - sage: GF5 = GF(5) - sage: IntegerMulAction(ZZ, GF5) - Left Integer Multiplication by Integer Ring on Finite Field of size 5 + sage: GF5 = GF(5) # optional - sage.rings.finite_rings + sage: IntegerMulAction(ZZ, GF5) # optional - sage.rings.finite_rings + Left Integer Multiplication by Integer Ring + on Finite Field of size 5 """ return "Integer Multiplication" @@ -847,11 +859,11 @@ cdef class IntegerPowAction(IntegerAction): :: - sage: var('x,y') + sage: var('x,y') # optional - sage.symbolic (x, y) - sage: RDF('-2.3')^(x+y^3+sin(x)) + sage: RDF('-2.3')^(x+y^3+sin(x)) # optional - sage.symbolic (-2.3)^(y^3 + x + sin(x)) - sage: RDF('-2.3')^x + sage: RDF('-2.3')^x # optional - sage.symbolic (-2.3)^x """ def __init__(self, Z, M, is_left=False, m=None): @@ -875,13 +887,13 @@ cdef class IntegerPowAction(IntegerAction): ``GF(101)``:: sage: from sage.structure.coerce_actions import IntegerPowAction - sage: GF101 = GF(101) - sage: act = IntegerPowAction(ZZ, GF101) - sage: act(3, 100) + sage: GF101 = GF(101) # optional - sage.rings.finite_rings + sage: act = IntegerPowAction(ZZ, GF101) # optional - sage.rings.finite_rings + sage: act(3, 100) # optional - sage.rings.finite_rings 1 - sage: act(3, -1) + sage: act(3, -1) # optional - sage.rings.finite_rings 34 - sage: act(3, 1000000000000000000000000000000000000000000001) + sage: act(3, 1000000000000000000000000000000000000000000001) # optional - sage.rings.finite_rings 3 """ cdef Element e = a diff --git a/src/sage/structure/coerce_dict.pyx b/src/sage/structure/coerce_dict.pyx index 440993aadd6..e9c923c6343 100644 --- a/src/sage/structure/coerce_dict.pyx +++ b/src/sage/structure/coerce_dict.pyx @@ -41,12 +41,12 @@ However, this leak was fixed by :trac:`715`, using weak references:: ....: 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 3537c24e678..7ccc402c43a 100644 --- a/src/sage/structure/coerce_maps.pyx +++ b/src/sage/structure/coerce_maps.pyx @@ -34,16 +34,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 @@ -52,7 +55,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 @@ -83,8 +87,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") @@ -193,13 +197,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): @@ -216,19 +220,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) @@ -242,19 +246,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'] @@ -265,13 +269,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 @@ -299,8 +303,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 @@ -333,12 +337,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 e52f4665a3f..c304407aaea 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -360,7 +360,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) @@ -654,7 +654,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() @@ -896,17 +896,17 @@ cdef class Element(SageObject): EXAMPLES:: - sage: from sage.libs.mpmath.all import mp, mpmathify - sage: mp.dps = 30 - sage: 25._mpmath_(53) + sage: from sage.libs.mpmath.all import mp, mpmathify # optional - mpmath + sage: mp.dps = 30 # optional - mpmath + sage: 25._mpmath_(53) # optional - mpmath 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) @@ -927,11 +927,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 @@ -1031,13 +1031,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 """ @@ -1137,7 +1137,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 @@ -1150,9 +1150,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 @@ -1287,16 +1287,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) @@ -1497,13 +1497,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] @@ -1565,16 +1565,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) @@ -1682,11 +1682,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) :: @@ -2001,15 +2001,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 @@ -2147,7 +2147,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 @@ -2226,7 +2226,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", @@ -2249,21 +2249,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 @@ -2271,36 +2271,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 """ @@ -2317,7 +2317,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): @@ -2343,12 +2343,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: @@ -2460,8 +2460,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 @@ -2473,11 +2473,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()) @@ -2491,10 +2491,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 @@ -2506,10 +2506,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 @@ -2557,9 +2557,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: @@ -2688,22 +2688,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) @@ -2800,8 +2800,8 @@ cdef class RingElement(ModuleElement): :: - sage: R. = GF(7)[] - sage: divmod(x^2, x-1) + sage: R. = GF(7)[] # optional - sage.libs.pari + sage: divmod(x^2, x - 1) # optional - sage.libs.pari (x + 1, 1) :: @@ -2846,8 +2846,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' @@ -2891,30 +2891,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:: @@ -2937,13 +2937,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 @@ -2987,16 +2987,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.libs.pari + sage: x = F.gen() # optional - sage.libs.pari + sage: z = F.zero() # optional - sage.libs.pari + sage: x.inverse_mod(F.ideal(z)) # optional - sage.libs.pari 2*z2 + 3 - sage: x.inverse_mod(F.ideal(1)) + sage: x.inverse_mod(F.ideal(1)) # optional - sage.libs.pari 1 - sage: z.inverse_mod(F.ideal(1)) + sage: z.inverse_mod(F.ideal(1)) # optional - sage.libs.pari 1 - sage: z.inverse_mod(F.ideal(z)) + sage: z.inverse_mod(F.ideal(z)) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: an element of a proper ideal does not have an inverse modulo that ideal @@ -3019,24 +3019,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.libs.pari + sage: K(3).divides(1) # optional - sage.libs.pari True - sage: K(3).divides(K(1)) + sage: K(3).divides(K(1)) # optional - sage.libs.pari True :: @@ -3160,22 +3160,22 @@ cdef class CommutativeRingElement(RingElement): and an ideal:: sage: R. = PolynomialRing(QQ, 3) - sage: (x^2 + y^2 + z^2).mod(x+y+z) + sage: (x^2 + y^2 + z^2).mod(x + y + z) # optional - sage.libs.singular 2*y^2 + 2*y*z + 2*z^2 Notice above that `x` is eliminated. In the next example, both `y` and `z` are eliminated:: - sage: (x^2 + y^2 + z^2).mod( (x - y, y - z) ) + sage: (x^2 + y^2 + z^2).mod( (x - y, y - z) ) # optional - sage.libs.singular 3*z^2 sage: f = (x^2 + y^2 + z^2)^2; f x^4 + 2*x^2*y^2 + y^4 + 2*x^2*z^2 + 2*y^2*z^2 + z^4 - sage: f.mod( (x - y, y - z) ) + sage: f.mod( (x - y, y - z) ) # optional - sage.libs.singular 9*z^4 In this example `y` is eliminated:: - sage: (x^2 + y^2 + z^2).mod( (x^3, y - z) ) + sage: (x^2 + y^2 + z^2).mod( (x^3, y - z) ) # optional - sage.libs.singular x^2 + 2*z^2 """ from sage.rings.ideal import is_Ideal @@ -3367,7 +3367,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:: @@ -3404,195 +3404,251 @@ cdef class Vector(ModuleElementWithMutability): Here we test (vector * vector) multiplication:: - sage: parent(vector(ZZ,[1,2])*vector(ZZ,[1,2])) + sage: parent(vector(ZZ, [1,2]) * vector(ZZ, [1,2])) # optional - sage.modules Integer Ring - sage: parent(vector(ZZ,[1,2])*vector(QQ,[1,2])) + sage: parent(vector(ZZ, [1,2]) * vector(QQ, [1,2])) # optional - sage.modules Rational Field - sage: parent(vector(QQ,[1,2])*vector(ZZ,[1,2])) + sage: parent(vector(QQ, [1,2]) * vector(ZZ, [1,2])) # optional - sage.modules Rational Field - sage: parent(vector(QQ,[1,2])*vector(QQ,[1,2])) + sage: parent(vector(QQ, [1,2]) * vector(QQ, [1,2])) # optional - sage.modules Rational Field - sage: parent(vector(QQ,[1,2,3,4])*vector(ZZ['x'],[1,2,3,4])) + sage: parent(vector(QQ, [1,2,3,4]) * vector(ZZ['x'], [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x'],[1,2,3,4])*vector(QQ,[1,2,3,4])) + sage: parent(vector(ZZ['x'], [1,2,3,4]) * vector(QQ, [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(QQ,[1,2,3,4])*vector(ZZ['x']['y'],[1,2,3,4])) + sage: parent(vector(QQ, [1,2,3,4]) * vector(ZZ['x']['y'], [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2,3,4])*vector(QQ,[1,2,3,4])) + sage: parent(vector(ZZ['x']['y'], [1,2,3,4]) * vector(QQ, [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(QQ['x'],[1,2,3,4])*vector(ZZ['x']['y'],[1,2,3,4])) + sage: parent(vector(QQ['x'], [1,2,3,4]) * vector(ZZ['x']['y'], [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2,3,4])*vector(QQ['x'],[1,2,3,4])) + sage: parent(vector(ZZ['x']['y'], [1,2,3,4]) * vector(QQ['x'], [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(QQ['y'],[1,2,3,4])*vector(ZZ['x']['y'],[1,2,3,4])) + sage: parent(vector(QQ['y'], [1,2,3,4]) * vector(ZZ['x']['y'], [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2,3,4])*vector(QQ['y'],[1,2,3,4])) + sage: parent(vector(ZZ['x']['y'], [1,2,3,4]) * vector(QQ['y'], [1,2,3,4])) # optional - sage.modules Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x'],[1,2,3,4])*vector(ZZ['y'],[1,2,3,4])) + sage: parent(vector(ZZ['x'], [1,2,3,4]) * vector(ZZ['y'], [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Integer Ring' - sage: parent(vector(ZZ['x'],[1,2,3,4])*vector(QQ['y'],[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and + 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Integer Ring' + sage: parent(vector(ZZ['x'], [1,2,3,4]) * vector(QQ['y'], [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' - sage: parent(vector(QQ['x'],[1,2,3,4])*vector(ZZ['y'],[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and + 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' + sage: parent(vector(QQ['x'], [1,2,3,4]) * vector(ZZ['y'], [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Integer Ring' - sage: parent(vector(QQ['x'],[1,2,3,4])*vector(QQ['y'],[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and + 'Ambient free module of rank 4 over the integral domain Univariate Polynomial Ring in y over Integer Ring' + sage: parent(vector(QQ['x'], [1,2,3,4]) * vector(QQ['y'], [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and + 'Ambient free module of rank 4 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' Here we test (vector * matrix) multiplication:: - sage: parent(vector(ZZ,[1,2])*matrix(ZZ,2,2,[1,2,3,4])) + sage: parent(vector(ZZ, [1,2]) * matrix(ZZ, 2, 2, [1,2,3,4])) # optional - sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring - sage: parent(vector(QQ,[1,2])*matrix(ZZ,2,2,[1,2,3,4])) + sage: parent(vector(QQ, [1,2]) * matrix(ZZ, 2, 2, [1,2,3,4])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(vector(ZZ,[1,2])*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(vector(ZZ, [1,2]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(vector(QQ,[1,2])*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(vector(QQ, [1,2]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(vector(QQ,[1,2])*matrix(ZZ['x'],2,2,[1,2,3,4])) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x'],[1,2])*matrix(QQ,2,2,[1,2,3,4])) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(QQ,[1,2])*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2])*matrix(QQ,2,2,[1,2,3,4])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(QQ['x'],[1,2])*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2])*matrix(QQ['x'],2,2,[1,2,3,4])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(QQ['y'],[1,2])*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2])*matrix(QQ['y'],2,2,[1,2,3,4])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(ZZ['x'],[1,2])*matrix(ZZ['y'],2,2,[1,2,3,4])) + sage: parent(vector(QQ, [1,2]) * matrix(ZZ['x'], 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x'], [1,2]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(QQ, [1,2]) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x']['y'], [1,2]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(QQ['x'], [1,2]) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x']['y'], [1,2]) * matrix(QQ['x'], 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(QQ['y'], [1,2]) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x']['y'], [1,2]) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(ZZ['x'], [1,2]) * matrix(ZZ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' - sage: parent(vector(ZZ['x'],[1,2])*matrix(QQ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' + sage: parent(vector(ZZ['x'], [1,2]) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' - sage: parent(vector(QQ['x'],[1,2])*matrix(ZZ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' + sage: parent(vector(QQ['x'], [1,2]) * matrix(ZZ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' - sage: parent(vector(QQ['x'],[1,2])*matrix(QQ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' + sage: parent(vector(QQ['x'], [1,2]) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' Here we test (vector * scalar) multiplication:: - sage: parent(vector(ZZ,[1,2])*ZZ(1)) + sage: parent(vector(ZZ, [1,2]) * ZZ(1)) # optional - sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring - sage: parent(vector(QQ,[1,2])*ZZ(1)) + sage: parent(vector(QQ, [1,2]) * ZZ(1)) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(vector(ZZ,[1,2])*QQ(1)) + sage: parent(vector(ZZ, [1,2]) * QQ(1)) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(vector(QQ,[1,2])*QQ(1)) + sage: parent(vector(QQ, [1,2]) * QQ(1)) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(vector(QQ,[1,2])*ZZ['x'](1)) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x'],[1,2])*QQ(1)) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(QQ,[1,2])*ZZ['x']['y'](1)) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2])*QQ(1)) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(QQ['x'],[1,2])*ZZ['x']['y'](1)) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2])*QQ['x'](1)) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(QQ['y'],[1,2])*ZZ['x']['y'](1)) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(vector(ZZ['x']['y'],[1,2])*QQ['y'](1)) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(vector(ZZ['x'],[1,2])*ZZ['y'](1)) + sage: parent(vector(QQ, [1,2]) * ZZ['x'](1)) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x'], [1,2]) * QQ(1)) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(QQ, [1,2]) * ZZ['x']['y'](1)) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x']['y'], [1,2]) * QQ(1)) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(QQ['x'], [1,2]) * ZZ['x']['y'](1)) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x']['y'], [1,2]) * QQ['x'](1)) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(QQ['y'], [1,2]) * ZZ['x']['y'](1)) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(vector(ZZ['x']['y'], [1,2]) * QQ['y'](1)) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(vector(ZZ['x'], [1,2]) * ZZ['y'](1)) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring' - sage: parent(vector(ZZ['x'],[1,2])*QQ['y'](1)) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and + 'Univariate Polynomial Ring in y over Integer Ring' + sage: parent(vector(ZZ['x'], [1,2]) * QQ['y'](1)) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Rational Field' - sage: parent(vector(QQ['x'],[1,2])*ZZ['y'](1)) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in x over Integer Ring' and + 'Univariate Polynomial Ring in y over Rational Field' + sage: parent(vector(QQ['x'], [1,2]) * ZZ['y'](1)) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Integer Ring' - sage: parent(vector(QQ['x'],[1,2])*QQ['y'](1)) + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in y over Integer Ring' + sage: parent(vector(QQ['x'], [1,2]) * QQ['y'](1)) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in y over Rational Field' Here we test (scalar * vector) multiplication:: - sage: parent(ZZ(1)*vector(ZZ,[1,2])) + sage: parent(ZZ(1) * vector(ZZ, [1,2])) # optional - sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring - sage: parent(QQ(1)*vector(ZZ,[1,2])) + sage: parent(QQ(1) * vector(ZZ, [1,2])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(ZZ(1)*vector(QQ,[1,2])) + sage: parent(ZZ(1) * vector(QQ, [1,2])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(QQ(1)*vector(QQ,[1,2])) + sage: parent(QQ(1) * vector(QQ, [1,2])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(QQ(1)*vector(ZZ['x'],[1,2])) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x'](1)*vector(QQ,[1,2])) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - - sage: parent(QQ(1)*vector(ZZ['x']['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x']['y'](1)*vector(QQ,[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(QQ['x'](1)*vector(ZZ['x']['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x']['y'](1)*vector(QQ['x'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(QQ['y'](1)*vector(ZZ['x']['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x']['y'](1)*vector(QQ['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(ZZ['x'](1)*vector(ZZ['y'],[1,2])) + sage: parent(QQ(1) * vector(ZZ['x'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x'](1) * vector(QQ, [1,2])) # optional - sage.modules + Ambient free module of rank 2 + over the principal ideal domain Univariate Polynomial Ring in x over Rational Field + + sage: parent(QQ(1) * vector(ZZ['x']['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x']['y'](1) * vector(QQ, [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(QQ['x'](1) * vector(ZZ['x']['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x']['y'](1) * vector(QQ['x'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(QQ['y'](1) * vector(ZZ['x']['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x']['y'](1) * vector(QQ['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(ZZ['x'](1) * vector(ZZ['y'], [1,2])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring' - sage: parent(ZZ['x'](1)*vector(QQ['y'],[1,2])) + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Integer Ring' and + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring' + sage: parent(ZZ['x'](1) * vector(QQ['y'], [1,2])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Integer Ring' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' - sage: parent(QQ['x'](1)*vector(ZZ['y'],[1,2])) + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Integer Ring' and + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' + sage: parent(QQ['x'](1) * vector(ZZ['y'], [1,2])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Rational Field' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring' - sage: parent(QQ['x'](1)*vector(QQ['y'],[1,2])) + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring' + sage: parent(QQ['x'](1) * vector(QQ['y'], [1,2])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: '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 *: + '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' """ if have_same_parent(left, right): return (left)._dot_product_(right) @@ -3613,14 +3669,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) @@ -3647,32 +3703,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()] @@ -3706,210 +3763,269 @@ cdef class Matrix(ModuleElement): Here we test (matrix * matrix) multiplication:: - sage: parent(matrix(ZZ,2,2,[1,2,3,4])*matrix(ZZ,2,2,[1,2,3,4])) + sage: parent(matrix(ZZ, 2, 2, [1,2,3,4]) * matrix(ZZ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(ZZ,2,2,[1,2,3,4])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * matrix(ZZ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(matrix(ZZ,2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(matrix(ZZ, 2, 2, [1,2,3,4]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(ZZ['x'],2,2,[1,2,3,4])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * matrix(ZZ['x'], 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*matrix(QQ,2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*matrix(QQ['x'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ['y'],2,2,[1,2,3,4])*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*matrix(QQ['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*matrix(ZZ['y'],2,2,[1,2,3,4])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * matrix(QQ['x'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ['y'], 2, 2, [1,2,3,4]) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * matrix(ZZ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules 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 Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*matrix(QQ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules 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 Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*matrix(ZZ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * matrix(ZZ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules 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 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*matrix(QQ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules 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 'Full MatrixSpace of 2 by 2 dense matrices over 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 + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' We test that the bug reported in :trac:`27352` has been fixed:: - sage: A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]]) - sage: B = matrix(QQ, [[0, 4], [1, -1], [1, 2]]) - sage: A*B + sage: A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]]) # optional - sage.modules + sage: B = matrix(QQ, [[0, 4], [1, -1], [1, 2]]) # optional - sage.modules + sage: A * B # optional - sage.modules 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:: - sage: parent(matrix(ZZ,2,2,[1,2,3,4])*vector(ZZ,[1,2])) + sage: parent(matrix(ZZ, 2, 2, [1,2,3,4]) * vector(ZZ, [1,2])) # optional - sage.modules Ambient free module of rank 2 over the principal ideal domain Integer Ring - sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(ZZ,[1,2])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * vector(ZZ, [1,2])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(matrix(ZZ,2,2,[1,2,3,4])*vector(QQ,[1,2])) + sage: parent(matrix(ZZ, 2, 2, [1,2,3,4]) * vector(QQ, [1,2])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(QQ,[1,2])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * vector(QQ, [1,2])) # optional - sage.modules Vector space of dimension 2 over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(ZZ['x'],[1,2])) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*vector(QQ,[1,2])) - Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ,2,2,[1,2,3,4])*vector(ZZ['x']['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*vector(QQ,[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*vector(ZZ['x']['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*vector(QQ['x'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ['y'],2,2,[1,2,3,4])*vector(ZZ['x']['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*vector(QQ['y'],[1,2])) - Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*vector(ZZ['y'],[1,2])) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * vector(ZZ['x'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the principal ideal domain + Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * vector(QQ, [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the principal ideal domain + Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * vector(ZZ['x']['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * vector(QQ, [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * vector(ZZ['x']['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * vector(QQ['x'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ['y'], 2, 2, [1,2,3,4]) * vector(ZZ['x']['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * vector(QQ['y'], [1,2])) # optional - sage.modules + Ambient free module of rank 2 over the integral domain + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * vector(ZZ['y'], [1,2])) # optional - sage.modules 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 Integer Ring' and 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring' - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*vector(QQ['y'],[1,2])) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and + 'Ambient free module of rank 2 over the integral domain Univariate Polynomial Ring in y over Integer Ring' + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * vector(QQ['y'], [1,2])) # optional - sage.modules 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 Integer Ring' and 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*vector(ZZ['y'],[1,2])) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and + 'Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in y over Rational Field' + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * vector(ZZ['y'], [1,2])) # optional - sage.modules 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 integral domain Univariate Polynomial Ring in y over Integer Ring' - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*vector(QQ['y'],[1,2])) + 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 integral domain Univariate Polynomial Ring in y over Integer Ring' + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * vector(QQ['y'], [1,2])) # optional - sage.modules 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:: - sage: parent(matrix(ZZ,2,2,[1,2,3,4])*ZZ(1)) + sage: parent(matrix(ZZ, 2, 2, [1,2,3,4]) * ZZ(1)) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: parent(matrix(QQ,2,2,[1,2,3,4])*ZZ(1)) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * ZZ(1)) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(matrix(ZZ,2,2,[1,2,3,4])*QQ(1)) + sage: parent(matrix(ZZ, 2, 2, [1,2,3,4]) * QQ(1)) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*QQ(1)) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * QQ(1)) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*ZZ['x'](1)) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * ZZ['x'](1)) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*QQ(1)) + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * QQ(1)) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(QQ,2,2,[1,2,3,4])*ZZ['x']['y'](1)) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*QQ(1)) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*ZZ['x']['y'](1)) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*QQ['x'](1)) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(QQ['y'],2,2,[1,2,3,4])*ZZ['x']['y'](1)) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(matrix(ZZ['x']['y'],2,2,[1,2,3,4])*QQ['y'](1)) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*ZZ['y'](1)) + sage: parent(matrix(QQ, 2, 2, [1,2,3,4]) * ZZ['x']['y'](1)) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * QQ(1)) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * ZZ['x']['y'](1)) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * QQ['x'](1)) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(QQ['y'], 2, 2, [1,2,3,4]) * ZZ['x']['y'](1)) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(matrix(ZZ['x']['y'], 2, 2, [1,2,3,4]) * QQ['y'](1)) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * ZZ['y'](1)) # optional - sage.modules 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 Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring' - sage: parent(matrix(ZZ['x'],2,2,[1,2,3,4])*QQ['y'](1)) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and + 'Univariate Polynomial Ring in y over Integer Ring' + sage: parent(matrix(ZZ['x'], 2, 2, [1,2,3,4]) * QQ['y'](1)) # optional - sage.modules 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 Integer Ring' and 'Univariate Polynomial Ring in y over Rational Field' - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*ZZ['y'](1)) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring' and + 'Univariate Polynomial Ring in y over Rational Field' + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * ZZ['y'](1)) # optional - sage.modules 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 'Univariate Polynomial Ring in y over Integer Ring' - sage: parent(matrix(QQ['x'],2,2,[1,2,3,4])*QQ['y'](1)) + TypeError: unsupported operand parent(s) for *: + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in y over Integer Ring' + sage: parent(matrix(QQ['x'], 2, 2, [1,2,3,4]) * QQ['y'](1)) # optional - sage.modules 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 '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 + 'Univariate Polynomial Ring in y over Rational Field' Here we test (scalar * matrix) multiplication:: - sage: parent(ZZ(1)*matrix(ZZ,2,2,[1,2,3,4])) + sage: parent(ZZ(1) * matrix(ZZ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: parent(QQ(1)*matrix(ZZ,2,2,[1,2,3,4])) + sage: parent(QQ(1) * matrix(ZZ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(ZZ(1)*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(ZZ(1) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(QQ(1)*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(QQ(1) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: parent(QQ(1)*matrix(ZZ['x'],2,2,[1,2,3,4])) + sage: parent(QQ(1) * matrix(ZZ['x'], 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x'](1)*matrix(QQ,2,2,[1,2,3,4])) + sage: parent(ZZ['x'](1) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field - sage: parent(QQ(1)*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x']['y'](1)*matrix(QQ,2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(QQ['x'](1)*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x']['y'](1)*matrix(QQ['x'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(QQ['y'](1)*matrix(ZZ['x']['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - sage: parent(ZZ['x']['y'](1)*matrix(QQ['y'],2,2,[1,2,3,4])) - Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field - - sage: parent(ZZ['x'](1)*matrix(ZZ['y'],2,2,[1,2,3,4])) + sage: parent(QQ(1) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x']['y'](1) * matrix(QQ, 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(QQ['x'](1) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x']['y'](1) * matrix(QQ['x'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices over + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(QQ['y'](1) * matrix(ZZ['x']['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + sage: parent(ZZ['x']['y'](1) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules + Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + + sage: parent(ZZ['x'](1) * matrix(ZZ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' - sage: parent(ZZ['x'](1)*matrix(QQ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Integer Ring' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' + sage: parent(ZZ['x'](1) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Integer Ring' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' - sage: parent(QQ['x'](1)*matrix(ZZ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Integer Ring' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' + sage: parent(QQ['x'](1) * matrix(ZZ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' - sage: parent(QQ['x'](1)*matrix(QQ['y'],2,2,[1,2,3,4])) + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Integer Ring' + sage: parent(QQ['x'](1) * matrix(QQ['y'], 2, 2, [1,2,3,4])) # optional - sage.modules Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for *: 'Univariate Polynomial Ring in x over Rational Field' and 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' + TypeError: unsupported operand parent(s) for *: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field' Examples with matrices having matrix coefficients:: - sage: m = matrix - sage: a = m([[m([[1,2],[3,4]]),m([[5,6],[7,8]])],[m([[9,10],[11,12]]),m([[13,14],[15,16]])]]) - sage: 3*a + sage: m = matrix # optional - sage.modules + sage: a = m([[m([[1,2],[3,4]]),m([[5,6],[7,8]])],[m([[9,10],[11,12]]),m([[13,14],[15,16]])]]) # optional - sage.modules + sage: 3 * a # optional - sage.modules [[ 3 6] [ 9 12] [15 18] [21 24]] @@ -3917,9 +4033,9 @@ cdef class Matrix(ModuleElement): [33 36] [39 42] [45 48]] - sage: m = matrix - sage: a = m([[m([[1,2],[3,4]]),m([[5,6],[7,8]])],[m([[9,10],[11,12]]),m([[13,14],[15,16]])]]) - sage: a*3 + sage: m = matrix # optional - sage.modules + sage: a = m([[m([[1,2],[3,4]]),m([[5,6],[7,8]])],[m([[9,10],[11,12]]),m([[13,14],[15,16]])]]) # optional - sage.modules + sage: a * 3 # optional - sage.modules [[ 3 6] [ 9 12] [15 18] [21 24]] @@ -3961,32 +4077,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): @@ -4042,14 +4158,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 @@ -4060,7 +4176,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 @@ -4081,14 +4197,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 @@ -4138,15 +4254,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) @@ -4169,15 +4285,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) @@ -4198,12 +4314,12 @@ cdef class FieldElement(CommutativeRingElement): EXAMPLES:: - sage: K. = NumberField(x^4 + x^2 + 2/3) - sage: c = (1+b) // (1-b); c + 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) @@ -4253,10 +4369,10 @@ cdef class FieldElement(CommutativeRingElement): Test if :trac:`8671` is fixed:: sage: R. = QQ[] - sage: S. = R.quo(y^2 + 1) - sage: S.is_field = lambda : False - sage: F = Frac(S); u = F.one() - sage: u.quo_rem(u) + sage: S. = R.quo(y^2 + 1) # optional - sage.libs.pari + sage: S.is_field = lambda: False # optional - sage.libs.pari + sage: F = Frac(S); u = F.one() # optional - sage.libs.pari + sage: u.quo_rem(u) # optional - sage.libs.pari (1, 0) """ if not isinstance(right, FieldElement) or not (parent(right) is self._parent): @@ -4272,14 +4388,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): @@ -4294,8 +4410,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) @@ -4353,8 +4469,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] @@ -4404,14 +4520,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.libs.pari 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.libs.pari 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(): @@ -4444,7 +4562,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 @@ -4465,15 +4583,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 b2caa14a285..0d4a704783c 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,59 @@ 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) + (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: 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 +209,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 +284,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 +416,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,9 +523,9 @@ 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() @@ -551,11 +554,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 +579,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 +605,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 +623,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 @@ -673,14 +676,14 @@ def sort(self, key=None): We create a factored polynomial:: - sage: x = polygen(QQ,'x') - sage: F = factor(x^3 + 1); F + sage: x = polygen(QQ, 'x') + sage: F = factor(x^3 + 1); F # optional - sage.libs.pari (x + 1) * (x^2 - x + 1) 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: @@ -861,7 +864,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 +901,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 +1006,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 +1038,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[] @@ -1097,16 +1100,17 @@ def __pow__(self, n): sage: f^4 2^8 * 5^8 - sage: K. = NumberField(x^3 - 39*x - 91) - sage: F = K.factor(7); F + sage: x = polygen(ZZ, 'x') + 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 @@ -1138,10 +1142,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)], @@ -1159,12 +1163,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): @@ -1182,10 +1186,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 @@ -1211,7 +1215,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): @@ -1253,7 +1257,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 98178afca79..fc6b0735bae 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,24 @@ 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)), check=False) # optional - sage.rings.finite_rings 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 +310,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 +340,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 +402,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 +420,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 4157295be90..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) @@ -50,6 +50,7 @@ def default_prec(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: R = QQ[[x]] sage: R.default_prec() 20 diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 25c4157c3df..d3aa238e01f 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 """ # **************************************************************************** @@ -362,16 +362,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: @@ -585,8 +591,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_ @@ -824,7 +830,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): @@ -910,36 +916,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] @@ -949,14 +955,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] @@ -1005,22 +1011,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' @@ -1130,9 +1136,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 @@ -1195,8 +1201,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.rings.finite_rings + sage: V.coerce(0) # optional - sage.rings.finite_rings (0, 0, 0, 0, 0, 0, 0) """ cdef R = parent(x) @@ -1234,7 +1240,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), @@ -1371,29 +1377,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 @@ -1678,30 +1685,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: @@ -1762,35 +1769,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] @@ -1798,11 +1805,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] @@ -1811,29 +1818,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] """ @@ -1862,16 +1870,18 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: K.=NumberField(x^3+x^2+1,embedding=1) - sage: K.coerce_embedding() + 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 @@ -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 ....: 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: _ = gc.collect() # optional - sage.rings.finite_rings + sage: len([x for x in gc.get_objects() if isinstance(x, type(E))]) # optional - sage.rings.finite_rings 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: H = Sym.macdonald().H() # optional - sage.combinat + sage: P = Sym.macdonald().P() # optional - sage.combinat + sage: m = Sym.monomial() # optional - sage.combinat + sage: Ht = Sym.macdonald().Ht() # optional - sage.combinat + sage: phi = m.coerce_map_from(P) # optional - sage.combinat """ 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): @@ -2285,18 +2295,18 @@ cdef class Parent(sage.structure.category_object.CategoryObject): Another test:: - sage: K = NumberField([x^2-2, x^2-3], 'a,b') - sage: M = K.absolute_field('c') - sage: M_to_K, K_to_M = M.structure() - sage: M.register_coercion(K_to_M) - sage: K.register_coercion(M_to_K) - sage: phi = M.coerce_map_from(QQ) - sage: p = QQ.random_element() - sage: c = phi(p) - p; c + sage: K = NumberField([x^2 - 2, x^2 - 3], 'a,b') # optional - sage.rings.number_field + sage: M = K.absolute_field('c') # optional - sage.rings.number_field + sage: M_to_K, K_to_M = M.structure() # optional - sage.rings.number_field + sage: M.register_coercion(K_to_M) # optional - sage.rings.number_field + sage: K.register_coercion(M_to_K) # optional - sage.rings.number_field + sage: phi = M.coerce_map_from(QQ) # optional - sage.rings.number_field + 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 @@ -2318,16 +2328,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 @@ -2335,15 +2347,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: @@ -2539,10 +2554,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) @@ -2563,27 +2582,34 @@ cdef class Parent(sage.structure.category_object.CategoryObject): 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 + 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 + 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 + 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 + 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 :: @@ -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,10 +2832,14 @@ 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: 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 [RIF, RBF, CIF, CBF]] [False, False, False, False] """ @@ -2832,12 +2862,18 @@ 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 [SR, QQ['x'], QQ[['x']]]] - [False, False, False] sage: [R._is_real_numerical() for R in [RIF, RBF, CIF, CBF]] [False, False, False, False] """ @@ -2885,7 +2921,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 +2962,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 c4155736e99..4b84aa909d4 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)) """ @@ -243,31 +243,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 @@ -283,13 +283,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 @@ -338,7 +338,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 630f0ca8613..a99f586fbfc 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.pari 5 """ @@ -48,19 +48,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.rings.finite_rings + sage: V.list() # optional - 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.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 + 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 24532380e8a..a8e91de77d5 100644 --- a/src/sage/structure/proof/proof.py +++ b/src/sage/structure/proof/proof.py @@ -192,14 +192,16 @@ def get_flag(t = None, subsystem = None): class WithProof(): """ - Use WithProof to temporarily set the value of one of the proof + Use :class:`WithProof` to temporarily set the value of one of the proof 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 6cdaa84e4ef..dfda29da4e3 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..40571dcb217 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: g = SymmetricFunctions(QQ) # optional - sage.combinat to create the symmetric function algebra over `\QQ` actually gives back the same object:: - sage: f == g + sage: f == g # optional - sage.combinat True - sage: f is g + sage: f is g # optional - sage.combinat True This is a standard design pattern. It allows for sharing cached data (say @@ -1211,14 +1211,14 @@ 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 True - sage: issubclass(SymmetricFunctions, UniqueRepresentation) + sage: issubclass(SymmetricFunctions, UniqueRepresentation) # optional - sage.combinat 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... diff --git a/src/sage/symbolic/constants.py b/src/sage/symbolic/constants.py index 587b63e2dcb..e1682860786 100644 --- a/src/sage/symbolic/constants.py +++ b/src/sage/symbolic/constants.py @@ -599,8 +599,8 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: sympy.pi == pi # indirect doctest + sage: import sympy # optional - sympy + sage: sympy.pi == pi # indirect doctest # optional - sympy True """ import sympy @@ -739,10 +739,10 @@ def _sympy_(self): EXAMPLES:: - sage: bool(NaN._sympy_()._sage_() == NaN) + sage: bool(NaN._sympy_()._sage_() == NaN) # optional - sympy True - sage: import sympy - sage: sympy.nan == NaN # this should be fixed + sage: import sympy # optional - sympy + sage: sympy.nan == NaN # this should be fixed # optional - sympy False """ import sympy @@ -843,8 +843,8 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: sympy.GoldenRatio == golden_ratio # indirect doctest + sage: import sympy # optional - sympy + sage: sympy.GoldenRatio == golden_ratio # indirect doctest # optional - sympy True """ import sympy @@ -996,8 +996,8 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: sympy.EulerGamma == euler_gamma # indirect doctest + sage: import sympy # optional - sympy + sage: sympy.EulerGamma == euler_gamma # indirect doctest # optional - sympy True """ import sympy @@ -1064,8 +1064,8 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: sympy.Catalan == catalan # indirect doctest + sage: import sympy # optional - sympy + sage: sympy.Catalan == catalan # indirect doctest # optional - sympy True """ import sympy diff --git a/src/sage/symbolic/constants_c_impl.pxi b/src/sage/symbolic/constants_c_impl.pxi index 14369e848ca..293c3b972a8 100644 --- a/src/sage/symbolic/constants_c_impl.pxi +++ b/src/sage/symbolic/constants_c_impl.pxi @@ -106,8 +106,8 @@ cdef class E(Expression): 2.7182818284590452353602874714 sage: e._real_double_(RDF) # abs tol 5e-16 2.718281828459045 - sage: import sympy - sage: sympy.E == e # indirect doctest + sage: import sympy # optional - sympy + sage: sympy.E == e # indirect doctest # optional - sympy True TESTS:: diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index a8236db2a0b..cf9a584cf93 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -661,25 +661,25 @@ class SympyConverter(Converter): EXAMPLES:: - sage: import sympy + sage: import sympy # optional - sympy sage: var('x,y') (x, y) sage: f = exp(x^2) - arcsin(pi+x)/y - sage: f._sympy_() + sage: f._sympy_() # optional - sympy exp(x**2) - asin(x + pi)/y - sage: _._sage_() + sage: _._sage_() # optional - sympy -arcsin(pi + x)/y + e^(x^2) - sage: sympy.sympify(x) # indirect doctest + sage: sympy.sympify(x) # indirect doctest # optional - sympy x TESTS: Make sure we can convert I (:trac:`6424`):: - sage: bool(I._sympy_() == I) + sage: bool(I._sympy_() == I) # optional - sympy True - sage: (x+I)._sympy_() + sage: (x+I)._sympy_() # optional - sympy x + I """ @@ -687,9 +687,9 @@ def __init__(self): """ TESTS:: - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() # indirect doctest - sage: TestSuite(s).run(skip="_test_pickling") + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # indirect doctest # optional - sympy + sage: TestSuite(s).run(skip="_test_pickling") # optional - sympy """ from sage.interfaces.sympy import sympy_init sympy_init() @@ -698,11 +698,11 @@ def __call__(self, ex=None): """ EXAMPLES:: - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # optional - sympy sage: f(x, y) = x^2 + y^2; f (x, y) |--> x^2 + y^2 - sage: s(f) + sage: s(f) # optional - sympy Lambda((x, y), x**2 + y**2) """ if isinstance(ex, Expression) and ex.is_callable(): @@ -715,12 +715,12 @@ def pyobject(self, ex, obj): """ EXAMPLES:: - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # optional - sympy sage: f = SR(2) - sage: s.pyobject(f, f.pyobject()) + sage: s.pyobject(f, f.pyobject()) # optional - sympy 2 - sage: type(_) + sage: type(_) # optional - sympy """ try: @@ -732,10 +732,10 @@ def arithmetic(self, ex, operator): """ EXAMPLES:: - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # optional - sympy sage: f = x + 2 - sage: s.arithmetic(f, f.operator()) + sage: s.arithmetic(f, f.operator()) # optional - sympy x + 2 """ import sympy @@ -758,11 +758,11 @@ def symbol(self, ex): """ EXAMPLES:: - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() - sage: s.symbol(x) + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # optional - sympy + sage: s.symbol(x) # optional - sympy x - sage: type(_) + sage: type(_) # optional - sympy """ import sympy @@ -772,16 +772,16 @@ def relation(self, ex, op): """ EXAMPLES:: - sage: import operator - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() - sage: s.relation(x == 3, operator.eq) + sage: import operator # optional - sympy + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # optional - sympy + sage: s.relation(x == 3, operator.eq) # optional - sympy Eq(x, 3) - sage: s.relation(pi < 3, operator.lt) + sage: s.relation(pi < 3, operator.lt) # optional - sympy pi < 3 - sage: s.relation(x != pi, operator.ne) + sage: s.relation(x != pi, operator.ne) # optional - sympy Ne(x, pi) - sage: s.relation(x > 0, operator.gt) + sage: s.relation(x > 0, operator.gt) # optional - sympy x > 0 """ from sympy import Eq, Ne, Gt, Lt, Ge, Le @@ -792,15 +792,15 @@ def composition(self, ex, operator): """ EXAMPLES:: - sage: from sage.symbolic.expression_conversions import SympyConverter - sage: s = SympyConverter() + sage: from sage.symbolic.expression_conversions import SympyConverter # optional - sympy + sage: s = SympyConverter() # optional - sympy sage: f = sin(2) - sage: s.composition(f, f.operator()) + sage: s.composition(f, f.operator()) # optional - sympy sin(2) - sage: type(_) + sage: type(_) # optional - sympy sin sage: f = arcsin(2) - sage: s.composition(f, f.operator()) + sage: s.composition(f, f.operator()) # optional - sympy asin(2) """ g = ex.operands() @@ -824,26 +824,26 @@ def tuple(self, ex): EXAMPLES:: sage: t = SR._force_pyobject((3, 4, e^x)) - sage: t._sympy_() + sage: t._sympy_() # optional - sympy (3, 4, e^x) sage: t = SR._force_pyobject((cos(x),)) - sage: t._sympy_() + sage: t._sympy_() # optional - sympy (cos(x),) TESTS:: - sage: from sage.symbolic.expression_conversions import sympy_converter + sage: from sage.symbolic.expression_conversions import sympy_converter # optional - sympy sage: F = hypergeometric([1/3,2/3],[1,1],x) - sage: F._sympy_() + sage: F._sympy_() # optional - sympy hyper((1/3, 2/3), (1, 1), x) sage: F = hypergeometric([1/3,2/3],[1],x) - sage: F._sympy_() + sage: F._sympy_() # optional - sympy hyper((1/3, 2/3), (1,), x) sage: var('a,b,c,d') (a, b, c, d) - sage: hypergeometric((a,b,),(c,),d)._sympy_() + sage: hypergeometric((a,b,),(c,),d)._sympy_() # optional - sympy hyper((a, b), (c,), d) """ return tuple(ex.operands()) @@ -864,20 +864,20 @@ def derivative(self, ex, operator): (x, y) sage: f_sage = function('f_sage')(x, y) - sage: f_sympy = f_sage._sympy_() + sage: f_sympy = f_sage._sympy_() # optional - sympy sage: df_sage = f_sage.diff(x, 2, y, 1); df_sage diff(f_sage(x, y), x, x, y) - sage: df_sympy = df_sage._sympy_(); df_sympy + sage: df_sympy = df_sage._sympy_(); df_sympy # optional - sympy Derivative(f_sage(x, y), (x, 2), y) - sage: df_sympy == f_sympy.diff(x, 2, y, 1) + sage: df_sympy == f_sympy.diff(x, 2, y, 1) # optional - sympy True Check that :trac:`28964` is fixed:: sage: f = function('f') sage: _ = var('x,t') - sage: diff(f(x, t), x)._sympy_(), diff(f(x, t), t)._sympy_() + sage: diff(f(x, t), x)._sympy_(), diff(f(x, t), t)._sympy_() # optional - sympy (Derivative(f(x, t), x), Derivative(f(x, t), t)) Check differentiating by variables with multiple occurrences @@ -885,15 +885,15 @@ def derivative(self, ex, operator): sage: f = function('f') sage: _ = var('x1,x2,x3,x,t') - sage: f(x, x, t).diff(x)._sympy_()._sage_() + sage: f(x, x, t).diff(x)._sympy_()._sage_() # optional - sympy D[0](f)(x, x, t) + D[1](f)(x, x, t) sage: g = f(x1, x2, x3, t).diff(x1, 2, x2).subs(x1==x, x2==x, x3==x); g D[0, 0, 1](f)(x, x, x, t) - sage: g._sympy_() + sage: g._sympy_() # optional - sympy Subs(Derivative(f(_xi_1, _xi_2, x, t), (_xi_1, 2), _xi_2), (_xi_1, _xi_2), (x, x)) - sage: assert g._sympy_()._sage_() == g + sage: assert g._sympy_()._sage_() == g # optional - sympy Check that the use of dummy variables does not cause a collision:: @@ -901,7 +901,7 @@ def derivative(self, ex, operator): sage: _ = var('x1,x2,x,xi_1') sage: g = f(x1, x2, xi_1).diff(x1).subs(x1==x, x2==x); g D[0](f)(x, x, xi_1) - sage: assert g._sympy_()._sage_() == g + sage: assert g._sympy_()._sage_() == g # optional - sympy """ import sympy diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 4979188159a..36be92940c3 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -433,8 +433,8 @@ cdef class Function(SageObject): We can also handle numpy types:: - sage: import numpy - sage: sin(numpy.arange(5)) + sage: import numpy # optional - numpy + sage: sin(numpy.arange(5)) # optional - numpy array([ 0. , 0.84147098, 0.90929743, 0.14112001, -0.7568025 ]) Symbolic functions evaluate non-exact input numerically, and return @@ -483,9 +483,10 @@ cdef class Function(SageObject): Make sure we can pass mpmath arguments (:trac:`13608`):: - sage: import mpmath - sage: with mpmath.workprec(128): sin(mpmath.mpc('0.5', '1.2')) - mpc(real='0.86807452059118713192871150787046523179886', imag='1.3246769633571289324095313649562791720086') + sage: import mpmath # optional - mpmath + sage: with mpmath.workprec(128): sin(mpmath.mpc('0.5', '1.2')) # optional - mpmath + mpc(real='0.86807452059118713192871150787046523179886', + imag='1.3246769633571289324095313649562791720086') Check that :trac:`10133` is fixed:: @@ -504,11 +505,11 @@ cdef class Function(SageObject): Check that ``real_part`` and ``imag_part`` still works after :trac:`21216`:: - sage: import numpy - sage: a = numpy.array([1+2*I, -2-3*I], dtype=complex) - sage: real_part(a) + sage: import numpy # optional - numpy + sage: a = numpy.array([1+2*I, -2-3*I], dtype=complex) # optional - numpy + sage: real_part(a) # optional - numpy array([ 1., -2.]) - sage: imag_part(a) + sage: imag_part(a) # optional - numpy array([ 2., -3.]) """ if self._nargs > 0 and len(args) != self._nargs: @@ -742,13 +743,13 @@ cdef class Function(SageObject): EXAMPLES:: - sage: import numpy - sage: a = numpy.arange(5) - sage: csc(a) + sage: import numpy # optional - numpy + sage: a = numpy.arange(5) # optional - numpy + sage: csc(a) # optional - numpy doctest:...: RuntimeWarning: divide by zero encountered in ...divide array([ inf, 1.18839511, 1.09975017, 7.0861674 , -1.32134871]) - sage: factorial(a) + sage: factorial(a) # optional - numpy Traceback (most recent call last): ... NotImplementedError: The Function factorial does not support numpy arrays as arguments @@ -769,8 +770,8 @@ cdef class Function(SageObject): implementation, using sage reals instead of mpmath ones. This might change when aliases for these functions are established:: - sage: import mpmath - sage: with mpmath.workprec(128): arcsin(mpmath.mpf('0.5')) + sage: import mpmath # optional - mpmath + sage: with mpmath.workprec(128): arcsin(mpmath.mpf('0.5')) # optional - mpmath mpf('0.52359877559829887307710723054658381403157') TESTS: @@ -779,7 +780,7 @@ cdef class Function(SageObject): not using mpmath, we have to create a custom function which will certainly never get created in mpmath. :: - sage: import mpmath + sage: import mpmath # optional - mpmath sage: from sage.symbolic.function import BuiltinFunction sage: class NoMpmathFn(BuiltinFunction): ....: def _eval_(self, arg): @@ -787,13 +788,13 @@ cdef class Function(SageObject): ....: prec = parent.prec() ....: assert parent == RealField(prec) ....: return prec - sage: noMpmathFn = NoMpmathFn("noMpmathFn") - sage: with mpmath.workprec(64): noMpmathFn(sqrt(mpmath.mpf('2'))) + sage: noMpmathFn = NoMpmathFn("noMpmathFn") # optional - mpmath + sage: with mpmath.workprec(64): noMpmathFn(sqrt(mpmath.mpf('2'))) # optional - mpmath 64 - sage: mpmath.noMpmathFn = lambda x: 123 - sage: with mpmath.workprec(64): noMpmathFn(sqrt(mpmath.mpf('2'))) + sage: mpmath.noMpmathFn = lambda x: 123 # optional - mpmath + sage: with mpmath.workprec(64): noMpmathFn(sqrt(mpmath.mpf('2'))) # optional - mpmath 123 - sage: del mpmath.noMpmathFn + sage: del mpmath.noMpmathFn # optional - mpmath """ import mpmath @@ -944,16 +945,16 @@ cdef class BuiltinFunction(Function): (1.5430806348152437-0j) sage: assert type(_) is complex - sage: import mpmath - sage: cos(mpmath.mpf('1.321412')) + sage: import mpmath # optional - mpmath + sage: cos(mpmath.mpf('1.321412')) # optional - mpmath mpf('0.24680737898640387') - sage: cos(mpmath.mpc(1,1)) + sage: cos(mpmath.mpc(1,1)) # optional - mpmath mpc(real='0.83373002513114902', imag='-0.98889770576286506') - sage: import numpy - sage: sin(numpy.int32(0)) + sage: import numpy # optional - numpy + sage: sin(numpy.int32(0)) # optional - numpy 0.0 - sage: type(_) + sage: type(_) # optional - numpy TESTS:: diff --git a/src/sage/symbolic/integration/external.py b/src/sage/symbolic/integration/external.py index 0760f20920b..cc18073733b 100644 --- a/src/sage/symbolic/integration/external.py +++ b/src/sage/symbolic/integration/external.py @@ -3,7 +3,7 @@ TESTS:: sage: from sage.symbolic.integration.external import sympy_integrator - sage: sympy_integrator(sin(x), x) + sage: sympy_integrator(sin(x), x) # optional - sympy -cos(x) """ from sage.symbolic.expression import Expression @@ -54,9 +54,9 @@ def sympy_integrator(expression, v, a=None, b=None): EXAMPLES:: sage: from sage.symbolic.integration.external import sympy_integrator - sage: sympy_integrator(sin(x), x) + sage: sympy_integrator(sin(x), x) # optional - sympy -cos(x) - sage: sympy_integrator(cos(x), x) + sage: sympy_integrator(cos(x), x) # optional - sympy sin(x) """ import sympy diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index a0c497dc65d..932d4ebda93 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -1167,17 +1167,17 @@ cdef class NumpyToSRMorphism(Morphism): We check that :trac:`8949` and :trac:`9769` are fixed (see also :trac:`18076`):: - sage: import numpy + sage: import numpy # optional - numpy sage: f(x) = x^2 - sage: f(numpy.int8('2')) + sage: f(numpy.int8('2')) # optional - numpy 4 - sage: f(numpy.int32('3')) + sage: f(numpy.int32('3')) # optional - numpy 9 Note that the answer is a Sage integer and not a numpy type:: - sage: a = f(numpy.int8('2')).pyobject() - sage: type(a) + sage: a = f(numpy.int8('2')).pyobject() # optional - numpy + sage: type(a) # optional - numpy This behavior also applies to standard functions:: @@ -1200,15 +1200,15 @@ cdef class NumpyToSRMorphism(Morphism): EXAMPLES:: - sage: import numpy + sage: import numpy # optional - numpy sage: from sage.symbolic.ring import NumpyToSRMorphism - sage: f = NumpyToSRMorphism(numpy.float64) - sage: f(numpy.float64('2.0')) + sage: f = NumpyToSRMorphism(numpy.float64) # optional - numpy + sage: f(numpy.float64('2.0')) # optional - numpy 2.0 - sage: _.parent() + sage: _.parent() # optional - numpy Symbolic Ring - sage: NumpyToSRMorphism(str) + sage: NumpyToSRMorphism(str) # optional - numpy Traceback (most recent call last): ... TypeError: <... 'str'> is not a numpy number type @@ -1235,18 +1235,18 @@ cdef class NumpyToSRMorphism(Morphism): This should be called when coercing or converting a NumPy float or complex to the Symbolic Ring:: - sage: import numpy - sage: SR(numpy.int32('1')).pyobject().parent() + sage: import numpy # optional - numpy + sage: SR(numpy.int32('1')).pyobject().parent() # optional - numpy Integer Ring - sage: SR(numpy.int64('-2')).pyobject().parent() + sage: SR(numpy.int64('-2')).pyobject().parent() # optional - numpy Integer Ring - sage: SR(numpy.float16('1')).pyobject().parent() + sage: SR(numpy.float16('1')).pyobject().parent() # optional - numpy Real Double Field - sage: SR(numpy.float64('2.0')).pyobject().parent() + sage: SR(numpy.float64('2.0')).pyobject().parent() # optional - numpy Real Double Field - sage: SR(numpy.complex64(1jr)).pyobject().parent() + sage: SR(numpy.complex64(1jr)).pyobject().parent() # optional - numpy Complex Double Field """ return new_Expression_from_pyobject(self.codomain(), self._intermediate_ring(a), True) @@ -1260,13 +1260,13 @@ cdef class UnderscoreSageMorphism(Morphism): EXAMPLES:: - sage: import sympy + sage: import sympy # optional - sympy sage: from sage.symbolic.ring import UnderscoreSageMorphism - sage: b = sympy.var('b') - sage: f = UnderscoreSageMorphism(type(b), SR) - sage: f(b) + sage: b = sympy.var('b') # optional - sympy + sage: f = UnderscoreSageMorphism(type(b), SR) # optional - sympy + sage: f(b) # optional - sympy b - sage: _.parent() + sage: _.parent() # optional - sympy Symbolic Ring """ import sage.categories.homset @@ -1282,9 +1282,9 @@ cdef class UnderscoreSageMorphism(Morphism): This should be called when coercing or converting a SymPy object to the Symbolic Ring:: - sage: import sympy - sage: b = sympy.var('b') - sage: bool(SR(b) == SR(b._sage_())) + sage: import sympy # optional - sympy + sage: b = sympy.var('b') # optional - sympy + sage: bool(SR(b) == SR(b._sage_())) # optional - sympy True """ return self.codomain()(a._sage_()) diff --git a/src/sage/topology/simplicial_set_constructions.py b/src/sage/topology/simplicial_set_constructions.py index e5a14632098..984d1e5df60 100644 --- a/src/sage/topology/simplicial_set_constructions.py +++ b/src/sage/topology/simplicial_set_constructions.py @@ -1387,7 +1387,7 @@ def __classcall_private__(cls, maps=None, vertex_name=None): sage: from sage.topology.simplicial_set_constructions import PushoutOfSimplicialSets_finite sage: S2 = simplicial_sets.Sphere(2) sage: one = S2.Hom(S2).identity() - sage: PushoutOfSimplicialSets_finite([one, one]) == PushoutOfSimplicialSets_finite((one, one)) + sage: PushoutOfSimplicialSets_finite([one, one]) == PushoutOfSimplicialSets_finite((one, one)) # optional - sage.graphs True """ if maps: @@ -1411,9 +1411,9 @@ def __init__(self, maps=None, vertex_name=None): sage: from sage.topology.simplicial_set_constructions import PushoutOfSimplicialSets_finite sage: T = simplicial_sets.Torus() sage: S2 = simplicial_sets.Sphere(2) - sage: PushoutOfSimplicialSets_finite([T.base_point_map(), S2.base_point_map()]).n_cells(0)[0] + sage: PushoutOfSimplicialSets_finite([T.base_point_map(), S2.base_point_map()]).n_cells(0)[0] # optional - sage.graphs * - sage: PushoutOfSimplicialSets_finite([T.base_point_map(), S2.base_point_map()], vertex_name='v').n_cells(0)[0] + sage: PushoutOfSimplicialSets_finite([T.base_point_map(), S2.base_point_map()], vertex_name='v').n_cells(0)[0] # optional - sage.graphs v """ from sage.graphs.graph import Graph @@ -1584,15 +1584,15 @@ def structure_map(self, i): sage: S1 = simplicial_sets.Sphere(1) sage: T = simplicial_sets.Torus() - sage: X = S1.disjoint_union(T) # a pushout - sage: X.structure_map(0) + sage: X = S1.disjoint_union(T) # a pushout # optional - sage.graphs + sage: X.structure_map(0) # optional - sage.graphs Simplicial set morphism: From: S^1 To: Disjoint union: (S^1 u Torus) Defn: [v_0, sigma_1] --> [v_0, sigma_1] - sage: X.structure_map(1).domain() + sage: X.structure_map(1).domain() # optional - sage.graphs Torus - sage: X.structure_map(1).codomain() + sage: X.structure_map(1).codomain() # optional - sage.graphs Disjoint union: (S^1 u Torus) """ return self._structure[i] @@ -1626,11 +1626,11 @@ def universal_property(self, *maps): sage: f_0 = Hom(X, Y_0)({v:v, w:w, x:x, evw:evw, evx:evx}) sage: f_1 = Hom(X, Y_1)({v:v, w:v, x:x, evw:v.apply_degeneracies(0), evx:evx}) - sage: P = X.pushout(f_0, f_1) + sage: P = X.pushout(f_0, f_1) # optional - sage.graphs sage: one = Hom(Y_1, Y_1).identity() sage: g = Hom(Y_0, Y_1)({v:v, w:v, x:x, evw:v.apply_degeneracies(0), evx:evx, ewx:evx}) - sage: P.universal_property(g, one) + sage: P.universal_property(g, one) # optional - sage.graphs Simplicial set morphism: From: Pushout of maps: Simplicial set morphism: @@ -1685,10 +1685,10 @@ def __init__(self, inclusion, vertex_name='*'): sage: RP5 = simplicial_sets.RealProjectiveSpace(5) sage: RP2 = RP5.n_skeleton(2) - sage: RP5_2 = RP5.quotient(RP2) - sage: RP5_2 + sage: RP5_2 = RP5.quotient(RP2) # optional - sage.graphs + sage: RP5_2 # optional - sage.graphs Quotient: (RP^5/Simplicial set with 3 non-degenerate simplices) - sage: RP5_2.quotient_map() + sage: RP5_2.quotient_map() # optional - sage.graphs Simplicial set morphism: From: RP^5 To: Quotient: (RP^5/Simplicial set with 3 non-degenerate simplices) @@ -1714,14 +1714,14 @@ def ambient(self): sage: RP5 = simplicial_sets.RealProjectiveSpace(5) sage: RP2 = RP5.n_skeleton(2) - sage: RP5_2 = RP5.quotient(RP2) - sage: RP5_2.ambient() + sage: RP5_2 = RP5.quotient(RP2) # optional - sage.graphs + sage: RP5_2.ambient() # optional - sage.graphs RP^5 sage: B = simplicial_sets.ClassifyingSpace(groups.misc.MultiplicativeAbelian([2])) sage: K = B.n_skeleton(3) - sage: Q = B.quotient(K) - sage: Q.ambient() + sage: Q = B.quotient(K) # optional - sage.graphs + sage: Q.ambient() # optional - sage.graphs Classifying space of Multiplicative Abelian group isomorphic to C2 """ return self._maps[0].codomain() @@ -1736,14 +1736,14 @@ def subcomplex(self): sage: RP5 = simplicial_sets.RealProjectiveSpace(5) sage: RP2 = RP5.n_skeleton(2) - sage: RP5_2 = RP5.quotient(RP2) - sage: RP5_2.subcomplex() + sage: RP5_2 = RP5.quotient(RP2) # optional - sage.graphs + sage: RP5_2.subcomplex() # optional - sage.graphs Simplicial set with 3 non-degenerate simplices sage: B = simplicial_sets.ClassifyingSpace(groups.misc.MultiplicativeAbelian([2])) sage: K = B.n_skeleton(3) - sage: Q = B.quotient(K) - sage: Q.subcomplex() + sage: Q = B.quotient(K) # optional - sage.graphs + sage: Q.subcomplex() # optional - sage.graphs Simplicial set with 4 non-degenerate simplices """ return self._maps[0].domain() @@ -1766,10 +1766,10 @@ def n_skeleton(self, n): sage: B = simplicial_sets.ClassifyingSpace(groups.misc.MultiplicativeAbelian([2])) sage: K = B.n_skeleton(3) - sage: Q = B.quotient(K) - sage: Q.n_skeleton(6) + sage: Q = B.quotient(K) # optional - sage.graphs + sage: Q.n_skeleton(6) # optional - sage.graphs Quotient: (Simplicial set with 7 non-degenerate simplices/Simplicial set with 4 non-degenerate simplices) - sage: Q.n_skeleton(6).homology() + sage: Q.n_skeleton(6).homology() # optional - sage.graphs {0: 0, 1: 0, 2: 0, 3: 0, 4: Z, 5: C2, 6: 0} """ if self.is_finite(): @@ -1797,7 +1797,7 @@ def _repr_(self): EXAMPLES:: sage: T = simplicial_sets.Torus() - sage: T.quotient(T.n_skeleton(1)) + sage: T.quotient(T.n_skeleton(1)) # optional - sage.graphs Quotient: (Torus/Simplicial set with 4 non-degenerate simplices) """ return 'Quotient: ({}/{})'.format(self.ambient(), self.subcomplex()) @@ -1811,7 +1811,7 @@ def _latex_(self): sage: RPoo = simplicial_sets.RealProjectiveSpace(Infinity) sage: RP3 = RPoo.n_skeleton(3) sage: RP3.rename_latex('RP^{3}') - sage: latex(RPoo.quotient(RP3)) + sage: latex(RPoo.quotient(RP3)) # optional - sage.graphs RP^{\infty} / RP^{3} """ return '{} / {}'.format(latex(self.ambient()), latex(self.subcomplex())) @@ -1835,10 +1835,10 @@ def __init__(self, inclusion, vertex_name='*'): sage: RP5 = simplicial_sets.RealProjectiveSpace(5) sage: RP2 = RP5.n_skeleton(2) - sage: RP5_2 = RP5.quotient(RP2) - sage: RP5_2 + sage: RP5_2 = RP5.quotient(RP2) # optional - sage.graphs + sage: RP5_2 # optional - sage.graphs Quotient: (RP^5/Simplicial set with 3 non-degenerate simplices) - sage: RP5_2.quotient_map() + sage: RP5_2.quotient_map() # optional - sage.graphs Simplicial set morphism: From: RP^5 To: Quotient: (RP^5/Simplicial set with 3 non-degenerate simplices) @@ -1861,16 +1861,16 @@ def quotient_map(self): EXAMPLES:: sage: K = simplicial_sets.Simplex(1) - sage: S1 = K.quotient(K.n_skeleton(0)) - sage: q = S1.quotient_map() - sage: q + sage: S1 = K.quotient(K.n_skeleton(0)) # optional - sage.graphs + sage: q = S1.quotient_map() # optional - sage.graphs + sage: q # optional - sage.graphs Simplicial set morphism: From: 1-simplex To: Quotient: (1-simplex/Simplicial set with 2 non-degenerate simplices) Defn: [(0,), (1,), (0, 1)] --> [*, *, (0, 1)] - sage: q.domain() == K + sage: q.domain() == K # optional - sage.graphs True - sage: q.codomain() == S1 + sage: q.codomain() == S1 # optional - sage.graphs True """ return self.structure_map(0) @@ -1885,7 +1885,7 @@ def __classcall__(cls, factors=None): sage: from sage.topology.simplicial_set_constructions import SmashProductOfSimplicialSets_finite as Smash sage: S2 = simplicial_sets.Sphere(2) - sage: Smash([S2, S2]) == Smash((S2, S2)) + sage: Smash([S2, S2]) == Smash((S2, S2)) # optional - sage.graphs True """ if factors: @@ -1913,7 +1913,7 @@ def __init__(self, factors=None): sage: T = simplicial_sets.Torus() sage: S2 = simplicial_sets.Sphere(2) - sage: T.smash_product(S2).homology() == T.suspension(2).homology() + sage: T.smash_product(S2).homology() == T.suspension(2).homology() # optional - sage.graphs True """ if any(not space.is_pointed() for space in factors): @@ -1931,7 +1931,7 @@ def _repr_(self): sage: RP4 = simplicial_sets.RealProjectiveSpace(4) sage: S1 = simplicial_sets.Sphere(1) - sage: S1.smash_product(RP4, S1) + sage: S1.smash_product(RP4, S1) # optional - sage.graphs Smash product: (S^1 ^ RP^4 ^ S^1) """ s = 'Smash product: (' @@ -1947,7 +1947,7 @@ def _latex_(self): sage: RP4 = simplicial_sets.RealProjectiveSpace(4) sage: S1 = simplicial_sets.Sphere(1) - sage: latex(S1.smash_product(RP4, S1)) + sage: latex(S1.smash_product(RP4, S1)) # optional - sage.graphs S^{1} \wedge RP^{4} \wedge S^{1} """ return ' \\wedge '.join(latex(X) for X in self._factors) @@ -1961,7 +1961,7 @@ def __classcall__(cls, factors=None): sage: from sage.topology.simplicial_set_constructions import WedgeOfSimplicialSets sage: S2 = simplicial_sets.Sphere(2) - sage: WedgeOfSimplicialSets([S2, S2]) == WedgeOfSimplicialSets((S2, S2)) + sage: WedgeOfSimplicialSets([S2, S2]) == WedgeOfSimplicialSets((S2, S2)) # optional - sage.graphs True """ if factors: @@ -1991,26 +1991,26 @@ def __init__(self, factors=None): sage: CP2 = simplicial_sets.ComplexProjectiveSpace(2) sage: K = simplicial_sets.KleinBottle() - sage: W = CP2.wedge(K) - sage: W.homology() + sage: W = CP2.wedge(K) # optional - sage.graphs + sage: W.homology() # optional - sage.graphs {0: 0, 1: Z x C2, 2: Z, 3: 0, 4: Z} - sage: W.inclusion_map(1) + sage: W.inclusion_map(1) # optional - sage.graphs Simplicial set morphism: From: Klein bottle To: Wedge: (CP^2 v Klein bottle) Defn: [Delta_{0,0}, Delta_{1,0}, Delta_{1,1}, Delta_{1,2}, Delta_{2,0}, Delta_{2,1}] --> [*, Delta_{1,0}, Delta_{1,1}, Delta_{1,2}, Delta_{2,0}, Delta_{2,1}] - sage: W.projection_map(0).domain() + sage: W.projection_map(0).domain() # optional - sage.graphs Wedge: (CP^2 v Klein bottle) - sage: W.projection_map(0).codomain() # copy of CP^2 + sage: W.projection_map(0).codomain() # copy of CP^2 # optional - sage.graphs Quotient: (Wedge: (CP^2 v Klein bottle)/Simplicial set with 6 non-degenerate simplices) - sage: W.projection_map(0).codomain().homology() + sage: W.projection_map(0).codomain().homology() # optional - sage.graphs {0: 0, 1: 0, 2: Z, 3: 0, 4: Z} An error occurs if any of the factors is not pointed:: - sage: CP2.wedge(simplicial_sets.Simplex(1)) + sage: CP2.wedge(simplicial_sets.Simplex(1)) # optional - sage.graphs Traceback (most recent call last): ... ValueError: the simplicial sets must be pointed @@ -2036,7 +2036,7 @@ def _repr_(self): EXAMPLES:: sage: K = simplicial_sets.KleinBottle() - sage: K.wedge(K, K) + sage: K.wedge(K, K) # optional - sage.graphs Wedge: (Klein bottle v Klein bottle v Klein bottle) """ s = 'Wedge: (' @@ -2078,7 +2078,7 @@ def __init__(self, factors=None): sage: from sage.topology.simplicial_set_constructions import WedgeOfSimplicialSets_finite sage: K = simplicial_sets.Simplex(3) - sage: WedgeOfSimplicialSets_finite((K,K)) + sage: WedgeOfSimplicialSets_finite((K,K)) # optional - sage.graphs Traceback (most recent call last): ... ValueError: the simplicial sets must be pointed @@ -2102,15 +2102,15 @@ def inclusion_map(self, i): sage: S1 = simplicial_sets.Sphere(1) sage: S2 = simplicial_sets.Sphere(2) - sage: W = S1.wedge(S2, S1) - sage: W.inclusion_map(1) + sage: W = S1.wedge(S2, S1) # optional - sage.graphs + sage: W.inclusion_map(1) # optional - sage.graphs Simplicial set morphism: From: S^2 To: Wedge: (S^1 v S^2 v S^1) Defn: [v_0, sigma_2] --> [*, sigma_2] - sage: W.inclusion_map(0).domain() + sage: W.inclusion_map(0).domain() # optional - sage.graphs S^1 - sage: W.inclusion_map(2).domain() + sage: W.inclusion_map(2).domain() # optional - sage.graphs S^1 """ return self.structure_map(i) diff --git a/src/sage/topology/simplicial_set_examples.py b/src/sage/topology/simplicial_set_examples.py index 30bfa0fbaab..137289e39d8 100644 --- a/src/sage/topology/simplicial_set_examples.py +++ b/src/sage/topology/simplicial_set_examples.py @@ -31,7 +31,6 @@ import re import os -from pyparsing import OneOrMore, nestedExpr from sage.env import SAGE_ENV from sage.misc.cachefunc import cached_method, cached_function @@ -346,18 +345,18 @@ def RealProjectiveSpace(n): EXAMPLES:: - sage: simplicial_sets.RealProjectiveSpace(7) + sage: simplicial_sets.RealProjectiveSpace(7) # optional - sage.groups RP^7 - sage: RP5 = simplicial_sets.RealProjectiveSpace(5) - sage: RP5.homology() + sage: RP5 = simplicial_sets.RealProjectiveSpace(5) # optional - sage.groups + sage: RP5.homology() # optional - sage.groups {0: 0, 1: C2, 2: 0, 3: C2, 4: 0, 5: Z} - sage: RP5 + sage: RP5 # optional - sage.groups RP^5 - sage: latex(RP5) + sage: latex(RP5) # optional - sage.groups RP^{5} - sage: BC2 = simplicial_sets.RealProjectiveSpace(Infinity) - sage: latex(BC2) + sage: BC2 = simplicial_sets.RealProjectiveSpace(Infinity) # optional - sage.groups + sage: latex(BC2) # optional - sage.groups RP^{\infty} """ if n == Infinity: @@ -536,23 +535,23 @@ def ComplexProjectiveSpace(n): sage: simplicial_sets.ComplexProjectiveSpace(2).homology(reduced=False) {0: Z, 1: 0, 2: Z, 3: 0, 4: Z} - sage: CP3 = simplicial_sets.ComplexProjectiveSpace(3) - sage: CP3 + sage: CP3 = simplicial_sets.ComplexProjectiveSpace(3) # optional - pyparsing + sage: CP3 # optional - pyparsing CP^3 - sage: latex(CP3) + sage: latex(CP3) # optional - pyparsing CP^{3} - sage: CP3.f_vector() + sage: CP3.f_vector() # optional - pyparsing [1, 0, 3, 10, 25, 30, 15] - sage: K = CP3.suspension() # long time (1 second) - sage: R = K.cohomology_ring(GF(2)) # long time - sage: R.gens() # long time + sage: K = CP3.suspension() # long time (1 second) # optional - pyparsing + sage: R = K.cohomology_ring(GF(2)) # long time # optional - pyparsing + sage: R.gens() # long time # optional - pyparsing (h^{0,0}, h^{3,0}, h^{5,0}, h^{7,0}) - sage: x = R.gens()[1] # long time - sage: x.Sq(2) # long time + sage: x = R.gens()[1] # long time # optional - pyparsing + sage: x.Sq(2) # long time # optional - pyparsing h^{5,0} - sage: simplicial_sets.ComplexProjectiveSpace(4).f_vector() + sage: simplicial_sets.ComplexProjectiveSpace(4).f_vector() # optional - pyparsing [1, 0, 4, 22, 97, 255, 390, 315, 105] sage: simplicial_sets.ComplexProjectiveSpace(5) @@ -646,10 +645,12 @@ def simplicial_data_from_kenzo_output(filename): sage: from sage.topology.simplicial_set_examples import simplicial_data_from_kenzo_output sage: from sage.topology.simplicial_set import SimplicialSet sage: sphere = os.path.join(SAGE_ENV['SAGE_EXTCODE'], 'kenzo', 'S4.txt') - sage: S4 = SimplicialSet(simplicial_data_from_kenzo_output(sphere)) - sage: S4.homology(reduced=False) + sage: S4 = SimplicialSet(simplicial_data_from_kenzo_output(sphere)) # optional - pyparsing + sage: S4.homology(reduced=False) # optional - pyparsing {0: Z, 1: 0, 2: 0, 3: 0, 4: Z} """ + from pyparsing import OneOrMore, nestedExpr + with open(filename, 'r') as f: data = f.read() dim = 0 diff --git a/src/sage/typeset/ascii_art.py b/src/sage/typeset/ascii_art.py index fe2fd4c419b..73ab45f9b90 100644 --- a/src/sage/typeset/ascii_art.py +++ b/src/sage/typeset/ascii_art.py @@ -15,18 +15,18 @@ EXAMPLES:: - sage: n = var('n') - sage: integrate(n^2/x,x) + sage: n = var('n') # optional - sage.symbolic + sage: integrate(n^2/x, x) # optional - sage.symbolic n^2*log(x) - sage: ascii_art(integrate(n^2/x,x)) + sage: ascii_art(integrate(n^2/x, x)) # optional - sage.symbolic 2 n *log(x) - sage: ascii_art(integrate(n^2/(pi*x),x)) + sage: ascii_art(integrate(n^2/(pi*x), x)) # optional - sage.symbolic 2 n *log(x) --------- pi - sage: ascii_art(list(Partitions(6))) + sage: ascii_art(list(Partitions(6))) # optional - sage.combinat [ * ] [ ** * ] [ *** ** * * ] @@ -40,18 +40,18 @@ sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.run_cell('%display ascii_art') - sage: shell.run_cell("i = var('i')") - sage: shell.run_cell('sum(factorial(i)*x^i, i, 0, 10)') + sage: shell.run_cell("i = var('i')") # optional - sage.symbolic + sage: shell.run_cell('sum(factorial(i)*x^i, i, 0, 10)') # optional - sage.symbolic 10 9 8 7 6 5 4 3 3628800*x + 362880*x + 40320*x + 5040*x + 720*x + 120*x + 24*x + 6*x 2 + 2*x + x + 1 - sage: shell.run_cell('3/(7*x)') + sage: shell.run_cell('3/(7*x)') # optional - sage.symbolic 3 --- 7*x - sage: shell.run_cell('list(Compositions(5))') + sage: shell.run_cell('list(Compositions(5))') # optional - sage.combinat [ * [ * ** * * * [ * * ** *** * ** * * ** * * @@ -173,8 +173,8 @@ class AsciiArt(CharacterArt): EXAMPLES:: - sage: i = var('i') - sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) + sage: i = var('i') # optional - sage.symbolic + sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) # optional - sage.symbolic pi*x e """ @@ -216,9 +216,9 @@ def ascii_art(*obj, **kwds): EXAMPLES:: - sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) + sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) # optional - sage.symbolic ... - sage: result + sage: result # optional - sage.symbolic / | | 2 @@ -255,7 +255,7 @@ def ascii_art(*obj, **kwds): an ascii art separator:: sage: sep_line = ascii_art('\n'.join(' | ' for _ in range(6)), baseline=6) - sage: ascii_art(*Partitions(6), separator=sep_line, sep_baseline=0) + sage: ascii_art(*Partitions(6), separator=sep_line, sep_baseline=0) # optional - sage.combinat | | | | | | | | | | * | | | | | | | | | ** | * | | | | | | *** | | ** | * | * @@ -265,14 +265,14 @@ def ascii_art(*obj, **kwds): TESTS:: - sage: n = var('n') - sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) + sage: n = var('n') # optional - sage.symbolic + sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # optional - sage.symbolic / _________ \ -\2*x + \/ 1 - 4*x - 1/ ------------------------- _________ 2*x*\/ 1 - 4*x - sage: ascii_art(list(DyckWords(3))) + sage: ascii_art(list(DyckWords(3))) # optional - sage.combinat [ /\ ] [ /\ /\ /\/\ / \ ] [ /\/\/\, /\/ \, / \/\, / \, / \ ] diff --git a/src/sage/typeset/character_art.py b/src/sage/typeset/character_art.py index dd1107db48d..1ba93ceea6b 100644 --- a/src/sage/typeset/character_art.py +++ b/src/sage/typeset/character_art.py @@ -58,8 +58,8 @@ def __init__(self, lines=[], breakpoints=[], baseline=None): EXAMPLES:: - sage: i = var('i') - sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) + sage: i = var('i') # optional - sage.symbolic + sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) # optional - sage.symbolic pi*x e diff --git a/src/sage/typeset/character_art_factory.py b/src/sage/typeset/character_art_factory.py index d83aa4da4f5..dc2354e58c8 100644 --- a/src/sage/typeset/character_art_factory.py +++ b/src/sage/typeset/character_art_factory.py @@ -84,9 +84,9 @@ def build(self, obj, baseline=None): EXAMPLES:: - sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) + sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) # optional - sage.symbolic ... - sage: result + sage: result # optional - sage.symbolic / | | 2 @@ -99,14 +99,14 @@ def build(self, obj, baseline=None): TESTS:: - sage: n = var('n') - sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) + sage: n = var('n') # optional - sage.symbolic + sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # optional - sage.symbolic / _________ \ -\2*x + \/ 1 - 4*x - 1/ ------------------------- _________ 2*x*\/ 1 - 4*x - sage: ascii_art(list(DyckWords(3))) + sage: ascii_art(list(DyckWords(3))) # optional - sage.combinat [ /\ ] [ /\ /\ /\/\ / \ ] [ /\/\/\, /\/ \, / \/\, / \, / \ ] @@ -161,10 +161,10 @@ def build_from_magic_method(self, obj, baseline=None): EXAMPLES:: sage: from sage.typeset.ascii_art import _ascii_art_factory as factory - sage: out = factory.build_from_magic_method(identity_matrix(2)); out + sage: out = factory.build_from_magic_method(identity_matrix(2)); out # optional - sage.modules [1 0] [0 1] - sage: type(out) + sage: type(out) # optional - sage.modules """ magic_method = getattr(obj, self.magic_method_name) @@ -243,12 +243,12 @@ def build_container(self, content, left_border, right_border, baseline=0): TESTS:: - sage: l = ascii_art(list(DyckWords(3))) # indirect doctest - sage: l + sage: l = ascii_art(list(DyckWords(3))) # indirect doctest # optional - sage.combinat + sage: l # optional - sage.combinat [ /\ ] [ /\ /\ /\/\ / \ ] [ /\/\/\, /\/ \, / \/\, / \, / \ ] - sage: l._breakpoints + sage: l._breakpoints # optional - sage.combinat [9, 17, 25, 33] Check that zero-height strings are handled (:trac:`28527`):: @@ -289,7 +289,7 @@ def build_set(self, s, baseline=0): iteration over sets is non-deterministic so too is the results of this test:: - sage: ascii_art(set(DyckWords(3))) # indirect doctest random + sage: ascii_art(set(DyckWords(3))) # indirect doctest random # optional - sage.combinat { /\ } { /\ /\/\ /\ / \ } { / \/\, / \, /\/\/\, /\/ \, / \ } @@ -298,7 +298,7 @@ def build_set(self, s, baseline=0): a set, but still obtain the same output formatting:: sage: from sage.typeset.ascii_art import _ascii_art_factory as factory - sage: factory.build_set(sorted(set(DyckWords(3)))) + sage: factory.build_set(sorted(set(DyckWords(3)))) # optional - sage.combinat { /\ } { /\ /\ /\/\ / \ } { /\/\/\, /\/ \, / \/\, / \, / \ } @@ -316,13 +316,13 @@ def build_dict(self, d, baseline=0): TESTS:: sage: from collections import OrderedDict - sage: d = OrderedDict(enumerate(DyckWords(3))) - sage: art = ascii_art(d) # indirect doctest - sage: art + sage: d = OrderedDict(enumerate(DyckWords(3))) # optional - sage.combinat + sage: art = ascii_art(d) # indirect doctest # optional - sage.combinat + sage: art # optional - sage.combinat { /\ } { /\ /\ /\/\ / \ } { 0:/\/\/\, 1:/\/ \, 2:/ \/\, 3:/ \, 4:/ \ } - sage: art._breakpoints + sage: art._breakpoints # optional - sage.combinat [11, 21, 31, 41] Check that :trac:`29447` is fixed:: @@ -357,18 +357,18 @@ def build_list(self, l, baseline=0): TESTS:: - sage: l = ascii_art(list(DyckWords(3))) # indirect doctest - sage: l + sage: l = ascii_art(list(DyckWords(3))) # indirect doctest # optional - sage.combinat + sage: l # optional - sage.combinat [ /\ ] [ /\ /\ /\/\ / \ ] [ /\/\/\, /\/ \, / \/\, / \, / \ ] - sage: l._breakpoints + sage: l._breakpoints # optional - sage.combinat [9, 17, 25, 33] The breakpoints of the object are used as breakpoints:: - sage: l = ascii_art([DyckWords(2).list(), DyckWords(2).list()]) - sage: l._breakpoints + sage: l = ascii_art([DyckWords(2).list(), DyckWords(2).list()]) # optional - sage.combinat + sage: l._breakpoints # optional - sage.combinat [(2, [7]), 17, (18, [7])] The parentheses only stretch as high as the content (:trac:`28527`):: @@ -399,7 +399,7 @@ def build_tuple(self, t, baseline=0): TESTS:: - sage: ascii_art(tuple(DyckWords(3))) # indirect doctest + sage: ascii_art(tuple(DyckWords(3))) # indirect doctest # optional - sage.combinat ( /\ ) ( /\ /\ /\/\ / \ ) ( /\/\/\, /\/ \, / \/\, / \, / \ ) @@ -440,8 +440,8 @@ def concatenate(self, iterable, separator, empty=None, baseline=0, EXAMPLES:: - sage: i2 = identity_matrix(2) - sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x)) + sage: i2 = identity_matrix(2) # optional - sage.modules + sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x)) # optional - sage.modules sage.symbolic 1 1 [1 0]-[1 0]-[1 0] [0 1]x[0 1]x[0 1] diff --git a/src/sage/typeset/unicode_art.py b/src/sage/typeset/unicode_art.py index caed3475afe..0b4177e6a60 100644 --- a/src/sage/typeset/unicode_art.py +++ b/src/sage/typeset/unicode_art.py @@ -44,8 +44,8 @@ class UnicodeArt(CharacterArt): EXAMPLES:: - sage: i = var('i') - sage: unicode_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) + sage: i = var('i') # optional - sage.symbolic + sage: unicode_art(sum(pi^i/factorial(i)*x^i, i, 0, oo)) # optional - sage.symbolic π⋅x ℯ """ @@ -88,9 +88,9 @@ def unicode_art(*obj, **kwds): EXAMPLES:: - sage: result = unicode_art(integral(exp(sqrt(x))/(x+pi), x)) + sage: result = unicode_art(integral(exp(sqrt(x))/(x+pi), x)) # optional - sage.symbolic ... - sage: result + sage: result # optional - sage.symbolic ⌠ ⎮ √x ⎮ ℯ @@ -107,7 +107,7 @@ def unicode_art(*obj, **kwds): an unicode art separator:: sage: sep_line = unicode_art('\n'.join(' ⎟ ' for _ in range(5)), baseline=5) - sage: unicode_art(*AlternatingSignMatrices(3), + sage: unicode_art(*AlternatingSignMatrices(3), # optional - sage.combinat ....: separator=sep_line, sep_baseline=1) ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎛1 0 0⎞ ⎟ ⎛0 1 0⎞ ⎟ ⎛1 0 0⎞ ⎟ ⎛ 0 1 0⎞ ⎟ ⎛0 0 1⎞ ⎟ ⎛0 1 0⎞ ⎟ ⎛0 0 1⎞ @@ -117,14 +117,14 @@ def unicode_art(*obj, **kwds): TESTS:: - sage: n = var('n') - sage: unicode_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) + sage: n = var('n') # optional - sage.symbolic + sage: unicode_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # optional - sage.symbolic ⎛ _________ ⎞ -⎝2⋅x + ╲╱ 1 - 4⋅x - 1⎠ ───────────────────────── _________ 2⋅x⋅╲╱ 1 - 4⋅x - sage: unicode_art(list(DyckWords(3))) + sage: unicode_art(list(DyckWords(3))) # optional - sage.combinat ⎡ ╱╲ ⎤ ⎢ ╱╲ ╱╲ ╱╲╱╲ ╱ ╲ ⎥ ⎣ ╱╲╱╲╱╲, ╱╲╱ ╲, ╱ ╲╱╲, ╱ ╲, ╱ ╲ ⎦