diff --git a/src/sage/rings/algebraic_closure_finite_field.py b/src/sage/rings/algebraic_closure_finite_field.py index 6f6b93955cb..fb62627c9dc 100644 --- a/src/sage/rings/algebraic_closure_finite_field.py +++ b/src/sage/rings/algebraic_closure_finite_field.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Algebraic closures of finite fields diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 332977164f4..8315bb078bd 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -473,13 +473,13 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): EXAMPLES:: - sage: CDF._magma_init_(magma) # optional - magma + sage: CDF._magma_init_(magma) # optional - magma 'ComplexField(53 : Bits := true)' - sage: magma(CDF) # optional - magma + sage: magma(CDF) # optional - magma Complex field of precision 15 sage: floor(RR(log(2**53, 10))) 15 - sage: magma(CDF).sage() # optional - magma + sage: magma(CDF).sage() # optional - magma Complex Field with 53 bits of precision """ return "ComplexField(%s : Bits := true)" % self.prec() @@ -2570,11 +2570,11 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: f = CDF.coerce_map_from(numpy.complex_) - sage: f(numpy.complex_(I)) + sage: import numpy # optional - numpy + sage: f = CDF.coerce_map_from(numpy.complex_) # optional - numpy + sage: f(numpy.complex_(I)) # optional - numpy 1.0*I - sage: f(numpy.complex_(I)).parent() + sage: f(numpy.complex_(I)).parent() # optional - numpy Complex Double Field """ def __init__(self, R): @@ -2590,8 +2590,8 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: CDF(numpy.complex_(I)) # indirect doctest + sage: import numpy # optional - numpy + sage: CDF(numpy.complex_(I)) # indirect doctest # optional - numpy 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) @@ -2604,9 +2604,9 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) - sage: f._repr_type() + sage: import numpy # optional - numpy + sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) # optional - numpy + sage: f._repr_type() # optional - numpy 'Native' """ return "Native" diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 4fc6c4c8d35..319d6000b83 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -1039,10 +1039,10 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1.0, 2.5j]).dtype + sage: import numpy # optional - numpy + sage: numpy.array([1.0, 2.5j]).dtype # optional - numpy dtype('complex128') - sage: numpy.array([1.000000000000000000000000000000000000j]).dtype + sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # optional - numpy dtype('O') """ if self._prec <= 53: diff --git a/src/sage/rings/derivation.py b/src/sage/rings/derivation.py index 4c8cb4662b9..74903e6072f 100644 --- a/src/sage/rings/derivation.py +++ b/src/sage/rings/derivation.py @@ -35,7 +35,8 @@ sage: A. = QQ[] sage: M = A.derivation_module() sage: M - Module of derivations over Multivariate Polynomial Ring in x, y, z over Rational Field + Module of derivations over + Multivariate Polynomial Ring in x, y, z over Rational Field The method :meth:`~sage.rings.derivation.RingDerivationModule.gens` returns the generators of this module:: @@ -76,8 +77,10 @@ Sage knows moreover that `M` is a Lie algebra:: sage: M.category() - Join of Category of lie algebras with basis over Rational Field - and Category of modules with basis over Multivariate Polynomial Ring in x, y, z over Rational Field + Join of + Category of lie algebras with basis over Rational Field and + Category of modules with basis over + Multivariate Polynomial Ring in x, y, z over Rational Field Computations of Lie brackets are implemented as well:: @@ -116,7 +119,9 @@ sage: M = A.derivation_module(ev) sage: M - Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Rational Field sage: M.gens() (d/dx, d/dy, d/dz) @@ -138,7 +143,8 @@ sage: theta = B.hom([B(y),B(z),B(x)]) sage: theta - Ring endomorphism of Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field + Ring endomorphism of Fraction Field of + Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> y y |--> z z |--> x @@ -225,25 +231,32 @@ def __init__(self, domain, codomain, twist=None): sage: TestSuite(M).run() sage: from sage.rings.derivation import RingDerivationModule - sage: R5. = GF(5)[] - sage: R25. = GF(25)[] - sage: R7. = GF(7)[] - - sage: RingDerivationModule(R5, R25) - Module of derivations from Univariate Polynomial Ring in x over Finite Field of size 5 to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 - sage: RingDerivationModule(R5, R5^2) + sage: R5. = GF(5)[] # optional - sage.rings.finite_rings + sage: R25. = GF(25)[] # optional - sage.rings.finite_rings + sage: R7. = GF(7)[] # optional - sage.rings.finite_rings + + sage: RingDerivationModule(R5, R25) # optional - sage.rings.finite_rings + Module of derivations + from Univariate Polynomial Ring in x over Finite Field of size 5 + to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 + sage: RingDerivationModule(R5, R5^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - sage: RingDerivationModule(R5, R7) + TypeError: the codomain must be an algebra over the domain + or a morphism with the correct domain + sage: RingDerivationModule(R5, R7) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - - sage: theta = R5.hom([R5.gen()^2]) - sage: RingDerivationModule(R5, R25, twist=theta) - Module of twisted derivations from Univariate Polynomial Ring in x over Finite Field of size 5 to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 (twisting morphism: x |--> x^2) - sage: RingDerivationModule(R7, R7, twist=theta) + TypeError: the codomain must be an algebra over the domain + or a morphism with the correct domain + + sage: theta = R5.hom([R5.gen()^2]) # optional - sage.rings.finite_rings + sage: RingDerivationModule(R5, R25, twist=theta) # optional - sage.rings.finite_rings + Module of twisted derivations + from Univariate Polynomial Ring in x over Finite Field of size 5 + to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 + (twisting morphism: x |--> x^2) + sage: RingDerivationModule(R7, R7, twist=theta) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: the domain of the derivation must coerce to the domain of the twisting homomorphism @@ -460,8 +473,10 @@ def _coerce_map_from_(self, R): sage: M1 = A.derivation_module(); M1 Module of derivations over Univariate Polynomial Ring in x over Rational Field sage: M2 = A.derivation_module(B); M2 - Module of derivations from Univariate Polynomial Ring in x over Rational Field - to Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Module of derivations + from Univariate Polynomial Ring in x over Rational Field + to Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: M1._coerce_map_from_(M2) is None True sage: M1.has_coerce_map_from(M2) @@ -567,7 +582,8 @@ def defining_morphism(self): sage: M.defining_morphism() Polynomial base injection morphism: From: Univariate Polynomial Ring in x over Rational Field - To: Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + To: Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: ev = R.hom([QQ(0)]) sage: M = R.derivation_module(ev) @@ -857,7 +873,8 @@ def codomain(self): sage: S. = R[] sage: M = R.derivation_module(S) sage: M.random_element().codomain() - Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: M.random_element().codomain() is S True @@ -1057,10 +1074,10 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = GF(5)[] - sage: D = sum(v*R.derivation(v) for v in R.gens()); D + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: D = sum(v*R.derivation(v) for v in R.gens()); D # optional - sage.rings.finite_rings x*d/dx + y*d/dy + z*d/dz - sage: D.pth_power() == D + sage: D.pth_power() == D # optional - sage.rings.finite_rings True """ @@ -1132,17 +1149,17 @@ def pth_power(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: Dx = R.derivation(x) - sage: Dx.pth_power() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: Dx = R.derivation(x) # optional - sage.rings.finite_rings + sage: Dx.pth_power() # optional - sage.rings.finite_rings 0 - sage: (x*Dx).pth_power() + sage: (x*Dx).pth_power() # optional - sage.rings.finite_rings x*d/dx - sage: (x^6*Dx).pth_power() + sage: (x^6*Dx).pth_power() # optional - sage.rings.finite_rings x^26*d/dx - sage: Dy = R.derivation(y) - sage: (x*Dx + y*Dy).pth_power() + sage: Dy = R.derivation(y) # optional - sage.rings.finite_rings + sage: (x*Dx + y*Dy).pth_power() # optional - sage.rings.finite_rings x*d/dx + y*d/dy An error is raised if the domain has characteristic zero:: @@ -1165,14 +1182,14 @@ def pth_power(self): TESTS:: - sage: R. = GF(3)[] - sage: D = R.derivation_module().random_element() - sage: Dp = D.pth_power() - sage: f = R.random_element() - sage: Dp(f) == D(D(D(f))) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: D = R.derivation_module().random_element() # optional - sage.rings.finite_rings + sage: Dp = D.pth_power() # optional - sage.rings.finite_rings + sage: f = R.random_element() # optional - sage.rings.finite_rings + sage: Dp(f) == D(D(D(f))) # optional - sage.rings.finite_rings True - sage: D.bracket(Dp) + sage: D.bracket(Dp) # optional - sage.rings.finite_rings 0 """ @@ -1562,14 +1579,14 @@ def __init__(self, parent, arg=None): TESTS:: sage: from sage.rings.derivation import RingDerivationWithoutTwist_wrapper - sage: R. = GF(5)[] - sage: S = R.quo([x^5, y^5]) - sage: M = S.derivation_module() - sage: der = M.random_element() - sage: isinstance(der, RingDerivationWithoutTwist_wrapper) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S = R.quo([x^5, y^5]) # optional - sage.rings.finite_rings + sage: M = S.derivation_module() # optional - sage.rings.finite_rings + sage: der = M.random_element() # optional - sage.rings.finite_rings + sage: isinstance(der, RingDerivationWithoutTwist_wrapper) # optional - sage.rings.finite_rings True - sage: TestSuite(der).run() + sage: TestSuite(der).run() # optional - sage.rings.finite_rings """ if isinstance(arg, list) and len(arg) == 1 and isinstance(arg[0], RingDerivation): @@ -1600,11 +1617,11 @@ def _add_(self, other): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dy = S.derivation(y) - sage: Dx + Dy + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dy = S.derivation(y) # optional - sage.rings.finite_rings + sage: Dx + Dy # optional - sage.rings.finite_rings d/dx + d/dy """ @@ -1616,11 +1633,11 @@ def _sub_(self, other): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dy = S.derivation(y) - sage: Dx - Dy + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dy = S.derivation(y) # optional - sage.rings.finite_rings + sage: Dx - Dy # optional - sage.rings.finite_rings d/dx - d/dy """ @@ -1632,10 +1649,10 @@ def _neg_(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: -Dx + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: -Dx # optional - sage.rings.finite_rings -d/dx """ @@ -1647,12 +1664,12 @@ def _lmul_(self, factor): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dx * 2 + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dx * 2 # optional - sage.rings.finite_rings 2*d/dx - sage: Dx * x^2 + sage: Dx * x^2 # optional - sage.rings.finite_rings x^2*d/dx """ @@ -1664,12 +1681,12 @@ def _rmul_(self, factor): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: 2 * Dx + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: 2 * Dx # optional - sage.rings.finite_rings 2*d/dx - sage: x^2 * Dx + sage: x^2 * Dx # optional - sage.rings.finite_rings x^2*d/dx """ @@ -1682,20 +1699,20 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: M = S.derivation_module() - sage: M.basis() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: M = S.derivation_module() # optional - sage.rings.finite_rings + sage: M.basis() # optional - sage.rings.finite_rings Family (d/dx, d/dy) - sage: S.derivation(x).list() + sage: S.derivation(x).list() # optional - sage.rings.finite_rings [1, 0] - sage: S.derivation(y).list() + sage: S.derivation(y).list() # optional - sage.rings.finite_rings [0, 1] - sage: f = x*S.derivation(x) + y*S.derivation(y); f + sage: f = x*S.derivation(x) + y*S.derivation(y); f # optional - sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [x, y] """ @@ -1889,19 +1906,19 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[[]] - sage: M = R.derivation_module() - sage: M.basis() + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: M = R.derivation_module() # optional - sage.rings.finite_rings + sage: M.basis() # optional - sage.rings.finite_rings Family (d/dx, d/dy) - sage: R.derivation(x).list() + sage: R.derivation(x).list() # optional - sage.rings.finite_rings [1, 0] - sage: R.derivation(y).list() + sage: R.derivation(y).list() # optional - sage.rings.finite_rings [0, 1] - sage: f = x*R.derivation(x) + y*R.derivation(y); f + sage: f = x*R.derivation(x) + y*R.derivation(y); f # optional - sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [x, y] """ @@ -1974,11 +1991,11 @@ def _call_(self, x): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: f = x^3*S.derivation(); f + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: f = x^3*S.derivation(); f # optional - sage.rings.finite_rings x^3*d/dx - sage: f(x^3) + sage: f(x^3) # optional - sage.rings.finite_rings 0 """ @@ -2074,10 +2091,10 @@ def _latex_(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: der = k.derivation(a+1, twist=Frob) - sage: latex(der) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: der = k.derivation(a + 1, twist=Frob) # optional - sage.rings.finite_rings + sage: latex(der) # optional - sage.rings.finite_rings \left(a + 1\right) \left(\left[a \mapsto a^{5}\right] - \text{id}\right) """ scalar = self._scalar diff --git a/src/sage/rings/fast_arith.pyx b/src/sage/rings/fast_arith.pyx index df9b592cf97..88f2ca583e4 100644 --- a/src/sage/rings/fast_arith.pyx +++ b/src/sage/rings/fast_arith.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari """ Basic arithmetic with C integers """ diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index d535cf108f3..95cb5df1faf 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -546,13 +546,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: a = Mod(2,19) - sage: gap(a) + sage: gap(a) # optional - sage.libs.gap Z(19) - sage: gap(Mod(3, next_prime(10000))) + sage: gap(Mod(3, next_prime(10000))) # optional - sage.libs.gap Z(10007)^6190 - sage: gap(Mod(3, next_prime(100000))) + sage: gap(Mod(3, next_prime(100000))) # optional - sage.libs.gap ZmodpZObj( 3, 100003 ) - sage: gap(Mod(4, 48)) + sage: gap(Mod(4, 48)) # optional - sage.libs.gap ZmodnZObj( 4, 48 ) """ return '%s*One(ZmodnZ(%s))' % (self, self.__modulus.sageInteger) @@ -716,7 +716,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): Examples like this took extremely long before :trac:`32375`:: - sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) + sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) # optional - sage.libs.pari 99999999999999999999999999999999999999999999999999 We check that non-existence of solutions is detected: @@ -1028,27 +1028,27 @@ cdef class IntegerMod_abstract(FiniteRingElement): r""" EXAMPLES:: - sage: Mod(3,17).is_square() + sage: Mod(3, 17).is_square() False - sage: Mod(9,17).is_square() + sage: Mod(9, 17).is_square() # optional - sage.libs.pari True - sage: Mod(9,17*19^2).is_square() + sage: Mod(9, 17*19^2).is_square() # optional - sage.libs.pari True - sage: Mod(-1,17^30).is_square() + sage: Mod(-1, 17^30).is_square() # optional - sage.libs.pari True - sage: Mod(1/9, next_prime(2^40)).is_square() + sage: Mod(1/9, next_prime(2^40)).is_square() # optional - sage.libs.pari True - sage: Mod(1/25, next_prime(2^90)).is_square() + sage: Mod(1/25, next_prime(2^90)).is_square() # optional - sage.libs.pari True TESTS:: - sage: Mod(1/25, 2^8).is_square() + sage: Mod(1/25, 2^8).is_square() # optional - sage.libs.pari True - sage: Mod(1/25, 2^40).is_square() + sage: Mod(1/25, 2^40).is_square() # optional - sage.libs.pari True - sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time + sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time # optional - sage.libs.pari ....: for ep,eq,er in cartesian_product_iterator([[0,1,2,3],[0,1,2,3],[0,1,2,3]]): ....: for e2 in [0, 1, 2, 3, 4]: ....: n = p^ep * q^eq * r^er * 2^e2 @@ -1126,21 +1126,21 @@ cdef class IntegerMod_abstract(FiniteRingElement): 86 sage: mod(7, 18).sqrt() 5 - sage: a = mod(14, 5^60).sqrt() - sage: a*a + sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari + sage: a*a # optional - sage.libs.pari 14 - sage: mod(15, 389).sqrt(extend=False) + sage: mod(15, 389).sqrt(extend=False) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: self must be a square - sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) + sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari 9 - sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) + sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari 25 :: - sage: a = Mod(3,5); a + sage: a = Mod(3, 5); a 3 sage: x = Mod(-1, 360) sage: x.sqrt(extend=False) @@ -1386,30 +1386,31 @@ cdef class IntegerMod_abstract(FiniteRingElement): 5 sage: K(23).nth_root(3) # optional - sage.libs.pari 29 - sage: mod(225,2^5*3^2).nth_root(4, all=True) - [225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231] - sage: mod(275,2^5*7^4).nth_root(7, all=True) + sage: mod(225, 2^5*3^2).nth_root(4, all=True) # optional - sage.rings.padics + [225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, + 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231] + sage: mod(275, 2^5*7^4).nth_root(7, all=True) # optional - sage.rings.padics [58235, 25307, 69211, 36283, 3355, 47259, 14331] - sage: mod(1,8).nth_root(2,all=True) + sage: mod(1,8).nth_root(2, all=True) # optional - sage.rings.padics [1, 7, 5, 3] - sage: mod(4,8).nth_root(2,all=True) + sage: mod(4,8).nth_root(2, all=True) # optional - sage.rings.padics [2, 6] - sage: mod(1,16).nth_root(4,all=True) + sage: mod(1,16).nth_root(4, all=True) # optional - sage.rings.padics [1, 15, 13, 3, 9, 7, 5, 11] - sage: (mod(22,31)^200).nth_root(200) + sage: (mod(22,31)^200).nth_root(200) # optional - sage.groups 5 - sage: mod(3,6).nth_root(0,all=True) + sage: mod(3,6).nth_root(0, all=True) # optional - sage.rings.padics [] sage: mod(3,6).nth_root(0) Traceback (most recent call last): ... ValueError - sage: mod(1,6).nth_root(0,all=True) + sage: mod(1,6).nth_root(0, all=True) # optional - sage.rings.padics [1, 2, 3, 4, 5] TESTS:: - sage: for p in [1009,2003,10007,100003]: + sage: for p in [1009,2003,10007,100003]: # optional - sage.libs.pari ....: K = GF(p) ....: for r in (p-1).divisors(): ....: if r == 1: continue @@ -1434,7 +1435,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`13172` is resolved:: - sage: mod(-1, 4489).nth_root(2, all=True) + sage: mod(-1, 4489).nth_root(2, all=True) # optional - sage.rings.padics [] We check that :trac:`32084` is fixed:: @@ -1445,7 +1446,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): 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: @@ -1736,20 +1737,20 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: mod(1,2).is_primitive_root() + sage: mod(1, 2).is_primitive_root() True - sage: mod(3,4).is_primitive_root() + sage: mod(3, 4).is_primitive_root() True - sage: mod(2,7).is_primitive_root() + sage: mod(2, 7).is_primitive_root() # optional - sage.libs.pari False - sage: mod(3,98).is_primitive_root() + sage: mod(3, 98).is_primitive_root() # optional - sage.libs.pari True - sage: mod(11,1009^2).is_primitive_root() + sage: mod(11, 1009^2).is_primitive_root() # optional - sage.libs.pari True TESTS:: - sage: for p in prime_range(3,12): + sage: for p in prime_range(3,12): # optional - sage.libs.pari ....: for k in range(1,4): ....: for even in [1,2]: ....: n = even*p^k @@ -1762,14 +1763,14 @@ cdef class IntegerMod_abstract(FiniteRingElement): `0` is not a primitive root mod `n` (:trac:`23624`) except for `n=0`:: - sage: mod(0, 17).is_primitive_root() + sage: mod(0, 17).is_primitive_root() # optional - sage.libs.pari False - sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) + sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) # optional - sage.libs.pari True sage: mod(0, 1).is_primitive_root() True - sage: all(not mod(p^j, p^k).is_primitive_root() + sage: all(not mod(p^j, p^k).is_primitive_root() # optional - sage.libs.pari ....: for p in prime_range(3, 12) ....: for k in srange(1, 4) ....: for j in srange(0, k)) @@ -1824,14 +1825,15 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: Mod(-1,5).multiplicative_order() + sage: Mod(-1, 5).multiplicative_order() # optional - sage.libs.pari 2 - sage: Mod(1,5).multiplicative_order() + sage: Mod(1, 5).multiplicative_order() # optional - sage.libs.pari 1 - sage: Mod(0,5).multiplicative_order() + sage: Mod(0, 5).multiplicative_order() # optional - sage.libs.pari Traceback (most recent call last): ... - ArithmeticError: multiplicative order of 0 not defined since it is not a unit modulo 5 + ArithmeticError: multiplicative order of 0 not defined + since it is not a unit modulo 5 """ try: return sage.rings.integer.Integer(self.__pari__().znorder()) @@ -1854,9 +1856,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): :: - sage: R=ZZ.quo(9) - sage: a=R(3) - sage: b=R(6) + sage: R = ZZ.quo(9) + sage: a = R(3) + sage: b = R(6) sage: a.valuation(3) 1 sage: a.valuation(3) + b.valuation(3) @@ -1875,9 +1877,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): TESTS:: - sage: R=ZZ.quo(12) - sage: a=R(2) - sage: b=R(4) + sage: R = ZZ.quo(12) + sage: a = R(2) + sage: b = R(4) sage: a.valuation(2) 1 sage: b.valuation(2) @@ -1977,8 +1979,8 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): r""" EXAMPLES:: - sage: p = next_prime(2^32) # optional - sage.libs.pari - sage: GF(p)(int(p+1)) # optional - sage.libs.pari + sage: p = next_prime(2^32) # optional - sage.libs.pari + sage: GF(p)(int(p + 1)) # optional - sage.libs.pari 1 """ mpz_set_si(self.value, value) @@ -2915,9 +2917,9 @@ cdef class IntegerMod_int(IntegerMod_abstract): Traceback (most recent call last): ... ValueError: self must be a square - sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) + sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari 9 - sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) + sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari 25 :: @@ -2932,7 +2934,8 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: y = x.sqrt(); y sqrt359 sage: y.parent() - Univariate Quotient Polynomial Ring in sqrt359 over Ring of integers modulo 360 with modulus x^2 + 1 + Univariate Quotient Polynomial Ring in sqrt359 + over Ring of integers modulo 360 with modulus x^2 + 1 sage: y^2 359 @@ -2961,7 +2964,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): [406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444] sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) # optional - sage.libs.pari (13, 13, 104) - sage: all(x^2 == 169 for x in v) + sage: all(x^2 == 169 for x in v) # optional - sage.libs.pari True Modulo a power of 2:: diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index 5edf98b1ac7..41e89b5b9fa 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -16,16 +16,16 @@ :: sage: r = Integers(7) - sage: s = GF(7) # optional - sage.libs.pari - sage: r.has_coerce_map_from(s) # optional - sage.libs.pari + sage: s = GF(7) # optional - sage.rings.finite_rings + sage: r.has_coerce_map_from(s) # optional - sage.rings.finite_rings False - sage: s.has_coerce_map_from(r) # optional - sage.libs.pari + sage: s.has_coerce_map_from(r) # optional - sage.rings.finite_rings True - sage: s(1) + r(1) # optional - sage.libs.pari + sage: s(1) + r(1) # optional - sage.rings.finite_rings 2 - sage: parent(s(1) + r(1)) # optional - sage.libs.pari + sage: parent(s(1) + r(1)) # optional - sage.rings.finite_rings Finite Field of size 7 - sage: parent(r(1) + s(1)) # optional - sage.libs.pari + sage: parent(r(1) + s(1)) # optional - sage.rings.finite_rings Finite Field of size 7 We list the elements of `\ZZ/3\ZZ`:: @@ -259,9 +259,9 @@ def is_IntegerModRing(x): Use isinstance(..., sage.rings.abc.IntegerModRing) instead. See https://github.com/sagemath/sage/issues/32606 for details. True - sage: is_IntegerModRing(GF(13)) # optional - sage.libs.pari + sage: is_IntegerModRing(GF(13)) # optional - sage.rings.finite_rings True - sage: is_IntegerModRing(GF(4, 'a')) # optional - sage.libs.pari + sage: is_IntegerModRing(GF(4, 'a')) # optional - sage.rings.finite_rings False sage: is_IntegerModRing(10) False @@ -572,7 +572,8 @@ def extension(self, poly, name=None, names=None, **kwds): sage: R. = QQ[] sage: Integers(8).extension(t^2 - 3) - Univariate Quotient Polynomial Ring in t over Ring of integers modulo 8 with modulus t^2 + 5 + Univariate Quotient Polynomial Ring in t + over Ring of integers modulo 8 with modulus t^2 + 5 """ if self.modulus() == 1: return self @@ -1145,14 +1146,14 @@ def _element_constructor_(self, x): """ TESTS:: - sage: K2 = GF(2) # optional - sage.libs.pari - sage: K3 = GF(3) # optional - sage.libs.pari - sage: K8 = GF(8, 'a') # optional - sage.libs.pari - sage: K8(5) # indirect doctest # optional - sage.libs.pari + sage: K2 = GF(2) # optional - sage.rings.finite_rings + sage: K3 = GF(3) # optional - sage.rings.finite_rings + sage: K8 = GF(8, 'a') # optional - sage.rings.finite_rings + sage: K8(5) # indirect doctest # optional - sage.rings.finite_rings 1 - sage: K8('a+1') # optional - sage.libs.pari + sage: K8('a+1') # optional - sage.rings.finite_rings a + 1 - sage: K8(K2(1)) # optional - sage.libs.pari + sage: K8(K2(1)) # optional - sage.rings.finite_rings 1 The following test refers to :trac:`6468`:: @@ -1164,7 +1165,7 @@ def _element_constructor_(self, x): ....: raise PariError sage: P = foo_parent() sage: F = foo(P) - sage: GF(2)(F) # optional - sage.libs.pari + sage: GF(2)(F) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: error coercing to finite field @@ -1172,21 +1173,21 @@ def _element_constructor_(self, x): The following test refers to :trac:`8970`:: sage: R = Zmod(13); a = R(2) - sage: a == R(gap(a)) + sage: a == R(gap(a)) # optional - sage.libs.gap True libgap interface (:trac:`23714`):: - sage: a = libgap.eval("Z(13)^2") - sage: a.sage() + sage: a = libgap.eval("Z(13)^2") # optional - sage.libs.gap + sage: a.sage() # optional - sage.libs.gap 4 - sage: libgap(a.sage()) == a + sage: libgap(a.sage()) == a # optional - sage.libs.gap True better syntax for libgap interface:: - sage: a = libgap.Z(13)^2 - sage: libgap(a.sage()) == a + sage: a = libgap.Z(13)^2 # optional - sage.libs.gap + sage: libgap(a.sage()) == a # optional - sage.libs.gap True """ try: @@ -1320,9 +1321,9 @@ def __richcmp__(self, other, op): Ring of integers modulo 13 sage: Z11 == Z11, Z11 == Z12, Z11 == Z13 (True, False, False) - sage: F = GF(11); F # optional - sage.libs.pari + sage: F = GF(11); F # optional - sage.rings.finite_rings Finite Field of size 11 - sage: Z11 == F # optional - sage.libs.pari + sage: Z11 == F # optional - sage.rings.finite_rings False In :trac:`15229`, the following was implemented:: @@ -1331,7 +1332,7 @@ def __richcmp__(self, other, op): sage: R2 = IntegerModRing(5, is_field=True) sage: R1 is R2 # used to return False True - sage: R2 == GF(5) # optional - sage.libs.pari + sage: R2 == GF(5) # optional - sage.rings.finite_rings False """ @@ -1628,7 +1629,7 @@ def crt(v): EXAMPLES:: sage: from sage.rings.finite_rings.integer_mod_ring import crt - sage: crt([mod(3, 8),mod(1,19),mod(7, 15)]) + sage: crt([mod(3, 8), mod(1,19), mod(7, 15)]) 1027 """ if len(v) == 0: diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 3e9c85f1085..cb25cd9df92 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -264,11 +264,11 @@ def _coerce_map_from_(self, S): number fields:: sage: _. = ZZ[] - sage: K. = NumberField(x^5-3*x^4+2424*x^3+2*x-232) - sage: R = K.ring_of_integers() - sage: S. = R[] - sage: F = FractionField(S) - sage: F(1/a) + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: S. = R[] # optional - sage.rings.number_field + sage: F = FractionField(S) # optional - sage.rings.number_field + sage: F(1/a) # optional - sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 Some corner cases have been known to fail in the past (:trac:`5917`):: @@ -394,11 +394,11 @@ def _number_field_to_frac_of_ring_of_integers(self, x): number fields:: sage: _. = ZZ[] - sage: K. = NumberField(x^5-3*x^4+2424*x^3+2*x-232) - sage: R = K.ring_of_integers() - sage: S. = R[] - sage: F = FractionField(S) # indirect doctest - sage: F(1/a) + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: S. = R[] # optional - sage.rings.number_field + sage: F = FractionField(S) # indirect doctest # optional - sage.rings.number_field + sage: F(1/a) # optional - sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 """ f = x.polynomial() # Polynomial over QQ @@ -459,7 +459,7 @@ def characteristic(self): Integer Ring sage: R = Frac(ZZ['t']); R.characteristic() 0 - sage: R = Frac(GF(5)['w']); R.characteristic() + sage: R = Frac(GF(5)['w']); R.characteristic() # optional - sage.rings.finite_rings 5 """ return self._R.characteristic() @@ -481,7 +481,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest + sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest # optional - sage.rings.finite_rings \mathrm{Frac}(\Bold{F}_{7}[x, y, z]) """ return "\\mathrm{Frac}(%s)" % latex.latex(self._R) @@ -494,7 +494,7 @@ def _magma_init_(self, magma): sage: QQ['x'].fraction_field()._magma_init_(magma) # optional - magma 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...),["x"])),["x"])' - sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma + sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...,3,"grevlex"),["x","y","z"])),["x","y","z"])' ``_magma_init_`` gets called implicitly below:: @@ -571,17 +571,17 @@ def _element_constructor_(self, x, y=None, coerce=True): The next example failed before :trac:`4376`:: - sage: K(pari((x + 1)/(x^2 + x + 1))) + sage: K(pari((x + 1)/(x^2 + x + 1))) # optional - sage.libs.pari (x + 1)/(x^2 + x + 1) These examples failed before :trac:`11368`:: sage: R. = PolynomialRing(QQ) sage: S = R.fraction_field() - sage: S(pari((x + y)/y)) + sage: S(pari((x + y)/y)) # optional - sage.libs.pari (x + y)/y - sage: S(pari(x + y + 1/z)) + sage: S(pari(x + y + 1/z)) # optional - sage.libs.pari (x*z + y*z + 1)/z This example failed before :trac:`23664`:: @@ -613,13 +613,13 @@ def _element_constructor_(self, x, y=None, coerce=True): Check that :trac:`24539` is fixed:: sage: tau = polygen(QQ, 'tau') - sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) + sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) # optional - sage.rings.number_field z/(z + 1) Check that :trac:`26150` is fixed:: sage: z = SR.var('z') - sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) + sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) # optional - sage.rings.number_field (8*z + 10)/(z^5 - 3*z^4 + 2*z^3 + 2*z^2 - 3*z + 1) :: @@ -731,11 +731,12 @@ def construction(self): sage: Frac(ZZ['x']).construction() (FractionField, Univariate Polynomial Ring in x over Integer Ring) - sage: K = Frac(GF(3)['t']) - sage: f, R = K.construction() - sage: f(R) - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 3 - sage: f(R) == K + sage: K = Frac(GF(3)['t']) # optional - sage.rings.finite_rings + sage: f, R = K.construction() # optional - sage.rings.finite_rings + sage: f(R) # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 3 + sage: f(R) == K # optional - sage.rings.finite_rings True """ from sage.categories.pushout import FractionField @@ -983,8 +984,8 @@ def ring_of_integers(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) - sage: K.ring_of_integers() + sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings + sage: K.ring_of_integers() # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -995,8 +996,8 @@ def maximal_order(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) - sage: K.maximal_order() + sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings + sage: K.maximal_order() # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -1007,8 +1008,8 @@ def class_number(self): EXAMPLES:: - sage: R. = GF(5)[]; K = R.fraction_field() - sage: K.class_number() + sage: R. = GF(5)[]; K = R.fraction_field() # optional - sage.rings.finite_rings + sage: K.class_number() # optional - sage.rings.finite_rings 1 """ return 1 @@ -1019,11 +1020,11 @@ def _factor_univariate_polynomial(self, f): EXAMPLES:: - sage: k. = GF(9) - sage: K = k['t'].fraction_field() - sage: R. = K[] - sage: f = x^3 + a - sage: f.factor() + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: K = k['t'].fraction_field() # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: f = x^3 + a # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings (x + 2*a + 1)^3 """ @@ -1038,9 +1039,9 @@ def function_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: K = R.fraction_field() - sage: K.function_field() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: K.function_field() # optional - sage.rings.finite_rings Rational function field in t over Finite Field of size 5 .. SEEALSO:: @@ -1057,14 +1058,15 @@ def _coerce_map_from_(self, R): EXAMPLES:: - sage: R. = GF(5)[] - sage: K = R.fraction_field() - sage: L = K.function_field() - sage: f = K.coerce_map_from(L); f # indirect doctest + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: L = K.function_field() # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(L); f # indirect doctest # optional - sage.rings.finite_rings Isomorphism: From: Rational function field in t over Finite Field of size 5 - To: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 - sage: f(~L.gen()) + To: Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 + sage: f(~L.gen()) # optional - sage.rings.finite_rings 1/t """ @@ -1162,12 +1164,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R) - sage: S. = GF(2)[] - sage: g = S.fraction_field().coerce_map_from(S) + sage: S. = GF(2)[] # optional - sage.rings.finite_rings + sage: g = S.fraction_field().coerce_map_from(S) # optional - sage.rings.finite_rings - sage: f == g # indirect doctest + sage: f == g # indirect doctest # optional - sage.rings.finite_rings False - sage: f == f + sage: f == f # optional - sage.rings.finite_rings True """ @@ -1294,12 +1296,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R).section() - sage: S. = GF(2)[] - sage: g = S.fraction_field().coerce_map_from(S).section() + sage: S. = GF(2)[] # optional - sage.rings.finite_rings + sage: g = S.fraction_field().coerce_map_from(S).section() # optional - sage.rings.finite_rings - sage: f == g # indirect doctest + sage: f == g # indirect doctest # optional - sage.rings.finite_rings False - sage: f == f + sage: f == f # optional - sage.rings.finite_rings True """ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index c33e53e9d93..a8a4a6f4a61 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -102,8 +102,8 @@ cdef class FractionFieldElement(FieldElement): sage: f.numerator() 'hi' - sage: x = var('x') - sage: K((x + 1)/(x^2 + x + 1)) + sage: x = var('x') # optional - sage.symbolic + sage: K((x + 1)/(x^2 + x + 1)) # optional - sage.symbolic (x + 1)/(x^2 + x + 1) sage: K(355/113) 355/113 @@ -130,31 +130,31 @@ cdef class FractionFieldElement(FieldElement): sage: F = ZZ['x,y'].fraction_field() sage: x,y = F.gens() - sage: K = GF(7)['a,b'].fraction_field() - sage: a,b = K.gens() + sage: K = GF(7)['a,b'].fraction_field() # optional - sage.rings.finite_rings + sage: a,b = K.gens() # optional - sage.rings.finite_rings :: - sage: phi = F.hom([a+b, a*b], K) - sage: phi(x+y) # indirect doctest + sage: phi = F.hom([a + b, a*b], K) # optional - sage.rings.finite_rings + sage: phi(x+y) # indirect doctest # optional - sage.rings.finite_rings a*b + a + b :: - sage: (x^2/y)._im_gens_(K, [a+b, a*b]) + sage: (x^2/y)._im_gens_(K, [a + b, a*b]) # optional - sage.rings.finite_rings (a^2 + 2*a*b + b^2)/(a*b) - sage: (x^2/y)._im_gens_(K, [a, a*b]) + sage: (x^2/y)._im_gens_(K, [a, a*b]) # optional - sage.rings.finite_rings a/b :: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = K[] - sage: F = R.fraction_field() - sage: phi = F.hom([F(b),F(a)], base_map=cc) - sage: phi(i/a) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: F = R.fraction_field() # optional - sage.rings.number_field + sage: phi = F.hom([F(b), F(a)], base_map=cc) # optional - sage.rings.number_field + sage: phi(i/a) # optional - sage.rings.number_field ((-i))/b """ nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) @@ -576,8 +576,8 @@ cdef class FractionFieldElement(FieldElement): Subtraction is implemented by adding the negative:: - sage: K. = Frac(GF(7)['t']) - sage: t - 1/t # indirect doctest + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: t - 1/t # indirect doctest # optional - sage.rings.finite_rings (t^2 + 6)/t """ rnum = self.__numerator @@ -649,10 +649,10 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: a = t/(1+t) - sage: b = 3/t - sage: a*b # indirect doctest + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: a = t/(1+t) # optional - sage.rings.finite_rings + sage: b = 3/t # optional - sage.rings.finite_rings + sage: a * b # indirect doctest # optional - sage.rings.finite_rings 3/(t + 1) """ rnum = self.__numerator @@ -778,7 +778,7 @@ cdef class FractionFieldElement(FieldElement): TESTS:: sage: K = Frac(ZZ['x']) - sage: QQ(K(x) / K(2*x)) + sage: QQ(K(x) / K(2*x)) # optional - sage.symbolic 1/2 """ return self._conversion(QQ) @@ -814,15 +814,15 @@ cdef class FractionFieldElement(FieldElement): 3/2 sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) - sage: A((x+3) / (2*x - 1)) + sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A((x+3) / (2*x - 1)) # optional - sage.rings.number_field 14/15*u^2 + 7/15*u + 11/15 - sage: B = A['y'].fraction_field() - sage: A(B(u)) + sage: B = A['y'].fraction_field() # optional - sage.rings.number_field + sage: A(B(u)) # optional - sage.rings.number_field u - sage: C = A['x,y'].fraction_field() - sage: A(C(u)) + sage: C = A['x,y'].fraction_field() # optional - sage.rings.number_field + sage: A(C(u)) # optional - sage.rings.number_field u """ if self.__denominator.is_one(): @@ -900,10 +900,10 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(5)['t']) - sage: f = (t^2+t)/(t+2); f + sage: K. = Frac(GF(5)['t']) # optional - sage.rings.finite_rings + sage: f = (t^2+t)/(t+2); f # optional - sage.rings.finite_rings (t^2 + t)/(t + 2) - sage: -f + sage: -f # optional - sage.rings.finite_rings (4*t^2 + 4*t)/(t + 2) """ return self.__class__(self._parent, @@ -924,9 +924,9 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: f = (t^2+5)/(t-1) - sage: ~f + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: f = (t^2+5)/(t-1) # optional - sage.rings.finite_rings + sage: ~f # optional - sage.rings.finite_rings (t + 6)/(t^2 + 5) """ if self.is_zero(): @@ -938,12 +938,12 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: t/t == 1 + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: t/t == 1 # optional - sage.rings.finite_rings True - sage: t+1/t == (t^2+1)/t + sage: t+1/t == (t^2+1)/t # optional - sage.rings.finite_rings True - sage: t == t/5 + sage: t == t/5 # optional - sage.rings.finite_rings False :: @@ -1042,9 +1042,9 @@ cdef class FractionFieldElement(FieldElement): sage: x,y = F.gens() sage: elt = (2*x + 2*y) / (3*x - 3*y); elt (2*x + 2*y)/(3*x - 3*y) - sage: elt._symbolic_(SR) + sage: elt._symbolic_(SR) # optional - sage.symbolic 2/3*(x + y)/(x - y) - sage: symbolic_expression(elt) + sage: symbolic_expression(elt) # optional - sage.symbolic 2/3*(x + y)/(x - y) """ return ring(self.__numerator)/ring(self.__denominator) @@ -1101,18 +1101,18 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25440` has been resolved:: - sage: R. = GF(2)[] - sage: S. = R.fraction_field()[] - sage: (y+1)(R.one()) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R.fraction_field()[] # optional - sage.rings.finite_rings + sage: (y+1)(R.one()) # optional - sage.rings.finite_rings 0 Check that inexact elements are treated correctly:: - sage: K = Qp(2,5) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: L = R.fraction_field() # optional - sage.rings.padics - sage: S. = L[] # optional - sage.rings.padics - sage: y(K(1,1)/x) # optional - sage.rings.padics + sage: K = Qp(2, 5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: L = R.fraction_field() # optional - sage.rings.padics + sage: S. = L[] # optional - sage.rings.padics + sage: y(K(1,1)/x) # optional - sage.rings.padics (1 + O(2))/((1 + O(2))*x) """ if self.numerator().is_one(): @@ -1205,8 +1205,9 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): EXAMPLES:: sage: R. = QQ[] - sage: h = (t^14 + 2*t^12 - 4*t^11 - 8*t^9 + 6*t^8 + 12*t^6 - 4*t^5 - 8*t^3 + t^2 + 2)/(t^6 + 6*t^5 + 9*t^4 - 2*t^2 - 12*t - 18) - sage: h.support() # optional - sage.libs.pari + sage: h = (t^14 + 2*t^12 - 4*t^11 - 8*t^9 + 6*t^8 + 12*t^6 - 4*t^5 # optional - sage.libs.pari + ....: - 8*t^3 + t^2 + 2)/(t^6 + 6*t^5 + 9*t^4 - 2*t^2 - 12*t - 18) + sage: h.support() [t - 1, t + 3, t^2 + 2, t^2 + t + 1, t^4 - 2] """ L = [fac[0] for fac in self.numerator().factor()] + [fac[0] for fac in self.denominator().factor()] diff --git a/src/sage/rings/function_field/drinfeld_modules/action.py b/src/sage/rings/function_field/drinfeld_modules/action.py index 32a00f9ea71..cfa9774058a 100644 --- a/src/sage/rings/function_field/drinfeld_modules/action.py +++ b/src/sage/rings/function_field/drinfeld_modules/action.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" The module action induced by a Drinfeld module @@ -58,7 +59,8 @@ class DrinfeldModuleAction(Action): sage: phi = DrinfeldModule(A, [z, 0, 0, 1]) sage: action = phi.action() sage: action - Action on Finite Field in z of size 11^2 over its base induced by Drinfeld module defined by T |--> t^3 + z + Action on Finite Field in z of size 11^2 over its base + induced by Drinfeld module defined by T |--> t^3 + z The action on elements is computed as follows:: diff --git a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py index b50193c1862..23a992f2ce1 100644 --- a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld modules @@ -171,7 +172,10 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: phi(T) # phi_T, the generator of the Drinfeld module t^2 + t + z sage: phi(T^3 + T + 1) # phi_(T^3 + T + 1) - t^6 + (z^11 + z^9 + 2*z^6 + 2*z^4 + 2*z + 1)*t^4 + (2*z^11 + 2*z^10 + z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^3)*t^3 + (2*z^11 + z^10 + z^9 + 2*z^7 + 2*z^6 + z^5 + z^4 + 2*z^3 + 2*z + 2)*t^2 + (2*z^11 + 2*z^8 + 2*z^6 + z^5 + z^4 + 2*z^2)*t + z^3 + z + 1 + t^6 + (z^11 + z^9 + 2*z^6 + 2*z^4 + 2*z + 1)*t^4 + + (2*z^11 + 2*z^10 + z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^3)*t^3 + + (2*z^11 + z^10 + z^9 + 2*z^7 + 2*z^6 + z^5 + z^4 + 2*z^3 + 2*z + 2)*t^2 + + (2*z^11 + 2*z^8 + 2*z^6 + z^5 + z^4 + 2*z^2)*t + z^3 + z + 1 sage: phi(1) # phi_1 1 @@ -228,7 +232,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): :: sage: phi.ore_polring() # K{t} - Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base twisted by Frob^2 + Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base + twisted by Frob^2 :: @@ -252,7 +257,9 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: phi.morphism() # The Drinfeld module as a morphism Ring morphism: From: Univariate Polynomial Ring in T over Finite Field in z2 of size 3^2 - To: Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base twisted by Frob^2 + To: Ore Polynomial Ring in t + over Finite Field in z of size 3^12 over its base + twisted by Frob^2 Defn: T |--> t^2 + t + z One can compute the rank and height:: @@ -353,7 +360,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: P = (2*z^6 + z^3 + 2*z^2 + z + 2)*t + z^11 + 2*z^10 + 2*z^9 + 2*z^8 + z^7 + 2*z^6 + z^5 + z^3 + z^2 + z sage: psi = phi.velu(P) sage: psi - Drinfeld module defined by T |--> (2*z^11 + 2*z^9 + z^6 + 2*z^5 + 2*z^4 + 2*z^2 + 1)*t^2 + (2*z^11 + 2*z^10 + 2*z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^4 + 2*z^2 + 2*z)*t + z + Drinfeld module defined by T |--> (2*z^11 + 2*z^9 + z^6 + 2*z^5 + 2*z^4 + 2*z^2 + 1)*t^2 + + (2*z^11 + 2*z^10 + 2*z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^4 + 2*z^2 + 2*z)*t + z sage: P in Hom(phi, psi) True sage: P * phi(T) == psi(T) * P @@ -385,7 +393,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: action = phi.action() sage: action - Action on Finite Field in z of size 3^12 over its base induced by Drinfeld module defined by T |--> t^2 + t + z + Action on Finite Field in z of size 3^12 over its base + induced by Drinfeld module defined by T |--> t^2 + t + z The action on elements is computed by calling the action object:: @@ -867,7 +876,9 @@ def action(self): sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: action = phi.action() sage: action - Action on Finite Field in z12 of size 5^12 over its base induced by Drinfeld module defined by T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + Action on Finite Field in z12 of size 5^12 over its base + induced by Drinfeld module defined by T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 The action on elements is computed as follows:: @@ -901,7 +912,8 @@ def coefficient(self, n): sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: phi.coefficient(0) - 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi.coefficient(0) == p_root True sage: phi.coefficient(1) @@ -938,7 +950,8 @@ def coefficients(self, sparse=True): sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: phi.coefficients() - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, z12^3, z12^5] @@ -947,10 +960,12 @@ def coefficients(self, sparse=True): sage: rho = DrinfeldModule(A, [p_root, 0, 0, 0, 1]) sage: rho.coefficients() - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, 1] sage: rho.coefficients(sparse=False) - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, 0, 0, 0, @@ -1120,8 +1135,10 @@ def morphism(self): sage: phi.morphism() Ring morphism: From: Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - To: Ore Polynomial Ring in t over Finite Field in z12 of size 5^12 over its base twisted by Frob^2 - Defn: T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + To: Ore Polynomial Ring in t over Finite Field in z12 of size 5^12 + over its base twisted by Frob^2 + Defn: T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: from sage.rings.morphism import RingHomomorphism sage: isinstance(phi.morphism(), RingHomomorphism) True @@ -1144,7 +1161,8 @@ class the ``__call__`` method of this morphism:: sage: m.codomain() is phi.ore_polring() True sage: m.im_gens() - [z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12] + [z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12] sage: phi(T) == m.im_gens()[0] True """ @@ -1220,7 +1238,10 @@ def velu(self, isog): sage: isog = t + 2*z12^11 + 4*z12^9 + 2*z12^8 + 2*z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + 4*z12^2 + 4*z12 + 4 sage: psi = phi.velu(isog) sage: psi - Drinfeld module defined by T |--> (z12^11 + 3*z12^10 + z12^9 + z12^7 + z12^5 + 4*z12^4 + 4*z12^3 + z12^2 + 1)*t^2 + (2*z12^11 + 4*z12^10 + 2*z12^8 + z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + z12^2 + z12 + 4)*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + Drinfeld module defined by T |--> + (z12^11 + 3*z12^10 + z12^9 + z12^7 + z12^5 + 4*z12^4 + 4*z12^3 + z12^2 + 1)*t^2 + + (2*z12^11 + 4*z12^10 + 2*z12^8 + z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + z12^2 + z12 + 4)*t + + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: isog in Hom(phi, psi) True diff --git a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py index 6cc78a53fb4..9d468dba511 100644 --- a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Finite Drinfeld modules @@ -221,7 +222,8 @@ def frobenius_charpoly(self, var='X'): sage: phi = DrinfeldModule(A, [1, 0, z6]) sage: chi = phi.frobenius_charpoly() sage: chi - X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 + X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 :: diff --git a/src/sage/rings/function_field/drinfeld_modules/homset.py b/src/sage/rings/function_field/drinfeld_modules/homset.py index 84fdc4c6e14..c4f43db19da 100644 --- a/src/sage/rings/function_field/drinfeld_modules/homset.py +++ b/src/sage/rings/function_field/drinfeld_modules/homset.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Set of morphisms between two Drinfeld modules @@ -46,7 +47,9 @@ class DrinfeldModuleHomset(Homset): sage: psi = DrinfeldModule(A, [z6, 2*z6^5 + 2*z6^4 + 2*z6 + 1, 2]) sage: H = Hom(phi, psi) sage: H - Set of Drinfeld module morphisms from (gen) 2*t^2 + z6*t + z6 to (gen) 2*t^2 + (2*z6^5 + 2*z6^4 + 2*z6 + 1)*t + z6 + Set of Drinfeld module morphisms + from (gen) 2*t^2 + z6*t + z6 + to (gen) 2*t^2 + (2*z6^5 + 2*z6^4 + 2*z6 + 1)*t + z6 :: diff --git a/src/sage/rings/function_field/drinfeld_modules/morphism.py b/src/sage/rings/function_field/drinfeld_modules/morphism.py index dab86c43efa..2d5414095f5 100644 --- a/src/sage/rings/function_field/drinfeld_modules/morphism.py +++ b/src/sage/rings/function_field/drinfeld_modules/morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld module morphisms diff --git a/src/sage/rings/homset.py b/src/sage/rings/homset.py index 6f7a2d4b415..77fa3323bc0 100644 --- a/src/sage/rings/homset.py +++ b/src/sage/rings/homset.py @@ -133,25 +133,26 @@ def _element_constructor_(self, x, check=True, base_map=None): You can provide a morphism on the base:: - sage: k = GF(9) - sage: z2 = k.gen() - sage: cc = k.frobenius_endomorphism() - sage: R. = k[] - sage: H = Hom(R, R) - sage: phi = H([x^2], base_map=cc); phi - Ring endomorphism of Univariate Polynomial Ring in x over Finite Field in z2 of size 3^2 + sage: k = GF(9) # optional - sage.rings.finite_rings + sage: z2 = k.gen() # optional - sage.rings.finite_rings + sage: cc = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: H = Hom(R, R) # optional - sage.rings.finite_rings + sage: phi = H([x^2], base_map=cc); phi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Polynomial Ring in x + over Finite Field in z2 of size 3^2 Defn: x |--> x^2 with map of base ring - sage: phi(z2*x) == z2^3 * x^2 + sage: phi(z2 * x) == z2^3 * x^2 # optional - sage.rings.finite_rings True sage: R. = ZZ[] - sage: K. = GF(7^2) - sage: L. = K.extension(x^3 - 3) - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) - sage: phi(u) == u^7 + sage: K. = GF(7^2) # optional - sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: phi(u) == u^7 # optional - sage.rings.finite_rings True - sage: phi(a) == a^7 + sage: phi(a) == a^7 # optional - sage.rings.finite_rings True TESTS:: @@ -247,14 +248,15 @@ class RingHomset_quo_ring(RingHomset_generic): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: phi = S.hom([b,a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.hom([b,a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) Defn: a |--> b b |--> a - sage: phi(a) + sage: phi(a) # optional - sage.libs.singular b - sage: phi(b) + sage: phi(b) # optional - sage.libs.singular a TESTS: @@ -264,15 +266,15 @@ class RingHomset_quo_ring(RingHomset_generic): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: H = S.Hom(R) - sage: H == loads(dumps(H)) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: H = S.Hom(R) # optional - sage.libs.singular + sage: H == loads(dumps(H)) # optional - sage.libs.singular True We test pickling of actual homomorphisms in a quotient:: - sage: phi = S.hom([b,a]) - sage: phi == loads(dumps(phi)) + sage: phi = S.hom([b,a]) # optional - sage.libs.singular + sage: phi == loads(dumps(phi)) # optional - sage.libs.singular True """ @@ -285,17 +287,17 @@ def _element_constructor_(self, x, base_map=None, check=True): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: H = S.Hom(R) - sage: phi = H([b, a]); phi + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: H = S.Hom(R) # optional - sage.libs.singular + sage: phi = H([b, a]); phi # optional - sage.libs.singular Ring morphism: From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: a |--> b b |--> a sage: R2. = PolynomialRing(ZZ, 2) - sage: H2 = Hom(R2, S) - sage: H2(phi) + sage: H2 = Hom(R2, S) # optional - sage.libs.singular + sage: H2(phi) # optional - sage.libs.singular Composite map: From: Multivariate Polynomial Ring in x, y over Integer Ring To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index b7a7ec1c6a0..5a39427261b 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -125,9 +125,9 @@ def Ideal(*args, **kwds): Note that some rings use different ideal implementations than the standard, even if they are PIDs.:: - sage: R. = GF(5)[] - sage: I = R*(x^2+3) - sage: type(I) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: I = R * (x^2 + 3) # optional - sage.rings.finite_rings + sage: type(I) # optional - sage.rings.finite_rings You can also pass in a specific ideal type:: @@ -337,9 +337,9 @@ def random_element(self, *args, **kwds): EXAMPLES:: - sage: P. = GF(5)[[]] - sage: I = P.ideal([a^2, a*b + c, c^3]) - sage: I.random_element() # random + sage: P. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: I = P.ideal([a^2, a*b + c, c^3]) # optional - sage.rings.finite_rings + sage: I.random_element() # random # optional - sage.rings.finite_rings 2*a^5*c + a^2*b*c^4 + ... + O(a, b, c)^13 """ @@ -376,11 +376,11 @@ def __contains__(self, x): EXAMPLES:: sage: P. = QQ[] - sage: I = P*[a, b] - sage: a + b in I + sage: I = P * [a, b] + sage: a + b in I # optional - sage.libs.singular True sage: P2. = QQ[] - sage: x + 2*y + w*z in I + sage: x + 2*y + w*z in I # optional - sage.libs.singular False """ try: @@ -751,17 +751,17 @@ def is_primary(self, P=None): Some examples from the Macaulay2 documentation:: - sage: R. = GF(101)[] - sage: I = R.ideal([y^6]) - sage: I.is_primary() + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: I = R.ideal([y^6]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.rings.finite_rings True - sage: I.is_primary(R.ideal([y])) + sage: I.is_primary(R.ideal([y])) # optional - sage.rings.finite_rings True - sage: I = R.ideal([x^4, y^7]) - sage: I.is_primary() + sage: I = R.ideal([x^4, y^7]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.rings.finite_rings True - sage: I = R.ideal([x*y, y^2]) - sage: I.is_primary() + sage: I = R.ideal([x*y, y^2]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.rings.finite_rings False .. NOTE:: @@ -800,24 +800,24 @@ def is_prime(self): sage: R. = QQ[] sage: I = R.ideal([x, y]) - sage: I.is_prime() # a maximal ideal + sage: I.is_prime() # a maximal ideal # optional - sage.libs.singular True - sage: I = R.ideal([x^2-y]) - sage: I.is_prime() # a non-maximal prime ideal + sage: I = R.ideal([x^2 - y]) + sage: I.is_prime() # a non-maximal prime ideal # optional - sage.libs.singular True sage: I = R.ideal([x^2, y]) - sage: I.is_prime() # a non-prime primary ideal + sage: I.is_prime() # a non-prime primary ideal # optional - sage.libs.singular False sage: I = R.ideal([x^2, x*y]) - sage: I.is_prime() # a non-prime non-primary ideal + sage: I.is_prime() # a non-prime non-primary ideal # optional - sage.libs.singular False sage: S = Integers(8) - sage: S.ideal(0).is_prime() + sage: S.ideal(0).is_prime() # optional - sage.libs.singular False - sage: S.ideal(2).is_prime() + sage: S.ideal(2).is_prime() # optional - sage.libs.singular True - sage: S.ideal(4).is_prime() + sage: S.ideal(4).is_prime() # optional - sage.libs.singular False Note that this method is not implemented for all rings where it @@ -888,7 +888,7 @@ def embedded_primes(self): sage: R. = QQ[] sage: I = R.ideal(x^2, x*y) - sage: I.embedded_primes() + sage: I.embedded_primes() # optional - sage.libs.singular [Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational Field] """ # by definition, embedded primes are associated primes that @@ -917,13 +917,13 @@ def is_principal(self): EXAMPLES:: - sage: R = ZZ['x'] - sage: I = R.ideal(2,x) + sage: R. = ZZ[] + sage: I = R.ideal(2, x) sage: I.is_principal() Traceback (most recent call last): ... NotImplementedError - sage: J = R.base_extend(QQ).ideal(2,x) + sage: J = R.base_extend(QQ).ideal(2, x) sage: J.is_principal() True """ @@ -956,7 +956,7 @@ def is_trivial(self): :: sage: I = QQ['x', 'y'].ideal(-5) - sage: I.is_trivial() + sage: I.is_trivial() # optional - sage.libs.singular True :: @@ -969,7 +969,7 @@ def is_trivial(self): sage: R = QQ['x', 'y'] sage: I = R.ideal(R.gens()) - sage: I.is_trivial() + sage: I.is_trivial() # optional - sage.libs.singular False """ return self.is_zero() or self == self.ring().unit_ideal() @@ -1114,10 +1114,11 @@ def norm(self): EXAMPLES:: - sage: R. = GF(8, names='a')[] - sage: I = R.ideal(t^4 + t + 1) - sage: I.norm() - Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t over Finite Field in a of size 2^3 + sage: R. = GF(8, names='a')[] # optional - sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: I.norm() # optional - sage.rings.finite_rings + Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t + over Finite Field in a of size 2^3 """ return self @@ -1137,9 +1138,9 @@ def absolute_norm(self): EXAMPLES:: - sage: R. = GF(9, names='a')[] - sage: I = R.ideal(t^4 + t + 1) - sage: I.absolute_norm() + sage: R. = GF(9, names='a')[] # optional - sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: I.absolute_norm() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1157,7 +1158,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 ) @@ -1166,28 +1167,28 @@ def _macaulay2_init_(self, macaulay2=None): sage: R. = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]); I Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring - sage: macaulay2(I) # optional - macaulay2 + sage: macaulay2(I) # optional - macaulay2 2 2 ideal (x + 3x + 4, x + 1) Field ideals generated from the polynomial ring over two variables in the finite field of size 2:: - sage: P. = PolynomialRing(GF(2), 2) - sage: I = sage.rings.ideal.FieldIdeal(P); I - Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over - Finite Field of size 2 - sage: macaulay2(I) # optional - macaulay2 + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y + over Finite Field of size 2 + sage: macaulay2(I) # optional - macaulay2 # optional - sage.rings.finite_rings 2 2 ideal (x + x, y + y) Ideals in PIDs:: - sage: macaulay2(ideal(5)) # optional - macaulay2 + sage: macaulay2(ideal(5)) # optional - macaulay2 ideal 5 sage: J = ideal(QQ(5)) ... - sage: macaulay2(J) # optional - macaulay2 + sage: macaulay2(J) # optional - macaulay2 ideal 1 TESTS: @@ -1611,18 +1612,18 @@ def is_maximal(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: p = R.ideal(t^2 + 2) - sage: p.is_maximal() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: p = R.ideal(t^2 + 2) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings True - sage: p = R.ideal(t^2 + 1) - sage: p.is_maximal() + sage: p = R.ideal(t^2 + 1) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False - sage: p = R.ideal(0) - sage: p.is_maximal() + sage: p = R.ideal(0) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False - sage: p = R.ideal(1) - sage: p.is_maximal() + sage: p = R.ideal(1) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False """ if not self.ring().is_field() and self.is_zero(): @@ -1642,41 +1643,41 @@ def residue_field(self): sage: P = ZZ.ideal(61); P Principal ideal (61) of Integer Ring - sage: F = P.residue_field(); F + sage: F = P.residue_field(); F # optional - sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi + sage: pi = F.reduction_map(); pi # optional - sage.libs.pari Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) + sage: pi(123/234) # optional - sage.libs.pari 6 - sage: pi(1/61) + sage: pi(1/61) # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift + sage: lift = F.lift_map(); lift # optional - sage.libs.pari Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) + sage: lift(F(12345/67890)) # optional - sage.libs.pari 33 sage: (12345/67890) % 61 33 TESTS:: - sage: ZZ.ideal(96).residue_field() + sage: ZZ.ideal(96).residue_field() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: The ideal (Principal ideal (96) of Integer Ring) is not prime :: - sage: R.=QQ[] - sage: I=R.ideal(x^2+1) - sage: I.is_prime() + sage: R. = QQ[] + sage: I = R.ideal(x^2 + 1) + sage: I.is_prime() # optional - sage.libs.pari True - sage: I.residue_field() + sage: I.residue_field() # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: residue fields only supported for polynomial rings over finite fields. @@ -1737,21 +1738,20 @@ def Cyclic(R, n=None, homog=False, singular=None): An example from a multivariate polynomial ring over the rationals:: - sage: P. = PolynomialRing(QQ,3,order='lex') - sage: I = sage.rings.ideal.Cyclic(P) - sage: I - Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) of Multivariate Polynomial - Ring in x, y, z over Rational Field - sage: I.groebner_basis() + sage: P. = PolynomialRing(QQ, 3, order='lex') + sage: I = sage.rings.ideal.Cyclic(P); I # optional - sage.libs.singular + Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) + of Multivariate Polynomial Ring in x, y, z over Rational Field + sage: I.groebner_basis() # optional - sage.libs.singular [x + y + z, y^2 + y*z + z^2, z^3 - 1] We compute a Groebner basis for cyclic 6, which is a standard benchmark and test ideal:: sage: R. = QQ['x,y,z,t,u,v'] - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: B = I.groebner_basis() - sage: len(B) + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.libs.singular + sage: B = I.groebner_basis() # optional - sage.libs.singular + sage: len(B) # optional - sage.libs.singular 45 """ from .rational_field import RationalField @@ -1796,15 +1796,15 @@ def Katsura(R, n=None, homog=False, singular=None): EXAMPLES:: - sage: P. = PolynomialRing(QQ,3) - sage: I = sage.rings.ideal.Katsura(P,3); I + sage: P. = PolynomialRing(QQ, 3) + sage: I = sage.rings.ideal.Katsura(P, 3); I # optional - sage.libs.singular Ideal (x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y) of Multivariate Polynomial Ring in x, y, z over Rational Field :: - sage: Q. = PolynomialRing(QQ, implementation="singular") - sage: J = sage.rings.ideal.Katsura(Q,1); J + sage: Q. = PolynomialRing(QQ, implementation="singular") # optional - sage.libs.singular + sage: J = sage.rings.ideal.Katsura(Q,1); J # optional - sage.libs.singular Ideal (x - 1) of Multivariate Polynomial Ring in x over Rational Field """ from .rational_field import RationalField @@ -1844,18 +1844,18 @@ def FieldIdeal(R): The field ideal generated from the polynomial ring over two variables in the finite field of size 2:: - sage: P. = PolynomialRing(GF(2),2) - sage: I = sage.rings.ideal.FieldIdeal(P); I - Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over - Finite Field of size 2 + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + Ideal (x^2 + x, y^2 + y) of + Multivariate Polynomial Ring in x, y over Finite Field of size 2 Another, similar example:: - sage: Q. = PolynomialRing(GF(2^4,name='alpha'), 4) - sage: J = sage.rings.ideal.FieldIdeal(Q); J + sage: Q. = PolynomialRing(GF(2^4, name='alpha'), 4) # optional - sage.rings.finite_rings + sage: J = sage.rings.ideal.FieldIdeal(Q); J # optional - sage.rings.finite_rings Ideal (x1^16 + x1, x2^16 + x2, x3^16 + x3, x4^16 + x4) of - Multivariate Polynomial Ring in x1, x2, x3, x4 over Finite - Field in alpha of size 2^4 + Multivariate Polynomial Ring in x1, x2, x3, x4 + over Finite Field in alpha of size 2^4 """ q = R.base_ring().order() import sage.rings.infinity diff --git a/src/sage/rings/ideal_monoid.py b/src/sage/rings/ideal_monoid.py index efeccaef794..01193661aae 100644 --- a/src/sage/rings/ideal_monoid.py +++ b/src/sage/rings/ideal_monoid.py @@ -21,7 +21,8 @@ def IdealMonoid(R): EXAMPLES:: sage: R = QQ['x'] - sage: sage.rings.ideal_monoid.IdealMonoid(R) + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: IdealMonoid(R) Monoid of ideals of Univariate Polynomial Ring in x over Rational Field """ return IdealMonoid_c(R) @@ -34,7 +35,8 @@ class IdealMonoid_c(Parent): TESTS:: sage: R = QQ['x'] - sage: M = sage.rings.ideal_monoid.IdealMonoid(R) + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R) sage: TestSuite(M).run() Failure in _test_category: ... @@ -51,16 +53,18 @@ def __init__(self, R): TESTS:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M # indirect doctest - Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M # indirect doctest # optional - sage.rings.number_field + Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 + with a = 4.795831523312720?*I sage: id = QQ.ideal(6) sage: id.parent().category() Category of commutative monoids - sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules - sage: MS.ideal(MS.one()).parent().category() # optional - sage.modules + sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: MS.ideal(MS.one()).parent().category() # optional - sage.modules Category of monoids """ self.__R = R @@ -77,9 +81,11 @@ def _repr_(self): TESTS:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M._repr_() - 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I' + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M._repr_() # optional - sage.rings.number_field + 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 + with a = 4.795831523312720?*I' """ return "Monoid of ideals of %s" % self.__R @@ -89,8 +95,9 @@ def ring(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M.ring() is R + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M.ring() is R # optional - sage.rings.number_field True """ return self.__R @@ -101,11 +108,12 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: R. = QuadraticField(-23) - sage: M = sage.rings.ideal_monoid.IdealMonoid(R) - sage: M(a) # indirect doctest + sage: R. = QuadraticField(-23) # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R) # optional - sage.rings.number_field + sage: M(a) # indirect doctest # optional - sage.rings.number_field Fractional ideal (a) - sage: M([a-4, 13]) + sage: M([a-4, 13]) # optional - sage.rings.number_field Fractional ideal (13, 1/2*a + 9/2) """ try: @@ -129,9 +137,9 @@ def _coerce_map_from_(self, x): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M.has_coerce_map_from(R) # indirect doctest + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M.has_coerce_map_from(R) # indirect doctest # optional - sage.rings.number_field True sage: M.has_coerce_map_from(QQ.ideal_monoid()) # optional - sage.rings.number_field True @@ -151,13 +159,13 @@ def __eq__(self, other): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M == QQ + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M == QQ # optional - sage.rings.number_field False - sage: M == 17 + sage: M == 17 # optional - sage.rings.number_field False - sage: M == R.ideal_monoid() + sage: M == R.ideal_monoid() # optional - sage.rings.number_field True """ if not isinstance(other, IdealMonoid_c): @@ -171,13 +179,13 @@ def __ne__(self, other): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M != QQ + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M != QQ # optional - sage.rings.number_field True - sage: M != 17 + sage: M != 17 # optional - sage.rings.number_field True - sage: M != R.ideal_monoid() + sage: M != R.ideal_monoid() # optional - sage.rings.number_field False """ return not (self == other) @@ -188,13 +196,13 @@ def __hash__(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: hash(M) == hash(QQ) + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: hash(M) == hash(QQ) # optional - sage.rings.number_field False - sage: hash(M) == 17 + sage: hash(M) == 17 # optional - sage.rings.number_field False - sage: hash(M) == hash(R.ideal_monoid()) + sage: hash(M) == hash(R.ideal_monoid()) # optional - sage.rings.number_field True """ # uses a random number, to have a distinct hash diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index 4a64626d2ca..b08f441f2aa 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -203,8 +203,8 @@ We check that :trac:`17990` is fixed:: - sage: m = Matrix([Infinity]) - sage: m.rows() + sage: m = Matrix([Infinity]) # optional - sage.modules + sage: m.rows() # optional - sage.modules [(+Infinity)] """ #***************************************************************************** @@ -471,7 +471,7 @@ def _div_(self, other): Traceback (most recent call last): ... ValueError: unsigned oo times smaller number not defined - sage: SR(infinity) / unsigned_infinity + sage: SR(infinity) / unsigned_infinity # optional - sage.symbolic Traceback (most recent call last): ... RuntimeError: indeterminate expression: 0 * infinity encountered. @@ -567,8 +567,8 @@ def __init__(self): Sage can understand SymPy's complex infinity (:trac:`17493`):: - sage: import sympy - sage: SR(sympy.zoo) + sage: import sympy # optional - sympy + sage: SR(sympy.zoo) # optional - sympy Infinity Some equality checks:: @@ -675,7 +675,7 @@ def _element_constructor_(self, x): sage: UnsignedInfinityRing(2) # indirect doctest A number less than infinity - sage: UnsignedInfinityRing(I) + sage: UnsignedInfinityRing(I) # optional - sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(unsigned_infinity) Infinity @@ -683,10 +683,10 @@ def _element_constructor_(self, x): Infinity sage: UnsignedInfinityRing(-oo) Infinity - sage: K. = QuadraticField(3) - sage: UnsignedInfinityRing(a) + sage: K. = QuadraticField(3) # optional - sage.rings.number_field + sage: UnsignedInfinityRing(a) # optional - sage.rings.number_field A number less than infinity - sage: UnsignedInfinityRing(a - 2) + sage: UnsignedInfinityRing(a - 2) # optional - sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(RDF(oo)), UnsignedInfinityRing(RDF(-oo)) (Infinity, Infinity) @@ -700,14 +700,14 @@ def _element_constructor_(self, x): (Infinity, Infinity) sage: UnsignedInfinityRing(float('+inf')), UnsignedInfinityRing(float('-inf')) (Infinity, Infinity) - sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) + sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) # optional - sage.symbolic (Infinity, Infinity) The following rings have a ``is_infinity`` method:: sage: RR(oo).is_infinity() True - sage: SR(oo).is_infinity() + sage: SR(oo).is_infinity() # optional - sage.symbolic True """ # Lazy elements can wrap infinity or not, unwrap first @@ -747,11 +747,11 @@ def _coerce_map_from_(self, R): True sage: UnsignedInfinityRing.has_coerce_map_from(CC) True - sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) + sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) # optional - sage.rings.number_field True - sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) + sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) # optional - sage.modules False - sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) + sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) # optional - sage.groups False """ return isinstance(R, Ring) or R in (int, float, complex) @@ -942,12 +942,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: SR(unsigned_infinity)._sympy_() + sage: import sympy # optional - sympy + sage: SR(unsigned_infinity)._sympy_() # optional - sympy zoo - sage: gamma(-3)._sympy_() is sympy.factorial(-2) + sage: gamma(-3)._sympy_() is sympy.factorial(-2) # optional - sympy True - sage: gamma(-3) is sympy.factorial(-2)._sage_() + sage: gamma(-3) is sympy.factorial(-2)._sage_() # optional - sympy True """ import sympy @@ -1227,7 +1227,7 @@ def _coerce_map_from_(self, R): sage: InfinityRing.has_coerce_map_from(int) # indirect doctest True - sage: InfinityRing.has_coerce_map_from(AA) + sage: InfinityRing.has_coerce_map_from(AA) # optional - sage.rings.number_field True sage: InfinityRing.has_coerce_map_from(RDF) True @@ -1238,7 +1238,7 @@ def _coerce_map_from_(self, R): infinity ring:: sage: cm = get_coercion_model() - sage: cm.explain(AA(3), oo, operator.lt) + sage: cm.explain(AA(3), oo, operator.lt) # optional - sage.rings.number_field Coercion on left operand via Coercion map: From: Algebraic Real Field @@ -1279,7 +1279,7 @@ def _pushout_(self, other): r""" EXAMPLES:: - sage: QQbar(-2*i)*infinity + sage: QQbar(-2*i)*infinity # optional - sage.rings.number_field (-I)*Infinity """ from sage.symbolic.ring import SR @@ -1480,9 +1480,9 @@ def _latex_(self): TESTS:: - sage: a = InfinityRing(pi); a + sage: a = InfinityRing(pi); a # optional - sage.symbolic A positive finite number - sage: a._latex_() + sage: a._latex_() # optional - sage.symbolic 'A positive finite number' sage: [latex(InfinityRing(a)) for a in [-2..2]] [A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number] @@ -1623,12 +1623,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: bool(-oo == -sympy.oo) + sage: import sympy # optional - sympy + sage: bool(-oo == -sympy.oo) # optional - sympy True - sage: bool(SR(-oo) == -sympy.oo) + sage: bool(SR(-oo) == -sympy.oo) # optional - sympy True - sage: bool((-oo)._sympy_() == -sympy.oo) + sage: bool((-oo)._sympy_() == -sympy.oo) # optional - sympy True """ @@ -1641,9 +1641,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(-Infinity) + sage: gap(-Infinity) # optional - sage.libs.gap -infinity - sage: libgap(-Infinity) + sage: libgap(-Infinity) # optional - sage.libs.gap -infinity """ return '-infinity' @@ -1724,10 +1724,10 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: bool(oo == sympy.oo) # indirect doctest + sage: import sympy # optional - sympy + sage: bool(oo == sympy.oo) # indirect doctest # optional - sympy True - sage: bool(SR(oo) == sympy.oo) + sage: bool(SR(oo) == sympy.oo) # optional - sympy True """ import sympy @@ -1739,9 +1739,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(+Infinity) + sage: gap(+Infinity) # optional - sage.libs.gap infinity - sage: libgap(+Infinity) + sage: libgap(+Infinity) # optional - sage.libs.gap infinity """ return 'infinity' @@ -1770,7 +1770,7 @@ def test_comparison(ring): EXAMPLES:: sage: from sage.rings.infinity import test_comparison - sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, AA, RIF] + sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] sage: for R in rings: ....: print('testing {}'.format(R)) ....: test_comparison(R) @@ -1780,20 +1780,20 @@ def test_comparison(ring): testing Real Field with 200 bits of precision testing Real Double Field testing Real Lazy Field - testing Algebraic Real Field testing Real Interval Field with 53 bits of precision + sage: test_comparison(AA) # optional - sage.rings.number_field Comparison with number fields does not work:: - sage: K. = NumberField(x^2-3) - sage: (-oo < 1+sqrt3) and (1+sqrt3 < oo) # known bug + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: (-oo < 1 + sqrt3) and (1 + sqrt3 < oo) # known bug # optional - sage.rings.number_field False The symbolic ring handles its own infinities, but answers ``False`` (meaning: cannot decide) already for some very elementary comparisons:: - sage: test_comparison(SR) # known bug + sage: test_comparison(SR) # known bug # optional - sage.symbolic Traceback (most recent call last): ... AssertionError: testing -1000.0 in Symbolic Ring: id = ... diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 535cf19cce8..10a94aa156d 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -425,9 +425,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Conversion from PARI:: - sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari + sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari -10380104371593008048799446356441519384 - sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari + sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari -3 Conversion from gmpy2:: @@ -463,11 +463,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): -901824309821093821093812093810928309183091832091 sage: ZZ(RR(2.0)^80) 1208925819614629174706176 - sage: ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3))) # optional - sage.rings.number_field sage.symbolic + sage: ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3))) # optional - sage.rings.number_field sage.symbolic 5 - sage: ZZ(AA(32).nth_root(5)) # optional - sage.rings.number_field + sage: ZZ(AA(32).nth_root(5)) # optional - sage.rings.number_field 2 - sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari + sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari 4 sage: ZZ('sage') Traceback (most recent call last): @@ -479,10 +479,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): '3b' sage: ZZ( ZZ(5).digits(3) , 3) 5 - sage: import numpy - sage: ZZ(numpy.int64(7^7)) + sage: import numpy # optional - numpy + sage: ZZ(numpy.int64(7^7)) # optional - numpy 823543 - sage: ZZ(numpy.ubyte(-7)) + sage: ZZ(numpy.ubyte(-7)) # optional - numpy 249 sage: ZZ(True) 1 @@ -498,8 +498,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: k = GF(2) # optional - sage.libs.pari - sage: ZZ((k(0),k(1)), 2) # optional - sage.libs.pari + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: ZZ((k(0),k(1)), 2) # optional - sage.rings.finite_rings 2 :: @@ -535,72 +535,72 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Test conversion from PARI (:trac:`11685`):: - sage: ZZ(pari(-3)) # optional - sage.libs.pari + sage: ZZ(pari(-3)) # optional - sage.libs.pari -3 - sage: ZZ(pari("-3.0")) # optional - sage.libs.pari + sage: ZZ(pari("-3.0")) # optional - sage.libs.pari -3 - sage: ZZ(pari("-3.5")) # optional - sage.libs.pari + sage: ZZ(pari("-3.5")) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral real number to an Integer - sage: ZZ(pari("1e100")) # optional - sage.libs.pari + sage: ZZ(pari("1e100")) # optional - sage.libs.pari Traceback (most recent call last): ... PariError: precision too low in truncr (precision loss in truncation) - sage: ZZ(pari("10^50")) # optional - sage.libs.pari + sage: ZZ(pari("10^50")) # optional - sage.libs.pari 100000000000000000000000000000000000000000000000000 - sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari + sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari 3 - sage: ZZ(GF(3^20,'t')(1)) # optional - sage.libs.pari + sage: ZZ(GF(3^20,'t')(1)) # optional - sage.rings.finite_rings 1 - sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari + sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari sage.rings.finite_rings 1 sage: x = polygen(QQ) - sage: K. = NumberField(x^2+3) # optional - sage.rings.number_field - sage: ZZ(a^2) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 3) # optional - sage.rings.number_field + sage: ZZ(a^2) # optional - sage.rings.number_field -3 - sage: ZZ(pari(a)^2) # optional - sage.libs.pari sage.rings.number_field + sage: ZZ(pari(a)^2) # optional - sage.libs.pari sage.rings.number_field -3 - sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # optional - sage.libs.pari + sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Unable to coerce PARI x to an Integer Test coercion of p-adic with negative valuation:: - sage: ZZ(pari(Qp(11)(11^-7))) # optional - sage.libs.pari + sage: ZZ(pari(Qp(11)(11^-7))) # optional - sage.libs.pari sage.rings.padics Traceback (most recent call last): ... TypeError: cannot convert p-adic with negative valuation to an integer Test converting a list with a very large base:: - sage: a=ZZ(randint(0,2^128-1)) + sage: a = ZZ(randint(0, 2^128 - 1)) sage: L = a.digits(2^64) sage: a == sum([x * 2^(64*i) for i,x in enumerate(L)]) True - sage: a == ZZ(L,base=2^64) + sage: a == ZZ(L, base=2^64) True Test comparisons with numpy types (see :trac:`13386` and :trac:`18076`):: - sage: import numpy - sage: numpy.int8('12') == 12 + sage: import numpy # optional - numpy + sage: numpy.int8('12') == 12 # optional - numpy True - sage: 12 == numpy.int8('12') + sage: 12 == numpy.int8('12') # optional - numpy True - sage: float('15') == 15 + sage: float('15') == 15 # optional - numpy True - sage: 15 == float('15') + sage: 15 == float('15') # optional - numpy True Test underscores as digit separators (PEP 515, https://www.python.org/dev/peps/pep-0515/):: - sage: Integer('1_3') + sage: Integer('1_3') # optional - numpy 13 - sage: Integer(b'1_3') + sage: Integer(b'1_3') # optional - numpy 13 """ # TODO: All the code below should somehow be in an external @@ -769,8 +769,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: n = -10 - sage: R = GF(17) # optional - sage.libs.pari - sage: n._im_gens_(R, [R(1)]) # optional - sage.libs.pari + sage: R = GF(17) # optional - sage.rings.finite_rings + sage: n._im_gens_(R, [R(1)]) # optional - sage.rings.finite_rings 7 """ return codomain.coerce(self) @@ -1007,9 +1007,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: ex = SR(ZZ(7)); ex + sage: ex = SR(ZZ(7)); ex # optional - sage.symbolic 7 - sage: parent(ex) + sage: parent(ex) # optional - sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -1020,9 +1020,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 5; n._sympy_() + sage: n = 5; n._sympy_() # optional - sympy 5 - sage: n = -5; n._sympy_() + sage: n = -5; n._sympy_() # optional - sympy -5 """ import sympy @@ -2008,7 +2008,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Traceback (most recent call last): ... ZeroDivisionError: rational division by zero - sage: 3 / QQbar.zero() # optional - sage.rings.number_field + sage: 3 / QQbar.zero() # optional - sage.rings.number_field Traceback (most recent call last): ... ZeroDivisionError: division by zero in algebraic field @@ -2113,7 +2113,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 1 sage: 2^-0 1 - sage: (-1)^(1/3) # optional - sage.symbolic + sage: (-1)^(1/3) # optional - sage.symbolic (-1)^(1/3) For consistency with Python and MPFR, 0^0 is defined to be 1 in @@ -2140,7 +2140,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We raise 2 to various interesting exponents:: - sage: 2^x # symbolic x # optional - sage.symbolic + sage: 2^x # symbolic x # optional - sage.symbolic 2^x sage: 2^1.5 # real number 2.82842712474619 @@ -2151,19 +2151,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: r = 2 ^ int(-3); r; type(r) 1/8 - sage: f = 2^(sin(x)-cos(x)); f # optional - sage.symbolic + sage: f = 2^(sin(x)-cos(x)); f # optional - sage.symbolic 2^(-cos(x) + sin(x)) sage: f(x=3) 2^(-cos(3) + sin(3)) A symbolic sum:: - sage: x, y, z = var('x,y,z') # optional - sage.symbolic - sage: 2^(x + y + z) # optional - sage.symbolic + sage: x, y, z = var('x,y,z') # optional - sage.symbolic + sage: 2^(x + y + z) # optional - sage.symbolic 2^(x + y + z) - sage: 2^(1/2) # optional - sage.symbolic + sage: 2^(1/2) # optional - sage.symbolic sqrt(2) - sage: 2^(-1/2) # optional - sage.symbolic + sage: 2^(-1/2) # optional - sage.symbolic 1/2*sqrt(2) TESTS:: @@ -2767,7 +2767,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: Integer(124).log(5) # optional - sage.symbolic + sage: Integer(124).log(5) # optional - sage.symbolic log(124)/log(5) sage: Integer(124).log(5, 100) 2.9950093311241087454822446806 @@ -2829,7 +2829,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: (-2).log(3) # optional - sage.symbolic + sage: (-2).log(3) # optional - sage.symbolic (I*pi + log(2))/log(3) """ cdef int self_sgn @@ -2886,11 +2886,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: Integer(8).exp() # optional - sage.symbolic + sage: Integer(8).exp() # optional - sage.symbolic e^8 - sage: Integer(8).exp(prec=100) # optional - sage.symbolic + sage: Integer(8).exp(prec=100) # optional - sage.symbolic 2980.9579870417282747435920995 - sage: exp(Integer(8)) # optional - sage.symbolic + sage: exp(Integer(8)) # optional - sage.symbolic e^8 For even fairly large numbers, this may not be useful. @@ -2898,9 +2898,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: sage: y = Integer(145^145) - sage: y.exp() # optional - sage.symbolic + sage: y.exp() # optional - sage.symbolic e^25024207011349079210459585279553675697932183658421565260323592409432707306554163224876110094014450895759296242775250476115682350821522931225499163750010280453185147546962559031653355159703678703793369785727108337766011928747055351280379806937944746847277089168867282654496776717056860661614337004721164703369140625 - sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic + sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic +infinity """ from sage.functions.all import exp @@ -2980,12 +2980,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Setting the optional ``limit`` argument works as expected:: sage: a = 10^100 + 1 - sage: a.prime_divisors() + sage: a.prime_divisors() # optional - sage.libs.pari [73, 137, 401, 1201, 1601, 1676321, 5964848081, 129694419029057750551385771184564274499075700947656757821537291527196801] - sage: a.prime_divisors(limit=10^3) + sage: a.prime_divisors(limit=10^3) # optional - sage.libs.pari [73, 137, 401] - sage: a.prime_divisors(limit=10^7) + sage: a.prime_divisors(limit=10^7) # optional - sage.libs.pari [73, 137, 401, 1201, 1601, 1676321] """ res = [r[0] for r in self.factor(*args, **kwds)] @@ -3027,32 +3027,32 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): [1, 2, 3, 4, 6, 8, 9, 12, 17, 18, 24, 34, 36, 51, 68, 72, 102, 136, 153, 204, 306, 408, 612, 1224] sage: a = odd_part(factorial(31)) - sage: v = a.divisors() - sage: len(v) + sage: v = a.divisors() # optional - sage.libs.pari + sage: len(v) # optional - sage.libs.pari 172800 - sage: prod(e + 1 for p, e in factor(a)) + sage: prod(e + 1 for p, e in factor(a)) # optional - sage.libs.pari 172800 - sage: all(t.divides(a) for t in v) + sage: all(t.divides(a) for t in v) # optional - sage.libs.pari True :: sage: n = 2^551 - 1 - sage: L = n.divisors() # optional - sage.libs.pari - sage: len(L) # optional - sage.libs.pari + sage: L = n.divisors() # optional - sage.libs.pari + sage: len(L) # optional - sage.libs.pari 256 - sage: L[-1] == n # optional - sage.libs.pari + sage: L[-1] == n # optional - sage.libs.pari True TESTS: Overflow:: - sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large - sage: prod(primes_first_n(58)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(58)).divisors() # optional - sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large # 32-bit @@ -3062,8 +3062,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): (the ``divisors`` call below allocates about 800 MB every time, so a memory leak will not go unnoticed):: - sage: n = prod(primes_first_n(25)) # optional - sage.libs.pari - sage: for i in range(20): # long time # optional - sage.libs.pari + sage: n = prod(primes_first_n(25)) # optional - sage.libs.pari + sage: for i in range(20): # long time # optional - sage.libs.pari ....: try: ....: alarm(RDF.random_element(1e-3, 0.5)) ....: _ = n.divisors() @@ -3345,9 +3345,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): This example caused trouble in :trac:`6083`:: - sage: a = next_prime(2**31) # optional - sage.libs.pari - sage: b = Integers(a)(100) # optional - sage.libs.pari - sage: a % b # optional - sage.libs.pari + sage: a = next_prime(2**31) # optional - sage.libs.pari + sage: b = Integers(a)(100) # optional - sage.libs.pari + sage: a % b # optional - sage.libs.pari Traceback (most recent call last): ... ArithmeticError: reduction modulo 100 not defined @@ -3443,10 +3443,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: divmod(1, sys.maxsize+1r) # should not raise OverflowError: Python int too large to convert to C long (0, 1) - sage: import mpmath - sage: mpmath.mp.prec = 1000 - sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) - sage: len(str(root)) + sage: import mpmath # optional - mpmath + sage: mpmath.mp.prec = 1000 # optional - mpmath + sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # optional - mpmath + sage: len(str(root)) # optional - mpmath 301 """ cdef Integer q = PY_NEW(Integer) @@ -3701,44 +3701,44 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() # optional - sage.libs.pari + sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() # optional - sage.libs.pari 1000003 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() # optional - sage.libs.pari 1000003 - sage: n.trial_division(bound=100) # optional - sage.libs.pari + sage: n.trial_division(bound=100) # optional - sage.libs.pari 10000049000057 - sage: n.trial_division(bound=-10) # optional - sage.libs.pari + sage: n.trial_division(bound=-10) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: bound must be positive - sage: n.trial_division(bound=0) # optional - sage.libs.pari + sage: n.trial_division(bound=0) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: bound must be positive - sage: ZZ(0).trial_division() # optional - sage.libs.pari + sage: ZZ(0).trial_division() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: self must be nonzero - sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 100003 - sage: n.trial_division(bound=10^4) # optional - sage.libs.pari + sage: n.trial_division(bound=10^4) # optional - sage.libs.pari 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari + sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() # optional - sage.libs.pari 100003 - sage: n = 2 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 2 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 2 - sage: n = 3 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 3 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 3 - sage: n = 5 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 5 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 5 - sage: n = 2 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 2 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 2 - sage: n = 3 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 3 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 3 - sage: n = 5 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 5 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 5 You can specify a starting point:: @@ -3862,7 +3862,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 2^100 - 1; n.factor() # optional - sage.libs.pari + sage: n = 2^100 - 1; n.factor() # optional - sage.libs.pari 3 * 5^3 * 11 * 31 * 41 * 101 * 251 * 601 * 1801 * 4051 * 8101 * 268501 This factorization can be converted into a list of pairs `(p, @@ -3889,9 +3889,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): that appear in the factorization:: sage: n = 920384092842390423848290348203948092384082349082 - sage: n.factor(proof=False) # optional - sage.libs.pari + sage: n.factor(proof=False) # optional - sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 - sage: n.factor(proof=True) # optional - sage.libs.pari + sage: n.factor(proof=True) # optional - sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 We factor using trial division only:: @@ -3901,10 +3901,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We factor using a quadratic sieve algorithm:: - sage: p = next_prime(10^20) # optional - sage.libs.pari - sage: q = next_prime(10^21) # optional - sage.libs.pari - sage: n = p * q # optional - sage.libs.pari - sage: n.factor(algorithm='qsieve') # optional - sage.libs.pari + sage: p = next_prime(10^20) # optional - sage.libs.pari + sage: q = next_prime(10^21) # optional - sage.libs.pari + sage: n = p * q # optional - sage.libs.pari + sage: n.factor(algorithm='qsieve') # optional - sage.libs.pari doctest:... RuntimeWarning: the factorization returned by qsieve may be incomplete (the factors may not be prime) or even wrong; see qsieve? for details @@ -3912,10 +3912,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We factor using the elliptic curve method:: - sage: p = next_prime(10^15) # optional - sage.libs.pari - sage: q = next_prime(10^21) # optional - sage.libs.pari - sage: n = p * q # optional - sage.libs.pari - sage: n.factor(algorithm='ecm') # optional - sage.libs.pari + sage: p = next_prime(10^15) # optional - sage.libs.pari + sage: q = next_prime(10^21) # optional - sage.libs.pari + sage: n = p * q # optional - sage.libs.pari + sage: n.factor(algorithm='ecm') # optional - sage.libs.pari 1000000000000037 * 1000000000000000000117 TESTS:: @@ -4603,13 +4603,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: gamma(5) + sage: gamma(5) # optional - sage.symbolic 24 - sage: gamma(0) + sage: gamma(0) # optional - sage.symbolic Infinity - sage: gamma(-1) + sage: gamma(-1) # optional - sage.symbolic Infinity - sage: gamma(-2^150) + sage: gamma(-2^150) # optional - sage.symbolic Infinity """ if mpz_sgn(self.value) > 0: @@ -4799,23 +4799,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 144.perfect_power() # optional - sage.libs.pari + sage: 144.perfect_power() # optional - sage.libs.pari (12, 2) - sage: 1.perfect_power() # optional - sage.libs.pari + sage: 1.perfect_power() # optional - sage.libs.pari (1, 1) - sage: 0.perfect_power() # optional - sage.libs.pari + sage: 0.perfect_power() # optional - sage.libs.pari (0, 1) - sage: (-1).perfect_power() # optional - sage.libs.pari + sage: (-1).perfect_power() # optional - sage.libs.pari (-1, 1) - sage: (-8).perfect_power() # optional - sage.libs.pari + sage: (-8).perfect_power() # optional - sage.libs.pari (-2, 3) - sage: (-4).perfect_power() # optional - sage.libs.pari + sage: (-4).perfect_power() # optional - sage.libs.pari (-4, 1) - sage: (101^29).perfect_power() # optional - sage.libs.pari + sage: (101^29).perfect_power() # optional - sage.libs.pari (101, 29) - sage: (-243).perfect_power() # optional - sage.libs.pari + sage: (-243).perfect_power() # optional - sage.libs.pari (-3, 5) - sage: (-64).perfect_power() # optional - sage.libs.pari + sage: (-64).perfect_power() # optional - sage.libs.pari (-4, 3) """ parians = self.__pari__().ispower() @@ -5102,55 +5102,55 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 17.is_prime_power() # optional - sage.libs.pari + sage: 17.is_prime_power() # optional - sage.libs.pari True - sage: 10.is_prime_power() # optional - sage.libs.pari + sage: 10.is_prime_power() # optional - sage.libs.pari False - sage: 64.is_prime_power() # optional - sage.libs.pari + sage: 64.is_prime_power() # optional - sage.libs.pari True - sage: (3^10000).is_prime_power() # optional - sage.libs.pari + sage: (3^10000).is_prime_power() # optional - sage.libs.pari True - sage: (10000).is_prime_power() # optional - sage.libs.pari + sage: (10000).is_prime_power() # optional - sage.libs.pari False - sage: (-3).is_prime_power() # optional - sage.libs.pari + sage: (-3).is_prime_power() # optional - sage.libs.pari False - sage: 0.is_prime_power() # optional - sage.libs.pari + sage: 0.is_prime_power() # optional - sage.libs.pari False - sage: 1.is_prime_power() # optional - sage.libs.pari + sage: 1.is_prime_power() # optional - sage.libs.pari False - sage: p = next_prime(10^20); p # optional - sage.libs.pari + sage: p = next_prime(10^20); p # optional - sage.libs.pari 100000000000000000039 - sage: p.is_prime_power() # optional - sage.libs.pari + sage: p.is_prime_power() # optional - sage.libs.pari True - sage: (p^97).is_prime_power() # optional - sage.libs.pari + sage: (p^97).is_prime_power() # optional - sage.libs.pari True - sage: (p+1).is_prime_power() # optional - sage.libs.pari + sage: (p + 1).is_prime_power() # optional - sage.libs.pari False With the ``get_data`` keyword set to ``True``:: - sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari (3, 100) - sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari + sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari (12, 0) - sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari (100000000000000000039, 97) - sage: q = p.next_prime(); q # optional - sage.libs.pari + sage: q = p.next_prime(); q # optional - sage.libs.pari 100000000000000000129 - sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari (10000000000000000016800000000000000005031, 0) The method works for large entries when `proof=False`:: sage: proof.arithmetic(False) - sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari + sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari True sage: proof.arithmetic(True) We check that :trac:`4777` is fixed:: sage: n = 150607571^14 - sage: n.is_prime_power() # optional - sage.libs.pari + sage: n.is_prime_power() # optional - sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5224,26 +5224,26 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari False sage: z = 7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari True sage: z = -7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari False - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True :: sage: z = 10^80 + 129 - sage: z.is_prime(proof=False) # optional - sage.libs.pari + sage: z.is_prime(proof=False) # optional - sage.libs.pari True - sage: z.is_prime(proof=True) # optional - sage.libs.pari + sage: z.is_prime(proof=True) # optional - sage.libs.pari True When starting Sage the arithmetic proof flag is True. We can change @@ -5252,12 +5252,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: proof.arithmetic() True sage: n = 10^100 + 267 - sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari + sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari 5 loops, best of 3: 163 ms per loop sage: proof.arithmetic(False) sage: proof.arithmetic() False - sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari + sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari 1000 loops, best of 3: 573 us per loop ALGORITHM: @@ -5274,7 +5274,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ....: if tab[i]: ....: for j in range(2*i, size, i): ....: tab[j] = 0 - sage: all(ZZ(i).is_prime() == b for i,b in enumerate(tab)) # optional - sage.libs.pari + sage: all(ZZ(i).is_prime() == b for i,b in enumerate(tab)) # optional - sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5337,16 +5337,16 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari False sage: z = 7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True sage: z = -7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True """ cdef Integer n = self if self >= 0 else -self @@ -5366,10 +5366,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # optional - sage.libs.pari False """ return self.__pari__().ispseudoprime() @@ -5390,17 +5390,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: x = 10^200 + 357 - sage: x.is_pseudoprime() # optional - sage.libs.pari + sage: x.is_pseudoprime() # optional - sage.libs.pari True - sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari True - sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari (1000...000357, 12) - sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari True - sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari False - sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari + sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari True TESTS:: @@ -5409,7 +5409,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): False sage: (-1).is_pseudoprime_power() False - sage: 1.is_pseudoprime_power() # optional - sage.libs.pari + sage: 1.is_pseudoprime_power() # optional - sage.libs.pari False """ return self.is_prime_power(proof=False, get_data=get_data) @@ -5476,20 +5476,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field sage: n = 4 - sage: n.is_norm(K) # optional - sage.rings.number_field + sage: n.is_norm(K) # optional - sage.rings.number_field True - sage: 5.is_norm(K) # optional - sage.rings.number_field + sage: 5.is_norm(K) # optional - sage.rings.number_field False sage: 7.is_norm(QQ) True - sage: n.is_norm(K, element=True) # optional - sage.rings.number_field + sage: n.is_norm(K, element=True) # optional - sage.rings.number_field (True, -4*beta + 6) - sage: n.is_norm(K, element=True)[1].norm() # optional - sage.rings.number_field + sage: n.is_norm(K, element=True)[1].norm() # optional - sage.rings.number_field 4 sage: n = 5 - sage: n.is_norm(K, element=True) # optional - sage.rings.number_field + sage: n.is_norm(K, element=True) # optional - sage.rings.number_field (False, None) sage: n = 7 sage: n.is_norm(QQ, element=True) @@ -5505,9 +5505,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field + sage: 3._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field (1, 3) - sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field + sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field (zeta7^5 - zeta7^2, 1) """ from sage.rings.rational_field import QQ @@ -5608,11 +5608,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-163).class_number() # optional - sage.libs.pari + sage: (-163).class_number() # optional - sage.libs.pari 1 - sage: (-104).class_number() # optional - sage.libs.pari + sage: (-104).class_number() # optional - sage.libs.pari 6 - sage: [((4*n+1),(4*n+1).class_number()) for n in [21..29]] # optional - sage.libs.pari + sage: [((4*n + 1), (4*n + 1).class_number()) for n in [21..29]] # optional - sage.libs.pari [(85, 2), (89, 1), (93, 1), @@ -5694,8 +5694,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 2 sage: a.squarefree_part(bound=2**14) 2 - sage: a = 7^3 * next_prime(2^100)^2 * next_prime(2^200) # optional - sage.libs.pari - sage: a / a.squarefree_part(bound=1000) # optional - sage.libs.pari + sage: a = 7^3 * next_prime(2^100)^2 * next_prime(2^200) # optional - sage.libs.pari + sage: a / a.squarefree_part(bound=1000) # optional - sage.libs.pari 49 """ cdef Integer z @@ -5742,17 +5742,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-37).next_probable_prime() # optional - sage.libs.pari + sage: (-37).next_probable_prime() # optional - sage.libs.pari 2 - sage: (100).next_probable_prime() # optional - sage.libs.pari + sage: (100).next_probable_prime() # optional - sage.libs.pari 101 - sage: (2^512).next_probable_prime() # optional - sage.libs.pari + sage: (2^512).next_probable_prime() # optional - sage.libs.pari 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171 - sage: 0.next_probable_prime() # optional - sage.libs.pari + sage: 0.next_probable_prime() # optional - sage.libs.pari 2 - sage: 126.next_probable_prime() # optional - sage.libs.pari + sage: 126.next_probable_prime() # optional - sage.libs.pari 127 - sage: 144168.next_probable_prime() # optional - sage.libs.pari + sage: 144168.next_probable_prime() # optional - sage.libs.pari 144169 """ return Integer( self.__pari__().nextprime(True) ) @@ -5771,23 +5771,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 100.next_prime() # optional - sage.libs.pari + sage: 100.next_prime() # optional - sage.libs.pari 101 - sage: (10^50).next_prime() # optional - sage.libs.pari + sage: (10^50).next_prime() # optional - sage.libs.pari 100000000000000000000000000000000000000000000000151 Use ``proof=False``, which is way faster since it does not need a primality proof:: - sage: b = (2^1024).next_prime(proof=False) # optional - sage.libs.pari - sage: b - 2^1024 # optional - sage.libs.pari + sage: b = (2^1024).next_prime(proof=False) # optional - sage.libs.pari + sage: b - 2^1024 # optional - sage.libs.pari 643 :: - sage: Integer(0).next_prime() # optional - sage.libs.pari + sage: Integer(0).next_prime() # optional - sage.libs.pari 2 - sage: Integer(1001).next_prime() # optional - sage.libs.pari + sage: Integer(1001).next_prime() # optional - sage.libs.pari 1009 """ # Use PARI to compute the next *pseudo*-prime @@ -5816,11 +5816,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 10.previous_prime() # optional - sage.libs.pari + sage: 10.previous_prime() # optional - sage.libs.pari 7 - sage: 7.previous_prime() # optional - sage.libs.pari + sage: 7.previous_prime() # optional - sage.libs.pari 5 - sage: 14376485.previous_prime() # optional - sage.libs.pari + sage: 14376485.previous_prime() # optional - sage.libs.pari 14376463 sage: 2.previous_prime() @@ -5831,8 +5831,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): An example using ``proof=False``, which is way faster since it does not need a primality proof:: - sage: b = (2^1024).previous_prime(proof=False) # optional - sage.libs.pari - sage: 2^1024 - b # optional - sage.libs.pari + sage: b = (2^1024).previous_prime(proof=False) # optional - sage.libs.pari + sage: 2^1024 - b # optional - sage.libs.pari 105 """ if mpz_cmp_ui(self.value, 2) <= 0: @@ -5872,23 +5872,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (-1).next_prime_power() 2 - sage: 2.next_prime_power() # optional - sage.libs.pari + sage: 2.next_prime_power() # optional - sage.libs.pari 3 - sage: 103.next_prime_power() # optional - sage.libs.pari + sage: 103.next_prime_power() # optional - sage.libs.pari 107 - sage: 107.next_prime_power() # optional - sage.libs.pari + sage: 107.next_prime_power() # optional - sage.libs.pari 109 - sage: 2044.next_prime_power() # optional - sage.libs.pari + sage: 2044.next_prime_power() # optional - sage.libs.pari 2048 TESTS:: - sage: [(2**k-1).next_prime_power() for k in range(1,10)] # optional - sage.libs.pari + sage: [(2**k - 1).next_prime_power() for k in range(1,10)] # optional - sage.libs.pari [2, 4, 8, 16, 32, 64, 128, 256, 512] - sage: [(2**k).next_prime_power() for k in range(10)] # optional - sage.libs.pari + sage: [(2**k).next_prime_power() for k in range(10)] # optional - sage.libs.pari [2, 3, 5, 9, 17, 37, 67, 131, 257, 521] - sage: for _ in range(10): # optional - sage.libs.pari + sage: for _ in range(10): # optional - sage.libs.pari ....: n = ZZ.random_element(2**256).next_prime_power() ....: m = n.next_prime_power().previous_prime_power() ....: assert m == n, "problem with n = {}".format(n) @@ -5936,13 +5936,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3.previous_prime_power() # optional - sage.libs.pari + sage: 3.previous_prime_power() # optional - sage.libs.pari 2 - sage: 103.previous_prime_power() # optional - sage.libs.pari + sage: 103.previous_prime_power() # optional - sage.libs.pari 101 - sage: 107.previous_prime_power() # optional - sage.libs.pari + sage: 107.previous_prime_power() # optional - sage.libs.pari 103 - sage: 2044.previous_prime_power() # optional - sage.libs.pari + sage: 2044.previous_prime_power() # optional - sage.libs.pari 2039 sage: 2.previous_prime_power() @@ -5952,12 +5952,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: [(2**k+1).previous_prime_power() for k in range(1,10)] # optional - sage.libs.pari + sage: [(2**k + 1).previous_prime_power() for k in range(1,10)] # optional - sage.libs.pari [2, 4, 8, 16, 32, 64, 128, 256, 512] - sage: [(2**k).previous_prime_power() for k in range(2, 10)] # optional - sage.libs.pari + sage: [(2**k).previous_prime_power() for k in range(2, 10)] # optional - sage.libs.pari [3, 7, 13, 31, 61, 127, 251, 509] - sage: for _ in range(10): # optional - sage.libs.pari + sage: for _ in range(10): # optional - sage.libs.pari ....: n = ZZ.random_element(3,2**256).previous_prime_power() ....: m = n.previous_prime_power().next_prime_power() ....: assert m == n, "problem with n = {}".format(n) @@ -6026,11 +6026,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 100.is_squarefree() # optional - sage.libs.pari + sage: 100.is_squarefree() # optional - sage.libs.pari False - sage: 102.is_squarefree() # optional - sage.libs.pari + sage: 102.is_squarefree() # optional - sage.libs.pari True - sage: 0.is_squarefree() # optional - sage.libs.pari + sage: 0.is_squarefree() # optional - sage.libs.pari False """ return self.__pari__().issquarefree() @@ -6109,16 +6109,16 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: n = 9390823 - sage: m = n.__pari__(); m # optional - sage.libs.pari + sage: m = n.__pari__(); m # optional - sage.libs.pari 9390823 - sage: type(m) # optional - sage.libs.pari + sage: type(m) # optional - sage.libs.pari TESTS:: sage: n = 10^10000000 - sage: m = n.__pari__() # crash from trac 875 # optional - sage.libs.pari - sage: m % 1234567 # optional - sage.libs.pari + sage: m = n.__pari__() # crash from trac 875 # optional - sage.libs.pari + sage: m % 1234567 # optional - sage.libs.pari 1041334 """ @@ -6148,19 +6148,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1, 2, 3]) + sage: import numpy # optional - numpy + sage: numpy.array([1, 2, 3]) # optional - numpy array([1, 2, 3]) - sage: numpy.array([1, 2, 3]).dtype + sage: numpy.array([1, 2, 3]).dtype # optional - numpy dtype('int32') # 32-bit dtype('int64') # 64-bit - sage: numpy.array(2**40).dtype + sage: numpy.array(2**40).dtype # optional - numpy dtype('int64') - sage: numpy.array(2**400).dtype + sage: numpy.array(2**400).dtype # optional - numpy dtype('O') - sage: numpy.array([1,2,3,0.1]).dtype + sage: numpy.array([1,2,3,0.1]).dtype # optional - numpy dtype('float64') """ if mpz_fits_slong_p(self.value): @@ -6323,13 +6323,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 12 sage: sqrt(Integer(144)) 12 - sage: Integer(102).sqrt() # optional - sage.symbolic + sage: Integer(102).sqrt() # optional - sage.symbolic sqrt(102) :: sage: n = 2 - sage: n.sqrt(all=True) # optional - sage.symbolic + sage: n.sqrt(all=True) # optional - sage.symbolic [sqrt(2), -sqrt(2)] sage: n.sqrt(prec=10) 1.4 @@ -6352,7 +6352,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: type(5.sqrt()) # optional - sage.symbolic + sage: type(5.sqrt()) # optional - sage.symbolic sage: type(5.sqrt(prec=53)) @@ -6978,7 +6978,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: 10.binomial(2) 45 - sage: 10.binomial(2, algorithm='pari') # optional - sage.libs.pari + sage: 10.binomial(2, algorithm='pari') # optional - sage.libs.pari 45 sage: 10.binomial(-2) 0 @@ -6991,7 +6991,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (2**256).binomial(2**256) 1 - sage: (2**256).binomial(2**256-1) + sage: (2**256).binomial(2**256 - 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936 sage: (2**256).binomial(2**128) Traceback (most recent call last): @@ -7020,7 +7020,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): check for reliable interrupting, see :trac:`18919`:: sage: from cysignals import AlarmInterrupt - sage: for i in [1..10]: # long time (5s) # optional - sage.libs.pari + sage: for i in [1..10]: # long time (5s) # optional - sage.libs.pari ....: try: ....: alarm(i/11) ....: (2^100).binomial(2^22, algorithm='pari') diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index f6d18bacda8..d94cd7c90cc 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -126,8 +126,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): False sage: Z.category() Join of Category of euclidean domains - and Category of infinite enumerated sets - and Category of metric spaces + and Category of infinite enumerated sets + and Category of metric spaces sage: Z(2^(2^5) + 1) 4294967297 @@ -151,9 +151,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): The lists are interpreted in little-endian order, so that entry ``i`` of the list is the coefficient of ``base^i``:: - sage: Z([4,1,7],base=100) + sage: Z([4,1,7], base=100) 70104 - sage: Z([4,1,7],base=10) + sage: Z([4,1,7], base=10) 714 sage: Z([3, 7], 10) 73 @@ -166,13 +166,13 @@ cdef class IntegerRing_class(PrincipalIdealDomain): ``z`` represent numbers 10 to 36. Letter case does not matter. :: - sage: Z("sage",base=32) + sage: Z("sage", base=32) 928270 - sage: Z("SAGE",base=32) + sage: Z("SAGE", base=32) 928270 - sage: Z("Sage",base=32) + sage: Z("Sage", base=32) 928270 - sage: Z([14, 16, 10, 28],base=32) + sage: Z([14, 16, 10, 28], base=32) 928270 sage: 14 + 16*32 + 10*32^2 + 28*32^3 928270 @@ -248,23 +248,23 @@ cdef class IntegerRing_class(PrincipalIdealDomain): 17 sage: Z(Mod(19,23)) 19 - sage: Z(2 + 3*5 + O(5^3)) + sage: Z(2 + 3*5 + O(5^3)) # optional - sage.rings.padics 17 Arbitrary numeric bases are supported; strings or list of integers are used to provide the digits (more details in :class:`IntegerRing_class`):: - sage: Z("sage",base=32) + sage: Z("sage", base=32) 928270 - sage: Z([14, 16, 10, 28],base=32) + sage: Z([14, 16, 10, 28], base=32) 928270 The :meth:`digits<~sage.rings.integer.Integer.digits>` method allows you to get the list of digits of an integer in a different basis (note that the digits are returned in little-endian order):: - sage: b = Z([4,1,7],base=100) + sage: b = Z([4,1,7], base=100) sage: b 70104 sage: b.digits(base=71) @@ -433,23 +433,25 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - sage: ZZ.range(-5,5) + sage: ZZ.range(-5, 5) [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4] - sage: ZZ.range(0,50,5) + sage: ZZ.range(0, 50, 5) [0, 5, 10, 15, 20, 25, 30, 35, 40, 45] - sage: ZZ.range(0,50,-5) + sage: ZZ.range(0, 50, -5) [] - sage: ZZ.range(50,0,-5) + sage: ZZ.range(50, 0, -5) [50, 45, 40, 35, 30, 25, 20, 15, 10, 5] - sage: ZZ.range(50,0,5) + sage: ZZ.range(50, 0, 5) [] - sage: ZZ.range(50,-1,-5) + sage: ZZ.range(50, -1, -5) [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0] It uses different code if the step doesn't fit in a long:: - sage: ZZ.range(0,2^83,2^80) - [0, 1208925819614629174706176, 2417851639229258349412352, 3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880, 7253554917687775048237056, 8462480737302404222943232] + sage: ZZ.range(0, 2^83, 2^80) + [0, 1208925819614629174706176, 2417851639229258349412352, + 3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880, + 7253554917687775048237056, 8462480737302404222943232] Make sure :trac:`8818` is fixed:: @@ -532,7 +534,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.coerce(int(5)) # indirect doctest 5 - sage: ZZ.coerce(GF(7)(2)) # optional - sage.libs.pari + sage: ZZ.coerce(GF(7)(2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field of size 7 to Integer Ring @@ -554,14 +556,14 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Coercions are available from numpy integer types:: - sage: import numpy - sage: ZZ.coerce(numpy.int8('1')) + sage: import numpy # optional - numpy + sage: ZZ.coerce(numpy.int8('1')) # optional - numpy 1 - sage: ZZ.coerce(numpy.int32('32')) + sage: ZZ.coerce(numpy.int32('32')) # optional - numpy 32 - sage: ZZ.coerce(numpy.int64('-12')) + sage: ZZ.coerce(numpy.int64('-12')) # optional - numpy -12 - sage: ZZ.coerce(numpy.uint64('11')) + sage: ZZ.coerce(numpy.uint64('11')) # optional - numpy 11 TESTS:: @@ -666,7 +668,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): ....: counter += 1 ....: dic[ZZ.random_element(*args, **kwds)] += 1 - sage: prob = lambda x : 1/5 + sage: def prob(x): + ....: return 1/5 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(distribution="uniform") @@ -690,7 +693,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: -10 <= ZZ.random_element(-10, 10) < 10 True - sage: prob = lambda x : 1/20 + sage: def prob(x): + ....: return 1/20 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(-10, 10) @@ -699,7 +703,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: 0 <= ZZ.random_element(5) < 5 True - sage: prob = lambda x : 1/5 + sage: def prob(x): + ....: return 1/5 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(5) @@ -831,7 +836,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): True sage: ZZ._is_valid_homomorphism_(ZZ,[2]) False - sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8),[ZZ.quotient_ring(8)(1)]) + sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8), [ZZ.quotient_ring(8)(1)]) True """ if base_map is None: @@ -920,11 +925,11 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field + sage: ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 - sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') # optional - sage.rings.number_field - Relative Order in Number Field in a with defining polynomial - x^2 + 1 over its base field + sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') # optional - sage.rings.number_field + Relative Order in Number Field in a + with defining polynomial x^2 + 1 over its base field """ from sage.rings.number_field.order import EquationOrder return EquationOrder(poly, names=names, **kwds) @@ -1275,41 +1280,41 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] sage: p *= (1 + x^3458645 - 76*x^3435423343 + x^45346567867756556) - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(1, 23), (-1, 23), (100, 1), (-5445, 5)] sage: p *= x^156468451540687043504386074354036574634735074 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(0, 156468451540687043504386074354036574634735074), (1, 23), (-1, 23), (100, 1), (-5445, 5)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari [0, 1, -1, 100, -5445] sage: R. = PolynomialRing(ZZ, sparse=False) sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari [100, -5445, 1, -1] - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") + sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: unknown algorithm 'foobar' sage: p = x^20 * p - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari [(0, 20), (100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari [(100, 1), (-5445, 5), (0, 20), (1, 23), (-1, 23)] """ deg = p.degree() @@ -1462,7 +1467,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: gap(ZZ) # indirect doctest + sage: gap(ZZ) # indirect doctest # optional - sage.libs.gap Integers """ return 'Integers' @@ -1495,7 +1500,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: macaulay2(ZZ) #optional - macaulay2 + sage: macaulay2(ZZ) # optional - macaulay2 ZZ """ return "ZZ" @@ -1518,7 +1523,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ._sympy_() + sage: ZZ._sympy_() # optional - sympy Integers """ from sympy import Integers diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index 56551b50a55..c7e1c65d26d 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -6,11 +6,11 @@ sage: R = LaurentSeriesRing(QQ, "x") sage: R.base_ring() Rational Field - sage: S = LaurentSeriesRing(GF(17)['x'], 'y') - sage: S - Laurent Series Ring in y over Univariate Polynomial Ring in x over - Finite Field of size 17 - sage: S.base_ring() + sage: S = LaurentSeriesRing(GF(17)['x'], 'y') # optional - sage.rings.finite_rings + sage: S # optional - sage.rings.finite_rings + Laurent Series Ring in y over + Univariate Polynomial Ring in x over Finite Field of size 17 + sage: S.base_ring() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 17 .. SEEALSO:: @@ -74,7 +74,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: R = LaurentSeriesRing(QQ, 'x'); R Laurent Series Ring in x over Rational Field sage: x = R.0 - sage: g = 1 - x + x^2 - x^4 +O(x^8); g + sage: g = 1 - x + x^2 - x^4 + O(x^8); g 1 - x + x^2 - x^4 + O(x^8) sage: g = 10*x^(-3) + 2006 - 19*x + x^2 - x^4 +O(x^8); g 10*x^-3 + 2006 - 19*x + x^2 - x^4 + O(x^8) @@ -84,7 +84,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: Frac(QQ[['x']]) Laurent Series Ring in x over Rational Field - sage: Frac(GF(5)['y']) + sage: Frac(GF(5)['y']) # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in y over Finite Field of size 5 When the base ring is a domain, the fraction field is the @@ -96,17 +96,17 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): Laurent series rings are determined by their variable and the base ring, and are globally unique:: - sage: K = Qp(5, prec = 5) - sage: L = Qp(5, prec = 200) - sage: R. = LaurentSeriesRing(K) - sage: S. = LaurentSeriesRing(L) - sage: R is S + sage: K = Qp(5, prec=5) # optional - sage.rings.padics + sage: L = Qp(5, prec=200) # optional - sage.rings.padics + sage: R. = LaurentSeriesRing(K) # optional - sage.rings.padics + sage: S. = LaurentSeriesRing(L) # optional - sage.rings.padics + sage: R is S # optional - sage.rings.padics False - sage: T. = LaurentSeriesRing(Qp(5,prec=200)) - sage: S is T + sage: T. = LaurentSeriesRing(Qp(5, prec=200)) # optional - sage.rings.padics + sage: S is T # optional - sage.rings.padics True - sage: W. = LaurentSeriesRing(Qp(5,prec=199)) - sage: W is T + sage: W. = LaurentSeriesRing(Qp(5, prec=199)) # optional - sage.rings.padics + sage: W is T # optional - sage.rings.padics False sage: K = LaurentSeriesRing(CC, 'q') @@ -122,11 +122,15 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): a field equipped with a discrete valuation for which it is complete. The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) - sage: R. = k[[]] - sage: F = Frac(R) - sage: F.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets + sage: k = GF(11) # optional - sage.rings.finite_rings + sage: R. = k[[]] # optional - sage.rings.finite_rings + sage: F = Frac(R) # optional - sage.rings.finite_rings + sage: F.category() # optional - sage.rings.finite_rings + Join of + Category of complete discrete valuation fields and + Category of commutative algebras over (finite enumerated fields and + subquotients of monoids and quotients of semigroups) and + Category of infinite sets sage: TestSuite(F).run() TESTS: @@ -147,11 +151,14 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): Check categories (:trac:`24420`):: sage: LaurentSeriesRing(ZZ, 'x').category() - Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces) + Category of infinite commutative no zero divisors algebras + over (euclidean domains and infinite enumerated sets and metric spaces) sage: LaurentSeriesRing(QQ, 'x').category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of complete discrete valuation fields and Category of commutative algebras + over (number fields and quotient fields and metric spaces) and Category of infinite sets sage: LaurentSeriesRing(Zmod(4), 'x').category() - Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of infinite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) Check coercions (:trac:`24431`):: @@ -215,27 +222,34 @@ def __init__(self, power_series): sage: RZZ = LaurentSeriesRing(ZZ, 't') sage: RZZ.category() - Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces) + Category of infinite commutative no zero divisors algebras + over (euclidean domains and infinite enumerated sets and metric spaces) sage: TestSuite(RZZ).run() sage: R1 = LaurentSeriesRing(Zmod(1), 't') sage: R1.category() - Category of finite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of finite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) sage: TestSuite(R1).run() sage: R2 = LaurentSeriesRing(Zmod(2), 't') sage: R2.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets + Join of Category of complete discrete valuation fields + and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) + and Category of infinite sets sage: TestSuite(R2).run() sage: R4 = LaurentSeriesRing(Zmod(4), 't') sage: R4.category() - Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of infinite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) sage: TestSuite(R4).run() sage: RQQ = LaurentSeriesRing(QQ, 't') sage: RQQ.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of complete discrete valuation fields + and Category of commutative algebras over (number fields and quotient fields and metric spaces) + and Category of infinite sets sage: TestSuite(RQQ).run() """ base_ring = power_series.base_ring() @@ -361,9 +375,9 @@ def _repr_(self): """ EXAMPLES:: - sage: LaurentSeriesRing(QQ,'q') # indirect doctest + sage: LaurentSeriesRing(QQ, 'q') # indirect doctest Laurent Series Ring in q over Rational Field - sage: LaurentSeriesRing(ZZ,'t',sparse=True) + sage: LaurentSeriesRing(ZZ, 't', sparse=True) Sparse Laurent Series Ring in t over Integer Ring """ s = "Laurent Series Ring in %s over %s" % (self.variable_name(), self.base_ring()) @@ -386,35 +400,35 @@ def _element_constructor_(self, x, n=0, prec=infinity): EXAMPLES:: - sage: R. = LaurentSeriesRing(Qp(5, 10)) - sage: S. = LaurentSeriesRing(RationalField()) - sage: R(t + t^2 + O(t^3)) + sage: R. = LaurentSeriesRing(Qp(5, 10)) # optional - sage.rings.padics + sage: S. = LaurentSeriesRing(RationalField()) # optional - sage.rings.padics + sage: R(t + t^2 + O(t^3)) # optional - sage.rings.padics (1 + O(5^10))*u + (1 + O(5^10))*u^2 + O(u^3) - sage: R(t + t^2 + O(t^3), prec=2) + sage: R(t + t^2 + O(t^3), prec=2) # optional - sage.rings.padics (1 + O(5^10))*u + O(u^2) Coercing an element into its own parent produces that element again, unless a different ``n`` or ``prec`` is given:: - sage: u is R(u) + sage: u is R(u) # optional - sage.rings.padics True - sage: R(u, n=3, prec=7) + sage: R(u, n=3, prec=7) # optional - sage.rings.padics (1 + O(5^10))*u^4 + O(u^7) Rational functions are accepted:: - sage: I = sqrt(-1) - sage: K. = QQ[I] - sage: P. = PolynomialRing(K) - sage: L. = LaurentSeriesRing(QQ[I]) - sage: L((t*I)/(t^3+I*2*t)) + sage: I = sqrt(-1) # optional - sage.rings.number_field + sage: K. = QQ[I] # optional - sage.rings.number_field + sage: P. = PolynomialRing(K) # optional - sage.rings.number_field + sage: L. = LaurentSeriesRing(QQ[I]) # optional - sage.rings.number_field + sage: L((t*I)/(t^3+I*2*t)) # optional - sage.rings.number_field 1/2 + 1/4*I*u^2 - 1/8*u^4 - 1/16*I*u^6 + 1/32*u^8 + 1/64*I*u^10 - 1/128*u^12 - 1/256*I*u^14 + 1/512*u^16 + 1/1024*I*u^18 + O(u^20) :: - sage: L(t*I) / L(t^3+I*2*t) + sage: L(t*I) / L(t^3+I*2*t) # optional - sage.rings.number_field 1/2 + 1/4*I*u^2 - 1/8*u^4 - 1/16*I*u^6 + 1/32*u^8 + 1/64*I*u^10 - 1/128*u^12 - 1/256*I*u^14 + 1/512*u^16 + 1/1024*I*u^18 + O(u^20) @@ -440,23 +454,23 @@ def _element_constructor_(self, x, n=0, prec=infinity): Various conversions from PARI (see also :trac:`2508`):: sage: L. = LaurentSeriesRing(QQ, default_prec=10) - sage: L(pari('1/x')) + sage: L(pari('1/x')) # optional - sage.libs.pari q^-1 - sage: L(pari('polchebyshev(5)')) + sage: L(pari('polchebyshev(5)')) # optional - sage.libs.pari 5*q - 20*q^3 + 16*q^5 - sage: L(pari('polchebyshev(5) - 1/x^4')) + sage: L(pari('polchebyshev(5) - 1/x^4')) # optional - sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 - sage: L(pari('1/polchebyshev(5)')) + sage: L(pari('1/polchebyshev(5)')) # optional - sage.libs.pari 1/5*q^-1 + 4/5*q + 64/25*q^3 + 192/25*q^5 + 2816/125*q^7 + O(q^9) - sage: L(pari('polchebyshev(5) + O(x^40)')) + sage: L(pari('polchebyshev(5) + O(x^40)')) # optional - sage.libs.pari 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) + sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) # optional - sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('1/polchebyshev(5) + O(x^10)')) + sage: L(pari('1/polchebyshev(5) + O(x^10)')) # optional - sage.libs.pari 1/5*q^-1 + 4/5*q + 64/25*q^3 + 192/25*q^5 + 2816/125*q^7 + 8192/125*q^9 + O(q^10) - sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 + sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 # optional - sage.libs.pari 1/5*q^-11 + 4/5*q^-9 + 64/25*q^-7 + 192/25*q^-5 + 2816/125*q^-3 + 8192/125*q^-1 + O(1) - sage: L(pari('O(x^-10)')) + sage: L(pari('O(x^-10)')) # optional - sage.libs.pari O(q^-10) Check that :trac:`30073` is fixed:: @@ -522,8 +536,8 @@ def random_element(self, algorithm='default'): EXAMPLES:: - sage: S. = LaurentSeriesRing(GF(3)) - sage: S.random_element() # random + sage: S. = LaurentSeriesRing(GF(3)) # optional - sage.rings.finite_rings + sage: S.random_element() # random # optional - sage.rings.finite_rings s^-8 + s^-7 + s^-6 + s^-5 + s^-1 + s + s^3 + s^4 + s^5 + 2*s^6 + s^7 + s^11 + O(s^12) """ @@ -637,14 +651,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: S. = LaurentSeriesRing(GF(19)) - sage: R.hom([y], S) # indirect doctest + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: S. = LaurentSeriesRing(GF(19)) # optional - sage.rings.finite_rings + sage: R.hom([y], S) # indirect doctest # optional - sage.rings.finite_rings Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators - sage: f = R.hom(x+x^3,R) - sage: f(x^2) + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators + sage: f = R.hom(x + x^3,R) # optional - sage.rings.finite_rings + sage: f(x^2) # optional - sage.rings.finite_rings x^2 + 2*x^4 + x^6 The image of the generator needs to be a unit:: @@ -671,8 +686,8 @@ def characteristic(self): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: R.characteristic() + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.characteristic() # optional - sage.rings.finite_rings 17 """ return self.base_ring().characteristic() @@ -686,8 +701,8 @@ def residue_field(self): EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: R.residue_field() + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.residue_field() # optional - sage.rings.finite_rings Finite Field of size 17 sage: R. = LaurentSeriesRing(ZZ) diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index b11989eafbe..af04fe4e7e6 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -3,16 +3,16 @@ Laurent Series EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(7), 't'); R + sage: R. = LaurentSeriesRing(GF(7), 't'); R # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 - sage: f = 1/(1-t+O(t^10)); f + sage: f = 1/(1-t+O(t^10)); f # optional - sage.rings.finite_rings 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) Laurent series are immutable:: - sage: f[2] + sage: f[2] # optional - sage.rings.finite_rings 1 - sage: f[2] = 5 + sage: f[2] = 5 # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: Laurent series are immutable @@ -112,18 +112,18 @@ cdef class LaurentSeries(AlgebraElement): sage: R. = LaurentSeriesRing(ZZ) sage: R([1,2,3]) 1 + 2*q + 3*q^2 - sage: R([1,2,3],-5) + sage: R([1,2,3], -5) q^-5 + 2*q^-4 + 3*q^-3 :: - sage: S. = LaurentSeriesRing(GF(5)) - sage: T. = PowerSeriesRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentSeriesRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PowerSeriesRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Laurent Series Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 """ AlgebraElement.__init__(self, parent) @@ -185,7 +185,7 @@ cdef class LaurentSeries(AlgebraElement): sage: R. = LaurentSeriesRing(ZZ) sage: p = R([1,2,3]); p 1 + 2*q + 3*q^2 - sage: p.change_ring(GF(2)) + sage: p.change_ring(GF(2)) # optional - sage.rings.finite_rings 1 + q^2 """ return self._parent.change_ring(R)(self) @@ -197,9 +197,9 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: R. = LaurentSeriesRing(QQ) - sage: (2+t).is_unit() + sage: (2 + t).is_unit() True - sage: f = 2+t^2+O(t^10); f.is_unit() + sage: f = 2 + t^2 + O(t^10); f.is_unit() True sage: 1/f 1/2 - 1/4*t^2 + 1/8*t^4 - 1/16*t^6 + 1/32*t^8 + O(t^10) @@ -288,16 +288,16 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: R. = LaurentSeriesRing(K) - sage: z = t^-1 + i*t - sage: z._im_gens_(R, [t^2]) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: R. = LaurentSeriesRing(K) # optional - sage.rings.number_field + sage: z = t^-1 + i*t # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2]) # optional - sage.rings.number_field t^-2 + i*t^2 The argument base_map is not yet supported, because it isn't over power series:: - sage: cc = K.hom([i]) - sage: z._im_gens_(R, [t^2], base_map=cc) + sage: cc = K.hom([i]) # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError @@ -442,9 +442,9 @@ cdef class LaurentSeries(AlgebraElement): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentSeriesRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentSeriesRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -616,10 +616,10 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: t = LaurentSeriesRing(ZZ,'t').gen() - sage: f = 1/t**2+2/t+3+4*t + sage: f = 1/t**2 + 2/t + 3 + 4*t sage: f.residue() 2 - sage: f = t+t**2 + sage: f = t + t**2 sage: f.residue() 0 sage: f.residue().parent() @@ -671,11 +671,11 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: - sage: A. = LaurentSeriesRing(GF(5)) - sage: x = t^(-1) + t^2 + O(t^5) - sage: x.lift_to_precision(10) + sage: A. = LaurentSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: x = t^(-1) + t^2 + O(t^5) # optional - sage.rings.finite_rings + sage: x.lift_to_precision(10) # optional - sage.rings.finite_rings t^-1 + t^2 + O(t^10) - sage: x.lift_to_precision() + sage: x.lift_to_precision() # optional - sage.rings.finite_rings t^-1 + t^2 """ if absprec is not None and absprec <= self.precision_absolute(): @@ -1028,7 +1028,8 @@ cdef class LaurentSeries(AlgebraElement): sage: A. = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f - 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) + 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 """ @@ -1046,7 +1047,8 @@ cdef class LaurentSeries(AlgebraElement): sage: A. = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f - 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) + 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate_laurentseries(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10) """ @@ -1489,8 +1491,11 @@ cdef class LaurentSeries(AlgebraElement): ring:: sage: R. = LaurentSeriesRing(QQ, default_prec=20) - sage: (x - x^2).reverse() # get some Catalan numbers - x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + 477638700*x^19 + O(x^20) + sage: (x - x^2).reverse() # get some Catalan numbers + x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + + 477638700*x^19 + O(x^20) sage: (x - x^2).reverse(precision=3) x + x^2 + O(x^3) @@ -1743,10 +1748,10 @@ cdef class LaurentSeries(AlgebraElement): Check whether a polynomial over a Laurent series ring is contained in the polynomial ring over the power series ring (see :trac:`19459`): - sage: L. = LaurentSeriesRing(GF(2)) - sage: R. = PolynomialRing(L) - sage: S. = PolynomialRing(L._power_series_ring) - sage: t**(-1)*x*y in S + sage: L. = LaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(L) # optional - sage.rings.finite_rings + sage: S. = PolynomialRing(L._power_series_ring) # optional - sage.rings.finite_rings + sage: t**(-1)*x*y in S # optional - sage.rings.finite_rings False There used to be an issue with non-canonical representations of zero, @@ -1766,8 +1771,8 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`32440`:: - sage: L. = LaurentSeriesRing(QQ, implementation='pari') - sage: (x + O(x^3)).power_series() + sage: L. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: (x + O(x^3)).power_series() # optional - sage.libs.pari x + O(x^3) """ if self.__n < 0: @@ -1808,13 +1813,13 @@ cdef class LaurentSeries(AlgebraElement): x*t^-2 + O(t^2) sage: f(y=x) x*t^-2 + x*t^2 + O(t^8) - sage: f(t^3, x=2, y=x+x^2) + sage: f(t^3, x=2, y=x + x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) sage: f(t^3, 2, x+x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) - sage: f(x=2, t=t^3, y=x+x^2) + sage: f(x=2, t=t^3, y=x + x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) - sage: f(2, x+x^2, t=t^3) + sage: f(2, x + x^2, t=t^3) Traceback (most recent call last): ... ValueError: must not specify t keyword and positional argument @@ -1828,9 +1833,9 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`23928`:: - sage: R. = LaurentSeriesRing(QQ, implementation='pari') - sage: f = x.add_bigoh(7) - sage: f(x) + sage: R. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = x.add_bigoh(7) # optional - sage.libs.pari + sage: f(x) # optional - sage.libs.pari x + O(x^7) """ if len(kwds) >= 1: @@ -1870,16 +1875,16 @@ cdef class LaurentSeries(AlgebraElement): sage: L. = LaurentSeriesRing(QQ) sage: f = x + 1/x + O(x^2); f x^-1 + x + O(x^2) - sage: f.__pari__() + sage: f.__pari__() # optional - sage.libs.pari x^-1 + x + O(x^2) Check that :trac:`32437` is fixed:: - sage: F. = GF(257^2) - sage: R. = LaurentSeriesRing(F) - sage: g = t + O(t^99) - sage: f = u*t + O(t^99) - sage: g(f) # indirect doctest + sage: F. = GF(257^2) # optional - sage.rings.finite_rings + sage: R. = LaurentSeriesRing(F) # optional - sage.rings.finite_rings + sage: g = t + O(t^99) # optional - sage.rings.finite_rings + sage: f = u*t + O(t^99) # optional - sage.rings.finite_rings + sage: g(f) # indirect doctest # optional - sage.libs.pari sage.rings.finite_rings u*t + O(t^99) """ f = self.__u diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 6f4a602084b..da22e04903a 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -10,18 +10,18 @@ EXAMPLES:: sage: LZ = Localization(ZZ, (5,11)) - sage: m = matrix(LZ, [[5, 7], [0,11]]) # optional - sage.modules - sage: m.parent() # optional - sage.modules + sage: m = matrix(LZ, [[5, 7], [0,11]]) # optional - sage.modules + sage: m.parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring localized at (5, 11) - sage: ~m # parent of inverse is different: see documentation of m.__invert__ # optional - sage.modules + sage: ~m # parent of inverse is different: see documentation of m.__invert__ # optional - sage.modules [ 1/5 -7/55] [ 0 1/11] - sage: _.parent() # optional - sage.modules + sage: _.parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: mi = matrix(LZ, ~m) # optional - sage.modules - sage: mi.parent() # optional - sage.modules + sage: mi = matrix(LZ, ~m) # optional - sage.modules + sage: mi.parent() # optional - sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring localized at (5, 11) - sage: mi == ~m # optional - sage.modules + sage: mi == ~m # optional - sage.modules True The next example defines the most general ring containing the coefficients of the irreducible @@ -34,123 +34,123 @@ sage: I = S.cartesian_product(S) sage: add_units = u + [q, q + 1] + [ui - uj for ui, uj in I if ui != uj] sage: add_units += [q*ui - uj for ui, uj in I if ui != uj] - sage: L = R.localization(tuple(add_units)); L + sage: L = R.localization(tuple(add_units)); L # optional - sage.libs.pari Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, + u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) Define the representation matrices (of one of the three dimensional irreducible representations):: - sage: m1 = matrix(L, [[u1, 0, 0], [0, u0, 0], [0, 0, u0]]) # optional - sage.modules - sage: m2 = matrix(L, [[(u0*q - u0)/(u0 - u1), (u0*q - u1)/(u0 - u1), 0], # optional - sage.modules + sage: m1 = matrix(L, [[u1, 0, 0], [0, u0, 0], [0, 0, u0]]) # optional - sage.modules + sage: m2 = matrix(L, [[(u0*q - u0)/(u0 - u1), (u0*q - u1)/(u0 - u1), 0], # optional - sage.modules ....: [(-u1*q + u0)/(u0 - u1), (-u1*q + u1)/(u0 - u1), 0], ....: [0, 0, -1]]) - sage: m3 = matrix(L, [[-1, 0, 0], # optional - sage.modules + sage: m3 = matrix(L, [[-1, 0, 0], # optional - sage.modules ....: [0, u0*(1 - q)/(u1*q - u0), q*(u1 - u0)/(u1*q - u0)], ....: [0, (u1*q^2 - u0)/(u1*q - u0), (u1*q^ 2 - u1*q)/(u1*q - u0)]]) - sage: m1.base_ring() == L # optional - sage.modules + sage: m1.base_ring() == L # optional - sage.modules True Check relations of the Ariki-Koike algebra:: - sage: m1*m2*m1*m2 == m2*m1*m2*m1 # optional - sage.modules + sage: m1*m2*m1*m2 == m2*m1*m2*m1 # optional - sage.modules True - sage: m2*m3*m2 == m3*m2*m3 # optional - sage.modules + sage: m2*m3*m2 == m3*m2*m3 # optional - sage.modules True - sage: m1*m3 == m3*m1 # optional - sage.modules + sage: m1*m3 == m3*m1 # optional - sage.modules True - sage: m1**3 -(u0+u1+u2)*m1**2 +(u0*u1+u0*u2+u1*u2)*m1 - u0*u1*u2 == 0 # optional - sage.modules + sage: m1**3 - (u0+u1+u2)*m1**2 + (u0*u1+u0*u2+u1*u2)*m1 - u0*u1*u2 == 0 # optional - sage.modules True - sage: m2**2 -(q-1)*m2 - q == 0 # optional - sage.modules + sage: m2**2 - (q-1)*m2 - q == 0 # optional - sage.modules True - sage: m3**2 -(q-1)*m3 - q == 0 # optional - sage.modules + sage: m3**2 - (q-1)*m3 - q == 0 # optional - sage.modules True - sage: ~m1 in m1.parent() # optional - sage.modules + sage: ~m1 in m1.parent() # optional - sage.modules True - sage: ~m2 in m2.parent() # optional - sage.modules + sage: ~m2 in m2.parent() # optional - sage.modules True - sage: ~m3 in m3.parent() # optional - sage.modules + sage: ~m3 in m3.parent() # optional - sage.modules True Obtain specializations in positive characteristic:: - sage: Fp = GF(17) # optional - sage.libs.pari - sage: f = L.hom((3,5,7,11), codomain=Fp); f # optional - sage.libs.pari sage.rings.padics + sage: Fp = GF(17) # optional - sage.rings.finite_rings + sage: f = L.hom((3,5,7,11), codomain=Fp); f # optional - sage.rings.finite_rings Ring morphism: From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, + u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) To: Finite Field of size 17 Defn: u0 |--> 3 u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mFp1 = matrix({k:f(v) for k, v in m1.dict().items()}); mFp1 # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 # optional - sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mFp1.base_ring() # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mFp1.base_ring() # optional - sage.modules sage.rings.finite_rings Finite Field of size 17 - sage: mFp2 = matrix({k:f(v) for k, v in m2.dict().items()}); mFp2 # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 # optional - sage.modules sage.rings.finite_rings [ 2 3 0] [ 9 8 0] [ 0 0 16] - sage: mFp3 = matrix({k:f(v) for k, v in m3.dict().items()}); mFp3 # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mFp3 = matrix({k: f(v) for k, v in m3.dict().items()}); mFp3 # optional - sage.modules sage.rings.finite_rings [16 0 0] [ 0 4 5] [ 0 7 6] Obtain specializations in characteristic 0:: - sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ # optional - sage.libs.pari sage.rings.padics + sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ # optional - sage.rings.finite_rings Ring morphism: - From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring + localized at (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, + u2*q - u1, u2*q - u0, u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) To: Rational Field Defn: u0 |--> 3 u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mQ1 = matrix({k:fQ(v) for k, v in m1.dict().items()}); mQ1 # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 # optional - sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mQ1.base_ring() # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mQ1.base_ring() # optional - sage.modules sage.rings.finite_rings Rational Field - sage: mQ2 = matrix({k:fQ(v) for k, v in m2.dict().items()}); mQ2 # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 # optional - sage.modules sage.rings.finite_rings [-15 -14 0] [ 26 25 0] [ 0 0 -1] - sage: mQ3 = matrix({k:fQ(v) for k, v in m3.dict().items()}); mQ3 # optional - sage.libs.pari sage.modules sage.rings.padics + sage: mQ3 = matrix({k: fQ(v) for k, v in m3.dict().items()}); mQ3 # optional - sage.modules sage.rings.finite_rings [ -1 0 0] [ 0 -15/26 11/26] [ 0 301/26 275/26] sage: S. = QQ[] - sage: T = S.quo(x+y+z) - sage: F = T.fraction_field() - sage: fF = L.hom((x, y, z, t), codomain=F); fF + sage: T = S.quo(x + y + z) + sage: F = T.fraction_field() # optional - sage.libs.singular + sage: fF = L.hom((x, y, z, t), codomain=F); fF # optional - sage.libs.singular Ring morphism: - From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) - To: Fraction Field of Quotient of Multivariate Polynomial Ring in x, y, z, t over - Rational Field by the ideal (x + y + z) + From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring + localized at (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, + u2*q - u1, u2*q - u0, u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + To: Fraction Field of Quotient of Multivariate Polynomial Ring in x, y, z, t + over Rational Field by the ideal (x + y + z) Defn: u0 |--> -ybar - zbar u1 |--> ybar u2 |--> zbar q |--> tbar - sage: mF1 = matrix({k:fF(v) for k, v in m1.dict().items()}); mF1 # optional - sage.modules + sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # optional - sage.libs.singular sage.modules [ ybar 0 0] [ 0 -ybar - zbar 0] [ 0 0 -ybar - zbar] - sage: mF1.base_ring() == F # optional - sage.modules + sage: mF1.base_ring() == F # optional - sage.libs.singular sage.modules True TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.singular sage.modules AUTHORS: @@ -206,9 +206,9 @@ def normalize_extra_units(base_ring, add_units, warning=True): [z, y, x] sage: R. = ZZ[] - sage: Q. = R.quo(x**2-5) - sage: p = b**2-5 - sage: p == (b-a)*(b+a) + sage: Q. = R.quo(x**2 - 5) # optional - sage.libs.singular + sage: p = b**2 - 5 # optional - sage.libs.singular + sage: p == (b-a)*(b+a) # optional - sage.libs.singular True sage: normalize_extra_units(Q, [p]) # optional - sage.libs.pari doctest:...: UserWarning: Localization may not be represented uniquely @@ -389,10 +389,10 @@ def factor(self, proof=None): EXAMPLES:: sage: P. = QQ['x, y'] - sage: L = P.localization(X-Y) + sage: L = P.localization(X - Y) sage: x, y = L.gens() - sage: p = (x^2 - y^2)/(x-y)^2 - sage: p.factor() + sage: p = (x^2 - y^2)/(x-y)^2 # optional - sage.libs.singular + sage: p.factor() # optional - sage.libs.singular (1/(x - y)) * (x + y) """ num = self._value.numerator() @@ -411,9 +411,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+1) - sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest - sage: f(x/(x**2+1)) + sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari + sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # optional - sage.libs.pari + sage: f(x/(x**2+1)) # optional - sage.libs.pari 5/26 """ return self._value._im_gens_(codomain, im_gens, base_map=base_map) @@ -449,12 +449,12 @@ def is_unit(self): EXAMPLES:: sage: P. = QQ[] - sage: L = P.localization((x, y*z)) - sage: L(y*z).is_unit() + sage: L = P.localization((x, y*z)) # optional - sage.libs.pari + sage: L(y*z).is_unit() # optional - sage.libs.pari True - sage: L(z).is_unit() + sage: L(z).is_unit() # optional - sage.libs.pari True - sage: L(x*y*z).is_unit() + sage: L(x*y*z).is_unit() # optional - sage.libs.pari True """ return self.parent()._cut_off_extra_units_from_base_ring_element(self._value.numerator()).is_unit() @@ -467,9 +467,9 @@ def inverse_of_unit(self): sage: P. = ZZ[] sage: L = Localization(P, x*y*z) - sage: L(x*y*z).inverse_of_unit() + sage: L(x*y*z).inverse_of_unit() # optional - sage.libs.singular 1/(x*y*z) - sage: L(z).inverse_of_unit() + sage: L(z).inverse_of_unit() # optional - sage.libs.singular 1/z """ parent = self.parent() @@ -481,11 +481,11 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: P. = GF(7)[] # optional - sage.libs.pari - sage: L = Localization(P, (x, y, z)) # optional - sage.libs.pari - sage: L(1/x) < L(3/(x*y*z)**3) # optional - sage.libs.pari + sage: P. = GF(7)[] # optional - sage.rings.finite_rings + sage: L = Localization(P, (x, y, z)) # optional - sage.rings.finite_rings + sage: L(1/x) < L(3/(x*y*z)**3) # optional - sage.rings.finite_rings False - sage: ~L(y*z/x) == L(x/(y*z)) # optional - sage.libs.pari + sage: ~L(y*z/x) == L(x/(y*z)) # optional - sage.rings.finite_rings True """ sval = self._value @@ -518,8 +518,8 @@ def _rational_(self): TESTS:: sage: L = ZZ.localization(5) - sage: cp3 = cyclotomic_polynomial(3).change_ring(L) - sage: cp3.splitting_field('t') # indirect doctest + sage: cp3 = cyclotomic_polynomial(3).change_ring(L) # optional - sage.libs.pari + sage: cp3.splitting_field('t') # indirect doctest # optional - sage.libs.pari sage.rings.number_field Number Field in t with defining polynomial x^2 + x + 1 """ from sage.rings.rational_field import QQ @@ -604,37 +604,38 @@ class Localization(IntegralDomain, UniqueRepresentation): sage: Localization(Zp(7), (3, 5)) # optional - sage.rings.padics Traceback (most recent call last): ... - ValueError: all given elements are invertible in 7-adic Ring with capped relative precision 20 + ValueError: all given elements are invertible in + 7-adic Ring with capped relative precision 20 sage: R. = ZZ[] - sage: L = R.localization(x**2+1) + sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari sage: s = (x+5)/(x**2+1) - sage: s in L + sage: s in L # optional - sage.libs.pari True sage: t = (x+5)/(x**2+2) - sage: t in L + sage: t in L # optional - sage.libs.pari False - sage: L(t) + sage: L(t) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: fraction must have unit denominator - sage: L(s) in R + sage: L(s) in R # optional - sage.libs.pari False - sage: y = L(x) - sage: g = L(s) - sage: g.parent() + sage: y = L(x) # optional - sage.libs.pari + sage: g = L(s) # optional - sage.libs.pari + sage: g.parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) - sage: f = (y+5)/(y**2+1); f + sage: f = (y+5)/(y**2+1); f # optional - sage.libs.pari (x + 5)/(x^2 + 1) - sage: f == g + sage: f == g # optional - sage.libs.pari True - sage: (y+5)/(y**2+2) + sage: (y+5)/(y**2+2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: factor x^2 + 2 of denominator is not a unit sage: Lau. = LaurentPolynomialRing(ZZ) - sage: LauL = Lau.localization(u+1) + sage: LauL = Lau.localization(u + 1) sage: LauL(~u).parent() Multivariate Polynomial Ring in u, v over Integer Ring localized at (v, u, u + 1) @@ -657,12 +658,12 @@ def __init__(self, base_ring, extra_units, names=None, normalize=True, category= TESTS:: - sage: L = Localization(ZZ, (3,5)) + sage: L = Localization(ZZ, (3, 5)) sage: TestSuite(L).run() sage: R. = ZZ[] - sage: L = R.localization(x**2+1) - sage: TestSuite(L).run() + sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari + sage: TestSuite(L).run() # optional - sage.libs.pari """ if type(extra_units) is tuple: extra_units = list(extra_units) @@ -702,9 +703,10 @@ def _repr_(self): EXAMPLES:: - sage: R. = GF(3)[] - sage: Localization(R, a**2-1) - Univariate Polynomial Ring in a over Finite Field of size 3 localized at (a + 1, a + 2) + sage: R. = GF(3)[] # optional - sage.libs.pari + sage: Localization(R, a**2 - 1) # optional - sage.libs.pari + Univariate Polynomial Ring in a over Finite Field of size 3 + localized at (a + 1, a + 2) """ return "%s localized at %s" % (self.base(), self._extra_units) @@ -733,37 +735,38 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+1) - sage: L.hom([5]) # indirect doctest + sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari + sage: L.hom([5]) # indirect doctest # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: images of some localized elements fail to be units - sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest + sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # optional - sage.libs.pari Ring morphism: - From: Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) + From: Univariate Polynomial Ring in x over Integer Ring + localized at (x^2 + 1,) To: Integer Ring localized at (2, 13) Defn: x |--> 5 TESTS:: - sage: phi=R.hom([5]) - sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) + sage: phi = R.hom([5]) + sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: given base_map is not compatible with im_gens - sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: images of some localized elements fail to be units - sage: phi=R.hom([5], codomain=QQ) - sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) + sage: phi = R.hom([5], codomain=QQ) + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: codomain of base_map must be Integer Ring - sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) + sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) # optional - sage.libs.pari True """ B = self.base_ring() @@ -795,7 +798,7 @@ def ngens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2+1, y-1)).ngens() + sage: Localization(R, (x**2 + 1, y - 1)).ngens() # optional - sage.libs.pari 2 sage: Localization(ZZ, 2).ngens() @@ -811,7 +814,7 @@ def gen(self, i): EXAMPLES:: sage: R. = ZZ[] - sage: R.localization((x**2+1, y-1)).gen(0) + sage: R.localization((x**2 + 1, y - 1)).gen(0) # optional - sage.libs.pari x sage: ZZ.localization(2).gen(0) @@ -827,7 +830,7 @@ def gens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2+1, y-1)).gens() + sage: Localization(R, (x**2 + 1, y - 1)).gens() # optional - sage.libs.pari (x, y) sage: Localization(ZZ, 2).gens() @@ -851,10 +854,10 @@ def _cut_off_extra_units_from_base_ring_element(self, x): EXAMPLES:: sage: P. = QQ[] - sage: L = Localization(P, (x, y*z)) - sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) + sage: L = Localization(P, (x, y*z)) # optional - sage.libs.pari + sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) # optional - sage.libs.pari 1 - sage: L._cut_off_extra_units_from_base_ring_element(x*z) + sage: L._cut_off_extra_units_from_base_ring_element(x*z) # optional - sage.libs.pari 1 TESTS: @@ -894,16 +897,16 @@ def _fraction_to_element(self, x): EXAMPLES:: sage: P. = QQ[] - sage: d = x**2+y**2+z**2 - sage: L = Localization(P, d) - sage: L._fraction_to_element((x+y+z)/d) + sage: d = x**2 + y**2 + z**2 + sage: L = Localization(P, d) # optional - sage.libs.pari + sage: L._fraction_to_element((x+y+z)/d) # optional - sage.libs.pari (x + y + z)/(x^2 + y^2 + z^2) - sage: _ in L + sage: _ in L # optional - sage.libs.pari True TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.pari """ potential_non_unit_denom = self._cut_off_extra_units_from_base_ring_element(x.denominator()) if potential_non_unit_denom.is_unit(): @@ -932,7 +935,7 @@ def _coerce_map_from_(self, S): True sage: N._coerce_map_from_(M) False - sage: O = Localization(L, x**2+1) + sage: O = Localization(L, x**2 + 1) sage: O._coerce_map_from_(M) False sage: O._coerce_map_from_(L) @@ -951,11 +954,11 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: L = Localization(R, (a**2-3, a)) - sage: L.fraction_field() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = Localization(R, (a**2 - 3, a)) # optional - sage.rings.finite_rings + sage: L.fraction_field() # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in a over Finite Field of size 5 - sage: L.is_subring(_) + sage: L.is_subring(_) # optional - sage.rings.finite_rings True """ return self._fraction_field @@ -966,9 +969,9 @@ def characteristic(self): EXAMPLES:: - sage: R. = GF(5)[] # optional - sage.libs.pari - sage: L = R.localization((a**2-3, a)) # optional - sage.libs.pari - sage: L.characteristic() # optional - sage.libs.pari + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = R.localization((a**2 - 3, a)) # optional - sage.rings.finite_rings + sage: L.characteristic() # optional - sage.rings.finite_rings 5 """ return self.base_ring().characteristic() @@ -984,7 +987,7 @@ def krull_dimension(self): EXAMPLES:: - sage: R = ZZ.localization((2,3)) + sage: R = ZZ.localization((2, 3)) sage: R.krull_dimension() 1 """ @@ -1008,7 +1011,7 @@ def is_field(self, proof=True): EXAMPLES:: - sage: R = ZZ.localization((2,3)) + sage: R = ZZ.localization((2, 3)) sage: R.is_field() False """ diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index f70f9ee846c..929bc55703f 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -17,7 +17,8 @@ Natural inclusion `\ZZ \hookrightarrow \QQ`:: sage: phi(2/3) Traceback (most recent call last): ... - TypeError: 2/3 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 2/3 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented There is no homomorphism in the other direction:: @@ -25,30 +26,31 @@ There is no homomorphism in the other direction:: sage: H([1]) Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators EXAMPLES: Reduction to finite field:: - sage: H = Hom(ZZ, GF(9, 'a')) - sage: phi = H([1]) - sage: phi(5) + sage: H = Hom(ZZ, GF(9, 'a')) # optional - sage.rings.finite_rings + sage: phi = H([1]) # optional - sage.rings.finite_rings + sage: phi(5) # optional - sage.rings.finite_rings 2 - sage: psi = H([4]) - sage: psi(5) + sage: psi = H([4]) # optional - sage.rings.finite_rings + sage: psi(5) # optional - sage.rings.finite_rings 2 Map from single variable polynomial ring:: sage: R. = ZZ[] - sage: phi = R.hom([2], GF(5)) - sage: phi + sage: phi = R.hom([2], GF(5)) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 5 Defn: x |--> 2 - sage: phi(x + 12) + sage: phi(x + 12) # optional - sage.rings.finite_rings 4 Identity map on the real numbers:: @@ -61,7 +63,8 @@ Identity map on the real numbers:: sage: f = RR.hom( [2.0] ) Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators Homomorphism from one precision of field to another. @@ -71,7 +74,8 @@ From smaller to bigger doesn't make sense:: sage: f = RR.hom( R200 ) Traceback (most recent call last): ... - TypeError: natural coercion morphism from Real Field with 53 bits of precision to Real Field with 200 bits of precision not defined + TypeError: natural coercion morphism from Real Field with 53 bits of precision + to Real Field with 200 bits of precision not defined From bigger to small does:: @@ -108,7 +112,8 @@ An endomorphism of a quotient of a multi-variate polynomial ring:: sage: S. = quo(R, ideal(1 + y^2)) sage: phi = S.hom([a^2, -b]) sage: phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (y^2 + 1) + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (y^2 + 1) Defn: a |--> a^2 b |--> -b sage: phi(b) @@ -142,28 +147,28 @@ a quotient ring:: Inclusion of ``GF(2)`` into ``GF(4,'a')``:: - sage: k = GF(2) - sage: i = k.hom(GF(4, 'a')) - sage: i + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: i = k.hom(GF(4, 'a')) # optional - sage.rings.finite_rings + sage: i # optional - sage.rings.finite_rings Ring morphism: From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: i(0) + sage: i(0) # optional - sage.rings.finite_rings 0 - sage: a = i(1); a.parent() + sage: a = i(1); a.parent() # optional - sage.rings.finite_rings Finite Field in a of size 2^2 We next compose the inclusion with reduction from the integers to ``GF(2)``:: - sage: pi = ZZ.hom(k) - sage: pi + sage: pi = ZZ.hom(k) # optional - sage.rings.finite_rings + sage: pi # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 2 - sage: f = i * pi - sage: f + sage: f = i * pi # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings Composite map: From: Integer Ring To: Finite Field in a of size 2^2 @@ -175,27 +180,27 @@ We next compose the inclusion with reduction from the integers to From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: a = f(5); a + sage: a = f(5); a # optional - sage.rings.finite_rings 1 - sage: a.parent() + sage: a.parent() # optional - sage.rings.finite_rings Finite Field in a of size 2^2 Inclusion from `\QQ` to the 3-adic field:: - sage: phi = QQ.hom(Qp(3, print_mode='series')) # optional - sage.rings.padics - sage: phi # optional - sage.rings.padics + sage: phi = QQ.hom(Qp(3, print_mode='series')) # optional - sage.rings.padics + sage: phi # optional - sage.rings.padics Ring morphism: From: Rational Field To: 3-adic Field with capped relative precision 20 - sage: phi.codomain() # optional - sage.rings.padics + sage: phi.codomain() # optional - sage.rings.padics 3-adic Field with capped relative precision 20 - sage: phi(394) # optional - sage.rings.padics + sage: phi(394) # optional - sage.rings.padics 1 + 2*3 + 3^2 + 2*3^3 + 3^4 + 3^5 + O(3^20) An automorphism of a quotient of a univariate polynomial ring:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2-2) + sage: S. = R.quo(x^2 - 2) sage: sqrt2^2 2 sage: (3+sqrt2)^10 @@ -227,19 +232,19 @@ Endomorphism of power series ring:: Frobenius on a power series ring over a finite field:: - sage: R. = PowerSeriesRing(GF(5)) - sage: f = R.hom([t^5]); f + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = R.hom([t^5]); f # optional - sage.rings.finite_rings Ring endomorphism of Power Series Ring in t over Finite Field of size 5 Defn: t |--> t^5 - sage: a = 2 + t + 3*t^2 + 4*t^3 + O(t^4) - sage: b = 1 + t + 2*t^2 + t^3 + O(t^5) - sage: f(a) + sage: a = 2 + t + 3*t^2 + 4*t^3 + O(t^4) # optional - sage.rings.finite_rings + sage: b = 1 + t + 2*t^2 + t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f(a) # optional - sage.rings.finite_rings 2 + t^5 + 3*t^10 + 4*t^15 + O(t^20) - sage: f(b) + sage: f(b) # optional - sage.rings.finite_rings 1 + t^5 + 2*t^10 + t^15 + O(t^25) - sage: f(a*b) + sage: f(a*b) # optional - sage.rings.finite_rings 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) - sage: f(a)*f(b) + sage: f(a)*f(b) # optional - sage.rings.finite_rings 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) Homomorphism of Laurent series ring:: @@ -332,44 +337,51 @@ TESTS:: :: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]) - sage: c == loads(dumps(c)) + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]) # optional - sage.rings.number_field + sage: c == loads(dumps(c)) # optional - sage.rings.number_field True :: - sage: R. = PowerSeriesRing(GF(5)) - sage: f = R.hom([t^5]) - sage: f == loads(dumps(f)) + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = R.hom([t^5]) # optional - sage.rings.finite_rings + sage: f == loads(dumps(f)) # optional - sage.rings.finite_rings True We define the identity map in many possible ways. These should all compare equal:: - sage: k = GF(2) - sage: R. = k[] - sage: F4. = R.quo(x^2+x+1) - sage: H = End(F4) + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: F4. = R.quo(x^2+x+1) # optional - sage.rings.finite_rings + sage: H = End(F4) # optional - sage.rings.finite_rings sage: from sage.rings.morphism import * - sage: phi1 = H.identity(); phi1 - Identity endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 - sage: phi2 = H([a]); phi2 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi1 = H.identity(); phi1 # optional - sage.rings.finite_rings + Identity endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi2 = H([a]); phi2 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: a |--> a - sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: Induced from base ring by - Ring endomorphism of Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) + Ring endomorphism of Univariate Polynomial Ring in x + over Finite Field of size 2 (using GF2X) Defn: x |--> x - sage: phi4 = RingHomomorphism_cover(H); phi4 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi4 = RingHomomorphism_cover(H); phi4 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: Natural quotient map - sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 - Frobenius endomorphism x |--> x^(2^2) of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 - sage: maps = [phi1, phi2, phi3, phi4, phi5] - sage: for f in maps: + sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(2^2) of + Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 + sage: maps = [phi1, phi2, phi3, phi4, phi5] # optional - sage.rings.finite_rings + sage: for f in maps: # optional - sage.rings.finite_rings ....: for g in maps: ....: if f != g: ....: print("{} != {}".format(f, g)) @@ -457,13 +469,14 @@ cdef class RingMap_lift(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: S. = R.quo( (x^2 + y^2, y) ) - sage: S.lift() + sage: S. = R.quo( (x^2 + y^2, y) ) # optional - sage.libs.singular + sage: S.lift() # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2, y) + From: Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2, y) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift() == 0 + sage: S.lift() == 0 # optional - sage.libs.singular False Since :trac:`11068`, it is possible to create @@ -473,10 +486,10 @@ cdef class RingMap_lift(RingMap): of :class:`sage.rings.ring.Ring`, as in the following example:: - sage: MS = MatrixSpace(GF(5),2,2) - sage: I = MS*[MS.0*MS.1,MS.2+MS.3]*MS - sage: Q = MS.quo(I) - sage: Q.0*Q.1 # indirect doctest + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.modules sage.rings.finite_rings + sage: I = MS * [MS.0*MS.1, MS.2+MS.3] * MS # optional - sage.modules sage.rings.finite_rings + sage: Q = MS.quo(I) # optional - sage.modules sage.rings.finite_rings + sage: Q.0*Q.1 # indirect doctest # optional - sage.modules sage.rings.finite_rings [0 1] [0 0] """ @@ -496,12 +509,13 @@ cdef class RingMap_lift(RingMap): An invalid example:: - sage: GF9. = GaussianIntegers().quotient(3) # optional - sage.rings.number_field - sage: from sage.rings.morphism import RingMap_lift # optional - sage.rings.number_field - sage: RingMap_lift(GF9, ZZ) # optional - sage.rings.number_field + sage: GF9. = GaussianIntegers().quotient(3) # optional - sage.rings.number_field + sage: from sage.rings.morphism import RingMap_lift # optional - sage.rings.number_field + sage: RingMap_lift(GF9, ZZ) # optional - sage.rings.number_field Traceback (most recent call last): ... - TypeError: no canonical coercion from Number Field in I with defining polynomial x^2 + 1 with I = 1*I to Integer Ring + TypeError: no canonical coercion from Number Field in I + with defining polynomial x^2 + 1 with I = 1*I to Integer Ring """ self.S = S x = R(0).lift() @@ -640,14 +654,14 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: f = ZZ.hom(Zp(3)); f # optional - sage.rings.padics + sage: f = ZZ.hom(Zp(3)); f # optional - sage.rings.padics Ring morphism: From: Integer Ring To: 3-adic Ring with capped relative precision 20 TESTS:: - sage: isinstance(f, sage.rings.morphism.RingHomomorphism) # optional - sage.rings.padics + sage: isinstance(f, sage.rings.morphism.RingHomomorphism) # optional - sage.rings.padics True """ @@ -662,7 +676,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(3))._repr_type() # optional - sage.rings.padics + sage: ZZ.hom(Zp(3))._repr_type() # optional - sage.rings.padics 'Ring' """ @@ -775,17 +789,17 @@ cdef class RingHomomorphism(RingMap): result has the type of a homomorphism between its domain and codomain:: - sage: C = CyclotomicField(24) # optional - sage.rings.number_field - sage: f = End(C)[1] # optional - sage.rings.number_field - sage: type(f*f) == type(f) # optional - sage.rings.number_field + sage: C = CyclotomicField(24) # optional - sage.rings.number_field + sage: f = End(C)[1] # optional - sage.rings.number_field + sage: type(f*f) == type(f) # optional - sage.rings.number_field True An example where the domain of ``right`` is a relative number field:: sage: PQ. = QQ[] - sage: K. = NumberField([X^2 - 2, X^2 - 3]) # optional - sage.rings.number_field - sage: e, u, v, w = End(K) # optional - sage.rings.number_field - sage: u*v # optional - sage.rings.number_field + sage: K. = NumberField([X^2 - 2, X^2 - 3]) # optional - sage.rings.number_field + sage: e, u, v, w = End(K) # optional - sage.rings.number_field + sage: u*v # optional - sage.rings.number_field Relative number field endomorphism of Number Field in a with defining polynomial X^2 - 2 over its base field Defn: a |--> -a @@ -805,39 +819,44 @@ cdef class RingHomomorphism(RingMap): then Coercion map: From: Multivariate Polynomial Ring in a, b over Rational Field - To: Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field + To: Fraction Field of + Multivariate Polynomial Ring in a, b over Rational Field We check that composition works when there is a base map:: sage: R. = ZZ[] - sage: K. = GF(7^2) - sage: L. = K.extension(x^3 - 3) - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) - sage: phi - Ring endomorphism of Univariate Quotient Polynomial Ring in u over Finite Field in a of size 7^2 with modulus u^3 + 4 + sage: K. = GF(7^2) # optional - sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in u + over Finite Field in a of size 7^2 with modulus u^3 + 4 Defn: u |--> 2*u with map of base ring - sage: psi = phi^3; psi - Ring endomorphism of Univariate Quotient Polynomial Ring in u over Finite Field in a of size 7^2 with modulus u^3 + 4 + sage: psi = phi^3; psi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in u + over Finite Field in a of size 7^2 with modulus u^3 + 4 Defn: u |--> u with map of base ring - sage: psi(a) == phi(phi(phi(a))) + sage: psi(a) == phi(phi(phi(a))) # optional - sage.rings.finite_rings True It also works when the image of the base map is not contained within the base ring of the codomain:: sage: S. = QQ[] sage: T. = S[] - sage: cc = S.hom([x+y]) - sage: f = T.hom([x-y], base_map=cc) + sage: cc = S.hom([x + y]) + sage: f = T.hom([x - y], base_map=cc) sage: f*f - Ring endomorphism of Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Ring endomorphism of Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field Defn: y |--> 2*y with map of base ring sage: (f*f).base_map() Ring morphism: From: Univariate Polynomial Ring in x over Rational Field - To: Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + To: Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field Defn: x |--> 2*x with map of base ring @@ -888,9 +907,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.cover() - sage: f.pushforward(R.ideal([x,3*x+x*y+y^2])) - Ideal (xx, xx*yy + 3*xx) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.cover() # optional - sage.libs.singular + sage: f.pushforward(R.ideal([x, 3*x + x*y + y^2])) # optional - sage.libs.singular + Ideal (xx, xx*yy + 3*xx) of Quotient of Multivariate Polynomial Ring + in x, y over Rational Field by the ideal (x^2, y^2) """ if not ideal.is_Ideal(I): raise TypeError("I must be an ideal") @@ -921,18 +941,18 @@ cdef class RingHomomorphism(RingMap): sage: S. = QQ[] sage: f = R.hom([u^2, u*v, v^2], S) sage: I = S.ideal([u^6, u^5*v, u^4*v^2, u^3*v^3]) - sage: J = f.inverse_image(I); J + sage: J = f.inverse_image(I); J # optional - sage.libs.singular Ideal (y^2 - x*z, x*y*z, x^2*z, x^2*y, x^3) of Multivariate Polynomial Ring in x, y, z over Rational Field - sage: f(J) == I + sage: f(J) == I # optional - sage.libs.singular True Under the above homomorphism, there exists an inverse image for every element that only involves monomials of even degree:: - sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] + sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] # optional - sage.libs.singular [x, x^2, x*y*z + y] - sage: f.inverse_image(u*v^2) + sage: f.inverse_image(u*v^2) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: element u*v^2 does not have preimage @@ -940,27 +960,27 @@ cdef class RingHomomorphism(RingMap): The image of the inverse image ideal can be strictly smaller than the original ideal:: - sage: S. = QQ['u,v'].quotient('v^2 - 2') - sage: f = QuadraticField(2).hom([v], S) - sage: I = S.ideal(u + v) - sage: J = f.inverse_image(I) - sage: J.is_zero() + sage: S. = QQ['u,v'].quotient('v^2 - 2') # optional - sage.libs.singular + sage: f = QuadraticField(2).hom([v], S) # optional - sage.libs.singular sage.rings.number_field + sage: I = S.ideal(u + v) # optional - sage.libs.singular sage.rings.number_field + sage: J = f.inverse_image(I) # optional - sage.libs.singular sage.rings.number_field + sage: J.is_zero() # optional - sage.libs.singular sage.rings.number_field True - sage: f(J) < I + sage: f(J) < I # optional - sage.libs.singular sage.rings.number_field True Fractional ideals are not yet fully supported:: - sage: K. = NumberField(QQ['x']('x^2+2')) - sage: f = K.hom([-a], K) - sage: I = K.ideal([a + 1]) - sage: f.inverse_image(I) + sage: K. = NumberField(QQ['x']('x^2+2')) # optional - sage.rings.number_field + sage: f = K.hom([-a], K) # optional - sage.rings.number_field + sage: I = K.ideal([a + 1]) # optional - sage.rings.number_field + sage: f.inverse_image(I) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: inverse image not implemented... - sage: f.inverse_image(K.ideal(0)).is_zero() + sage: f.inverse_image(K.ideal(0)).is_zero() # optional - sage.rings.number_field True - sage: f.inverse()(I) + sage: f.inverse()(I) # optional - sage.rings.number_field Fractional ideal (-a + 1) ALGORITHM: @@ -974,7 +994,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(2)).inverse_image(ZZ.ideal(2)) # optional - sage.rings.padics + sage: ZZ.hom(Zp(2)).inverse_image(ZZ.ideal(2)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: not an ideal or element in codomain 2-adic Ring @@ -982,7 +1002,7 @@ cdef class RingHomomorphism(RingMap): :: - sage: ZZ.hom(Zp(2)).inverse_image(Zp(2).ideal(2)) # optional - sage.rings.padics + sage: ZZ.hom(Zp(2)).inverse_image(Zp(2).ideal(2)) # optional - sage.rings.padics Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1002,13 +1022,13 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: f = R.hom([x, QQbar(i) * x + y^2], R) # optional - sage.rings.number_field - sage: I = R.ideal(y^3) # optional - sage.rings.number_field - sage: J = f._inverse_image_ideal(I); J # optional - sage.rings.number_field + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = R.hom([x, QQbar(i) * x + y^2], R) # optional - sage.rings.number_field + sage: I = R.ideal(y^3) # optional - sage.rings.number_field + sage: J = f._inverse_image_ideal(I); J # optional - sage.rings.number_field Ideal (x^2 + 2*I*x*y - y^2) - of Multivariate Polynomial Ring in x, y over Algebraic Field - sage: f(J) <= I # optional - sage.rings.number_field + of Multivariate Polynomial Ring in x, y over Algebraic Field + sage: f(J) <= I # optional - sage.rings.number_field True TESTS: @@ -1016,17 +1036,17 @@ cdef class RingHomomorphism(RingMap): Check that :trac:`31367` is fixed:: sage: A. = QQ[] - sage: B. = QQ['x,y'].quotient('y') - sage: f = A.hom([x], B) - sage: f.kernel() + sage: B. = QQ['x,y'].quotient('y') # optional - sage.libs.singular + sage: f = A.hom([x], B) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Principal ideal (0) of Univariate Polynomial Ring in t over Rational Field :: sage: A. = QQ[] - sage: B. = QQ['x,y,z'].quotient('z') - sage: f = A.hom([x, y], B) - sage: f.kernel() + sage: B. = QQ['x,y,z'].quotient('z') # optional - sage.libs.singular + sage: f = A.hom([x, y], B) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Ideal (0) of Multivariate Polynomial Ring in t, u over Rational Field """ from .polynomial.polynomial_quotient_ring import is_PolynomialQuotientRing @@ -1068,36 +1088,36 @@ cdef class RingHomomorphism(RingMap): A degenerate case:: - sage: R. = QQ['x,y'].quotient(1) - sage: f = R.hom([y, x], R) - sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest + sage: R. = QQ['x,y'].quotient(1) # optional - sage.libs.singular + sage: f = R.hom([y, x], R) # optional - sage.libs.singular + sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest # optional - sage.libs.singular (0, 0) Check cases involving quotient rings in which a generator is constant (:trac:`31178`):: sage: R. = QQ[] - sage: B. = R.quotient(R.ideal(x)) - sage: g = R.hom([d^2, d^3], B) - sage: g.inverse_image(d) + sage: B. = R.quotient(R.ideal(x)) # optional - sage.libs.singular + sage: g = R.hom([d^2, d^3], B) # optional - sage.libs.singular + sage: g.inverse_image(d) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: element d does not have preimage - sage: g.inverse_image(d^2) + sage: g.inverse_image(d^2) # optional - sage.libs.singular x - sage: g.inverse_image(d^3) + sage: g.inverse_image(d^3) # optional - sage.libs.singular y - sage: A. = R.quotient(R.ideal(y^2 - x^3)) - sage: h = A.hom([d^2, d^3], B) - sage: h.inverse_image(d^2) + sage: A. = R.quotient(R.ideal(y^2 - x^3)) # optional - sage.libs.singular + sage: h = A.hom([d^2, d^3], B) # optional - sage.libs.singular + sage: h.inverse_image(d^2) # optional - sage.libs.singular a Check that quotient rings are handled correctly (:trac:`33217`):: - sage: A. = QQ['X,Y,Z'].quotient('X^2+Y^2+Z^2-1') - sage: B. = QQ['T,U,V,W'].quotient(['T^2+U^2-1', 'V^2+W^2-1']) - sage: psi = A.hom([v*u, w*u, t], B) - sage: psi.inverse_image(t^2) == z^2 + sage: A. = QQ['X,Y,Z'].quotient('X^2+Y^2+Z^2-1') # optional - sage.libs.singular + sage: B. = QQ['T,U,V,W'].quotient(['T^2+U^2-1', 'V^2+W^2-1']) # optional - sage.libs.singular + sage: psi = A.hom([v*u, w*u, t], B) # optional - sage.libs.singular + sage: psi.inverse_image(t^2) == z^2 # optional - sage.libs.singular True """ graph, from_B, to_A = self._graph_ideal() @@ -1117,7 +1137,7 @@ cdef class RingHomomorphism(RingMap): sage: A. = QQ[] sage: B. = QQ[] sage: f = A.hom([t^4, t^3 - t^2], B) - sage: f.kernel() + sage: f.kernel() # optional - sage.libs.singular Ideal (y^4 - x^3 + 4*x^2*y - 2*x*y^2 + x^2) of Multivariate Polynomial Ring in x, y over Rational Field @@ -1125,50 +1145,50 @@ cdef class RingHomomorphism(RingMap): sage: A. = QQ[] sage: B. = QQ[] - sage: f = A.hom([u^3, u^2*v, u*v^2, v^3],B) - sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) + sage: f = A.hom([u^3, u^2*v, u*v^2, v^3], B) + sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) # optional - sage.libs.singular True - sage: Q = A.quotient(f.kernel()) - sage: Q.hom(f.im_gens(), B).is_injective() + sage: Q = A.quotient(f.kernel()) # optional - sage.libs.singular + sage: Q.hom(f.im_gens(), B).is_injective() # optional - sage.libs.singular True The Steiner-Roman surface:: sage: R. = QQ[] - sage: S = R.quotient(x^2 + y^2 + z^2 - 1) - sage: f = R.hom([x*y, x*z, y*z], S) - sage: f.kernel() + sage: S = R.quotient(x^2 + y^2 + z^2 - 1) # optional - sage.libs.singular + sage: f = R.hom([x*y, x*z, y*z], S) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Ideal (x^2*y^2 + x^2*z^2 + y^2*z^2 - x*y*z) - of Multivariate Polynomial Ring in x, y, z over Rational Field + of Multivariate Polynomial Ring in x, y, z over Rational Field TESTS: The results are cached:: - sage: f.kernel() is f.kernel() + sage: f.kernel() is f.kernel() # optional - sage.libs.singular True A degenerate case:: sage: R. = QQ[] - sage: f = R.hom([0, 0], R.quotient(1)) - sage: f.kernel().is_one() + sage: f = R.hom([0, 0], R.quotient(1)) # optional - sage.libs.singular + sage: f.kernel().is_one() # optional - sage.libs.singular True :: - sage: K. = QuadraticField(2) - sage: K.hom([-sqrt2], K).kernel().is_zero() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: K.hom([-sqrt2], K).kernel().is_zero() # optional - sage.rings.number_field True :: - sage: A. = QuadraticField(2) - sage: B. = A.extension(A['b']('b^2-3')) - sage: C. = B.absolute_field() - sage: A.hom([B(a)], C).kernel().is_zero() + sage: A. = QuadraticField(2) # optional - sage.rings.number_field + sage: B. = A.extension(A['b']('b^2-3')) # optional - sage.rings.number_field + sage: C. = B.absolute_field() # optional - sage.rings.number_field + sage: A.hom([B(a)], C).kernel().is_zero() # optional - sage.rings.number_field True - sage: A.hom([a], B).kernel() + sage: A.hom([a], B).kernel() # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1267,8 +1287,8 @@ cdef class RingHomomorphism(RingMap): Non-commutative rings are not supported (:trac:`32824`):: - sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') - sage: A.hom(A.gens(), A).kernel() + sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') # optional - sage.combinat sage.modules + sage: A.hom(A.gens(), A).kernel() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: rings are not commutative @@ -1325,7 +1345,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([2*t - 1], R) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Ring endomorphism of Univariate Polynomial Ring in t over Rational Field Defn: t |--> 1/2*t + 1/2 @@ -1334,15 +1354,15 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([y*z, x*z, x*y], R) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: f.is_injective() + sage: f.is_injective() # optional - sage.libs.singular True - sage: Q. = R.quotient(x*y*z - 1) - sage: g = Q.hom([y*z, x*z, x*y], Q) - sage: g.inverse() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: g = Q.hom([y*z, x*z, x*y], Q) # optional - sage.libs.singular + sage: g.inverse() # optional - sage.libs.singular Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x*y*z - 1) Defn: x |--> y*z @@ -1353,24 +1373,24 @@ cdef class RingHomomorphism(RingMap): sage: S. = ZZ[] sage: f = S.hom([x + 2*y, x + 3*y], S) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Ring endomorphism of Multivariate Polynomial Ring in x, y over Integer Ring Defn: x |--> 3*x - 2*y y |--> -x + y - sage: (f.inverse() * f).is_identity() + sage: (f.inverse() * f).is_identity() # optional - sage.libs.singular True The following homomorphism is invertible over the rationals, but not over the integers:: sage: g = S.hom([x + y, x - y - 2], S) - sage: g.inverse() + sage: g.inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective sage: R. = QQ[x,y] sage: h = R.hom([x + y, x - y - 2], R) - sage: (h.inverse() * h).is_identity() + sage: (h.inverse() * h).is_identity() # optional - sage.libs.singular True This example by M. Nagata is a wild automorphism:: @@ -1378,13 +1398,13 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: sigma = R.hom([x - 2*y*(z*x+y^2) - z*(z*x+y^2)^2, ....: y + z*(z*x+y^2), z], R) - sage: tau = sigma.inverse(); tau + sage: tau = sigma.inverse(); tau # optional - sage.libs.singular Ring endomorphism of Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> -y^4*z - 2*x*y^2*z^2 - x^2*z^3 + 2*y^3 + 2*x*y*z + x y |--> -y^2*z - x*z^2 + y z |--> z - sage: (tau * sigma).is_identity() + sage: (tau * sigma).is_identity() # optional - sage.libs.singular True We compute the triangular automorphism that converts moments to @@ -1408,37 +1428,37 @@ cdef class RingHomomorphism(RingMap): x1^5 + 10*x1^3*x2 + 15*x1*x2^2 + 10*x1^2*x3 + 10*x2*x3 + 5*x1*x4 + x5] sage: all(p.is_homogeneous() for p in phi.im_gens()) True - sage: phi.inverse().im_gens()[:5] + sage: phi.inverse().im_gens()[:5] # optional - sage.libs.singular [x1, -x1^2 + x2, 2*x1^3 - 3*x1*x2 + x3, -6*x1^4 + 12*x1^2*x2 - 3*x2^2 - 4*x1*x3 + x4, 24*x1^5 - 60*x1^3*x2 + 30*x1*x2^2 + 20*x1^2*x3 - 10*x2*x3 - 5*x1*x4 + x5] - sage: (phi.inverse() * phi).is_identity() + sage: (phi.inverse() * phi).is_identity() # optional - sage.libs.singular True Automorphisms of number fields as well as Galois fields are supported:: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]) - sage: (c.inverse() * c).is_identity() + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]) # optional - sage.rings.number_field + sage: (c.inverse() * c).is_identity() # optional - sage.rings.number_field True - sage: F. = GF(7^3) - sage: f = F.hom(t^7, F) - sage: (f.inverse() * f).is_identity() + sage: F. = GF(7^3) # optional - sage.rings.finite_rings + sage: f = F.hom(t^7, F) # optional - sage.rings.finite_rings + sage: (f.inverse() * f).is_identity() # optional - sage.rings.finite_rings True An isomorphism between the algebraic torus and the circle over a number field:: - sage: K. = QuadraticField(-1) - sage: A. = K['z,w'].quotient('z*w - 1') - sage: B. = K['x,y'].quotient('x^2 + y^2 - 1') - sage: f = A.hom([x + i*y, x - i*y], B) - sage: g = f.inverse() - sage: g.morphism_from_cover().im_gens() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: A. = K['z,w'].quotient('z*w - 1') # optional - sage.rings.number_field + sage: B. = K['x,y'].quotient('x^2 + y^2 - 1') # optional - sage.rings.number_field + sage: f = A.hom([x + i*y, x - i*y], B) # optional - sage.rings.number_field + sage: g = f.inverse() # optional - sage.rings.number_field + sage: g.morphism_from_cover().im_gens() # optional - sage.rings.number_field [1/2*z + 1/2*w, (-1/2*i)*z + (1/2*i)*w] - sage: all(g(f(z)) == z for z in A.gens()) + sage: all(g(f(z)) == z for z in A.gens()) # optional - sage.rings.number_field True TESTS: @@ -1446,43 +1466,43 @@ cdef class RingHomomorphism(RingMap): Morphisms involving quotient rings:: sage: R. = QQ[] - sage: S. = QQ['s,u,t'].quotient('u-t^2') - sage: f = R.hom([s, -t], S) - sage: (f.inverse() * f).is_identity() + sage: S. = QQ['s,u,t'].quotient('u-t^2') # optional - sage.libs.singular + sage: f = R.hom([s, -t], S) # optional - sage.libs.singular + sage: (f.inverse() * f).is_identity() # optional - sage.libs.singular True - sage: Q. = R.quotient(x-y^2) - sage: g = Q.hom([v, -w], Q) - sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w + sage: Q. = R.quotient(x - y^2) # optional - sage.libs.singular + sage: g = Q.hom([v, -w], Q) # optional - sage.libs.singular + sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w # optional - sage.libs.singular True sage: S. = QQ[] - sage: h = Q.hom([z^2, -z], S) - sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w + sage: h = Q.hom([z^2, -z], S) # optional - sage.libs.singular + sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w # optional - sage.libs.singular True Morphisms between number fields and quotient rings:: - sage: K. = QuadraticField(2) - sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) - sage: (f.inverse() * f).is_identity() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) # optional - sage.rings.number_field + sage: (f.inverse() * f).is_identity() # optional - sage.rings.number_field True - sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) - sage: (g.inverse() * g).is_identity() + sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) # optional - sage.rings.number_field + sage: (g.inverse() * g).is_identity() # optional - sage.rings.number_field True Morphisms involving Galois fields:: - sage: A. = GF(7^3) - sage: R = A.polynomial_ring().quotient(A.polynomial()) - sage: g = A.hom(R.gens(), R) - sage: (g.inverse() * g).is_identity() + sage: A. = GF(7^3) # optional - sage.rings.finite_rings + sage: R = A.polynomial_ring().quotient(A.polynomial()) # optional - sage.rings.finite_rings + sage: g = A.hom(R.gens(), R) # optional - sage.rings.finite_rings + sage: (g.inverse() * g).is_identity() # optional - sage.rings.finite_rings True - sage: B., f = A.extension(3, map=True) - sage: f.inverse() + sage: B., f = A.extension(3, map=True) # optional - sage.rings.finite_rings + sage: f.inverse() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: B., f = A.extension(1, map=True) - sage: f.inverse() + sage: B., f = A.extension(1, map=True) # optional - sage.rings.finite_rings + sage: f.inverse() # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in T of size 7^3 To: Finite Field in t of size 7^3 @@ -1492,7 +1512,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: S. = QQ[] - sage: S.hom([x, y, 0], R).inverse() + sage: S.hom([x, y, 0], R).inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1501,12 +1521,12 @@ cdef class RingHomomorphism(RingMap): Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q. = R.quotient([x^5, y^4]) - sage: R.hom([u, v], Q).inverse() + sage: Q. = R.quotient([x^5, y^4]) # optional - sage.libs.singular + sage: R.hom([u, v], Q).inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q.cover().inverse() + sage: Q.cover().inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1520,23 +1540,23 @@ cdef class RingHomomorphism(RingMap): A homomorphism over ``QQbar``:: - sage: R. = QQbar[] - sage: f = R.hom([x + QQbar(I)*y^2, -y], R) - sage: (f.inverse() * f).is_identity() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = R.hom([x + QQbar(I)*y^2, -y], R) # optional - sage.rings.number_field + sage: (f.inverse() * f).is_identity() # optional - sage.rings.number_field True Check that results are cached:: - sage: R. = GF(823)[] - sage: f = R.hom([x, y+x^2], R) - sage: f.inverse() is f.inverse() + sage: R. = GF(823)[] # optional - sage.rings.finite_rings + sage: f = R.hom([x, y+x^2], R) # optional - sage.rings.finite_rings + sage: f.inverse() is f.inverse() # optional - sage.rings.finite_rings True Some subclasses of ring homomorphisms are not supported:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) - sage: FrobeniusEndomorphism_generic(K).inverse() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K).inverse() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1563,11 +1583,11 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([x + 123*y^2, y], R) - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular False - sage: f.is_injective() + sage: f.is_injective() # optional - sage.libs.singular True - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular True """ if not self.is_injective(): @@ -1587,9 +1607,9 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = GF(17)[] - sage: f = R.hom([3*x, y + x^2 + x^3], R) - sage: (f * ~f).is_identity() + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = R.hom([3*x, y + x^2 + x^3], R) # optional - sage.rings.finite_rings + sage: (f * ~f).is_identity() # optional - sage.rings.finite_rings True """ return self.inverse() @@ -1601,10 +1621,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_surjective() + sage: R.hom([y*z, x*z, x*y], R).is_surjective() # optional - sage.libs.singular False - sage: Q. = R.quotient(x*y*z - 1) - sage: R.hom([y*z, x*z, x*y], Q).is_surjective() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: R.hom([y*z, x*z, x*y], Q).is_surjective() # optional - sage.libs.singular True ALGORITHM: @@ -1625,10 +1645,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_invertible() + sage: R.hom([y*z, x*z, x*y], R).is_invertible() # optional - sage.libs.singular False - sage: Q. = R.quotient(x*y*z - 1) - sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() # optional - sage.libs.singular True ALGORITHM: @@ -1761,7 +1781,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: phi = R.hom([x,x+y]); phi + sage: phi = R.hom([x, x + y]); phi Ring endomorphism of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x y |--> x + y @@ -1770,33 +1790,34 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): Here's another example where the domain isn't free:: - sage: S. = R.quotient(x - y) - sage: phi = S.hom([xx+1,xx+1]) + sage: S. = R.quotient(x - y) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx + 1]) # optional - sage.libs.singular Note that one has to specify valid images:: - sage: phi = S.hom([xx+1,xx-1]) + sage: phi = S.hom([xx + 1, xx - 1]) # optional - sage.libs.singular Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators You can give a map of the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = K[] - sage: z = 1 + i*t + (3+4*i)*t^2 - sage: z._im_gens_(R, [t^2], base_map=cc) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: z = 1 + i*t + (3+4*i)*t^2 # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field (-4*i + 3)*t^4 - i*t^2 + 1 The base map's codomain is extended to the whole codomain:: sage: S. = QQ[] sage: T. = S[] - sage: cc = S.hom([x+1]) - sage: f = T.hom([x-y], base_map=cc) - sage: g = T.hom([x-y], base_map=cc.extend_codomain(T)) + sage: cc = S.hom([x + 1]) + sage: f = T.hom([x - y], base_map=cc) + sage: g = T.hom([x - y], base_map=cc.extend_codomain(T)) sage: f == g True sage: f.base_map() == cc.extend_codomain(T) @@ -1807,11 +1828,12 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): speed up creation of a homomorphism:: sage: R. = QQ[] - sage: S. = R.quotient(x - y) - sage: phi = S.hom([xx+1,xx-1], check=False) + sage: S. = R.quotient(x - y) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx - 1], check=False) # optional - sage.libs.singular Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators """ RingHomomorphism.__init__(self, parent) if not isinstance(im_gens, sage.structure.sequence.Sequence_generic): @@ -1849,7 +1871,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: f.im_gens() [x, x + y] @@ -1870,29 +1892,31 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = 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: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field - sage: phi # 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: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field + sage: phi # optional - sage.rings.number_field Ring endomorphism of Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 Defn: y |--> y^2 with map of base ring - sage: phi(y) # optional - sage.rings.number_field + sage: phi(y) # optional - sage.rings.number_field y^2 - sage: phi(i*y) # optional - sage.rings.number_field + sage: phi(i*y) # optional - sage.rings.number_field -i*y^2 - sage: phi.base_map() # optional - sage.rings.number_field + sage: phi.base_map() # optional - sage.rings.number_field Composite map: From: Number Field in i with defining polynomial x^2 + 1 - To: Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + To: Univariate Polynomial Ring in y over Number Field in i + with defining polynomial x^2 + 1 Defn: Ring endomorphism of Number Field in i with defining polynomial x^2 + 1 Defn: i |--> -i then Polynomial base injection morphism: From: Number Field in i with defining polynomial x^2 + 1 - To: Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + To: Univariate Polynomial Ring in y over Number Field in i + with defining polynomial x^2 + 1 """ return self._base_map @@ -1903,7 +1927,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: g = copy(f) # indirect doctest sage: g == f True @@ -1923,7 +1947,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: g = copy(f) # indirect doctest sage: g == f True @@ -1944,51 +1968,51 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A single variate quotient over `\QQ`:: sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) - sage: f1 = R.hom([a]) - sage: f2 = R.hom([a + a^2 + a + 1]) - sage: f1 == f2 + sage: Q. = R.quotient(x^2 + x + 1) # optional - sage.libs.pari + sage: f1 = R.hom([a]) # optional - sage.libs.pari + sage: f2 = R.hom([a + a^2 + a + 1]) # optional - sage.libs.pari + sage: f1 == f2 # optional - sage.libs.pari True - sage: f1 == R.hom([a^2]) + sage: f1 == R.hom([a^2]) # optional - sage.libs.pari False - sage: f1(x^3 + x) + sage: f1(x^3 + x) # optional - sage.libs.pari a + 1 - sage: f2(x^3 + x) + sage: f2(x^3 + x) # optional - sage.libs.pari a + 1 TESTS:: - sage: loads(dumps(f2)) == f2 + sage: loads(dumps(f2)) == f2 # optional - sage.libs.pari True :: - sage: R. = QQ[]; f = R.hom([x,x+y]); g = R.hom([y,x]) - sage: f == g # indirect doctest + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) # optional - sage.libs.pari + sage: f == g # indirect doctest # optional - sage.libs.pari False EXAMPLES: A multivariate quotient over a finite field:: - sage: R. = GF(7)[] - sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) - sage: f1 = R.hom([a, b]) - sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) - sage: f1 == f2 + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) # optional - sage.rings.finite_rings + sage: f1 = R.hom([a, b]) # optional - sage.rings.finite_rings + sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) # optional - sage.rings.finite_rings + sage: f1 == f2 # optional - sage.rings.finite_rings True - sage: f1 == R.hom([b,a]) + sage: f1 == R.hom([b, a]) # optional - sage.rings.finite_rings False - sage: x^3 + x + y^2 + sage: x^3 + x + y^2 # optional - sage.rings.finite_rings x^3 + y^2 + x - sage: f1(x^3 + x + y^2) + sage: f1(x^3 + x + y^2) # optional - sage.rings.finite_rings a - b - sage: f2(x^3 + x + y^2) + sage: f2(x^3 + x + y^2) # optional - sage.rings.finite_rings a - b TESTS:: - sage: loads(dumps(f2)) == f2 + sage: loads(dumps(f2)) == f2 # optional - sage.rings.finite_rings True This was fixed in :trac:`24277`:: @@ -2080,8 +2104,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: Pf = PR.hom(f,PS) sage: Pf Ring morphism: - From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Rational Field + To: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field @@ -2095,47 +2121,54 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): Similarly, we can construct the induced homomorphism on a matrix ring over our polynomial rings:: - sage: MR = MatrixSpace(R, 2, 2) # optional - sage.modules - sage: MS = MatrixSpace(S, 2, 2) # optional - sage.modules - sage: M = MR([x^2 + 1/7*x*y - y^2, - 1/2*y^2 + 2*y + 1/6, 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) # optional - sage.modules - sage: Mf = MR.hom(f, MS) # optional - sage.modules - sage: Mf # optional - sage.modules + sage: MR = MatrixSpace(R, 2, 2) # optional - sage.modules + sage: MS = MatrixSpace(S, 2, 2) # optional - sage.modules + sage: M = MR([x^2 + 1/7*x*y - y^2, -1/2*y^2 + 2*y + 1/6, # optional - sage.modules + ....: 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) + sage: Mf = MR.hom(f, MS) # optional - sage.modules + sage: Mf # optional - sage.modules Ring morphism: - From: Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field - To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in z over Rational Field + From: Full MatrixSpace of 2 by 2 dense matrices + over Multivariate Polynomial Ring in x, y over Rational Field + To: Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Univariate Polynomial Ring in z over Rational Field Defn: x |--> 2*z y |--> 3*z - sage: Mf(M) # optional - sage.modules + sage: Mf(M) # optional - sage.modules [ -29/7*z^2 -9/2*z^2 + 6*z + 1/6] [ 16*z^2 - 28*z 9/2*z^2 + 131/22*z] The construction of induced homomorphisms is recursive, and so we have:: - sage: MPR = MatrixSpace(PR, 2) # optional - sage.modules - sage: MPS = MatrixSpace(PS, 2) # optional - sage.modules - sage: M = MPR([(- x + y)*t^2 + 58*t - 3*x^2 + x*y, (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, - ....: (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, (x + 6*y + 1)*t^2]) - sage: MPf = MPR.hom(f, MPS); MPf # optional - sage.modules + sage: MPR = MatrixSpace(PR, 2) # optional - sage.modules + sage: MPS = MatrixSpace(PS, 2) # optional - sage.modules + sage: M = MPR([(-x + y)*t^2 + 58*t - 3*x^2 + x*y, # optional - sage.modules + ....: (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, + ....: (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, + ....: (x + 6*y + 1)*t^2]) + sage: MPf = MPR.hom(f, MPS); MPf # optional - sage.modules Ring morphism: - From: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t - over Multivariate Polynomial Ring in x, y over Rational Field - To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t - over Univariate Polynomial Ring in z over Rational Field + From: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial + Ring in t over Multivariate Polynomial Ring in x, y over Rational Field + To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial + Ring in t over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: - From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Rational Field + To: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Univariate Polynomial Ring in z over Rational Field Defn: x |--> 2*z y |--> 3*z - sage: MPf(M) # optional - sage.modules + sage: MPf(M) # optional - sage.modules [ z*t^2 + 58*t - 6*z^2 (-6/7*z^2 - 1/20*z)*t^2 + 29*z^2*t + 6*z] [ (-z + 1)*t^2 + 11*z^2 + 15/2*z + 1/4 (20*z + 1)*t^2] """ @@ -2147,11 +2180,12 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: from sage.rings.morphism import RingHomomorphism_from_base sage: R. = ZZ[] - sage: f = R.hom([2*x],R) - sage: P = MatrixSpace(R,2).Hom(MatrixSpace(R,2)) - sage: g = RingHomomorphism_from_base(P,f) - sage: g - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + sage: f = R.hom([2*x], R) + sage: P = MatrixSpace(R, 2).Hom(MatrixSpace(R, 2)) # optional - sage.modules + sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules + sage: g # optional - sage.modules + Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring Defn: Induced from base ring by Ring endomorphism of Univariate Polynomial Ring in x over Integer Ring Defn: x |--> 2*x @@ -2160,11 +2194,13 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): codomain are constructed in a compatible way. So, the following results in an error:: - sage: P = MatrixSpace(R,2).Hom(R['t']) - sage: g = RingHomomorphism_from_base(P,f) + sage: P = MatrixSpace(R, 2).Hom(R['t']) # optional - sage.modules + sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules Traceback (most recent call last): ... - ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring) and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring) must have the same functorial construction over their base rings + ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring) + and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring) + must have the same functorial construction over their base rings """ RingHomomorphism.__init__(self, parent) if underlying.domain() != parent.domain().base(): @@ -2183,11 +2219,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([2*z,3*z],S) - sage: MR = MatrixSpace(R,2) - sage: MS = MatrixSpace(S,2) - sage: g = MR.hom(f,MS) - sage: g.underlying_map() == f + sage: f = R.hom([2*z, 3*z], S) + sage: MR = MatrixSpace(R, 2) # optional - sage.modules + sage: MS = MatrixSpace(S, 2) # optional - sage.modules + sage: g = MR.hom(f, MS) # optional - sage.modules + sage: g.underlying_map() == f # optional - sage.modules True """ return self._underlying @@ -2200,10 +2236,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([2*z,3*z],S) + sage: f = R.hom([2*z, 3*z],S) sage: PR. = R[] sage: PS = S['t'] - sage: phi = PR.hom(f,PS) + sage: phi = PR.hom(f, PS) sage: type(phi) sage: psi = copy(phi); psi # indirect doctest @@ -2261,24 +2297,24 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): `\QQ`:: sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) - sage: f1 = R.hom([a]) - sage: f2 = R.hom([a + a^2 + a + 1]) - sage: PR. = R[] - sage: PQ = Q['s','t'] - sage: f1P = PR.hom(f1,PQ) - sage: f2P = PR.hom(f2,PQ) - sage: f1P == f2P + sage: Q. = R.quotient(x^2 + x + 1) # optional - sage.libs.pari sage.modules + sage: f1 = R.hom([a]) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f2 = R.hom([a + a^2 + a + 1]) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: PR. = R[] # optional - sage.libs.pari sage.libs.singular sage.modules + sage: PQ = Q['s','t'] # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P = PR.hom(f1,PQ) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f2P = PR.hom(f2,PQ) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P == f2P # optional - sage.libs.pari sage.libs.singular sage.modules True TESTS:: - sage: f1P == loads(dumps(f1P)) + sage: f1P == loads(dumps(f1P)) # optional - sage.libs.pari sage.libs.singular sage.modules True - sage: R. = QQ[]; f = R.hom([x,x+y]); g = R.hom([y,x]) + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) sage: S. = R[] - sage: fS = S.hom(f,S); gS = S.hom(g,S) + sage: fS = S.hom(f, S); gS = S.hom(g, S) sage: fS != gS # indirect doctest True @@ -2286,20 +2322,20 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A matrix ring over a multivariate quotient over a finite field:: - sage: R. = GF(7)[] - sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) - sage: f1 = R.hom([a, b]) - sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) - sage: MR = MatrixSpace(R,2) - sage: MQ = MatrixSpace(Q,2) - sage: f1M = MR.hom(f1,MQ) - sage: f2M = MR.hom(f2,MQ) - sage: f1M == f2M + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) # optional - sage.rings.finite_rings + sage: f1 = R.hom([a, b]) # optional - sage.rings.finite_rings + sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) # optional - sage.rings.finite_rings + sage: MR = MatrixSpace(R, 2) # optional - sage.rings.finite_rings sage.modules + sage: MQ = MatrixSpace(Q, 2) # optional - sage.rings.finite_rings sage.modules + sage: f1M = MR.hom(f1, MQ) # optional - sage.rings.finite_rings sage.modules + sage: f2M = MR.hom(f2, MQ) # optional - sage.rings.finite_rings sage.modules + sage: f1M == f2M # optional - sage.rings.finite_rings sage.modules True TESTS:: - sage: f1M == loads(dumps(f1M)) + sage: f1M == loads(dumps(f1M)) # optional - sage.rings.finite_rings sage.modules True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2319,10 +2355,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): over a multivariate polynomial ring:: sage: R1. = ZZ[] - sage: f = R1.hom([x+y, x-y]) - sage: R2 = MatrixSpace(FractionField(R1)['t'], 2) # optional - sage.modules - sage: g = R2.hom(f, R2) # optional - sage.modules - sage: g #indirect doctest # optional - sage.modules + sage: f = R1.hom([x + y, x - y]) + sage: R2 = MatrixSpace(FractionField(R1)['t'], 2) # optional - sage.modules + sage: g = R2.hom(f, R2) # optional - sage.modules + sage: g #indirect doctest # optional - sage.modules Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by @@ -2370,11 +2406,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([a+b, a-b], S) + sage: f = R.hom([a + b, a - b], S) # optional - sage.libs.singular sage: PR. = R[] sage: PS = S['t'] - sage: Pf = PR.hom(f, PS) - sage: Pf.inverse() + sage: Pf = PR.hom(f, PS) # optional - sage.libs.singular + sage: Pf.inverse() # optional - sage.libs.singular Ring morphism: From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field @@ -2386,7 +2422,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): To: Multivariate Polynomial Ring in x, y over Rational Field Defn: a |--> 1/2*x + 1/2*y b |--> 1/2*x - 1/2*y - sage: Pf.inverse()(Pf(x*t^2 + y*t)) + sage: Pf.inverse()(Pf(x*t^2 + y*t)) # optional - sage.libs.singular x*t^2 + y*t """ return self.parent().reversed()(self._underlying.inverse()) @@ -2400,8 +2436,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([x^2]) - sage: g = f.extend_to_fraction_field() - sage: type(g) + sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular + sage: type(g) # optional - sage.libs.singular """ def __init__(self, parent, morphism): @@ -2429,11 +2465,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x^2]).extend_to_fraction_field() - sage: f + sage: f = S.hom([x^2]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x^2 - sage: f._repr_defn() + sage: f._repr_defn() # optional - sage.libs.singular 'x |--> x^2' """ return self._morphism._repr_defn() @@ -2449,10 +2485,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() - sage: f(1/x) + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f(1/x) # optional - sage.libs.singular 1/(x + 1) - sage: f(1/(x-1)) + sage: f(1/(x-1)) # optional - sage.libs.singular 1/x """ return self._morphism(x.numerator()) / self._morphism(x.denominator()) @@ -2464,12 +2500,12 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular - sage: g = copy(f) # indirect doctest - sage: f == g + sage: g = copy(f) # indirect doctest # optional - sage.libs.singular + sage: f == g # optional - sage.libs.singular True - sage: f is g + sage: f is g # optional - sage.libs.singular False """ self._morphism = _slots['_morphism'] @@ -2482,8 +2518,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() - sage: loads(dumps(f)) == f + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: loads(dumps(f)) == f # optional - sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2499,10 +2535,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([2*x - 1]) - sage: g = f.extend_to_fraction_field() - sage: g.inverse() + sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular + sage: g.inverse() # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring - in x over Rational Field + in x over Rational Field Defn: x |--> 1/2*x + 1/2 """ return self.parent().reversed()(self._morphism.inverse()) @@ -2515,13 +2551,14 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover(); phi + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover(); phi # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) Defn: Natural quotient map - sage: phi(x+y) + sage: phi(x + y) # optional - sage.libs.singular a + b """ def __init__(self, parent): @@ -2568,7 +2605,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): sage: f(1/2) Traceback (most recent call last): ... - TypeError: 1/2 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 1/2 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented """ return self.codomain()(x) @@ -2606,11 +2644,11 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover() - sage: phi == loads(dumps(phi)) + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover() # optional - sage.libs.singular + sage: phi == loads(dumps(phi)) # optional - sage.libs.singular True - sage: phi == R.quo(x^2 + y^3).cover() + sage: phi == R.quo(x^2 + y^3).cover() # optional - sage.libs.singular False """ if not isinstance(other, RingHomomorphism_cover): @@ -2626,13 +2664,13 @@ cdef class RingHomomorphism_cover(RingHomomorphism): TESTS:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover() - sage: type(phi) + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover() # optional - sage.libs.singular + sage: type(phi) # optional - sage.libs.singular - sage: hash(phi) == hash(phi) + sage: hash(phi) == hash(phi) # optional - sage.libs.singular True - sage: {phi: 1}[phi] + sage: {phi: 1}[phi] # optional - sage.libs.singular 1 """ return hash((self.domain(), self.codomain())) @@ -2647,12 +2685,12 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: R. = QQ['x,y'].quotient('x^2 * y^2') - sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) + sage: R. = QQ['x,y'].quotient('x^2 * y^2') # optional - sage.libs.singular + sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) # optional - sage.libs.singular Ideal (x^2*y^2, x^3, y^3 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: S. = QQbar['u,v'].quotient('u^4 - 1') - sage: S.cover().inverse_image(S.ideal(u^2 - 1)) + sage: S. = QQbar['u,v'].quotient('u^4 - 1') # optional - sage.libs.singular + sage: S.cover().inverse_image(S.ideal(u^2 - 1)) # optional - sage.libs.singular Ideal (u^4 - 1, u^2 - 1) of Multivariate Polynomial Ring in u, v over Algebraic Field """ @@ -2667,8 +2705,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: Q. = QQ['x,y'].quotient('x + y') - sage: Q.cover().inverse_image(u) + sage: Q. = QQ['x,y'].quotient('x + y') # optional - sage.libs.singular + sage: Q.cover().inverse_image(u) # optional - sage.libs.singular -y """ return b.lift() @@ -2697,25 +2735,27 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: loads(dumps(phi)) == phi + sage: loads(dumps(phi)) == phi # optional - sage.libs.singular True Validity of the homomorphism is determined, when possible, and a ``TypeError`` is raised if there is no homomorphism sending the generators to the given images:: - sage: S.hom([b^2, c^2, a^2]) + sage: S.hom([b^2, c^2, a^2]) # optional - sage.libs.singular Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators """ def __init__(self, parent, phi): """ @@ -2723,8 +2763,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2, y^2) Defn: xx |--> yy yy |--> xx """ @@ -2750,20 +2791,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest - sage: psi == phi + sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular + sage: psi == phi # optional - sage.libs.singular True - sage: psi is phi + sage: psi is phi # optional - sage.libs.singular False - sage: psi(a) == phi(a) + sage: psi(a) == phi(a) # optional - sage.libs.singular True """ @@ -2777,20 +2819,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest - sage: psi == phi + sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular + sage: psi == phi # optional - sage.libs.singular True - sage: psi is phi + sage: psi is phi # optional - sage.libs.singular False - sage: psi(a) == phi(a) + sage: psi(a) == phi(a) # optional - sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2804,8 +2847,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.hom([yy,xx]) - sage: f._phi() + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy,xx]) # optional - sage.libs.singular + sage: f._phi() # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) @@ -2821,11 +2864,12 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]) - sage: S.hom([yy,xx]).morphism_from_cover() + sage: R. = QQ[]; S. = R.quo([x^2, y^2]) # optional - sage.libs.singular + sage: S.hom([yy,xx]).morphism_from_cover() # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + To: Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2, y^2) Defn: x |--> yy y |--> xx """ @@ -2837,14 +2881,14 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = PolynomialRing(GF(19), 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]) - sage: psi = S.hom([c, b, a]) - sage: f = S.hom([b, c, a + a^3 + b^3 + c^3]) - sage: phi == psi + sage: R. = PolynomialRing(GF(19), 3) # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.rings.finite_rings + sage: phi = S.hom([b, c, a]) # optional - sage.rings.finite_rings + sage: psi = S.hom([c, b, a]) # optional - sage.rings.finite_rings + sage: f = S.hom([b, c, a + a^3 + b^3 + c^3]) # optional - sage.rings.finite_rings + sage: phi == psi # optional - sage.rings.finite_rings False - sage: phi == f + sage: phi == f # optional - sage.rings.finite_rings True """ if not isinstance(other, RingHomomorphism_from_quotient): @@ -2861,14 +2905,14 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = PolynomialRing(GF(19), 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]) - sage: type(phi) + sage: R. = PolynomialRing(GF(19), 3) # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.rings.finite_rings + sage: phi = S.hom([b, c, a]) # optional - sage.rings.finite_rings + sage: type(phi) # optional - sage.rings.finite_rings - sage: hash(phi) == hash(phi) + sage: hash(phi) == hash(phi) # optional - sage.rings.finite_rings True - sage: {phi: 1}[phi] + sage: {phi: 1}[phi] # optional - sage.rings.finite_rings 1 """ return hash(self.phi) @@ -2879,9 +2923,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]) - sage: f = S.hom([yy,xx]) - sage: print(f._repr_defn()) + sage: R. = QQ[]; S. = R.quo([x^2,y^2]) # optional - sage.libs.singular + sage: f = S.hom([yy, xx]) # optional - sage.libs.singular + sage: print(f._repr_defn()) # optional - sage.libs.singular xx |--> yy yy |--> xx """ @@ -2896,8 +2940,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.hom([yy,xx]) - sage: f(3*x + (1/2)*y) # indirect doctest + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy, xx]) # optional - sage.libs.singular + sage: f(3*x + (1/2)*y) # indirect doctest # optional - sage.libs.singular 1/2*xx + 3*yy """ return self.phi(self.lift(x)) @@ -2924,11 +2968,13 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): TESTS:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) - sage: FrobeniusEndomorphism_generic(K) - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: FrobeniusEndomorphism_generic(K, 2) - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K) # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: FrobeniusEndomorphism_generic(K, 2) # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 """ from .ring import CommutativeRing from sage.categories.homset import Hom @@ -2955,10 +3001,10 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(5)['T']) - sage: phi = K.frobenius_endomorphism() - sage: psi = copy(phi) - sage: phi == psi + sage: K = Frac(GF(5)['T']) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: psi = copy(phi) # optional - sage.rings.finite_rings + sage: phi == psi # optional - sage.rings.finite_rings True """ self._p = _slots['_domain'].characteristic() @@ -2975,14 +3021,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(25)['T']) - sage: phi = K.frobenius_endomorphism(2) - sage: phi - Frobenius endomorphism x |--> x^(5^2) of Fraction Field of Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 + sage: K = Frac(GF(25)['T']) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism(2) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Fraction Field of + Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - sage: psi = loads(dumps(phi)); psi - Frobenius endomorphism x |--> x^(5^2) of Fraction Field of Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - sage: phi == psi + sage: psi = loads(dumps(phi)); psi # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Fraction Field of + Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 + sage: phi == psi # optional - sage.rings.finite_rings True """ slots = RingHomomorphism._extra_slots(self) @@ -2995,12 +3043,14 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 - sage: Frob._repr_() - 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5' + sage: Frob._repr_() # optional - sage.rings.finite_rings + 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5' """ if self._power == 0: s = "Identity endomorphism" @@ -3017,11 +3067,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob._repr_short() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob._repr_short() # optional - sage.rings.finite_rings 'Frob' - sage: (Frob^2)._repr_short() + sage: (Frob^2)._repr_short() # optional - sage.rings.finite_rings 'Frob^2' """ if self._power == 0: @@ -3038,9 +3088,9 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(2) - sage: Frob._latex_() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(2) # optional - sage.rings.finite_rings + sage: Frob._latex_() # optional - sage.rings.finite_rings '\\verb"Frob"^{2}' """ if self._power == 0: @@ -3055,11 +3105,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): """ TESTS:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob(u) + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob(u) # optional - sage.rings.finite_rings u^5 - sage: (Frob^2)(1+u) + sage: (Frob^2)(1 + u) # optional - sage.rings.finite_rings 1 + u^25 """ return x ** self._q @@ -3072,11 +3122,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob.power() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob.power() # optional - sage.rings.finite_rings 1 - sage: (Frob^9).power() + sage: (Frob^9).power() # optional - sage.rings.finite_rings 9 """ return self._power @@ -3087,11 +3137,13 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: Frob^2 - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: Frob^2 # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 """ return self.__class__(self.domain(), self.power()*n) @@ -3101,13 +3153,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: f = K.frobenius_endomorphism(); f - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: g = K.frobenius_endomorphism(2); g - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 - sage: f * g - Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = K.frobenius_endomorphism(); f # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: g = K.frobenius_endomorphism(2); g # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 + sage: f * g # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u + over Finite Field of size 5 """ if isinstance(right, FrobeniusEndomorphism_generic): return self.__class__(self.domain(), self._power + right.power()) @@ -3147,15 +3202,15 @@ def _tensor_product_ring(B, A): sage: from sage.rings.morphism import _tensor_product_ring sage: R. = QQ[] - sage: S. = R.quotient(x^2 + y^2) - sage: Q = _tensor_product_ring(S, R); Q + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: Q = _tensor_product_ring(S, R); Q # optional - sage.libs.singular Quotient of Multivariate Polynomial Ring in u, v, x, y over Rational Field by the ideal (u^2 + v^2) - sage: Q.term_order() + sage: Q.term_order() # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Degree reverse lexicographic term order of length 2) - sage: _tensor_product_ring(R, R) + sage: _tensor_product_ring(R, R) # optional - sage.libs.singular Multivariate Polynomial Ring in y0, y1, x0, x1 over Rational Field TESTS: diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 0f7aa3b2d43..e69e67c39d9 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -49,9 +49,9 @@ True sage: TestSuite(M).run() - sage: H = PowerSeriesRing(PolynomialRing(ZZ,3,'z'),4,'f'); H - Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate - Polynomial Ring in z0, z1, z2 over Integer Ring + sage: H = PowerSeriesRing(PolynomialRing(ZZ, 3, 'z'), 4, 'f'); H + Multivariate Power Series Ring in f0, f1, f2, f3 + over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: TestSuite(H).run() sage: loads(dumps(H)) is H True @@ -75,21 +75,21 @@ - Use angle-bracket notation:: - sage: S. = PowerSeriesRing(GF(65537)); S + sage: S. = PowerSeriesRing(GF(65537)); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s + sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s # optional - sage.rings.finite_rings -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + O(x, y)^5 - sage: s in S + sage: s in S # optional - sage.rings.finite_rings True - sage: TestSuite(S).run() - sage: loads(dumps(S)) is S + sage: TestSuite(S).run() # optional - sage.rings.finite_rings + sage: loads(dumps(S)) is S # optional - sage.rings.finite_rings True - Use double square bracket notation:: sage: ZZ[['s,t,u']] Multivariate Power Series Ring in s, t, u over Integer Ring - sage: GF(127931)[['x,y']] + sage: GF(127931)[['x,y']] # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 127931 Variable ordering determines how series are displayed. @@ -118,15 +118,15 @@ sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field sage: R.base_extend(RR) - Multivariate Power Series Ring in t, u, v over Real Field with 53 - bits of precision + Multivariate Power Series Ring in t, u, v + over Real Field with 53 bits of precision sage: R.change_ring(IntegerModRing(10)) - Multivariate Power Series Ring in t, u, v over Ring of integers - modulo 10 + Multivariate Power Series Ring in t, u, v + over Ring of integers modulo 10 - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) + sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 Coercion from polynomial ring:: @@ -159,19 +159,19 @@ Coercion from symbolic ring:: - sage: x,y = var('x,y') - sage: S = PowerSeriesRing(GF(11),2,'x,y'); S + sage: x,y = var('x,y') # optional - sage.symbolic + sage: S = PowerSeriesRing(GF(11),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: type(x) + sage: type(x) # optional - sage.symbolic - sage: type(S(x)) + sage: type(S(x)) # optional - sage.rings.finite_rings sage.symbolic - sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f + sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f # optional - sage.rings.finite_rings sage.symbolic 5 - x^2 + 4*x*y + y^2 + O(x, y)^3 - sage: f.parent() + sage: f.parent() # optional - sage.rings.finite_rings sage.symbolic Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: f.parent() == S + sage: f.parent() == S # optional - sage.rings.finite_rings sage.symbolic True The implementation of the multivariate power series ring uses a combination @@ -230,12 +230,12 @@ def is_MPowerSeriesRing(x): sage: from sage.rings.power_series_ring import is_PowerSeriesRing sage: from sage.rings.multi_power_series_ring import is_MPowerSeriesRing - sage: M = PowerSeriesRing(ZZ,4,'v') + sage: M = PowerSeriesRing(ZZ, 4, 'v') sage: is_PowerSeriesRing(M) False sage: is_MPowerSeriesRing(M) True - sage: T = PowerSeriesRing(RR,'v') + sage: T = PowerSeriesRing(RR, 'v') sage: is_PowerSeriesRing(T) True sage: is_MPowerSeriesRing(T) @@ -290,7 +290,7 @@ def __classcall__(cls, base_ring, num_gens, name_list, TESTS:: - sage: P1 = PowerSeriesRing(QQ, ['f0','f1','f2','f3'], order = TermOrder('degrevlex')) + sage: P1 = PowerSeriesRing(QQ, ['f0','f1','f2','f3'], order=TermOrder('degrevlex')) sage: P2 = PowerSeriesRing(QQ,4,'f', order='degrevlex') sage: P1 is P2 # indirect doctest True @@ -390,11 +390,11 @@ def _repr_(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) - sage: R #indirect doctest + sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R #indirect doctest # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 17 - sage: R.rename('my multivariate power series ring') - sage: R + sage: R.rename('my multivariate power series ring') # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings my multivariate power series ring """ if self.ngens() == 0: @@ -479,10 +479,10 @@ def characteristic(self): EXAMPLES:: - sage: H = PowerSeriesRing(GF(65537),4,'f'); H + sage: H = PowerSeriesRing(GF(65537),4,'f'); H # optional - sage.rings.finite_rings Multivariate Power Series Ring in f0, f1, f2, f3 over Finite Field of size 65537 - sage: H.characteristic() + sage: H.characteristic() # optional - sage.rings.finite_rings 65537 """ return self.base_ring().characteristic() @@ -493,12 +493,12 @@ def construction(self): EXAMPLES:: - sage: M = PowerSeriesRing(QQ,4,'f'); M + sage: M = PowerSeriesRing(QQ, 4, 'f'); M Multivariate Power Series Ring in f0, f1, f2, f3 over Rational Field sage: (c,R) = M.construction(); (c,R) (Completion[('f0', 'f1', 'f2', 'f3'), prec=12], - Multivariate Polynomial Ring in f0, f1, f2, f3 over Rational Field) + Multivariate Polynomial Ring in f0, f1, f2, f3 over Rational Field) sage: c Completion[('f0', 'f1', 'f2', 'f3'), prec=12] sage: c(R) @@ -555,10 +555,10 @@ def change_ring(self, R): TypeError: no base extension defined - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) + sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 """ return PowerSeriesRing(R, names = self.variable_names(), default_prec = self.default_prec()) @@ -578,16 +578,16 @@ def remove_var(self, *var): Power Series Ring in u over Integer Ring - sage: M = PowerSeriesRing(GF(5),5,'t'); M - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over - Finite Field of size 5 - sage: M.remove_var(M.gens()[3]) - Multivariate Power Series Ring in t0, t1, t2, t4 over Finite - Field of size 5 + sage: M = PowerSeriesRing(GF(5),5,'t'); M # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 5 + sage: M.remove_var(M.gens()[3]) # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t4 + over Finite Field of size 5 Removing all variables results in the base ring:: - sage: M.remove_var(*M.gens()) + sage: M.remove_var(*M.gens()) # optional - sage.rings.finite_rings Finite Field of size 5 """ @@ -636,10 +636,10 @@ def _coerce_impl(self, f): sage: R(f2) -2*v^2 + 5*u*v^2 + O(t, u, v)^6 - sage: R2 = R.change_ring(GF(2)) - sage: R2(f1) + sage: R2 = R.change_ring(GF(2)) # optional - sage.rings.finite_rings + sage: R2(f1) # optional - sage.rings.finite_rings v + t*v - sage: R2(f2) + sage: R2(f2) # optional - sage.rings.finite_rings u*v^2 + O(t, u, v)^6 TESTS:: @@ -676,8 +676,8 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = PowerSeriesRing(Zmod(8)); R - Multivariate Power Series Ring in a, b, c over Ring of integers - modulo 8 + Multivariate Power Series Ring in a, b, c + over Ring of integers modulo 8 sage: M = PowerSeriesRing(ZZ,3,'x,y,z') sage: M._is_valid_homomorphism_(R,[a,c,b]) True @@ -711,13 +711,13 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): from the base ring to the codomain:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: Q8. = CyclotomicField(8) - sage: X. = PowerSeriesRing(Q8) - sage: M. = PowerSeriesRing(K) - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: Q8. = CyclotomicField(8) # optional - sage.rings.number_field + sage: X. = PowerSeriesRing(Q8) # optional - sage.rings.number_field + sage: M. = PowerSeriesRing(K) # optional - sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion # optional - sage.rings.number_field False - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) # optional - sage.rings.number_field True """ try: @@ -759,32 +759,32 @@ def _coerce_map_from_(self, P): EXAMPLES:: - sage: A = GF(17)[['x','y']] - sage: A.has_coerce_map_from(ZZ) + sage: A = GF(17)[['x','y']] # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x']) + sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['y','x']) + sage: A.has_coerce_map_from(ZZ['y','x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ[['x']]) + sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ[['y','x']]) + sage: A.has_coerce_map_from(ZZ[['y','x']]) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x','z']) + sage: A.has_coerce_map_from(ZZ['x','z']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(GF(3)['x','y']) + sage: A.has_coerce_map_from(GF(3)['x','y']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) + sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) # optional - sage.rings.finite_rings False TESTS:: - sage: M = PowerSeriesRing(ZZ,3,'x,y,z') + sage: M = PowerSeriesRing(ZZ, 3, 'x,y,z') sage: M._coerce_map_from_(M) True - sage: M._coerce_map_from_(M.remove_var(x)) + sage: M._coerce_map_from_(M.remove_var(x)) # optional - sage.symbolic True - sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) + sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) # optional - sage.symbolic True sage: M._coerce_map_from_(PolynomialRing(ZZ,'x,z')) True @@ -802,7 +802,8 @@ def _coerce_map_from_(self, P): sage: P = PolynomialRing(ZZ,3,'z') sage: H = PowerSeriesRing(P,4,'f'); H - Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring + Multivariate Power Series Ring in f0, f1, f2, f3 over + Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: H._coerce_map_from_(P) True sage: H._coerce_map_from_(P.remove_var(P.gen(1))) @@ -921,11 +922,11 @@ def is_sparse(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,3,'s,t,u'); M + sage: M = PowerSeriesRing(ZZ, 3, 's,t,u'); M Multivariate Power Series Ring in s, t, u over Integer Ring sage: M.is_sparse() False - sage: N = PowerSeriesRing(ZZ,3,'s,t,u',sparse=True); N + sage: N = PowerSeriesRing(ZZ, 3, 's,t,u', sparse=True); N Sparse Multivariate Power Series Ring in s, t, u over Integer Ring sage: N.is_sparse() True @@ -938,11 +939,11 @@ def is_dense(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,3,'s,t,u'); M + sage: M = PowerSeriesRing(ZZ, 3, 's,t,u'); M Multivariate Power Series Ring in s, t, u over Integer Ring sage: M.is_dense() True - sage: N = PowerSeriesRing(ZZ,3,'s,t,u',sparse=True); N + sage: N = PowerSeriesRing(ZZ, 3, 's,t,u', sparse=True); N Sparse Multivariate Power Series Ring in s, t, u over Integer Ring sage: N.is_dense() False @@ -955,7 +956,7 @@ def gen(self, n=0): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,10,'v') + sage: M = PowerSeriesRing(ZZ, 10, 'v') sage: M.gen(6) v6 """ @@ -970,7 +971,7 @@ def ngens(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,10,'v') + sage: M = PowerSeriesRing(ZZ, 10, 'v') sage: M.ngens() 10 """ @@ -986,8 +987,8 @@ def prec_ideal(self): sage: A. = PowerSeriesRing(ZZ) sage: A.prec_ideal() - Ideal (s, t, u) of Multivariate Polynomial Ring in s, t, u over - Integer Ring + Ideal (s, t, u) of + Multivariate Polynomial Ring in s, t, u over Integer Ring """ return self._poly_ring().ideal(self._poly_ring().gens()) diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 91ac18389c2..b70abc0ac92 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -29,7 +29,7 @@ sage: f*g - g 2*s^2*t^2 + O(s, t)^5 - sage: f*=s; f + sage: f *= s; f s + 2*s^2 + 3*s^3 + O(s, t)^8 sage: f%2 s + s^3 + O(s, t)^8 @@ -56,43 +56,43 @@ sage: f = s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + R.O(5); f s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + O(s, t)^5 - sage: f(t,s) + sage: f(t, s) s*t + t^2 + s*t^2 + t^3 + 3*s*t^3 + 3*t^4 + O(s, t)^5 - sage: f(t^2,s^2) + sage: f(t^2, s^2) s^2*t^2 + t^4 + s^2*t^4 + t^6 + 3*s^2*t^6 + 3*t^8 + O(s, t)^10 Substitution is defined only for elements of positive valuation, unless `f` has infinite precision:: - sage: f(t^2,s^2+1) + sage: f(t^2, s^2 + 1) Traceback (most recent call last): ... TypeError: Substitution defined only for elements of positive valuation, unless self has infinite precision. sage: g = f.truncate() - sage: g(t^2,s^2+1) + sage: g(t^2, s^2 + 1) t^2 + s^2*t^2 + 2*t^4 + s^2*t^4 + 4*t^6 + 3*s^2*t^6 + 3*t^8 - sage: g(t^2,(s^2+1).O(3)) + sage: g(t^2, (s^2+1).O(3)) t^2 + s^2*t^2 + 2*t^4 + O(s, t)^5 0 has valuation ``+Infinity``:: - sage: f(t^2,0) + sage: f(t^2, 0) t^4 + t^6 + 3*t^8 + O(s, t)^10 - sage: f(t^2,s^2+s) + sage: f(t^2, s^2 + s) s*t^2 + s^2*t^2 + t^4 + O(s, t)^5 Substitution of power series with finite precision works too:: - sage: f(s.O(2),t) + sage: f(s.O(2), t) s^2 + s*t + O(s, t)^3 - sage: f(f,f) + sage: f(f, f) 2*s^4 + 4*s^3*t + 2*s^2*t^2 + 4*s^5 + 8*s^4*t + 4*s^3*t^2 + 16*s^6 + 34*s^5*t + 20*s^4*t^2 + 2*s^3*t^3 + O(s, t)^7 - sage: t(f,f) + sage: t(f, f) s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + O(s, t)^5 - sage: t(0,f) == s(f,0) + sage: t(0, f) == s(f, 0) True The ``subs`` syntax works as expected:: @@ -100,10 +100,10 @@ sage: r0 = -t^2 - s*t^3 - 2*t^6 + s^7 + s^5*t^2 + R.O(10) sage: r1 = s^4 - s*t^4 + s^6*t - 4*s^2*t^5 - 6*s^3*t^5 + R.O(10) sage: r2 = 2*s^3*t^2 - 2*s*t^4 - 2*s^3*t^4 + s*t^7 + R.O(10) - sage: r0.subs({t:r2,s:r1}) + sage: r0.subs({t: r2, s: r1}) -4*s^6*t^4 + 8*s^4*t^6 - 4*s^2*t^8 + 8*s^6*t^6 - 8*s^4*t^8 - 4*s^4*t^9 + 4*s^2*t^11 - 4*s^6*t^8 + O(s, t)^15 - sage: r0.subs({t:r2,s:r1}) == r0(r1,r2) + sage: r0.subs({t: r2, s: r1}) == r0(r1, r2) True Construct ring homomorphisms from one power series ring to another:: @@ -253,19 +253,19 @@ class MPowerSeries(PowerSeries): 1 + s + t - s*t + O(s, t)^5 - sage: T = PowerSeriesRing(GF(3),5,'t'); T - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite - Field of size 3 - sage: t = T.gens() - sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w + sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.libs.pari + 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 t0 + t1*t3 - t4^3 - t0^3*t2^2 - sage: w = w.add_bigoh(5); w + sage: w = w.add_bigoh(5); w # optional - sage.libs.pari t0 + t1*t3 - t4^3 + O(t0, t1, t2, t3, t4)^5 - sage: w in T + sage: w in T # optional - sage.libs.pari True - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) - sage: w + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.libs.pari + sage: w # optional - sage.libs.pari t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 @@ -274,20 +274,20 @@ class MPowerSeries(PowerSeries): sage: S.random_element(4) # random -2*t + t^2 - 12*s^3 + O(s, t)^4 - sage: T.random_element(10) # random + sage: T.random_element(10) # random # optional - sage.libs.pari -t1^2*t3^2*t4^2 + t1^5*t3^3*t4 + O(t0, t1, t2, t3, t4)^10 Convert elements from polynomial rings:: - sage: R = PolynomialRing(ZZ,5,T.variable_names()) - sage: t = R.gens() - sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2 - sage: T(r) + sage: R = PolynomialRing(ZZ, 5, T.variable_names()) # optional - sage.libs.pari + sage: t = R.gens() # optional - sage.libs.pari + sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2 # optional - sage.libs.pari + sage: T(r) # optional - sage.libs.pari -t2*t3 + t3^2 + t4^2 - sage: r.parent() + sage: r.parent() # optional - sage.libs.pari Multivariate Polynomial Ring in t0, t1, t2, t3, t4 over Integer Ring - sage: r in T + sage: r in T # optional - sage.libs.pari True """ @@ -313,10 +313,11 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False): sage: g.parent() Multivariate Power Series Ring in s, t over Rational Field - sage: K = NumberField(x-3,'a') - sage: g = K.random_element()*f - sage: g.parent() - Multivariate Power Series Ring in s, t over Number Field in a with defining polynomial x - 3 + sage: K = NumberField(x - 3,'a') # optional - sage.rings.number_field + sage: g = K.random_element()*f # optional - sage.rings.number_field + sage: g.parent() # optional - sage.rings.number_field + Multivariate Power Series Ring in s, t over + Number Field in a with defining polynomial x - 3 TESTS:: @@ -450,20 +451,20 @@ def __call__(self, *x, **kwds): Checking that :trac:`15059` is fixed:: - sage: M. = PowerSeriesRing(GF(5)) - sage: s = M.hom([u, u+v]) - sage: s(M.one()) + sage: M. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari + sage: s = M.hom([u, u+v]) # optional - sage.libs.pari + sage: s(M.one()) # optional - sage.libs.pari 1 Since :trac:`26105` you can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = PowerSeriesRing(K) - sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = PowerSeriesRing(K) # optional - sage.rings.number_field + sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f # optional - sage.rings.number_field s^2 + i*s*t + (4*i + 3)*s^3 + O(s, t)^4 - sage: f(t, s, base_map=cc) + sage: f(t, s, base_map=cc) # optional - sage.rings.number_field (-i)*s*t + t^2 + (-4*i + 3)*t^3 + O(s, t)^4 """ if len(x) != self.parent().ngens(): @@ -566,14 +567,14 @@ def _value(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R + sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.libs.pari Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = 1 + a + b - a*b + R.O(3); f + sage: f = 1 + a + b - a*b + R.O(3); f # optional - sage.libs.pari 1 + a + b - a*b + O(a, b, c)^3 - sage: f._value() + sage: f._value() # optional - sage.libs.pari 1 + a + b - a*b - sage: f._value().parent() + sage: f._value().parent() # optional - sage.libs.pari Multivariate Polynomial Ring in a, b, c over Finite Field of size 5 """ return self._go_to_fg(self._bg_value) @@ -602,15 +603,15 @@ def _latex_(self): EXAMPLES:: - sage: M = PowerSeriesRing(GF(5),3,'t'); M + sage: M = PowerSeriesRing(GF(5),3,'t'); M # optional - sage.libs.pari Multivariate Power Series Ring in t0, t1, t2 over Finite Field of size 5 - sage: t = M.gens() - sage: f = -t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 \ - + 2*t[1]*t[2]^12 + 2*t[0]^7*t[1]^5*t[2]^2 + M.O(15) - sage: f + sage: t = M.gens() # optional - sage.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 -t0^4*t1^3*t2^4 - 2*t0*t1^4*t2^7 + 2*t1*t2^12 + 2*t0^7*t1^5*t2^2 + O(t0, t1, t2)^15 - sage: f._latex_() + sage: f._latex_() # optional - sage.libs.pari '-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}' @@ -709,30 +710,30 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R + sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.libs.pari Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = a + b + c + a^2*c - sage: f == f^2 + sage: f = a + b + c + a^2*c # optional - sage.libs.pari + sage: f == f^2 # optional - sage.libs.pari False - sage: f = f.truncate() - sage: f == f.O(4) + sage: f = f.truncate() # optional - sage.libs.pari + sage: f == f.O(4) # optional - sage.libs.pari True Ordering is determined by underlying polynomial ring:: - sage: a > b + sage: a > b # optional - sage.libs.pari True - sage: a > a^2 + sage: a > a^2 # optional - sage.libs.pari True - sage: b > a^2 + sage: b > a^2 # optional - sage.libs.pari True - sage: (f^2).O(3) + sage: (f^2).O(3) # optional - sage.libs.pari a^2 + 2*a*b + 2*a*c + b^2 + 2*b*c + c^2 + O(a, b, c)^3 - sage: f < f^2 + sage: f < f^2 # optional - sage.libs.pari False - sage: f > f^2 + sage: f > f^2 # optional - sage.libs.pari True - sage: f < 2*f + sage: f < 2*f # optional - sage.libs.pari True """ return richcmp(self._bg_value, other._bg_value, op) @@ -896,22 +897,22 @@ def quo_rem(self, other, precision=None): sage: g = 1 + 2*a - 3*a*b + R.O(3) sage: q, r = f.quo_rem(g); q, r (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^3) - sage: f == q*g+r + sage: f == q*g + r True sage: q, r = (a*f).quo_rem(g); q, r (a - a^2 + a*b + 2*a^3 + O(a, b, c)^4, 0 + O(a, b, c)^4) - sage: a*f == q*g+r + sage: a*f == q*g + r True - sage: q, r = (a*f).quo_rem(a*g); q, r + sage: q, r = (a*f).quo_rem(a*g); q, r # optional - sage.libs.singular (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^4) - sage: a*f == q*(a*g)+r + sage: a*f == q*(a*g) + r # optional - sage.libs.singular True - sage: q, r = (a*f).quo_rem(b*g); q, r + sage: q, r = (a*f).quo_rem(b*g); q, r # optional - sage.libs.singular (a - 3*a^2 + O(a, b, c)^3, a + a^2 + O(a, b, c)^4) - sage: a*f == q*(b*g)+r + sage: a*f == q*(b*g) + r # optional - sage.libs.singular True Trying to divide two polynomials, we run into the issue that @@ -920,59 +921,61 @@ def quo_rem(self, other, precision=None): algorithm would never terminate). Here, default precision comes to our help:: - sage: (1+a^3).quo_rem(a+a^2) - (a^2 - a^3 + a^4 - a^5 + a^6 - a^7 + a^8 - a^9 + a^10 + O(a, b, c)^11, 1 + O(a, b, c)^12) + sage: (1 + a^3).quo_rem(a + a^2) # optional - sage.libs.singular + (a^2 - a^3 + a^4 - a^5 + a^6 - a^7 + a^8 - a^9 + a^10 + O(a, b, c)^11, + 1 + O(a, b, c)^12) - sage: (1+a^3+a*b).quo_rem(b+c) + sage: (1 + a^3 + a*b).quo_rem(b + c) # optional - sage.libs.singular (a + O(a, b, c)^11, 1 - a*c + a^3 + O(a, b, c)^12) - sage: (1+a^3+a*b).quo_rem(b+c, precision=17) + sage: (1 + a^3 + a*b).quo_rem(b + c, precision=17) # optional - sage.libs.singular (a + O(a, b, c)^16, 1 - a*c + a^3 + O(a, b, c)^17) - sage: (a^2+b^2+c^2).quo_rem(a+b+c) + sage: (a^2 + b^2 + c^2).quo_rem(a + b + c) # optional - sage.libs.singular (a - b - c + O(a, b, c)^11, 2*b^2 + 2*b*c + 2*c^2 + O(a, b, c)^12) - sage: (a^2+b^2+c^2).quo_rem(1/(1+a+b+c)) - (a^2 + b^2 + c^2 + a^3 + a^2*b + a^2*c + a*b^2 + a*c^2 + b^3 + b^2*c + b*c^2 + c^3 + O(a, b, c)^14, + sage: (a^2 + b^2 + c^2).quo_rem(1/(1+a+b+c)) # optional - sage.libs.singular + (a^2 + b^2 + c^2 + a^3 + a^2*b + a^2*c + a*b^2 + a*c^2 + + b^3 + b^2*c + b*c^2 + c^3 + O(a, b, c)^14, 0) - sage: (a^2+b^2+c^2).quo_rem(a/(1+a+b+c)) + sage: (a^2 + b^2 + c^2).quo_rem(a/(1+a+b+c)) # optional - sage.libs.singular (a + a^2 + a*b + a*c + O(a, b, c)^13, b^2 + c^2) - sage: (1+a+a^15).quo_rem(a^2) + sage: (1 + a + a^15).quo_rem(a^2) # optional - sage.libs.singular (0 + O(a, b, c)^10, 1 + a + O(a, b, c)^12) - sage: (1+a+a^15).quo_rem(a^2, precision=15) + sage: (1 + a + a^15).quo_rem(a^2, precision=15) # optional - sage.libs.singular (0 + O(a, b, c)^13, 1 + a + O(a, b, c)^15) - sage: (1+a+a^15).quo_rem(a^2, precision=16) + sage: (1 + a + a^15).quo_rem(a^2, precision=16) # optional - sage.libs.singular (a^13 + O(a, b, c)^14, 1 + a + O(a, b, c)^16) Illustrating the dependency on the ordering of variables:: - sage: (1+a+b).quo_rem(b+c) + sage: (1 + a + b).quo_rem(b + c) # optional - sage.libs.singular (1 + O(a, b, c)^11, 1 + a - c + O(a, b, c)^12) - sage: (1+b+c).quo_rem(c+a) + sage: (1 + b + c).quo_rem(c + a) # optional - sage.libs.singular (0 + O(a, b, c)^11, 1 + b + c + O(a, b, c)^12) - sage: (1+c+a).quo_rem(a+b) + sage: (1 + c + a).quo_rem(a + b) # optional - sage.libs.singular (1 + O(a, b, c)^11, 1 - b + c + O(a, b, c)^12) TESTS:: - sage: (f).quo_rem(R.zero()) + sage: (f).quo_rem(R.zero()) # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError - sage: (f).quo_rem(R.zero().add_bigoh(2)) + sage: (f).quo_rem(R.zero().add_bigoh(2)) # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError Coercion is applied on ``other``:: - sage: (a+b).quo_rem(1) + sage: (a + b).quo_rem(1) # optional - sage.libs.singular (a + b + O(a, b, c)^12, 0 + O(a, b, c)^12) sage: R. = PowerSeriesRing(QQ) - sage: R(3).quo_rem(2) + sage: R(3).quo_rem(2) # optional - sage.libs.singular (3/2 + O(a, b, c)^12, 0 + O(a, b, c)^12) """ parent = self.parent() @@ -1036,30 +1039,30 @@ def _div_(self, denom_r): When possible, division by non-units also works:: - sage: a/(a*f) + sage: a/(a*f) # optional - sage.libs.singular 1 - a - b + a^2 + 3*a*b + b^2 + O(a, b, c)^3 - sage: a/(R.zero()) + sage: a/(R.zero()) # optional - sage.libs.singular Traceback (most recent call last): ZeroDivisionError - sage: (a*f)/f + sage: (a*f)/f # optional - sage.libs.singular a + O(a, b, c)^4 - sage: f/(a*f) + sage: f/(a*f) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: not divisible An example where one loses precision:: - sage: ((1+a)*f - f) / a*f + sage: ((1+a)*f - f) / a*f # optional - sage.libs.singular 1 + 2*a + 2*b + O(a, b, c)^2 TESTS:: - sage: ((a+b)*f) / f == (a+b) + sage: ((a+b)*f) / f == (a+b) # optional - sage.libs.singular True - sage: ((a+b)*f) / (a+b) == f + sage: ((a+b)*f) / (a+b) == f # optional - sage.libs.singular True """ if denom_r.is_unit(): # faster if denom_r is a unit @@ -1082,7 +1085,7 @@ def __mod__(self, other): False sage: g in R.base_extend(Zmod(2)) True - sage: g.polynomial() == f.polynomial() % 2 + sage: g.polynomial() == f.polynomial() % 2 # optional - sage.libs.singular True """ if isinstance(other, (int, Integer)): @@ -1157,14 +1160,14 @@ def variables(self): EXAMPLES:: - sage: T = PowerSeriesRing(GF(3),5,'t'); T + 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 = T.gens() - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) - sage: w + sage: t = T.gens() # optional - sage.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 t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 - sage: w.variables() + sage: w.variables() # optional - sage.libs.pari (t0, t2, t4) """ return tuple(self.parent(v) for v in self._value().variables()) @@ -1394,16 +1397,16 @@ def valuation(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(4949717)); R - Multivariate Power Series Ring in a, b over Finite Field of - size 4949717 - sage: f = a^2 + a*b + a^3 + R.O(9) - sage: f.valuation() + sage: R. = PowerSeriesRing(GF(4949717)); R # optional - sage.libs.pari + 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 2 - sage: g = 1 + a + a^3 - sage: g.valuation() + sage: g = 1 + a + a^3 # optional - sage.libs.pari + sage: g.valuation() # optional - sage.libs.pari 0 - sage: R.zero().valuation() + sage: R.zero().valuation() # optional - sage.libs.pari +Infinity """ try: @@ -1443,8 +1446,7 @@ def is_nilpotent(self): EXAMPLES:: sage: R. = PowerSeriesRing(Zmod(8)); R - Multivariate Power Series Ring in a, b, c over Ring of integers - modulo 8 + Multivariate Power Series Ring in a, b, c over Ring of integers modulo 8 sage: f = a + b + c + a^2*c sage: f.is_nilpotent() False @@ -1537,7 +1539,7 @@ def is_square(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.is_square() Traceback (most recent call last): @@ -1553,7 +1555,7 @@ def square_root(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.square_root() Traceback (most recent call last): @@ -1571,7 +1573,7 @@ def derivative(self, *args): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a^2*b + T.O(5) sage: f.derivative(a) 1 + 2*a*b + O(a, b)^4 @@ -1604,7 +1606,7 @@ def integral(self, *args): EXAMPLES:: - sage: T. = PowerSeriesRing(QQ,2) + sage: T. = PowerSeriesRing(QQ, 2) sage: f = a + b + a^2*b + T.O(5) sage: f.integral(a, 2) 1/6*a^3 + 1/2*a^2*b + 1/12*a^4*b + O(a, b)^7 @@ -1615,7 +1617,7 @@ def integral(self, *args): Only integration with respect to variables works:: - sage: f.integral(a+b) + sage: f.integral(a + b) Traceback (most recent call last): ... ValueError: a + b is not a variable @@ -1628,7 +1630,7 @@ def integral(self, *args): first case, Sage will report that it has not been able to coerce some coefficient to the base ring:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + T.O(5) sage: f.integral(a) Traceback (most recent call last): @@ -1650,7 +1652,7 @@ def integral(self, *args): In non-zero characteristic, Sage will report that a zero division occurred :: - sage: T. = PowerSeriesRing(Zmod(3),2) + sage: T. = PowerSeriesRing(Zmod(3), 2) sage: (a^3).integral(a) a^4 sage: (a^2).integral(a) @@ -1726,7 +1728,7 @@ def ogf(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.ogf() Traceback (most recent call last): @@ -1741,7 +1743,7 @@ def egf(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.egf() Traceback (most recent call last): @@ -1756,7 +1758,7 @@ def __pari__(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__pari__() Traceback (most recent call last): @@ -1777,7 +1779,7 @@ def list(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.list() Traceback (most recent call last): @@ -1795,7 +1797,7 @@ def variable(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.variable() Traceback (most recent call last): @@ -1811,7 +1813,7 @@ def shift(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.shift(3) Traceback (most recent call last): @@ -1826,7 +1828,7 @@ def __lshift__(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__lshift__(3) Traceback (most recent call last): @@ -1841,7 +1843,7 @@ def __rshift__(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__rshift__(3) Traceback (most recent call last): @@ -1857,7 +1859,7 @@ def valuation_zero_part(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.valuation_zero_part() Traceback (most recent call last): @@ -1873,7 +1875,7 @@ def solve_linear_de(self, prec=infinity, b=None, f0=None): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.solve_linear_de() Traceback (most recent call last): @@ -1898,15 +1900,15 @@ def exp(self, prec=infinity): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(3) - sage: exp(f) + sage: exp(f) # optional - sage.symbolic 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 sage: f.exp() 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 sage: f.exp(prec=2) 1 + a + b + O(a, b)^2 - sage: log(exp(f)) - f + sage: log(exp(f)) - f # optional - sage.symbolic 0 + O(a, b)^3 If the power series has a constant coefficient `c` and @@ -1914,8 +1916,8 @@ def exp(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f - sage: exp(g) + sage: g = 2 + f + sage: exp(g) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and @@ -1925,7 +1927,7 @@ def exp(self, prec=infinity): Another workaround for this limitation is to change base ring to one which is closed under exponentiation, such as `\RR` or `\CC`:: - sage: exp(g.change_ring(RDF)) + sage: exp(g.change_ring(RDF)) # optional - sage.symbolic 7.38905609... + 7.38905609...*a + 7.38905609...*b + 3.69452804...*a^2 + 14.7781121...*a*b + 3.69452804...*b^2 + O(a, b)^3 @@ -1933,17 +1935,17 @@ def exp(self, prec=infinity): sage: T.default_prec() 12 - sage: exp(a) + sage: exp(a) # optional - sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + 1/120*a^5 + 1/720*a^6 + 1/5040*a^7 + 1/40320*a^8 + 1/362880*a^9 + 1/3628800*a^10 + 1/39916800*a^11 + O(a, b)^12 sage: a.exp(prec=5) 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 - sage: exp(a + T.O(5)) + sage: exp(a + T.O(5)) # optional - sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: exp(a^2 + T.O(5)) + sage: exp(a^2 + T.O(5)) # optional - sage.symbolic 1 + a^2 + 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1990,7 +1992,7 @@ def log(self, prec=infinity): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = 1 + a + b + a*b + T.O(5) sage: f.log() a + b - 1/2*a^2 - 1/2*b^2 + 1/3*a^3 + 1/3*b^3 - 1/4*a^4 - 1/4*b^4 + O(a, b)^5 @@ -2004,7 +2006,7 @@ def log(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f + sage: g = 2 + f sage: log(g) Traceback (most recent call last): ... @@ -2095,7 +2097,7 @@ class MO(): sage: m^1 0 + O(u, v)^1 - sage: T. = PowerSeriesRing(ZZ,3) + sage: T. = PowerSeriesRing(ZZ, 3) sage: z = O(a, b, c) sage: z^1 0 + O(a, b, c)^1 diff --git a/src/sage/rings/number_field/number_field_base.pyx b/src/sage/rings/number_field/number_field_base.pyx index dd9a8b9d550..852811c132e 100644 --- a/src/sage/rings/number_field/number_field_base.pyx +++ b/src/sage/rings/number_field/number_field_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.number_field """ Base class for all number fields diff --git a/src/sage/rings/number_field/number_field_element_base.pyx b/src/sage/rings/number_field/number_field_element_base.pyx index 5385833f1d4..c4938237a6d 100644 --- a/src/sage/rings/number_field/number_field_element_base.pyx +++ b/src/sage/rings/number_field/number_field_element_base.pyx @@ -20,8 +20,8 @@ cdef class NumberFieldElement_base(FieldElement): EXAMPLES:: - sage: k. = NumberField(x^3 + x + 1) - sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) + sage: k. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field + sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/numbers_abc.py b/src/sage/rings/numbers_abc.py index 478a0b36408..6bbcddccf40 100644 --- a/src/sage/rings/numbers_abc.py +++ b/src/sage/rings/numbers_abc.py @@ -57,10 +57,10 @@ def register_sage_classes(): Because we do this, NumPy's ``isscalar()`` recognizes Sage types:: - sage: from numpy import isscalar - sage: isscalar(3.141) + sage: from numpy import isscalar # optional - numpy + sage: isscalar(3.141) # optional - numpy True - sage: isscalar(4/17) + sage: isscalar(4/17) # optional - numpy True """ from sage.misc.superseded import deprecation diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 818243aa271..7a035943e64 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -18,7 +18,7 @@ x_3 sage: b y_4 - sage: c = a*b+a^3-2*b^4 + sage: c = a*b + a^3 - 2*b^4 sage: c x_3^3 + x_3*y_4 - 2*y_4^4 @@ -299,15 +299,16 @@ def polynomial(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(GF(7)) - sage: p = x[2]*y[1]+3*y[0] - sage: p + sage: X. = InfinitePolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: p = x[2]*y[1] + 3*y[0] # optional - sage.rings.finite_rings + sage: p # optional - sage.rings.finite_rings x_2*y_1 + 3*y_0 - sage: p.polynomial() + sage: p.polynomial() # optional - sage.rings.finite_rings x_2*y_1 + 3*y_0 - sage: p.polynomial().parent() - Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 over Finite Field of size 7 - sage: p.parent() + sage: p.polynomial().parent() # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 + over Finite Field of size 7 + sage: p.parent() # optional - sage.rings.finite_rings Infinite polynomial ring in x, y over Finite Field of size 7 """ @@ -439,13 +440,13 @@ def subs(self, fixed=None, **kwargs): The substitution can also handle matrices:: - sage: M = matrix([[1,0],[0,2]]) - sage: N = matrix([[0,3],[4,0]]) - sage: g = x[0]^2 + 3*x[1] - sage: g.subs({'x_0': M}) + sage: M = matrix([[1,0], [0,2]]) # optional - sage.modules + sage: N = matrix([[0,3], [4,0]]) # optional - sage.modules + sage: g = x[0]^2 + 3*x[1] # optional - sage.modules + sage: g.subs({'x_0': M}) # optional - sage.modules [3*x_1 + 1 0] [ 0 3*x_1 + 4] - sage: g.subs({x[0]: M, x[1]: N}) + sage: g.subs({x[0]: M, x[1]: N}) # optional - sage.modules [ 1 9] [12 4] @@ -454,11 +455,11 @@ def subs(self, fixed=None, **kwargs): sage: R. = InfinitePolynomialRing(QQ) sage: f = x[0] - sage: f.subs({x[0]:1}) + sage: f.subs({x[0]: 1}) 1 sage: f.subs(x_0=5) 5 - sage: f.subs({x[0]:1}, x_0=5) + sage: f.subs({x[0]: 1}, x_0=5) 1 TESTS:: @@ -539,10 +540,10 @@ def is_nilpotent(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(QQbar) - sage: (x[0]+x[1]).is_nilpotent() + sage: R. = InfinitePolynomialRing(QQbar) # optional - sage.rings.number_field + sage: (x[0] + x[1]).is_nilpotent() # optional - sage.rings.number_field False - sage: R(0).is_nilpotent() + sage: R(0).is_nilpotent() # optional - sage.rings.number_field True sage: _. = InfinitePolynomialRing(Zmod(4)) sage: (2*x[0]).is_nilpotent() @@ -895,11 +896,11 @@ def symmetric_cancellation_order(self, other): sage: X. = InfinitePolynomialRing(QQ) sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]^2) (None, 1, 1) - sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) + sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) # optional - sage.combinat (-1, [2, 3, 1], y_1) - sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) + sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) # optional - sage.combinat (None, 1, 1) - sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[2]) + sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[2]) # optional - sage.combinat (-1, [2, 3, 1], 1) """ @@ -1255,8 +1256,8 @@ def __call__(self, *args, **kwargs): sage: a(x_1=x[100]) x_100 + x_0 - sage: M = matrix([[1,1],[2,0]]) - sage: a(x_1=M) + sage: M = matrix([[1,1], [2,0]]) # optional - sage.modules + sage: a(x_1=M) # optional - sage.modules [x_0 + 1 1] [ 2 x_0] """ @@ -1384,10 +1385,10 @@ def __pow__(self, n): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: p = x[10]*y[2]+2*x[1]*y[3] - sage: P = Permutation(((1,2),(3,4,5))) - sage: p^P # indirect doctest + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: p = x[10]*y[2] + 2*x[1]*y[3] + sage: P = Permutation(((1,2),(3,4,5))) # optional - sage.combinat + sage: p^P # indirect doctest # optional - sage.combinat x_10*y_1 + 2*x_2*y_4 """ @@ -1477,10 +1478,10 @@ def _richcmp_(self, x, op): An example in which a previous version had failed:: - sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') - sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') - sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') - sage: p < q # indirect doctest + sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') # optional - sage.rings.finite_rings + sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') # optional - sage.rings.finite_rings + sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') # optional - sage.rings.finite_rings + sage: p < q # indirect doctest # optional - sage.rings.finite_rings False """ @@ -1534,7 +1535,7 @@ def __call__(self, *args, **kwargs): sage: X. = InfinitePolynomialRing(QQ) sage: a = x[0] + x[1] - sage: a(x_0=2,x_1=x[1]) + sage: a(x_0=2, x_1=x[1]) x_1 + 2 sage: _.parent() Infinite polynomial ring in x over Rational Field @@ -1569,7 +1570,7 @@ def _richcmp_(self, x, op): A classical and an infinite polynomial ring:: - sage: X. = InfinitePolynomialRing(ZZ,order='degrevlex') + sage: X. = InfinitePolynomialRing(ZZ, order='degrevlex') sage: Y. = QQ[] sage: x[3] == x_3 True @@ -1577,16 +1578,16 @@ def _richcmp_(self, x, op): Two infinite polynomial rings with different order and implementation:: - sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex',implementation='sparse') + sage: Y = InfinitePolynomialRing(QQ,['x','y'], order='deglex', implementation='sparse') sage: x[2] == Y(x[2]) True An example in which a previous version had failed:: - sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='dense') - sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') - sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') - sage: p < q + sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='dense') # optional - sage.rings.finite_rings + sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') # optional - sage.rings.finite_rings + sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') # optional - sage.rings.finite_rings + sage: p < q # optional - sage.rings.finite_rings False """ @@ -1664,9 +1665,9 @@ def __pow__(self, n): sage: X. = InfinitePolynomialRing(QQ) sage: x[10]^3 x_10^3 - sage: p = x[10]*y[2]+2*x[1]*y[3] - sage: P = Permutation(((1,2),(3,4,5))) - sage: p^P + sage: p = x[10]*y[2] + 2*x[1]*y[3] + sage: P = Permutation(((1,2),(3,4,5))) # optional - sage.combinat + sage: p^P # optional - sage.combinat x_10*y_1 + 2*x_2*y_4 """ diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index f9441c08cde..b9318c36d49 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -71,11 +71,12 @@ sage: g2 = 3*beta[1]; g2 3*beta_1 sage: A.polynomial_ring() - Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0, beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field + Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0, + beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field Of course, we provide the usual polynomial arithmetic:: - sage: f+g + sage: f + g x_5 + 3*y_1 + 2 sage: p = x[10]^2*(f+g); p x_10^2*x_5 + 3*x_10^2*y_1 + 2*x_10^2 @@ -85,10 +86,10 @@ There is a permutation action on the variables, by permuting positive variable indices:: - sage: P = Permutation(((10,1))) - sage: p^P + sage: P = Permutation(((10,1))) # optional - sage.combinat + sage: p^P # optional - sage.combinat x_5*x_1^2 + 3*x_1^2*y_10 + 2*x_1^2 - sage: p2^P + sage: p2^P # optional - sage.combinat alpha_5*alpha_1^2 + 3*alpha_1^2*beta_10 + 2*alpha_1^2 Note that `x_0^P = x_0`, since the permutations only change *positive* @@ -126,7 +127,8 @@ sage: A. = ZZ[] sage: B. = InfinitePolynomialRing(A, order='degrevlex') sage: B - Infinite polynomial ring in b, c, d over Multivariate Polynomial Ring in a_3, a_1 over Integer Ring + Infinite polynomial ring in b, c, d over + Multivariate Polynomial Ring in a_3, a_1 over Integer Ring It is no problem if one generator of the Infinite Polynomial Ring is called ``x`` and one variable of the base ring is also called @@ -144,7 +146,8 @@ :: sage: Y - Infinite polynomial ring in x, z over Multivariate Polynomial Ring in x, y_1 over Integer Ring + Infinite polynomial ring in x, z over + Multivariate Polynomial Ring in x, y_1 over Integer Ring The variable ``x`` of ``X`` can still be interpreted in ``Y``, although the first generator of ``Y`` is called ``x`` as well:: @@ -171,7 +174,7 @@ Traceback (most recent call last): ... CoercionException: Overlapping variables (('z', 'y'),['y_1']) are incompatible - sage: X. = PolynomialRing(ZZ,order='lex') + sage: X. = PolynomialRing(ZZ, order='lex') sage: # y_1 and y_2 would be in opposite order in an Infinite Polynomial Ring sage: Y. = InfinitePolynomialRing(X) Traceback (most recent call last): @@ -184,10 +187,10 @@ construction available:: sage: X. = InfinitePolynomialRing(ZZ) - sage: Y. = InfinitePolynomialRing(X,order='degrevlex') + sage: Y. = InfinitePolynomialRing(X, order='degrevlex') sage: Y Infinite polynomial ring in z over Infinite polynomial ring in x, y over Integer Ring - sage: Y. = InfinitePolynomialRing(X,implementation='sparse') + sage: Y. = InfinitePolynomialRing(X, implementation='sparse') sage: Y Infinite polynomial ring in z over Infinite polynomial ring in x, y over Integer Ring @@ -203,18 +206,18 @@ sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 - sage: R. = InfinitePolynomialRing(ZZ,implementation='sparse') + sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') sage: X. = InfinitePolynomialRing(R) sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 - sage: R. = InfinitePolynomialRing(ZZ,implementation='sparse') - sage: X. = InfinitePolynomialRing(R,implementation='sparse') + sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') + sage: X. = InfinitePolynomialRing(R, implementation='sparse') sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 sage: R. = InfinitePolynomialRing(ZZ) - sage: X. = InfinitePolynomialRing(R,implementation='sparse') + sage: X. = InfinitePolynomialRing(R, implementation='sparse') sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 @@ -309,11 +312,13 @@ def create_key(self, R, names=('x',), order='lex', implementation='dense'): (InfPoly{[y1], "lex", "dense"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[y1], "lex", "dense"}] - sage: InfinitePolynomialRing.create_key(QQ, names=['beta'], order='deglex', implementation='sparse') + sage: InfinitePolynomialRing.create_key(QQ, names=['beta'], order='deglex', + ....: implementation='sparse') (InfPoly{[beta], "deglex", "sparse"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[beta], "deglex", "sparse"}] - sage: InfinitePolynomialRing.create_key(QQ, names=['x','y'], implementation='dense') + sage: InfinitePolynomialRing.create_key(QQ, names=['x','y'], + ....: implementation='dense') (InfPoly{[x,y], "lex", "dense"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[x,y], "lex", "dense"}] @@ -805,8 +810,8 @@ def construction(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.libs.pari - sage: R.construction() # optional - sage.libs.pari + sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: R.construction() # optional - sage.rings.finite_rings [InfPoly{[x,y], "lex", "dense"}, Finite Field of size 5] """ @@ -1104,10 +1109,10 @@ def is_noetherian(self): TESTS:: - sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.libs.pari - sage: R # optional - sage.libs.pari + sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Infinite polynomial ring in x over Finite Field of size 2 - sage: R.is_noetherian() # optional - sage.libs.pari + sage: R.is_noetherian() # optional - sage.rings.finite_rings False sage: R. = InfinitePolynomialRing(QQ) @@ -1131,10 +1136,10 @@ def is_field(self, *args, **kwds): TESTS:: - sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.libs.pari - sage: R # optional - sage.libs.pari + sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Infinite polynomial ring in x over Finite Field of size 2 - sage: R.is_field() # optional - sage.libs.pari + sage: R.is_field() # optional - sage.rings.finite_rings False :trac:`9443`:: @@ -1225,8 +1230,8 @@ def gen(self, i=None): x_1 sage: X.gen() is X.gen(0) True - sage: XX = InfinitePolynomialRing(GF(5)) # optional - sage.libs.pari - sage: XX.gen(0) is XX.gen() # optional - sage.libs.pari + sage: XX = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: XX.gen(0) is XX.gen() # optional - sage.rings.finite_rings True """ if i is not None and i > len(self._names): @@ -1292,10 +1297,10 @@ def characteristic(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(GF(25,'a')) # optional - sage.libs.pari - sage: X # optional - sage.libs.pari + sage: X. = InfinitePolynomialRing(GF(25,'a')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings Infinite polynomial ring in x, y over Finite Field in a of size 5^2 - sage: X.characteristic() # optional - sage.libs.pari + sage: X.characteristic() # optional - sage.rings.finite_rings 5 """ @@ -1344,8 +1349,8 @@ def order(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.libs.pari - sage: R.order() # optional - sage.libs.pari + sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R.order() # optional - sage.rings.finite_rings +Infinity """ from sage.rings.infinity import Infinity @@ -1358,8 +1363,8 @@ def key_basis(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.libs.pari - sage: R.key_basis() # optional - sage.libs.pari + sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R.key_basis() # optional - sage.rings.finite_rings Key polynomial basis over Finite Field of size 2 """ from sage.combinat.key_polynomial import KeyPolynomialBasis @@ -1567,8 +1572,8 @@ def construction(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.libs.pari - sage: R.construction() # optional - sage.libs.pari + sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: R.construction() # optional - sage.rings.finite_rings [InfPoly{[x,y], "lex", "dense"}, Finite Field of size 5] """ return [InfinitePolynomialFunctor(self._names, self._order, 'dense'), self._base] @@ -1641,7 +1646,8 @@ def polynomial_ring(self): Multivariate Polynomial Ring in xx_0, yy_0 over Integer Ring sage: a = yy[3] sage: X.polynomial_ring() - Multivariate Polynomial Ring in xx_3, xx_2, xx_1, xx_0, yy_3, yy_2, yy_1, yy_0 over Integer Ring + Multivariate Polynomial Ring in xx_3, xx_2, xx_1, xx_0, yy_3, yy_2, yy_1, yy_0 + over Integer Ring """ return self._P diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b597397c9e5..42e9a1935da 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -255,38 +255,40 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): EXAMPLES:: - sage: k. = GF(9) - sage: R. = LaurentPolynomialRing(k) - sage: f = x*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = LaurentPolynomialRing(k) # optional - sage.rings.finite_rings + sage: f = x*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (a + 1) + (a + 1)*x - sage: R. = LaurentPolynomialRing(k, 2) - sage: f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: R. = LaurentPolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: f = x*a + 2*x^3*y*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (2*a + 1)*x^3*y + (a + 1)*x + a + 1 Examples with different base ring:: - sage: R. = GF(9); S. = GF(81) - sage: h = Hom(R,S)[0]; h + sage: R. = GF(9); S. = GF(81) # optional - sage.rings.finite_rings + sage: h = Hom(R, S)[0]; h # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = LaurentPolynomialRing(R, 2) - sage: f = r*X+Y - sage: g = f.map_coefficients(h); g + sage: T. = LaurentPolynomialRing(R, 2) # optional - sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings (2*s^3 + 2*s^2 + 1)*X + Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() - sage: g = f.map_coefficients(h); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in s of size 3^4 + sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in r of size 3^2 + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -331,13 +333,13 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): :: - sage: S. = LaurentPolynomialRing(GF(5)) - sage: T. = PolynomialRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentPolynomialRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PolynomialRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Univariate Laurent Polynomial Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 :: @@ -511,12 +513,12 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): You can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = LaurentPolynomialRing(K) - sage: H = Hom(R, R) - sage: phi = H([t^-2], base_map=cc) - sage: phi(i*t) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = LaurentPolynomialRing(K) # optional - sage.rings.number_field + sage: H = Hom(R, R) # optional - sage.rings.number_field + sage: phi = H([t^-2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*t) # optional - sage.rings.number_field -i*t^-2 """ x = im_gens[0] @@ -605,9 +607,9 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentPolynomialRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentPolynomialRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -813,20 +815,20 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + 2/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + 2)/x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 9 Since :trac:`24072` the symbolic ring does not accept positive characteristic:: - sage: R. = LaurentPolynomialRing(GF(7)) - sage: SR(2*w^3 + 1) + sage: R. = LaurentPolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: SR(2*w^3 + 1) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -1046,10 +1048,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): """ EXAMPLES:: - sage: R. = LaurentPolynomialRing(GF(2)) - sage: f = 1/x^3 + x + x^2 + 3*x^4 - sage: g = 1 - x + x^2 - x^4 - sage: f*g + sage: R. = LaurentPolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: f = 1/x^3 + x + x^2 + 3*x^4 # optional - sage.rings.finite_rings + sage: g = 1 - x + x^2 - x^4 # optional - sage.rings.finite_rings + sage: f*g # optional - sage.rings.finite_rings x^-3 + x^-2 + x^-1 + x^8 """ cdef LaurentPolynomial_univariate right = right_r @@ -2076,7 +2078,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): """ TESTS:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R. = LaurentPolynomialRing(QQ) sage: loads(dumps(x1)) == x1 # indirect doctest True @@ -2179,12 +2181,12 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): check compatibility with :trac:`26105`:: - sage: F. = GF(4) - sage: LF. = LaurentPolynomialRing(F) - sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) - sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs + sage: F. = GF(4) # optional - sage.rings.finite_rings + sage: LF. = LaurentPolynomialRing(F) # optional - sage.rings.finite_rings + sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs # optional - sage.rings.finite_rings a + (t + 1)*b^-1 + t*a^-3*b^2 - sage: s == rho(rs) + sage: s == rho(rs) # optional - sage.rings.finite_rings True """ p = self._poly @@ -2670,7 +2672,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: - sage: L. = LaurentPolynomialRing(QQ,order='degrevlex') + sage: L. = LaurentPolynomialRing(QQ, order='degrevlex') sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 sage: f.coefficients() [4, 3, 2, 1] @@ -2980,11 +2982,11 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: R. = LaurentPolynomialRing(QQ) - sage: (s^2-t^2).quo_rem(s-t) + sage: (s^2 - t^2).quo_rem(s - t) (s + t, 0) - sage: (s^-2-t^2).quo_rem(s-t) + sage: (s^-2 - t^2).quo_rem(s - t) (s + t, -s^2 + s^-2) - sage: (s^-2-t^2).quo_rem(s^-1-t) + sage: (s^-2 - t^2).quo_rem(s^-1 - t) (t + s^-1, 0) TESTS: @@ -3059,7 +3061,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: L. = LaurentPolynomialRing(QQ) - sage: a = w^2*z^-1+3; a + sage: a = w^2*z^-1 + 3; a w^2*z^-1 + 3 sage: e = a.exponents() sage: e.sort(); e @@ -3294,13 +3296,13 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + y/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + y)/x - sage: g(x=2,y=2) + sage: g(x=2, y=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2,y=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic 9 """ d = {repr(g): R.var(g) for g in self._parent.gens()} @@ -3323,7 +3325,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: R = LaurentPolynomialRing(ZZ,'x, y') sage: x, y = R.gens() - sage: t = x**4*y+x*y+y+x**(-1)+y**(-3) + sage: t = x**4*y + x*y + y + x**(-1) + y**(-3) sage: t.derivative(x, x) 12*x^2*y + 2*x^-3 sage: t.derivative(y, 2) @@ -3398,7 +3400,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: f = (x^3 + y^-3)*z sage: f.is_univariate() False - sage: g = f(1,y,4) + sage: g = f(1, y, 4) sage: g.is_univariate() True sage: R(1).is_univariate() @@ -3428,7 +3430,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable - sage: g = f(10,y); g + sage: g = f(10, y); g 700*y^2 + 305 - 2*y^-1 sage: h = g.univariate_polynomial(); h -2*y^-1 + 305 + 700*y^2 @@ -3578,14 +3580,14 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: p = x^-2*y + x*y^-2 sage: p.rescale_vars({0: 2, 1: 3}) 2/9*x*y^-2 + 3/4*x^-2*y - sage: F = GF(2) - sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) # optional - sage.rings.finite_rings x*y^-2 + x^-2*y Test for :trac:`30331`:: - sage: F. = CyclotomicField(3) - sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) + sage: F. = CyclotomicField(3) # optional - sage.rings.number_field + sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) # optional - sage.rings.number_field 2*z*x*y^-2 + 1/4*z*x^-2*y """ cdef int i @@ -3638,10 +3640,11 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: L. = LaurentPolynomialRing(QQ, 2) sage: p = 2*x^2 + y - x*y - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]])) + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]])) 2*x^2*y^2 - x^-2*y^2 + x^-3*y - sage: F = GF(2) - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]]), new_ring=L.change_ring(F)) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]]), # optional - sage.rings.finite_rings + ....: new_ring=L.change_ring(F)) x^-2*y^2 + x^-3*y """ diff --git a/src/sage/rings/polynomial/laurent_polynomial_ideal.py b/src/sage/rings/polynomial/laurent_polynomial_ideal.py index 0168a56e267..2289b69e111 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ideal.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ideal.py @@ -55,10 +55,12 @@ def __init__(self, ring, gens, coerce=True, hint=None): sage: R. = LaurentPolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) - Ideal (x, y) of Multivariate Laurent Polynomial Ring in x, y over Integer Ring - sage: R. = LaurentPolynomialRing(GF(3), 2) - sage: R.ideal([x0^2, x1^-3]) - Ideal (x0^2, x1^-3) of Multivariate Laurent Polynomial Ring in x0, x1 over Finite Field of size 3 + Ideal (x, y) of Multivariate Laurent Polynomial Ring in x, y + over Integer Ring + sage: R. = LaurentPolynomialRing(GF(3), 2) # optional - sage.rings.finite_rings + sage: R.ideal([x0^2, x1^-3]) # optional - sage.rings.finite_rings + Ideal (x0^2, x1^-3) of Multivariate Laurent Polynomial Ring in x0, x1 + over Finite Field of size 3 sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([~x + ~y - 1]) @@ -70,19 +72,20 @@ def __init__(self, ring, gens, coerce=True, hint=None): True sage: P. = LaurentPolynomialRing(QQ, 3) - sage: I1 = P.ideal([x*y*z+x*y+2*y^2, x+z]) - sage: I2 = P.ideal([x*y*z+x*y+2*y^2+x+z, x+z]) + sage: I1 = P.ideal([x*y*z + x*y + 2*y^2, x + z]) + sage: I2 = P.ideal([x*y*z + x*y + 2*y^2 + x + z, x + z]) sage: I1 == I2 True - sage: I3 = P.ideal([x*y*z+x*y+2*y^2+x+z, x+z, y]) + sage: I3 = P.ideal([x*y*z + x*y + 2*y^2 + x + z, x + z, y]) sage: I1 < I3 True sage: I1.minimal_associated_primes() - (Ideal (-1/2*z^2 + y - 1/2*z, x + z) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field,) + (Ideal (-1/2*z^2 + y - 1/2*z, x + z) of Multivariate + Laurent Polynomial Ring in x, y, z over Rational Field,) - sage: K. = CyclotomicField(4) - sage: J = I1.base_extend(K) - sage: J.base_ring() + sage: K. = CyclotomicField(4) # optional - sage.rings.number_field + sage: J = I1.base_extend(K) # optional - sage.rings.number_field + sage: J.base_ring() # optional - sage.rings.number_field Cyclotomic Field of order 4 and degree 2 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) @@ -207,10 +210,11 @@ def change_ring(self, R, hint=None): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) + sage: I = P.ideal([x + y]) sage: Q. = LaurentPolynomialRing(QQ, 3) sage: I.change_ring(Q) - Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field + Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y, z + over Rational Field """ return R.ideal(self.gens(), hint=hint) @@ -223,10 +227,11 @@ def base_extend(self, F): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) - sage: K. = CyclotomicField(3) - sage: I.base_extend(K) - Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 + sage: I = P.ideal([x + y]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: I.base_extend(K) # optional - sage.rings.number_field + Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y + over Cyclotomic Field of order 3 and degree 2 """ ring = self.ring() return self.change_ring(ring.change_ring(F), hint=self._hint) @@ -241,12 +246,14 @@ def apply_map(self, f, new_ring=None, new_base_ring=None, apply_to_hint=None): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+1, y-1]) - sage: I.apply_map(lambda z: z+2) - Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: K. = CyclotomicField(4) - sage: I.apply_map(lambda z: z+2, new_base_ring=K) - Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 4 and degree 2 + sage: I = P.ideal([x + 1, y - 1]) + sage: I.apply_map(lambda z: z + 2) + Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y + over Rational Field + sage: K. = CyclotomicField(4) # optional - sage.rings.number_field + sage: I.apply_map(lambda z: z + 2, new_base_ring=K) # optional - sage.rings.number_field + Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y + over Cyclotomic Field of order 4 and degree 2 """ ring = self.ring() if new_ring is not None: @@ -269,16 +276,18 @@ def apply_coeff_map(self, f, new_base_ring=None, forward_hint=True): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: P. = LaurentPolynomialRing(K, 2) - sage: I = P.ideal([x+z, y-z]) - sage: h = K.hom([z^2]) - sage: I.apply_coeff_map(h) - Ideal (x - z - 1, y + z + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 - sage: K1. = CyclotomicField(12) - sage: h1 = K.hom([z1^4]) - sage: I.apply_coeff_map(h1, new_base_ring=K1) - Ideal (x + z1^2 - 1, y - z1^2 + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 12 and degree 4 + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: P. = LaurentPolynomialRing(K, 2) # optional - sage.rings.number_field + sage: I = P.ideal([x + z, y - z]) # optional - sage.rings.number_field + sage: h = K.hom([z^2]) # optional - sage.rings.number_field + sage: I.apply_coeff_map(h) # optional - sage.rings.number_field + Ideal (x - z - 1, y + z + 1) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 3 and degree 2 + sage: K1. = CyclotomicField(12) # optional - sage.rings.number_field + sage: h1 = K.hom([z1^4]) # optional - sage.rings.number_field + sage: I.apply_coeff_map(h1, new_base_ring=K1) # optional - sage.rings.number_field + Ideal (x + z1^2 - 1, y - z1^2 + 1) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 12 and degree 4 """ ring = self.ring() if new_base_ring is None: @@ -301,12 +310,13 @@ def toric_coordinate_change(self, M, forward_hint=True): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: P. = LaurentPolynomialRing(K, 2) - sage: I = P.ideal([x+1, y-1]) - sage: M = Matrix([[2,1],[1,-3]]) - sage: I.toric_coordinate_change(M) - Ideal (x^2*y + 1, -1 + x*y^-3) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: P. = LaurentPolynomialRing(K, 2) # optional - sage.rings.number_field + sage: I = P.ideal([x + 1, y - 1]) # optional - sage.rings.number_field + sage: M = Matrix([[2,1], [1,-3]]) # optional - sage.rings.number_field + sage: I.toric_coordinate_change(M) # optional - sage.rings.number_field + Ideal (x^2*y + 1, -1 + x*y^-3) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 3 and degree 2 """ if forward_hint: R = self.ring() @@ -357,10 +367,12 @@ def normalize_gens(self): sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([~x+y]) sage: J = P.ideal([y+1]) - sage: I+J - Ideal (y + x^-1, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: (I+J).normalize_gens() - Ideal (x - 1, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field + sage: I + J + Ideal (y + x^-1, y + 1) of Multivariate Laurent Polynomial Ring + in x, y over Rational Field + sage: (I + J).normalize_gens() + Ideal (x - 1, y + 1) of Multivariate Laurent Polynomial Ring + in x, y over Rational Field """ return self.ring().ideal(self.groebner_basis(), hint=self._hint) @@ -381,7 +393,8 @@ def polynomial_ideal(self, saturate=True): sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([x^2*y + 3*x*y^2]) sage: I.polynomial_ideal() - Ideal (x + 3*y) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x + 3*y) of Multivariate Polynomial Ring in x, y + over Rational Field """ if self._poly_ideal is not None and (self._saturated or not saturate): return self._poly_ideal @@ -416,9 +429,9 @@ def groebner_basis(self, saturate=True): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) - sage: J = P.ideal([y+1]) - sage: (I+J).groebner_basis() + sage: I = P.ideal([x + y]) + sage: J = P.ideal([y + 1]) + sage: (I + J).groebner_basis() (x - 1, y + 1) """ l = self.polynomial_ideal(saturate=saturate).groebner_basis() @@ -470,10 +483,12 @@ def associated_primes(self): sage: P. = LaurentPolynomialRing(QQ, 3) sage: p = z^2 + 1; q = z^3 + 2 - sage: I = P.ideal((p*q^2, y-z^2)) + sage: I = P.ideal((p*q^2, y - z^2)) sage: tuple(sorted(I.associated_primes(), key=str)) - (Ideal (y + 1, z^2 + 1) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, - Ideal (z^2 - y, y*z + 2, y^2 + 2*z) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) + (Ideal (y + 1, z^2 + 1) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, + Ideal (z^2 - y, y*z + 2, y^2 + 2*z) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) """ l = self.polynomial_ideal(saturate=False).associated_primes() l2 = [self.ring().ideal(I.gens(), hint=I) for I in l] @@ -490,10 +505,12 @@ def minimal_associated_primes(self, saturate=False): sage: P. = LaurentPolynomialRing(QQ, 3) sage: p = z^2 + 1; q = z^3 + 2 - sage: I = P.ideal((p*q^2, y-z^2)) + sage: I = P.ideal((p*q^2, y - z^2)) sage: tuple(sorted(I.minimal_associated_primes(), key=str)) - (Ideal (z^2 + 1, -z^2 + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, - Ideal (z^3 + 2, -z^2 + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) + (Ideal (z^2 + 1, -z^2 + y) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, + Ideal (z^3 + 2, -z^2 + y) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) """ l = self.polynomial_ideal(saturate=saturate).minimal_associated_primes() l2 = [self.ring().ideal(I.gens(), hint=I) for I in l] @@ -508,7 +525,8 @@ def radical(self): sage: P. = LaurentPolynomialRing(QQ, 3) sage: I = P.ideal(((x+1)^2, (y+1)^3, ((x+1)*z)^4 + (y+1)^3 + 10*(x+1)^2)) sage: I.radical() - Ideal (y + 1, x + 1) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field + Ideal (y + 1, x + 1) of Multivariate Laurent Polynomial Ring in x, y, z + over Rational Field """ J = self.polynomial_ideal().radical() return self.ring().ideal(J.gens()) diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 7129701c54f..70034eecaa1 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -185,13 +185,13 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + y - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic x^3 + y - sage: g(x=2,y=2) + sage: g(x=2, y=2) # optional - sage.symbolic 10 - sage: g = SR(f) - sage: g(x=2,y=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic 10 """ d = dict([(repr(g), R.var(g)) for g in self.parent().gens()]) @@ -348,12 +348,12 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials over the symbolic ring (just for fun....):: - sage: x = var("x") - sage: S. = PolynomialRing(SR) - sage: f = u*v*x - sage: f.derivative(x) == u*v + sage: x = var("x") # optional - sage.symbolic + sage: S. = PolynomialRing(SR) # optional - sage.symbolic + sage: f = u*v*x # optional - sage.symbolic + sage: f.derivative(x) == u*v # optional - sage.symbolic True - sage: f.derivative(u) == v*x + sage: f.derivative(u) == v*x # optional - sage.symbolic True """ return multi_derivative(self, args) @@ -870,7 +870,7 @@ cdef class MPolynomial(CommutativePolynomial): Check that :trac:`25022` is fixed:: sage: K. = ZZ[] - sage: (x*y).change_ring(SR).monomials() + sage: (x*y).change_ring(SR).monomials() # optional - sage.rings.number_field [x*y] """ if isinstance(R, Map): @@ -977,39 +977,39 @@ cdef class MPolynomial(CommutativePolynomial): Multivariate polynomial over integers:: sage: R. = ZZ[] - sage: gap(-x*y + 3*z) # indirect doctest + sage: gap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: gap(R.zero()) # indirect doctest + sage: gap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 - sage: (x+y+z)._gap_(libgap) + sage: (x+y+z)._gap_(libgap) # optional - sage.libs.gap x+y+z - sage: g = gap(x - y + 3*x*y*z) - sage: R(g) + sage: g = gap(x - y + 3*x*y*z) # optional - sage.libs.gap + sage: R(g) # optional - sage.libs.gap 3*x*y*z + x - y - sage: g = libgap(5*x - y*z) - sage: R(g) + sage: g = libgap(5*x - y*z) # optional - sage.libs.gap + sage: R(g) # optional - sage.libs.gap -y*z + 5*x Multivariate polynomial over a cyclotomic field:: - sage: F. = CyclotomicField(8) - sage: P. = F[] - sage: p = zeta + zeta^2*x + zeta^3*y + (1+zeta)*x*y - sage: gap(p) # indirect doctest + sage: F. = CyclotomicField(8) # optional - sage.rings.number_field + sage: P. = F[] # optional - sage.rings.number_field + sage: p = zeta + zeta^2*x + zeta^3*y + (1+zeta)*x*y # optional - sage.rings.number_field + sage: gap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field (1+E(8))*x*y+E(4)*x+E(8)^3*y+E(8) - sage: libgap(p) # indirect doctest + sage: libgap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field (1+E(8))*x*y+E(4)*x+E(8)^3*y+E(8) Multivariate polynomial over a polynomial ring over a cyclotomic field:: - sage: S. = F[] - sage: P. = S[] - sage: p = zeta + zeta^2*x*z + zeta^3*y*z^2 + (1+zeta)*x*y*z - sage: gap(p) # indirect doctest + sage: S. = F[] # optional - sage.rings.number_field + sage: P. = S[] # optional - sage.rings.number_field + sage: p = zeta + zeta^2*x*z + zeta^3*y*z^2 + (1+zeta)*x*y*z # optional - sage.rings.number_field + sage: gap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field ((1+E(8))*z)*x*y+E(4)*z*x+E(8)^3*z^2*y+E(8) - sage: libgap(p) # indirect doctest + sage: libgap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field ((1+E(8))*z)*x*y+E(4)*z*x+E(8)^3*z^2*y+E(8) """ R = gap(self.parent()) @@ -1021,9 +1021,9 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x*y + 3*z) # indirect doctest + sage: libgap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: libgap(R.zero()) # indirect doctest + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -1696,9 +1696,9 @@ cdef class MPolynomial(CommutativePolynomial): an example when the coefficients live in a finite field:: - sage: F = FiniteField(11) - sage: R. = PolynomialRing(F,4) - sage: z.macaulay_resultant([x^3, 5*y, w]) # optional - sage.modules + 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 4 example when the denominator in the algorithm vanishes(in this case @@ -1904,9 +1904,9 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) - sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g + sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g # optional - sage.libs.singular 1/16*x1 + 3/16 - sage: (f*g).reduce(I) + sage: (f*g).reduce(I) # optional - sage.libs.singular 1 Test a non-invertible element:: @@ -1914,7 +1914,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) sage: f = x1 + x2 - sage: f.inverse_mod(I) + sage: f.inverse_mod(I) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -2344,7 +2344,7 @@ cdef class MPolynomial(CommutativePolynomial): An example where precision needs to be increased:: sage: R. = PolynomialRing(QQ) - sage: F=-16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7 + sage: F = -16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7 sage: F.reduced_form(prec=50, smallest_coeffs=False) # optional - sage.modules Traceback (most recent call last): ... diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index f35e7f09336..3f46a0ee9c8 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -2287,9 +2287,9 @@ def resultant(self, other, variable=None): sage: P. = MPolynomialRing_polydict_domain(QQ, 2, order='degrevlex') sage: a = x + y sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: a.resultant(b) # optional - sage.libs.singular -2*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.libs.singular 2*x^3 Check that :trac:`15061` is fixed:: @@ -2303,7 +2303,7 @@ def resultant(self, other, variable=None): sage: R. = RR[] sage: p = x + y sage: q = x*y - sage: p.resultant(q) + sage: p.resultant(q) # optional - sage.libs.singular -y^2 Check that this method works over QQbar (:trac:`25351`):: diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index 1f0eaae63d0..30a956b784b 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -2798,31 +2798,31 @@ def hilbert_polynomial(self, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint 5*t - 5 Of course, the Hilbert polynomial of a zero-dimensional ideal is zero:: - sage: J0 = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5, y^3-2*x*z^2+x*y,x^4+x*y-y*z^2]) + sage: J0 = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5, y^3 - 2*x*z^2 + x*y, x^4 + x*y - y*z^2]) sage: J = P*[m.lm() for m in J0.groebner_basis()] sage: J.dimension() 0 - sage: J.hilbert_polynomial() + sage: J.hilbert_polynomial() # optional - sage.libs.flint 0 It is possible to request a computation using the Singular library:: - sage: I.hilbert_polynomial(algorithm = 'singular') == I.hilbert_polynomial() + sage: I.hilbert_polynomial(algorithm='singular') == I.hilbert_polynomial() # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_polynomial(algorithm = 'singular') == J.hilbert_polynomial() + sage: J.hilbert_polynomial(algorithm='singular') == J.hilbert_polynomial() # optional - sage.libs.flint sage.libs.singular True Here is a bigger examples:: sage: n = 4; m = 11; P = PolynomialRing(QQ, n * m, "x"); x = P.gens(); M = Matrix(n, x) sage: Minors = P.ideal(M.minors(2)) - sage: hp = Minors.hilbert_polynomial(); hp + sage: hp = Minors.hilbert_polynomial(); hp # optional - sage.libs.flint 1/21772800*t^13 + 61/21772800*t^12 + 1661/21772800*t^11 + 26681/21772800*t^10 + 93841/7257600*t^9 + 685421/7257600*t^8 + 1524809/3110400*t^7 + 39780323/21772800*t^6 + 6638071/1360800*t^5 @@ -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 + sage: Minors.hilbert_polynomial(algorithm='singular') # not tested # optional - sage.libs.singular Traceback (most recent call last): ... RuntimeError: error in Singular function call 'hilbPoly': @@ -2844,8 +2844,8 @@ def hilbert_polynomial(self, algorithm='sage'): Note that in this example, the Hilbert polynomial gives the coefficients of the Hilbert-Poincaré series in all degrees:: - sage: P = PowerSeriesRing(QQ, 't', default_prec = 50) - sage: hs = Minors.hilbert_series() + sage: P = PowerSeriesRing(QQ, 't', default_prec=50) + sage: hs = Minors.hilbert_series() # optional - sage.libs.flint sage: list(P(hs.numerator()) / P(hs.denominator())) == [hp(t = k) for k in range(50)] True @@ -2855,9 +2855,9 @@ def hilbert_polynomial(self, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3, x*y^2, y^4, x^2*y*z, y^3*z, x^2*z^2, x*y*z^2, x*z^3]) - sage: I.hilbert_polynomial(algorithm='singular') + sage: I.hilbert_polynomial(algorithm='singular') # optional - sage.libs.singular 3 - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint 3 Check that this method works over QQbar (:trac:`25351`):: @@ -2871,7 +2871,7 @@ def hilbert_polynomial(self, algorithm='sage'): sage: R. = QQ[] sage: I = R.ideal([X^2*Y^3, X*Z]) - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint t + 5 """ if not self.is_homogeneous(): @@ -2934,39 +2934,39 @@ def hilbert_series(self, grading=None, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series() + sage: I.hilbert_series() # optional - sage.libs.flint (t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1) sage: R. = PolynomialRing(QQ) - sage: J = R.ideal([a^2*b,a*b^2]) - sage: J.hilbert_series() + sage: J = R.ideal([a^2*b, a*b^2]) + sage: J.hilbert_series() # optional - sage.libs.flint (t^3 - t^2 - t - 1)/(t - 1) - sage: J.hilbert_series(grading=(10,3)) + sage: J.hilbert_series(grading=(10,3)) # optional - sage.libs.flint (t^25 + t^24 + t^23 - t^15 - t^14 - t^13 - t^12 - t^11 - t^10 - t^9 - t^8 - t^7 - t^6 - t^5 - t^4 - t^3 - t^2 - t - 1)/(t^12 + t^11 + t^10 - t^2 - t - 1) sage: K = R.ideal([a^2*b^3, a*b^4 + a^3*b^2]) - sage: K.hilbert_series(grading=[1,2]) + sage: K.hilbert_series(grading=[1,2]) # optional - sage.libs.flint (t^11 + t^8 - t^6 - t^5 - t^4 - t^3 - t^2 - t - 1)/(t^2 - 1) - sage: K.hilbert_series(grading=[2,1]) + sage: K.hilbert_series(grading=[2,1]) # optional - sage.libs.flint (2*t^7 - t^6 - t^4 - t^2 - 1)/(t - 1) TESTS:: - sage: I.hilbert_series() == I.hilbert_series(algorithm = 'singular') + sage: I.hilbert_series() == I.hilbert_series(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_series() == J.hilbert_series(algorithm = 'singular') + sage: J.hilbert_series() == J.hilbert_series(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_series(grading = (10,3)) == J.hilbert_series(grading = (10,3), algorithm = 'singular') + sage: J.hilbert_series(grading=(10,3)) == J.hilbert_series(grading=(10,3), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: K.hilbert_series(grading = (1,2)) == K.hilbert_series(grading = (1,2), algorithm = 'singular') + sage: K.hilbert_series(grading=(1,2)) == K.hilbert_series(grading=(1,2), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: K.hilbert_series(grading = (2,1)) == K.hilbert_series(grading = (2,1), algorithm = 'singular') + sage: K.hilbert_series(grading=(2,1)) == K.hilbert_series(grading=(2,1), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series(grading=5) + sage: I.hilbert_series(grading=5) # optional - sage.libs.flint Traceback (most recent call last): ... TypeError: grading must be a list or a tuple of integers @@ -3033,22 +3033,22 @@ def hilbert_numerator(self, grading = None, algorithm = 'sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_numerator() + sage: I.hilbert_numerator() # optional - sage.libs.flint -t^5 + 1 sage: R. = PolynomialRing(QQ) - sage: J = R.ideal([a^2*b,a*b^2]) - sage: J.hilbert_numerator() + sage: J = R.ideal([a^2*b, a*b^2]) + sage: J.hilbert_numerator() # optional - sage.libs.flint t^4 - 2*t^3 + 1 - sage: J.hilbert_numerator(grading=(10,3)) + sage: J.hilbert_numerator(grading=(10,3)) # optional - sage.libs.flint t^26 - t^23 - t^16 + 1 TESTS:: - sage: I.hilbert_numerator() == I.hilbert_numerator(algorithm = 'singular') + sage: I.hilbert_numerator() == I.hilbert_numerator(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_numerator() == J.hilbert_numerator(algorithm = 'singular') + sage: J.hilbert_numerator() == J.hilbert_numerator(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_numerator(grading=(10,3)) == J.hilbert_numerator(grading=(10,3), algorithm = 'singular') + sage: J.hilbert_numerator(grading=(10,3)) == J.hilbert_numerator(grading=(10,3), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True Check that this method works over QQbar (:trac:`25351`):: diff --git a/src/sage/rings/polynomial/multi_polynomial_ring.py b/src/sage/rings/polynomial/multi_polynomial_ring.py index 24bac53eb15..26658f081d4 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring.py +++ b/src/sage/rings/polynomial/multi_polynomial_ring.py @@ -203,7 +203,7 @@ def __call__(self, x=0, check=True): sage: R. = QQ[] sage: S. = ZZ[] - sage: T. = GF(7)[] + sage: T. = GF(7)[] # optional - sage.libs.pari We convert from integer polynomials to rational polynomials, and back:: @@ -219,9 +219,9 @@ def __call__(self, x=0, check=True): :: - sage: f = R(T.0^2 - 4*T.1^3); f + sage: f = R(T.0^2 - 4*T.1^3); f # optional - sage.libs.pari 3*y^3 + x^2 - sage: parent(f) + sage: parent(f) # optional - sage.libs.pari Multivariate Polynomial Ring in x, y over Rational Field We dump and load the polynomial ring S:: @@ -241,9 +241,9 @@ def __call__(self, x=0, check=True): variable names:: sage: R. = PolynomialRing(QQ,2) - sage: S. = PolynomialRing(GF(7),2) + sage: S. = PolynomialRing(GF(7),2) # optional - sage.libs.pari sage: f = x^2 + 2/3*y^3 - sage: S(f) + sage: S(f) # optional - sage.libs.pari 3*b^3 + a^2 Conversion from symbolic variables:: @@ -279,12 +279,12 @@ def __call__(self, x=0, check=True): :: - sage: R = GF(5)['x,y,z'] + sage: R = GF(5)['x,y,z'] # optional - sage.libs.pari sage: S = ZZ['y'] - sage: R(7*S.0) + sage: R(7*S.0) # optional - sage.libs.pari 2*y sage: T = ZZ['x,z'] - sage: R(2*T.0 + 6*T.1 + T.0*T.1^2) + sage: R(2*T.0 + 6*T.1 + T.0*T.1^2) # optional - sage.libs.pari 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 32da7af3195..a2a4e4a925a 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -238,7 +238,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: P. = PolynomialRing(ZZ) sage: P.completion([]) is P True - sage: P.completion(SR.var('x')) + sage: P.completion(SR.var('x')) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: x is not an element of Multivariate Polynomial Ring @@ -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) + 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) + 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]) + 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) + sage: R.interpolation(3, F) # optional - sage.modules 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25 .. SEEALSO:: @@ -1653,9 +1653,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): An example when the coefficients live in a finite field:: - sage: F = FiniteField(11) - sage: R. = PolynomialRing(F,4) - sage: R.macaulay_resultant([z,x^3,5*y,w]) # optional - sage.modules + sage: F = FiniteField(11) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(F, 4) # optional - sage.rings.finite_rings + sage: R.macaulay_resultant([z,x^3,5*y,w]) # optional - sage.modules sage.rings.finite_rings 4 Example when the denominator in the algorithm vanishes(in this case @@ -1670,7 +1670,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): to the traditional resultant:: sage: R. = PolynomialRing(QQ,1) - sage: f = x^2+1; g = x^5+1 + sage: f = x^2 + 1; g = x^5 + 1 sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() @@ -1773,8 +1773,8 @@ cdef class BooleanPolynomialRing_base(MPolynomialRing_base): EXAMPLES:: sage: from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base - sage: R. = BooleanPolynomialRing() - sage: isinstance(R, BooleanPolynomialRing_base) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: isinstance(R, BooleanPolynomialRing_base) # optional - sage.rings.polynomial.pbori True By design, there is only one direct implementation subclass:: diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index 37aecfd64c8..03dce6f9fdb 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -782,7 +782,7 @@ cdef class PolyDict: Check that :trac:`29604` is fixed:: - sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) + sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) # optional - sage.libs.pari 'x' """ if not self: @@ -1004,9 +1004,9 @@ cdef class PolyDict: sage: f + g PolyDict with representation {(1, 1): 3, (1, 2): 3, (1, 5): -3, (2, 1): 4, (2, 3): 0} - sage: K = GF(2) - sage: f = PolyDict({(1, 1): K(1)}) - sage: f + f + sage: K = GF(2) # optional - sage.rings.finite_rings + sage: f = PolyDict({(1, 1): K(1)}) # optional - sage.rings.finite_rings + sage: f + f # optional - sage.rings.finite_rings PolyDict with representation {(1, 1): 0} """ cdef dict D = self.__repn diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 7fa6f1cb946..3c4a8389dbf 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -170,11 +170,11 @@ cpdef is_Polynomial(f): y^3 + x*y - 3*x sage: is_Polynomial(f) False - sage: var('x,y') + sage: var('x,y') # optional - sage.symbolic (x, y) - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y -3*x; f # optional - sage.symbolic y^3 + x*y - 3*x - sage: is_Polynomial(f) + sage: is_Polynomial(f) # optional - sage.symbolic False """ from sage.misc.superseded import deprecation @@ -296,12 +296,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R = GF(2)['x']['y'] - sage: R([0,1]).is_zero() + sage: R = GF(2)['x']['y'] # optional - sage.libs.pari + sage: R([0,1]).is_zero() # optional - sage.libs.pari False - sage: R([0]).is_zero() + sage: R([0]).is_zero() # optional - sage.libs.pari True - sage: R([-1]).is_zero() + sage: R([-1]).is_zero() # optional - sage.libs.pari False """ return self.degree() < 0 @@ -346,11 +346,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: x = polygen(GF(389)) - sage: plot(x^2 + 1, rgbcolor=(0,0,1)) + sage: x = polygen(GF(389)) # optional - sage.libs.pari + sage: plot(x^2 + 1, rgbcolor=(0,0,1)) # optional - sage.libs.pari sage.plot Graphics object consisting of 1 graphics primitive sage: x = polygen(QQ) - sage: plot(x^2 + 1, rgbcolor=(1,0,0)) + sage: plot(x^2 + 1, rgbcolor=(1,0,0)) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ R = self.base_ring() @@ -517,13 +517,13 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = GF(17)[] - sage: f = w^3 + 3*w +2 - sage: f(5) + 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 6 - sage: f(w=5) + sage: f(w=5) # optional - sage.libs.pari 6 - sage: f(x=10) # x isn't mentioned + sage: f(x=10) # x isn't mentioned # optional - sage.libs.pari w^3 + 3*w + 2 Nested polynomial ring elements can be called like multivariate @@ -572,7 +572,7 @@ cdef class Polynomial(CommutativePolynomial): The following results in an element of the symbolic ring. :: - sage: f(x=sqrt(2)) + sage: f(x=sqrt(2)) # optional - sage.symbolic y^2 + sqrt(2)*y + sqrt(2) :: @@ -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) - sage: zero(1.).parent() # should raise an error + sage: zero = GF(2)['x'](0) # optional - sage.libs.pari + sage: zero(1.).parent() # should raise an error # optional - sage.libs.pari 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)[] - sage: f = R(list(range(100,201))) - sage: g = R(list(range(1,1001))) - sage: S. = R.quotient(f) - sage: g(y) + sage: R. = GF(31337)[] # optional - sage.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 22537*y^99 + 4686*y^98 + 13285*y^97 + 4216*y^96 + ... + 6389*y^3 + 30062*y^2 + 13755*y + 11875 :: - sage: T. = GF(31337)[] - sage: g(z) + sage: T. = GF(31337)[] # optional - sage.libs.pari + sage: g(z) # optional - sage.libs.pari 1000*z^999 + 999*z^998 + 998*z^997 + 997*z^996 + ... + 5*z^4 + 4*z^3 + 3*z^2 + 2*z + 1 - sage: g(z^2) + sage: g(z^2) # optional - sage.libs.pari 1000*z^1998 + 999*z^1996 + 998*z^1994 + 997*z^1992 + ... + 5*z^8 + 4*z^6 + 3*z^4 + 2*z^2 + 1 - sage: g(T([0,1])) + sage: g(T([0, 1])) # optional - sage.libs.pari 1000*z^999 + 999*z^998 + 998*z^997 + 997*z^996 + ... + 5*z^4 + 4*z^3 + 3*z^2 + 2*z + 1 - sage: g(T.zero()) + sage: g(T.zero()) # optional - sage.libs.pari 1 - sage: g(T(2)) + sage: g(T(2)) # optional - sage.libs.pari 23069 :: - sage: U. = GF(31337)[] - sage: g(u) + sage: U. = GF(31337)[] # optional - sage.libs.pari + sage: g(u) # optional - sage.libs.pari 1000*u^999 + 999*u^998 + 998*u^997 + 997*u^996 + ... + 5*u^4 + 4*u^3 + 3*u^2 + 2*u + 1 - sage: g(u*v^2) + sage: g(u*v^2) # optional - sage.libs.pari 1000*u^999*v^1998 + 999*u^998*v^1996 + 998*u^997*v^1994 + ... + 4*u^3*v^6 + 3*u^2*v^4 + 2*u*v^2 + 1 - sage: g(U.zero()) + sage: g(U.zero()) # optional - sage.libs.pari 1 - sage: g(U(2)) + sage: g(U(2)) # optional - sage.libs.pari -8268 Sparse tests for :trac:`33165`:: @@ -1295,11 +1295,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f(x^2 + 3) # indirect doctest 28 - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: phi = S.hom([y^2], base_map=cc) - sage: phi(i*y) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*y) # optional - sage.rings.number_field -i*y^2 """ a = im_gens[0] @@ -1328,9 +1328,9 @@ cdef class Polynomial(CommutativePolynomial): sage: a = QQ['x'](1/5) sage: QQ(a) 1/5 - sage: AA(a) + sage: AA(a) # optional - sage.rings.number_field 1/5 - sage: QQbar(a) + sage: QQbar(a) # optional - sage.rings.number_field 1/5 sage: RDF(a) 0.2 @@ -1353,30 +1353,30 @@ cdef class Polynomial(CommutativePolynomial): sage: complex(a) (0.2+0j) - sage: b = AA['x'](AA(2/3).sqrt()) - sage: AA(b) + sage: b = AA['x'](AA(2/3).sqrt()) # optional - sage.rings.number_field + sage: AA(b) # optional - sage.rings.number_field 0.8164965809277260? - sage: RR(b) + sage: RR(b) # optional - sage.rings.number_field 0.816496580927726 - sage: RBF(b) + sage: RBF(b) # optional - sage.rings.number_field [0.816496580927726 +/- 2.44e-16] - sage: RIF(b) + sage: RIF(b) # optional - sage.rings.number_field 0.8164965809277260? - sage: float(b) + sage: float(b) # optional - sage.rings.number_field 0.816496580927726 - sage: c = QQbar['x'](QQbar(-2/5).sqrt()) - sage: QQbar(c) + sage: c = QQbar['x'](QQbar(-2/5).sqrt()) # optional - sage.rings.number_field + sage: QQbar(c) # optional - sage.rings.number_field 0.6324555320336758?*I - sage: CDF(c) + sage: CDF(c) # optional - sage.rings.number_field 0.6324555320336758*I - sage: CC(c) + sage: CC(c) # optional - sage.rings.number_field 0.632455532033676*I - sage: CBF(c) # abs tol 1e-16 + sage: CBF(c) # abs tol 1e-16 # optional - sage.rings.number_field [0.6324555320336759 +/- 3.38e-17]*I - sage: CIF(c) + sage: CIF(c) # optional - sage.rings.number_field 0.6324555320336758?*I - sage: complex(c) + sage: complex(c) # optional - sage.rings.number_field 0.6324555320336758j sage: K. = Frac(RR['x']) @@ -1388,8 +1388,8 @@ cdef class Polynomial(CommutativePolynomial): TypeError: cannot convert nonconstant polynomial sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) - sage: A(A['x'](u)) + sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A(A['x'](u)) # optional - sage.rings.number_field u """ if self.degree() > 0: @@ -1431,8 +1431,8 @@ cdef class Polynomial(CommutativePolynomial): r""" EXAMPLES:: - sage: p = PolynomialRing(QQbar, 'x')(1+I) - sage: complex(p) + sage: p = PolynomialRing(QQbar, 'x')(1+I) # optional - sage.rings.number_field + sage: complex(p) # optional - sage.rings.number_field (1+1j) """ return self._scalar_conversion(complex) @@ -1457,20 +1457,20 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic x^3 + x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 10 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 10 The polynomial has to be over a field of characteristic 0 (see :trac:`24072`):: - sage: R. = GF(7)[] - sage: f = SR(2*w^3 + 1); f + sage: R. = GF(7)[] # optional - sage.libs.pari + sage: f = SR(2*w^3 + 1); f # optional - sage.libs.pari sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -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)) - sage: x.squarefree_decomposition() + sage: x = polygen(GF(3)) # optional - sage.libs.pari + sage: x.squarefree_decomposition() # optional - sage.libs.pari x - sage: f = QQbar['x'](1) - sage: f.squarefree_decomposition() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.squarefree_decomposition() # optional - sage.rings.number_field 1 """ @@ -2028,75 +2028,89 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = GF(11)[] - sage: f = 7*x^7 + 8*x^6 + 4*x^5 + x^4 + 6*x^3 + 10*x^2 + 8*x + 5 - sage: f.any_root() + sage: R. = GF(11)[] # optional - sage.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 2 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (7) * (x + 9) * (x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2) - sage: f = x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2 - sage: f.any_root(GF(11^6, 'a')) + sage: f = x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2 # optional - sage.libs.pari + sage: f.any_root(GF(11^6, 'a')) # optional - sage.libs.pari a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a - sage: sorted(f.roots(GF(11^6, 'a'))) - [(10*a^5 + 2*a^4 + 8*a^3 + 9*a^2 + a, 1), (a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a, 1), (9*a^5 + 5*a^4 + 10*a^3 + 8*a^2 + 3*a + 1, 1), (2*a^5 + 8*a^4 + 3*a^3 + 6*a + 2, 1), (a^5 + 3*a^4 + 8*a^3 + 2*a^2 + 3*a + 4, 1), (10*a^5 + 3*a^4 + 8*a^3 + a^2 + 10*a + 4, 1)] - sage: f.any_root(GF(11^6, 'a')) + sage: sorted(f.roots(GF(11^6, 'a'))) # optional - sage.libs.pari + [(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 a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a - sage: g = (x-1)*(x^2 + 3*x + 9) * (x^5 + 5*x^4 + 8*x^3 + 5*x^2 + 3*x + 5) - sage: g.any_root(ring=GF(11^10, 'b'), degree=1) + sage: g = (x-1)*(x^2 + 3*x + 9) * (x^5 + 5*x^4 + 8*x^3 + 5*x^2 + 3*x + 5) # optional - sage.libs.pari + sage: g.any_root(ring=GF(11^10, 'b'), degree=1) # optional - sage.libs.pari 1 - sage: g.any_root(ring=GF(11^10, 'b'), degree=2) + sage: g.any_root(ring=GF(11^10, 'b'), degree=2) # optional - sage.libs.pari 5*b^9 + 4*b^7 + 4*b^6 + 8*b^5 + 10*b^2 + 10*b + 5 - sage: g.any_root(ring=GF(11^10, 'b'), degree=5) + sage: g.any_root(ring=GF(11^10, 'b'), degree=5) # optional - sage.libs.pari 5*b^9 + b^8 + 3*b^7 + 2*b^6 + b^5 + 4*b^4 + 3*b^3 + 7*b^2 + 10*b TESTS:: - sage: R. = GF(5)[] - sage: K. = GF(5^12) - sage: for _ in range(40): + sage: R. = GF(5)[] # optional - sage.libs.pari + sage: K. = GF(5^12) # optional - sage.libs.pari + sage: for _ in range(40): # optional - sage.libs.pari ....: f = R.random_element(degree=4) ....: assert f(f.any_root(K)) == 0 Check that our Cantor-Zassenhaus implementation does not loop over finite fields of even characteristic (see :trac:`16162`):: - sage: K. = GF(2**8) - sage: x = polygen(K) - sage: r = (x**2+x+1).any_root() # used to loop - sage: r**2 + r + sage: K. = GF(2**8) # optional - sage.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 1 - sage: (x**2+a+1).any_root() + sage: (x**2+a+1).any_root() # optional - sage.libs.pari a^7 + a^2 Also check that such computations can be interrupted:: - sage: K. = GF(2^8) - sage: x = polygen(K) - sage: pol = x^1000000 + x + a - sage: alarm(0.5); pol.any_root() + sage: K. = GF(2^8) # optional - sage.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 Traceback (most recent call last): ... AlarmInterrupt Check root computation over large finite fields:: - sage: K. = GF(2**50) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a - sage: K. = GF(2**150) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + a^8 + a^6 + a^5 + a^4 + a + 1 + sage: K. = GF(2**50) # optional - sage.libs.pari + sage: x = polygen(K) # optional - sage.libs.pari + sage: (x**10+x+a).any_root() # optional - sage.libs.pari + 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 + a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + + a^8 + a^6 + a^5 + a^4 + a + 1 Check that :trac:`21998` has been resolved:: - sage: K. = GF(2^4) - sage: R. = K[] - sage: f = x^2 + x + a^2 + a - sage: r = f.any_root() - sage: r^2 + r + sage: K. = GF(2^4) # optional - sage.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 a^2 + a """ if self.base_ring().is_finite() and self.base_ring().is_field(): @@ -2290,9 +2304,9 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') - sage: f = x^3 + 4*x - sage: f / (x - 1) + sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') # optional - sage.libs.pari + sage: f = x^3 + 4*x # optional - sage.libs.pari + sage: f / (x - 1) # optional - sage.libs.pari x^2 + x Be careful about coercions (this used to be broken):: @@ -2307,21 +2321,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`12217` is fixed:: - sage: P. = GF(5)[] - sage: x/0 + sage: P. = GF(5)[] # optional - sage.libs.pari + sage: x/0 # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(0, 5) does not exist - sage: P. = GF(25, 'a')[] - sage: x/5 + sage: P. = GF(25, 'a')[] # optional - sage.libs.pari + sage: x/5 # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: division by zero in finite field Check that :trac:`23611` is fixed:: - sage: int(1) / x + sage: int(1) / x # optional - sage.libs.pari 1/x """ # Same parents => bypass coercion @@ -2354,10 +2368,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f^3 x^3 - 3*x^2 + 3*x - 1 - sage: R = PolynomialRing(GF(2), 'x') - sage: f = R(x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x) - sage: h = R(x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1) - sage: pow(f, 2, h) + sage: R = PolynomialRing(GF(2), 'x') # optional - sage.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 x^9 + x^8 + x^7 + x^5 + x^3 TESTS:: @@ -2384,46 +2398,46 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: k = GF(5) - sage: D. = k[] - sage: l. = k.extension(x^2 + 2) - sage: R. = l[] - sage: f = t^4 + (2*x - 1)*t^3 + (2*x + 1)*t^2 + 3 - sage: h = t^4 - x*t^3 + (3*x + 1)*t^2 + 2*t + 2*x - 1 - sage: pow(f, 2, h) + sage: k = GF(5) # optional - sage.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 3*t^3 + (2*x + 3)*t^2 + (2*x + 2)*t + 2*x + 2 - sage: pow(f, 10**7, h) + sage: pow(f, 10**7, h) # optional - sage.libs.pari 4*x*t^3 + 2*x*t^2 + 4*x*t + 4 Check that :trac:`18457` is fixed:: - sage: R. = PolynomialRing(GF(5), sparse=True) - sage: (1+x)^(5^10) # used to hang forever + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.libs.pari + sage: (1+x)^(5^10) # used to hang forever # optional - sage.libs.pari x^9765625 + 1 - sage: S. = GF(3)[] - sage: R1. = PolynomialRing(S, sparse=True) - sage: (1+x+t)^(3^10) + sage: S. = GF(3)[] # optional - sage.libs.pari + sage: R1. = PolynomialRing(S, sparse=True) # optional - sage.libs.pari + sage: (1+x+t)^(3^10) # optional - sage.libs.pari x^59049 + t^59049 + 1 - sage: R2. = PolynomialRing(S, sparse=False) - sage: (1+x+t)^(3^10) + sage: R2. = PolynomialRing(S, sparse=False) # optional - sage.libs.pari + sage: (1+x+t)^(3^10) # optional - sage.libs.pari x^59049 + t^59049 + 1 Check that the algorithm used is indeed correct:: sage: from sage.arith.power import generic_power - sage: R1 = PolynomialRing(GF(8,'a'), 'x') - sage: R2 = PolynomialRing(GF(9,'b'), 'x', sparse=True) - sage: R3 = PolynomialRing(R2, 'y') - sage: R4 = PolynomialRing(R1, 'y', sparse=True) - sage: for d in range(20,40): # long time + sage: R1 = PolynomialRing(GF(8,'a'), 'x') # optional - sage.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 ....: for R in [R1, R2, R3, R3]: ....: a = R.random_element() ....: assert a^d == generic_power(a, d) Test the powering modulo ``x^n`` (calling :meth:`power_trunc`):: - sage: R. = GF(3)[] - sage: pow(x + 1, 51, x^7) + sage: R. = GF(3)[] # optional - sage.libs.pari + sage: pow(x + 1, 51, x^7) # optional - sage.libs.pari x^6 + 2*x^3 + 1 sage: S. = QQ[] @@ -2434,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)[] - sage: k. = kk.quo(a^2+a+1) - sage: K. = k[] - sage: (T*y)^21 + 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 T^21 """ if not isinstance(left, Polynomial): @@ -2529,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)[] - sage: p = x^2 - x + 1 - sage: q = p.power_trunc(80, 20) - sage: q + 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 x^19 + x^18 + ... + 2*x^4 + 2*x^3 + x + 1 - sage: (p^80).truncate(20) == q + sage: (p^80).truncate(20) == q # optional - sage.libs.pari True - sage: R. = GF(7)[] - sage: p = (x^2 + x + 1).power_trunc(2^100, 100) - sage: p + 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 2*x^99 + x^98 + x^95 + 2*x^94 + ... + 3*x^2 + 2*x + 1 - sage: for i in range(100): + sage: for i in range(100): # optional - sage.libs.pari ....: 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) @@ -2632,10 +2646,10 @@ cdef class Polynomial(CommutativePolynomial): elements in the Sage library yet that do not implement ``__bool__``, so we have to create one artificially.):: - sage: class PatchedAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): + sage: class PatchedAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): # optional - sage.rings.number_field ....: def __bool__(self): raise NotImplementedError() - sage: R. = QQbar[] - sage: R([PatchedAlgebraicNumber(0), 1]) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R([PatchedAlgebraicNumber(0), 1]) # optional - sage.rings.number_field x + 0 """ if name is None: @@ -2710,10 +2724,10 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: C3. = CyclotomicField(3) - sage: R. = C3[] - sage: f = X^3 - omega*X - sage: latex(f) + sage: C3. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = C3[] # optional - sage.rings.number_field + sage: f = X^3 - omega*X # optional - sage.rings.number_field + sage: latex(f) # optional - sage.rings.number_field X^{3} - \omega X sage: R. = RDF[] sage: latex(x+2) @@ -2726,9 +2740,9 @@ cdef class Polynomial(CommutativePolynomial): The following illustrates a (non-intentional) superfluity of parentheses - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: latex(I*x^2-I*x) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: latex(I*x^2 - I*x) # optional - sage.rings.number_field \left(\sqrt{-1}\right) x^{2} + \left(-\sqrt{-1}\right) x """ s = " " @@ -2801,7 +2815,7 @@ cdef class Polynomial(CommutativePolynomial): # Verified R. = RR[] 3.1415926535897931*x - sage: sage_input(polygen(GF(7)) + 12, verify=True) + sage: sage_input(polygen(GF(7)) + 12, verify=True) # optional - sage.libs.pari # Verified R. = GF(7)[] x + 5 @@ -2910,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) - sage: R.inject_variables(verbose=False) - sage: A, B, C = a0 + a1*y + a2*y^2, b0 + b1*y + b2*y^2, c1*y + c2*y^2 - sage: D = d0 + d1*y + d2*y^2 + d3*y^3 + d4*y^4 + d5*y^5 + d6*y^6 + d7*y^7 - sage: F = D.subs({y: B}) - sage: G = A.subs({y: F}) + C - sage: g = G.mod(y^8 + y) - sage: g.degree(y) + sage: R = PolynomialRing(GF(8), 17, gens) # optional - sage.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 7 """ return self % other @@ -2956,10 +2970,10 @@ cdef class Polynomial(CommutativePolynomial): Show the product in the symbolic ring:: - sage: L = SR['x'] - sage: var('a0,a1,b0,b1') + sage: L = SR['x'] # optional - sage.symbolic + sage: var('a0,a1,b0,b1') # optional - sage.symbolic (a0, a1, b0, b1) - sage: L([a0,a1])._mul_generic(L([b0,b1])) + sage: L([a0, a1])._mul_generic(L([b0, b1])) # optional - sage.symbolic a1*b1*x^2 + (a1*b0 + a0*b1)*x + a0*b0 A non-commutative example:: @@ -3174,12 +3188,12 @@ cdef class Polynomial(CommutativePolynomial): Show the product in the symbolic ring:: - sage: L = SR['x'] - sage: var('a0,a1,b0,b1') + sage: L = SR['x'] # optional - sage.symbolic + sage: var('a0,a1,b0,b1') # optional - sage.symbolic (a0, a1, b0, b1) - sage: L([a0,a1])._mul_karatsuba(L([b0,b1]),0) + sage: L([a0, a1])._mul_karatsuba(L([b0, b1]), 0) # optional - sage.symbolic a1*b1*x^2 + ((a0 + a1)*(b0 + b1) - a0*b0 - a1*b1)*x + a0*b0 - sage: L([a0,a1])._mul_karatsuba(L([b0,b1]),2) + sage: L([a0, a1])._mul_karatsuba(L([b0, b1]), 2) # optional - sage.symbolic a1*b1*x^2 + (a1*b0 + a0*b1)*x + a0*b0 A noncommutative example:: @@ -3307,11 +3321,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 - 17*x + 3 - sage: f.base_extend(GF(7)) + sage: f.base_extend(GF(7)) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: no such base extension - sage: f.change_ring(GF(7)) + sage: f.change_ring(GF(7)) # optional - sage.libs.pari x^3 + 4*x + 3 """ S = self._parent.base_extend(R) @@ -3344,17 +3358,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: f = K.defining_polynomial() - sage: f.change_ring(GF(7)) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: f = K.defining_polynomial() # optional - sage.rings.number_field + sage: f.change_ring(GF(7)) # optional - sage.libs.pari # optional - sage.rings.number_field x^2 + x + 1 :: - sage: K. = CyclotomicField(3) - sage: R. = K[] - sage: f = x^2 + z - sage: f.change_ring(K.embeddings(CC)[1]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + z # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(CC)[1]) # optional - sage.rings.number_field x^2 - 0.500000000000000 - 0.866025403784438*I :: @@ -3376,10 +3390,10 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28541` is fixed:: - sage: F. = GF(7^2) - sage: S. = F[] - sage: P = x^2 + a*x + a^2 - sage: P.change_ring(F.frobenius_endomorphism()) + sage: F. = GF(7^2) # optional - sage.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 x^2 + (6*a + 1)*x + 6*a + 5 """ if isinstance(R, Map): @@ -3577,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)[] - sage: x = R(0) - sage: x.denominator() + sage: R. = GF(5)[] # optional - sage.libs.pari + sage: x = R(0) # optional - sage.libs.pari + sage: x.denominator() # optional - sage.libs.pari 1 - sage: type(x.denominator()) + sage: type(x.denominator()) # optional - sage.libs.pari - sage: isinstance(x.numerator() / x.denominator(), Polynomial) + sage: isinstance(x.numerator() / x.denominator(), Polynomial) # optional - sage.libs.pari True - sage: isinstance(x.numerator() / R(1), Polynomial) + sage: isinstance(x.numerator() / R(1), Polynomial) # optional - sage.libs.pari False TESTS: @@ -3667,12 +3681,12 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: K=NumberField(symbolic_expression('x^3+2'),'a')['s,t']['x'] - sage: f=K.random_element() - sage: f.numerator() / f.denominator() == f + sage: K = NumberField(symbolic_expression('x^3+2'), 'a')['s,t']['x'] # optional - sage.rings.number_field sage.symbolic + sage: f = K.random_element() # optional - sage.rings.number_field sage.symbolic + sage: f.numerator() / f.denominator() == f # optional - sage.rings.number_field sage.symbolic True - sage: R=RR['x'] - sage: f=R.random_element() + sage: R = RR['x'] + sage: f = R.random_element() sage: f.numerator() / f.denominator() == f True """ @@ -3782,17 +3796,17 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28147` is fixed:: - sage: R. = GF(65537)[] - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 - sage: p.derivative() + sage: R. = GF(65537)[] # optional - sage.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 4*x^3 + 65486*x^2 + 4*x + 65536 - sage: R. = GF(19^2)[] - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 - sage: p.derivative() + sage: R. = GF(19^2)[] # optional - sage.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 4*x^3 + 6*x^2 + 4*x + 18 - sage: R. = GF(2)[] - sage: p = x^4 + x^2 + x - sage: p.derivative() + sage: R. = GF(2)[] # optional - sage.libs.pari + sage: p = x^4 + x^2 + x # optional - sage.libs.pari + sage: p.derivative() # optional - sage.libs.pari 1 sage: R. = Integers(77)[] @@ -3807,8 +3821,8 @@ cdef class Polynomial(CommutativePolynomial): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var("y") - sage: f._derivative(y) + sage: y = var("y") # optional - sage.symbolic + sage: f._derivative(y) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -3816,21 +3830,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`26844` is fixed by :trac:`28147`:: - sage: A = PolynomialRing(GF(3), name='t') - sage: K = A.fraction_field() - sage: t = K.gen() - sage: t.derivative(t) + sage: A = PolynomialRing(GF(3), name='t') # optional - sage.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 1 Check that :trac:`28187` is fixed:: - sage: R. = GF(65537)[] - sage: x._derivative(2*x) + sage: R. = GF(65537)[] # optional - sage.libs.pari + sage: x._derivative(2*x) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var('y') - sage: R.gen()._derivative(y) + sage: y = var('y') # optional - sage.symbolic + sage: R.gen()._derivative(y) # optional - sage.libs.pari sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -3907,16 +3921,16 @@ cdef class Polynomial(CommutativePolynomial): This shows that the issue at :trac:`7711` is resolved:: - sage: P. = PolynomialRing(GF(2147483647)) - sage: Q. = PolynomialRing(P) - sage: p=x+y+z - sage: p.integral() + sage: P. = PolynomialRing(GF(2147483647)) # optional - sage.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 -1073741823*y^2 + (x + z)*y - sage: P. = PolynomialRing(GF(next_prime(2147483647))) - sage: Q. = PolynomialRing(P) - sage: p=x+y+z - sage: p.integral() + sage: P. = PolynomialRing(GF(next_prime(2147483647))) # optional - sage.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 1073741830*y^2 + (x + z)*y A truly convoluted example:: @@ -4049,38 +4063,39 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = (x^3 - 1)^2 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (x - 1)^2 * (x^2 + x + 1)^2 Since `\QQ` is a field, the irreducible factors are monic:: sage: f = 10*x^5 - 1 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (10) * (x^5 - 1/10) sage: f = 10*x^5 - 10 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) Over `\ZZ` the irreducible factors need not be monic:: sage: x = ZZ['x'].0 sage: f = 10*x^5 - 1 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari 10*x^5 - 1 We factor a non-monic polynomial over a finite field of 25 elements:: - sage: k. = GF(25) - sage: R. = k[] - sage: f = 2*x^10 + 2*x + 2*a - sage: F = f.factor(); F - (2) * (x + a + 2) * (x^2 + 3*x + 4*a + 4) * (x^2 + (a + 1)*x + a + 2) * (x^5 + (3*a + 4)*x^4 + (3*a + 3)*x^3 + 2*a*x^2 + (3*a + 1)*x + 3*a + 1) + sage: k. = GF(25) # optional - sage.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 + (2) * (x + a + 2) * (x^2 + 3*x + 4*a + 4) * (x^2 + (a + 1)*x + a + 2) + * (x^5 + (3*a + 4)*x^4 + (3*a + 3)*x^3 + 2*a*x^2 + (3*a + 1)*x + 3*a + 1) Notice that the unit factor is included when we multiply `F` back out:: - sage: expand(F) + sage: expand(F) # optional - sage.libs.pari 2*x^10 + 2*x + 2*a A new ring. In the example below, we set the special method @@ -4089,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") - sage: (x^2).factor() + sage: R. = PolynomialRing(IntegerModRing(4), implementation="NTL") # optional - sage.libs.ntl + sage: (x^2).factor() # optional - sage.libs.ntl Traceback (most recent call last): ... NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented sage: R.base_ring()._factor_univariate_polynomial = lambda f: f.change_ring(ZZ).factor() sage: (x^2).factor() # optional - sage.libs.pari x^2 - sage: del R.base_ring()._factor_univariate_polynomial # clean up + sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl Arbitrary precision real and complex factorization:: @@ -4125,24 +4140,26 @@ cdef class Polynomial(CommutativePolynomial): Over a number field:: - sage: K. = CyclotomicField(15) - sage: x = polygen(K) - sage: ((x^3 + z*x + 1)^3*(x - z)).factor() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: ((x^3 + z*x + 1)^3 * (x - z)).factor() # optional - sage.rings.number_field (x - z) * (x^3 + z*x + 1)^3 - sage: cyclotomic_polynomial(12).change_ring(K).factor() + sage: cyclotomic_polynomial(12).change_ring(K).factor() # optional - sage.rings.number_field (x^2 - z^5 - 1) * (x^2 + z^5) - sage: ((x^3 + z*x + 1)^3*(x/(z+2) - 1/3)).factor() - (-1/331*z^7 + 3/331*z^6 - 6/331*z^5 + 11/331*z^4 - 21/331*z^3 + 41/331*z^2 - 82/331*z + 165/331) * (x - 1/3*z - 2/3) * (x^3 + z*x + 1)^3 + sage: ((x^3 + z*x + 1)^3 * (x/(z+2) - 1/3)).factor() # optional - sage.rings.number_field + (-1/331*z^7 + 3/331*z^6 - 6/331*z^5 + 11/331*z^4 + - 21/331*z^3 + 41/331*z^2 - 82/331*z + 165/331) + * (x - 1/3*z - 2/3) * (x^3 + z*x + 1)^3 Over a relative number field:: sage: x = polygen(QQ) - sage: K. = CyclotomicField(3) - sage: L. = K.extension(x^3 - 2) - sage: t = polygen(L, 't') - sage: f = (t^3 + t + a)*(t^5 + t + z); f + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 2) # optional - sage.rings.number_field + sage: t = polygen(L, 't') # optional - sage.rings.number_field + sage: f = (t^3 + t + a) * (t^5 + t + z); f # optional - sage.rings.number_field t^8 + t^6 + a*t^5 + t^4 + z*t^3 + t^2 + (a + z)*t + z*a - sage: f.factor() + sage: f.factor() # optional - sage.rings.number_field (t^3 + t + a) * (t^5 + t + z) Over the real double field:: @@ -4187,16 +4204,22 @@ cdef class Polynomial(CommutativePolynomial): Factoring polynomials over the algebraic numbers (see :trac:`8544`):: - sage: R. = QQbar[] - sage: (x^8-1).factor() - (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) * (x + 0.7071067811865475? - 0.7071067811865475?*I) * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^8 - 1).factor() # optional - sage.rings.number_field + (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) + * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) + * (x + 0.7071067811865475? - 0.7071067811865475?*I) + * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1) Factoring polynomials over the algebraic reals (see :trac:`8544`):: - sage: R. = AA[] - sage: (x^8+1).factor() - (x^2 - 1.847759065022574?*x + 1.000000000000000?) * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 1.847759065022574?*x + 1.000000000000000?) + sage: R. = AA[] # optional - sage.rings.number_field + sage: (x^8 + 1).factor() # optional - sage.rings.number_field + (x^2 - 1.847759065022574?*x + 1.000000000000000?) + * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) + * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) + * (x^2 + 1.847759065022574?*x + 1.000000000000000?) TESTS: @@ -4217,91 +4240,94 @@ cdef class Polynomial(CommutativePolynomial): sage: f = 8*x^9 + 42*x^6 + 6*x^3 - 1 sage: g = x^24 - 12*x^23 + 72*x^22 - 286*x^21 + 849*x^20 - 2022*x^19 + 4034*x^18 - 6894*x^17 + 10182*x^16 - 13048*x^15 + 14532*x^14 - 13974*x^13 + 11365*x^12 - 7578*x^11 + 4038*x^10 - 1766*x^9 + 762*x^8 - 408*x^7 + 236*x^6 - 126*x^5 + 69*x^4 - 38*x^3 + 18*x^2 - 6*x + 1 sage: assert g.is_irreducible() - sage: K. = NumberField(g) - sage: len(f.roots(K)) + sage: K. = NumberField(g) # optional - sage.rings.number_field + sage: len(f.roots(K)) # optional - sage.rings.number_field 9 sage: f.factor() (8) * (x^3 + 1/4) * (x^6 + 5*x^3 - 1/2) - sage: f.change_ring(K).factor() + sage: f.change_ring(K).factor() # optional - sage.rings.number_field (8) * (x - 3260097/3158212*a^22 + 35861067/3158212*a^21 - 197810817/3158212*a^20 + 722970825/3158212*a^19 - 1980508347/3158212*a^18 + 4374189477/3158212*a^17 - 4059860553/1579106*a^16 + 6442403031/1579106*a^15 - 17542341771/3158212*a^14 + 20537782665/3158212*a^13 - 20658463789/3158212*a^12 + 17502836649/3158212*a^11 - 11908953451/3158212*a^10 + 6086953981/3158212*a^9 - 559822335/789553*a^8 + 194545353/789553*a^7 - 505969453/3158212*a^6 + 338959407/3158212*a^5 - 155204647/3158212*a^4 + 79628015/3158212*a^3 - 57339525/3158212*a^2 + 26692783/3158212*a - 1636338/789553) * ... - sage: f = QQbar['x'](1) - sage: f.factor() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.factor() # optional - sage.rings.number_field 1 Factorization also works even if the variable of the finite field is nefariously labeled `x`:: - sage: R. = GF(3^2, 'x')[] - sage: f = x^10 +7*x -13 - sage: G = f.factor(); G - (x + x) * (x + 2*x + 1) * (x^4 + (x + 2)*x^3 + (2*x + 2)*x + 2) * (x^4 + 2*x*x^3 + (x + 1)*x + 2) + sage: R. = GF(3^2, 'x')[] # optional - sage.libs.pari + sage: f = x^10 +7*x -13 # optional - sage.libs.pari + sage: G = f.factor(); G # optional - sage.libs.pari + (x + x) * (x + 2*x + 1) * (x^4 + (x + 2)*x^3 + (2*x + 2)*x + 2) + * (x^4 + 2*x*x^3 + (x + 1)*x + 2) sage: prod(G) == f True :: - sage: R. = GF(9,'x')[] # purposely calling it x to test robustness - sage: f = x0^3 + x0 + 1 - sage: f.factor() + sage: R. = GF(9,'x')[] # purposely calling it x to test robustness # optional - sage.libs.pari + sage: f = x0^3 + x0 + 1 # optional - sage.libs.pari + sage: f.factor() # optional - sage.libs.pari (x0 + 2) * (x0 + x) * (x0 + 2*x + 1) - sage: f = 0*x0 - sage: f.factor() + sage: f = 0*x0 # optional - sage.libs.pari + sage: f.factor() # optional - sage.libs.pari Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined :: - sage: f = x0^0 - sage: f.factor() + sage: f = x0^0 # optional - sage.libs.pari + sage: f.factor() # optional - sage.libs.pari 1 Over a complicated number field:: sage: x = polygen(QQ, 'x') sage: f = x^6 + 10/7*x^5 - 867/49*x^4 - 76/245*x^3 + 3148/35*x^2 - 25944/245*x + 48771/1225 - sage: K. = NumberField(f) - sage: S. = K[] - sage: ff = S(f); ff + sage: K. = NumberField(f) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: ff = S(f); ff # optional - sage.rings.number_field T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/1225 - sage: F = ff.factor() - sage: len(F) + sage: F = ff.factor() # optional - sage.rings.number_field + sage: len(F) # optional - sage.rings.number_field 4 - sage: F[:2] - [(T - a, 1), (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^4 + 527617096480/924556084127*a^3 + 1289745809920/924556084127*a^2 - 3227142391585/924556084127*a - 401502691578/924556084127, 1)] - sage: expand(F) + sage: F[:2] # optional - sage.rings.number_field + [(T - a, 1), + (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^4 + 527617096480/924556084127*a^3 + + 1289745809920/924556084127*a^2 - 3227142391585/924556084127*a - 401502691578/924556084127, 1)] + sage: expand(F) # optional - sage.rings.number_field T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/1225 :: sage: f = x^2 - 1/3 - sage: K. = NumberField(f) - sage: A. = K[] - sage: A(x^2 - 1).factor() + sage: K. = NumberField(f) # optional - sage.rings.number_field + sage: A. = K[] # optional - sage.rings.number_field + sage: A(x^2 - 1).factor() # optional - sage.rings.number_field (T - 1) * (T + 1) :: - sage: A(3*x^2 - 1).factor() + sage: A(3*x^2 - 1).factor() # optional - sage.rings.number_field (3) * (T - a) * (T + a) :: - sage: A(x^2 - 1/3).factor() + sage: A(x^2 - 1/3).factor() # optional - sage.rings.number_field (T - a) * (T + a) Test that :trac:`10279` is fixed:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(t^4 - t^2 + 1) - sage: pol = t^3 + (-4*a^3 + 2*a)*t^2 - 11/3*a^2*t + 2/3*a^3 - 4/3*a - sage: pol.factor() + sage: K. = NumberField(t^4 - t^2 + 1) # optional - sage.rings.number_field + sage: pol = t^3 + (-4*a^3 + 2*a)*t^2 - 11/3*a^2*t + 2/3*a^3 - 4/3*a # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (t - 2*a^3 + a) * (t - 4/3*a^3 + 2/3*a) * (t - 2/3*a^3 + 1/3*a) Test that this factorization really uses ``nffactor()`` internally:: sage: pari.default("debug", 3) - sage: F = pol.factor() + sage: F = pol.factor() # optional - sage.rings.number_field Entering nffactor: ... @@ -4310,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) - sage: R. = PolynomialRing(K) + sage: K. = NumberField(x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field - sage: pol = (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7)*t^10 + (4/7*a^5 - 2/7*a^4 - 2/7*a^3 - 2/7*a^2 - 2/7*a - 6/7)*t^9 + (90/49*a^5 + 152/49*a^4 + 18/49*a^3 + 24/49*a^2 + 30/49*a + 36/49)*t^8 + (-10/49*a^5 + 10/7*a^4 + 198/49*a^3 - 102/49*a^2 - 60/49*a - 26/49)*t^7 + (40/49*a^5 + 45/49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49)*t^6 + (90/49*a^5 + 110/49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 + 250/49*a^3 + 232/49*a^2 + 32/7*a + 8)*t^4 + (-184/49*a^5 - 58/49*a^4 - 52/49*a^3 - 66/49*a^2 - 72/49*a - 72/49)*t^3 + (18/49*a^5 - 32/49*a^4 + 10/49*a^3 + 4/49*a^2)*t^2 + (2/49*a^4 - 4/49*a^3 + 2/49*a^2)*t - sage: pol.factor() + sage: pol = (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7)*t^10 + (4/7*a^5 - 2/7*a^4 - 2/7*a^3 - 2/7*a^2 - 2/7*a - 6/7)*t^9 + (90/49*a^5 + 152/49*a^4 + 18/49*a^3 + 24/49*a^2 + 30/49*a + 36/49)*t^8 + (-10/49*a^5 + 10/7*a^4 + 198/49*a^3 - 102/49*a^2 - 60/49*a - 26/49)*t^7 + (40/49*a^5 + 45/49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49)*t^6 + (90/49*a^5 + 110/49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 + 250/49*a^3 + 232/49*a^2 + 32/7*a + 8)*t^4 + (-184/49*a^5 - 58/49*a^4 - 52/49*a^3 - 66/49*a^2 - 72/49*a - 72/49)*t^3 + (18/49*a^5 - 32/49*a^4 + 10/49*a^3 + 4/49*a^2)*t^2 + (2/49*a^4 - 4/49*a^3 + 2/49*a^2)*t # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7) * t * (t - a^5 - a^4 - a^3 - a^2 - a - 1)^4 * (t^5 + (-12/7*a^5 - 10/7*a^4 - 8/7*a^3 - 6/7*a^2 - 4/7*a - 2/7)*t^4 + (12/7*a^5 - 8/7*a^3 + 16/7*a^2 + 2/7*a + 20/7)*t^3 + (-20/7*a^5 - 20/7*a^3 - 20/7*a^2 + 4/7*a - 2)*t^2 + (12/7*a^5 + 12/7*a^3 + 2/7*a + 16/7)*t - 4/7*a^5 - 4/7*a^3 - 4/7*a - 2/7) - sage: pol = (1/7*a^2 - 1/7*a)*t^10 + (4/7*a - 6/7)*t^9 + (102/49*a^5 + 99/49*a^4 + 96/49*a^3 + 93/49*a^2 + 90/49*a + 150/49)*t^8 + (-160/49*a^5 - 36/49*a^4 - 48/49*a^3 - 8/7*a^2 - 60/49*a - 60/49)*t^7 + (30/49*a^5 - 55/49*a^4 + 20/49*a^3 + 5/49*a^2)*t^6 + (6/49*a^4 - 12/49*a^3 + 6/49*a^2)*t^5 - sage: pol.factor() + sage: pol = (1/7*a^2 - 1/7*a)*t^10 + (4/7*a - 6/7)*t^9 + (102/49*a^5 + 99/49*a^4 + 96/49*a^3 + 93/49*a^2 + 90/49*a + 150/49)*t^8 + (-160/49*a^5 - 36/49*a^4 - 48/49*a^3 - 8/7*a^2 - 60/49*a - 60/49)*t^7 + (30/49*a^5 - 55/49*a^4 + 20/49*a^3 + 5/49*a^2)*t^6 + (6/49*a^4 - 12/49*a^3 + 6/49*a^2)*t^5 # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (1/7*a^2 - 1/7*a) * t^5 * (t^5 + (-40/7*a^5 - 38/7*a^4 - 36/7*a^3 - 34/7*a^2 - 32/7*a - 30/7)*t^4 + (60/7*a^5 - 30/7*a^4 - 18/7*a^3 - 9/7*a^2 - 3/7*a)*t^3 + (60/7*a^4 - 40/7*a^3 - 16/7*a^2 - 4/7*a)*t^2 + (30/7*a^3 - 25/7*a^2 - 5/7*a)*t + 6/7*a^2 - 6/7*a) - sage: pol = x^10 + (4/7*a - 6/7)*x^9 + (9/49*a^2 - 3/7*a + 15/49)*x^8 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^7 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x^6 + (-6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807)*x^5 - sage: pol.factor() + sage: pol = x^10 + (4/7*a - 6/7)*x^9 + (9/49*a^2 - 3/7*a + 15/49)*x^8 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^7 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x^6 + (-6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807)*x^5 # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field x^5 * (x^5 + (4/7*a - 6/7)*x^4 + (9/49*a^2 - 3/7*a + 15/49)*x^3 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^2 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x - 6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807) Factoring over a number field over which we cannot factor the discriminant by trial division:: sage: x = polygen(QQ) - sage: K. = NumberField(x^16 - x - 6) - sage: R. = PolynomialRing(K) - sage: f = (x+a)^50 - (a-1)^50 - sage: len(factor(f)) + sage: K. = NumberField(x^16 - x - 6) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = (x+a)^50 - (a-1)^50 # optional - sage.rings.number_field + sage: len(factor(f)) # optional - sage.rings.number_field 6 - sage: pari(K.discriminant()).factor(limit=10^6) + sage: pari(K.discriminant()).factor(limit=10^6) # optional - sage.rings.number_field [-1, 1; 3, 15; 23, 1; 887, 1; 12583, 1; 2354691439917211, 1] - sage: factor(K.discriminant()) + sage: factor(K.discriminant()) # optional - sage.rings.number_field -1 * 3^15 * 23 * 887 * 12583 * 6335047 * 371692813 Factoring over a number field over which we cannot factor the discriminant and over which `nffactor()` fails:: sage: p = next_prime(10^50); q = next_prime(10^51); n = p*q - sage: K. = QuadraticField(p*q) - sage: R. = PolynomialRing(K) - sage: K.pari_polynomial('a').nffactor("x^2+1") + sage: K. = QuadraticField(p*q) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: K.pari_polynomial('a').nffactor("x^2+1") # optional - sage.rings.number_field Mat([x^2 + 1, 1]) - sage: factor(x^2 + 1) + sage: factor(x^2 + 1) # optional - sage.rings.number_field x^2 + 1 - sage: factor( (x - a) * (x + 2*a) ) + sage: factor((x - a) * (x + 2*a)) # optional - sage.rings.number_field (x - a) * (x + 2*a) A test where nffactor used to fail without a nf structure:: sage: x = polygen(QQ) - sage: K = NumberField([x^2-1099511627777, x^3-3],'a') - sage: x = polygen(K) - sage: f = x^3 - 3 - sage: factor(f) + sage: K = NumberField([x^2-1099511627777, x^3-3], 'a') # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: f = x^3 - 3 # optional - sage.rings.number_field + sage: factor(f) # optional - sage.rings.number_field (x - a1) * (x^2 + a1*x + a1^2) We check that :trac:`7554` is fixed:: @@ -4540,31 +4566,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R.=PolynomialRing(ZZ) sage: f = (2*x + 1) * (3*x^2 - 5)^2 - sage: f._factor_pari_helper(pari(f).factor()) + sage: f._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (2*x + 1) * (3*x^2 - 5)^2 - sage: f._factor_pari_helper(pari(f).factor(), unit=11) + sage: f._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari 11 * (2*x + 1) * (3*x^2 - 5)^2 - sage: (8*f)._factor_pari_helper(pari(f).factor()) + sage: (8*f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari 8 * (2*x + 1) * (3*x^2 - 5)^2 - sage: (8*f)._factor_pari_helper(pari(f).factor(), unit=11) + sage: (8*f)._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari 88 * (2*x + 1) * (3*x^2 - 5)^2 - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor(), unit=11) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari (198) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) - sage: F = f._factor_pari_helper(pari(f).factor()); F + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari + sage: F = f._factor_pari_helper(pari(f).factor()); F # optional - sage.libs.pari 1323551250 * (2*x^2 + 1) * (3*x^3 + 1)^2 * (5*x^5 + 1)^4 * (7*x^7 + 1)^6 - sage: F.prod() == f + sage: F.prod() == f # optional - sage.libs.pari True - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: g = GF(19)['x'](f) - sage: G = g._factor_pari_helper(pari(g).factor()); G - (4) * (x + 3) * (x + 16)^5 * (x + 11)^6 * (x^2 + 7*x + 9)^4 * (x^2 + 15*x + 9)^4 * (x^3 + 13)^2 * (x^6 + 8*x^5 + 7*x^4 + 18*x^3 + 11*x^2 + 12*x + 1)^6 - sage: G.prod() == g + sage: g = GF(19)['x'](f) # optional - sage.libs.pari + sage: G = g._factor_pari_helper(pari(g).factor()); G # optional - sage.libs.pari + (4) * (x + 3) * (x + 16)^5 * (x + 11)^6 * (x^2 + 7*x + 9)^4 + * (x^2 + 15*x + 9)^4 * (x^3 + 13)^2 + * (x^6 + 8*x^5 + 7*x^4 + 18*x^3 + 11*x^2 + 12*x + 1)^6 + sage: G.prod() == g # optional - sage.libs.pari True """ pols, exps = G @@ -4625,25 +4653,25 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: K. = (x^3 + 2).splitting_field(); K + sage: K. = (x^3 + 2).splitting_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^6 + 3*x^5 + 6*x^4 + 11*x^3 + 12*x^2 - 3*x + 1 - sage: K. = (x^3 - 3*x + 1).splitting_field(); K + sage: K. = (x^3 - 3*x + 1).splitting_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - 3*x + 1 Relative situation:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^3 + 2) - sage: S. = PolynomialRing(K) - sage: L. = (t^2 - a).splitting_field() - sage: L + sage: K. = NumberField(x^3 + 2) # optional - sage.rings.number_field + sage: S. = PolynomialRing(K) # optional - sage.rings.number_field + sage: L. = (t^2 - a).splitting_field() # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field Number Field in b with defining polynomial t^6 + 2 With ``map=True``, we also get the embedding of the base field into the splitting field:: - sage: L., phi = (t^2 - a).splitting_field(map=True) - sage: phi + sage: L., phi = (t^2 - a).splitting_field(map=True) # optional - sage.rings.number_field + sage: phi # optional - sage.rings.number_field Ring morphism: From: Number Field in a with defining polynomial x^3 + 2 To: Number Field in b with defining polynomial t^6 + 2 @@ -4651,14 +4679,14 @@ cdef class Polynomial(CommutativePolynomial): An example over a finite field:: - sage: P. = PolynomialRing(GF(7)) - sage: t = x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(7)) # optional - sage.libs.pari + sage: t = x^2 + 1 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 7^2 - sage: P. = PolynomialRing(GF(7^3, 'a')) - sage: t = x^2 + 1 - sage: t.splitting_field('b', map=True) + sage: P. = PolynomialRing(GF(7^3, 'a')) # optional - sage.libs.pari + sage: t = x^2 + 1 # optional - sage.libs.pari + sage: t.splitting_field('b', map=True) # optional - sage.libs.pari (Finite Field in b of size 7^6, Ring morphism: From: Finite Field in a of size 7^3 @@ -4668,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 - sage: t.splitting_field('a', map=True) + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.libs.pari + sage: t.splitting_field('a', map=True) # optional - sage.libs.pari (Finite Field in a of size 7^3, Identity endomorphism of Finite Field in a of size 7^3) - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b', map=True) + sage: t = x^56 - 14*x^3 # optional - sage.libs.pari + sage: t.splitting_field('b', map=True) # optional - sage.libs.pari (Finite Field in b of size 7^3, Ring morphism: From: Finite Field in a of size 7^3 @@ -4696,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')) - sage: t = x^2 + 1 - sage: t.splitting_field('b') + 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 Finite Field in b of size 11^10 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 11^30 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 11^130 - sage: P. = PolynomialRing(GF(19^6, 'a')) - sage: t = -x^6 + x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(19^6, 'a')) # optional - sage.libs.pari + sage: t = -x^6 + x^2 + 1 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 19^6 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 19^18 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 19^156 - sage: P. = PolynomialRing(GF(83^6, 'a')) - sage: t = 2*x^14 - 5 + 6*x - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(83^6, 'a')) # optional - sage.libs.pari + sage: t = 2*x^14 - 5 + 6*x # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 83^84 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 83^78 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 83^12 - sage: P. = PolynomialRing(GF(401^13, 'a')) - sage: t = 2*x^14 - 5 + 6*x - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(401^13, 'a')) # optional - sage.libs.pari + sage: t = 2*x^14 - 5 + 6*x # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 401^104 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 401^156 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.libs.pari + sage: t.splitting_field('b') # optional - sage.libs.pari Finite Field in b of size 401^52 sage: R. = QQ[] @@ -4866,20 +4894,22 @@ cdef class Polynomial(CommutativePolynomial): One can easily add gcd functionality to new rings by providing a method ``_gcd_univariate_polynomial``:: - sage: O = ZZ[-sqrt(5)] - sage: R. = O[] - sage: a = O.1 - sage: p = x + a - sage: q = x^2 - 5 - sage: p.gcd(q) + sage: O = ZZ[-sqrt(5)] # optional - sage.rings.number_field sage.symbolic + sage: R. = O[] # optional - sage.rings.number_field sage.symbolic + sage: a = O.1 # optional - sage.rings.number_field sage.symbolic + sage: p = x + a # optional - sage.rings.number_field sage.symbolic + sage: q = x^2 - 5 # optional - sage.rings.number_field sage.symbolic + sage: p.gcd(q) # optional - sage.rings.number_field sage.symbolic Traceback (most recent call last): ... - NotImplementedError: Order in Number Field in a with defining polynomial x^2 - 5 with a = -2.236067977499790? does not provide a gcd implementation for univariate polynomials - sage: S. = O.number_field()[] - sage: O._gcd_univariate_polynomial = lambda f,g : R(S(f).gcd(S(g))) - sage: p.gcd(q) + NotImplementedError: Order in Number Field in a + with defining polynomial x^2 - 5 with a = -2.236067977499790? does not + provide a gcd implementation for univariate polynomials + sage: S. = O.number_field()[] # optional - sage.rings.number_field sage.symbolic + sage: O._gcd_univariate_polynomial = lambda f,g : R(S(f).gcd(S(g))) # optional - sage.rings.number_field sage.symbolic + sage: p.gcd(q) # optional - sage.rings.number_field sage.symbolic x + a - sage: del O._gcd_univariate_polynomial + sage: del O._gcd_univariate_polynomial # optional - sage.rings.number_field sage.symbolic Use multivariate implementation for polynomials over polynomials rings:: @@ -4933,8 +4963,8 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`32033` has been fixed:: - sage: R. = GF(3)[] - sage: lcm(R(0), R(0)) + sage: R. = GF(3)[] # optional - sage.libs.pari + sage: lcm(R(0), R(0)) # optional - sage.libs.pari 0 :: @@ -5009,26 +5039,26 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = GF(2)['x'] - sage: f = x^4+x^3+x^2+x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: R. = GF(2)['x'] # optional - sage.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 (True, False) - sage: f = x^3+x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: f = x^3+x+1 # optional - sage.libs.pari + sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari (True, True) - sage: R. = GF(3)[] - sage: f = x^3-x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: R. = GF(3)[] # optional - sage.libs.pari + sage: f = x^3-x+1 # optional - sage.libs.pari + sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari (True, True) - sage: f = x^2+1 - sage: f.is_irreducible(), f.is_primitive() + sage: f = x^2+1 # optional - sage.libs.pari + sage: f.is_irreducible(), f.is_primitive() # optional - sage.libs.pari (True, False) - sage: R. = GF(5)[] - sage: f = x^2+x+1 - sage: f.is_primitive() + 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 False - sage: f = x^2-x+2 - sage: f.is_primitive() + sage: f = x^2-x+2 # optional - sage.libs.pari + sage: f.is_primitive() # optional - sage.libs.pari True sage: x=polygen(QQ); f=x^2+1 sage: f.is_primitive() @@ -5048,16 +5078,16 @@ cdef class Polynomial(CommutativePolynomial): sage: f.is_primitive() False - sage: K=NumberField(x^2+5,'a') - sage: R=K.ring_of_integers() - sage: a=R.gen(1) - sage: a^2 + sage: K = NumberField(x^2 + 5, 'a') # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: a = R.gen(1) # optional - sage.rings.number_field + sage: a^2 # optional - sage.rings.number_field -5 - sage: f=a*x+2 - sage: f.is_primitive() + sage: f = a*x + 2 # optional - sage.rings.number_field + sage: f.is_primitive() # optional - sage.rings.number_field True - sage: f=(1+a)*x+2 - sage: f.is_primitive() + sage: f = (1+a)*x + 2 # optional - sage.rings.number_field + sage: f.is_primitive() # optional - sage.rings.number_field False sage: x = polygen(Integers(10)) @@ -5068,30 +5098,30 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(2)['x'] - sage: f = x^4+x^3+x^2+x+1 - sage: f.is_primitive(15) + sage: R. = GF(2)['x'] # optional - sage.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 False - sage: f.is_primitive(15, [3,5]) + sage: f.is_primitive(15, [3,5]) # optional - sage.libs.pari False - sage: f.is_primitive(n_prime_divs=[3,5]) + sage: f.is_primitive(n_prime_divs=[3,5]) # optional - sage.libs.pari False - sage: f = x^3+x+1 - sage: f.is_primitive(7, [7]) + sage: f = x^3+x+1 # optional - sage.libs.pari + sage: f.is_primitive(7, [7]) # optional - sage.libs.pari True - sage: R. = GF(3)[] - sage: f = x^3-x+1 - sage: f.is_primitive(26, [2,13]) + 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 True - sage: f = x^2+1 - sage: f.is_primitive(8, [2]) + sage: f = x^2+1 # optional - sage.libs.pari + sage: f.is_primitive(8, [2]) # optional - sage.libs.pari False - sage: R. = GF(5)[] - sage: f = x^2+x+1 - sage: f.is_primitive(24, [2,3]) + 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 False - sage: f = x^2-x+2 - sage: f.is_primitive(24, [2,3]) + sage: f = x^2-x+2 # optional - sage.libs.pari + sage: f.is_primitive(24, [2,3]) # optional - sage.libs.pari True sage: x = polygen(Integers(103)); f = x^2 + 1 sage: f.is_primitive() # optional - sage.libs.pari @@ -5211,7 +5241,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('a') + sage: f.root_field('a') # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + x + 17 :: @@ -5225,41 +5255,42 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('b') + sage: f.root_field('b') # optional - sage.rings.number_field Number Field in b with defining polynomial x^3 + x + 17 :: sage: y = QQ['x'].0 - sage: L. = NumberField(y^3-2) - sage: R. = L['x'] - sage: f = x^3 + x + 17 - sage: f.root_field('c') + sage: L. = NumberField(y^3 - 2) # optional - sage.rings.number_field + sage: R. = L['x'] # optional - sage.rings.number_field + sage: f = x^3 + x + 17 # optional - sage.rings.number_field + sage: f.root_field('c') # optional - sage.rings.number_field Number Field in c with defining polynomial x^3 + x + 17 over its base field :: - sage: R. = PolynomialRing(GF(9,'a')) - sage: f = x^3 + x^2 + 8 - sage: K. = f.root_field(); K - Univariate Quotient Polynomial Ring in alpha over Finite Field in a of size 3^2 with modulus x^3 + x^2 + 2 - sage: alpha^2 + 1 + sage: R. = PolynomialRing(GF(9, 'a')) # optional - sage.libs.pari + sage: f = x^3 + x^2 + 8 # optional - sage.libs.pari + sage: K. = f.root_field(); K # optional - sage.libs.pari + 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 alpha^2 + 1 - sage: alpha^3 + alpha^2 + sage: alpha^3 + alpha^2 # optional - sage.libs.pari 1 :: sage: R. = QQ[] sage: f = x^2 - sage: K. = f.root_field() + sage: K. = f.root_field() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: polynomial must be irreducible TESTS:: - sage: (PolynomialRing(Integers(31),name='x').0+5).root_field('a') + sage: (PolynomialRing(Integers(31), name='x').0 + 5).root_field('a') # optional - sage.libs.pari Ring of integers modulo 31 """ R = self.base_ring() @@ -5302,8 +5333,8 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) - sage: M = f.sylvester_matrix(g) - sage: M + sage: M = f.sylvester_matrix(g) # optional - sage.modules + sage: M # optional - sage.modules [ 42 317 134 1786 0 0 0] [ 0 42 317 134 1786 0 0] [ 0 0 42 317 134 1786 0] @@ -5315,7 +5346,7 @@ cdef class Polynomial(CommutativePolynomial): If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will be zero:: - sage: M.determinant() + sage: M.determinant() # optional - sage.modules 0 If self and right are polynomials of positive degree, the determinant @@ -5323,16 +5354,16 @@ cdef class Polynomial(CommutativePolynomial): sage: h1 = R._random_nonzero_element() sage: h2 = R._random_nonzero_element() - sage: M1 = h1.sylvester_matrix(h2) - sage: M1.determinant() == h1.resultant(h2) + sage: M1 = h1.sylvester_matrix(h2) # optional - sage.modules + sage: M1.determinant() == h1.resultant(h2) # optional - sage.libs.pari sage.modules True The rank of the Sylvester matrix is related to the degree of the gcd of self and right:: - sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() + sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() # optional - sage.modules True - sage: h1.gcd(h2).degree() == h1.degree() + h2.degree() - M1.rank() + sage: h1.gcd(h2).degree() == h1.degree() + h2.degree() - M1.rank() # optional - sage.modules True TESTS: @@ -5340,65 +5371,69 @@ cdef class Polynomial(CommutativePolynomial): The variable is optional, but must be the same in both rings:: sage: K. = QQ['x'] - sage: f = x+1 + sage: f = x + 1 sage: g = QQ['y']([1, 0, 1]) - sage: f.sylvester_matrix(f, x) + sage: f.sylvester_matrix(f, x) # optional - sage.modules [1 1] [1 1] - sage: f.sylvester_matrix(g, x) + sage: f.sylvester_matrix(g, x) # optional - sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Rational Field' + TypeError: no common canonical parent for objects with parents: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in y over Rational Field' Polynomials must be defined over compatible base rings:: sage: f = QQ['x']([1, 0, 1]) sage: g = ZZ['x']([1, 0, 1]) - sage: h = GF(25, 'a')['x']([1, 0, 1]) - sage: f.sylvester_matrix(g) + sage: h = GF(25, 'a')['x']([1, 0, 1]) # optional - sage.libs.pari + sage: f.sylvester_matrix(g) # optional - sage.modules [1 0 1 0] [0 1 0 1] [1 0 1 0] [0 1 0 1] - sage: g.sylvester_matrix(h) + sage: g.sylvester_matrix(h) # optional - sage.libs.pari sage.modules [1 0 1 0] [0 1 0 1] [1 0 1 0] [0 1 0 1] - sage: f.sylvester_matrix(h) + sage: f.sylvester_matrix(h) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in x over Finite Field in a of size 5^2' + TypeError: no common canonical parent for objects with parents: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in x over Finite Field in a of size 5^2' We can compute the sylvester matrix of a univariate and multivariate polynomial:: sage: K. = QQ['x,y'] sage: g = K.random_element() - sage: f.sylvester_matrix(g) == K(f).sylvester_matrix(g,x) + sage: f.sylvester_matrix(g) == K(f).sylvester_matrix(g, x) # optional - sage.modules True Corner cases:: - sage: K.=QQ[] - sage: f = x^2+1 + sage: K. = QQ[] + sage: f = x^2 + 1 sage: g = K(0) - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(f) + sage: g.sylvester_matrix(f) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(g) + sage: g.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: K(3).sylvester_matrix(x^2) + sage: K(3).sylvester_matrix(x^2) # optional - sage.modules [3 0] [0 3] - sage: K(3).sylvester_matrix(K(4)) + sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules [] """ @@ -5470,10 +5505,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = PolynomialRing(GF(9,'a'), sparse=True) - sage: a = w._new_constant_poly(0, R); a + sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.libs.pari + sage: a = w._new_constant_poly(0, R); a # optional - sage.libs.pari 0 - sage: a.coefficients() + sage: a.coefficients() # optional - sage.libs.pari [] """ t = type(self) @@ -5516,12 +5551,12 @@ cdef class Polynomial(CommutativePolynomial): sage: b = a(2*191*236607587) sage: b.is_nilpotent() True - sage: R. = a[] - sage: f = 3 + b*x + b^2*x^2 - sage: f.is_unit() + sage: R. = a[] # optional - sage.libs.pari + sage: f = 3 + b*x + b^2*x^2 # optional - sage.libs.pari + sage: f.is_unit() # optional - sage.libs.pari True - sage: f = 3 + b*x + b^2*x^2 + 17*x^3 - sage: f.is_unit() + sage: f = 3 + b*x + b^2*x^2 + 17*x^3 # optional - sage.libs.pari + sage: f.is_unit() # optional - sage.libs.pari False EXERCISE (Atiyah-McDonald, Ch 1): Let `A[x]` be a @@ -5798,18 +5833,18 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(QQbar) - sage: f = QQbar(i)*x^2 + 3*x - sage: f.global_height() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = QQbar(i)*x^2 + 3*x # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 1.09861228866811 :: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^2 + 5) - sage: T. = PolynomialRing(K) - sage: f = 1/1331 * t^2 + 5 * t + 7 - sage: f.global_height() + sage: K. = NumberField(x^2 + 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = 1/1331 * t^2 + 5 * t + 7 # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 9.13959596745043 :: @@ -5875,11 +5910,11 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = K[] - sage: I = K.ideal(3) - sage: f = 1/3*t^2 + 3 - sage: f.local_height(I) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = K[] # optional - sage.rings.number_field + sage: I = K.ideal(3) # optional - sage.rings.number_field + sage: f = 1/3*t^2 + 3 # optional - sage.rings.number_field + sage: f.local_height(I) # optional - sage.rings.number_field 1.09861228866811 :: @@ -5927,10 +5962,10 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = K[] - sage: f = 1/2*t^2 + 3 - sage: f.local_height_arch(1, prec=52) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = K[] # optional - sage.rings.number_field + sage: f = 1/2*t^2 + 3 # optional - sage.rings.number_field + sage: f.local_height_arch(1, prec=52) # optional - sage.rings.number_field 1.09861228866811 :: @@ -6147,11 +6182,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = - 1/2*x^2 + x^9 + 7*x + 5/11 sage: f.monomials() [x^9, x^2, x, 1] - sage: x = var('x') - sage: K. = NumberField(x**2 + 1) - sage: R. = QQ[] - sage: p = rho*y - sage: p.monomials() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x**2 + 1) # optional - sage.rings.number_field + sage: R. = QQ[] # optional - sage.rings.number_field + sage: p = rho * y # optional - sage.rings.number_field + sage: p.monomials() # optional - sage.rings.number_field [y] """ if self.is_zero(): @@ -6248,11 +6283,11 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = x^3 + 2 - sage: f.newton_slopes(2) + sage: f.newton_slopes(2) # optional - sage.libs.pari [1/3, 1/3, 1/3] sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = x^5 + 6*x^2 + 4 - sage: p.newton_slopes(2) + sage: p.newton_slopes(2) # optional - sage.libs.pari [1/2, 1/2, 1/3, 1/3, 1/3] sage: p.newton_slopes(2, lengths=True) [(1/2, 2), (1/3, 3)] @@ -6309,13 +6344,13 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: Pol. = QQ[] - sage: x.dispersion_set(x + 1) + sage: x.dispersion_set(x + 1) # optional - sage.libs.pari [1] - sage: (x + 1).dispersion_set(x) + sage: (x + 1).dispersion_set(x) # optional - sage.libs.pari [] sage: pol = x^3 + x - 7 - sage: (pol*pol(x+3)^2).dispersion_set() + sage: (pol*pol(x+3)^2).dispersion_set() # optional - sage.libs.pari [0, 3] """ other = self if other is None else self._parent.coerce(other) @@ -6356,16 +6391,16 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: Pol. = QQ[] - sage: x.dispersion(x + 1) + sage: x.dispersion(x + 1) # optional - sage.libs.pari 1 - sage: (x + 1).dispersion(x) + sage: (x + 1).dispersion(x) # optional - sage.libs.pari -Infinity - sage: Pol. = QQbar[] - sage: pol = Pol([sqrt(5), 1, 3/2]) - sage: pol.dispersion() + sage: Pol. = QQbar[] # optional - sage.libs.pari sage.rings.number_field + sage: pol = Pol([sqrt(5), 1, 3/2]) # optional - sage.libs.pari sage.rings.number_field sage.symbolic + sage: pol.dispersion() # optional - sage.libs.pari sage.rings.number_field sage.symbolic 0 - sage: (pol*pol(x+3)).dispersion() + sage: (pol*pol(x+3)).dispersion() # optional - sage.libs.pari sage.rings.number_field sage.symbolic 3 """ dispersions = self.dispersion_set(other) @@ -6386,7 +6421,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: f = QQ['x']([0,1,2/3,3]) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari 3*x^3 + 2/3*x^2 + x :: @@ -6394,19 +6429,20 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = QQ['a'] sage: R. = S['x'] sage: f = R([0, a]) + R([0, 0, 2/3]) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari 2/3*x^2 + a*x Polynomials over a number field work, provided that the variable is called 'x':: sage: x = polygen(QQ) - sage: K. = NumberField(x^2 + x + 1) - sage: R. = PolynomialRing(K) - sage: pol = (b + x)^3; pol + sage: K. = NumberField(x^2 + x + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: pol = (b + x)^3; pol # optional - sage.rings.number_field x^3 + 3*b*x^2 + (-3*b - 3)*x + 1 - sage: pari(pol) - Mod(1, y^2 + y + 1)*x^3 + Mod(3*y, y^2 + y + 1)*x^2 + Mod(-3*y - 3, y^2 + y + 1)*x + Mod(1, y^2 + y + 1) + sage: pari(pol) # optional - sage.libs.pari sage.rings.number_field + Mod(1, y^2 + y + 1)*x^3 + Mod(3*y, y^2 + y + 1)*x^2 + + Mod(-3*y - 3, y^2 + y + 1)*x + Mod(1, y^2 + y + 1) TESTS: @@ -6415,7 +6451,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = y^3 + a - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari Traceback (most recent call last): ... PariError: incorrect priority in gtopoly: variable x <= a @@ -6425,9 +6461,9 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = QQ['a'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 2*x^3) + sage: pari(a*x + 2*x^3) # optional - sage.libs.pari 2*x^3 + a*x Stacked polynomial rings, second with a multivariate ring on the @@ -6435,27 +6471,27 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = ZZ['a', 'b'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 2*b*x^3) + sage: pari(a*x + 2*b*x^3) # optional - sage.libs.pari 2*b*x^3 + a*x Stacked polynomial rings with exotic base rings:: - sage: S. = GF(7)['a', 'b'] - sage: R. = S['x'] - sage: pari(x^2 + 9*x) + sage: S. = GF(7)['a', 'b'] # optional - sage.libs.pari + sage: R. = S['x'] # optional - sage.libs.pari + sage: pari(x^2 + 9*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 9*b*x^3) + sage: pari(a*x + 9*b*x^3) # optional - sage.libs.pari 2*b*x^3 + a*x :: sage: S. = Integers(8)['a'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari Mod(1, 8)*x^2 + Mod(2, 8)*x - sage: pari(a*x + 10*x^3) + sage: pari(a*x + 10*x^3) # optional - sage.libs.pari Mod(2, 8)*x^3 + Mod(1, 8)*a*x """ return self._pari_with_name(self._parent.variable_name()) @@ -6476,18 +6512,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = 2*x^2 + 7*x - 5 - sage: pol._pari_or_constant() + sage: pol._pari_or_constant() # optional - sage.libs.pari 2*x^2 + 7*x - 5 - sage: pol._pari_or_constant('a') + sage: pol._pari_or_constant('a') # optional - sage.libs.pari 2*a^2 + 7*a - 5 sage: pol = R(7) - sage: pol._pari_or_constant() + sage: pol._pari_or_constant() # optional - sage.libs.pari 7 - sage: pol._pari_or_constant().type() + sage: pol._pari_or_constant().type() # optional - sage.libs.pari 't_INT' - sage: pol.__pari__().type() + sage: pol.__pari__().type() # optional - sage.libs.pari 't_POL' - sage: PolynomialRing(IntegerModRing(101), 't')()._pari_or_constant() + sage: PolynomialRing(IntegerModRing(101), 't')()._pari_or_constant() # optional - sage.libs.pari Mod(0, 101) """ if self.is_constant(): @@ -6506,9 +6542,9 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: (2*a^2 + a)._pari_with_name() + sage: (2*a^2 + a)._pari_with_name() # optional - sage.libs.pari 2*x^2 + x - sage: (2*a^2 + a)._pari_with_name('y') + sage: (2*a^2 + a)._pari_with_name('y') # optional - sage.libs.pari 2*y^2 + y """ vals = [x.__pari__() for x in self.list()] @@ -6523,7 +6559,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: magma = Magma() # new session + sage: magma = Magma() # new session # optional - magma sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 sage: f._magma_init_(magma) # optional - magma @@ -6549,8 +6585,8 @@ cdef class Polynomial(CommutativePolynomial): A more complicated nested example:: - sage: k. = GF(9); R. = k[]; S. = R[] - sage: magma(a*W^20 + s*t/a) # optional - magma + sage: k. = GF(9); R. = k[]; S. = R[] # optional - sage.libs.pari + sage: magma(a*W^20 + s*t/a) # optional - magma # optional - sage.libs.pari a*W^20 + a^7*s*t """ # Get a reference to Magma version of parent. @@ -6571,33 +6607,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g # indirect doctest + sage: g = gap(f); g # indirect doctest # optional - sage.libs.gap y^3-17*y+5 - sage: f._gap_init_() + sage: f._gap_init_() # optional - sage.libs.gap 'y^3 - 17*y + 5' sage: R. = ZZ[] - sage: gap(R) + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: g + sage: g # optional - sage.libs.gap y^3-17*y+5 - sage: gap(z^2 + z) + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z - sage: libgap(z^2 + z) + sage: libgap(z^2 + z) # optional - sage.libs.gap z^2+z Coefficients in a finite field:: - sage: R. = GF(7)[] - sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g + sage: R. = GF(7)[] # optional - sage.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 y^3+Z(7)^4*y+Z(7)^5 - sage: h = libgap(f); h + sage: h = libgap(f); h # optional - sage.libs.gap sage.libs.pari y^3+Z(7)^4*y+Z(7)^5 - sage: g.Factors() + sage: g.Factors() # optional - sage.libs.gap sage.libs.pari [ y+Z(7)^0, y+Z(7)^0, y+Z(7)^5 ] - sage: h.Factors() + sage: h.Factors() # optional - sage.libs.gap sage.libs.pari [ y+Z(7)^0, y+Z(7)^0, y+Z(7)^5 ] - sage: f.factor() + sage: f.factor() # optional - sage.libs.gap sage.libs.pari (y + 5) * (y + 1)^2 """ R = gap(self._parent) @@ -6609,9 +6645,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x^3 + 3*x) # indirect doctest + sage: libgap(-x^3 + 3*x) # indirect doctest # optional - sage.libs.gap -x^3+3*x - sage: libgap(R.zero()) # indirect doctest + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -6623,13 +6659,13 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] - sage: f = R('e*i') * x + x^2 - sage: f._giac_init_() + sage: R. = GF(101)['e,i'][] # optional - sage.libs.pari + sage: f = R('e*i') * x + x^2 # optional - sage.libs.pari + sage: f._giac_init_() # optional - sage.libs.pari '((1)*1)*sageVARx^2+((1)*sageVARe*sageVARi)*sageVARx' - sage: giac(f) + sage: giac(f) # optional - sage.libs.pari sageVARx^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) + sage: giac(R.zero()) # optional - sage.libs.pari 0 """ g = 'sageVAR' + self.variable_name() @@ -6660,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 + sage: r = f.resultant(g); r # optional - sage.libs.pari -8 - sage: r.parent() is QQ + sage: r.parent() is QQ # optional - sage.libs.pari True We can compute resultants over univariate and multivariate @@ -6671,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 + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + a^2 - sage: r.parent() is R + sage: r.parent() is R # optional - sage.libs.pari True :: @@ -6681,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 + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + b^2 - sage: r.parent() is R + sage: r.parent() is R # optional - sage.libs.pari True TESTS:: @@ -6691,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 + sage: h = f.resultant(g); h # optional - sage.libs.pari y^3 - x^2 - sage: h.parent() is R + sage: h.parent() is R # optional - sage.libs.pari True Check that :trac:`13672` is fixed:: - sage: R. = GF(2)[] - sage: S. = R[] - sage: f = (t^2 + t)*x + t^2 + t - sage: g = (t + 1)*x + t^2 - sage: f.resultant(g) + sage: R. = GF(2)[] # optional - sage.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 t^4 + t Check that :trac:`15061` is fixed:: @@ -6711,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()) + sage: P.resultant(P.derivative()) # optional - sage.libs.pari -4 - 4*T + O(T^2) Check that :trac:`16360` is fixed:: sage: K. = FunctionField(QQ) sage: R. = K[] - sage: y.resultant(y+x) + sage: y.resultant(y + x) # optional - sage.libs.pari x sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(b^2-a) - sage: R. = L[] - sage: f=x^2-a - sage: g=x-b - sage: f.resultant(g) + sage: L. = K.extension(b^2 - a) # optional - sage.libs.singular + sage: R. = L[] # optional - sage.libs.singular + sage: f = x^2 - a # optional - sage.libs.singular + sage: g = x - b # optional - sage.libs.singular + sage: f.resultant(g) # optional - sage.libs.pari sage.libs.singular 0 Check that :trac:`17817` is fixed:: @@ -6738,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) + 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 @@ -6747,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) + sage: f.resultant(g) # optional - sage.libs.pari 133.92599999999996 + 37.56999999999999*I """ variable = self.variable_name() @@ -6907,38 +6943,39 @@ cdef class Polynomial(CommutativePolynomial): This function works over any field. However for base rings other than `\ZZ` and `\QQ` only the resultant algorithm is available:: - sage: x = polygen(QQbar) - sage: p1 = x**2 - AA(2).sqrt() - sage: p2 = x**3 - AA(3).sqrt() - sage: r1 = p1.roots(multiplicities=False) - sage: r2 = p2.roots(multiplicities=False) - sage: p = p1.composed_op(p2, operator.add) - sage: p - x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 - 14.69693845669907?*x + 0.1715728752538099? - sage: all(p(x+y).is_zero() for x in r1 for y in r2) - True - - sage: x = polygen(GF(2)) - sage: p1 = x**2 + x - 1 - sage: p2 = x**3 + x - 1 - sage: p_add = p1.composed_op(p2, operator.add) - sage: p_add + sage: x = polygen(QQbar) # optional - sage.rings.number_field + sage: p1 = x**2 - AA(2).sqrt() # optional - sage.rings.number_field + sage: p2 = x**3 - AA(3).sqrt() # optional - sage.rings.number_field + sage: r1 = p1.roots(multiplicities=False) # optional - sage.rings.number_field + sage: r2 = p2.roots(multiplicities=False) # optional - sage.rings.number_field + sage: p = p1.composed_op(p2, operator.add) # optional - sage.rings.number_field + sage: p # optional - sage.rings.number_field + x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 + - 14.69693845669907?*x + 0.1715728752538099? + sage: all(p(x+y).is_zero() for x in r1 for y in r2) # optional - sage.rings.number_field + True + + sage: x = polygen(GF(2)) # optional - sage.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 x^6 + x^5 + x^3 + x^2 + 1 - sage: p_mul = p1.composed_op(p2, operator.mul) - sage: p_mul + sage: p_mul = p1.composed_op(p2, operator.mul) # optional - sage.libs.pari + sage: p_mul # optional - sage.libs.pari x^6 + x^4 + x^2 + x + 1 - sage: p_div = p1.composed_op(p2, operator.truediv) - sage: p_div + sage: p_div = p1.composed_op(p2, operator.truediv) # optional - sage.libs.pari + sage: p_div # optional - sage.libs.pari x^6 + x^5 + x^4 + x^2 + 1 - sage: K = GF(2**6, 'a') - sage: r1 = p1.roots(K, multiplicities=False) - sage: r2 = p2.roots(K, multiplicities=False) - sage: all(p_add(x1+x2).is_zero() for x1 in r1 for x2 in r2) + sage: K = GF(2**6, 'a') # optional - sage.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 True - sage: all(p_mul(x1*x2).is_zero() for x1 in r1 for x2 in r2) + sage: all(p_mul(x1*x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.libs.pari True - sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) + sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.libs.pari True TESTS: @@ -7101,14 +7138,14 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^2 - 2*x + 2 sage: f2 = f.compose_power(2); f2 x^4 - 4*x^3 + 8*x^2 - 16*x + 16 - sage: f2 == f.composed_op(f,operator.mul) + sage: f2 == f.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True - sage: f3 = f.compose_power(3); f3 + sage: f3 = f.compose_power(3); f3 # optional - sage.libs.singular sage.modules x^8 - 8*x^7 + 32*x^6 - 64*x^5 + 128*x^4 - 512*x^3 + 2048*x^2 - 4096*x + 4096 - sage: f3 == f2.composed_op(f,operator.mul) + sage: f3 == f2.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True - sage: f4 = f.compose_power(4) - sage: f4 == f3.composed_op(f,operator.mul) + sage: f4 = f.compose_power(4) # optional - sage.libs.singular sage.modules + sage: f4 == f3.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True """ try: @@ -7148,16 +7185,16 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: f = cyclotomic_polynomial(30) - sage: f.adams_operator(7)==f + sage: f = cyclotomic_polynomial(30) # optional - sage.libs.pari + sage: f.adams_operator(7)==f # optional - sage.libs.pari True - sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 + sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 # optional - sage.libs.pari True - sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4 + sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4 # optional - sage.libs.pari True - sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8 + sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8 # optional - sage.libs.pari True - sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8 + sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8 # optional - sage.libs.pari True sage: x = polygen(QQ) @@ -7304,18 +7341,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + x + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -31 - sage: d.parent() is QQ + sage: d.parent() is QQ # optional - sage.libs.pari True - sage: EllipticCurve([1, 1]).discriminant()/16 + sage: EllipticCurve([1, 1]).discriminant()/16 # optional - sage.libs.pari -31 :: sage: R. = QQ[] sage: f = 2*x^3 + x + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -116 We can compute discriminants over univariate and multivariate @@ -7324,9 +7361,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = a*x + x + a + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari 1 - sage: d.parent() is R + sage: d.parent() is R # optional - sage.libs.pari True :: @@ -7334,9 +7371,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a + b - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -4*a - 4*b - sage: d.parent() is R + sage: d.parent() is R # optional - sage.libs.pari True TESTS:: @@ -7344,24 +7381,24 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a - sage: f.discriminant() + sage: f.discriminant() # optional - sage.libs.pari 1 Check that :trac:`13672` is fixed:: - sage: R. = GF(5)[] - sage: S. = R[] - sage: f = x^10 + 2*x^6 + 2*x^5 + x + 2 - sage: (f-t).discriminant() + sage: R. = GF(5)[] # optional - sage.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 4*t^5 The following examples show that :trac:`11782` has been fixed:: - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: ZZ.quo(81)['x'](3*x^2 + 3*x + 3).discriminant() + sage: ZZ.quo(81)['x'](3*x^2 + 3*x + 3).discriminant() # optional - sage.libs.pari sage.symbolic 54 - sage: ZZ.quo(9)['x'](2*x^3 + x^2 + x).discriminant() + sage: ZZ.quo(9)['x'](2*x^3 + x^2 + x).discriminant() # optional - sage.libs.pari sage.symbolic 2 This was fixed by :trac:`15422`:: @@ -7374,11 +7411,11 @@ cdef class Polynomial(CommutativePolynomial): sage: PR. = QQ[] sage: PRmu. = PR[] - sage: E1 = diagonal_matrix(PR, [1, b^2, -b^2]) - sage: M = matrix(PR, [[1,-t1,x1-t1*y1],[t1,1,y1+t1*x1],[0,0,1]]) - sage: E1 = M.transpose()*E1*M - sage: E2 = E1.subs(t1=t2, x1=x2, y1=y2) - sage: det(mu*E1 + E2).discriminant().degrees() + sage: E1 = diagonal_matrix(PR, [1, b^2, -b^2]) # optional - sage.modules + sage: M = matrix(PR, [[1,-t1,x1-t1*y1], [t1,1,y1+t1*x1], [0,0,1]]) # optional - sage.modules + sage: E1 = M.transpose()*E1*M # optional - sage.modules + sage: E2 = E1.subs(t1=t2, x1=x2, y1=y2) # optional - sage.modules + sage: det(mu*E1 + E2).discriminant().degrees() # optional - sage.modules sage.libs.pari (24, 12, 12, 8, 8, 8, 8) This addresses an issue raised by :trac:`15061`:: @@ -7387,7 +7424,7 @@ cdef class Polynomial(CommutativePolynomial): sage: F = R([1,1],2) sage: RP. = PolynomialRing(R) sage: P = x^2 - F - sage: P.discriminant() + sage: P.discriminant() # optional - sage.libs.pari 4 + 4*T + O(T^2) """ # Late import to avoid cyclic dependencies: @@ -7532,12 +7569,14 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = x^3 - 1 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(1, 1)] - sage: f.roots(ring=CC) # note -- low order bits slightly different on ppc. - [(1.00000000000000, 1), (-0.500000000000000 - 0.86602540378443...*I, 1), (-0.500000000000000 + 0.86602540378443...*I, 1)] + sage: f.roots(ring=CC) # ... - low order bits slightly different on ppc # optional - sage.libs.pari + [(1.00000000000000, 1), + (-0.500000000000000 - 0.86602540378443...*I, 1), + (-0.500000000000000 + 0.86602540378443...*I, 1)] sage: f = (x^3 - 1)^2 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(1, 2)] :: @@ -7550,14 +7589,14 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: K. = CyclotomicField(3) - sage: f = K.defining_polynomial() - sage: f.roots(ring=GF(7)) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: f = K.defining_polynomial() # optional - sage.rings.number_field + sage: f.roots(ring=GF(7)) # optional - sage.libs.pari # optional - sage.rings.number_field [(4, 1), (2, 1)] - sage: g = f.change_ring(GF(7)) - sage: g.roots() + sage: g = f.change_ring(GF(7)) # optional - sage.libs.pari # optional - sage.rings.number_field + sage: g.roots() # optional - sage.libs.pari # optional - sage.rings.number_field [(4, 1), (2, 1)] - sage: g.roots(multiplicities=False) + sage: g.roots(multiplicities=False) # optional - sage.libs.pari # optional - sage.rings.number_field [4, 2] A new ring. In the example below, we add the special method @@ -7568,7 +7607,7 @@ cdef class Polynomial(CommutativePolynomial): introduce:: sage: R. = QQ[] - sage: (x^2 + 1).roots() + sage: (x^2 + 1).roots() # optional - sage.libs.pari [] sage: g = lambda f, *args, **kwds: f.change_ring(CDF).roots() sage: QQ._roots_univariate_polynomial = g @@ -7756,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) + 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) @@ -7774,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 + sage: rts = p.roots(ring=QQbar); rts # optional - sage.rings.number_field [(1.167303978261419?, 1), (-0.7648844336005847? - 0.3524715460317263?*I, 1), (-0.7648844336005847? + 0.3524715460317263?*I, 1), (0.1812324444698754? - 1.083954101317711?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(1.167303978261419?, 1)] sage: p = (x - rts[4][0])^2 * (3*x^2 + x + 1) - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)] sage: p.roots(ring=CIF) [(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)] @@ -7805,13 +7844,13 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: K. = QuadraticField(-1) - sage: y = polygen(K) - sage: p = y^4 - 2 - im - sage: p.roots(ring=CC) + 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) - sage: p.roots(ring=CIF) + 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 @@ -7827,9 +7866,9 @@ cdef class Polynomial(CommutativePolynomial): We can also find roots over number fields:: - sage: K. = CyclotomicField(15) - sage: R. = PolynomialRing(K) - sage: (x^2 + x + 1).roots() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: (x^2 + x + 1).roots() # optional - sage.rings.number_field [(z^5, 1), (-z^5 - 1, 1)] There are many combinations of floating-point input and output @@ -7865,17 +7904,18 @@ cdef class Polynomial(CommutativePolynomial): Note that we can find the roots of a polynomial with algebraic coefficients:: - sage: rt2 = sqrt(AA(2)) - sage: rt3 = sqrt(AA(3)) - sage: x = polygen(AA) - sage: f = (x - rt2) * (x - rt3); f + sage: rt2 = sqrt(AA(2)) # optional - sage.rings.number_field + sage: rt3 = sqrt(AA(3)) # optional - sage.rings.number_field + sage: x = polygen(AA) # optional - sage.rings.number_field + sage: f = (x - rt2) * (x - rt3); f # optional - sage.rings.number_field x^2 - 3.146264369941973?*x + 2.449489742783178? - sage: rts = f.roots(); rts + sage: rts = f.roots(); rts # optional - sage.rings.number_field [(1.414213562373095?, 1), (1.732050807568878?, 1)] - sage: rts[0][0] == rt2 + sage: rts[0][0] == rt2 # optional - sage.rings.number_field True - sage: f.roots(ring=RealIntervalField(150)) - [(1.414213562373095048801688724209698078569671875376948073176679738?, 1), (1.732050807568877293527446341505872366942805253810380628055806980?, 1)] + sage: f.roots(ring=RealIntervalField(150)) # optional - sage.rings.number_field + [(1.414213562373095048801688724209698078569671875376948073176679738?, 1), + (1.732050807568877293527446341505872366942805253810380628055806980?, 1)] We can handle polynomials with huge coefficients. @@ -7899,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) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] sage: p = bigc*x + 1 sage: p.roots(ring=RR) [(-2.85106096489671e-452, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] sage: p = x^2 - bigc sage: p.roots(ring=RR) [(-5.92238652153286e225, 1), (5.92238652153286e225, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-5.9223865215328558?e225, 1), (5.9223865215328558?e225, 1)] Check that :trac:`30522` is fixed:: @@ -8015,9 +8055,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: K. = CyclotomicField(2) - sage: R. = K[] - sage: factor(x^3-1) + sage: K. = CyclotomicField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: factor(x^3 - 1) # optional - sage.rings.number_field (x - 1) * (x^2 + x + 1) This shows that the issue from :trac:`6237` is fixed:: @@ -8397,11 +8437,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = 20*x^3 - 50*x^2 + 20*x - sage: F = pol.factor(); F + sage: F = pol.factor(); F # optional - sage.libs.pari 2 * 5 * (x - 2) * x * (2*x - 1) - sage: pol._roots_from_factorization(F, multiplicities=True) + sage: pol._roots_from_factorization(F, multiplicities=True) # optional - sage.libs.pari [(2, 1), (0, 1)] - sage: pol.change_ring(QQ)._roots_from_factorization(F, multiplicities=False) + sage: pol.change_ring(QQ)._roots_from_factorization(F, multiplicities=False) # optional - sage.libs.pari [2, 0, 1/2] """ seq = [] @@ -8464,9 +8504,9 @@ cdef class Polynomial(CommutativePolynomial): """ Return the real roots of this polynomial, without multiplicities. - Calls self.roots(ring=RR), unless this is a polynomial with + Calls ``self.roots(ring=RR)``, unless this is a polynomial with floating-point real coefficients, in which case it calls - self.roots(). + ``self.roots()``. EXAMPLES:: @@ -8557,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) + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1.01, 2) + sage: pol.number_of_roots_in_interval(1.01, 2) # optional - sage.libs.pari 1 - sage: pol.number_of_roots_in_interval(None, 2) + sage: pol.number_of_roots_in_interval(None, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1, Infinity) + sage: pol.number_of_roots_in_interval(1, Infinity) # optional - sage.libs.pari 3 - sage: pol.number_of_roots_in_interval() + sage: pol.number_of_roots_in_interval() # optional - sage.libs.pari 3 - sage: pol = (x-1)*(x-2)*(x-3) + sage: pol = (x-1) * (x-2) * (x-3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_roots_in_interval() + sage: pol2.number_of_roots_in_interval() # optional - sage.libs.pari 3 sage: R. = PolynomialRing(CC) - sage: pol = (x-1)*(x-CC(I)) - sage: pol.number_of_roots_in_interval(0,2) + sage: pol = (x-1) * (x-CC(I)) + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 1 TESTS:: sage: R. = PolynomialRing(ZZ) sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_roots_in_interval(1, 2) + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 sage: pol = chebyshev_T(5,x) - sage: pol.number_of_roots_in_interval(-1,2) + sage: pol.number_of_roots_in_interval(-1, 2) # optional - sage.libs.pari 5 - sage: pol.number_of_roots_in_interval(0,2) + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 3 """ @@ -8615,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() + sage: pol.number_of_real_roots() # optional - sage.libs.pari 3 - sage: pol = (x-1)*(x-2)*(x-3) + sage: pol = (x-1) * (x-2) * (x-3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_real_roots() + sage: pol2.number_of_real_roots() # optional - sage.libs.pari 3 sage: R. = PolynomialRing(CC) - sage: pol = (x-1)*(x-CC(I)) - sage: pol.number_of_real_roots() + sage: pol = (x-1) * (x-CC(I)) + sage: pol.number_of_real_roots() # optional - sage.libs.pari 1 """ return self.number_of_roots_in_interval() @@ -8637,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) + sage: pol.all_roots_in_interval(1, 3) # optional - sage.libs.pari True - sage: pol.all_roots_in_interval(1.01, 3) + sage: pol.all_roots_in_interval(1.01, 3) # optional - sage.libs.pari False - sage: pol = chebyshev_T(5,x) - sage: pol.all_roots_in_interval(-1,1) + sage: pol = chebyshev_T(5, x) + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari True - sage: pol = chebyshev_T(5,x/2) - sage: pol.all_roots_in_interval(-1,1) + sage: pol = chebyshev_T(5, x/2) + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari False - sage: pol.all_roots_in_interval() + sage: pol.all_roots_in_interval() # optional - sage.libs.pari True """ pol = self // self.gcd(self.derivative()) @@ -8661,10 +8701,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = chebyshev_T(5, x) - sage: pol.is_real_rooted() + sage: pol.is_real_rooted() # optional - sage.libs.pari True sage: pol = x^2 + 1 - sage: pol.is_real_rooted() + sage: pol.is_real_rooted() # optional - sage.libs.pari False """ return self.all_roots_in_interval() @@ -8745,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) - sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4 - sage: u.trace_polynomial() + sage: K. = NumberField(x^2 - 2, embedding=1.4) # optional - sage.rings.number_field + sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4 # optional - sage.rings.number_field + sage: u.trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 1, 1, 2) - sage: (u*(x^2-2)).trace_polynomial() + sage: (u*(x^2-2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 1, x^2 - 2, 2) - sage: (u*(x^2-2)^2).trace_polynomial() + sage: (u*(x^2-2)^2).trace_polynomial() # optional - sage.rings.number_field (x^4 + a*x^3 - 9*x^2 - 8*a*x + 8, 1, 2) - sage: (u*(x^2-2)^3).trace_polynomial() + sage: (u*(x^2-2)^3).trace_polynomial() # optional - sage.rings.number_field (x^4 + a*x^3 - 9*x^2 - 8*a*x + 8, x^2 - 2, 2) - sage: u = x^4 + a*x^3 + 3*x^2 + 4*a*x + 16 - sage: u.trace_polynomial() + sage: u = x^4 + a*x^3 + 3*x^2 + 4*a*x + 16 # optional - sage.rings.number_field + sage: u.trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, 1, 4) - sage: (u*(x-2)).trace_polynomial() + sage: (u*(x-2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x - 2, 4) - sage: (u*(x+2)).trace_polynomial() + sage: (u*(x+2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x + 2, 4) TESTS: @@ -8825,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) + sage: P0.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (True, 5) - sage: P0.is_weil_polynomial(return_q=False) + sage: P0.is_weil_polynomial(return_q=False) # optional - sage.libs.pari True - sage: P1.is_weil_polynomial(return_q=True) + sage: P1.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (False, 0) - sage: P1.is_weil_polynomial(return_q=False) + sage: P1.is_weil_polynomial(return_q=False) # optional - sage.libs.pari False - sage: P2.is_weil_polynomial() + sage: P2.is_weil_polynomial() # optional - sage.libs.pari False .. SEEALSO:: @@ -8848,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() + sage: u.is_weil_polynomial() # optional - sage.libs.pari True AUTHORS: @@ -8969,12 +9009,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (2*x^2).gcd(2*x) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (2*x^2).gcd(2*x) # optional - sage.rings.number_field x - sage: R.zero().gcd(0) + sage: R.zero().gcd(0) # optional - sage.rings.number_field 0 - sage: (2*x).gcd(0) + sage: (2*x).gcd(0) # optional - sage.rings.number_field x One can easily add xgcd functionality to new rings by providing a @@ -9114,37 +9154,37 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PowerSeriesRing(QQ, 'z').gen() sage: P = PolynomialRing(QQ,'x') sage: x = P.gen() - sage: p = P(exp(z).list()) + sage: p = P(z.exp().list()) sage: m = x^5 sage: n, d = p.rational_reconstruction(m, 4, 0) - sage: print((n ,d)) + sage: print((n, d)) (1/24*x^4 + 1/6*x^3 + 1/2*x^2 + x + 1, 1) sage: print(((p*d - n) % m ).is_zero()) True sage: m = x^3 sage: n, d = p.rational_reconstruction(m, 1, 1) - sage: print((n ,d)) + sage: print((n, d)) (-x - 2, x - 2) sage: print(((p*d - n) % m ).is_zero()) True sage: p = P(log(1-z).list()) sage: m = x^9 sage: n, d = p.rational_reconstruction(m, 4, 4) - sage: print((n ,d)) + sage: print((n, d)) (25/6*x^4 - 130/3*x^3 + 105*x^2 - 70*x, x^4 - 20*x^3 + 90*x^2 - 140*x + 70) sage: print(((p*d - n) % m ).is_zero()) True sage: p = P(sqrt(1+z).list()) sage: m = x^6 sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print((n ,d)) + sage: print((n, d)) (1/6*x^3 + 3*x^2 + 8*x + 16/3, x^2 + 16/3*x + 16/3) sage: print(((p*d - n) % m ).is_zero()) True - sage: p = P(exp(2*z).list()) + sage: p = P((2*z).exp().list()) sage: m = x^7 sage: n, d = p.rational_reconstruction(m, 3, 3) - sage: print((n ,d)) + sage: print((n, d)) (-x^3 - 6*x^2 - 15*x - 15, x^3 - 6*x^2 + 15*x - 15) sage: print(((p*d - n) % m ).is_zero()) True @@ -9152,12 +9192,12 @@ cdef class Polynomial(CommutativePolynomial): Over `\RR[z]`:: sage: z = PowerSeriesRing(RR, 'z').gen() - sage: P = PolynomialRing(RR,'x') + sage: P = PolynomialRing(RR, 'x') sage: x = P.gen() - sage: p = P(exp(2*z).list()) + sage: p = P((2*z).exp().list()) sage: m = x^7 sage: n, d = p.rational_reconstruction(m, 3, 3) - sage: print((n ,d)) # absolute tolerance 1e-10 + sage: print((n, d)) # absolute tolerance 1e-10 (-x^3 - 6.0*x^2 - 15.0*x - 15.0, x^3 - 6.0*x^2 + 15.0*x - 15.0) .. SEEALSO:: @@ -9360,11 +9400,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = ZZ[] - sage: (x^3 + 1).is_irreducible() + sage: (x^3 + 1).is_irreducible() # optional - sage.libs.pari False - sage: (x^2 - 1).is_irreducible() + sage: (x^2 - 1).is_irreducible() # optional - sage.libs.pari False - sage: (x^3 + 2).is_irreducible() + sage: (x^3 + 2).is_irreducible() # optional - sage.libs.pari True sage: R(0).is_irreducible() False @@ -9376,28 +9416,28 @@ cdef class Polynomial(CommutativePolynomial): sage: R(2*x).is_irreducible() # optional - sage.libs.pari False sage: R. = QQ[] - sage: R(2*x).is_irreducible() + sage: R(2*x).is_irreducible() # optional - sage.libs.pari True TESTS:: - sage: F. = NumberField(x^2-5) - sage: Fx. = PolynomialRing(F) - sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) - sage: f.is_irreducible() + sage: F. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: Fx. = PolynomialRing(F) # optional - sage.rings.number_field + sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) # optional - sage.rings.number_field + sage: f.is_irreducible() # optional - sage.rings.number_field False - sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) - sage: f.is_irreducible() + sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) # optional - sage.rings.number_field + sage: f.is_irreducible() # optional - sage.rings.number_field True If the base ring implements `_is_irreducible_univariate_polynomial`, then this method gets used instead of the generic algorithm which just factors the input:: - sage: R. = QQbar[] - sage: hasattr(QQbar, "_is_irreducible_univariate_polynomial") + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: hasattr(QQbar, "_is_irreducible_univariate_polynomial") # optional - sage.rings.number_field True - sage: (x^2 + 1).is_irreducible() + sage: (x^2 + 1).is_irreducible() # optional - sage.rings.number_field False Constants can be irreducible if they are not units:: @@ -9405,9 +9445,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: R(1).is_irreducible() False - sage: R(4).is_irreducible() + sage: R(4).is_irreducible() # optional - sage.libs.pari False - sage: R(5).is_irreducible() + sage: R(5).is_irreducible() # optional - sage.libs.pari True Check that caching works:: @@ -9582,36 +9622,36 @@ cdef class Polynomial(CommutativePolynomial): decomposition or a full factorization, depending on which is available:: - sage: K. = FunctionField(GF(3)) - sage: R. = K[] - sage: (x^3-x).is_squarefree() + sage: K. = FunctionField(GF(3)) # optional - sage.libs.pari + sage: R. = K[] # optional - sage.libs.pari + sage: (x^3-x).is_squarefree() # optional - sage.libs.pari True - sage: (x^3-1).is_squarefree() + sage: (x^3-1).is_squarefree() # optional - sage.libs.pari False - sage: (x^3+t).is_squarefree() + sage: (x^3+t).is_squarefree() # optional - sage.libs.pari True - sage: (x^3+t^3).is_squarefree() + sage: (x^3+t^3).is_squarefree() # optional - sage.libs.pari False In the following example, `t^2` is a unit in the base field:: - sage: R(t^2).is_squarefree() + sage: R(t^2).is_squarefree() # optional - sage.libs.pari True This method is not consistent with :meth:`.squarefree_decomposition`:: sage: R. = ZZ[] sage: f = 4 * x - sage: f.is_squarefree() + sage: f.is_squarefree() # optional - sage.libs.pari False - sage: f.squarefree_decomposition() + sage: f.squarefree_decomposition() # optional - sage.libs.pari (4) * x If you want this method equally not to consider the content, you can remove it as in the following example:: sage: c = f.content() - sage: (f/c).is_squarefree() + sage: (f/c).is_squarefree() # optional - sage.libs.pari True If the base ring is not an integral domain, the question is not @@ -9640,15 +9680,15 @@ cdef class Polynomial(CommutativePolynomial): then this method gets used instead of the generic algorithm in :meth:`_is_squarefree_generic`:: - sage: R. = QQbar[] - sage: (x^2).is_squarefree() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^2).is_squarefree() # optional - sage.rings.number_field False - sage: hasattr(QQbar, '_is_squarefree_univariate_polynomial') + sage: hasattr(QQbar, '_is_squarefree_univariate_polynomial') # optional - sage.rings.number_field False - sage: QQbar._is_squarefree_univariate_polynomial = lambda self: True - sage: (x^2).is_squarefree() + sage: QQbar._is_squarefree_univariate_polynomial = lambda self: True # optional - sage.rings.number_field + sage: (x^2).is_squarefree() # optional - sage.rings.number_field True - sage: del(QQbar._is_squarefree_univariate_polynomial) + sage: del(QQbar._is_squarefree_univariate_polynomial) # optional - sage.rings.number_field """ B = self._parent.base_ring() @@ -9668,10 +9708,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x^2*(x + 1)).is_squarefree() # indirect doctest + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^2*(x + 1)).is_squarefree() # indirect doctest # optional - sage.rings.number_field False - sage: (x*(x+1)).is_squarefree() # indirect doctest + sage: (x*(x+1)).is_squarefree() # indirect doctest # optional - sage.rings.number_field True """ @@ -9722,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)[] - sage: (x^3 + x^2).radical() + sage: P. = GF(2)[] # optional - sage.libs.pari + sage: (x^3 + x^2).radical() # optional - sage.libs.pari x^2 + x """ P = self._parent @@ -9852,10 +9892,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f = (x+1)^100 sage: f.number_of_terms() 101 - sage: S = GF(5)['y'] - sage: S(f).number_of_terms() + sage: S = GF(5)['y'] # optional - sage.libs.pari + sage: S(f).number_of_terms() # optional - sage.libs.pari 5 - sage: cyclotomic_polynomial(105).number_of_terms() + sage: cyclotomic_polynomial(105).number_of_terms() # optional - sage.libs.pari 33 The method :meth:`hamming_weight` is an alias:: @@ -9891,17 +9931,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = SR[] - sage: f = (1+I)*x^2 + 3*x - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = SR[] # optional - sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic (-I + 1)*x^2 + 3*x + I sage: R. = ZZ[] sage: f = x^2 + 2 sage: f.map_coefficients(lambda a: a + 42) 43*x^2 + 44 - sage: R. = PolynomialRing(SR, sparse=True) - sage: f = (1+I)*x^(2^32) - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = PolynomialRing(SR, sparse=True) # optional - sage.symbolic + sage: f = (1+I)*x^(2^32) - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic (-I + 1)*x^4294967296 + I sage: R. = PolynomialRing(ZZ, sparse=True) sage: f = x^(2^32) + 2 @@ -9911,21 +9951,21 @@ cdef class Polynomial(CommutativePolynomial): Examples with different base ring:: sage: R. = ZZ[] - sage: k = GF(2) - sage: residue = lambda x: k(x) - sage: f = 4*x^2+x+3 - sage: g = f.map_coefficients(residue); g + sage: k = GF(2) # optional - sage.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 x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring - sage: g = f.map_coefficients(residue, new_base_ring = k); g + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.libs.pari x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: residue = k.coerce_map_from(ZZ) - sage: g = f.map_coefficients(residue); g + sage: residue = k.coerce_map_from(ZZ) # optional - sage.libs.pari + sage: g = f.map_coefficients(residue); g # optional - sage.libs.pari x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) """ R = self._parent @@ -9998,7 +10038,7 @@ cdef class Polynomial(CommutativePolynomial): sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") # optional - sage.libs.pari True - sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") + sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") # optional - sage.libs.pari True sage: y = polygen(QQ) @@ -10253,12 +10293,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: pol. = PolynomialRing(Rationals()) - sage: u = x^5-1; u.has_cyclotomic_factor() + sage: u = x^5 - 1; u.has_cyclotomic_factor() True - sage: u = x^5-2; u.has_cyclotomic_factor() + sage: u = x^5 - 2; u.has_cyclotomic_factor() False - sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() #random - sage: u.has_cyclotomic_factor() # random + sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() # random # optional - sage.libs.pari + sage: u.has_cyclotomic_factor() # random # optional - sage.libs.pari True """ if not QQ.has_coerce_map_from(self.base_ring()): @@ -10481,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) - sage: x = R2.gen() - sage: R3. = R2[] - sage: (y**2 - 2*y + 1).nth_root(2) + sage: R2 = R.quotient(x**2 + 1) # optional - sage.libs.pari + sage: x = R2.gen() # optional - sage.libs.pari + sage: R3. = R2[] # optional - sage.libs.pari + sage: (y**2 - 2*y + 1).nth_root(2) # optional - sage.libs.pari -y + 1 - sage: (y**3).nth_root(3) + sage: (y**3).nth_root(3) # optional - sage.libs.pari y - sage: (y**2 + x).nth_root(2) + sage: (y**2 + x).nth_root(2) # optional - sage.libs.pari Traceback (most recent call last): ... AttributeError: ... has no attribute 'nth_root' @@ -10608,10 +10648,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R.one()._nth_root_series(3, 5) 1 - sage: R. = QQbar[] - sage: p = 2 + 3*x^2 - sage: q = p._nth_root_series(3, 20) - sage: (q**3).truncate(20) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = 2 + 3*x^2 # optional - sage.rings.number_field + sage: q = p._nth_root_series(3, 20) # optional - sage.rings.number_field + sage: (q**3).truncate(20) # optional - sage.rings.number_field 3*x^2 + 2 The exponent must be invertible in the base ring:: @@ -10751,8 +10791,8 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = PolynomialRing(ZZ, implementation="NTL") - sage: (2*x + 1).divides(4*x**2 + 1) + sage: R. = PolynomialRing(ZZ, implementation="NTL") # optional - sage.libs.ntl + sage: (2*x + 1).divides(4*x**2 + 1) # optional - sage.libs.ntl False sage: K. = GF(4) # optional - sage.libs.pari sage: R. = K[] # optional - sage.libs.pari @@ -11364,14 +11404,14 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = SR[] - sage: R(0).is_term() + sage: R. = SR[] # optional - sage.symbolic + sage: R(0).is_term() # optional - sage.symbolic False - sage: R(1).is_term() + sage: R(1).is_term() # optional - sage.symbolic True - sage: (3*x^5).is_term() + sage: (3*x^5).is_term() # optional - sage.symbolic True - sage: (1+3*x^5).is_term() + sage: (1+3*x^5).is_term() # optional - sage.symbolic False """ if not self.__coeffs: @@ -11876,13 +11916,13 @@ def universal_discriminant(n): EXAMPLES:: sage: from sage.rings.polynomial.polynomial_element import universal_discriminant - sage: universal_discriminant(1) + sage: universal_discriminant(1) # optional - sage.libs.pari 1 - sage: universal_discriminant(2) + sage: universal_discriminant(2) # optional - sage.libs.pari a1^2 - 4*a0*a2 - sage: universal_discriminant(3) + sage: universal_discriminant(3) # optional - sage.libs.pari a1^2*a2^2 - 4*a0*a2^3 - 4*a1^3*a3 + 18*a0*a1*a2*a3 - 27*a0^2*a3^2 - sage: universal_discriminant(4).degrees() + sage: universal_discriminant(4).degrees() # optional - sage.libs.pari (3, 4, 4, 4, 3) .. SEEALSO:: diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index e7b2d5e9768..d629f47c9ff 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -65,13 +65,14 @@ class Polynomial_generic_sparse(Polynomial): A more extensive example:: - sage: A. = PolynomialRing(Integers(5),sparse=True) ; f = T^2+1 ; B = A.quo(f) - sage: C. = PolynomialRing(B) - sage: C - Univariate Polynomial Ring in s over Univariate Quotient Polynomial Ring in Tbar over Ring of integers modulo 5 with modulus T^2 + 1 - sage: s + T + sage: A. = PolynomialRing(Integers(5), sparse=True); 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 + Univariate Polynomial Ring in s over Univariate Quotient Polynomial Ring in Tbar + over Ring of integers modulo 5 with modulus T^2 + 1 + sage: s + T # optional - sage.libs.pari s + Tbar - sage: (s + T)**2 + sage: (s + T)**2 # optional - sage.libs.pari s^2 + 2*Tbar*s + 4 """ @@ -243,10 +244,10 @@ def _derivative(self, var=None): Check that :trac:`28187` is fixed:: sage: R = PolynomialRing(ZZ, 't', sparse=True) - sage: t, u = var('t, u') - sage: R.gen()._derivative(t) + sage: t, u = var('t, u') # optional - sage.symbolic + sage: R.gen()._derivative(t) # optional - sage.symbolic 1 - sage: R.gen()._derivative(u) + sage: R.gen()._derivative(u) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to u @@ -418,14 +419,14 @@ def __getitem__(self, n): EXAMPLES:: sage: R. = PolynomialRing(RDF, sparse=True) - sage: e = RDF(e) - sage: f = sum(e^n*w^n for n in range(4)); f # abs tol 1.1e-14 + sage: e = RDF(e) # optional - sage.symbolic + sage: f = sum(e^n*w^n for n in range(4)); f # abs tol 1.1e-14 # optional - sage.symbolic 20.085536923187664*w^3 + 7.3890560989306495*w^2 + 2.718281828459045*w + 1.0 - sage: f[1] # abs tol 5e-16 + sage: f[1] # abs tol 5e-16 # optional - sage.symbolic 2.718281828459045 - sage: f[5] + sage: f[5] # optional - sage.symbolic 0.0 - sage: f[-1] + sage: f[-1] # optional - sage.symbolic 0.0 sage: R. = PolynomialRing(RealField(19), sparse=True) sage: f = (2-3.5*x)^3; f @@ -825,12 +826,12 @@ def quo_rem(self, other): Polynomials over noncommutative rings are also allowed:: - sage: HH = QuaternionAlgebra(QQ, -1, -1) - sage: P. = PolynomialRing(HH, sparse=True) - sage: f = P.random_element(5) - sage: g = P.random_element((0, 5)) - sage: q, r = f.quo_rem(g) - sage: f == q*g + r + sage: HH = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: P. = PolynomialRing(HH, sparse=True) # optional - sage.combinat sage.modules + sage: f = P.random_element(5) # optional - sage.combinat sage.modules + sage: g = P.random_element((0, 5)) # optional - sage.combinat sage.modules + sage: q, r = f.quo_rem(g) # optional - sage.combinat sage.modules + sage: f == q*g + r # optional - sage.combinat sage.modules True TESTS:: diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index 01135411305..b39aeeb8b4a 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -205,7 +205,7 @@ def create_key(self, ring, polynomial, names=None): In most applications this will not be a concern since the calling code takes care of normalizing the generators:: - sage: R.quo(x + 1) is R.quo(2*x + 2) + sage: R.quo(x + 1) is R.quo(2*x + 2) # optional - sage.libs.pari True """ @@ -468,53 +468,53 @@ def _element_constructor_(self, x): This was fixed in :trac:`8800`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q = P.quo([(x^2+1)^2]) - sage: Q1.has_coerce_map_from(Q) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q = P.quo([(x^2+1)^2]) # optional - sage.libs.pari + sage: Q1.has_coerce_map_from(Q) # optional - sage.libs.pari False - sage: Q1(Q.gen()) + sage: Q1(Q.gen()) # optional - sage.libs.pari xbar Here we test against several issues discussed in :trac:`8992`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) - sage: p = Q1.gen() + Q2.gen() - sage: p + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) # optional - sage.libs.pari + sage: p = Q1.gen() + Q2.gen() # optional - sage.libs.pari + sage: p # optional - sage.libs.pari 2*xbar - sage: p.parent() + 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') + sage: p.parent()('xbar') # optional - sage.libs.pari xbar Note that the result of string conversion has the correct parent, even when the given string suggests an element of the cover ring or the base ring:: - sage: a = Q1('x'); a + sage: a = Q1('x'); a # optional - sage.libs.pari xbar - sage: a.parent() is Q1 + sage: a.parent() is Q1 # optional - sage.libs.pari True - sage: b = Q1('1'); b + sage: b = Q1('1'); b # optional - sage.libs.pari 1 - sage: b.parent() is Q1 + sage: b.parent() is Q1 # optional - sage.libs.pari True Conversion may lift an element of one quotient ring to the base ring of another quotient ring:: - sage: R. = P[] - sage: Q3 = R.quo([(y^2+1)]) - sage: Q3(Q1.gen()) + sage: R. = P[] # optional - sage.libs.pari + sage: Q3 = R.quo([(y^2+1)]) # optional - sage.libs.pari + sage: Q3(Q1.gen()) # optional - sage.libs.pari x - sage: Q3.has_coerce_map_from(Q1) + sage: Q3.has_coerce_map_from(Q1) # optional - sage.libs.pari False String conversion takes into account both the generators of the quotient ring and its base ring:: - sage: Q3('x*ybar^2') + sage: Q3('x*ybar^2') # optional - sage.libs.pari -x """ @@ -571,10 +571,10 @@ def _coerce_map_from_(self, R): The following tests against a bug fixed in :trac:`8992`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari sage: R. = P[] - sage: Q2 = R.quo([(y^2+1)]) - sage: Q2.has_coerce_map_from(Q1) + sage: Q2 = R.quo([(y^2+1)]) # optional - sage.libs.pari + sage: Q2.has_coerce_map_from(Q1) # optional - sage.libs.pari False """ @@ -653,12 +653,12 @@ def lift(self, x): EXAMPLES:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.lift(Q.0^3) + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.lift(Q.0^3) # optional - sage.libs.pari -2*x - sage: Q(-2*x) + sage: Q(-2*x) # optional - sage.libs.pari -2*xbar - sage: Q.0^3 + sage: Q.0^3 # optional - sage.libs.pari -2*xbar """ @@ -674,14 +674,14 @@ def __eq__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx == Ry False - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: Qx == Qy + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: Qx == Qy # optional - sage.libs.pari False - sage: Qx == Qx + sage: Qx == Qx # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2+1) - sage: Qz == Qx + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz == Qx # optional - sage.libs.pari True """ if not isinstance(other, PolynomialQuotientRing_generic): @@ -699,14 +699,14 @@ def __ne__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx != Ry True - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: Qx != Qy + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: Qx != Qy # optional - sage.libs.pari True - sage: Qx != Qx + sage: Qx != Qx # optional - sage.libs.pari False - sage: Qz = Rx.quotient(x^2+1) - sage: Qz != Qx + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz != Qx # optional - sage.libs.pari False """ return not (self == other) @@ -721,14 +721,14 @@ def __hash__(self): sage: Ry. = PolynomialRing(QQ) sage: hash(Rx) == hash(Ry) False - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: hash(Qx) == hash(Qy) + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: hash(Qx) == hash(Qy) # optional - sage.libs.pari False - sage: hash(Qx) == hash(Qx) + sage: hash(Qx) == hash(Qx) # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2+1) - sage: hash(Qz) == hash(Qx) + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: hash(Qz) == hash(Qx) # optional - sage.libs.pari True """ return hash((self.polynomial_ring(), self.modulus())) @@ -740,8 +740,8 @@ def _singular_init_(self, S=None): TESTS:: sage: P. = QQ[] - sage: Q = P.quo([(x^2+1)]) - sage: singular(Q) # indirect doctest + sage: Q = P.quo([(x^2 + 1)]) # optional - sage.libs.pari + sage: singular(Q) # indirect doctest # optional - sage.libs.pari polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 @@ -750,7 +750,7 @@ def _singular_init_(self, S=None): // block 2 : ordering C // quotient ring from ideal _[1]=xbar^2+1 - sage: singular(Q.gen()) + sage: singular(Q.gen()) # optional - sage.libs.pari xbar """ @@ -844,7 +844,7 @@ def cardinality(self): sage: R.quo(1).order() 1 - sage: R.quo(x^3-2).order() + sage: R.quo(x^3 - 2).order() # optional - sage.libs.pari +Infinity :: @@ -985,11 +985,11 @@ def discriminant(self, v=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^3 + x^2 + x + 1) - sage: S.discriminant() + sage: S = R.quotient(x^3 + x^2 + x + 1) # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari -16 - sage: S = R.quotient((x + 1) * (x + 1)) - sage: S.discriminant() + sage: S = R.quotient((x + 1) * (x + 1)) # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari 0 The discriminant of the quotient polynomial ring need not equal the @@ -997,10 +997,10 @@ def discriminant(self, v=None): discriminant of a number field is by definition the discriminant of the ring of integers of the number field:: - sage: S = R.quotient(x^2 - 8) - sage: S.number_field().discriminant() + sage: S = R.quotient(x^2 - 8) # optional - sage.libs.pari + sage: S.number_field().discriminant() # optional - sage.libs.pari 8 - sage: S.discriminant() + sage: S.discriminant() # optional - sage.libs.pari 32 """ return self.modulus().discriminant() @@ -1013,8 +1013,8 @@ class of the image of the generator of the polynomial ring. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 8, 'gamma') - sage: S.gen() + sage: S = R.quotient(x^2 - 8, 'gamma') # optional - sage.libs.pari + sage: S.gen() # optional - sage.libs.pari gamma """ if n != 0: @@ -1036,22 +1036,24 @@ def is_field(self, proof = True): sage: S.is_field() # optional - sage.libs.pari False sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 2) - sage: S.is_field() + sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari + sage: S.is_field() # optional - sage.libs.pari True If proof is ``True``, requires the ``is_irreducible`` method of the modulus to be implemented:: - sage: R1. = Qp(2)[] - sage: F1 = R1.quotient_ring(x^2+x+1) - sage: R2. = F1[] - sage: F2 = R2.quotient_ring(x^2+x+1) - sage: F2.is_field() + sage: R1. = Qp(2)[] # optional - sage.rings.padics + sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.rings.padics + sage: R2. = F1[] # optional - sage.rings.padics + sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.rings.padics + sage: F2.is_field() # optional - sage.rings.padics Traceback (most recent call last): ... - NotImplementedError: cannot rewrite Univariate Quotient Polynomial Ring in xbar over 2-adic Field with capped relative precision 20 with modulus (1 + O(2^20))*x^2 + (1 + O(2^20))*x + 1 + O(2^20) as an isomorphic ring - sage: F2.is_field(proof = False) + NotImplementedError: cannot rewrite Univariate Quotient Polynomial Ring in + xbar over 2-adic Field with capped relative precision 20 with modulus + (1 + O(2^20))*x^2 + (1 + O(2^20))*x + 1 + O(2^20) as an isomorphic ring + sage: F2.is_field(proof = False) # optional - sage.rings.padics False """ @@ -1079,22 +1081,22 @@ def is_integral_domain(self, proof = True): sage: S = R.quotient(z^2 - z) # optional - sage.libs.pari sage: S.is_integral_domain() # optional - sage.libs.pari False - sage: T = R.quotient(z^2 + 1) - sage: T.is_integral_domain() + sage: T = R.quotient(z^2 + 1) # optional - sage.libs.pari + sage: T.is_integral_domain() # optional - sage.libs.pari True sage: U = R.quotient(-1) sage: U.is_integral_domain() False sage: R2. = PolynomialRing(R) - sage: S2 = R2.quotient(z^2 - y^3) - sage: S2.is_integral_domain() + sage: S2 = R2.quotient(z^2 - y^3) # optional - sage.libs.pari + sage: S2.is_integral_domain() # optional - sage.libs.pari True - sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) - sage: S3.is_integral_domain() + sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) # optional - sage.libs.pari + sage: S3.is_integral_domain() # optional - sage.libs.pari False sage: R. = PolynomialRing(ZZ.quotient(4)) - sage: S = R.quotient(z-1) + sage: S = R.quotient(z - 1) sage: S.is_integral_domain() False @@ -1112,7 +1114,7 @@ def is_integral_domain(self, proof = True): Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof = False) + sage: S.is_integral_domain(proof = False) # optional - sage.libs.pari sage.rings.number_field False The reason that the modulus y^2 - y -1 is not prime is that it @@ -1233,8 +1235,8 @@ def polynomial_ring(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2-2) - sage: S.polynomial_ring() + sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari + sage: S.polynomial_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Rational Field """ return self.__ring @@ -1657,13 +1659,13 @@ def S_units(self, S, proof=True): sage: K. = QQ['x'].quotient(x^2 + 3) sage: u, o = K.S_units([])[0]; o 6 - sage: 2*u - 1 in {a, -a} + sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari True - sage: u^6 + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True :: @@ -1748,14 +1750,15 @@ def units(self, proof=True): sage: u = K.units()[0][0] sage: 2*u - 1 in {a, -a} True - sage: u^6 + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True - sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.units(()) + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari + sage: K.units(()) # optional - sage.libs.pari [(-1, 2)] :: @@ -1779,13 +1782,13 @@ def units(self, proof=True): Note that all the returned values live where we expect them to:: - sage: L. = K['y'].quotient(y^3 + 5) - sage: U = L.units() - sage: type(U[0][0]) + sage: L. = K['y'].quotient(y^3 + 5) # optional - sage.libs.pari + sage: U = L.units() # optional - sage.libs.pari + sage: type(U[0][0]) # optional - sage.libs.pari - sage: type(U[0][1]) + sage: type(U[0][1]) # optional - sage.libs.pari - sage: type(U[1][1]) + sage: type(U[1][1]) # optional - sage.libs.pari """ @@ -1960,9 +1963,9 @@ def _isomorphic_ring(self): Finite Field in z8 of size 2^8 sage: R. = QQ[] - sage: K = R.quo(x^2 + 1) - sage: from_L, to_L, L = K._isomorphic_ring() - sage: L + sage: K = R.quo(x^2 + 1) # optional - sage.libs.pari + sage: from_L, to_L, L = K._isomorphic_ring() # optional - sage.libs.pari sage.rings.number_field + sage: L # optional - sage.libs.pari sage.rings.number_field Number Field in xbar with defining polynomial x^2 + 1 TESTS: @@ -2132,7 +2135,7 @@ class PolynomialQuotientRing_coercion(DefaultConvertMap_unique): sage: R. = ZZ[] sage: S. = QQ[] - sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)); f + sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)); f # optional - sage.libs.pari Coercion map: From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 To: Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 @@ -2140,17 +2143,17 @@ class PolynomialQuotientRing_coercion(DefaultConvertMap_unique): TESTS:: sage: from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_coercion - sage: isinstance(f, PolynomialQuotientRing_coercion) + sage: isinstance(f, PolynomialQuotientRing_coercion) # optional - sage.libs.pari True - sage: TestSuite(f).run(skip=['_test_pickling']) + sage: TestSuite(f).run(skip=['_test_pickling']) # optional - sage.libs.pari Pickling works:: - sage: g = loads(dumps(f)); g + sage: g = loads(dumps(f)); g # optional - sage.libs.pari Coercion map: From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 To: Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 - sage: f == g + sage: f == g # optional - sage.libs.pari True """ @@ -2166,8 +2169,8 @@ def is_injective(self): sage: R. = ZZ[] sage: S. = QQ[] - sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)) - sage: f.is_injective() + sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)) # optional - sage.libs.pari + sage: f.is_injective() # optional - sage.libs.pari True """ @@ -2220,11 +2223,11 @@ def _richcmp_(self, other, op): sage: R. = ZZ[] sage: S. = ZZ[] - sage: f = S.quo(x).coerce_map_from(R.quo(x^2)) - sage: g = S.quo(x).coerce_map_from(R.quo(x^3)) - sage: f == g + sage: f = S.quo(x).coerce_map_from(R.quo(x^2)) # optional - sage.libs.pari + sage: g = S.quo(x).coerce_map_from(R.quo(x^3)) # optional - sage.libs.pari + sage: f == g # optional - sage.libs.pari False - sage: f == f + sage: f == f # optional - sage.libs.pari True """ @@ -2265,10 +2268,10 @@ def __init__(self, ring, polynomial, name=None, category=None): Check that :trac:`29017` is fixed:: sage: R. = ZZ[] - sage: Q = R.quo(x-1) - sage: H = R.Hom(Q) - sage: h = R.hom(Q) - sage: h.parent() is H + sage: Q = R.quo(x - 1) # optional - sage.libs.pari + sage: H = R.Hom(Q) # optional - sage.libs.pari + sage: h = R.hom(Q) # optional - sage.libs.pari + sage: h.parent() is H # optional - sage.libs.pari True """ category = CommutativeAlgebras(ring.base_ring().category()).Quotients().NoZeroDivisors().or_subcategory(category) @@ -2293,14 +2296,14 @@ def field_extension(self, names): EXAMPLES:: sage: R. = PolynomialRing(Rationals()) - sage: S. = R.quotient(x^3-2) - sage: F., f, g = S.field_extension() - sage: F + sage: S. = R.quotient(x^3 - 2) # optional - sage.libs.pari + sage: F., f, g = S.field_extension() # optional - sage.libs.pari sage.rings.number_field + sage: F # optional - sage.libs.pari sage.rings.number_field Number Field in b with defining polynomial x^3 - 2 - sage: a = F.gen() - sage: f(alpha) + sage: a = F.gen() # optional - sage.libs.pari sage.rings.number_field + sage: f(alpha) # optional - sage.libs.pari sage.rings.number_field b - sage: g(a) + sage: g(a) # optional - sage.libs.pari sage.rings.number_field alpha Note that the parent ring must be an integral domain:: @@ -2374,12 +2377,12 @@ class PolynomialQuotientRing_field(PolynomialQuotientRing_domain, Field): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^2 + 1) - sage: S + sage: S. = R.quotient(x^2 + 1) # optional - sage.rings.number_field + sage: S # optional - sage.rings.number_field Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 - sage: loads(S.dumps()) == S + sage: loads(S.dumps()) == S # optional - sage.rings.number_field True - sage: loads(xbar.dumps()) == xbar + sage: loads(xbar.dumps()) == xbar # optional - sage.rings.number_field True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2400,10 +2403,14 @@ def complex_embeddings(self, prec=53): sage: R. = QQ[] sage: f = x^5 + x + 17 - sage: k = R.quotient(f) - sage: v = k.complex_embeddings(100) - sage: [phi(k.0^2) for phi in v] - [2.9757207403766761469671194565, -2.4088994371613850098316292196 + 1.9025410530350528612407363802*I, -2.4088994371613850098316292196 - 1.9025410530350528612407363802*I, 0.92103906697304693634806949137 - 3.0755331188457794473265418086*I, 0.92103906697304693634806949137 + 3.0755331188457794473265418086*I] + sage: k = R.quotient(f) # optional - sage.rings.number_field + sage: v = k.complex_embeddings(100) # optional - sage.rings.number_field + sage: [phi(k.0^2) for phi in v] # optional - sage.rings.number_field + [2.9757207403766761469671194565, + -2.4088994371613850098316292196 + 1.9025410530350528612407363802*I, + -2.4088994371613850098316292196 - 1.9025410530350528612407363802*I, + 0.92103906697304693634806949137 - 3.0755331188457794473265418086*I, + 0.92103906697304693634806949137 + 3.0755331188457794473265418086*I] """ CC = sage.rings.complex_mpfr.ComplexField(prec) v = self.modulus().roots(multiplicities=False, ring=CC) diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py index 2f10705fdda..d2b0e167b76 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari r""" Elements of Quotients of Univariate Polynomial Rings diff --git a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx index c13372dcd25..6f8a19a6ad0 100644 --- a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +++ b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx @@ -6,19 +6,19 @@ TESTS: Check that operations with numpy elements work well (see :trac:`18076` and :trac:`8426`):: - sage: import numpy + sage: import numpy # optional - numpy sage: x = polygen(RR) - sage: x * numpy.int32('1') + sage: x * numpy.int32('1') # optional - numpy x - sage: numpy.int32('1') * x + sage: numpy.int32('1') * x # optional - numpy x - sage: x * numpy.int64('1') + sage: x * numpy.int64('1') # optional - numpy x - sage: numpy.int64('1') * x + sage: numpy.int64('1') * x # optional - numpy x - sage: x * numpy.float32('1.5') + sage: x * numpy.float32('1.5') # optional - numpy 1.50000000000000*x - sage: numpy.float32('1.5') * x + sage: numpy.float32('1.5') * x # optional - numpy 1.50000000000000*x """ diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index 31663110bc5..090d41fa538 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -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) + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.libs.pari sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.libs.pari False - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.libs.pari False - sage: S.0 + R.0 + sage: S.0 + R.0 # optional - sage.libs.pari 2*x - sage: (S.0 + R.0).parent() + sage: (S.0 + R.0).parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 5 - sage: (S.0 + R.0).parent().is_sparse() + sage: (S.0 + R.0).parent().is_sparse() # optional - sage.libs.pari False Similarly, there is a coercion from the (non-default) NTL implementation for univariate polynomials over the integers to the default FLINT implementation, but not vice versa:: - sage: R. = PolynomialRing(ZZ, implementation = 'NTL') - sage: S. = PolynomialRing(ZZ, implementation = 'FLINT') - sage: (S.0+R.0).parent() is S + sage: R. = PolynomialRing(ZZ, implementation='NTL') # optional - sage.libs.ntl + sage: S. = PolynomialRing(ZZ, implementation='FLINT') # optional - sage.libs.flint + sage: (S.0+R.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True - sage: (R.0+S.0).parent() is S + sage: (R.0+S.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True TESTS:: @@ -122,9 +122,9 @@ Check that :trac:`5562` has been fixed:: sage: R. = PolynomialRing(RDF, 1) - sage: v1 = vector([u]) - sage: v2 = vector([CDF(2)]) - sage: v1 * v2 + sage: v1 = vector([u]) # optional - sage.modules + sage: v2 = vector([CDF(2)]) # optional - sage.modules + sage: v1 * v2 # optional - sage.modules 2.0*u """ @@ -210,11 +210,11 @@ def is_PolynomialRing(x): :: - sage: R. = PolynomialRing(ZZ, implementation="singular"); R + sage: R. = PolynomialRing(ZZ, implementation="singular"); R # optional - sage.libs.singular Multivariate Polynomial Ring in w over Integer Ring - sage: is_PolynomialRing(R) + sage: is_PolynomialRing(R) # optional - sage.libs.singular False - sage: type(R) + sage: type(R) # optional - sage.libs.singular """ return isinstance(x, PolynomialRing_general) @@ -243,7 +243,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, and Category of commutative algebras over (euclidean domains and infinite enumerated sets and metric spaces) and Category of infinite sets - sage: category(GF(7)['x']) + sage: category(GF(7)['x']) # optional - sage.libs.pari Join of Category of euclidean domains and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets @@ -268,13 +268,13 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: Zmod(1)['x'].is_finite() True - sage: GF(7)['x'].is_finite() + sage: GF(7)['x'].is_finite() # optional - sage.libs.pari False sage: Zmod(1)['x']['y'].is_finite() True - sage: GF(7)['x']['y'].is_finite() + sage: GF(7)['x']['y'].is_finite() # optional - sage.libs.pari False """ @@ -357,9 +357,9 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, Coercing in pari elements:: - sage: QQ['x'](pari('[1,2,3/5]')) + sage: QQ['x'](pari('[1,2,3/5]')) # optional - sage.libs.pari 3/5*x^2 + 2*x + 1 - sage: QQ['x'](pari('(-1/3)*x^10 + (2/3)*x - 1/5')) + sage: QQ['x'](pari('(-1/3)*x^10 + (2/3)*x - 1/5')) # optional - sage.libs.pari -1/3*x^10 + 2/3*x - 1/5 Coercing strings:: @@ -377,10 +377,10 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, This shows that the issue at :trac:`4106` is fixed:: - sage: x = var('x') + sage: x = var('x') # optional - sage.symbolic sage: R = IntegerModRing(4) - sage: S = R['x'] - sage: S(x) + sage: S = R['x'] # optional - sage.symbolic + sage: S(x) # optional - sage.symbolic x Throw a TypeError if any of the coefficients cannot be coerced @@ -393,16 +393,16 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, Check that the bug in :trac:`11239` is fixed:: - sage: K. = GF(5^2, prefix='z') - sage: L. = GF(5^4, prefix='z') - sage: f = K['x'].gen() + a - sage: L['x'](f) + sage: K. = GF(5^2, prefix='z') # optional - sage.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 x + b^3 + b^2 + b + 3 A test from :trac:`14485` :: - sage: x = SR.var('x') - sage: QQbar[x](x^6+x^5+x^4-x^3+x^2-x+2/5) + sage: x = SR.var('x') # optional - sage.symbolic + sage: QQbar[x](x^6 + x^5 + x^4 - x^3 + x^2 - x + 2/5) # optional - sage.rings.number_field sage.symbolic x^6 + x^5 + x^4 - x^3 + x^2 - x + 2/5 Check support for unicode characters (:trac:`29280`):: @@ -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)) + sage: R.coerce_map_from(GF(7)) # optional - sage.libs.pari """ from .polynomial_element import PolynomialBaseringInjection @@ -761,20 +761,20 @@ def _coerce_map_from_(self, P): Over the integers, there is a coercion from the NTL and generic implementation to the default FLINT implementation:: - sage: R = PolynomialRing(ZZ, 't', implementation="NTL") - sage: S = PolynomialRing(ZZ, 't', implementation="FLINT") + sage: R = PolynomialRing(ZZ, 't', implementation="NTL") # optional - sage.libs.ntl + sage: S = PolynomialRing(ZZ, 't', implementation="FLINT") # optional - sage.libs.flint sage: T = PolynomialRing(ZZ, 't', implementation="generic") - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.libs.flint sage.libs.ntl False - sage: R.has_coerce_map_from(T) + sage: R.has_coerce_map_from(T) # optional - sage.libs.ntl False - sage: S.has_coerce_map_from(T) + sage: S.has_coerce_map_from(T) # optional - sage.libs.flint True - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.libs.flint sage.libs.ntl True - sage: T.has_coerce_map_from(R) + sage: T.has_coerce_map_from(R) # optional - sage.libs.ntl False - sage: T.has_coerce_map_from(S) + sage: T.has_coerce_map_from(S) # optional - sage.libs.flint False """ base_ring = self.base_ring() @@ -843,9 +843,9 @@ def _magma_init_(self, magma): Univariate Polynomial Ring in y over Rational Field sage: S.1 # optional - magma y - sage: magma(PolynomialRing(GF(7), 'x')) # optional - magma + sage: magma(PolynomialRing(GF(7), 'x')) # optional - magma # optional - sage.libs.pari Univariate Polynomial Ring in x over GF(7) - sage: magma(PolynomialRing(GF(49,'a'), 'x')) # optional - magma + sage: magma(PolynomialRing(GF(49,'a'), 'x')) # optional - magma # optional - sage.libs.pari Univariate Polynomial Ring in x over GF(7^2) sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma Univariate Polynomial Ring in x over Univariate Polynomial Ring in w over Integer Ring @@ -867,9 +867,9 @@ def _magma_init_(self, magma): A nested example over a Givaro finite field:: - sage: k. = GF(9) - sage: R. = k[] - sage: magma(a^2*x^3 + (a+1)*x + a) # optional - magma + sage: k. = GF(9) # optional - sage.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 a^2*x^3 + a^2*x + a """ B = magma(self.base_ring()) @@ -888,23 +888,23 @@ def _gap_init_(self, gap=None): EXAMPLES:: sage: R. = ZZ[] - sage: gap(R) + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: gap(R) is gap(R) + sage: gap(R) is gap(R) # optional - sage.libs.gap True - sage: gap(z^2 + z) + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z A univariate polynomial ring over a multivariate polynomial ring over a number field:: sage: Q. = QQ[] - sage: K. = NumberField(t^2+t+1) - sage: P. = K[] - sage: S. = P[] - sage: gap(S) + sage: K. = NumberField(t^2+t+1) # optional - sage.rings.number_field + sage: P. = K[] # optional - sage.rings.number_field + sage: S. = P[] # optional - sage.rings.number_field + sage: gap(S) # optional - sage.rings.number_field PolynomialRing( PolynomialRing( , ["x", "y"] ), ["z"] ) - sage: gap(S) is gap(S) + sage: gap(S) is gap(S) # optional - 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) + sage: sage_input(GF(5)['x']['y'], verify=True) # optional - sage.libs.pari # Verified GF(5)['x']['y'] - sage: from sage.misc.sage_input import SageInputBuilder - sage: ZZ['z']._sage_input_(SageInputBuilder(), False) + sage: from sage.misc.sage_input import SageInputBuilder # optional - sage.libs.pari + sage: ZZ['z']._sage_input_(SageInputBuilder(), False) # optional - sage.libs.pari {constr_parent: {subscr: {atomic:ZZ}[{atomic:'z'}]} with gens: ('z',)} """ base = sib(self.base_ring()) @@ -964,7 +964,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = QQ[] - sage: R._is_valid_homomorphism_(GF(7), [5]) + sage: R._is_valid_homomorphism_(GF(7), [5]) # optional - sage.libs.pari False sage: R._is_valid_homomorphism_(Qp(7), [5]) # optional - sage.rings.padics True @@ -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')) + sage: R.change_ring(GF(19^2, 'b')) # optional - sage.libs.pari 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 + sage: S = R.change_ring(GF(19^2, 'b')); S # optional - sage.libs.pari Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2 sage: S.characteristic() 19 @@ -1164,23 +1164,23 @@ def cyclotomic_polynomial(self, n): EXAMPLES:: sage: R = ZZ['x'] - sage: R.cyclotomic_polynomial(8) + sage: R.cyclotomic_polynomial(8) # optional - sage.libs.pari x^4 + 1 - sage: R.cyclotomic_polynomial(12) + sage: R.cyclotomic_polynomial(12) # optional - sage.libs.pari x^4 - x^2 + 1 - sage: S = PolynomialRing(FiniteField(7), 'x') - sage: S.cyclotomic_polynomial(12) + sage: S = PolynomialRing(FiniteField(7), 'x') # optional - sage.libs.pari + sage: S.cyclotomic_polynomial(12) # optional - sage.libs.pari x^4 + 6*x^2 + 1 - sage: S.cyclotomic_polynomial(1) + sage: S.cyclotomic_polynomial(1) # optional - sage.libs.pari x + 6 TESTS: Make sure it agrees with other systems for the trivial case:: - sage: ZZ['x'].cyclotomic_polynomial(1) + sage: ZZ['x'].cyclotomic_polynomial(1) # optional - sage.libs.pari x - 1 - sage: gp('polcyclo(1)') + sage: gp('polcyclo(1)') # optional - sage.libs.pari x - 1 """ if n <= 0: @@ -1308,12 +1308,12 @@ def krull_dimension(self): sage: R. = QQ[] sage: R.krull_dimension() 1 - sage: R. = GF(9,'a')[]; R + sage: R. = GF(9, 'a')[]; R # optional - sage.libs.pari Univariate Polynomial Ring in z over Finite Field in a of size 3^2 - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.libs.pari 1 - sage: S. = R[] - sage: S.krull_dimension() + sage: S. = R[] # optional - sage.libs.pari + sage: S.krull_dimension() # optional - sage.libs.pari 2 sage: for n in range(10): # optional - sage.libs.pari ....: S = PolynomialRing(S, 'w') @@ -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') - sage: for _ in range(100): + sage: R = PolynomialRing(GF(2), 'z') # optional - sage.libs.pari + sage: for _ in range(100): # optional - sage.libs.pari ....: d = randint(-1,20) ....: P = R.random_element(degree=d) ....: assert P.degree() == d, "problem with {} which has not degree {}".format(P,d) - sage: R.random_element(degree=-2) + sage: R.random_element(degree=-2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: degree should be an integer greater or equal than -1 @@ -1571,8 +1571,8 @@ def polynomials( self, of_degree = None, max_degree = None ): EXAMPLES:: - sage: P = PolynomialRing(GF(3),'y') - sage: for p in P.polynomials( of_degree = 2 ): print(p) + sage: P = PolynomialRing(GF(3), 'y') # optional - sage.libs.pari + sage: for p in P.polynomials(of_degree=2): print(p) # optional - sage.libs.pari 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) + sage: for p in P.polynomials(max_degree=1): print(p) # optional - sage.libs.pari 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) + sage: for p in P.polynomials(max_degree=1, of_degree=3): print(p) # optional - sage.libs.pari 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') - sage: for p in P.monics( of_degree = 2 ): print(p) + 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 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) + sage: for p in P.monics(max_degree=1): print(p) # optional - sage.libs.pari 1 y y + a y + a + 1 y + 1 - sage: for p in P.monics( max_degree = 1, of_degree = 3 ): print(p) + sage: for p in P.monics(max_degree=1, of_degree=3): print(p) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: you should pass exactly one of of_degree and max_degree @@ -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()) + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl """ self._implementation_repr = '' @@ -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) - sage: len(L) + sage: L = R.weil_polynomials(4, 2) # optional - sage.libs.flint + sage: len(L) # optional - sage.libs.flint 35 - sage: L[9] + sage: L[9] # optional - sage.libs.flint T^4 + T^3 + 2*T^2 + 2*T + 4 - sage: all(p.is_weil_polynomial() for p in L) + sage: all(p.is_weil_polynomial() for p in L) # optional - sage.libs.flint True Setting multiple leading coefficients:: sage: R. = QQ[] - sage: l = R.weil_polynomials(4,2,lead=((1,0),(2,4),(1,2))) - sage: l + sage: l = R.weil_polynomials(4, 2, lead=((1,0), (2,4), (1,2))) # optional - sage.libs.flint + sage: l # optional - sage.libs.flint [T^4 + 2*T^3 + 5*T^2 + 4*T + 4, T^4 + 2*T^3 + 3*T^2 + 4*T + 4, T^4 - 2*T^3 + 5*T^2 - 4*T + 4, @@ -1912,40 +1912,43 @@ 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) - sage: len(l) + sage: l = R.weil_polynomials(10, 1, lead=2) # optional - sage.libs.flint + sage: len(l) # optional - sage.libs.flint 4865 - sage: l[len(l)//2] + sage: l[len(l)//2] # optional - sage.libs.flint 2*T^10 + T^8 + T^6 + T^4 + T^2 + 2 TESTS: We check that products of Weil polynomials are also listed as Weil polynomials:: - sage: all((f * g) in R.weil_polynomials(6, q) for q in [3,4] for f in R.weil_polynomials(2, q) for g in R.weil_polynomials(4, q)) + sage: all((f * g) in R.weil_polynomials(6, q) for q in [3, 4] # optional - sage.libs.flint + ....: for f in R.weil_polynomials(2, q) for g in R.weil_polynomials(4, q)) True We check that irreducible Weil polynomials of degree 6 are CM:: - sage: simples = [f for f in R.weil_polynomials(6, 3) if f.is_irreducible()] - sage: len(simples) + sage: simples = [f for f in R.weil_polynomials(6, 3) if f.is_irreducible()] # optional - sage.libs.flint + sage: len(simples) # optional - sage.libs.flint 348 - sage: reals = [R([f[3+i] + sum((-3)^j * (i+2*j)/(i+j) * binomial(i+j,j) * f[3+i+2*j] for j in range(1,(3+i)//2+1)) for i in range(4)]) for f in simples] + sage: reals = [R([f[3+i] + sum((-3)^j * (i+2*j)/(i+j) * binomial(i+j,j) * f[3+i+2*j] # optional - sage.libs.flint + ....: for j in range(1, (3+i)//2 + 1)) + ....: for i in range(4)]) for f in simples] Check that every polynomial in this list has 3 real roots between `-2 \sqrt{3}` and `2 \sqrt{3}`:: - sage: roots = [f.roots(RR, multiplicities=False) for f in reals] - sage: all(len(L) == 3 and all(x^2 <= 12 for x in L) for L in roots) + sage: roots = [f.roots(RR, multiplicities=False) for f in reals] # optional - sage.libs.flint + sage: all(len(L) == 3 and all(x^2 <= 12 for x in L) for L in roots) # optional - sage.libs.flint True Finally, check that the original polynomials are reconstructed as CM polynomials:: - sage: all(f == T^3*r(T + 3/T) for (f, r) in zip(simples, reals)) + sage: all(f == T^3*r(T + 3/T) for (f, r) in zip(simples, reals)) # optional - sage.libs.flint True A simple check (not sufficient):: - sage: all(f.number_of_real_roots() == 0 for f in simples) + sage: all(f.number_of_real_roots() == 0 for f in simples) # optional - sage.libs.flint True """ R = self.base_ring() @@ -1984,7 +1987,7 @@ def _repr_(self): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) """ s = PolynomialRing_commutative._repr_(self) @@ -2004,11 +2007,11 @@ def construction(self): sage: functor.implementation is None True - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: functor, arg = R.construction(); functor, arg + sage: functor, arg = R.construction(); functor, arg # optional - sage.libs.ntl (Poly[x], Integer Ring) - sage: functor.implementation + sage: functor.implementation # optional - sage.libs.ntl 'NTL' """ implementation = None @@ -2033,7 +2036,7 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_field as PRing sage: R = PRing(QQ, 'x'); R Univariate Polynomial Ring in x over Rational Field - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint sage: R = PRing(QQ, 'x', sparse=True); R Sparse Univariate Polynomial Ring in x over Rational Field @@ -2046,7 +2049,7 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, Demonstrate that :trac:`8762` is fixed:: - sage: R. = PolynomialRing(GF(next_prime(10^20)), sparse=True) + sage: R. = PolynomialRing(GF(next_prime(10^20)), sparse=True) # optional - sage.libs.pari sage: x^(10^20) # this should be fast x^100000000000000000000 """ @@ -2093,8 +2096,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: R. = GF(5)[] - sage: R._ideal_class_() + sage: R. = GF(5)[] # optional - sage.libs.pari + sage: R._ideal_class_() # optional - sage.libs.pari """ from sage.rings.polynomial.ideal import Ideal_1poly_field @@ -2249,41 +2252,45 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r -2 sage: f(-4) 9 - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: f = R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)]); f + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.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 a^2*x^2 + a^2*x + a^2 - sage: f(a^2+a) + sage: f(a^2+a) # optional - sage.libs.pari a - sage: f(a) + sage: f(a) # optional - sage.libs.pari 1 - sage: f(a^2) + sage: f(a^2) # optional - sage.libs.pari a^2 + a + 1 Now use a memory efficient version of Neville's method:: sage: R = PolynomialRing(QQ, 'x') - sage: R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)], algorithm="neville") + sage: R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)], + ....: algorithm="neville") [9, -11/7*x + 19/7, -17/42*x^2 - 83/42*x + 53/7, -23/84*x^3 - 11/84*x^2 + 13/7*x + 1] - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)], algorithm="neville") + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.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 + ....: algorithm="neville") [a^2 + a + 1, x + a + 1, a^2*x^2 + a^2*x + a^2] Repeated use of Neville's method to get better Lagrange interpolation polynomials:: sage: R = PolynomialRing(QQ, 'x') - sage: p = R.lagrange_polynomial([(0,1),(2,2)], algorithm="neville") - sage: R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)], algorithm="neville", previous_row=p)[-1] + sage: p = R.lagrange_polynomial([(0,1), (2,2)], algorithm="neville") + sage: R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)], + ....: algorithm="neville", previous_row=p)[-1] -23/84*x^3 - 11/84*x^2 + 13/7*x + 1 - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: p = R.lagrange_polynomial([(a^2+a,a),(a,1)], algorithm="neville") - sage: R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)], algorithm="neville", previous_row=p)[-1] + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.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 + ....: algorithm="neville", previous_row=p)[-1] a^2*x^2 + a^2*x + a^2 TESTS: @@ -2325,10 +2332,10 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r Check that base fields of positive characteristic are treated correctly (see :trac:`9787`):: - sage: R. = GF(101)[] - sage: R.lagrange_polynomial([[1, 0], [2, 0]]) + sage: R. = GF(101)[] # optional - sage.libs.pari + sage: R.lagrange_polynomial([[1, 0], [2, 0]]) # optional - sage.libs.pari 0 - sage: R.lagrange_polynomial([[1, 0], [2, 0], [3, 0]]) + sage: R.lagrange_polynomial([[1, 0], [2, 0], [3, 0]]) # optional - sage.libs.pari 0 """ # Perhaps we should be slightly stricter on the input and use @@ -2414,24 +2421,25 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: R.fraction_field() - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 + sage: R. = GF(5)[] # optional - sage.libs.pari + sage: R.fraction_field() # optional - sage.libs.pari + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 TESTS: Check that :trac:`25449` has been resolved:: - sage: k = GF(25453) - sage: F. = FunctionField(k) - sage: R. = k[] - sage: t(x) + sage: k = GF(25453) # optional - sage.libs.pari + sage: F. = FunctionField(k) # optional - sage.libs.pari + sage: R. = k[] # optional - sage.libs.pari + sage: t(x) # optional - sage.libs.pari x - sage: k = GF(55667) - sage: F. = FunctionField(k) - sage: R. = k[] - sage: t(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 x """ @@ -2451,24 +2459,24 @@ class PolynomialRing_dense_finite_field(PolynomialRing_field): EXAMPLES:: - sage: R = PolynomialRing(GF(27, 'a'), 'x') - sage: type(R) + sage: R = PolynomialRing(GF(27, 'a'), 'x') # optional - sage.libs.pari + sage: type(R) # optional - sage.libs.pari """ def __init__(self, base_ring, name="x", element_class=None, implementation=None): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field - sage: R = PolynomialRing_dense_finite_field(GF(5), implementation='generic') - sage: type(R(0)) + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.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: S = PolynomialRing_dense_finite_field(GF(25, 'a'), implementation='NTL') - sage: type(S(0)) + sage: S = PolynomialRing_dense_finite_field(GF(25, 'a'), implementation='NTL') # optional - sage.libs.pari + sage: type(S(0)) # optional - sage.libs.pari - sage: S = PolynomialRing_dense_finite_field(GF(64), implementation='superfast') + sage: S = PolynomialRing_dense_finite_field(GF(64), implementation='superfast') # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: unknown implementation 'superfast' for dense polynomial rings over Finite Field in z6 of size 2^6 @@ -2497,16 +2505,16 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field - sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.libs.pari + sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) # optional - sage.libs.pari ['NTL', None] - sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), False) # optional - sage.libs.pari ['NTL', None] - sage: PolynomialRing_dense_finite_field._implementation_names_impl("generic", GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl("generic", GF(4), False) # optional - sage.libs.pari ['generic'] - sage: PolynomialRing_dense_finite_field._implementation_names_impl("FLINT", GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl("FLINT", GF(4), False) # optional - sage.libs.pari NotImplemented - sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) # optional - sage.libs.pari NotImplemented """ if sparse: @@ -2541,14 +2549,14 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: f = GF(5^3, 'a')['x'].irreducible_element(2) - sage: f.degree() + sage: f = GF(5^3, 'a')['x'].irreducible_element(2) # optional - sage.libs.pari + sage: f.degree() # optional - sage.libs.pari 2 - sage: f.is_irreducible() + sage: f.is_irreducible() # optional - sage.libs.pari True - sage: GF(19)['x'].irreducible_element(21, algorithm="first_lexicographic") + sage: GF(19)['x'].irreducible_element(21, algorithm="first_lexicographic") # optional - sage.libs.pari x^21 + x + 5 - sage: GF(5**2, 'a')['x'].irreducible_element(17, algorithm="first_lexicographic") + sage: GF(5**2, 'a')['x'].irreducible_element(17, algorithm="first_lexicographic") # optional - sage.libs.pari x^17 + a*x + 4*a + 3 AUTHORS: @@ -2609,15 +2617,15 @@ def _roth_ruckenstein(self, p, degree_bound, precision): EXAMPLES:: - sage: F = GF(17) - sage: Px. = F[] - sage: Pxy. = Px[] - sage: p = (y - (x**2 + x + 1)) * (y**2 - x + 1) * (y - (x**3 + 4*x + 16)) - sage: Px._roth_ruckenstein(p, 3, None) + sage: F = GF(17) # optional - sage.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 [x^3 + 4*x + 16, x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 2, None) + sage: Px._roth_ruckenstein(p, 2, None) # optional - sage.libs.pari [x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 1, 2) + sage: Px._roth_ruckenstein(p, 1, 2) # optional - sage.libs.pari [(4*x + 16, 2), (2*x + 13, 2), (15*x + 4, 2), (x + 1, 2)] """ def roth_rec(p, lam, k, g): @@ -2708,28 +2716,29 @@ def _alekhnovich(self, p, degree_bound, precision=None, dc_threshold=None): EXAMPLES:: - sage: R. = GF(17)[] - sage: S. = R[] - sage: p = (y - 2*x^2 - 3*x - 14) * (y - 3*x + 2) * (y - 1) - sage: R._alekhnovich(p, 2) + sage: R. = GF(17)[] # optional - sage.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 [3*x + 15, 2*x^2 + 3*x + 14, 1] - sage: R._alekhnovich(p, 1) + sage: R._alekhnovich(p, 1) # optional - sage.libs.pari [3*x + 15, 1] - sage: R._alekhnovich(p, 1, precision = 2) + sage: R._alekhnovich(p, 1, precision=2) # optional - sage.libs.pari [(3*x + 15, 2), (3*x + 14, 2), (1, 2)] Example of benchmark to check that `dc_threshold = None` is better:: - sage: p = prod(y - R.random_element(20) for _ in range(10)) * S.random_element(10,10) # not tested - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = None) # not tested + sage: p = prod(y - R.random_element(20) # not tested # optional - sage.libs.pari + ....: for _ in range(10)) * S.random_element(10,10) + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = None) # not tested # optional - sage.libs.pari 1 loop, best of 3: 418 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 1) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 1) # not tested # optional - sage.libs.pari 1 loop, best of 3: 416 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 2) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 2) # not tested # optional - sage.libs.pari 1 loop, best of 3: 418 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 3) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 3) # not tested # optional - sage.libs.pari 1 loop, best of 3: 454 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 4) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 4) # not tested # optional - sage.libs.pari 1 loop, best of 3: 519 ms per loop AUTHORS: @@ -2819,24 +2828,24 @@ def _roots_univariate_polynomial(self, p, ring=None, multiplicities=False, algor EXAMPLES:: - sage: R. = GF(13)[] - sage: S. = R[] - sage: p = y^2 + (12*x^2 + x + 11)*y + x^3 + 12*x^2 + 12*x + 1 - sage: p.roots(multiplicities=False) + sage: R. = GF(13)[] # optional - sage.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 [x^2 + 11*x + 1, x + 1] - sage: p.roots(multiplicities=False, degree_bound=1) + sage: p.roots(multiplicities=False, degree_bound=1) # optional - sage.libs.pari [x + 1] - sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") + sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") # optional - sage.libs.pari [x^2 + 11*x + 1, x + 1] TESTS: Check that :trac:`23639` is fixed:: - sage: R = GF(3)['x']['y'] - sage: R.one().roots(multiplicities=False) + sage: R = GF(3)['x']['y'] # optional - sage.libs.pari + sage: R.one().roots(multiplicities=False) # optional - sage.libs.pari [] - sage: R.zero().roots(multiplicities=False) + sage: R.zero().roots(multiplicities=False) # optional - sage.libs.pari Traceback (most recent call last): ... ArithmeticError: roots of 0 are not defined @@ -3078,27 +3087,27 @@ def __init__(self, base_ring, name=None, element_class=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_n as PRing sage: R = PRing(Zmod(15), 'x'); R Univariate Polynomial Ring in x over Ring of integers modulo 15 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R + sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 15 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl - sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R + sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl - sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT') + sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT') # optional - sage.libs.flint Traceback (most recent call last): ... ValueError: FLINT does not support modulus 27670116110564327424 - sage: R = PRing(Zmod(2**63*3), 'x'); R + sage: R = PRing(Zmod(2**63*3), 'x'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl """ if element_class is None: @@ -3189,7 +3198,7 @@ def _repr_(self): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) """ s = PolynomialRing_commutative._repr_(self) @@ -3201,19 +3210,25 @@ def residue_field(self, ideal, names=None): EXAMPLES:: - sage: R. = GF(2)[] - sage: k. = R.residue_field(t^3+t+1); k - Residue field in a of Principal ideal (t^3 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k.list() + sage: R. = GF(2)[] # optional - sage.libs.pari + sage: k. = R.residue_field(t^3+t+1); k # optional - sage.libs.pari + 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 [0, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1, 1] - sage: R.residue_field(t) - Residue field of Principal ideal (t) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: P = R.irreducible_element(8) * R - sage: P - Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k. = R.residue_field(P); k - Residue field in a of Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k.cardinality() + sage: R.residue_field(t) # optional - sage.libs.pari + 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 + 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 + 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 256 Non-maximal ideals are not accepted:: @@ -3244,36 +3259,36 @@ def __init__(self, base_ring, name="x", implementation=None, element_class=None, """ TESTS:: - sage: P = GF(2)['x']; P + sage: P = GF(2)['x']; P # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.libs.pari - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p # optional - sage.libs.pari + sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 5 - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.libs.pari - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P + sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 5 (using NTL) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.libs.pari - sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') - sage: P + sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') # optional - sage.libs.pari + sage: P # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 9223372036854775837 (using NTL) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.libs.pari This caching bug was fixed in :trac:`24264`:: sage: p = 2^64 + 13 - sage: A = GF(p^2) - sage: B = GF(p^3) - sage: R = A.modulus().parent() - sage: S = B.modulus().parent() - sage: R is S + sage: A = GF(p^2) # optional - sage.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 True """ if element_class is None: @@ -3315,15 +3330,15 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: PolynomialRing(GF(2), 'x', implementation="GF2X") + sage: PolynomialRing(GF(2), 'x', implementation="GF2X") # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation="NTL") + sage: PolynomialRing(GF(2), 'x', implementation="NTL") # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation=None) + sage: PolynomialRing(GF(2), 'x', implementation=None) # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation="FLINT") + sage: PolynomialRing(GF(2), 'x', implementation="FLINT") # optional - sage.libs.pari Univariate Polynomial Ring in x over Finite Field of size 2 - sage: PolynomialRing(GF(3), 'x', implementation="GF2X") + sage: PolynomialRing(GF(3), 'x', implementation="GF2X") # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: GF2X only supports modulus 2 @@ -3395,35 +3410,35 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: GF(5)['x'].irreducible_element(2) + sage: GF(5)['x'].irreducible_element(2) # optional - sage.libs.pari x^2 + 4*x + 2 - sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra") + sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra") # optional - sage.libs.pari x^2 + x + 1 - sage: GF(5)['x'].irreducible_element(2, algorithm="primitive") + sage: GF(5)['x'].irreducible_element(2, algorithm="primitive") # optional - sage.libs.pari x^2 + 4*x + 2 - sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic") + sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic") # optional - sage.libs.pari x^32 + 2 - sage: GF(5)['x'].irreducible_element(32, algorithm="conway") + sage: GF(5)['x'].irreducible_element(32, algorithm="conway") # optional - sage.libs.pari Traceback (most recent call last): ... RuntimeError: requested Conway polynomial not in database. - sage: GF(5)['x'].irreducible_element(32, algorithm="primitive") + sage: GF(5)['x'].irreducible_element(32, algorithm="primitive") # optional - sage.libs.pari x^32 + ... In characteristic 2:: - sage: GF(2)['x'].irreducible_element(33) + sage: GF(2)['x'].irreducible_element(33) # optional - sage.libs.pari x^33 + x^13 + x^12 + x^11 + x^10 + x^8 + x^6 + x^3 + 1 - sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight") + sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight") # optional - sage.libs.pari x^33 + x^10 + 1 In degree 1:: - sage: GF(97)['x'].irreducible_element(1) + sage: GF(97)['x'].irreducible_element(1) # optional - sage.libs.pari x + 96 - sage: GF(97)['x'].irreducible_element(1, algorithm="conway") + sage: GF(97)['x'].irreducible_element(1, algorithm="conway") # optional - sage.libs.pari x + 92 - sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") + sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") # optional - sage.libs.pari x AUTHORS: diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index 5441588b5bf..25763ac3d09 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -179,32 +179,32 @@ def PolynomialRing(base_ring, *args, **kwds): like 2^1000000 * x^1000000 in FLINT may be unwise. :: - sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL + sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT + sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT # optional - sage.libs.flint Univariate Polynomial Ring in x over Integer Ring - sage: ZxFLINT is ZZ['x'] + sage: ZxFLINT is ZZ['x'] # optional - sage.libs.flint True - sage: ZxFLINT is PolynomialRing(ZZ, 'x') + sage: ZxFLINT is PolynomialRing(ZZ, 'x') # optional - sage.libs.flint True - sage: xNTL = ZxNTL.gen() - sage: xFLINT = ZxFLINT.gen() - sage: xNTL.parent() + sage: xNTL = ZxNTL.gen() # optional - sage.libs.ntl + sage: xFLINT = ZxFLINT.gen() # optional - sage.libs.flint + sage: xNTL.parent() # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: xFLINT.parent() + sage: xFLINT.parent() # optional - sage.libs.flint Univariate Polynomial Ring in x over Integer Ring There is a coercion from the non-default to the default implementation, so the values can be mixed in a single expression:: - sage: (xNTL + xFLINT^2) + sage: (xNTL + xFLINT^2) # optional - sage.libs.flint sage.libs.ntl x^2 + x The result of such an expression will use the default, i.e., the FLINT implementation:: - sage: (xNTL + xFLINT^2).parent() + sage: (xNTL + xFLINT^2).parent() # optional - sage.libs.flint sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring The generic implementation uses neither NTL nor FLINT:: @@ -298,16 +298,16 @@ 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 + 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() + 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 + 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, ...)** diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index c94bac346d7..e457baa333e 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -61,7 +61,7 @@ def _do_singular_init_(singular, base_ring, char, _vars, order): TESTS:: sage: from sage.rings.polynomial.polynomial_singular_interface import _do_singular_init_ - sage: _do_singular_init_(singular, ZZ, 0, 'X', 'dp') + sage: _do_singular_init_(singular, ZZ, 0, 'X', 'dp') # optional - sage.libs.singular (polynomial ring, over a domain, global ordering // coefficients: ZZ // number of vars : 1 diff --git a/src/sage/rings/polynomial/symmetric_ideal.py b/src/sage/rings/polynomial/symmetric_ideal.py index 9e1146a9526..779e0983c3f 100644 --- a/src/sage/rings/polynomial/symmetric_ideal.py +++ b/src/sage/rings/polynomial/symmetric_ideal.py @@ -405,8 +405,9 @@ def reduce(self, I, tailreduce=False): sage: J = (y[2]) * X sage: I.reduce(J) - Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field - sage: I.reduce(J, tailreduce=True) + Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field + sage: I.reduce(J, tailreduce=True) # optional - sage.combinat Symmetric Ideal (x_3^2*y_1) of Infinite polynomial ring in x, y over Rational Field """ @@ -455,14 +456,15 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None Here, we show the ``report`` option:: - sage: I.interreduction(report=True) + sage: I.interreduction(report=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> [1/2] > [2/2] T[1]> > - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field ``[m/n]`` indicates that polynomial number ``m`` is considered and the total number of polynomials under consideration is @@ -476,8 +478,9 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None sage: R = SymmetricReductionStrategy(X) sage: R Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational Field - sage: I.interreduction(RStrat=R) - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + sage: I.interreduction(RStrat=R) # optional - sage.combinat + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field sage: R Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational Field, modulo x_1^2, diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index f72485f0336..bf6d879d9d2 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -657,7 +657,7 @@ def __init__(self, name='lex', n=0, force=False): sage: T = TermOrder('degrevlex') sage: R. = PolynomialRing(QQ, order=T) - sage: R._singular_() + sage: R._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 @@ -673,7 +673,7 @@ def __init__(self, name='lex', n=0, force=False): sage: S = R.change_ring(order=T2) sage: S == T False - sage: S._singular_() + sage: S._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 @@ -1677,7 +1677,7 @@ def singular_str(self): sage: T = P.term_order() sage: T.singular_str() '(a(1:2),ls(2),a(1:2),ls(2))' - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1699,7 +1699,7 @@ def singular_str(self): sage: T = TermOrder("degneglex", 2) + TermOrder("degneglex", 2) sage: T._singular_ringorder_column = 0 sage: P = PolynomialRing(QQ, 4, names='x', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1717,7 +1717,7 @@ def singular_str(self): sage: T._singular_ringorder_column = 1 sage: P = PolynomialRing(QQ, 4, names='y', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1735,7 +1735,7 @@ def singular_str(self): sage: T._singular_ringorder_column = 2 sage: P = PolynomialRing(QQ, 4, names='z', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2156,9 +2156,9 @@ def termorder_from_singular(S): EXAMPLES:: sage: from sage.rings.polynomial.term_order import termorder_from_singular - sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') + sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') # optional - sage.libs.singular '' - sage: termorder_from_singular(singular) + sage: termorder_from_singular(singular) # optional - sage.libs.singular Block term order with blocks: (Matrix term order with matrix [1 2] @@ -2170,7 +2170,7 @@ def termorder_from_singular(S): This information is reflected in ``_singular_ringorder_column`` attribute of the term order. :: - sage: singular.ring(0, '(x,y,z,w)', '(C,dp(2),lp(2))') + sage: singular.ring(0, '(x,y,z,w)', '(C,dp(2),lp(2))') # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2179,15 +2179,15 @@ def termorder_from_singular(S): // : names x y // block 3 : ordering lp // : names z w - sage: T = termorder_from_singular(singular) - sage: T + sage: T = termorder_from_singular(singular) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Lexicographic term order of length 2) - sage: T._singular_ringorder_column + sage: T._singular_ringorder_column # optional - sage.libs.singular 0 - sage: singular.ring(0, '(x,y,z,w)', '(c,dp(2),lp(2))') + sage: singular.ring(0, '(x,y,z,w)', '(c,dp(2),lp(2))') # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2196,12 +2196,12 @@ def termorder_from_singular(S): // : names x y // block 3 : ordering lp // : names z w - sage: T = termorder_from_singular(singular) - sage: T + sage: T = termorder_from_singular(singular) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Lexicographic term order of length 2) - sage: T._singular_ringorder_column + sage: T._singular_ringorder_column # optional - sage.libs.singular 1 TESTS: @@ -2209,16 +2209,16 @@ def termorder_from_singular(S): Check that ``degneglex`` term orders are converted correctly (:trac:`29635`):: - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:4),ls(4))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:4),ls(4))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:4),ls(4))' - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),a(1:2),ls(2))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),a(1:2),ls(2))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:2),ls(2),a(1:2),ls(2))' - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),C,a(1:2),ls(2))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),C,a(1:2),ls(2))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:2),ls(2),C,a(1:2),ls(2))' - sage: PolynomialRing(QQ, 'x,y', order='degneglex')('x^2')._singular_().sage() + sage: PolynomialRing(QQ, 'x,y', order='degneglex')('x^2')._singular_().sage() # optional - sage.libs.singular x^2 """ from sage.rings.integer_ring import ZZ diff --git a/src/sage/rings/polynomial/toy_buchberger.py b/src/sage/rings/polynomial/toy_buchberger.py index a3de7c4bfd3..f71b9423e36 100644 --- a/src/sage/rings/polynomial/toy_buchberger.py +++ b/src/sage/rings/polynomial/toy_buchberger.py @@ -24,39 +24,39 @@ Consider Katsura-6 with respect to a ``degrevlex`` ordering. :: sage: from sage.rings.polynomial.toy_buchberger import * - sage: P. = PolynomialRing(GF(32003)) - sage: I = sage.rings.ideal.Katsura(P, 6) + sage: P. = PolynomialRing(GF(32003)) # optional - sage.libs.pari + sage: I = sage.rings.ideal.Katsura(P, 6) # optional - sage.libs.pari - sage: g1 = buchberger(I) - sage: g2 = buchberger_improved(I) - sage: g3 = I.groebner_basis() + 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 All algorithms actually compute a Groebner basis:: - sage: Ideal(g1).basis_is_groebner() + sage: Ideal(g1).basis_is_groebner() # optional - sage.libs.pari True - sage: Ideal(g2).basis_is_groebner() + sage: Ideal(g2).basis_is_groebner() # optional - sage.libs.pari True - sage: Ideal(g3).basis_is_groebner() + sage: Ideal(g3).basis_is_groebner() # optional - sage.libs.pari True The results are correct:: - sage: Ideal(g1) == Ideal(g2) == Ideal(g3) + sage: Ideal(g1) == Ideal(g2) == Ideal(g3) # optional - sage.libs.pari True If ``get_verbose()`` is `\ge 1`, a protocol is provided:: sage: from sage.misc.verbose import set_verbose sage: set_verbose(1) - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127)) # optional - sage.libs.pari + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.libs.pari // sage... ideal - sage: I + 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: buchberger(I) # random + sage: buchberger(I) # random # optional - sage.libs.pari (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,14 +117,14 @@ The original Buchberger algorithm performs 15 useless reductions to zero for this example:: - sage: gb = buchberger(I) + sage: gb = buchberger(I) # optional - sage.libs.pari ... 15 reductions to zero. The 'improved' Buchberger algorithm in contrast only performs 1 reduction to zero:: - sage: gb = buchberger_improved(I) + sage: gb = buchberger_improved(I) # optional - sage.libs.pari ... 1 reductions to zero. sage: sorted(gb) # optional - sage.libs.pari diff --git a/src/sage/rings/polynomial/toy_variety.py b/src/sage/rings/polynomial/toy_variety.py index 1d5e581bb89..ea80c4d64d3 100644 --- a/src/sage/rings/polynomial/toy_variety.py +++ b/src/sage/rings/polynomial/toy_variety.py @@ -100,7 +100,7 @@ def coefficient_matrix(polys): sage: from sage.rings.polynomial.toy_variety import coefficient_matrix sage: R. = PolynomialRing(QQ) - sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1]) + sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1]) # optional - sage.modules [1 0 0 1] [0 0 1 1] [0 1 0 1] @@ -159,12 +159,12 @@ def is_linearly_dependent(polys) -> bool: sage: R. = PolynomialRing(QQ) sage: B = [x^2 + 1, y^2 + 1, x*y + 1] sage: p = 3*B[0] - 2*B[1] + B[2] - sage: is_linearly_dependent(B + [p]) + sage: is_linearly_dependent(B + [p]) # optional - sage.modules True - sage: p = x*B[0] - sage: is_linearly_dependent(B + [p]) + sage: p = x*B[0] # optional - sage.modules + sage: is_linearly_dependent(B + [p]) # optional - sage.modules False - sage: is_linearly_dependent([]) + sage: is_linearly_dependent([]) # optional - sage.modules False """ if not polys: diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 9a789d7baeb..31d3a2ef9e9 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -105,9 +105,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = 3 - t^3 + O(t^5) - sage: f.polynomial() + sage: R. = GF(7)[[]] # optional - sage.libs.pari + sage: f = 3 - t^3 + O(t^5) # optional - sage.libs.pari + sage: f.polynomial() # optional - sage.libs.pari 6*t^3 + 3 """ return self.__f @@ -159,12 +159,12 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] - sage: bool(1 + t + O(t^18)) + sage: R. = GF(11)[[]] # optional - sage.libs.pari + sage: bool(1 + t + O(t^18)) # optional - sage.libs.pari True - sage: bool(R(0)) + sage: bool(R(0)) # optional - sage.libs.pari False - sage: bool(O(t^18)) + sage: bool(O(t^18)) # optional - sage.libs.pari False """ return not not self.__f @@ -225,17 +225,17 @@ cdef class PowerSeries_poly(PowerSeries): A series defined over another ring can be substituted:: - sage: S. = GF(7)[[]] - sage: f(2*u + u^3 + O(u^5)) + sage: S. = GF(7)[[]] # optional - sage.libs.pari + sage: f(2*u + u^3 + O(u^5)) # optional - sage.libs.pari 4*u^2 + u^3 + 4*u^4 + 5*u^5 + O(u^6) As can a p-adic integer as long as the coefficient ring is compatible:: - sage: f(100 + O(5^7)) + sage: f(100 + O(5^7)) # optional - sage.rings.padics 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: f.change_ring(Zp(5))(100 + O(5^7)) + sage: f.change_ring(Zp(5))(100 + O(5^7)) # optional - sage.rings.padics 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: f.change_ring(Zp(5))(100 + O(2^7)) + sage: f.change_ring(Zp(5))(100 + O(2^7)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: Cannot substitute this value @@ -248,7 +248,7 @@ cdef class PowerSeries_poly(PowerSeries): Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation - sage: f(2 + O(5^3)) + sage: f(2 + O(5^3)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation @@ -268,18 +268,18 @@ cdef class PowerSeries_poly(PowerSeries): Arguments beyond the first can refer to the base ring:: - sage: P. = GF(5)[] - sage: Q. = P[[]] - sage: h = (1 - x*y)^-1 + O(y^7); h + sage: P. = GF(5)[] # optional - sage.libs.pari + sage: Q. = P[[]] # optional - sage.libs.pari + sage: h = (1 - x*y)^-1 + O(y^7); h # optional - sage.libs.pari 1 + x*y + x^2*y^2 + x^3*y^3 + x^4*y^4 + x^5*y^5 + x^6*y^6 + O(y^7) - sage: h(y^2, 3) + sage: h(y^2, 3) # optional - sage.libs.pari 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) These secondary values can also be specified using keywords:: - sage: h(y=y^2, x=3) + sage: h(y=y^2, x=3) # optional - sage.libs.pari 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) - sage: h(y^2, x=3) + sage: h(y^2, x=3) # optional - sage.libs.pari 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) """ P = self.parent() @@ -375,27 +375,27 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = 3 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(0, 5) - sage: f + sage: R. = GF(7)[[]] # optional - sage.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 5 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(2, 1) ; f + sage: f._unsafe_mutate(2, 1) ; f # optional - sage.libs.pari 5 + t^2 + 6*t^3 + O(t^5) - Mutating can even bump up the precision:: - sage: f._unsafe_mutate(6, 1) ; f + sage: f._unsafe_mutate(6, 1) ; f # optional - sage.libs.pari 5 + t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(0, 0) ; f + sage: f._unsafe_mutate(0, 0) ; f # optional - sage.libs.pari t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(1, 0) ; f + sage: f._unsafe_mutate(1, 0) ; f # optional - sage.libs.pari t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(11,0) ; f + sage: f._unsafe_mutate(11,0) ; f # optional - sage.libs.pari t^2 + 6*t^3 + t^6 + O(t^12) - sage: g = t + O(t^7) - sage: g._unsafe_mutate(1,0) ; g + sage: g = t + O(t^7) # optional - sage.libs.pari + sage: g._unsafe_mutate(1,0) ; g # optional - sage.libs.pari O(t^7) """ self.__f._unsafe_mutate(i, value) @@ -554,9 +554,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = t + 3*t^4 + O(t^11) - sage: f * GF(7)(3) + sage: R. = GF(7)[[]] # optional - sage.libs.pari + sage: f = t + 3*t^4 + O(t^11) # optional - sage.libs.pari + sage: f * GF(7)(3) # optional - sage.libs.pari 3*t + 2*t^4 + O(t^11) """ return PowerSeries_poly(self._parent, self.__f * c, self._prec, check=False) @@ -567,9 +567,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] - sage: f = 1 + 3*t^4 + O(t^120) - sage: 2 * f + sage: R. = GF(11)[[]] # optional - sage.libs.pari + sage: f = 1 + 3*t^4 + O(t^120) # optional - sage.libs.pari + sage: 2 * f # optional - sage.libs.pari 2 + 6*t^4 + O(t^120) """ return PowerSeries_poly(self._parent, c * self.__f, self._prec, check=False) @@ -597,11 +597,11 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = t + t^4 + O(t^7) - sage: f >> 1 + sage: R. = GF(2)[[]] # optional - sage.libs.pari + sage: f = t + t^4 + O(t^7) # optional - sage.libs.pari + sage: f >> 1 # optional - sage.libs.pari 1 + t^3 + O(t^6) - sage: f >> 10 + sage: f >> 10 # optional - sage.libs.pari O(t^0) """ if n: @@ -733,10 +733,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.libs.pari + sage: f = 1/(1+I+O(I^8)); f # optional - sage.libs.pari 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) + sage: f.truncate(5) # optional - sage.libs.pari I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -764,10 +764,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.libs.pari + sage: f = 1/(1+I+O(I^8)); f # optional - sage.libs.pari 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate_powerseries(5) + sage: f.truncate_powerseries(5) # optional - sage.libs.pari 1 + I + I^2 + I^3 + I^4 + O(I^5) """ return PowerSeries_poly(self._parent, self.__f.truncate(prec), @@ -845,8 +845,8 @@ cdef class PowerSeries_poly(PowerSeries): TESTS:: sage: R. = PowerSeriesRing(QQ, sparse=True) - sage: x = var('x') - sage: t.derivative(x) + sage: x = var('x') # optional - sage.symbolic + sage: t.derivative(x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to x @@ -1195,19 +1195,19 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: sage: R. = PowerSeriesRing(QQ) - sage: s = R([1,2,3,4,5],prec=10); s + sage: s = R([1,2,3,4,5], prec=10); s 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^10) - sage: SR(s) + sage: SR(s) # optional - sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + Order(x^10) - sage: SR(s).is_terminating_series() + sage: SR(s).is_terminating_series() # optional - sage.symbolic False - sage: SR(s).variables() + sage: SR(s).variables() # optional - sage.symbolic (x,) sage: s = R([1,2,3,4,5]); s 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: SR(s) + sage: SR(s) # optional - sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: _.is_terminating_series() + sage: _.is_terminating_series() # optional - sage.symbolic True TESTS: @@ -1215,7 +1215,7 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`18094` is fixed:: sage: R. = PolynomialRing(ZZ) - sage: SR(R(0).add_bigoh(20)) + sage: SR(R(0).add_bigoh(20)) # optional - sage.symbolic Order(x^20) """ from sage.symbolic.ring import SR diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index ac74082401b..67dc04dcf97 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -264,7 +264,7 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, Power series ring with many variables:: - sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R + sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R # optional - sage.libs.pari Multivariate Power Series Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring @@ -274,12 +274,12 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, :: - sage: R.inject_variables() + sage: R.inject_variables() # optional - sage.libs.pari Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 - sage: f = x47 + 3*x11*x29 - x19 + R.O(3) - sage: f in R + sage: f = x47 + 3*x11*x29 - x19 + R.O(3) # optional - sage.libs.pari + sage: f in R # optional - sage.libs.pari True diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 52588ce2a8d..b9e46323289 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -133,15 +133,15 @@ def is_PowerSeries(x): sage: R. = PowerSeriesRing(ZZ) sage: from sage.rings.power_series_ring_element import is_PowerSeries - sage: is_PowerSeries(1+x^2) + sage: is_PowerSeries(1 + x^2) True - sage: is_PowerSeries(x-x) + sage: is_PowerSeries(x - x) True sage: is_PowerSeries(0) False - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: is_PowerSeries(1+x^2) + sage: is_PowerSeries(1 + x^2) # optional - sage.symbolic False """ return isinstance(x, PowerSeries) @@ -1275,9 +1275,9 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = SR[[]] - sage: f = (1+I)*x^2 + 3*x - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = SR[[]] # optional - sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic I + 3*x + (-I + 1)*x^2 sage: R. = ZZ[[]] sage: f = x^2 + 2 @@ -1351,7 +1351,7 @@ cdef class PowerSeries(AlgebraElement): Another example:: - sage: (log(1+t)/t).jacobi_continued_fraction() + sage: (log(1+t)/t).jacobi_continued_fraction() # optional - sage.symbolic ((1/2, -1/12), (1/2, -1/15), (1/2, -9/140), @@ -1410,8 +1410,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: t = PowerSeriesRing(QQ, 't').gen() - sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) - sage: s.stieltjes_continued_fraction() + sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) # optional - sage.combinat + sage: s.stieltjes_continued_fraction() # optional - sage.combinat (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) Another example:: @@ -1848,14 +1848,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cos(f) + sage: cos(f) # optional - sage.symbolic 1 - 1/2*t^2 - t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cos(f) + sage: cos(f) # optional - sage.symbolic 1 - 1/2*a^2 - a*b - 1/2*b^2 + O(a, b)^3 sage: f.cos() 1 - 1/2*a^2 - a*b - 1/2*b^2 + O(a, b)^3 @@ -1875,16 +1875,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cos(a) + sage: cos(a) # optional - sage.symbolic 1 - 1/2*a^2 + 1/24*a^4 - 1/720*a^6 + 1/40320*a^8 - 1/3628800*a^10 + O(a, b)^12 sage: a.cos(prec=5) 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cos(a + T.O(5)) + sage: cos(a + T.O(5)) # optional - sage.symbolic 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cos(a^2 + T.O(5)) + sage: cos(a^2 + T.O(5)) # optional - sage.symbolic 1 - 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1933,14 +1933,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sin(f) + sage: sin(f) # optional - sage.symbolic t + t^2 - 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) + sage: sin(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.sin() a + b + a*b + O(a, b)^3 @@ -1960,16 +1960,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sin(a) + sage: sin(a) # optional - sage.symbolic a - 1/6*a^3 + 1/120*a^5 - 1/5040*a^7 + 1/362880*a^9 - 1/39916800*a^11 + O(a, b)^12 sage: a.sin(prec=5) a - 1/6*a^3 + O(a, b)^5 - sage: sin(a + T.O(5)) + sage: sin(a + T.O(5)) # optional - sage.symbolic a - 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sin(a^2 + T.O(5)) + sage: sin(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ R = self.parent() @@ -2019,14 +2019,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tan(f) + sage: tan(f) # optional - sage.symbolic t + t^2 + 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tan(f) + sage: tan(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.tan() a + b + a*b + O(a, b)^3 @@ -2036,8 +2036,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: tan(g) + sage: g = 2 + f + sage: tan(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply tan to formal power series with zero constant term @@ -2046,16 +2046,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tan(a) + sage: tan(a) # optional - sage.symbolic a + 1/3*a^3 + 2/15*a^5 + 17/315*a^7 + 62/2835*a^9 + 1382/155925*a^11 + O(a, b)^12 sage: a.tan(prec=5) a + 1/3*a^3 + O(a, b)^5 - sage: tan(a + T.O(5)) + sage: tan(a + T.O(5)) # optional - sage.symbolic a + 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tan(a^2 + T.O(5)) + sage: tan(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ if not self[0].is_zero(): @@ -2083,14 +2083,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sinh(f) + sage: sinh(f) # optional - sage.symbolic t + t^2 + 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) + sage: sinh(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.sinh() a + b + a*b + O(a, b)^3 @@ -2100,8 +2100,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: sinh(g) + sage: g = 2 + f + sage: sinh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply sinh to formal power series with zero @@ -2111,17 +2111,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sinh(a) + sage: sinh(a) # optional - sage.symbolic a + 1/6*a^3 + 1/120*a^5 + 1/5040*a^7 + 1/362880*a^9 + 1/39916800*a^11 + O(a, b)^12 sage: a.sinh(prec=5) a + 1/6*a^3 + O(a, b)^5 - sage: sinh(a + T.O(5)) + sage: sinh(a + T.O(5)) # optional - sage.symbolic a + 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sinh(a^2 + T.O(5)) + sage: sinh(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ @@ -2172,14 +2172,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cosh(f) + sage: cosh(f) # optional - sage.symbolic 1 + 1/2*t^2 + t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cosh(f) + sage: cosh(f) # optional - sage.symbolic 1 + 1/2*a^2 + a*b + 1/2*b^2 + O(a, b)^3 sage: f.cosh() 1 + 1/2*a^2 + a*b + 1/2*b^2 + O(a, b)^3 @@ -2189,8 +2189,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: cosh(g) + sage: g = 2 + f + sage: cosh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply cosh to formal power series with zero @@ -2200,17 +2200,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cosh(a) + sage: cosh(a) # optional - sage.symbolic 1 + 1/2*a^2 + 1/24*a^4 + 1/720*a^6 + 1/40320*a^8 + 1/3628800*a^10 + O(a, b)^12 sage: a.cosh(prec=5) 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cosh(a + T.O(5)) + sage: cosh(a + T.O(5)) # optional - sage.symbolic 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cosh(a^2 + T.O(5)) + sage: cosh(a^2 + T.O(5)) # optional - sage.symbolic 1 + 1/2*a^4 + O(a, b)^5 """ @@ -2260,14 +2260,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tanh(f) + sage: tanh(f) # optional - sage.symbolic t + t^2 - 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tanh(f) + sage: tanh(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.tanh() a + b + a*b + O(a, b)^3 @@ -2277,8 +2277,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: tanh(g) + sage: g = 2 + f + sage: tanh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply tanh to formal power series with zero @@ -2288,17 +2288,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tanh(a) + sage: tanh(a) # optional - sage.symbolic a - 1/3*a^3 + 2/15*a^5 - 17/315*a^7 + 62/2835*a^9 - 1382/155925*a^11 + O(a, b)^12 sage: a.tanh(prec=5) a - 1/3*a^3 + O(a, b)^5 - sage: tanh(a + T.O(5)) + sage: tanh(a + T.O(5)) # optional - sage.symbolic a - 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tanh(a^2 + T.O(5)) + sage: tanh(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ @@ -2790,7 +2790,7 @@ cdef class PowerSeries(AlgebraElement): There are currently limits to the possible base rings over which this function works. See the documentation for - ``sage.rings.polynomial.polynomial_element.Polynomial.__pari__`` + :meth:`~sage.rings.polynomial.polynomial_element.Polynomial.__pari__` EXAMPLES:: diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 8c50896dfc4..0f5c994a0a6 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -178,13 +178,14 @@ def QuotientRing(R, I, names=None, **kwds): ring can be specified as shown below):: sage: P. = QQ[] - sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) - sage: R - Univariate Quotient Polynomial Ring in xx over Rational Field with modulus x^2 + 1 - sage: R.gens(); R.gen() + sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) # optional - sage.libs.pari + sage: R # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xx over Rational Field + with modulus x^2 + 1 + sage: R.gens(); R.gen() # optional - sage.libs.pari (xx,) xx - sage: for n in range(4): xx^n + sage: for n in range(4): xx^n # optional - sage.libs.pari 1 xx -1 @@ -193,13 +194,13 @@ def QuotientRing(R, I, names=None, **kwds): :: sage: P. = QQ[] - sage: S = QuotientRing(P, P.ideal(x^2 - 2)) - sage: S + sage: S = QuotientRing(P, P.ideal(x^2 - 2)) # optional - sage.libs.pari + sage: S # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 2 - sage: xbar = S.gen(); S.gen() + sage: xbar = S.gen(); S.gen() # optional - sage.libs.pari xbar - sage: for n in range(3): xbar^n + sage: for n in range(3): xbar^n # optional - sage.libs.pari 1 xbar 2 @@ -207,7 +208,7 @@ def QuotientRing(R, I, names=None, **kwds): Sage coerces objects into ideals when possible:: sage: P. = QQ[] - sage: R = QuotientRing(P, x^2 + 1); R + 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 @@ -217,15 +218,15 @@ def QuotientRing(R, I, names=None, **kwds): `\QQ[x,y]`:: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T + sage: S. = QuotientRing(R,R.ideal(1 + y^2)) # optional - sage.libs.pari + sage: T. = QuotientRing(S,S.ideal(a)) # optional - sage.libs.pari + sage: T # optional - sage.libs.pari Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() + sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.pari (x, y) (a, b) (0, d) - sage: for n in range(4): d^n + sage: for n in range(4): d^n # optional - sage.libs.pari 1 d -1 @@ -244,20 +245,23 @@ def QuotientRing(R, I, names=None, **kwds): Here is an example of the quotient of a free algebra by a twosided homogeneous ideal (see :trac:`7797`):: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c - sage: J = Q*[a^3-b^3]*Q - sage: R. = Q.quo(J); R - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal + (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) + sage: i^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 + sage: j^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k Check that :trac:`5978` is fixed by if we quotient by the zero ideal `(0)` @@ -407,10 +411,10 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2 + y^2) - sage: a^2 + b^2 == 0 + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: a^2 + b^2 == 0 # optional - sage.libs.singular True - sage: S(0) == a^2 + b^2 + sage: S(0) == a^2 + b^2 # optional - sage.libs.singular True Again, a quotient of a quotient is just the quotient of the original top @@ -418,12 +422,12 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: - sage: R. = PolynomialRing(QQ,2) - sage: S. = R.quo(1 + y^2) - sage: T. = S.quo(a) - sage: T + 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() + sage: T.gens() # optional - sage.libs.singular (0, d) """ Element = quotient_ring_element.QuotientRingElement @@ -506,8 +510,8 @@ def construction(self): sage: F, R = Integers(5).construction() sage: F(R) Ring of integers modulo 5 - sage: F, R = GF(5).construction() - sage: F(R) + sage: F, R = GF(5).construction() # optional - sage.libs.pari + sage: F(R) # optional - sage.libs.pari Finite Field of size 5 """ from sage.categories.pushout import QuotientFunctor @@ -634,18 +638,18 @@ def cover(self): sage: R. = PolynomialRing(QQ) sage: Q = R.quo( (x^2,y^2) ) - sage: pi = Q.cover() - sage: pi(x^3+y) + sage: pi = Q.cover() # optional - sage.libs.singular + sage: pi(x^3 + y) # optional - sage.libs.singular ybar - sage: l = pi.lift(x+y^3) - sage: l + sage: l = pi.lift(x + y^3) # optional - sage.libs.singular + sage: l # optional - sage.libs.singular x - sage: l = pi.lift(); l + sage: l = pi.lift(); l # optional - sage.libs.singular Set-theoretic ring morphism: From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: l(x+y^3) + sage: l(x + y^3) # optional - sage.libs.singular x """ try: @@ -667,38 +671,38 @@ def lifting_map(self): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: pi = S.cover(); pi + sage: pi = S.cover(); pi # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) Defn: Natural quotient map - sage: L = S.lifting_map(); L + sage: L = S.lifting_map(); L # optional - sage.libs.singular Set-theoretic ring morphism: From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: L(S.0) + sage: L(S.0) # optional - sage.libs.singular x - sage: L(S.1) + sage: L(S.1) # optional - sage.libs.singular y Note that some reduction may be applied so that the lift of a reduction need not equal the original element:: - sage: z = pi(x^3 + 2*y^2); z + sage: z = pi(x^3 + 2*y^2); z # optional - sage.libs.singular -xbar*ybar^2 + 2*ybar^2 - sage: L(z) + sage: L(z) # optional - sage.libs.singular -x*y^2 + 2*y^2 - sage: L(z) == x^3 + 2*y^2 + sage: L(z) == x^3 + 2*y^2 # optional - sage.libs.singular False Test that there also is a lift for rings that are no instances of :class:`~sage.rings.ring.Ring` (see :trac:`11068`):: - sage: MS = MatrixSpace(GF(5),2,2) - sage: I = MS*[MS.0*MS.1,MS.2+MS.3]*MS - sage: Q = MS.quo(I) - sage: Q.lift() + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.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 Set-theoretic ring morphism: From: Quotient of Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 5 by the ideal ( @@ -739,12 +743,12 @@ def lift(self,x=None): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.lift() + sage: S.lift() # optional - sage.libs.singular Set-theoretic ring morphism: From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift(S.0) == x + sage: S.lift(S.0) == x # optional - sage.libs.singular True """ @@ -768,7 +772,7 @@ def retract(self,x): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.retract((x+y)^2) + sage: S.retract((x+y)^2) # optional - sage.libs.singular 2*xbar*ybar """ @@ -808,12 +812,12 @@ def defining_ideal(self): homomorphism theorems, this is actually a quotient by a sum of two ideals:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: S.defining_ideal() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: S.defining_ideal() # optional - sage.libs.singular Ideal (y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: T.defining_ideal() + sage: T.defining_ideal() # optional - sage.libs.singular Ideal (x, y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field """ return self.__I @@ -827,14 +831,14 @@ def is_field(self, proof = True): TESTS:: sage: Q = QuotientRing(ZZ,7*ZZ) - sage: Q.is_field() + sage: Q.is_field() # optional - sage.libs.pari True Requires the ``is_maximal`` method of the defining ideal to be implemented:: sage: R. = ZZ[] - sage: R.quotient_ring(R.ideal([2, 4 +x])).is_field() + sage: R.quotient_ring(R.ideal([2, 4 + x])).is_field() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError @@ -861,19 +865,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = QQ[] - sage: R.quo(x^2 - y).is_integral_domain() + sage: R.quo(x^2 - y).is_integral_domain() # optional - sage.singular True - sage: R.quo(x^2 - y^2).is_integral_domain() + sage: R.quo(x^2 - y^2).is_integral_domain() # optional - sage.singular False - sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) + sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # optional - sage.singular False - sage: R. = ZZ[] - sage: Q = R.quotient_ring([a, b]) - sage: Q.is_integral_domain() + sage: R. = ZZ[] # optional - sage.singular + sage: Q = R.quotient_ring([a, b]) # optional - sage.singular + sage: Q.is_integral_domain() # optional - sage.singular Traceback (most recent call last): ... NotImplementedError - sage: Q.is_integral_domain(proof=False) + sage: Q.is_integral_domain(proof=False) # optional - sage.singular False """ if proof: @@ -950,11 +954,13 @@ def ideal(self, *gens, **kwds): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S.ideal() - Ideal (0) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: S.ideal(x+y+1) - Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + sage: S = R.quotient_ring(x^2 + y^2) + sage: S.ideal() # optional - sage.libs.pari + Ideal (0) of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) + sage: S.ideal(x + y + 1) # optional - sage.libs.pari + Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) TESTS: @@ -990,10 +996,10 @@ def _element_constructor_(self, x, coerce=True): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S(x) # indirect doctest + sage: S = R.quotient_ring(x^2 + y^2) + sage: S(x) # indirect doctest # optional - sage.libs.singular xbar - sage: S(x^2 + y^2) + sage: S(x^2 + y^2) # optional - sage.libs.singular 0 The rings that coerce into the quotient ring canonically, are: @@ -1006,21 +1012,21 @@ def _element_constructor_(self, x, coerce=True): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: S.coerce(0) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: S.coerce(0) # optional - sage.libs.singular 0 - sage: S.coerce(2/3) + sage: S.coerce(2/3) # optional - sage.libs.singular 2/3 - sage: S.coerce(a^2 - b) + sage: S.coerce(a^2 - b) # optional - sage.libs.singular -b^2 - b - sage: S.coerce(GF(7)(3)) + sage: S.coerce(GF(7)(3)) # optional - sage.libs.pari 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) TESTS:: - sage: S(x, coerce=False) + sage: S(x, coerce=False) # optional - sage.libs.singular a """ if isinstance(x, quotient_ring_element.QuotientRingElement): @@ -1043,15 +1049,15 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) + sage: S = R.quotient_ring(x^2 + y^2) sage: S.has_coerce_map_from(R) # indirect doctest True sage: S.has_coerce_map_from(QQ) True - sage: T = S.quotient_ring(x^3 - y) - sage: S.has_coerce_map_from(T) + sage: T = S.quotient_ring(x^3 - y) # optional - sage.libs.singular + sage: S.has_coerce_map_from(T) # optional - sage.libs.singular False - sage: T.has_coerce_map_from(R) + sage: T.has_coerce_map_from(R) # optional - sage.libs.singular True TESTS: @@ -1059,33 +1065,33 @@ def _coerce_map_from_(self, R): We check that :trac:`13682` is fixed:: sage: R. = PolynomialRing(QQ) - sage: I = R.ideal(x^2+y^2) - sage: J = R.ideal(x^2+y^2, x^3 - y) - sage: I < J + sage: I = R.ideal(x^2 + y^2) + sage: J = R.ideal(x^2 + y^2, x^3 - y) + sage: I < J # optional - sage.libs.singular True - sage: S = R.quotient(I) - sage: T = R.quotient(J) - sage: T.has_coerce_map_from(S) + sage: S = R.quotient(I) # optional - sage.libs.singular + sage: T = R.quotient(J) # optional - sage.libs.singular + sage: T.has_coerce_map_from(S) # optional - sage.libs.singular True - sage: S.quotient_ring(x^4-x*y+1).has_coerce_map_from(S) + sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) # optional - sage.libs.singular True - sage: S.has_coerce_map_from(T) + sage: S.has_coerce_map_from(T) # optional - sage.libs.singular False We also allow coercions with the cover rings:: sage: Rp. = PolynomialRing(ZZ) - sage: Ip = Rp.ideal(x^2+y^2) - sage: Jp = Rp.ideal(x^2+y^2, x^3 - y) - sage: Sp = Rp.quotient(Ip) - sage: Tp = Rp.quotient(Jp) - sage: R.has_coerce_map_from(Rp) + sage: Ip = Rp.ideal(x^2 + y^2) + sage: Jp = Rp.ideal(x^2 + y^2, x^3 - y) + sage: Sp = Rp.quotient(Ip) # optional - sage.libs.singular + sage: Tp = Rp.quotient(Jp) # optional - sage.libs.singular + sage: R.has_coerce_map_from(Rp) # optional - sage.libs.singular True - sage: Sp.has_coerce_map_from(Sp) + sage: Sp.has_coerce_map_from(Sp) # optional - sage.libs.singular True - sage: T.has_coerce_map_from(Sp) + sage: T.has_coerce_map_from(Sp) # optional - sage.libs.singular True - sage: Sp.has_coerce_map_from(T) + sage: Sp.has_coerce_map_from(T) # optional - sage.libs.singular False """ C = self.cover_ring() @@ -1117,9 +1123,9 @@ def __richcmp__(self, other, op): equal, but since the generators are different, the corresponding quotient rings are not equal:: - sage: R.ideal(x^2+y^2) == R.ideal(-x^2 - y^2) + sage: R.ideal(x^2 + y^2) == R.ideal(-x^2 - y^2) # optional - sage.libs.singular True - sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) + sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) # optional - sage.libs.singular False """ if not isinstance(other, QuotientRing_nc): @@ -1141,7 +1147,7 @@ def ngens(self): EXAMPLES:: - sage: R = QuotientRing(ZZ,7*ZZ) + sage: R = QuotientRing(ZZ, 7*ZZ) sage: R.gens(); R.ngens() (1,) 1 @@ -1149,15 +1155,16 @@ def ngens(self): :: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.singular (x, y) (a, b) (0, d) - sage: R.ngens(); S.ngens(); T.ngens() + sage: R.ngens(); S.ngens(); T.ngens() # optional - sage.libs.singular 2 2 2 @@ -1170,24 +1177,25 @@ def gen(self, i=0): EXAMPLES:: - sage: R = QuotientRing(ZZ,7*ZZ) + sage: R = QuotientRing(ZZ, 7*ZZ) sage: R.gen(0) 1 :: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gen(0); R.gen(1) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gen(0); R.gen(1) # optional - sage.libs.singular x y - sage: S.gen(0); S.gen(1) + sage: S.gen(0); S.gen(1) # optional - sage.libs.singular a b - sage: T.gen(0); T.gen(1) + sage: T.gen(0); T.gen(1) # optional - sage.libs.singular 0 d """ @@ -1213,8 +1221,8 @@ def _singular_(self, singular=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S._singular_() + sage: S = R.quotient_ring(x^2 + y^2) + sage: S._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 @@ -1247,11 +1255,11 @@ def _singular_init_(self, singular=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: T = S._singular_init_() - sage: parent(S) + sage: S = R.quotient_ring(x^2 + y^2) + sage: T = S._singular_init_() # optional - sage.libs.singular + sage: parent(S) # optional - sage.libs.singular - sage: parent(T) + sage: parent(T) # optional - sage.libs.singular Singular """ if singular is None: @@ -1271,9 +1279,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: magma(Q) # optional - magma # indirect doctest + sage: P. = PolynomialRing(GF(2)) # optional - sage.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 Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y @@ -1365,11 +1373,12 @@ def _macaulay2_init_(self, macaulay2=None): 2 2 2 (x*y - z , y - w ) - sage: R. = PolynomialRing(GF(101), 2) - sage: I = R.ideal([x^2 + x, y^2 + y]) - sage: Q = R.quotient_ring(I); Q - Quotient of Multivariate Polynomial Ring in x, y over Finite Field of size 101 by the ideal (x^2 + x, y^2 + y) - sage: Q._macaulay2_init_() # optional - macaulay2 + sage: R. = PolynomialRing(GF(101), 2) # optional - sage.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 + 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 ZZ ---[x...y] 101 diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index e2f190a4b1c..73b50171801 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -45,7 +45,8 @@ class QuotientRingElement(RingElement): sage: R. = PolynomialRing(ZZ) sage: S. = R.quo((4 + 3*x + x^2, 1 + x^2)); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) sage: v = S.gens(); v (xbar,) @@ -58,24 +59,25 @@ class QuotientRingElement(RingElement): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quo(x^2 + y^2); S - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: S.gens() + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) + sage: S.gens() # optional - sage.libs.singular (xbar, ybar) We name each of the generators. :: - sage: S. = R.quotient(x^2 + y^2) - sage: a + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: a # optional - sage.libs.singular a - sage: b + sage: b # optional - sage.libs.singular b - sage: a^2 + b^2 == 0 + sage: a^2 + b^2 == 0 # optional - sage.libs.singular True - sage: b.lift() + sage: b.lift() # optional - sage.libs.singular y - sage: (a^3 + b^2).lift() + sage: (a^3 + b^2).lift() # optional - sage.libs.singular -x*y^2 + y^2 """ def __init__(self, parent, rep, reduce=True): @@ -87,7 +89,8 @@ def __init__(self, parent, rep, reduce=True): sage: R. = PolynomialRing(ZZ) sage: S. = R.quo((4 + 3*x + x^2, 1 + x^2)); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) sage: v = S.gens(); v (xbar,) """ @@ -106,10 +109,10 @@ def _reduce_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a._reduce_() - sage: a._QuotientRingElement__rep + sage: a._reduce_() # optional - sage.libs.singular + sage: a._QuotientRingElement__rep # optional - sage.libs.singular x """ I = self.parent().defining_ideal() @@ -122,11 +125,11 @@ def lift(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.lift() + sage: a.lift() # optional - sage.libs.singular x - sage: (3/5*(a + a^2 + b^2)).lift() + sage: (3/5*(a + a^2 + b^2)).lift() # optional - sage.libs.singular 3/5*x """ return self.__rep @@ -139,16 +142,16 @@ def __bool__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: bool(a) # indirect doctest + sage: bool(a) # indirect doctest # optional - sage.libs.singular True - sage: bool(S(0)) + sage: bool(S(0)) # optional - sage.libs.singular False TESTS:: - sage: bool(a - a) + sage: bool(a - a) # optional - sage.libs.singular False """ return self.__rep not in self.parent().defining_ideal() @@ -161,18 +164,18 @@ def is_unit(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) + sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) # optional - sage.libs.singular - sage: a*b + sage: a*b # optional - sage.libs.singular 1 - sage: S(2).is_unit() + sage: S(2).is_unit() # optional - sage.libs.singular True Check that :trac:`29469` is fixed:: - sage: a.is_unit() + sage: a.is_unit() # optional - sage.libs.singular True - sage: (a+b).is_unit() + sage: (a+b).is_unit() # optional - sage.libs.singular False """ if self.__rep.is_unit(): @@ -193,18 +196,18 @@ def _repr_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a-2*a*b # indirect doctest + sage: a-2*a*b # indirect doctest # optional - sage.libs.singular -2*a*b + a In :trac:`11068`, the case of quotient rings without assigned names has been covered as well:: - sage: S = SteenrodAlgebra(2) - sage: I = S*[S.0+S.1]*S - sage: Q = S.quo(I) - sage: Q.0 + sage: S = SteenrodAlgebra(2) # optional - sage.libs.singular + sage: I = S * [S.0 + S.1] * S # optional - sage.libs.singular + sage: Q = S.quo(I) # optional - sage.libs.singular + sage: Q.0 # optional - sage.libs.singular Sq(1) """ @@ -234,8 +237,8 @@ def _latex_(self): sage: a = R.gen(0) sage: I = R.ideal(a**2 + a + 1) sage: S = R.quotient(I, names=R.variable_names()) - sage: a = S.gen(0) - sage: latex(a) + sage: a = S.gen(0) # optional - sage.libs.singular + sage: latex(a) # optional - sage.libs.singular a """ from sage.structure.parent_gens import localvars @@ -259,20 +262,20 @@ def __pari__(self): EXAMPLES:: sage: R. = QQ[] - sage: I = R.ideal(x^3,y^3) - sage: S. = R.quo(I) - sage: pari(xb) + sage: I = R.ideal(x^3, y^3) + sage: S. = R.quo(I) # optional - sage.libs.singular + sage: pari(xb) # optional - sage.libs.pari sage.libs.singular Traceback (most recent call last): ... ValueError: Pari does not support quotients by non-principal ideals Note that the quotient does work in the case that the ideal is principal:: - sage: I = R.ideal(x^3+y^3) - sage: S. = R.quo(I) - sage: pari(xb)^4 + sage: I = R.ideal(x^3 + y^3) + sage: S. = R.quo(I) # optional - sage.libs.singular + sage: pari(xb)^4 # optional - sage.libs.pari sage.libs.singular Mod(-y^3*x, x^3 + y^3) - sage: pari(yb)^4 + sage: pari(yb)^4 # optional - sage.libs.pari sage.libs.singular Mod(y^4, x^3 + y^3) """ gens = self.parent().defining_ideal().gens() @@ -288,14 +291,14 @@ def _add_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a + b + sage: a + b # optional - sage.libs.singular a + b TESTS:: - sage: a._add_(b) + sage: a._add_(b) # optional - sage.libs.singular a + b """ return self.__class__(self.parent(), self.__rep + right.__rep) @@ -308,14 +311,14 @@ def _sub_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a - b + sage: a - b # optional - sage.libs.singular a - b TESTS:: - sage: a._sub_(b) + sage: a._sub_(b) # optional - sage.libs.singular a - b """ return self.__class__(self.parent(), self.__rep - right.__rep) @@ -328,16 +331,16 @@ def _mul_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a * b + sage: a * b # optional - sage.libs.singular a*b TESTS:: - sage: a._mul_(b) + sage: a._mul_(b) # optional - sage.libs.singular a*b - sage: a._mul_(a) + sage: a._mul_(a) # optional - sage.libs.singular -b^2 """ return self.__class__(self.parent(), self.__rep * right.__rep) @@ -352,30 +355,30 @@ def _div_(self, right): sage: R. = QQ[] sage: I = R.ideal([x^2 + 1, y^3 - 2]) - sage: S. = R.quotient(I) - sage: 1/(1+i) + sage: S. = R.quotient(I) # optional - sage.libs.singular + sage: 1/(1+i) # optional - sage.libs.singular -1/2*i + 1/2 Confirm via symbolic computation:: - sage: 1/(1+sqrt(-1)) + sage: 1/(1+sqrt(-1)) # optional - sage.symbolic -1/2*I + 1/2 Another more complicated quotient:: - sage: b = 1/(i+cuberoot); b + sage: b = 1/(i+cuberoot); b # optional - sage.libs.singular 1/5*i*cuberoot^2 - 2/5*i*cuberoot + 2/5*cuberoot^2 - 1/5*i + 1/5*cuberoot - 2/5 - sage: b*(i+cuberoot) + sage: b*(i+cuberoot) # optional - sage.libs.singular 1 Another really easy example:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a / S(2) + sage: a / S(2) # optional - sage.libs.singular 1/2*a - sage: (a*b)._div_(b) + sage: (a*b)._div_(b) # optional - sage.libs.singular a An example in which we try to divide in a ring that is not a @@ -383,18 +386,18 @@ def _div_(self, right): sage: R. = QQ[] sage: I = R.ideal([x^2 - 1, y^3 - 2]) - sage: S. = R.quotient(I) - sage: 1/cuberoot + sage: S. = R.quotient(I) # optional - sage.libs.singular + sage: 1/cuberoot # optional - sage.libs.singular 1/2*cuberoot^2 - sage: 1/a + sage: 1/a # optional - sage.libs.singular a Check that :trac:`13670` is fixed (i.e. that the error message actually describes what happens when the result of division is not defined):: sage: R. = QQ[] - sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) - sage: 1 / S(x1 + x2) + sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) # optional - sage.libs.singular + sage: 1 / S(x1 + x2) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: Division failed. The numerator is not a multiple of the denominator. @@ -406,7 +409,7 @@ def _div_(self, right): sage: R. = QQ[] sage: S. = R[] - sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) + sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: Can only reduce polynomials over fields. @@ -474,15 +477,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None): quotient ring work correctly (see :trac:`16135`):: sage: R. = QQ[] - sage: K = R.quotient(x^2 - y^3).fraction_field() + sage: K = R.quotient(x^2 - y^3).fraction_field() # optional - sage.libs.singular sage: L. = FunctionField(QQ) - sage: f = K.hom((t^3, t^2)) - sage: list(map(f, K.gens())) + sage: f = K.hom((t^3, t^2)) # optional - sage.libs.singular + sage: list(map(f, K.gens())) # optional - sage.libs.singular [t^3, t^2] - sage: xbar, ybar = K.gens() - sage: f(1/ybar) + sage: xbar, ybar = K.gens() # optional - sage.libs.singular + sage: f(1/ybar) # optional - sage.libs.singular 1/t^2 - sage: f(xbar/ybar) + sage: f(xbar/ybar) # optional - sage.libs.singular t """ return self.lift()._im_gens_(codomain, im_gens, base_map=base_map) @@ -495,13 +498,13 @@ def __int__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: int(S(-3)) # indirect doctest + sage: int(S(-3)) # indirect doctest # optional - sage.libs.singular -3 - sage: type(int(S(-3))) + sage: type(int(S(-3))) # optional - sage.libs.singular <... 'int'> - sage: int(a) + sage: int(a) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -512,14 +515,14 @@ def _integer_(self, Z): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: ZZ(S(-3)) + sage: ZZ(S(-3)) # optional - sage.libs.singular -3 TESTS:: - sage: type(ZZ(S(-3))) + sage: type(ZZ(S(-3))) # optional - sage.libs.singular """ return Z(self.lift()) @@ -528,14 +531,14 @@ def _rational_(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: QQ(S(-2/3)) + sage: QQ(S(-2/3)) # optional - sage.libs.singular -2/3 TESTS:: - sage: type(S(-2/3)._rational_()) + sage: type(S(-2/3)._rational_()) # optional - sage.libs.singular """ from sage.rings.rational_field import QQ @@ -545,11 +548,11 @@ def __neg__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: -a # indirect doctest + sage: -a # indirect doctest # optional - sage.libs.singular -a - sage: -(a+b) + sage: -(a+b) # optional - sage.libs.singular -a - b """ return self.__class__(self.parent(), -self.__rep) @@ -558,11 +561,11 @@ def __pos__(self): """ TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+b).__pos__() + sage: (a+b).__pos__() # optional - sage.libs.singular a + b - sage: c = a+b; c.__pos__() is c + sage: c = a+b; c.__pos__() is c # optional - sage.libs.singular True """ return self @@ -571,19 +574,19 @@ def __invert__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: ~S(2/3) + sage: ~S(2/3) # optional - sage.libs.singular 3/2 TESTS:: - sage: S(2/3).__invert__() + sage: S(2/3).__invert__() # optional - sage.libs.singular 3/2 Note that a is not invertible as an element of R:: - sage: a.__invert__() + sage: a.__invert__() # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -598,11 +601,11 @@ def __float__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: float(S(2/3)) + sage: float(S(2/3)) # optional - sage.libs.singular 0.6666666666666666 - sage: float(a) + sage: float(a) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -613,10 +616,10 @@ def __hash__(self): r""" TESTS:: - sage: R. = QQ[] - sage: S. = R.quo(x^2 + y^2) - sage: c = a*a + b - sage: hash(a) != hash(b) + sage: R. = QQ[] # optional - sage.libs.singular + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: c = a*a + b # optional - sage.libs.singular + sage: hash(a) != hash(b) # optional - sage.libs.singular True """ return hash(self.__rep) @@ -625,38 +628,38 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a > b # indirect doctest + sage: a > b # indirect doctest # optional - sage.libs.singular True - sage: b > a + sage: b > a # optional - sage.libs.singular False - sage: a == loads(dumps(a)) + sage: a == loads(dumps(a)) # optional - sage.libs.singular True TESTS:: - sage: a == (a+1-1) + sage: a == (a+1-1) # optional - sage.libs.singular True - sage: a > b + sage: a > b # optional - sage.libs.singular True See :trac:`7797`:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.0^4 # indirect doctest + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular + sage: Q.0^4 # indirect doctest # optional - sage.combinat sage.libs.singular ybar*zbar*zbar*xbar + ybar*zbar*zbar*ybar + ybar*zbar*zbar*zbar The issue from :trac:`8005` was most likely fixed as part of :trac:`9138`:: - sage: F = GF(5) - sage: R.=F[] - sage: I=Ideal(R, [x, y]) - sage: S.=QuotientRing(R,I) - sage: x1^4 + sage: F = GF(5) # optional - sage.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 0 """ # A containment test is not implemented for univariate polynomial @@ -679,18 +682,18 @@ def lt(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lt() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.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 2*xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lt() + sage: (a + 3*a*b + b).lt() # optional - sage.libs.singular 3*a*b """ return self.__class__(self.parent(), self.__rep.lt()) @@ -701,18 +704,18 @@ def lm(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lm() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.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 xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lm() + sage: (a+3*a*b+b).lm() # optional - sage.libs.singular a*b """ @@ -724,18 +727,18 @@ def lc(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lc() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.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 2 TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lc() + sage: (a + 3*a*b + b).lc() # optional - sage.libs.singular 3 """ return self.__rep.lc() @@ -751,17 +754,17 @@ def variables(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.variables() + sage: a.variables() # optional - sage.libs.singular (a,) - sage: b.variables() + sage: b.variables() # optional - sage.libs.singular (b,) - sage: s = a^2 + b^2 + 1; s + sage: s = a^2 + b^2 + 1; s # optional - sage.libs.singular 1 - sage: s.variables() + sage: s.variables() # optional - sage.libs.singular () - sage: (a+b).variables() + sage: (a + b).variables() # optional - sage.libs.singular (a, b) """ return tuple(self.__class__(self.parent(), v) for v in self.__rep.variables()) @@ -776,13 +779,13 @@ def monomials(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.monomials() + sage: a.monomials() # optional - sage.libs.singular [a] - sage: (a+a*b).monomials() + sage: (a + a*b).monomials() # optional - sage.libs.singular [a*b, a] - sage: R.zero().monomials() + sage: R.zero().monomials() # optional - sage.libs.singular [] """ return [self.__class__(self.parent(), m) for m in self.__rep.monomials()] @@ -798,10 +801,10 @@ def _singular_(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(2),2) - sage: I = sage.rings.ideal.FieldIdeal(P) - sage: Q = P.quo(I) - sage: Q._singular_() + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.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 polynomial ring, over a field, global ordering // coefficients: ZZ/2 // number of vars : 2 @@ -811,20 +814,20 @@ def _singular_(self, singular=singular_default): // quotient ring from ideal _[1]=x2+x _[2]=y2+y - sage: xbar = Q(x); xbar + sage: xbar = Q(x); xbar # optional - sage.libs.pari xbar - sage: xbar._singular_() + sage: xbar._singular_() # optional - sage.libs.pari x - sage: Q(xbar._singular_()) # a round-trip + sage: Q(xbar._singular_()) # a round-trip # optional - sage.libs.pari xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a-2/3*b)._singular_() + sage: (a - 2/3*b)._singular_() # optional - sage.libs.singular x-2/3*y - sage: S((a-2/3*b)._singular_()) + sage: S((a - 2/3*b)._singular_()) # optional - sage.libs.singular a - 2/3*b """ if singular is None: @@ -837,12 +840,12 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: xbar, ybar = Q.gens() - sage: magma(xbar) # optional -- magma + sage: P. = PolynomialRing(GF(2)) # optional - sage.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 x - sage: xbar._magma_init_(magma) # optional -- magma + sage: xbar._magma_init_(magma) # optional - magma # optional - sage.libs.pari '_sage_[...]!_sage_ref...' """ g = magma(self.__rep) @@ -855,19 +858,19 @@ def _macaulay2_(self, macaulay2=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y]) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7; f + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.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 2*xbar*ybar^17 + xbar*ybar^10 - sage: mf = macaulay2(f); mf # optional - macaulay2 + sage: mf = macaulay2(f); mf # optional - macaulay2 # optional - sage.libs.pari 17 10 2x*y + x*y - sage: mf.sage() # optional - macaulay2 + sage: mf.sage() # optional - macaulay2 # optional - sage.libs.pari 2*x*y^17 + x*y^10 - sage: mf.sage() == f # optional - macaulay2 + sage: mf.sage() == f # optional - macaulay2 # optional - sage.libs.pari True - sage: Q(mf) # optional - macaulay2 + sage: Q(mf) # optional - macaulay2 # optional - sage.libs.pari 2*xbar*ybar^17 + xbar*ybar^10 In Macaulay2, the variable names for a quotient ring are inherited from @@ -879,15 +882,15 @@ def _macaulay2_(self, macaulay2=None): :: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y], names=R.gens()) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7; f + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.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 2*x*y^17 + x*y^10 - sage: macaulay2(f) # optional - macaulay2 + sage: macaulay2(f) # optional - macaulay2 # optional - sage.libs.pari 17 10 2x*y + x*y - sage: _.sage() # optional - macaulay2 + sage: _.sage() # optional - macaulay2 # optional - sage.libs.pari 2*x*y^17 + x*y^10 TESTS: @@ -895,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) - sage: Q = R.quotient([x^2 - y], names=R.gens()) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7 - sage: macaulay2(f) # optional - macaulay2 + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.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 17 10 2x*y + x*y - sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 - sage: macaulay2(f) # optional - macaulay2 + sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 # optional - sage.libs.pari + sage: macaulay2(f) # optional - macaulay2 # optional - sage.libs.pari 17 10 2x*y + x*y """ @@ -932,17 +935,17 @@ def reduce(self, G): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 5, order='lex') - sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, a*b*e + c*e, b*c + c*d*e + 1]) - sage: Q = P.quotient( sage.rings.ideal.FieldIdeal(P) ) - sage: I2 = ideal([Q(f) for f in I1.gens()]) - sage: f = Q((a*b + c*d + 1)^2 + e) - sage: f.reduce(I2.gens()) + sage: P. = PolynomialRing(GF(2), 5, order='lex') # optional - sage.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 ebar Notice that the result above is not minimal:: - sage: I2.reduce(f) + sage: I2.reduce(f) # optional - sage.libs.pari 0 """ try: diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index d272a913646..3450a235722 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -300,30 +300,31 @@ cpdef rational_power_parts(a, Rational b, factor_limit=10**5): sage: rational_power_parts(3/4, -1/2) (2, 3) - sage: t = (3/4)^(-1/2); t + sage: t = (3/4)^(-1/2); t # optional - sage.symbolic 2/3*sqrt(3) - sage: t^2 + sage: t^2 # optional - sage.symbolic 4/3 Check if :trac:`15605` is fixed:: sage: rational_power_parts(-1, -1/3) (1, -1) - sage: (-1)^(-1/3) + sage: (-1)^(-1/3) # optional - sage.symbolic -(-1)^(2/3) - sage: 1 / ((-1)^(1/3)) + sage: 1 / ((-1)^(1/3)) # optional - sage.symbolic -(-1)^(2/3) sage: rational_power_parts(-1, 2/3) (1, -1) - sage: (-1)^(2/3) + sage: (-1)^(2/3) # optional - sage.symbolic (-1)^(2/3) sage: all(rational_power_parts(-1, i/77) == (1,-1) for i in range(1,9)) True - sage: (-1)^(1/3)*(-1)^(1/5) + sage: (-1)^(1/3)*(-1)^(1/5) # optional - sage.symbolic (-1)^(8/15) - sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) + sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) # optional - sage.symbolic True - sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) for p in srange(1,6) for q in srange(1,6)) + sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) # optional - sage.symbolic + ....: for p in srange(1, 6) for q in srange(1, 6)) True A few more tests added in :trac:`26414`:: @@ -447,17 +448,17 @@ cdef class Rational(sage.structure.element.FieldElement): Conversions from numpy:: - sage: import numpy as np - sage: QQ(np.int8('-15')) + sage: import numpy as np # optional - numpy + sage: QQ(np.int8('-15')) # optional - numpy -15 - sage: QQ(np.int16('-32')) + sage: QQ(np.int16('-32')) # optional - numpy -32 - sage: QQ(np.int32('-19')) + sage: QQ(np.int32('-19')) # optional - numpy -19 - sage: QQ(np.uint32('1412')) + sage: QQ(np.uint32('1412')) # optional - numpy 1412 - sage: QQ(np.float16('12')) + sage: QQ(np.float16('12')) # optional - numpy 12 Conversions from gmpy2:: @@ -963,9 +964,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: ex = SR(QQ(7)/3); ex + sage: ex = SR(QQ(7)/3); ex # optional - sage.symbolic 7/3 - sage: parent(ex) + sage: parent(ex) # optional - sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -976,12 +977,12 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: n = 1/2; n._sympy_() + sage: n = 1/2; n._sympy_() # optional - sympy 1/2 - sage: n = -1/5; n._sympy_() + sage: n = -1/5; n._sympy_() # optional - sympy -1/5 - sage: from sympy import Symbol - sage: QQ(1)+Symbol('x')*QQ(2) + sage: from sympy import Symbol # optional - sympy + sage: QQ(1) + Symbol('x')*QQ(2) # optional - sympy 2*x + 1 """ import sympy @@ -1049,16 +1050,16 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1, 2, 3/1]) + sage: import numpy # optional - numpy + sage: numpy.array([1, 2, 3/1]) # optional - numpy array([1, 2, 3]) - sage: numpy.array(QQ(2**40)).dtype + sage: numpy.array(QQ(2**40)).dtype # optional - numpy dtype('int64') - sage: numpy.array(QQ(2**400)).dtype + sage: numpy.array(QQ(2**400)).dtype # optional - numpy dtype('O') - sage: numpy.array([1, 1/2, 3/4]) + sage: numpy.array([1, 1/2, 3/4]) # optional - numpy array([1. , 0.5 , 0.75]) """ if mpz_cmp_ui(mpq_denref(self.value), 1) == 0: @@ -1902,16 +1903,16 @@ cdef class Rational(sage.structure.element.FieldElement): sage: x.sqrt(all=True) [10, -10] sage: x = 81/5 - sage: x.sqrt() + sage: x.sqrt() # optional - sage.symbolic 9*sqrt(1/5) sage: x = -81/3 - sage: x.sqrt() + sage: x.sqrt() # optional - sage.symbolic 3*sqrt(-3) :: sage: n = 2/3 - sage: n.sqrt() + sage: n.sqrt() # optional - sage.symbolic sqrt(2/3) sage: n.sqrt(prec=10) 0.82 @@ -1925,7 +1926,7 @@ cdef class Rational(sage.structure.element.FieldElement): Traceback (most recent call last): ... ValueError: square root of 2/3 not a rational number - sage: sqrt(-2/3, all=True) + sage: sqrt(-2/3, all=True) # optional - sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] sage: sqrt(-2/3, prec=53) 0.816496580927726*I @@ -2516,9 +2517,9 @@ cdef class Rational(sage.structure.element.FieldElement): sage: (2/3)^5 32/243 - sage: (-1/1)^(1/3) + sage: (-1/1)^(1/3) # optional - sage.symbolic (-1)^(1/3) - sage: (2/3)^(3/4) + sage: (2/3)^(3/4) # optional - sage.symbolic (2/3)^(3/4) sage: (-1/3)^0 1 @@ -2533,18 +2534,18 @@ cdef class Rational(sage.structure.element.FieldElement): 2/3 sage: parent(a) Rational Field - sage: (-27/125)^(1/3) + sage: (-27/125)^(1/3) # optional - sage.symbolic 3/5*(-1)^(1/3) - sage: (-27/125)^(1/2) + sage: (-27/125)^(1/2) # optional - sage.symbolic 3/5*sqrt(-3/5) The result is normalized to have the rational power in the numerator:: - sage: 2^(-1/2) + sage: 2^(-1/2) # optional - sage.symbolic 1/2*sqrt(2) - sage: 8^(-1/5) + sage: 8^(-1/5) # optional - sage.symbolic 1/8*8^(4/5) - sage: 3^(-3/2) + sage: 3^(-3/2) # optional - sage.symbolic 1/9*sqrt(3) TESTS:: @@ -2556,7 +2557,7 @@ cdef class Rational(sage.structure.element.FieldElement): This works even if the base is a Python integer:: - sage: int(2)^(1/2) + sage: int(2)^(1/2) # optional - sage.symbolic sqrt(2) sage: a = int(2)^(3/1); a 8 @@ -3122,15 +3123,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (124/345).log(5) + sage: (124/345).log(5) # optional - sage.symbolic log(124/345)/log(5) - sage: (124/345).log(5,100) + sage: (124/345).log(5, 100) -0.63578895682825611710391773754 - sage: log(QQ(125)) + sage: log(QQ(125)) # optional - sage.symbolic 3*log(5) sage: log(QQ(125), 5) 3 - sage: log(QQ(125), 3) + sage: log(QQ(125), 3) # optional - sage.symbolic 3*log(5)/log(3) sage: QQ(8).log(1/2) -3 @@ -3150,14 +3151,14 @@ cdef class Rational(sage.structure.element.FieldElement): -4/3 sage: (125/8).log(5/2) 3 - sage: (125/8).log(5/2,prec=53) + sage: (125/8).log(5/2, prec=53) 3.00000000000000 TESTS:: - sage: (25/2).log(5/2) + sage: (25/2).log(5/2) # optional - sage.symbolic log(25/2)/log(5/2) - sage: (-1/2).log(3) + sage: (-1/2).log(3) # optional - sage.symbolic (I*pi + log(1/2))/log(3) """ cdef int self_sgn @@ -3226,15 +3227,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: gamma(1/2) + sage: gamma(1/2) # optional - sage.symbolic sqrt(pi) - sage: gamma(7/2) + sage: gamma(7/2) # optional - sage.symbolic 15/8*sqrt(pi) - sage: gamma(-3/2) + sage: gamma(-3/2) # optional - sage.symbolic 4/3*sqrt(pi) - sage: gamma(6/1) + sage: gamma(6/1) # optional - sage.symbolic 120 - sage: gamma(1/3) + sage: gamma(1/3) # optional - sage.symbolic gamma(1/3) This function accepts an optional precision argument:: diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index d2027e1827e..d9e4ff4455a 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)) + sage: QQ.embeddings(CyclotomicField(5)) # optional - sage.rings.number_field [Coercion map: From: Rational Field To: Cyclotomic Field of order 5 and degree 4] `K` must have characteristic 0:: - sage: QQ.embeddings(GF(3)) + sage: QQ.embeddings(GF(3)) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no embeddings of the rational field into K. @@ -773,28 +773,28 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): TESTS:: - sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) + sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: first argument must be a list or integer :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be nonzero :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) + sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: list should be of even cardinality :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: all entries in list must be prime or -1 for @@ -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) + 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)) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: second argument must be a rational number :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) + sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: if the infinite place is in the list, the second @@ -1058,12 +1058,12 @@ def extension(self, poly, names, **kwds): We make a single absolute extension:: - sage: K. = QQ.extension(x^3 + 5); K + sage: K. = QQ.extension(x^3 + 5); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 We make an extension generated by roots of two polynomials:: - sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K + sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 over its base field sage: b^2 # optional - sage.rings.number_field -3 @@ -1079,7 +1079,7 @@ def algebraic_closure(self): EXAMPLES:: - sage: QQ.algebraic_closure() + sage: QQ.algebraic_closure() # optional - sage.rings.number_field Algebraic Field """ from sage.rings.qqbar import QQbar @@ -1421,7 +1421,7 @@ 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)) + sage: all(QQ.selmer_space([], p)[0].dimension() == 0 for p in primes(3, 10)) # optional - sage.libs.pari True In general there is one generator for each `p\in S`, and an @@ -1519,7 +1519,7 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(QQ) # indirect doctest + sage: gap(QQ) # indirect doctest # optional - sage.libs.gap Rationals """ return 'Rationals' @@ -1587,7 +1587,7 @@ def _sympy_(self): EXAMPLES:: - sage: QQ._sympy_() + sage: QQ._sympy_() # optional - sympy Rationals """ from sympy import Rationals @@ -1633,20 +1633,20 @@ def _factor_univariate_polynomial(self, f): TESTS:: sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial( x ) + sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari x - sage: QQ._factor_univariate_polynomial( 2*x ) + sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari (2) * x - sage: QQ._factor_univariate_polynomial( (x^2 - 1/4)^4 ) + sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # optional - sage.libs.pari (x - 1/2)^4 * (x + 1/2)^4 - sage: QQ._factor_univariate_polynomial( (2*x + 1) * (3*x^2 - 5)^2 ) + sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) # optional - sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) - sage: QQ._factor_univariate_polynomial(f) + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(f) # optional - sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: QQ._factor_univariate_polynomial( 10*x^5 - 1 ) + sage: QQ._factor_univariate_polynomial(10*x^5 - 1) # optional - sage.libs.pari (10) * (x^5 - 1/10) - sage: QQ._factor_univariate_polynomial( 10*x^5 - 10 ) + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 2663c30c719..8b57280df3b 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -27,8 +27,8 @@ Test NumPy conversions:: sage: RDF(1).__array_interface__ {'typestr': '=f8'} - sage: import numpy - sage: numpy.array([RDF.pi()]).dtype + sage: import numpy # optional - numpy + sage: numpy.array([RDF.pi()]).dtype # optional - numpy dtype('float64') """ @@ -332,10 +332,10 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): sage: RLF(2/3) + RDF(1) 1.6666666666666665 - sage: import numpy - sage: RDF.coerce(numpy.int8('1')) + sage: import numpy # optional - numpy + sage: RDF.coerce(numpy.int8('1')) # optional - numpy 1.0 - sage: RDF.coerce(numpy.float64('1')) + sage: RDF.coerce(numpy.float64('1')) # optional - numpy 1.0 sage: RDF.coerce(pi) @@ -793,20 +793,20 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(pi) - sage: a.ulp() + sage: a = RDF(pi) # optional - sage.symbolic + sage: a.ulp() # optional - sage.symbolic 4.440892098500626e-16 - sage: b = a + a.ulp() + sage: b = a + a.ulp() # optional - sage.symbolic Adding or subtracting an ulp always gives a different number:: - sage: a + a.ulp() == a + sage: a + a.ulp() == a # optional - sage.symbolic False - sage: a - a.ulp() == a + sage: a - a.ulp() == a # optional - sage.symbolic False - sage: b + b.ulp() == b + sage: b + b.ulp() == b # optional - sage.symbolic False - sage: b - b.ulp() == b + sage: b - b.ulp() == b # optional - sage.symbolic False Since the default rounding mode is round-to-nearest, adding or @@ -815,13 +815,13 @@ cdef class RealDoubleElement(FieldElement): can only happen if the input number is (up to sign) exactly a power of 2:: - sage: a - a.ulp()/3 == a + sage: a - a.ulp()/3 == a # optional - sage.symbolic True - sage: a + a.ulp()/3 == a + sage: a + a.ulp()/3 == a # optional - sage.symbolic True - sage: b - b.ulp()/3 == b + sage: b - b.ulp()/3 == b # optional - sage.symbolic True - sage: b + b.ulp()/3 == b + sage: b + b.ulp()/3 == b # optional - sage.symbolic True sage: c = RDF(1) sage: c - c.ulp()/3 == c @@ -980,11 +980,11 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: s1 = RDF(sin(1)); s1 + sage: s1 = RDF(sin(1)); s1 # optional - sage.symbolic 0.8414709848078965 - sage: s1._interface_init_() + sage: s1._interface_init_() # optional - sage.symbolic '0.8414709848078965' - sage: s1 == RDF(gp(s1)) + sage: s1 == RDF(gp(s1)) # optional - sage.libs.pari sage.symbolic True """ return repr(self._value) @@ -1009,7 +1009,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: sage_input(RDF(NaN)) + sage: sage_input(RDF(NaN)) # optional - sage.symbolic RDF(NaN) sage: sage_input(RDF(-infinity), verify=True) # Verified @@ -1268,12 +1268,12 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(exp(1.0)); a + sage: a = RDF(exp(1.0)); a # optional - sage.symbolic 2.718281828459045 - sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() - sage: sign,mantissa,exponent + sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() # optional - sage.symbolic + sage: sign,mantissa,exponent # optional - sage.symbolic (1, 6121026514868073, -51) - sage: sign*mantissa*(2**exponent) == a + sage: sign*mantissa*(2**exponent) == a # optional - sage.symbolic True The mantissa is always a nonnegative number:: @@ -1968,7 +1968,7 @@ cdef class RealDoubleElement(FieldElement): sage: r = sqrt(RDF(2)); r 1.4142135623730951 - sage: r.algebraic_dependency(5) + sage: r.algebraic_dependency(5) # optional - sage.libs.pari x^2 - 2 """ return sage.arith.all.algdep(self,n) diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 33e94b93094..1904bbff3e7 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -230,10 +230,10 @@ specified if given a non-interval and an interval:: TESTS:: - sage: import numpy - sage: RIF(2) == numpy.int8('2') + sage: import numpy # optional - numpy + sage: RIF(2) == numpy.int8('2') # optional - numpy True - sage: numpy.int8('2') == RIF(2) + sage: numpy.int8('2') == RIF(2) # optional - numpy True sage: RIF(0,1) < float('2') Traceback (most recent call last): diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 5fc5d640ce9..2f8f37008d7 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -1438,12 +1438,12 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: import numpy - sage: numpy.arange(10.0) + sage: import numpy # optional - numpy + sage: numpy.arange(10.0) # optional - numpy array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) - sage: numpy.array([1.0, 1.1, 1.2]).dtype + sage: numpy.array([1.0, 1.1, 1.2]).dtype # optional - numpy dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype + sage: numpy.array([1.000000000000000000000000000000000000]).dtype # optional - numpy dtype('O') """ if (self._parent).__prec <= 53: diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index e25d33cfc8e..8ffb679e747 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -165,13 +165,13 @@ cdef class Ring(ParentWithGens): sage: QQ.is_finite() False - sage: GF(2^10,'a').is_finite() + sage: GF(2^10, 'a').is_finite() # optional - sage.libs.pari True - sage: R. = GF(7)[] - sage: R.is_finite() + sage: R. = GF(7)[] # optional - sage.libs.pari + sage: R.is_finite() # optional - sage.libs.pari False - sage: S. = R.quo(x^2+1) - sage: S.is_finite() + sage: S. = R.quo(x^2+1) # optional - sage.libs.pari + sage: S.is_finite() # optional - sage.libs.pari True sage: Integers(7).cardinality() @@ -255,11 +255,11 @@ cdef class Ring(ParentWithGens): """ EXAMPLES:: - sage: QQ.base_extend(GF(7)) + sage: QQ.base_extend(GF(7)) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: no base extension defined - sage: ZZ.base_extend(GF(7)) + sage: ZZ.base_extend(GF(7)) # optional - sage.libs.pari Finite Field of size 7 """ if R.has_coerce_map_from(self): @@ -447,20 +447,22 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: R. = GF(7)[] - sage: (x+y)*R - Ideal (x + y) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 7 - sage: (x+y,z+y^3)*R - Ideal (x + y, y^3 + z) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 7 + sage: R. = GF(7)[] # optional - sage.libs.pari + sage: (x+y) * R # optional - sage.libs.pari + 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 + Ideal (x + y, y^3 + z) of Multivariate Polynomial Ring in x, y, z + over Finite Field of size 7 The following was implemented in :trac:`7797`:: - sage: A = SteenrodAlgebra(2) - sage: A*[A.1+A.2,A.1^2] + sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules + sage: A * [A.1+A.2, A.1^2] # optional - sage.combinat sage.modules Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: [A.1+A.2,A.1^2]*A + sage: [A.1+A.2, A.1^2] * A # optional - sage.combinat sage.modules Right Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: A*[A.1+A.2,A.1^2]*A + sage: A * [A.1+A.2, A.1^2] * A # optional - sage.combinat sage.modules Twosided Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis """ @@ -518,18 +520,18 @@ cdef class Ring(ParentWithGens): sage: RR._ideal_class_() - sage: R. = GF(5)[] - sage: R._ideal_class_(1) + sage: R. = GF(5)[] # optional - sage.libs.pari + sage: R._ideal_class_(1) # optional - sage.libs.pari - sage: S = R.quo(x^3-y^2) - sage: S._ideal_class_(1) + sage: S = R.quo(x^3 - y^2) # optional - sage.libs.pari + sage: S._ideal_class_(1) # optional - sage.libs.pari - sage: S._ideal_class_(2) + sage: S._ideal_class_(2) # optional - sage.libs.pari - sage: T. = S[] - sage: T._ideal_class_(5) + sage: T. = S[] # optional - sage.libs.pari + sage: T._ideal_class_(5) # optional - sage.libs.pari - sage: T._ideal_class_(1) + sage: T._ideal_class_(1) # optional - sage.libs.pari Since :trac:`7797`, non-commutative rings have ideals as well:: @@ -703,7 +705,7 @@ cdef class Ring(ParentWithGens): sage: QQ.is_field() True - sage: GF(9,'a').is_field() + sage: GF(9, 'a').is_field() # optional - sage.libs.pari True sage: ZZ.is_field() False @@ -715,12 +717,12 @@ cdef class Ring(ParentWithGens): This illustrates the use of the ``proof`` parameter:: sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: S.is_field(proof = True) + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_field(proof=True) # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_field(proof = False) + sage: S.is_field(proof=False) # optional - sage.libs.singular False """ if self.is_zero(): @@ -765,30 +767,30 @@ cdef class Ring(ParentWithGens): sage: ZZ.is_subring(QQ) True - sage: ZZ.is_subring(GF(19)) + sage: ZZ.is_subring(GF(19)) # optional - sage.libs.pari False TESTS:: sage: QQ.is_subring(QQ['x']) True - sage: QQ.is_subring(GF(7)) + sage: QQ.is_subring(GF(7)) # optional - sage.libs.pari False - sage: QQ.is_subring(CyclotomicField(7)) + sage: QQ.is_subring(CyclotomicField(7)) # optional - sage.rings.number_field True sage: QQ.is_subring(ZZ) False Every ring is a subring of itself, :trac:`17287`:: - sage: QQbar.is_subring(QQbar) + sage: QQbar.is_subring(QQbar) # optional - sage.rings.number_field True sage: RR.is_subring(RR) True sage: CC.is_subring(CC) True - sage: K. = NumberField(x^3-x+1/10) - sage: K.is_subring(K) + sage: K. = NumberField(x^3 - x + 1/10) # optional - sage.rings.number_field + sage: K.is_subring(K) # optional - sage.rings.number_field True sage: R. = RR[] sage: R.is_subring(R) @@ -810,9 +812,9 @@ cdef class Ring(ParentWithGens): sage: QQ.is_prime_field() True - sage: GF(3).is_prime_field() + sage: GF(3).is_prime_field() # optional - sage.libs.pari True - sage: GF(9,'a').is_prime_field() + sage: GF(9, 'a').is_prime_field() # optional - sage.libs.pari False sage: ZZ.is_prime_field() False @@ -854,19 +856,19 @@ cdef class Ring(ParentWithGens): sage: Qp(7).is_integral_domain() # optional - sage.rings.padics True sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: S.is_integral_domain() + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_integral_domain() # optional - sage.libs.singular False This illustrates the use of the ``proof`` parameter:: sage: R. = ZZ[] - sage: S. = R.quo((b^3)) - sage: S.is_integral_domain(proof=True) + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_integral_domain(proof=True) # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof=False) + sage: S.is_integral_domain(proof=False) # optional - sage.libs.singular False TESTS: @@ -874,7 +876,7 @@ cdef class Ring(ParentWithGens): Make sure :trac:`10481` is fixed:: sage: x = polygen(ZZ, 'x') - sage: R. = ZZ['x'].quo(x^2) + sage: R. = ZZ['x'].quo(x^2) # optional - sage.libs.pari sage: R.fraction_field() Traceback (most recent call last): ... @@ -884,11 +886,11 @@ cdef class Ring(ParentWithGens): Forward the proof flag to ``is_field``, see :trac:`22910`:: - sage: R1. = GF(5)[] - sage: F1 = R1.quotient_ring(x^2+x+1) - sage: R2. = F1[] - sage: F2 = R2.quotient_ring(x^2+x+1) - sage: F2.is_integral_domain(False) + sage: R1. = GF(5)[] # optional - sage.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 False """ if self.is_field(proof): @@ -921,7 +923,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: GF(19).order() + sage: GF(19).order() # optional - sage.libs.pari 19 sage: QQ.order() +Infinity @@ -959,17 +961,17 @@ cdef class Ring(ParentWithGens): zeta3 sage: CyclotomicField(3).zeta(3).multiplicative_order() # optional - sage.rings.number_field 3 - sage: a = GF(7).zeta(); a + sage: a = GF(7).zeta(); a # optional - sage.libs.pari 3 - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.libs.pari 6 - sage: a = GF(49,'z').zeta(); a + sage: a = GF(49,'z').zeta(); a # optional - sage.libs.pari z - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.libs.pari 48 - sage: a = GF(49,'z').zeta(2); a + sage: a = GF(49,'z').zeta(2); a # optional - sage.libs.pari 6 - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.libs.pari 2 sage: QQ.zeta(3) Traceback (most recent call last): @@ -985,7 +987,7 @@ cdef class Ring(ParentWithGens): 1 sage: Ring.zeta(QQ, 2) -1 - sage: Ring.zeta(QQ, 3) + sage: Ring.zeta(QQ, 3) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no 3rd root of unity in Rational Field @@ -1024,9 +1026,9 @@ cdef class Ring(ParentWithGens): sage: CyclotomicField(19).zeta_order() # optional - sage.rings.number_field 38 - sage: GF(19).zeta_order() + sage: GF(19).zeta_order() # optional - sage.libs.pari 18 - sage: GF(5^3,'a').zeta_order() + sage: GF(5^3,'a').zeta_order() # optional - sage.libs.pari 124 sage: Zp(7, prec=8).zeta_order() # optional - sage.rings.padics 6 @@ -1369,16 +1371,18 @@ cdef class CommutativeRing(Ring): sage: R = QQ['x'] sage: y = polygen(R) - sage: R.extension(y^2 - 5, 'a') - Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 + sage: R.extension(y^2 - 5, 'a') # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a over + Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 :: - sage: P. = PolynomialRing(GF(5)) - sage: F. = GF(5).extension(x^2 - 2) - sage: P. = F[] - sage: R. = F.extension(t^2 - a); R - Univariate Quotient Polynomial Ring in b over Finite Field in a of size 5^2 with modulus b^2 + 4*a + sage: P. = PolynomialRing(GF(5)) # optional - sage.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 + Univariate Quotient Polynomial Ring in b over + Finite Field in a of size 5^2 with modulus b^2 + 4*a """ from sage.rings.polynomial.polynomial_element import Polynomial if not isinstance(poly, Polynomial): @@ -1414,17 +1418,19 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: Frob(u) + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.libs.pari + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.libs.pari + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: Frob(u) # optional - sage.libs.pari u^5 We can specify a power:: - sage: f = K.frobenius_endomorphism(2); f - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 - sage: f(1+u) + sage: f = K.frobenius_endomorphism(2); f # optional - sage.libs.pari + 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 1 + u^25 """ from .morphism import FrobeniusEndomorphism_generic @@ -1459,18 +1465,18 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: M = R.derivation_module(); M + 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() + 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 + 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 + sage: M.gen() / x # optional - sage.modules 1/x*d/dx Here is an example with a non-canonical defining morphism:: @@ -1483,30 +1489,30 @@ cdef class CommutativeRing(Ring): Defn: x |--> 0 y |--> 1 z |--> 2 - sage: M = R.derivation_module(ev) - sage: M + sage: M = R.derivation_module(ev) # optional - sage.modules + sage: M # optional - sage.modules Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field Elements in `M` acts as derivations at `(0,1,2)`:: - sage: Dx = M.gen(0); Dx + sage: Dx = M.gen(0); Dx # optional - sage.modules d/dx - sage: Dy = M.gen(1); Dy + sage: Dy = M.gen(1); Dy # optional - sage.modules d/dy - sage: Dz = M.gen(2); Dz + sage: Dz = M.gen(2); Dz # optional - sage.modules d/dz sage: f = x^2 + y^2 + z^2 - sage: Dx(f) # = 2*x evaluated at (0,1,2) + sage: Dx(f) # = 2*x evaluated at (0,1,2) # optional - sage.modules 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) + sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) + sage: Dz(f) # = 2*z evaluated at (0,1,2) # optional - sage.modules 4 An example with a twisting homomorphism:: sage: theta = R.hom([x^2, y^2, z^2]) - sage: M = R.derivation_module(twist=theta); M + sage: M = R.derivation_module(twist=theta); M # optional - sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) @@ -1545,23 +1551,23 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: R.derivation() + sage: R.derivation() # optional - sage.modules d/dx In that case, ``arg`` could be a generator:: - sage: R.derivation(y) + sage: R.derivation(y) # optional - sage.modules d/dy or a list of coefficients:: - sage: R.derivation([1,2,3]) + sage: R.derivation([1,2,3]) # optional - sage.modules d/dx + 2*d/dy + 3*d/dz It is not possible to define derivations with respect to a polynomial which is not a variable:: - sage: R.derivation(x^2) + sage: R.derivation(x^2) # optional - sage.modules Traceback (most recent call last): ... ValueError: unable to create the derivation @@ -1570,18 +1576,18 @@ cdef class CommutativeRing(Ring): sage: R. = QQ[] sage: theta = R.hom([x^2, y^2, z^2]) - sage: f = R.derivation(twist=theta); f + sage: f = R.derivation(twist=theta); f # optional - sage.modules 0 - sage: f.parent() + sage: f.parent() # optional - sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) Specifying a scalar, the returned twisted derivation is the corresponding multiple of `\theta - id`:: - sage: R.derivation(1, twist=theta) + sage: R.derivation(1, twist=theta) # optional - sage.modules [x |--> x^2, y |--> y^2, z |--> z^2] - id - sage: R.derivation(x, twist=theta) + sage: R.derivation(x, twist=theta) # optional - sage.modules x*([x |--> x^2, y |--> y^2, z |--> z^2] - id) """ @@ -1699,9 +1705,9 @@ cdef class IntegralDomain(CommutativeRing): True sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() + sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field True - sage: GF(5).is_integrally_closed() + sage: GF(5).is_integrally_closed() # optional - sage.libs.pari True sage: Z5 = Integers(5); Z5 Ring of integers modulo 5 @@ -1718,7 +1724,7 @@ cdef class IntegralDomain(CommutativeRing): EXAMPLES:: - sage: GF(7).is_field() + sage: GF(7).is_field() # optional - sage.libs.pari True The following examples have their own ``is_field`` implementations:: @@ -1788,9 +1794,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.krull_dimension() 1 - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.krull_dimension() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.krull_dimension() # optional - sage.rings.number_field 1 The following are not Dedekind domains but have @@ -1807,12 +1813,13 @@ cdef class DedekindDomain(IntegralDomain): sage: U.krull_dimension() 4 - sage: K. = QuadraticField(-1) - sage: R = K.order(2*i); R - Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.is_maximal() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R = K.order(2*i); R # optional - sage.rings.number_field + Order in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ return 1 @@ -1831,18 +1838,18 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_integrally_closed() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_integrally_closed() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_integrally_closed() # optional - sage.rings.number_field True These, however, are not Dedekind domains:: sage: QQ.is_integrally_closed() True - sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() + sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() # optional - sage.rings.number_field sage.symbolic False - sage: T. = PolynomialRing(QQ,2); T + sage: T. = PolynomialRing(QQ, 2); T Multivariate Polynomial Ring in x, y over Rational Field sage: T.is_integral_domain() True @@ -1855,11 +1862,12 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.integral_closure() - Gaussian Integers in Number Field in s with defining polynomial x^2 + 1 - sage: OK.integral_closure() == OK + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.integral_closure() # optional - sage.rings.number_field + Gaussian Integers in Number Field in s + with defining polynomial x^2 + 1 + sage: OK.integral_closure() == OK # optional - sage.rings.number_field True sage: QQ.integral_closure() == QQ @@ -1878,9 +1886,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_noetherian() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_noetherian() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_noetherian() # optional - sage.rings.number_field True sage: QQ.is_noetherian() True @@ -1961,22 +1969,22 @@ cdef class PrincipalIdealDomain(IntegralDomain): coercible:: sage: R. = PolynomialRing(QQ) - sage: S. = NumberField(x^2 - 2, 'a') - sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) - sage: print(f); print(g) + sage: S. = NumberField(x^2 - 2, 'a') # optional - sage.rings.number_field + sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) # optional - sage.rings.number_field + sage: print(f); print(g) # optional - sage.rings.number_field x^2 - 2 x^3 - a*x^2 - 2*x + 2*a - sage: f in R + sage: f in R # optional - sage.rings.number_field True - sage: g in R + sage: g in R # optional - sage.rings.number_field False - sage: R.gcd(f,g) + sage: R.gcd(f, g) # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce 2*a to a rational - sage: R.base_extend(S).gcd(f,g) + sage: R.base_extend(S).gcd(f,g) # optional - sage.rings.number_field x^2 - 2 - sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # optional - sage.rings.number_field x - a """ if coerce: @@ -2116,8 +2124,8 @@ cdef class Field(PrincipalIdealDomain): sage: CC.fraction_field() Complex Field with 53 bits of precision - sage: F = NumberField(x^2 + 1, 'i') - sage: F.fraction_field() + sage: F = NumberField(x^2 + 1, 'i') # optional - sage.rings.number_field + sage: F.fraction_field() # optional - sage.rings.number_field Number Field in i with defining polynomial x^2 + 1 """ return self @@ -2130,10 +2138,10 @@ cdef class Field(PrincipalIdealDomain): sage: QQ._pseudo_fraction_field() Rational Field - sage: K = GF(5) - sage: K._pseudo_fraction_field() + sage: K = GF(5) # optional - sage.libs.pari + sage: K._pseudo_fraction_field() # optional - sage.libs.pari Finite Field of size 5 - sage: K._pseudo_fraction_field() is K + sage: K._pseudo_fraction_field() is K # optional - sage.libs.pari True """ return self @@ -2245,8 +2253,8 @@ cdef class Field(PrincipalIdealDomain): EXAMPLES:: - sage: k = GF(9, 'a') - sage: k.prime_subfield() + sage: k = GF(9, 'a') # optional - sage.libs.pari + sage: k.prime_subfield() # optional - sage.libs.pari Finite Field of size 3 """ if self.characteristic() == 0: @@ -2286,7 +2294,7 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A + sage: A = Algebra(ZZ); A # optional - sage.modules """ # This is a low-level class. For performance, we trust that the category @@ -2306,12 +2314,12 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A + sage: A = Algebra(ZZ); A # optional - sage.modules - sage: A.characteristic() + sage: A.characteristic() # optional - sage.modules 0 - sage: A = Algebra(GF(7^3, 'a')) - sage: A.characteristic() + sage: A = Algebra(GF(7^3, 'a')) # optional - sage.libs.pari sage.modules + sage: A.characteristic() # optional - sage.libs.pari sage.modules 7 """ return self.base_ring().characteristic() diff --git a/src/sage/rings/semirings/non_negative_integer_semiring.py b/src/sage/rings/semirings/non_negative_integer_semiring.py index ea3bce495d9..9c73b3ede34 100644 --- a/src/sage/rings/semirings/non_negative_integer_semiring.py +++ b/src/sage/rings/semirings/non_negative_integer_semiring.py @@ -37,15 +37,15 @@ class NonNegativeIntegerSemiring(NonNegativeIntegers): Here is a piece of the Cayley graph for the multiplicative structure:: - sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) - sage: G + sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) # optional - sage.graphs + sage: G # optional - sage.graphs Looped multi-digraph on 9 vertices - sage: G.plot() + sage: G.plot() # optional - sage.graphs Graphics object consisting of 48 graphics primitives This is the Hasse diagram of the divisibility order on ``NN``. - sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() + sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() # optional - sage.graphs Note: as for :class:`NonNegativeIntegers `, ``NN`` is diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 7d44a03766b..979f4d69d5c 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -23,9 +23,9 @@ def prime_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.prime_finite_field(); K + sage: K = sage.rings.tests.prime_finite_field(); K # optional - sage.libs.pari Finite Field of size ... - sage: K.cardinality().is_prime() + sage: K.cardinality().is_prime() # optional - sage.libs.pari True """ from sage.rings.integer_ring import ZZ @@ -42,11 +42,11 @@ def finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.finite_field(); K + sage: K = sage.rings.tests.finite_field(); K # optional - sage.libs.pari Finite Field...of size ... - sage: K.cardinality().is_prime_power() + sage: K.cardinality().is_prime_power() # optional - sage.libs.pari True - sage: while K.cardinality().is_prime(): + sage: while K.cardinality().is_prime(): # optional - sage.libs.pari ....: K = sage.rings.tests.finite_field() """ from sage.rings.integer_ring import ZZ @@ -65,12 +65,12 @@ def small_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.small_finite_field(); K + sage: K = sage.rings.tests.small_finite_field(); K # optional - sage.libs.pari Finite Field...of size ... - sage: q = K.cardinality() - sage: q.is_prime_power() + sage: q = K.cardinality() # optional - sage.libs.pari + sage: q.is_prime_power() # optional - sage.libs.pari True - sage: q <= 2^16 + sage: q <= 2^16 # optional - sage.libs.pari True """ from sage.rings.integer_ring import ZZ @@ -107,7 +107,7 @@ def padic_field(): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.padic_field() + sage: sage.rings.tests.padic_field() # optional - sage.rings.padics ...-adic Field with capped relative precision ... """ from sage.rings.integer_ring import ZZ @@ -124,7 +124,7 @@ def quadratic_number_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.quadratic_number_field(); K + sage: K = sage.rings.tests.quadratic_number_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 ... with a = ... """ from sage.rings.integer_ring import ZZ @@ -142,7 +142,7 @@ def absolute_number_field(maxdeg=10): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.absolute_number_field(); K + sage: K = sage.rings.tests.absolute_number_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial ... sage: K.degree() <= 10 # optional - sage.rings.number_field True @@ -167,26 +167,26 @@ def relative_number_field(n=2, maxdeg=2): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.relative_number_field(3); K + sage: K = sage.rings.tests.relative_number_field(3); K # optional - sage.rings.number_field Number Field in aaa with defining polynomial x^2 ... over its base field - sage: K.relative_degree() + sage: K.relative_degree() # optional - sage.rings.number_field 2 - sage: L = K.base_ring() - sage: L.relative_degree() + sage: L = K.base_ring() # optional - sage.rings.number_field + sage: L.relative_degree() # optional - sage.rings.number_field 2 - sage: M = L.base_ring() - sage: M.relative_degree() + sage: M = L.base_ring() # optional - sage.rings.number_field + sage: M.relative_degree() # optional - sage.rings.number_field 2 - sage: M.base_ring() is QQ + sage: M.base_ring() is QQ # optional - sage.rings.number_field True TESTS: Check that :trac:`32117` is fixed:: - sage: set_random_seed(3030) - sage: from sage.rings.tests import relative_number_field - sage: _ = relative_number_field(3) + sage: set_random_seed(3030) # optional - sage.rings.number_field + sage: from sage.rings.tests import relative_number_field # optional - sage.rings.number_field + sage: _ = relative_number_field(3) # optional - sage.rings.number_field """ from sage.rings.integer_ring import ZZ K = absolute_number_field(maxdeg) @@ -333,7 +333,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.test_random_elements(trials=2, seed=0) + sage: sage.rings.tests.test_random_elements(trials=2, seed=0) # optional - sage.rings.number_field survived 0 tests Rational Field -1/2 @@ -382,7 +382,7 @@ def test_random_arith(level=MAX_LEVEL, trials=1): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.test_random_arith(trials=2, seed=0) + sage: sage.rings.tests.test_random_arith(trials=2, seed=0) # optional - sage.rings.number_field survived 0 tests Rational Field -1/2 -1/95 @@ -437,16 +437,21 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, Test Karatsuba multiplication of polynomials of small degree over some common rings:: - sage: for C in [QQ, ZZ[I], ZZ[I, sqrt(2)], GF(49, 'a'), MatrixSpace(GF(17), 3)]: + 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: for C in rings: ....: sage.rings.tests.test_karatsuba_multiplication(C, 10, 10) Zero-tests over ``QQbar`` are currently very slow, so we test only very small examples:: - sage.rings.tests.test_karatsuba_multiplication(QQbar, 3, 3, numtests=2) + sage: sage.rings.tests.test_karatsuba_multiplication(QQbar, 3, 3, numtests=2) # optional - sage.rings.number_field Larger degrees (over ``ZZ``, using FLINT):: - sage: sage.rings.tests.test_karatsuba_multiplication(ZZ, 1000, 1000, ref_mul=lambda f,g: f*g, base_ring_random_elt_args=[1000]) + sage: sage.rings.tests.test_karatsuba_multiplication(ZZ, 1000, 1000, + ....: ref_mul=lambda f,g: f*g, base_ring_random_elt_args=[1000]) Some more aggressive tests::