diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 6d2304fb630..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) # optional - sage.rings.padics + sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics True - sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics + 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__() # optional - sage.rings.padics + 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) # optional - sage.rings.padics + sage: isinstance(Zp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics False - sage: isinstance(Qp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics + 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__() # optional - sage.rings.padics + 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/factorint.pyx b/src/sage/rings/factorint.pyx index dd51f3db3d7..2d68e3080ca 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -49,23 +49,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 @@ -129,24 +129,24 @@ cpdef factor_aurifeuillian(n, check=True): EXAMPLES:: sage: from sage.rings.factorint import factor_aurifeuillian as fa - sage: fa(2^6+1) # optional - sage.libs.pari + sage: fa(2^6 + 1) # optional - sage.libs.pari [5, 13] - sage: fa(2^58+1) # optional - sage.libs.pari + sage: fa(2^58 + 1) # optional - sage.libs.pari [536838145, 536903681] - sage: fa(3^3+1) # optional - sage.libs.pari + sage: fa(3^3 + 1) # optional - sage.libs.pari [4, 1, 7] - sage: fa(5^5-1) # optional - sage.libs.pari + sage: fa(5^5 - 1) # optional - sage.libs.pari [4, 11, 71] - sage: prod(_) == 5^5-1 # optional - sage.libs.pari + sage: prod(_) == 5^5 - 1 # optional - sage.libs.pari True - sage: fa(2^4+1) # optional - sage.libs.pari + sage: fa(2^4 + 1) # optional - sage.libs.pari [17] - sage: fa((6^2*3)^3+1) # optional - sage.libs.pari + 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]: # optional - sage.libs.pari + 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 @@ -222,7 +222,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 """ @@ -317,16 +317,16 @@ def factor_using_pari(n, int_=False, debug_level=0, proof=None): EXAMPLES:: - sage: factor(-2**72 + 3, algorithm='pari') # indirect doctest # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: pari.get_debug_level() # optional - sage.libs.pari 0 """ from sage.libs.pari.all import pari diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index ac6d55e4ef1..3b3ad232224 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari +# 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 5a3b65906a2..49abe86126f 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari +# 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 90e5ab260c3..1690b3cf8dd 100644 --- a/src/sage/rings/finite_rings/finite_field_constructor.py +++ b/src/sage/rings/finite_rings/finite_field_constructor.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari +# 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 95cb5df1faf..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)) # optional - sage.libs.pari sage.symbolic + 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)) # optional - sage.symbolic + 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()) # optional - sage.libs.pari + sage: factor(a.order()) # optional - sage.libs.pari 2^3 * 191^3 * 236607587^3 sage: b = a(2*191) sage: b.is_nilpotent() @@ -605,18 +605,18 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: K = GF(7) # optional - sage.libs.pari - sage: sage_input(K(5), verify=True) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: a = b^17 # optional - sage.libs.pari - sage: a.log(b) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: a.log() # optional - sage.libs.pari 51 A bigger example:: - sage: FF = FiniteField(2^32 + 61) # optional - sage.libs.pari - sage: c = FF(4294967356) # optional - sage.libs.pari - sage: x = FF(2) # optional - sage.libs.pari - sage: a = c.log(x) # optional - sage.libs.pari - sage: a # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: a.log(b) # optional - sage.libs.pari + 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,24 +694,24 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`9205` is fixed:: - sage: Mod(5, 9).log(Mod(2, 9)) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: pari(b) # optional - sage.libs.pari b - sage: GF(7)(5).log() # optional - sage.libs.pari + sage: GF(7)(5).log() # optional - sage.rings.finite_rings 5 - sage: pari(b) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: (x^e).log(x) == e # optional - sage.libs.pari True Examples like this took extremely long before :trac:`32375`:: @@ -723,22 +723,22 @@ cdef class IntegerMod_abstract(FiniteRingElement): No local solutions:: - sage: Mod(1111, 1234567).log(1111**3) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: R(1).factor() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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]]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: a = k.gen() # optional - sage.libs.pari - sage: a.charpoly('x') # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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') # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: a = k.gen(); a # optional - sage.libs.pari + sage: k = GF(7) # optional - sage.rings.finite_rings + sage: a = k.gen(); a # optional - sage.rings.finite_rings 1 - sage: a.polynomial() # optional - sage.libs.pari + sage: a.polynomial() # optional - sage.rings.finite_rings 1 - sage: type(a.polynomial()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: a = k(389) # optional - sage.libs.pari - sage: a.norm() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: a = k(389) # optional - sage.libs.pari - sage: a.trace() # optional - sage.libs.pari + 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: @@ -1182,11 +1182,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): :: - sage: t = FiniteField(next_prime(2^100))(4) # optional - sage.libs.pari - sage: t.sqrt(extend=False, all=True) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: t.sqrt(extend=False, all=True) # optional - sage.libs.pari + 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,13 +1378,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: K = GF(31) # optional - sage.libs.pari - sage: a = K(22) # optional - sage.libs.pari - sage: K(22).nth_root(7) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: K(25).nth_root(5) # optional - sage.rings.finite_rings 5 - sage: K(23).nth_root(3) # optional - sage.libs.pari + sage: K(23).nth_root(3) # optional - sage.rings.finite_rings 29 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, @@ -1410,7 +1410,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): TESTS:: - sage: for p in [1009,2003,10007,100003]: # optional - sage.libs.pari + 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 @@ -1420,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): # optional - sage.libs.pari + sage: for t in range(200): # optional - sage.libs.pari ....: n = randint(1,2^63) ....: K = Integers(n) ....: b = K.random_element() @@ -1440,13 +1440,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`32084` is fixed:: - sage: mod(24, 25).nth_root(50)^50 # optional - sage.rings.padics + 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: @@ -1627,11 +1627,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): This method is also inherited by prime finite fields elements:: - sage: k = GF(97) # optional - sage.libs.pari - sage: a = k(RationalField()('2/3')) # optional - sage.libs.pari - sage: a # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: a.rational_reconstruction() # optional - sage.rings.finite_rings 2/3 """ return self.lift().rational_reconstruction(self.modulus()) @@ -1646,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() @@ -1668,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: @@ -1843,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:: @@ -1852,7 +1852,7 @@ 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)`` :: @@ -1907,7 +1907,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(7)(3) // 5 # optional - sage.libs.pari + sage: GF(7)(3) // 5 # optional - sage.rings.finite_rings 2 """ return self._mul_(~right) @@ -1934,9 +1934,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: F. = GF(13) # optional - sage.libs.pari - sage: V = F.vector_space(map=False) # optional - sage.libs.pari - sage: V(a) # optional - sage.libs.pari + 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]) @@ -1980,7 +1980,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): EXAMPLES:: sage: p = next_prime(2^32) # optional - sage.libs.pari - sage: GF(p)(int(p + 1)) # optional - sage.libs.pari + sage: GF(p)(int(p + 1)) # optional - sage.rings.finite_rings 1 """ mpz_set_si(self.value, value) @@ -2252,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) # optional - sage.libs.pari - sage: R = Integers(p) # optional - sage.libs.pari - sage: R(9876)^(p-1) # optional - sage.libs.pari + 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 @@ -2267,14 +2267,14 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): We define ``0^0`` to be unity, :trac:`13894`:: - 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 + 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)) # optional - sage.libs.pari + 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 @@ -2910,8 +2910,8 @@ cdef class IntegerMod_int(IntegerMod_abstract): 86 sage: mod(7, 18).sqrt() 5 - sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari - sage: a*a # optional - sage.libs.pari + 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): @@ -2951,7 +2951,7 @@ 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) # optional - sage.libs.pari + sage: GF(107)(0).sqrt(all=True) # optional - sage.rings.finite_rings [0] :: @@ -2983,7 +2983,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): Check for :trac:`30797`:: - sage: GF(103)(-1).sqrt(extend=False, all=True) # optional - sage.libs.pari + sage: GF(103)(-1).sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [] """ cdef int_fast32_t i, n = self.__modulus.int32 @@ -3550,9 +3550,9 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: R = Integers(10) sage: R(2)^10 4 - 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 + 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 @@ -3578,14 +3578,14 @@ cdef class IntegerMod_int64(IntegerMod_abstract): We define ``0^0`` to be unity, :trac:`13894`:: - 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 + 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)) # optional - sage.libs.pari + 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 @@ -3906,10 +3906,10 @@ 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) # optional - sage.libs.pari - sage: b^2 == a # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: mod(100, 5^7).sqrt()^2 # optional - sage.libs.pari 100 TESTS: @@ -3917,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) # optional - sage.libs.pari + sage: hex(y.sqrt()^2 - y) # optional - sage.libs.pari '0x0' Testing with random squares in random rings:: - 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 + 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(): @@ -4106,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) # optional - sage.combinat + 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 @@ -4174,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) # optional - sage.combinat + 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 @@ -4320,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] @@ -4390,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] @@ -4452,7 +4460,7 @@ cdef class IntegerMod_to_Integer(Map): EXAMPLES:: - sage: ZZ.convert_map_from(GF(2)) # optional - sage.libs.pari + sage: ZZ.convert_map_from(GF(2)) # optional - sage.rings.finite_rings Lifting map: From: Finite Field of size 2 To: Integer Ring @@ -4464,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() # optional - sage.libs.pari + 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 @@ -4496,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 41e89b5b9fa..71f392a13cd 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -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) # optional - sage.libs.pari + sage: _unit_gens_primepowercase(17, 1) # optional - sage.libs.pari [(3, 16)] - sage: _unit_gens_primepowercase(3, 3) # optional - sage.libs.pari + 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() # optional - sage.groups - sage: a = gens[0] # optional - sage.groups - sage: a # optional - sage.groups + 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() # optional - sage.groups + sage: a.is_square() # optional - sage.groups False - sage: def pow(i): return a**i # optional - sage.groups - sage: [pow(i) for i in range(16)] # optional - sage.groups + 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() # optional - sage.groups - sage: gens # optional - sage.groups + sage: gens = Z16.unit_gens() # optional - sage.groups + sage: gens # optional - sage.groups (15, 5) - 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 + 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)] # optional - sage.groups + 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)] # optional - sage.groups + 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() # optional - sage.groups + sage: a.multiplicative_order() # optional - sage.groups 2 - sage: b.multiplicative_order() # optional - sage.groups + sage: b.multiplicative_order() # optional - sage.groups 4 sage: TestSuite(Z16).run() @@ -639,22 +639,22 @@ def multiplicative_subgroups(self): EXAMPLES:: - sage: Integers(5).multiplicative_subgroups() # optional - sage.groups + sage: Integers(5).multiplicative_subgroups() # optional - sage.groups ((2,), (4,), ()) - sage: Integers(15).multiplicative_subgroups() # optional - sage.groups + sage: Integers(15).multiplicative_subgroups() # optional - sage.groups ((11, 7), (11, 4), (2,), (11,), (14,), (7,), (4,), ()) - sage: Integers(2).multiplicative_subgroups() # optional - sage.groups + sage: Integers(2).multiplicative_subgroups() # optional - sage.groups ((),) - sage: len(Integers(341).multiplicative_subgroups()) # optional - sage.groups + sage: len(Integers(341).multiplicative_subgroups()) # optional - sage.groups 80 TESTS:: - sage: IntegerModRing(1).multiplicative_subgroups() # optional - sage.groups + sage: IntegerModRing(1).multiplicative_subgroups() # optional - sage.groups ((),) - sage: IntegerModRing(2).multiplicative_subgroups() # optional - sage.groups + sage: IntegerModRing(2).multiplicative_subgroups() # optional - sage.groups ((),) - sage: IntegerModRing(3).multiplicative_subgroups() # optional - sage.groups + sage: IntegerModRing(3).multiplicative_subgroups() # optional - sage.groups ((2,), ()) """ return tuple(tuple(g.value() for g in H.gens()) @@ -668,7 +668,7 @@ def is_integral_domain(self, proof=None): sage: Integers(389).is_integral_domain() True - sage: Integers(389^2).is_integral_domain() # optional - sage.libs.pari + sage: Integers(389^2).is_integral_domain() # optional - sage.libs.pari False TESTS: @@ -689,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() # optional - sage.libs.pari + sage: Integers(389^2).is_unique_factorization_domain() # optional - sage.libs.pari False """ return self.is_field(proof) @@ -791,10 +791,10 @@ def field(self): sage: R = Integers(7); R Ring of integers modulo 7 - sage: R.field() # optional - sage.libs.pari + sage: R.field() # optional - sage.rings.finite_rings Finite Field of size 7 sage: R = Integers(9) - sage: R.field() # optional - sage.libs.pari + sage: R.field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: self must be a field @@ -828,8 +828,8 @@ def _pseudo_fraction_field(self): This should be very fast:: - 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 + 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 @@ -848,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() # optional - sage.libs.pari + sage: R.multiplicative_group_is_cyclic() # optional - sage.libs.pari True - sage: Integers(8).multiplicative_group_is_cyclic() # optional - sage.libs.pari + sage: Integers(8).multiplicative_group_is_cyclic() # optional - sage.libs.pari False - sage: Integers(4).multiplicative_group_is_cyclic() # optional - sage.libs.pari + sage: Integers(4).multiplicative_group_is_cyclic() # optional - sage.libs.pari True - sage: Integers(25*3).multiplicative_group_is_cyclic() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: Integers(162).multiplicative_group_is_cyclic() # optional - sage.libs.pari True """ n = self.order() @@ -886,24 +886,24 @@ def multiplicative_generator(self): sage: R = Integers(7); R Ring of integers modulo 7 - sage: R.multiplicative_generator() # optional - sage.libs.pari + sage: R.multiplicative_generator() # optional - sage.libs.pari 3 sage: R = Integers(9) - sage: R.multiplicative_generator() # optional - sage.libs.pari + sage: R.multiplicative_generator() # optional - sage.libs.pari 2 - sage: Integers(8).multiplicative_generator() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: Integers(4).multiplicative_generator() # optional - sage.libs.pari 3 - sage: Integers(25*3).multiplicative_generator() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: Integers(25*3).unit_gens() # optional - sage.libs.pari (26, 52) - sage: Integers(162).unit_gens() # optional - sage.libs.pari + sage: Integers(162).unit_gens() # optional - sage.libs.pari (83,) """ try: @@ -928,9 +928,9 @@ def quadratic_nonresidue(self): EXAMPLES:: sage: R = Integers(17) - sage: R.quadratic_nonresidue() # optional - sage.libs.pari + sage: R.quadratic_nonresidue() # optional - sage.libs.pari 3 - sage: R(3).is_square() # optional - sage.libs.pari + sage: R(3).is_square() # optional - sage.libs.pari False """ try: @@ -955,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() # optional - sage.libs.pari + sage: R.square_roots_of_one() # optional - sage.libs.pari (1, 511, 513, 1023) :: - sage: v = Integers(9*5).square_roots_of_one(); v # optional - sage.libs.pari + 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] # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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] # optional - sage.libs.pari + 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: @@ -1133,7 +1133,7 @@ def _pari_order(self): EXAMPLES:: - sage: Zmod(87)._pari_order() # optional - sage.libs.pari + sage: Zmod(87)._pari_order() # optional - sage.libs.pari 87 """ try: @@ -1296,7 +1296,7 @@ def _convert_map_from_(self, other): EXAMPLES:: - sage: Zmod(81).convert_map_from(Qp(3)) # optional - sage.rings.padics + 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 @@ -1366,12 +1366,12 @@ def unit_gens(self, **kwds): EXAMPLES:: sage: R = IntegerModRing(18) - sage: R.unit_gens() # optional - sage.groups + sage: R.unit_gens() # optional - sage.groups (11,) sage: R = IntegerModRing(17) - sage: R.unit_gens() # optional - sage.groups + sage: R.unit_gens() # optional - sage.groups (3,) - sage: IntegerModRing(next_prime(10^30)).unit_gens() # optional - sage.groups + sage: IntegerModRing(next_prime(10^30)).unit_gens() # optional - sage.groups (5,) The choice of generators is affected by the optional keyword @@ -1379,18 +1379,18 @@ def unit_gens(self, **kwds): See :meth:`unit_group` for details. :: sage: A = Zmod(55) - sage: A.unit_gens(algorithm='sage') # optional - sage.groups + sage: A.unit_gens(algorithm='sage') # optional - sage.groups (12, 46) - sage: A.unit_gens(algorithm='pari') # optional - sage.groups sage.libs.pari + sage: A.unit_gens(algorithm='pari') # optional - sage.groups sage.libs.pari (2, 21) TESTS:: - sage: IntegerModRing(2).unit_gens() # optional - sage.groups + sage: IntegerModRing(2).unit_gens() # optional - sage.groups () - sage: IntegerModRing(4).unit_gens() # optional - sage.groups + sage: IntegerModRing(4).unit_gens() # optional - sage.groups (3,) - sage: IntegerModRing(8).unit_gens() # optional - sage.groups + sage: IntegerModRing(8).unit_gens() # optional - sage.groups (7, 5) """ @@ -1401,10 +1401,10 @@ def unit_group_exponent(self): EXAMPLES:: sage: R = IntegerModRing(17) - sage: R.unit_group_exponent() # optional - sage.groups + sage: R.unit_group_exponent() # optional - sage.groups 16 sage: R = IntegerModRing(18) - sage: R.unit_group_exponent() # optional - sage.groups + sage: R.unit_group_exponent() # optional - sage.groups 6 """ return self.unit_group().exponent() @@ -1416,7 +1416,7 @@ def unit_group_order(self): EXAMPLES:: sage: R = Integers(500) - sage: R.unit_group_order() # optional - sage.groups + sage: R.unit_group_order() # optional - sage.groups 200 """ return self.unit_group().order() @@ -1455,52 +1455,52 @@ 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 # optional - sage.groups + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C4 - sage: G.gens_values() # optional - sage.groups + sage: G.gens_values() # optional - sage.groups (11, 7) - sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari + 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() # optional - sage.groups sage.libs.pari + 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 # optional - sage.groups + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C2 x C4 - sage: G.gens_values() # optional - sage.groups + sage: G.gens_values() # optional - sage.groups (31, 21, 17) - sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari + 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() # optional - sage.groups sage.libs.pari + sage: H.gens_values() # optional - sage.groups sage.libs.pari (17, 31, 21) sage: A = Zmod(192) - sage: G = A.unit_group(); G # optional - sage.groups + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C16 x C2 - sage: G.gens_values() # optional - sage.groups + sage: G.gens_values() # optional - sage.groups (127, 133, 65) - sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari + 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() # optional - sage.groups sage.libs.pari + 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() # optional - sage.groups + sage: A.unit_group() # optional - sage.groups Multiplicative Abelian group isomorphic to C10 x C28 - sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.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() # optional - sage.groups + 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 + 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 @@ -1509,17 +1509,17 @@ def unit_group(self, algorithm='sage'): We test the cases where the unit group is trivial:: sage: A = Zmod(1) - sage: A.unit_group() # optional - sage.groups + sage: A.unit_group() # optional - sage.groups Trivial Abelian group - sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Trivial Abelian group sage: A = Zmod(2) - sage: A.unit_group() # optional - sage.groups + sage: A.unit_group() # optional - sage.groups Trivial Abelian group - sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Trivial Abelian group - sage: Zmod(3).unit_group(algorithm='bogus') # optional - sage.groups + sage: Zmod(3).unit_group(algorithm='bogus') # optional - sage.groups Traceback (most recent call last): ... ValueError: unknown algorithm 'bogus' for computing the unit group diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index cb25cd9df92..71a4c9102eb 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -1234,19 +1234,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) # 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 + 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) # optional - sage.libs.pari - sage: 1/(x + 1) in L # indirect doctest # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: 1/(x + 2) in L # indirect doctest # optional - sage.libs.pari False """ codom = self.codomain() diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index a8a4a6f4a61..4e5dabe8b75 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -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) :: diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 5a39427261b..4e4a3e5c135 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -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) # optional - sage.libs.pari - sage: U = R.quotient_ring(J) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: S == U # optional - sage.libs.pari True """ if len(args) == 0: @@ -470,11 +470,11 @@ def base_ring(self): And `p`-adic numbers:: - sage: R = Zp(7, prec=10); R # optional - sage.rings.padics + sage: R = Zp(7, prec=10); R # optional - sage.rings.padics 7-adic Ring with capped relative precision 10 - sage: I = 7*R; I # optional - sage.rings.padics + 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() # optional - sage.rings.padics + 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,12 @@ 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') # optional - sage.libs.pari - sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S # optional - sage.libs.pari + 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 + 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 """ @@ -695,16 +698,16 @@ def is_maximal(self): sage: R = ZZ sage: I = R.ideal(7) - sage: I.is_maximal() # optional - sage.libs.pari + sage: I.is_maximal() # optional - sage.libs.pari True - sage: R.ideal(16).is_maximal() # optional - sage.libs.pari + sage: R.ideal(16).is_maximal() # optional - sage.libs.pari False sage: S = Integers(8) - sage: S.ideal(0).is_maximal() # optional - sage.libs.pari + sage: S.ideal(0).is_maximal() # optional - sage.libs.pari False - sage: S.ideal(2).is_maximal() # optional - sage.libs.pari + sage: S.ideal(2).is_maximal() # optional - sage.libs.pari True - sage: S.ideal(4).is_maximal() # optional - sage.libs.pari + sage: S.ideal(4).is_maximal() # optional - sage.libs.pari False """ from sage.rings.integer_ring import ZZ @@ -1158,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 ) @@ -1167,7 +1170,7 @@ 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) @@ -1571,18 +1574,18 @@ def is_prime(self): EXAMPLES:: - sage: ZZ.ideal(2).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(2).is_prime() # optional - sage.libs.pari True - sage: ZZ.ideal(-2).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(-2).is_prime() # optional - sage.libs.pari True - sage: ZZ.ideal(4).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(4).is_prime() # optional - sage.libs.pari False - sage: ZZ.ideal(0).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(0).is_prime() # optional - sage.libs.pari True sage: R. = QQ[] - sage: P = R.ideal(x^2 + 1); P # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: P.is_prime() # optional - sage.libs.pari True In fields, only the zero ideal is prime:: diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index b08f441f2aa..2a424880b55 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -288,7 +288,7 @@ def _maxima_init_(self): """ TESTS:: - sage: maxima(-oo) # optional - sage.symbolic + 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) # optional - sage.libs.pari + sage: pari(-oo) # optional - sage.libs.pari -oo - sage: pari(oo) # optional - sage.libs.pari + sage: pari(oo) # optional - sage.libs.pari +oo """ # For some reason, it seems problematic to import sage.libs.all.pari, diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index d94cd7c90cc..8a307b3988c 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -397,19 +397,19 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ[sqrt(2), sqrt(3)] # optional - sage.rings.number_field sage.symbolic + 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 # optional - sage.rings.number_field sage.symbolic + 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() # optional - sage.rings.number_field sage.symbolic + sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic False - sage: R = ZZ[(1 + sqrt(5))/2]; R # optional - sage.rings.number_field sage.symbolic + 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() # optional - sage.rings.number_field sage.symbolic + sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic True """ if x in self: @@ -981,40 +981,40 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: F = ZZ.residue_field(61); F # optional - sage.libs.pari + sage: F = ZZ.residue_field(61); F # optional - sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: pi(123/234) # optional - sage.libs.pari 6 - sage: pi(1/61) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: lift(F(12345/67890)) # optional - sage.libs.pari 33 - sage: (12345/67890) % 61 # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: ZZ.residue_field(96) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: 96 is not prime @@ -1165,7 +1165,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.completion(infinity, 53) Integer Ring - sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics + 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: @@ -1553,9 +1553,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: v = ZZ.valuation(3); v # optional - sage.rings.padics + sage: v = ZZ.valuation(3); v # optional - sage.rings.padics 3-adic valuation - sage: v(3) # optional - sage.rings.padics + sage: v(3) # optional - sage.rings.padics 1 .. SEEALSO:: diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index da22e04903a..3062c9439d8 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -199,10 +199,10 @@ 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]) # optional - sage.libs.pari + 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]) # optional - sage.libs.pari + 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[] @@ -210,10 +210,10 @@ def normalize_extra_units(base_ring, add_units, warning=True): 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]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: L = P.localization((x, y*z-x)) # optional - sage.libs.pari - sage: LocalizationElement(L, 4/(y*z-x)**2) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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) """ @@ -601,7 +601,7 @@ class Localization(IntegralDomain, UniqueRepresentation): ... ValueError: factor 7 of denominator is not a unit - sage: Localization(Zp(7), (3, 5)) # optional - sage.rings.padics + sage: Localization(Zp(7), (3, 5)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: all given elements are invertible in @@ -703,8 +703,8 @@ def _repr_(self): EXAMPLES:: - sage: R. = GF(3)[] # optional - sage.libs.pari - sage: Localization(R, a**2 - 1) # optional - sage.libs.pari + 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) """ diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index b70abc0ac92..a30dde1f1c5 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -253,19 +253,19 @@ class MPowerSeries(PowerSeries): 1 + s + t - s*t + O(s, t)^5 - sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.libs.pari + 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.libs.pari - sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: w # optional - sage.libs.pari + 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,7 +274,7 @@ 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 # optional - sage.libs.pari + 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 @@ -451,9 +451,9 @@ def __call__(self, *x, **kwds): Checking that :trac:`15059` is fixed:: - sage: M. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari - sage: s = M.hom([u, u+v]) # optional - sage.libs.pari - sage: s(M.one()) # optional - sage.libs.pari + 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:: @@ -567,14 +567,14 @@ def _value(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: f._value() # optional - sage.rings.finite_rings 1 + a + b - a*b - sage: f._value().parent() # optional - sage.libs.pari + 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) @@ -603,15 +603,15 @@ def _latex_(self): EXAMPLES:: - sage: M = PowerSeriesRing(GF(5),3,'t'); M # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: f = (-t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 # optional - sage.libs.pari - + 2*t[1]*t[2]^12 + 2*t[0]^7*t[1]^5*t[2]^2 + M.O(15)) - sage: f # optional - sage.libs.pari + 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_() # optional - sage.libs.pari + 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}' @@ -710,30 +710,30 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f == f^2 # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: f == f.O(4) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: a > b # optional - sage.rings.finite_rings True - sage: a > a^2 # optional - sage.libs.pari + sage: a > a^2 # optional - sage.rings.finite_rings True - sage: b > a^2 # optional - sage.libs.pari + sage: b > a^2 # optional - sage.rings.finite_rings True - sage: (f^2).O(3) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: f < f^2 # optional - sage.rings.finite_rings False - sage: f > f^2 # optional - sage.libs.pari + sage: f > f^2 # optional - sage.rings.finite_rings True - sage: f < 2*f # optional - sage.libs.pari + sage: f < 2*f # optional - sage.rings.finite_rings True """ return richcmp(self._bg_value, other._bg_value, op) @@ -1160,14 +1160,14 @@ def variables(self): EXAMPLES:: - sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.libs.pari + 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.libs.pari - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.libs.pari - sage: w # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: w.variables() # optional - sage.rings.finite_rings (t0, t2, t4) """ return tuple(self.parent(v) for v in self._value().variables()) @@ -1397,16 +1397,16 @@ def valuation(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(4949717)); R # optional - sage.libs.pari + 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.libs.pari - sage: f.valuation() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: g.valuation() # optional - sage.libs.pari + sage: g = 1 + a + a^3 # optional - sage.rings.finite_rings + sage: g.valuation() # optional - sage.rings.finite_rings 0 - sage: R.zero().valuation() # optional - sage.libs.pari + sage: R.zero().valuation() # optional - sage.rings.finite_rings +Infinity """ try: diff --git a/src/sage/rings/padics/misc.py b/src/sage/rings/padics/misc.py index 76e5fc04f2d..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) # optional - sage.rings.padics + 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 # optional - sage.rings.padics + 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 # optional - sage.rings.padics + 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) # optional - sage.rings.padics + 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) # optional - sage.rings.padics + 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/polynomial/flatten.py b/src/sage/rings/polynomial/flatten.py index 889a1f0a363..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) # optional - sage.rings.number_field - sage: R = K['x','y']['a','b'] # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: f(R('v*a*x^2 + b^2 + 1/v*y')) # optional - sage.rings.number_field + 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'] # optional - sage.rings.number_field + sage: R = QQbar['x','y']['a','b'] # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - 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 + 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) # optional - sage.rings.number_field + sage: R. = PolynomialRing(QQbar, 1) # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field - sage: f.domain(), f.codomain() # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field - sage: f.domain(), f.codomain() # optional - sage.rings.number_field + 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): @@ -367,8 +375,8 @@ def _call_(self, p): sage: from sage.rings.polynomial.flatten import FlatteningMorphism sage: rings = [ZZ['x']['y']['a,b,c']] - sage: rings += [GF(4)['x','y']['a','b']] # optional - sage.libs.pari - sage: rings += [AA['x']['a','b']['y'], QQbar['a1','a2']['t']['X','Y']] # optional - sage.rings.number_field + 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() @@ -425,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 @@ -439,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 """ @@ -657,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/ideal.py b/src/sage/rings/polynomial/ideal.py index 51424bb6ab9..858fc505b8d 100644 --- a/src/sage/rings/polynomial/ideal.py +++ b/src/sage/rings/polynomial/ideal.py @@ -75,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 # optional - sage.libs.singular + sage: G = I.groebner_basis(); G # optional - sage.libs.singular [x - 1] - sage: type(G) # optional - sage.libs.singular + sage: type(G) # optional - sage.libs.singular - sage: list(G) # optional - sage.libs.singular + 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 7a035943e64..8a67eb9f9bb 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -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))) # optional - sage.combinat - sage: c^P # optional - sage.combinat + 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 @@ -656,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) # optional - sage.libs.singular + sage: factor(z) # optional - sage.libs.singular x_1^-1 * x_2^-1 """ if not x.variables(): @@ -1472,7 +1472,7 @@ 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 diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 70034eecaa1..8412e612080 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -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] @@ -315,13 +315,13 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials implemented via Singular:: - sage: R. = PolynomialRing(FiniteField(5)) # optional - sage.libs.pari - sage: f = x^3*y^5 + x^7*y # optional - sage.libs.pari - sage: type(f) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f.derivative(x) # optional - sage.rings.finite_rings 2*x^6*y - 2*x^2*y^5 - sage: f.derivative(y) # optional - sage.libs.pari + sage: f.derivative(y) # optional - sage.rings.finite_rings x^7 Generic multivariate polynomials:: @@ -348,12 +348,12 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials over the symbolic ring (just for fun....):: - 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 + 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 # optional - sage.symbolic + sage: f.derivative(u) == v*x # optional - sage.symbolic True """ return multi_derivative(self, args) @@ -389,11 +389,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)[] # optional - sage.libs.pari - sage: f = x^2 + x + y # optional - sage.libs.pari - sage: f.polynomial(x) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f.polynomial(y) # optional - sage.rings.finite_rings y + x^2 + x """ cdef int ind @@ -446,8 +446,8 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - 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 + 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) @@ -561,9 +561,9 @@ cdef class MPolynomial(CommutativePolynomial): Verify that :trac:`16251` has been resolved, i.e., polynomials with unhashable coefficients are unhashable:: - sage: K. = Qq(9) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: hash(t) # optional - sage.rings.padics + 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' @@ -691,9 +691,9 @@ cdef class MPolynomial(CommutativePolynomial): In particular, this can be surprising in positive characteristic:: - sage: R. = GF(2)[] # optional - sage.libs.pari - sage: f = x + 1 # optional - sage.libs.pari - sage: f.homogenize(x) # optional - sage.libs.pari + 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:: @@ -816,15 +816,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 # optional - sage.libs.singular + sage: g % f # optional - sage.libs.singular 0 - sage: (g+1) % f # optional - sage.libs.singular + sage: (g+1) % f # optional - sage.libs.singular 1 sage: M = x*y sage: N = x^2*y^3 - sage: M.divides(N) # optional - sage.libs.singular + sage: M.divides(N) # optional - sage.libs.singular True """ try: @@ -848,21 +848,21 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + 3/5*y + 1 - sage: f.change_ring(GF(7)) # optional - sage.libs.pari + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings x^3 + 2*y + 1 :: - sage: R. = GF(9,'a')[] # optional - sage.libs.pari - sage: (x+2*y).change_ring(GF(3)) # optional - sage.libs.pari + 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) # 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 + 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: @@ -870,7 +870,7 @@ cdef class MPolynomial(CommutativePolynomial): Check that :trac:`25022` is fixed:: sage: K. = ZZ[] - sage: (x*y).change_ring(SR).monomials() # optional - sage.rings.number_field + sage: (x*y).change_ring(SR).monomials() # optional - sage.rings.number_field [x*y] """ if isinstance(R, Map): @@ -894,47 +894,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() # optional - sage.groups + sage: p.is_symmetric() # optional - sage.groups True - sage: (x + y - z).is_symmetric() # optional - sage.groups + sage: (x + y - z).is_symmetric() # optional - sage.groups False - sage: R.one().is_symmetric() # optional - sage.groups + sage: R.one().is_symmetric() # optional - sage.groups True sage: p = (x-y)*(y-z)*(z-x) - sage: p.is_symmetric() # optional - sage.groups + sage: p.is_symmetric() # optional - sage.groups False - sage: p.is_symmetric(AlternatingGroup(3)) # optional - sage.groups + sage: p.is_symmetric(AlternatingGroup(3)) # optional - sage.groups True sage: R. = QQ[] - sage: ((x + y)**2).is_symmetric() # optional - sage.groups + sage: ((x + y)**2).is_symmetric() # optional - sage.groups True - sage: R.one().is_symmetric() # optional - sage.groups + sage: R.one().is_symmetric() # optional - sage.groups True - sage: (x + 2*y).is_symmetric() # optional - sage.groups + 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)) # optional - sage.groups + 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)) # optional - sage.groups + 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) # optional - sage.groups + 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)) # optional - sage.groups + sage: R.one().is_symmetric(SymmetricGroup(4)) # optional - sage.groups Traceback (most recent call last): ... ValueError: invalid data to initialize a permutation @@ -977,39 +981,39 @@ cdef class MPolynomial(CommutativePolynomial): Multivariate polynomial over integers:: sage: R. = ZZ[] - sage: gap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap + sage: gap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: gap(R.zero()) # indirect doctest # optional - sage.libs.gap + sage: gap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 - sage: (x+y+z)._gap_(libgap) # optional - sage.libs.gap + sage: (x+y+z)._gap_(libgap) # optional - sage.libs.gap x+y+z - sage: g = gap(x - y + 3*x*y*z) # optional - sage.libs.gap - sage: R(g) # optional - sage.libs.gap + 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) # optional - sage.libs.gap - sage: R(g) # optional - sage.libs.gap + 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) # 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 + 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 # optional - sage.libs.gap sage.rings.number_field + 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[] # 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 + 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 # optional - sage.libs.gap sage.rings.number_field + 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()) @@ -1021,9 +1025,9 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap + sage: libgap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -1036,12 +1040,12 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: k. = GF(25); R. = k[] # optional - sage.libs.pari - sage: f = y*x^2*b + x*(b+1) + 1 # optional - sage.libs.pari - sage: magma = Magma() # so var names same below # optional - sage.libs.pari - sage: magma(f) # optional - magma # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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:: @@ -1071,13 +1075,13 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] # optional - sage.libs.pari - sage: f = R('e*i') * x + y^2 # optional - sage.libs.pari - sage: f._giac_init_() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: giac(f) # optional - sage.rings.finite_rings sageVARy^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) # optional - sage.libs.pari + sage: giac(R.zero()) # optional - sage.rings.finite_rings 0 """ g = ['sageVAR' + x for x in self.parent().variable_names()] @@ -1093,7 +1097,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] @@ -1121,20 +1125,20 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = 1 + x*y + x^3 + y^3 - sage: P = f.newton_polytope() # optional - sage.geometry.polyhedron - sage: P # optional - sage.geometry.polyhedron + 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() # optional - sage.geometry.polyhedron + sage: P.is_simple() # optional - sage.geometry.polyhedron True TESTS:: sage: R. = QQ[] - sage: R(0).newton_polytope() # optional - sage.geometry.polyhedron + sage: R(0).newton_polytope() # optional - sage.geometry.polyhedron The empty polyhedron in ZZ^0 - sage: R(1).newton_polytope() # optional - sage.geometry.polyhedron + 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() # optional - sage.geometry.polyhedron + 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 @@ -1284,32 +1288,32 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: k. = GF(9); R. = k[]; f = x*a + 2*x^3*y*a + a # optional - sage.libs.pari - sage: f.map_coefficients(lambda a: a + 1) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: h = Hom(R,S)[0]; h # optional - sage.libs.pari + 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[] # optional - sage.libs.pari - sage: f = r*X + Y # optional - sage.libs.pari - sage: g = f.map_coefficients(h); g # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: g = f.map_coefficients(h); g # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() # optional - sage.libs.pari + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -1333,10 +1337,10 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: k. = GF(9) # optional - sage.libs.pari - sage: R. = PolynomialRing(k) # optional - sage.libs.pari - sage: f = (x-a) * (y-a) # optional - sage.libs.pari - sage: f._norm_over_nonprime_finite_field() # optional - sage.libs.pari + 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() @@ -1372,8 +1376,8 @@ cdef class MPolynomial(CommutativePolynomial): 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) # optional - sage.modules - sage: M # optional - sage.modules + 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] @@ -1382,10 +1386,10 @@ 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() # optional - sage.modules + sage: M.determinant() # optional - sage.modules 0 - sage: f.sylvester_matrix(1 + g, x).determinant() # optional - sage.modules + 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 @@ -1393,7 +1397,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: f = R.random_element(4) sage: g = R.random_element(4) - sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) # optional - sage.modules + sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) # optional - sage.modules True TESTS: @@ -1402,7 +1406,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: f = x + y sage: g = x + y - sage: f.sylvester_matrix(g) # optional - sage.modules + sage: f.sylvester_matrix(g) # optional - sage.modules [1 y] [1 y] @@ -1414,21 +1418,23 @@ cdef class MPolynomial(CommutativePolynomial): sage: g = x + y sage: R. = GF(25, 'a')[] sage: h = x + y - sage: f.sylvester_matrix(g, 'x') # optional - sage.modules + sage: f.sylvester_matrix(g, 'x') # optional - sage.modules [1 y] [1 y] - sage: g.sylvester_matrix(h, 'x') # optional - sage.modules + sage: g.sylvester_matrix(h, 'x') # optional - sage.modules [1 y] [1 y] - sage: f.sylvester_matrix(h, 'x') # optional - sage.modules + 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) # optional - sage.modules + sage: f.sylvester_matrix(g) # optional - sage.modules [1 y] [1 z] @@ -1437,22 +1443,22 @@ cdef class MPolynomial(CommutativePolynomial): sage: K.=QQ[] sage: f = x^2 + 1 sage: g = K(0) - sage: f.sylvester_matrix(g) # optional - sage.modules + 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) # optional - sage.modules + 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) # optional - sage.modules + 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) # optional - sage.modules + sage: K(3).sylvester_matrix(x^2) # optional - sage.modules [3 0] [0 3] - sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules + sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules [] """ @@ -1519,11 +1525,11 @@ cdef class MPolynomial(CommutativePolynomial): 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 + sage: f.discriminant(x) # optional - sage.libs.singular 1 - sage: f.discriminant(y) # optional - sage.libs.singular + sage: f.discriminant(y) # optional - sage.libs.singular -383/16*x^2*z^2 + 8*x*z^2 - sage: f.discriminant(z) # optional - sage.libs.singular + 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 @@ -1531,20 +1537,20 @@ cdef class MPolynomial(CommutativePolynomial): 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 + 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() # optional - sage.libs.singular + 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() # optional - sage.libs.singular + 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[] # 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 + 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: @@ -1623,25 +1629,25 @@ cdef class MPolynomial(CommutativePolynomial): The number of polynomials has to match the number of variables:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant(x+z) # optional - sage.modules + 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]) # optional - sage.modules + 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) # optional - sage.modules + 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 @@ -1650,14 +1656,14 @@ cdef class MPolynomial(CommutativePolynomial): sage: K. = PolynomialRing(ZZ, 2) sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) - sage: flist[0].macaulay_resultant(flist[1:]) # optional - sage.modules + 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:]) # optional - sage.modules + 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`):: @@ -1667,38 +1673,38 @@ 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) # optional - sage.modules + 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]) # optional - sage.modules + 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]) # optional - sage.modules + 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]) # optional - sage.modules + 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) # optional - sage.modules + 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) # optional - sage.libs.pari - sage: R. = PolynomialRing(F, 4) # optional - sage.libs.pari - sage: z.macaulay_resultant([x^3, 5*y, w]) # optional - sage.libs.pari sage.modules + 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 @@ -1706,7 +1712,7 @@ cdef class MPolynomial(CommutativePolynomial): char polynomials of numerator/denominator):: sage: R. = PolynomialRing(QQ, 3) - sage: y.macaulay_resultant([x + z, z^2]) # optional - sage.modules + 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:: @@ -1716,7 +1722,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() - sage: f.resultant(g) == fh.macaulay_resultant(gh) # optional - sage.modules + sage: f.resultant(g) == fh.macaulay_resultant(gh) # optional - sage.modules True """ @@ -1757,10 +1763,10 @@ cdef class MPolynomial(CommutativePolynomial): :: - 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 + 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() # optional - sage.rings.number_field sage.symbolic + sage: f.denominator() # optional - sage.rings.number_field sage.symbolic 102 Finally, we try to compute the denominator of a polynomial with @@ -1778,18 +1784,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)[] # optional - sage.libs.pari - sage: x = R(0) # optional - sage.libs.pari - sage: x.denominator() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: type(x.denominator()) # optional - sage.rings.finite_rings - sage: type(a.denominator()) # optional - sage.libs.pari + sage: type(a.denominator()) # optional - sage.rings.finite_rings sage: from sage.rings.polynomial.multi_polynomial_element import MPolynomial - sage: isinstance(a / b, MPolynomial) # optional - sage.libs.pari + sage: isinstance(a / b, MPolynomial) # optional - sage.rings.finite_rings False - sage: isinstance(a.numerator() / a.denominator(), MPolynomial) # optional - sage.libs.pari + sage: isinstance(a.numerator() / a.denominator(), MPolynomial) # optional - sage.rings.finite_rings True """ if self.degree() == -1: @@ -1834,12 +1840,12 @@ cdef class MPolynomial(CommutativePolynomial): :: - 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 + 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() # optional - sage.rings.number_field sage.symbolic + sage: f.numerator() # optional - sage.rings.number_field sage.symbolic 3*y^19 - 34*x + 17 - sage: f == f.numerator() # optional - sage.rings.number_field sage.symbolic + sage: f == f.numerator() # optional - sage.rings.number_field sage.symbolic False We try to compute the numerator of a polynomial with coefficients in @@ -1847,10 +1853,10 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: K. = GF(3)['x, y, z'] # optional - sage.libs.pari - sage: f = 2*x*z + 2*z^2 + 2*y + 1; f # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: f.numerator() # optional - sage.rings.finite_rings -x*z - z^2 - y + 1 We check that the computation the numerator and denominator @@ -1858,9 +1864,9 @@ cdef class MPolynomial(CommutativePolynomial): :: - 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 + 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() @@ -1904,9 +1910,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 # optional - sage.libs.singular + 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) # optional - sage.libs.singular + sage: (f*g).reduce(I) # optional - sage.libs.singular 1 Test a non-invertible element:: @@ -1914,7 +1920,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) # optional - sage.libs.singular + sage: f.inverse_mod(I) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -1947,38 +1953,38 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: p = x^3 + y + x*z^2 # optional - sage.libs.pari - sage: p.weighted_degree({z:0, x:1, y:2}) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: p.weighted_degree(1, 2, 0) # optional - sage.rings.finite_rings 3 - sage: p.weighted_degree((1, 4, 2)) # optional - sage.libs.pari + sage: p.weighted_degree((1, 4, 2)) # optional - sage.rings.finite_rings 5 - sage: p.weighted_degree((1, 4, 1)) # optional - sage.libs.pari + sage: p.weighted_degree((1, 4, 1)) # optional - sage.rings.finite_rings 4 - sage: p.weighted_degree(2**64, 2**50, 2**128) # optional - sage.libs.pari + sage: p.weighted_degree(2**64, 2**50, 2**128) # optional - sage.rings.finite_rings 680564733841876926945195958937245974528 - sage: q = R.random_element(100, 20) #random # optional - sage.libs.pari - sage: q.weighted_degree(1, 1, 1) == q.total_degree() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: p.weighted_degree(2/1, 1, 1) # optional - sage.rings.finite_rings 6 The ``weighted_degree`` coincides with the ``degree`` of a weighted @@ -2304,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) # optional - sage.modules + 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, @@ -2317,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) # optional - sage.modules + 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 @@ -2326,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) # optional - sage.modules + 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 @@ -2335,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) # optional - sage.modules + 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] @@ -2345,11 +2351,11 @@ cdef class MPolynomial(CommutativePolynomial): 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) # optional - sage.modules + 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) # optional - sage.modules + 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] @@ -2359,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) # optional - sage.modules + 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() # optional - sage.modules + 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] @@ -2376,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') # optional - sage.modules + 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] @@ -2386,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() # optional - sage.modules + 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 @@ -2395,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) # optional - sage.modules + 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 - @@ -2406,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 # optional - sage.modules + 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, @@ -2419,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 # optional - sage.modules + 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, @@ -2509,16 +2515,16 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: (x + y).is_unit() # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_unit() # optional - sage.rings.number_field False - sage: R(0).is_unit() # optional - sage.rings.number_field + sage: R(0).is_unit() # optional - sage.rings.number_field False - sage: R(-1).is_unit() # optional - sage.rings.number_field + sage: R(-1).is_unit() # optional - sage.rings.number_field True - sage: R(-1 + x).is_unit() # optional - sage.rings.number_field + sage: R(-1 + x).is_unit() # optional - sage.rings.number_field False - sage: R(2).is_unit() # optional - sage.rings.number_field + sage: R(2).is_unit() # optional - sage.rings.number_field True Check that :trac:`22454` is fixed:: @@ -2555,10 +2561,10 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: (x + y).is_nilpotent() # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_nilpotent() # optional - sage.rings.number_field False - sage: R(0).is_nilpotent() # optional - sage.rings.number_field + sage: R(0).is_nilpotent() # optional - sage.rings.number_field True sage: _. = Zmod(4)[] sage: (2*x).is_nilpotent() @@ -2587,8 +2593,8 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: (x + y)._test_subs() # optional - sage.rings.number_field + 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 3f46a0ee9c8..d2d5831c6a6 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -186,10 +186,10 @@ def _richcmp_(self, right, op): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field + sage: x^3*y^2*z^4 < x^3*y^2*z^1 # optional - sage.rings.number_field False :: @@ -202,10 +202,10 @@ def _richcmp_(self, right, op): :: - 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 + 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 # optional - sage.rings.number_field + 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, @@ -215,9 +215,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - 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 + 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:: @@ -336,9 +336,9 @@ def _lmul_(self, a): :: - 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 + 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) @@ -357,9 +357,9 @@ def _rmul_(self, a): :: - 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 + 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) @@ -422,15 +422,15 @@ def change_ring(self, R): sage: R. = QQ[] sage: f = x^2 + 5*y - sage: f.change_ring(GF(5)) # optional - sage.libs.pari + sage: f.change_ring(GF(5)) # optional - sage.libs.pari x^2 :: - 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 + 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): @@ -451,10 +451,10 @@ def __init__(self, parent, x): """ EXAMPLES:: - sage: R, x = PolynomialRing(QQbar, 10, 'x').objgens() # optional - sage.rings.number_field - sage: x # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + sage: loads(dumps(x)) == x # optional - sage.rings.number_field True """ if not isinstance(x, polydict.PolyDict): @@ -484,12 +484,12 @@ def _repr_(self): """ EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: repr(-x^2 - y + 1) # indirect doctest # optional - sage.rings.number_field + 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) # 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 + 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: @@ -505,12 +505,12 @@ def _latex_(self): r""" EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: latex(-x^2 - y + 1) # optional - sage.rings.number_field + 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) # 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 + 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: @@ -525,9 +525,9 @@ def _repr_with_changed_varnames(self, varnames): """ EXAMPLES:: - 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 + 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: @@ -542,8 +542,8 @@ def _macaulay2_(self, macaulay2=None): """ EXAMPLES:: - sage: R = GF(13)['a,b']['c,d'] # optional - sage.libs.pari - sage: macaulay2(R('a^2 + c')) # optional - macaulay2 sage.libs.pari + 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 @@ -552,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.libs.pari + sage: macaulay2(R('a^2')).ring()._operator('===', R) # optional - macaulay2 sage.libs.pari true """ if macaulay2 is None: @@ -570,20 +570,20 @@ def degrees(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field - sage: f.degrees() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # 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 + 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() # optional - sage.rings.number_field + sage: R(0).degrees() # optional - sage.rings.number_field (0, 0, 0, 0) """ if not self: @@ -661,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) # optional - sage.libs.pari + 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))) # optional - sage.libs.pari - sage: x, y = R.gens() # optional - sage.libs.pari - sage: x.degree() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: y.degree() # optional - sage.libs.pari 3 - sage: x.degree(y), x.degree(x), y.degree(x), y.degree(y) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: f.degree(x) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f.degree(y) # optional - sage.libs.pari 2 - sage: f.degree() # optional - sage.libs.pari + sage: f.degree() # optional - sage.libs.pari 8 - sage: f.degree(std_grading=True) # optional - sage.libs.pari + sage: f.degree(std_grading=True) # optional - sage.libs.pari 3 - sage: R(0).degree() # optional - sage.libs.pari + sage: R(0).degree() # optional - sage.libs.pari -1 Degree of zero polynomial for other implementation :trac:`20048` :: - sage: R. = GF(3037000453)[] # optional - sage.libs.pari - sage: R.zero().degree(x) # optional - sage.libs.pari + sage: R. = GF(3037000453)[] # optional - sage.libs.pari + sage: R.zero().degree(x) # optional - sage.libs.pari -1 """ if x is None: @@ -717,24 +717,24 @@ def total_degree(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field - sage: f.total_degree() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: f.total_degree() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: f.total_degree() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: f.total_degree() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: f.total_degree() # optional - sage.rings.number_field + 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() @@ -767,38 +767,38 @@ def monomial_coefficient(self, mon): :: - sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field The parent of the return is a member of the base ring. :: - sage: f = 2 * x * y # optional - sage.rings.number_field - sage: c = f.monomial_coefficient(x*y); c # 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() # optional - sage.rings.number_field + sage: c.parent() # optional - sage.rings.number_field Algebraic Field :: - 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 + 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) # optional - sage.rings.number_field + sage: f.monomial_coefficient(x*y) # optional - sage.rings.number_field 5 - sage: f.monomial_coefficient(x^9) # optional - sage.rings.number_field + sage: f.monomial_coefficient(x^9) # optional - sage.rings.number_field -1 - sage: f.monomial_coefficient(x^10) # optional - sage.rings.number_field + sage: f.monomial_coefficient(x^10) # optional - sage.rings.number_field 0 :: 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 + 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) # optional - sage.rings.number_field + sage: f.monomial_coefficient(x) # optional - sage.rings.number_field -a """ if parent(mon) is not self.parent(): @@ -820,23 +820,23 @@ def __iter__(self): EXAMPLES:: - 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 + 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') # 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 + 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') # 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 + 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)] :: @@ -867,22 +867,22 @@ def __getitem__(self, x): EXAMPLES:: - 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 + 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] # optional - sage.rings.number_field + sage: f[1,1] # optional - sage.rings.number_field 17 - sage: f[0,1] # optional - sage.rings.number_field + sage: f[0,1] # optional - sage.rings.number_field 0 :: - sage: R. = PolynomialRing(QQbar, 1); R # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + sage: f = 5*x^2 + 3; f # optional - sage.rings.number_field 5*x^2 + 3 - sage: f[2] # optional - sage.rings.number_field + sage: f[2] # optional - sage.rings.number_field 5 """ if isinstance(x, MPolynomial): @@ -908,14 +908,14 @@ def iterator_exp_coeff(self, as_ETuples=True): EXAMPLES:: - 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 + 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') # 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 + 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() @@ -960,31 +960,31 @@ def coefficient(self, degrees): EXAMPLES:: - 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 + 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() # optional - sage.rings.number_field + 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']) # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: f.coefficient({y: 1}) # optional - sage.rings.number_field + 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}) # optional - sage.rings.number_field + sage: f.coefficient({y: 0}) # optional - sage.rings.number_field -x^9 + (-7)*x - sage: f.coefficient({x: 0, y: 0}) # optional - sage.rings.number_field + sage: f.coefficient({x: 0, y: 0}) # optional - sage.rings.number_field 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 + 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]) # optional - sage.rings.number_field + sage: f.coefficient([0, None]) # optional - sage.rings.number_field y^2 + y + 1 - sage: f.coefficient(x) # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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 :: @@ -1034,28 +1034,28 @@ def global_height(self, prec=None): EXAMPLES:: - 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 + 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) # 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 + 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 # optional - sage.rings.number_field sage.symbolic - sage: g.global_height() # optional - sage.rings.number_field sage.symbolic + 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) # 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 + 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 :: @@ -1174,10 +1174,10 @@ def local_height_arch(self, i, prec=None): :: sage: R. = QQ[] - 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 + 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 :: @@ -1209,9 +1209,9 @@ def _exponents(self): EXAMPLES:: - 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 + 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) @@ -1231,29 +1231,29 @@ def exponents(self, as_ETuples=True): EXAMPLES:: - 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 + 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]) # optional - sage.rings.number_field + sage: type(f.exponents()[0]) # optional - sage.rings.number_field - sage: type(f.exponents(as_ETuples=False)[0]) # optional - sage.rings.number_field + 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) # 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 + 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() # optional - sage.rings.number_field + sage: E.pop() # optional - sage.rings.number_field (0, 1, 0) - sage: E != f.exponents() # optional - sage.rings.number_field + sage: E != f.exponents() # optional - sage.rings.number_field True """ if as_ETuples: @@ -1285,18 +1285,18 @@ def is_homogeneous(self): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: (x+y).is_homogeneous() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: (x.parent()(0)).is_homogeneous() # optional - sage.rings.number_field True - sage: (x+y^2).is_homogeneous() # optional - sage.rings.number_field + sage: (x+y^2).is_homogeneous() # optional - sage.rings.number_field False - sage: (x^2 + y^2).is_homogeneous() # optional - sage.rings.number_field + sage: (x^2 + y^2).is_homogeneous() # optional - sage.rings.number_field True - sage: (x^2 + y^2*x).is_homogeneous() # optional - sage.rings.number_field + sage: (x^2 + y^2*x).is_homogeneous() # optional - sage.rings.number_field False - sage: (x^2*y + y^2*x).is_homogeneous() # optional - sage.rings.number_field + sage: (x^2*y + y^2*x).is_homogeneous() # optional - sage.rings.number_field True """ return self.element().is_homogeneous() @@ -1318,11 +1318,11 @@ def _homogenize(self, var): EXAMPLES:: - 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 + 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() # optional - sage.rings.number_field + sage: g.parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y, z over Algebraic Field SEE: ``self.homogenize`` @@ -1340,12 +1340,12 @@ def is_generator(self): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: x.is_generator() # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_generator() # optional - sage.rings.number_field True - sage: (x + y - y).is_generator() # optional - sage.rings.number_field + sage: (x + y - y).is_generator() # optional - sage.rings.number_field True - sage: (x*y).is_generator() # optional - sage.rings.number_field + sage: (x*y).is_generator() # optional - sage.rings.number_field False """ elt = self.element() @@ -1363,21 +1363,21 @@ def is_monomial(self): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: x.is_monomial() # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_monomial() # optional - sage.rings.number_field True - sage: (x + 2*y).is_monomial() # optional - sage.rings.number_field + sage: (x + 2*y).is_monomial() # optional - sage.rings.number_field False - sage: (2*x).is_monomial() # optional - sage.rings.number_field + sage: (2*x).is_monomial() # optional - sage.rings.number_field False - sage: (x*y).is_monomial() # optional - sage.rings.number_field + sage: (x*y).is_monomial() # optional - sage.rings.number_field True To allow a non-1 leading coefficient, use is_term():: - sage: (2*x*y).is_term() # optional - sage.rings.number_field + sage: (2*x*y).is_term() # optional - sage.rings.number_field True - sage: (2*x*y).is_monomial() # optional - sage.rings.number_field + sage: (2*x*y).is_monomial() # optional - sage.rings.number_field False """ return len(self.element()) == 1 and self.element().coefficients()[0] == 1 @@ -1392,21 +1392,21 @@ def is_term(self): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: x.is_term() # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_term() # optional - sage.rings.number_field True - sage: (x + 2*y).is_term() # optional - sage.rings.number_field + sage: (x + 2*y).is_term() # optional - sage.rings.number_field False - sage: (2*x).is_term() # optional - sage.rings.number_field + sage: (2*x).is_term() # optional - sage.rings.number_field True - sage: (7*x^5*y).is_term() # optional - sage.rings.number_field + sage: (7*x^5*y).is_term() # optional - sage.rings.number_field True To require leading coefficient 1, use is_monomial():: - sage: (2*x*y).is_monomial() # optional - sage.rings.number_field + sage: (2*x*y).is_monomial() # optional - sage.rings.number_field False - sage: (2*x*y).is_term() # optional - sage.rings.number_field + sage: (2*x*y).is_term() # optional - sage.rings.number_field True """ return len(self.element()) == 1 @@ -1433,11 +1433,11 @@ def subs(self, fixed=None, **kw): EXAMPLES:: - 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 + 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}) # optional - sage.rings.number_field + sage: f.subs({x: 5}) # optional - sage.rings.number_field 25*y^2 + y + 30 """ variables = list(self.parent().gens()) @@ -1457,22 +1457,22 @@ def monomials(self): EXAMPLES:: - 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 + 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[] # optional - sage.rings.number_field - sage: F = ((fx*gy - fy*gx)^3) # optional - sage.rings.number_field - sage: F # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: F = ((fx*gy - fy*gx)^3) # optional - sage.rings.number_field + sage: 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() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: F.coefficients() # optional - sage.rings.number_field [-1, 3, -3, 1] - sage: sum(map(mul,zip(F.coefficients(),F.monomials()))) == F # optional - sage.rings.number_field + sage: sum(map(mul,zip(F.coefficients(),F.monomials()))) == F # optional - sage.rings.number_field True """ ring = self.parent() @@ -1486,12 +1486,12 @@ def constant_coefficient(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field - sage: f.constant_coefficient() # optional - sage.rings.number_field + 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()) @@ -1508,16 +1508,16 @@ def is_univariate(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.is_univariate() # optional - sage.rings.number_field + sage: g.is_univariate() # optional - sage.rings.number_field True - sage: f = x^0 # optional - sage.rings.number_field - sage: f.is_univariate() # optional - sage.rings.number_field + sage: f = x^0 # optional - sage.rings.number_field + sage: f.is_univariate() # optional - sage.rings.number_field True """ mons = self.element().dict() @@ -1550,17 +1550,17 @@ def univariate_polynomial(self, R=None): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.univariate_polynomial() # optional - sage.rings.number_field + sage: g.univariate_polynomial() # optional - sage.rings.number_field 700*y^2 - 2*y + 305 - sage: g.univariate_polynomial(PolynomialRing(QQ, 'z')) # optional - sage.rings.number_field + sage: g.univariate_polynomial(PolynomialRing(QQ, 'z')) # optional - sage.rings.number_field 700*z^2 - 2*z + 305 TESTS:: @@ -1615,13 +1615,13 @@ def variables(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.variables() # optional - sage.rings.number_field + sage: g.variables() # optional - sage.rings.number_field (y,) TESTS: @@ -1640,11 +1640,11 @@ def variable(self,i): EXAMPLES:: - 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 + 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) # optional - sage.rings.number_field + sage: f.variable(1) # optional - sage.rings.number_field y """ return self.variables()[int(i)] @@ -1655,13 +1655,13 @@ def nvariables(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.nvariables() # optional - sage.rings.number_field + sage: g.nvariables() # optional - sage.rings.number_field 1 """ return len(self.degrees().nonzero_positions()) @@ -1672,12 +1672,12 @@ def is_constant(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field - sage: g.is_constant() # optional - sage.rings.number_field + 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() @@ -1689,10 +1689,10 @@ def lm(self): EXAMPLES:: - 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 + 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() # optional - sage.libs.pari + sage: (x^3*y^2*z^4 + x^3*y^2*z^1).lm() # optional - sage.libs.pari x^3*y^2*z^4 :: @@ -1705,18 +1705,18 @@ def lm(self): :: - 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 + 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() # optional - sage.rings.number_field + 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') # optional - sage.libs.pari - sage: f = x + y # optional - sage.libs.pari - sage: f.lm() # optional - sage.libs.pari + 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 """ @@ -1738,9 +1738,9 @@ def lc(self): EXAMPLES:: - 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 + 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: @@ -1761,21 +1761,21 @@ def lt(self): EXAMPLES:: - 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 + 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") # 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 + 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') # optional - sage.libs.pari - sage: f = x + y # optional - sage.libs.pari - sage: f.lt() # optional - sage.libs.pari + 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: @@ -1829,14 +1829,14 @@ def _floordiv_(self, right): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: 2*x*y//y # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: 2*x*y//y # optional - sage.rings.number_field 2*x - sage: 2*x//y # optional - sage.rings.number_field + sage: 2*x//y # optional - sage.rings.number_field 0 - sage: 2*x//4 # optional - sage.rings.number_field + sage: 2*x//4 # optional - sage.rings.number_field 1/2*x - sage: type(0//y) # optional - sage.rings.number_field + sage: type(0//y) # optional - sage.rings.number_field """ # handle division by monomials without using Singular @@ -2050,8 +2050,8 @@ def factor(self, proof=None): Check that we can factor over the algebraic field (:trac:`25390`):: - sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field - sage: factor(x^2 + y^2) # optional - sage.rings.number_field + 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:: @@ -2101,12 +2101,12 @@ def factor(self, proof=None): We check a case that failed with an exception at some point:: - 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 + 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 """ @@ -2185,11 +2185,11 @@ def lift(self,I): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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_() @@ -2232,9 +2232,9 @@ def quo_rem(self, right): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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() @@ -2294,8 +2294,8 @@ def resultant(self, other, variable=None): Check that :trac:`15061` is fixed:: - sage: R. = AA[] # optional - sage.rings.number_field - sage: (x^2 + 1).resultant(x^2 - y) # optional - sage.rings.number_field + 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`:: @@ -2308,12 +2308,12 @@ def resultant(self, other, variable=None): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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) # optional - sage.rings.number_field + sage: a.resultant(b, y) # optional - sage.rings.number_field 2*x^3 """ R = self.parent() @@ -2373,48 +2373,48 @@ def reduce(self, I): EXAMPLES:: - 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 + 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()) # optional - sage.rings.number_field + sage: g.reduce(F.gens()) # optional - sage.rings.number_field (-6)*y^2 + 2*y :: - sage: f = 3*x # optional - sage.rings.number_field - sage: f.reduce([2*x, y]) # optional - sage.rings.number_field + 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) # 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 + 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) # optional - sage.rings.number_field + sage: f = y13*y15; f.reduce(J) # optional - sage.rings.number_field y13*y15 - sage: f = y13*y15 + y9 - y12; f.reduce(J) # optional - sage.rings.number_field + 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') # 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 + 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[] # optional - sage.rings.number_field - sage: x.reduce(R.zero_ideal()) # optional - sage.rings.number_field + 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 @@ -2480,11 +2480,11 @@ def degree_lowest_rational_function(r, x): EXAMPLES:: - 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 + 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 @@ -2492,13 +2492,13 @@ def degree_lowest_rational_function(r, x): :: - sage: r = f/g; r # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: degree_lowest_rational_function(r, a) # optional - sage.libs.pari -1 - sage: degree_lowest_rational_function(r, b) # optional - sage.libs.pari + sage: degree_lowest_rational_function(r, b) # optional - sage.libs.pari 0 - sage: degree_lowest_rational_function(r, c) # optional - sage.libs.pari + 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 30a956b784b..ad2e44c38a6 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -165,11 +165,11 @@ sage: factor(164878) 2 * 7 * 11777 - sage: I.change_ring(P.change_ring(GF(2))).groebner_basis() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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:: @@ -180,7 +180,7 @@ 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() # optional - sage.libs.pari + sage: I.change_ring(P.change_ring(GF(3))).groebner_basis() # optional - sage.rings.finite_rings [1] TESTS:: @@ -342,9 +342,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R,4) # indirect doctest # optional - sage.libs.pari - sage: magma(I) # optional - magma # optional - sage.libs.pari + 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 @@ -379,18 +379,18 @@ def _groebner_basis_magma(self, deg_bound=None, prot=False, magma=magma_default) EXAMPLES:: - sage: R. = PolynomialRing(GF(127), 10) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.libs.pari - sage: gb = I.groebner_basis('magma:GroebnerBasis') # indirect doctest; optional - magma # optional - sage.libs.pari - sage: len(gb) # optional - magma # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.libs.pari - sage: gb = I.groebner_basis('magma:GroebnerBasis', deg_bound=4) # indirect doctest; optional - magma # optional - sage.libs.pari - sage: len(gb) # optional - magma # optional - sage.libs.pari + 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() @@ -1079,9 +1079,9 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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() @@ -1137,9 +1137,9 @@ def dimension(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(32003), order='degrevlex') # optional - sage.libs.pari - sage: I = ideal(x^2 - y, x^3) # optional - sage.libs.pari - sage: I.dimension() # optional - sage.libs.pari + 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. @@ -1151,22 +1151,22 @@ def dimension(self, singular=singular_default): EXAMPLES:: - sage: R. = PolynomialRing(GF(2147483659^2), order='lex') # optional - sage.libs.pari - sage: I = R.ideal([x*y, x*y+1]) # optional - sage.libs.pari - sage: I.dimension() # optional - sage.libs.pari + 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)]) # optional - sage.libs.pari - sage: I.dimension() # optional - sage.libs.pari + 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]) # optional - sage.libs.pari - sage: I.dimension() # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: I = R.ideal(0) # optional - sage.libs.pari - sage: I.dimension() # optional - sage.libs.pari + 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 @@ -1178,9 +1178,9 @@ def dimension(self, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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:: @@ -1279,19 +1279,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) # optional - sage.libs.pari - sage: sage.rings.ideal.FieldIdeal(P).vector_space_dimension() # known bug # optional - sage.libs.pari + 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[] # 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 + 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() # optional - sage.rings.number_field + sage: I.vector_space_dimension() # optional - sage.rings.number_field 3 """ @@ -1328,12 +1328,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') # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: I.groebner_basis(algorithm='ginv') # optional - ginv # optional - sage.libs.pari + 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] @@ -1576,9 +1576,9 @@ def genus(self): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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 @@ -1636,10 +1636,10 @@ def intersection(self, *others): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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() @@ -1718,10 +1718,10 @@ def radical(self): :: - sage: R. = PolynomialRing(GF(37), 3) # optional - sage.libs.pari - sage: p = z^2 + 1; q = z^3 + 2 # optional - sage.libs.pari - sage: I = (p*q^2, y - z^2)*R # optional - sage.libs.pari - sage: I.radical() # optional - sage.libs.pari + 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 @@ -1805,16 +1805,16 @@ def syzygy_module(self): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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()) # optional - sage.rings.number_field - sage: M*G # optional - sage.rings.number_field + 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 @@ -1943,8 +1943,8 @@ def interreduced_basis(self): The interreduced basis of 0 is 0:: - sage: P. = GF(2)[] # optional - sage.libs.pari - sage: Ideal(P(0)).interreduced_basis() # optional - sage.libs.pari + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: Ideal(P(0)).interreduced_basis() # optional - sage.rings.finite_rings [0] ALGORITHM: @@ -1957,9 +1957,9 @@ def interreduced_basis(self): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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() @@ -1987,17 +1987,17 @@ def basis_is_groebner(self, singular=singular_default): EXAMPLES:: - sage: R. = PolynomialRing(GF(127), 10) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R, 4) # optional - sage.libs.pari - sage: I.basis_is_groebner() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari - sage: I2.basis_is_groebner() # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: R. = PolynomialRing(GF(7583)) # optional - sage.rings.finite_rings 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, \ @@ -2019,12 +2019,12 @@ def basis_is_groebner(self, singular=singular_default): + 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] # optional - sage.libs.pari + - 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] # optional - sage.rings.finite_rings - sage: Ideal(l).basis_is_groebner() # optional - sage.libs.pari + sage: Ideal(l).basis_is_groebner() # optional - sage.rings.finite_rings False - sage: gb = Ideal(l).groebner_basis() # optional - sage.libs.pari - sage: Ideal(gb).basis_is_groebner() # optional - sage.libs.pari + sage: gb = Ideal(l).groebner_basis() # optional - sage.rings.finite_rings + sage: Ideal(gb).basis_is_groebner() # optional - sage.rings.finite_rings True .. NOTE:: @@ -2042,12 +2042,12 @@ def basis_is_groebner(self, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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()) # optional - sage.rings.number_field - sage: I2.basis_is_groebner() # optional - sage.rings.number_field + 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 @@ -2130,9 +2130,9 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula :: - sage: R. = PolynomialRing(GF(32003), 3, order='lex') # optional - sage.libs.pari - 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.libs.pari - sage: I.transformed_basis('gwalk') # optional - sage.libs.pari + 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 @@ -2151,12 +2151,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[] # 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 + 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() @@ -2243,9 +2243,9 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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 # optional - sage.rings.number_field @@ -2318,15 +2318,15 @@ def quotient(self, J): EXAMPLES:: - sage: R. = PolynomialRing(GF(181), 3) # optional - sage.libs.pari - sage: I = Ideal([x^2+x*y*z, y^2-z^3*y, z^3+y^5*x*z]) # optional - sage.libs.pari - sage: J = Ideal([x]) # optional - sage.libs.pari - sage: Q = I.quotient(J) # optional - sage.libs.pari - sage: y*z + x in I # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: x in J # optional - sage.rings.finite_rings True - sage: x * (y*z + x) in I # optional - sage.libs.pari + sage: x * (y*z + x) in I # optional - sage.rings.finite_rings True TESTS: @@ -2341,10 +2341,10 @@ def quotient(self, J): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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:: @@ -2397,10 +2397,10 @@ def saturation(self, other): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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 @@ -2450,10 +2450,10 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True EXAMPLES:: - sage: K. = GF(27) # this example is from the MAGMA handbook # optional - sage.libs.pari - sage: P. = PolynomialRing(K, 2, order='lex') # optional - sage.libs.pari - sage: I = Ideal([x^8 + y + 2, y^6 + x*y^5 + x^2]) # optional - sage.libs.pari - sage: I = Ideal(I.groebner_basis()); I # optional - sage.libs.pari + 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 - @@ -2463,18 +2463,18 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True + 1) of Multivariate Polynomial Ring in x, y over Finite Field in w of size 3^3 - sage: V = I.variety(); # optional - sage.libs.pari - sage: sorted(V, key=str) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: [f.subs(v) for f in I.gens() for v in V] # check that all polynomials vanish # optional - sage.rings.finite_rings [0, 0, 0, 0, 0, 0] - sage: [I.subs(v).is_zero() for v in V] # same test, but nicer syntax # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: I.vector_space_dimension() # optional - sage.rings.finite_rings 48 Here we compute the points of intersection of a hyperbola and a @@ -2496,7 +2496,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) # optional - sage.rings.number_field + sage: I.variety(ring=AA) # optional - sage.rings.number_field [{y: 1, x: 1}, {y: 0.3611030805286474?, x: 2.769292354238632?}] @@ -2509,7 +2509,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) # optional - sage.rings.number_field + 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, @@ -2521,7 +2521,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}] @@ -2544,9 +2544,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') # optional - sage.libs.pari - sage: I = ideal([x^3 - 2*y^2, 3*x + y^4]) # optional - sage.libs.pari - sage: I.variety() # optional - sage.libs.pari + 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. @@ -2559,20 +2559,20 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True sage: K. = QQ[] 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 + sage: v = I.variety(AA)[0]; v[x], v[y] # optional - sage.rings.number_field (4.464101615137755?, -7.464101615137755?) - sage: list(v)[0].parent() # optional - sage.rings.number_field + sage: list(v)[0].parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y over Algebraic Real Field - sage: v[x] # optional - sage.rings.number_field + sage: v[x] # optional - sage.rings.number_field 4.464101615137755? - sage: v["y"] # optional - sage.rings.number_field + sage: v["y"] # optional - sage.rings.number_field -7.464101615137755? msolve also works over finite fields:: - sage: R. = PolynomialRing(GF(536870909), 2, order='lex') # optional - sage.libs.pari - sage: I = Ideal([x^2 - 1, y^2 - 1]) # optional - sage.libs.pari - sage: sorted(I.variety(algorithm='msolve', proof=False), key=str) # optional - msolve # optional - sage.libs.pari + 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', proof=False), key=str) # optional - msolve # optional - sage.rings.finite_rings [{x: 1, y: 1}, {x: 1, y: 536870908}, {x: 536870908, y: 1}, @@ -2581,9 +2581,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') # optional - sage.libs.pari - sage: I = Ideal([x^2 - 1, y^2 - 1]) # optional - sage.libs.pari - sage: I.variety(algorithm='msolve', proof=False) # optional - msolve # optional - sage.libs.pari + 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 @@ -2618,20 +2618,20 @@ def _variety_triangular_decomposition(self, ring): TESTS:: - sage: K. = GF(27) # optional - sage.libs.pari - sage: P. = PolynomialRing(K, 2, order='lex') # optional - sage.libs.pari - sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: sorted(I.variety(), key=str) # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: R.inject_variables() # optional - sage.libs.pari + 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, \ @@ -2642,10 +2642,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]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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', @@ -2698,7 +2698,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) # optional - sage.rings.number_field + sage: I.variety(QQbar) # optional - sage.rings.number_field [...a: 0...] An early version of :trac:`25351` broke this method by adding the @@ -2706,13 +2706,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) # 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 + 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) # 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 + 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 """ @@ -2798,7 +2798,7 @@ 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() # optional - sage.libs.flint + sage: I.hilbert_polynomial() # optional - sage.libs.flint 5*t - 5 Of course, the Hilbert polynomial of a zero-dimensional ideal @@ -2808,21 +2808,21 @@ def hilbert_polynomial(self, algorithm='sage'): sage: J = P*[m.lm() for m in J0.groebner_basis()] sage: J.dimension() 0 - sage: J.hilbert_polynomial() # optional - sage.libs.flint + 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() # optional - sage.libs.flint sage.libs.singular + 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() # optional - sage.libs.flint sage.libs.singular + 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: Minors = P.ideal(M.minors(2)) - sage: hp = Minors.hilbert_polynomial(); hp # optional - sage.libs.flint + 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 @@ -2833,7 +2833,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 # optional - sage.libs.singular + sage: Minors.hilbert_polynomial(algorithm='singular') # not tested # optional - sage.libs.singular Traceback (most recent call last): ... RuntimeError: error in Singular function call 'hilbPoly': @@ -2845,7 +2845,7 @@ def hilbert_polynomial(self, algorithm='sage'): coefficients of the Hilbert-Poincaré series in all degrees:: sage: P = PowerSeriesRing(QQ, 't', default_prec=50) - sage: hs = Minors.hilbert_series() # optional - sage.libs.flint + 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 @@ -2855,23 +2855,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') # optional - sage.libs.singular + sage: I.hilbert_polynomial(algorithm='singular') # optional - sage.libs.singular 3 - sage: I.hilbert_polynomial() # optional - sage.libs.flint + sage: I.hilbert_polynomial() # optional - sage.libs.flint 3 Check that this method works over QQbar (:trac:`25351`):: - 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 + 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() # optional - sage.libs.flint + sage: I.hilbert_polynomial() # optional - sage.libs.flint t + 5 """ if not self.is_homogeneous(): @@ -2934,28 +2934,28 @@ 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() # optional - sage.libs.flint + 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() # optional - sage.libs.flint + sage: J.hilbert_series() # optional - sage.libs.flint (t^3 - t^2 - t - 1)/(t - 1) - sage: J.hilbert_series(grading=(10,3)) # optional - sage.libs.flint + 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]) # optional - sage.libs.flint + 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]) # optional - sage.libs.flint + 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') # optional - sage.libs.flint sage.libs.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') # optional - sage.libs.flint sage.libs.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') # optional - sage.libs.flint sage.libs.singular True @@ -3033,13 +3033,13 @@ 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() # optional - sage.libs.flint + 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() # optional - sage.libs.flint + sage: J.hilbert_numerator() # optional - sage.libs.flint t^4 - 2*t^3 + 1 - sage: J.hilbert_numerator(grading=(10,3)) # optional - sage.libs.flint + sage: J.hilbert_numerator(grading=(10,3)) # optional - sage.libs.flint t^26 - t^23 - t^16 + 1 TESTS:: @@ -3053,9 +3053,9 @@ def hilbert_numerator(self, grading = None, algorithm = 'sage'): Check that this method works over QQbar (:trac:`25351`):: - 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 + 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 @@ -3225,19 +3225,19 @@ def normal_basis(self, degree=None, algorithm='libsingular', Check that this method works over QQbar (:trac:`25351`):: - 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 + 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) # optional - sage.rings.number_field - sage: [J.normal_basis(d) for d in (0..3)] # optional - sage.rings.number_field + 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) # optional - sage.libs.pari - sage: S.ideal(x^6 + y^3 + z^2).normal_basis(6, algorithm='singular') # optional - sage.libs.pari + 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 @@ -3317,14 +3317,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) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.libs.pari - sage: gb1 = I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.libs.pari - sage: gb2 = I.groebner_basis('macaulay2:mgb') # optional - macaulay2 # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.libs.pari - sage: gb3 = I.groebner_basis('macaulay2:f4') # optional - macaulay2 # optional - sage.libs.pari - sage: gb1 == gb2 == gb3 # optional - macaulay2 # optional - sage.libs.pari + 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:: @@ -3388,22 +3388,22 @@ def __init__(self, ring, gens, coerce=True, side = "left"): EXAMPLES:: - 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 + 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 # optional - sage.combinat sage.modules - sage: I # random # optional - sage.combinat sage.modules + sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) # indirect doctest # optional - sage.combinat sage.modules + 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 + 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 # optional - sage.combinat sage.modules + 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(), key=str) # optional - sage.combinat sage.modules + sage: sorted(H.ideal([y^2, x^2, z^2-H.one()], side="twosided").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="right") # optional - sage.combinat sage.modules + 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. @@ -3428,15 +3428,15 @@ def __call_singular(self, cmd, arg = None): EXAMPLES:: - 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 + 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) # optional - sage.combinat sage.modules - sage: id.std() # indirect doctest # random # optional - sage.combinat sage.modules + 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 + sage: sorted(id.std().gens(), key=str) # optional - sage.combinat sage.modules [x, y, z] """ from sage.libs.singular.function import singular_function @@ -3453,16 +3453,16 @@ def std(self): EXAMPLES:: - 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 + 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) # optional - sage.combinat sage.modules - sage: I.std() #random # 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.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 + 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] @@ -3470,35 +3470,35 @@ def std(self): 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]) # optional - sage.combinat sage.modules - sage: JL #random # optional - sage.combinat sage.modules + 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 + sage: sorted(JL.gens(), key=str) # optional - sage.combinat sage.modules [x^3, y^3, z^3 - 4*z] - sage: JL.std() #random # 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: sorted(JL.std().gens(), key=str) # optional - sage.combinat sage.modules + 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') # optional - sage.combinat sage.modules - sage: JT #random # optional - sage.combinat sage.modules + 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 + sage: sorted(JT.gens(), key=str) # optional - sage.combinat sage.modules [x^3, y^3, z^3 - 4*z] - sage: JT.std() #random # 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} - sage: sorted(JT.std().gens(), key=str) # optional - sage.combinat sage.modules + 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 + sage: JT.std() == JL.twostd() # optional - sage.combinat sage.modules True ALGORITHM: Uses Singular's std command @@ -3515,21 +3515,23 @@ def elimination_ideal(self, variables): EXAMPLES:: - 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 + 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) # 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, + 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() # optional - sage.combinat sage.modules - sage: J # optional - sage.combinat sage.modules + sage: J = I.twostd() # optional - sage.combinat sage.modules + sage: 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, + 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: {...} @@ -3550,15 +3552,15 @@ def twostd(self): EXAMPLES:: - 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 + 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) # optional - sage.combinat sage.modules - sage: I.twostd() #random # 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.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 + 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 @@ -3577,10 +3579,10 @@ def _groebner_strategy(self): EXAMPLES:: - 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 + 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} @@ -3605,24 +3607,26 @@ def reduce(self,p): EXAMPLES:: - 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, side='twosided') # optional - sage.combinat sage.modules - 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 + 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, side='twosided') # optional - sage.combinat sage.modules + 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() # optional - sage.combinat sage.modules + 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) # optional - sage.combinat sage.modules + sage: I.reduce(z^2) # optional - sage.combinat sage.modules 1 """ @@ -3634,15 +3638,15 @@ def _contains_(self,p): We define a left and a two-sided ideal:: - 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 + 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 + 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, @@ -3651,9 +3655,9 @@ def _contains_(self,p): 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 # optional - sage.combinat sage.modules + sage: x*y^2-y*z in JL #indirect doctest # optional - sage.combinat sage.modules False - sage: x*y^2-y*z in JT # optional - sage.combinat sage.modules + sage: x*y^2-y*z in JT # optional - sage.combinat sage.modules True """ @@ -3673,12 +3677,12 @@ def syzygy_module(self): EXAMPLES:: - 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 + 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) # optional - sage.combinat sage.modules - sage: G = vector(I.gens()); G # 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: 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. @@ -3690,7 +3694,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 # optional - sage.combinat sage.modules + 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] @@ -3701,7 +3705,7 @@ 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 # optional - sage.combinat sage.modules + sage: M*G # optional - sage.combinat sage.modules (0, 0, 0, 0, 0, 0, 0, 0, 0) ALGORITHM: Uses Singular's syz command @@ -3728,12 +3732,12 @@ def res(self, length): EXAMPLES:: - 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 + 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) # optional - sage.combinat sage.modules - sage: I.res(3) # 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.res(3) # optional - sage.combinat sage.modules """ if self.side() == 'twosided': @@ -3763,8 +3767,8 @@ def __init__(self, ring, gens, coerce=True): 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)[] # optional - sage.libs.pari - sage: R.ideal([x0^2, x1^3]) # optional - sage.libs.pari + 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) @@ -3850,22 +3854,22 @@ def __richcmp__(self, other, op): :: - sage: R. = GF(32003)[] # optional - sage.libs.pari - sage: I = R*[x^2 + x, y] # optional - sage.libs.pari - sage: J = R*[x + 1, y] # optional - sage.libs.pari - sage: J < I # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: I < J # optional - sage.rings.finite_rings True :: - sage: R. = GF(32003)[] # optional - sage.libs.pari - sage: I = R*[x^2 + x, y] # optional - sage.libs.pari - sage: J = R*[x + 1, y] # optional - sage.libs.pari - sage: J > I # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: I > J # optional - sage.rings.finite_rings False :: @@ -3903,15 +3907,15 @@ def __richcmp__(self, other, op): We test to make sure that pickling works with the cached Groebner basis:: - sage: R. = GF(32003)[] # optional - sage.libs.pari - sage: I = R*[x^2 + x, y] # optional - sage.libs.pari - sage: J = R*[x + 1, y] # optional - sage.libs.pari - sage: J >= I # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: I >= J # optional - sage.rings.finite_rings False - sage: loads(dumps(I)).__getstate__() # optional - sage.libs.pari + 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, @@ -4277,31 +4281,31 @@ 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) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.libs.pari - sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: I.groebner_basis('macaulay2:f4') # optional - macaulay2 # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: I.groebner_basis('macaulay2:mgb') # optional - macaulay2 # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.libs.pari - sage: I.groebner_basis('msolve') # optional - msolve # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma # optional - sage.libs.pari + 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 @@ -4474,54 +4478,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') # 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 + 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 # optional - sage.rings.number_field - sage: I.groebner_basis('libsingular:groebner') # 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('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 # optional - sage.rings.number_field - sage: I.groebner_basis('libsingular:std') # 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('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 # optional - sage.rings.number_field - sage: I.groebner_basis('libsingular:stdhilb') # 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('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 # optional - sage.rings.number_field - sage: I.groebner_basis('libsingular:stdfglm') # 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('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 # optional - sage.rings.number_field - sage: I.groebner_basis('libsingular:slimgb') # 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('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 # 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 + 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 # optional - sage.rings.number_field - sage: I.groebner_basis('toy:buchberger2') # 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('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 # optional - sage.rings.number_field - sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 # 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('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 # optional - sage.rings.number_field - sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma # 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('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') # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.libs.pari - sage: I.groebner_basis('msolve') # optional - msolve # optional - sage.libs.pari + 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()) @@ -4868,28 +4872,28 @@ def homogenize(self, var='h'): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) # optional - sage.libs.pari - sage: I = Ideal([x^2*y + z + 1, x + y^2 + 1]); I # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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]) # optional - sage.libs.pari - sage: I.homogenize() # optional - sage.libs.pari + 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 @@ -4965,51 +4969,51 @@ def degree_of_semi_regularity(self): We consider a homogeneous example:: sage: n = 8 - sage: K = GF(127) # optional - sage.libs.pari - sage: P = PolynomialRing(K, n, 'x') # optional - sage.libs.pari - sage: s = [K.random_element() for _ in range(n)] # optional - sage.libs.pari - sage: L = [] # optional - sage.libs.pari - sage: for i in range(2 * n): # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: I.degree_of_semi_regularity() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + 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): # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: I.degree_of_semi_regularity() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + 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): # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: I.degree_of_semi_regularity() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 2 .. NOTE:: @@ -5175,12 +5179,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)[] # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: f = I.random_element(degree=4, compute_gb=True, terms=infinity) # optional - sage.libs.pari - sage: f.degree() <= 4 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 @@ -5188,43 +5192,43 @@ 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') # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(P) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: F = Sequence(I.random_element(degree=d, compute_gb=True, terms=infinity) # optional - sage.rings.finite_rings ....: for _ in range(n^d)) 2. We linearize and compute the echelon form:: - sage: A, v = F.coefficient_matrix() # optional - sage.libs.pari - sage: A.echelonize() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari - sage: G.is_groebner() # optional - sage.libs.pari + 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.libs.pari + 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') # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: f = I.random_element(degree=3) # optional - sage.libs.pari - sage: f # random # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: G = Sequence([x+7, y-2, z+110]) # optional - sage.libs.pari - sage: I = Ideal([sum(P.random_element() * g for g in G) for _ in range(4)]) # optional - sage.libs.pari - sage: all(I.random_element(degree=1) == 0 for _ in range(100)) # optional - sage.libs.pari + 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) for _ in range(4)]) # optional - sage.rings.finite_rings + 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 @@ -5289,33 +5293,33 @@ def weil_restriction(self): EXAMPLES:: - sage: k. = GF(2^2) # optional - sage.libs.pari - sage: P. = PolynomialRing(k, 2) # optional - sage.libs.pari - sage: I = Ideal([x*y + 1, a*x + 1]) # optional - sage.libs.pari - sage: I.variety() # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: J # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: J.variety() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: P. = PolynomialRing(k) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: I.dimension() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: I.variety() # optional - sage.rings.finite_rings [{z: 0, y: 0, x: 1}] - sage: J = I.weil_restriction(); J # optional - sage.libs.pari + 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 @@ -5335,9 +5339,9 @@ def weil_restriction(self): 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.libs.pari + 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())) # optional - sage.libs.pari + 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}] diff --git a/src/sage/rings/polynomial/multi_polynomial_ring.py b/src/sage/rings/polynomial/multi_polynomial_ring.py index 26658f081d4..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)[] # optional - sage.libs.pari - sage: frob = R.hom([x^5, y^5, z^5]) # optional - sage.libs.pari - sage: frob(x^2 + 2*y - z^4) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: f = R(T.0^2 - 4*T.1^3); f # optional - sage.rings.finite_rings 3*y^3 + x^2 - sage: parent(f) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: S. = PolynomialRing(GF(7),2) # optional - sage.rings.finite_rings sage: f = x^2 + 2/3*y^3 - sage: S(f) # optional - sage.libs.pari + 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') # optional - sage.symbolic - sage: R = QQ['x,y,z'] # optional - sage.symbolic - sage: type(x) # optional - sage.symbolic + 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)) # optional - sage.symbolic + sage: type(R(x)) # optional - sage.symbolic - sage: f = R(x^3 + y^3 - z^3); f # optional - sage.symbolic + sage: f = R(x^3 + y^3 - z^3); f # optional - sage.symbolic x^3 + y^3 - z^3 - sage: type(f) # optional - sage.symbolic + sage: type(f) # optional - sage.symbolic - sage: parent(f) # optional - sage.symbolic + 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 # optional - sage.symbolic + 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) # optional - sage.symbolic + sage: g = R(f); parent(g) # optional - sage.symbolic Multivariate Polynomial Ring in x, y, z over Rational Field - sage: (f - g).expand() # optional - sage.symbolic + 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'] # optional - sage.libs.pari + sage: R = GF(5)['x,y,z'] # optional - sage.rings.finite_rings sage: S = ZZ['y'] - sage: R(7*S.0) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 a2a4e4a925a..c4273a54811 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -399,7 +399,7 @@ 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) # optional - sage.modules + sage: R.interpolation(4, F) # optional - sage.modules x^3*y + z^2 + y + 25 @@ -407,7 +407,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): ....: return a^3*b + b + c^2 + 25 ....: sage: R. = PolynomialRing(QQ) - sage: R.interpolation([3,1,2], F) # optional - sage.modules + sage: R.interpolation([3,1,2], F) # optional - sage.modules x^3*y + z^2 + y + 25 @@ -419,7 +419,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]) # optional - sage.modules + sage: R.interpolation([3,1,2], points, [F(*x) for x in points]) # optional - sage.modules x^3*y + z^2 + y + 25 ALGORITHM: @@ -453,7 +453,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): ....: return a^3*b + b + c^2 + 25 ....: sage: R. = PolynomialRing(QQ) - sage: R.interpolation(3, F) # optional - sage.modules + sage: R.interpolation(3, F) # optional - sage.modules 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25 .. SEEALSO:: @@ -583,13 +583,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) # 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 + 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 # optional - sage.rings.number_field + sage: x + 1/u # optional - sage.rings.number_field x + 1/u """ try: @@ -740,33 +740,33 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) # optional - sage.libs.pari - sage: R._magma_init_(magma) # optional - magma # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: magma(R) # optional - magma # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 +800,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - 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 + 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) # optional - sage.rings.number_field + sage: libgap(P) # optional - sage.rings.number_field [x,y] """ L = ['"%s"' % t for t in self.variable_names()] @@ -862,8 +862,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) # optional - sage.libs.pari - sage: R.characteristic() # optional - sage.libs.pari + 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() @@ -1347,11 +1347,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: P. = PolynomialRing(GF(127), 3, order='lex') # optional - sage.libs.pari - sage: x > y^2 # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: x > y^2 # optional - sage.libs.pari + 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: @@ -1572,7 +1572,7 @@ 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]) # optional - sage.modules + sage: R.macaulay_resultant([y, x+z]) # optional - sage.modules Traceback (most recent call last): ... TypeError: number of polynomials(= 2) must equal number of @@ -1581,7 +1581,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The polynomials need to be all homogeneous:: sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y, x+z, z+x^3]) # optional - sage.modules + 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 @@ -1591,7 +1591,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: S. = PolynomialRing(QQ, 2) sage: R. = PolynomialRing(QQ,3) - sage: S.macaulay_resultant([y, z+x]) # optional - sage.modules + 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 @@ -1600,7 +1600,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: K. = PolynomialRing(ZZ, 2) sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,2]) - sage: R.macaulay_resultant(flist) # optional - sage.modules + 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 - @@ -1613,7 +1613,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: K. = PolynomialRing(ZZ, 2) sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,1]) - sage: R.macaulay_resultant(flist) # optional - sage.modules + 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,31 +1624,31 @@ 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]) # optional - sage.modules + 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]) # optional - sage.modules + 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]) # optional - sage.modules + 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]) # optional - sage.modules + 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) # optional - sage.modules + 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:: @@ -1663,7 +1663,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): char polynomials of numerator/denominator):: sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y, x+z, z^2]) # optional - sage.modules + sage: R.macaulay_resultant([y, x+z, z^2]) # optional - sage.modules -1 When there are only 2 polynomials, macaulay resultant degenerates @@ -1674,7 +1674,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() - sage: f.resultant(g) == RH.macaulay_resultant([fh,gh]) # optional - sage.modules + sage: f.resultant(g) == RH.macaulay_resultant([fh,gh]) # optional - sage.modules True """ @@ -1754,9 +1754,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: sage: R = QQ['x,y,z'] - sage: W = R.weyl_algebra(); W # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules + sage: W.polynomial_ring() == R # optional - sage.combinat sage.modules True """ from sage.algebras.weyl_algebra import DifferentialWeylAlgebra diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 452d3932ce8..d5ee0395a35 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -219,12 +219,12 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): EXAMPLES:: - sage: P. = PolynomialRing(GF(127), 4) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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, @@ -233,12 +233,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() # optional - sage.libs.pari + sage: F.nparts() # optional - sage.rings.finite_rings 2 If an ideal is provided, the generators are used:: - sage: Sequence(I) # optional - sage.libs.pari + 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, @@ -246,22 +246,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 # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: F.nparts() # optional - sage.rings.finite_rings 1 We test that the ring is inferred correctly:: - sage: P. = GF(2)[] # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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: @@ -270,10 +270,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) # optional - sage.libs.pari - sage: L. = PowerSeriesRing(F,'t') # optional - sage.libs.pari - sage: R. = PolynomialRing(L,'x,y') # optional - sage.libs.pari - sage: PolynomialSequence([0], R) # optional - sage.libs.pari + 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`):: @@ -385,23 +385,23 @@ def __init__(self, parts, ring, immutable=False, cr=False, cr_str=None): EXAMPLES:: - sage: P. = PolynomialRing(GF(127), 4) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + 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] """ @@ -417,11 +417,11 @@ def __copy__(self): EXAMPLES:: - 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 + 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)) # optional - sage.rings.polynomial.pbori + sage: type(F) == type(copy(F)) # optional - sage.rings.polynomial.pbori True """ return self.__class__(self._parts, self._ring, immutable=self.is_immutable()) @@ -432,9 +432,9 @@ def ring(self): EXAMPLES:: - 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 + 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 @@ -453,9 +453,9 @@ def nparts(self): EXAMPLES:: - 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 + 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) @@ -466,10 +466,10 @@ def parts(self): EXAMPLES:: - 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 + 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) @@ -480,10 +480,10 @@ def part(self, i): EXAMPLES:: - 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 + 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] @@ -494,14 +494,14 @@ def ideal(self): EXAMPLES:: - 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 + 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:]) # optional - sage.rings.polynomial.pbori + sage: set(J.gens().variables()).issubset(P.gens()[:4] + P.gens()[-4:]) # optional - sage.rings.polynomial.pbori True """ return self._ring.ideal(tuple(self)) @@ -521,10 +521,10 @@ def groebner_basis(self, *args, **kwargs): EXAMPLES:: - 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 + 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: @@ -532,12 +532,12 @@ def groebner_basis(self, *args, **kwargs): Check that this method also works for boolean polynomials (:trac:`10680`):: - 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 + 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]) # optional - sage.rings.polynomial.pbori - sage: F1.groebner_basis() # optional - sage.rings.polynomial.pbori + 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) @@ -548,9 +548,9 @@ def monomials(self): EXAMPLES:: - 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 + 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() @@ -565,9 +565,9 @@ def nmonomials(self): EXAMPLES:: - 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 + 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()) @@ -579,9 +579,9 @@ def variables(self): EXAMPLES:: - 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 + 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() @@ -596,9 +596,9 @@ def nvariables(self): EXAMPLES:: - 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 + 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()) @@ -639,13 +639,13 @@ def algebraic_dependence(self): :: - sage: R. = PolynomialRing(GF(7)) # optional - sage.libs.pari - sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) # optional - sage.libs.pari - sage: I = S.algebraic_dependence(); I # optional - sage.libs.pari + 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.libs.pari + sage: [F(S) for F in I.gens()] # optional - sage.rings.finite_rings [0] .. NOTE:: @@ -706,23 +706,23 @@ def coefficient_matrix(self, sparse=True): EXAMPLES:: - sage: P. = PolynomialRing(GF(127), 4) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: I.gens() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: A,v = F.coefficient_matrix() # optional - sage.libs.pari - sage: A # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: v # optional - sage.rings.finite_rings [a^2] [a*b] [b^2] @@ -738,7 +738,7 @@ def coefficient_matrix(self, sparse=True): [ d] [ 1] - sage: A*v # optional - sage.libs.pari + 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] @@ -778,10 +778,10 @@ def subs(self, *args, **kwargs): EXAMPLES:: - 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 + 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 # optional - sage.rings.polynomial.pbori + 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]) @@ -792,14 +792,14 @@ def _singular_(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: F = Sequence(I); F # optional - sage.libs.pari + 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_() # optional - sage.libs.pari + 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, @@ -814,10 +814,10 @@ def _magma_init_(self, magma): EXAMPLES:: - 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 + 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 @@ -836,9 +836,9 @@ def _repr_(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: F = Sequence(I); F # indirect doctest # optional - sage.libs.pari + 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, @@ -847,8 +847,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) # optional - sage.rings.polynomial.pbori - sage: F,s = sr.polynomial_system(); F # optional - sage.rings.polynomial.pbori + 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 """ @@ -864,24 +864,24 @@ def __add__(self, right): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari - sage: F = Sequence(I) # optional - sage.libs.pari - sage: F + [a^127 + a] # optional - sage.libs.pari + 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]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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, @@ -908,9 +908,9 @@ def connection_graph(self): EXAMPLES:: - sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori - sage: F = Sequence([x*y + y + 1, z + 1]) # optional - sage.rings.polynomial.pbori - sage: F.connection_graph() # optional - sage.rings.polynomial.pbori + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([x*y + y + 1, z + 1]) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph() # optional - sage.rings.polynomial.pbori Graph on 3 vertices """ V = sorted(self.variables()) @@ -934,15 +934,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) # optional - sage.rings.polynomial.pbori - sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori + 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)) # optional - sage.rings.polynomial.pbori - sage: Fz.connected_components() # optional - sage.rings.polynomial.pbori + 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, @@ -969,9 +969,9 @@ def _groebner_strategy(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) # optional - sage.libs.pari - sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.libs.pari - sage: F._groebner_strategy() # optional - sage.libs.pari + 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 """ @@ -984,13 +984,13 @@ def maximal_degree(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(7)) # optional - sage.libs.pari - sage: F = Sequence([x*y + x, x]) # optional - sage.libs.pari - sage: F.maximal_degree() # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: F = Sequence([], universe=P) # optional - sage.libs.pari - sage: F.maximal_degree() # optional - sage.libs.pari + 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 """ @@ -1003,15 +1003,15 @@ def __reduce__(self): """ TESTS:: - sage: P. = PolynomialRing(GF(127)) # optional - sage.libs.pari - sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.libs.pari - sage: loads(dumps(F)) == F # indirect doctest # optional - sage.libs.pari + 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]) # optional - sage.libs.pari - sage: hash(f) == hash(loads(dumps(f))) # optional - sage.libs.pari + 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 """ @@ -1130,12 +1130,12 @@ def is_groebner(self, singular=singular): EXAMPLES:: - sage: R. = PolynomialRing(GF(127), 10) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Cyclic(R, 4) # optional - sage.libs.pari - sage: I.basis.is_groebner() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari - sage: I2.basis.is_groebner() # optional - sage.libs.pari + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.finite_rings + sage: I2.basis.is_groebner() # optional - sage.rings.finite_rings True """ @@ -1194,37 +1194,37 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc EXAMPLES:: - 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: 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) # optional - sage.rings.polynomial.pbori + 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') # optional - sage.rings.polynomial.pbori + 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``:: - 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: 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 # optional - sage.rings.polynomial.pbori + 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 and the list of reductors is empty:: - 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 + 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() # 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 + 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], []) @@ -1232,29 +1232,29 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc The function should really dispose of linear equations (:trac:`13968`):: - 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 + 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() # 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 + 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() # 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 + 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() # optional - sage.rings.polynomial.pbori - sage: f = a*d + a + b*d + c*d + 1 # optional - sage.rings.polynomial.pbori + 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] @@ -1336,15 +1336,15 @@ def _groebner_strategy(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) # optional - sage.libs.pari - sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.libs.pari - sage: F._groebner_strategy() # optional - sage.libs.pari + 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() # 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 + 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 @@ -1400,63 +1400,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() # 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 + 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]) # optional - sage.rings.polynomial.pbori + sage: S.subs(sol[0]) # optional - sage.rings.polynomial.pbori [0, 0, 0] We obtain all solutions:: - sage: sols = S.solve(n=Infinity) # optional - sage.rings.polynomial.pbori - sage: print(reproducible_repr(sols)) # optional - sage.rings.polynomial.pbori + 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] # optional - sage.rings.polynomial.pbori + 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 # optional - sage.rings.polynomial.pbori - sage: print(reproducible_repr(sol)) # optional - FES # optional - sage.rings.polynomial.pbori + 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]) # optional - FES # optional - sage.rings.polynomial.pbori + 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 # optional - sage.rings.polynomial.pbori - sage: print(reproducible_repr(sol)) # optional - pycryptosat # optional - sage.rings.polynomial.pbori + 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]) # optional - sage.rings.polynomial.pbori + 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() # 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 + 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) # optional - sage.rings.polynomial.pbori - sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori + 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() # 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 + 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 [] """ @@ -1534,17 +1534,17 @@ def reduced(self): EXAMPLES:: - 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 + 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() # optional - sage.rings.polynomial.pbori - sage: len(g) == len(set(gi.lt() for gi in g)) # optional - sage.rings.polynomial.pbori + 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)): # optional - sage.rings.polynomial.pbori + sage: for i in range(len(g)): # optional - sage.rings.polynomial.pbori ....: for j in range(len(g)): ....: if i == j: ....: continue @@ -1582,27 +1582,27 @@ def weil_restriction(self): EXAMPLES:: - sage: k. = GF(2^2) # optional - sage.libs.pari - sage: P. = PolynomialRing(k, 2) # optional - sage.libs.pari - sage: a = P.base_ring().gen() # optional - sage.libs.pari - sage: F = Sequence([x*y + 1, a*x + 1], P) # optional - sage.libs.pari - sage: F2 = F.weil_restriction() # optional - sage.libs.pari - sage: F2 # optional - sage.libs.pari + 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] Another bigger example for a small scale AES:: - 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 + 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 # optional - sage.rings.polynomial.pbori + sage: F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: F2 = F.weil_restriction(); F2 # optional - sage.rings.polynomial.pbori + 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 3cc489dd325..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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - 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.libs.pari - sage: b = (2*t^2 + 3)*x^2 + (3*t^2 + 1)*x + 4*t + 2 # optional - sage.libs.pari - sage: q, r = a.left_quo_rem(b) # optional - sage.libs.pari - sage: q # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: r # optional - sage.rings.finite_rings (t + 2)*x + 3*t^2 + 2*t + 4 - sage: a == b*q + r # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: b = (x + t) * (t*x + t + 1) * (x + t^2) # optional - sage.libs.pari - sage: a.right_gcd(b) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_right_divisible_by(b) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: d.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: d.is_left_divisible_by(b) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: OrePolynomialBaseringInjection(k, k['x', Frob]) #indirect doctest # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = x + t # optional - sage.libs.pari - sage: a[1] = t + 1 # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - 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.libs.pari - sage: b = a.left_monic(); b # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: b.degree() == a.degree() # optional - sage.rings.finite_rings True - sage: b.is_left_divisible_by(a) # optional - sage.libs.pari + sage: b.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: twist = S.twisting_morphism(-a.degree()) # optional - sage.libs.pari - sage: a == b * twist(a.leading_coefficient()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - 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.libs.pari - sage: b = a.right_monic(); b # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: b.degree() == a.degree() # optional - sage.rings.finite_rings True - sage: b.is_right_divisible_by(a) # optional - sage.libs.pari + sage: b.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: a == a.leading_coefficient() * b # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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,13 +635,13 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: R. = GF(11)[] # optional - sage.libs.pari - sage: der = R.derivation() # optional - sage.libs.pari - sage: S. = R['x', der] # optional - sage.libs.pari - sage: f = t/x # optional - sage.libs.pari - sage: f # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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 """ @@ -697,20 +697,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = x^2 + t*x + t^2 + 3 # optional - sage.libs.pari - sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.libs.pari - sage: c = a*b # optional - sage.libs.pari - sage: c.is_right_divisible_by(a) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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 @@ -746,20 +746,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = x^2 + t*x + t^2 + 3 # optional - sage.libs.pari - sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.libs.pari - sage: c = a*b # optional - sage.libs.pari - sage: a.left_divides(c) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: b.left_divides(c) # optional - sage.rings.finite_rings False Divisibility by `0` does not make sense:: - sage: S(0).left_divides(c) # optional - sage.libs.pari + sage: S(0).left_divides(c) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -781,20 +781,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = x^2 + t*x + t^2 + 3 # optional - sage.libs.pari - sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.libs.pari - sage: c = a*b # optional - sage.libs.pari - sage: a.right_divides(c) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: b.right_divides(c) # optional - sage.rings.finite_rings True Divisibility by `0` does not make sense:: - sage: S(0).right_divides(c) # optional - sage.libs.pari + sage: S(0).right_divides(c) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -859,21 +859,21 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = (x + t) * (x^2 + t*x + 1) # optional - sage.libs.pari - sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) # optional - sage.libs.pari - sage: g,u,v = a.left_xgcd(b); g # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: a*u + b*v == g # optional - sage.rings.finite_rings True The base ring must be a field:: @@ -962,13 +962,13 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - 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.libs.pari - sage: b = (3*t^2 + 4*t + 2)*x^2 + (2*t^2 + 4*t + 3)*x + 2*t^2 + t + 1 # optional - sage.libs.pari - sage: q,r = a.left_quo_rem(b) # optional - sage.libs.pari - sage: a == b*q + r # optional - sage.libs.pari + 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 @@ -1091,21 +1091,21 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = (x^2 + t*x + 1) * (x + t) # optional - sage.libs.pari - sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) # optional - sage.libs.pari - sage: g,u,v = a.right_xgcd(b); g # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: u*a + v*b == g # optional - sage.rings.finite_rings True The base ring must be a field:: @@ -1174,17 +1174,17 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = (x^2 + t*x + 1) * (x + t) # optional - sage.libs.pari - sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) # optional - sage.libs.pari - sage: a.right_gcd(b) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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:: @@ -1241,22 +1241,22 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = (x + t) * (x^2 + t*x + 1) # optional - sage.libs.pari - sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) # optional - sage.libs.pari - sage: a.left_gcd(b) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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[] # optional - sage.libs.pari + 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) @@ -1302,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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism(3) # optional - sage.libs.pari - sage: S. = k['x', Frob] # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: P = S.random_element(degree=2) * D # optional - sage.libs.pari - sage: Q = S.random_element(degree=2) * D # optional - sage.libs.pari - sage: L = P.left_lcm(Q) # optional - sage.libs.pari - sage: U = left_lcm_cofactor(P, Q) # optional - sage.misc.cython # optional - sage.libs.pari - sage: (U*P).right_monic() == L # optional - sage.misc.cython # optional - sage.libs.pari + 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 @@ -1345,18 +1345,18 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: P = (x + t^2) * (x + t) # optional - sage.libs.pari - sage: Q = 2 * (x^2 + t + 1) * (x * t) # optional - sage.libs.pari - sage: L, U, V = P.left_xlcm(Q) # optional - sage.libs.pari - sage: L # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: U*P == L # optional - sage.rings.finite_rings True - sage: V*Q == L # optional - sage.libs.pari + sage: V*Q == L # optional - sage.rings.finite_rings True """ if self.base_ring() not in _Fields: @@ -1380,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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism(3) # optional - sage.libs.pari - sage: S. = k['x', Frob] # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: P = D * S.random_element(degree=2) # optional - sage.libs.pari - sage: Q = D * S.random_element(degree=2) # optional - sage.libs.pari - sage: L = P.right_lcm(Q) # optional - sage.libs.pari - sage: U = right_lcm_cofactor(P, Q) # optional - sage.misc.cython # optional - sage.libs.pari - sage: (P*U).left_monic() == L # optional - sage.misc.cython # optional - sage.libs.pari + 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 @@ -1430,17 +1430,17 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: P = (x + t) * (x + t^2) # optional - sage.libs.pari - sage: Q = 2 * (x + t) * (x^2 + t + 1) # optional - sage.libs.pari - sage: L, U, V = P.right_xlcm(Q) # optional - sage.libs.pari - sage: L # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: P*U == L # optional - sage.rings.finite_rings True - sage: Q*V == L # optional - sage.libs.pari + sage: Q*V == L # optional - sage.rings.finite_rings True """ if self.base_ring() not in _Fields: @@ -1485,23 +1485,23 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = (x + t^2) * (x + t) # optional - sage.libs.pari - sage: b = 2 * (x^2 + t + 1) * (x * t) # optional - sage.libs.pari - sage: c = a.left_lcm(b); c # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_right_divisible_by(b) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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:: @@ -1555,23 +1555,23 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = (x + t) * (x + t^2) # optional - sage.libs.pari - sage: b = 2 * (x + t) * (x^2 + t + 1) # optional - sage.libs.pari - sage: c = a.right_lcm(b); c # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: c.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_left_divisible_by(b) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 @@ -2053,12 +2053,12 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: a = 1 + t*x^2 # optional - sage.libs.pari - sage: b = x + 1 # optional - sage.libs.pari - sage: a.left_mod(b) # optional - sage.libs.pari + 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) @@ -2854,55 +2854,55 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): EXAMPLES:: - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: der = R.derivation() # optional - sage.libs.pari - sage: A. = R['d', der] # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: L.hilbert_shift(t) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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') # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x', Frob] # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: Q = P.hilbert_shift(a); Q # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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.libs.pari + 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) # optional - sage.libs.pari - sage: V = S.random_element(degree=5) # optional - sage.libs.pari - sage: s = k.random_element() # optional - sage.libs.pari - sage: (U+V).hilbert_shift(s) == U.hilbert_shift(s) + V.hilbert_shift(s) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: s = k.random_element() # optional - sage.libs.pari - sage: P.hilbert_shift(s).hilbert_shift(-s) == P # optional - sage.libs.pari + 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 @@ -3004,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""" @@ -3020,10 +3021,10 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.libs.pari + 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 @@ -3047,11 +3048,11 @@ cdef class OrePolynomialBaseringInjection(Morphism): EXAMPLES:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.libs.pari - sage: m.an_element() # optional - sage.libs.pari + 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 @@ -3072,13 +3073,13 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.libs.pari - sage: m(4) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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: @@ -3094,11 +3095,11 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.libs.pari - sage: m.section() # optional - sage.libs.pari + 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 03dce6f9fdb..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']) # optional - sage.libs.pari + sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) # optional - sage.rings.finite_rings 'x' """ if not self: @@ -1075,8 +1075,8 @@ cdef class PolyDict: 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! # optional - sage.groups - sage: f = PolyDict({(2, 3): x}) # optional - sage.groups - sage: f.scalar_rmult(y) # 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) @@ -1097,8 +1097,8 @@ cdef class PolyDict: 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! # optional - sage.groups - sage: f = PolyDict({(2,3):x}) # optional - sage.groups - sage: f.scalar_lmult(y) # 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) @@ -1126,8 +1126,8 @@ cdef class PolyDict: 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! # optional - sage.groups - sage: f = PolyDict({(2, 3): x}) # optional - sage.groups - sage: f.term_lmult(ETuple((1, 2)), y) # 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}) @@ -1155,8 +1155,8 @@ cdef class PolyDict: 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! # optional - sage.groups - sage: f = PolyDict({(2, 3): x}) # optional - sage.groups - sage: f.term_rmult(ETuple((1, 2)), y) # 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 3c4a8389dbf..515338982e2 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -296,12 +296,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R = GF(2)['x']['y'] # optional - sage.libs.pari - sage: R([0,1]).is_zero() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: R([0]).is_zero() # optional - sage.rings.finite_rings True - sage: R([-1]).is_zero() # optional - sage.libs.pari + sage: R([-1]).is_zero() # optional - sage.rings.finite_rings False """ return self.degree() < 0 @@ -346,11 +346,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: x = polygen(GF(389)) # optional - sage.libs.pari - sage: plot(x^2 + 1, rgbcolor=(0,0,1)) # optional - sage.libs.pari sage.plot + 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)) # optional - sage.plot + sage: plot(x^2 + 1, rgbcolor=(1,0,0)) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ R = self.base_ring() @@ -486,12 +486,12 @@ cdef class Polynomial(CommutativePolynomial): We evaluate a polynomial over a quaternion algebra:: - 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 + 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 # optional - sage.combinat sage.modules + 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 +502,28 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = R(2/3) - sage: a = matrix(ZZ, 2) # optional - sage.combinat sage.modules - sage: b = f(a); b # optional - sage.combinat sage.modules + 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() # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules + sage: b = f(a); b # optional - sage.combinat sage.modules [1 0] [0 1] - sage: b.parent() # optional - sage.combinat sage.modules + sage: b.parent() # optional - sage.combinat sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field :: - sage: R. = GF(17)[] # optional - sage.libs.pari - sage: f = w^3 + 3*w +2 # optional - sage.libs.pari - sage: f(5) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f(w=5) # optional - sage.rings.finite_rings 6 - sage: f(x=10) # x isn't mentioned # optional - sage.libs.pari + 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 @@ -598,7 +598,7 @@ cdef class Polynomial(CommutativePolynomial): 3 sage: parent(f(0)) Rational Field - sage: parent(f(Qp(5)(0))) # optional - sage.rings.padics + sage: parent(f(Qp(5)(0))) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 TESTS: @@ -677,8 +677,8 @@ cdef class Polynomial(CommutativePolynomial): sage: one(1, 1.).parent() Real Field with 53 bits of precision - sage: zero = GF(2)['x'](0) # optional - sage.libs.pari - sage: zero(1.).parent() # should raise an error # optional - sage.libs.pari + 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 +707,37 @@ cdef class Polynomial(CommutativePolynomial): These were drastically slower prior to :trac:`33165`:: - sage: R. = GF(31337)[] # optional - sage.libs.pari - sage: f = R(list(range(100, 201))) # optional - sage.libs.pari - sage: g = R(list(range(1, 1001))) # optional - sage.libs.pari - sage: S. = R.quotient(f) # optional - sage.libs.pari - sage: g(y) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: g(z) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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])) # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: g(T.zero()) # optional - sage.rings.finite_rings 1 - sage: g(T(2)) # optional - sage.libs.pari + sage: g(T(2)) # optional - sage.rings.finite_rings 23069 :: - sage: U. = GF(31337)[] # optional - sage.libs.pari - sage: g(u) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: g(U.zero()) # optional - sage.rings.finite_rings 1 - sage: g(U(2)) # optional - sage.libs.pari + sage: g(U(2)) # optional - sage.rings.finite_rings -8268 Sparse tests for :trac:`33165`:: @@ -1188,21 +1188,21 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - 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 + 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() # optional - sage.rings.padics + 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) # optional - sage.rings.padics + sage: foo(x) # optional - sage.rings.padics (1 + O(2^20))*x """ return (self._parent,) + tuple(self) @@ -1239,9 +1239,9 @@ cdef class Polynomial(CommutativePolynomial): Verify that :trac:`16251` has been resolved, i.e., polynomials with unhashable coefficients are unhashable:: - sage: K. = Qq(9) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: hash(t) # optional - sage.rings.padics + 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' @@ -1431,8 +1431,8 @@ cdef class Polynomial(CommutativePolynomial): r""" EXAMPLES:: - sage: p = PolynomialRing(QQbar, 'x')(1+I) # optional - sage.rings.number_field - sage: complex(p) # optional - sage.rings.number_field + 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) @@ -1469,8 +1469,8 @@ cdef class Polynomial(CommutativePolynomial): The polynomial has to be over a field of characteristic 0 (see :trac:`24072`):: - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: f = SR(2*w^3 + 1); f # optional - sage.libs.pari sage.symbolic + 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 @@ -1557,22 +1557,22 @@ 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 # optional - sage.modules + 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) # optional - sage.modules + 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 # optional - sage.modules + 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 # optional - sage.modules + sage: f = inverse_mod(x^3 - x + 1, x - 2); f # optional - sage.modules 0.14285714285714285 - sage: f * (x^3 - x + 1) % (x - 2) # optional - sage.modules + 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 # optional - sage.modules + 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 # optional - sage.modules + sage: poly = f*g % m # optional - sage.modules sage: # Remove noisy zero terms: - sage: parent(poly)([0.0 if abs(c) <= epsilon else c # abs tol 1e-14 # optional - sage.modules + 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 @@ -1680,14 +1680,14 @@ cdef class Polynomial(CommutativePolynomial): Even noncommutative ones:: - 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 + 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) # optional - sage.modules - sage: (p*q).truncate(13) == M.one() # optional - sage.modules + sage: q = p.inverse_series_trunc(13) # optional - sage.modules + sage: (p*q).truncate(13) == M.one() # optional - sage.modules True TESTS:: @@ -1771,20 +1771,20 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - 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 + 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)) # optional - sage.modules + 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)) # optional - sage.modules + sage: list((a*x + 1)*(b*x)) # optional - sage.modules [ [0 0] [1 2] [1 2] [0 0], [3 4], [0 0] @@ -1916,11 +1916,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)) # optional - sage.libs.pari - sage: x.squarefree_decomposition() # optional - sage.libs.pari + 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) # optional - sage.rings.number_field - sage: f.squarefree_decomposition() # optional - sage.rings.number_field + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.squarefree_decomposition() # optional - sage.rings.number_field 1 """ @@ -2028,73 +2028,73 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = GF(11)[] # optional - sage.libs.pari - sage: f = 7*x^7 + 8*x^6 + 4*x^5 + x^4 + 6*x^3 + 10*x^2 + 8*x + 5 # optional - sage.libs.pari - sage: f.any_root() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.any_root(GF(11^6, 'a')) # optional - sage.libs.pari + 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'))) # optional - sage.libs.pari + 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.libs.pari + 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) # optional - sage.libs.pari - sage: g.any_root(ring=GF(11^10, 'b'), degree=1) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: K. = GF(5^12) # optional - sage.libs.pari - sage: for _ in range(40): # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: x = polygen(K) # optional - sage.libs.pari - sage: r = (x**2+x+1).any_root() # used to loop # optional - sage.libs.pari - sage: r**2 + r # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: x = polygen(K) # optional - sage.libs.pari - sage: pol = x^1000000 + x + a # optional - sage.libs.pari - sage: alarm(0.5); pol.any_root() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: x = polygen(K) # optional - sage.libs.pari - sage: (x**10+x+a).any_root() # optional - sage.libs.pari + 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.libs.pari - sage: x = polygen(K) # optional - sage.libs.pari - sage: (x**10+x+a).any_root() # optional - sage.libs.pari + 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 @@ -2106,11 +2106,11 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`21998` has been resolved:: - sage: K. = GF(2^4) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: f = x^2 + x + a^2 + a # optional - sage.libs.pari - sage: r = f.any_root() # optional - sage.libs.pari - sage: r^2 + r # optional - sage.libs.pari + 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(): @@ -2304,9 +2304,9 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') # optional - sage.libs.pari - sage: f = x^3 + 4*x # optional - sage.libs.pari - sage: f / (x - 1) # optional - sage.libs.pari + 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):: @@ -2321,21 +2321,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`12217` is fixed:: - sage: P. = GF(5)[] # optional - sage.libs.pari - sage: x/0 # optional - sage.libs.pari + 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')[] # optional - sage.libs.pari - sage: x/5 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: int(1) / x # optional - sage.rings.finite_rings 1/x """ # Same parents => bypass coercion @@ -2368,10 +2368,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f^3 x^3 - 3*x^2 + 3*x - 1 - sage: R = PolynomialRing(GF(2), 'x') # optional - sage.libs.pari - sage: f = R(x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x) # optional - sage.libs.pari - sage: h = R(x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1) # optional - sage.libs.pari - sage: pow(f, 2, h) # optional - sage.libs.pari + 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:: @@ -2398,46 +2398,46 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: k = GF(5) # optional - sage.libs.pari - sage: D. = k[] # optional - sage.libs.pari - sage: l. = k.extension(x^2 + 2) # optional - sage.libs.pari - sage: R. = l[] # optional - sage.libs.pari - sage: f = t^4 + (2*x - 1)*t^3 + (2*x + 1)*t^2 + 3 # optional - sage.libs.pari - sage: h = t^4 - x*t^3 + (3*x + 1)*t^2 + 2*t + 2*x - 1 # optional - sage.libs.pari - sage: pow(f, 2, h) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: (1+x)^(5^10) # used to hang forever # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: R1. = PolynomialRing(S, sparse=True) # optional - sage.libs.pari - sage: (1+x+t)^(3^10) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: (1+x+t)^(3^10) # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: R2 = PolynomialRing(GF(9,'b'), 'x', sparse=True) # optional - sage.libs.pari - sage: R3 = PolynomialRing(R2, 'y') # optional - sage.libs.pari - sage: R4 = PolynomialRing(R1, 'y', sparse=True) # optional - sage.libs.pari - sage: for d in range(20,40): # long time # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: pow(x + 1, 51, x^7) # optional - sage.libs.pari + 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[] @@ -2448,10 +2448,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)[] # optional - sage.libs.pari - sage: k. = kk.quo(a^2+a+1) # optional - sage.libs.pari - sage: K. = k[] # optional - sage.libs.pari - sage: (T*y)^21 # optional - sage.libs.pari + 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): @@ -2543,20 +2543,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)[] # optional - sage.libs.pari - sage: p = x^2 - x + 1 # optional - sage.libs.pari - sage: q = p.power_trunc(80, 20) # optional - sage.libs.pari - sage: q # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: (p^80).truncate(20) == q # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: p = (x^2 + x + 1).power_trunc(2^100, 100) # optional - sage.libs.pari - sage: p # optional - sage.libs.pari + 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): # optional - sage.libs.pari + 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) @@ -2815,7 +2815,7 @@ cdef class Polynomial(CommutativePolynomial): # Verified R. = RR[] 3.1415926535897931*x - sage: sage_input(polygen(GF(7)) + 12, verify=True) # optional - sage.libs.pari + sage: sage_input(polygen(GF(7)) + 12, verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] x + 5 @@ -2924,14 +2924,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) # optional - sage.libs.pari - sage: R.inject_variables(verbose=False) # optional - sage.libs.pari - sage: A, B, C = a0 + a1*y + a2*y^2, b0 + b1*y + b2*y^2, c1*y + c2*y^2 # optional - sage.libs.pari - 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.libs.pari - sage: F = D.subs({y: B}) # optional - sage.libs.pari - sage: G = A.subs({y: F}) + C # optional - sage.libs.pari - sage: g = G.mod(y^8 + y) # optional - sage.libs.pari - sage: g.degree(y) # optional - sage.libs.pari + 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 @@ -3321,11 +3321,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 - 17*x + 3 - sage: f.base_extend(GF(7)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings x^3 + 4*x + 3 """ S = self._parent.base_extend(R) @@ -3358,17 +3358,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - 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.libs.pari # optional - sage.rings.number_field + 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) # 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 + 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 :: @@ -3390,10 +3390,10 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28541` is fixed:: - sage: F. = GF(7^2) # optional - sage.libs.pari - sage: S. = F[] # optional - sage.libs.pari - sage: P = x^2 + a*x + a^2 # optional - sage.libs.pari - sage: P.change_ring(F.frobenius_endomorphism()) # optional - sage.libs.pari + 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): @@ -3591,15 +3591,15 @@ cdef class Polynomial(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)[] # optional - sage.libs.pari - sage: x = R(0) # optional - sage.libs.pari - sage: x.denominator() # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: type(x.denominator()) # optional - sage.rings.finite_rings - sage: isinstance(x.numerator() / x.denominator(), Polynomial) # optional - sage.libs.pari + sage: isinstance(x.numerator() / x.denominator(), Polynomial) # optional - sage.rings.finite_rings True - sage: isinstance(x.numerator() / R(1), Polynomial) # optional - sage.libs.pari + sage: isinstance(x.numerator() / R(1), Polynomial) # optional - sage.rings.finite_rings False TESTS: @@ -3796,17 +3796,17 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28147` is fixed:: - sage: R. = GF(65537)[] # optional - sage.libs.pari - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 # optional - sage.libs.pari - sage: p.derivative() # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 # optional - sage.libs.pari - sage: p.derivative() # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: p = x^4 + x^2 + x # optional - sage.libs.pari - sage: p.derivative() # optional - sage.libs.pari + 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)[] @@ -3821,8 +3821,8 @@ cdef class Polynomial(CommutativePolynomial): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var("y") # optional - sage.symbolic - sage: f._derivative(y) # optional - sage.symbolic + 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 @@ -3830,21 +3830,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`26844` is fixed by :trac:`28147`:: - sage: A = PolynomialRing(GF(3), name='t') # optional - sage.libs.pari - sage: K = A.fraction_field() # optional - sage.libs.pari - sage: t = K.gen() # optional - sage.libs.pari - sage: t.derivative(t) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: x._derivative(2*x) # optional - sage.libs.pari + 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') # optional - sage.symbolic - sage: R.gen()._derivative(y) # optional - sage.libs.pari sage.symbolic + 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 @@ -3921,16 +3921,16 @@ cdef class Polynomial(CommutativePolynomial): This shows that the issue at :trac:`7711` is resolved:: - sage: P. = PolynomialRing(GF(2147483647)) # optional - sage.libs.pari - sage: Q. = PolynomialRing(P) # optional - sage.libs.pari - sage: p = x + y + z # optional - sage.libs.pari - sage: p.integral() # optional - sage.libs.pari + 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))) # optional - sage.libs.pari - sage: Q. = PolynomialRing(P) # optional - sage.libs.pari - sage: p = x + y + z # optional - sage.libs.pari - sage: p.integral() # optional - sage.libs.pari + 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:: @@ -4085,17 +4085,17 @@ cdef class Polynomial(CommutativePolynomial): We factor a non-monic polynomial over a finite field of 25 elements:: - sage: k. = GF(25) # optional - sage.libs.pari - sage: R. = k[] # optional - sage.libs.pari - sage: f = 2*x^10 + 2*x + 2*a # optional - sage.libs.pari - sage: F = f.factor(); F # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 @@ -4104,15 +4104,15 @@ cdef class Polynomial(CommutativePolynomial): used to easily extend polynomial factorization to work over new rings you introduce:: - sage: R. = PolynomialRing(IntegerModRing(4), implementation="NTL") # optional - sage.libs.ntl - sage: (x^2).factor() # optional - sage.libs.ntl + 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() # optional - sage.libs.pari x^2 - sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl + sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl Arbitrary precision real and complex factorization:: @@ -4254,9 +4254,9 @@ cdef class Polynomial(CommutativePolynomial): Factorization also works even if the variable of the finite field is nefariously labeled `x`:: - sage: R. = GF(3^2, 'x')[] # optional - sage.libs.pari - sage: f = x^10 +7*x -13 # optional - sage.libs.pari - sage: G = f.factor(); G # optional - sage.libs.pari + 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 @@ -4264,70 +4264,70 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = GF(9,'x')[] # purposely calling it x to test robustness # optional - sage.libs.pari - sage: f = x0^3 + x0 + 1 # optional - sage.libs.pari - sage: f.factor() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.factor() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.factor() # optional - sage.libs.pari + 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) # optional - sage.rings.number_field - sage: S. = K[] # optional - sage.rings.number_field - sage: ff = S(f); ff # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field - sage: len(F) # optional - sage.rings.number_field + sage: F = ff.factor() # optional - sage.rings.number_field + sage: len(F) # optional - sage.rings.number_field 4 - sage: F[:2] # optional - sage.rings.number_field + 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 + 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) # optional - sage.rings.number_field - sage: A. = K[] # optional - sage.rings.number_field - sage: A(x^2 - 1).factor() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: A(3*x^2 - 1).factor() # optional - sage.rings.number_field (3) * (T - a) * (T + a) :: - sage: A(x^2 - 1/3).factor() # optional - sage.rings.number_field + 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) # 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 + 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() # optional - sage.rings.number_field + sage: F = pol.factor() # optional - sage.rings.number_field Entering nffactor: ... @@ -4336,55 +4336,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) # optional - sage.rings.number_field - sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: pol.factor() # 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 # 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 # optional - sage.rings.number_field - sage: pol.factor() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: pol.factor() # optional - sage.rings.number_field + 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) # 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 + 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) # optional - sage.rings.number_field + 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()) # optional - sage.rings.number_field + 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) # 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 + 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) # optional - sage.rings.number_field + sage: factor(x^2 + 1) # optional - sage.rings.number_field x^2 + 1 - sage: factor((x - a) * (x + 2*a)) # optional - sage.rings.number_field + 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') # 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 + 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:: @@ -4566,25 +4566,25 @@ 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()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: F = f._factor_pari_helper(pari(f).factor()); F # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: F.prod() == f # optional - sage.libs.pari True - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari @@ -4653,25 +4653,25 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: K. = (x^3 + 2).splitting_field(); K # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # 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 + 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) # optional - sage.rings.number_field - sage: phi # optional - sage.rings.number_field + 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 @@ -4679,14 +4679,14 @@ cdef class Polynomial(CommutativePolynomial): An example over a finite field:: - sage: P. = PolynomialRing(GF(7)) # optional - sage.libs.pari - sage: t = x^2 + 1 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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')) # optional - sage.libs.pari - sage: t = x^2 + 1 # optional - sage.libs.pari - sage: t.splitting_field('b', map=True) # optional - sage.libs.pari + 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 @@ -4696,13 +4696,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 # optional - sage.libs.pari - sage: t.splitting_field('a', map=True) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b', map=True) # optional - sage.libs.pari + 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 @@ -4724,48 +4724,48 @@ cdef class Polynomial(CommutativePolynomial): ... NotImplementedError: splitting_field() is only implemented over number fields and finite fields - sage: P. = PolynomialRing(GF(11^5, 'a')) # optional - sage.libs.pari - sage: t = x^2 + 1 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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')) # optional - sage.libs.pari - sage: t = -x^6 + x^2 + 1 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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')) # optional - sage.libs.pari - sage: t = 2*x^14 - 5 + 6*x # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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')) # optional - sage.libs.pari - sage: t = 2*x^14 - 5 + 6*x # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: t.splitting_field('b') # optional - sage.libs.pari + 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[] @@ -4963,8 +4963,8 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`32033` has been fixed:: - sage: R. = GF(3)[] # optional - sage.libs.pari - sage: lcm(R(0), R(0)) # optional - sage.libs.pari + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: lcm(R(0), R(0)) # optional - sage.rings.finite_rings 0 :: @@ -5039,26 +5039,26 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = GF(2)['x'] # optional - sage.libs.pari - sage: f = x^4+x^3+x^2+x+1 # optional - sage.libs.pari - sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: f = x^3-x+1 # optional - sage.libs.pari - sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: f = x^2+x+1 # optional - sage.libs.pari - sage: f.is_primitive() # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.is_primitive() # optional - sage.libs.pari + 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() @@ -5078,16 +5078,16 @@ cdef class Polynomial(CommutativePolynomial): sage: f.is_primitive() False - 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 + 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 # optional - sage.rings.number_field - sage: f.is_primitive() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: f.is_primitive() # optional - sage.rings.number_field + 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)) @@ -5098,33 +5098,33 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(2)['x'] # optional - sage.libs.pari - sage: f = x^4+x^3+x^2+x+1 # optional - sage.libs.pari - sage: f.is_primitive(15) # optional - sage.libs.pari + 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]) # optional - sage.libs.pari + sage: f.is_primitive(15, [3,5]) # optional - sage.rings.finite_rings False - sage: f.is_primitive(n_prime_divs=[3,5]) # optional - sage.libs.pari + sage: f.is_primitive(n_prime_divs=[3,5]) # optional - sage.rings.finite_rings False - sage: f = x^3+x+1 # optional - sage.libs.pari - sage: f.is_primitive(7, [7]) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: f = x^3-x+1 # optional - sage.libs.pari - sage: f.is_primitive(26, [2,13]) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.is_primitive(8, [2]) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: f = x^2+x+1 # optional - sage.libs.pari - sage: f.is_primitive(24, [2,3]) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: f.is_primitive(24, [2,3]) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: f.is_primitive() # optional - sage.rings.finite_rings False """ R = self.base_ring() @@ -5241,56 +5241,56 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('a') # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field + 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) # 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 + 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')) # optional - sage.libs.pari - sage: f = x^3 + x^2 + 8 # optional - sage.libs.pari - sage: K. = f.root_field(); K # optional - sage.libs.pari + 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.libs.pari + sage: alpha^2 + 1 # optional - sage.rings.finite_rings alpha^2 + 1 - sage: alpha^3 + alpha^2 # optional - sage.libs.pari + sage: alpha^3 + alpha^2 # optional - sage.rings.finite_rings 1 :: sage: R. = QQ[] sage: f = x^2 - sage: K. = f.root_field() # optional - sage.libs.pari + 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') # optional - sage.libs.pari + 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() @@ -5387,18 +5387,18 @@ cdef class Polynomial(CommutativePolynomial): sage: f = QQ['x']([1, 0, 1]) sage: g = ZZ['x']([1, 0, 1]) - sage: h = GF(25, 'a')['x']([1, 0, 1]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari sage.modules + 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) # optional - sage.libs.pari sage.modules + 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: @@ -5505,10 +5505,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.libs.pari - sage: a = w._new_constant_poly(0, R); a # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: a.coefficients() # optional - sage.rings.finite_rings [] """ t = type(self) @@ -5910,11 +5910,11 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - 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 + 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 :: @@ -5962,10 +5962,10 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - 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 + 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 :: @@ -6183,10 +6183,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f.monomials() [x^9, x^2, x, 1] 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 + 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(): @@ -6478,11 +6478,11 @@ cdef class Polynomial(CommutativePolynomial): Stacked polynomial rings with exotic base rings:: - sage: S. = GF(7)['a', 'b'] # optional - sage.libs.pari - sage: R. = S['x'] # optional - sage.libs.pari - sage: pari(x^2 + 9*x) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: pari(a*x + 9*b*x^3) # optional - sage.rings.finite_rings 2*b*x^3 + a*x :: @@ -6585,8 +6585,8 @@ cdef class Polynomial(CommutativePolynomial): A more complicated nested example:: - sage: k. = GF(9); R. = k[]; S. = R[] # optional - sage.libs.pari - sage: magma(a*W^20 + s*t/a) # optional - magma # optional - sage.libs.pari + 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. @@ -6607,33 +6607,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g # indirect doctest # optional - sage.libs.gap + sage: g = gap(f); g # indirect doctest # optional - sage.libs.gap y^3-17*y+5 - sage: f._gap_init_() # optional - sage.libs.gap + sage: f._gap_init_() # optional - sage.libs.gap 'y^3 - 17*y + 5' sage: R. = ZZ[] - sage: gap(R) # optional - sage.libs.gap + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: g # optional - sage.libs.gap + sage: g # optional - sage.libs.gap y^3-17*y+5 - sage: gap(z^2 + z) # optional - sage.libs.gap + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z - sage: libgap(z^2 + z) # optional - sage.libs.gap + sage: libgap(z^2 + z) # optional - sage.libs.gap z^2+z Coefficients in a finite field:: - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: f = y^3 - 17*y + 5 # optional - sage.libs.pari - sage: g = gap(f); g # optional - sage.libs.gap sage.libs.pari + 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 # optional - sage.libs.gap sage.libs.pari + 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() # optional - sage.libs.gap sage.libs.pari + 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() # optional - sage.libs.gap sage.libs.pari + 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() # optional - sage.libs.gap sage.libs.pari + sage: f.factor() # optional - sage.libs.gap sage.rings.finite_rings (y + 5) * (y + 1)^2 """ R = gap(self._parent) @@ -6645,9 +6645,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x^3 + 3*x) # indirect doctest # optional - sage.libs.gap + sage: libgap(-x^3 + 3*x) # indirect doctest # optional - sage.libs.gap -x^3+3*x - sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -6659,13 +6659,13 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] # optional - sage.libs.pari - sage: f = R('e*i') * x + x^2 # optional - sage.libs.pari - sage: f._giac_init_() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: giac(f) # optional - sage.rings.finite_rings sageVARx^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) # optional - sage.libs.pari + sage: giac(R.zero()) # optional - sage.rings.finite_rings 0 """ g = 'sageVAR' + self.variable_name() @@ -6696,9 +6696,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 # optional - sage.libs.pari + sage: r = f.resultant(g); r # optional - sage.libs.pari -8 - sage: r.parent() is QQ # optional - sage.libs.pari + sage: r.parent() is QQ # optional - sage.libs.pari True We can compute resultants over univariate and multivariate @@ -6707,9 +6707,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 # optional - sage.libs.pari + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + a^2 - sage: r.parent() is R # optional - sage.libs.pari + sage: r.parent() is R # optional - sage.libs.pari True :: @@ -6717,9 +6717,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 # optional - sage.libs.pari + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + b^2 - sage: r.parent() is R # optional - sage.libs.pari + sage: r.parent() is R # optional - sage.libs.pari True TESTS:: @@ -6727,18 +6727,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 # optional - sage.libs.pari + sage: h = f.resultant(g); h # optional - sage.libs.pari y^3 - x^2 - sage: h.parent() is R # optional - sage.libs.pari + sage: h.parent() is R # optional - sage.libs.pari True Check that :trac:`13672` is fixed:: - sage: R. = GF(2)[] # optional - sage.libs.pari - sage: S. = R[] # optional - sage.libs.pari - sage: f = (t^2 + t)*x + t^2 + t # optional - sage.libs.pari - sage: g = (t + 1)*x + t^2 # optional - sage.libs.pari - sage: f.resultant(g) # optional - sage.libs.pari + 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:: @@ -6747,23 +6747,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()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: y.resultant(y + x) # optional - sage.libs.pari x sage: K. = FunctionField(QQ) sage: R. = K[] - 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 + 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:: @@ -6774,7 +6774,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) # optional - sage.libs.pari + 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 @@ -6783,7 +6783,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) # optional - sage.libs.pari + sage: f.resultant(g) # optional - sage.libs.pari 133.92599999999996 + 37.56999999999999*I """ variable = self.variable_name() @@ -6933,49 +6933,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) # optional - sage.libs.singular + 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) # optional - sage.libs.singular + sage: p1.composed_op(p2, operator.mul) # optional - sage.libs.singular x^8 - 2*x^4 + 1 - sage: p1.composed_op(p2, operator.truediv) # optional - sage.libs.singular + 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) # 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 + 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 + 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.libs.pari - sage: p1 = x**2 + x - 1 # optional - sage.libs.pari - sage: p2 = x**3 + x - 1 # optional - sage.libs.pari - sage: p_add = p1.composed_op(p2, operator.add) # optional - sage.libs.pari - sage: p_add # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: p_mul # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: p_div # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: r1 = p1.roots(K, multiplicities=False) # optional - sage.libs.pari - sage: r2 = p2.roots(K, multiplicities=False) # optional - sage.libs.pari - sage: all(p_add(x1+x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True TESTS: @@ -7386,10 +7386,10 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`13672` is fixed:: - sage: R. = GF(5)[] # optional - sage.libs.pari - sage: S. = R[] # optional - sage.libs.pari - sage: f = x^10 + 2*x^6 + 2*x^5 + x + 2 # optional - sage.libs.pari - sage: (f - t).discriminant() # optional - sage.libs.pari + 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:: @@ -7403,8 +7403,8 @@ cdef class Polynomial(CommutativePolynomial): This was fixed by :trac:`15422`:: - sage: R. = PolynomialRing(Qp(2)) # optional - sage.rings.padics - sage: (s^2).discriminant() # optional - sage.rings.padics + sage: R. = PolynomialRing(Qp(2)) # optional - sage.rings.padics + sage: (s^2).discriminant() # optional - sage.rings.padics 0 This was fixed by :trac:`16014`:: @@ -7589,14 +7589,14 @@ cdef class Polynomial(CommutativePolynomial): :: - 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.libs.pari # optional - sage.rings.number_field + 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)) # optional - sage.libs.pari # optional - sage.rings.number_field - sage: g.roots() # optional - sage.libs.pari # optional - sage.rings.number_field + 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) # optional - sage.libs.pari # optional - sage.rings.number_field + 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 @@ -7795,7 +7795,7 @@ cdef class Polynomial(CommutativePolynomial): [-0.6180339887498948482045868343657?, 1.6180339887498948482045868343657?] sage: f.roots(ring=RealIntervalField(150)) [(-0.6180339887498948482045868343656381177203091798057628621354486227?, 1), (1.618033988749894848204586834365638117720309179805762862135448623?, 1)] - sage: f.roots(ring=AA) # optional - sage.rings.number_field + 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) @@ -7813,12 +7813,12 @@ cdef class Polynomial(CommutativePolynomial): [(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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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)] @@ -7844,13 +7844,13 @@ cdef class Polynomial(CommutativePolynomial): :: - 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 + 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 + 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 @@ -7866,9 +7866,9 @@ cdef class Polynomial(CommutativePolynomial): We can also find roots over number fields:: - 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 + 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 @@ -7939,21 +7939,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) # optional - sage.rings.number_field + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] - sage: p.roots(ring=QQbar) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] - sage: p.roots(ring=QQbar) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-5.9223865215328558?e225, 1), (5.9223865215328558?e225, 1)] Check that :trac:`30522` is fixed:: @@ -8096,19 +8096,19 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = (x - 1)^2 - sage: pol.roots(Qp(3, 5)) # optional - sage.rings.padics + 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() # optional - sage.rings.padics + 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)) # optional - sage.rings.padics + 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 # optional - sage.rings.padics + sage: r = pol.roots(Zp(3, 5), multiplicities=False); r # optional - sage.rings.padics [1 + O(3^5)] - sage: parent(r[0]) # optional - sage.rings.padics + 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`:: @@ -8137,7 +8137,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))) # optional - sage.rings.padics + sage: len(cyclotomic_polynomial(3).roots(ZpFM(739, 566))) # optional - sage.rings.padics 2 Check that :trac:`26421` is fixed:: @@ -8151,8 +8151,8 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`31040` is fixed:: sage: R. = QQ[] - sage: K. = Qq(3).extension(x^2 + 1) # optional - sage.rings.padics - sage: (x^2 + 1).roots(K) # optional - sage.rings.padics + 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)] @@ -8437,9 +8437,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = 20*x^3 - 50*x^2 + 20*x - sage: F = pol.factor(); F # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari [2, 0, 1/2] @@ -8471,14 +8471,14 @@ cdef class Polynomial(CommutativePolynomial): sage: Pols. = QQ[] sage: pol = (n - 1/2)^2 * (n - 1)^2 * (n - 2) - sage: rts = pol.roots(ZZ, multiplicities=False); rts # optional - sage.libs.pari + sage: rts = pol.roots(ZZ, multiplicities=False); rts # optional - sage.libs.pari [2, 1] - sage: rts[0].parent() # optional - sage.libs.pari + 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) # optional - sage.libs.singular + sage: ((y - 1)*(y - x))._roots_in_subring(QQ, True, None) # optional - sage.libs.singular [(1, 1)] """ K = self._parent.base_ring() @@ -8597,35 +8597,35 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1.01, 2) # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval(1.01, 2) # optional - sage.libs.pari 1 - sage: pol.number_of_roots_in_interval(None, 2) # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval(None, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1, Infinity) # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval(1, Infinity) # optional - sage.libs.pari 3 - sage: pol.number_of_roots_in_interval() # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval() # optional - sage.libs.pari 3 sage: pol = (x-1) * (x-2) * (x-3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_roots_in_interval() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval(-1, 2) # optional - sage.libs.pari 5 - sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 3 """ @@ -8655,15 +8655,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() # optional - sage.libs.pari + sage: pol.number_of_real_roots() # optional - sage.libs.pari 3 sage: pol = (x-1) * (x-2) * (x-3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_real_roots() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: pol.number_of_real_roots() # optional - sage.libs.pari 1 """ return self.number_of_roots_in_interval() @@ -8677,17 +8677,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) # optional - sage.libs.pari + sage: pol.all_roots_in_interval(1, 3) # optional - sage.libs.pari True - sage: pol.all_roots_in_interval(1.01, 3) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari False - sage: pol.all_roots_in_interval() # optional - sage.libs.pari + sage: pol.all_roots_in_interval() # optional - sage.libs.pari True """ pol = self // self.gcd(self.derivative()) @@ -8701,10 +8701,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = chebyshev_T(5, x) - sage: pol.is_real_rooted() # optional - sage.libs.pari + sage: pol.is_real_rooted() # optional - sage.libs.pari True sage: pol = x^2 + 1 - sage: pol.is_real_rooted() # optional - sage.libs.pari + sage: pol.is_real_rooted() # optional - sage.libs.pari False """ return self.all_roots_in_interval() @@ -8785,22 +8785,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) # 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 + 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() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field - sage: u.trace_polynomial() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: (u*(x+2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x + 2, 4) TESTS: @@ -8865,15 +8865,15 @@ 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) # optional - sage.libs.pari + sage: P0.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (True, 5) - sage: P0.is_weil_polynomial(return_q=False) # optional - sage.libs.pari + sage: P0.is_weil_polynomial(return_q=False) # optional - sage.libs.pari True - sage: P1.is_weil_polynomial(return_q=True) # optional - sage.libs.pari + sage: P1.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (False, 0) - sage: P1.is_weil_polynomial(return_q=False) # optional - sage.libs.pari + sage: P1.is_weil_polynomial(return_q=False) # optional - sage.libs.pari False - sage: P2.is_weil_polynomial() # optional - sage.libs.pari + sage: P2.is_weil_polynomial() # optional - sage.libs.pari False .. SEEALSO:: @@ -8888,7 +8888,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() # optional - sage.libs.pari + sage: u.is_weil_polynomial() # optional - sage.libs.pari True AUTHORS: @@ -9142,11 +9142,11 @@ cdef class Polynomial(CommutativePolynomial): Over `\QQ_5`:: - 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 + 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:: @@ -9622,36 +9622,36 @@ cdef class Polynomial(CommutativePolynomial): decomposition or a full factorization, depending on which is available:: - sage: K. = FunctionField(GF(3)) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: (x^3-x).is_squarefree() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: (x^3-1).is_squarefree() # optional - sage.rings.finite_rings False - sage: (x^3+t).is_squarefree() # optional - sage.libs.pari + sage: (x^3+t).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3+t^3).is_squarefree() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: f.is_squarefree() # optional - sage.rings.finite_rings False - sage: f.squarefree_decomposition() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: (f/c).is_squarefree() # optional - sage.rings.finite_rings True If the base ring is not an integral domain, the question is not @@ -9762,8 +9762,8 @@ cdef class Polynomial(CommutativePolynomial): If self has a factor of multiplicity divisible by the characteristic (see :trac:`8736`):: - sage: P. = GF(2)[] # optional - sage.libs.pari - sage: (x^3 + x^2).radical() # optional - sage.libs.pari + 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 @@ -9892,10 +9892,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f = (x+1)^100 sage: f.number_of_terms() 101 - sage: S = GF(5)['y'] # optional - sage.libs.pari - sage: S(f).number_of_terms() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: cyclotomic_polynomial(105).number_of_terms() # optional - sage.rings.finite_rings 33 The method :meth:`hamming_weight` is an alias:: @@ -9951,21 +9951,21 @@ cdef class Polynomial(CommutativePolynomial): Examples with different base ring:: sage: R. = ZZ[] - sage: k = GF(2) # optional - sage.libs.pari - sage: residue = lambda x: k(x) # optional - sage.libs.pari - sage: f = 4*x^2+x+3 # optional - sage.libs.pari - sage: g = f.map_coefficients(residue); g # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: g = f.map_coefficients(residue); g # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) """ R = self._parent @@ -10013,20 +10013,20 @@ cdef class Polynomial(CommutativePolynomial): Quick tests:: sage: P. = ZZ['x'] - sage: (x - 1).is_cyclotomic() # optional - sage.libs.pari + sage: (x - 1).is_cyclotomic() # optional - sage.libs.pari True - sage: (x + 1).is_cyclotomic() # optional - sage.libs.pari + sage: (x + 1).is_cyclotomic() # optional - sage.libs.pari True - sage: (x^2 - 1).is_cyclotomic() # optional - sage.libs.pari + sage: (x^2 - 1).is_cyclotomic() # optional - sage.libs.pari False - sage: (x^2 + x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari + sage: (x^2 + x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 3 - sage: (x^2 + 2*x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: all(cyclotomic_polynomial(i).is_cyclotomic() for i in range(1, 101)) # optional - sage.libs.pari True Some more tests:: @@ -10042,9 +10042,9 @@ cdef class Polynomial(CommutativePolynomial): True sage: y = polygen(QQ) - sage: (y/2 - 1/2).is_cyclotomic() # optional - sage.libs.pari + sage: (y/2 - 1/2).is_cyclotomic() # optional - sage.libs.pari False - sage: (2*(y/2 - 1/2)).is_cyclotomic() # optional - sage.libs.pari + sage: (2*(y/2 - 1/2)).is_cyclotomic() # optional - sage.libs.pari True Invalid arguments:: @@ -10056,8 +10056,8 @@ cdef class Polynomial(CommutativePolynomial): Test using other rings:: - sage: z = polygen(GF(5)) # optional - sage.libs.pari - sage: (z - 1).is_cyclotomic() # optional - sage.libs.pari + 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 @@ -10065,28 +10065,28 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R = ZZ['x'] - sage: for _ in range(20): # optional - sage.libs.pari + 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): # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: type((x^2 - 2).is_cyclotomic(certificate=True)) # optional - sage.libs.pari - sage: type((x - 1).is_cyclotomic(certificate=True)) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: (x - 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 1 """ S = self.base_ring() @@ -10163,20 +10163,20 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(ZZ) - sage: (x^5 - 1).is_cyclotomic_product() # optional - sage.libs.pari + sage: (x^5 - 1).is_cyclotomic_product() # optional - sage.libs.pari True - sage: (x^5 + x^4 - x^2 + 1).is_cyclotomic_product() # optional - sage.libs.pari + 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]) # optional - sage.libs.pari - sage: p.is_cyclotomic_product() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: (x^5 - 1/3).is_cyclotomic_product() # optional - sage.libs.pari False sage: x = polygen(Zmod(5)) - sage: (x - 1).is_cyclotomic_product() # optional - sage.libs.pari + sage: (x - 1).is_cyclotomic_product() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError: not implemented in non-zero characteristic @@ -10297,8 +10297,8 @@ cdef class Polynomial(CommutativePolynomial): True sage: u = x^5 - 2; u.has_cyclotomic_factor() False - sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() # random # optional - sage.libs.pari - sage: u.has_cyclotomic_factor() # random # optional - sage.libs.pari + 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()): @@ -10389,9 +10389,9 @@ cdef class Polynomial(CommutativePolynomial): In positive characteristic, the degree can drop in this case:: - sage: R. = GF(2)[] # optional - sage.libs.pari - sage: f = x + 1 # optional - sage.libs.pari - sage: f.homogenize(x) # optional - sage.libs.pari + 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 @@ -10468,43 +10468,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) # 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 + 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 # optional - sage.rings.number_field + sage: b^3 == a # optional - sage.rings.number_field True - 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 + 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 # optional - sage.rings.number_field - sage: p.nth_root(20) # optional - sage.rings.number_field + 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() # optional - sage.libs.pari - sage: R. = GF(4)[] # optional - sage.libs.pari - sage: p = z*x**4 + 2*x - 1 # optional - sage.libs.pari - sage: r = (p**15).nth_root(15) # optional - sage.libs.pari - sage: r * p[0] == p * r[0] # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: ((x+1)**2).nth_root(2) # optional - sage.rings.finite_rings x + 1 - sage: ((x+1)**4).nth_root(4) # optional - sage.libs.pari + sage: ((x+1)**4).nth_root(4) # optional - sage.rings.finite_rings x + 1 - sage: ((x+1)**12).nth_root(12) # optional - sage.libs.pari + sage: ((x+1)**12).nth_root(12) # optional - sage.rings.finite_rings x + 1 - sage: (x^4 + x^3 + 1).nth_root(2) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: r = p.nth_root(17) # optional - sage.libs.pari + 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 @@ -10521,14 +10521,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) # 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 + 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) # optional - sage.libs.pari + sage: (y**3).nth_root(3) # optional - sage.libs.pari y - sage: (y**2 + x).nth_root(2) # optional - sage.libs.pari + sage: (y**2 + x).nth_root(2) # optional - sage.libs.pari Traceback (most recent call last): ... AttributeError: ... has no attribute 'nth_root' @@ -10564,7 +10564,7 @@ cdef class Polynomial(CommutativePolynomial): Some random tests:: - sage: for R in [QQ['x'], GF(4)['x']]: # optional - sage.libs.pari + 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) @@ -10648,10 +10648,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R.one()._nth_root_series(3, 5) 1 - 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 + 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:: @@ -10673,12 +10673,12 @@ cdef class Polynomial(CommutativePolynomial): Finite characteristic:: - sage: R. = GF(2)[] # optional - sage.libs.pari - sage: (1 + x)._nth_root_series(3, 10) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: (1 + x^2)._nth_root_series(2, 10) # optional - sage.rings.finite_rings x + 1 - sage: (1 + x)._nth_root_series(2, 10) # optional - sage.libs.pari + sage: (1 + x)._nth_root_series(2, 10) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 2nd power @@ -10791,21 +10791,21 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = PolynomialRing(ZZ, implementation="NTL") # optional - sage.libs.ntl - sage: (2*x + 1).divides(4*x**2 + 1) # optional - sage.libs.ntl + 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) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: S. = R[] # optional - sage.libs.pari - sage: p = ((3*z + 2)*x + 2*z - 1) * y + 2*x + z # optional - sage.libs.pari - sage: q = y^2 + z*y*x + 2*y + z # optional - sage.libs.pari - sage: p.divides(q), p.divides(p*q) # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: S. = R[] # optional - sage.libs.pari - sage: p = (x+y+1) * z + x*y # optional - sage.libs.pari - sage: q = (y^2-x^2) * z^2 + z + x-y # optional - sage.libs.pari - sage: p.divides(q), p.divides(p*q) # optional - sage.libs.pari + 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(): @@ -11535,30 +11535,30 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: f - g * (1+2*x) # optional - sage.rings.number_field -3/2 - sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field + 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[] # optional - sage.rings.number_field - sage: x // x # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x // x # optional - sage.rings.number_field 1 - sage: x // 1 # optional - sage.rings.number_field + sage: x // 1 # optional - sage.rings.number_field x - sage: x // int(1) # optional - sage.rings.number_field + sage: x // int(1) # optional - sage.rings.number_field x - sage: x //= int(1); x # optional - sage.rings.number_field + sage: x //= int(1); x # optional - sage.rings.number_field x - sage: int(1) // x # check that this doesn't segfault # optional - sage.rings.number_field + 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' @@ -11673,10 +11673,10 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = GF(17)[] # optional - sage.libs.pari - sage: f = (1+2*x)^3 + 3*x; f # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: f.list() # optional - sage.rings.finite_rings [1, 9, 12, 8] """ if copy: @@ -11779,12 +11779,12 @@ cdef class Polynomial_generic_dense(Polynomial): Polynomials over noncommutative rings are also allowed (after :trac:`34733`):: - 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 + 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: @@ -11952,7 +11952,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`) # optional - sage.libs.pari + 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() @@ -12052,9 +12052,9 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): Coefficients indistinguishable from 0 are not removed. - 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 + 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 @@ -12088,27 +12088,27 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): EXAMPLES:: - 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 + 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() # optional - sage.rings.padics + sage: f.degree() # optional - sage.rings.padics 1 - sage: (f - T).degree() # optional - sage.rings.padics + sage: (f - T).degree() # optional - sage.rings.padics 0 - sage: (f - T).degree(secure=True) # optional - sage.rings.padics + 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) # optional - sage.rings.padics - sage: li = [3^i * x for i in range(0,5)]; li # optional - sage.rings.padics + 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 # optional - sage.rings.padics + 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() # optional - sage.rings.padics + sage: f.degree() # optional - sage.rings.padics -1 - sage: f.degree(secure=True) # optional - sage.rings.padics + sage: f.degree(secure=True) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: the leading coefficient is indistinguishable from 0 @@ -12140,20 +12140,20 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): EXAMPLES:: - 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 + 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() # optional - sage.rings.padics + sage: f.degree() # optional - sage.rings.padics 1 - sage: f.prec_degree() # optional - sage.rings.padics + sage: f.prec_degree() # optional - sage.rings.padics 1 - sage: g = f - T; g # optional - sage.rings.padics + sage: g = f - T; g # optional - sage.rings.padics O(3^10)*T + 2 + O(3^10) - sage: g.degree() # optional - sage.rings.padics + sage: g.degree() # optional - sage.rings.padics 0 - sage: g.prec_degree() # optional - sage.rings.padics + sage: g.prec_degree() # optional - sage.rings.padics 1 AUTHOR: @@ -12172,20 +12172,20 @@ cdef class ConstantPolynomialSection(Map): EXAMPLES:: - sage: P0. = GF(3)[] # optional - sage.libs.pari - sage: P1. = GF(3)[] # optional - sage.libs.pari - sage: P0(-y_1) # indirect doctest # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: type(phi) # optional - sage.rings.finite_rings - sage: phi(P0.one()) # optional - sage.libs.pari + sage: phi(P0.one()) # optional - sage.rings.finite_rings 1 - sage: phi(y_1) # optional - sage.libs.pari + sage: phi(y_1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: not a constant polynomial @@ -12236,13 +12236,13 @@ cdef class PolynomialBaseringInjection(Morphism): supposed to be the fastest maps for that purpose. See :trac:`9944`. :: - sage: R. = Qp(3)[] # optional - sage.rings.padics - sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics + 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)[] # optional - sage.rings.padics - sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics + 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 @@ -12284,11 +12284,11 @@ cdef class PolynomialBaseringInjection(Morphism): :: - 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 + 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 # optional - sage.rings.padics + 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" @@ -12352,8 +12352,8 @@ cdef class PolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.polynomial_element import PolynomialBaseringInjection - 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 + 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 d629f47c9ff..4f7f7d4a04b 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -14,10 +14,10 @@ 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 + 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,14 +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) # optional - sage.libs.pari - sage: C. = PolynomialRing(B) # optional - sage.libs.pari - sage: C # optional - sage.libs.pari + 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 + sage: s + T # optional - sage.libs.pari s + Tbar - sage: (s + T)**2 # optional - sage.libs.pari + sage: (s + T)**2 # optional - sage.libs.pari s^2 + 2*Tbar*s + 4 """ @@ -189,13 +190,13 @@ def valuation(self, p=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.libs.pari - sage: f = w^1997 - w^10000 # optional - sage.libs.pari - sage: f.valuation() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: R(19).valuation() # optional - sage.rings.finite_rings 0 - sage: R(0).valuation() # optional - sage.libs.pari + sage: R(0).valuation() # optional - sage.rings.finite_rings +Infinity """ if not self.__coeffs: @@ -244,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') # optional - sage.symbolic - sage: R.gen()._derivative(t) # optional - sage.symbolic + sage: t, u = var('t, u') # optional - sage.symbolic + sage: R.gen()._derivative(t) # optional - sage.symbolic 1 - sage: R.gen()._derivative(u) # optional - sage.symbolic + sage: R.gen()._derivative(u) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to u @@ -549,14 +550,14 @@ def __floordiv__(self, right): EXAMPLES:: - 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 + 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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: f - g * (1+2*x) # optional - sage.rings.number_field -3/2 - sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field + sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field (4*x^2 + 4*x + 5/2, -3/2) """ @@ -826,12 +827,12 @@ def quo_rem(self, other): Polynomials over noncommutative rings are also allowed:: - 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 + 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:: @@ -1066,11 +1067,11 @@ def quo_rem(self, other): EXAMPLES:: sage: R. = PolynomialRing(QQ) - 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 + 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)) # optional - sage.rings.number_field + sage: x.xgcd(K(1)) # optional - sage.rings.number_field (1, 0, 1) """ P = self.parent() @@ -1141,15 +1142,15 @@ def newton_slopes(self, repetition=True): EXAMPLES:: - 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 + 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() # 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.newton_slopes(repetition=False) # optional - sage.rings.padics + sage: f.newton_slopes(repetition=False) # optional - sage.rings.padics [1, 0, -1/3] AUTHOR: @@ -1169,15 +1170,15 @@ def newton_polygon(self): EXAMPLES:: - 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 + 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 # optional - sage.rings.padics + 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() # optional - sage.rings.padics + sage: g.newton_polygon() # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: The coefficient of t^4 has not enough precision @@ -1186,10 +1187,10 @@ def newton_polygon(self): Check that :trac:`22936` is fixed:: - sage: S. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari - sage: R. = S[] # optional - sage.libs.pari - sage: p = x^2 + y + x*y^2 # optional - sage.libs.pari - sage: p.newton_polygon() # optional - sage.libs.pari + 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: @@ -1224,16 +1225,16 @@ def hensel_lift(self, a): EXAMPLES:: - 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 + 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) # optional - sage.rings.padics + sage: f(root) # optional - sage.rings.padics O(5^10) - 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 + 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 @@ -1272,27 +1273,27 @@ def _factor_of_degree(self, deg): EXAMPLES:: - 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: 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) # optional - sage.rings.padics - sage: (f % g).is_zero() # optional - sage.rings.padics + 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 # optional - sage.rings.padics + 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)) # optional - sage.libs.pari - sage: R. = S[] # optional - sage.libs.pari - sage: p = x^2 + y + x*y^2 # optional - sage.libs.pari - sage: p._factor_of_degree(1) # optional - sage.libs.pari + 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: @@ -1336,30 +1337,30 @@ def factor_of_slope(self, slope=None): EXAMPLES:: - sage: K = Qp(5) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: K = Qp(5) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.libs.pari - sage: f.newton_slopes() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: g.newton_slopes() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: (f % g).is_zero() # optional - sage.rings.padics True - sage: h = f.factor_of_slope() # optional - sage.libs.pari - sage: h.newton_slopes() # optional - sage.libs.pari + sage: h = f.factor_of_slope() # optional - sage.rings.padics + sage: h.newton_slopes() # optional - sage.rings.padics [1] - sage: (f % h).is_zero() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f.factor_of_slope(-1) # optional - sage.rings.padics 1 + O(5^20) AUTHOR: @@ -1405,18 +1406,18 @@ def slope_factorization(self): EXAMPLES:: - 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 + 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() # optional - sage.rings.padics - sage: F.prod() == f # optional - sage.rings.padics + sage: F = f.slope_factorization() # optional - sage.rings.padics + sage: F.prod() == f # optional - sage.rings.padics True - sage: for (f,_) in F: # optional - sage.rings.padics + 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] @@ -1424,10 +1425,10 @@ def slope_factorization(self): TESTS:: - sage: S. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari - sage: R. = S[] # optional - sage.libs.pari - sage: p = x^2 + y + x*y^2 # optional - sage.libs.pari - sage: p.slope_factorization() # optional - sage.libs.pari + 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)) @@ -1482,11 +1483,11 @@ def _roots(self, secure, minval, hint): TESTS:: - 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 + 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 b39aeeb8b4a..d61ee11e8cf 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -81,25 +81,25 @@ class PolynomialQuotientRingFactory(UniqueFactory): sage: Z = IntegerRing() 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 + 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 + sage: a^3 # optional - sage.libs.pari -7 - sage: S.is_field() # optional - sage.libs.pari + sage: S.is_field() # optional - sage.libs.pari False - sage: a in S # optional - sage.libs.pari + sage: a in S # optional - sage.libs.pari True - sage: x in S # optional - sage.libs.pari + sage: x in S # optional - sage.libs.pari True - sage: a in R # optional - sage.libs.pari + sage: a in R # optional - sage.libs.pari False - sage: S.polynomial_ring() # optional - sage.libs.pari + sage: S.polynomial_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring - sage: S.modulus() # optional - sage.libs.pari + sage: S.modulus() # optional - sage.libs.pari x^3 + 7 - sage: S.degree() # optional - sage.libs.pari + sage: S.degree() # optional - sage.libs.pari 3 We create the "iterated" polynomial ring quotient @@ -110,15 +110,16 @@ class PolynomialQuotientRingFactory(UniqueFactory): :: - sage: A. = PolynomialRing(GF(2)); A # optional - sage.libs.pari + 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 # optional - sage.libs.pari - 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.libs.pari + 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.libs.pari + 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 @@ -128,21 +129,22 @@ class PolynomialQuotientRingFactory(UniqueFactory): polynomial ring over `\QQ`:: sage: R = PolynomialRing(RationalField(), 'x'); x = R.gen() - 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 + 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() # optional - sage.libs.pari + 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 # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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 @@ -161,14 +163,14 @@ class PolynomialQuotientRingFactory(UniqueFactory): sage: R. = PolynomialRing(IntegerRing()) sage: f = x^2 + 1 - sage: R.quotient(f) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 """ @@ -193,19 +195,19 @@ def create_key(self, ring, polynomial, names=None): Consequently, you get two distinct objects:: - sage: S = PolynomialQuotientRing(R, x + 1); S # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: S is T # optional - sage.libs.pari False - sage: S == T # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: R.quo(x + 1) is R.quo(2*x + 2) # optional - sage.libs.pari True """ @@ -234,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'))) # optional - sage.libs.pari + 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 """ @@ -272,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. @@ -288,18 +292,19 @@ class PolynomialQuotientRing_generic(QuotientRing_generic): :: sage: R. = PolynomialRing(ZZ) - 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 + 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) # optional - sage.libs.pari + sage: f(x) # optional - sage.libs.pari 2 - sage: f(x^2 - 4) # optional - sage.libs.pari + sage: f(x^2 - 4) # optional - sage.libs.pari 0 - sage: f(x^2) # optional - sage.libs.pari + sage: f(x^2) # optional - sage.libs.pari 4 TESTS: @@ -315,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) # optional - sage.libs.pari - sage: Q.category() # optional - sage.libs.pari + 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) @@ -325,24 +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) # optional - sage.libs.pari + 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('_')] # optional - sage.libs.pari + 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 + 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() # optional - sage.libs.pari + sage: Q in Fields() # optional - sage.libs.pari True - sage: Q.category() # optional - sage.libs.pari + 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__ # optional - sage.libs.pari + sage: first_class == Q.__class__ # optional - sage.libs.pari False - sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] # optional - sage.libs.pari + sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] # optional - sage.libs.pari ['cartesian_product', 'euclidean_degree', 'factor', @@ -366,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() # optional - sage.libs.pari - sage: isinstance(e, Q.element_class) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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']) # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: isinstance(Q(x), Q.element_class) # optional - sage.libs.pari + sage: TestSuite(Q(x)).run() # optional - sage.libs.pari + sage: isinstance(Q(x), Q.element_class) # optional - sage.libs.pari True """ Element = PolynomialQuotientRingElement @@ -391,18 +396,18 @@ def __init__(self, ring, polynomial, name=None, category=None): TESTS:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(x^2 - 4) # optional - sage.libs.pari + 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') # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: S = R.quo(x) # optional - sage.libs.pari - sage: S in FiniteFields() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: type(S).mro() # optional - sage.rings.finite_rings [, ... , @@ -448,18 +453,18 @@ def _element_constructor_(self, x): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3 - 3*x + 1) # optional - sage.libs.pari - sage: S(x) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: S(x^3) # optional - sage.libs.pari 3*alpha - 1 - sage: S([1,2]) # optional - sage.libs.pari + sage: S([1,2]) # optional - sage.libs.pari 2*alpha + 1 - sage: S([1,2,3,4,5]) # optional - sage.libs.pari + sage: S([1,2,3,4,5]) # optional - sage.libs.pari 18*alpha^2 + 9*alpha - 3 - sage: S(S.gen()+1) # optional - sage.libs.pari + sage: S(S.gen()+1) # optional - sage.libs.pari alpha + 1 - sage: S(S.gen()^10+1) # optional - sage.libs.pari + sage: S(S.gen()^10+1) # optional - sage.libs.pari 90*alpha^2 - 109*alpha + 28 TESTS: @@ -468,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)]) # 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 + 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()) # optional - sage.libs.pari + 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)]) # 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 + 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() # 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 + 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 # optional - sage.libs.pari + sage: a = Q1('x'); a # optional - sage.libs.pari xbar - sage: a.parent() is Q1 # optional - sage.libs.pari + sage: a.parent() is Q1 # optional - sage.libs.pari True - sage: b = Q1('1'); b # optional - sage.libs.pari + sage: b = Q1('1'); b # optional - sage.libs.pari 1 - sage: b.parent() is Q1 # optional - sage.libs.pari + 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[] # optional - sage.libs.pari - sage: Q3 = R.quo([(y^2+1)]) # optional - sage.libs.pari - sage: Q3(Q1.gen()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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') # optional - sage.libs.pari + sage: Q3('x*ybar^2') # optional - sage.libs.pari -x """ @@ -556,25 +562,25 @@ def _coerce_map_from_(self, R): TESTS:: - sage: P5. = GF(5)[] # optional - sage.libs.pari - sage: Q = P5.quo([(x^2+1)^2]) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: Q.has_coerce_map_from(Q1) #indirect doctest # optional - sage.rings.finite_rings True - sage: Q1.has_coerce_map_from(Q) # optional - sage.libs.pari + sage: Q1.has_coerce_map_from(Q) # optional - sage.rings.finite_rings False - sage: Q1.has_coerce_map_from(Q2) # optional - sage.libs.pari + 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)]) # optional - sage.libs.pari + 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)]) # optional - sage.libs.pari - sage: Q2.has_coerce_map_from(Q1) # optional - sage.libs.pari + sage: Q2 = R.quo([(y^2 + 1)]) # optional - sage.libs.pari + sage: Q2.has_coerce_map_from(Q1) # optional - sage.libs.pari False """ @@ -595,15 +601,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: T. = ZZ[] - 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 + 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])) # optional - sage.rings.number_field + 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])) # optional - sage.rings.number_field + 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()): @@ -653,12 +659,12 @@ def lift(self, x): EXAMPLES:: sage: P. = QQ[] - sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari - sage: Q.lift(Q.0^3) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: Q(-2*x) # optional - sage.libs.pari -2*xbar - sage: Q.0^3 # optional - sage.libs.pari + sage: Q.0^3 # optional - sage.libs.pari -2*xbar """ @@ -674,14 +680,14 @@ def __eq__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx == Ry False - 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 + 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 # optional - sage.libs.pari + sage: Qx == Qx # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari - sage: Qz == Qx # optional - sage.libs.pari + 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): @@ -699,14 +705,14 @@ def __ne__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx != Ry True - 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 + 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 # optional - sage.libs.pari + sage: Qx != Qx # optional - sage.libs.pari False - sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari - sage: Qz != Qx # optional - sage.libs.pari + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz != Qx # optional - sage.libs.pari False """ return not (self == other) @@ -721,14 +727,14 @@ def __hash__(self): sage: Ry. = PolynomialRing(QQ) sage: hash(Rx) == hash(Ry) False - 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 + 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) # optional - sage.libs.pari + sage: hash(Qx) == hash(Qx) # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari - sage: hash(Qz) == hash(Qx) # optional - sage.libs.pari + 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())) @@ -740,8 +746,8 @@ def _singular_init_(self, S=None): TESTS:: sage: P. = QQ[] - sage: Q = P.quo([(x^2 + 1)]) # optional - sage.libs.pari - sage: singular(Q) # indirect doctest # optional - sage.libs.pari + 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 @@ -750,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()) # optional - sage.libs.pari + sage: singular(Q.gen()) # optional - sage.libs.pari xbar """ @@ -779,10 +785,10 @@ def construction(self): sage: F, R = Q.construction() sage: F(R) == Q True - sage: P. = GF(3)[] # optional - sage.libs.pari - sage: Q = P.quo([2 + t^2]) # optional - sage.libs.pari - sage: F, R = Q.construction() # optional - sage.libs.pari - sage: F(R) == Q # optional - sage.libs.pari + 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: @@ -811,8 +817,8 @@ def base_ring(self): :: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quo(z^3 + z^2 + z + 1) # optional - sage.libs.pari - sage: S.base_ring() # optional - sage.libs.pari + 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 @@ -820,9 +826,9 @@ def base_ring(self): :: - 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 + 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 """ @@ -839,22 +845,22 @@ def cardinality(self): sage: R. = ZZ[] sage: R.quo(1).cardinality() 1 - sage: R.quo(x^3 - 2).cardinality() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: R.quo(x^3 - 2).order() # optional - sage.libs.pari +Infinity :: - sage: R. = GF(9, 'a')[] # optional - sage.libs.pari - sage: R.quo(2*x^3 + x + 1).cardinality() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: GF(9, 'a').extension(2*x^3 + x + 1).cardinality() # optional - sage.rings.finite_rings 729 - sage: R.quo(2).cardinality() # optional - sage.libs.pari + sage: R.quo(2).cardinality() # optional - sage.rings.finite_rings 1 TESTS:: @@ -888,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() # optional - sage.libs.pari + sage: R.quo(x^3 - 2).is_finite() # optional - sage.libs.pari False :: - sage: R. = GF(9, 'a')[] # optional - sage.libs.pari - sage: R.quo(2*x^3 + x + 1).is_finite() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: R.quo(2).is_finite() # optional - sage.rings.finite_rings True :: - sage: P. = GF(2)[] # optional - sage.libs.pari - sage: P.quotient(v^2 - v).is_finite() # optional - sage.libs.pari + 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() @@ -918,9 +924,9 @@ def __iter__(self): r""" EXAMPLES:: - sage: R. = GF(3)[] # optional - sage.libs.pari - sage: Q = R.quo(x^3 - x^2 - x - 1) # optional - sage.libs.pari - sage: list(Q) # optional - sage.libs.pari + 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, @@ -931,7 +937,7 @@ def __iter__(self): ... 2*xbar^2 + 2*xbar + 1, 2*xbar^2 + 2*xbar + 2] - sage: len(_) == Q.cardinality() == 27 # optional - sage.libs.pari + sage: len(_) == Q.cardinality() == 27 # optional - sage.rings.finite_rings True """ if not self.is_finite(): @@ -952,12 +958,12 @@ def characteristic(self): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quo(z - 19) # optional - sage.libs.pari - sage: S.characteristic() # optional - sage.libs.pari + sage: S. = R.quo(z - 19) # optional - sage.libs.pari + sage: S.characteristic() # optional - sage.libs.pari 0 - sage: R. = PolynomialRing(GF(9, 'a')) # optional - sage.libs.pari - sage: S = R.quotient(x^3 + 1) # optional - sage.libs.pari - sage: S.characteristic() # optional - sage.libs.pari + 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() @@ -969,9 +975,9 @@ def degree(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(3)) # optional - sage.libs.pari - sage: S = R.quotient(x^2005 + 1) # optional - sage.libs.pari - sage: S.degree() # optional - sage.libs.pari + 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() @@ -985,11 +991,11 @@ def discriminant(self, v=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^3 + x^2 + x + 1) # optional - sage.libs.pari - sage: S.discriminant() # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: S.discriminant() # optional - sage.libs.pari + 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 @@ -997,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) # optional - sage.libs.pari - sage: S.number_field().discriminant() # optional - sage.libs.pari + sage: S = R.quotient(x^2 - 8) # optional - sage.libs.pari + sage: S.number_field().discriminant() # optional - sage.libs.pari 8 - sage: S.discriminant() # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari 32 """ return self.modulus().discriminant() @@ -1013,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') # optional - sage.libs.pari - sage: S.gen() # optional - sage.libs.pari + sage: S = R.quotient(x^2 - 8, 'gamma') # optional - sage.libs.pari + sage: S.gen() # optional - sage.libs.pari gamma """ if n != 0: @@ -1032,28 +1038,28 @@ def is_field(self, proof = True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(z^2 - 2) # optional - sage.libs.pari - sage: S.is_field() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S.is_field() # optional - sage.libs.pari + 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)[] # 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 + 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) # optional - sage.rings.padics + sage: F2.is_field(proof = False) # optional - sage.rings.padics False """ @@ -1078,21 +1084,21 @@ def is_integral_domain(self, proof = True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quotient(z^2 - z) # optional - sage.libs.pari - sage: S.is_integral_domain() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: T.is_integral_domain() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S2.is_integral_domain() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S3.is_integral_domain() # optional - sage.libs.pari + 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)) @@ -1180,9 +1186,9 @@ def modulus(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(3)) # optional - sage.libs.pari - sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari - sage: S.modulus() # optional - sage.libs.pari + 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 @@ -1213,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() # optional - sage.rings.number_field - sage: K # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field - sage: alpha^29 # optional - sage.rings.number_field + sage: alpha = K.gen() # optional - sage.rings.number_field + sage: alpha^29 # optional - sage.rings.number_field 17*alpha + 1 """ if self.characteristic() != 0: @@ -1235,8 +1241,8 @@ def polynomial_ring(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari - sage: S.polynomial_ring() # optional - sage.libs.pari + 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 @@ -1259,10 +1265,10 @@ def random_element(self, *args, **kwds): EXAMPLES:: - sage: F1. = GF(2^7) # optional - sage.libs.pari - sage: P1. = F1[] # optional - sage.libs.pari - sage: F2 = F1.extension(x^2 + x + 1, 'u') # optional - sage.libs.pari - sage: F2.random_element().parent() is F2 # optional - sage.libs.pari + 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( \ @@ -1385,43 +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) # 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 + 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)]) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: K.class_group() # optional - sage.rings.number_field + 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 + 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)]) # optional - sage.rings.number_field + 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)]) # optional - sage.rings.number_field + sage: S.S_class_group([K.ideal(2, a+1)]) # optional - sage.rings.number_field [] - sage: S.S_class_group([K.ideal(a)]) # optional - sage.rings.number_field + 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) # 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 + 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, @@ -1442,7 +1448,7 @@ 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 # optional - sage.rings.number_field + 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), @@ -1454,21 +1460,21 @@ def S_class_group(self, S, proof=True): Note that all the returned values live where we expect them to:: - sage: CG = S.S_class_group([]) # optional - sage.rings.number_field - sage: type(CG[0][0][1]) # optional - sage.rings.number_field + 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]) # optional - sage.rings.number_field + 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) # 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 + 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, @@ -1479,10 +1485,10 @@ 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] # optional - sage.rings.number_field + sage: C[2][1] # optional - sage.rings.number_field 2 - sage: gens = C[2][0] # optional - sage.rings.number_field - sage: expected_gens = ( # optional - sage.rings.number_field + 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, @@ -1548,48 +1554,48 @@ def class_group(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) # optional - sage.rings.number_field - sage: K.class_group() # optional - sage.rings.number_field + 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 + 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) # 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 + 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(()) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: K.class_group() # optional - sage.rings.number_field + 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 + 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[] # 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 + 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), @@ -1600,10 +1606,10 @@ def class_group(self, proof=True): Now we take an example over a nontrivial base with two factors, each contributing to the class group:: - 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 + 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, @@ -1622,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() # optional - sage.rings.number_field - sage: type(CG[0][0][1]) # optional - sage.rings.number_field + 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]) # optional - sage.rings.number_field + sage: type(CG[0][1]) # optional - sage.rings.number_field """ @@ -1651,40 +1657,40 @@ def S_units(self, S, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) # optional - sage.rings.number_field - sage: K.unit_group() # optional - sage.rings.number_field + 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 6 - sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari + sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari True - sage: u^6 # optional - sage.libs.pari + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 # optional - sage.libs.pari + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True :: - 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 + 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 + 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)]) # optional - sage.rings.number_field + 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] # optional - sage.rings.number_field + 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, @@ -1693,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([]) # optional - sage.rings.number_field - sage: type(U[0][0]) # optional - sage.rings.number_field + 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]) # optional - sage.rings.number_field + sage: type(U[0][1]) # optional - sage.rings.number_field - sage: type(U[1][1]) # optional - sage.rings.number_field + sage: type(U[1][1]) # optional - sage.rings.number_field """ @@ -1742,53 +1748,55 @@ def units(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) # optional - sage.rings.number_field - sage: K.unit_group() # optional - sage.rings.number_field + 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 # optional - sage.libs.pari + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 # optional - sage.libs.pari + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True sage: x = polygen(ZZ, 'x') - sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari - sage: K.units(()) # optional - sage.libs.pari + 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) # 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 + 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) # optional - sage.rings.number_field - sage: L.unit_group() # optional - sage.rings.number_field + 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 + sage: L.unit_group().gens() # abstract generators # optional - sage.rings.number_field (u0, u1, u2) - 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] + 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) # optional - sage.libs.pari - sage: U = L.units() # optional - sage.libs.pari - sage: type(U[0][0]) # optional - sage.libs.pari + 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]) # optional - sage.libs.pari + sage: type(U[0][1]) # optional - sage.libs.pari - sage: type(U[1][1]) # optional - sage.libs.pari + sage: type(U[1][1]) # optional - sage.libs.pari """ @@ -1817,22 +1825,24 @@ def selmer_generators(self, S, m, proof=True): EXAMPLES:: - 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 + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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] """ @@ -1867,13 +1877,13 @@ def _factor_multivariate_polynomial(self, f, proof=True): TESTS:: - sage: k. = GF(4) # optional - sage.libs.pari - sage: R. = k[] # optional - sage.libs.pari - sage: l. = k.extension(b^2 + b + a) # optional - sage.libs.pari - sage: K. = FunctionField(l) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: F = t * x # optional - sage.libs.pari - sage: F.factor(proof=False) # optional - sage.libs.pari + 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 """ @@ -1894,17 +1904,17 @@ def _factor_univariate_polynomial(self, f): TESTS:: - sage: K = GF(2) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: L. = K.extension(x^2 + x + 1) # optional - sage.libs.pari - sage: R. = L[] # optional - sage.libs.pari - sage: M. = L.extension(y^2 + y + x) # optional - sage.libs.pari - sage: R. = M[] # optional - sage.libs.pari - sage: R(y).factor() # indirect doctest # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: (y*T^2 + y*T + y*x).factor() # indirect doctest # optional - sage.rings.finite_rings (y) * (T + y) * (T + y + 1) """ @@ -1945,36 +1955,36 @@ def _isomorphic_ring(self): EXAMPLES:: - sage: K. = GF(4) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: L. = K.extension(b^2 + b + a); L # optional - sage.libs.pari + 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.libs.pari + 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[] # optional - sage.libs.pari - sage: M. = L.extension(c^2 + b*c + b); M # optional - sage.libs.pari + 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.libs.pari + 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) # 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 + 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) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: from_L, to_L, L = R.quo(b)._isomorphic_ring(); L # optional - sage.libs.pari + 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 """ @@ -2091,13 +2101,13 @@ def _test_isomorphic_ring(self, **options): TESTS:: - sage: K. = GF(4) # optional - sage.libs.pari - sage: R. = K[] # optional - sage.libs.pari - sage: L. = K.extension(b^2 + b + a) # optional - sage.libs.pari - sage: L._test_isomorphic_ring() # optional - sage.libs.pari - sage: R. = L[] # optional - sage.libs.pari - sage: M. = L.extension(c^2 + b*c + b) # optional - sage.libs.pari - sage: M._test_isomorphic_ring() # optional - sage.libs.pari + 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) @@ -2135,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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: isinstance(f, PolynomialQuotientRing_coercion) # optional - sage.libs.pari True - sage: TestSuite(f).run(skip=['_test_pickling']) # optional - sage.libs.pari + sage: TestSuite(f).run(skip=['_test_pickling']) # optional - sage.libs.pari Pickling works:: - sage: g = loads(dumps(f)); g # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: f == g # optional - sage.libs.pari True """ @@ -2169,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)) # optional - sage.libs.pari - sage: f.is_injective() # optional - sage.libs.pari + 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 """ @@ -2193,18 +2205,18 @@ def is_surjective(self): domain:: sage: R. = ZZ[] - sage: f = R.quo(x).coerce_map_from(R.quo(x^2)) # optional - sage.libs.pari - sage: f.is_surjective() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: R. = A[] # optional - sage.libs.pari - sage: S. = A.fraction_field()[] # optional - sage.libs.pari - sage: f = S.quo(x^2 + 2).coerce_map_from(R.quo(x^2 + 2)) # optional - sage.libs.pari - sage: f.is_surjective() # optional - sage.libs.pari + 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 """ @@ -2223,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)) # 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 + 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 # optional - sage.libs.pari + sage: f == f # optional - sage.libs.pari True """ @@ -2241,13 +2253,13 @@ class PolynomialQuotientRing_domain(PolynomialQuotientRing_generic, IntegralDoma EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quotient(x^2 + 1) # optional - sage.libs.pari - sage: S # optional - sage.libs.pari + 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 + sage: loads(S.dumps()) == S # optional - sage.libs.pari True - sage: loads(xbar.dumps()) == xbar # optional - sage.libs.pari + sage: loads(xbar.dumps()) == xbar # optional - sage.libs.pari True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2257,21 +2269,21 @@ def __init__(self, ring, polynomial, name=None, category=None): TESTS:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quotient(x^2 + 1) # optional - sage.libs.pari - sage: TestSuite(S).run() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: S in IntegralDomains() # optional - sage.libs.pari True Check that :trac:`29017` is fixed:: sage: R. = ZZ[] - 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 + 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) @@ -2296,21 +2308,21 @@ def field_extension(self, names): EXAMPLES:: sage: R. = PolynomialRing(Rationals()) - 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 + 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() # optional - sage.libs.pari sage.rings.number_field - sage: f(alpha) # optional - sage.libs.pari sage.rings.number_field + 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) # optional - sage.libs.pari sage.rings.number_field + 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'] # optional - sage.libs.pari - sage: S. = R.quo(x^3 - 2) # optional - sage.libs.pari - sage: F, g, h = S.field_extension('b') # optional - sage.libs.pari + 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' @@ -2318,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'] # optional - sage.libs.pari - sage: S. = R.quo(x^3 + 2*x + 1) # optional - sage.libs.pari - sage: F, g, h = S.field_extension('b') # optional - sage.libs.pari - sage: h(F.0^2 + 3) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # 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 + 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 @@ -2345,19 +2357,19 @@ def field_extension(self, names): :: sage: R. = QQ['x'] - 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 + 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) # 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 + 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)) # optional - sage.rings.number_field + sage: h(g(z)) # optional - sage.rings.number_field z - sage: g(h(w)) # optional - sage.rings.number_field + sage: g(h(w)) # optional - sage.rings.number_field w AUTHORS: @@ -2377,12 +2389,13 @@ class PolynomialQuotientRing_field(PolynomialQuotientRing_domain, Field): EXAMPLES:: sage: R. = PolynomialRing(QQ) - 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 + 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 # optional - sage.rings.number_field + sage: loads(xbar.dumps()) == xbar # optional - sage.rings.number_field True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2403,9 +2416,9 @@ def complex_embeddings(self, prec=53): sage: R. = QQ[] sage: f = x^5 + x + 17 - 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 + 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, diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py index d2b0e167b76..0991bc1e44b 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py @@ -8,8 +8,8 @@ :: sage: R. = ZZ[] - sage: S. = R.quotient(x^3 + 3*x - 1) # optional - sage.libs.pari - sage: 2 * a^3 # optional - sage.libs.pari + 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 @@ -17,24 +17,24 @@ :: - sage: S1. = S[] # optional - sage.libs.pari + sage: S1. = S[] # optional - sage.libs.pari And, we quotient out that by `y^2 + a`. :: - sage: T. = S1.quotient(y^2 + a) # optional - sage.libs.pari + sage: T. = S1.quotient(y^2 + a) # optional - sage.libs.pari In the quotient `z^2` is `-a`. :: - sage: z^2 # optional - sage.libs.pari + sage: z^2 # optional - sage.libs.pari -a And since `a^3 = -3x + 1`, we have:: - sage: z^6 # optional - sage.libs.pari + sage: z^6 # optional - sage.libs.pari 3*a - 1 :: @@ -47,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 @@ -97,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) @@ -162,15 +162,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: Zx. = ZZ[] - 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 + 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) # optional - sage.rings.number_field + sage: phi(i*q) # optional - sage.rings.number_field -i*t - i """ return self._polynomial._im_gens_(codomain, im_gens, base_map=base_map) @@ -271,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 @@ -287,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 """ @@ -304,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 @@ -322,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) @@ -469,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: @@ -694,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: @@ -716,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() @@ -742,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 """ @@ -772,13 +772,14 @@ def rational_reconstruction(self, *args, **kwargs): EXAMPLES:: - sage: R. = GF(65537)[] # optional - sage.libs.pari - sage: m = (x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 + 17496*x^6 # optional - sage.libs.pari - ....: + 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.libs.pari + 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.libs.pari - sage: f_mod_m.rational_reconstruction() # optional - sage.libs.pari + 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_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index 090d41fa538..db99b06f53f 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -47,17 +47,17 @@ We create a polynomial ring over a quaternion algebra:: - 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 + 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 # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules - sage: f * g # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules + sage: g * f # optional - sage.combinat sage.modules w^2 + (i + j)*w - k :trac:`9944` introduced some changes related with @@ -88,28 +88,28 @@ 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) # optional - sage.libs.pari + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) # optional - sage.libs.pari + sage: R.has_coerce_map_from(S) # optional - sage.rings.finite_rings False - sage: S.has_coerce_map_from(R) # optional - sage.libs.pari + sage: S.has_coerce_map_from(R) # optional - sage.rings.finite_rings False - sage: S.0 + R.0 # optional - sage.libs.pari + sage: S.0 + R.0 # optional - sage.rings.finite_rings 2*x - sage: (S.0 + R.0).parent() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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') # optional - sage.libs.ntl - sage: S. = PolynomialRing(ZZ, implementation='FLINT') # optional - sage.libs.flint - sage: (S.0+R.0).parent() is S # optional - sage.libs.flint sage.libs.ntl + sage: 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 # optional - sage.libs.flint sage.libs.ntl + 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]) # optional - sage.modules - sage: v2 = vector([CDF(2)]) # optional - sage.modules - sage: v1 * v2 # optional - sage.modules + 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 # optional - sage.libs.singular + sage: R. = PolynomialRing(ZZ, implementation="singular"); R # optional - sage.libs.singular Multivariate Polynomial Ring in w over Integer Ring - sage: is_PolynomialRing(R) # optional - sage.libs.singular + sage: is_PolynomialRing(R) # optional - sage.libs.singular False - sage: type(R) # optional - sage.libs.singular + 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']) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: GF(7)['x']['y'].is_finite() # optional - sage.rings.finite_rings False """ @@ -393,10 +393,10 @@ 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') # optional - sage.libs.pari - sage: L. = GF(5^4, prefix='z') # optional - sage.libs.pari - sage: f = K['x'].gen() + a # optional - sage.libs.pari - sage: L['x'](f) # optional - sage.libs.pari + 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` :: @@ -693,7 +693,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)) # optional - sage.libs.pari + sage: R.coerce_map_from(GF(7)) # optional - sage.rings.finite_rings """ from .polynomial_element import PolynomialBaseringInjection @@ -843,11 +843,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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 +867,9 @@ def _magma_init_(self, magma): A nested example over a Givaro finite field:: - sage: k. = GF(9) # optional - sage.libs.pari - sage: R. = k[] # optional - sage.libs.pari - sage: magma(a^2*x^3 + (a+1)*x + a) # optional - magma # optional - sage.libs.pari + 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()) @@ -899,12 +899,12 @@ def _gap_init_(self, gap=None): ring over a number field:: sage: Q. = QQ[] - sage: K. = NumberField(t^2+t+1) # optional - sage.rings.number_field + 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.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) # optional - sage.rings.number_field + sage: gap(S) is gap(S) # optional - sage.libs.gap sage.rings.number_field True """ if gap is not None: @@ -920,11 +920,11 @@ def _sage_input_(self, sib, coerced): EXAMPLES:: - sage: sage_input(GF(5)['x']['y'], verify=True) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: ZZ['z']._sage_input_(SageInputBuilder(), False) # optional - sage.libs.pari + 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()) @@ -964,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]) # optional - sage.libs.pari + sage: R._is_valid_homomorphism_(GF(7), [5]) # optional - sage.rings.finite_rings False - sage: R._is_valid_homomorphism_(Qp(7), [5]) # optional - sage.rings.padics + sage: R._is_valid_homomorphism_(Qp(7), [5]) # optional - sage.rings.padics True """ # Since poly rings are free, any image of the gen @@ -1005,7 +1005,7 @@ def _latex_(self): r""" EXAMPLES:: - sage: S.=ZZ[] + sage: S. = ZZ[] sage: latex(S) \Bold{Z}[\alpha_{12}] """ @@ -1043,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')) # optional - sage.libs.pari + 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 @@ -1147,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 # optional - sage.libs.pari + 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 @@ -1168,10 +1168,10 @@ def cyclotomic_polynomial(self, n): x^4 + 1 sage: R.cyclotomic_polynomial(12) # optional - sage.libs.pari x^4 - x^2 + 1 - sage: S = PolynomialRing(FiniteField(7), 'x') # optional - sage.libs.pari - sage: S.cyclotomic_polynomial(12) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: S.cyclotomic_polynomial(1) # optional - sage.rings.finite_rings x + 6 TESTS: @@ -1308,16 +1308,16 @@ def krull_dimension(self): sage: R. = QQ[] sage: R.krull_dimension() 1 - sage: R. = GF(9, 'a')[]; R # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: R.krull_dimension() # optional - sage.rings.finite_rings 1 - sage: S. = R[] # optional - sage.libs.pari - sage: S.krull_dimension() # optional - sage.libs.pari + sage: S. = R[] # optional - sage.rings.finite_rings + sage: S.krull_dimension() # optional - sage.rings.finite_rings 2 - sage: for n in range(10): # optional - sage.libs.pari + sage: for n in range(10): # optional - sage.rings.finite_rings ....: S = PolynomialRing(S, 'w') - sage: S.krull_dimension() # optional - sage.libs.pari + sage: S.krull_dimension() # optional - sage.rings.finite_rings 12 """ return self.base_ring().krull_dimension() + 1 @@ -1391,13 +1391,13 @@ def random_element(self, degree=(-1,2), *args, **kwds): Check that :trac:`16682` is fixed:: - sage: R = PolynomialRing(GF(2), 'z') # optional - sage.libs.pari - sage: for _ in range(100): # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 @@ -1495,12 +1495,12 @@ def _Karatsuba_threshold(self): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: R._Karatsuba_threshold # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R._Karatsuba_threshold # optional - sage.rings.number_field 8 - sage: MS = MatrixSpace(ZZ, 2, 2) # optional - sage.modules - sage: R. = MS[] # optional - sage.modules - sage: R._Karatsuba_threshold # optional - sage.modules + 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() @@ -1571,8 +1571,8 @@ def polynomials( self, of_degree = None, max_degree = None ): EXAMPLES:: - sage: P = PolynomialRing(GF(3), 'y') # optional - sage.libs.pari - sage: for p in P.polynomials(of_degree=2): print(p) # optional - sage.libs.pari + 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 @@ -1591,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) # optional - sage.libs.pari + sage: for p in P.polynomials(max_degree=1): print(p) # optional - sage.rings.finite_rings 0 1 2 @@ -1601,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) # optional - sage.libs.pari + 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 @@ -1638,8 +1638,8 @@ def monics( self, of_degree = None, max_degree = None ): EXAMPLES:: - sage: P = PolynomialRing(GF(4, 'a'), 'y') # optional - sage.libs.pari - sage: for p in P.monics(of_degree=2): print(p) # optional - sage.libs.pari + 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 @@ -1656,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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 @@ -1751,9 +1751,9 @@ def weyl_algebra(self): EXAMPLES:: sage: R = QQ['x'] - sage: W = R.weyl_algebra(); W # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules + sage: W.polynomial_ring() == R # optional - sage.combinat sage.modules True """ from sage.algebras.weyl_algebra import DifferentialWeylAlgebra @@ -1816,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()) # optional - sage.libs.flint + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl + 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()) # optional - sage.libs.ntl + sage: type(R.gen()) # optional - sage.libs.ntl """ self._implementation_repr = '' @@ -1890,19 +1890,19 @@ def weil_polynomials(self, d, q, sign=1, lead=1): EXAMPLES:: sage: R. = ZZ[] - sage: L = R.weil_polynomials(4, 2) # optional - sage.libs.flint - sage: len(L) # optional - sage.libs.flint + sage: L = R.weil_polynomials(4, 2) # optional - sage.libs.flint + sage: len(L) # optional - sage.libs.flint 35 - sage: L[9] # optional - sage.libs.flint + 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) # optional - sage.libs.flint + 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))) # optional - sage.libs.flint - sage: l # optional - sage.libs.flint + 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, @@ -1912,10 +1912,10 @@ def weil_polynomials(self, d, q, sign=1, lead=1): 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) # optional - sage.libs.flint - sage: len(l) # optional - sage.libs.flint + 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] # optional - sage.libs.flint + sage: l[len(l)//2] # optional - sage.libs.flint 2*T^10 + T^8 + T^6 + T^4 + T^2 + 2 TESTS: @@ -1987,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 # optional - sage.libs.ntl + 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) @@ -2007,11 +2007,11 @@ def construction(self): sage: functor.implementation is None True - sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl + 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 # optional - sage.libs.ntl + sage: functor, arg = R.construction(); functor, arg # optional - sage.libs.ntl (Poly[x], Integer Ring) - sage: functor.implementation # optional - sage.libs.ntl + sage: functor.implementation # optional - sage.libs.ntl 'NTL' """ implementation = None @@ -2036,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()) # optional - sage.libs.flint + 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 @@ -2049,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) # optional - sage.libs.pari + 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 """ @@ -2096,8 +2096,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: R. = GF(5)[] # optional - sage.libs.pari - sage: R._ideal_class_() # optional - sage.libs.pari + 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 @@ -2137,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]_:: @@ -2173,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] @@ -2242,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 @@ -2252,15 +2249,15 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r -2 sage: f(-4) 9 - sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.libs.pari - sage: a = R.base_ring().gen() # optional - sage.libs.pari - sage: f = R.lagrange_polynomial([(a^2+a,a), (a,1), (a^2,a^2+a+1)]); f # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f(a^2 + a) # optional - sage.rings.finite_rings a - sage: f(a) # optional - sage.libs.pari + sage: f(a) # optional - sage.rings.finite_rings 1 - sage: f(a^2) # optional - sage.libs.pari + sage: f(a^2) # optional - sage.rings.finite_rings a^2 + a + 1 Now use a memory efficient version of Neville's method:: @@ -2272,9 +2269,9 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r -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') # optional - sage.libs.pari - sage: a = R.base_ring().gen() # optional - sage.libs.pari - sage: R.lagrange_polynomial([(a^2+a,a), (a,1), (a^2,a^2+a+1)], # optional - sage.libs.pari + 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] @@ -2286,10 +2283,10 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r 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') # optional - sage.libs.pari - sage: a = R.base_ring().gen() # optional - sage.libs.pari - sage: p = R.lagrange_polynomial([(a^2+a,a), (a,1)], algorithm="neville") # optional - sage.libs.pari - sage: R.lagrange_polynomial([(a^2+a,a), (a,1), (a^2,a^2+a+1)], # optional - sage.libs.pari + 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 @@ -2332,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)[] # optional - sage.libs.pari - sage: R.lagrange_polynomial([[1, 0], [2, 0]]) # optional - sage.libs.pari + 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]]) # optional - sage.libs.pari + 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 @@ -2421,8 +2418,8 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] # optional - sage.libs.pari - sage: R.fraction_field() # optional - sage.libs.pari + 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 @@ -2430,16 +2427,16 @@ def fraction_field(self): Check that :trac:`25449` has been resolved:: - sage: k = GF(25453) # optional - sage.libs.pari - sage: F. = FunctionField(k) # optional - sage.libs.pari - sage: R. = k[] # optional - sage.libs.pari - sage: t(x) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: F. = FunctionField(k) # optional - sage.libs.pari - sage: R. = k[] # optional - sage.libs.pari - sage: t(x) # optional - sage.libs.pari + 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 """ @@ -2459,24 +2456,24 @@ class PolynomialRing_dense_finite_field(PolynomialRing_field): EXAMPLES:: - sage: R = PolynomialRing(GF(27, 'a'), 'x') # optional - sage.libs.pari - sage: type(R) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: R = PolynomialRing_dense_finite_field(GF(5), implementation='generic') # optional - sage.libs.pari - sage: type(R(0)) # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: type(S(0)) # optional - sage.libs.pari + 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') # optional - sage.libs.pari + 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 @@ -2505,16 +2502,16 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.libs.pari - sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) # optional - sage.rings.finite_rings NotImplemented """ if sparse: @@ -2549,14 +2546,15 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: f = GF(5^3, 'a')['x'].irreducible_element(2) # optional - sage.libs.pari - sage: f.degree() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: f.is_irreducible() # optional - sage.rings.finite_rings True - sage: GF(19)['x'].irreducible_element(21, algorithm="first_lexicographic") # optional - sage.libs.pari + sage: GF(19)['x'].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") # optional - sage.libs.pari + sage: GF(5**2, 'a')['x'].irreducible_element(17, # optional - sage.rings.finite_rings + ....: algorithm="first_lexicographic") x^17 + a*x + 4*a + 3 AUTHORS: @@ -2617,15 +2615,15 @@ def _roth_ruckenstein(self, p, degree_bound, precision): EXAMPLES:: - sage: F = GF(17) # optional - sage.libs.pari - sage: Px. = F[] # optional - sage.libs.pari - sage: Pxy. = Px[] # optional - sage.libs.pari - sage: p = (y - (x**2 + x + 1)) * (y**2 - x + 1) * (y - (x**3 + 4*x + 16)) # optional - sage.libs.pari - sage: Px._roth_ruckenstein(p, 3, None) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: Px._roth_ruckenstein(p, 2, None) # optional - sage.rings.finite_rings [x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 1, 2) # optional - sage.libs.pari + 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): @@ -2716,29 +2714,29 @@ def _alekhnovich(self, p, degree_bound, precision=None, dc_threshold=None): EXAMPLES:: - sage: R. = GF(17)[] # optional - sage.libs.pari - sage: S. = R[] # optional - sage.libs.pari - sage: p = (y - 2*x^2 - 3*x - 14) * (y - 3*x + 2) * (y - 1) # optional - sage.libs.pari - sage: R._alekhnovich(p, 2) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: R._alekhnovich(p, 1) # optional - sage.rings.finite_rings [3*x + 15, 1] - sage: R._alekhnovich(p, 1, precision=2) # optional - sage.libs.pari + 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) # not tested # optional - sage.libs.pari + 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.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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: @@ -2828,24 +2826,24 @@ def _roots_univariate_polynomial(self, p, ring=None, multiplicities=False, algor EXAMPLES:: - sage: R. = GF(13)[] # optional - sage.libs.pari - sage: S. = R[] # optional - sage.libs.pari - sage: p = y^2 + (12*x^2 + x + 11)*y + x^3 + 12*x^2 + 12*x + 1 # optional - sage.libs.pari - sage: p.roots(multiplicities=False) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: p.roots(multiplicities=False, degree_bound=1) # optional - sage.rings.finite_rings [x + 1] - sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") # optional - sage.libs.pari + 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'] # optional - sage.libs.pari - sage: R.one().roots(multiplicities=False) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: R.zero().roots(multiplicities=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: roots of 0 are not defined @@ -2890,7 +2888,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: isinstance(S, PolynomialRing_cdvr) False - sage: S. = Zp(5)[] # optional - sage.rings.padics + sage: S. = Zp(5)[] # optional - sage.rings.padics sage: isinstance(S, PolynomialRing_cdvr) True """ @@ -2921,8 +2919,8 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: isinstance(S, PolynomialRing_cdvf) False - sage: S. = Qp(5)[] # optional - sage.rings.padics - sage: isinstance(S, PolynomialRing_cdvf) # optional - sage.rings.padics + sage: S. = Qp(5)[] # optional - sage.rings.padics + sage: isinstance(S, PolynomialRing_cdvf) # optional - sage.rings.padics True """ if element_class is None: @@ -3210,38 +3208,38 @@ def residue_field(self, ideal, names=None): EXAMPLES:: - sage: R. = GF(2)[] # optional - sage.libs.pari - sage: k. = R.residue_field(t^3+t+1); k # optional - sage.libs.pari + 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.libs.pari + 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) # optional - sage.libs.pari + 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.libs.pari - sage: P # optional - sage.libs.pari + 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.libs.pari + 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.libs.pari + sage: k.cardinality() # optional - sage.rings.finite_rings 256 Non-maximal ideals are not accepted:: - sage: R.residue_field(t^2 + 1) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: R.residue_field(1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal @@ -3259,36 +3257,36 @@ def __init__(self, base_ring, name="x", implementation=None, element_class=None, """ TESTS:: - sage: P = GF(2)['x']; P # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p # optional - sage.libs.pari - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') # optional - sage.libs.pari - sage: P # optional - sage.libs.pari + 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()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: B = GF(p^3) # optional - sage.libs.pari - sage: R = A.modulus().parent() # optional - sage.libs.pari - sage: S = B.modulus().parent() # optional - sage.libs.pari - sage: R is S # optional - sage.libs.pari + 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: @@ -3330,15 +3328,15 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: PolynomialRing(GF(2), 'x', implementation="GF2X") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + sage: PolynomialRing(GF(3), 'x', implementation="GF2X") # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: GF2X only supports modulus 2 @@ -3410,35 +3408,35 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: GF(5)['x'].irreducible_element(2) # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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") # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: GF(97)['x'].irreducible_element(1) # optional - sage.rings.finite_rings x + 96 - sage: GF(97)['x'].irreducible_element(1, algorithm="conway") # optional - sage.libs.pari + 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") # optional - sage.libs.pari + sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") # optional - sage.rings.finite_rings x AUTHORS: @@ -3517,7 +3515,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) diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index 25763ac3d09..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 # optional - sage.libs.pari - 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 # optional - sage.libs.ntl + 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 # optional - sage.libs.flint + 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'] # optional - sage.libs.flint + sage: ZxFLINT is ZZ['x'] # optional - sage.libs.flint True - sage: ZxFLINT is PolynomialRing(ZZ, 'x') # optional - sage.libs.flint + sage: ZxFLINT is PolynomialRing(ZZ, 'x') # optional - sage.libs.flint True - sage: xNTL = ZxNTL.gen() # optional - sage.libs.ntl - sage: xFLINT = ZxFLINT.gen() # optional - sage.libs.flint - sage: xNTL.parent() # optional - sage.libs.ntl + 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() # optional - sage.libs.flint + 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) # optional - sage.libs.flint sage.libs.ntl + 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() # optional - sage.libs.flint sage.libs.ntl + 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") # optional - sage.libs.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 # optional - sage.libs.singular + 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) # optional - sage.libs.pari + 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 # 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 + 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() # 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 + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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,37 +942,37 @@ def BooleanPolynomialRing_constructor(n=None, names=None, order="lex"): EXAMPLES:: - sage: R. = BooleanPolynomialRing() # indirect doctest # optional - sage.rings.polynomial.pbori - sage: R # optional - sage.rings.polynomial.pbori + 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 # optional - sage.rings.polynomial.pbori - sage: x*p # optional - sage.rings.polynomial.pbori + 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() # optional - sage.rings.polynomial.pbori + sage: R.term_order() # optional - sage.rings.polynomial.pbori Lexicographic 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 + 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') # optional - sage.rings.polynomial.pbori - sage: R.term_order() # optional - sage.rings.polynomial.pbori + 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')) # optional - sage.rings.polynomial.pbori + sage: BooleanPolynomialRing(names=('x','y')) # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y - sage: BooleanPolynomialRing(names='x,y') # optional - sage.rings.polynomial.pbori + sage: BooleanPolynomialRing(names='x,y') # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y TESTS:: - sage: P. = BooleanPolynomialRing(2, order='deglex') # optional - sage.rings.polynomial.pbori - sage: x > y # optional - sage.rings.polynomial.pbori + 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)') # optional - sage.rings.polynomial.pbori diff --git a/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx b/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx index 8148a21747a..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'] # optional - sage.libs.pari - sage: f = ZZ.hom(GF(5)) # optional - sage.libs.pari - sage: F = PolynomialRingHomomorphism_from_base(R.Hom(S), f) # optional - sage.libs.pari - sage: F(2 * x, check=True) # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: A = PolynomialRing(GF(7), 'x', sparse=True) # optional - sage.libs.pari - sage: B = PolynomialRing(k, 'x', sparse=True) # optional - sage.libs.pari - sage: g = GF(7).hom(k) # optional - sage.libs.pari - sage: G = PolynomialRingHomomorphism_from_base(A.Hom(B), g) # optional - sage.libs.pari - sage: G(A.gen()^1000000, True, construct=False) # optional - sage.libs.pari + 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 e457baa333e..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') # optional - sage.libs.pari - sage: R == loads(dumps(R)) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: f = (a^3 + 2*b^2*a)^7; f # optional - sage.libs.pari + 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') # optional - sage.libs.singular + 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')) # optional - sage.rings.number_field - sage: singular(R) # optional - sage.rings.number_field + 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") # optional - sage.libs.pari - sage: singular(R) # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: singular(R) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: R = k['x'] # optional - sage.libs.pari - sage: K = R.fraction_field() # optional - sage.libs.pari - sage: S = K['y'] # optional - sage.libs.pari - sage: singular(S) # optional - sage.libs.pari + 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 @@ -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]) # optional - sage.rings.number_field - sage: can_convert_to_singular(K['s,t']) # optional - sage.rings.number_field + 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)[] # optional - sage.libs.pari - sage: R._has_singular # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: R._has_singular # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: R._has_singular # optional - sage.libs.pari + 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)[] # optional - sage.libs.pari - sage: R._has_singular # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: f = (a^3 + 2*b^2*a)^7; f # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: h = f._singular_(); h # optional - sage.rings.finite_rings a^21+2*a^7*b^14 - sage: P(h) # optional - sage.libs.pari + sage: P(h) # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 - sage: P(h^20) == f^20 # optional - sage.libs.pari + sage: P(h^20) == f^20 # optional - sage.rings.finite_rings True - sage: R. = PolynomialRing(GF(7)) # optional - sage.libs.pari - sage: f = (x^3 + 2*x^2*x)^7 # optional - sage.libs.pari - sage: f # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: h = f._singular_(); h # optional - sage.rings.finite_rings 3*x^21 - sage: R(h) # optional - sage.libs.pari + sage: R(h) # optional - sage.rings.finite_rings 3*x^21 - sage: R(h^20) == f^20 # optional - sage.libs.pari + 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 67cf7e68cde..7acfec8c97f 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari (because all doctests use finite fields) +# 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 2073c50d6b4..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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: eval_pts = [1, t, t^2] # optional - sage.libs.pari - sage: b = _minimal_vanishing_polynomial(S, eval_pts); b # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: eval_pts = [ t , t^2 ] # optional - sage.libs.pari - sage: values = [ 3*t^2 + 4*t + 4 , 4*t ] # optional - sage.libs.pari - sage: d = _lagrange_polynomial(S, eval_pts, values); d # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 ] # optional - sage.libs.pari - sage: values = [ 1, 3 ] # optional - sage.libs.pari - sage: _lagrange_polynomial(S, eval_pts, values) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: eval_pts = [1, t, t^2] # optional - sage.libs.pari - sage: b = S.minimal_vanishing_polynomial(eval_pts); b # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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]) # optional - sage.libs.pari + 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]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob] # optional - sage.libs.pari - sage: points = [(t, 3*t^2 + 4*t + 4), (t^2, 4*t)] # optional - sage.libs.pari - sage: d = S.lagrange_polynomial(points); d # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari - sage: sigma = iota.section() # optional - sage.libs.pari - sage: TestSuite(sigma).run(skip=['_test_category']) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari - sage: sigma = iota.section() # optional - sage.libs.pari - sage: sigma(x^3) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari - sage: sigma = iota.section() # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: s == sigma # optional - sage.libs.pari + sage: s = loads(dumps(sigma)) # optional - sage.rings.finite_rings + sage: s == sigma # optional - sage.rings.finite_rings True - sage: s != sigma # optional - sage.libs.pari + sage: s != sigma # optional - sage.rings.finite_rings False - sage: s is sigma # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari - sage: TestSuite(iota).run(skip=['_test_category']) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: S.convert_map_from(Z) # indirect doctest # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari - sage: iota # optional - sage.libs.pari + 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_() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z. = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: i == iota # optional - sage.libs.pari + sage: i = loads(dumps(iota)) # optional - sage.rings.finite_rings + sage: i == iota # optional - sage.rings.finite_rings True - sage: i != iota # optional - sage.libs.pari + sage: i != iota # optional - sage.rings.finite_rings False - sage: i is iota # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.libs.pari - sage: Z = S.center() # optional - sage.libs.pari - sage: iota = S.convert_map_from(Z) # optional - sage.libs.pari - sage: sigma = iota.section() # optional - sage.libs.pari - sage: sigma(x^3) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x', Frob]; S # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: S.category() # optional - sage.rings.finite_rings Category of algebras over Finite Field in t of size 5^3 - sage: TestSuite(S).run() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: phi = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x', phi] # optional - sage.libs.pari - sage: (x^4).is_central() # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: S.center() is Z # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x',Frob]; S # optional - sage.libs.pari - 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 # optional - sage.libs.pari + sage: Z = S.center(); Z # optional - sage.rings.finite_rings Univariate Polynomial Ring in z over Finite Field of size 5 - sage: Z.gen() # optional - sage.libs.pari + sage: Z.gen() # optional - sage.rings.finite_rings z We can pass in another variable name:: - sage: S.center(name='y') # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: S.has_coerce_map_from(Zy) # optional - sage.rings.finite_rings True - sage: P = y + x; P # optional - sage.libs.pari + sage: P = y + x; P # optional - sage.rings.finite_rings x^3 + x - sage: P.parent() # optional - sage.libs.pari - 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.libs.pari + 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) # optional - sage.libs.pari + sage: Zy(x^6 + 2*x^3 + 3) # optional - sage.rings.finite_rings y^2 + 2*y + 3 - sage: Zy(x^2) # optional - sage.libs.pari + 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] # optional - sage.libs.pari - sage: S2. = k['x2', Frob] # optional - sage.libs.pari - sage: S1.center() is S2.center() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: phi = K.frobenius_endomorphism() # optional - sage.libs.pari - sage: A. = K['X', phi] # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: C # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: D # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: A.center() # optional - sage.rings.finite_rings Univariate Polynomial Ring in v over Finite Field of size 11 - sage: A.center() is D # optional - sage.libs.pari + sage: A.center() is D # optional - sage.rings.finite_rings True TESTS:: - sage: C. = S.center() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: T. = k['x', Frob]; T # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x', Frob] # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: S._matrix_retraction # random # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S._matrix_retraction # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S._matrix_retraction # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: Frob = k.frobenius_endomorphism() # optional - sage.libs.pari - sage: S. = k['x', Frob] # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: S._retraction(a) # random # optional - sage.rings.finite_rings 6 We can specify a seed:: - sage: S._retraction(a^2, seed=a) # random # optional - sage.libs.pari + 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 779e0983c3f..8f4e684b6af 100644 --- a/src/sage/rings/polynomial/symmetric_ideal.py +++ b/src/sage/rings/polynomial/symmetric_ideal.py @@ -118,7 +118,7 @@ class SymmetricIdeal(Ideal_generic): The default ordering is lexicographic. We now compute a Groebner basis:: - sage: J = I.groebner_basis(); J # about 3 seconds # optional - sage.combinat + 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] @@ -127,17 +127,17 @@ class SymmetricIdeal(Ideal_generic): four elements. Ideal membership in ``I`` can now be tested by commuting symmetric reduction modulo ``J``:: - sage: I.reduce(J) # optional - sage.combinat + 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]) # optional - sage.combinat - sage: J[2] # optional - sage.combinat + 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 # optional - sage.combinat + 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 # optional - sage.combinat + sage: J[2]^P in J # optional - sage.combinat False However, any element of ``J`` has symmetric reduction zero even @@ -145,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)] # optional - sage.combinat + 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] # optional - sage.combinat + 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 @@ -164,12 +164,13 @@ class SymmetricIdeal(Ideal_generic): :: 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 + 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 + sage: I * I == X * (x[1]^2) # optional - sage.combinat False """ @@ -234,11 +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() # optional - sage.combinat - sage: I # optional - sage.combinat + 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 + sage: x[2]^2 + x[3] in I # indirect doctest # optional - sage.combinat True """ try: @@ -259,7 +260,7 @@ def __mul__(self, other): sage: X. = InfinitePolynomialRing(QQ) sage: I = X * (x[1]) - sage: I*I # indirect doctest # optional - sage.combinat + 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 """ @@ -299,7 +300,7 @@ def __pow__(self, n): sage: X. = InfinitePolynomialRing(QQ) sage: I = X * (x[1]) - sage: I^2 # indirect doctest # optional - sage.combinat + 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 """ @@ -328,20 +329,20 @@ def is_maximal(self): sage: R. = InfinitePolynomialRing(QQ) 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 + 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 + 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() # optional - sage.combinat - sage: I # optional - sage.combinat + 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 + sage: I.is_maximal() # optional - sage.combinat True """ @@ -396,7 +397,7 @@ 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]]) # optional - sage.combinat + 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 @@ -407,7 +408,7 @@ def reduce(self, I, tailreduce=False): 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) # optional - sage.combinat + 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 """ @@ -452,11 +453,12 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None sage: X. = InfinitePolynomialRing(QQ) 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) # optional - sage.combinat + sage: I.interreduction(report=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> @@ -478,7 +480,7 @@ 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) # optional - sage.combinat + 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 @@ -568,7 +570,7 @@ def interreduced_basis(self): sage: X. = InfinitePolynomialRing(QQ) sage: I = X * (x[1] + x[2], x[1]*x[2]) - sage: I.interreduced_basis() # optional - sage.combinat + sage: I.interreduced_basis() # optional - sage.combinat [-x_1^2, x_2 + x_1] """ @@ -615,11 +617,12 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F sage: X. = InfinitePolynomialRing(QQ) 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 + 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) # optional - sage.combinat + 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 """ @@ -674,7 +677,7 @@ def symmetric_basis(self): sage: X. = InfinitePolynomialRing(QQ) sage: I = X * (x[1] + x[2], x[1]*x[2]) - sage: I.symmetric_basis() # optional - sage.combinat + sage: I.symmetric_basis() # optional - sage.combinat [x_1^2, x_2 + x_1] """ @@ -799,10 +802,10 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= sage: X. = InfinitePolynomialRing(QQ) sage: I1 = X * (x[1] + x[2], x[1]*x[2]) - sage: I1.groebner_basis() # optional - sage.combinat + 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() # optional - sage.combinat + 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 @@ -812,13 +815,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) # optional - sage.combinat + 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) # optional - sage.combinat + sage: I1.groebner_basis(report=True, reduced=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> @@ -891,7 +894,7 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= sage: R. = InfinitePolynomialRing(ZZ) sage: I = R * [x[1] + x[2], y[1]] - sage: I.groebner_basis() # optional - sage.combinat + sage: I.groebner_basis() # optional - sage.combinat Traceback (most recent call last): ... TypeError: The base ring (= Integer Ring) must be a field @@ -900,17 +903,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') # optional - sage.libs.pari + 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 + sage: I.groebner_basis() # optional - sage.combinat sage.libs.pari [1] - sage: Y. = InfinitePolynomialRing(GF(3), order='degrevlex', # optional - sage.libs.pari + 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 + 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 94e87448bbe..75d3e4c4261 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 @@ -77,15 +77,15 @@ change variable index 1 into 2 and 2 into 3. So, we add this to 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) # optional - sage.combinat + 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]) # optional - sage.combinat + 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]) # optional - sage.combinat + 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 @@ -97,7 +97,7 @@ Symmetric Reduction Strategy is created:: 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]) # optional - sage.combinat + sage: S2.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 """ @@ -144,7 +144,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]) # optional - sage.combinat + sage: S.tailreduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) # optional - sage.combinat y_3 """ @@ -424,18 +424,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]) # optional - sage.combinat - sage: S # optional - sage.combinat - 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 +446,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]) # optional - sage.combinat - sage: S # optional - sage.combinat - 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]) # optional - sage.combinat + sage: S.reduce(x[3] + x[2]) # optional - sage.combinat -2*x_1 - 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 + 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 +533,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 +545,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 +633,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]) # optional - sage.combinat + 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) # optional - sage.combinat + 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 bf6d879d9d2..92cd909fab3 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 # optional - sage.modules + sage: m = matrix(2, [2,3,0,1]); m # optional - sage.modules [2 3] [0 1] - sage: T = TermOrder(m); T # optional - sage.modules + sage: T = TermOrder(m); T # optional - sage.modules Matrix term order with matrix [2 3] [0 1] - sage: P. = PolynomialRing(QQ, 2, order=T) # optional - sage.modules - sage: P # optional - sage.modules + 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 # optional - sage.modules + sage: a > b # optional - sage.modules False - sage: a^3 < b^2 # optional - sage.modules + sage: a^3 < b^2 # optional - sage.modules True - sage: S = TermOrder('M(2,3,0,1)') # optional - sage.modules - sage: T == S # optional - sage.modules + 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 @@ -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_() # optional - sage.libs.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_() # optional - sage.libs.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() # optional - sage.libs.pari - sage: T.singular_str() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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)') # optional - sage.rings.number_field - sage: y > x^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: x*y > y*z # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: x > y^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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)') # optional - sage.rings.number_field - sage: a > c^4 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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)') # optional - sage.rings.number_field - sage: x > y # optional - sage.rings.number_field + 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)') # optional - sage.rings.number_field - sage: y > x^2 # indirect doctest # optional - sage.rings.number_field + 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 # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y^2; f.lm() # indirect doctest # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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') # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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)') # optional - sage.rings.number_field - sage: f = a + c^4; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^3 + z; f.lm() # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^3 + z; f.lm() # optional - sage.rings.number_field + 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)') # optional - sage.rings.number_field - sage: f = a + c^4; f.lm() # indirect doctest # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: g = a + e^4; g.lm() # optional - sage.rings.number_field a """ n = 0 @@ -1601,8 +1605,8 @@ def tuple_weight(self, f): EXAMPLES:: 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 + 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)') # optional - sage.libs.pari - sage: T = P.term_order() # optional - sage.libs.pari - sage: T.singular_str() # optional - sage.libs.pari + 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_() # optional - sage.libs.pari + 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_() # optional - sage.libs.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_() # optional - sage.libs.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_() # optional - sage.libs.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_() # optional - sage.libs.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)') # optional - sage.libs.pari - sage: T = P.term_order() # optional - sage.libs.pari - sage: T.singular_moreblocks() # optional - sage.libs.pari + 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)') # optional - sage.libs.pari - sage: T = P.term_order() # optional - sage.libs.pari - sage: T.singular_moreblocks() # optional - sage.libs.pari + 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)') # optional - sage.libs.pari - sage: T = P.term_order() # optional - sage.libs.pari - sage: T.singular_moreblocks() # optional - sage.libs.pari + 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)') # optional - sage.libs.pari - sage: T = P.term_order() # optional - sage.libs.pari - sage: T.macaulay2_str() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: magma(P) # optional - magma # optional - sage.libs.pari + 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() # optional - sage.libs.pari - sage: T.magma_str() # optional - sage.libs.pari + 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)") # optional - sage.modules - sage: t.matrix() # optional - sage.modules + 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 """ diff --git a/src/sage/rings/polynomial/toy_buchberger.py b/src/sage/rings/polynomial/toy_buchberger.py index f71b9423e36..e01dada2479 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)) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P, 6) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: g2 = buchberger_improved(I) # optional - sage.libs.pari - sage: g3 = I.groebner_basis() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: Ideal(g1).basis_is_groebner() # optional - sage.rings.finite_rings True - sage: Ideal(g2).basis_is_groebner() # optional - sage.libs.pari + sage: Ideal(g2).basis_is_groebner() # optional - sage.rings.finite_rings True - sage: Ideal(g3).basis_is_groebner() # optional - sage.libs.pari + sage: Ideal(g3).basis_is_groebner() # optional - sage.rings.finite_rings True The results are correct:: - sage: Ideal(g1) == Ideal(g2) == Ideal(g3) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari + 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 # optional - sage.libs.pari - 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: gb = buchberger_improved(I) # optional - sage.rings.finite_rings ... 1 reductions to zero. - sage: sorted(gb) # optional - sage.libs.pari - [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: diff --git a/src/sage/rings/polynomial/toy_d_basis.py b/src/sage/rings/polynomial/toy_d_basis.py index 30459d4a44c..3101ae239b9 100644 --- a/src/sage/rings/polynomial/toy_d_basis.py +++ b/src/sage/rings/polynomial/toy_d_basis.py @@ -20,7 +20,7 @@ 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) @@ -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] diff --git a/src/sage/rings/polynomial/toy_variety.py b/src/sage/rings/polynomial/toy_variety.py index ea80c4d64d3..16ccfb6cf8c 100644 --- a/src/sage/rings/polynomial/toy_variety.py +++ b/src/sage/rings/polynomial/toy_variety.py @@ -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)) # optional - sage.libs.pari - sage: B = [x^2 + 1, y^2 + 1, x*y + 1] # optional - sage.libs.pari - sage: p = 3*B[0] - 2*B[1] + B[2] # optional - sage.libs.pari - sage: linear_representation(p, B) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 # optional - sage.libs.pari - sage: p2 = z^2 - z # optional - sage.libs.pari - sage: p3 = (x-2)^2*(y-1)^3 # optional - sage.libs.pari - sage: I = R.ideal(p1,p2,p3) # optional - sage.libs.pari - sage: triangular_factorization(I.groebner_basis()) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 # optional - sage.libs.pari - sage: p2 = z^2 - z # optional - sage.libs.pari - sage: p3 = (x-2)^2*(y-1)^3 # optional - sage.libs.pari - sage: I = R.ideal(p1,p2,p3) # optional - sage.libs.pari - sage: elim_pol(I.groebner_basis()) # optional - sage.libs.pari + 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 31d3a2ef9e9..d952e4afbfc 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)[[]] # optional - sage.libs.pari - sage: f = 3 - t^3 + O(t^5) # optional - sage.libs.pari - sage: f.polynomial() # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: bool(1 + t + O(t^18)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: bool(R(0)) # optional - sage.rings.finite_rings False - sage: bool(O(t^18)) # optional - sage.libs.pari + sage: bool(O(t^18)) # optional - sage.rings.finite_rings False """ return not not self.__f @@ -225,8 +225,8 @@ cdef class PowerSeries_poly(PowerSeries): A series defined over another ring can be substituted:: - sage: S. = GF(7)[[]] # optional - sage.libs.pari - sage: f(2*u + u^3 + O(u^5)) # optional - sage.libs.pari + 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:: @@ -268,18 +268,18 @@ cdef class PowerSeries_poly(PowerSeries): Arguments beyond the first can refer to the base ring:: - sage: P. = GF(5)[] # optional - sage.libs.pari - sage: Q. = P[[]] # optional - sage.libs.pari - sage: h = (1 - x*y)^-1 + O(y^7); h # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = 3 + 6*t^3 + O(t^5) # optional - sage.libs.pari - sage: f._unsafe_mutate(0, 5) # optional - sage.libs.pari - sage: f # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: g._unsafe_mutate(1,0) ; g # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = t + 3*t^4 + O(t^11) # optional - sage.libs.pari - sage: f * GF(7)(3) # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = 1 + 3*t^4 + O(t^120) # optional - sage.libs.pari - sage: 2 * f # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = t + t^4 + O(t^7) # optional - sage.libs.pari - sage: f >> 1 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = 1/(1+I+O(I^8)); f # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = 1/(1+I+O(I^8)); f # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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), diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index 67dc04dcf97..265b073d958 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -258,7 +258,7 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, Power series ring over finite field:: - sage: S = PowerSeriesRing(GF(65537),'x,y'); S # optional - sage.libs.pari + 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 @@ -520,11 +520,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) # optional - sage.libs.pari - sage: R. = k[[]] # optional - sage.libs.pari - sage: R.category() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: TestSuite(R).run() # optional - sage.rings.finite_rings It is checked that the default precision is non-negative (see :trac:`19409`):: @@ -616,13 +616,13 @@ def _repr_(self): EXAMPLES:: - sage: R = GF(17)[['y']] # optional - sage.libs.pari - sage: R # optional - sage.libs.pari + 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__() # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: R # optional - sage.libs.pari + 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()) @@ -662,11 +662,11 @@ def _latex_(self): EXAMPLES:: - sage: R = GF(17)[['y']] # optional - sage.libs.pari - sage: latex(R) # indirect doctest # optional - sage.libs.pari + 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']] # optional - sage.libs.pari - sage: latex(R) # optional - sage.libs.pari + 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]) @@ -680,14 +680,14 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: A = GF(17)[['x']] # optional - sage.libs.pari - sage: A.has_coerce_map_from(ZZ) # indirect doctest # optional - sage.libs.pari + 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']) # optional - sage.libs.pari + sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['y']) # optional - sage.libs.pari + sage: A.has_coerce_map_from(ZZ['y']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.libs.pari + sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings True """ @@ -892,15 +892,15 @@ def _coerce_impl(self, x): We illustrate canonical coercion between power series rings with compatible base rings:: - sage: R. = PowerSeriesRing(GF(7)['w']) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: g = R.coerce(f); g # optional - sage.rings.finite_rings 1 + 2*t + 3*t^2 + 4*t^3 - sage: parent(g) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: S.coerce(g) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no canonical coercion @@ -981,11 +981,11 @@ def base_extend(self, R): EXAMPLES:: - sage: R. = GF(7)[[]]; R # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: R.change_ring(ZZ) # optional - sage.rings.finite_rings Power Series Ring in T over Integer Ring - sage: R.base_extend(ZZ) # optional - sage.libs.pari + sage: R.base_extend(ZZ) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined @@ -1003,13 +1003,13 @@ def change_ring(self, R): sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field - sage: R.change_ring(GF(7)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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')) # optional - sage.rings.number_field + 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? """ @@ -1233,8 +1233,8 @@ def residue_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) # optional - sage.libs.pari - sage: R.residue_field() # optional - sage.libs.pari + 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)) # optional - sage.rings.padics sage: R.residue_field() # optional - sage.rings.padics @@ -1330,10 +1330,10 @@ def fraction_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(7)) # optional - sage.libs.pari - sage: R.fraction_field() # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: Frac(R) # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 """ return self.laurent_series_ring() @@ -1347,7 +1347,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 b9e46323289..936cf6b8485 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -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 # optional - sage.libs.pari - 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)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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 @@ -492,11 +492,11 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: A. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari - sage: x = t + t^2 + O(t^5) # optional - sage.libs.pari - sage: x.lift_to_precision(10) # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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')[[]] # optional - sage.libs.pari - sage: (t^2 + O(t^3)).base_ring() # optional - sage.libs.pari + 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)[[]] # optional - sage.libs.pari - sage: f = 1/(1+I+O(I^8)); f # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: f.truncate(5) # optional - sage.rings.finite_rings I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -1203,12 +1203,12 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari - sage: f = exp(x) + O(x^7); f # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: f = exp(x) + O(x^7) # optional - sage.libs.pari - sage: f >> 3 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: f >> 7 # optional - sage.libs.pari O(x^0) - sage: f >> 99 # optional - sage.libs.pari + sage: f >> 99 # optional - sage.libs.pari O(x^0) - sage: (f >> 99) << 99 # optional - sage.libs.pari + 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[[]] # 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 + 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) # optional - sage.libs.pari - sage: residue = lambda x: k(x) # optional - sage.libs.pari - sage: f = 4*x^2+x+3 # optional - sage.libs.pari - sage: g = f.map_coefficients(residue); g # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: g = f.map_coefficients(residue); g # optional - sage.libs.pari + 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() # optional - sage.libs.pari + 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') # optional - sage.libs.pari - sage: f = q - q^3 + O(q^10) # optional - sage.libs.pari - sage: f.map_coefficients(lambda c: c - 2) # optional - sage.libs.pari + 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() # optional - sage.symbolic + 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) # optional - sage.combinat - sage: s.stieltjes_continued_fraction() # optional - sage.combinat + 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)[[]] # optional - sage.libs.pari - sage: p = 1 + 2 * u^2 # optional - sage.libs.pari - sage: p.nth_root(4) # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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 @@ -2037,7 +2037,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: tan(g) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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: sinh(f) # optional - sage.symbolic + 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 @@ -2101,7 +2101,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: sinh(g) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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 @@ -2190,7 +2190,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: cosh(g) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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 @@ -2278,7 +2278,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: tanh(g) # optional - sage.symbolic + 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) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.symbolic + 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)) # optional - sage.libs.pari - sage: (1 + x + O(x^2)).exp() # optional - sage.libs.pari + 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 @@ -2795,22 +2795,22 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: k. = QQ[[]] - sage: f = 1+17*w+15*w^3+O(w^5) - sage: pari(f) # indirect doctest # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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 # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: pari(1 + O(x^1)) # optional - sage.libs.pari Mod(1, 6) + O(x) - sage: pari(O(x^1)) # optional - sage.libs.pari + sage: pari(O(x^1)) # optional - sage.libs.pari O(x) - sage: pari(O(x^0)) # optional - sage.libs.pari + sage: pari(O(x^0)) # optional - sage.libs.pari O(x^0) """ n = self.prec() diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 0f5c994a0a6..b683889b79a 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -158,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,) @@ -196,8 +196,8 @@ def QuotientRing(R, I, names=None, **kwds): sage: P. = QQ[] 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 + 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 # optional - sage.libs.pari @@ -209,19 +209,20 @@ def QuotientRing(R, I, names=None, **kwds): sage: P. = QQ[] 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 + 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)) # optional - sage.libs.pari - sage: T. = QuotientRing(S,S.ideal(a)) # optional - sage.libs.pari + 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) + 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) @@ -347,12 +348,12 @@ def is_QuotientRing(x): :: - 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 + 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) # optional - sage.combinat sage.modules + sage: is_QuotientRing(F) # optional - sage.combinat sage.modules False """ return isinstance(x, QuotientRing_nc) @@ -375,26 +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') # 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 + 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 + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules - sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + 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 + sage: i^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat sage.modules + 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`, @@ -406,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) # optional - sage.libs.singular - sage: a^2 + b^2 == 0 # optional - sage.libs.singular + 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 # optional - sage.libs.singular + 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 @@ -423,11 +425,12 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: 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 + 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 @@ -445,14 +448,15 @@ def __init__(self, R, I, names, category=None): EXAMPLES:: - 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 + 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 + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 # optional - sage.combinat sage.modules + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c """ @@ -499,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') # 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) + 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() # optional - sage.libs.pari - sage: F(R) # optional - sage.libs.pari + 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 @@ -583,19 +588,19 @@ def is_commutative(self): The non-commutative case is more interesting:: - 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 + 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 # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules - sage: R = F.quo(J) # optional - sage.combinat sage.modules - sage: R.is_commutative() # optional - sage.combinat sage.modules + 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 """ @@ -618,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: @@ -637,19 +641,20 @@ def cover(self): :: sage: R. = PolynomialRing(QQ) - 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 + 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) # optional - sage.libs.singular - sage: l # optional - sage.libs.singular + sage: l = pi.lift(x + y^3) # optional - sage.libs.singular + sage: l # optional - sage.libs.singular x - sage: l = pi.lift(); l # optional - sage.libs.singular + 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) # optional - sage.libs.singular + sage: l(x + y^3) # optional - sage.libs.singular x """ try: @@ -671,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 # optional - sage.libs.singular + 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 # optional - sage.libs.singular + 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) # optional - sage.libs.singular + sage: L(S.0) # optional - sage.libs.singular x - sage: L(S.1) # optional - sage.libs.singular + 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 # optional - sage.libs.singular + sage: z = pi(x^3 + 2*y^2); z # optional - sage.libs.singular -xbar*ybar^2 + 2*ybar^2 - sage: L(z) # optional - sage.libs.singular + sage: L(z) # optional - sage.libs.singular -x*y^2 + 2*y^2 - sage: L(z) == x^3 + 2*y^2 # optional - sage.libs.singular + 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) # optional - sage.libs.pari - sage: I = MS * [MS.0*MS.1, MS.2+MS.3] * MS # optional - sage.libs.pari - sage: Q = MS.quo(I) # optional - sage.libs.pari - sage: Q.lift() # optional - sage.libs.pari + 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], @@ -727,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. @@ -745,7 +753,8 @@ def lift(self,x=None): sage: S = R.quotient(x^2 + y^2) 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 # optional - sage.libs.singular @@ -813,11 +822,11 @@ def defining_ideal(self): ideals:: 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 + 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() # optional - sage.libs.singular + 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 @@ -830,15 +839,15 @@ def is_field(self, proof = True): TESTS:: - sage: Q = QuotientRing(ZZ,7*ZZ) - sage: Q.is_field() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: R.quotient_ring(R.ideal([2, 4 + x])).is_field() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError @@ -865,19 +874,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = QQ[] - sage: R.quo(x^2 - y).is_integral_domain() # optional - sage.singular + sage: R.quo(x^2 - y).is_integral_domain() # optional - sage.singular True - sage: R.quo(x^2 - y^2).is_integral_domain() # optional - sage.singular + 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) # optional - sage.singular + sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # optional - sage.singular False - sage: R. = ZZ[] # optional - sage.singular - sage: Q = R.quotient_ring([a, b]) # optional - sage.singular - sage: Q.is_integral_domain() # optional - sage.singular + 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) # optional - sage.singular + sage: Q.is_integral_domain(proof=False) # optional - sage.singular False """ if proof: @@ -894,7 +903,7 @@ def is_noetherian(self): EXAMPLES:: - sage: R = QuotientRing(ZZ, 102*ZZ) + sage: R = QuotientRing(ZZ, 102 * ZZ) sage: R.is_noetherian() True @@ -931,7 +940,7 @@ def cover_ring(self): EXAMPLES:: - sage: Q = QuotientRing(ZZ,7*ZZ) + sage: Q = QuotientRing(ZZ, 7 * ZZ) sage: Q.cover_ring() Integer Ring @@ -1019,10 +1028,11 @@ def _element_constructor_(self, x, coerce=True): 2/3 sage: S.coerce(a^2 - b) # optional - sage.libs.singular -b^2 - b - sage: S.coerce(GF(7)(3)) # optional - sage.libs.pari sage.libs.singular + 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:: @@ -1279,9 +1289,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) # optional - sage.libs.pari - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.libs.pari - sage: magma(Q) # optional - magma # indirect doctest # optional - sage.libs.pari + 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 @@ -1319,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): @@ -1373,12 +1384,12 @@ def _macaulay2_init_(self, macaulay2=None): 2 2 2 (x*y - z , y - w ) - sage: R. = PolynomialRing(GF(101), 2) # optional - sage.libs.pari - sage: I = R.ideal([x^2 + x, y^2 + y]) # optional - sage.libs.pari - sage: Q = R.quotient_ring(I); Q # optional - sage.libs.pari + 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.libs.pari + sage: Q._macaulay2_init_() # optional - macaulay2 # optional - sage.rings.finite_rings ZZ ---[x...y] 101 diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 73b50171801..bcd8fcab99c 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -655,11 +655,11 @@ def _richcmp_(self, other, op): The issue from :trac:`8005` was most likely fixed as part of :trac:`9138`:: - sage: F = GF(5) # optional - sage.libs.pari - sage: R. = F[] # optional - sage.libs.pari - sage: I = Ideal(R, [x, y]) # optional - sage.libs.pari - sage: S. = QuotientRing(R, I) # optional - sage.libs.pari - sage: x1^4 # optional - sage.libs.pari + 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 @@ -682,18 +682,18 @@ def lt(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.libs.pari - sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.libs.pari - sage: Q = R.quo(I) # optional - sage.libs.pari - sage: f = Q(z*y + 2*x) # optional - sage.libs.pari - sage: f.lt() # optional - sage.libs.pari + 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) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a + 3*a*b + b).lt() # optional - sage.libs.singular + sage: (a + 3*a*b + b).lt() # optional - sage.libs.singular 3*a*b """ return self.__class__(self.parent(), self.__rep.lt()) @@ -704,18 +704,18 @@ def lm(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.libs.pari - sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.libs.pari - sage: Q = R.quo(I) # optional - sage.libs.pari - sage: f = Q(z*y + 2*x) # optional - sage.libs.pari - sage: f.lm() # optional - sage.libs.pari + 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) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lm() # optional - sage.libs.singular + sage: (a+3*a*b+b).lm() # optional - sage.libs.singular a*b """ @@ -727,18 +727,18 @@ def lc(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.libs.pari - sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.libs.pari - sage: Q = R.quo(I) # optional - sage.libs.pari - sage: f = Q(z*y + 2*x) # optional - sage.libs.pari - sage: f.lc() # optional - sage.libs.pari + 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) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a + 3*a*b + b).lc() # optional - sage.libs.singular + sage: (a + 3*a*b + b).lc() # optional - sage.libs.singular 3 """ return self.__rep.lc() @@ -754,17 +754,17 @@ def variables(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.variables() # optional - sage.libs.singular + sage: a.variables() # optional - sage.libs.singular (a,) - sage: b.variables() # optional - sage.libs.singular + sage: b.variables() # optional - sage.libs.singular (b,) - sage: s = a^2 + b^2 + 1; s # optional - sage.libs.singular + sage: s = a^2 + b^2 + 1; s # optional - sage.libs.singular 1 - sage: s.variables() # optional - sage.libs.singular + sage: s.variables() # optional - sage.libs.singular () - sage: (a + b).variables() # optional - sage.libs.singular + sage: (a + b).variables() # optional - sage.libs.singular (a, b) """ return tuple(self.__class__(self.parent(), v) for v in self.__rep.variables()) @@ -779,13 +779,13 @@ def monomials(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.monomials() # optional - sage.libs.singular + sage: a.monomials() # optional - sage.libs.singular [a] - sage: (a + a*b).monomials() # optional - sage.libs.singular + sage: (a + a*b).monomials() # optional - sage.libs.singular [a*b, a] - sage: R.zero().monomials() # optional - sage.libs.singular + sage: R.zero().monomials() # optional - sage.libs.singular [] """ return [self.__class__(self.parent(), m) for m in self.__rep.monomials()] @@ -801,10 +801,10 @@ def _singular_(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 2) # optional - sage.libs.pari - sage: I = sage.rings.ideal.FieldIdeal(P) # optional - sage.libs.pari - sage: Q = P.quo(I) # optional - sage.libs.pari - sage: Q._singular_() # optional - sage.libs.pari + 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 @@ -814,11 +814,11 @@ def _singular_(self, singular=singular_default): // quotient ring from ideal _[1]=x2+x _[2]=y2+y - sage: xbar = Q(x); xbar # optional - sage.libs.pari + sage: xbar = Q(x); xbar # optional - sage.rings.finite_rings xbar - sage: xbar._singular_() # optional - sage.libs.pari + sage: xbar._singular_() # optional - sage.rings.finite_rings x - sage: Q(xbar._singular_()) # a round-trip # optional - sage.libs.pari + sage: Q(xbar._singular_()) # a round-trip # optional - sage.rings.finite_rings xbar TESTS:: @@ -840,12 +840,12 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) # optional - sage.libs.pari - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.libs.pari - sage: xbar, ybar = Q.gens() # optional - sage.libs.pari - sage: magma(xbar) # optional - magma # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: xbar._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings '_sage_[...]!_sage_ref...' """ g = magma(self.__rep) @@ -858,19 +858,19 @@ def _macaulay2_(self, macaulay2=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 2) # optional - sage.libs.pari - sage: Q = R.quotient([x^2 - y]) # optional - sage.libs.pari - sage: x, y = Q.gens() # optional - sage.libs.pari - sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: mf = macaulay2(f); mf # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: mf.sage() # optional - macaulay2 # optional - sage.libs.pari + sage: mf.sage() # optional - macaulay2 # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 - sage: mf.sage() == f # optional - macaulay2 # optional - sage.libs.pari + sage: mf.sage() == f # optional - macaulay2 # optional - sage.rings.finite_rings True - sage: Q(mf) # optional - macaulay2 # optional - sage.libs.pari + 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 @@ -882,15 +882,15 @@ def _macaulay2_(self, macaulay2=None): :: - sage: R. = PolynomialRing(GF(7), 2) # optional - sage.libs.pari - sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.libs.pari - sage: x, y = Q.gens() # optional - sage.libs.pari - sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: _.sage() # optional - macaulay2 # optional - sage.libs.pari + sage: _.sage() # optional - macaulay2 # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 TESTS: @@ -898,15 +898,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) # optional - sage.libs.pari - sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.libs.pari - sage: x, y = Q.gens() # optional - sage.libs.pari - sage: f = (x^3 + 2*y^2*x)^7 # optional - sage.libs.pari - sage: macaulay2(f) # optional - macaulay2 # optional - sage.libs.pari + 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 # optional - sage.libs.pari - sage: macaulay2(f) # optional - macaulay2 # optional - sage.libs.pari + 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 """ @@ -935,17 +935,18 @@ def reduce(self, G): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 5, order='lex') # optional - sage.libs.pari - sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, a*b*e + c*e, b*c + c*d*e + 1]) # optional - sage.libs.pari - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.libs.pari - sage: I2 = ideal([Q(f) for f in I1.gens()]) # optional - sage.libs.pari - sage: f = Q((a*b + c*d + 1)^2 + e) # optional - sage.libs.pari - sage: f.reduce(I2.gens()) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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 3450a235722..2be981c7ea0 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -423,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)) # optional - sage.rings.number_field + 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)) # optional - sage.rings.number_field + 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 @@ -441,24 +442,24 @@ cdef class Rational(sage.structure.element.FieldElement): Conversion from PARI:: - sage: Rational(pari('-939082/3992923')) # optional - sage.libs.pari + sage: Rational(pari('-939082/3992923')) # optional - sage.libs.pari -939082/3992923 - sage: Rational(pari('Pol([-1/2])')) #9595 # optional - sage.libs.pari + sage: Rational(pari('Pol([-1/2])')) #9595 # optional - sage.libs.pari -1/2 Conversions from numpy:: - sage: import numpy as np # optional - numpy - sage: QQ(np.int8('-15')) # optional - numpy + sage: import numpy as np # optional - numpy + sage: QQ(np.int8('-15')) # optional - numpy -15 - sage: QQ(np.int16('-32')) # optional - numpy + sage: QQ(np.int16('-32')) # optional - numpy -32 - sage: QQ(np.int32('-19')) # optional - numpy + sage: QQ(np.int32('-19')) # optional - numpy -19 - sage: QQ(np.uint32('1412')) # optional - numpy + sage: QQ(np.uint32('1412')) # optional - numpy 1412 - sage: QQ(np.float16('12')) # optional - numpy + sage: QQ(np.float16('12')) # optional - numpy 12 Conversions from gmpy2:: @@ -1036,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) @@ -1423,43 +1424,43 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field - sage: (1/7).is_norm(K) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: (1/10).is_norm(K) # optional - sage.rings.number_field False - sage: 0.is_norm(K) # optional - sage.rings.number_field + sage: 0.is_norm(K) # optional - sage.rings.number_field True - sage: (1/7).is_norm(K, element=True) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: (1/10).is_norm(K, element=True) # optional - sage.rings.number_field (False, None) - sage: (1/691).is_norm(QQ, element=True) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: B # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: e.norm() # optional - sage.rings.number_field 1/5 A non-Galois number field:: - 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 + 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() # optional - sage.rings.number_field + sage: e.norm() # optional - sage.rings.number_field 3/5 - sage: 7.is_norm(K) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + sage: 7.is_norm(K, proof=False) # optional - sage.rings.number_field False AUTHORS: @@ -1542,9 +1543,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field + sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field (i + 1, 1) - sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # optional - sage.rings.number_field + sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # optional - sage.rings.number_field (1, 7) AUTHORS: @@ -1992,20 +1993,20 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1/7).period() # optional - sage.libs.pari + sage: (1/7).period() # optional - sage.libs.pari 6 sage: RR(1/7) 0.142857142857143 - sage: (1/8).period() # optional - sage.libs.pari + 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() # optional - sage.libs.pari + sage: (1/6).period() # optional - sage.libs.pari 1 sage: x = 333/106 - sage: x.period() # optional - sage.libs.pari + sage: x.period() # optional - sage.libs.pari 13 sage: RealField(200)(x) 3.1415094339622641509433962264150943396226415094339622641509 @@ -3770,11 +3771,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: n = 9390823/17 - sage: m = n.__pari__(); m # optional - sage.libs.pari + sage: m = n.__pari__(); m # optional - sage.libs.pari 9390823/17 - sage: type(m) # optional - sage.libs.pari + sage: type(m) # optional - sage.libs.pari - sage: m.type() # optional - sage.libs.pari + 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 d9e4ff4455a..a76e648f6db 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -608,14 +608,14 @@ def embeddings(self, K): sage: QQ.embeddings(QQ) [Identity endomorphism of Rational Field] - sage: QQ.embeddings(CyclotomicField(5)) # optional - sage.rings.number_field + 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)) # optional - sage.libs.pari + sage: QQ.embeddings(GF(3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: no embeddings of the rational field into K. @@ -764,37 +764,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) # optional - sage.rings.padics + 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) # optional - sage.rings.padics + 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) # optional - sage.rings.padics + 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) # optional - sage.libs.pari sage.modules + 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) # optional - sage.libs.pari sage.modules + 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) # optional - sage.libs.pari sage.modules + 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) # optional - sage.libs.pari sage.modules + 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 @@ -802,7 +802,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # optional - sage.libs.pari sage.modules + 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 @@ -810,14 +810,14 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) # optional - sage.libs.pari sage.modules + 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) # optional - sage.libs.pari sage.modules + 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 @@ -1079,7 +1079,7 @@ def algebraic_closure(self): EXAMPLES:: - sage: QQ.algebraic_closure() # optional - sage.rings.number_field + sage: QQ.algebraic_closure() # optional - sage.rings.number_field Algebraic Field """ from sage.rings.qqbar import QQbar @@ -1421,39 +1421,41 @@ def selmer_space(self, S, p, proof=None): sage: QS2gens # optional - sage.rings.number_field [-1] - sage: all(QQ.selmer_space([], p)[0].dimension() == 0 for p in primes(3, 10)) # optional - sage.libs.pari + 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) # optional - sage.modules - sage: QS2 # optional - sage.modules + 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 # optional - sage.modules + sage: QS2gens # optional - sage.modules [5, 7, -1] - sage: toQS2(-7) # optional - sage.modules + sage: toQS2(-7) # optional - sage.modules (0, 1, 1) - sage: fromQS2((0,1,1)) # optional - sage.modules + 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) # optional - sage.modules + sage: toQS2(-5/7) # optional - sage.modules (1, 1, 1) - sage: fromQS2((1,1,1)) # optional - sage.modules + sage: fromQS2((1,1,1)) # optional - sage.modules -35 - sage: ((-5/7)/(-35)).is_square() # optional - sage.modules + 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) # optional - sage.modules + 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 @@ -1519,7 +1521,7 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(QQ) # indirect doctest # optional - sage.libs.gap + sage: gap(QQ) # indirect doctest # optional - sage.libs.gap Rationals """ return 'Rationals' @@ -1633,20 +1635,20 @@ def _factor_univariate_polynomial(self, f): TESTS:: sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari x - sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari (2) * x - sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: QQ._factor_univariate_polynomial(f) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 8b57280df3b..f0f1b818883 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -1680,7 +1680,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF(1.5).__pari__() # optional - sage.libs.pari + sage: RDF(1.5).__pari__() # optional - sage.libs.pari 1.50000000000000 """ global new_gen_from_real_double_element diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 8ffb679e747..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() # optional - sage.libs.pari + sage: GF(2^10, 'a').is_finite() # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: R.is_finite() # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S.is_finite() # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + 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! # optional - sage.combinat sage.modules + 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,18 +310,19 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - 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 + 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) + 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: @@ -365,10 +366,10 @@ cdef class Ring(ParentWithGens): Here is an example over a non-commutative ring:: - sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules - sage: A.ideal(A.1, A.2^2) # optional - sage.combinat sage.modules + 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') # optional - sage.combinat sage.modules + 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: @@ -447,22 +448,22 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: R. = GF(7)[] # optional - sage.libs.pari - sage: (x+y) * R # optional - sage.libs.pari + 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.libs.pari + 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) # optional - sage.combinat sage.modules - sage: A * [A.1+A.2, A.1^2] # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules + 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 # optional - sage.combinat sage.modules + 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 """ @@ -520,18 +521,18 @@ cdef class Ring(ParentWithGens): sage: RR._ideal_class_() - sage: R. = GF(5)[] # optional - sage.libs.pari - sage: R._ideal_class_(1) # optional - sage.libs.pari + 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) # optional - sage.libs.pari - sage: S._ideal_class_(1) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: S._ideal_class_(2) # optional - sage.rings.finite_rings - sage: T. = S[] # optional - sage.libs.pari - sage: T._ideal_class_(5) # optional - sage.libs.pari + sage: T. = S[] # optional - sage.rings.finite_rings + sage: T._ideal_class_(5) # optional - sage.rings.finite_rings - sage: T._ideal_class_(1) # optional - sage.libs.pari + sage: T._ideal_class_(1) # optional - sage.rings.finite_rings Since :trac:`7797`, non-commutative rings have ideals as well:: @@ -575,7 +576,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: Zp(7).unit_ideal() # optional - sage.rings.padics + 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: @@ -606,10 +607,10 @@ cdef class Ring(ParentWithGens): Make sure that :trac:`13644` is fixed:: - 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 + 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 """ @@ -677,8 +678,8 @@ cdef class Ring(ParentWithGens): True sage: QQ['x,y,z'].is_commutative() True - sage: Q. = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules - sage: Q.is_commutative() # optional - sage.combinat sage.modules + 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(): @@ -705,7 +706,7 @@ cdef class Ring(ParentWithGens): sage: QQ.is_field() True - sage: GF(9, 'a').is_field() # optional - sage.libs.pari + sage: GF(9, 'a').is_field() # optional - sage.rings.finite_rings True sage: ZZ.is_field() False @@ -749,9 +750,9 @@ cdef class Ring(ParentWithGens): True sage: ZZ.is_exact() True - sage: Qp(7).is_exact() # optional - sage.rings.padics + sage: Qp(7).is_exact() # optional - sage.rings.padics False - sage: Zp(7, type='capped-abs').is_exact() # optional - sage.rings.padics + sage: Zp(7, type='capped-abs').is_exact() # optional - sage.rings.padics False """ return True @@ -767,30 +768,30 @@ cdef class Ring(ParentWithGens): sage: ZZ.is_subring(QQ) True - sage: ZZ.is_subring(GF(19)) # optional - sage.libs.pari + 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)) # optional - sage.libs.pari + sage: QQ.is_subring(GF(7)) # optional - sage.rings.finite_rings False - sage: QQ.is_subring(CyclotomicField(7)) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field - sage: K.is_subring(K) # optional - sage.rings.number_field + 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) @@ -812,15 +813,15 @@ cdef class Ring(ParentWithGens): sage: QQ.is_prime_field() True - sage: GF(3).is_prime_field() # optional - sage.libs.pari + sage: GF(3).is_prime_field() # optional - sage.rings.finite_rings True - sage: GF(9, 'a').is_prime_field() # optional - sage.libs.pari + 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() # optional - sage.rings.padics + sage: Qp(19).is_prime_field() # optional - sage.rings.padics False """ return False @@ -851,9 +852,9 @@ cdef class Ring(ParentWithGens): True sage: Integers(8).is_integral_domain() False - sage: Zp(7).is_integral_domain() # optional - sage.rings.padics + sage: Zp(7).is_integral_domain() # optional - sage.rings.padics True - sage: Qp(7).is_integral_domain() # optional - sage.rings.padics + sage: Qp(7).is_integral_domain() # optional - sage.rings.padics True sage: R. = QQ[] sage: S. = R.quo((b^3)) # optional - sage.libs.singular @@ -886,11 +887,11 @@ cdef class Ring(ParentWithGens): Forward the proof flag to ``is_field``, see :trac:`22910`:: - sage: R1. = GF(5)[] # optional - sage.libs.pari - sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.libs.pari - sage: R2. = F1[] # optional - sage.libs.pari - sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.libs.pari - sage: F2.is_integral_domain(False) # optional - sage.libs.pari + 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): @@ -923,7 +924,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: GF(19).order() # optional - sage.libs.pari + sage: GF(19).order() # optional - sage.rings.finite_rings 19 sage: QQ.order() +Infinity @@ -955,29 +956,29 @@ cdef class Ring(ParentWithGens): -1 sage: QQ.zeta(1) 1 - sage: CyclotomicField(6).zeta(6) # optional - sage.rings.number_field + sage: CyclotomicField(6).zeta(6) # optional - sage.rings.number_field zeta6 - sage: CyclotomicField(3).zeta(3) # optional - sage.rings.number_field + sage: CyclotomicField(3).zeta(3) # optional - sage.rings.number_field zeta3 - sage: CyclotomicField(3).zeta(3).multiplicative_order() # optional - sage.rings.number_field + sage: CyclotomicField(3).zeta(3).multiplicative_order() # optional - sage.rings.number_field 3 - sage: a = GF(7).zeta(); a # optional - sage.libs.pari + sage: a = GF(7).zeta(); a # optional - sage.rings.finite_rings 3 - sage: a.multiplicative_order() # optional - sage.libs.pari + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 6 - sage: a = GF(49,'z').zeta(); a # optional - sage.libs.pari + sage: a = GF(49,'z').zeta(); a # optional - sage.rings.finite_rings z - sage: a.multiplicative_order() # optional - sage.libs.pari + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 48 - sage: a = GF(49,'z').zeta(2); a # optional - sage.libs.pari + sage: a = GF(49,'z').zeta(2); a # optional - sage.rings.finite_rings 6 - sage: a.multiplicative_order() # optional - sage.libs.pari + 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() # optional - sage.rings.padics + 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:: @@ -987,7 +988,7 @@ cdef class Ring(ParentWithGens): 1 sage: Ring.zeta(QQ, 2) -1 - sage: Ring.zeta(QQ, 3) # optional - sage.libs.pari + sage: Ring.zeta(QQ, 3) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no 3rd root of unity in Rational Field @@ -1024,13 +1025,13 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: CyclotomicField(19).zeta_order() # optional - sage.rings.number_field + sage: CyclotomicField(19).zeta_order() # optional - sage.rings.number_field 38 - sage: GF(19).zeta_order() # optional - sage.libs.pari + sage: GF(19).zeta_order() # optional - sage.rings.finite_rings 18 - sage: GF(5^3,'a').zeta_order() # optional - sage.libs.pari + sage: GF(5^3,'a').zeta_order() # optional - sage.rings.finite_rings 124 - sage: Zp(7, prec=8).zeta_order() # optional - sage.rings.padics + sage: Zp(7, prec=8).zeta_order() # optional - sage.rings.padics 6 """ return self.zeta().multiplicative_order() @@ -1198,10 +1199,11 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: R. = GF(3)[] # optional - sage.libs.pari - sage: R.localization((x*y, x**2+y**2)) # optional - sage.libs.pari - 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.libs.pari + 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(): @@ -1275,11 +1277,11 @@ cdef class CommutativeRing(Ring): sage: QQ.is_commutative() True - sage: ZpCA(7).is_commutative() # optional - sage.rings.padics + sage: ZpCA(7).is_commutative() # optional - sage.rings.padics True - sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # optional - sage.combinat sage.modules + 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() # optional - sage.combinat sage.modules + sage: A.is_commutative() # optional - sage.combinat sage.modules False """ return True @@ -1315,18 +1317,18 @@ cdef class CommutativeRing(Ring): All orders in number fields have Krull dimension 1, including non-maximal orders:: - sage: K. = QuadraticField(-1) # optional - sage.rings.number_field - sage: R = K.maximal_order(); R # optional - sage.rings.number_field + 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 + sage: R.krull_dimension() # optional - sage.rings.number_field 1 - sage: R = K.order(2*i); R # 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 + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() # optional - sage.rings.number_field + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ raise NotImplementedError @@ -1371,16 +1373,16 @@ cdef class CommutativeRing(Ring): sage: R = QQ['x'] sage: y = polygen(R) - sage: R.extension(y^2 - 5, 'a') # optional - sage.libs.pari + 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)) # optional - sage.libs.pari - sage: F. = GF(5).extension(x^2 - 2) # optional - sage.libs.pari - sage: P. = F[] # optional - sage.libs.pari - sage: R. = F.extension(t^2 - a); R # optional - sage.libs.pari + 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 """ @@ -1418,19 +1420,19 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari - sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.libs.pari + 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.libs.pari + sage: Frob(u) # optional - sage.rings.finite_rings u^5 We can specify a power:: - sage: f = K.frobenius_endomorphism(2); f # optional - sage.libs.pari + 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.libs.pari + sage: f(1+u) # optional - sage.rings.finite_rings 1 + u^25 """ from .morphism import FrobeniusEndomorphism_generic @@ -1465,18 +1467,21 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - 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 + 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 # 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 + 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:: @@ -1489,30 +1494,32 @@ cdef class CommutativeRing(Ring): Defn: x |--> 0 y |--> 1 z |--> 2 - 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 + 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 # optional - sage.modules + sage: Dx = M.gen(0); Dx # optional - sage.modules d/dx - sage: Dy = M.gen(1); Dy # optional - sage.modules + sage: Dy = M.gen(1); Dy # optional - sage.modules d/dy - sage: Dz = M.gen(2); Dz # optional - sage.modules + 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) # optional - sage.modules + sage: Dx(f) # = 2*x evaluated at (0,1,2) # optional - sage.modules 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules + sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) # optional - sage.modules + 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 # optional - sage.modules + 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) @@ -1551,23 +1558,23 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: R.derivation() # optional - sage.modules + sage: R.derivation() # optional - sage.modules d/dx In that case, ``arg`` could be a generator:: - sage: R.derivation(y) # optional - sage.modules + sage: R.derivation(y) # optional - sage.modules d/dy or a list of coefficients:: - sage: R.derivation([1,2,3]) # optional - sage.modules + 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) # optional - sage.modules + sage: R.derivation(x^2) # optional - sage.modules Traceback (most recent call last): ... ValueError: unable to create the derivation @@ -1576,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 # optional - sage.modules + sage: f = R.derivation(twist=theta); f # optional - sage.modules 0 - sage: f.parent() # optional - sage.modules + 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) # optional - sage.modules + 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) # optional - sage.modules + sage: R.derivation(x, twist=theta) # optional - sage.modules x*([x |--> x^2, y |--> y^2, z |--> z^2] - id) """ @@ -1705,9 +1712,9 @@ cdef class IntegralDomain(CommutativeRing): True sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field + sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field True - sage: GF(5).is_integrally_closed() # optional - sage.libs.pari + sage: GF(5).is_integrally_closed() # optional - sage.rings.finite_rings True sage: Z5 = Integers(5); Z5 Ring of integers modulo 5 @@ -1724,7 +1731,7 @@ cdef class IntegralDomain(CommutativeRing): EXAMPLES:: - sage: GF(7).is_field() # optional - sage.libs.pari + sage: GF(7).is_field() # optional - sage.rings.finite_rings True The following examples have their own ``is_field`` implementations:: @@ -1794,9 +1801,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.krull_dimension() 1 - 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 + 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 @@ -1813,13 +1820,13 @@ cdef class DedekindDomain(IntegralDomain): sage: U.krull_dimension() 4 - sage: K. = QuadraticField(-1) # optional - sage.rings.number_field - sage: R = K.order(2*i); R # optional - sage.rings.number_field + 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 + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() # optional - sage.rings.number_field + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ return 1 @@ -1838,16 +1845,16 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_integrally_closed() True - 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 + 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() # optional - sage.rings.number_field sage.symbolic + sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() # optional - sage.rings.number_field sage.symbolic False sage: T. = PolynomialRing(QQ, 2); T Multivariate Polynomial Ring in x, y over Rational Field @@ -1862,12 +1869,12 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: - 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 + 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 + sage: OK.integral_closure() == OK # optional - sage.rings.number_field True sage: QQ.integral_closure() == QQ @@ -1886,9 +1893,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_noetherian() True - 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 + 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 @@ -1912,7 +1919,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: Zp(5).is_noetherian() # optional - sage.rings.padics + sage: Zp(5).is_noetherian() # optional - sage.rings.padics True """ return True @@ -1923,7 +1930,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: QQ.class_group() # optional - sage.groups + sage: QQ.class_group() # optional - sage.groups Trivial Abelian group """ from sage.groups.abelian_gps.abelian_group import AbelianGroup @@ -1969,22 +1976,22 @@ cdef class PrincipalIdealDomain(IntegralDomain): coercible:: sage: R. = PolynomialRing(QQ) - 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 + 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 # optional - sage.rings.number_field + sage: f in R # optional - sage.rings.number_field True - sage: g in R # optional - sage.rings.number_field + sage: g in R # optional - sage.rings.number_field False - sage: R.gcd(f, g) # optional - sage.rings.number_field + 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) # optional - sage.rings.number_field + 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)) # optional - sage.rings.number_field + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # optional - sage.rings.number_field x - a """ if coerce: @@ -2077,7 +2084,7 @@ cpdef bint _is_Field(x) except -2: True sage: _is_Field(ZZ) False - sage: _is_Field(pAdicField(2)) # optional - sage.rings.padics + sage: _is_Field(pAdicField(2)) # optional - sage.rings.padics True sage: _is_Field(5) False @@ -2124,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') # optional - sage.rings.number_field - sage: F.fraction_field() # optional - sage.rings.number_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 @@ -2138,10 +2145,10 @@ cdef class Field(PrincipalIdealDomain): sage: QQ._pseudo_fraction_field() Rational Field - sage: K = GF(5) # optional - sage.libs.pari - sage: K._pseudo_fraction_field() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: K._pseudo_fraction_field() is K # optional - sage.rings.finite_rings True """ return self @@ -2253,8 +2260,8 @@ cdef class Field(PrincipalIdealDomain): EXAMPLES:: - sage: k = GF(9, 'a') # optional - sage.libs.pari - sage: k.prime_subfield() # optional - sage.libs.pari + 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: @@ -2318,8 +2325,8 @@ cdef class Algebra(Ring): sage: A.characteristic() # optional - sage.modules 0 - sage: A = Algebra(GF(7^3, 'a')) # optional - sage.libs.pari sage.modules - sage: A.characteristic() # optional - sage.libs.pari sage.modules + 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() @@ -2334,16 +2341,16 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: B = QuaternionAlgebra(2) # optional - sage.combinat sage.modules - sage: B.has_standard_involution() # optional - sage.combinat sage.modules + 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) # 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 + 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) # optional - sage.combinat sage.modules - sage: L.has_standard_involution() # optional - sage.combinat sage.modules + 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 @@ -2397,7 +2404,7 @@ cdef class CommutativeAlgebra(CommutativeRing): sage: sage.rings.ring.CommutativeAlgebra(QQ) - sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ, -1, -1)) # optional - sage.combinat sage.modules + 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 diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 979f4d69d5c..222251b745e 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 # optional - sage.libs.pari + sage: K = sage.rings.tests.prime_finite_field(); K # optional - sage.rings.finite_rings Finite Field of size ... - sage: K.cardinality().is_prime() # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: K = sage.rings.tests.finite_field(); K # optional - sage.rings.finite_rings Finite Field...of size ... - sage: K.cardinality().is_prime_power() # optional - sage.libs.pari + sage: K.cardinality().is_prime_power() # optional - sage.rings.finite_rings True - sage: while K.cardinality().is_prime(): # optional - sage.libs.pari + 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 # optional - sage.libs.pari + sage: K = sage.rings.tests.small_finite_field(); K # optional - sage.rings.finite_rings Finite Field...of size ... - sage: q = K.cardinality() # optional - sage.libs.pari - sage: q.is_prime_power() # optional - sage.libs.pari + sage: q = K.cardinality() # optional - sage.rings.finite_rings + sage: q.is_prime_power() # optional - sage.rings.finite_rings True - sage: q <= 2^16 # optional - sage.libs.pari + sage: q <= 2^16 # optional - sage.rings.finite_rings True """ from sage.rings.integer_ring import ZZ @@ -439,8 +439,8 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, sage: rings = [QQ] sage: rings += [ZZ[I], ZZ[I, sqrt(2)]] # optional - sage.rings.number_field - sage: rings += [GF(49, 'a')] # optional - sage.libs.pari - sage: rings += [MatrixSpace(GF(17), 3)] # optional - sage.libs.pari sage.modules + sage: rings += [GF(49, 'a')] # optional - sage.rings.finite_rings + sage: rings += [MatrixSpace(GF(17), 3)] # optional - sage.rings.finite_rings sage.modules sage: for C in rings: ....: sage.rings.tests.test_karatsuba_multiplication(C, 10, 10)