From cde4f0252ba3e1fcc235354a9c98199e32ff56d8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 31 May 2023 23:16:15 -0700 Subject: [PATCH 01/50] sage.rings: More # optional --- src/sage/rings/power_series_poly.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 7c93168d4b1..46d7bbf1303 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -34,9 +34,9 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`22216` is fixed:: sage: R. = PowerSeriesRing(QQ) - sage: R(pari('1 + O(T)')) + sage: R(pari('1 + O(T)')) # optional - sage.libs.pari 1 + O(T) - sage: R(pari('1/T + O(T)')) + sage: R(pari('1/T + O(T)')) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: series has negative valuation From 32310c736497294d401d50cd99a1bbd91fc420c8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 1 Jun 2023 23:01:56 -0700 Subject: [PATCH 02/50] sage.rings: More # optional --- src/sage/rings/complex_mpfr.pyx | 6 +- src/sage/rings/morphism.pyx | 10 +- src/sage/rings/rational_field.py | 2 +- src/sage/rings/real_mpfr.pyx | 40 +- src/sage/rings/ring_extension.pyx | 740 ++++++++++--------- src/sage/rings/ring_extension_conversion.pyx | 2 + src/sage/rings/ring_extension_element.pyx | 421 +++++------ src/sage/rings/ring_extension_homset.py | 8 +- src/sage/rings/ring_extension_morphism.pyx | 293 ++++---- 9 files changed, 769 insertions(+), 753 deletions(-) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 33d73d81b12..49f10a44373 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -493,9 +493,9 @@ class ComplexField_class(sage.rings.abc.ComplexField): Check that :trac:`14989` is fixed:: sage: x = polygen(ZZ, 'x') - sage: QQi = NumberField(x^2 + 1, 'i', embedding=CC(0,1)) - sage: i = QQi.order(QQi.gen()).gen(1) - sage: CC(i) + sage: QQi = NumberField(x^2 + 1, 'i', embedding=CC(0,1)) # optional - sage.rings.number_field + sage: i = QQi.order(QQi.gen()).gen(1) # optional - sage.rings.number_field + sage: CC(i) # optional - sage.rings.number_field 1.00000000000000*I TESTS:: diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index ba341f7f93a..9a88fccc29f 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -109,16 +109,16 @@ A map from a multivariate polynomial ring to itself:: An endomorphism of a quotient of a multi-variate polynomial ring:: sage: R. = PolynomialRing(QQ) - sage: S. = quo(R, ideal(1 + y^2)) - sage: phi = S.hom([a^2, -b]) - sage: phi + sage: S. = quo(R, ideal(1 + y^2)) # optional - sage.libs.singular + sage: phi = S.hom([a^2, -b]) # optional - sage.libs.singular + sage: phi # optional - sage.libs.singular 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) + sage: phi(b) # optional - sage.libs.singular -b - sage: phi(a^2 + b^2) + sage: phi(a^2 + b^2) # optional - sage.libs.singular a^4 - 1 The reduction map from the integers to the integers modulo 8, viewed as diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index cbd5a4ba483..6c7ba63c29f 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -326,7 +326,7 @@ def completion(self, p, prec, extras={}): sage: QQ.completion(infinity, 53) Real Field with 53 bits of precision - sage: QQ.completion(5, 15, {'print_mode': 'bars'}) + sage: QQ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics 5-adic Field with capped relative precision 15 """ from sage.rings.infinity import Infinity diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index ea7ff07a216..837ec08319d 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -719,7 +719,7 @@ cdef class RealField_class(sage.rings.abc.RealField): TESTS:: - sage: 1.0 - ZZ(1) - int(1) - 1 - QQ(1) - RealField(100)(1) - AA(1) - RLF(1) + sage: 1.0 - ZZ(1) - int(1) - 1 - QQ(1) - RealField(100)(1) - AA(1) - RLF(1) # optional - sage.rings.number_field -6.00000000000000 sage: R = RR['x'] # Hold reference to avoid garbage collection, see Issue #24709 sage: R.get_action(ZZ) @@ -920,7 +920,7 @@ cdef class RealField_class(sage.rings.abc.RealField): False sage: RR._is_valid_homomorphism_(CC,[CC(1)]) True - sage: RR._is_valid_homomorphism_(GF(2),GF(2)(1)) + sage: RR._is_valid_homomorphism_(GF(2),GF(2)(1)) # optional - sage.rings.finite_rings False """ @@ -2385,7 +2385,10 @@ cdef class RealNumber(sage.structure.element.RingElement): """ if have_same_parent(left, right): return ( left)._add_(right) - from .real_mpfi import RealIntervalFieldElement + try: + from .real_mpfi import RealIntervalFieldElement + except ImportError: + RealIntervalFieldElement = None if type(right) is RealIntervalFieldElement: return right.__add__(left) elif isinstance(left, RealNumber): @@ -2406,7 +2409,10 @@ cdef class RealNumber(sage.structure.element.RingElement): """ if have_same_parent(left, right): return ( left)._sub_(right) - from .real_mpfi import RealIntervalFieldElement + try: + from .real_mpfi import RealIntervalFieldElement + except ImportError: + RealIntervalFieldElement = None if type(right) is RealIntervalFieldElement: return (-right).__add__(left) elif isinstance(left, RealNumber): @@ -2427,7 +2433,10 @@ cdef class RealNumber(sage.structure.element.RingElement): """ if have_same_parent(left, right): return ( left)._mul_(right) - from .real_mpfi import RealIntervalFieldElement + try: + from .real_mpfi import RealIntervalFieldElement + except ImportError: + RealIntervalFieldElement = None if type(right) is RealIntervalFieldElement: return right.__mul__(left) elif isinstance(left, RealNumber): @@ -2448,7 +2457,10 @@ cdef class RealNumber(sage.structure.element.RingElement): """ if have_same_parent(left, right): return ( left)._div_(right) - from .real_mpfi import RealIntervalFieldElement + try: + from .real_mpfi import RealIntervalFieldElement + except ImportError: + RealIntervalFieldElement = None if type(right) is RealIntervalFieldElement: return right.__rtruediv__(left) elif isinstance(left, RealNumber): @@ -3236,7 +3248,7 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__int__() + sage: RR(pi).__int__() # optional - sage.symbolic 3 sage: type(RR(pi).__int__()) <... 'int'> @@ -3254,7 +3266,7 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__complex__() + sage: RR(pi).__complex__() # optional - sage.symbolic (3.141592653589793+0j) sage: type(RR(pi).__complex__()) <... 'complex'> @@ -3268,7 +3280,7 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi)._complex_number_() + sage: RR(pi)._complex_number_() # optional - sage.symbolic 3.14159265358979 sage: parent(RR(pi)._complex_number_()) Complex Field with 53 bits of precision @@ -5340,11 +5352,11 @@ cdef class RealNumber(sage.structure.element.RingElement): Computing zeta using PARI is much more efficient in difficult cases. Here's how to compute zeta with at least a given precision:: - sage: z = pari(2).zeta(precision=53); z + sage: z = pari(2).zeta(precision=53); z # optional - sage.libs.pari 1.64493406684823 - sage: pari(2).zeta(precision=128).sage().prec() + sage: pari(2).zeta(precision=128).sage().prec() # optional - sage.libs.pari 128 - sage: pari(2).zeta(precision=65).sage().prec() + sage: pari(2).zeta(precision=65).sage().prec() # optional - sage.libs.pari 128 # 64-bit 96 # 32-bit @@ -5356,9 +5368,9 @@ cdef class RealNumber(sage.structure.element.RingElement): :: - sage: type(z) + sage: type(z) # optional - sage.libs.pari - sage: R(z) + sage: R(z) # optional - sage.libs.pari 1.64493406684823 """ cdef RealNumber x = self._new() diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index ddd675e8a3e..8143d84d3ee 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -11,41 +11,40 @@ that is `L`. For example, the following line constructs the extension of finite fields `\mathbf{F}_{5^4}/\mathbf{F}_{5^2}`:: - sage: GF(5^4).over(GF(5^2)) + sage: GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base By default, Sage reuses the canonical generator of the top ring (here `z_4 \in \mathbf{F}_{5^4}`), together with its name. However, the user can customize them by passing in appropriate arguments:: - sage: F = GF(5^2) - sage: k = GF(5^4) - sage: z4 = k.gen() - sage: K. = k.over(F, gen = 1-z4) - sage: K + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: k = GF(5^4) # optional - sage.rings.finite_rings + sage: z4 = k.gen() # optional - sage.rings.finite_rings + sage: K. = k.over(F, gen=1-z4); K # optional - sage.rings.finite_rings Field in a with defining polynomial x^2 + z2*x + 4 over its base The base of the extension is available via the method :meth:`base` (or equivalently :meth:`base_ring`):: - sage: K.base() + sage: K.base() # optional - sage.rings.finite_rings Finite Field in z2 of size 5^2 It is also possible to build an extension on top of another extension, obtaining this way a tower of extensions:: - sage: L. = GF(5^8).over(K) - sage: L + sage: L. = GF(5^8).over(K) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings Field in b with defining polynomial x^2 + (4*z2 + 3*a)*x + 1 - a over its base - sage: L.base() + sage: L.base() # optional - sage.rings.finite_rings Field in a with defining polynomial x^2 + z2*x + 4 over its base - sage: L.base().base() + sage: L.base().base() # optional - sage.rings.finite_rings Finite Field in z2 of size 5^2 The method :meth:`bases` gives access to the complete list of rings in a tower:: - sage: L.bases() + sage: L.bases() # optional - sage.rings.finite_rings [Field in b with defining polynomial x^2 + (4*z2 + 3*a)*x + 1 - a over its base, Field in a with defining polynomial x^2 + z2*x + 4 over its base, Finite Field in z2 of size 5^2] @@ -54,44 +53,44 @@ Once we have constructed an extension (or a tower of extensions), we have interesting methods attached to it. As a basic example, one can compute a basis of the top ring over any base in the tower:: - sage: L.basis_over(K) + sage: L.basis_over(K) # optional - sage.rings.finite_rings [1, b] - sage: L.basis_over(F) + sage: L.basis_over(F) # optional - sage.rings.finite_rings [1, a, b, a*b] When the base is omitted, the default is the natural base of the extension:: - sage: L.basis_over() + sage: L.basis_over() # optional - sage.rings.finite_rings [1, b] The method :meth:`sage.rings.ring_extension_element.RingExtensionWithBasis.vector` computes the coordinates of an element according to the above basis:: - sage: u = a + 2*b + 3*a*b - sage: u.vector() # over K + sage: u = a + 2*b + 3*a*b # optional - sage.rings.finite_rings + sage: u.vector() # over K # optional - sage.rings.finite_rings (a, 2 + 3*a) - sage: u.vector(F) + sage: u.vector(F) # optional - sage.rings.finite_rings (0, 1, 2, 3) One can also compute traces and norms with respect to any base of the tower:: - sage: u.trace() # over K + sage: u.trace() # over K # optional - sage.rings.finite_rings (2*z2 + 1) + (2*z2 + 1)*a - sage: u.trace(F) + sage: u.trace(F) # optional - sage.rings.finite_rings z2 + 1 - sage: u.trace().trace() # over K, then over F + sage: u.trace().trace() # over K, then over F # optional - sage.rings.finite_rings z2 + 1 - sage: u.norm() # over K + sage: u.norm() # over K # optional - sage.rings.finite_rings (z2 + 1) + (4*z2 + 2)*a - sage: u.norm(F) + sage: u.norm(F) # optional - sage.rings.finite_rings 2*z2 + 2 And minimal polynomials:: - sage: u.minpoly() + sage: u.minpoly() # optional - sage.rings.finite_rings x^2 + ((3*z2 + 4) + (3*z2 + 4)*a)*x + (z2 + 1) + (4*z2 + 2)*a - sage: u.minpoly(F) + sage: u.minpoly(F) # optional - sage.rings.finite_rings x^4 + (4*z2 + 4)*x^3 + x^2 + (z2 + 1)*x + 2*z2 + 2 @@ -165,9 +164,9 @@ def tower_bases(ring, degree): ([Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field], [1]) - sage: K. = Qq(5^2) - sage: L. = K.extension(x^3 - 5) - sage: tower_bases(L, True) + sage: K. = Qq(5^2) # optional - sage.rings.padics + sage: L. = K.extension(x^3 - 5) # optional - sage.rings.padics + sage: tower_bases(L, True) # optional - sage.rings.padics ([5-adic Eisenstein Extension Field in w defined by x^3 - 5 over its base field, 5-adic Unramified Extension Field in a defined by x^2 + 4*x + 2, 5-adic Field with capped relative precision 20], @@ -213,12 +212,12 @@ def common_base(K, L, degree): sage: from sage.rings.ring_extension import common_base - sage: common_base(GF(5^3), GF(5^7), False) + sage: common_base(GF(5^3), GF(5^7), False) # optional - sage.rings.finite_rings Finite Field of size 5 - sage: common_base(GF(5^3), GF(5^7), True) + sage: common_base(GF(5^3), GF(5^7), True) # optional - sage.rings.finite_rings (Finite Field of size 5, 3, 7) - sage: common_base(GF(5^3), GF(7^5), False) + sage: common_base(GF(5^3), GF(7^5), False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: unable to find a common base @@ -337,8 +336,7 @@ class RingExtensionFactory(UniqueFactory): sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension(x^2 - 2) - sage: E = K.over(QQ) - sage: E + sage: E = K.over(QQ); E Field in a with defining polynomial x^2 - 2 over its base sage: E2. = K.over(QQ) @@ -381,7 +379,8 @@ class RingExtensionFactory(UniqueFactory): {'is_backend_exposed': True, 'print_options': {'print_elements_as': None, 'print_parent_as': None}})]}) - sage: RingExtension.create_key_and_extra_args(GF(5^4), GF(5^2), names=('a',)) + sage: RingExtension.create_key_and_extra_args(GF(5^4), GF(5^2), # optional - sage.rings.finite_rings + ....: names=('a',)) ((Ring morphism: From: Finite Field in z2 of size 5^2 To: Finite Field in z4 of size 5^4 @@ -560,8 +559,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): ... TypeError: only commutative rings are accepted - sage: K = GF(5^3) - sage: K.over(K.frobenius_endomorphism()) + sage: K = GF(5^3) # optional - sage.rings.finite_rings + sage: K.over(K.frobenius_endomorphism()) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: exotic defining morphism between two rings in the tower; consider using another variable name @@ -693,8 +692,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES: - sage: E = GF(5^3).over() - sage: hash(E) # random + sage: E = GF(5^3).over() # optional - sage.rings.finite_rings + sage: hash(E) # random # optional - sage.rings.finite_rings 140257667982632 """ return hash_by_id(self) @@ -706,10 +705,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(7^3).over() - sage: type(K) + sage: K = GF(7^3).over() # optional - sage.rings.finite_rings + sage: type(K) # optional - sage.rings.finite_rings - sage: loads(dumps(K)) is K + sage: loads(dumps(K)) is K # optional - sage.rings.finite_rings True """ (defining_morphism, gens, names) = self._factory_data[2] @@ -722,8 +721,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: E = GF(5^3).over() - sage: E.construction() + sage: E = GF(5^3).over() # optional - sage.rings.finite_rings + sage: E.construction() # optional - sage.rings.finite_rings """ # One could define a construction functor K' -> K' otimes_K L, but we leave this to another issue @@ -764,18 +763,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: k = GF(5) - sage: K. = GF(5^2).over(k) - sage: L. = GF(5^4).over(K) + sage: k = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over(k) # optional - sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: x = L.from_base_ring(k(2)); x + sage: x = L.from_base_ring(k(2)); x # optional - sage.rings.finite_rings 2 - sage: x.parent() + sage: x.parent() # optional - sage.rings.finite_rings Field in v with defining polynomial x^2 + (3 - u)*x + u over its base - sage: x = L.from_base_ring(u); x + sage: x = L.from_base_ring(u); x # optional - sage.rings.finite_rings u - sage: x.parent() + sage: x.parent() # optional - sage.rings.finite_rings Field in v with defining polynomial x^2 + (3 - u)*x + u over its base """ if r not in self._base: @@ -797,24 +796,24 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A. = GF(5^2).over() # over GF(5) - sage: B. = GF(5^4).over(A) - sage: C. = GF(5^12).over(B) - sage: D. = GF(5^24).over(C) + sage: A. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: B. = GF(5^4).over(A) # optional - sage.rings.finite_rings + sage: C. = GF(5^12).over(B) # optional - sage.rings.finite_rings + sage: D. = GF(5^24).over(C) # optional - sage.rings.finite_rings Observe what happens when we modify the option ``over``:: - sage: D + sage: D # optional - sage.rings.finite_rings Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over its base - sage: D.print_options(over=2) - sage: D + sage: D.print_options(over=2) # optional - sage.rings.finite_rings + sage: D # optional - sage.rings.finite_rings Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over Field in c with defining polynomial x^3 + (1 + (2 - a)*b)*x^2 + (2 + 2*b)*x - b over Field in b with defining polynomial x^2 + (3 - a)*x + a over its base - sage: D.print_options(over=Infinity) - sage: D + sage: D.print_options(over=Infinity) # optional - sage.rings.finite_rings + sage: D # optional - sage.rings.finite_rings Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over Field in c with defining polynomial x^3 + (1 + (2 - a)*b)*x^2 + (2 + 2*b)*x - b over Field in b with defining polynomial x^2 + (3 - a)*x + a over @@ -823,19 +822,19 @@ cdef class RingExtension_generic(CommutativeAlgebra): Now the option ``base``:: - sage: d^2 + sage: d^2 # optional - sage.rings.finite_rings -c + ((-1 + a) + ((-1 + 3*a) + b)*c + ((3 - a) + (-1 + a)*b)*c^2)*d - sage: D.basis_over(B) + sage: D.basis_over(B) # optional - sage.rings.finite_rings [1, c, c^2, d, c*d, c^2*d] - sage: D.print_options(base=B) - sage: d^2 + sage: D.print_options(base=B) # optional - sage.rings.finite_rings + sage: d^2 # optional - sage.rings.finite_rings -c + (-1 + a)*d + ((-1 + 3*a) + b)*c*d + ((3 - a) + (-1 + a)*b)*c^2*d - sage: D.basis_over(A) + sage: D.basis_over(A) # optional - sage.rings.finite_rings [1, b, c, b*c, c^2, b*c^2, d, b*d, c*d, b*c*d, c^2*d, b*c^2*d] - sage: D.print_options(base=A) - sage: d^2 + sage: D.print_options(base=A) # optional - sage.rings.finite_rings + sage: d^2 # optional - sage.rings.finite_rings -c + (-1 + a)*d + (-1 + 3*a)*c*d + b*c*d + (3 - a)*c^2*d + (-1 + a)*b*c^2*d """ for (name, value) in options.items(): @@ -1039,21 +1038,21 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: E1 = GF(3^6).over(GF(3^3)) - sage: E1.coerce_map_from(GF(3^3)) # indirect doctest + sage: E1 = GF(3^6).over(GF(3^3)) # optional - sage.rings.finite_rings + sage: E1.coerce_map_from(GF(3^3)) # indirect doctest # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in z3 of size 3^3 To: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base Defn: z3 |--> z3 - sage: E1.coerce_map_from(GF(3)) # indirect doctest + sage: E1.coerce_map_from(GF(3)) # indirect doctest # optional - sage.rings.finite_rings Ring morphism: From: Finite Field of size 3 To: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base Defn: 1 |--> 1 - sage: E2 = GF(3^18).over(GF(3^9)) - sage: E2.coerce_map_from(E1) # indirect doctest + sage: E2 = GF(3^18).over(GF(3^9)) # optional - sage.rings.finite_rings + sage: E2.coerce_map_from(E1) # indirect doctest # optional - sage.rings.finite_rings Ring morphism: From: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base To: Field in z18 with defining polynomial x^2 + (z9^8 + 2*z9^7 + z9^5 + 2*z9^4 + z9^2 + z9 + 1)*x + z9 over its base @@ -1061,11 +1060,11 @@ cdef class RingExtension_generic(CommutativeAlgebra): A test with iterated extensions:: - sage: A = GF(3^18).over(GF(3^3)) # simple extension GF(3^3) -> GF(3^18) - sage: B = GF(3^18).over(E1) # iterated extension GF(3^3) -> GF(3^6) -> GF(3^18) - sage: A.has_coerce_map_from(B) + sage: A = GF(3^18).over(GF(3^3)) # simple extension GF(3^3) -> GF(3^18) # optional - sage.rings.finite_rings + sage: B = GF(3^18).over(E1) # iterated extension GF(3^3) -> GF(3^6) -> GF(3^18) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(B) # optional - sage.rings.finite_rings False - sage: B.has_coerce_map_from(A) + sage: B.has_coerce_map_from(A) # optional - sage.rings.finite_rings True """ @@ -1085,17 +1084,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) - sage: K = GF(5^4).over(F) - sage: K.base() + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: K.base() # optional - sage.rings.finite_rings Finite Field in z2 of size 5^2 In case of iterated extensions, the base is itself an extension:: - sage: L = GF(5^8).over(K) - sage: L.base() + sage: L = GF(5^8).over(K) # optional - sage.rings.finite_rings + sage: L.base() # optional - sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L.base() is K + sage: L.base() is K # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -1111,20 +1110,20 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(K) + sage: F = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: F.bases() + sage: F.bases() # optional - sage.rings.finite_rings [Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] - sage: K.bases() + sage: K.bases() # optional - sage.rings.finite_rings [Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] - sage: L.bases() + sage: L.bases() # optional - sage.rings.finite_rings [Field in z12 with defining polynomial x^3 + (1 + (2 - z2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, @@ -1150,15 +1149,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(K) + sage: F = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: F.absolute_base() + sage: F.absolute_base() # optional - sage.rings.finite_rings Finite Field of size 5 - sage: K.absolute_base() + sage: K.absolute_base() # optional - sage.rings.finite_rings Finite Field of size 5 - sage: L.absolute_base() + sage: L.absolute_base() # optional - sage.rings.finite_rings Finite Field of size 5 .. SEEALSO:: @@ -1179,28 +1178,28 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) - sage: B = GF(5^12).over(A) + sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: B = GF(5^12).over(A) # optional - sage.rings.finite_rings - sage: A.is_defined_over(GF(5^2)) + sage: A.is_defined_over(GF(5^2)) # optional - sage.rings.finite_rings True - sage: A.is_defined_over(GF(5)) + sage: A.is_defined_over(GF(5)) # optional - sage.rings.finite_rings False - sage: B.is_defined_over(A) + sage: B.is_defined_over(A) # optional - sage.rings.finite_rings True - sage: B.is_defined_over(GF(5^4)) + sage: B.is_defined_over(GF(5^4)) # optional - sage.rings.finite_rings True - sage: B.is_defined_over(GF(5^2)) + sage: B.is_defined_over(GF(5^2)) # optional - sage.rings.finite_rings True - sage: B.is_defined_over(GF(5)) + sage: B.is_defined_over(GF(5)) # optional - sage.rings.finite_rings False Note that an extension is defined over itself:: - sage: A.is_defined_over(A) + sage: A.is_defined_over(A) # optional - sage.rings.finite_rings True - sage: A.is_defined_over(GF(5^4)) + sage: A.is_defined_over(GF(5^4)) # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -1231,26 +1230,26 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(K) - sage: L.bases() + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: L.bases() # optional - sage.rings.finite_rings [Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base, Finite Field in z2 of size 5^2] - sage: L._check_base(K) + sage: L._check_base(K) # optional - sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(GF(5^4)) + sage: L._check_base(GF(5^4)) # optional - sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(GF(5^4)) is K + sage: L._check_base(GF(5^4)) is K # optional - sage.rings.finite_rings True When ``base`` is ``None``, the base of the extension is returned:: - sage: L._check_base(None) + sage: L._check_base(None) # optional - sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(None) is L.base() + sage: L._check_base(None) is L.base() # optional - sage.rings.finite_rings True """ @@ -1276,17 +1275,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(K) + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: K.defining_morphism() + sage: K.defining_morphism() # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in z2 of size 5^2 To: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base Defn: z2 |--> z2 - sage: L.defining_morphism() + sage: L.defining_morphism() # optional - sage.rings.finite_rings Ring morphism: From: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base To: Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base @@ -1295,13 +1294,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): One can also pass in a base over which the extension is explicitly defined (see also :meth:`is_defined_over`):: - sage: L.defining_morphism(F) + sage: L.defining_morphism(F) # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in z2 of size 5^2 To: Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base Defn: z2 |--> z2 - sage: L.defining_morphism(GF(5)) + sage: L.defining_morphism(GF(5)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1338,13 +1337,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: K.gens() + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.gens() # optional - sage.rings.finite_rings (a,) - sage: L. = GF(5^4).over(K) - sage: L.gens() + sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: L.gens() # optional - sage.rings.finite_rings (b,) - sage: L.gens(GF(5)) + sage: L.gens(GF(5)) # optional - sage.rings.finite_rings (b, a) sage: S. = QQ[] @@ -1368,16 +1367,16 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) - sage: K.gens() + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.gens() # optional - sage.rings.finite_rings (z2,) - sage: K.ngens() + sage: K.ngens() # optional - sage.rings.finite_rings 1 - sage: L = GF(5^4).over(K) - sage: L.gens(GF(5)) + sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: L.gens(GF(5)) # optional - sage.rings.finite_rings (z4, z2) - sage: L.ngens(GF(5)) + sage: L.ngens(GF(5)) # optional - sage.rings.finite_rings 2 """ return len(self.gens(base)) @@ -1388,15 +1387,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) - sage: x =K.gen(); x + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: x =K.gen(); x # optional - sage.rings.finite_rings z2 Observe that the generator lives in the extension:: - sage: x.parent() + sage: x.parent() # optional - sage.rings.finite_rings Field in z2 with defining polynomial x^2 + 4*x + 2 over its base - sage: x.parent() is K + sage: x.parent() is K # optional - sage.rings.finite_rings True """ return self.gens()[0] @@ -1407,13 +1406,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) - sage: x = K.random_element(); x # random + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: x = K.random_element(); x # random # optional - sage.rings.finite_rings 3 + z2 - sage: x.parent() + sage: x.parent() # optional - sage.rings.finite_rings Field in z2 with defining polynomial x^2 + 4*x + 2 over its base - sage: x.parent() is K + sage: x.parent() is K # optional - sage.rings.finite_rings True """ elt = self._backend.random_element() @@ -1430,29 +1429,29 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(K) + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: K.degree_over(F) + sage: K.degree_over(F) # optional - sage.rings.finite_rings 2 - sage: L.degree_over(K) + sage: L.degree_over(K) # optional - sage.rings.finite_rings 3 - sage: L.degree_over(F) + sage: L.degree_over(F) # optional - sage.rings.finite_rings 6 If ``base`` is omitted, the degree is computed over the base of the extension:: - sage: K.degree_over() + sage: K.degree_over() # optional - sage.rings.finite_rings 2 - sage: L.degree_over() + sage: L.degree_over() # optional - sage.rings.finite_rings 3 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: K.degree_over(GF(5)) + sage: K.degree_over(GF(5)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1496,20 +1495,20 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) - sage: B = GF(5^12).over(A) + sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: B = GF(5^12).over(A) # optional - sage.rings.finite_rings - sage: A.degree(GF(5^2)) + sage: A.degree(GF(5^2)) # optional - sage.rings.finite_rings 2 - sage: B.degree(A) + sage: B.degree(A) # optional - sage.rings.finite_rings 3 - sage: B.degree(GF(5^2)) + sage: B.degree(GF(5^2)) # optional - sage.rings.finite_rings 6 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: A.degree(GF(5)) + sage: A.degree(GF(5)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1526,8 +1525,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) - sage: A.relative_degree() + sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: A.relative_degree() # optional - sage.rings.finite_rings 2 .. SEEALSO:: @@ -1542,12 +1541,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) - sage: B = GF(5^12).over(A) + sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: B = GF(5^12).over(A) # optional - sage.rings.finite_rings - sage: A.absolute_degree() + sage: A.absolute_degree() # optional - sage.rings.finite_rings 2 - sage: B.absolute_degree() + sage: B.absolute_degree() # optional - sage.rings.finite_rings 6 .. SEEALSO:: @@ -1567,18 +1566,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) - sage: L = GF(5^4).over(K) + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: L.is_finite_over(K) + sage: L.is_finite_over(K) # optional - sage.rings.finite_rings True - sage: L.is_finite_over(GF(5)) + sage: L.is_finite_over(GF(5)) # optional - sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: L.is_finite_over() + sage: L.is_finite_over() # optional - sage.rings.finite_rings True """ cdef CommutativeRing b @@ -1612,8 +1611,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(5^2).over() # over GF(5) - sage: K.is_finite_over() # indirect doctest + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.is_finite_over() # indirect doctest # optional - sage.rings.finite_rings True """ raise NotImplementedError @@ -1630,18 +1629,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) - sage: L = GF(5^4).over(K) + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: L.is_free_over(K) + sage: L.is_free_over(K) # optional - sage.rings.finite_rings True - sage: L.is_free_over(GF(5)) + sage: L.is_free_over(GF(5)) # optional - sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: L.is_free_over() + sage: L.is_free_over() # optional - sage.rings.finite_rings True """ cdef CommutativeRing b @@ -1675,8 +1674,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(5^2).over() # over GF(5) - sage: K.is_free_over() # indirect doctest + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.is_free_over() # indirect doctest # optional - sage.rings.finite_rings True """ raise NotImplementedError @@ -1691,17 +1690,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^5).over() # over GF(5) - sage: K.is_field() + sage: K = GF(5^5).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.is_field() # optional - sage.rings.finite_rings True - sage: S. = QQ[] - sage: A = S.over(QQ) - sage: A.is_field() + sage: S. = QQ[] # optional - sage.rings.finite_rings + sage: A = S.over(QQ) # optional - sage.rings.finite_rings + sage: A.is_field() # optional - sage.rings.finite_rings False - sage: B = A.fraction_field() - sage: B.is_field() + sage: B = A.fraction_field() # optional - sage.rings.finite_rings + sage: B.is_field() # optional - sage.rings.finite_rings True """ return self._backend.is_field(proof=proof) @@ -1728,43 +1727,45 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) - sage: OK = A.over() # over ZZ - sage: OK + sage: A. = ZZ.extension(x^2 - 5) # optional - sage.rings.number_field + sage: OK = A.over() # over ZZ # optional - sage.rings.number_field + sage: OK # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1 = OK.fraction_field() - sage: K1 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + sage: K1 = OK.fraction_field(); K1 # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base + sage: K1.bases() # optional - sage.rings.number_field + [Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - sage: K2 = OK.fraction_field(extend_base=True) - sage: K2 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + sage: K2 = OK.fraction_field(extend_base=True); K2 # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base + sage: K2.bases() # optional - sage.rings.number_field + [Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base, Rational Field] Note that there is no coercion between `K_1` and `K_2`:: - sage: K1.has_coerce_map_from(K2) + sage: K1.has_coerce_map_from(K2) # optional - sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) + sage: K2.has_coerce_map_from(K1) # optional - sage.rings.number_field False We check that when the extension is a field, its fraction field does not change:: - sage: K1.fraction_field() is K1 + sage: K1.fraction_field() is K1 # optional - sage.rings.number_field True - sage: K2.fraction_field() is K2 + sage: K2.fraction_field() is K2 # optional - sage.rings.number_field True TESTS:: - sage: A = GF(5).over(ZZ) + sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings sage: A.fraction_field(extend_base=True) Traceback (most recent call last): ... @@ -1790,8 +1791,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(5^2).over() - sage: K.fraction_field() # indirect doctest + sage: K = GF(5^2).over() # optional - sage.rings.finite_rings + sage: K.fraction_field() # indirect doctest # optional - sage.rings.finite_rings Field in z2 with defining polynomial x^2 + 4*x + 2 over its base sage: K = QQ.over(ZZ) @@ -1825,15 +1826,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(F) + sage: F = GF(5^2) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(F) # optional - sage.rings.finite_rings - sage: K.Hom(L) # indirect doctest + sage: K.Hom(L) # indirect doctest # optional - sage.rings.finite_rings Set of Homomorphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base - sage: K.Hom(L, category=Sets()) + sage: K.Hom(L, category=Sets()) # optional - sage.rings.finite_rings Set of Morphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base in Category of sets @@ -1869,12 +1870,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: L. = GF(5^6).over(K) + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings We define (by hand) the relative Frobenius endomorphism of the extension `L/K`:: - sage: L.hom([b^25]) + sage: L.hom([b^25]) # optional - sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> 2 + 2*a*b + (2 - a)*b^2 @@ -1882,16 +1883,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): because it is not a homomorphism of `K`-algebras. For this reason, the construction ``L.hom([b^5])`` fails:: - sage: L.hom([b^5]) + sage: L.hom([b^5]) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: images do not define a valid homomorphism What we need is to specify a base map:: - sage: FrobK = K.hom([a^5]) - sage: FrobL = L.hom([b^5], base_map=FrobK) - sage: FrobL + sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings + sage: FrobL = L.hom([b^5], base_map=FrobK); FrobL # optional - sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: @@ -1899,13 +1899,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): As a shortcut, we may use the following construction:: - sage: phi = L.hom([b^5, a^5]) - sage: phi + sage: phi = L.hom([b^5, a^5]); phi # optional - sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a - sage: phi == FrobL + sage: phi == FrobL # optional - sage.rings.finite_rings True """ if codomain is None: @@ -1924,14 +1923,14 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) - sage: K = GF(5^4).over(F) - sage: L = GF(5^12).over(K) - sage: F.characteristic() + sage: F = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: F.characteristic() # optional - sage.rings.finite_rings 5 - sage: K.characteristic() + sage: K.characteristic() # optional - sage.rings.finite_rings 5 - sage: L.characteristic() + sage: L.characteristic() # optional - sage.rings.finite_rings 5 :: @@ -1942,28 +1941,30 @@ cdef class RingExtension_generic(CommutativeAlgebra): :: - sage: F = GF(11) - sage: A. = F[] - sage: K = Frac(F).over(F) - sage: K.characteristic() + sage: F = GF(11) # optional - sage.rings.finite_rings + sage: A. = F[] # optional - sage.rings.finite_rings + sage: K = Frac(F).over(F) # optional - sage.rings.finite_rings + sage: K.characteristic() # optional - sage.rings.finite_rings 11 :: - sage: E = GF(7).over(ZZ) - sage: E.characteristic() + sage: E = GF(7).over(ZZ) # optional - sage.rings.finite_rings + sage: E.characteristic() # optional - sage.rings.finite_rings 7 TESTS: Ensure issue :trac:`34692` is fixed:: - sage: Fq = GF(11) - sage: FqX. = Fq[] - sage: k = Frac(FqX) - sage: K = k.over(FqX) - sage: K.frobenius_endomorphism() - Frobenius endomorphism x |--> x^11 of Fraction Field of Univariate Polynomial Ring in X over Finite Field of size 11 over its base + sage: Fq = GF(11) # optional - sage.rings.finite_rings + sage: FqX. = Fq[] # optional - sage.rings.finite_rings + sage: k = Frac(FqX) # optional - sage.rings.finite_rings + sage: K = k.over(FqX) # optional - sage.rings.finite_rings + sage: K.frobenius_endomorphism() # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^11 of + Fraction Field of Univariate Polynomial Ring in X over + Finite Field of size 11 over its base """ return self._backend.characteristic() @@ -2004,13 +2005,13 @@ cdef class RingExtensionFractionField(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) - sage: OK = A.over() - sage: K = OK.fraction_field() - sage: K - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: OK = A.over() # optional - sage.rings.number_field + sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + Fraction Field of + Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: TestSuite(K).run() + sage: TestSuite(K).run() # optional - sage.rings.number_field """ RingExtension_generic.__init__(self, defining_morphism, **kwargs) @@ -2026,15 +2027,15 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) - sage: OK = A.over() - sage: K = OK.fraction_field() - sage: K - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: OK = A.over() # optional - sage.rings.number_field + sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + Fraction Field of + Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: K.ring() + sage: K.ring() # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: K.ring() is OK + sage: K.ring() is OK # optional - sage.rings.number_field True """ return self._ring @@ -2046,11 +2047,11 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) - sage: OK = A.over() - sage: K = OK.fraction_field() + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: OK = A.over() # optional - sage.rings.number_field + sage: K = OK.fraction_field() # optional - sage.rings.number_field - sage: K._repr_topring() + sage: K._repr_topring() # optional - sage.rings.number_field 'Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2' """ if isinstance(self._ring, RingExtension_generic): @@ -2090,11 +2091,10 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: E = GF(5^4).over(GF(5^2)) - sage: E + sage: E = GF(5^4).over(GF(5^2)); E # optional - sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: TestSuite(E).run() + sage: TestSuite(E).run() # optional - sage.rings.finite_rings """ Element = RingExtensionWithBasisElement @@ -2117,12 +2117,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^3 - 2) - sage: E = K.over() - sage: E + sage: K. = QQ.extension(x^3 - 2) # optional - sage.rings.number_field + sage: E = K.over(); E # optional - sage.rings.number_field Field in a with defining polynomial x^3 - 2 over its base - sage: TestSuite(E).run() + sage: TestSuite(E).run() # optional - sage.rings.number_field """ RingExtension_generic.__init__(self, defining_morphism, **kwargs) self._basis = [ self(b) for b in basis ] @@ -2162,26 +2161,26 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: F = GF(5) - sage: K = GF(5^2).over(F) - sage: L = GF(5^4).over(K) + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K = GF(5^2).over(F) # optional - sage.rings.finite_rings + sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: L._print_option_base(F) is F + sage: L._print_option_base(F) is F # optional - sage.rings.finite_rings True - sage: L._print_option_base(K) is K + sage: L._print_option_base(K) is K # optional - sage.rings.finite_rings True - sage: L._print_option_base(GF(5^2)) is K + sage: L._print_option_base(GF(5^2)) is K # optional - sage.rings.finite_rings True - sage: L._print_option_base(None) is K + sage: L._print_option_base(None) is K # optional - sage.rings.finite_rings True - sage: L._print_option_base(L) + sage: L._print_option_base(L) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: base must be strict - sage: K._print_option_base(L) + sage: K._print_option_base(L) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base @@ -2236,8 +2235,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: K = GF(5^2).over() # over GF(5) - sage: K.is_finite_over() # indirect doctest + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.is_finite_over() # indirect doctest # optional - sage.rings.finite_rings True """ if base is self or base is self._base: @@ -2255,8 +2254,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: K = GF(5^2).over() # over GF(5) - sage: K.is_free_over() # indirect doctest + sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.is_free_over() # indirect doctest # optional - sage.rings.finite_rings True """ if base is self or base is self._base: @@ -2274,32 +2273,32 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: - sage: F. = GF(5^2).over() # over GF(5) - sage: K. = GF(5^4).over(F) - sage: L. = GF(5^12).over(K) + sage: F. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: L.basis_over(K) + sage: L.basis_over(K) # optional - sage.rings.finite_rings [1, c, c^2] - sage: L.basis_over(F) + sage: L.basis_over(F) # optional - sage.rings.finite_rings [1, b, c, b*c, c^2, b*c^2] - sage: L.basis_over(GF(5)) + sage: L.basis_over(GF(5)) # optional - sage.rings.finite_rings [1, a, b, a*b, c, a*c, b*c, a*b*c, c^2, a*c^2, b*c^2, a*b*c^2] If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: L.basis_over() + sage: L.basis_over() # optional - sage.rings.finite_rings [1, c, c^2] - sage: K.basis_over() + sage: K.basis_over() # optional - sage.rings.finite_rings [1, b] Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: L.degree_over(GF(5^6)) + sage: L.degree_over(GF(5^6)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z6 of size 5^6 @@ -2358,54 +2357,60 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: - sage: F = GF(11) - sage: K. = GF(11^2).over() - sage: L. = GF(11^6).over(K) + sage: F = GF(11) # optional - sage.rings.finite_rings + sage: K. = GF(11^2).over() # optional - sage.rings.finite_rings + sage: L. = GF(11^6).over(K) # optional - sage.rings.finite_rings Forgetting a part of the multiplicative structure, the field L can be viewed as a vector space of dimension 3 over K, equipped with a distinguished basis, namely `(1, b, b^2)`:: - sage: V, i, j = L.free_module(K) - sage: V - Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base - sage: i + sage: V, i, j = L.free_module(K) # optional - sage.rings.finite_rings + sage: V # optional - sage.rings.finite_rings + Vector space of dimension 3 over + Field in a with defining polynomial x^2 + 7*x + 2 over its base + sage: i # optional - sage.rings.finite_rings Generic map: - From: Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base - To: Field in b with defining polynomial x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base - sage: j + From: Vector space of dimension 3 over + Field in a with defining polynomial x^2 + 7*x + 2 over its base + To: Field in b with defining polynomial + x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base + sage: j # optional - sage.rings.finite_rings Generic map: - From: Field in b with defining polynomial x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base - To: Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base + From: Field in b with defining polynomial + x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base + To: Vector space of dimension 3 over + Field in a with defining polynomial x^2 + 7*x + 2 over its base - sage: j(b) + sage: j(b) # optional - sage.rings.finite_rings (0, 1, 0) - sage: i((1, a, a+1)) + sage: i((1, a, a+1)) # optional - sage.rings.finite_rings 1 + a*b + (1 + a)*b^2 Similarly, one can view L as a F-vector space of dimension 6:: - sage: V, i, j, = L.free_module(F) - sage: V + sage: V, i, j, = L.free_module(F) # optional - sage.rings.finite_rings + sage: V # optional - sage.rings.finite_rings Vector space of dimension 6 over Finite Field of size 11 In this case, the isomorphisms between `V` and `L` are given by the basis `(1, a, b, ab, b^2, ab^2)`: - sage: j(a*b) + sage: j(a*b) # optional - sage.rings.finite_rings (0, 0, 0, 1, 0, 0) - sage: i((1,2,3,4,5,6)) + sage: i((1,2,3,4,5,6)) # optional - sage.rings.finite_rings (1 + 2*a) + (3 + 4*a)*b + (5 + 6*a)*b^2 When ``base`` is omitted, the default is the base of this extension:: - sage: L.free_module(map=False) - Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base + sage: L.free_module(map=False) # optional - sage.rings.finite_rings + Vector space of dimension 3 over + Field in a with defining polynomial x^2 + 7*x + 2 over its base Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: L.degree(GF(11^3)) + sage: L.degree(GF(11^3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z3 of size 11^3 @@ -2441,9 +2446,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: K = GF(7^5).over() - sage: L = GF(7^15).over(K) - sage: for base in L.bases(): + sage: K = GF(7^5).over() # optional - sage.rings.finite_rings + sage: L = GF(7^15).over(K) # optional - sage.rings.finite_rings + sage: for base in L.bases(): # optional - sage.rings.finite_rings ....: V, i, j = L.free_module(base) ....: assert([ i(v) for v in V.basis() ] == L.basis_over(base)) ....: assert([ j(x) for x in L.basis_over(base) ] == V.basis()) @@ -2477,43 +2482,45 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) - sage: OK = A.over() # over ZZ - sage: OK + sage: A. = ZZ.extension(x^2 - 5) # optional - sage.rings.number_field + sage: OK = A.over() # over ZZ # optional - sage.rings.number_field + sage: OK # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1 = OK.fraction_field() - sage: K1 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + sage: K1 = OK.fraction_field(); K1 # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base + sage: K1.bases() # optional - sage.rings.number_field + [Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - sage: K2 = OK.fraction_field(extend_base=True) - sage: K2 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + sage: K2 = OK.fraction_field(extend_base=True); K2 # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base + sage: K2.bases() # optional - sage.rings.number_field + [Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base, Rational Field] Note that there is no coercion map between `K_1` and `K_2`:: - sage: K1.has_coerce_map_from(K2) + sage: K1.has_coerce_map_from(K2) # optional - sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) + sage: K2.has_coerce_map_from(K1) # optional - sage.rings.number_field False We check that when the extension is a field, its fraction field does not change:: - sage: K1.fraction_field() is K1 + sage: K1.fraction_field() is K1 # optional - sage.rings.number_field True - sage: K2.fraction_field() is K2 + sage: K2.fraction_field() is K2 # optional - sage.rings.number_field True TESTS:: - sage: A = GF(5).over(ZZ) + sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings sage: A.fraction_field(extend_base=True) Traceback (most recent call last): ... @@ -2544,13 +2551,13 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^3 - 7) - sage: K = A.over() + sage: A. = QQ.extension(x^3 - 7) # optional - sage.rings.number_field + sage: K = A.over() # optional - sage.rings.number_field - sage: type(K) + sage: type(K) # optional - sage.rings.number_field - sage: TestSuite(K).run() + sage: TestSuite(K).run() # optional - sage.rings.number_field """ def __init__(self, defining_morphism, gen, names, check=True, **kwargs): @@ -2572,12 +2579,11 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^3 + 3*x + 1) - sage: E = K.over() - sage: E + sage: K. = QQ.extension(x^3 + 3*x + 1) # optional - sage.rings.number_field + sage: E = K.over(); E # optional - sage.rings.number_field Field in a with defining polynomial x^3 + 3*x + 1 over its base - sage: TestSuite(E).run() + sage: TestSuite(E).run() # optional - sage.rings.number_field """ self._name = names[0] backend_base = backend_parent(defining_morphism.domain()) @@ -2604,12 +2610,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^3).over() - sage: K._repr_topring() + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: K._repr_topring() # optional - sage.rings.finite_rings 'Field in a with defining polynomial x^3 + 3*x + 3' - sage: L. = GF(5^9).over(K) - sage: L._repr_topring() + sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings + sage: L._repr_topring() # optional - sage.rings.finite_rings 'Field in b with defining polynomial x^3 + (1 + 3*a^2)*x^2 + (3 + 2*a + 2*a^2)*x - a' """ if self._name is None: @@ -2622,12 +2628,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^3).over() - sage: K._latex_topring() + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: K._latex_topring() # optional - sage.rings.finite_rings '\\Bold{F}_{5}[a]' - sage: L. = GF(5^9).over(K) - sage: L._latex_topring() + sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings + sage: L._latex_topring() # optional - sage.rings.finite_rings '\\Bold{F}_{5}[a][b]' """ if self._name is None: @@ -2648,18 +2654,18 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(7^10).over(GF(7^2)) - sage: K - Field in u with defining polynomial x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 over its base + sage: K. = GF(7^10).over(GF(7^2)); K # optional - sage.rings.finite_rings + Field in u with defining polynomial x^5 + (6*z2 + 4)*x^4 + + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 over its base - sage: P = K.modulus(); P + sage: P = K.modulus(); P # optional - sage.rings.finite_rings x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 - sage: P(u) + sage: P(u) # optional - sage.rings.finite_rings 0 We can use a different variable name:: - sage: K.modulus('y') + sage: K.modulus('y') # optional - sage.rings.finite_rings y^5 + (6*z2 + 4)*y^4 + (3*z2 + 5)*y^3 + (2*z2 + 2)*y^2 + 4*y + 6*z2 """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -2680,14 +2686,14 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: K.gens() + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K.gens() # optional - sage.rings.finite_rings (a,) - sage: L. = GF(5^4).over(K) - sage: L.gens() + sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: L.gens() # optional - sage.rings.finite_rings (b,) - sage: L.gens(GF(5)) + sage: L.gens(GF(5)) # optional - sage.rings.finite_rings (b, a) """ if base is None: @@ -2722,43 +2728,45 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) - sage: OK = A.over() # over ZZ - sage: OK + sage: A. = ZZ.extension(x^2 - 5) # optional - sage.rings.number_field + sage: OK = A.over() # over ZZ # optional - sage.rings.number_field + sage: OK # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1 = OK.fraction_field() - sage: K1 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + sage: K1 = OK.fraction_field(); K1 # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base + sage: K1.bases() # optional - sage.rings.number_field + [Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - sage: K2 = OK.fraction_field(extend_base=True) - sage: K2 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + sage: K2 = OK.fraction_field(extend_base=True); K2 # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base + sage: K2.bases() # optional - sage.rings.number_field + [Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 5 over its base, Rational Field] Note that there is no coercion map between `K_1` and `K_2`:: - sage: K1.has_coerce_map_from(K2) + sage: K1.has_coerce_map_from(K2) # optional - sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) + sage: K2.has_coerce_map_from(K1) # optional - sage.rings.number_field False We check that when the extension is a field, its fraction field does not change:: - sage: K1.fraction_field() is K1 + sage: K1.fraction_field() is K1 # optional - sage.rings.number_field True - sage: K2.fraction_field() is K2 + sage: K2.fraction_field() is K2 # optional - sage.rings.number_field True TESTS:: - sage: A = GF(5).over(ZZ) + sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings sage: A.fraction_field(extend_base=True) Traceback (most recent call last): ... diff --git a/src/sage/rings/ring_extension_conversion.pyx b/src/sage/rings/ring_extension_conversion.pyx index 9d94fb7567d..6ea90ddbdb5 100644 --- a/src/sage/rings/ring_extension_conversion.pyx +++ b/src/sage/rings/ring_extension_conversion.pyx @@ -1,3 +1,5 @@ +# sage.doctest: optional - sage.rings.finite_rings + ############################################################################# # Copyright (C) 2019 Xavier Caruso # diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 4b1809a8db5..aa6bfc45be3 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -43,9 +43,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over() - sage: x = K.random_element() - sage: TestSuite(x).run() + sage: K = GF(5^4).over() # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: TestSuite(x).run() # optional - sage.rings.finite_rings """ def __init__(self, RingExtension_generic parent, x, *args, **kwds): @@ -86,11 +86,11 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^3).over() - sage: x = K.random_element() - sage: type(x) + sage: K = GF(5^3).over() # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: type(x) # optional - sage.rings.finite_rings - sage: loads(dumps(x)) == x + sage: loads(dumps(x)) == x # optional - sage.rings.finite_rings True """ return self._parent, (self._backend,) @@ -173,8 +173,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES: - sage: E. = GF(5^3).over() - sage: hash(a) + sage: E. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: hash(a) # optional - sage.rings.finite_rings 5 """ return hash(self._backend) @@ -188,9 +188,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K. = GF(5^2).over() - sage: L. = GF(5^4).over(K) - sage: b._repr_() + sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: b._repr_() # optional - sage.rings.finite_rings 'b' """ cdef RingExtension_generic parent = self._parent @@ -232,9 +232,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K. = GF(5^2).over() - sage: L. = GF(5^4).over(K) - sage: b._latex_() + sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: b._latex_() # optional - sage.rings.finite_rings 'b' """ cdef RingExtension_generic parent = self._parent @@ -370,13 +370,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^2).over() - sage: x = K.random_element() - sage: x == x + sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: x == x # optional - sage.rings.finite_rings True - sage: x == x + 1 + sage: x == x + 1 # optional - sage.rings.finite_rings False - sage: x == x^25 + sage: x == x^25 # optional - sage.rings.finite_rings True """ return left._backend._richcmp_(backend_element(right), op) @@ -387,13 +387,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) - sage: x = K.random_element() - sage: y = K.random_element() + sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: y = K.random_element() # optional - sage.rings.finite_rings - sage: (x+y).parent() is K + sage: (x+y).parent() is K # optional - sage.rings.finite_rings True - sage: x + y == y + x + sage: x + y == y + x # optional - sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -407,13 +407,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) - sage: x = K.random_element() + sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: y = -x - sage: y.parent() is K + sage: y = -x # optional - sage.rings.finite_rings + sage: y.parent() is K # optional - sage.rings.finite_rings True - sage: x + y == 0 + sage: x + y == 0 # optional - sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -427,13 +427,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) - sage: x = K.random_element() - sage: y = K.random_element() + sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: y = K.random_element() # optional - sage.rings.finite_rings - sage: (x-y).parent() is K + sage: (x-y).parent() is K # optional - sage.rings.finite_rings True - sage: x - y == x + (-y) + sage: x - y == x + (-y) # optional - sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -447,13 +447,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) - sage: x = K.random_element() - sage: y = K.random_element() + sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: y = K.random_element() # optional - sage.rings.finite_rings - sage: (x*y).parent() is K + sage: (x*y).parent() is K # optional - sage.rings.finite_rings True - sage: x * y == y * x + sage: x * y == y * x # optional - sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -469,15 +469,16 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) - sage: OK = A.over() - sage: a = OK(a) + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: OK = A.over() # optional - sage.rings.number_field + sage: a = OK(a) # optional - sage.rings.number_field - sage: b = 1/a; b + sage: b = 1/a; b # optional - sage.rings.number_field a/2 - sage: b.parent() - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: a*b + sage: b.parent() # optional - sage.rings.number_field + Fraction Field of + Order in Number Field in a with defining polynomial x^2 - 2 over its base + sage: a*b # optional - sage.rings.number_field 1 """ cdef RingExtensionElement ans @@ -496,8 +497,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^4).over(GF(5^2)) - sage: a.additive_order() + sage: K. = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: a.additive_order() # optional - sage.rings.finite_rings 5 """ return self._backend.additive_order() @@ -508,8 +509,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^4).over(GF(5^2)) - sage: a.multiplicative_order() + sage: K. = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 624 """ return self._backend.multiplicative_order() @@ -570,16 +571,16 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^3).over() - sage: a.is_square() + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: a.is_square() # optional - sage.rings.finite_rings False - sage: a.is_square(root=True) + sage: a.is_square(root=True) # optional - sage.rings.finite_rings (False, None) - sage: b = a + 1 - sage: b.is_square() + sage: b = a + 1 # optional - sage.rings.finite_rings + sage: b.is_square() # optional - sage.rings.finite_rings True - sage: b.is_square(root=True) + sage: b.is_square(root=True) # optional - sage.rings.finite_rings (True, 2 + 3*a + a^2) """ is_sq = self._backend.is_square() @@ -599,7 +600,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): - ``extend`` -- a boolean (default: ``True``); if "True", return a square root in an extension ring, if necessary. - Otherwise, raise a ``ValueError`` if the root is not in + Otherwise, raise a :class:`ValueError` if the root is not in the ring - ``all`` -- a boolean (default: ``False``); if ``True``, @@ -610,15 +611,15 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): .. NOTE:: - The option `extend=True` is often not implemented. + The option ``extend=True`` is often not implemented. EXAMPLES:: - sage: K. = GF(5^3).over() - sage: b = a + 1 - sage: b.sqrt() + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: b = a + 1 # optional - sage.rings.finite_rings + sage: b.sqrt() # optional - sage.rings.finite_rings 2 + 3*a + a^2 - sage: b.sqrt(all=True) + sage: b.sqrt(all=True) # optional - sage.rings.finite_rings [2 + 3*a + a^2, 3 + 2*a - a^2] """ sq = self._backend.sqrt(extend=extend, all=all) @@ -664,8 +665,8 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES: - sage: E. = GF(5^3).over() - sage: hash(a) + sage: E. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: hash(a) # optional - sage.rings.finite_rings 5 """ return hash(self._backend) @@ -745,29 +746,29 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) - sage: OK = A.over() # over ZZ - sage: K = OK.fraction_field() - sage: K - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: OK = A.over() # over ZZ # optional - sage.rings.number_field + sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 2 over its base - sage: x = K(1/a); x + sage: x = K(1/a); x # optional - sage.rings.number_field a/2 - sage: num = x.numerator(); num + sage: num = x.numerator(); num # optional - sage.rings.number_field a The numerator is an element of the ring which was used to construct the fraction field:: - sage: num.parent() + sage: num.parent() # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: num.parent() is OK + sage: num.parent() is OK # optional - sage.rings.number_field True TESTS:: - sage: x = K.random_element() - sage: x == x.numerator() / x.denominator() + sage: x = K.random_element() # optional - sage.rings.number_field + sage: x == x.numerator() / x.denominator() # optional - sage.rings.number_field True """ ring = (self._parent)._ring @@ -781,29 +782,29 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: sage: R. = ZZ[] - sage: A. = ZZ.extension(x^2 - 2) - sage: OK = A.over() # over ZZ - sage: K = OK.fraction_field() - sage: K - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: OK = A.over() # over ZZ # optional - sage.rings.number_field + sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + Fraction Field of Order in Number Field in a + with defining polynomial x^2 - 2 over its base - sage: x = K(1/a); x + sage: x = K(1/a); x # optional - sage.rings.number_field a/2 - sage: denom = x.denominator(); denom + sage: denom = x.denominator(); denom # optional - sage.rings.number_field 2 The denominator is an element of the ring which was used to construct the fraction field:: - sage: denom.parent() + sage: denom.parent() # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: denom.parent() is OK + sage: denom.parent() is OK # optional - sage.rings.number_field True TESTS:: - sage: x = K.random_element() - sage: x == x.numerator() / x.denominator() + sage: x = K.random_element() # optional - sage.rings.number_field + sage: x == x.numerator() / x.denominator() # optional - sage.rings.number_field True """ ring = (self._parent)._ring @@ -820,11 +821,11 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: K. = GF(5^3).over() - sage: L. = GF(5^9).over(K) - sage: type(b) + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings + sage: type(b) # optional - sage.rings.finite_rings - sage: TestSuite(b).run() + sage: TestSuite(b).run() # optional - sage.rings.finite_rings """ def __hash__(self): """ @@ -832,8 +833,8 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES: - sage: E. = GF(5^3).over() - sage: hash(a) + sage: E. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: hash(a) # optional - sage.rings.finite_rings 5 """ return hash(self._backend) @@ -851,13 +852,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() - sage: L. = GF(5^9).over(K) - sage: u = 1/(a+b) + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings + sage: u = 1/(a+b) # optional - sage.rings.finite_rings - sage: u._repr_extension(base=K) + sage: u._repr_extension(base=K) # optional - sage.rings.finite_rings '(2 + 2*a) + (-1 + a - a^2)*b + (2 + 3*a + 3*a^2)*b^2' - sage: u._repr_extension(base=GF(5)) + sage: u._repr_extension(base=GF(5)) # optional - sage.rings.finite_rings '2 + 2*a - b + a*b - a^2*b + 2*b^2 + 3*a*b^2 + 3*a^2*b^2' """ cdef RingExtensionWithBasis parent = self._parent @@ -929,13 +930,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() - sage: L. = GF(5^9).over(K) - sage: u = 1/(a+b) + sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings + sage: u = 1/(a+b) # optional - sage.rings.finite_rings - sage: u._latex_extension(base=K) + sage: u._latex_extension(base=K) # optional - sage.rings.finite_rings \left( 2 + 2 a \right) + \left( -1 + a - a^{2} \right) b + \left( 2 + 3 a + 3 a^{2} \right) b^{2} - sage: u._latex_extension(base=GF(5)) + sage: u._latex_extension(base=GF(5)) # optional - sage.rings.finite_rings 2 + 2 a - b + ab - a^{2}b + 2 b^{2} + 3 ab^{2} + 3 a^{2}b^{2} """ cdef RingExtensionWithBasis parent = self._parent @@ -995,28 +996,28 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) - sage: K. = GF(5^2).over() # over F - sage: L. = GF(5^6).over(K) - sage: x = (a+b)^4; x + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over F # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: x = (a+b)^4; x # optional - sage.rings.finite_rings (-1 + a) + (3 + a)*b + (1 - a)*b^2 - sage: x.vector(K) # basis is (1, b, b^2) + sage: x.vector(K) # basis is (1, b, b^2) # optional - sage.rings.finite_rings (-1 + a, 3 + a, 1 - a) - sage: x.vector(F) # basis is (1, a, b, a*b, b^2, a*b^2) + sage: x.vector(F) # basis is (1, a, b, a*b, b^2, a*b^2) # optional - sage.rings.finite_rings (4, 1, 3, 1, 1, 4) If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: x.vector() + sage: x.vector() # optional - sage.rings.finite_rings (-1 + a, 3 + a, 1 - a) Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: x.vector(GF(5^3)) + sage: x.vector(GF(5^3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3 @@ -1036,11 +1037,11 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: K = GF(11^10).over(GF(11^2)) - sage: x = K.random_element() - sage: coeffs = x.vector() - sage: basis = K.basis_over() - sage: x == sum(coeffs[i]*basis[i] for i in range(5)) + sage: K = GF(11^10).over(GF(11^2)) # optional - sage.rings.finite_rings + sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: coeffs = x.vector() # optional - sage.rings.finite_rings + sage: basis = K.basis_over() # optional - sage.rings.finite_rings + sage: x == sum(coeffs[i]*basis[i] for i in range(5)) # optional - sage.rings.finite_rings True """ _, _, j = (self._parent)._free_module(base, map=True) @@ -1059,55 +1060,55 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F. = GF(5^2).over() # over GF(5) - sage: K. = GF(5^4).over(F) - sage: L. = GF(5^12).over(K) - sage: u = 1/(a + b + c); u + sage: F. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^4).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: u = 1/(a + b + c); u # optional - sage.rings.finite_rings (2 + (-1 - a)*b) + ((2 + 3*a) + (1 - a)*b)*c + ((-1 - a) - a*b)*c^2 - sage: P = u.polynomial(K); P + sage: P = u.polynomial(K); P # optional - sage.rings.finite_rings ((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b - sage: P.base_ring() is K + sage: P.base_ring() is K # optional - sage.rings.finite_rings True - sage: P(c) == u + sage: P(c) == u # optional - sage.rings.finite_rings True When the base is `F`, we obtain a bivariate polynomial:: - sage: P = u.polynomial(F); P + sage: P = u.polynomial(F); P # optional - sage.rings.finite_rings (-a)*x0^2*x1 + (-1 - a)*x0^2 + (1 - a)*x0*x1 + (2 + 3*a)*x0 + (-1 - a)*x1 + 2 We check that its value at the generators is the element we started with:: - sage: L.gens(F) + sage: L.gens(F) # optional - sage.rings.finite_rings (c, b) - sage: P(c, b) == u + sage: P(c, b) == u # optional - sage.rings.finite_rings True Similarly, when the base is ``GF(5)``, we get a trivariate polynomial: - sage: P = u.polynomial(GF(5)); P + sage: P = u.polynomial(GF(5)); P # optional - sage.rings.finite_rings -x0^2*x1*x2 - x0^2*x2 - x0*x1*x2 - x0^2 + x0*x1 - 2*x0*x2 - x1*x2 + 2*x0 - x1 + 2 - sage: P(c, b, a) == u + sage: P(c, b, a) == u # optional - sage.rings.finite_rings True Different variable names can be specified:: - sage: u.polynomial(GF(5), var='y') + sage: u.polynomial(GF(5), var='y') # optional - sage.rings.finite_rings -y0^2*y1*y2 - y0^2*y2 - y0*y1*y2 - y0^2 + y0*y1 - 2*y0*y2 - y1*y2 + 2*y0 - y1 + 2 - sage: u.polynomial(GF(5), var=['x','y','z']) + sage: u.polynomial(GF(5), var=['x','y','z']) # optional - sage.rings.finite_rings -x^2*y*z - x^2*z - x*y*z - x^2 + x*y - 2*x*z - y*z + 2*x - y + 2 If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.polynomial() + sage: u.polynomial() # optional - sage.rings.finite_rings ((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.polynomial(GF(5^3)) + sage: u.polynomial(GF(5^3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3 @@ -1148,19 +1149,19 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # over GF(5) - sage: L. = GF(5^6).over(K) - sage: u = a/(1+b) + sage: K. = GF(5^3).over() # over GF(5) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: u = a/(1+b) # optional - sage.rings.finite_rings - sage: u + sage: u # optional - sage.rings.finite_rings (2 + a + 3*a^2) + (3 + 3*a + a^2)*b - sage: b*u + sage: b*u # optional - sage.rings.finite_rings (3 + 2*a^2) + (2 + 2*a - a^2)*b - sage: u.matrix(K) + sage: u.matrix(K) # optional - sage.rings.finite_rings [2 + a + 3*a^2 3 + 3*a + a^2] [ 3 + 2*a^2 2 + 2*a - a^2] - sage: u.matrix(GF(5)) + sage: u.matrix(GF(5)) # optional - sage.rings.finite_rings [2 1 3 3 3 1] [1 3 1 2 0 3] [2 3 3 1 3 0] @@ -1171,14 +1172,14 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.matrix() + sage: u.matrix() # optional - sage.rings.finite_rings [2 + a + 3*a^2 3 + 3*a + a^2] [ 3 + 2*a^2 2 + 2*a - a^2] Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.matrix(GF(5^2)) + sage: u.matrix(GF(5^2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1204,11 +1205,11 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) - sage: K = GF(11^6).over(F) - sage: L = GF(11^18).over(K) + sage: F = GF(11^2) # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(F) # optional - sage.rings.finite_rings + sage: L = GF(11^18).over(K) # optional - sage.rings.finite_rings - sage: for base in L.bases(): + sage: for base in L.bases(): # optional - sage.rings.finite_rings ....: x = L.random_element() ....: y = L.random_element() ....: assert((x+y).matrix(base) == x.matrix(base) + y.matrix(base)) @@ -1232,41 +1233,41 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) - sage: K. = GF(5^3).over(F) - sage: L. = GF(5^6).over(K) - sage: u = a/(1+b) + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: u = a/(1+b) # optional - sage.rings.finite_rings - sage: tr = u.trace(K); tr + sage: tr = u.trace(K); tr # optional - sage.rings.finite_rings -1 + 3*a + 2*a^2 We check that the trace lives in the base ring:: - sage: tr.parent() + sage: tr.parent() # optional - sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: tr.parent() is K + sage: tr.parent() is K # optional - sage.rings.finite_rings True Similarly, one can compute the trace over F:: - sage: u.trace(F) + sage: u.trace(F) # optional - sage.rings.finite_rings 0 We check the transitivity of the trace:: - sage: u.trace(F) == tr.trace(F) + sage: u.trace(F) == tr.trace(F) # optional - sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.trace() + sage: u.trace() # optional - sage.rings.finite_rings -1 + 3*a + 2*a^2 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.trace(GF(5^2)) + sage: u.trace(GF(5^2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1291,15 +1292,15 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) - sage: K = GF(11^6).over(F) - sage: L = GF(11^18).over(K) + sage: F = GF(11^2) # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(F) # optional - sage.rings.finite_rings + sage: L = GF(11^18).over(K) # optional - sage.rings.finite_rings - sage: x = L.random_element() - sage: x.trace(F) == x.trace().trace() + sage: x = L.random_element() # optional - sage.rings.finite_rings + sage: x.trace(F) == x.trace().trace() # optional - sage.rings.finite_rings True - sage: for base in L.bases(): + sage: for base in L.bases(): # optional - sage.rings.finite_rings ....: x = L.random_element() ....: y = L.random_element() ....: assert(x.trace(base) == x.matrix(base).trace()) @@ -1326,41 +1327,41 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) - sage: K. = GF(5^3).over(F) - sage: L. = GF(5^6).over(K) - sage: u = a/(1+b) + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: u = a/(1+b) # optional - sage.rings.finite_rings - sage: nr = u.norm(K); nr + sage: nr = u.norm(K); nr # optional - sage.rings.finite_rings 3 + 2*a^2 We check that the norm lives in the base ring:: - sage: nr.parent() + sage: nr.parent() # optional - sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: nr.parent() is K + sage: nr.parent() is K # optional - sage.rings.finite_rings True Similarly, one can compute the norm over F:: - sage: u.norm(F) + sage: u.norm(F) # optional - sage.rings.finite_rings 4 We check the transitivity of the norm:: - sage: u.norm(F) == nr.norm(F) + sage: u.norm(F) == nr.norm(F) # optional - sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.norm() + sage: u.norm() # optional - sage.rings.finite_rings 3 + 2*a^2 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.norm(GF(5^2)) + sage: u.norm(GF(5^2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1385,15 +1386,15 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) - sage: K = GF(11^6).over(F) - sage: L = GF(11^18).over(K) + sage: F = GF(11^2) # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(F) # optional - sage.rings.finite_rings + sage: L = GF(11^18).over(K) # optional - sage.rings.finite_rings - sage: x = L.random_element() - sage: x.norm(F) == x.norm().norm() + sage: x = L.random_element() # optional - sage.rings.finite_rings + sage: x.norm(F) == x.norm().norm() # optional - sage.rings.finite_rings True - sage: for base in L.bases(): + sage: for base in L.bases(): # optional - sage.rings.finite_rings ....: x = L.random_element() ....: y = L.random_element() ....: assert(x.norm(base) == x.matrix(base).determinant()) @@ -1420,46 +1421,46 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) - sage: K. = GF(5^3).over(F) - sage: L. = GF(5^6).over(K) - sage: u = a/(1+b) + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: u = a/(1+b) # optional - sage.rings.finite_rings - sage: chi = u.charpoly(K); chi + sage: chi = u.charpoly(K); chi # optional - sage.rings.finite_rings x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2 We check that the charpoly has coefficients in the base ring:: - sage: chi.base_ring() + sage: chi.base_ring() # optional - sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: chi.base_ring() is K + sage: chi.base_ring() is K # optional - sage.rings.finite_rings True and that it annihilates u:: - sage: chi(u) + sage: chi(u) # optional - sage.rings.finite_rings 0 Similarly, one can compute the characteristic polynomial over F:: - sage: u.charpoly(F) + sage: u.charpoly(F) # optional - sage.rings.finite_rings x^6 + x^4 + 2*x^3 + 3*x + 4 A different variable name can be specified:: - sage: u.charpoly(F, var='t') + sage: u.charpoly(F, var='t') # optional - sage.rings.finite_rings t^6 + t^4 + 2*t^3 + 3*t + 4 If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.charpoly() + sage: u.charpoly() # optional - sage.rings.finite_rings x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.charpoly(GF(5^2)) + sage: u.charpoly(GF(5^2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1469,9 +1470,9 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): We check that the characteristic polynomial of an element in the base ring is a power of a polynomial of degree 1:: - sage: S. = K[] - sage: u = K.random_element() - sage: L(u).charpoly() == (x - u)^2 + sage: S. = K[] # optional - sage.rings.finite_rings + sage: u = K.random_element() # optional - sage.rings.finite_rings + sage: L(u).charpoly() == (x - u)^2 # optional - sage.rings.finite_rings True """ return self.matrix(base).charpoly(var) @@ -1487,46 +1488,46 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) - sage: K. = GF(5^3).over(F) - sage: L. = GF(5^6).over(K) - sage: u = 1 / (a+b) + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: u = 1 / (a+b) # optional - sage.rings.finite_rings - sage: chi = u.minpoly(K); chi + sage: chi = u.minpoly(K); chi # optional - sage.rings.finite_rings x^2 + (2*a + a^2)*x - 1 + a We check that the minimal polynomial has coefficients in the base ring:: - sage: chi.base_ring() + sage: chi.base_ring() # optional - sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: chi.base_ring() is K + sage: chi.base_ring() is K # optional - sage.rings.finite_rings True and that it annihilates u:: - sage: chi(u) + sage: chi(u) # optional - sage.rings.finite_rings 0 Similarly, one can compute the minimal polynomial over F:: - sage: u.minpoly(F) + sage: u.minpoly(F) # optional - sage.rings.finite_rings x^6 + 4*x^5 + x^4 + 2*x^2 + 3 A different variable name can be specified:: - sage: u.minpoly(F, var='t') + sage: u.minpoly(F, var='t') # optional - sage.rings.finite_rings t^6 + 4*t^5 + t^4 + 2*t^2 + 3 If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.minpoly() + sage: u.minpoly() # optional - sage.rings.finite_rings x^2 + (2*a + a^2)*x - 1 + a Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.minpoly(GF(5^2)) + sage: u.minpoly(GF(5^2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1536,15 +1537,15 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): We check that the minimal polynomial of an element in the base ring has degree 1:: - sage: S. = K[] - sage: u = K.random_element() - sage: L(u).minpoly() == x - u + sage: S. = K[] # optional - sage.rings.finite_rings + sage: u = K.random_element() # optional - sage.rings.finite_rings + sage: L(u).minpoly() == x - u # optional - sage.rings.finite_rings True In a similar fashion, the minimal polynomial over `F` of an element of `K` should have degree 1 or 3:: - sage: L(u).minpoly(F).degree() in [ 1, 3 ] + sage: L(u).minpoly(F).degree() in [ 1, 3 ] # optional - sage.rings.finite_rings True """ cdef RingExtensionWithBasis parent = self._parent diff --git a/src/sage/rings/ring_extension_homset.py b/src/sage/rings/ring_extension_homset.py index 28b2b736dd8..65c39803caa 100644 --- a/src/sage/rings/ring_extension_homset.py +++ b/src/sage/rings/ring_extension_homset.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Homset between extensions of rings @@ -29,7 +30,9 @@ class RingExtensionHomset(RingHomset_generic): sage: L = GF(5^8).over(K) sage: H = Hom(K,L) sage: H - Set of Homomorphisms from Field in z2 with defining polynomial x^2 + 4*x + 2 over its base to Field in z8 with defining polynomial x^4 + (3 - z2)*x + z2 over its base + Set of Homomorphisms + from Field in z2 with defining polynomial x^2 + 4*x + 2 over its base + to Field in z8 with defining polynomial x^4 + (3 - z2)*x + z2 over its base sage: type(H) <... 'sage.rings.ring_extension_homset.RingExtensionHomset_with_category'> @@ -44,7 +47,8 @@ def __call__(self, *args, **kwargs): sage: K. = GF(5^2).over() sage: L. = GF(5^4).over(K) sage: Hom(L,L)([b^5, a^5]) - Ring endomorphism of Field in b with defining polynomial x^2 + (3 - a)*x + a over its base + Ring endomorphism of + Field in b with defining polynomial x^2 + (3 - a)*x + a over its base Defn: b |--> (2 + a) + 2*b with map on base ring: a |--> 1 - a diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index 04d2aa4a650..bd5b012cfaa 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -83,19 +83,19 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() - sage: L. = GF(5^4).over(K) - sage: phi = L.hom([b^5, a^5]) - sage: phi - Ring endomorphism of Field in b with defining polynomial x^2 + (3 - a)*x + a over its base + sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: phi = L.hom([b^5, a^5]); phi # optional - sage.rings.finite_rings + Ring endomorphism of Field in b + with defining polynomial x^2 + (3 - a)*x + a over its base Defn: b |--> (2 + a) + 2*b with map on base ring: a |--> 1 - a - sage: type(phi) + sage: type(phi) # optional - sage.rings.finite_rings - sage: TestSuite(phi).run() + sage: TestSuite(phi).run() # optional - sage.rings.finite_rings """ def __init__(self, parent, defn, base_map=None, check=True): @@ -117,8 +117,7 @@ cdef class RingExtensionHomomorphism(RingMap): sage: S. = QQ[] sage: T. = QQ[] - sage: f = T.hom([x^2, y^2]) - sage: f + sage: f = T.hom([x^2, y^2]); f Ring endomorphism of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x^2 y |--> y^2 @@ -220,13 +219,12 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = K.hom([a^5]) - sage: f + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = K.hom([a^5]); f # optional - sage.rings.finite_rings Ring endomorphism of Field in a with defining polynomial x^2 + 4*x + 2 over its base Defn: a |--> 1 - a - sage: f._repr_type() + sage: f._repr_type() # optional - sage.rings.finite_rings 'Ring' """ return "Ring" @@ -242,20 +240,19 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: A. = QQ.extension(x^2 - 2) - sage: K. = A.over() - sage: f = K.hom([-sqrt2]) - sage: f + sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: K. = A.over() # optional - sage.rings.number_field + sage: f = K.hom([-sqrt2]); f # optional - sage.rings.number_field Ring endomorphism of Field in sqrt2 with defining polynomial x^2 - 2 over its base Defn: sqrt2 |--> -sqrt2 - sage: f(sqrt2) + sage: f(sqrt2) # optional - sage.rings.number_field -sqrt2 TESTS:: sage: a = QQ.random_element() sage: b = QQ.random_element() - sage: f(a + b*sqrt2) == a - b*sqrt2 + sage: f(a + b*sqrt2) == a - b*sqrt2 # optional - sage.rings.number_field True """ y = self._backend(backend_element(x)) @@ -271,19 +268,19 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: F = GF(5) - sage: K. = GF(5^2).over(F) - sage: L. = GF(5^6).over(K) + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over(F) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings We define the absolute Frobenius of L:: - sage: FrobL = L.hom([b^5, a^5]) - sage: FrobL - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + sage: FrobL = L.hom([b^5, a^5]); FrobL # optional - sage.rings.finite_rings + Ring endomorphism of + Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a - sage: FrobL.base_map() + sage: FrobL.base_map() # optional - sage.rings.finite_rings Ring morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base @@ -292,11 +289,11 @@ cdef class RingExtensionHomomorphism(RingMap): The square of ``FrobL`` acts trivially on K; in other words, it has a trivial base map:: - sage: phi = FrobL^2 - sage: phi - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + sage: phi = FrobL^2; phi # optional - sage.rings.finite_rings + Ring endomorphism of + Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> 2 + 2*a*b + (2 - a)*b^2 - sage: phi.base_map() + sage: phi.base_map() # optional - sage.rings.finite_rings """ domain = self.domain() @@ -335,15 +332,15 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) - sage: L. = GF(5^6).over(K) + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: FrobK = K.hom([a^5]) - sage: FrobL = L.hom([b^5], base_map=FrobK) + sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings + sage: FrobL = L.hom([b^5], base_map=FrobK) # optional - sage.rings.finite_rings - sage: FrobK^2 == End(K).identity() + sage: FrobK^2 == End(K).identity() # optional - sage.rings.finite_rings True - sage: FrobL^6 == End(L).identity() + sage: FrobL^6 == End(L).identity() # optional - sage.rings.finite_rings True """ eq = are_equal_morphisms(self._backend, backend_morphism(other)) @@ -359,23 +356,22 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: FrobK = K.hom([a^5]) - sage: FrobK.is_identity() + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings + sage: FrobK.is_identity() # optional - sage.rings.finite_rings False - sage: (FrobK^2).is_identity() + sage: (FrobK^2).is_identity() # optional - sage.rings.finite_rings True Coercion maps are not considered as identity morphisms:: - sage: L. = GF(5^6).over(K) - sage: iota = L.defining_morphism() - sage: iota + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: iota = L.defining_morphism(); iota # optional - sage.rings.finite_rings Ring morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: a |--> a - sage: iota.is_identity() + sage: iota.is_identity() # optional - sage.rings.finite_rings False """ if self.domain() is not self.codomain(): @@ -388,24 +384,23 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K = GF(5^10).over(GF(5^5)) - sage: iota = K.defining_morphism() - sage: iota + sage: K = GF(5^10).over(GF(5^5)) # optional - sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in z5 of size 5^5 - To: Field in z10 with defining polynomial x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base + To: Field in z10 with defining polynomial + x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base Defn: z5 |--> z5 - sage: iota.is_injective() + sage: iota.is_injective() # optional - sage.rings.finite_rings True - sage: K = GF(7).over(ZZ) - sage: iota = K.defining_morphism() - sage: iota + sage: K = GF(7).over(ZZ) # optional - sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base Defn: 1 |--> 1 - sage: iota.is_injective() + sage: iota.is_injective() # optional - sage.rings.finite_rings False """ return self._backend.is_injective() @@ -416,24 +411,23 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K = GF(5^10).over(GF(5^5)) - sage: iota = K.defining_morphism() - sage: iota + sage: K = GF(5^10).over(GF(5^5)) # optional - sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in z5 of size 5^5 - To: Field in z10 with defining polynomial x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base + To: Field in z10 with defining polynomial + x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base Defn: z5 |--> z5 - sage: iota.is_surjective() + sage: iota.is_surjective() # optional - sage.rings.finite_rings False - sage: K = GF(7).over(ZZ) - sage: iota = K.defining_morphism() - sage: iota + sage: K = GF(7).over(ZZ) # optional - sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base Defn: 1 |--> 1 - sage: iota.is_surjective() + sage: iota.is_surjective() # optional - sage.rings.finite_rings True """ return self._backend.is_surjective() @@ -447,11 +441,11 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: L. = GF(5^6).over(K) - sage: FrobL = L.hom([b^5, a^5]) # absolute Frobenius + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: FrobL = L.hom([b^5, a^5]) # absolute Frobenius # optional - sage.rings.finite_rings - sage: print(FrobL._repr_defn()) + sage: print(FrobL._repr_defn()) # optional - sage.rings.finite_rings b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a @@ -479,14 +473,13 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) - sage: K. = A.over() - sage: f = K.hom([-sqrt5]) - sage: f + sage: A. = QQ.extension(x^2 - 5) # optional - sage.rings.number_field + sage: K. = A.over() # optional - sage.rings.number_field + sage: f = K.hom([-sqrt5]); f # optional - sage.rings.number_field Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> -sqrt5 - sage: f^2 # indirect doctest + sage: f^2 # indirect doctest # optional - sage.rings.number_field Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> sqrt5 """ @@ -505,13 +498,13 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = K.hom([a^5]) + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = K.hom([a^5]) # optional - sage.rings.finite_rings - sage: g = copy(f) # indirect doctest - sage: f == g + sage: g = copy(f) # indirect doctest # optional - sage.rings.finite_rings + sage: f == g # optional - sage.rings.finite_rings True - sage: f is g + sage: f is g # optional - sage.rings.finite_rings False """ self._backend = _slots['_backend'] @@ -523,9 +516,9 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = K.hom([a^5]) - sage: loads(dumps(f)) == f + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = K.hom([a^5]) # optional - sage.rings.finite_rings + sage: loads(dumps(f)) == f # optional - sage.rings.finite_rings True """ slots = RingMap._extra_slots(self) @@ -540,17 +533,17 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: - sage: K = GF(11^9).over(GF(11^3)) - sage: f = K.coerce_map_from(GF(11^9)) - sage: f + sage: K = GF(11^9).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(11^9)); f # optional - sage.rings.finite_rings Coercion morphism: From: Finite Field in z9 of size 11^9 - To: Field in z9 with defining polynomial x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base + To: Field in z9 with defining polynomial + x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base - sage: type(f) + sage: type(f) # optional - sage.rings.finite_rings - sage: TestSuite(f).run() + sage: TestSuite(f).run() # optional - sage.rings.finite_rings """ def __init__(self, parent): r""" @@ -559,9 +552,9 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) - sage: K = A.over() - sage: K.coerce_map_from(A) + sage: A. = QQ.extension(x^2 - 5) # optional - sage.rings.number_field + sage: K = A.over() # optional - sage.rings.number_field + sage: K.coerce_map_from(A) # optional - sage.rings.number_field Coercion morphism: From: Number Field in a with defining polynomial x^2 - 5 To: Field in a with defining polynomial x^2 - 5 over its base @@ -576,14 +569,13 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = K.coerce_map_from(GF(5^2)) - sage: f + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(5^2)); f # optional - sage.rings.finite_rings Coercion morphism: From: Finite Field in z2 of size 5^2 To: Field in a with defining polynomial x^2 + 4*x + 2 over its base - sage: f._repr_type() + sage: f._repr_type() # optional - sage.rings.finite_rings 'Coercion' """ return "Coercion" @@ -594,14 +586,13 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = K.coerce_map_from(GF(5^2)) - sage: f + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(5^2)); f # optional - sage.rings.finite_rings Coercion morphism: From: Finite Field in z2 of size 5^2 To: Field in a with defining polynomial x^2 + 4*x + 2 over its base - sage: f._repr_defn() + sage: f._repr_defn() # optional - sage.rings.finite_rings '' """ return "" @@ -616,9 +607,9 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = K.coerce_map_from(GF(5^2)) - sage: f(GF(5^2).gen()) + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(5^2)) # optional - sage.rings.finite_rings + sage: f(GF(5^2).gen()) # optional - sage.rings.finite_rings a """ codomain = self.codomain() @@ -632,17 +623,17 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: - sage: K = GF(11^9).over(GF(11^3)) - sage: f = GF(11^9).convert_map_from(K) - sage: f + sage: K = GF(11^9).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: f = GF(11^9).convert_map_from(K); f # optional - sage.rings.finite_rings Canonical morphism: - From: Field in z9 with defining polynomial x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base + From: Field in z9 with defining polynomial + x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base To: Finite Field in z9 of size 11^9 - sage: type(f) + sage: type(f) # optional - sage.rings.finite_rings - sage: TestSuite(f).run() + sage: TestSuite(f).run() # optional - sage.rings.finite_rings """ def __init__(self, parent): @@ -652,9 +643,9 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) - sage: K = A.over() - sage: A.convert_map_from(K) + sage: A. = QQ.extension(x^2 - 5) # optional - sage.rings.number_field + sage: K = A.over() # optional - sage.rings.number_field + sage: A.convert_map_from(K) # optional - sage.rings.number_field Canonical morphism: From: Field in a with defining polynomial x^2 - 5 over its base To: Number Field in a with defining polynomial x^2 - 5 @@ -669,14 +660,13 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = GF(5^2).convert_map_from(K) - sage: f + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = GF(5^2).convert_map_from(K); f # optional - sage.rings.finite_rings Canonical morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Finite Field in z2 of size 5^2 - sage: f._repr_type() + sage: f._repr_type() # optional - sage.rings.finite_rings 'Canonical' """ return "Canonical" @@ -687,14 +677,13 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = GF(5^2).convert_map_from(K) - sage: f + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = GF(5^2).convert_map_from(K); f # optional - sage.rings.finite_rings Canonical morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Finite Field in z2 of size 5^2 - sage: f._repr_defn() + sage: f._repr_defn() # optional - sage.rings.finite_rings '' """ return "" @@ -709,9 +698,9 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) - sage: f = GF(5^2).convert_map_from(K) - sage: f(a) + sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings + sage: f = GF(5^2).convert_map_from(K) # optional - sage.rings.finite_rings + sage: f(a) # optional - sage.rings.finite_rings z2 """ return (x)._backend @@ -724,9 +713,9 @@ cdef class MapFreeModuleToRelativeRing(Map): TESTS:: - sage: K = GF(5^2).over() - sage: V, i, j = K.free_module() - sage: type(i) + sage: K = GF(5^2).over() # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: type(i) # optional - sage.rings.finite_rings """ @@ -742,9 +731,9 @@ cdef class MapFreeModuleToRelativeRing(Map): TESTS:: - sage: K = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: i + sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: i # optional - sage.rings.finite_rings Generic map: From: Vector space of dimension 2 over Finite Field in z3 of size 11^3 To: Field in z6 with defining polynomial x^2 + (10*z3^2 + z3 + 6)*x + z3 over its base @@ -762,9 +751,9 @@ cdef class MapFreeModuleToRelativeRing(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: i.is_injective() + sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: i.is_injective() # optional - sage.rings.finite_rings True """ return True @@ -775,9 +764,9 @@ cdef class MapFreeModuleToRelativeRing(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: i.is_surjective() + sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: i.is_surjective() # optional - sage.rings.finite_rings True """ return True @@ -792,9 +781,9 @@ cdef class MapFreeModuleToRelativeRing(Map): EXAMPLES:: - sage: K. = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: i((0,1)) + sage: K. = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: i((0,1)) # optional - sage.rings.finite_rings a """ cdef Element elt @@ -811,9 +800,9 @@ cdef class MapRelativeRingToFreeModule(Map): TESTS:: - sage: K = GF(5^2).over() - sage: V, i, j = K.free_module() - sage: type(j) + sage: K = GF(5^2).over() # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: type(j) # optional - sage.rings.finite_rings """ @@ -829,9 +818,9 @@ cdef class MapRelativeRingToFreeModule(Map): TESTS:: - sage: K = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: j + sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: j # optional - sage.rings.finite_rings Generic map: From: Field in z6 with defining polynomial x^2 + (10*z3^2 + z3 + 6)*x + z3 over its base To: Vector space of dimension 2 over Finite Field in z3 of size 11^3 @@ -871,9 +860,9 @@ cdef class MapRelativeRingToFreeModule(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: j.is_injective() + sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: j.is_injective() # optional - sage.rings.finite_rings True """ return True @@ -884,9 +873,9 @@ cdef class MapRelativeRingToFreeModule(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: j.is_surjective() + sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: j.is_surjective() # optional - sage.rings.finite_rings True """ return True @@ -901,9 +890,9 @@ cdef class MapRelativeRingToFreeModule(Map): EXAMPLES:: - sage: K. = GF(11^6).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: j(a) + sage: K. = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: j(a) # optional - sage.rings.finite_rings (0, 1) """ coeffs = self.backend_coefficients(x) @@ -920,9 +909,9 @@ cdef class MapRelativeRingToFreeModule(Map): TESTS:: - sage: K. = GF(11^9).over(GF(11^3)) - sage: V, i, j = K.free_module() - sage: j(a + 2*a^2) # indirect doctest + sage: K. = GF(11^9).over(GF(11^3)) # optional - sage.rings.finite_rings + sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings + sage: j(a + 2*a^2) # indirect doctest # optional - sage.rings.finite_rings (0, 1, 2) """ cdef list coeffs = [ ] From 4f1383c36353b1adc3079998a079868e4522a968 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 1 Jun 2023 23:35:47 -0700 Subject: [PATCH 03/50] Fix # optional --- src/sage/rings/ring_extension.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index 8143d84d3ee..cbbfd2903f8 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -2521,7 +2521,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) + sage: A.fraction_field(extend_base=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -2767,7 +2767,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) + sage: A.fraction_field(extend_base=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective From 6c47ef7ee060aaf4aa7be8a2f0031208d0c55056 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 2 Jun 2023 11:09:51 -0700 Subject: [PATCH 04/50] sage.rings: More # optional --- src/sage/rings/ring_extension.pyx | 105 +++++++++++++++++------------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index cbbfd2903f8..4b88454f611 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -33,8 +33,7 @@ equivalently :meth:`base_ring`):: It is also possible to build an extension on top of another extension, obtaining this way a tower of extensions:: - sage: L. = GF(5^8).over(K) # optional - sage.rings.finite_rings - sage: L # optional - sage.rings.finite_rings + sage: L. = GF(5^8).over(K); L # optional - sage.rings.finite_rings Field in b with defining polynomial x^2 + (4*z2 + 3*a)*x + 1 - a over its base sage: L.base() # optional - sage.rings.finite_rings Field in a with defining polynomial x^2 + z2*x + 4 over its base @@ -156,12 +155,14 @@ def tower_bases(ring, degree): sage: S. = QQ[] sage: T. = S[] sage: tower_bases(T, False) - ([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, Univariate Polynomial Ring in x over Rational Field, Rational Field], []) sage: tower_bases(T, True) - ([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], [1]) sage: K. = Qq(5^2) # optional - sage.rings.padics @@ -335,12 +336,12 @@ class RingExtensionFactory(UniqueFactory): True sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^2 - 2) - sage: E = K.over(QQ); E + sage: K. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: E = K.over(QQ); E # optional - sage.rings.number_field Field in a with defining polynomial x^2 - 2 over its base - sage: E2. = K.over(QQ) - sage: E2 is E + sage: E2. = K.over(QQ) # optional - sage.rings.number_field + sage: E2 is E # optional - sage.rings.number_field False """ def create_key_and_extra_args(self, ring, defining_morphism=None, gens=None, names=None, constructors=None): @@ -376,8 +377,9 @@ class RingExtensionFactory(UniqueFactory): To: Rational Field Defn: 1 |--> 1, (), ()), {'constructors': [(, - {'is_backend_exposed': True, - 'print_options': {'print_elements_as': None, 'print_parent_as': None}})]}) + {'is_backend_exposed': True, + 'print_options': {'print_elements_as': None, + 'print_parent_as': None}})]}) sage: RingExtension.create_key_and_extra_args(GF(5^4), GF(5^2), # optional - sage.rings.finite_rings ....: names=('a',)) @@ -386,7 +388,7 @@ class RingExtensionFactory(UniqueFactory): To: Finite Field in z4 of size 5^4 Defn: z2 |--> z4^3 + z4^2 + z4 + 3, (z4,), ('a',)), {'constructors': [(, - {'gen': z4, 'is_backend_exposed': True, 'names': ('a',)})]}) + {'gen': z4, 'is_backend_exposed': True, 'names': ('a',)})]}) """ use_generic_constructor = True is_backend_exposed = True @@ -535,9 +537,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): .. NOTE: - The attribute `is_backend_exposed` is only used for printing; + The attribute ``is_backend_exposed`` is only used for printing; when it is ``False``, printing an element like its backend is - disabled (and a ``RuntimeError`` is raised when it would occur). + disabled (and a :class:`RuntimeError` is raised when it would occur). OUTPUT: @@ -623,12 +625,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^2 - 2) - sage: E = K.over() # over QQ + sage: K. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: E = K.over() # over QQ # optional - sage.rings.number_field - sage: hasattr(E, 'automorphisms') + sage: hasattr(E, 'automorphisms') # optional - sage.rings.number_field True - sage: E.automorphisms() + sage: E.automorphisms() # optional - sage.rings.number_field [Ring endomorphism of Field in a with defining polynomial x^2 - 2 over its base Defn: a |--> a, Ring endomorphism of Field in a with defining polynomial x^2 - 2 over its base @@ -660,10 +662,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) - sage: K. = A.over() + sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: K. = A.over() # optional - sage.rings.number_field - sage: dir(K) + sage: dir(K) # optional - sage.rings.number_field ['CartesianProduct', 'Element', 'Hom', @@ -804,7 +806,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): Observe what happens when we modify the option ``over``:: sage: D # optional - sage.rings.finite_rings - Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over its base + Field in d with defining polynomial + x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over its base sage: D.print_options(over=2) # optional - sage.rings.finite_rings sage: D # optional - sage.rings.finite_rings @@ -1124,7 +1127,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): Finite Field of size 5] sage: L.bases() # optional - sage.rings.finite_rings - [Field in z12 with defining polynomial x^3 + (1 + (2 - z2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, + [Field in z12 with defining polynomial + x^3 + (1 + (2 - z2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] @@ -1288,7 +1292,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): sage: L.defining_morphism() # optional - sage.rings.finite_rings Ring morphism: From: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - To: Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base + To: Field in z12 with defining polynomial + x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base Defn: z4 |--> z4 One can also pass in a base over which the extension is explicitly @@ -1297,7 +1302,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): sage: L.defining_morphism(F) # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in z2 of size 5^2 - To: Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base + To: Field in z12 with defining polynomial + x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base Defn: z2 |--> z2 sage: L.defining_morphism(GF(5)) # optional - sage.rings.finite_rings @@ -1473,11 +1479,11 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) - sage: B. = QQ.extension(x^6 - 2) - sage: f = A.hom([b^3]) - sage: E = B.over(f) - sage: E.degree_over() # indirect doctest + sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: B. = QQ.extension(x^6 - 2) # optional - sage.rings.number_field + sage: f = A.hom([b^3]) # optional - sage.rings.number_field + sage: E = B.over(f) # optional - sage.rings.number_field + sage: E.degree_over() # indirect doctest # optional - sage.rings.number_field 3 """ if base is self: @@ -1766,7 +1772,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) + sage: A.fraction_field(extend_base=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -1831,13 +1837,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): sage: L = GF(5^12).over(F) # optional - sage.rings.finite_rings sage: K.Hom(L) # indirect doctest # optional - sage.rings.finite_rings - Set of Homomorphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base + Set of Homomorphisms + from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base + to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base sage: K.Hom(L, category=Sets()) # optional - sage.rings.finite_rings - Set of Morphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base - in Category of sets + Set of Morphisms + from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base + to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base + in Category of sets """ from sage.rings.ring_extension_homset import RingExtensionHomset @@ -1876,7 +1886,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): We define (by hand) the relative Frobenius endomorphism of the extension `L/K`:: sage: L.hom([b^25]) # optional - sage.rings.finite_rings - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + Ring endomorphism of + Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> 2 + 2*a*b + (2 - a)*b^2 Defining the absolute Frobenius of `L` is a bit more complicated @@ -1892,7 +1903,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings sage: FrobL = L.hom([b^5], base_map=FrobK); FrobL # optional - sage.rings.finite_rings - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + Ring endomorphism of + Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a @@ -1900,7 +1912,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): As a shortcut, we may use the following construction:: sage: phi = L.hom([b^5, a^5]); phi # optional - sage.rings.finite_rings - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + Ring endomorphism of + Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a @@ -2210,11 +2223,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) - sage: B. = QQ.extension(x^6 - 2) - sage: f = A.hom([b^3]) - sage: E = B.over(f) - sage: E.degree_over() # indirect doctest + sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: B. = QQ.extension(x^6 - 2) # optional - sage.rings.number_field + sage: f = A.hom([b^3]) # optional - sage.rings.number_field + sage: E = B.over(f) # optional - sage.rings.number_field + sage: E.degree_over() # indirect doctest # optional - sage.rings.number_field 3 """ if base is self: @@ -2318,9 +2331,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^3 - 2) - sage: K. = A.over() - sage: K.basis_over() + sage: A. = QQ.extension(x^3 - 2) # optional - sage.rings.number_field + sage: K. = A.over() # optional - sage.rings.number_field + sage: K.basis_over() # optional - sage.rings.number_field [1, u, u^2] """ if base is self: From cb68414c991ff3c37304c67063dea2fdabd67629 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 3 Jun 2023 17:00:24 -0700 Subject: [PATCH 05/50] sage.rings: More # optional --- src/sage/rings/lazy_series.py | 488 +++++++++++----------- src/sage/rings/lazy_series_ring.py | 182 ++++---- src/sage/rings/ring_extension_element.pyx | 14 +- 3 files changed, 344 insertions(+), 340 deletions(-) diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index b58e21e655c..8698af54927 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -1459,12 +1459,12 @@ def _ascii_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat - sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat - sage: L.options.display_length = 3 # optional - sage.combinat - sage: ascii_art(1 / (1 - e[1]*z)) # optional - sage.combinat + sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat sage.modules + sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat sage.modules + sage: L.options.display_length = 3 # optional - sage.combinat sage.modules + sage: ascii_art(1 / (1 - e[1]*z)) # optional - sage.combinat sage.modules e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() # optional - sage.combinat + sage: L.options._reset() # optional - sage.combinat sage.modules """ from sage.typeset.ascii_art import ascii_art, AsciiArt if isinstance(self._coeff_stream, Stream_zero): @@ -1479,12 +1479,12 @@ def _unicode_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat - sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat - sage: L.options.display_length = 3 # optional - sage.combinat - sage: unicode_art(1 / (1 - e[1]*z)) # optional - sage.combinat + sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat sage.modules + sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat sage.modules + sage: L.options.display_length = 3 # optional - sage.combinat sage.modules + sage: unicode_art(1 / (1 - e[1]*z)) # optional - sage.combinat sage.modules e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() # optional - sage.combinat + sage: L.options._reset() # optional - sage.combinat sage.modules """ from sage.typeset.unicode_art import unicode_art, UnicodeArt if isinstance(self._coeff_stream, Stream_zero): @@ -2028,8 +2028,8 @@ def cos(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: cos(z)[0:6] == cos(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: cos(z)[0:6] == cos(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2054,8 +2054,8 @@ def tan(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: tan(z)[0:6] == tan(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: tan(z)[0:6] == tan(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ return self.sin() / self.cos() @@ -2076,8 +2076,8 @@ def cot(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: cot(z)[0:6] == cot(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: cot(z)[0:6] == cot(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ return ~self.tan() @@ -2098,8 +2098,8 @@ def csc(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: (z*csc(z))[0:6] == (x*csc(x)).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: (z*csc(z))[0:6] == (x*csc(x)).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ return ~self.sin() @@ -2120,8 +2120,8 @@ def sec(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: sec(z)[0:6] == sec(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: sec(z)[0:6] == sec(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ return ~self.cos() @@ -2146,8 +2146,8 @@ def arcsin(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: asin(z)[0:6] == asin(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: asin(z)[0:6] == asin(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2183,8 +2183,8 @@ def arccos(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: acos(z)[0:6] == acos(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: acos(z)[0:6] == acos(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from sage.symbolic.constants import pi @@ -2207,8 +2207,8 @@ def arctan(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: atan(z)[0:6] == atan(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: atan(z)[0:6] == atan(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2246,8 +2246,8 @@ def arccot(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: acot(z)[0:6] == acot(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: acot(z)[0:6] == acot(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from sage.symbolic.constants import pi @@ -2273,8 +2273,8 @@ def sinh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: sinh(z)[0:6] == sinh(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: sinh(z)[0:6] == sinh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2300,8 +2300,8 @@ def cosh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: cosh(z)[0:6] == cosh(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: cosh(z)[0:6] == cosh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2327,8 +2327,8 @@ def tanh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: tanh(z)[0:6] == tanh(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: tanh(z)[0:6] == tanh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from sage.arith.misc import bernoulli @@ -2358,8 +2358,8 @@ def coth(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: coth(z)[0:6] == coth(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: coth(z)[0:6] == coth(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from sage.arith.misc import bernoulli @@ -2390,8 +2390,8 @@ def sech(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: sech(z)[0:6] == sech(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: sech(z)[0:6] == sech(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from sage.combinat.combinat import euler_number @@ -2421,8 +2421,8 @@ def csch(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: csch(z)[0:6] == csch(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: csch(z)[0:6] == csch(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ from sage.arith.misc import bernoulli @@ -2460,8 +2460,8 @@ def arcsinh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: asinh(z)[0:6] == asinh(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: asinh(z)[0:6] == asinh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ @@ -2498,8 +2498,8 @@ def arctanh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: atanh(z)[0:6] == atanh(x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: atanh(z)[0:6] == atanh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ @@ -2533,8 +2533,8 @@ def hypergeometric(self, a, b): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") - sage: z.hypergeometric([1,1],[1])[0:6] == hypergeometric([1,1],[1], x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic + sage: z.hypergeometric([1,1],[1])[0:6] == hypergeometric([1,1],[1], x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True """ @@ -2685,10 +2685,9 @@ def sqrt(self): This also works for Dirichlet series:: - sage: D = LazyDirichletSeriesRing(SR, "s") - sage: Z = D(constant=1) - sage: f = sqrt(Z) - sage: f # optional - sage.symbolic + sage: D = LazyDirichletSeriesRing(SR, "s") # optional - sage.symbolic + sage: Z = D(constant=1) # optional - sage.symbolic + sage: f = sqrt(Z); f # optional - sage.symbolic 1 + 1/2/2^s + 1/2/3^s + 3/8/4^s + 1/2/5^s + 1/4/6^s + 1/2/7^s + O(1/(8^s)) sage: f*f - Z # optional - sage.symbolic O(1/(8^s)) @@ -2799,22 +2798,22 @@ def _mul_(self, other): Multiplication of series with eventually constant coefficients may yield another such series:: - sage: L. = LazyLaurentSeriesRing(SR) - sage: var("a b c d e u v w") + sage: L. = LazyLaurentSeriesRing(SR) # optional - sage.symbolic + sage: var("a b c d e u v w") # optional - sage.symbolic (a, b, c, d, e, u, v, w) - sage: s = a/z^2 + b*z + c*z^2 + d*z^3 + e*z^4 - sage: t = L([u, v], constant=w, valuation=-1) - sage: s1 = s.approximate_series(44) - sage: t1 = t.approximate_series(44) - sage: s1 * t1 - (s * t).approximate_series(42) + sage: s = a/z^2 + b*z + c*z^2 + d*z^3 + e*z^4 # optional - sage.symbolic + sage: t = L([u, v], constant=w, valuation=-1) # optional - sage.symbolic + sage: s1 = s.approximate_series(44) # optional - sage.symbolic + sage: t1 = t.approximate_series(44) # optional - sage.symbolic + sage: s1 * t1 - (s * t).approximate_series(42) # optional - sage.symbolic O(z^42) Check products with exact series:: - sage: L([1], constant=3)^2 + sage: L([1], constant=3)^2 # optional - sage.symbolic 1 + 6*z + 15*z^2 + 24*z^3 + 33*z^4 + 42*z^5 + 51*z^6 + O(z^7) - sage: (1+z) * L([1,0,1], constant=1) + sage: (1+z) * L([1,0,1], constant=1) # optional - sage.symbolic 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6) """ P = self.parent() @@ -2935,8 +2934,8 @@ def __pow__(self, n): We also support the general case:: - sage: L. = LazyLaurentSeriesRing(SR) - sage: (1 + z)^(1 + z) + sage: L. = LazyLaurentSeriesRing(SR) # optional - sage.symbolic + sage: (1 + z)^(1 + z) # optional - sage.symbolic 1 + z + z^2 + 1/2*z^3 + 1/3*z^4 + 1/12*z^5 + 3/40*z^6 + O(z^7) """ @@ -2996,14 +2995,14 @@ def __invert__(self): We can also compute the multiplicative inverse of a symmetric function:: - sage: h = SymmetricFunctions(QQ).h() - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(p) - sage: E = L(lambda n: h[n]) - sage: (~E)[:4] + sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: L = LazySymmetricFunctions(p) # optional - sage.modules + sage: E = L(lambda n: h[n]) # optional - sage.modules + sage: (~E)[:4] # optional - sage.modules [p[], -p[1], 1/2*p[1, 1] - 1/2*p[2], -1/6*p[1, 1, 1] + 1/2*p[2, 1] - 1/3*p[3]] - sage: (E * ~E)[:6] + sage: (E * ~E)[:6] # optional - sage.modules [p[], 0, 0, 0, 0, 0] TESTS:: @@ -3115,8 +3114,8 @@ def _div_(self, other): An example over the ring of symmetric functions:: sage: e = SymmetricFunctions(QQ).e() - sage: R. = LazyLaurentSeriesRing(e) - sage: 1 / (1 - e[1]*z) + sage: R. = LazyLaurentSeriesRing(e) # optional - sage.modules + sage: 1 / (1 - e[1]*z) # optional - sage.modules e[] + e[1]*z + e[1, 1]*z^2 + e[1, 1, 1]*z^3 + e[1, 1, 1, 1]*z^4 + e[1, 1, 1, 1, 1]*z^5 + e[1, 1, 1, 1, 1, 1]*z^6 + O(e[]*z^7) @@ -3369,11 +3368,11 @@ def log(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") - sage: log(1+z)[0:6] == log(1+x).series(x, 6).coefficients(sparse=False) + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic + sage: log(1+z)[0:6] == log(1+x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic True - sage: log(z) + sage: log(z) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only compose with a positive valuation series @@ -5314,19 +5313,19 @@ def xgcd(self, f): sage: g == s * a + t * b True - sage: L. = LazyPowerSeriesRing(GF(2)) - sage: a = L(lambda n: n % 2, valuation=3); a + sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: a = L(lambda n: n % 2, valuation=3); a # optional - sage.rings.finite_rings x^3 + x^5 + x^7 + x^9 + O(x^10) - sage: b = L(lambda n: binomial(n,2) % 2, valuation=3); b + sage: b = L(lambda n: binomial(n,2) % 2, valuation=3); b # optional - sage.rings.finite_rings x^3 + x^6 + x^7 + O(x^10) - sage: g, s, t = a.xgcd(b) - sage: g + sage: g, s, t = a.xgcd(b) # optional - sage.rings.finite_rings + sage: g # optional - sage.rings.finite_rings x^3 - sage: s + sage: s # optional - sage.rings.finite_rings 1 + x + x^3 + x^4 + x^5 + O(x^7) - sage: t + sage: t # optional - sage.rings.finite_rings x + x^2 + x^4 + x^5 + x^6 + O(x^8) - sage: g == s * a + t * b + sage: g == s * a + t * b # optional - sage.rings.finite_rings True sage: LazyPowerSeriesRing.options._reset() # reset the options @@ -5368,11 +5367,11 @@ def _format_series(self, formatter, format_strings=False): TESTS:: - sage: h = SymmetricFunctions(ZZ).h() - sage: e = SymmetricFunctions(ZZ).e() - sage: L = LazySymmetricFunctions(tensor([h, e])) - sage: f = L(lambda n: sum(tensor([h[k], e[n-k]]) for k in range(n+1))) - sage: f._format_series(repr) + sage: h = SymmetricFunctions(ZZ).h() # optional - sage.modules + sage: e = SymmetricFunctions(ZZ).e() # optional - sage.modules + sage: L = LazySymmetricFunctions(tensor([h, e])) # optional - sage.modules + sage: f = L(lambda n: sum(tensor([h[k], e[n-k]]) for k in range(n+1))) # optional - sage.modules + sage: f._format_series(repr) # optional - sage.modules '(h[]#e[]) + (h[]#e[1]+h[1]#e[]) + (h[]#e[2]+h[1]#e[1]+h[2]#e[]) @@ -5443,8 +5442,8 @@ class LazySymmetricFunction(LazyCompletionGradedAlgebraElement): EXAMPLES:: - sage: s = SymmetricFunctions(ZZ).s() - sage: L = LazySymmetricFunctions(s) + sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules """ def is_unit(self): """ @@ -5452,22 +5451,22 @@ def is_unit(self): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() - sage: L = LazySymmetricFunctions(m) + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: L(2*m[1]).is_unit() + sage: L(2*m[1]).is_unit() # optional - sage.modules False - sage: L(-1 + 2*m[1]).is_unit() + sage: L(-1 + 2*m[1]).is_unit() # optional - sage.modules True - sage: L(2 + m[1]).is_unit() + sage: L(2 + m[1]).is_unit() # optional - sage.modules False - sage: m = SymmetricFunctions(QQ).m() - sage: L = LazySymmetricFunctions(m) + sage: m = SymmetricFunctions(QQ).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: L(2 + 3*m[1]).is_unit() + sage: L(2 + 3*m[1]).is_unit() # optional - sage.modules True """ if self.is_zero(): # now 0 != 1 @@ -5511,54 +5510,54 @@ def __call__(self, *args, check=True): EXAMPLES:: sage: P. = QQ[] - sage: s = SymmetricFunctions(P).s() - sage: L = LazySymmetricFunctions(s) - sage: f = s[2] - sage: g = s[3] - sage: L(f)(L(g)) - L(f(g)) + sage: s = SymmetricFunctions(P).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: f = s[2] # optional - sage.modules + sage: g = s[3] # optional - sage.modules + sage: L(f)(L(g)) - L(f(g)) # optional - sage.modules 0 - sage: f = s[2] + s[2,1] - sage: g = s[1] + s[2,2] - sage: L(f)(L(g)) - L(f(g)) + sage: f = s[2] + s[2,1] # optional - sage.modules + sage: g = s[1] + s[2,2] # optional - sage.modules + sage: L(f)(L(g)) - L(f(g)) # optional - sage.modules 0 - sage: L(f)(g) - L(f(g)) + sage: L(f)(g) - L(f(g)) # optional - sage.modules 0 - sage: f = s[2] + s[2,1] - sage: g = s[1] + s[2,2] - sage: L(f)(L(q*g)) - L(f(q*g)) + sage: f = s[2] + s[2,1] # optional - sage.modules + sage: g = s[1] + s[2,2] # optional - sage.modules + sage: L(f)(L(q*g)) - L(f(q*g)) # optional - sage.modules 0 The Frobenius character of the permutation action on set partitions is a plethysm:: - sage: s = SymmetricFunctions(QQ).s() - sage: S = LazySymmetricFunctions(s) - sage: E1 = S(lambda n: s[n], valuation=1) - sage: E = 1 + E1 - sage: P = E(E1) - sage: P[:5] + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: S = LazySymmetricFunctions(s) # optional - sage.modules + sage: E1 = S(lambda n: s[n], valuation=1) # optional - sage.modules + sage: E = 1 + E1 # optional - sage.modules + sage: P = E(E1) # optional - sage.modules + sage: P[:5] # optional - sage.modules [s[], s[1], 2*s[2], s[2, 1] + 3*s[3], 2*s[2, 2] + 2*s[3, 1] + 5*s[4]] The plethysm with a tensor product is also implemented:: - sage: s = SymmetricFunctions(QQ).s() - sage: X = tensor([s[1],s[[]]]) - sage: Y = tensor([s[[]],s[1]]) - sage: S = LazySymmetricFunctions(s) - sage: S2 = LazySymmetricFunctions(tensor([s, s])) - sage: A = S(s[1,1,1]) - sage: B = S2(X+Y) - sage: A(B) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: X = tensor([s[1],s[[]]]) # optional - sage.modules + sage: Y = tensor([s[[]],s[1]]) # optional - sage.modules + sage: S = LazySymmetricFunctions(s) # optional - sage.modules + sage: S2 = LazySymmetricFunctions(tensor([s, s])) # optional - sage.modules + sage: A = S(s[1,1,1]) # optional - sage.modules + sage: B = S2(X+Y) # optional - sage.modules + sage: A(B) # optional - sage.modules (s[]#s[1,1,1]+s[1]#s[1,1]+s[1,1]#s[1]+s[1,1,1]#s[]) - sage: H = S(lambda n: s[n]) - sage: H(S2(X*Y)) + sage: H = S(lambda n: s[n]) # optional - sage.modules + sage: H(S2(X*Y)) # optional - sage.modules (s[]#s[]) + (s[1]#s[1]) + (s[1,1]#s[1,1]+s[2]#s[2]) + (s[1,1,1]#s[1,1,1]+s[2,1]#s[2,1]+s[3]#s[3]) + O^7 - sage: H(S2(X+Y)) + sage: H(S2(X+Y)) # optional - sage.modules (s[]#s[]) + (s[]#s[1]+s[1]#s[]) + (s[]#s[2]+s[1]#s[1]+s[2]#s[]) + (s[]#s[3]+s[1]#s[2]+s[2]#s[1]+s[3]#s[]) + (s[]#s[4]+s[1]#s[3]+s[2]#s[2]+s[3]#s[1]+s[4]#s[]) @@ -5568,24 +5567,24 @@ def __call__(self, *args, check=True): TESTS:: - sage: s = SymmetricFunctions(QQ).s() - sage: S = LazySymmetricFunctions(s) - sage: f = 1 / (1 - S(s[2])) - sage: g = f(s[2]); g + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: S = LazySymmetricFunctions(s) # optional - sage.modules + sage: f = 1 / (1 - S(s[2])) # optional - sage.modules + sage: g = f(s[2]); g # optional - sage.modules s[] + (s[2,2]+s[4]) + O^7 - sage: S(sum(f[i](s[2]) for i in range(5))).truncate(10) == g.truncate(10) + sage: S(sum(f[i](s[2]) for i in range(5))).truncate(10) == g.truncate(10) # optional - sage.modules True - sage: f = 1 / (1 - S(s[2])) - sage: g = S(s[1]) / (1 - S(s[1])) - sage: f(g) + sage: f = 1 / (1 - S(s[2])) # optional - sage.modules + sage: g = S(s[1]) / (1 - S(s[1])) # optional - sage.modules + sage: f(g) # optional - sage.modules s[] + s[2] + (s[1,1,1]+2*s[2,1]+s[3]) + (2*s[1,1,1,1]+4*s[2,1,1]+5*s[2,2]+5*s[3,1]+3*s[4]) + (2*s[1,1,1,1,1]+10*s[2,1,1,1]+14*s[2,2,1]+18*s[3,1,1]+16*s[3,2]+14*s[4,1]+4*s[5]) + (3*s[1,1,1,1,1,1]+22*s[2,1,1,1,1]+38*s[2,2,1,1]+28*s[2,2,2]+48*s[3,1,1,1]+82*s[3,2,1]+25*s[3,3]+51*s[4,1,1]+56*s[4,2]+31*s[5,1]+9*s[6]) + O^7 - sage: f(0) + sage: f(0) # optional - sage.modules 1 - sage: f(s(1)) + sage: f(s(1)) # optional - sage.modules Traceback (most recent call last): ... ValueError: can only compose with a positive valuation series @@ -5593,22 +5592,22 @@ def __call__(self, *args, check=True): Check that composing the zero series with anything yields zero in the correct parent:: - sage: e = SymmetricFunctions(QQ).e() - sage: h = SymmetricFunctions(QQ).h() - sage: s = SymmetricFunctions(QQ).s() - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(tensor([e, h])) - sage: r = (L(0)(s[1], p[1])); r + sage: e = SymmetricFunctions(QQ).e() # optional - sage.modules + sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: L = LazySymmetricFunctions(tensor([e, h])) # optional - sage.modules + sage: r = (L(0)(s[1], p[1])); r # optional - sage.modules 0 - sage: r.parent() + sage: r.parent() # optional - sage.modules Symmetric Functions over Rational Field in the Schur basis Check that composing `f` with zero series yields the constant term of `f`:: - sage: f = 3*L(tensor([s[1], s[1]])) - sage: f(0, 0) + sage: f = 3*L(tensor([s[1], s[1]])) # optional - sage.modules + sage: f(0, 0) # optional - sage.modules 0 - sage: (3+f)(0, 0) + sage: (3+f)(0, 0) # optional - sage.modules 3 """ fP = parent(self) @@ -5695,39 +5694,39 @@ def revert(self): EXAMPLES:: - sage: h = SymmetricFunctions(QQ).h() - sage: L = LazySymmetricFunctions(h) - sage: f = L(lambda n: h[n]) - 1 - sage: f(f.revert()) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules + sage: L = LazySymmetricFunctions(h) # optional - sage.modules + sage: f = L(lambda n: h[n]) - 1 # optional - sage.modules + sage: f(f.revert()) # optional - sage.modules h[1] + O^8 TESTS:: - sage: f = L(lambda n: h[n]) - 1 - h[1] - sage: g = f.revert() - sage: g[1] + sage: f = L(lambda n: h[n]) - 1 - h[1] # optional - sage.modules + sage: g = f.revert() # optional - sage.modules + sage: g[1] # optional - sage.modules Traceback (most recent call last): ... ValueError: compositional inverse does not exist - sage: R. = QQ[] - sage: p = SymmetricFunctions(R.fraction_field()).p() - sage: L = LazySymmetricFunctions(p) - sage: f = L(a + b*p[1]) - sage: f.revert() + sage: R. = QQ[] # optional - sage.modules + sage: p = SymmetricFunctions(R.fraction_field()).p() # optional - sage.modules + sage: L = LazySymmetricFunctions(p) # optional - sage.modules + sage: f = L(a + b*p[1]) # optional - sage.modules + sage: f.revert() # optional - sage.modules (((-a)/b)*p[]) + 1/b*p[1] - sage: f = L(2*p[1]) - sage: f.revert() + sage: f = L(2*p[1]) # optional - sage.modules + sage: f.revert() # optional - sage.modules 1/2*p[1] - sage: f = L(2*p[1] + p[1,1]) - sage: f.revert() + sage: f = L(2*p[1] + p[1,1]) # optional - sage.modules + sage: f.revert() # optional - sage.modules 1/2*p[1] + (-1/8*p[1,1]) + (1/16*p[1,1,1]) + (-5/128*p[1,1,1,1]) + (7/256*p[1,1,1,1,1]) + (-21/1024*p[1,1,1,1,1,1]) + (33/2048*p[1,1,1,1,1,1,1]) + O^8 - sage: f.revert()(f) + sage: f.revert()(f) # optional - sage.modules p[1] + O^8 ALGORITHM: @@ -5820,32 +5819,33 @@ def derivative_with_respect_to_p1(self, n=1): The species `E` of sets satisfies the relationship `E' = E`:: - sage: h = SymmetricFunctions(QQ).h() - sage: T = LazySymmetricFunctions(h) - sage: E = T(lambda n: h[n]) - sage: E - E.derivative_with_respect_to_p1() + sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules + sage: T = LazySymmetricFunctions(h) # optional - sage.modules + sage: E = T(lambda n: h[n]) # optional - sage.modules + sage: E - E.derivative_with_respect_to_p1() # optional - sage.modules O^6 The species `C` of cyclic orderings and the species `L` of linear orderings satisfy the relationship `C' = L`:: - sage: p = SymmetricFunctions(QQ).p() - sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) for k in divisors(n))/n if n > 0 else 0)) - sage: L = T(lambda n: p([1]*n)) - sage: L - C.derivative_with_respect_to_p1() + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) + ....: for k in divisors(n))/n if n > 0 else 0)) + sage: L = T(lambda n: p([1]*n)) # optional - sage.modules + sage: L - C.derivative_with_respect_to_p1() # optional - sage.modules O^6 TESTS:: - sage: T = LazySymmetricFunctions(p) - sage: a = T(p([1,1,1])) - sage: a.derivative_with_respect_to_p1() + sage: T = LazySymmetricFunctions(p) # optional - sage.modules + sage: a = T(p([1,1,1])) # optional - sage.modules + sage: a.derivative_with_respect_to_p1() # optional - sage.modules (3*p[1,1]) + O^9 - sage: a.derivative_with_respect_to_p1(1) + sage: a.derivative_with_respect_to_p1(1) # optional - sage.modules (3*p[1,1]) + O^9 - sage: a.derivative_with_respect_to_p1(2) + sage: a.derivative_with_respect_to_p1(2) # optional - sage.modules 6*p[1] + O^8 - sage: a.derivative_with_respect_to_p1(3) + sage: a.derivative_with_respect_to_p1(3) # optional - sage.modules 6*p[] + O^7 """ P = self.parent() @@ -5900,12 +5900,12 @@ def functorial_composition(self, *args): :class:`~sage.combinat.species.subset_species.SubsetSpecies`.:: sage: R. = QQ[] - sage: h = SymmetricFunctions(R).h() - sage: m = SymmetricFunctions(R).m() - sage: L = LazySymmetricFunctions(m) - sage: P = L(lambda n: sum(q^k*h[n-k]*h[k] for k in range(n+1))) - sage: P2 = L(lambda n: h[2]*h[n-2], valuation=2) - sage: P.functorial_composition(P2)[:4] + sage: h = SymmetricFunctions(R).h() # optional - sage.modules + sage: m = SymmetricFunctions(R).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: P = L(lambda n: sum(q^k*h[n-k]*h[k] for k in range(n+1))) # optional - sage.modules + sage: P2 = L(lambda n: h[2]*h[n-2], valuation=2) # optional - sage.modules + sage: P.functorial_composition(P2)[:4] # optional - sage.modules [m[], m[1], (q+1)*m[1, 1] + (q+1)*m[2], @@ -5913,12 +5913,12 @@ def functorial_composition(self, *args): For example, there are:: - sage: P.functorial_composition(P2)[4].coefficient([4])[3] + sage: P.functorial_composition(P2)[4].coefficient([4])[3] # optional - sage.modules 3 unlabelled graphs on 4 vertices and 3 edges, and:: - sage: P.functorial_composition(P2)[4].coefficient([2,2])[3] + sage: P.functorial_composition(P2)[4].coefficient([2,2])[3] # optional - sage.modules 8 labellings of their vertices with two 1's and two 2's. @@ -5926,43 +5926,43 @@ def functorial_composition(self, *args): The symmetric function `h_1 \sum_n h_n` is the neutral element with respect to functorial composition:: - sage: p = SymmetricFunctions(QQ).p() - sage: h = SymmetricFunctions(QQ).h() - sage: e = SymmetricFunctions(QQ).e() - sage: L = LazySymmetricFunctions(h) - sage: E = L(lambda n: h[n]) - sage: Ep = p[1]*E.derivative_with_respect_to_p1(); Ep + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules + sage: e = SymmetricFunctions(QQ).e() # optional - sage.modules + sage: L = LazySymmetricFunctions(h) # optional - sage.modules + sage: E = L(lambda n: h[n]) # optional - sage.modules + sage: Ep = p[1]*E.derivative_with_respect_to_p1(); Ep # optional - sage.modules h[1] + (h[1,1]) + (h[2,1]) + (h[3,1]) + (h[4,1]) + (h[5,1]) + O^7 - sage: f = L(lambda n: h[n-n//2, n//2]) - sage: f - Ep.functorial_composition(f) + sage: f = L(lambda n: h[n-n//2, n//2]) # optional - sage.modules + sage: f - Ep.functorial_composition(f) # optional - sage.modules O^7 The functorial composition distributes over the sum:: - sage: F1 = L(lambda n: h[n]) - sage: F2 = L(lambda n: e[n]) - sage: f1 = F1.functorial_composition(f) - sage: f2 = F2.functorial_composition(f) - sage: (F1 + F2).functorial_composition(f) - f1 - f2 # long time + sage: F1 = L(lambda n: h[n]) # optional - sage.modules + sage: F2 = L(lambda n: e[n]) # optional - sage.modules + sage: f1 = F1.functorial_composition(f) # optional - sage.modules + sage: f2 = F2.functorial_composition(f) # optional - sage.modules + sage: (F1 + F2).functorial_composition(f) - f1 - f2 # long time # optional - sage.modules O^7 TESTS: Check a corner case:: - sage: h = SymmetricFunctions(QQ).h() - sage: L = LazySymmetricFunctions(h) - sage: L(h[2,1]).functorial_composition(3*h[0]) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules + sage: L = LazySymmetricFunctions(h) # optional - sage.modules + sage: L(h[2,1]).functorial_composition(3*h[0]) # optional - sage.modules 3*h[] + O^7 Check an instance of a non-group action:: - sage: s = SymmetricFunctions(QQ).s() - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(p) - sage: f = L(lambda n: s[n]) - sage: g = 2*s[2, 1, 1] + s[2, 2] + 3*s[4] - sage: r = f.functorial_composition(g); r[4] + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: L = LazySymmetricFunctions(p) # optional - sage.modules + sage: f = L(lambda n: s[n]) # optional - sage.modules + sage: g = 2*s[2, 1, 1] + s[2, 2] + 3*s[4] # optional - sage.modules + sage: r = f.functorial_composition(g); r[4] # optional - sage.modules Traceback (most recent call last): ... ValueError: the argument is not the Frobenius character of a permutation representation @@ -6111,14 +6111,14 @@ def arithmetic_product(self, *args, check=True): consistent for all the lists in the structure. :: sage: R. = QQ[] - sage: p = SymmetricFunctions(R).p() - sage: m = SymmetricFunctions(R).m() - sage: L = LazySymmetricFunctions(m) - - sage: C = species.CycleSpecies().cycle_index_series() - sage: c = L(lambda n: C[n]) - sage: Lplus = L(lambda n: p([1]*n), valuation=1) - sage: r = c.arithmetic_product(Lplus); r + sage: p = SymmetricFunctions(R).p() # optional - sage.modules + sage: m = SymmetricFunctions(R).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + + sage: C = species.CycleSpecies().cycle_index_series() # optional - sage.modules + sage: c = L(lambda n: C[n]) # optional - sage.modules + sage: Lplus = L(lambda n: p([1]*n), valuation=1) # optional - sage.modules + sage: r = c.arithmetic_product(Lplus); r # optional - sage.modules m[1] + (3*m[1,1]+2*m[2]) + (8*m[1,1,1]+4*m[2,1]+2*m[3]) + (42*m[1,1,1,1]+21*m[2,1,1]+12*m[2,2]+7*m[3,1]+3*m[4]) @@ -6128,7 +6128,7 @@ def arithmetic_product(self, *args, check=True): In particular, the number of regular octopuses is:: - sage: [r[n].coefficient([1]*n) for n in range(8)] + sage: [r[n].coefficient([1]*n) for n in range(8)] # optional - sage.modules [0, 1, 3, 8, 42, 144, 1440, 5760] It is shown in [MM2008]_ that the exponential generating @@ -6136,7 +6136,7 @@ def arithmetic_product(self, *args, check=True): (x) = \sum_{n \geq 1} \sigma (n) (n - 1)! \frac{x^{n}}{n!}` (where `\sigma (n)` is the sum of the divisors of `n`). :: - sage: [sum(divisors(i))*factorial(i-1) for i in range(1,8)] + sage: [sum(divisors(i))*factorial(i-1) for i in range(1,8)] # optional - sage.modules [1, 3, 8, 42, 144, 1440, 5760] AUTHORS: @@ -6151,37 +6151,37 @@ def arithmetic_product(self, *args, check=True): Check that the product with zero works:: - sage: s = SymmetricFunctions(QQ).s() - sage: L = LazySymmetricFunctions(s) - sage: L(0).arithmetic_product(s[2]) + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: L(0).arithmetic_product(s[2]) # optional - sage.modules 0 - sage: L(s[2]).arithmetic_product(0) + sage: L(s[2]).arithmetic_product(0) # optional - sage.modules 0 Check that the arithmetic product of symmetric functions of finite support works:: - sage: L(s([2])).arithmetic_product(s([1,1,1])) + sage: L(s([2])).arithmetic_product(s([1,1,1])) # optional - sage.modules s[2, 2, 1, 1] + s[3, 1, 1, 1] + s[3, 2, 1] + s[3, 3] + 2*s[4, 1, 1] - sage: f = 1/(1-L(s[1])) - sage: f.arithmetic_product(s[1]) - f + sage: f = 1/(1-L(s[1])) # optional - sage.modules + sage: f.arithmetic_product(s[1]) - f # optional - sage.modules O^7 Check that the arithmetic product of symmetric functions with constant a term works as advertised:: - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(p) - sage: L(5).arithmetic_product(3*p[2,1]) + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: L = LazySymmetricFunctions(p) # optional - sage.modules + sage: L(5).arithmetic_product(3*p[2,1]) # optional - sage.modules 15*p[] Check the arithmetic product of symmetric functions over a finite field works:: - sage: s = SymmetricFunctions(FiniteField(2)).s() - sage: L = LazySymmetricFunctions(s) - sage: L(s([2])).arithmetic_product(s([1,1,1])) + sage: s = SymmetricFunctions(FiniteField(2)).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: L(s([2])).arithmetic_product(s([1,1,1])) # optional - sage.modules s[2, 2, 1, 1] + s[3, 1, 1, 1] + s[3, 2, 1] + s[3, 3] """ @@ -6278,36 +6278,36 @@ def symmetric_function(self, degree=None): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).s() - sage: S = LazySymmetricFunctions(s) - sage: elt = S(s[2]) - sage: elt.symmetric_function() + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: S = LazySymmetricFunctions(s) # optional - sage.modules + sage: elt = S(s[2]) # optional - sage.modules + sage: elt.symmetric_function() # optional - sage.modules s[2] TESTS:: - sage: s = SymmetricFunctions(QQ).s() - sage: S = LazySymmetricFunctions(s) - sage: elt = S(s[2]) - sage: elt.symmetric_function() + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: S = LazySymmetricFunctions(s) # optional - sage.modules + sage: elt = S(s[2]) # optional - sage.modules + sage: elt.symmetric_function() # optional - sage.modules s[2] - sage: f = 1 / (1 - elt) - sage: f + sage: f = 1 / (1 - elt) # optional - sage.modules + sage: f # optional - sage.modules s[] + s[2] + (s[2,2]+s[3,1]+s[4]) + (s[2,2,2]+2*s[3,2,1]+s[3,3]+s[4,1,1]+3*s[4,2]+2*s[5,1]+s[6]) + O^7 - sage: f.symmetric_function() + sage: f.symmetric_function() # optional - sage.modules Traceback (most recent call last): ... ValueError: not a symmetric function - sage: f4 = f.truncate(5); f4 + sage: f4 = f.truncate(5); f4 # optional - sage.modules s[] + s[2] + (s[2,2]+s[3,1]+s[4]) - sage: f4.symmetric_function() + sage: f4.symmetric_function() # optional - sage.modules s[] + s[2] + s[2, 2] + s[3, 1] + s[4] - sage: f4.symmetric_function() == f.symmetric_function(4) + sage: f4.symmetric_function() == f.symmetric_function(4) # optional - sage.modules True - sage: S.zero().symmetric_function() + sage: S.zero().symmetric_function() # optional - sage.modules 0 - sage: f4.symmetric_function(0) + sage: f4.symmetric_function(0) # optional - sage.modules s[] """ diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index 32545f65574..e1358b0704b 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -712,9 +712,9 @@ def one(self): sage: L.one() 1 - sage: m = SymmetricFunctions(ZZ).m() - sage: L = LazySymmetricFunctions(m) - sage: L.one() + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: L.one() # optional - sage.modules m[] """ @@ -733,9 +733,9 @@ def zero(self): sage: L.zero() 0 - sage: s = SymmetricFunctions(ZZ).s() - sage: L = LazySymmetricFunctions(s) - sage: L.zero() + sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: L.zero() # optional - sage.modules 0 sage: L = LazyDirichletSeriesRing(ZZ, 'z') @@ -807,11 +807,11 @@ def _coerce_map_from_(self, S): sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings True - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # optional - sage.modules sage.rings.finite_rings + sage: L.has_coerce_map_from(ZZ) # optional - sage.modules sage.rings.finite_rings True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) # optional - sage.modules sage.rings.finite_rings True """ if self.base_ring().has_coerce_map_from(S): @@ -2237,27 +2237,26 @@ class LazyCompletionGradedAlgebra(LazySeriesRing): EXAMPLES:: - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) - sage: S = NCSF.Complete() - sage: L = S.formal_series_ring() - sage: L - Lazy completion of Non-Commutative Symmetric Functions over the Rational Field in the Complete basis + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # optional - sage.modules + sage: S = NCSF.Complete() # optional - sage.modules + sage: L = S.formal_series_ring(); L # optional - sage.modules + Lazy completion of Non-Commutative Symmetric Functions + over the Rational Field in the Complete basis - sage: f = 1 / (1 - L(S[1])) - sage: f - S[] + S[1] + (S[1,1]) + (S[1,1,1]) + (S[1,1,1,1]) + (S[1,1,1,1,1]) + (S[1,1,1,1,1,1]) + O^7 - sage: g = 1 / (1 - L(S[2])) - sage: g + sage: f = 1 / (1 - L(S[1])); f # optional - sage.modules + S[] + S[1] + (S[1,1]) + (S[1,1,1]) + (S[1,1,1,1]) + (S[1,1,1,1,1]) + + (S[1,1,1,1,1,1]) + O^7 + sage: g = 1 / (1 - L(S[2])); g # optional - sage.modules S[] + S[2] + (S[2,2]) + (S[2,2,2]) + O^7 - sage: f * g + sage: f * g # optional - sage.modules S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[1,2]) + (S[1,1,1,1]+S[1,1,2]+S[2,2]) + (S[1,1,1,1,1]+S[1,1,1,2]+S[1,2,2]) + (S[1,1,1,1,1,1]+S[1,1,1,1,2]+S[1,1,2,2]+S[2,2,2]) + O^7 - sage: g * f + sage: g * f # optional - sage.modules S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[2,1]) + (S[1,1,1,1]+S[2,1,1]+S[2,2]) + (S[1,1,1,1,1]+S[2,1,1,1]+S[2,2,1]) + (S[1,1,1,1,1,1]+S[2,1,1,1,1]+S[2,2,1,1]+S[2,2,2]) + O^7 - sage: f * g - g * f + sage: f * g - g * f # optional - sage.modules (S[1,2]-S[2,1]) + (S[1,1,2]-S[2,1,1]) + (S[1,1,1,2]+S[1,2,2]-S[2,1,1,1]-S[2,2,1]) + (S[1,1,1,1,2]+S[1,1,2,2]-S[2,1,1,1,1]-S[2,2,1,1]) + O^7 @@ -2272,23 +2271,23 @@ def __init__(self, basis, sparse=True, category=None): sage: LazySymmetricFunctions.options.halting_precision(6) - sage: s = SymmetricFunctions(QQ).s() - sage: L = LazySymmetricFunctions(s) - sage: TestSuite(L).run() + sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: TestSuite(L).run() # optional - sage.modules - sage: p = SymmetricFunctions(GF(5)).p() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(p) # optional - sage.rings.finite_rings - sage: TestSuite(L).run() # optional - sage.rings.finite_rings + sage: p = SymmetricFunctions(GF(5)).p() # optional - sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(p) # optional - sage.modules sage.rings.finite_rings + sage: TestSuite(L).run() # optional - sage.modules sage.rings.finite_rings Reversion will only work when the base ring is a field:: - sage: s = SymmetricFunctions(ZZ).s() - sage: L = LazySymmetricFunctions(s) - sage: TestSuite(L).run(skip=['_test_revert']) + sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: TestSuite(L).run(skip=['_test_revert']) # optional - sage.modules - sage: s = SymmetricFunctions(QQ["q"]).s() - sage: L = LazySymmetricFunctions(s) - sage: TestSuite(L).run(skip=['_test_revert']) + sage: s = SymmetricFunctions(QQ["q"]).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: TestSuite(L).run(skip=['_test_revert']) # optional - sage.modules Options are remembered across doctests:: @@ -2297,15 +2296,15 @@ def __init__(self, basis, sparse=True, category=None): Check that :trac:`34470` is fixed. The ideal generated by `p[1]` and `p[2]` is not principal:: - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(s) - sage: L in PrincipalIdealDomains + sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules + sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: L in PrincipalIdealDomains # optional - sage.modules False Check that a basis which is not graded is not enough:: - sage: ht = SymmetricFunctions(ZZ).ht() - sage: L = LazySymmetricFunctions(ht) + sage: ht = SymmetricFunctions(ZZ).ht() # optional - sage.modules + sage: L = LazySymmetricFunctions(ht) # optional - sage.modules Traceback (most recent call last): ... ValueError: basis should be in GradedAlgebrasWithBasis @@ -2344,8 +2343,8 @@ def _repr_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings - sage: LazySymmetricFunctions(s) # optional - sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.modules sage.rings.finite_rings + sage: LazySymmetricFunctions(s) # optional - sage.modules sage.rings.finite_rings Lazy completion of Symmetric Functions over Finite Field of size 2 in the Schur basis """ return "Lazy completion of {}".format(self._laurent_poly_ring) @@ -2356,9 +2355,9 @@ def _latex_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.rings.finite_rings - sage: latex(L) # optional - sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # optional - sage.modules sage.rings.finite_rings + sage: latex(L) # optional - sage.modules sage.rings.finite_rings \text{\texttt{Symmetric{ }Functions{ }over{ }Finite{ }Field{ }of{ }size{ }2{ }in{ }the{ }Schur{ }basis}} """ from sage.misc.latex import latex @@ -2370,10 +2369,10 @@ def _monomial(self, c, n): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() - sage: s = SymmetricFunctions(ZZ).s() - sage: L = LazySymmetricFunctions(m) - sage: L._monomial(s[2,1], 3) + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: L._monomial(s[2,1], 3) # optional - sage.modules 2*m[1, 1, 1] + m[2, 1] """ L = self._laurent_poly_ring @@ -2395,63 +2394,66 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No EXAMPLES:: - sage: m = SymmetricFunctions(GF(2)).m() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(m) # optional - sage.rings.finite_rings - sage: L(2) # optional - sage.rings.finite_rings + sage: m = SymmetricFunctions(GF(2)).m() # optional - sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(m) # optional - sage.modules sage.rings.finite_rings + sage: L(2) # optional - sage.modules sage.rings.finite_rings 0 - sage: L(3) # optional - sage.rings.finite_rings + sage: L(3) # optional - sage.modules sage.rings.finite_rings m[] - sage: m = SymmetricFunctions(ZZ).m() - sage: L = LazySymmetricFunctions(m) - sage: f = L(lambda i: m([i]), valuation=5, degree=10); f + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: f = L(lambda i: m([i]), valuation=5, degree=10); f # optional - sage.modules m[5] + m[6] + m[7] + m[8] + m[9] - sage: f.coefficient(6) + sage: f.coefficient(6) # optional - sage.modules m[6] - sage: f[20] + sage: f[20] # optional - sage.modules 0 Alternatively, ``x`` can be a list of elements of the base ring. Then these elements are read as coefficients of the terms of degrees starting from the ``valuation``:: - sage: f = L([m[1],m[2],m[3]], valuation=1); f + sage: f = L([m[1],m[2],m[3]], valuation=1); f # optional - sage.modules m[1] + m[2] + m[3] Finally, ``x`` can be a symmetric function:: - sage: m = SymmetricFunctions(ZZ).m() - sage: s = SymmetricFunctions(ZZ).s() - sage: L = LazySymmetricFunctions(m) - sage: L(s.an_element()) + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: L(s.an_element()) # optional - sage.modules 2*m[] + 2*m[1] + (3*m[1,1]+3*m[2]) TESTS:: - sage: e = SymmetricFunctions(ZZ).e() - sage: h = SymmetricFunctions(ZZ).h() - sage: L = LazySymmetricFunctions(tensor([h, e])) - sage: L(lambda n: 0) + sage: e = SymmetricFunctions(ZZ).e() # optional - sage.modules + sage: h = SymmetricFunctions(ZZ).h() # optional - sage.modules + sage: L = LazySymmetricFunctions(tensor([h, e])) # optional - sage.modules + sage: L(lambda n: 0) # optional - sage.modules O^7 - sage: L(lambda n: tensor([h[n], e([])]) + tensor([h([]), e[n]]), degree=3) + sage: L(lambda n: tensor([h[n], e([])]) + tensor([h([]), e[n]]), degree=3) # optional - sage.modules (2*h[]#e[]) + (h[]#e[1]+h[1]#e[]) + (h[]#e[2]+h[2]#e[]) - sage: L(lambda n: n)[3]; + sage: L(lambda n: n)[3]; # optional - sage.modules Traceback (most recent call last): ... - ValueError: coefficient 3*h[] # e[] should be an element of homogeneous degree 3 but has degree 0 + ValueError: coefficient 3*h[] # e[] should be an element + of homogeneous degree 3 but has degree 0 - sage: L([1, 2, 3]); + sage: L([1, 2, 3]); # optional - sage.modules Traceback (most recent call last): ... - ValueError: coefficient 2*h[] # e[] should be an element of homogeneous degree 1 but has degree 0 + ValueError: coefficient 2*h[] # e[] should be an element + of homogeneous degree 1 but has degree 0 - sage: L(lambda n: n, degree=3); + sage: L(lambda n: n, degree=3); # optional - sage.modules Traceback (most recent call last): ... - ValueError: coefficient h[] # e[] should be an element of homogeneous degree 1 but has degree 0 + ValueError: coefficient h[] # e[] should be an element + of homogeneous degree 1 but has degree 0 """ if valuation is None: valuation = 0 @@ -2566,9 +2568,9 @@ def _an_element_(self): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() - sage: L = LazySymmetricFunctions(m) - sage: L.an_element() + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: L.an_element() # optional - sage.modules 2*m[] + 2*m[1] + 3*m[2] """ return self(self._laurent_poly_ring.an_element()) @@ -2579,9 +2581,9 @@ def some_elements(self): EXAMPLES:: - sage: m = SymmetricFunctions(GF(5)).m() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(m) # optional - sage.rings.finite_rings - sage: L.some_elements()[:5] # optional - sage.rings.finite_rings + sage: m = SymmetricFunctions(GF(5)).m() # optional - sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(m) # optional - sage.modules sage.rings.finite_rings + sage: L.some_elements()[:5] # optional - sage.modules sage.rings.finite_rings [0, m[], 2*m[] + 2*m[1] + 3*m[2], 2*m[1] + 3*m[2], 3*m[] + 2*m[1] + (m[1,1]+m[2]) + (2*m[1,1,1]+m[3]) @@ -2590,10 +2592,10 @@ def some_elements(self): + (2*m[2,2,1,1]+m[2,2,2]+2*m[3,2,1]+2*m[3,3]+m[4,1,1]+3*m[4,2]+4*m[5,1]+4*m[6]) + O^7] - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) - sage: S = NCSF.Complete() - sage: L = S.formal_series_ring() - sage: L.some_elements()[:4] + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # optional - sage.modules + sage: S = NCSF.Complete() # optional - sage.modules + sage: L = S.formal_series_ring() # optional - sage.modules + sage: L.some_elements()[:4] # optional - sage.modules [0, S[], 2*S[] + 2*S[1] + (3*S[1,1]), 2*S[1] + (3*S[1,1])] """ @@ -2632,13 +2634,15 @@ class LazySymmetricFunctions(LazyCompletionGradedAlgebra): EXAMPLES:: - sage: s = SymmetricFunctions(ZZ).s() - sage: LazySymmetricFunctions(s) + sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules + sage: LazySymmetricFunctions(s) # optional - sage.modules Lazy completion of Symmetric Functions over Integer Ring in the Schur basis - sage: m = SymmetricFunctions(ZZ).m() - sage: LazySymmetricFunctions(tensor([s, m])) - Lazy completion of Symmetric Functions over Integer Ring in the Schur basis # Symmetric Functions over Integer Ring in the monomial basis + sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules + sage: LazySymmetricFunctions(tensor([s, m])) # optional - sage.modules + Lazy completion of + Symmetric Functions over Integer Ring in the Schur basis + # Symmetric Functions over Integer Ring in the monomial basis """ Element = LazySymmetricFunction diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index aa6bfc45be3..d2ca2bec4a3 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -104,12 +104,12 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) - sage: K. = A.over() # over QQ + sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: K. = A.over() # over QQ # optional - sage.rings.number_field - sage: hasattr(a, 'continued_fraction') + sage: hasattr(a, 'continued_fraction') # optional - sage.rings.number_field True - sage: a.continued_fraction() + sage: a.continued_fraction() # optional - sage.rings.number_field [1; (2)*] """ try: @@ -138,10 +138,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) - sage: K. = A.over() + sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: K. = A.over() # optional - sage.rings.number_field - sage: dir(a) + sage: dir(a) # optional - sage.rings.number_field ['__abs__', '__add__', ... From cddaa1aaed4c3594cbaa10d87db39c68e8f3faa2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 4 Jun 2023 15:27:44 -0700 Subject: [PATCH 06/50] More # optional --- src/sage/rings/ideal.py | 24 +++++++++++----------- src/sage/rings/morphism.pyx | 41 +++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 2bb3a47e4d3..de0525c3e1d 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -510,30 +510,30 @@ def apply_morphism(self, phi): TESTS:: sage: x = polygen(ZZ) - sage: K. = NumberField(x^2 + 1) - sage: A = K.ideal(a) - sage: taus = K.embeddings(K) - sage: A.apply_morphism(taus[0]) # identity + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_fields + sage: A = K.ideal(a) # optional - sage.rings.number_fields + sage: taus = K.embeddings(K) # optional - sage.rings.number_fields + sage: A.apply_morphism(taus[0]) # identity # optional - sage.rings.number_fields Fractional ideal (a) - sage: A.apply_morphism(taus[1]) # complex conjugation + sage: A.apply_morphism(taus[1]) # complex conjugation # optional - sage.rings.number_fields Fractional ideal (-a) - sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1]) + sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1]) # optional - sage.rings.number_fields True :: - sage: K. = NumberField(x^2 + 5) - sage: B = K.ideal([2, a + 1]); B + sage: K. = NumberField(x^2 + 5) # optional - sage.rings.number_fields + sage: B = K.ideal([2, a + 1]); B # optional - sage.rings.number_fields Fractional ideal (2, a + 1) - sage: taus = K.embeddings(K) - sage: B.apply_morphism(taus[0]) # identity + sage: taus = K.embeddings(K) # optional - sage.rings.number_fields + sage: B.apply_morphism(taus[0]) # identity # optional - sage.rings.number_fields Fractional ideal (2, a + 1) Since 2 is totally ramified, complex conjugation fixes it:: - sage: B.apply_morphism(taus[1]) # complex conjugation + sage: B.apply_morphism(taus[1]) # complex conjugation # optional - sage.rings.number_fields Fractional ideal (2, a + 1) - sage: taus[1](B) + sage: taus[1](B) # optional - sage.rings.number_fields Fractional ideal (2, a + 1) """ from sage.categories.morphism import is_Morphism diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 9a88fccc29f..9e5b1b0f551 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -200,23 +200,24 @@ Inclusion from `\QQ` to the 3-adic field:: An automorphism of a quotient of a univariate polynomial ring:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2 - 2) - sage: sqrt2^2 + sage: S. = R.quo(x^2 - 2) # optional - sage.libs.pari + sage: sqrt2^2 # optional - sage.libs.pari 2 - sage: (3+sqrt2)^10 + sage: (3+sqrt2)^10 # optional - sage.libs.pari 993054*sqrt2 + 1404491 - sage: c = S.hom([-sqrt2]) - sage: c(1+sqrt2) + sage: c = S.hom([-sqrt2]) # optional - sage.libs.pari + sage: c(1+sqrt2) # optional - sage.libs.pari -sqrt2 + 1 Note that Sage verifies that the morphism is valid:: - sage: (1 - sqrt2)^2 + sage: (1 - sqrt2)^2 # optional - sage.libs.pari -2*sqrt2 + 3 - sage: c = S.hom([1-sqrt2]) # this is not valid + sage: c = S.hom([1 - sqrt2]) # this is not valid # optional - sage.libs.pari 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 Endomorphism of power series ring:: @@ -278,35 +279,35 @@ positive:: Complex conjugation on cyclotomic fields:: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]); c + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]); c # optional - sage.rings.number_field Ring endomorphism of Cyclotomic Field of order 7 and degree 6 Defn: zeta7 |--> -zeta7^5 - zeta7^4 - zeta7^3 - zeta7^2 - zeta7 - 1 - sage: a = (1+zeta7)^5; a + sage: a = (1+zeta7)^5; a # optional - sage.rings.number_field zeta7^5 + 5*zeta7^4 + 10*zeta7^3 + 10*zeta7^2 + 5*zeta7 + 1 - sage: c(a) + sage: c(a) # optional - sage.rings.number_field 5*zeta7^5 + 5*zeta7^4 - 4*zeta7^2 - 5*zeta7 - 4 - sage: c(zeta7 + 1/zeta7) # this element is obviously fixed by inversion + sage: c(zeta7 + 1/zeta7) # this element is obviously fixed by inversion # optional - sage.rings.number_field -zeta7^5 - zeta7^4 - zeta7^3 - zeta7^2 - 1 - sage: zeta7 + 1/zeta7 + sage: zeta7 + 1/zeta7 # optional - sage.rings.number_field -zeta7^5 - zeta7^4 - zeta7^3 - zeta7^2 - 1 Embedding a number field into the reals:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^3 - 2) - sage: alpha = RR(2)^(1/3); alpha + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: alpha = RR(2)^(1/3); alpha # optional - sage.rings.number_field 1.25992104989487 - sage: i = K.hom([alpha],check=False); i + sage: i = K.hom([alpha],check=False); i # optional - sage.rings.number_field Ring morphism: From: Number Field in beta with defining polynomial x^3 - 2 To: Real Field with 53 bits of precision Defn: beta |--> 1.25992104989487 - sage: i(beta) + sage: i(beta) # optional - sage.rings.number_field 1.25992104989487 - sage: i(beta^3) + sage: i(beta^3) # optional - sage.rings.number_field 2.00000000000000 - sage: i(beta^2 + 1) + sage: i(beta^2 + 1) # optional - sage.rings.number_field 2.58740105196820 An example from Jim Carlson:: From 6360ca7aa57f6c0a3435b60a1dae431cc5435e67 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 4 Jun 2023 23:30:25 -0700 Subject: [PATCH 07/50] sage.rings: More # optional --- src/sage/rings/complex_mpfr.pyx | 42 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 49f10a44373..4551a330989 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -2371,37 +2371,35 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): First we compute `\eta(1+i)`:: sage: i = CC.0 - sage: z = 1+i; z.eta() + sage: z = 1 + i; z.eta() # optional - sage.libs.pari 0.742048775836565 + 0.198831370229911*I We compute eta to low precision directly from the definition:: - sage: z = 1 + i; z.eta() - 0.742048775836565 + 0.198831370229911*I - sage: pi = CC(pi) # otherwise we will get a symbolic result. - sage: exp(pi * i * z / 12) * prod([1-exp(2*pi*i*n*z) for n in range(1,10)]) + sage: pi = CC(pi) # otherwise we will get a symbolic result. # optional - sage.symbolic + sage: exp(pi * i * z / 12) * prod(1 - exp(2*pi*i*n*z) # optional - sage.symbolic + ....: for n in range(1,10)) 0.742048775836565 + 0.198831370229911*I The optional argument allows us to omit the fractional part:: - sage: z = 1 + i - sage: z.eta(omit_frac=True) + sage: z.eta(omit_frac=True) # optional - sage.libs.pari 0.998129069925959 - sage: prod([1-exp(2*pi*i*n*z) for n in range(1,10)]) + sage: prod(1 - exp(2*pi*i*n*z) for n in range(1,10)) # optional - sage.symbolic 0.998129069925958 + 4.59099857829247e-19*I We illustrate what happens when `z` is not in the upper half plane:: sage: z = CC(1) - sage: z.eta() + sage: z.eta() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: value must be in the upper half plane You can also use functional notation:: - sage: eta(1+CC(I)) + sage: eta(1 + CC(I)) # optional - sage.libs.pari 0.742048775836565 + 0.198831370229911*I """ try: @@ -2586,7 +2584,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): 1.62780548487271 + 0.136827548397369*I sage: a.agm(b, algorithm="principal") 1.62780548487271 + 0.136827548397369*I - sage: a.agm(b, algorithm="pari") + sage: a.agm(b, algorithm="pari") # optional - sage.libs.pari 1.62780548487271 + 0.136827548397369*I An example to show that the returned value depends on the algorithm @@ -2604,7 +2602,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): 0.490319232466314 sage: a.agm(b, algorithm="principal").abs() 0.338446122230459 - sage: a.agm(b, algorithm="pari").abs() + sage: a.agm(b, algorithm="pari").abs() # optional - sage.libs.pari 0.490319232466314 TESTS: @@ -2871,17 +2869,17 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: i = ComplexField(30).0 - sage: (1+i).gamma() + sage: (1 + i).gamma() # optional - sage.libs.pari 0.49801567 - 0.15494983*I TESTS:: - sage: CC(0).gamma() + sage: CC(0).gamma() # optional - sage.libs.pari Infinity :: - sage: CC(-1).gamma() + sage: CC(-1).gamma() # optional - sage.libs.pari Infinity """ try: @@ -2898,13 +2896,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: C, i = ComplexField(30).objgen() - sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 + sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 # optional - sage.libs.pari 0.0020969149 - 0.059981914*I - sage: (1+i).gamma_inc(5) + sage: (1+i).gamma_inc(5) # optional - sage.libs.pari -0.0013781309 + 0.0065198200*I - sage: C(2).gamma_inc(1 + i) + sage: C(2).gamma_inc(1 + i) # optional - sage.libs.pari 0.70709210 - 0.42035364*I - sage: CC(2).gamma_inc(5) + sage: CC(2).gamma_inc(5) # optional - sage.libs.pari 0.0404276819945128 TESTS: @@ -2912,7 +2910,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): Check that :trac:`7099` is fixed:: sage: C = ComplexField(400) - sage: C(2 + I).gamma_inc(C(3 + I)) # abs tol 1e-120 + sage: C(2 + I).gamma_inc(C(3 + I)) # abs tol 1e-120 # optional - sage.libs.pari 0.121515644664508695525971545977439666159749344176962379708992904126499444842886620664991650378432544392118359044438541515 + 0.101533909079826033296475736021224621546966200987295663190553587086145836461236284668967411665020429964946098113930918850*I """ @@ -3246,9 +3244,9 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: i = ComplexField(30).gen() sage: z = 1 + i - sage: z.zeta() + sage: z.zeta() # optional - sage.libs.pari 0.58215806 - 0.92684856*I - sage: zeta(z) + sage: zeta(z) # optional - sage.libs.pari 0.58215806 - 0.92684856*I sage: CC(1).zeta() From f768cb0d45cf6d446abd975ea958a94e896bd955 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 7 Jun 2023 17:57:55 -0700 Subject: [PATCH 08/50] sage.rings: More # optional --- src/sage/rings/abc.pyx | 8 +-- src/sage/rings/complex_double.pyx | 54 +++++++++---------- src/sage/rings/complex_mpfr.pyx | 46 ++++++++-------- src/sage/rings/continued_fraction.py | 2 +- src/sage/rings/laurent_series_ring.py | 4 +- .../rings/laurent_series_ring_element.pyx | 8 +-- src/sage/rings/puiseux_series_ring.py | 4 +- 7 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index d967cfbb95c..d62d23f7645 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -202,12 +202,12 @@ class RealBallField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(RBF, sage.rings.abc.RealBallField) + sage: isinstance(RBF, sage.rings.abc.RealBallField) # optional - sage.libs.flint True By design, there is a unique direct subclass:: - sage: sage.rings.abc.RealBallField.__subclasses__() + sage: sage.rings.abc.RealBallField.__subclasses__() # optional - sage.libs.flint [] sage: len(sage.rings.abc.RealBallField.__subclasses__()) <= 1 @@ -302,12 +302,12 @@ class ComplexBallField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CBF, sage.rings.abc.ComplexBallField) + sage: isinstance(CBF, sage.rings.abc.ComplexBallField) # optional - sage.libs.flint True By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexBallField.__subclasses__() + sage: sage.rings.abc.ComplexBallField.__subclasses__() # optional - sage.libs.flint [] sage: len(sage.rings.abc.ComplexBallField.__subclasses__()) <= 1 diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 132ae733eb9..1e679393c80 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -1145,13 +1145,13 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,2).__pari__() + sage: CDF(1,2).__pari__() # optional - sage.libs.pari 1.00000000000000 + 2.00000000000000*I - sage: pari(CDF(1,2)) + sage: pari(CDF(1,2)) # optional - sage.libs.pari 1.00000000000000 + 2.00000000000000*I - sage: pari(CDF(2.0)) + sage: pari(CDF(2.0)) # optional - sage.libs.pari 2.00000000000000 - sage: pari(CDF(I)) + sage: pari(CDF(I)) # optional - sage.libs.pari 1.00000000000000*I """ global new_gen_from_complex_double_element @@ -2194,30 +2194,30 @@ cdef class ComplexDoubleElement(FieldElement): We compute a few values of :meth:`eta()`:: - sage: CDF(0,1).eta() + sage: CDF(0,1).eta() # optional - sage.libs.pari 0.7682254223260566 - sage: CDF(1,1).eta() + sage: CDF(1,1).eta() # optional - sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I - sage: CDF(25,1).eta() + sage: CDF(25,1).eta() # optional - sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I :meth:`eta()` works even if the inputs are large:: sage: CDF(0, 10^15).eta() 0.0 - sage: CDF(10^15, 0.1).eta() # abs tol 1e-10 + sage: CDF(10^15, 0.1).eta() # abs tol 1e-10 # optional - sage.libs.pari -0.115342592727 - 0.19977923088*I We compute a few values of :meth:`eta()`, but with the fractional power of `e` omitted:: - sage: CDF(0,1).eta(True) + sage: CDF(0,1).eta(True) # optional - sage.libs.pari 0.9981290699259585 We compute :meth:`eta()` to low precision directly from the definition:: - sage: z = CDF(1,1); z.eta() + sage: z = CDF(1,1); z.eta() # optional - sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I sage: i = CDF(0,1); pi = CDF(pi) sage: exp(pi * i * z / 12) * prod([1-exp(2*pi*i*n*z) for n in range(1,10)]) @@ -2225,7 +2225,7 @@ cdef class ComplexDoubleElement(FieldElement): The optional argument allows us to omit the fractional part:: - sage: z.eta(omit_frac=True) + sage: z.eta(omit_frac=True) # optional - sage.libs.pari 0.9981290699259585 sage: pi = CDF(pi) sage: prod([1-exp(2*pi*i*n*z) for n in range(1,10)]) # abs tol 1e-12 @@ -2242,7 +2242,7 @@ cdef class ComplexDoubleElement(FieldElement): You can also use functional notation:: sage: z = CDF(1,1) - sage: eta(z) + sage: eta(z) # optional - sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I """ if GSL_IMAG(self._complex) <= 0: @@ -2372,9 +2372,9 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,2).dilog() + sage: CDF(1,2).dilog() # optional - sage.libs.pari -0.059474798673809476 + 2.0726479717747566*I - sage: CDF(10000000,10000000).dilog() + sage: CDF(10000000,10000000).dilog() # optional - sage.libs.pari -134.411774490731 + 38.79396299904504*I """ global complex_double_element_dilog @@ -2389,13 +2389,13 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(5,0).gamma() + sage: CDF(5,0).gamma() # optional - sage.libs.pari 24.0 - sage: CDF(1,1).gamma() + sage: CDF(1,1).gamma() # optional - sage.libs.pari 0.49801566811835607 - 0.15494982830181067*I - sage: CDF(0).gamma() + sage: CDF(0).gamma() # optional - sage.libs.pari Infinity - sage: CDF(-1,0).gamma() + sage: CDF(-1,0).gamma() # optional - sage.libs.pari Infinity """ if not GSL_IMAG(self._complex): @@ -2420,11 +2420,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,1).gamma_inc(CDF(2,3)) + sage: CDF(1,1).gamma_inc(CDF(2,3)) # optional - sage.libs.pari 0.0020969148636468277 - 0.059981913655449706*I - sage: CDF(1,1).gamma_inc(5) + sage: CDF(1,1).gamma_inc(5) # optional - sage.libs.pari -0.001378130936215849 + 0.006519820023119819*I - sage: CDF(2,0).gamma_inc(CDF(1,1)) + sage: CDF(2,0).gamma_inc(CDF(1,1)) # optional - sage.libs.pari 0.7070920963459381 - 0.4203536409598115*I """ global complex_double_element_gamma_inc @@ -2439,11 +2439,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: sage: z = CDF(1, 1) - sage: z.zeta() + sage: z.zeta() # optional - sage.libs.pari 0.5821580597520036 - 0.9268485643308071*I - sage: zeta(z) + sage: zeta(z) # optional - sage.libs.pari 0.5821580597520036 - 0.9268485643308071*I - sage: zeta(CDF(1)) + sage: zeta(CDF(1)) # optional - sage.libs.pari Infinity """ if GSL_REAL(self._complex) == 1 and GSL_IMAG(self._complex) == 0: @@ -2469,16 +2469,16 @@ cdef class ComplexDoubleElement(FieldElement): sage: z = (1/2)*(1 + RDF(sqrt(3)) *CDF.0); z # abs tol 1e-16 0.5 + 0.8660254037844387*I - sage: p = z.algdep(5); p + sage: p = z.algdep(5); p # optional - sage.libs.pari sage.symbolic x^2 - x + 1 sage: abs(z^2 - z + 1) < 1e-14 True :: - sage: CDF(0,2).algdep(10) + sage: CDF(0,2).algdep(10) # optional - sage.libs.pari x^2 + 4 - sage: CDF(1,5).algdep(2) + sage: CDF(1,5).algdep(2) # optional - sage.libs.pari x^2 - 2*x + 26 """ from sage.arith.misc import algdep diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 4551a330989..236df6a6b2e 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -2111,7 +2111,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arccos() + sage: (1+CC(I)).arccos() # optional - sage.libs.pari 0.904556894302381 - 1.06127506190504*I """ return self._parent(self.__pari__().acos()) @@ -2122,7 +2122,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arccosh() + sage: (1+CC(I)).arccosh() # optional - sage.libs.pari 1.06127506190504 + 0.904556894302381*I """ return self._parent(self.__pari__().acosh()) @@ -2133,7 +2133,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arcsin() + sage: (1+CC(I)).arcsin() # optional - sage.libs.pari 0.666239432492515 + 1.06127506190504*I """ return self._parent(self.__pari__().asin()) @@ -2144,7 +2144,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arcsinh() + sage: (1+CC(I)).arcsinh() # optional - sage.libs.pari 1.06127506190504 + 0.666239432492515*I """ return self._parent(self.__pari__().asinh()) @@ -2155,7 +2155,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arctan() + sage: (1+CC(I)).arctan() # optional - sage.libs.pari 1.01722196789785 + 0.402359478108525*I """ return self._parent(self.__pari__().atan()) @@ -2166,7 +2166,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arctanh() + sage: (1+CC(I)).arctanh() # optional - sage.libs.pari 0.402359478108525 + 1.01722196789785*I """ return self._parent(self.__pari__().atanh()) @@ -2177,7 +2177,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).coth() + sage: ComplexField(100)(1,1).coth() # optional - sage.libs.pari 0.86801414289592494863584920892 - 0.21762156185440268136513424361*I """ return ~(self.tanh()) @@ -2188,7 +2188,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arccoth() + sage: ComplexField(100)(1,1).arccoth() # optional - sage.libs.pari 0.40235947810852509365018983331 - 0.55357435889704525150853273009*I """ return (~self).arctanh() @@ -2199,7 +2199,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).csc() + sage: ComplexField(100)(1,1).csc() # optional - sage.libs.pari 0.62151801717042842123490780586 - 0.30393100162842645033448560451*I """ return ~(self.sin()) @@ -2210,7 +2210,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).csch() + sage: ComplexField(100)(1,1).csch() # optional - sage.libs.pari 0.30393100162842645033448560451 - 0.62151801717042842123490780586*I """ return ~(self.sinh()) @@ -2221,7 +2221,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arccsch() + sage: ComplexField(100)(1,1).arccsch() # optional - sage.libs.pari 0.53063753095251782601650945811 - 0.45227844715119068206365839783*I """ return (~self).arcsinh() @@ -2232,7 +2232,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).sec() + sage: ComplexField(100)(1,1).sec() # optional - sage.libs.pari 0.49833703055518678521380589177 + 0.59108384172104504805039169297*I """ return ~(self.cos()) @@ -2243,7 +2243,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).sech() + sage: ComplexField(100)(1,1).sech() # optional - sage.libs.pari 0.49833703055518678521380589177 - 0.59108384172104504805039169297*I """ return ~(self.cosh()) @@ -2254,7 +2254,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arcsech() + sage: ComplexField(100)(1,1).arcsech() # optional - sage.libs.pari 0.53063753095251782601650945811 - 1.1185178796437059371676632938*I """ return (~self).arccosh() @@ -2265,13 +2265,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).cot() + sage: (1+CC(I)).cot() # optional - sage.libs.pari 0.217621561854403 - 0.868014142895925*I - sage: i = ComplexField(200).0 - sage: (1+i).cot() + sage: i = ComplexField(200).0 # optional - sage.libs.pari + sage: (1+i).cot() # optional - sage.libs.pari 0.21762156185440268136513424360523807352075436916785404091068 - 0.86801414289592494863584920891627388827343874994609327121115*I - sage: i = ComplexField(220).0 - sage: (1+i).cot() + sage: i = ComplexField(220).0 # optional - sage.libs.pari + sage: (1+i).cot() # optional - sage.libs.pari 0.21762156185440268136513424360523807352075436916785404091068124239 - 0.86801414289592494863584920891627388827343874994609327121115071646*I TESTS: @@ -2596,7 +2596,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): -0.371591652351761 + 0.319894660206830*I sage: a.agm(b, algorithm="principal") 0.338175462986180 - 0.0135326969565405*I - sage: a.agm(b, algorithm="pari") + sage: a.agm(b, algorithm="pari") # optional - sage.libs.pari -0.371591652351761 + 0.319894660206830*I sage: a.agm(b, algorithm="optimal").abs() 0.490319232466314 @@ -2819,7 +2819,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: a = ComplexNumber(1,0) - sage: a.dilog() + sage: a.dilog() # optional - sage.libs.pari 1.64493406684823 sage: float(pi^2/6) # optional - sage.symbolic 1.6449340668482262 @@ -2827,13 +2827,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): :: sage: b = ComplexNumber(0,1) - sage: b.dilog() + sage: b.dilog() # optional - sage.libs.pari -0.205616758356028 + 0.915965594177219*I :: sage: c = ComplexNumber(0,0) - sage: c.dilog() + sage: c.dilog() # optional - sage.libs.pari 0.000000000000000 """ return self._parent(self.__pari__().dilog()) diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index c5298a34ae4..696a99753bb 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -1744,7 +1744,7 @@ def __neg__(self): sage: quots2 = [((),(1,)), ((), (1,2)), ((0,),(1,)), ....: ((),(2,1)), ((3,),(2,1))] - sage: for q in quots2: + sage: for q in quots2: # optional - sage.rings.number_field ....: cf = continued_fraction(q) ....: ncf = -cf ....: nncf = -ncf diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index e2a5c524cfe..46c86bf378d 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -442,8 +442,8 @@ def _element_constructor_(self, x, n=0, prec=infinity): Check that :trac:`28993` is fixed:: - sage: from sage.modular.etaproducts import qexp_eta - sage: qexp_eta(S, prec=30) + sage: from sage.modular.etaproducts import qexp_eta # optional - sage.modular + sage: qexp_eta(S, prec=30) # optional - sage.modular 1 - t - t^2 + t^5 + t^7 - t^12 - t^15 + t^22 + t^26 + O(t^30) When converting from `R((z))` to `R((z))((w))`, the variable diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index 8e950478045..fa08abe8d99 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -1701,11 +1701,11 @@ cdef class LaurentSeries(AlgebraElement): sage: (x^-2 + 1 + x).nth_root(2)**2 x^-2 + 1 + x + O(x^18) - sage: j = j_invariant_qexp() - sage: q = j.parent().gen() - sage: j(q^3).nth_root(3) + sage: j = j_invariant_qexp() # optional - sage.modular + sage: q = j.parent().gen() # optional - sage.modular + sage: j(q^3).nth_root(3) # optional - sage.modular q^-1 + 248*q^2 + 4124*q^5 + ... + O(q^29) - sage: (j(q^2) - 1728).nth_root(2) + sage: (j(q^2) - 1728).nth_root(2) # optional - sage.modular q^-1 - 492*q - 22590*q^3 - ... + O(q^19) """ if prec is None: diff --git a/src/sage/rings/puiseux_series_ring.py b/src/sage/rings/puiseux_series_ring.py index 27a91d6a187..fdad0caef39 100644 --- a/src/sage/rings/puiseux_series_ring.py +++ b/src/sage/rings/puiseux_series_ring.py @@ -302,8 +302,8 @@ def _element_constructor_(self, x, e=1, prec=infinity): sage: P(z) + y**(1/2) 3 + y^(1/2) + 2*y + y^2 + 2*y^3 + O(y^5) - sage: from sage.modular.etaproducts import qexp_eta - sage: y^(1/24)*qexp_eta(P, prec=30) + sage: from sage.modular.etaproducts import qexp_eta # optional - sage.modular + sage: y^(1/24)*qexp_eta(P, prec=30) # optional - sage.modular y^(1/24) - y^(25/24) - y^(49/24) + y^(121/24) + y^(169/24) - y^(289/24) - y^(361/24) + y^(529/24) + y^(625/24) + O(y^(721/24)) """ P = parent(x) From bee4da57cf80ab5f4c1c7ca3ff864cf1ede20b9b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 9 Jun 2023 00:55:41 -0700 Subject: [PATCH 09/50] More # optional --- src/sage/rings/real_lazy.pyx | 1 + src/sage/rings/ring_extension_element.pyx | 4 ++-- src/sage/rings/semirings/tropical_semiring.pyx | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/sage/rings/real_lazy.pyx b/src/sage/rings/real_lazy.pyx index b6ff3f64015..9fd6d547625 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.real_mpfr """ Lazy real and complex numbers diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index d2ca2bec4a3..98539da208f 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -553,9 +553,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): sage: A. = PolynomialRing(QQ) sage: E = A.over(QQ) - sage: E(x^2+1).is_prime() + sage: E(x^2 + 1).is_prime() # optional - sage.libs.pari True - sage: E(x^2-1).is_prime() + sage: E(x^2 - 1).is_prime() # optional - sage.libs.pari False """ return self._backend.is_prime() diff --git a/src/sage/rings/semirings/tropical_semiring.pyx b/src/sage/rings/semirings/tropical_semiring.pyx index 5beff3cff55..19d2fc1cde2 100644 --- a/src/sage/rings/semirings/tropical_semiring.pyx +++ b/src/sage/rings/semirings/tropical_semiring.pyx @@ -555,9 +555,9 @@ class TropicalSemiring(Parent, UniqueRepresentation): EXAMPLES:: - sage: TR = TropicalSemiring(RR) - sage: T60 = TropicalSemiring(RealField(60)) - sage: TR.has_coerce_map_from(T60) + sage: TR = TropicalSemiring(RR) # optional - sage.rings.real_mpfr + sage: T60 = TropicalSemiring(RealField(60)) # optional - sage.rings.real_mpfr + sage: TR.has_coerce_map_from(T60) # optional - sage.rings.real_mpfr True sage: TQ = TropicalSemiring(QQ) sage: TQ.has_coerce_map_from(TropicalSemiring(ZZ)) @@ -570,15 +570,15 @@ class TropicalSemiring(Parent, UniqueRepresentation): True sage: TR.has_coerce_map_from(float) False - sage: TR.has_coerce_map_from(RR) + sage: TR.has_coerce_map_from(RR) # optional - sage.rings.real_mpfr False sage: TR.has_coerce_map_from(QQ) False - sage: TR.coerce_map_from(T60)(T60(2)) + sage: TR.coerce_map_from(T60)(T60(2)) # optional - sage.rings.real_mpfr 2.00000000000000 - sage: TR.coerce(T60(3.4)) + sage: TR.coerce(T60(3.4)) # optional - sage.rings.real_mpfr 3.40000000000000 - sage: TR.coerce(T60.infinity()) + sage: TR.coerce(T60.infinity()) # optional - sage.rings.real_mpfr +infinity sage: TQ.coerce(TR(3.4)) Traceback (most recent call last): From c19447c89eaa324fbf5a9ec20d6a2f0718231107 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 17:49:30 -0700 Subject: [PATCH 10/50] More # optional --- src/sage/rings/lazy_series.py | 10 +++++----- src/sage/rings/quotient_ring_element.py | 8 ++++---- src/sage/rings/semirings/tropical_semiring.pyx | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index 8698af54927..cf9c4f9cb20 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -3113,7 +3113,7 @@ def _div_(self, other): An example over the ring of symmetric functions:: - sage: e = SymmetricFunctions(QQ).e() + sage: e = SymmetricFunctions(QQ).e() # optional - sage.modules sage: R. = LazyLaurentSeriesRing(e) # optional - sage.modules sage: 1 / (1 - e[1]*z) # optional - sage.modules e[] + e[1]*z + e[1, 1]*z^2 + e[1, 1, 1]*z^3 + e[1, 1, 1, 1]*z^4 @@ -5829,7 +5829,7 @@ def derivative_with_respect_to_p1(self, n=1): orderings satisfy the relationship `C' = L`:: sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) + sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) # optional - sage.modules ....: for k in divisors(n))/n if n > 0 else 0)) sage: L = T(lambda n: p([1]*n)) # optional - sage.modules sage: L - C.derivative_with_respect_to_p1() # optional - sage.modules @@ -6339,7 +6339,7 @@ class LazyDirichletSeries(LazyModuleElement): sage: f = L(constant=1)^2 sage: f # optional - sage.symbolic 1 + 2/2^z + 2/3^z + 3/4^z + 2/5^z + 4/6^z + 2/7^z + O(1/(8^z)) - sage: f.coefficient(100) == number_of_divisors(100) + sage: f.coefficient(100) == number_of_divisors(100) # optional - sage.libs.pari True Lazy Dirichlet series is picklable:: @@ -6385,9 +6385,9 @@ def valuation(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, "z") - sage: mu = L(moebius); mu.valuation() + sage: mu = L(moebius); mu.valuation() # optional - sage.libs.pari 0 - sage: (mu - mu).valuation() + sage: (mu - mu).valuation() # optional - sage.libs.pari +Infinity sage: g = L(constant=1, valuation=2) sage: g.valuation() diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 27ceb3ceaf9..8ef6d665a29 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -644,10 +644,10 @@ def _richcmp_(self, other, op): See :trac:`7797`:: - 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 + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules + sage: Q.0^4 # indirect doctest # optional - sage.combinat sage.libs.singular sage.modules ybar*zbar*zbar*xbar + ybar*zbar*zbar*ybar + ybar*zbar*zbar*zbar The issue from :trac:`8005` was most likely fixed as part of diff --git a/src/sage/rings/semirings/tropical_semiring.pyx b/src/sage/rings/semirings/tropical_semiring.pyx index 19d2fc1cde2..519f3213bd6 100644 --- a/src/sage/rings/semirings/tropical_semiring.pyx +++ b/src/sage/rings/semirings/tropical_semiring.pyx @@ -562,17 +562,17 @@ class TropicalSemiring(Parent, UniqueRepresentation): sage: TQ = TropicalSemiring(QQ) sage: TQ.has_coerce_map_from(TropicalSemiring(ZZ)) True - sage: TR.has_coerce_map_from(TR) + sage: TR.has_coerce_map_from(TR) # optional - sage.rings.real_mpfr True sage: TQ.has_coerce_map_from(TQ) True - sage: TR.has_coerce_map_from(TQ) + sage: TR.has_coerce_map_from(TQ) # optional - sage.rings.real_mpfr True - sage: TR.has_coerce_map_from(float) + sage: TR.has_coerce_map_from(float) # optional - sage.rings.real_mpfr False sage: TR.has_coerce_map_from(RR) # optional - sage.rings.real_mpfr False - sage: TR.has_coerce_map_from(QQ) + sage: TR.has_coerce_map_from(QQ) # optional - sage.rings.real_mpfr False sage: TR.coerce_map_from(T60)(T60(2)) # optional - sage.rings.real_mpfr 2.00000000000000 @@ -580,7 +580,7 @@ class TropicalSemiring(Parent, UniqueRepresentation): 3.40000000000000 sage: TR.coerce(T60.infinity()) # optional - sage.rings.real_mpfr +infinity - sage: TQ.coerce(TR(3.4)) + sage: TQ.coerce(TR(3.4)) # optional - sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: no canonical coercion from Tropical semiring over From c476af4ff49eabe388187dd22888816cf71622f3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 11 Jun 2023 00:23:10 -0700 Subject: [PATCH 11/50] src/sage/rings/integer_ring.pyx: Docstring cosmetics --- src/sage/rings/integer_ring.pyx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index b4046098436..c7eb8b053cc 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -600,10 +600,11 @@ cdef class IntegerRing_class(PrincipalIdealDomain): - ``x``, ``y`` integers -- bounds for the result. - ``distribution``-- a string: - - ``'uniform'`` - - ``'mpz_rrandomb'`` - - ``'1/n'`` - - ``'gaussian'`` + + - ``'uniform'`` + - ``'mpz_rrandomb'`` + - ``'1/n'`` + - ``'gaussian'`` OUTPUT: From 31bc15e7ce544fcbecce09fabea93d9fb6e15a36 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 11 Jun 2023 10:48:25 -0700 Subject: [PATCH 12/50] sage.rings: More # optional --- src/sage/rings/complex_mpfr.pyx | 12 ++++++------ src/sage/rings/fraction_field_element.pyx | 8 ++++---- src/sage/rings/localization.py | 6 +++--- src/sage/rings/rational.pyx | 16 ++++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 236df6a6b2e..64e3fe9cf3c 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -849,17 +849,17 @@ class ComplexField_class(sage.rings.abc.ComplexField): sage: k = ComplexField(100) sage: R. = k[] - sage: k._factor_univariate_polynomial( x ) + sage: k._factor_univariate_polynomial( x ) # optional - sage.libs.pari x - sage: k._factor_univariate_polynomial( 2*x ) + sage: k._factor_univariate_polynomial( 2*x ) # optional - sage.libs.pari (2.0000000000000000000000000000) * x - sage: k._factor_univariate_polynomial( x^2 ) + sage: k._factor_univariate_polynomial( x^2 ) # optional - sage.libs.pari x^2 - sage: k._factor_univariate_polynomial( x^2 + 3 ) + sage: k._factor_univariate_polynomial( x^2 + 3 ) # optional - sage.libs.pari (x - 1.7320508075688772935274463415*I) * (x + 1.7320508075688772935274463415*I) - sage: k._factor_univariate_polynomial( x^2 + 1 ) + sage: k._factor_univariate_polynomial( x^2 + 1 ) # optional - sage.libs.pari (x - I) * (x + I) - sage: k._factor_univariate_polynomial( k(I) * (x^2 + 1) ) + sage: k._factor_univariate_polynomial( k(I) * (x^2 + 1) ) # optional - sage.libs.pari (1.0000000000000000000000000000*I) * (x - I) * (x + I) """ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 11a2b646d35..368162e9119 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -857,15 +857,15 @@ cdef class FractionFieldElement(FieldElement): sage: x,y = FR.gens() sage: a = x^2; a x^2 - sage: type(a.numerator()) + sage: type(a.numerator()) # optional - sage.lings.singular - sage: type(a.denominator()) + sage: type(a.denominator()) # optional - sage.lings.singular sage: a = x^(-2); a 1/x^2 - sage: type(a.numerator()) + sage: type(a.numerator()) # optional - sage.lings.singular - sage: type(a.denominator()) + sage: type(a.denominator()) # optional - sage.lings.singular sage: x^0 1 diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 3062c9439d8..a0659202ac6 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -267,9 +267,9 @@ def __init__(self, parent, x): sage: from sage.rings.localization import LocalizationElement sage: P. = RR[] - sage: L = Localization(P, x**2+x+1) - sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) - sage: l._value == (x**2+1)/(x**2+x+1) + sage: L = Localization(P, x**2 + x + 1) # optional - sage.libs.pari + sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) # optional - sage.libs.pari + sage: l._value == (x**2+1)/(x**2+x+1) # optional - sage.libs.pari True """ IntegralDomainElement.__init__(self, parent) diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 313ace10d98..326bd258b06 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -3131,21 +3131,21 @@ cdef class Rational(sage.structure.element.FieldElement): 3*log(5)/log(3) sage: QQ(8).log(1/2) -3 - sage: (1/8).log(1/2) + sage: (1/8).log(1/2) # optional - sage.libs.pari 3 - sage: (1/2).log(1/8) + sage: (1/2).log(1/8) # optional - sage.libs.pari 1/3 - sage: (1/2).log(8) + sage: (1/2).log(8) # optional - sage.libs.pari -1/3 - sage: (16/81).log(8/27) + sage: (16/81).log(8/27) # optional - sage.libs.pari 4/3 - sage: (8/27).log(16/81) + sage: (8/27).log(16/81) # optional - sage.libs.pari 3/4 - sage: log(27/8, 16/81) + sage: log(27/8, 16/81) # optional - sage.libs.pari -3/4 - sage: log(16/81, 27/8) + sage: log(16/81, 27/8) # optional - sage.libs.pari -4/3 - sage: (125/8).log(5/2) + sage: (125/8).log(5/2) # optional - sage.libs.pari 3 sage: (125/8).log(5/2, prec=53) 3.00000000000000 From fa68888101ef0f96e2c3d9705e1480fd01afe72c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 11 Jun 2023 23:45:21 -0700 Subject: [PATCH 13/50] sage.rings: More # optional --- src/sage/rings/fraction_field.py | 8 +- src/sage/rings/fraction_field_element.pyx | 6 +- src/sage/rings/infinity.py | 4 +- src/sage/rings/integer_ring.pyx | 6 +- src/sage/rings/lazy_series_ring.py | 19 ++-- .../rings/multi_power_series_ring_element.py | 4 +- src/sage/rings/quotient_ring.py | 101 +++++++++--------- src/sage/rings/rational_field.py | 8 +- src/sage/rings/real_double.pyx | 18 ++-- src/sage/rings/ring.pyx | 6 +- 10 files changed, 91 insertions(+), 89 deletions(-) diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 1aff655bed8..15691eabe39 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -314,13 +314,13 @@ def _coerce_map_from_(self, S): Coercion from a localization:: sage: R. = ZZ[] - sage: L = Localization(R, (x**2 + 1,7)) - sage: F = L.fraction_field() - sage: f = F.coerce_map_from(L); f + sage: L = Localization(R, (x**2 + 1,7)) # optional - sage.libs.pari + sage: F = L.fraction_field() # optional - sage.libs.pari + sage: f = F.coerce_map_from(L); f # optional - sage.libs.pari Coercion map: From: Univariate Polynomial Ring in x over Integer Ring localized at (7, x^2 + 1) To: Fraction Field of Univariate Polynomial Ring in x over Integer Ring - sage: f(L(1/7)) == 1/7 + sage: f(L(1/7)) == 1/7 # optional - sage.libs.pari True """ from sage.rings.rational_field import QQ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 368162e9119..78b13455d56 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -173,10 +173,10 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - sage: R. = RealField(10)[] - sage: f = (x^2+2*x+1)/(x+1); f + sage: R. = RealField(10)[] # optional - sage.rings.real_mpfr + sage: f = (x^2+2*x+1)/(x+1); f # optional - sage.rings.real_mpfr (x^2 + 2.0*x + 1.0)/(x + 1.0) - sage: f.reduce(); f + sage: f.reduce(); f # optional - sage.rings.real_mpfr x + 1.0 TESTS: diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index d4cbe9372bb..4e3f27784a2 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -1769,8 +1769,8 @@ def test_comparison(ring): EXAMPLES:: sage: from sage.rings.infinity import test_comparison - sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] - sage: for R in rings: + sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] # optional - sage.rings.real_mpfr + sage: for R in rings: # optional - sage.rings.real_mpfr ....: print('testing {}'.format(R)) ....: test_comparison(R) testing Integer Ring diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index c7eb8b053cc..68933ce7fa5 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -719,7 +719,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): We return a sample from a discrete Gaussian distribution:: - sage: ZZ.random_element(11.0, distribution="gaussian").parent() is ZZ + sage: ZZ.random_element(11.0, distribution="gaussian").parent() is ZZ # optional - sage.modules True TESTS: @@ -728,7 +728,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.random_element(5, -5, distribution="1/n").parent() is ZZ True - sage: ZZ.random_element(5, -5, distribution="gaussian").parent() is ZZ + sage: ZZ.random_element(5, -5, distribution="gaussian").parent() is ZZ # optional - sage.modules True sage: ZZ.random_element(5, -5, distribution="mpz_rrandomb").parent() is ZZ True @@ -737,7 +737,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Traceback (most recent call last): ... TypeError: x must be > 0 - sage: ZZ.random_element(-10, -5, distribution="gaussian") + sage: ZZ.random_element(-10, -5, distribution="gaussian") # optional - sage.modules Traceback (most recent call last): ... TypeError: x must be > 0 diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index e1358b0704b..e105188d7fe 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -1197,7 +1197,7 @@ def __init__(self, base_ring, names, sparse=True, category=None): and Category of infinite sets sage: L = LazyLaurentSeriesRing(ZZ['x, y'], 't') - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.singular sage: L.category() Category of infinite commutative no zero divisors algebras over (unique factorization domains and commutative algebras over @@ -1220,8 +1220,8 @@ def __init__(self, base_ring, names, sparse=True, category=None): (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) - sage: E. = ExteriorAlgebra(QQ) - sage: L = LazyLaurentSeriesRing(E, 't') # not tested + sage: E. = ExteriorAlgebra(QQ) # optional - sage.modules + sage: L = LazyLaurentSeriesRing(E, 't') # not tested # optional - sage.modules sage: LazyLaurentSeriesRing.options._reset() # reset the options """ @@ -1603,7 +1603,7 @@ def euler(self): sage: P = 1 / phi; P 1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + O(q^7) - sage: P[:20] == [Partitions(n).cardinality() for n in range(20)] + sage: P[:20] == [Partitions(n).cardinality() for n in range(20)] # optional - sage.libs.flint True TESTS:: @@ -1937,11 +1937,11 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No (a + b + 1)/(c^3 + a*b + 1) sage: f.parent() Fraction Field of Multivariate Polynomial Ring in a, b, c over Integer Ring - sage: L(f) + sage: L(f) # optional - sage.libs.singular 1 + (a+b) + (-a*b) + (-a^2*b-a*b^2-c^3) + (a^2*b^2-a*c^3-b*c^3) + (a^3*b^2+a^2*b^3+2*a*b*c^3) + (-a^3*b^3+2*a^2*b*c^3+2*a*b^2*c^3+c^6) + O(a,b,c)^7 - sage: L(f) == (1 + aa + bb) / (1 + aa*bb + cc^3) + sage: L(f) == (1 + aa + bb) / (1 + aa*bb + cc^3) # optional - sage.libs.singular True TESTS:: @@ -2743,10 +2743,10 @@ def __init__(self, base_ring, names, sparse=True, category=None): sage: LazyDirichletSeriesRing.options.halting_precision(12) sage: L = LazyDirichletSeriesRing(ZZ, 't') - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.symbolic sage: L = LazyDirichletSeriesRing(QQ, 't') - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.symbolic sage: LazyDirichletSeriesRing.options._reset() # reset the options @@ -2990,8 +2990,7 @@ def _monomial(self, c, n): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: m = L._monomial(5, 3) - sage: m # optional - sage.symbolic + sage: m = L._monomial(5, 3); m # optional - sage.symbolic 5/3^z """ try: diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 9aa3f6ea5a4..0251356ecd1 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -516,8 +516,8 @@ def _subs_formal(self, *x, **kwds): -2/33*z^3 - 1/5*z^5 sage: f(z,1) #indirect doctest -1/5 - 2/33*z + z^2 - z^5 - sage: RF = RealField(10) - sage: f(z,RF(1)) #indirect doctest + sage: RF = RealField(10) # optional - sage.rings.real_mpfr + sage: f(z, RF(1)) # indirect doctest # optional - sage.rings.real_mpfr -0.20 - 0.061*z + 1.0*z^2 - 0.00*z^3 - 0.00*z^4 - 1.0*z^5 sage: m = matrix(QQ,[[1,0,1],[0,2,1],[-1,0,0]]) diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 178cae67a22..f90dcc6c9aa 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -84,17 +84,19 @@ easily:: sage: from itertools import product - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) # optional - sage.combinat sage.modules - sage: Q3 # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) # optional - sage.combinat sage.libs.singular sage.modules + sage: Q3 # optional - sage.combinat sage.libs.singular sage.modules Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) - over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) - sage: Q3.0*Q3.1 - Q3.1*Q3.0 # optional - sage.combinat sage.modules + over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, + x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, + y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) + sage: Q3.0*Q3.1 - Q3.1*Q3.0 # optional - sage.combinat sage.libs.singular sage.modules xbar*ybar - ybar*xbar - sage: Q3.0*(Q3.1*Q3.2) - (Q3.1*Q3.2)*Q3.0 # optional - sage.combinat sage.modules + sage: Q3.0*(Q3.1*Q3.2) - (Q3.1*Q3.2)*Q3.0 # optional - sage.combinat sage.libs.singular sage.modules 0 - sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) # optional - sage.combinat sage.modules - sage: Q2.is_commutative() # optional - sage.combinat sage.modules + sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) # optional - sage.combinat sage.libs.singular sage.modules + sage: Q2.is_commutative() # optional - sage.combinat sage.libs.singular sage.modules True """ @@ -246,23 +248,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') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.libs.singular sage.modules Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b # optional - sage.combinat sage.modules + sage: a*b # optional - sage.combinat sage.libs.singular sage.modules -b*c - sage: a^3 # optional - sage.combinat sage.modules + sage: a^3 # optional - sage.combinat sage.libs.singular sage.modules -b*c*a - b*c*b - b*c*c - sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules - sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.libs.singular sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.libs.singular sage.modules Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 # optional - sage.combinat sage.modules + sage: i^3 # optional - sage.combinat sage.libs.singular sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat sage.modules + sage: j^3 # optional - sage.combinat sage.libs.singular 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)` @@ -348,12 +350,12 @@ def is_QuotientRing(x): :: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.modules - sage: is_QuotientRing(Q) # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules + sage: is_QuotientRing(Q) # optional - sage.combinat sage.libs.singular sage.modules True - sage: is_QuotientRing(F) # optional - sage.combinat sage.modules + sage: is_QuotientRing(F) # optional - sage.combinat sage.libs.singular sage.modules False """ return isinstance(x, QuotientRing_nc) @@ -376,26 +378,27 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): Here is a quotient of a free algebra by a twosided homogeneous ideal:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2]*F # optional - sage.combinat sage.modules - sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2]*F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.libs.singular sage.modules Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b # optional - sage.combinat sage.modules + sage: a*b # optional - sage.combinat sage.libs.singular sage.modules -b*c - sage: a^3 # optional - sage.combinat sage.modules + sage: a^3 # optional - sage.combinat sage.libs.singular sage.modules -b*c*a - b*c*b - b*c*c A quotient of a quotient is just the quotient of the original top ring by the sum of two ideals:: - sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules - sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.libs.singular sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.libs.singular sage.modules + Quotient of + Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 # optional - sage.combinat sage.modules + sage: i^3 # optional - sage.combinat sage.libs.singular sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat sage.modules + sage: j^3 # optional - sage.combinat sage.libs.singular sage.modules -j*k*i - j*k*j - j*k*k For rings that *do* inherit from :class:`~sage.rings.ring.CommutativeRing`, @@ -449,15 +452,15 @@ def __init__(self, R, I, names, category=None): EXAMPLES:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.libs.singular sage.modules Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b # optional - sage.combinat sage.modules + sage: a*b # optional - sage.combinat sage.libs.singular sage.modules -b*c - sage: a^3 # optional - sage.combinat sage.modules + sage: a^3 # optional - sage.combinat sage.libs.singular sage.modules -b*c*a - b*c*b - b*c*c """ @@ -504,10 +507,10 @@ def construction(self): sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: R.quotient_ring(I).construction() (QuotientFunctor, Univariate Polynomial Ring in x over Integer Ring) - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.modules - sage: Q.construction() # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules + sage: Q.construction() # optional - sage.combinat sage.libs.singular sage.modules (QuotientFunctor, Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) @@ -589,19 +592,19 @@ def is_commutative(self): The non-commutative case is more interesting:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.modules - sage: Q.is_commutative() # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules + sage: Q.is_commutative() # optional - sage.combinat sage.libs.singular sage.modules False - sage: Q.1*Q.2 == Q.2*Q.1 # optional - sage.combinat sage.modules + sage: Q.1*Q.2 == Q.2*Q.1 # optional - sage.combinat sage.libs.singular sage.modules False In the next example, the generators apparently commute:: - sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # optional - sage.combinat sage.modules - sage: R = F.quo(J) # optional - sage.combinat sage.modules - sage: R.is_commutative() # optional - sage.combinat sage.modules + sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # optional - sage.combinat sage.libs.singular sage.modules + sage: R = F.quo(J) # optional - sage.combinat sage.libs.singular sage.modules + sage: R.is_commutative() # optional - sage.combinat sage.libs.singular sage.modules True """ diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 6c7ba63c29f..5d74779c564 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -657,7 +657,7 @@ def places(self, all_complex=False, prec=None): EXAMPLES:: - sage: QQ.places() + sage: QQ.places() # optional - sage.rings.real_mpfr [Ring morphism: From: Rational Field To: Real Field with 53 bits of precision @@ -667,7 +667,7 @@ def places(self, all_complex=False, prec=None): From: Rational Field To: Real Double Field Defn: 1 |--> 1.0] - sage: QQ.places(prec=200, all_complex=True) + sage: QQ.places(prec=200, all_complex=True) # optional - sage.rings.real_mpfr [Ring morphism: From: Rational Field To: Complex Field with 200 bits of precision @@ -696,12 +696,12 @@ def complex_embedding(self, prec=53): EXAMPLES:: - sage: QQ.complex_embedding() + sage: QQ.complex_embedding() # optional - sage.rings.real_mpfr Ring morphism: From: Rational Field To: Complex Field with 53 bits of precision Defn: 1 |--> 1.00000000000000 - sage: QQ.complex_embedding(20) + sage: QQ.complex_embedding(20) # optional - sage.rings.real_mpfr Ring morphism: From: Rational Field To: Complex Field with 20 bits of precision diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index ec4af251254..11de275ce72 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -84,7 +84,7 @@ def is_RealDoubleField(x): use isinstance(..., sage.rings.abc.RealDoubleField) instead See https://github.com/sagemath/sage/issues/32610 for details. True - sage: is_RealDoubleField(RealField(53)) + sage: is_RealDoubleField(RealField(53)) # optional - sage.rings.real_mpfr False """ from sage.misc.superseded import deprecation @@ -128,15 +128,15 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: - sage: a = RealField(200)(2).sqrt(); a + sage: a = RealField(200)(2).sqrt(); a # optional - sage.rings.real_mpfr 1.4142135623730950488016887242096980785696718753769480731767 - sage: b = RDF(a); b + sage: b = RDF(a); b # optional - sage.rings.real_mpfr 1.4142135623730951 - sage: a.parent()(b) + sage: a.parent()(b) # optional - sage.rings.real_mpfr 1.4142135623730951454746218587388284504413604736328125000000 - sage: a.parent()(b) == b + sage: a.parent()(b) == b # optional - sage.rings.real_mpfr True - sage: b == RR(a) + sage: b == RR(a) # optional - sage.rings.real_mpfr True TESTS:: @@ -446,7 +446,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RDF.to_prec(52) + sage: RDF.to_prec(52) # optional - sage.rings.real_mpfr Real Field with 52 bits of precision sage: RDF.to_prec(53) Real Double Field @@ -1167,8 +1167,8 @@ cdef class RealDoubleElement(FieldElement): sage: RDF(2.1)._im_gens_(RR, [RR(1)]) 2.10000000000000 - sage: R = RealField(20) - sage: RDF(2.1)._im_gens_(R, [R(1)]) + sage: R = RealField(20) # optional - sage.rings.real_mpfr + sage: RDF(2.1)._im_gens_(R, [R(1)]) # optional - sage.rings.real_mpfr 2.1000 """ return codomain(self) # since 1 |--> 1 diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 4cba2c9ba7f..8780f23483e 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -1123,9 +1123,9 @@ cdef class Ring(ParentWithGens): sage: RDF.epsilon() 2.220446049250313e-16 - sage: ComplexField(53).epsilon() + sage: ComplexField(53).epsilon() # optional - sage.rings.real_mpfr 2.22044604925031e-16 - sage: RealField(10).epsilon() + sage: RealField(10).epsilon() # optional - sage.rings.real_mpfr 0.0020 For exact rings, zero is returned:: @@ -1142,7 +1142,7 @@ cdef class Ring(ParentWithGens): For the symbolic ring, there is no reasonable answer:: - sage: SR.epsilon() # optional - sage.symbolics + sage: SR.epsilon() # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError From 74deb0fd0bd6afccd71bc07b418286582f726eae Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 12 Jun 2023 09:16:40 -0700 Subject: [PATCH 14/50] src/sage/rings/multi_power_series_ring_element.py: Add # optional --- src/sage/rings/multi_power_series_ring_element.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 0251356ecd1..eeca8245b90 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -520,22 +520,21 @@ def _subs_formal(self, *x, **kwds): sage: f(z, RF(1)) # indirect doctest # optional - sage.rings.real_mpfr -0.20 - 0.061*z + 1.0*z^2 - 0.00*z^3 - 0.00*z^4 - 1.0*z^5 - sage: m = matrix(QQ,[[1,0,1],[0,2,1],[-1,0,0]]) - sage: m + sage: m = matrix(QQ,[[1,0,1],[0,2,1],[-1,0,0]]); m # optional - sage.modules [ 1 0 1] [ 0 2 1] [-1 0 0] - sage: f(m,m) #indirect doctest + sage: f(m,m) # indirect doctest # optional - sage.modules [ 2/33 0 1/5] [ 131/55 -1136/165 -24/11] [ -1/5 0 -23/165] - sage: f(m,m) == -2/33*m^3 - 1/5*m^5 #indirect doctest + sage: f(m,m) == -2/33*m^3 - 1/5*m^5 # indirect doctest # optional - sage.modules True sage: f = f.add_bigoh(10) sage: f(z,z) -2/33*z^3 - 1/5*z^5 + O(z^10) - sage: f(m,m) + sage: f(m,m) # optional - sage.modules Traceback (most recent call last): ... AttributeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' object has no attribute 'add_bigoh' From 608def5b6f425022895eb74170c37bc18d0dba35 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 14 Jun 2023 18:25:01 -0700 Subject: [PATCH 15/50] sage.rings: More # optional --- src/sage/rings/ideal.py | 12 ++-- src/sage/rings/laurent_series_ring.py | 5 +- .../rings/laurent_series_ring_element.pyx | 3 +- src/sage/rings/rational.pyx | 62 +++++++++---------- src/sage/rings/rational_field.py | 12 ++-- src/sage/rings/ring.pyx | 12 ++-- 6 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index de0525c3e1d..72204ac3dec 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -486,14 +486,14 @@ def apply_morphism(self, phi): EXAMPLES:: - sage: psi = CC['x'].hom([-CC['x'].0]) - sage: J = ideal([CC['x'].0 + 1]); J + sage: psi = CC['x'].hom([-CC['x'].0]) # optional - sage.rings.real_mpfr + sage: J = ideal([CC['x'].0 + 1]); J # optional - sage.rings.real_mpfr Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision - sage: psi(J) + sage: psi(J) # optional - sage.rings.real_mpfr Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision - sage: J.apply_morphism(psi) + sage: J.apply_morphism(psi) # optional - sage.rings.real_mpfr Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision @@ -965,8 +965,8 @@ def is_trivial(self): :: - sage: I = CC['x'].ideal(0) - sage: I.is_trivial() + sage: I = CC['x'].ideal(0) # optional - sage.rings.real_mpfr + sage: I.is_trivial() # optional - sage.rings.real_mpfr True This test addresses issue :trac:`20514`:: diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index 46c86bf378d..90f926035d7 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -114,10 +114,9 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: W is T # optional - sage.rings.padics False - sage: K = LaurentSeriesRing(CC, 'q') - sage: K + sage: K = LaurentSeriesRing(CC, 'q'); K # optional - sage.rings.real_mpfr Laurent Series Ring in q over Complex Field with 53 bits of precision - sage: loads(K.dumps()) == K + sage: loads(K.dumps()) == K # optional - sage.rings.real_mpfr True sage: P = QQ[['x']] sage: F = Frac(P) diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index fa08abe8d99..20419196b31 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -21,8 +21,7 @@ We compute with a Laurent series over the complex mpfr numbers. :: - sage: K. = Frac(CC[['q']]) - sage: K + sage: K. = Frac(CC[['q']]); K # optional - sage.rings.real_mpfr Laurent Series Ring in q over Complex Field with 53 bits of precision sage: q 1.00000000000000*q diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 326bd258b06..8adb1f632ed 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -805,9 +805,9 @@ cdef class Rational(sage.structure.element.FieldElement): sage: a = (355/113).continued_fraction(); a [3; 7, 16] - sage: a.n(digits=10) + sage: a.n(digits=10) # optional - sage.rings.real_mpfr 3.141592920 - sage: pi.n(digits=10) + sage: pi.n(digits=10) # optional - sage.rings.real_mpfr sage.symbolic 3.141592654 It's almost pi! @@ -1196,11 +1196,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(25/6) - sage: a.local_height(2) + sage: a.local_height(2) # optional - sage.rings.real_mpfr 0.693147180559945 - sage: a.local_height(3) + sage: a.local_height(3) # optional - sage.rings.real_mpfr 1.09861228866811 - sage: a.local_height(5) + sage: a.local_height(5) # optional - sage.rings.real_mpfr 0.000000000000000 """ from sage.rings.real_mpfr import RealField @@ -1234,11 +1234,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.local_height_arch() + sage: a.local_height_arch() # optional - sage.rings.real_mpfr 0.000000000000000 - sage: (1/a).local_height_arch() + sage: (1/a).local_height_arch() # optional - sage.rings.real_mpfr 1.42711635564015 - sage: (1/a).local_height_arch(100) + sage: (1/a).local_height_arch(100) # optional - sage.rings.real_mpfr 1.4271163556401457483890413081 """ from sage.rings.real_mpfr import RealField @@ -1277,11 +1277,11 @@ cdef class Rational(sage.structure.element.FieldElement): sage: a = QQ(5/6) sage: a.support() [2, 3, 5] - sage: a.global_height_non_arch() + sage: a.global_height_non_arch() # optional - sage.rings.real_mpfr 1.79175946922805 - sage: [a.local_height(p) for p in a.support()] + sage: [a.local_height(p) for p in a.support()] # optional - sage.rings.real_mpfr [0.693147180559945, 1.09861228866811, 0.000000000000000] - sage: sum([a.local_height(p) for p in a.support()]) + sage: sum([a.local_height(p) for p in a.support()]) # optional - sage.rings.real_mpfr 1.79175946922805 """ from sage.rings.real_mpfr import RealField @@ -1318,11 +1318,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.global_height_arch() + sage: a.global_height_arch() # optional - sage.rings.real_mpfr 0.000000000000000 - sage: (1/a).global_height_arch() + sage: (1/a).global_height_arch() # optional - sage.rings.real_mpfr 1.42711635564015 - sage: (1/a).global_height_arch(100) + sage: (1/a).global_height_arch(100) # optional - sage.rings.real_mpfr 1.4271163556401457483890413081 """ return self.local_height_arch(prec) @@ -1350,15 +1350,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.global_height_arch() + a.global_height_non_arch() + sage: a.global_height_arch() + a.global_height_non_arch() # optional - sage.rings.real_mpfr 3.21887582486820 - sage: a.global_height() + sage: a.global_height() # optional - sage.rings.real_mpfr 3.21887582486820 - sage: (1/a).global_height() + sage: (1/a).global_height() # optional - sage.rings.real_mpfr 3.21887582486820 - sage: QQ(0).global_height() + sage: QQ(0).global_height() # optional - sage.rings.real_mpfr 0.000000000000000 - sage: QQ(1).global_height() + sage: QQ(1).global_height() # optional - sage.rings.real_mpfr 0.000000000000000 """ from sage.rings.real_mpfr import RealField @@ -1910,13 +1910,13 @@ cdef class Rational(sage.structure.element.FieldElement): sage: n = 2/3 sage: n.sqrt() # optional - sage.symbolic sqrt(2/3) - sage: n.sqrt(prec=10) + sage: n.sqrt(prec=10) # optional - sage.rings.real_mpfr 0.82 - sage: n.sqrt(prec=100) + sage: n.sqrt(prec=100) # optional - sage.rings.real_mpfr 0.81649658092772603273242802490 - sage: n.sqrt(prec=100)^2 + sage: n.sqrt(prec=100)^2 # optional - sage.rings.real_mpfr 0.66666666666666666666666666667 - sage: n.sqrt(prec=53, all=True) + sage: n.sqrt(prec=53, all=True) # optional - sage.rings.real_mpfr [0.816496580927726, -0.816496580927726] sage: n.sqrt(extend=False, all=True) Traceback (most recent call last): @@ -1924,9 +1924,9 @@ cdef class Rational(sage.structure.element.FieldElement): ValueError: square root of 2/3 not a rational number sage: sqrt(-2/3, all=True) # optional - sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] - sage: sqrt(-2/3, prec=53) + sage: sqrt(-2/3, prec=53) # optional - sage.rings.real_mpfr 0.816496580927726*I - sage: sqrt(-2/3, prec=53, all=True) + sage: sqrt(-2/3, prec=53, all=True) # optional - sage.rings.real_mpfr [0.816496580927726*I, -0.816496580927726*I] AUTHORS: @@ -2193,12 +2193,12 @@ cdef class Rational(sage.structure.element.FieldElement): Test that conversion agrees with `RR`:: sage: Q = [a/b for a in [-99..99] for b in [1..99]] - sage: all(RDF(q) == RR(q) for q in Q) + sage: all(RDF(q) == RR(q) for q in Q) # optional - sage.rings.real_mpfr True Test that the conversion has correct rounding on simple rationals:: - sage: for p in [-100..100]: + sage: for p in [-100..100]: # optional - sage.rings.real_mpfr ....: for q in [1..100]: ....: r = RDF(p/q) ....: assert (RR(r).exact_rational() - p/q) <= r.ulp()/2 @@ -3121,7 +3121,7 @@ cdef class Rational(sage.structure.element.FieldElement): 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) # optional - sage.rings.real_mpfr -0.63578895682825611710391773754 sage: log(QQ(125)) # optional - sage.symbolic 3*log(5) @@ -3147,7 +3147,7 @@ cdef class Rational(sage.structure.element.FieldElement): -4/3 sage: (125/8).log(5/2) # optional - sage.libs.pari 3 - sage: (125/8).log(5/2, prec=53) + sage: (125/8).log(5/2, prec=53) # optional - sage.rings.real_mpfr 3.00000000000000 TESTS:: @@ -3236,9 +3236,9 @@ cdef class Rational(sage.structure.element.FieldElement): This function accepts an optional precision argument:: - sage: (1/3).gamma(prec=100) + sage: (1/3).gamma(prec=100) # optional - sage.rings.real_mpfr 2.6789385347077476336556929410 - sage: (1/2).gamma(prec=100) + sage: (1/2).gamma(prec=100) # optional - sage.rings.real_mpfr 1.7724538509055160272981674833 TESTS: diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 5d74779c564..4c7725aaead 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -16,11 +16,11 @@ :: - sage: RealField(9).pi() + sage: RealField(9).pi() # optional - sage.rings.real_mpfr 3.1 - sage: QQ(RealField(9).pi()) + sage: QQ(RealField(9).pi()) # optional - sage.rings.real_mpfr 22/7 - sage: QQ(RealField().pi()) + sage: QQ(RealField().pi()) # optional - sage.rings.real_mpfr 245850922/78256779 sage: QQ(35) 35 @@ -98,11 +98,11 @@ class RationalField(Singleton, number_field_base.NumberField): :: - sage: QQ(RR(3929329/32)) + sage: QQ(RR(3929329/32)) # optional - sage.rings.real_mpfr 3929329/32 - sage: QQ(-RR(3929329/32)) + sage: QQ(-RR(3929329/32)) # optional - sage.rings.real_mpfr -3929329/32 - sage: QQ(RR(1/7)) - 1/7 + sage: QQ(RR(1/7)) - 1/7 # optional - sage.rings.real_mpfr 0 If you specify the optional second argument ``base``, then the string diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 8780f23483e..30933870522 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -786,16 +786,16 @@ cdef class Ring(ParentWithGens): sage: QQbar.is_subring(QQbar) # optional - sage.rings.number_field True - sage: RR.is_subring(RR) + sage: RR.is_subring(RR) # optional - sage.rings.real_mpfr True - sage: CC.is_subring(CC) + sage: CC.is_subring(CC) # optional - sage.rings.real_mpfr True sage: x = polygen(ZZ, 'x') 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) + sage: R. = RR[] # optional - sage.rings.real_mpfr + sage: R.is_subring(R) # optional - sage.rings.real_mpfr True """ if self is other: @@ -2131,9 +2131,9 @@ cdef class Field(PrincipalIdealDomain): sage: QQ.fraction_field() Rational Field - sage: RR.fraction_field() + sage: RR.fraction_field() # optional - sage.rings.real_mpfr Real Field with 53 bits of precision - sage: CC.fraction_field() + sage: CC.fraction_field() # optional - sage.rings.real_mpfr Complex Field with 53 bits of precision sage: x = polygen(ZZ, 'x') From 0e70ba3426a02359b89d21e1ae0a4adcbfac37ca Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 15 Jun 2023 21:39:35 -0700 Subject: [PATCH 16/50] sage.rings: More # optional --- src/sage/rings/abc.pyx | 4 ++-- src/sage/rings/fraction_field.py | 12 ++++++------ src/sage/rings/laurent_series_ring_element.pyx | 6 +++--- src/sage/rings/localization.py | 10 +++++----- src/sage/rings/multi_power_series_ring.py | 4 ++-- src/sage/rings/power_series_poly.pyx | 5 ++--- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index d62d23f7645..4893c29d1fc 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -177,7 +177,7 @@ cdef class RealField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(RR, sage.rings.abc.RealField) + sage: isinstance(RR, sage.rings.abc.RealField) # optional - sage.rings.real_mpfr True By design, there is a unique direct subclass:: @@ -277,7 +277,7 @@ cdef class ComplexField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CC, sage.rings.abc.ComplexField) + sage: isinstance(CC, sage.rings.abc.ComplexField) # optional - sage.rings.real_mpfr True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 15691eabe39..31d51c3195c 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -25,11 +25,11 @@ The GCD is not taken (since it doesn't converge sometimes) in the inexact case:: - sage: Z. = CC[] - sage: I = CC.gen() - sage: (1+I+z)/(z+0.1*I) + sage: Z. = CC[] # optional - sage.rings.real_mpfr + sage: I = CC.gen() # optional - sage.rings.real_mpfr + sage: (1+I+z)/(z+0.1*I) # optional - sage.rings.real_mpfr (z + 1.00000000000000 + I)/(z + 0.100000000000000*I) - sage: (1+I*z)/(z+1.1) + sage: (1+I*z)/(z+1.1) # optional - sage.rings.real_mpfr (I*z + 1.00000000000000)/(z + 1.10000000000000) TESTS:: @@ -306,8 +306,8 @@ def _coerce_map_from_(self, S): Test for :trac:`31320`:: sage: FQt = Frac(QQ['t']) - sage: LCt = LaurentPolynomialRing(CC,'t') - sage: coercion_model.common_parent(FQt, LCt) + sage: LCt = LaurentPolynomialRing(CC,'t') # optional - sage.rings.real_mpfr + sage: coercion_model.common_parent(FQt, LCt) # optional - sage.rings.real_mpfr Fraction Field of Univariate Polynomial Ring in t over Complex Field with 53 bits of precision diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index 20419196b31..63cac5bce7a 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -23,16 +23,16 @@ We compute with a Laurent series over the complex mpfr numbers. sage: K. = Frac(CC[['q']]); K # optional - sage.rings.real_mpfr Laurent Series Ring in q over Complex Field with 53 bits of precision - sage: q + sage: q # optional - sage.rings.real_mpfr 1.00000000000000*q Saving and loading. :: - sage: loads(q.dumps()) == q + sage: loads(q.dumps()) == q # optional - sage.rings.real_mpfr True - sage: loads(K.dumps()) == K + sage: loads(K.dumps()) == K # optional - sage.rings.real_mpfr True IMPLEMENTATION: Laurent series in Sage are represented internally diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index a0659202ac6..bda24010204 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -282,14 +282,14 @@ def _repr_(self): EXAMPLES:: sage: from sage.rings.localization import LocalizationElement - sage: P. = CC[] - sage: L = Localization(P, x**2+x+1) - sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) - sage: l._repr_() == str(l) + sage: P. = CC[] # optional - sage.rings.real_mpfr + sage: L = Localization(P, x**2 + x + 1) # optional - sage.rings.real_mpfr + sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) # optional - sage.rings.real_mpfr + sage: l._repr_() == str(l) # optional - sage.rings.real_mpfr True sage: R. = ZZ[] - sage: L. = R.localization(X-Y) + sage: L. = R.localization(X - Y) sage: x*y/(x-y) x*y/(x - y) """ diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 410de0bbff0..e8b58284316 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -117,7 +117,7 @@ sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field - sage: R.base_extend(RR) + sage: R.base_extend(RR) # optional - sage.rings.real_mpfr Multivariate Power Series Ring in t, u, v over Real Field with 53 bits of precision sage: R.change_ring(IntegerModRing(10)) @@ -543,7 +543,7 @@ def change_ring(self, R): sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field - sage: R.base_extend(RR) + sage: R.base_extend(RR) # optional - sage.rings.real_mpfr Multivariate Power Series Ring in t, u, v over Real Field with 53 bits of precision sage: R.change_ring(IntegerModRing(10)) diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 46d7bbf1303..63d26c53757 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -16,10 +16,9 @@ cdef class PowerSeries_poly(PowerSeries): """ EXAMPLES:: - sage: R. = PowerSeriesRing(CC) - sage: R + sage: R. = PowerSeriesRing(CC); R # optional - sage.rings.real_mpfr Power Series Ring in q over Complex Field with 53 bits of precision - sage: loads(q.dumps()) == q + sage: loads(q.dumps()) == q # optional - sage.rings.real_mpfr True sage: R. = QQ[[]] From 8153ac0dd63e95c72ba040a5d8f49b8421177164 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 19 Jun 2023 00:11:47 -0700 Subject: [PATCH 17/50] More # optional --- src/sage/rings/infinity.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index 4e3f27784a2..2d812f5dd1c 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -691,11 +691,11 @@ def _element_constructor_(self, x): A number less than infinity sage: UnsignedInfinityRing(RDF(oo)), UnsignedInfinityRing(RDF(-oo)) (Infinity, Infinity) - sage: UnsignedInfinityRing(RR(oo)), UnsignedInfinityRing(RR(-oo)) + sage: UnsignedInfinityRing(RR(oo)), UnsignedInfinityRing(RR(-oo)) # optional - sage.rings.real_mpfr (Infinity, Infinity) sage: UnsignedInfinityRing(CDF(oo)), UnsignedInfinityRing(CDF(-oo)) (Infinity, Infinity) - sage: UnsignedInfinityRing(CC(oo)), UnsignedInfinityRing(CC(-oo)) + sage: UnsignedInfinityRing(CC(oo)), UnsignedInfinityRing(CC(-oo)) # optional - sage.rings.real_mpfr (Infinity, Infinity) sage: UnsignedInfinityRing(RIF(oo)), UnsignedInfinityRing(RIF(-oo)) (Infinity, Infinity) @@ -746,7 +746,7 @@ def _coerce_map_from_(self, R): sage: UnsignedInfinityRing.has_coerce_map_from(int) # indirect doctest True - sage: UnsignedInfinityRing.has_coerce_map_from(CC) + sage: UnsignedInfinityRing.has_coerce_map_from(CC) # optional - sage.rings.real_mpfr True sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) # optional - sage.rings.number_field True @@ -983,7 +983,7 @@ def is_Infinite(x): True sage: sage.rings.infinity.is_Infinite(3) False - sage: sage.rings.infinity.is_Infinite(RR(infinity)) + sage: sage.rings.infinity.is_Infinite(RR(infinity)) # optional - sage.rings.real_mpfr False sage: sage.rings.infinity.is_Infinite(ZZ) False @@ -1137,7 +1137,7 @@ def _element_constructor_(self, x): A negative finite number sage: InfinityRing(RDF(oo)), InfinityRing(RDF(-oo)) (+Infinity, -Infinity) - sage: InfinityRing(RR(oo)), InfinityRing(RR(-oo)) + sage: InfinityRing(RR(oo)), InfinityRing(RR(-oo)) # optional - sage.rings.real_mpfr (+Infinity, -Infinity) sage: InfinityRing(RIF(oo)), InfinityRing(RIF(-oo)) (+Infinity, -Infinity) @@ -1149,7 +1149,7 @@ def _element_constructor_(self, x): The following rings have ``is_positive_infinity`` / ``is_negative_infinity`` methods:: - sage: RR(oo).is_positive_infinity(), RR(-oo).is_negative_infinity() + sage: RR(oo).is_positive_infinity(), RR(-oo).is_negative_infinity() # optional - sage.rings.real_mpfr (True, True) sage: SR(oo).is_positive_infinity(), SR(-oo).is_negative_infinity() # optional - sage.symbolic (True, True) @@ -1157,10 +1157,10 @@ def _element_constructor_(self, x): Complex infinity raises an exception. This is fine (there is no coercion, so there is no promise of functoriality):: - sage: i_infinity = CC(0, oo) - sage: InfinityRing(CC(oo)), InfinityRing(CC(-oo)) + sage: i_infinity = CC(0, oo) # optional - sage.rings.real_mpfr + sage: InfinityRing(CC(oo)), InfinityRing(CC(-oo)) # optional - sage.rings.real_mpfr (+Infinity, -Infinity) - sage: InfinityRing(i_infinity) + sage: InfinityRing(i_infinity) # optional - sage.rings.real_mpfr Traceback (most recent call last): ... ValueError: infinite but not with +/- phase @@ -1263,9 +1263,9 @@ def _coerce_map_from_(self, R): sage: InfinityRing.has_coerce_map_from(CDF) False - sage: InfinityRing.has_coerce_map_from(CC) + sage: InfinityRing.has_coerce_map_from(CC) # optional - sage.rings.real_mpfr False - sage: CC(0, oo) < CC(1) # does not coerce to infinity ring + sage: CC(0, oo) < CC(1) # does not coerce to infinity ring # optional - sage.rings.real_mpfr True """ from sage.structure.coerce import parent_is_real_numerical From c7dc6a3f5126f25e2b6247f31bbded35c6df0aaf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 20 Jun 2023 15:20:32 -0700 Subject: [PATCH 18/50] More # optional --- src/sage/rings/real_double.pyx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 11de275ce72..7fcfad0ceaf 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -650,29 +650,29 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): TESTS:: sage: R. = RDF[] - sage: RDF._factor_univariate_polynomial(x) + sage: RDF._factor_univariate_polynomial(x) # optional - numpy x - sage: RDF._factor_univariate_polynomial(2*x) + sage: RDF._factor_univariate_polynomial(2*x) # optional - numpy (2.0) * x - sage: RDF._factor_univariate_polynomial(x^2) + sage: RDF._factor_univariate_polynomial(x^2) # optional - numpy x^2 - sage: RDF._factor_univariate_polynomial(x^2 + 1) + sage: RDF._factor_univariate_polynomial(x^2 + 1) # optional - numpy x^2 + 1.0 - sage: RDF._factor_univariate_polynomial(x^2 - 1) + sage: RDF._factor_univariate_polynomial(x^2 - 1) # optional - numpy (x - 1.0) * (x + 1.0) The implementation relies on the ``roots()`` method which often reports roots not to be real even though they are:: sage: f = (x-1)^3 - sage: f.roots(ring=CDF) # abs tol 2e-5 + sage: f.roots(ring=CDF) # abs tol 2e-5 # optional - numpy [(1.0000065719436413, 1), (0.9999967140281792 - 5.691454546815028e-06*I, 1), (0.9999967140281792 + 5.691454546815028e-06*I, 1)] This leads to the following incorrect factorization:: - sage: f.factor() # abs tol 2e-5 + sage: f.factor() # abs tol 2e-5 # optional - numpy (x - 1.0000065719436413) * (x^2 - 1.9999934280563585*x + 0.9999934280995487) """ roots = f.roots(sage.rings.complex_double.CDF) From 3a0d43f9f75f382e87e1df601bf78d4f2bb9edaf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 25 Jun 2023 22:55:43 -0700 Subject: [PATCH 19/50] More # optional --- src/sage/rings/power_series_ring_element.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 54314d538ed..c9a73a18665 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -152,7 +152,7 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: PowerSeriesRing(CC, 'q') + sage: PowerSeriesRing(CC, 'q') # optional - sage.rings.real_mpfr Power Series Ring in q over Complex Field with 53 bits of precision sage: T = PowerSeriesRing(GF(3), 5, 't'); T # optional - sage.rings.finite_rings Multivariate Power Series Ring in t0, t1, t2, t3, t4 From b572224427326a68a20987114ce1d9ac86b335e1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 29 Jun 2023 19:55:48 -0700 Subject: [PATCH 20/50] sage.schemes: Update # needs --- src/sage/rings/real_double.pyx | 114 ++++++++++++++++----------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 7fcfad0ceaf..bb5b06d489c 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -5,21 +5,21 @@ EXAMPLES: We create the real double vector space of dimension `3`:: - sage: V = RDF^3; V # optional - sage.modules + sage: V = RDF^3; V # needs sage.modules Vector space of dimension 3 over Real Double Field Notice that this space is unique:: - sage: V is RDF^3 # optional - sage.modules + sage: V is RDF^3 # needs sage.modules True - sage: V is FreeModule(RDF, 3) # optional - sage.modules + sage: V is FreeModule(RDF, 3) # needs sage.modules True - sage: V is VectorSpace(RDF, 3) # optional - sage.modules + sage: V is VectorSpace(RDF, 3) # needs sage.modules True Also, you can instantly create a space of large dimension:: - sage: V = RDF^10000 # optional - sage.modules + sage: V = RDF^10000 # needs sage.modules TESTS: @@ -27,8 +27,8 @@ Test NumPy conversions:: sage: RDF(1).__array_interface__ {'typestr': '=f8'} - sage: import numpy # optional - numpy - sage: numpy.array([RDF.pi()]).dtype # optional - numpy + sage: import numpy # needs numpy + sage: numpy.array([RDF.pi()]).dtype # needs numpy dtype('float64') """ @@ -84,7 +84,7 @@ def is_RealDoubleField(x): use isinstance(..., sage.rings.abc.RealDoubleField) instead See https://github.com/sagemath/sage/issues/32610 for details. True - sage: is_RealDoubleField(RealField(53)) # optional - sage.rings.real_mpfr + sage: is_RealDoubleField(RealField(53)) # needs sage.rings.real_mpfr False """ from sage.misc.superseded import deprecation @@ -128,15 +128,15 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: - sage: a = RealField(200)(2).sqrt(); a # optional - sage.rings.real_mpfr + sage: a = RealField(200)(2).sqrt(); a # needs sage.rings.real_mpfr 1.4142135623730950488016887242096980785696718753769480731767 - sage: b = RDF(a); b # optional - sage.rings.real_mpfr + sage: b = RDF(a); b # needs sage.rings.real_mpfr 1.4142135623730951 - sage: a.parent()(b) # optional - sage.rings.real_mpfr + sage: a.parent()(b) # needs sage.rings.real_mpfr 1.4142135623730951454746218587388284504413604736328125000000 - sage: a.parent()(b) == b # optional - sage.rings.real_mpfr + sage: a.parent()(b) == b # needs sage.rings.real_mpfr True - sage: b == RR(a) # optional - sage.rings.real_mpfr + sage: b == RR(a) # needs sage.rings.real_mpfr True TESTS:: @@ -329,22 +329,22 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): sage: RLF(2/3) + RDF(1) 1.6666666666666665 - sage: import numpy # optional - numpy - sage: RDF.coerce(numpy.int8('1')) # optional - numpy + sage: import numpy # needs numpy + sage: RDF.coerce(numpy.int8('1')) # needs numpy 1.0 - sage: RDF.coerce(numpy.float64('1')) # optional - numpy + sage: RDF.coerce(numpy.float64('1')) # needs numpy 1.0 - sage: RDF.coerce(pi) + sage: RDF.coerce(pi) # needs sage.symbolic Traceback (most recent call last): ... TypeError: no canonical coercion from Symbolic Ring to Real Double Field Test that :trac:`15695` is fixed (see also :trac:`18076`):: - sage: 1j + numpy.float64(2) + sage: 1j + numpy.float64(2) # needs numpy 2.00000000000000 + 1.00000000000000*I - sage: parent(_) + sage: parent(_) # needs numpy Complex Field with 53 bits of precision """ if S is int or S is float: @@ -446,7 +446,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RDF.to_prec(52) # optional - sage.rings.real_mpfr + sage: RDF.to_prec(52) # needs sage.rings.real_mpfr Real Field with 52 bits of precision sage: RDF.to_prec(53) Real Double Field @@ -650,29 +650,29 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): TESTS:: sage: R. = RDF[] - sage: RDF._factor_univariate_polynomial(x) # optional - numpy + sage: RDF._factor_univariate_polynomial(x) # needs numpy x - sage: RDF._factor_univariate_polynomial(2*x) # optional - numpy + sage: RDF._factor_univariate_polynomial(2*x) # needs numpy (2.0) * x - sage: RDF._factor_univariate_polynomial(x^2) # optional - numpy + sage: RDF._factor_univariate_polynomial(x^2) # needs numpy x^2 - sage: RDF._factor_univariate_polynomial(x^2 + 1) # optional - numpy + sage: RDF._factor_univariate_polynomial(x^2 + 1) # needs numpy x^2 + 1.0 - sage: RDF._factor_univariate_polynomial(x^2 - 1) # optional - numpy + sage: RDF._factor_univariate_polynomial(x^2 - 1) # needs numpy (x - 1.0) * (x + 1.0) The implementation relies on the ``roots()`` method which often reports roots not to be real even though they are:: sage: f = (x-1)^3 - sage: f.roots(ring=CDF) # abs tol 2e-5 # optional - numpy + sage: f.roots(ring=CDF) # abs tol 2e-5 # needs numpy [(1.0000065719436413, 1), (0.9999967140281792 - 5.691454546815028e-06*I, 1), (0.9999967140281792 + 5.691454546815028e-06*I, 1)] This leads to the following incorrect factorization:: - sage: f.factor() # abs tol 2e-5 # optional - numpy + sage: f.factor() # abs tol 2e-5 # needs numpy (x - 1.0000065719436413) * (x^2 - 1.9999934280563585*x + 0.9999934280995487) """ roots = f.roots(sage.rings.complex_double.CDF) @@ -790,20 +790,20 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(pi) # optional - sage.symbolic - sage: a.ulp() # optional - sage.symbolic + sage: a = RDF(pi) # needs sage.symbolic + sage: a.ulp() # needs sage.symbolic 4.440892098500626e-16 - sage: b = a + a.ulp() # optional - sage.symbolic + sage: b = a + a.ulp() # needs sage.symbolic Adding or subtracting an ulp always gives a different number:: - sage: a + a.ulp() == a # optional - sage.symbolic + sage: a + a.ulp() == a # needs sage.symbolic False - sage: a - a.ulp() == a # optional - sage.symbolic + sage: a - a.ulp() == a # needs sage.symbolic False - sage: b + b.ulp() == b # optional - sage.symbolic + sage: b + b.ulp() == b # needs sage.symbolic False - sage: b - b.ulp() == b # optional - sage.symbolic + sage: b - b.ulp() == b # needs sage.symbolic False Since the default rounding mode is round-to-nearest, adding or @@ -812,13 +812,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 # optional - sage.symbolic + sage: a - a.ulp()/3 == a # needs sage.symbolic True - sage: a + a.ulp()/3 == a # optional - sage.symbolic + sage: a + a.ulp()/3 == a # needs sage.symbolic True - sage: b - b.ulp()/3 == b # optional - sage.symbolic + sage: b - b.ulp()/3 == b # needs sage.symbolic True - sage: b + b.ulp()/3 == b # optional - sage.symbolic + sage: b + b.ulp()/3 == b # needs sage.symbolic True sage: c = RDF(1) sage: c - c.ulp()/3 == c @@ -977,11 +977,11 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: s1 = RDF(sin(1)); s1 # optional - sage.symbolic + sage: s1 = RDF(sin(1)); s1 # needs sage.symbolic 0.8414709848078965 - sage: s1._interface_init_() # optional - sage.symbolic + sage: s1._interface_init_() # needs sage.symbolic '0.8414709848078965' - sage: s1 == RDF(gp(s1)) # optional - sage.libs.pari sage.symbolic + sage: s1 == RDF(gp(s1)) # needs sage.libs.pari sage.symbolic True """ return repr(self._value) @@ -1006,7 +1006,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: sage_input(RDF(NaN)) # optional - sage.symbolic + sage: sage_input(RDF(NaN)) # needs sage.symbolic RDF(NaN) sage: sage_input(RDF(-infinity), verify=True) # Verified @@ -1014,13 +1014,13 @@ cdef class RealDoubleElement(FieldElement): sage: sage_input(RDF(-infinity)*polygen(RDF)) R. = RDF[] -RDF(infinity)*x + RDF(NaN) - sage: sage_input(RDF(pi), verify=True) + sage: sage_input(RDF(pi), verify=True) # needs sage.symbolic # Verified RDF(3.1415926535897931) - sage: sage_input(RDF(-e), verify=True, preparse=False) + sage: sage_input(RDF(-e), verify=True, preparse=False) # needs sage.symbolic # Verified -RDF(2.718281828459045...) - sage: sage_input(RDF(pi)*polygen(RDF), verify=True, preparse=None) # optional - sage.symbolic + sage: sage_input(RDF(pi)*polygen(RDF), verify=True, preparse=None) # needs sage.symbolic # Verified R = RDF['x'] x = R.gen() @@ -1167,8 +1167,8 @@ cdef class RealDoubleElement(FieldElement): sage: RDF(2.1)._im_gens_(RR, [RR(1)]) 2.10000000000000 - sage: R = RealField(20) # optional - sage.rings.real_mpfr - sage: RDF(2.1)._im_gens_(R, [R(1)]) # optional - sage.rings.real_mpfr + sage: R = RealField(20) # needs sage.rings.real_mpfr + sage: RDF(2.1)._im_gens_(R, [R(1)]) # needs sage.rings.real_mpfr 2.1000 """ return codomain(self) # since 1 |--> 1 @@ -1265,12 +1265,12 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(exp(1.0)); a # optional - sage.symbolic + sage: a = RDF(exp(1.0)); a # needs sage.symbolic 2.718281828459045 - sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() # optional - sage.symbolic - sage: sign,mantissa,exponent # optional - sage.symbolic + sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() # needs sage.symbolic + sage: sign,mantissa,exponent # needs sage.symbolic (1, 6121026514868073, -51) - sage: sign*mantissa*(2**exponent) == a # optional - sage.symbolic + sage: sign*mantissa*(2**exponent) == a # needs sage.symbolic True The mantissa is always a nonnegative number:: @@ -1649,9 +1649,9 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: sage: a = RDF(1/3) - sage: CC(a) + sage: CC(a) # needs sage.rings.real_mpfr 0.333333333333333 - sage: a._complex_mpfr_field_(CC) + sage: a._complex_mpfr_field_(CC) # needs sage.rings.real_mpfr 0.333333333333333 If we coerce to a higher-precision field the extra bits appear @@ -1659,9 +1659,9 @@ cdef class RealDoubleElement(FieldElement): :: - sage: a._complex_mpfr_field_(ComplexField(100)) + sage: a._complex_mpfr_field_(ComplexField(100)) # needs sage.rings.real_mpfr 0.33333333333333331482961625625 - sage: a._complex_mpfr_field_(ComplexField(100)).str(2) + sage: a._complex_mpfr_field_(ComplexField(100)).str(2) # needs sage.rings.real_mpfr '0.01010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000' """ return CC(self._value) @@ -1683,7 +1683,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF(1.5).__pari__() # optional - sage.libs.pari + sage: RDF(1.5).__pari__() # needs sage.libs.pari 1.50000000000000 """ global new_gen_from_real_double_element @@ -1969,7 +1969,7 @@ cdef class RealDoubleElement(FieldElement): sage: r = sqrt(RDF(2)); r 1.4142135623730951 - sage: r.algebraic_dependency(5) # optional - sage.libs.pari + sage: r.algebraic_dependency(5) # needs sage.libs.pari x^2 - 2 """ return sage.arith.all.algdep(self,n) From 84afcb53f049c4416406fca1313293155fe1dcd4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 1 Jul 2023 15:42:59 -0700 Subject: [PATCH 21/50] Update # optional / # needs --- src/sage/rings/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index d7d14aa4e0a..85977bf587b 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -392,9 +392,9 @@ def test_random_arith(level=MAX_LEVEL, trials=1): a -2*a - 1 2*a - 30164 - sage: sage.rings.tests.test_random_arith(trials=10) + sage: sage.rings.tests.test_random_arith(trials=10) # optional - sage.rings.finite_rings survived 0 tests... - sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?) + sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?), optional - sage.rings.finite_rings survived 0 tests... """ i = 0 From 58f08045c0c29caf551811b54a5017dc69f992a2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 00:58:02 -0700 Subject: [PATCH 22/50] sage.rings: Update # optional / # needs --- src/sage/rings/abc.pyx | 8 ++-- src/sage/rings/integer.pyx | 12 ++--- src/sage/rings/noncommutative_ideals.pyx | 56 ++++++++++++++---------- src/sage/rings/rational.pyx | 8 ++-- src/sage/rings/rational_field.py | 49 ++++++++++++--------- src/sage/rings/real_double.pyx | 16 +++---- src/sage/rings/ring.pyx | 12 ++--- 7 files changed, 89 insertions(+), 72 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 4893c29d1fc..d0785dff8c2 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -182,7 +182,7 @@ cdef class RealField(Field): By design, there is a unique direct subclass:: - sage: sage.rings.abc.RealField.__subclasses__() + sage: sage.rings.abc.RealField.__subclasses__() # optional - sage.rings.real_mpfr [] sage: len(sage.rings.abc.RealField.__subclasses__()) <= 1 @@ -282,7 +282,7 @@ cdef class ComplexField(Field): By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexField.__subclasses__() + sage: sage.rings.abc.ComplexField.__subclasses__() # optional - sage.rings.real_mpfr [] sage: len(sage.rings.abc.ComplexField.__subclasses__()) <= 1 @@ -352,12 +352,12 @@ cdef class ComplexDoubleField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CDF, sage.rings.abc.ComplexDoubleField) + sage: isinstance(CDF, sage.rings.abc.ComplexDoubleField) # optional - sage.rings.complex_double True By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexDoubleField.__subclasses__() + sage: sage.rings.abc.ComplexDoubleField.__subclasses__() # optional - sage.rings.complex_double [] sage: len(sage.rings.abc.ComplexDoubleField.__subclasses__()) <= 1 diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index d5e87626d31..c2414413fda 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -2766,11 +2766,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: Integer(124).log(5) # optional - sage.symbolic log(124)/log(5) - sage: Integer(124).log(5, 100) + sage: Integer(124).log(5, 100) # optional - sage.rings.real_mpfr 2.9950093311241087454822446806 sage: Integer(125).log(5) 3 - sage: Integer(125).log(5, prec=53) + sage: Integer(125).log(5, prec=53) # optional - sage.rings.real_mpfr 3.00000000000000 sage: log(Integer(125)) # optional - sage.symbolic 3*log(5) @@ -2791,16 +2791,16 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): But approximations are probably more useful in this case, and work to as high a precision as we desire:: - sage: x.log(3, 53) # default precision for RealField + sage: x.log(3, 53) # default precision for RealField # optional - sage.rings.real_mpfr 100000.000000000 - sage: (x + 1).log(3, 53) + sage: (x + 1).log(3, 53) # optional - sage.rings.real_mpfr 100000.000000000 - sage: (x + 1).log(3, 1000) + sage: (x + 1).log(3, 1000) # optional - sage.rings.real_mpfr 100000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 We can use non-integer bases, with default e:: - sage: x.log(2.5, prec=53) + sage: x.log(2.5, prec=53) # optional - sage.rings.real_mpfr 119897.784671579 We also get logarithms of negative integers, via the diff --git a/src/sage/rings/noncommutative_ideals.pyx b/src/sage/rings/noncommutative_ideals.pyx index af27882313d..ec2e9292d55 100644 --- a/src/sage/rings/noncommutative_ideals.pyx +++ b/src/sage/rings/noncommutative_ideals.pyx @@ -39,6 +39,7 @@ algebras. TESTS:: + sage: # needs sage.combinat sage: A = SteenrodAlgebra(2) sage: IL = A*[A.1+A.2,A.1^2]; IL Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis @@ -115,6 +116,7 @@ class IdealMonoid_nc(IdealMonoid_c): TESTS:: + sage: # needs sage.combinat sage: A = SteenrodAlgebra(2) # indirect doctest sage: IL = A*[A.1+A.2,A.1^2]; IL Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis @@ -128,6 +130,7 @@ class IdealMonoid_nc(IdealMonoid_c): :: + sage: # needs sage.combinat sage: IL == loads(dumps(IL)) True sage: IR == loads(dumps(IR)) @@ -244,6 +247,7 @@ class Ideal_nc(Ideal_generic): TESTS:: + sage: # needs sage.combinat sage: A = SteenrodAlgebra(2) sage: A*[A.1+A.2,A.1^2] # indirect doctest Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis @@ -263,14 +267,15 @@ class Ideal_nc(Ideal_generic): EXAMPLES:: - sage: A = SteenrodAlgebra(2) - sage: IR = [A.1+A.2,A.1^2]*A - sage: IL = A*[A.1+A.2,A.1^2] - sage: IT = A*[A.1+A.2,A.1^2]*A - sage: IT == IL - False - sage: IR == [A.1+A.2,A.1^2]*A - True + sage: # needs sage.combinat + sage: A = SteenrodAlgebra(2) + sage: IR = [A.1+A.2,A.1^2]*A + sage: IL = A*[A.1+A.2,A.1^2] + sage: IT = A*[A.1+A.2,A.1^2]*A + sage: IT == IL + False + sage: IR == [A.1+A.2,A.1^2]*A + True """ if not isinstance(right, Ideal_nc): return False @@ -289,14 +294,15 @@ class Ideal_nc(Ideal_generic): EXAMPLES:: - sage: A = SteenrodAlgebra(2) - sage: IR = [A.1+A.2,A.1^2]*A - sage: IL = A*[A.1+A.2,A.1^2] - sage: IT = A*[A.1+A.2,A.1^2]*A - sage: IT != IL - True - sage: IR != [A.1+A.2,A.1^2]*A - False + sage: # needs sage.combinat + sage: A = SteenrodAlgebra(2) + sage: IR = [A.1+A.2,A.1^2]*A + sage: IL = A*[A.1+A.2,A.1^2] + sage: IT = A*[A.1+A.2,A.1^2]*A + sage: IT != IL + True + sage: IR != [A.1+A.2,A.1^2]*A + False """ return not self.__eq__(right) @@ -306,14 +312,15 @@ class Ideal_nc(Ideal_generic): EXAMPLES:: - sage: A = SteenrodAlgebra(2) - sage: IR = [A.1+A.2,A.1^2]*A - sage: IL = A*[A.1+A.2,A.1^2] - sage: IT = A*[A.1+A.2,A.1^2]*A - sage: hash(IT) == hash(IL) - False - sage: hash(IR) == hash([A.1^2,A.1+A.2]*A) - True + sage: # needs sage.combinat + sage: A = SteenrodAlgebra(2) + sage: IR = [A.1+A.2,A.1^2]*A + sage: IL = A*[A.1+A.2,A.1^2] + sage: IT = A*[A.1+A.2,A.1^2]*A + sage: hash(IT) == hash(IL) + False + sage: hash(IR) == hash([A.1^2,A.1+A.2]*A) + True """ return hash((self.parent(), self.__side, frozenset(self.gens()))) @@ -323,6 +330,7 @@ class Ideal_nc(Ideal_generic): EXAMPLES:: + sage: # needs sage.combinat sage: A = SteenrodAlgebra(2) sage: IL = A*[A.1+A.2,A.1^2] sage: IR = [A.1+A.2,A.1^2]*A diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 8adb1f632ed..f08b37d6d45 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -1990,20 +1990,20 @@ cdef class Rational(sage.structure.element.FieldElement): sage: (1/7).period() # optional - sage.libs.pari 6 - sage: RR(1/7) + sage: RR(1/7) # optional - sage.rings.real_mpfr 0.142857142857143 sage: (1/8).period() # optional - sage.libs.pari 1 - sage: RR(1/8) + sage: RR(1/8) # optional - sage.rings.real_mpfr 0.125000000000000 - sage: RR(1/6) + sage: RR(1/6) # optional - sage.rings.real_mpfr 0.166666666666667 sage: (1/6).period() # optional - sage.libs.pari 1 sage: x = 333/106 sage: x.period() # optional - sage.libs.pari 13 - sage: RealField(200)(x) + sage: RealField(200)(x) # optional - sage.rings.real_mpfr 3.1415094339622641509433962264150943396226415094339622641509 """ cdef unsigned int alpha, beta diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 4c7725aaead..ee665002556 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -110,25 +110,26 @@ class RationalField(Singleton, number_field_base.NumberField): :: - sage: QQ(23.2, 2) + sage: QQ(23.2, 2) # optional - sage.rings.real_mpfr 6530219459687219/281474976710656 - sage: 6530219459687219.0/281474976710656 + sage: 6530219459687219.0/281474976710656 # optional - sage.rings.real_mpfr 23.20000000000000 - sage: a = 23.2; a + sage: a = 23.2; a # optional - sage.rings.real_mpfr 23.2000000000000 - sage: QQ(a, 10) + sage: QQ(a, 10) # optional - sage.rings.real_mpfr 116/5 Here's a nice example involving elliptic curves:: - sage: E = EllipticCurve('11a') - sage: L = E.lseries().at1(300)[0]; L + sage: # optional - sage.rings.real_mpfr sage.schemes + sage: E = EllipticCurve('11a') # optional - sage.schemes + sage: L = E.lseries().at1(300)[0]; L # optional - sage.schemes 0.2538418608559106843377589233... - sage: O = E.period_lattice().omega(); O + sage: O = E.period_lattice().omega(); O # optional - sage.schemes 1.26920930427955 - sage: t = L/O; t + sage: t = L/O; t # optional - sage.schemes 0.200000000000000 - sage: QQ(RealField(45)(t)) + sage: QQ(RealField(45)(t)) # optional - sage.rings.real_mpfr sage.schemes 1/5 """ def __new__(cls): @@ -324,7 +325,7 @@ def completion(self, p, prec, extras={}): EXAMPLES:: - sage: QQ.completion(infinity, 53) + sage: QQ.completion(infinity, 53) # optional - sage.rings.real_mpfr Real Field with 53 bits of precision sage: QQ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics 5-adic Field with capped relative precision 15 @@ -675,19 +676,27 @@ def places(self, all_complex=False, prec=None): """ from sage.rings.infinity import Infinity if prec is None: - from sage.rings.real_mpfr import RR as R - from sage.rings.cc import CC as C + if all_complex: + from sage.rings.cc import CC as domain + else: + from sage.rings.real_mpfr import RR as domain elif prec == 53: - from sage.rings.real_double import RDF as R - from sage.rings.complex_double import CDF as C + if all_complex: + from sage.rings.complex_double import CDF as domain + else: + from sage.rings.real_double import RDF as domain elif prec == Infinity: - from sage.rings.qqbar import AA as R, QQbar as C + if all_complex: + from sage.rings.qqbar import QQbar as domain + else: + from sage.rings.qqbar import AA as domain else: - from sage.rings.real_mpfr import RealField - from sage.rings.complex_mpfr import ComplexField - R = RealField(prec) - C = ComplexField(prec) - domain = C if all_complex else R + if all_complex: + from sage.rings.complex_mpfr import ComplexField + domain = ComplexField(prec) + else: + from sage.rings.real_mpfr import RealField + domain = RealField(prec) return [self.hom([domain(1)])] def complex_embedding(self, prec=53): diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index bb5b06d489c..ffa28ed5866 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -103,7 +103,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RR == RDF + sage: RR == RDF # needs sage.rings.real_mpfr False sage: RDF == RealDoubleField() # RDF is the shorthand True @@ -281,7 +281,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RDF.complex_field() + sage: RDF.complex_field() # needs sage.rings.complex_double Complex Double Field """ from sage.rings.complex_double import CDF @@ -294,7 +294,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RDF.algebraic_closure() + sage: RDF.algebraic_closure() # needs sage.rings.complex_double Complex Double Field """ from sage.rings.complex_double import CDF @@ -320,11 +320,11 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): 9499294.0 sage: RDF.coerce(61/3) 20.333333333333332 - sage: parent(RDF(3) + CDF(5)) + sage: parent(RDF(3) + CDF(5)) # needs sage.rings.complex_double Complex Double Field - sage: parent(CDF(5) + RDF(3)) + sage: parent(CDF(5) + RDF(3)) # needs sage.rings.complex_double Complex Double Field - sage: CDF.gen(0) + 5.0 + sage: CDF.gen(0) + 5.0 # needs sage.rings.complex_double 5.0 + 1.0*I sage: RLF(2/3) + RDF(1) 1.6666666666666665 @@ -1027,9 +1027,9 @@ cdef class RealDoubleElement(FieldElement): 3.1415926535897931*x sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: RDF(22/7)._sage_input_(sib, True) + sage: RDF(22/7)._sage_input_(sib, True) # needs sage.sage.rings.real_mpfr {atomic:3.1428571428571428} - sage: RDF(22/7)._sage_input_(sib, False) + sage: RDF(22/7)._sage_input_(sib, False) # needs sage.sage.rings.real_mpfr {call: {atomic:RDF}({atomic:3.1428571428571428})} """ cdef bint isinf = libc.math.isinf(self._value) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 30933870522..48f7e967326 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -158,7 +158,7 @@ cdef class Ring(ParentWithGens): False sage: QQ._repr_option('element_is_atomic') True - sage: CDF._repr_option('element_is_atomic') + sage: CDF._repr_option('element_is_atomic') # optional - sage.rings.complex_double False Check that categories correctly implement `is_finite` and `cardinality`:: @@ -167,8 +167,8 @@ cdef class Ring(ParentWithGens): False sage: GF(2^10, 'a').is_finite() # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] # optional - sage.rings.finite_rings - sage: R.is_finite() # optional - sage.rings.finite_rings + sage: R. = GF(7)[] + sage: R.is_finite() False sage: S. = R.quo(x^2 + 1) # optional - sage.rings.finite_rings sage: S.is_finite() # optional - sage.rings.finite_rings @@ -879,11 +879,11 @@ cdef class Ring(ParentWithGens): sage: x = polygen(ZZ, 'x') sage: R. = ZZ['x'].quo(x^2) # optional - sage.libs.pari - sage: R.fraction_field() + sage: R.fraction_field() # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: self must be an integral domain. - sage: R.is_integral_domain() + sage: R.is_integral_domain() # optional - sage.libs.pari False Forward the proof flag to ``is_field``, see :trac:`22910`:: @@ -1135,7 +1135,7 @@ cdef class Ring(ParentWithGens): This also works over derived rings:: - sage: RR['x'].epsilon() + sage: RR['x'].epsilon() # optional - sage.rings.real_mpfr 2.22044604925031e-16 sage: QQ['x'].epsilon() 0 From c5509e2d1629e5138e2aced5aa634edfb26bd028 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 2 Jul 2023 19:33:41 -0700 Subject: [PATCH 23/50] Update # optional / # needs --- src/sage/rings/noncommutative_ideals.pyx | 2 +- src/sage/rings/real_mpfr.pyx | 161 ++++++++++++----------- 2 files changed, 84 insertions(+), 79 deletions(-) diff --git a/src/sage/rings/noncommutative_ideals.pyx b/src/sage/rings/noncommutative_ideals.pyx index ec2e9292d55..6965f1c6c61 100644 --- a/src/sage/rings/noncommutative_ideals.pyx +++ b/src/sage/rings/noncommutative_ideals.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.modules +# sage.doctest: needs sage.modules """ Ideals of non-commutative rings diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 837ec08319d..15fa8bdffe9 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -654,7 +654,7 @@ cdef class RealField_class(sage.rings.abc.RealField): Traceback (most recent call last): ... ValueError: can only convert signed infinity to RR - sage: R(CIF(NaN)) + sage: R(CIF(NaN)) # needs sage.symbolic NaN sage: R(complex(1.7)) 1.7000 @@ -719,7 +719,7 @@ cdef class RealField_class(sage.rings.abc.RealField): TESTS:: - sage: 1.0 - ZZ(1) - int(1) - 1 - QQ(1) - RealField(100)(1) - AA(1) - RLF(1) # optional - sage.rings.number_field + sage: 1.0 - ZZ(1) - int(1) - 1 - QQ(1) - RealField(100)(1) - AA(1) - RLF(1) # needs sage.rings.number_field -6.00000000000000 sage: R = RR['x'] # Hold reference to avoid garbage collection, see Issue #24709 sage: R.get_action(ZZ) @@ -920,7 +920,7 @@ cdef class RealField_class(sage.rings.abc.RealField): False sage: RR._is_valid_homomorphism_(CC,[CC(1)]) True - sage: RR._is_valid_homomorphism_(GF(2),GF(2)(1)) # optional - sage.rings.finite_rings + sage: RR._is_valid_homomorphism_(GF(2),GF(2)(1)) False """ @@ -1438,12 +1438,12 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.arange(10.0) # optional - numpy + sage: import numpy # needs numpy + sage: numpy.arange(10.0) # needs numpy array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) - sage: numpy.array([1.0, 1.1, 1.2]).dtype # optional - numpy + sage: numpy.array([1.0, 1.1, 1.2]).dtype # needs numpy dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype # optional - numpy + sage: numpy.array([1.000000000000000000000000000000000000]).dtype # needs numpy dtype('O') """ if (self._parent).__prec <= 53: @@ -1604,7 +1604,7 @@ cdef class RealNumber(sage.structure.element.RingElement): 'Infinity' sage: format(RR(-oo), '.4') '-Infinity' - sage: format(RR(NaN), '.4') + sage: format(RR(NaN), '.4') # needs sage.symbolic 'NaN' sage: '{}'.format(RR(oo)) '+infinity' @@ -1652,11 +1652,11 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: n = 1.3939494594 sage: n._interface_init_() '1.3939494593999999' - sage: s1 = RR(sin(1)); s1 + sage: s1 = RR(sin(1)); s1 # needs sage.symbolic 0.841470984807897 - sage: s1._interface_init_() + sage: s1._interface_init_() # needs sage.symbolic '0.84147098480789650' - sage: s1 == RR(gp(s1)) + sage: s1 == RR(gp(s1)) # needs sage.symbolic True """ return self.str(10, no_sci=True) @@ -1680,6 +1680,8 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: + sage: values = [-infinity, -20, 0, 1, 2^500, -2^4000, -2^-500, 2^-4000] + sage: values += [NaN, -e] # needs sage.symbolic sage: for prec in (2, 53, 200): ....: for rnd_dir in ('RNDN', 'RNDD', 'RNDU', 'RNDZ'): ....: fld = RealField(prec, rnd=rnd_dir) @@ -1694,7 +1696,7 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: RR60 = RealField(60) sage: RR(-infinity)._sage_input_(sib, True) {unop:- {call: {atomic:RR}({atomic:Infinity})}} - sage: RR(NaN)._sage_input_(sib, True) + sage: RR(NaN)._sage_input_(sib, True) # needs sage.symbolic {call: {atomic:RR}({atomic:NaN})} sage: RR(12345)._sage_input_(sib, True) {atomic:12345} @@ -1712,9 +1714,9 @@ cdef class RealNumber(sage.structure.element.RingElement): {call: {atomic:RR}({atomic:1.579})} sage: RR(1.579)._sage_input_(sib_np, 2) {atomic:1.579} - sage: RealField(150)(pi)._sage_input_(sib, True) + sage: RealField(150)(pi)._sage_input_(sib, True) # needs sage.symbolic {atomic:3.1415926535897932384626433832795028841971694008} - sage: RealField(150)(pi)._sage_input_(sib_np, True) + sage: RealField(150)(pi)._sage_input_(sib_np, True) # needs sage.symbolic {call: {call: {atomic:RealField}({atomic:150})}({atomic:'3.1415926535897932384626433832795028841971694008'})} """ # We have a bewildering array of conditions to deal with: @@ -2336,7 +2338,7 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: [x.fp_rank_delta(x.nextabove()) for x in + sage: [x.fp_rank_delta(x.nextabove()) for x in # needs sage.symbolic ....: (RR(-infinity), -1.0, 0.0, 1.0, RR(pi), RR(infinity))] [1, 1, 1, 1, 1, 0] @@ -2517,22 +2519,22 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RealField(100)(1/7)._sympy_() + sage: RealField(100)(1/7)._sympy_() # needs sympy 0.14285714285714285714285714286 - sage: type(_) + sage: type(_) # needs sympy TESTS: An indirect doctest to check this (see :trac:`14915`):: - sage: x,y = var('x, y') - sage: integrate(y, y, 0.5, 8*log(x), algorithm='sympy') + sage: x,y = var('x, y') # needs sage.symbolic + sage: integrate(y, y, 0.5, 8*log(x), algorithm='sympy') # needs sympy sage.symbolic 32*log(x)^2 - 0.125000000000000 Check that :trac:`28903` is fixed:: - sage: (10.0^400)._sympy_() + sage: (10.0^400)._sympy_() # needs sympy 1.00000000000000e+400 """ import sympy @@ -3138,11 +3140,11 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: RR(infinity).nexttoward(0) 2.09857871646739e323228496 # 32-bit 5.87565378911159e1388255822130839282 # 64-bit - sage: RR(pi).str() + sage: RR(pi).str() # needs sage.symbolic '3.1415926535897931' - sage: RR(pi).nexttoward(22/7).str() + sage: RR(pi).nexttoward(22/7).str() # needs sage.symbolic '3.1415926535897936' - sage: RR(pi).nexttoward(21/7).str() + sage: RR(pi).nexttoward(21/7).str() # needs sage.symbolic '3.1415926535897927' """ cdef RealNumber other_rn @@ -3172,9 +3174,9 @@ cdef class RealNumber(sage.structure.element.RingElement): 8.50969131174084e-1388255822130839284 # 64-bit sage: RR('+infinity').nextabove() +infinity - sage: RR(-sqrt(2)).str() + sage: RR(-sqrt(2)).str() # needs sage.symbolic '-1.4142135623730951' - sage: RR(-sqrt(2)).nextabove().str() + sage: RR(-sqrt(2)).nextabove().str() # needs sage.symbolic '-1.4142135623730949' """ @@ -3198,9 +3200,9 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: RR('+infinity').nextbelow() 2.09857871646739e323228496 # 32-bit 5.87565378911159e1388255822130839282 # 64-bit - sage: RR(-sqrt(2)).str() + sage: RR(-sqrt(2)).str() # needs sage.symbolic '-1.4142135623730951' - sage: RR(-sqrt(2)).nextbelow().str() + sage: RR(-sqrt(2)).nextbelow().str() # needs sage.symbolic '-1.4142135623730954' """ @@ -3220,9 +3222,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__float__() + sage: RR(pi).__float__() # needs sage.symbolic 3.141592653589793 - sage: type(RR(pi).__float__()) + sage: type(RR(pi).__float__()) # needs sage.symbolic <... 'float'> """ return mpfr_get_d(self.value, (self._parent).rnd) @@ -3248,9 +3250,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__int__() # optional - sage.symbolic + sage: RR(pi).__int__() # needs sage.symbolic 3 - sage: type(RR(pi).__int__()) + sage: type(RR(pi).__int__()) # needs sage.symbolic <... 'int'> """ if not mpfr_number_p(self.value): @@ -3266,9 +3268,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__complex__() # optional - sage.symbolic + sage: RR(pi).__complex__() # needs sage.symbolic (3.141592653589793+0j) - sage: type(RR(pi).__complex__()) + sage: type(RR(pi).__complex__()) # needs sage.symbolic <... 'complex'> """ @@ -3280,9 +3282,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi)._complex_number_() # optional - sage.symbolic + sage: RR(pi)._complex_number_() # needs sage.symbolic 3.14159265358979 - sage: parent(RR(pi)._complex_number_()) + sage: parent(RR(pi)._complex_number_()) # needs sage.symbolic Complex Field with 53 bits of precision """ from sage.rings.complex_mpfr import ComplexField @@ -3295,11 +3297,11 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: sage: R = RealField(100) - sage: R(pi) + sage: R(pi) # needs sage.symbolic 3.1415926535897932384626433833 - sage: axiom(R(pi)) # optional - axiom # indirect doctest + sage: axiom(R(pi)) # optional - axiom # needs sage.symbolic 3.1415926535 8979323846 26433833 - sage: fricas(R(pi)) # optional - fricas + sage: fricas(R(pi)) # optional - fricas # needs sage.symbolic 3.1415926535_8979323846_26433833 """ @@ -3320,48 +3322,48 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(2.0).__pari__() + sage: RR(2.0).__pari__() # needs sage.libs.pari 2.00000000000000 The current Pari precision affects the printing of this number, but Pari does maintain the same 250-bit number on both 32-bit and 64-bit platforms:: - sage: RealField(250).pi().__pari__() + sage: RealField(250).pi().__pari__() # needs sage.libs.pari 3.14159265358979 - sage: RR(0.0).__pari__() + sage: RR(0.0).__pari__() # needs sage.libs.pari 0.E-19 - sage: RR(-1.234567).__pari__() + sage: RR(-1.234567).__pari__() # needs sage.libs.pari -1.23456700000000 - sage: RR(2.0).sqrt().__pari__() + sage: RR(2.0).sqrt().__pari__() # needs sage.libs.pari 1.41421356237310 - sage: RR(2.0).sqrt().__pari__().sage() + sage: RR(2.0).sqrt().__pari__().sage() # needs sage.libs.pari 1.41421356237309515 - sage: RR(2.0).sqrt().__pari__().sage().prec() + sage: RR(2.0).sqrt().__pari__().sage().prec() # needs sage.libs.pari 64 - sage: RealField(70)(pi).__pari__().sage().prec() + sage: RealField(70)(pi).__pari__().sage().prec() # needs sage.libs.pari sage.symbolic 96 # 32-bit 128 # 64-bit - sage: for i in range(100, 200): + sage: for i in range(100, 200): # needs sage.libs.pari ....: assert(RR(i).sqrt() == RR(i).sqrt().__pari__().sage()) TESTS: Check that we create real zeros without mantissa:: - sage: RDF(0).__pari__().sizeword() + sage: RDF(0).__pari__().sizeword() # needs sage.libs.pari 2 - sage: RealField(100)(0.0).__pari__().sizeword() + sage: RealField(100)(0.0).__pari__().sizeword() # needs sage.libs.pari 2 Check that the largest and smallest exponents representable by PARI convert correctly:: - sage: a = pari(0.5) << (sys.maxsize+1)/4 - sage: RR(a) >> (sys.maxsize+1)/4 + sage: a = pari(0.5) << (sys.maxsize+1)/4 # needs sage.libs.pari + sage: RR(a) >> (sys.maxsize+1)/4 # needs sage.libs.pari 0.500000000000000 - sage: a = pari(0.5) >> (sys.maxsize-3)/4 - sage: RR(a) << (sys.maxsize-3)/4 + sage: a = pari(0.5) >> (sys.maxsize-3)/4 # needs sage.libs.pari + sage: RR(a) << (sys.maxsize-3)/4 # needs sage.libs.pari 0.500000000000000 """ # This uses interfaces of MPFR and PARI which are documented @@ -3516,7 +3518,7 @@ cdef class RealNumber(sage.structure.element.RingElement): 42391158275216203520420085760 sage: RR(3^60).exact_rational() - 3^60 6125652559 - sage: RealField(5)(-pi).exact_rational() + sage: RealField(5)(-pi).exact_rational() # needs sage.symbolic -25/8 TESTS:: @@ -3620,9 +3622,9 @@ cdef class RealNumber(sage.structure.element.RingElement): -1/3 sage: check(RR(-1/3)) -1/3 - sage: check(RealField(20)(pi)) + sage: check(RealField(20)(pi)) # needs sage.symbolic 355/113 - sage: check(RR(pi)) + sage: check(RR(pi)) # needs sage.symbolic 245850922/78256779 sage: check(RR(2).sqrt()) 131836323/93222358 @@ -3786,13 +3788,13 @@ cdef class RealNumber(sage.structure.element.RingElement): -333/1000 sage: RR(3/4).nearby_rational(max_denominator=2) 1 - sage: RR(pi).nearby_rational(max_denominator=120) + sage: RR(pi).nearby_rational(max_denominator=120) # needs sage.symbolic 355/113 - sage: RR(pi).nearby_rational(max_denominator=10000) + sage: RR(pi).nearby_rational(max_denominator=10000) # needs sage.symbolic 355/113 - sage: RR(pi).nearby_rational(max_denominator=100000) + sage: RR(pi).nearby_rational(max_denominator=100000) # needs sage.symbolic 312689/99532 - sage: RR(pi).nearby_rational(max_denominator=1) + sage: RR(pi).nearby_rational(max_denominator=1) # needs sage.symbolic 3 sage: RR(-3.5).nearby_rational(max_denominator=1) -3 @@ -4096,7 +4098,7 @@ cdef class RealNumber(sage.structure.element.RingElement): True sage: RR('-100').is_real() True - sage: RR(NaN).is_real() + sage: RR(NaN).is_real() # needs sage.symbolic False """ return not mpfr_nan_p(self.value) @@ -4241,7 +4243,7 @@ cdef class RealNumber(sage.structure.element.RingElement): :: sage: r = 4344 - sage: r.sqrt() + sage: r.sqrt() # needs sage.symbolic 2*sqrt(1086) :: @@ -4357,10 +4359,10 @@ cdef class RealNumber(sage.structure.element.RingElement): We raise a real number to a symbolic object:: - sage: x, y = var('x,y') - sage: 1.5^x + sage: x, y = var('x,y') # needs sage.symbolic + sage: 1.5^x # needs sage.symbolic 1.50000000000000^x - sage: -2.3^(x+y^3+sin(x)) + sage: -2.3^(x+y^3+sin(x)) # needs sage.symbolic -2.30000000000000^(y^3 + x + sin(x)) TESTS: @@ -4418,21 +4420,21 @@ cdef class RealNumber(sage.structure.element.RingElement): 0.693147180559945 sage: log(RR(2), "e") 0.693147180559945 - sage: log(RR(2), e) + sage: log(RR(2), e) # needs sage.symbolic 0.693147180559945 :: sage: r = R(-1); r.log() 3.14159265358979*I - sage: log(RR(-1),e) + sage: log(RR(-1), e) # needs sage.symbolic 3.14159265358979*I sage: r.log(2) 4.53236014182719*I For the error value NaN (Not A Number), log will return NaN:: - sage: r = R(NaN); r.log() + sage: r = R(NaN); r.log() # needs sage.symbolic NaN """ @@ -5121,8 +5123,8 @@ cdef class RealNumber(sage.structure.element.RingElement): :: sage: m = (a-b)^2/(a+b)^2 - sage: E = numerical_integral(1/sqrt(1-m*sin(x)^2), 0, RR.pi()/2)[0] - sage: RR.pi()/4 * (a+b)/E + sage: E = numerical_integral(1/sqrt(1-m*sin(x)^2), 0, RR.pi()/2)[0] # needs sage.symbolic + sage: RR.pi()/4 * (a+b)/E # needs sage.symbolic 1.96811775182478 TESTS:: @@ -5352,11 +5354,11 @@ cdef class RealNumber(sage.structure.element.RingElement): Computing zeta using PARI is much more efficient in difficult cases. Here's how to compute zeta with at least a given precision:: - sage: z = pari(2).zeta(precision=53); z # optional - sage.libs.pari + sage: z = pari(2).zeta(precision=53); z # needs sage.libs.pari 1.64493406684823 - sage: pari(2).zeta(precision=128).sage().prec() # optional - sage.libs.pari + sage: pari(2).zeta(precision=128).sage().prec() # needs sage.libs.pari 128 - sage: pari(2).zeta(precision=65).sage().prec() # optional - sage.libs.pari + sage: pari(2).zeta(precision=65).sage().prec() # needs sage.libs.pari 128 # 64-bit 96 # 32-bit @@ -5368,9 +5370,9 @@ cdef class RealNumber(sage.structure.element.RingElement): :: - sage: type(z) # optional - sage.libs.pari + sage: type(z) # needs sage.libs.pari - sage: R(z) # optional - sage.libs.pari + sage: R(z) # needs sage.libs.pari 1.64493406684823 """ cdef RealNumber x = self._new() @@ -5523,8 +5525,11 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: check(RealField(20)(22/7), 19) [1.0621, 1.0621, 1.0622, 1.0621] - sage: check(RealField(200)(e), 4) - [1.2840254166877414840734205680624364583362808652814630892175, 1.2840254166877414840734205680624364583362808652814630892175, 1.2840254166877414840734205680624364583362808652814630892176, 1.2840254166877414840734205680624364583362808652814630892175] + sage: check(RealField(200)(e), 4) # needs sage.symbolic + [1.2840254166877414840734205680624364583362808652814630892175, + 1.2840254166877414840734205680624364583362808652814630892175, + 1.2840254166877414840734205680624364583362808652814630892176, + 1.2840254166877414840734205680624364583362808652814630892175] Check that :trac:`12105` is fixed:: @@ -5937,7 +5942,7 @@ def is_RealNumber(x): False sage: is_RealNumber(RDF(2)) False - sage: is_RealNumber(pi) + sage: is_RealNumber(pi) # needs sage.symbolic False """ return isinstance(x, RealNumber) From d32e0de03cf7b08cc97568f24046053e796804c1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 3 Jul 2023 00:26:23 -0700 Subject: [PATCH 24/50] sage.schemes: Update # needs --- src/sage/rings/laurent_series_ring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index 90f926035d7..ccf3e9fa271 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -405,7 +405,6 @@ def _element_constructor_(self, x, n=0, prec=infinity): EXAMPLES:: 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) # optional - sage.rings.padics @@ -442,6 +441,7 @@ def _element_constructor_(self, x, n=0, prec=infinity): Check that :trac:`28993` is fixed:: sage: from sage.modular.etaproducts import qexp_eta # optional - sage.modular + sage: S. = LaurentSeriesRing(RationalField()) sage: qexp_eta(S, prec=30) # optional - sage.modular 1 - t - t^2 + t^5 + t^7 - t^12 - t^15 + t^22 + t^26 + O(t^30) From aea10e2b74e8327f6c32eadd900d4c9a765936f4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 11 Jul 2023 13:50:00 -0700 Subject: [PATCH 25/50] src/sage/rings/laurent_series_ring.py: Restore a lost doctest line --- src/sage/rings/laurent_series_ring.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index ccf3e9fa271..b8d7ec38f40 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -405,6 +405,7 @@ def _element_constructor_(self, x, n=0, prec=infinity): EXAMPLES:: 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) # optional - sage.rings.padics From b22ee693f576cbcb254eb378a84859b866c5467a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 12 Jul 2023 18:39:31 -0700 Subject: [PATCH 26/50] ./sage -fixdoctests --distribution sagemath-categories --probe all --only-tags src/sage/rings/*.{py,pyx} --- src/sage/rings/abc.pyx | 84 +- src/sage/rings/big_oh.py | 2 +- src/sage/rings/complex_arb.pyx | 151 +-- src/sage/rings/complex_conversion.pyx | 2 +- src/sage/rings/complex_double.pyx | 130 +-- src/sage/rings/complex_interval.pyx | 39 +- src/sage/rings/complex_interval_field.py | 4 +- src/sage/rings/complex_mpc.pyx | 22 +- src/sage/rings/complex_mpfr.pyx | 159 +-- src/sage/rings/continued_fraction.py | 414 ++++---- src/sage/rings/continued_fraction_gosper.py | 27 +- src/sage/rings/derivation.py | 174 ++-- src/sage/rings/factorint.pyx | 17 +- src/sage/rings/fraction_field.py | 143 +-- src/sage/rings/fraction_field_element.pyx | 128 +-- src/sage/rings/ideal.py | 232 ++--- src/sage/rings/ideal_monoid.py | 75 +- src/sage/rings/infinity.py | 137 +-- src/sage/rings/integer.pyx | 500 +++++----- src/sage/rings/integer_ring.pyx | 88 +- src/sage/rings/laurent_series_ring.py | 114 ++- .../rings/laurent_series_ring_element.pyx | 95 +- src/sage/rings/lazy_series.py | 792 ++++++++------- src/sage/rings/lazy_series_ring.py | 354 +++---- src/sage/rings/localization.py | 257 ++--- src/sage/rings/monomials.py | 4 +- src/sage/rings/morphism.pyx | 941 +++++++++--------- src/sage/rings/multi_power_series_ring.py | 99 +- .../rings/multi_power_series_ring_element.py | 238 ++--- src/sage/rings/numbers_abc.py | 16 +- src/sage/rings/power_series_poly.pyx | 127 +-- src/sage/rings/power_series_ring.py | 112 ++- src/sage/rings/power_series_ring_element.pyx | 233 ++--- src/sage/rings/puiseux_series_ring.py | 22 +- .../rings/puiseux_series_ring_element.pyx | 25 +- src/sage/rings/qqbar.py | 786 ++++++++------- src/sage/rings/quotient_ring.py | 357 +++---- src/sage/rings/quotient_ring_element.py | 380 +++---- src/sage/rings/rational.pyx | 250 ++--- src/sage/rings/rational_field.py | 144 +-- src/sage/rings/real_arb.pyx | 132 +-- src/sage/rings/real_double.pyx | 41 +- src/sage/rings/real_double_element_gsl.pyx | 12 +- src/sage/rings/real_lazy.pyx | 30 +- src/sage/rings/real_mpfi.pyx | 138 +-- src/sage/rings/real_mpfr.pyx | 26 +- src/sage/rings/ring.pyx | 416 ++++---- src/sage/rings/ring_extension.pyx | 716 ++++++------- src/sage/rings/ring_extension_element.pyx | 435 ++++---- src/sage/rings/ring_extension_morphism.pyx | 253 ++--- src/sage/rings/tate_algebra_ideal.pyx | 16 +- src/sage/rings/tests.py | 64 +- src/sage/rings/universal_cyclotomic_field.py | 20 +- 53 files changed, 5257 insertions(+), 4916 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index d0785dff8c2..860827b5ca5 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -14,13 +14,13 @@ class NumberField_quadratic(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K. = QuadraticField(2) # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.NumberField_quadratic) # optional - sage.rings.number_field + sage: K. = QuadraticField(2) # needs sage.rings.number_field + sage: isinstance(K, sage.rings.abc.NumberField_quadratic) # needs sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.NumberField_quadratic.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.NumberField_quadratic.__subclasses__() # needs sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_quadratic.__subclasses__()) <= 1 @@ -40,13 +40,13 @@ class NumberField_cyclotomic(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K. = CyclotomicField(15) # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.NumberField_cyclotomic) # optional - sage.rings.number_field + sage: K. = CyclotomicField(15) # needs sage.rings.number_field + sage: isinstance(K, sage.rings.abc.NumberField_cyclotomic) # needs sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.NumberField_cyclotomic.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.NumberField_cyclotomic.__subclasses__() # needs sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_cyclotomic.__subclasses__()) <= 1 @@ -66,13 +66,13 @@ class UniversalCyclotomicField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K = UniversalCyclotomicField() # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.UniversalCyclotomicField) # optional - sage.rings.number_field + sage: K = UniversalCyclotomicField() # needs sage.rings.number_field + sage: isinstance(K, sage.rings.abc.UniversalCyclotomicField) # needs sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.UniversalCyclotomicField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.UniversalCyclotomicField.__subclasses__() # needs sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_cyclotomic.__subclasses__()) <= 1 @@ -92,16 +92,16 @@ class AlgebraicField_common(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicField_common) # needs sage.rings.number_field True - sage: isinstance(AA, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicField_common) # needs sage.rings.number_field True By design, other than the abstract subclasses :class:`~sage.rings.abc.AlgebraicField` and :class:`~sage.rings.abc.AlgebraicRealField`, there is only one direct implementation subclass:: - sage: sage.rings.abc.AlgebraicField_common.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicField_common.__subclasses__() # needs sage.rings.number_field [, , ] @@ -123,14 +123,14 @@ class AlgebraicField(AlgebraicField_common): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicField) # needs sage.rings.number_field True - sage: isinstance(AA, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicField) # needs sage.rings.number_field False By design, there is a unique direct subclass:: - sage: sage.rings.abc.AlgebraicField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicField.__subclasses__() # needs sage.rings.number_field [] sage: len(sage.rings.abc.AlgebraicField.__subclasses__()) <= 1 @@ -150,14 +150,14 @@ class AlgebraicRealField(AlgebraicField_common): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicRealField) # needs sage.rings.number_field False - sage: isinstance(AA, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicRealField) # needs sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.AlgebraicRealField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicRealField.__subclasses__() # needs sage.rings.number_field [] sage: len(sage.rings.abc.AlgebraicRealField.__subclasses__()) <= 1 @@ -177,12 +177,12 @@ cdef class RealField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(RR, sage.rings.abc.RealField) # optional - sage.rings.real_mpfr + sage: isinstance(RR, sage.rings.abc.RealField) # needs sage.rings.real_mpfr True By design, there is a unique direct subclass:: - sage: sage.rings.abc.RealField.__subclasses__() # optional - sage.rings.real_mpfr + sage: sage.rings.abc.RealField.__subclasses__() # needs sage.rings.real_mpfr [] sage: len(sage.rings.abc.RealField.__subclasses__()) <= 1 @@ -202,12 +202,12 @@ class RealBallField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(RBF, sage.rings.abc.RealBallField) # optional - sage.libs.flint + sage: isinstance(RBF, sage.rings.abc.RealBallField) # needs sage.libs.flint True By design, there is a unique direct subclass:: - sage: sage.rings.abc.RealBallField.__subclasses__() # optional - sage.libs.flint + sage: sage.rings.abc.RealBallField.__subclasses__() # needs sage.libs.flint [] sage: len(sage.rings.abc.RealBallField.__subclasses__()) <= 1 @@ -277,12 +277,12 @@ cdef class ComplexField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CC, sage.rings.abc.ComplexField) # optional - sage.rings.real_mpfr + sage: isinstance(CC, sage.rings.abc.ComplexField) # needs sage.rings.real_mpfr True By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexField.__subclasses__() # optional - sage.rings.real_mpfr + sage: sage.rings.abc.ComplexField.__subclasses__() # needs sage.rings.real_mpfr [] sage: len(sage.rings.abc.ComplexField.__subclasses__()) <= 1 @@ -302,12 +302,12 @@ class ComplexBallField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CBF, sage.rings.abc.ComplexBallField) # optional - sage.libs.flint + sage: isinstance(CBF, sage.rings.abc.ComplexBallField) # needs sage.libs.flint True By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexBallField.__subclasses__() # optional - sage.libs.flint + sage: sage.rings.abc.ComplexBallField.__subclasses__() # needs sage.libs.flint [] sage: len(sage.rings.abc.ComplexBallField.__subclasses__()) <= 1 @@ -352,12 +352,12 @@ cdef class ComplexDoubleField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CDF, sage.rings.abc.ComplexDoubleField) # optional - sage.rings.complex_double + sage: isinstance(CDF, sage.rings.abc.ComplexDoubleField) # needs sage.rings.complex_double True By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexDoubleField.__subclasses__() # optional - sage.rings.complex_double + sage: sage.rings.abc.ComplexDoubleField.__subclasses__() # needs sage.rings.complex_double [] sage: len(sage.rings.abc.ComplexDoubleField.__subclasses__()) <= 1 @@ -403,13 +403,13 @@ class Order: sage: import sage.rings.abc sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field - sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # needs sage.rings.number_field + sage: isinstance(O, sage.rings.abc.Order) # needs sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.Order.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.Order.__subclasses__() # needs sage.rings.number_field [] sage: len(sage.rings.abc.Order.__subclasses__()) <= 1 @@ -429,14 +429,14 @@ class pAdicRing(EuclideanDomain): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics + sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) # needs sage.rings.padics True - sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics + sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) # needs sage.rings.padics False By design, there is a unique direct subclass:: - sage: sage.rings.abc.pAdicRing.__subclasses__() # optional - sage.rings.padics + sage: sage.rings.abc.pAdicRing.__subclasses__() # needs sage.rings.padics [] sage: len(sage.rings.abc.pAdicRing.__subclasses__()) <= 1 @@ -456,14 +456,14 @@ class pAdicField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(Zp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics + sage: isinstance(Zp(5), sage.rings.abc.pAdicField) # needs sage.rings.padics False - sage: isinstance(Qp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics + sage: isinstance(Qp(5), sage.rings.abc.pAdicField) # needs sage.rings.padics True By design, there is a unique direct subclass:: - sage: sage.rings.abc.pAdicField.__subclasses__() # optional - sage.rings.padics + sage: sage.rings.abc.pAdicField.__subclasses__() # needs sage.rings.padics [] sage: len(sage.rings.abc.pAdicField.__subclasses__()) <= 1 @@ -483,13 +483,13 @@ cdef class SymbolicRing(CommutativeRing): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(SR, sage.rings.abc.SymbolicRing) # optional - sage.symbolic + sage: isinstance(SR, sage.rings.abc.SymbolicRing) # needs sage.symbolic True By design, other than the abstract subclass :class:`~sage.rings.abc.CallableSymbolicExpressionRing`, there is only one direct implementation subclass:: - sage: sage.rings.abc.SymbolicRing.__subclasses__() # optional - sage.symbolic + sage: sage.rings.abc.SymbolicRing.__subclasses__() # needs sage.symbolic [, ] @@ -510,13 +510,13 @@ class CallableSymbolicExpressionRing(SymbolicRing): EXAMPLES:: sage: import sage.rings.abc - sage: f = x.function(x).parent() # optional - sage.symbolic - sage: isinstance(f, sage.rings.abc.CallableSymbolicExpressionRing) # optional - sage.symbolic + sage: f = x.function(x).parent() # needs sage.symbolic + sage: isinstance(f, sage.rings.abc.CallableSymbolicExpressionRing) # needs sage.symbolic True By design, there is a unique direct subclass:: - sage: sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__() # optional - sage.symbolic + sage: sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__() # needs sage.symbolic [] sage: len(sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__()) <= 1 diff --git a/src/sage/rings/big_oh.py b/src/sage/rings/big_oh.py index 21938a2256b..e9b22e77b37 100644 --- a/src/sage/rings/big_oh.py +++ b/src/sage/rings/big_oh.py @@ -119,7 +119,7 @@ def O(*x, **kwds): Traceback (most recent call last): ... ArithmeticError: O(y) not defined - sage: O(x, y) # needs sage.symbolic + sage: O(x, y) Traceback (most recent call last): ... ArithmeticError: O(x, y) not defined diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index ef432c1e945..f8d490f12c3 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -101,13 +101,14 @@ Coercion Automatic coercions work as expected:: - sage: bpol = 1/3*CBF(i) + AA(sqrt(2)) # optional - sage.symbolic - sage: bpol += polygen(RealBallField(20), 'x') + QQbar(i) # optional - sage.symbolic - sage: bpol # optional - sage.symbolic + sage: # needs sage.symbolic + sage: bpol = 1/3*CBF(i) + AA(sqrt(2)) + sage: bpol += polygen(RealBallField(20), 'x') + QQbar(i) + sage: bpol x + [1.41421 +/- ...e-6] + [1.33333 +/- ...e-6]*I - sage: bpol.parent() # optional - sage.symbolic + sage: bpol.parent() Univariate Polynomial Ring in x over Complex ball field with 20 bits of precision - sage: bpol/3 # optional - sage.symbolic + sage: bpol/3 ([0.333333 +/- ...e-7])*x + [0.47140 +/- ...e-6] + [0.44444 +/- ...e-6]*I TESTS:: @@ -117,12 +118,12 @@ TESTS:: :: - sage: SR.coerce(CBF(0.42 + 3.33*I)) # optional - sage.symbolic + sage: SR.coerce(CBF(0.42 + 3.33*I)) # needs sage.symbolic [0.4200000000000000 +/- ...e-17] + [3.330000000000000 +/- ...e-17]*I Check that :trac:`19839` is fixed:: - sage: log(SR(CBF(0.42))).pyobject().parent() # optional - sage.symbolic + sage: log(SR(CBF(0.42))).pyobject().parent() # needs sage.symbolic Complex ball field with 53 bits of precision :trac:`24621`:: @@ -591,15 +592,15 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): 1.000000000000000 sage: CBF(1, 1) 1.000000000000000 + 1.000000000000000*I - sage: CBF(pi, sqrt(2)) # optional - sage.symbolic + sage: CBF(pi, sqrt(2)) # needs sage.symbolic [3.141592653589793 +/- ...e-16] + [1.414213562373095 +/- ...e-16]*I sage: CBF(I) 1.000000000000000*I - sage: CBF(pi + I/3) # optional - sage.symbolic + sage: CBF(pi + I/3) # needs sage.symbolic [3.141592653589793 +/- ...e-16] + [0.3333333333333333 +/- ...e-17]*I sage: CBF(QQbar(i/7)) # abs tol 1e-16 [0.1428571428571429 +/- 4.29e-17]*I - sage: CBF(AA(sqrt(2))) # optional - sage.symbolic + sage: CBF(AA(sqrt(2))) # needs sage.symbolic [1.414213562373095 +/- ...e-16] sage: CBF(CIF(0, 1)) 1.000000000000000*I @@ -616,9 +617,9 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): sage: NF. = QuadraticField(-2) sage: CBF(1/5 + a/2) [0.2000000000000000 +/- ...e-17] + [0.707106781186547 +/- ...e-16]*I - sage: CBF(infinity, NaN) + sage: CBF(infinity, NaN) # needs sage.symbolic [+/- inf] + nan*I - sage: CBF(x) + sage: CBF(x) # needs sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert x to a ComplexBall @@ -636,13 +637,14 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): The following conversions used to yield incorrect enclosures:: - sage: a = CBF(airy_ai(1)); a # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = CBF(airy_ai(1)); a [0.1352924163128814 +/- 6.95e-17] - sage: a.overlaps(ComplexBallField(100).one().airy_ai()) # optional - sage.symbolic + sage: a.overlaps(ComplexBallField(100).one().airy_ai()) True - sage: v = CBF(zetaderiv(1, 3/2)); v # optional - sage.symbolic + sage: v = CBF(zetaderiv(1, 3/2)); v [-3.932239737431101 +/- 5.58e-16] - sage: v.overlaps(ComplexBallField(100)(3/2).zetaderiv(1)) # optional - sage.symbolic + sage: v.overlaps(ComplexBallField(100)(3/2).zetaderiv(1)) True """ try: @@ -1077,7 +1079,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): ....: return CBF(NaN) ....: else: ....: return z.sqrt() - sage: CBF.integral(my_sqrt, -1 + CBF(i), -1 - CBF(i)) + sage: CBF.integral(my_sqrt, -1 + CBF(i), -1 - CBF(i)) # needs sage.symbolic [+/- ...e-14] + [-0.4752076627926 +/- 5...e-14]*I Note, though, that proper handling of the ``analytic`` flag is required @@ -1085,7 +1087,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): sage: correct = CBF.integral(my_sqrt, 1, 2); correct [1.21895141649746 +/- ...e-15] - sage: RBF(integral(sqrt(x), x, 1, 2)) # long time # optional - sage.symbolic + sage: RBF(integral(sqrt(x), x, 1, 2)) # long time # needs sage.symbolic [1.21895141649746 +/- ...e-15] sage: wrong = CBF.integral(lambda z, _: z.sqrt(), 1, 2) # WRONG! sage: correct - wrong @@ -1348,7 +1350,7 @@ cdef class ComplexBall(RingElement): 0 sage: ComplexBall(CBF100, ComplexBall(CBF53, ComplexBall(CBF100, 1/3))) [0.333333333333333333333333333333 +/- ...e-31] - sage: ComplexBall(CBF100, RBF(pi)) + sage: ComplexBall(CBF100, RBF(pi)) # needs sage.symbolic [3.141592653589793 +/- ...e-16] sage: ComplexBall(CBF100, -3r) @@ -1512,7 +1514,7 @@ cdef class ComplexBall(RingElement): TESTS:: - sage: [loads(dumps(b)).identical(b) for b in + sage: [loads(dumps(b)).identical(b) for b in # needs sage.symbolic ....: [ComplexBallField(60)(1/3 + i*pi), CBF(NaN)]] [True, True] """ @@ -2104,9 +2106,9 @@ cdef class ComplexBall(RingElement): sage: CBF(17, 1023).nbits() 10 - sage: CBF(1/3, NaN).nbits() + sage: CBF(1/3, NaN).nbits() # needs sage.symbolic 53 - sage: CBF(NaN).nbits() + sage: CBF(NaN).nbits() # needs sage.symbolic 0 """ return acb_bits(self.value) @@ -2121,13 +2123,13 @@ cdef class ComplexBall(RingElement): their parent's nominal precision (see :mod:`~sage.rings.real_arb` for more information):: - sage: b = CBF(exp(I*pi/3).n(100)) - sage: b.mid() + sage: b = CBF(exp(I*pi/3).n(100)) # needs sage.symbolic + sage: b.mid() # needs sage.symbolic 0.50000000000000000000000000000 + 0.86602540378443864676372317075*I The ``round()`` method rounds such a ball to its parent's precision:: - sage: b.round().mid() + sage: b.round().mid() # needs sage.symbolic 0.500000000000000 + 0.866025403784439*I .. SEEALSO:: :meth:`trim` @@ -2150,7 +2152,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(exp(I*pi/3)).accuracy() + sage: CBF(exp(I*pi/3)).accuracy() # needs sage.symbolic 51 sage: CBF(I/2).accuracy() == CBF.base().maximal_accuracy() True @@ -2218,7 +2220,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(NaN).is_NaN() + sage: CBF(NaN).is_NaN() # needs sage.symbolic True sage: CBF(-5).gamma().is_NaN() True @@ -2261,7 +2263,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(pi, 1/3).is_nonzero() + sage: CBF(pi, 1/3).is_nonzero() # needs sage.symbolic True sage: CBF(RIF(-0.5, 0.5), 1/3).is_nonzero() True @@ -2505,7 +2507,7 @@ cdef class ComplexBall(RingElement): sage: CBF(1).contains_exact(CBF(1)) True - sage: CBF(sqrt(2)).contains_exact(sqrt(2)) # optional - sage.symbolic + sage: CBF(sqrt(2)).contains_exact(sqrt(2)) # needs sage.symbolic Traceback (most recent call last): ... TypeError: unsupported type: @@ -2805,7 +2807,7 @@ cdef class ComplexBall(RingElement): sage: CBF(-1)**(1/2) 1.000000000000000*I - sage: CBF(e)**CBF(i*pi) + sage: CBF(e)**CBF(i*pi) # needs sage.symbolic [-1.00000000000000 +/- ...e-16] + [+/- ...e-15]*I sage: CBF(0, 1)**AA(2)**(1/2) [-0.60569986707881 +/- ...e-15] + [0.79569320156748 +/- ...e-15]*I @@ -2824,13 +2826,13 @@ cdef class ComplexBall(RingElement): TESTS:: - sage: (CBF(e)**CBF(i))**RBF(pi) + sage: (CBF(e)**CBF(i))**RBF(pi) # needs sage.symbolic [-1.0000000000000 +/- ...e-15] + [+/- ...e-15]*I sage: CBF(2*i)**10r -1024.000000000000 sage: CBF(1,1) ^ -1r 0.5000000000000000 - 0.5000000000000000*I - sage: CBF(2)**SR.var('x') # optional - sage.symbolic + sage: CBF(2)**SR.var('x') # needs sage.symbolic 2.000000000000000^x """ if (isinstance(base, ComplexBall) @@ -2864,7 +2866,7 @@ cdef class ComplexBall(RingElement): TESTS:: - sage: CBF(2).pow(SR.var('x')) # optional - sage.symbolic + sage: CBF(2).pow(SR.var('x')) # needs sage.symbolic Traceback (most recent call last): ... TypeError: no canonical coercion from Symbolic Ring to Complex ball @@ -3119,7 +3121,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(i*pi).exp() + sage: CBF(i*pi).exp() # needs sage.symbolic [-1.00000000000000 +/- ...e-16] + [+/- ...e-16]*I """ cdef ComplexBall res = self._new() @@ -3136,7 +3138,7 @@ cdef class ComplexBall(RingElement): sage: CBF(1/2).exppii() 1.000000000000000*I - sage: CBF(0, -1/pi).exppii() + sage: CBF(0, -1/pi).exppii() # needs sage.symbolic [2.71828182845904 +/- ...e-15] """ cdef ComplexBall res = self._new() @@ -3151,7 +3153,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(i*pi).sin() + sage: CBF(i*pi).sin() # needs sage.symbolic [11.54873935725775 +/- ...e-15]*I """ cdef ComplexBall res = self._new() @@ -3166,7 +3168,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(i*pi).cos() + sage: CBF(i*pi).cos() # needs sage.symbolic [11.59195327552152 +/- ...e-15] """ cdef ComplexBall res = self._new() @@ -3181,9 +3183,9 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(pi/2, 1/10).tan() + sage: CBF(pi/2, 1/10).tan() # needs sage.symbolic [+/- ...e-14] + [10.03331113225399 +/- ...e-15]*I - sage: CBF(pi/2).tan() + sage: CBF(pi/2).tan() # needs sage.symbolic nan """ cdef ComplexBall res = self._new() @@ -3198,9 +3200,9 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(pi, 1/10).cot() + sage: CBF(pi, 1/10).cot() # needs sage.symbolic [+/- ...e-14] + [-10.03331113225399 +/- ...e-15]*I - sage: CBF(pi).cot() + sage: CBF(pi).cot() # needs sage.symbolic nan """ cdef ComplexBall res = self._new() @@ -3277,7 +3279,7 @@ cdef class ComplexBall(RingElement): sage: CBF(1, 1).tanh() [1.083923327338694 +/- ...e-16] + [0.2717525853195117 +/- ...e-17]*I - sage: CBF(0, pi/2).tanh() + sage: CBF(0, pi/2).tanh() # needs sage.symbolic nan*I """ cdef ComplexBall res = self._new() @@ -3294,7 +3296,7 @@ cdef class ComplexBall(RingElement): sage: CBF(1, 1).coth() [0.868014142895925 +/- ...e-16] + [-0.2176215618544027 +/- ...e-17]*I - sage: CBF(0, pi).coth() + sage: CBF(0, pi).coth() # needs sage.symbolic nan*I """ cdef ComplexBall res = self._new() @@ -3309,7 +3311,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(pi/2, 1/10).sech() + sage: CBF(pi/2, 1/10).sech() # needs sage.symbolic [0.397174529918189 +/- ...e-16] + [-0.0365488656274242 +/- ...e-17]*I """ cdef ComplexBall res = self._new() @@ -3326,7 +3328,7 @@ cdef class ComplexBall(RingElement): sage: CBF(1, 1).csch() [0.303931001628426 +/- ...e-16] + [-0.621518017170428 +/- ...e-16]*I - sage: CBF(i*pi).csch() + sage: CBF(i*pi).csch() # needs sage.symbolic nan*I """ cdef ComplexBall res = self._new() @@ -3837,15 +3839,15 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(1, pi/2).hypergeometric([], []) + sage: CBF(1, pi/2).hypergeometric([], []) # needs sage.symbolic [+/- ...e-16] + [2.71828182845904 +/- ...e-15]*I - sage: CBF(1, pi).hypergeometric([1/4], [1/4]) + sage: CBF(1, pi).hypergeometric([1/4], [1/4]) # needs sage.symbolic [-2.7182818284590 +/- ...e-14] + [+/- ...e-14]*I - sage: CBF(1000, 1000).hypergeometric([10], [AA(sqrt(2))]) # optional - sage.symbolic + sage: CBF(1000, 1000).hypergeometric([10], [AA(sqrt(2))]) # needs sage.symbolic [9.79300951360e+454 +/- ...e+442] + [5.522579106816e+455 +/- ...e+442]*I - sage: CBF(1000, 1000).hypergeometric([100], [AA(sqrt(2))]) # optional - sage.symbolic + sage: CBF(1000, 1000).hypergeometric([100], [AA(sqrt(2))]) # needs sage.symbolic [1.27967355557e+590 +/- ...e+578] + [-9.32333491987e+590 +/- ...e+578]*I sage: CBF(0, 1).hypergeometric([], [1/2, 1/3, 1/4]) @@ -3879,7 +3881,7 @@ cdef class ComplexBall(RingElement): TESTS:: - sage: CBF(0, 1).hypergeometric([QQbar(sqrt(2)), RLF(pi)], [1r, 1/2]) # optional - sage.symbolic + sage: CBF(0, 1).hypergeometric([QQbar(sqrt(2)), RLF(pi)], [1r, 1/2]) # needs sage.symbolic [-8.7029449215408 +/- ...e-14] + [-0.8499070546106 +/- ...e-14]*I """ @@ -3953,7 +3955,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(1000, 1000).hypergeometric_U(RLF(pi), -100) + sage: CBF(1000, 1000).hypergeometric_U(RLF(pi), -100) # needs sage.symbolic [-7.261605907166e-11 +/- ...e-24] + [-7.928136216391e-11 +/- ...e-24]*I sage: CBF(1000, 1000).hypergeometric_U(0, -100) 1.000000000000000 @@ -4006,7 +4008,7 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: CBF(10*pi).airy() + sage: CBF(10*pi).airy() # needs sage.symbolic ([1.2408955946101e-52 +/- ...e-66], [-6.965048886977e-52 +/- ...e-65], [2.2882956833435e+50 +/- ...e+36], @@ -4218,7 +4220,7 @@ cdef class ComplexBall(RingElement): TESTS: - sage: CBF(Ei(I)) # abs tol 1e-16 + sage: CBF(Ei(I)) # abs tol 1e-16 # needs sage.symbolic [0.337403922900968 +/- 3.76e-16] + [2.51687939716208 +/- 2.01e-15]*I """ cdef ComplexBall result = self._new() @@ -4242,7 +4244,7 @@ cdef class ComplexBall(RingElement): TESTS: - sage: CBF(Si(I)) + sage: CBF(Si(I)) # needs sage.symbolic [1.05725087537573 +/- 2.77e-15]*I """ cdef ComplexBall result = self._new() @@ -4268,7 +4270,7 @@ cdef class ComplexBall(RingElement): TESTS: - sage: CBF(Ci(I)) # abs tol 1e-17 + sage: CBF(Ci(I)) # abs tol 1e-17 # needs sage.symbolic [0.837866940980208 +/- 4.72e-16] + [1.570796326794897 +/- 5.54e-16]*I """ cdef ComplexBall result = self._new() @@ -4294,7 +4296,7 @@ cdef class ComplexBall(RingElement): TESTS: - sage: CBF(Shi(I)) # abs tol 1e-15 + sage: CBF(Shi(I)) # abs tol 1e-15 # needs sage.symbolic [0.946083070367183 +/- 9.22e-16]*I """ cdef ComplexBall result = self._new() @@ -4320,7 +4322,7 @@ cdef class ComplexBall(RingElement): TESTS: - sage: CBF(Chi(I)) # abs tol 1e-16 + sage: CBF(Chi(I)) # abs tol 1e-16 # needs sage.symbolic [0.337403922900968 +/- 3.25e-16] + [1.570796326794897 +/- 5.54e-16]*I """ cdef ComplexBall result = self._new() @@ -4347,16 +4349,16 @@ cdef class ComplexBall(RingElement): 0 sage: CBF(0).li(offset=True) [-1.045163780117493 +/- ...e-16] - sage: li(0).n() + sage: li(0).n() # needs sage.symbolic 0.000000000000000 - sage: Li(0).n() + sage: Li(0).n() # needs sage.symbolic -1.04516378011749 TESTS:: - sage: CBF(li(0)) + sage: CBF(li(0)) # needs sage.symbolic 0 - sage: CBF(Li(0)) + sage: CBF(Li(0)) # needs sage.symbolic [-1.04516378011749...] """ cdef ComplexBall result = self._new() @@ -4375,9 +4377,9 @@ cdef class ComplexBall(RingElement): sage: CBF(0).Li() [-1.045163780117493 +/- ...e-16] - sage: li(0).n() + sage: li(0).n() # needs sage.symbolic 0.000000000000000 - sage: Li(0).n() + sage: Li(0).n() # needs sage.symbolic -1.04516378011749 """ cdef ComplexBall result = self._new() @@ -4479,12 +4481,13 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: tau = CBF(sqrt(2),pi) # optional - sage.symbolic - sage: tau.modular_lambda() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: tau = CBF(sqrt(2),pi) + sage: tau.modular_lambda() [-0.00022005123884157 +/- ...e-18] + [-0.00079787346459944 +/- ...e-18]*I - sage: (tau + 2).modular_lambda() # optional - sage.symbolic + sage: (tau + 2).modular_lambda() [-0.00022005123884157 +/- ...e-18] + [-0.00079787346459944 +/- ...e-18]*I - sage: (tau / (1 - 2*tau)).modular_lambda() # optional - sage.symbolic + sage: (tau / (1 - 2*tau)).modular_lambda() [-0.00022005123884 +/- ...e-15] + [-0.00079787346460 +/- ...e-15]*I """ @@ -4564,19 +4567,19 @@ cdef class ComplexBall(RingElement): EXAMPLES:: sage: tau = CBF(1,4) - sage: z = CBF(sqrt(2), sqrt(3)) # optional - sage.symbolic - sage: z.elliptic_p(tau) # optional - sage.symbolic + sage: z = CBF(sqrt(2), sqrt(3)) # needs sage.symbolic + sage: z.elliptic_p(tau) # needs sage.symbolic [-3.28920996772709 +/- ...e-15] + [-0.0003673767302933 +/- ...e-17]*I - sage: (z + tau).elliptic_p(tau) # optional - sage.symbolic + sage: (z + tau).elliptic_p(tau) # needs sage.symbolic [-3.28920996772709 +/- ...e-15] + [-0.000367376730293 +/- ...e-16]*I - sage: (z + 1).elliptic_p(tau) # optional - sage.symbolic + sage: (z + 1).elliptic_p(tau) # needs sage.symbolic [-3.28920996772709 +/- ...e-15] + [-0.0003673767302933 +/- ...e-17]*I - sage: z.elliptic_p(tau, 3) # optional - sage.symbolic + sage: z.elliptic_p(tau, 3) # needs sage.symbolic [[-3.28920996772709 +/- ...e-15] + [-0.0003673767302933 +/- ...e-17]*I, [0.002473055794309 +/- ...e-16] + [0.003859554040267 +/- ...e-16]*I, [-0.01299087561709 +/- ...e-15] + [0.00725027521915 +/- ...e-15]*I] - sage: (z + 3 + 4*tau).elliptic_p(tau, 3) # optional - sage.symbolic + sage: (z + 3 + 4*tau).elliptic_p(tau, 3) # needs sage.symbolic [[-3.28920996772709 +/- ...e-15] + [-0.00036737673029 +/- ...e-15]*I, [0.0024730557943 +/- ...e-14] + [0.0038595540403 +/- ...e-14]*I, [-0.01299087562 +/- ...e-12] + [0.00725027522 +/- ...e-12]*I] @@ -4615,7 +4618,7 @@ cdef class ComplexBall(RingElement): sage: CBF(0,1).elliptic_invariants() ([189.07272012923 +/- ...e-12], [+/- ...e-12]) - sage: CBF(sqrt(2)/2, sqrt(2)/2).elliptic_invariants() # optional - sage.symbolic + sage: CBF(sqrt(2)/2, sqrt(2)/2).elliptic_invariants() # needs sage.symbolic ([+/- ...e-12] + [-332.5338031465...]*I, [1254.46842157...] + [1254.46842157...]*I) """ diff --git a/src/sage/rings/complex_conversion.pyx b/src/sage/rings/complex_conversion.pyx index a11f86a7735..abf179064c6 100644 --- a/src/sage/rings/complex_conversion.pyx +++ b/src/sage/rings/complex_conversion.pyx @@ -12,7 +12,7 @@ cdef class CCtoCDF(Map): sage: f = CCtoCDF(CC, CDF) # indirect doctest sage: f(CC.0) 1.0*I - sage: f(exp(pi*CC.0/4)) + sage: f(exp(pi*CC.0/4)) # needs sage.symbolic 0.7071067811865476 + 0.7071067811865475*I """ z = ComplexDoubleElement.__new__(ComplexDoubleElement) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 1e679393c80..1cabe39fedf 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -24,7 +24,7 @@ EXAMPLES:: Complex Double Field sage: type(CDF.0) - sage: ComplexDoubleElement(sqrt(2),3) + sage: ComplexDoubleElement(sqrt(2), 3) # needs sage.symbolic 1.4142135623730951 + 3.0*I sage: parent(CDF(-2)) Complex Double Field @@ -421,16 +421,16 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): Thus the sum of a CDF and a symbolic object is symbolic:: - sage: a = pi + CDF.0; a + sage: a = pi + CDF.0; a # needs sage.symbolic pi + 1.0*I - sage: parent(a) + sage: parent(a) # needs sage.symbolic Symbolic Ring TESTS:: sage: CDF(1) + RR(1) 2.0 - sage: CDF.0 - CC(1) - int(1) - RR(1) - QQbar(1) + sage: CDF.0 - CC(1) - int(1) - RR(1) - QQbar(1) # needs sage.rings.number_field -4.0 + 1.0*I sage: CDF.has_coerce_map_from(ComplexField(20)) False @@ -476,7 +476,7 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): 'ComplexField(53 : Bits := true)' sage: magma(CDF) # optional - magma Complex field of precision 15 - sage: floor(RR(log(2**53, 10))) + sage: floor(RR(log(2**53, 10))) # needs sage.symbolic 15 sage: magma(CDF).sage() # optional - magma Complex Field with 53 bits of precision @@ -890,13 +890,14 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF((1.2, 0.3))._magma_init_(magma) # optional - magma + sage: # optional - magma + sage: CDF((1.2, 0.3))._magma_init_(magma) 'ComplexField(53 : Bits := true)![1.2, 0.3]' - sage: magma(CDF(1.2, 0.3)) # optional - magma # indirect doctest + sage: magma(CDF(1.2, 0.3)) 1.20000000000000 + 0.300000000000000*$.1 - sage: s = magma(CDF(1.2, 0.3)).sage(); s # optional - magma # indirect doctest + sage: s = magma(CDF(1.2, 0.3)).sage(); s 1.20000000000000 + 0.300000000000000*I - sage: s.parent() # optional - magma + sage: s.parent() Complex Field with 53 bits of precision """ return "%s![%s, %s]" % (self.parent()._magma_init_(magma), self.real(), self.imag()) @@ -981,11 +982,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: s1 = CDF(exp(I)); s1 + sage: s1 = CDF(exp(I)); s1 # needs sage.symbolic 0.5403023058681398 + 0.8414709848078965*I - sage: s1._interface_init_() + sage: s1._interface_init_() # needs sage.symbolic '0.54030230586813977 + 0.84147098480789650*I' - sage: s1 == CDF(gp(s1)) + sage: s1 == CDF(gp(s1)) # needs sage.symbolic True """ # Sending to another computer algebra system is slow anyway, right? @@ -1025,11 +1026,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1, 0)._sympy_() + sage: CDF(1, 0)._sympy_() # needs sympy 1.00000000000000 - sage: CDF(1/3, 1)._sympy_() + sage: CDF(1/3, 1)._sympy_() # needs sympy 0.333333333333333 + 1.0*I - sage: type(_) + sage: type(_) # needs sympy """ x = GSL_REAL(self._complex) @@ -1145,13 +1146,14 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,2).__pari__() # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: CDF(1,2).__pari__() 1.00000000000000 + 2.00000000000000*I - sage: pari(CDF(1,2)) # optional - sage.libs.pari + sage: pari(CDF(1,2)) 1.00000000000000 + 2.00000000000000*I - sage: pari(CDF(2.0)) # optional - sage.libs.pari + sage: pari(CDF(2.0)) 2.00000000000000 - sage: pari(CDF(I)) # optional - sage.libs.pari + sage: pari(CDF(I)) 1.00000000000000*I """ global new_gen_from_complex_double_element @@ -1628,7 +1630,7 @@ cdef class ComplexDoubleElement(FieldElement): sage: CDF(1, 2).is_NaN() False - sage: CDF(NaN).is_NaN() + sage: CDF(NaN).is_NaN() # needs sage.symbolic True sage: (1/CDF(0, 0)).is_NaN() True @@ -1663,11 +1665,11 @@ cdef class ComplexDoubleElement(FieldElement): We raise to symbolic powers:: - sage: var('x, n') + sage: var('x, n') # needs sage.symbolic (x, n) - sage: CDF(1.2)^x + sage: CDF(1.2)^x # needs sage.symbolic 1.2^x - sage: CDF(1.2)^(x^n + n^x) + sage: CDF(1.2)^(x^n + n^x) # needs sage.symbolic 1.2^(n^x + x^n) A real number powered to an exact integer always yields a real @@ -1739,9 +1741,9 @@ cdef class ComplexDoubleElement(FieldElement): We numerically verify a famous identity to the precision of a double:: - sage: z = CDF(0, 2*pi); z + sage: z = CDF(0, 2*pi); z # needs sage.symbolic 6.283185307179586*I - sage: exp(z) # rel tol 1e-4 + sage: exp(z) # rel tol 1e-4 # needs sage.symbolic 1.0 - 2.4492935982947064e-16*I """ return self._new_c(gsl_complex_exp(self._complex)) @@ -2194,41 +2196,42 @@ cdef class ComplexDoubleElement(FieldElement): We compute a few values of :meth:`eta()`:: - sage: CDF(0,1).eta() # optional - sage.libs.pari + sage: CDF(0,1).eta() # needs sage.libs.pari 0.7682254223260566 - sage: CDF(1,1).eta() # optional - sage.libs.pari + sage: CDF(1,1).eta() # needs sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I - sage: CDF(25,1).eta() # optional - sage.libs.pari + sage: CDF(25,1).eta() # needs sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I :meth:`eta()` works even if the inputs are large:: sage: CDF(0, 10^15).eta() 0.0 - sage: CDF(10^15, 0.1).eta() # abs tol 1e-10 # optional - sage.libs.pari + sage: CDF(10^15, 0.1).eta() # abs tol 1e-10 # needs sage.libs.pari -0.115342592727 - 0.19977923088*I We compute a few values of :meth:`eta()`, but with the fractional power of `e` omitted:: - sage: CDF(0,1).eta(True) # optional - sage.libs.pari + sage: CDF(0,1).eta(True) # needs sage.libs.pari 0.9981290699259585 We compute :meth:`eta()` to low precision directly from the definition:: - sage: z = CDF(1,1); z.eta() # optional - sage.libs.pari + sage: z = CDF(1,1); z.eta() # needs sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I - sage: i = CDF(0,1); pi = CDF(pi) - sage: exp(pi * i * z / 12) * prod([1-exp(2*pi*i*n*z) for n in range(1,10)]) + sage: i = CDF(0,1); pi = CDF(pi) # needs sage.symbolic + sage: exp(pi * i * z / 12) * prod(1 - exp(2*pi*i*n*z) # needs sage.libs.pari sage.symbolic + ....: for n in range(1, 10)) 0.7420487758365647 + 0.19883137022991068*I The optional argument allows us to omit the fractional part:: - sage: z.eta(omit_frac=True) # optional - sage.libs.pari + sage: z.eta(omit_frac=True) # needs sage.libs.pari 0.9981290699259585 - sage: pi = CDF(pi) - sage: prod([1-exp(2*pi*i*n*z) for n in range(1,10)]) # abs tol 1e-12 + sage: pi = CDF(pi) # needs sage.symbolic + sage: prod(1 - exp(2*pi*i*n*z) for n in range(1,10)) # abs tol 1e-12 # needs sage.libs.pari sage.symbolic 0.998129069926 + 4.59084695545e-19*I We illustrate what happens when `z` is not in the upper half plane:: @@ -2242,7 +2245,7 @@ cdef class ComplexDoubleElement(FieldElement): You can also use functional notation:: sage: z = CDF(1,1) - sage: eta(z) # optional - sage.libs.pari + sage: eta(z) # needs sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I """ if GSL_IMAG(self._complex) <= 0: @@ -2372,9 +2375,9 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,2).dilog() # optional - sage.libs.pari + sage: CDF(1,2).dilog() # needs sage.libs.pari -0.059474798673809476 + 2.0726479717747566*I - sage: CDF(10000000,10000000).dilog() # optional - sage.libs.pari + sage: CDF(10000000,10000000).dilog() # needs sage.libs.pari -134.411774490731 + 38.79396299904504*I """ global complex_double_element_dilog @@ -2389,13 +2392,14 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(5,0).gamma() # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: CDF(5,0).gamma() 24.0 - sage: CDF(1,1).gamma() # optional - sage.libs.pari + sage: CDF(1,1).gamma() 0.49801566811835607 - 0.15494982830181067*I - sage: CDF(0).gamma() # optional - sage.libs.pari + sage: CDF(0).gamma() Infinity - sage: CDF(-1,0).gamma() # optional - sage.libs.pari + sage: CDF(-1,0).gamma() Infinity """ if not GSL_IMAG(self._complex): @@ -2420,11 +2424,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,1).gamma_inc(CDF(2,3)) # optional - sage.libs.pari + sage: CDF(1,1).gamma_inc(CDF(2,3)) # needs sage.libs.pari 0.0020969148636468277 - 0.059981913655449706*I - sage: CDF(1,1).gamma_inc(5) # optional - sage.libs.pari + sage: CDF(1,1).gamma_inc(5) # needs sage.libs.pari -0.001378130936215849 + 0.006519820023119819*I - sage: CDF(2,0).gamma_inc(CDF(1,1)) # optional - sage.libs.pari + sage: CDF(2,0).gamma_inc(CDF(1,1)) # needs sage.libs.pari 0.7070920963459381 - 0.4203536409598115*I """ global complex_double_element_gamma_inc @@ -2439,11 +2443,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: sage: z = CDF(1, 1) - sage: z.zeta() # optional - sage.libs.pari + sage: z.zeta() # needs sage.libs.pari 0.5821580597520036 - 0.9268485643308071*I - sage: zeta(z) # optional - sage.libs.pari + sage: zeta(z) # needs sage.libs.pari 0.5821580597520036 - 0.9268485643308071*I - sage: zeta(CDF(1)) # optional - sage.libs.pari + sage: zeta(CDF(1)) # needs sage.libs.pari Infinity """ if GSL_REAL(self._complex) == 1 and GSL_IMAG(self._complex) == 0: @@ -2467,18 +2471,18 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: z = (1/2)*(1 + RDF(sqrt(3)) *CDF.0); z # abs tol 1e-16 + sage: z = (1/2)*(1 + RDF(sqrt(3)) * CDF.0); z # abs tol 1e-16 # needs sage.symbolic 0.5 + 0.8660254037844387*I - sage: p = z.algdep(5); p # optional - sage.libs.pari sage.symbolic + sage: p = z.algdep(5); p # needs sage.libs.pari sage.symbolic x^2 - x + 1 - sage: abs(z^2 - z + 1) < 1e-14 + sage: abs(z^2 - z + 1) < 1e-14 # needs sage.symbolic True :: - sage: CDF(0,2).algdep(10) # optional - sage.libs.pari + sage: CDF(0,2).algdep(10) # needs sage.libs.pari x^2 + 4 - sage: CDF(1,5).algdep(2) # optional - sage.libs.pari + sage: CDF(1,5).algdep(2) # needs sage.libs.pari x^2 - 2*x + 26 """ from sage.arith.misc import algdep @@ -2569,11 +2573,11 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy # optional - numpy - sage: f = CDF.coerce_map_from(numpy.complex_) # optional - numpy - sage: f(numpy.complex_(I)) # optional - numpy + sage: import numpy # needs numpy + sage: f = CDF.coerce_map_from(numpy.complex_) # needs numpy + sage: f(numpy.complex_(I)) # needs numpy 1.0*I - sage: f(numpy.complex_(I)).parent() # optional - numpy + sage: f(numpy.complex_(I)).parent() # needs numpy Complex Double Field """ def __init__(self, R): @@ -2589,8 +2593,8 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy # optional - numpy - sage: CDF(numpy.complex_(I)) # indirect doctest # optional - numpy + sage: import numpy # needs numpy + sage: CDF(numpy.complex_(I)) # indirect doctest # needs numpy 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) @@ -2603,9 +2607,9 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy # optional - numpy - sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) # optional - numpy - sage: f._repr_type() # optional - numpy + sage: import numpy # needs numpy + sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) # needs numpy + sage: f._repr_type() # needs numpy 'Native' """ return "Native" diff --git a/src/sage/rings/complex_interval.pyx b/src/sage/rings/complex_interval.pyx index 12e32fc2d90..05c77675c53 100644 --- a/src/sage/rings/complex_interval.pyx +++ b/src/sage/rings/complex_interval.pyx @@ -230,7 +230,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): '-2.5000000000000000?*I' sage: CIF(1.5).str(base=3) '1.1111111111111111111111111111111112?' - sage: CIF(1, pi).str(style='brackets') + sage: CIF(1, pi).str(style='brackets') # needs sage.symbolic '[1.0000000000000000 .. 1.0000000000000000] + [3.1415926535897931 .. 3.1415926535897936]*I' .. SEEALSO:: @@ -285,23 +285,24 @@ cdef class ComplexIntervalFieldElement(FieldElement): EXAMPLES:: - sage: sum(plot(CIF(RIF(1/k, 1/k), RIF(-k, k))) for k in [1..10]) + sage: sum(plot(CIF(RIF(1/k, 1/k), RIF(-k, k))) for k in [1..10]) # needs sage.plot Graphics object consisting of 20 graphics primitives Exact and nearly exact points are still visible:: - sage: plot(CIF(pi, 1), color='red') + plot(CIF(1, e), color='purple') + plot(CIF(-1, -1)) + sage: plot(CIF(pi, 1), color='red') + plot(CIF(1, e), color='purple') + plot(CIF(-1, -1)) # needs sage.plot Graphics object consisting of 6 graphics primitives A demonstration that `z \mapsto z^2` acts chaotically on `|z|=1`:: + sage: # needs sage.symbolic sage: z = CIF(0, 2*pi/1000).exp() - sage: g = Graphics() - sage: for i in range(40): + sage: g = Graphics() # needs sage.plot + sage: for i in range(40): # needs sage.plot ....: z = z^2 ....: g += z.plot(color=(1./(40-i), 0, 1)) ... - sage: g + sage: g # needs sage.plot Graphics object consisting of 80 graphics primitives """ from sage.plot.polygon import polygon2d @@ -351,15 +352,15 @@ cdef class ComplexIntervalFieldElement(FieldElement): (2.50000000000000, 3.00000000000000) (-4.50000000000000, -4.00000000000000) - sage: z = CIF(RIF(sqrt(2), sqrt(3)), RIF(e, pi)) - sage: a, b, c, d = z.bisection() - sage: a.intersection(b).intersection(c).intersection(d) == CIF(z.center()) + sage: z = CIF(RIF(sqrt(2), sqrt(3)), RIF(e, pi)) # needs sage.symbolic + sage: a, b, c, d = z.bisection() # needs sage.symbolic + sage: a.intersection(b).intersection(c).intersection(d) == CIF(z.center()) # needs sage.symbolic True - sage: zz = a.union(b).union(c).union(c) - sage: zz.real().endpoints() == z.real().endpoints() + sage: zz = a.union(b).union(c).union(c) # needs sage.symbolic + sage: zz.real().endpoints() == z.real().endpoints() # needs sage.symbolic True - sage: zz.imag().endpoints() == z.imag().endpoints() + sage: zz.imag().endpoints() == z.imag().endpoints() # needs sage.symbolic True """ a00 = self._new() @@ -399,9 +400,9 @@ cdef class ComplexIntervalFieldElement(FieldElement): True sage: CIF(-5, 0).sqrt().is_exact() False - sage: CIF(0, 2*pi).is_exact() + sage: CIF(0, 2*pi).is_exact() # needs sage.symbolic False - sage: CIF(e).is_exact() + sage: CIF(e).is_exact() # needs sage.symbolic False sage: CIF(1e100).is_exact() True @@ -985,7 +986,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): Here a conversion to Maxima happens, which results in a ``TypeError``:: sage: a = CIF(2.3) - sage: maxima(a) + sage: maxima(a) # needs sage.symbolic Traceback (most recent call last): ... TypeError @@ -999,7 +1000,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): EXAMPLES:: - sage: sage_input(CIF(RIF(e, pi), RIF(sqrt(2), sqrt(3))), verify=True) + sage: sage_input(CIF(RIF(e, pi), RIF(sqrt(2), sqrt(3))), verify=True) # needs sage.symbolic # Verified CIF(RIF(RR(2.7182818284590451), RR(3.1415926535897936)), RIF(RR(1.4142135623730949), RR(1.7320508075688774))) sage: sage_input(ComplexIntervalField(64)(2)^I, preparse=False, verify=True) @@ -1997,7 +1998,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): sage: CIF(2, 1).is_NaN() False - sage: CIF(NaN).is_NaN() + sage: CIF(NaN).is_NaN() # needs sage.symbolic True sage: (1 / CIF(0, 0)).is_NaN() True @@ -2019,7 +2020,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): Check that :trac:`17285` is fixed:: - sage: CIF(cos(2/3)) + sage: CIF(cos(2/3)) # needs sage.symbolic 0.7858872607769480? ALGORITHM: @@ -2061,7 +2062,7 @@ cdef class ComplexIntervalFieldElement(FieldElement): Check that :trac:`17825` is fixed:: - sage: CIF(sin(2/3)) + sage: CIF(sin(2/3)) # needs sage.symbolic 0.618369803069737? ALGORITHM: diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index 7cbf5d60929..2d1aef3160d 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -304,7 +304,7 @@ def _magma_init_(self, magma): sage: magma(ComplexIntervalField(100)) # optional - magma # indirect doctest Complex field of precision 30 - sage: floor(RR(log(2**100, 10))) + sage: floor(RR(log(2**100, 10))) # needs sage.symbolic 30 """ return "ComplexField(%s : Bits := true)" % self.prec() @@ -445,7 +445,7 @@ def __call__(self, x=None, im=None, **kwds): TypeError: unable to convert '1+I' to real interval sage: CIF(2,3) 2 + 3*I - sage: CIF(pi, e) + sage: CIF(pi, e) # needs sage.symbolic 3.141592653589794? + 2.718281828459046?*I sage: ComplexIntervalField(100)(CIF(RIF(2,3))) 3.? diff --git a/src/sage/rings/complex_mpc.pyx b/src/sage/rings/complex_mpc.pyx index b3681ff724f..477fc0fbccf 100644 --- a/src/sage/rings/complex_mpc.pyx +++ b/src/sage/rings/complex_mpc.pyx @@ -1195,27 +1195,27 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): sage: MPC = MPComplexField() sage: a = MPC(2,1) - sage: a.__pari__() + sage: a.__pari__() # needs sage.libs.pari 2.00000000000000 + 1.00000000000000*I - sage: pari(a) + sage: pari(a) # needs sage.libs.pari 2.00000000000000 + 1.00000000000000*I - sage: pari(a).type() + sage: pari(a).type() # needs sage.libs.pari 't_COMPLEX' - sage: a = MPC(pi) - sage: pari(a) + sage: a = MPC(pi) # needs sage.libs.pari sage.symbolic + sage: pari(a) # needs sage.libs.pari sage.symbolic 3.14159265358979 - sage: pari(a).type() + sage: pari(a).type() # needs sage.libs.pari sage.symbolic 't_REAL' sage: a = MPC(-2).sqrt() - sage: pari(a) + sage: pari(a) # needs sage.libs.pari 1.41421356237310*I The precision is preserved, rounded up to the wordsize:: sage: MPC = MPComplexField(250) - sage: MPC(1,2).__pari__().bitprecision() + sage: MPC(1,2).__pari__().bitprecision() # needs sage.libs.pari 256 - sage: MPC(pi).__pari__().bitprecision() + sage: MPC(pi).__pari__().bitprecision() # needs sage.libs.pari 256 """ if mpfr_zero_p(self.value.re): @@ -1520,7 +1520,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): 2.23606797749979 sage: a.__abs__() 2.23606797749979 - sage: float(sqrt(2^2 + 1^1)) + sage: float(sqrt(2^2 + 1^1)) # needs sage.symbolic 2.23606797749979 sage: b = MPC(42,0) @@ -2212,7 +2212,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): sage: a = MPC(1,0) sage: a.dilog() 1.64493406684823 - sage: float(pi^2/6) + sage: float(pi^2/6) # needs sage.symbolic 1.6449340668482262 :: diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 64e3fe9cf3c..8ab4706ff1a 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -493,9 +493,9 @@ class ComplexField_class(sage.rings.abc.ComplexField): Check that :trac:`14989` is fixed:: sage: x = polygen(ZZ, 'x') - sage: QQi = NumberField(x^2 + 1, 'i', embedding=CC(0,1)) # optional - sage.rings.number_field - sage: i = QQi.order(QQi.gen()).gen(1) # optional - sage.rings.number_field - sage: CC(i) # optional - sage.rings.number_field + sage: QQi = NumberField(x^2 + 1, 'i', embedding=CC(0,1)) # needs sage.rings.number_field + sage: i = QQi.order(QQi.gen()).gen(1) # needs sage.rings.number_field + sage: CC(i) # needs sage.rings.number_field 1.00000000000000*I TESTS:: @@ -715,8 +715,8 @@ class ComplexField_class(sage.rings.abc.ComplexField): sage: re, im = CC6.random_element(2^-20) sage: -2^-20 <= re <= 2^-20, -2^-20 <= im <= 2^-20 (True, True) - sage: re, im = CC6.random_element(pi^20) - sage: bool(-pi^20 <= re <= pi^20), bool(-pi^20 <= im <= pi^20) + sage: re, im = CC6.random_element(pi^20) # needs sage.symbolic + sage: bool(-pi^20 <= re <= pi^20), bool(-pi^20 <= im <= pi^20) # needs sage.symbolic (True, True) Passes extra positional or keyword arguments through:: @@ -849,17 +849,17 @@ class ComplexField_class(sage.rings.abc.ComplexField): sage: k = ComplexField(100) sage: R. = k[] - sage: k._factor_univariate_polynomial( x ) # optional - sage.libs.pari + sage: k._factor_univariate_polynomial( x ) # needs sage.libs.pari x - sage: k._factor_univariate_polynomial( 2*x ) # optional - sage.libs.pari + sage: k._factor_univariate_polynomial( 2*x ) # needs sage.libs.pari (2.0000000000000000000000000000) * x - sage: k._factor_univariate_polynomial( x^2 ) # optional - sage.libs.pari + sage: k._factor_univariate_polynomial( x^2 ) # needs sage.libs.pari x^2 - sage: k._factor_univariate_polynomial( x^2 + 3 ) # optional - sage.libs.pari + sage: k._factor_univariate_polynomial( x^2 + 3 ) # needs sage.libs.pari (x - 1.7320508075688772935274463415*I) * (x + 1.7320508075688772935274463415*I) - sage: k._factor_univariate_polynomial( x^2 + 1 ) # optional - sage.libs.pari + sage: k._factor_univariate_polynomial( x^2 + 1 ) # needs sage.libs.pari (x - I) * (x + I) - sage: k._factor_univariate_polynomial( k(I) * (x^2 + 1) ) # optional - sage.libs.pari + sage: k._factor_univariate_polynomial( k(I) * (x^2 + 1) ) # needs sage.libs.pari (1.0000000000000000000000000000*I) * (x - I) * (x + I) """ @@ -1038,10 +1038,10 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.array([1.0, 2.5j]).dtype # optional - numpy + sage: import numpy # needs numpy + sage: numpy.array([1.0, 2.5j]).dtype # needs numpy dtype('complex128') - sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # optional - numpy + sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # needs numpy dtype('O') """ if self._prec <= 53: @@ -1265,19 +1265,19 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: a = CC(pi + I*e); a # optional - sage.symbolic + sage: a = CC(pi + I*e); a # needs sage.symbolic 3.14159265358979 + 2.71828182845905*I - sage: a.str(truncate=True) # optional - sage.symbolic + sage: a.str(truncate=True) # needs sage.symbolic '3.14159265358979 + 2.71828182845905*I' - sage: a.str() # optional - sage.symbolic + sage: a.str() # needs sage.symbolic '3.1415926535897931 + 2.7182818284590451*I' - sage: a.str(base=2) # optional - sage.symbolic + sage: a.str(base=2) # needs sage.symbolic '11.001001000011111101101010100010001000010110100011000 + 10.101101111110000101010001011000101000101011101101001*I' - sage: CC(0.5 + 0.625*I).str(base=2) # optional - sage.symbolic + sage: CC(0.5 + 0.625*I).str(base=2) # needs sage.symbolic '0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I' - sage: a.str(base=16) # optional - sage.symbolic + sage: a.str(base=16) # needs sage.symbolic '3.243f6a8885a30 + 2.b7e151628aed2*I' - sage: a.str(base=36) # optional - sage.symbolic + sage: a.str(base=36) # needs sage.symbolic '3.53i5ab8p5fc + 2.puw5nggjf8f*I' sage: CC(0) 0.000000000000000 @@ -1390,23 +1390,23 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): Coerce the object using the ``pari`` function:: sage: a = ComplexNumber(2,1) - sage: pari(a) # optional - sage.libs.pari + sage: pari(a) # needs sage.libs.pari 2.00000000000000 + 1.00000000000000*I - sage: pari(a).type() # optional - sage.libs.pari + sage: pari(a).type() # needs sage.libs.pari 't_COMPLEX' - sage: type(pari(a)) # optional - sage.libs.pari + sage: type(pari(a)) # needs sage.libs.pari - sage: a.__pari__() # optional - sage.libs.pari + sage: a.__pari__() # needs sage.libs.pari 2.00000000000000 + 1.00000000000000*I - sage: type(a.__pari__()) # optional - sage.libs.pari + sage: type(a.__pari__()) # needs sage.libs.pari - sage: a = CC(pi) # optional - sage.symbolic - sage: pari(a) # optional - sage.libs.pari sage.symbolic + sage: a = CC(pi) # needs sage.symbolic + sage: pari(a) # needs sage.libs.pari sage.symbolic 3.14159265358979 - sage: pari(a).type() # optional - sage.libs.pari sage.symbolic + sage: pari(a).type() # needs sage.libs.pari sage.symbolic 't_REAL' sage: a = CC(-2).sqrt() - sage: pari(a) # optional - sage.libs.pari + sage: pari(a) # needs sage.libs.pari 1.41421356237310*I """ if self.is_real(): @@ -1473,11 +1473,11 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: CC(1, 0)._sympy_() # optional - sympy + sage: CC(1, 0)._sympy_() # needs sympy 1.00000000000000 - sage: CC(1/3, 1)._sympy_() # optional - sympy + sage: CC(1/3, 1)._sympy_() # needs sympy 0.333333333333333 + 1.0*I - sage: type(_) # optional - sympy + sage: type(_) # needs sympy """ import sympy @@ -1879,7 +1879,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): 2.23606797749979 sage: a.__abs__() 2.23606797749979 - sage: float(sqrt(2^2 + 1^1)) + sage: float(sqrt(2^2 + 1^1)) # needs sage.symbolic 2.23606797749979 :: @@ -2089,13 +2089,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): You can either use the indirect:: sage: z = CC(0,1) - sage: plot(z) # optional - sage.plot + sage: plot(z) # needs sage.plot Graphics object consisting of 1 graphics primitive or the more direct:: sage: z = CC(0,1) - sage: z.plot() # optional - sage.plot + sage: z.plot() # needs sage.plot Graphics object consisting of 1 graphics primitive """ return sage.plot.point.point2d((self.real(), self.imag()), **kargs) @@ -2111,7 +2111,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arccos() # optional - sage.libs.pari + sage: (1+CC(I)).arccos() # needs sage.libs.pari 0.904556894302381 - 1.06127506190504*I """ return self._parent(self.__pari__().acos()) @@ -2122,7 +2122,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arccosh() # optional - sage.libs.pari + sage: (1+CC(I)).arccosh() # needs sage.libs.pari 1.06127506190504 + 0.904556894302381*I """ return self._parent(self.__pari__().acosh()) @@ -2133,7 +2133,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arcsin() # optional - sage.libs.pari + sage: (1+CC(I)).arcsin() # needs sage.libs.pari 0.666239432492515 + 1.06127506190504*I """ return self._parent(self.__pari__().asin()) @@ -2144,7 +2144,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arcsinh() # optional - sage.libs.pari + sage: (1+CC(I)).arcsinh() # needs sage.libs.pari 1.06127506190504 + 0.666239432492515*I """ return self._parent(self.__pari__().asinh()) @@ -2155,7 +2155,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arctan() # optional - sage.libs.pari + sage: (1+CC(I)).arctan() # needs sage.libs.pari 1.01722196789785 + 0.402359478108525*I """ return self._parent(self.__pari__().atan()) @@ -2166,7 +2166,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arctanh() # optional - sage.libs.pari + sage: (1+CC(I)).arctanh() # needs sage.libs.pari 0.402359478108525 + 1.01722196789785*I """ return self._parent(self.__pari__().atanh()) @@ -2177,7 +2177,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).coth() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).coth() # needs sage.libs.pari 0.86801414289592494863584920892 - 0.21762156185440268136513424361*I """ return ~(self.tanh()) @@ -2188,7 +2188,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arccoth() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).arccoth() # needs sage.libs.pari 0.40235947810852509365018983331 - 0.55357435889704525150853273009*I """ return (~self).arctanh() @@ -2199,7 +2199,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).csc() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).csc() # needs sage.libs.pari 0.62151801717042842123490780586 - 0.30393100162842645033448560451*I """ return ~(self.sin()) @@ -2210,7 +2210,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).csch() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).csch() # needs sage.libs.pari 0.30393100162842645033448560451 - 0.62151801717042842123490780586*I """ return ~(self.sinh()) @@ -2221,7 +2221,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arccsch() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).arccsch() # needs sage.libs.pari 0.53063753095251782601650945811 - 0.45227844715119068206365839783*I """ return (~self).arcsinh() @@ -2232,7 +2232,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).sec() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).sec() # needs sage.libs.pari 0.49833703055518678521380589177 + 0.59108384172104504805039169297*I """ return ~(self.cos()) @@ -2243,7 +2243,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).sech() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).sech() # needs sage.libs.pari 0.49833703055518678521380589177 - 0.59108384172104504805039169297*I """ return ~(self.cosh()) @@ -2254,7 +2254,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arcsech() # optional - sage.libs.pari + sage: ComplexField(100)(1,1).arcsech() # needs sage.libs.pari 0.53063753095251782601650945811 - 1.1185178796437059371676632938*I """ return (~self).arccosh() @@ -2265,13 +2265,14 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).cot() # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: (1+CC(I)).cot() 0.217621561854403 - 0.868014142895925*I - sage: i = ComplexField(200).0 # optional - sage.libs.pari - sage: (1+i).cot() # optional - sage.libs.pari + sage: i = ComplexField(200).0 + sage: (1+i).cot() 0.21762156185440268136513424360523807352075436916785404091068 - 0.86801414289592494863584920891627388827343874994609327121115*I - sage: i = ComplexField(220).0 # optional - sage.libs.pari - sage: (1+i).cot() # optional - sage.libs.pari + sage: i = ComplexField(220).0 + sage: (1+i).cot() 0.21762156185440268136513424360523807352075436916785404091068124239 - 0.86801414289592494863584920891627388827343874994609327121115071646*I TESTS: @@ -2371,35 +2372,35 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): First we compute `\eta(1+i)`:: sage: i = CC.0 - sage: z = 1 + i; z.eta() # optional - sage.libs.pari + sage: z = 1 + i; z.eta() # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I We compute eta to low precision directly from the definition:: - sage: pi = CC(pi) # otherwise we will get a symbolic result. # optional - sage.symbolic - sage: exp(pi * i * z / 12) * prod(1 - exp(2*pi*i*n*z) # optional - sage.symbolic + sage: pi = CC(pi) # otherwise we will get a symbolic result. # needs sage.symbolic + sage: exp(pi * i * z / 12) * prod(1 - exp(2*pi*i*n*z) # needs sage.libs.pari sage.symbolic ....: for n in range(1,10)) 0.742048775836565 + 0.198831370229911*I The optional argument allows us to omit the fractional part:: - sage: z.eta(omit_frac=True) # optional - sage.libs.pari + sage: z.eta(omit_frac=True) # needs sage.libs.pari 0.998129069925959 - sage: prod(1 - exp(2*pi*i*n*z) for n in range(1,10)) # optional - sage.symbolic + sage: prod(1 - exp(2*pi*i*n*z) for n in range(1,10)) # needs sage.libs.pari sage.symbolic 0.998129069925958 + 4.59099857829247e-19*I We illustrate what happens when `z` is not in the upper half plane:: sage: z = CC(1) - sage: z.eta() # optional - sage.libs.pari + sage: z.eta() # needs sage.libs.pari Traceback (most recent call last): ... ValueError: value must be in the upper half plane You can also use functional notation:: - sage: eta(1 + CC(I)) # optional - sage.libs.pari + sage: eta(1 + CC(I)) # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I """ try: @@ -2584,7 +2585,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): 1.62780548487271 + 0.136827548397369*I sage: a.agm(b, algorithm="principal") 1.62780548487271 + 0.136827548397369*I - sage: a.agm(b, algorithm="pari") # optional - sage.libs.pari + sage: a.agm(b, algorithm="pari") # needs sage.libs.pari 1.62780548487271 + 0.136827548397369*I An example to show that the returned value depends on the algorithm @@ -2596,13 +2597,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): -0.371591652351761 + 0.319894660206830*I sage: a.agm(b, algorithm="principal") 0.338175462986180 - 0.0135326969565405*I - sage: a.agm(b, algorithm="pari") # optional - sage.libs.pari + sage: a.agm(b, algorithm="pari") # needs sage.libs.pari -0.371591652351761 + 0.319894660206830*I sage: a.agm(b, algorithm="optimal").abs() 0.490319232466314 sage: a.agm(b, algorithm="principal").abs() 0.338446122230459 - sage: a.agm(b, algorithm="pari").abs() # optional - sage.libs.pari + sage: a.agm(b, algorithm="pari").abs() # needs sage.libs.pari 0.490319232466314 TESTS: @@ -2819,21 +2820,21 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: a = ComplexNumber(1,0) - sage: a.dilog() # optional - sage.libs.pari + sage: a.dilog() # needs sage.libs.pari 1.64493406684823 - sage: float(pi^2/6) # optional - sage.symbolic + sage: float(pi^2/6) # needs sage.symbolic 1.6449340668482262 :: sage: b = ComplexNumber(0,1) - sage: b.dilog() # optional - sage.libs.pari + sage: b.dilog() # needs sage.libs.pari -0.205616758356028 + 0.915965594177219*I :: sage: c = ComplexNumber(0,0) - sage: c.dilog() # optional - sage.libs.pari + sage: c.dilog() # needs sage.libs.pari 0.000000000000000 """ return self._parent(self.__pari__().dilog()) @@ -2869,17 +2870,17 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: i = ComplexField(30).0 - sage: (1 + i).gamma() # optional - sage.libs.pari + sage: (1 + i).gamma() # needs sage.libs.pari 0.49801567 - 0.15494983*I TESTS:: - sage: CC(0).gamma() # optional - sage.libs.pari + sage: CC(0).gamma() # needs sage.libs.pari Infinity :: - sage: CC(-1).gamma() # optional - sage.libs.pari + sage: CC(-1).gamma() # needs sage.libs.pari Infinity """ try: @@ -2896,13 +2897,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: C, i = ComplexField(30).objgen() - sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 # optional - sage.libs.pari + sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 # needs sage.libs.pari 0.0020969149 - 0.059981914*I - sage: (1+i).gamma_inc(5) # optional - sage.libs.pari + sage: (1+i).gamma_inc(5) # needs sage.libs.pari -0.0013781309 + 0.0065198200*I - sage: C(2).gamma_inc(1 + i) # optional - sage.libs.pari + sage: C(2).gamma_inc(1 + i) # needs sage.libs.pari 0.70709210 - 0.42035364*I - sage: CC(2).gamma_inc(5) # optional - sage.libs.pari + sage: CC(2).gamma_inc(5) # needs sage.libs.pari 0.0404276819945128 TESTS: @@ -2910,7 +2911,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): Check that :trac:`7099` is fixed:: sage: C = ComplexField(400) - sage: C(2 + I).gamma_inc(C(3 + I)) # abs tol 1e-120 # optional - sage.libs.pari + sage: C(2 + I).gamma_inc(C(3 + I)) # abs tol 1e-120 # needs sage.libs.pari 0.121515644664508695525971545977439666159749344176962379708992904126499444842886620664991650378432544392118359044438541515 + 0.101533909079826033296475736021224621546966200987295663190553587086145836461236284668967411665020429964946098113930918850*I """ @@ -3244,9 +3245,9 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: i = ComplexField(30).gen() sage: z = 1 + i - sage: z.zeta() # optional - sage.libs.pari + sage: z.zeta() # needs sage.libs.pari 0.58215806 - 0.92684856*I - sage: zeta(z) # optional - sage.libs.pari + sage: zeta(z) # needs sage.libs.pari 0.58215806 - 0.92684856*I sage: CC(1).zeta() diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index 696a99753bb..c25a89cfd90 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -67,14 +67,14 @@ sage: 0 + 1/(2 + 1/22) 22/45 - sage: continued_fraction(pi) + sage: continued_fraction(pi) # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] - sage: continued_fraction_list(pi, nterms=5) + sage: continued_fraction_list(pi, nterms=5) # needs sage.symbolic [3, 7, 15, 1, 292] sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^3 - 5, embedding=1.709) # optional - sage.rings.number_field - sage: continued_fraction(cbrt5) # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 5, embedding=1.709) # needs sage.rings.number_field + sage: continued_fraction(cbrt5) # needs sage.rings.number_field [1; 1, 2, 2, 4, 3, 3, 1, 5, 1, 1, 4, 10, 17, 1, 14, 1, 1, 3052, 1, ...] It is also possible to create a continued fraction from a list of partial @@ -85,10 +85,9 @@ Even infinite:: - sage: w = words.ThueMorseWord([1,2]) - sage: w + sage: w = words.ThueMorseWord([1,2]); w # needs sage.combinat word: 1221211221121221211212211221211221121221... - sage: continued_fraction(w) + sage: continued_fraction(w) # needs sage.combinat [1; 2, 2, 1, 2, 1, 1, 2, 2, 1...] To go back and forth between the value (as a real number) and the partial @@ -101,18 +100,18 @@ sage: cf.value() 13/27 - sage: cf = continued_fraction(pi) - sage: cf.quotients() + sage: cf = continued_fraction(pi) # needs sage.symbolic + sage: cf.quotients() # needs sage.symbolic lazy list [3, 7, 15, ...] - sage: cf.value() + sage: cf.value() # needs sage.symbolic pi + sage: # needs sage.combinat sage: w = words.FibonacciWord([1,2]) sage: cf = continued_fraction(w) sage: cf.quotients() word: 1211212112112121121211211212112112121121... - sage: v = cf.value() - sage: v + sage: v = cf.value(); v 1.387954587967143? sage: v.n(digits=100) 1.387954587967142336919313859873185477878152452498532271894917289826418577622648932169885237034242967 @@ -122,6 +121,7 @@ Recall that quadratic numbers correspond to ultimately periodic continued fractions. For them special methods give access to preperiod and period:: + sage: # needs sage.rings.number_field sage: K. = QuadraticField(2) sage: cf = continued_fraction(sqrt2); cf [1; (2)*] @@ -132,18 +132,18 @@ sage: cf.period() (2,) - sage: cf = (3*sqrt2 + 1/2).continued_fraction(); cf + sage: cf = (3*sqrt2 + 1/2).continued_fraction(); cf # needs sage.rings.number_field [4; (1, 2, 1, 7)*] sage: cf = continued_fraction([(1,2,3),(1,4)]); cf [1; 2, 3, (1, 4)*] - sage: cf.value() + sage: cf.value() # needs sage.rings.number_field -2/23*sqrt2 + 36/23 On the following we can remark how the tail may change even in the same quadratic field:: - sage: for i in range(20): print(continued_fraction(i*sqrt2)) + sage: for i in range(20): print(continued_fraction(i*sqrt2)) # needs sage.rings.number_field [0] [1; (2)*] [2; (1, 4)*] @@ -157,6 +157,7 @@ Nevertheless, the tail is preserved under invertible integer homographies:: + sage: # needs sage.rings.number_field sage: apply_homography = lambda m,z: (m[0,0]*z + m[0,1]) / (m[1,0]*z + m[1,1]) sage: m1 = SL2Z([60,13,83,18]) sage: m2 = SL2Z([27,80,28,83]) @@ -361,7 +362,7 @@ def str(self, nterms=10, unicode=False, join=True): EXAMPLES:: - sage: print(continued_fraction(pi).str()) + sage: print(continued_fraction(pi).str()) # needs sage.symbolic 1 3 + ---------------------------------------------------- 1 @@ -381,9 +382,9 @@ def str(self, nterms=10, unicode=False, join=True): 1 2 + --------- 1 + ... - sage: print(continued_fraction(pi).str(nterms=1)) + sage: print(continued_fraction(pi).str(nterms=1)) # needs sage.symbolic 3 + ... - sage: print(continued_fraction(pi).str(nterms=2)) + sage: print(continued_fraction(pi).str(nterms=2)) # needs sage.symbolic 1 3 + --------- 7 + ... @@ -505,8 +506,8 @@ def _latex_(self, nterms=10): r""" EXAMPLES:: - sage: cf_pi = continued_fraction(pi) - sage: latex(cf_pi) + sage: cf_pi = continued_fraction(pi) # needs sage.symbolic + sage: latex(cf_pi) # needs sage.symbolic 3 + \frac{\displaystyle 1}{\displaystyle 7 + \frac{\displaystyle 1}{\displaystyle 15 @@ -518,7 +519,7 @@ def _latex_(self, nterms=10): + \frac{\displaystyle 1}{\displaystyle 2 + \frac{\displaystyle 1}{\displaystyle 1 + \frac{\displaystyle 1}{\displaystyle \dots}}}}}}}}}} - sage: print(cf_pi._latex_(nterms=3)) + sage: print(cf_pi._latex_(nterms=3)) # needs sage.symbolic 3 + \frac{\displaystyle 1}{\displaystyle 7 + \frac{\displaystyle 1}{\displaystyle 15 @@ -594,18 +595,19 @@ def _mpfr_(self, R): EXAMPLES:: - sage: continued_fraction(1/2).n() + sage: continued_fraction(1/2).n() # needs sage.rings.real_mpfr 0.500000000000000 - sage: continued_fraction([0,4]).n() + sage: continued_fraction([0,4]).n() # needs sage.rings.real_mpfr 0.250000000000000 - sage: continued_fraction([12,1,3,4,2,2,3,1,2]).n(digits=4) + sage: continued_fraction([12,1,3,4,2,2,3,1,2]).n(digits=4) # needs sage.rings.real_mpfr 12.76 - sage: continued_fraction(12/7).n(digits=13) == (12/7).n(digits=13) + sage: continued_fraction(12/7).n(digits=13) == (12/7).n(digits=13) # needs sage.rings.real_mpfr True - sage: continued_fraction(-14/333).n(digits=21) == (-14/333).n(digits=21) + sage: continued_fraction(-14/333).n(digits=21) == (-14/333).n(digits=21) # needs sage.rings.real_mpfr True + sage: # needs sage.symbolic sage: a = (106*pi - 333) / (355 - 113*pi) - 292 sage: cf = continued_fraction(a); cf [0; 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, 1, 84, 2, 1, ...] @@ -623,23 +625,23 @@ def _mpfr_(self, R): 0.63459101 sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^3 - 2, 'a', embedding=1.25) # optional - sage.rings.number_field - sage: b = 504/253*a^2 + 635/253*a + 661/253 # optional - sage.rings.number_field - sage: cf = continued_fraction(b); cf # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 2, 'a', embedding=1.25) # needs sage.rings.number_field + sage: b = 504/253*a^2 + 635/253*a + 661/253 # needs sage.rings.number_field + sage: cf = continued_fraction(b); cf # needs sage.rings.number_field [8; 1, 14, 1, 10, 2, 1, 4, 12, 2, 3, 2, 1, 3, 4, 1, 1, 2, 14, 3, ...] - sage: cf.n(digits=3) + sage: cf.n(digits=3) # needs sage.rings.number_field 8.94 - sage: cf.n(digits=6) + sage: cf.n(digits=6) # needs sage.rings.number_field 8.93715 - sage: cf.n(digits=7) + sage: cf.n(digits=7) # needs sage.rings.number_field 8.937154 - sage: cf.n(digits=8) + sage: cf.n(digits=8) # needs sage.rings.number_field 8.9371541 - sage: cf.n(digits=9) + sage: cf.n(digits=9) # needs sage.rings.number_field 8.93715414 - sage: cf.n(digits=10) + sage: cf.n(digits=10) # needs sage.rings.number_field 8.937154138 - sage: cf.n(digits=11) + sage: cf.n(digits=11) # needs sage.rings.number_field 8.9371541378 TESTS: @@ -648,7 +650,7 @@ def _mpfr_(self, R): rational case):: sage: fields = [] - sage: for prec in [17, 24, 53, 128, 256]: + sage: for prec in [17, 24, 53, 128, 256]: # needs sage.rings.real_mpfr ....: for rnd in ['RNDN', 'RNDD', 'RNDU', 'RNDZ', 'RNDA']: ....: fields.append(RealField(prec=prec, rnd=rnd)) sage: for n in range(3000): # long time, not tested, known bug (see :trac:`29957`) @@ -745,7 +747,7 @@ def __float__(self): sage: a = continued_fraction(-17/389); a [-1; 1, 21, 1, 7, 2] - sage: float(a) + sage: float(a) # needs sage.rings.real_mpfr -0.043701799485861184 sage: float(-17/389) -0.043701799485861184 @@ -759,6 +761,7 @@ def numerator(self, n): EXAMPLES:: + sage: # needs sage.symbolic sage: c = continued_fraction(pi); c [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] sage: c.numerator(0) @@ -793,6 +796,7 @@ def denominator(self, n): EXAMPLES:: + sage: # needs sage.symbolic sage: c = continued_fraction(pi); c [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] sage: c.denominator(0) @@ -815,11 +819,11 @@ def convergent(self, n): EXAMPLES:: - sage: a = continued_fraction(pi); a + sage: a = continued_fraction(pi); a # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] - sage: a.convergent(3) + sage: a.convergent(3) # needs sage.symbolic 355/113 - sage: a.convergent(15) + sage: a.convergent(15) # needs sage.symbolic 411557987/131002976 """ return self.numerator(n) / self.denominator(n) @@ -883,15 +887,15 @@ def __getitem__(self, n): TESTS:: - sage: cf1 = continued_fraction(pi); cf1 + sage: cf1 = continued_fraction(pi); cf1 # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] - sage: cf2 = continued_fraction(QuadraticField(2).gen()); cf2 + sage: cf2 = continued_fraction(QuadraticField(2).gen()); cf2 # needs sage.rings.number_field [1; (2)*] sage: cf3 = continued_fraction(4/17); cf3 [0; 4, 4] - sage: cf1[3:17] + sage: cf1[3:17] # needs sage.symbolic [1; 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2] - sage: cf2[:10] + sage: cf2[:10] # needs sage.rings.number_field [1; 2, 2, 2, 2, 2, 2, 2, 2, 2] sage: cf3[1:16] [4; 4] @@ -899,7 +903,7 @@ def __getitem__(self, n): Be careful that the truncation of an infinite continued fraction might be shorter by one:: - sage: len(continued_fraction(golden_ratio)[:8]) + sage: len(continued_fraction(golden_ratio)[:8]) # needs sage.symbolic 7 """ if isinstance(n, slice): @@ -926,6 +930,7 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.symbolic sage: cf = continued_fraction(pi) sage: i = iter(cf) sage: [next(i) for _ in range(10)] @@ -964,7 +969,7 @@ def sign(self): EXAMPLES:: - sage: continued_fraction(tan(pi/7)).sign() + sage: continued_fraction(tan(pi/7)).sign() # needs sage.symbolic 1 sage: continued_fraction(-34/2115).sign() -1 @@ -1032,7 +1037,7 @@ def is_zero(self): False sage: continued_fraction(-1/2).is_zero() False - sage: continued_fraction(pi).is_zero() + sage: continued_fraction(pi).is_zero() # needs sage.symbolic False """ return self.quotient(0) == ZZ_0 and self.quotient(1) is Infinity @@ -1049,7 +1054,7 @@ def is_one(self): False sage: continued_fraction(0).is_one() False - sage: continued_fraction(pi).is_one() + sage: continued_fraction(pi).is_one() # needs sage.symbolic False """ return self.quotient(0) == ZZ_1 and self.quotient(1) is Infinity @@ -1098,7 +1103,7 @@ def multiplicative_order(self): 2 sage: continued_fraction(1).multiplicative_order() 1 - sage: continued_fraction(pi).multiplicative_order() + sage: continued_fraction(pi).multiplicative_order() # needs sage.symbolic +Infinity """ if self.is_zero(): @@ -1128,18 +1133,17 @@ def numerical_approx(self, prec=None, digits=None, algorithm=None): EXAMPLES:: - sage: w = words.FibonacciWord([1,3]) - sage: cf = continued_fraction(w) - sage: cf + sage: w = words.FibonacciWord([1,3]) # needs sage.combinat + sage: cf = continued_fraction(w); cf # needs sage.combinat [1; 3, 1, 1, 3, 1, 3, 1, 1, 3, 1, 1, 3, 1, 3, 1, 1, 3, 1, 3...] - sage: cf.numerical_approx(prec=53) + sage: cf.numerical_approx(prec=53) # needs sage.combinat 1.28102513329557 The method `n` is a shortcut to this one:: - sage: cf.n(digits=25) + sage: cf.n(digits=25) # needs sage.combinat 1.281025133295569815552930 - sage: cf.n(digits=33) + sage: cf.n(digits=33) # needs sage.combinat 1.28102513329556981555293038097590 """ from sage.arith.numerical_approx import (digits_to_bits, @@ -1174,22 +1178,20 @@ def apply_homography(self, a, b, c, d, forward_value=False): We demonstrate now the effect of the optional argument ``forward_value``:: - sage: cf = continued_fraction(pi) - sage: h1 = cf.apply_homography(35, -27, 12, -5) - sage: h1 + sage: cf = continued_fraction(pi) # needs sage.symbolic + sage: h1 = cf.apply_homography(35, -27, 12, -5); h1 # needs sage.symbolic [2; 1, 1, 6, 3, 1, 2, 1, 5, 3, 1, 1, 1, 1, 9, 12, 1, 1, 1, 3...] - sage: h1.value() + sage: h1.value() # needs sage.symbolic 2.536941776086946? - sage: h2 = cf.apply_homography(35, -27, 12, -5, forward_value=True) - sage: h2 + sage: h2 = cf.apply_homography(35, -27, 12, -5, forward_value=True); h2 # needs sage.symbolic [2; 1, 1, 6, 3, 1, 2, 1, 5, 3, 1, 1, 1, 1, 9, 12, 1, 1, 1, 3...] - sage: h2.value() + sage: h2.value() # needs sage.symbolic (35*pi - 27)/(12*pi - 5) TESTS:: - sage: CF = [continued_fraction(x) for x in [sqrt(2), AA(3).sqrt(), + sage: CF = [continued_fraction(x) for x in [sqrt(2), AA(3).sqrt(), # needs sage.rings.number_field sage.symbolic ....: AA(3)**(1/3), QuadraticField(37).gen(), pi, 113/27, ....: [3,1,2,2], words.FibonacciWord([1,3])]] sage: for _ in range(100): # not tested, known bug (see :trac:`32086`) @@ -1211,7 +1213,7 @@ def apply_homography(self, a, b, c, d, forward_value=False): ... ValueError: continued fraction can not represent infinity - sage: continued_fraction(pi).apply_homography(0, 1, 0, 0) + sage: continued_fraction(pi).apply_homography(0, 1, 0, 0) # needs sage.symbolic Traceback (most recent call last): ... ZeroDivisionError: division by zero @@ -1262,9 +1264,9 @@ def __neg__(self): EXAMPLES:: - sage: -continued_fraction(e) + sage: -continued_fraction(e) # needs sage.symbolic [-3; 3, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1, 14...] - sage: -continued_fraction(sqrt(7)) + sage: -continued_fraction(sqrt(7)) # needs sage.symbolic [-3; 2, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4...] """ return self.apply_homography(-1, 0, 0, 1) @@ -1275,9 +1277,9 @@ def __invert__(self): EXAMPLES:: - sage: ~continued_fraction(e) + sage: ~continued_fraction(e) # needs sage.symbolic [0; 2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1...] - sage: ~continued_fraction(sqrt(7)) + sage: ~continued_fraction(sqrt(7)) # needs sage.symbolic [0; 2, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1, 4, 1, 1...] """ return self.apply_homography(0, 1, 1, 0) @@ -1327,13 +1329,13 @@ def period(self): EXAMPLES:: - sage: K. = QuadraticField(3) - sage: cf = continued_fraction(sqrt3); cf + sage: K. = QuadraticField(3) # needs sage.rings.number_field + sage: cf = continued_fraction(sqrt3); cf # needs sage.rings.number_field [1; (1, 2)*] - sage: cf.period() + sage: cf.period() # needs sage.rings.number_field (1, 2) - sage: for k in xsrange(2,40): + sage: for k in xsrange(2,40): # needs sage.rings.number_field ....: if not k.is_square(): ....: s = QuadraticField(k).gen() ....: cf = continued_fraction(s) @@ -1365,15 +1367,15 @@ def preperiod(self): EXAMPLES:: - sage: K. = QuadraticField(3) - sage: cf = continued_fraction(sqrt3); cf + sage: K. = QuadraticField(3) # needs sage.rings.number_field + sage: cf = continued_fraction(sqrt3); cf # needs sage.rings.number_field [1; (1, 2)*] - sage: cf.preperiod() + sage: cf.preperiod() # needs sage.rings.number_field (1,) - sage: cf = continued_fraction(sqrt3/7); cf + sage: cf = continued_fraction(sqrt3/7); cf # needs sage.rings.number_field [0; 4, (24, 8)*] - sage: cf.preperiod() + sage: cf.preperiod() # needs sage.rings.number_field (0, 4) """ return self._x1 @@ -1448,6 +1450,7 @@ def __richcmp__(self, other, op): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: a = continued_fraction([(0,),(1,2,3,1,2,3,1)]); a.n() 0.694249167819459 sage: b = continued_fraction([(0,),(1,2,3)]); b.n() @@ -1492,49 +1495,49 @@ def value(self): sage: cf = continued_fraction([(),(2,)]); cf [(2)*] - sage: v = cf.value(); v + sage: v = cf.value(); v # needs sage.rings.number_field sqrt2 + 1 - sage: v.continued_fraction() + sage: v.continued_fraction() # needs sage.rings.number_field [(2)*] sage: cf = continued_fraction([(),(1,2)]); cf [(1, 2)*] - sage: v = cf.value(); v + sage: v = cf.value(); v # needs sage.rings.number_field 1/2*sqrt3 + 1/2 - sage: v.continued_fraction() + sage: v.continued_fraction() # needs sage.rings.number_field [(1, 2)*] The number ``sqrt3`` that appear above is actually internal to the continued fraction. In order to be access it from the console:: - sage: cf.value().parent().inject_variables() + sage: cf.value().parent().inject_variables() # needs sage.rings.number_field Defining sqrt3 - sage: sqrt3 + sage: sqrt3 # needs sage.rings.number_field sqrt3 - sage: ((sqrt3+1)/2).continued_fraction() + sage: ((sqrt3+1)/2).continued_fraction() # needs sage.rings.number_field [(1, 2)*] Some ultimately periodic but non periodic examples:: sage: cf = continued_fraction([(1,),(2,)]); cf [1; (2)*] - sage: v = cf.value(); v + sage: v = cf.value(); v # needs sage.rings.number_field sqrt2 - sage: v.continued_fraction() + sage: v.continued_fraction() # needs sage.rings.number_field [1; (2)*] sage: cf = continued_fraction([(1,3),(1,2)]); cf [1; 3, (1, 2)*] - sage: v = cf.value(); v + sage: v = cf.value(); v # needs sage.rings.number_field -sqrt3 + 3 - sage: v.continued_fraction() + sage: v.continued_fraction() # needs sage.rings.number_field [1; 3, (1, 2)*] sage: cf = continued_fraction([(-5,18), (1,3,1,5)]) - sage: cf.value().continued_fraction() == cf + sage: cf.value().continued_fraction() == cf # needs sage.rings.number_field True sage: cf = continued_fraction([(-1,),(1,)]) - sage: cf.value().continued_fraction() == cf + sage: cf.value().continued_fraction() == cf # needs sage.rings.number_field True TESTS:: @@ -1544,7 +1547,7 @@ def value(self): sage: a3 = ((1,),(1,2)) sage: a4 = ((-2,2),(1,124,13)) sage: a5 = ((0,),(1,)) - sage: for a in a1,a2,a3,a4,a5: + sage: for a in a1,a2,a3,a4,a5: # needs sage.rings.number_field ....: cf = continued_fraction(a) ....: assert cf.value().continued_fraction() == cf """ @@ -1575,10 +1578,10 @@ def _repr_(self): r""" TESTS:: - sage: a = continued_fraction(pi.n()); a + sage: a = continued_fraction(pi.n()); a # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3] - sage: a.rename('continued fraction of pi') - sage: a + sage: a.rename('continued fraction of pi') # needs sage.symbolic + sage: a # needs sage.symbolic continued fraction of pi sage: continued_fraction([(0,1),(2,)]) @@ -1656,10 +1659,10 @@ def _latex_(self): + \frac{\displaystyle 1}{\displaystyle 7 + \frac{\displaystyle 1}{\displaystyle 2 }}}}} - sage: K. = QuadraticField(1234) - sage: cf=continued_fraction(a); cf + sage: K. = QuadraticField(1234) # needs sage.rings.number_field + sage: cf = continued_fraction(a); cf # needs sage.rings.number_field [35; (7, 1, 3, 1, 4, 4, 2, 9, 1, 1, 2, 3, 1, 1, 34, 1, 1, 3, 2, 1, 1, 9, 2, 4, 4, 1, 3, 1, 7, 70)*] - sage: latex(cf) + sage: latex(cf) # needs sage.rings.number_field 35 + \frac{\displaystyle 1}{\displaystyle 7 + \frac{\displaystyle 1}{\displaystyle 1 @@ -1701,6 +1704,7 @@ def __invert__(self): sage: a.value() * (~a).value() 1 + sage: # needs sage.rings.number_field sage: K. = QuadraticField(5) sage: a1 = (sqrt5+1)/2 sage: c1 = a1.continued_fraction(); c1 @@ -1710,9 +1714,9 @@ def __invert__(self): sage: c1.value() * (~c1).value() 1 - sage: c2 = (sqrt5/3 + 1/7).continued_fraction(); c2 + sage: c2 = (sqrt5/3 + 1/7).continued_fraction(); c2 # needs sage.rings.number_field [0; 1, (7, 1, 17, ..., 1, 2)*] - sage: c2.value() * (~c2).value() + sage: c2.value() * (~c2).value() # needs sage.rings.number_field 1 """ if not self: @@ -1744,7 +1748,7 @@ def __neg__(self): sage: quots2 = [((),(1,)), ((), (1,2)), ((0,),(1,)), ....: ((),(2,1)), ((3,),(2,1))] - sage: for q in quots2: # optional - sage.rings.number_field + sage: for q in quots2: # needs sage.rings.number_field ....: cf = continued_fraction(q) ....: ncf = -cf ....: nncf = -ncf @@ -1795,16 +1799,14 @@ class ContinuedFraction_real(ContinuedFraction_base): EXAMPLES:: - sage: cf = continued_fraction(pi) - sage: cf + sage: cf = continued_fraction(pi); cf # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] - sage: cf.value() + sage: cf.value() # needs sage.symbolic pi - sage: cf = continued_fraction(e) - sage: cf + sage: cf = continued_fraction(e); cf # needs sage.symbolic [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1, ...] - sage: cf.value() + sage: cf.value() # needs sage.symbolic e """ def __init__(self, x): @@ -1815,7 +1817,7 @@ def __init__(self, x): TESTS:: - sage: TestSuite(continued_fraction(pi)).run() + sage: TestSuite(continued_fraction(pi)).run() # needs sage.symbolic """ ContinuedFraction_base.__init__(self) self._x0 = x @@ -1833,7 +1835,7 @@ def length(self): EXAMPLES:: - sage: continued_fraction(pi).length() + sage: continued_fraction(pi).length() # needs sage.symbolic +Infinity """ return Infinity @@ -1842,7 +1844,7 @@ def __len__(self): r""" TESTS:: - sage: len(continued_fraction(pi)) + sage: len(continued_fraction(pi)) # needs sage.symbolic Traceback (most recent call last): ... ValueError: the length is infinite! @@ -1855,9 +1857,9 @@ def __richcmp__(self, other, op): EXAMPLES:: - sage: continued_fraction(pi) > continued_fraction(e) + sage: continued_fraction(pi) > continued_fraction(e) # needs sage.symbolic True - sage: continued_fraction(pi) > continued_fraction(e+4) + sage: continued_fraction(pi) > continued_fraction(e+4) # needs sage.symbolic False """ try: @@ -1875,7 +1877,7 @@ def _repr_(self): EXAMPLES:: - sage: continued_fraction(pi) # indirect doctest + sage: continued_fraction(pi) # indirect doctest # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] """ return '[%d; ' % self.quotient(0) + ', '.join(str(self.quotient(i)) for i in range(1, 20)) + ", ...]" @@ -1886,12 +1888,13 @@ def quotient(self, n): EXAMPLES:: + sage: # needs sage.symbolic sage: cf = continued_fraction(pi) sage: cf.quotient(27) 13 sage: cf.quotient(2552) 152 - sage: cf.quotient(10000) # long time + sage: cf.quotient(10000) # long time 5 The algorithm is not efficient with element of the symbolic ring and, @@ -1900,6 +1903,7 @@ def quotient(self, n): evaluate in ``RIF`` an expression of the form ``(a*x+b)/(c*x+d)`` where both the numerator and the denominator are extremely small:: + sage: # needs sage.symbolic sage: a1 = pi sage: c1 = continued_fraction(a1) sage: p0 = c1.numerator(12); q0 = c1.denominator(12) @@ -1916,23 +1920,24 @@ def quotient(self, n): ``pi`` gives a very satisfactory answer:: sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^3 - 2, embedding=1.25) # optional - sage.rings.number_field - sage: c2 = continued_fraction(a2) # optional - sage.rings.number_field - sage: p0 = c2.numerator(111); q0 = c2.denominator(111) # optional - sage.rings.number_field - sage: p1 = c2.numerator(112); q1 = c2.denominator(112) # optional - sage.rings.number_field - sage: num = (q0*a2 - p0); num.n() # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 2, embedding=1.25) # needs sage.rings.number_field + sage: c2 = continued_fraction(a2) # needs sage.rings.number_field + sage: p0 = c2.numerator(111); q0 = c2.denominator(111) # needs sage.rings.number_field + sage: p1 = c2.numerator(112); q1 = c2.denominator(112) # needs sage.rings.number_field + sage: num = (q0*a2 - p0); num.n() # needs sage.rings.number_field -4.56719261665907e46 - sage: den = (q1*a2 - p1); den.n() + sage: den = (q1*a2 - p1); den.n() # needs sage.rings.number_field -3.65375409332726e47 - sage: a2 = -num/den - sage: b2 = RIF(a2); b2 + sage: a2 = -num/den # needs sage.rings.number_field + sage: b2 = RIF(a2); b2 # needs sage.rings.number_field 1.002685823312715? - sage: b2.absolute_diameter() + sage: b2.absolute_diameter() # needs sage.rings.number_field 8.88178419700125e-16 The consequence is that the precision needed with ``c1`` grows when we compute larger and larger partial quotients:: + sage: # needs sage.symbolic sage: c1.quotient(100) 2 sage: c1._xa.parent() @@ -1946,6 +1951,7 @@ def quotient(self, n): sage: c1._xa.parent() Real Interval Field with 1053 bits of precision + sage: # needs sage.rings.number_field sage: c2.quotient(200) 6 sage: c2._xa.parent() @@ -1995,8 +2001,8 @@ def value(self): EXAMPLES:: - sage: cf = continued_fraction(e) - sage: cf.value() + sage: cf = continued_fraction(e) # needs sage.symbolic + sage: cf.value() # needs sage.symbolic e """ return self._x0 @@ -2008,16 +2014,16 @@ class ContinuedFraction_infinite(ContinuedFraction_base): EXAMPLES:: - sage: t = continued_fraction(words.ThueMorseWord([1,2])); t + sage: t = continued_fraction(words.ThueMorseWord([1,2])); t # needs sage.combinat [1; 2, 2, 1, 2, 1, 1, 2, 2, 1...] - sage: t.n(digits=100) + sage: t.n(digits=100) # needs sage.combinat 1.422388736882785488341547116024565825306879108991711829311892452916456747272565883312455412962072042 We check that comparisons work well:: - sage: t > continued_fraction(1) and t < continued_fraction(3/2) + sage: t > continued_fraction(1) and t < continued_fraction(3/2) # needs sage.combinat True - sage: t < continued_fraction(1) or t > continued_fraction(2) + sage: t < continued_fraction(1) or t > continued_fraction(2) # needs sage.combinat False Can also be called with a ``value`` option:: @@ -2025,16 +2031,14 @@ class ContinuedFraction_infinite(ContinuedFraction_base): sage: def f(n): ....: if n % 3 == 2: return 2*(n+1)//3 ....: return 1 - sage: w = Word(f, alphabet=NN) - sage: w + sage: w = Word(f, alphabet=NN); w # needs sage.combinat word: 1,1,2,1,1,4,1,1,6,1,1,8,1,1,10,1,1,12,1,1,14,1,1,16,1,1,18,1,1,20,1,1,22,1,1,24,1,1,26,1,... - sage: cf = continued_fraction(w, value=e-1) - sage: cf + sage: cf = continued_fraction(w, value=e-1); cf # needs sage.combinat sage.symbolic [1; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1...] In that case a small check is done on the input:: - sage: cf = continued_fraction(w, value=pi) + sage: cf = continued_fraction(w, value=pi) # needs sage.combinat sage.symbolic Traceback (most recent call last): ... ValueError: value evaluates to 3.141592653589794? while the continued @@ -2056,32 +2060,32 @@ def __init__(self, w, value=None, check=True): TESTS:: - sage: w = words.FibonacciWord(['a','b']) - sage: continued_fraction(w) + sage: w = words.FibonacciWord(['a','b']) # needs sage.combinat + sage: continued_fraction(w) # needs sage.combinat Traceback (most recent call last): ... ValueError: the sequence must consist of integers sage: from itertools import count - sage: w = Word(count(), length="infinite") - sage: continued_fraction(w) + sage: w = Word(count(), length="infinite") # needs sage.combinat + sage: continued_fraction(w) # needs sage.combinat [0; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19...] - sage: w = Word(count(), length="unknown") - sage: continued_fraction(w) + sage: w = Word(count(), length="unknown") # needs sage.combinat + sage: continued_fraction(w) # needs sage.combinat Traceback (most recent call last): ... ValueError: word with unknown length cannot be converted to continued fractions - sage: continued_fraction(words.FibonacciWord([0,1])) + sage: continued_fraction(words.FibonacciWord([0,1])) # needs sage.combinat Traceback (most recent call last): ... ValueError: only the first partial quotient can be null - sage: w = words.ThueMorseWord([int(1), int(2)]) - sage: t = continued_fraction(w) - sage: type(t.quotient(1)) + sage: w = words.ThueMorseWord([int(1), int(2)]) # needs sage.combinat + sage: t = continued_fraction(w) # needs sage.combinat + sage: type(t.quotient(1)) # needs sage.combinat """ ContinuedFraction_base.__init__(self) @@ -2118,8 +2122,8 @@ def _repr_(self): EXAMPLES:: - sage: w = words.FibonacciWord([3,13]) - sage: cf = continued_fraction(w); cf + sage: w = words.FibonacciWord([3,13]) # needs sage.combinat + sage: cf = continued_fraction(w); cf # needs sage.combinat [3; 13, 3, 3, 13, 3, 13, 3, 3, 13, 3, 3, 13, 3, 13, 3, 3, 13, 3, 13...] """ return "[" + str(self._w[0]) + "; " + ", ".join(map(str, self._w[1:20])) + "...]" @@ -2130,9 +2134,9 @@ def length(self): EXAMPLES:: - sage: w = words.FibonacciWord([3,13]) - sage: cf = continued_fraction(w) - sage: cf.length() + sage: w = words.FibonacciWord([3,13]) # needs sage.combinat + sage: cf = continued_fraction(w) # needs sage.combinat + sage: cf.length() # needs sage.combinat +Infinity """ return Infinity @@ -2147,6 +2151,7 @@ def quotient(self, n): EXAMPLES:: + sage: # needs sage.combinat sage: w = words.FibonacciWord([1,3]) sage: cf = continued_fraction(w) sage: cf.quotient(0) @@ -2164,9 +2169,9 @@ def quotients(self): EXAMPLES:: - sage: w = words.FibonacciWord([1,5]) - sage: cf = continued_fraction(w) - sage: cf.quotients() + sage: w = words.FibonacciWord([1,5]) # needs sage.combinat + sage: cf = continued_fraction(w) # needs sage.combinat + sage: cf.quotients() # needs sage.combinat word: 1511515115115151151511511515115115151151... """ return self._w @@ -2181,6 +2186,7 @@ def _Integer_quotient(self, n): EXAMPLES:: + sage: # needs sage.combinat sage: w = words.ThueMorseWord([int(1), int(2)]) sage: t = continued_fraction(w) sage: t.quotient(0) @@ -2204,20 +2210,17 @@ def value(self): sage: def f(n): ....: if n % 3 == 2: return 2*(n+1)//3 ....: return 1 - sage: w = Word(f, alphabet=NN) - sage: w + sage: w = Word(f, alphabet=NN); w # needs sage.combinat word: 1,1,2,1,1,4,1,1,6,1,1,8,1,1,10,1,1,12,1,1,14,1,1,16,1,1,18,1,1,20,1,1,22,1,1,24,1,1,26,1,... - sage: cf = continued_fraction(w, value=e-1) - sage: cf + sage: cf = continued_fraction(w, value=e-1); cf # needs sage.combinat sage.symbolic [1; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1...] - sage: cf.value() + sage: cf.value() # needs sage.combinat sage.symbolic e - 1 - sage: w = words.FibonacciWord([2,5]) - sage: cf = continued_fraction(w) - sage: cf + sage: w = words.FibonacciWord([2,5]) # needs sage.combinat + sage: cf = continued_fraction(w); cf # needs sage.combinat [2; 5, 2, 2, 5, 2, 5, 2, 2, 5, 2, 2, 5, 2, 5, 2, 2, 5, 2, 5...] - sage: cf.value() + sage: cf.value() # needs sage.combinat 2.184951302409338? """ if self._value is not None: @@ -2234,12 +2237,12 @@ def __neg__(self): EXAMPLES:: - sage: -continued_fraction(words.FibonacciWord([2,5])) + sage: -continued_fraction(words.FibonacciWord([2,5])) # needs sage.combinat [-3; 1, 4, 2, 2, 5, 2, 5, 2, 2, 5, 2, 2, 5, 2, 5, 2, 2, 5, 2...] sage: from sage.misc.lazy_list import lazy_list sage: l = lazy_list(lambda n: (n**2)%17) - sage: -continued_fraction(l) + sage: -continued_fraction(l) # needs sage.combinat [-1; 5, 9, 16, 8, 2, 15, 13, 13, 15, 2, 8, 16, 9, 4, 1, 0, 1, 4, 9...] """ from sage.combinat.words.word import Word @@ -2381,32 +2384,34 @@ def continued_fraction_list(x, type="std", partial_convergents=False, Specifying ``bits`` or ``nterms`` modify the length of the output:: - sage: continued_fraction_list(e, bits=20) + sage: continued_fraction_list(e, bits=20) # needs sage.symbolic [2, 1, 2, 1, 1, 4, 2] - sage: continued_fraction_list(sqrt(2)+sqrt(3), bits=30) + sage: continued_fraction_list(sqrt(2)+sqrt(3), bits=30) # needs sage.symbolic [3, 6, 1, 5, 7, 2] - sage: continued_fraction_list(pi, bits=53) + sage: continued_fraction_list(pi, bits=53) # needs sage.symbolic [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14] - sage: continued_fraction_list(log(3/2), nterms=15) + sage: continued_fraction_list(log(3/2), nterms=15) # needs sage.symbolic [0, 2, 2, 6, 1, 11, 2, 1, 2, 2, 1, 4, 3, 1, 1] - sage: continued_fraction_list(tan(sqrt(pi)), nterms=20) + sage: continued_fraction_list(tan(sqrt(pi)), nterms=20) # needs sage.symbolic [-5, 9, 4, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 2, 4, 3, 1, 63] When the continued fraction is infinite (ie ``x`` is an irrational number) and the parameters ``bits`` and ``nterms`` are not specified then a warning is raised:: - sage: continued_fraction_list(sqrt(2)) - doctest:...: UserWarning: the continued fraction of sqrt(2) seems infinite, return only the first 20 terms + sage: continued_fraction_list(sqrt(2)) # needs sage.symbolic + doctest:...: UserWarning: the continued fraction of sqrt(2) seems infinite, + return only the first 20 terms [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] - sage: continued_fraction_list(sqrt(4/19)) - doctest:...: UserWarning: the continued fraction of 2*sqrt(1/19) seems infinite, return only the first 20 terms + sage: continued_fraction_list(sqrt(4/19)) # needs sage.symbolic + doctest:...: UserWarning: the continued fraction of 2*sqrt(1/19) seems infinite, + return only the first 20 terms [0, 2, 5, 1, 1, 2, 1, 16, 1, 2, 1, 1, 5, 4, 5, 1, 1, 2, 1, 16] An examples with the list of partial convergents:: - sage: continued_fraction_list(RR(pi), partial_convergents=True) + sage: continued_fraction_list(RR(pi), partial_convergents=True) # needs sage.symbolic ([3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3], [(3, 1), (22, 7), @@ -2427,11 +2432,11 @@ def continued_fraction_list(x, type="std", partial_convergents=False, sage: continued_fraction_list(1 + 10^-10, nterms=3) [1, 10000000000] - sage: continued_fraction_list(1 + 10^-20 - e^-100, nterms=3) + sage: continued_fraction_list(1 + 10^-20 - e^-100, nterms=3) # needs sage.symbolic [1, 100000000000000000000, 2688] - sage: continued_fraction_list(1 + 10^-20 - e^-100, nterms=5) + sage: continued_fraction_list(1 + 10^-20 - e^-100, nterms=5) # needs sage.symbolic [1, 100000000000000000000, 2688, 8, 1] - sage: continued_fraction_list(1 + 10^-20 - e^-100, nterms=5) + sage: continued_fraction_list(1 + 10^-20 - e^-100, nterms=5) # needs sage.symbolic [1, 100000000000000000000, 2688, 8, 1] Fixed :trac:`18901`:: @@ -2444,7 +2449,7 @@ def continued_fraction_list(x, type="std", partial_convergents=False, Check that this works for arb elements (:trac:`20069`):: - sage: continued_fraction(RBF(e)) + sage: continued_fraction(RBF(e)) # needs sage.symbolic [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12] """ from .rational_field import QQ @@ -2537,31 +2542,33 @@ def continued_fraction(x, value=None): It can be called with elements defined from symbolic values, in which case the partial quotients are evaluated in a lazy way:: - sage: c = continued_fraction(golden_ratio); c # optional - sage.symbolic + sage: c = continued_fraction(golden_ratio); c # needs sage.symbolic [1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...] - sage: c.convergent(12) # optional - sage.symbolic + sage: c.convergent(12) # needs sage.symbolic 377/233 - sage: fibonacci(14)/fibonacci(13) + sage: fibonacci(14)/fibonacci(13) # needs sage.libs.pari 377/233 - sage: continued_fraction(pi) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: continued_fraction(pi) [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] - sage: c = continued_fraction(pi); c # optional - sage.symbolic + sage: c = continued_fraction(pi); c [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] - sage: a = c.convergent(3); a # optional - sage.symbolic + sage: a = c.convergent(3); a 355/113 - sage: a.n() # optional - sage.symbolic + sage: a.n() 3.14159292035398 - sage: pi.n() # optional - sage.symbolic + sage: pi.n() 3.14159265358979 - sage: continued_fraction(sqrt(2)) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: continued_fraction(sqrt(2)) [1; 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...] - sage: continued_fraction(tan(1)) # optional - sage.symbolic + sage: continued_fraction(tan(1)) [1; 1, 1, 3, 1, 5, 1, 7, 1, 9, 1, 11, 1, 13, 1, 15, 1, 17, 1, 19, ...] - sage: continued_fraction(tanh(1)) # optional - sage.symbolic + sage: continued_fraction(tanh(1)) [0; 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, ...] - sage: continued_fraction(e) # optional - sage.symbolic + sage: continued_fraction(e) [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 1, 1, 12, 1, 1, ...] If you want to play with quadratic numbers (such as ``golden_ratio`` and @@ -2569,21 +2576,22 @@ def continued_fraction(x, value=None): follows since preperiods and periods are computed:: sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 - 5, embedding=2.23) # optional - sage.rings.number_field - sage: my_golden_ratio = (1 + sqrt5)/2 # optional - sage.rings.number_field - sage: cf = continued_fraction((1+sqrt5)/2); cf # optional - sage.rings.number_field + sage: K. = NumberField(x^2 - 5, embedding=2.23) # needs sage.rings.number_field + sage: my_golden_ratio = (1 + sqrt5)/2 # needs sage.rings.number_field + sage: cf = continued_fraction((1+sqrt5)/2); cf # needs sage.rings.number_field [(1)*] - sage: cf.convergent(12) + sage: cf.convergent(12) # needs sage.rings.number_field 377/233 - sage: cf.period() + sage: cf.period() # needs sage.rings.number_field (1,) - sage: cf = continued_fraction(2/3+sqrt5/5); cf + sage: cf = continued_fraction(2/3+sqrt5/5); cf # needs sage.rings.number_field [1; 8, (1, 3, 1, 1, 3, 9)*] - sage: cf.preperiod() + sage: cf.preperiod() # needs sage.rings.number_field (1, 8) - sage: cf.period() + sage: cf.period() # needs sage.rings.number_field (1, 3, 1, 1, 3, 9) + sage: # needs sage.rings.number_field sage: L. = NumberField(x^2 - 2, embedding=1.41) sage: cf = continued_fraction(sqrt2); cf [1; (2)*] @@ -2600,20 +2608,20 @@ def continued_fraction(x, value=None): sage: cf = continued_fraction([(1,1), (2,8)]); cf [1; 1, (2, 8)*] - sage: cf.value() + sage: cf.value() # needs sage.rings.number_field 2/11*sqrt5 + 14/11 It is possible to deal with higher degree number fields but in that case the continued fraction expansion is known to be aperiodic:: - sage: K. = NumberField(x^3 - 2, embedding=1.25) - sage: cf = continued_fraction(a); cf + sage: K. = NumberField(x^3 - 2, embedding=1.25) # needs sage.rings.number_field + sage: cf = continued_fraction(a); cf # needs sage.rings.number_field [1; 3, 1, 5, 1, 1, 4, 1, 1, 8, 1, 14, 1, 10, 2, 1, 4, 12, 2, 3, ...] Note that initial rounding can result in incorrect trailing partial quotients:: - sage: continued_fraction(RealField(39)(e)) + sage: continued_fraction(RealField(39)(e)) # needs sage.symbolic [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, 1, 10, 2] Note the value returned for floating point number is the continued fraction @@ -2635,8 +2643,8 @@ def continued_fraction(x, value=None): Constants in symbolic subrings work like constants in ``SR``:: - sage: SCR = SR.subring(no_variables=True) # optional - sage.symbolic - sage: continued_fraction(SCR(pi)) # optional - sage.symbolic + sage: SCR = SR.subring(no_variables=True) # needs sage.symbolic + sage: continued_fraction(SCR(pi)) # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] """ diff --git a/src/sage/rings/continued_fraction_gosper.py b/src/sage/rings/continued_fraction_gosper.py index 08d5dd34658..4f86b3d9da6 100644 --- a/src/sage/rings/continued_fraction_gosper.py +++ b/src/sage/rings/continued_fraction_gosper.py @@ -4,12 +4,13 @@ EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.rings.continued_fraction_gosper import gosper_iterator sage: x = continued_fraction(pi) sage: it = iter(gosper_iterator(3,2,3,1,x)) - sage: Word(it, length='infinite') + sage: Word(it, length='infinite') # needs sage.combinat word: 1,10,2,2,1,4,1,1,1,97,4,1,2,1,2,45,6,4,9,1,27,2,6,1,4,2,3,1,3,1,15,2,1,1,2,1,1,2,32,1,... - sage: continued_fraction((3*pi + 2) / (3*pi + 1)) + sage: continued_fraction((3*pi + 2) / (3*pi + 1)) # needs sage.combinat [1; 10, 2, 2, 1, 4, 1, 1, 1, 97, 4, 1, 2, 1, 2, 45, 6, 4, 9, 1, ...] REFERENCES: @@ -104,9 +105,9 @@ def __iter__(self): sage: from sage.rings.continued_fraction_gosper import gosper_iterator sage: a, b, c, d = (Integer(randint(-100,100)) for _ in range(4)) - sage: ig = iter(gosper_iterator(a, b, c, d, continued_fraction(pi))) - sage: icf = iter(continued_fraction((a*pi + b) / (c*pi + d))); - sage: for i in range(10): + sage: ig = iter(gosper_iterator(a, b, c, d, continued_fraction(pi))) # needs sage.symbolic + sage: icf = iter(continued_fraction((a*pi + b) / (c*pi + d))); # needs sage.symbolic + sage: for i in range(10): # needs sage.symbolic ....: try: ....: assert next(ig) == next(icf) ....: except StopIteration: @@ -121,8 +122,8 @@ def __next__(self): TESTS:: sage: from sage.rings.continued_fraction_gosper import gosper_iterator - sage: it = gosper_iterator(1, 0, 0, 1, continued_fraction(pi)) - sage: list(next(it) for _ in range(10)) + sage: it = gosper_iterator(1, 0, 0, 1, continued_fraction(pi)) # needs sage.symbolic + sage: list(next(it) for _ in range(10)) # needs sage.symbolic [3, 7, 15, 1, 292, 1, 1, 1, 2, 1] """ while True: @@ -156,10 +157,10 @@ def emit(self, q): sage: a = Integer(randint(-100,100)); b = Integer(randint(-100,100)); sage: c = Integer(randint(-100,100)); d = Integer(randint(-100,100)); sage: from sage.rings.continued_fraction_gosper import gosper_iterator - sage: gi = gosper_iterator(a,b,c,d,continued_fraction(pi)) - sage: for i in range(10): + sage: gi = gosper_iterator(a, b, c, d, continued_fraction(pi)) # needs sage.symbolic + sage: for i in range(10): # needs sage.symbolic ....: gi.emit(i) - sage: gi.currently_emitted + sage: gi.currently_emitted # needs sage.symbolic 10 """ self.currently_emitted += 1 @@ -182,10 +183,10 @@ def ingest(self): sage: a = Integer(randint(-100,100)); b = Integer(randint(-100,100)); sage: c = Integer(randint(-100,100)); d = Integer(randint(-100,100)); sage: from sage.rings.continued_fraction_gosper import gosper_iterator - sage: gi = gosper_iterator(a,b,c,d,continued_fraction(pi)) - sage: for i in range(10): + sage: gi = gosper_iterator(a, b, c, d, continued_fraction(pi)) # needs sage.symbolic + sage: for i in range(10): # needs sage.symbolic ....: gi.ingest() - sage: gi.currently_read + sage: gi.currently_read # needs sage.symbolic 10 """ try: diff --git a/src/sage/rings/derivation.py b/src/sage/rings/derivation.py index 74903e6072f..136c8c40307 100644 --- a/src/sage/rings/derivation.py +++ b/src/sage/rings/derivation.py @@ -231,32 +231,32 @@ def __init__(self, domain, codomain, twist=None): sage: TestSuite(M).run() sage: from sage.rings.derivation import RingDerivationModule - 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: R5. = GF(5)[] # needs sage.rings.finite_rings + sage: R25. = GF(25)[] # needs sage.rings.finite_rings + sage: R7. = GF(7)[] # needs sage.rings.finite_rings - sage: RingDerivationModule(R5, R25) # optional - sage.rings.finite_rings + sage: RingDerivationModule(R5, R25) # needs 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 + sage: RingDerivationModule(R5, R5^2) # needs 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) # optional - sage.rings.finite_rings + sage: RingDerivationModule(R5, R7) # needs 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]) # optional - sage.rings.finite_rings - sage: RingDerivationModule(R5, R25, twist=theta) # optional - sage.rings.finite_rings + sage: theta = R5.hom([R5.gen()^2]) # needs sage.rings.finite_rings + sage: RingDerivationModule(R5, R25, twist=theta) # needs 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 + sage: RingDerivationModule(R7, R7, twist=theta) # needs sage.rings.finite_rings Traceback (most recent call last): ... TypeError: the domain of the derivation must coerce to the domain of the twisting homomorphism @@ -1074,10 +1074,10 @@ def _richcmp_(self, other, op): EXAMPLES:: - 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 + sage: R. = GF(5)[] # needs sage.rings.finite_rings + sage: D = sum(v*R.derivation(v) for v in R.gens()); D # needs sage.rings.finite_rings x*d/dx + y*d/dy + z*d/dz - sage: D.pth_power() == D # optional - sage.rings.finite_rings + sage: D.pth_power() == D # needs sage.rings.finite_rings True """ @@ -1149,17 +1149,18 @@ def pth_power(self): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: Dx = R.derivation(x) + sage: Dx.pth_power() 0 - sage: (x*Dx).pth_power() # optional - sage.rings.finite_rings + sage: (x*Dx).pth_power() x*d/dx - sage: (x^6*Dx).pth_power() # optional - sage.rings.finite_rings + sage: (x^6*Dx).pth_power() x^26*d/dx - sage: Dy = R.derivation(y) # optional - sage.rings.finite_rings - sage: (x*Dx + y*Dy).pth_power() # optional - sage.rings.finite_rings + sage: Dy = R.derivation(y) # needs sage.rings.finite_rings + sage: (x*Dx + y*Dy).pth_power() # needs sage.rings.finite_rings x*d/dx + y*d/dy An error is raised if the domain has characteristic zero:: @@ -1182,14 +1183,15 @@ def pth_power(self): TESTS:: - 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 + sage: # needs sage.rings.finite_rings + 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))) True - sage: D.bracket(Dp) # optional - sage.rings.finite_rings + sage: D.bracket(Dp) # needs sage.rings.finite_rings 0 """ @@ -1578,15 +1580,16 @@ def __init__(self, parent, arg=None): TESTS:: + sage: # needs sage.rings.finite_rings sage: from sage.rings.derivation import 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 + 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) True - sage: TestSuite(der).run() # optional - sage.rings.finite_rings + sage: TestSuite(der).run() # needs sage.rings.finite_rings """ if isinstance(arg, list) and len(arg) == 1 and isinstance(arg[0], RingDerivation): @@ -1617,11 +1620,12 @@ def _add_(self, other): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + 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 d/dx + d/dy """ @@ -1633,11 +1637,12 @@ def _sub_(self, other): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + 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 d/dx - d/dy """ @@ -1649,10 +1654,11 @@ def _neg_(self): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: S. = R.quo([X^5, Y^5]) + sage: Dx = S.derivation(x) + sage: -Dx -d/dx """ @@ -1664,12 +1670,13 @@ def _lmul_(self, factor): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: S. = R.quo([X^5, Y^5]) + sage: Dx = S.derivation(x) + sage: Dx * 2 2*d/dx - sage: Dx * x^2 # optional - sage.rings.finite_rings + sage: Dx * x^2 x^2*d/dx """ @@ -1681,12 +1688,13 @@ def _rmul_(self, factor): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: S. = R.quo([X^5, Y^5]) + sage: Dx = S.derivation(x) + sage: 2 * Dx 2*d/dx - sage: x^2 * Dx # optional - sage.rings.finite_rings + sage: x^2 * Dx x^2*d/dx """ @@ -1699,20 +1707,21 @@ def list(self): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: S. = R.quo([X^5, Y^5]) + sage: M = S.derivation_module() + sage: M.basis() Family (d/dx, d/dy) - sage: S.derivation(x).list() # optional - sage.rings.finite_rings + sage: S.derivation(x).list() # needs sage.rings.finite_rings [1, 0] - sage: S.derivation(y).list() # optional - sage.rings.finite_rings + sage: S.derivation(y).list() # needs sage.rings.finite_rings [0, 1] - sage: f = x*S.derivation(x) + y*S.derivation(y); f # optional - sage.rings.finite_rings + sage: f = x*S.derivation(x) + y*S.derivation(y); f # needs sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() # optional - sage.rings.finite_rings + sage: f.list() # needs sage.rings.finite_rings [x, y] """ @@ -1906,19 +1915,19 @@ def list(self): EXAMPLES:: - 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 + sage: R. = GF(5)[[]] # needs sage.rings.finite_rings + sage: M = R.derivation_module() # needs sage.rings.finite_rings + sage: M.basis() # needs sage.rings.finite_rings Family (d/dx, d/dy) - sage: R.derivation(x).list() # optional - sage.rings.finite_rings + sage: R.derivation(x).list() # needs sage.rings.finite_rings [1, 0] - sage: R.derivation(y).list() # optional - sage.rings.finite_rings + sage: R.derivation(y).list() # needs sage.rings.finite_rings [0, 1] - sage: f = x*R.derivation(x) + y*R.derivation(y); f # optional - sage.rings.finite_rings + sage: f = x*R.derivation(x) + y*R.derivation(y); f # needs sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() # optional - sage.rings.finite_rings + sage: f.list() # needs sage.rings.finite_rings [x, y] """ @@ -1991,11 +2000,12 @@ def _call_(self, x): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: S. = R.quo([X^5, Y^5]) + sage: f = x^3*S.derivation(); f x^3*d/dx - sage: f(x^3) # optional - sage.rings.finite_rings + sage: f(x^3) 0 """ @@ -2091,10 +2101,11 @@ def _latex_(self): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: k. = GF(5^3) + sage: Frob = k.frobenius_endomorphism() + sage: der = k.derivation(a + 1, twist=Frob) + sage: latex(der) \left(a + 1\right) \left(\left[a \mapsto a^{5}\right] - \text{id}\right) """ scalar = self._scalar @@ -2370,13 +2381,12 @@ def extend_to_fraction_field(self): sage: d x*([x |--> y, y |--> x] - id) - sage: D = d.extend_to_fraction_field() - sage: D + sage: D = d.extend_to_fraction_field(); D # needs sage.libs.singular x*([x |--> y, y |--> x] - id) - sage: D.domain() + sage: D.domain() # needs sage.libs.singular Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring - sage: D(1/x) + sage: D(1/x) # needs sage.libs.singular (x - y)/y """ parent = self.parent() diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index fea5b444b00..d4df0e5ea05 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -129,25 +129,26 @@ cpdef factor_aurifeuillian(n, check=True): EXAMPLES:: + sage: # needs sage.libs.pari sage: from sage.rings.factorint import factor_aurifeuillian as fa - sage: fa(2^6 + 1) # optional - sage.libs.pari + sage: fa(2^6 + 1) [5, 13] - sage: fa(2^58 + 1) # optional - sage.libs.pari + sage: fa(2^58 + 1) [536838145, 536903681] - sage: fa(3^3 + 1) # optional - sage.libs.pari + sage: fa(3^3 + 1) [4, 1, 7] - sage: fa(5^5 - 1) # optional - sage.libs.pari + sage: fa(5^5 - 1) [4, 11, 71] - sage: prod(_) == 5^5 - 1 # optional - sage.libs.pari + sage: prod(_) == 5^5 - 1 True - sage: fa(2^4 + 1) # optional - sage.libs.pari + sage: fa(2^4 + 1) [17] - sage: fa((6^2*3)^3 + 1) # optional - sage.libs.pari + sage: fa((6^2*3)^3 + 1) [109, 91, 127] TESTS:: - sage: for n in [2,3,5,6,30,31,33]: # optional - sage.libs.pari + sage: for n in [2,3,5,6,30,31,33]: # needs sage.libs.pari ....: for m in [8,96,109201283]: ....: s = -1 if n % 4 == 1 else 1 ....: y = (m^2*n)^n + s diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 31d51c3195c..5d7e4cfab4d 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -25,11 +25,12 @@ The GCD is not taken (since it doesn't converge sometimes) in the inexact case:: - sage: Z. = CC[] # optional - sage.rings.real_mpfr - sage: I = CC.gen() # optional - sage.rings.real_mpfr - sage: (1+I+z)/(z+0.1*I) # optional - sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: Z. = CC[] + sage: I = CC.gen() + sage: (1+I+z)/(z+0.1*I) (z + 1.00000000000000 + I)/(z + 0.100000000000000*I) - sage: (1+I*z)/(z+1.1) # optional - sage.rings.real_mpfr + sage: (1+I*z)/(z+1.1) (I*z + 1.00000000000000)/(z + 1.10000000000000) TESTS:: @@ -264,11 +265,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) # 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 + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # needs sage.rings.number_field + sage: R = K.ring_of_integers() # needs sage.rings.number_field + sage: S. = R[] # needs sage.rings.number_field + sage: F = FractionField(S) # needs sage.rings.number_field + sage: F(1/a) # needs 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`):: @@ -296,6 +297,7 @@ def _coerce_map_from_(self, S): sage: 1/(R.gen() + 1) 1/(x + 1) + sage: # needs sage.modules sage: R = LaurentPolynomialRing(ZZ, 'x,y') sage: FF = FractionField(PolynomialRing(ZZ, 'x,y')) sage: prod(R.gens()) + prod(FF.gens()) @@ -306,21 +308,21 @@ def _coerce_map_from_(self, S): Test for :trac:`31320`:: sage: FQt = Frac(QQ['t']) - sage: LCt = LaurentPolynomialRing(CC,'t') # optional - sage.rings.real_mpfr - sage: coercion_model.common_parent(FQt, LCt) # optional - sage.rings.real_mpfr + sage: LCt = LaurentPolynomialRing(CC,'t') # needs sage.rings.real_mpfr + sage: coercion_model.common_parent(FQt, LCt) # needs sage.rings.real_mpfr Fraction Field of Univariate Polynomial Ring in t over Complex Field with 53 bits of precision Coercion from a localization:: sage: R. = ZZ[] - sage: L = Localization(R, (x**2 + 1,7)) # optional - sage.libs.pari - sage: F = L.fraction_field() # optional - sage.libs.pari - sage: f = F.coerce_map_from(L); f # optional - sage.libs.pari + sage: L = Localization(R, (x**2 + 1,7)) # needs sage.libs.pari + sage: F = L.fraction_field() + sage: f = F.coerce_map_from(L); f # needs sage.libs.pari Coercion map: From: Univariate Polynomial Ring in x over Integer Ring localized at (7, x^2 + 1) To: Fraction Field of Univariate Polynomial Ring in x over Integer Ring - sage: f(L(1/7)) == 1/7 # optional - sage.libs.pari + sage: f(L(1/7)) == 1/7 # needs sage.libs.pari True """ from sage.rings.rational_field import QQ @@ -394,11 +396,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) # 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 + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # needs sage.rings.number_field + sage: R = K.ring_of_integers() # needs sage.rings.number_field + sage: S. = R[] # needs sage.rings.number_field + sage: F = FractionField(S) # indirect doctest # needs sage.rings.number_field + sage: F(1/a) # needs sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 """ f = x.polynomial() # Polynomial over QQ @@ -459,7 +461,7 @@ def characteristic(self): Integer Ring sage: R = Frac(ZZ['t']); R.characteristic() 0 - sage: R = Frac(GF(5)['w']); R.characteristic() # optional - sage.rings.finite_rings + sage: R = Frac(GF(5)['w']); R.characteristic() 5 """ return self._R.characteristic() @@ -481,7 +483,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest # optional - sage.rings.finite_rings + sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest \mathrm{Frac}(\Bold{F}_{7}[x, y, z]) """ return "\\mathrm{Frac}(%s)" % latex.latex(self._R) @@ -494,7 +496,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 # optional - sage.rings.finite_rings + sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma, needs sage.rings.finite_rings 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...,3,"grevlex"),["x","y","z"])),["x","y","z"])' ``_magma_init_`` gets called implicitly below:: @@ -538,7 +540,7 @@ def is_exact(self): sage: Frac(ZZ['x']).is_exact() True - sage: Frac(CDF['x']).is_exact() + sage: Frac(CDF['x']).is_exact() # needs sage.rings.complex_double False """ return self.ring().is_exact() @@ -571,17 +573,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))) # optional - sage.libs.pari + sage: K(pari((x + 1)/(x^2 + x + 1))) # needs 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)) # optional - sage.libs.pari + sage: S(pari((x + y)/y)) # needs sage.libs.pari (x + y)/y - sage: S(pari(x + y + 1/z)) # optional - sage.libs.pari + sage: S(pari(x + y + 1/z)) # needs sage.libs.pari (x*z + y*z + 1)/z This example failed before :trac:`23664`:: @@ -607,19 +609,19 @@ def _element_constructor_(self, x, y=None, coerce=True): sage: A. = Frac(PolynomialRing(QQ,'a,c')) sage: B. = PolynomialRing(A,'d,e') sage: R. = PolynomialRing(B,'x') - sage: (a*d*x^2+a+e+1).resultant(-4*c^2*x+1) + sage: (a*d*x^2+a+e+1).resultant(-4*c^2*x+1) # needs sage.libs.pari a*d + (16*c^4)*e + (16*a*c^4 + 16*c^4) Check that :trac:`24539` is fixed:: sage: tau = polygen(QQ, 'tau') - sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) # optional - sage.rings.number_field + sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) # needs sage.rings.number_field z/(z + 1) Check that :trac:`26150` is fixed:: - sage: z = SR.var('z') # optional - sage.symbolic - sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) # optional - sage.rings.number_field sage.symbolic + sage: z = SR.var('z') # needs sage.symbolic + sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) # needs sage.rings.number_field sage.symbolic (8*z + 10)/(z^5 - 3*z^4 + 2*z^3 + 2*z^2 - 3*z + 1) :: @@ -731,12 +733,12 @@ def construction(self): sage: Frac(ZZ['x']).construction() (FractionField, Univariate Polynomial Ring in x over Integer Ring) - 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 + 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 # optional - sage.rings.finite_rings + sage: f(R) == K True """ from sage.categories.pushout import FractionField @@ -986,8 +988,8 @@ def ring_of_integers(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings - sage: K.ring_of_integers() # optional - sage.rings.finite_rings + sage: K = FractionField(GF(5)['t']) + sage: K.ring_of_integers() Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -998,8 +1000,8 @@ def maximal_order(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings - sage: K.maximal_order() # optional - sage.rings.finite_rings + sage: K = FractionField(GF(5)['t']) + sage: K.maximal_order() Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -1010,8 +1012,8 @@ def class_number(self): EXAMPLES:: - sage: R. = GF(5)[]; K = R.fraction_field() # optional - sage.rings.finite_rings - sage: K.class_number() # optional - sage.rings.finite_rings + sage: R. = GF(5)[]; K = R.fraction_field() + sage: K.class_number() 1 """ return 1 @@ -1022,11 +1024,12 @@ def _factor_univariate_polynomial(self, f): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: k. = GF(9) + sage: K = k['t'].fraction_field() + sage: R. = K[] + sage: f = x^3 + a + sage: f.factor() (x + 2*a + 1)^3 """ @@ -1041,9 +1044,9 @@ def function_field(self): EXAMPLES:: - 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 + sage: R. = GF(5)[] + sage: K = R.fraction_field() + sage: K.function_field() Rational function field in t over Finite Field of size 5 .. SEEALSO:: @@ -1060,15 +1063,16 @@ def _coerce_map_from_(self, R): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: K = R.fraction_field() + sage: L = K.function_field() + sage: f = K.coerce_map_from(L); f # indirect doctest 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()) # optional - sage.rings.finite_rings + sage: f(~L.gen()) 1/t """ @@ -1166,12 +1170,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R) - sage: S. = GF(2)[] # optional - sage.rings.finite_rings - sage: g = S.fraction_field().coerce_map_from(S) # optional - sage.rings.finite_rings + sage: S. = GF(2)[] + sage: g = S.fraction_field().coerce_map_from(S) - sage: f == g # indirect doctest # optional - sage.rings.finite_rings + sage: f == g # indirect doctest False - sage: f == f # optional - sage.rings.finite_rings + sage: f == f True """ @@ -1236,19 +1240,20 @@ def _call_(self, x, check=True): Over inexact rings, we have to take the precision of the denominators into account:: - sage: R = ZpCR(2) # optional - sage.rings.padics - sage: S. = R[] # optional - sage.rings.padics - sage: f = x/S(R(3, absprec=2)) # optional - sage.rings.padics - sage: S(f) # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: R = ZpCR(2) + sage: S. = R[] + sage: f = x/S(R(3, absprec=2)) + sage: S(f) (1 + 2 + O(2^2))*x Test for Localization:: sage: R. = ZZ[] - sage: L = Localization(R, x**2 + 2*x + 1) # optional - sage.libs.pari - sage: 1/(x + 1) in L # indirect doctest # optional - sage.libs.pari + sage: L = Localization(R, x**2 + 2*x + 1) # needs sage.libs.pari + sage: 1/(x + 1) in L # indirect doctest # needs sage.libs.pari True - sage: 1/(x + 2) in L # indirect doctest # optional - sage.libs.pari + sage: 1/(x + 2) in L # indirect doctest # needs sage.libs.pari False """ codom = self.codomain() @@ -1298,12 +1303,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R).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: S. = GF(2)[] + sage: g = S.fraction_field().coerce_map_from(S).section() - sage: f == g # indirect doctest # optional - sage.rings.finite_rings + sage: f == g # indirect doctest False - sage: f == f # optional - sage.rings.finite_rings + sage: f == f True """ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 78b13455d56..d8517147070 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -64,9 +64,9 @@ cdef class FractionFieldElement(FieldElement): Test if :trac:`5451` is fixed:: - sage: A = FiniteField(9,'theta')['t'] # optional - sage.rings.finite_rings - sage: K. = FractionField(A) # optional - sage.rings.finite_rings - sage: f = 2/(t^2 + 2*t); g = t^9/(t^18 + t^10 + t^2); f + g # optional - sage.rings.finite_rings + sage: A = FiniteField(9,'theta')['t'] # needs sage.rings.finite_rings + sage: K. = FractionField(A) # needs sage.rings.finite_rings + sage: f = 2/(t^2 + 2*t); g = t^9/(t^18 + t^10 + t^2); f + g # needs sage.rings.finite_rings (2*t^15 + 2*t^14 + 2*t^13 + 2*t^12 + 2*t^11 + 2*t^10 + 2*t^9 + t^7 + t^6 + t^5 + t^4 + t^3 + t^2 + t + 1)/(t^17 + t^9 + t) Test if :trac:`8671` is fixed:: @@ -99,8 +99,8 @@ cdef class FractionFieldElement(FieldElement): sage: f.numerator() 'hi' - sage: x = var('x') # optional - sage.symbolic - sage: K((x + 1)/(x^2 + x + 1)) # optional - sage.symbolic + sage: x = var('x') # needs sage.symbolic + sage: K((x + 1)/(x^2 + x + 1)) (x + 1)/(x^2 + x + 1) sage: K(355/113) 355/113 @@ -127,31 +127,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() # optional - sage.rings.finite_rings - sage: a,b = K.gens() # optional - sage.rings.finite_rings + sage: K = GF(7)['a,b'].fraction_field() + sage: a,b = K.gens() :: - 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 + sage: phi = F.hom([a + b, a*b], K) + sage: phi(x+y) # indirect doctest a*b + a + b :: - sage: (x^2/y)._im_gens_(K, [a + b, a*b]) # optional - sage.rings.finite_rings + sage: (x^2/y)._im_gens_(K, [a + b, a*b]) (a^2 + 2*a*b + b^2)/(a*b) - sage: (x^2/y)._im_gens_(K, [a, a*b]) # optional - sage.rings.finite_rings + sage: (x^2/y)._im_gens_(K, [a, a*b]) a/b :: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field - sage: cc = K.hom([-i]) # optional - sage.rings.number_field - sage: 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 + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field + sage: cc = K.hom([-i]) # needs sage.rings.number_field + sage: R. = K[] # needs sage.rings.number_field + sage: F = R.fraction_field() # needs sage.rings.number_field + sage: phi = F.hom([F(b), F(a)], base_map=cc) # needs sage.rings.number_field + sage: phi(i/a) # needs sage.rings.number_field ((-i))/b """ nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) @@ -173,10 +173,10 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - sage: R. = RealField(10)[] # optional - sage.rings.real_mpfr - sage: f = (x^2+2*x+1)/(x+1); f # optional - sage.rings.real_mpfr + sage: R. = RealField(10)[] # needs sage.rings.real_mpfr + sage: f = (x^2+2*x+1)/(x+1); f # needs sage.rings.real_mpfr (x^2 + 2.0*x + 1.0)/(x + 1.0) - sage: f.reduce(); f # optional - sage.rings.real_mpfr + sage: f.reduce(); f # needs sage.rings.real_mpfr x + 1.0 TESTS: @@ -393,10 +393,10 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25199` is fixed:: - sage: R. = QQbar[] # optional - sage.rings.number_field - sage: hash(R.0) == hash(FractionField(R).0) # optional - sage.rings.number_field + sage: R. = QQbar[] # needs sage.rings.number_field + sage: hash(R.0) == hash(FractionField(R).0) True - sage: ((x+1)/(x^2+1)).subs({x: 1}) # optional - sage.rings.number_field + sage: ((x+1)/(x^2+1)).subs({x: 1}) 1 """ if self.__denominator.is_one(): @@ -568,13 +568,13 @@ cdef class FractionFieldElement(FieldElement): (x + y)/(x*y) sage: 1/x + 1/(x*y) (y + 1)/(x*y) - sage: Frac(CDF['x']).gen() + 3 + sage: Frac(CDF['x']).gen() + 3 # needs sage.rings.complex_double x + 3.0 Subtraction is implemented by adding the negative:: - sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings - sage: t - 1/t # indirect doctest # optional - sage.rings.finite_rings + sage: K. = Frac(GF(7)['t']) + sage: t - 1/t # indirect doctest (t^2 + 6)/t """ rnum = self.__numerator @@ -646,10 +646,11 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: K. = Frac(GF(7)['t']) + sage: a = t/(1+t) + sage: b = 3/t + sage: a * b # indirect doctest 3/(t + 1) """ rnum = self.__numerator @@ -775,7 +776,7 @@ cdef class FractionFieldElement(FieldElement): TESTS:: sage: K = Frac(ZZ['x']) - sage: QQ(K(x) / K(2*x)) # optional - sage.symbolic + sage: QQ(K(x) / K(2*x)) # needs sage.symbolic 1/2 """ return self._conversion(QQ) @@ -811,15 +812,16 @@ cdef class FractionFieldElement(FieldElement): 3/2 sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field - sage: A((x+3) / (2*x - 1)) # optional - sage.rings.number_field + sage: A. = NumberField(x^3 - 2) # needs sage.rings.number_field + sage: A((x+3) / (2*x - 1)) # needs sage.rings.number_field 14/15*u^2 + 7/15*u + 11/15 - sage: B = A['y'].fraction_field() # optional - sage.rings.number_field - sage: A(B(u)) # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: B = A['y'].fraction_field() + sage: A(B(u)) u - sage: C = A['x,y'].fraction_field() # optional - sage.rings.number_field - sage: A(C(u)) # optional - sage.rings.number_field + sage: C = A['x,y'].fraction_field() + sage: A(C(u)) u """ if self.__denominator.is_one(): @@ -857,15 +859,15 @@ cdef class FractionFieldElement(FieldElement): sage: x,y = FR.gens() sage: a = x^2; a x^2 - sage: type(a.numerator()) # optional - sage.lings.singular + sage: type(a.numerator()) # needs sage.lings.singular - sage: type(a.denominator()) # optional - sage.lings.singular + sage: type(a.denominator()) # needs sage.lings.singular sage: a = x^(-2); a 1/x^2 - sage: type(a.numerator()) # optional - sage.lings.singular + sage: type(a.numerator()) # needs sage.lings.singular - sage: type(a.denominator()) # optional - sage.lings.singular + sage: type(a.denominator()) # needs sage.lings.singular sage: x^0 1 @@ -897,10 +899,10 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(5)['t']) # optional - sage.rings.finite_rings - sage: f = (t^2+t)/(t+2); f # optional - sage.rings.finite_rings + sage: K. = Frac(GF(5)['t']) + sage: f = (t^2+t)/(t+2); f (t^2 + t)/(t + 2) - sage: -f # optional - sage.rings.finite_rings + sage: -f (4*t^2 + 4*t)/(t + 2) """ return self.__class__(self._parent, @@ -921,9 +923,9 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - 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 + sage: K. = Frac(GF(7)['t']) + sage: f = (t^2+5)/(t-1) + sage: ~f (t + 6)/(t^2 + 5) """ if self.is_zero(): @@ -935,12 +937,13 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings - sage: t/t == 1 # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = Frac(GF(7)['t']) + sage: t/t == 1 True - sage: t + 1/t == (t^2+1)/t # optional - sage.rings.finite_rings + sage: t + 1/t == (t^2+1)/t True - sage: t == t/5 # optional - sage.rings.finite_rings + sage: t == t/5 False :: @@ -1039,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) # optional - sage.symbolic + sage: elt._symbolic_(SR) # needs sage.symbolic 2/3*(x + y)/(x - y) - sage: symbolic_expression(elt) # optional - sage.symbolic + sage: symbolic_expression(elt) # needs sage.symbolic 2/3*(x + y)/(x - y) """ return ring(self.__numerator)/ring(self.__denominator) @@ -1098,18 +1101,19 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25440` has been resolved:: - 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 + sage: R. = GF(2)[] + sage: S. = R.fraction_field()[] + sage: (y+1)(R.one()) 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: # needs sage.rings.padics + sage: K = Qp(2, 5) + sage: R. = K[] + sage: L = R.fraction_field() + sage: S. = L[] + sage: y(K(1,1)/x) (1 + O(2))/((1 + O(2))*x) """ if self.numerator().is_one(): @@ -1204,7 +1208,7 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): 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.support() # needs sage.libs.pari [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/ideal.py b/src/sage/rings/ideal.py index 72204ac3dec..97694acde35 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)[] # optional - sage.rings.finite_rings - sage: I = R * (x^2 + 3) # optional - sage.rings.finite_rings - sage: type(I) # optional - sage.rings.finite_rings + sage: R. = GF(5)[] + sage: I = R * (x^2 + 3) + sage: type(I) You can also pass in a specific ideal type:: @@ -163,11 +163,11 @@ def Ideal(*args, **kwds): sage: J = R.ideal([2*x + 2*x^2]) sage: J Principal ideal (x^2 + x) of Univariate Polynomial Ring in x over Rational Field - sage: S = R.quotient_ring(I) # optional - sage.libs.pari - sage: U = R.quotient_ring(J) # optional - sage.libs.pari + sage: S = R.quotient_ring(I) # needs sage.libs.pari + sage: U = R.quotient_ring(J) # needs sage.libs.pari sage: I == J True - sage: S == U # optional - sage.libs.pari + sage: S == U # needs sage.libs.pari True """ if len(args) == 0: @@ -295,8 +295,8 @@ def _repr_short(self): the generators are not represented from left to right but from top to bottom. This is the case, e.g., for matrices:: - sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules - sage: MS * [MS.1, 2] # optional - sage.modules + sage: MS = MatrixSpace(QQ, 2, 2) # needs sage.modules + sage: MS * [MS.1, 2] # needs sage.modules Left Ideal ( [0 1] @@ -337,9 +337,9 @@ def random_element(self, *args, **kwds): EXAMPLES:: - 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 + sage: P. = GF(5)[[]] + sage: I = P.ideal([a^2, a*b + c, c^3]) + sage: I.random_element() # random 2*a^5*c + a^2*b*c^4 + ... + O(a, b, c)^13 """ @@ -377,10 +377,10 @@ def __contains__(self, x): sage: P. = QQ[] sage: I = P * [a, b] - sage: a + b in I # optional - sage.libs.singular + sage: a + b in I # needs sage.libs.singular True sage: P2. = QQ[] - sage: x + 2*y + w*z in I # optional - sage.libs.singular + sage: x + 2*y + w*z in I False """ try: @@ -470,11 +470,11 @@ def base_ring(self): And `p`-adic numbers:: - sage: R = Zp(7, prec=10); R # optional - sage.rings.padics + sage: R = Zp(7, prec=10); R # needs sage.rings.padics 7-adic Ring with capped relative precision 10 - sage: I = 7*R; I # optional - sage.rings.padics + sage: I = 7*R; I # needs sage.rings.padics Principal ideal (7 + O(7^11)) of 7-adic Ring with capped relative precision 10 - sage: I.base_ring() # optional - sage.rings.padics + sage: I.base_ring() # needs sage.rings.padics 7-adic Ring with capped relative precision 10 """ return self.ring().base_ring() @@ -486,14 +486,15 @@ def apply_morphism(self, phi): EXAMPLES:: - sage: psi = CC['x'].hom([-CC['x'].0]) # optional - sage.rings.real_mpfr - sage: J = ideal([CC['x'].0 + 1]); J # optional - sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: psi = CC['x'].hom([-CC['x'].0]) + sage: J = ideal([CC['x'].0 + 1]); J Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision - sage: psi(J) # optional - sage.rings.real_mpfr + sage: psi(J) Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision - sage: J.apply_morphism(psi) # optional - sage.rings.real_mpfr + sage: J.apply_morphism(psi) Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision @@ -510,30 +511,31 @@ def apply_morphism(self, phi): TESTS:: sage: x = polygen(ZZ) - sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_fields - sage: A = K.ideal(a) # optional - sage.rings.number_fields - sage: taus = K.embeddings(K) # optional - sage.rings.number_fields - sage: A.apply_morphism(taus[0]) # identity # optional - sage.rings.number_fields + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_fields + sage: A = K.ideal(a) # needs sage.rings.number_fields + sage: taus = K.embeddings(K) # needs sage.rings.number_fields + sage: A.apply_morphism(taus[0]) # identity # needs sage.rings.number_fields Fractional ideal (a) - sage: A.apply_morphism(taus[1]) # complex conjugation # optional - sage.rings.number_fields + sage: A.apply_morphism(taus[1]) # complex conjugation # needs sage.rings.number_fields Fractional ideal (-a) - sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1]) # optional - sage.rings.number_fields + sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1]) # needs sage.rings.number_fields True :: - sage: K. = NumberField(x^2 + 5) # optional - sage.rings.number_fields - sage: B = K.ideal([2, a + 1]); B # optional - sage.rings.number_fields + sage: # needs sage.rings.number_fields + sage: K. = NumberField(x^2 + 5) + sage: B = K.ideal([2, a + 1]); B Fractional ideal (2, a + 1) - sage: taus = K.embeddings(K) # optional - sage.rings.number_fields - sage: B.apply_morphism(taus[0]) # identity # optional - sage.rings.number_fields + sage: taus = K.embeddings(K) + sage: B.apply_morphism(taus[0]) # identity Fractional ideal (2, a + 1) Since 2 is totally ramified, complex conjugation fixes it:: - sage: B.apply_morphism(taus[1]) # complex conjugation # optional - sage.rings.number_fields + sage: B.apply_morphism(taus[1]) # complex conjugation # needs sage.rings.number_fields Fractional ideal (2, a + 1) - sage: taus[1](B) # optional - sage.rings.number_fields + sage: taus[1](B) # needs sage.rings.number_fields Fractional ideal (2, a + 1) """ from sage.categories.morphism import is_Morphism @@ -589,12 +591,12 @@ def ring(self): sage: I = R.ideal(x^2 - 3) sage: I.ring() Univariate Polynomial Ring in x over Rational Field - sage: Rbar = R.quotient(I, names='a') # optional - sage.libs.pari - sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S # optional - sage.libs.pari + sage: Rbar = R.quotient(I, names='a') # needs sage.libs.pari + sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S # needs sage.libs.pari Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 - sage: J = S.ideal(y^2 + 1) # optional - sage.libs.pari - sage: J.ring() # optional - sage.libs.pari + sage: J = S.ideal(y^2 + 1) # needs sage.libs.pari + sage: J.ring() # needs sage.libs.pari Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 """ @@ -699,16 +701,16 @@ def is_maximal(self): sage: R = ZZ sage: I = R.ideal(7) - sage: I.is_maximal() # optional - sage.libs.pari + sage: I.is_maximal() True - sage: R.ideal(16).is_maximal() # optional - sage.libs.pari + sage: R.ideal(16).is_maximal() False sage: S = Integers(8) - sage: S.ideal(0).is_maximal() # optional - sage.libs.pari + sage: S.ideal(0).is_maximal() False - sage: S.ideal(2).is_maximal() # optional - sage.libs.pari + sage: S.ideal(2).is_maximal() True - sage: S.ideal(4).is_maximal() # optional - sage.libs.pari + sage: S.ideal(4).is_maximal() False """ from sage.rings.integer_ring import ZZ @@ -744,28 +746,29 @@ def is_primary(self, P=None): sage: R. = QQ[] sage: I = R.ideal([x^2, x*y]) - sage: I.is_primary() # optional - sage.libs.singular + sage: I.is_primary() # needs sage.libs.singular False - sage: J = I.primary_decomposition()[1]; J # optional - sage.libs.singular + sage: J = I.primary_decomposition()[1]; J # needs sage.libs.singular Ideal (y, x^2) of Multivariate Polynomial Ring in x, y over Rational Field - sage: J.is_primary() # optional - sage.libs.singular + sage: J.is_primary() # needs sage.libs.singular True - sage: J.is_prime() # optional - sage.libs.singular + sage: J.is_prime() # needs sage.libs.singular False Some examples from the Macaulay2 documentation:: - 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.libs.singular sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = GF(101)[] + sage: I = R.ideal([y^6]) + sage: I.is_primary() # needs sage.libs.singular True - sage: I.is_primary(R.ideal([y])) # optional - sage.libs.singular sage.rings.finite_rings + sage: I.is_primary(R.ideal([y])) # needs sage.libs.singular True - sage: I = R.ideal([x^4, y^7]) # optional - sage.libs.singular sage.rings.finite_rings - sage: I.is_primary() # optional - sage.libs.singular sage.rings.finite_rings + sage: I = R.ideal([x^4, y^7]) + sage: I.is_primary() # needs sage.libs.singular True - sage: I = R.ideal([x*y, y^2]) # optional - sage.libs.singular sage.rings.finite_rings - sage: I.is_primary() # optional - sage.libs.singular sage.rings.finite_rings + sage: I = R.ideal([x*y, y^2]) + sage: I.is_primary() # needs sage.libs.singular False .. NOTE:: @@ -804,24 +807,24 @@ def is_prime(self): sage: R. = QQ[] sage: I = R.ideal([x, y]) - sage: I.is_prime() # a maximal ideal # optional - sage.libs.singular + sage: I.is_prime() # a maximal ideal # needs sage.libs.singular True sage: I = R.ideal([x^2 - y]) - sage: I.is_prime() # a non-maximal prime ideal # optional - sage.libs.singular + sage: I.is_prime() # a non-maximal prime ideal # needs sage.libs.singular True sage: I = R.ideal([x^2, y]) - sage: I.is_prime() # a non-prime primary ideal # optional - sage.libs.singular + sage: I.is_prime() # a non-prime primary ideal # needs sage.libs.singular False sage: I = R.ideal([x^2, x*y]) - sage: I.is_prime() # a non-prime non-primary ideal # optional - sage.libs.singular + sage: I.is_prime() # a non-prime non-primary ideal # needs sage.libs.singular False sage: S = Integers(8) - sage: S.ideal(0).is_prime() # optional - sage.libs.singular + sage: S.ideal(0).is_prime() False - sage: S.ideal(2).is_prime() # optional - sage.libs.singular + sage: S.ideal(2).is_prime() True - sage: S.ideal(4).is_prime() # optional - sage.libs.singular + sage: S.ideal(4).is_prime() False Note that this method is not implemented for all rings where it @@ -892,7 +895,7 @@ def embedded_primes(self): sage: R. = QQ[] sage: I = R.ideal(x^2, x*y) - sage: I.embedded_primes() # optional - sage.libs.singular + sage: I.embedded_primes() # needs sage.libs.singular [Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational Field] """ # by definition, embedded primes are associated primes that @@ -960,20 +963,20 @@ def is_trivial(self): :: sage: I = QQ['x', 'y'].ideal(-5) - sage: I.is_trivial() # optional - sage.libs.singular + sage: I.is_trivial() # needs sage.libs.singular True :: - sage: I = CC['x'].ideal(0) # optional - sage.rings.real_mpfr - sage: I.is_trivial() # optional - sage.rings.real_mpfr + sage: I = CC['x'].ideal(0) # needs sage.rings.real_mpfr + sage: I.is_trivial() # needs sage.rings.real_mpfr True This test addresses issue :trac:`20514`:: sage: R = QQ['x', 'y'] sage: I = R.ideal(R.gens()) - sage: I.is_trivial() # optional - sage.libs.singular + sage: I.is_trivial() # needs sage.libs.singular False """ return self.is_zero() or self == self.ring().unit_ideal() @@ -1118,9 +1121,9 @@ def norm(self): EXAMPLES:: - 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 + sage: R. = GF(8, names='a')[] # needs sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # needs sage.rings.finite_rings + sage: I.norm() # needs 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 """ @@ -1142,9 +1145,9 @@ def absolute_norm(self): EXAMPLES:: - 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 + sage: R. = GF(9, names='a')[] # needs sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # needs sage.rings.finite_rings + sage: I.absolute_norm() # needs sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1178,11 +1181,11 @@ def _macaulay2_init_(self, macaulay2=None): Field ideals generated from the polynomial ring over two variables in the 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 + 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 # optional - sage.rings.finite_rings + sage: macaulay2(I) # optional - macaulay2 # needs sage.rings.finite_rings 2 2 ideal (x + x, y + y) @@ -1229,7 +1232,7 @@ def free_resolution(self, *args, **kwds): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^4 + 3*x^2 + 2]) - sage: I.free_resolution() # optional - sage.modules + sage: I.free_resolution() # needs sage.modules S^1 <-- S^1 <-- 0 """ if not self.is_principal(): @@ -1248,7 +1251,7 @@ def graded_free_resolution(self, *args, **kwds): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^3]) - sage: I.graded_free_resolution() # optional - sage.modules + sage: I.graded_free_resolution() # needs sage.modules S(0) <-- S(-3) <-- 0 """ from sage.homology.graded_resolution import GradedFiniteFreeResolution_free_module @@ -1575,18 +1578,18 @@ def is_prime(self): EXAMPLES:: - sage: ZZ.ideal(2).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(2).is_prime() True - sage: ZZ.ideal(-2).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(-2).is_prime() True - sage: ZZ.ideal(4).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(4).is_prime() False - sage: ZZ.ideal(0).is_prime() # optional - sage.libs.pari + sage: ZZ.ideal(0).is_prime() True sage: R. = QQ[] - sage: P = R.ideal(x^2 + 1); P # optional - sage.libs.pari + sage: P = R.ideal(x^2 + 1); P Principal ideal (x^2 + 1) of Univariate Polynomial Ring in x over Rational Field - sage: P.is_prime() # optional - sage.libs.pari + sage: P.is_prime() # needs sage.libs.pari True In fields, only the zero ideal is prime:: @@ -1616,18 +1619,19 @@ def is_maximal(self): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: p = R.ideal(t^2 + 2) + sage: p.is_maximal() True - sage: p = R.ideal(t^2 + 1) # optional - sage.rings.finite_rings - sage: p.is_maximal() # optional - sage.rings.finite_rings + sage: p = R.ideal(t^2 + 1) + sage: p.is_maximal() False - sage: p = R.ideal(0) # optional - sage.rings.finite_rings - sage: p.is_maximal() # optional - sage.rings.finite_rings + sage: p = R.ideal(0) + sage: p.is_maximal() False - sage: p = R.ideal(1) # optional - sage.rings.finite_rings - sage: p.is_maximal() # optional - sage.rings.finite_rings + sage: p = R.ideal(1) + sage: p.is_maximal() False """ if not self.ring().is_field() and self.is_zero(): @@ -1647,30 +1651,30 @@ def residue_field(self): sage: P = ZZ.ideal(61); P Principal ideal (61) of Integer Ring - sage: F = P.residue_field(); F # optional - sage.libs.pari + sage: F = P.residue_field(); F # needs sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi # optional - sage.libs.pari + sage: pi = F.reduction_map(); pi # needs sage.libs.pari Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) # optional - sage.libs.pari + sage: pi(123/234) # needs sage.libs.pari 6 - sage: pi(1/61) # optional - sage.libs.pari + sage: pi(1/61) # needs sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift # optional - sage.libs.pari + sage: lift = F.lift_map(); lift # needs sage.libs.pari Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) # optional - sage.libs.pari + sage: lift(F(12345/67890)) # needs sage.libs.pari 33 sage: (12345/67890) % 61 33 TESTS:: - sage: ZZ.ideal(96).residue_field() # optional - sage.libs.pari + sage: ZZ.ideal(96).residue_field() Traceback (most recent call last): ... ValueError: The ideal (Principal ideal (96) of Integer Ring) is not prime @@ -1679,9 +1683,9 @@ def residue_field(self): sage: R. = QQ[] sage: I = R.ideal(x^2 + 1) - sage: I.is_prime() # optional - sage.libs.pari + sage: I.is_prime() # needs sage.libs.pari True - sage: I.residue_field() # optional - sage.libs.pari + sage: I.residue_field() Traceback (most recent call last): ... TypeError: residue fields only supported for polynomial rings over finite fields. @@ -1707,8 +1711,8 @@ def __repr__(self): sage: from sage.rings.ideal import Ideal_fractional sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field - sage: Ideal_fractional(K, [a]) # indirect doctest # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field + sage: Ideal_fractional(K, [a]) # indirect doctest # needs sage.rings.number_field Fractional ideal (a) of Number Field in a with defining polynomial x^2 + 1 """ return "Fractional ideal %s of %s"%(self._repr_short(), self.ring()) @@ -1744,19 +1748,19 @@ def Cyclic(R, n=None, homog=False, singular=None): rationals:: sage: P. = PolynomialRing(QQ, 3, order='lex') - sage: I = sage.rings.ideal.Cyclic(P); I # optional - sage.libs.singular + sage: I = sage.rings.ideal.Cyclic(P); I # needs 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 + sage: I.groebner_basis() # needs 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) # optional - sage.libs.singular - sage: B = I.groebner_basis() # optional - sage.libs.singular - sage: len(B) # optional - sage.libs.singular + sage: I = sage.rings.ideal.Cyclic(R, 6) # needs sage.libs.singular + sage: B = I.groebner_basis() # needs sage.libs.singular + sage: len(B) # needs sage.libs.singular 45 """ from .rational_field import RationalField @@ -1802,14 +1806,14 @@ def Katsura(R, n=None, homog=False, singular=None): EXAMPLES:: sage: P. = PolynomialRing(QQ, 3) - sage: I = sage.rings.ideal.Katsura(P, 3); I # optional - sage.libs.singular + sage: I = sage.rings.ideal.Katsura(P, 3); I # needs 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") # optional - sage.libs.singular - sage: J = sage.rings.ideal.Katsura(Q,1); J # optional - sage.libs.singular + sage: Q. = PolynomialRing(QQ, implementation="singular") # needs sage.libs.singular + sage: J = sage.rings.ideal.Katsura(Q,1); J # needs sage.libs.singular Ideal (x - 1) of Multivariate Polynomial Ring in x over Rational Field """ from .rational_field import RationalField @@ -1849,15 +1853,15 @@ 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) # optional - sage.rings.finite_rings - sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + 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 Another, similar example:: - 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 + sage: Q. = PolynomialRing(GF(2^4, name='alpha'), 4) # needs sage.rings.finite_rings + sage: J = sage.rings.ideal.FieldIdeal(Q); J # needs 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 diff --git a/src/sage/rings/ideal_monoid.py b/src/sage/rings/ideal_monoid.py index 01193661aae..ee3ac892b8f 100644 --- a/src/sage/rings/ideal_monoid.py +++ b/src/sage/rings/ideal_monoid.py @@ -3,8 +3,8 @@ WARNING: This is used by some rings that are not commutative! :: - sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules - sage: type(MS.ideal(MS.one()).parent()) # optional - sage.modules + sage: MS = MatrixSpace(QQ, 3, 3) # needs sage.modules + sage: type(MS.ideal(MS.one()).parent()) # needs sage.modules """ @@ -53,9 +53,9 @@ def __init__(self, R): TESTS:: - sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: R = QuadraticField(-23, 'a') # needs sage.rings.number_field sage: from sage.rings.ideal_monoid import IdealMonoid - sage: M = IdealMonoid(R); M # indirect doctest # optional - sage.rings.number_field + sage: M = IdealMonoid(R); M # indirect doctest # needs sage.rings.number_field Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I @@ -63,8 +63,8 @@ def __init__(self, R): 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) # needs sage.modules + sage: MS.ideal(MS.one()).parent().category() # needs sage.modules Category of monoids """ self.__R = R @@ -81,9 +81,9 @@ def _repr_(self): TESTS:: - sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: R = QuadraticField(-23, 'a') # needs sage.rings.number_field sage: from sage.rings.ideal_monoid import IdealMonoid - sage: M = IdealMonoid(R); M._repr_() # optional - sage.rings.number_field + sage: M = IdealMonoid(R); M._repr_() # needs sage.rings.number_field 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I' """ @@ -95,9 +95,9 @@ def ring(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: R = QuadraticField(-23, 'a') # needs 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 + sage: M = IdealMonoid(R); M.ring() is R # needs sage.rings.number_field True """ return self.__R @@ -108,12 +108,13 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: R. = QuadraticField(-23) # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: R. = QuadraticField(-23) 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 + sage: M = IdealMonoid(R) + sage: M(a) # indirect doctest Fractional ideal (a) - sage: M([a-4, 13]) # optional - sage.rings.number_field + sage: M([a-4, 13]) Fractional ideal (13, 1/2*a + 9/2) """ try: @@ -137,15 +138,16 @@ def _coerce_map_from_(self, x): EXAMPLES:: - 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 + sage: # needs sage.rings.number_field + sage: R = QuadraticField(-23, 'a') + sage: M = R.ideal_monoid() + sage: M.has_coerce_map_from(R) # indirect doctest True - sage: M.has_coerce_map_from(QQ.ideal_monoid()) # optional - sage.rings.number_field + sage: M.has_coerce_map_from(QQ.ideal_monoid()) True - sage: M.has_coerce_map_from(Zmod(6)) # optional - sage.rings.number_field + sage: M.has_coerce_map_from(Zmod(6)) False - sage: M.has_coerce_map_from(loads(dumps(M))) # optional - sage.rings.number_field + sage: M.has_coerce_map_from(loads(dumps(M))) True """ if isinstance(x, IdealMonoid_c): @@ -159,13 +161,14 @@ def __eq__(self, other): EXAMPLES:: - 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 + sage: # needs sage.rings.number_field + sage: R = QuadraticField(-23, 'a') + sage: M = R.ideal_monoid() + sage: M == QQ False - sage: M == 17 # optional - sage.rings.number_field + sage: M == 17 False - sage: M == R.ideal_monoid() # optional - sage.rings.number_field + sage: M == R.ideal_monoid() True """ if not isinstance(other, IdealMonoid_c): @@ -179,13 +182,14 @@ def __ne__(self, other): EXAMPLES:: - 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 + sage: # needs sage.rings.number_field + sage: R = QuadraticField(-23, 'a') + sage: M = R.ideal_monoid() + sage: M != QQ True - sage: M != 17 # optional - sage.rings.number_field + sage: M != 17 True - sage: M != R.ideal_monoid() # optional - sage.rings.number_field + sage: M != R.ideal_monoid() False """ return not (self == other) @@ -196,13 +200,14 @@ def __hash__(self): EXAMPLES:: - 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 + sage: # needs sage.rings.number_field + sage: R = QuadraticField(-23, 'a') + sage: M = R.ideal_monoid() + sage: hash(M) == hash(QQ) False - sage: hash(M) == 17 # optional - sage.rings.number_field + sage: hash(M) == 17 False - sage: hash(M) == hash(R.ideal_monoid()) # optional - sage.rings.number_field + sage: hash(M) == hash(R.ideal_monoid()) 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 2d812f5dd1c..19b52f7b242 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]) # optional - sage.modules - sage: m.rows() # optional - sage.modules + sage: m = Matrix([Infinity]) # needs sage.modules + sage: m.rows() # needs sage.modules [(+Infinity)] """ #***************************************************************************** @@ -290,7 +290,7 @@ def _maxima_init_(self): """ TESTS:: - sage: maxima(-oo) # optional - sage.symbolic + sage: maxima(-oo) # needs sage.symbolic minf sage: [x._maxima_init_() for x in [unsigned_infinity, oo, -oo]] ['inf', 'inf', 'minf'] @@ -306,7 +306,7 @@ def _fricas_init_(self): sage: fricas(-oo) # optional - fricas - infinity - sage: [x._fricas_init_() for x in [unsigned_infinity, oo, -oo]] # optional - fricas + sage: [x._fricas_init_() for x in [unsigned_infinity, oo, -oo]] ['%infinity', '%plusInfinity', '%minusInfinity'] sage: [fricas(x) for x in [unsigned_infinity, oo, -oo]] # optional - fricas [infinity, + infinity, - infinity] @@ -324,9 +324,9 @@ def __pari__(self): EXAMPLES:: - sage: pari(-oo) # optional - sage.libs.pari + sage: pari(-oo) # needs sage.libs.pari -oo - sage: pari(oo) # optional - sage.libs.pari + sage: pari(oo) # needs sage.libs.pari +oo """ from sage.libs.pari.all import pari @@ -472,7 +472,7 @@ def _div_(self, other): Traceback (most recent call last): ... ValueError: unsigned oo times smaller number not defined - sage: SR(infinity) / unsigned_infinity # optional - sage.symbolic + sage: SR(infinity) / unsigned_infinity # needs sage.symbolic Traceback (most recent call last): ... RuntimeError: indeterminate expression: 0 * infinity encountered. @@ -490,7 +490,7 @@ def __float__(self): +infinity sage: float(infinity) # random +infinity - sage: CDF(infinity) + sage: CDF(infinity) # needs sage.rings.complex_double +infinity sage: infinity.__float__() # random +infinity @@ -499,7 +499,7 @@ def __float__(self): -infinity sage: float(-infinity) # random -inf - sage: CDF(-infinity) + sage: CDF(-infinity) # needs sage.rings.complex_double -infinity sage: (-infinity).__float__() # random -inf @@ -568,8 +568,8 @@ def __init__(self): Sage can understand SymPy's complex infinity (:trac:`17493`):: - sage: import sympy # optional - sympy - sage: SR(sympy.zoo) # optional - sympy + sage: import sympy # needs sympy + sage: SR(sympy.zoo) # needs sympy Infinity Some equality checks:: @@ -676,7 +676,7 @@ def _element_constructor_(self, x): sage: UnsignedInfinityRing(2) # indirect doctest A number less than infinity - sage: UnsignedInfinityRing(I) # optional - sage.rings.number_field + sage: UnsignedInfinityRing(I) # needs sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(unsigned_infinity) Infinity @@ -684,31 +684,31 @@ def _element_constructor_(self, x): Infinity sage: UnsignedInfinityRing(-oo) Infinity - sage: K. = QuadraticField(3) # optional - sage.rings.number_field - sage: UnsignedInfinityRing(a) # optional - sage.rings.number_field + sage: K. = QuadraticField(3) # needs sage.rings.number_field + sage: UnsignedInfinityRing(a) # needs sage.rings.number_field A number less than infinity - sage: UnsignedInfinityRing(a - 2) # optional - sage.rings.number_field + sage: UnsignedInfinityRing(a - 2) # needs sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(RDF(oo)), UnsignedInfinityRing(RDF(-oo)) (Infinity, Infinity) - sage: UnsignedInfinityRing(RR(oo)), UnsignedInfinityRing(RR(-oo)) # optional - sage.rings.real_mpfr + sage: UnsignedInfinityRing(RR(oo)), UnsignedInfinityRing(RR(-oo)) (Infinity, Infinity) - sage: UnsignedInfinityRing(CDF(oo)), UnsignedInfinityRing(CDF(-oo)) + sage: UnsignedInfinityRing(CDF(oo)), UnsignedInfinityRing(CDF(-oo)) # needs sage.rings.complex_double (Infinity, Infinity) - sage: UnsignedInfinityRing(CC(oo)), UnsignedInfinityRing(CC(-oo)) # optional - sage.rings.real_mpfr + sage: UnsignedInfinityRing(CC(oo)), UnsignedInfinityRing(CC(-oo)) # needs sage.rings.real_mpfr (Infinity, Infinity) sage: UnsignedInfinityRing(RIF(oo)), UnsignedInfinityRing(RIF(-oo)) (Infinity, Infinity) sage: UnsignedInfinityRing(float('+inf')), UnsignedInfinityRing(float('-inf')) (Infinity, Infinity) - sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) # optional - sage.symbolic + sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) # needs sage.symbolic (Infinity, Infinity) The following rings have a ``is_infinity`` method:: sage: RR(oo).is_infinity() True - sage: SR(oo).is_infinity() # optional - sage.symbolic + sage: SR(oo).is_infinity() # needs sage.symbolic True """ # Lazy elements can wrap infinity or not, unwrap first @@ -746,13 +746,13 @@ def _coerce_map_from_(self, R): sage: UnsignedInfinityRing.has_coerce_map_from(int) # indirect doctest True - sage: UnsignedInfinityRing.has_coerce_map_from(CC) # optional - sage.rings.real_mpfr + sage: UnsignedInfinityRing.has_coerce_map_from(CC) # needs sage.rings.real_mpfr True - sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) # optional - sage.rings.number_field + sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) # needs sage.rings.number_field True - sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) # optional - sage.modules + sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) # needs sage.modules False - sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) # optional - sage.groups + sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) # needs sage.groups False """ return isinstance(R, Ring) or R in (int, float, complex) @@ -942,12 +942,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy # optional - sympy - sage: SR(unsigned_infinity)._sympy_() # optional - sympy + sage: import sympy # needs sympy + sage: SR(unsigned_infinity)._sympy_() # needs sympy zoo - sage: gamma(-3)._sympy_() is sympy.factorial(-2) # optional - sympy + sage: gamma(-3)._sympy_() is sympy.factorial(-2) # needs sympy True - sage: gamma(-3) is sympy.factorial(-2)._sage_() # optional - sympy + sage: gamma(-3) is sympy.factorial(-2)._sage_() # needs sympy True """ import sympy @@ -983,7 +983,7 @@ def is_Infinite(x): True sage: sage.rings.infinity.is_Infinite(3) False - sage: sage.rings.infinity.is_Infinite(RR(infinity)) # optional - sage.rings.real_mpfr + sage: sage.rings.infinity.is_Infinite(RR(infinity)) False sage: sage.rings.infinity.is_Infinite(ZZ) False @@ -1130,43 +1130,43 @@ def _element_constructor_(self, x): sage: [InfinityRing(a) for a in [-2..2]] [A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number] - sage: K. = QuadraticField(3) # optional - sage.rings.number_field - sage: InfinityRing(a) # optional - sage.rings.number_field + sage: K. = QuadraticField(3) # needs sage.rings.number_field + sage: InfinityRing(a) # needs sage.rings.number_field A positive finite number - sage: InfinityRing(a - 2) # optional - sage.rings.number_field + sage: InfinityRing(a - 2) # needs sage.rings.number_field A negative finite number sage: InfinityRing(RDF(oo)), InfinityRing(RDF(-oo)) (+Infinity, -Infinity) - sage: InfinityRing(RR(oo)), InfinityRing(RR(-oo)) # optional - sage.rings.real_mpfr + sage: InfinityRing(RR(oo)), InfinityRing(RR(-oo)) (+Infinity, -Infinity) sage: InfinityRing(RIF(oo)), InfinityRing(RIF(-oo)) (+Infinity, -Infinity) sage: InfinityRing(float('+inf')), InfinityRing(float('-inf')) (+Infinity, -Infinity) - sage: InfinityRing(SR(oo)), InfinityRing(SR(-oo)) # optional - sage.symbolic + sage: InfinityRing(SR(oo)), InfinityRing(SR(-oo)) # needs sage.symbolic (+Infinity, -Infinity) The following rings have ``is_positive_infinity`` / ``is_negative_infinity`` methods:: - sage: RR(oo).is_positive_infinity(), RR(-oo).is_negative_infinity() # optional - sage.rings.real_mpfr + sage: RR(oo).is_positive_infinity(), RR(-oo).is_negative_infinity() (True, True) - sage: SR(oo).is_positive_infinity(), SR(-oo).is_negative_infinity() # optional - sage.symbolic + sage: SR(oo).is_positive_infinity(), SR(-oo).is_negative_infinity() # needs sage.symbolic (True, True) Complex infinity raises an exception. This is fine (there is no coercion, so there is no promise of functoriality):: - sage: i_infinity = CC(0, oo) # optional - sage.rings.real_mpfr - sage: InfinityRing(CC(oo)), InfinityRing(CC(-oo)) # optional - sage.rings.real_mpfr + sage: i_infinity = CC(0, oo) # needs sage.rings.real_mpfr + sage: InfinityRing(CC(oo)), InfinityRing(CC(-oo)) # needs sage.rings.real_mpfr (+Infinity, -Infinity) - sage: InfinityRing(i_infinity) # optional - sage.rings.real_mpfr + sage: InfinityRing(i_infinity) # needs sage.rings.real_mpfr Traceback (most recent call last): ... ValueError: infinite but not with +/- phase - sage: InfinityRing(CDF(oo)), InfinityRing(CDF(-oo)) + sage: InfinityRing(CDF(oo)), InfinityRing(CDF(-oo)) # needs sage.rings.complex_double (+Infinity, -Infinity) - sage: InfinityRing(CDF(i_infinity)) + sage: InfinityRing(CDF(i_infinity)) # needs sage.rings.complex_double sage.rings.real_mpfr Traceback (most recent call last): ... ValueError: infinite but not with +/- phase @@ -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) # optional - sage.rings.number_field + sage: InfinityRing.has_coerce_map_from(AA) # needs 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) # optional - sage.rings.number_field + sage: cm.explain(AA(3), oo, operator.lt) # needs sage.rings.number_field Coercion on left operand via Coercion map: From: Algebraic Real Field @@ -1251,9 +1251,9 @@ def _coerce_map_from_(self, R): symbolic comparisons with infinities all happen in the symbolic ring:: - sage: SR.has_coerce_map_from(InfinityRing) # optional - sage.symbolic + sage: SR.has_coerce_map_from(InfinityRing) # needs sage.symbolic True - sage: InfinityRing.has_coerce_map_from(SR) # optional - sage.symbolic + sage: InfinityRing.has_coerce_map_from(SR) # needs sage.symbolic False Complex numbers do not coerce into the infinity ring (what @@ -1261,11 +1261,11 @@ def _coerce_map_from_(self, R): be compared, so we do not have to enforce consistency when comparing with infinity either:: - sage: InfinityRing.has_coerce_map_from(CDF) + sage: InfinityRing.has_coerce_map_from(CDF) # needs sage.rings.complex_double False - sage: InfinityRing.has_coerce_map_from(CC) # optional - sage.rings.real_mpfr + sage: InfinityRing.has_coerce_map_from(CC) # needs sage.rings.real_mpfr False - sage: CC(0, oo) < CC(1) # does not coerce to infinity ring # optional - sage.rings.real_mpfr + sage: CC(0, oo) < CC(1) # does not coerce to infinity ring # needs sage.rings.real_mpfr True """ from sage.structure.coerce import parent_is_real_numerical @@ -1279,7 +1279,7 @@ def _pushout_(self, other): r""" EXAMPLES:: - sage: QQbar(-2*i)*infinity # optional - sage.rings.number_field sage.symbolic + sage: QQbar(-2*i)*infinity # needs sage.rings.number_field sage.symbolic (-I)*Infinity """ from sage.symbolic.ring import SR @@ -1480,9 +1480,9 @@ def _latex_(self): TESTS:: - sage: a = InfinityRing(pi); a # optional - sage.symbolic + sage: a = InfinityRing(pi); a # needs sage.symbolic A positive finite number - sage: a._latex_() # optional - sage.symbolic + sage: a._latex_() # needs 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 # optional - sympy - sage: bool(-oo == -sympy.oo) # optional - sympy + sage: import sympy # needs sympy + sage: bool(-oo == -sympy.oo) # needs sympy True - sage: bool(SR(-oo) == -sympy.oo) # optional - sympy + sage: bool(SR(-oo) == -sympy.oo) # needs sympy True - sage: bool((-oo)._sympy_() == -sympy.oo) # optional - sympy + sage: bool((-oo)._sympy_() == -sympy.oo) # needs sympy True """ @@ -1641,9 +1641,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(-Infinity) # optional - sage.libs.gap + sage: gap(-Infinity) # needs sage.libs.gap -infinity - sage: libgap(-Infinity) # optional - sage.libs.gap + sage: libgap(-Infinity) # needs sage.libs.gap -infinity """ return '-infinity' @@ -1724,10 +1724,10 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy # optional - sympy - sage: bool(oo == sympy.oo) # indirect doctest # optional - sympy + sage: import sympy # needs sympy + sage: bool(oo == sympy.oo) # indirect doctest # needs sympy True - sage: bool(SR(oo) == sympy.oo) # optional - sage.symbolic sympy + sage: bool(SR(oo) == sympy.oo) # needs sympy sage.symbolic True """ import sympy @@ -1739,9 +1739,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(+Infinity) # optional - sage.libs.gap + sage: gap(+Infinity) # needs sage.libs.gap infinity - sage: libgap(+Infinity) # optional - sage.libs.gap + sage: libgap(+Infinity) # needs sage.libs.gap infinity """ return 'infinity' @@ -1769,8 +1769,8 @@ def test_comparison(ring): EXAMPLES:: sage: from sage.rings.infinity import test_comparison - sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] # optional - sage.rings.real_mpfr - sage: for R in rings: # optional - sage.rings.real_mpfr + sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] # needs sage.rings.real_mpfr + sage: for R in rings: # needs sage.rings.real_mpfr ....: print('testing {}'.format(R)) ....: test_comparison(R) testing Integer Ring @@ -1780,19 +1780,20 @@ def test_comparison(ring): testing Real Double Field testing Real Lazy Field testing Real Interval Field with 53 bits of precision - sage: test_comparison(AA) # optional - sage.rings.number_field + sage: test_comparison(AA) # needs sage.rings.number_field Comparison with number fields does not work:: - 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 + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3) # needs sage.rings.number_field + sage: (-oo < 1 + sqrt3) and (1 + sqrt3 < oo) # known bug # needs 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 # optional - sage.symbolic + sage: test_comparison(SR) # known bug # needs 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 c2414413fda..3e9fe6ce885 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -24,7 +24,7 @@ Add an integer and a rational number:: Add an integer and a complex number:: - sage: b = ComplexField().0 + 1.5 + sage: b = ComplexField().0 + 1.5 # needs sage.rings.real_mpfr sage: loads((a + b).dumps()) == a + b True @@ -64,8 +64,8 @@ Return version of this integer in the multi-precision floating real field `\RR`:: sage: n = 9390823 - sage: RR = RealField(200) - sage: RR(n) + sage: RR = RealField(200) # needs sage.rings.real_mpfr + sage: RR(n) # needs sage.rings.real_mpfr 9.3908230000000000000000000000000000000000000000000000000000e6 AUTHORS: @@ -421,9 +421,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Conversion from PARI:: - sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari + sage: Integer(pari('-10380104371593008048799446356441519384')) # needs sage.libs.pari -10380104371593008048799446356441519384 - sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari + sage: Integer(pari('Pol([-3])')) # needs sage.libs.pari -3 Conversion from gmpy2:: @@ -459,11 +459,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))) # needs 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)) # needs sage.rings.number_field 2 - sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari + sage: ZZ(pari('Mod(-3,7)')) # needs sage.libs.pari 4 sage: ZZ('sage') Traceback (most recent call last): @@ -475,10 +475,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): '3b' sage: ZZ( ZZ(5).digits(3) , 3) 5 - sage: import numpy # optional - numpy - sage: ZZ(numpy.int64(7^7)) # optional - numpy + sage: import numpy # needs numpy + sage: ZZ(numpy.int64(7^7)) # needs numpy 823543 - sage: ZZ(numpy.ubyte(-7)) # optional - numpy + sage: ZZ(numpy.ubyte(-7)) # needs numpy 249 sage: ZZ(True) 1 @@ -494,8 +494,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: k = GF(2) # optional - sage.rings.finite_rings - sage: ZZ((k(0),k(1)), 2) # optional - sage.rings.finite_rings + sage: k = GF(2) + sage: ZZ((k(0),k(1)), 2) 2 :: @@ -531,40 +531,40 @@ 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)) # needs sage.libs.pari -3 - sage: ZZ(pari("-3.0")) # optional - sage.libs.pari + sage: ZZ(pari("-3.0")) # needs sage.libs.pari -3 - sage: ZZ(pari("-3.5")) # optional - sage.libs.pari + sage: ZZ(pari("-3.5")) # needs 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")) # needs 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")) # needs sage.libs.pari 100000000000000000000000000000000000000000000000000 - sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari + sage: ZZ(pari("Pol(3)")) # needs sage.libs.pari 3 - sage: ZZ(GF(3^20,'t')(1)) # optional - sage.rings.finite_rings + sage: ZZ(GF(3^20,'t')(1)) # needs sage.rings.finite_rings 1 - sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari sage.rings.finite_rings + sage: ZZ(pari(GF(3^20,'t')(1))) # needs 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) # needs sage.rings.number_field + sage: ZZ(a^2) # needs sage.rings.number_field -3 - sage: ZZ(pari(a)^2) # optional - sage.libs.pari sage.rings.number_field + sage: ZZ(pari(a)^2) # needs 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 # needs 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.rings.padics + sage: ZZ(pari(Qp(11)(11^-7))) # needs sage.libs.pari sage.rings.padics Traceback (most recent call last): ... TypeError: cannot convert p-adic with negative valuation to an integer @@ -580,23 +580,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Test comparisons with numpy types (see :trac:`13386` and :trac:`18076`):: - sage: import numpy # optional - numpy - sage: numpy.int8('12') == 12 # optional - numpy + sage: import numpy # needs numpy + sage: numpy.int8('12') == 12 # needs numpy True - sage: 12 == numpy.int8('12') # optional - numpy + sage: 12 == numpy.int8('12') # needs numpy True - sage: float('15') == 15 # optional - numpy + sage: float('15') == 15 True - sage: 15 == float('15') # optional - numpy + sage: 15 == float('15') True Test underscores as digit separators (PEP 515, https://www.python.org/dev/peps/pep-0515/):: - sage: Integer('1_3') # optional - numpy + sage: Integer('1_3') 13 - sage: Integer(b'1_3') # optional - numpy + sage: Integer(b'1_3') 13 """ # TODO: All the code below should somehow be in an external @@ -765,8 +765,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: n = -10 - sage: R = GF(17) # optional - sage.rings.finite_rings - sage: n._im_gens_(R, [R(1)]) # optional - sage.rings.finite_rings + sage: R = GF(17) + sage: n._im_gens_(R, [R(1)]) 7 """ return codomain.coerce(self) @@ -1003,9 +1003,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: ex = SR(ZZ(7)); ex # optional - sage.symbolic + sage: ex = SR(ZZ(7)); ex # needs sage.symbolic 7 - sage: parent(ex) # optional - sage.symbolic + sage: parent(ex) # needs sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -1016,9 +1016,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 5; n._sympy_() # optional - sympy + sage: n = 5; n._sympy_() # needs sympy 5 - sage: n = -5; n._sympy_() # optional - sympy + sage: n = -5; n._sympy_() # needs sympy -5 """ import sympy @@ -2004,7 +2004,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() # needs sage.rings.number_field Traceback (most recent call last): ... ZeroDivisionError: division by zero in algebraic field @@ -2109,7 +2109,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 1 sage: 2^-0 1 - sage: (-1)^(1/3) # optional - sage.symbolic + sage: (-1)^(1/3) # needs sage.symbolic (-1)^(1/3) For consistency with Python and MPFR, 0^0 is defined to be 1 in @@ -2136,30 +2136,31 @@ 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 # needs sage.symbolic 2^x sage: 2^1.5 # real number 2.82842712474619 sage: 2^float(1.5) # python float abs tol 3e-16 2.8284271247461903 - sage: 2^I # complex number + sage: 2^I # complex number # needs sage.symbolic 2^I 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 # needs sage.symbolic 2^(-cos(x) + sin(x)) - sage: f(x=3) + sage: f(x=3) # needs sage.symbolic 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: # needs sage.symbolic + sage: x, y, z = var('x,y,z') + sage: 2^(x + y + z) 2^(x + y + z) - sage: 2^(1/2) # optional - sage.symbolic + sage: 2^(1/2) sqrt(2) - sage: 2^(-1/2) # optional - sage.symbolic + sage: 2^(-1/2) 1/2*sqrt(2) TESTS:: @@ -2651,9 +2652,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: sage: x = 3^100000 - sage: RR(log(RR(x), 3)) + sage: RR(log(RR(x), 3)) # needs sage.symbolic 100000.000000000 - sage: RR(log(RR(x + 100000), 3)) + sage: RR(log(RR(x + 100000), 3)) # needs sage.symbolic 100000.000000000 :: @@ -2764,15 +2765,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: Integer(124).log(5) # optional - sage.symbolic + sage: Integer(124).log(5) # needs sage.symbolic log(124)/log(5) - sage: Integer(124).log(5, 100) # optional - sage.rings.real_mpfr + sage: Integer(124).log(5, 100) # needs sage.rings.real_mpfr 2.9950093311241087454822446806 sage: Integer(125).log(5) 3 - sage: Integer(125).log(5, prec=53) # optional - sage.rings.real_mpfr + sage: Integer(125).log(5, prec=53) # needs sage.rings.real_mpfr 3.00000000000000 - sage: log(Integer(125)) # optional - sage.symbolic + sage: log(Integer(125)) # needs sage.symbolic 3*log(5) For extremely large numbers, this works:: @@ -2785,28 +2786,28 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): works in a reasonable amount of time for this ``x``:: sage: x = 3^100000 - sage: log(x) # optional - sage.symbolic + sage: log(x) # needs sage.symbolic log(1334971414230...5522000001) But approximations are probably more useful in this case, and work to as high a precision as we desire:: - sage: x.log(3, 53) # default precision for RealField # optional - sage.rings.real_mpfr + sage: x.log(3, 53) # default precision for RealField # needs sage.rings.real_mpfr 100000.000000000 - sage: (x + 1).log(3, 53) # optional - sage.rings.real_mpfr + sage: (x + 1).log(3, 53) # needs sage.rings.real_mpfr 100000.000000000 - sage: (x + 1).log(3, 1000) # optional - sage.rings.real_mpfr + sage: (x + 1).log(3, 1000) # needs sage.rings.real_mpfr 100000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 We can use non-integer bases, with default e:: - sage: x.log(2.5, prec=53) # optional - sage.rings.real_mpfr + sage: x.log(2.5, prec=53) # needs sage.rings.real_mpfr 119897.784671579 We also get logarithms of negative integers, via the symbolic ring, using the branch from `-\pi` to `\pi`:: - sage: log(-1) # optional - sage.symbolic + sage: log(-1) # needs sage.symbolic I*pi The logarithm of zero is done likewise:: @@ -2826,7 +2827,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: (-2).log(3) # optional - sage.symbolic + sage: (-2).log(3) # needs sage.symbolic (I*pi + log(2))/log(3) """ cdef int self_sgn @@ -2883,11 +2884,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: Integer(8).exp() # optional - sage.symbolic + sage: Integer(8).exp() # needs sage.symbolic e^8 - sage: Integer(8).exp(prec=100) # optional - sage.symbolic + sage: Integer(8).exp(prec=100) # needs sage.symbolic 2980.9579870417282747435920995 - sage: exp(Integer(8)) # optional - sage.symbolic + sage: exp(Integer(8)) # needs sage.symbolic e^8 For even fairly large numbers, this may not be useful. @@ -2895,9 +2896,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: sage: y = Integer(145^145) - sage: y.exp() # optional - sage.symbolic + sage: y.exp() # needs sage.symbolic e^25024207011349079210459585279553675697932183658421565260323592409432707306554163224876110094014450895759296242775250476115682350821522931225499163750010280453185147546962559031653355159703678703793369785727108337766011928747055351280379806937944746847277089168867282654496776717056860661614337004721164703369140625 - sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic + sage: y.exp(prec=53) # default RealField precision # needs sage.symbolic +infinity """ from sage.functions.all import exp @@ -2977,12 +2978,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() # optional - sage.libs.pari + sage: a.prime_divisors() # needs sage.libs.pari [73, 137, 401, 1201, 1601, 1676321, 5964848081, 129694419029057750551385771184564274499075700947656757821537291527196801] - sage: a.prime_divisors(limit=10^3) # optional - sage.libs.pari + sage: a.prime_divisors(limit=10^3) [73, 137, 401] - sage: a.prime_divisors(limit=10^7) # optional - sage.libs.pari + sage: a.prime_divisors(limit=10^7) [73, 137, 401, 1201, 1601, 1676321] """ res = [r[0] for r in self.factor(*args, **kwds)] @@ -3024,32 +3025,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() # optional - sage.libs.pari - sage: len(v) # optional - sage.libs.pari + sage: v = a.divisors() # needs sage.libs.pari + sage: len(v) # needs sage.libs.pari 172800 - sage: prod(e + 1 for p, e in factor(a)) # optional - sage.libs.pari + sage: prod(e + 1 for p, e in factor(a)) # needs sage.libs.pari 172800 - sage: all(t.divides(a) for t in v) # optional - sage.libs.pari + sage: all(t.divides(a) for t in v) # needs 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() # needs sage.libs.pari + sage: len(L) # needs sage.libs.pari 256 - sage: L[-1] == n # optional - sage.libs.pari + sage: L[-1] == n # needs sage.libs.pari True TESTS: Overflow:: - sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(64)).divisors() # needs 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() # needs sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large # 32-bit @@ -3059,8 +3060,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)) # needs sage.libs.pari + sage: for i in range(20): # long time # needs sage.libs.pari ....: try: ....: alarm(RDF.random_element(1e-3, 0.5)) ....: _ = n.divisors() @@ -3342,9 +3343,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) # needs sage.libs.pari + sage: b = Integers(a)(100) # needs sage.libs.pari + sage: a % b # needs sage.libs.pari Traceback (most recent call last): ... ArithmeticError: reduction modulo 100 not defined @@ -3440,10 +3441,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 # 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 + sage: import mpmath # needs mpmath + sage: mpmath.mp.prec = 1000 # needs mpmath + sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # needs mpmath + sage: len(str(root)) # needs mpmath 301 """ cdef Integer q = PY_NEW(Integer) @@ -3696,44 +3697,46 @@ 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: # needs sage.libs.pari + sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() 1000003 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() 1000003 - sage: n.trial_division(bound=100) # optional - sage.libs.pari + sage: n.trial_division(bound=100) 10000049000057 - sage: n.trial_division(bound=-10) # optional - sage.libs.pari + sage: n.trial_division(bound=-10) 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) Traceback (most recent call last): ... ValueError: bound must be positive - sage: ZZ(0).trial_division() # optional - sage.libs.pari + sage: ZZ(0).trial_division() 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: # needs sage.libs.pari + sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() 100003 - sage: n.trial_division(bound=10^4) # optional - sage.libs.pari + sage: n.trial_division(bound=10^4) 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari + sage: (-n).trial_division(bound=10^4) 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() 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() 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() 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() 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() 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() 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() 5 You can specify a starting point:: @@ -3859,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() # needs 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, @@ -3886,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) # needs sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 - sage: n.factor(proof=True) # optional - sage.libs.pari + sage: n.factor(proof=True) # needs sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 We factor using trial division only:: @@ -3899,15 +3902,16 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): An example where FLINT is used:: sage: n = 82862385732327628428164127822 - sage: n.factor(algorithm='flint') # optional - sage.libs.flint + sage: n.factor(algorithm='flint') # needs sage.libs.flint 2 * 3 * 11 * 13 * 41 * 73 * 22650083 * 1424602265462161 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: # needs sage.libs.pari + sage: p = next_prime(10^20) + sage: q = next_prime(10^21) + sage: n = p * q + sage: n.factor(algorithm='qsieve') doctest:... RuntimeWarning: the factorization returned by qsieve may be incomplete (the factors may not be prime) or even wrong; see qsieve? for details @@ -3915,10 +3919,11 @@ 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: # needs sage.libs.pari + sage: p = next_prime(10^15) + sage: q = next_prime(10^21) + sage: n = p * q + sage: n.factor(algorithm='ecm') 1000000000000037 * 1000000000000000000117 TESTS:: @@ -4614,13 +4619,14 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: gamma(5) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: gamma(5) 24 - sage: gamma(0) # optional - sage.symbolic + sage: gamma(0) Infinity - sage: gamma(-1) # optional - sage.symbolic + sage: gamma(-1) Infinity - sage: gamma(-2^150) # optional - sage.symbolic + sage: gamma(-2^150) Infinity """ if mpz_sgn(self.value) > 0: @@ -4810,7 +4816,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 144.perfect_power() # optional - sage.libs.pari + sage: 144.perfect_power() # needs sage.libs.pari (12, 2) sage: 1.perfect_power() (1, 1) @@ -4818,15 +4824,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): (0, 1) sage: (-1).perfect_power() (-1, 1) - sage: (-8).perfect_power() # optional - sage.libs.pari + sage: (-8).perfect_power() # needs sage.libs.pari (-2, 3) sage: (-4).perfect_power() (-4, 1) - sage: (101^29).perfect_power() # optional - sage.libs.pari + sage: (101^29).perfect_power() # needs sage.libs.pari (101, 29) - sage: (-243).perfect_power() # optional - sage.libs.pari + sage: (-243).perfect_power() # needs sage.libs.pari (-3, 5) - sage: (-64).perfect_power() # optional - sage.libs.pari + sage: (-64).perfect_power() # needs sage.libs.pari (-4, 3) TESTS:: @@ -4872,9 +4878,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: ZZ(5).global_height() + sage: ZZ(5).global_height() # needs sage.rings.real_mpfr 1.60943791243410 - sage: ZZ(-2).global_height(prec=100) + sage: ZZ(-2).global_height(prec=100) # needs sage.rings.real_mpfr 0.69314718055994530941723212146 sage: exp(_) 2.0000000000000000000000000000 @@ -5135,55 +5141,57 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 17.is_prime_power() # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: 17.is_prime_power() True - sage: 10.is_prime_power() # optional - sage.libs.pari + sage: 10.is_prime_power() False - sage: 64.is_prime_power() # optional - sage.libs.pari + sage: 64.is_prime_power() True - sage: (3^10000).is_prime_power() # optional - sage.libs.pari + sage: (3^10000).is_prime_power() True - sage: (10000).is_prime_power() # optional - sage.libs.pari + sage: (10000).is_prime_power() False - sage: (-3).is_prime_power() # optional - sage.libs.pari + sage: (-3).is_prime_power() False - sage: 0.is_prime_power() # optional - sage.libs.pari + sage: 0.is_prime_power() False - sage: 1.is_prime_power() # optional - sage.libs.pari + sage: 1.is_prime_power() False - sage: p = next_prime(10^20); p # optional - sage.libs.pari + sage: p = next_prime(10^20); p 100000000000000000039 - sage: p.is_prime_power() # optional - sage.libs.pari + sage: p.is_prime_power() True - sage: (p^97).is_prime_power() # optional - sage.libs.pari + sage: (p^97).is_prime_power() True - sage: (p + 1).is_prime_power() # optional - sage.libs.pari + sage: (p + 1).is_prime_power() False With the ``get_data`` keyword set to ``True``:: - sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: (3^100).is_prime_power(get_data=True) (3, 100) - sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari + sage: 12.is_prime_power(get_data=True) (12, 0) - sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p^97).is_prime_power(get_data=True) (100000000000000000039, 97) - sage: q = p.next_prime(); q # optional - sage.libs.pari + sage: q = p.next_prime(); q 100000000000000000129 - sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p*q).is_prime_power(get_data=True) (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() # needs 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() # needs sage.libs.pari True TESTS:: @@ -5277,26 +5285,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() # needs sage.libs.pari True sage: z = 2^31 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() False sage: z = 7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() True sage: z = -7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() False - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() True :: sage: z = 10^80 + 129 - sage: z.is_prime(proof=False) # optional - sage.libs.pari + sage: z.is_prime(proof=False) # needs sage.libs.pari True - sage: z.is_prime(proof=True) # optional - sage.libs.pari + sage: z.is_prime(proof=True) # needs sage.libs.pari True When starting Sage the arithmetic proof flag is True. We can change @@ -5305,12 +5313,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 # needs 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 # needs sage.libs.pari 1000 loops, best of 3: 573 us per loop ALGORITHM: @@ -5327,7 +5335,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)) # needs sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5390,16 +5398,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() # needs sage.libs.pari True sage: z = 2^31 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() False sage: z = 7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() True sage: z = -7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() True """ cdef Integer n = self if self >= 0 else -self @@ -5419,10 +5427,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() # needs sage.libs.pari True sage: z = 2^31 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # needs sage.libs.pari False """ return self.__pari__().ispseudoprime() @@ -5443,17 +5451,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() # needs sage.libs.pari True - sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power() # needs 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) # needs sage.libs.pari (1000...000357, 12) - sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (997^100).is_pseudoprime_power() # needs sage.libs.pari True - sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (998^100).is_pseudoprime_power() # needs sage.libs.pari False - sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari + sage: ((10^1000 + 453)^2).is_pseudoprime_power() # needs sage.libs.pari True TESTS:: @@ -5462,7 +5470,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() # needs sage.libs.pari False """ return self.is_prime_power(proof=False, get_data=get_data) @@ -5530,20 +5538,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') # needs sage.rings.number_field sage: n = 4 - sage: n.is_norm(K) # optional - sage.rings.number_field + sage: n.is_norm(K) # needs sage.rings.number_field True - sage: 5.is_norm(K) # optional - sage.rings.number_field + sage: 5.is_norm(K) # needs 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) # needs 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() # needs 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) # needs sage.rings.number_field (False, None) sage: n = 7 sage: n.is_norm(QQ, element=True) @@ -5559,9 +5567,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')) # needs sage.rings.number_field (1, 3) - sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field + sage: 7._bnfisnorm(CyclotomicField(7)) # needs sage.rings.number_field (zeta7^5 - zeta7^2, 1) """ from sage.rings.rational_field import QQ @@ -5662,11 +5670,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-163).class_number() # optional - sage.libs.pari + sage: (-163).class_number() # needs sage.libs.pari 1 - sage: (-104).class_number() # optional - sage.libs.pari + sage: (-104).class_number() # needs 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]] # needs sage.libs.pari [(85, 2), (89, 1), (93, 1), @@ -5748,8 +5756,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) # needs sage.libs.pari + sage: a / a.squarefree_part(bound=1000) # needs sage.libs.pari 49 """ cdef Integer z @@ -5796,17 +5804,18 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-37).next_probable_prime() # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: (-37).next_probable_prime() 2 - sage: (100).next_probable_prime() # optional - sage.libs.pari + sage: (100).next_probable_prime() 101 - sage: (2^512).next_probable_prime() # optional - sage.libs.pari + sage: (2^512).next_probable_prime() 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171 - sage: 0.next_probable_prime() # optional - sage.libs.pari + sage: 0.next_probable_prime() 2 - sage: 126.next_probable_prime() # optional - sage.libs.pari + sage: 126.next_probable_prime() 127 - sage: 144168.next_probable_prime() # optional - sage.libs.pari + sage: 144168.next_probable_prime() 144169 """ return Integer( self.__pari__().nextprime(True) ) @@ -5825,23 +5834,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 100.next_prime() # optional - sage.libs.pari + sage: 100.next_prime() # needs sage.libs.pari 101 - sage: (10^50).next_prime() # optional - sage.libs.pari + sage: (10^50).next_prime() # needs 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) # needs sage.libs.pari + sage: b - 2^1024 # needs sage.libs.pari 643 :: - sage: Integer(0).next_prime() # optional - sage.libs.pari + sage: Integer(0).next_prime() # needs sage.libs.pari 2 - sage: Integer(1001).next_prime() # optional - sage.libs.pari + sage: Integer(1001).next_prime() # needs sage.libs.pari 1009 """ # Use PARI to compute the next *pseudo*-prime @@ -5870,11 +5879,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 10.previous_prime() # optional - sage.libs.pari + sage: 10.previous_prime() # needs sage.libs.pari 7 - sage: 7.previous_prime() # optional - sage.libs.pari + sage: 7.previous_prime() # needs sage.libs.pari 5 - sage: 14376485.previous_prime() # optional - sage.libs.pari + sage: 14376485.previous_prime() # needs sage.libs.pari 14376463 sage: 2.previous_prime() @@ -5885,8 +5894,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) # needs sage.libs.pari + sage: 2^1024 - b # needs sage.libs.pari 105 """ if mpz_cmp_ui(self.value, 2) <= 0: @@ -5926,23 +5935,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() 3 - sage: 103.next_prime_power() # optional - sage.libs.pari + sage: 103.next_prime_power() # needs sage.libs.pari 107 - sage: 107.next_prime_power() # optional - sage.libs.pari + sage: 107.next_prime_power() 109 - sage: 2044.next_prime_power() # optional - sage.libs.pari + sage: 2044.next_prime_power() # needs 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)] [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)] # needs 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): # needs 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) @@ -5990,13 +5999,14 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3.previous_prime_power() # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: 3.previous_prime_power() 2 - sage: 103.previous_prime_power() # optional - sage.libs.pari + sage: 103.previous_prime_power() 101 - sage: 107.previous_prime_power() # optional - sage.libs.pari + sage: 107.previous_prime_power() 103 - sage: 2044.previous_prime_power() # optional - sage.libs.pari + sage: 2044.previous_prime_power() 2039 sage: 2.previous_prime_power() @@ -6006,12 +6016,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)] [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)] # needs 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): # needs 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) @@ -6080,11 +6090,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 100.is_squarefree() # optional - sage.libs.pari + sage: 100.is_squarefree() # needs sage.libs.pari False - sage: 102.is_squarefree() # optional - sage.libs.pari + sage: 102.is_squarefree() # needs sage.libs.pari True - sage: 0.is_squarefree() # optional - sage.libs.pari + sage: 0.is_squarefree() # needs sage.libs.pari False """ return self.__pari__().issquarefree() @@ -6129,11 +6139,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-4).is_fundamental_discriminant() + sage: (-4).is_fundamental_discriminant() # needs sage.libs.pari True sage: (-12).is_fundamental_discriminant() False - sage: 101.is_fundamental_discriminant() + sage: 101.is_fundamental_discriminant() # needs sage.libs.pari True TESTS:: @@ -6142,7 +6152,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): False sage: 1.is_fundamental_discriminant() False - sage: len([D for D in srange(-100,100) if D.is_fundamental_discriminant()]) + sage: len([D for D in srange(-100,100) # needs sage.libs.pari + ....: if D.is_fundamental_discriminant()]) 61 """ @@ -6163,16 +6174,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 # needs sage.libs.pari 9390823 - sage: type(m) # optional - sage.libs.pari + sage: type(m) # needs 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 # needs sage.libs.pari + sage: m % 1234567 # needs sage.libs.pari 1041334 """ @@ -6202,19 +6213,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.array([1, 2, 3]) # optional - numpy + sage: import numpy # needs numpy + sage: numpy.array([1, 2, 3]) # needs numpy array([1, 2, 3]) - sage: numpy.array([1, 2, 3]).dtype # optional - numpy + sage: numpy.array([1, 2, 3]).dtype # needs numpy dtype('int32') # 32-bit dtype('int64') # 64-bit - sage: numpy.array(2**40).dtype # optional - numpy + sage: numpy.array(2**40).dtype # needs numpy dtype('int64') - sage: numpy.array(2**400).dtype # optional - numpy + sage: numpy.array(2**400).dtype # needs numpy dtype('O') - sage: numpy.array([1,2,3,0.1]).dtype # optional - numpy + sage: numpy.array([1,2,3,0.1]).dtype # needs numpy dtype('float64') """ if mpz_fits_slong_p(self.value): @@ -6241,11 +6252,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): '117' Large integers use hex: - sage: m = 3^(2^20) # optional - magma - sage: s = m._magma_init_(magma) # optional - magma - sage: 'StringToInteger' in s # optional - magma + sage: # optional - magma + sage: m = 3^(2^20) + sage: s = m._magma_init_(magma) + sage: 'StringToInteger' in s True - sage: magma(m).sage() == m # optional - magma + sage: magma(m).sage() == m True """ if self.ndigits(2) > 10000: @@ -6377,19 +6389,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 12 sage: sqrt(Integer(144)) 12 - sage: Integer(102).sqrt() # optional - sage.symbolic + sage: Integer(102).sqrt() # needs sage.symbolic sqrt(102) :: sage: n = 2 - sage: n.sqrt(all=True) # optional - sage.symbolic + sage: n.sqrt(all=True) # needs sage.symbolic [sqrt(2), -sqrt(2)] - sage: n.sqrt(prec=10) + sage: n.sqrt(prec=10) # needs sage.rings.real_mpfr 1.4 - sage: n.sqrt(prec=100) + sage: n.sqrt(prec=100) # needs sage.rings.real_mpfr 1.4142135623730950488016887242 - sage: n.sqrt(prec=100, all=True) + sage: n.sqrt(prec=100, all=True) # needs sage.rings.real_mpfr [1.4142135623730950488016887242, -1.4142135623730950488016887242] sage: n.sqrt(extend=False) Traceback (most recent call last): @@ -6406,13 +6418,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: type(5.sqrt()) # optional - sage.symbolic + sage: type(5.sqrt()) # needs sage.symbolic - sage: type(5.sqrt(prec=53)) + sage: type(5.sqrt(prec=53)) # needs sage.rings.real_mpfr - sage: type((-5).sqrt(prec=53)) + sage: type((-5).sqrt(prec=53)) # needs sage.rings.real_mpfr - sage: type(0.sqrt(prec=53)) + sage: type(0.sqrt(prec=53)) # needs sage.rings.real_mpfr Check that :trac:`9466` and :trac:`26509` are fixed:: @@ -7030,7 +7042,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') # needs sage.libs.pari 45 sage: 10.binomial(-2) 0 @@ -7072,7 +7084,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) # needs 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 68933ce7fa5..15375a7b1df 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -245,7 +245,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): 17 sage: Z(Mod(19,23)) 19 - sage: Z(2 + 3*5 + O(5^3)) # optional - sage.rings.padics + sage: Z(2 + 3*5 + O(5^3)) # needs sage.rings.padics 17 Arbitrary numeric bases are supported; strings or list of integers @@ -394,19 +394,19 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ[sqrt(2), sqrt(3)] # optional - sage.rings.number_field sage.symbolic + sage: ZZ[sqrt(2), sqrt(3)] # needs sage.rings.number_field sage.symbolic Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field sage: ZZ['x'] Univariate Polynomial Ring in x over Integer Ring sage: ZZ['x,y'] Multivariate Polynomial Ring in x, y over Integer Ring - sage: R = ZZ[sqrt(5) + 1]; R # optional - sage.rings.number_field sage.symbolic + sage: R = ZZ[sqrt(5) + 1]; R # needs sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^2 - 2*x - 4 with a = 3.236067977499790? - sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic + sage: R.is_maximal() # needs sage.rings.number_field sage.symbolic False - sage: R = ZZ[(1 + sqrt(5))/2]; R # optional - sage.rings.number_field sage.symbolic + sage: R = ZZ[(1 + sqrt(5))/2]; R # needs sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^2 - x - 1 with a = 1.618033988749895? - sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic + sage: R.is_maximal() # needs sage.rings.number_field sage.symbolic True """ if x in self: @@ -531,7 +531,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.coerce(int(5)) # indirect doctest 5 - sage: ZZ.coerce(GF(7)(2)) # optional - sage.rings.finite_rings + sage: ZZ.coerce(GF(7)(2)) Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field of size 7 to Integer Ring @@ -553,14 +553,15 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Coercions are available from numpy integer types:: - sage: import numpy # optional - numpy - sage: ZZ.coerce(numpy.int8('1')) # optional - numpy + sage: # needs numpy + sage: import numpy + sage: ZZ.coerce(numpy.int8('1')) 1 - sage: ZZ.coerce(numpy.int32('32')) # optional - numpy + sage: ZZ.coerce(numpy.int32('32')) 32 - sage: ZZ.coerce(numpy.int64('-12')) # optional - numpy + sage: ZZ.coerce(numpy.int64('-12')) -12 - sage: ZZ.coerce(numpy.uint64('11')) # optional - numpy + sage: ZZ.coerce(numpy.uint64('11')) 11 TESTS:: @@ -719,7 +720,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): We return a sample from a discrete Gaussian distribution:: - sage: ZZ.random_element(11.0, distribution="gaussian").parent() is ZZ # optional - sage.modules + sage: ZZ.random_element(11.0, distribution="gaussian").parent() is ZZ # needs sage.modules True TESTS: @@ -728,7 +729,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.random_element(5, -5, distribution="1/n").parent() is ZZ True - sage: ZZ.random_element(5, -5, distribution="gaussian").parent() is ZZ # optional - sage.modules + sage: ZZ.random_element(5, -5, distribution="gaussian").parent() is ZZ # needs sage.modules True sage: ZZ.random_element(5, -5, distribution="mpz_rrandomb").parent() is ZZ True @@ -737,7 +738,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Traceback (most recent call last): ... TypeError: x must be > 0 - sage: ZZ.random_element(-10, -5, distribution="gaussian") # optional - sage.modules + sage: ZZ.random_element(-10, -5, distribution="gaussian") Traceback (most recent call last): ... TypeError: x must be > 0 @@ -924,9 +925,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field + sage: ZZ.extension(x^2 - 5, 'a') # needs 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 + sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') # needs sage.rings.number_field Relative Order in Number Field in a with defining polynomial x^2 + 1 over its base field """ @@ -980,40 +981,41 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: F = ZZ.residue_field(61); F # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: F = ZZ.residue_field(61); F Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi # optional - sage.libs.pari + sage: pi = F.reduction_map(); pi Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) # optional - sage.libs.pari + sage: pi(123/234) 6 - sage: pi(1/61) # optional - sage.libs.pari + sage: pi(1/61) Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift # optional - sage.libs.pari + sage: lift = F.lift_map(); lift Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) # optional - sage.libs.pari + sage: lift(F(12345/67890)) 33 - sage: (12345/67890) % 61 # optional - sage.libs.pari + sage: (12345/67890) % 61 33 Construction can be from a prime ideal instead of a prime:: - sage: ZZ.residue_field(ZZ.ideal(97)) # optional - sage.libs.pari + sage: ZZ.residue_field(ZZ.ideal(97)) # needs sage.libs.pari Residue field of Integers modulo 97 TESTS:: - sage: ZZ.residue_field(ZZ.ideal(96)) # optional - sage.libs.pari + sage: ZZ.residue_field(ZZ.ideal(96)) Traceback (most recent call last): ... TypeError: Principal ideal (96) of Integer Ring is not prime - sage: ZZ.residue_field(96) # optional - sage.libs.pari + sage: ZZ.residue_field(96) Traceback (most recent call last): ... TypeError: 96 is not prime @@ -1164,7 +1166,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.completion(infinity, 53) Integer Ring - sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics + sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) # needs sage.rings.padics 5-adic Ring with capped relative precision 15 """ if p == sage.rings.infinity.Infinity: @@ -1279,41 +1281,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) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) # needs 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) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) # needs sage.libs.pari [(1, 23), (-1, 23), (100, 1), (-5445, 5)] sage: p *= x^156468451540687043504386074354036574634735074 - sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) # needs sage.libs.pari [(0, 156468451540687043504386074354036574634735074), (1, 23), (-1, 23), (100, 1), (-5445, 5)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # needs 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) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) # needs sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # needs sage.libs.pari [100, -5445, 1, -1] - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # needs sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # needs sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") Traceback (most recent call last): ... ValueError: unknown algorithm 'foobar' sage: p = x^20 * p - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # needs sage.libs.pari [(0, 20), (100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # needs sage.libs.pari [(100, 1), (-5445, 5), (0, 20), (1, 23), (-1, 23)] """ deg = p.degree() @@ -1466,7 +1468,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: gap(ZZ) # indirect doctest # optional - sage.libs.gap + sage: gap(ZZ) # indirect doctest # needs sage.libs.gap Integers """ return 'Integers' @@ -1522,7 +1524,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ._sympy_() # optional - sympy + sage: ZZ._sympy_() # needs sympy Integers """ from sympy import Integers @@ -1552,9 +1554,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: v = ZZ.valuation(3); v # optional - sage.rings.padics + sage: v = ZZ.valuation(3); v # needs sage.rings.padics 3-adic valuation - sage: v(3) # optional - sage.rings.padics + sage: v(3) # needs sage.rings.padics 1 .. SEEALSO:: diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index b8d7ec38f40..a5fc28597eb 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') # optional - sage.rings.finite_rings - sage: S # optional - sage.rings.finite_rings + 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() # optional - sage.rings.finite_rings + sage: S.base_ring() Univariate Polynomial Ring in x over Finite Field of size 17 .. SEEALSO:: @@ -89,7 +89,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: Frac(QQ[['x']]) Laurent Series Ring in x over Rational Field - sage: Frac(GF(5)['y']) # optional - sage.rings.finite_rings + sage: Frac(GF(5)['y']) 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 @@ -101,22 +101,23 @@ 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) # 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 + sage: # needs sage.rings.padics + sage: K = Qp(5, prec=5) + sage: L = Qp(5, prec=200) + sage: R. = LaurentSeriesRing(K) + sage: S. = LaurentSeriesRing(L) + sage: R is S False - sage: T. = LaurentSeriesRing(Qp(5, prec=200)) # optional - sage.rings.padics - sage: S is T # optional - sage.rings.padics + sage: T. = LaurentSeriesRing(Qp(5, prec=200)) + sage: S is T True - sage: W. = LaurentSeriesRing(Qp(5, prec=199)) # optional - sage.rings.padics - sage: W is T # optional - sage.rings.padics + sage: W. = LaurentSeriesRing(Qp(5, prec=199)) + sage: W is T False - sage: K = LaurentSeriesRing(CC, 'q'); K # optional - sage.rings.real_mpfr + sage: K = LaurentSeriesRing(CC, 'q'); K # needs sage.rings.real_mpfr Laurent Series Ring in q over Complex Field with 53 bits of precision - sage: loads(K.dumps()) == K # optional - sage.rings.real_mpfr + sage: loads(K.dumps()) == K # needs sage.rings.real_mpfr True sage: P = QQ[['x']] sage: F = Frac(P) @@ -126,10 +127,10 @@ 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) # 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 + 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 @@ -404,35 +405,37 @@ def _element_constructor_(self, x, n=0, prec=infinity): EXAMPLES:: - 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 + sage: # needs sage.rings.padics + sage: R. = LaurentSeriesRing(Qp(5, 10)) + sage: S. = LaurentSeriesRing(RationalField()) + sage: R(t + t^2 + O(t^3)) (1 + O(5^10))*u + (1 + O(5^10))*u^2 + O(u^3) - sage: R(t + t^2 + O(t^3), prec=2) # optional - sage.rings.padics + sage: R(t + t^2 + O(t^3), prec=2) (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) # optional - sage.rings.padics + sage: u is R(u) # needs sage.rings.padics True - sage: R(u, n=3, prec=7) # optional - sage.rings.padics + sage: R(u, n=3, prec=7) # needs sage.rings.padics (1 + O(5^10))*u^4 + O(u^7) Rational functions are accepted:: - sage: I = sqrt(-1) # optional - sage.rings.number_field sage.symbolic - sage: K. = QQ[I] # optional - sage.rings.number_field sage.symbolic - sage: P. = PolynomialRing(K) # optional - sage.rings.number_field sage.symbolic - sage: L. = LaurentSeriesRing(QQ[I]) # optional - sage.rings.number_field sage.symbolic - sage: L((t*I)/(t^3+I*2*t)) # optional - sage.rings.number_field sage.symbolic + sage: # needs sage.rings.number_field sage.symbolic + 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)) 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) # optional - sage.rings.number_field + sage: L(t*I) / L(t^3+I*2*t) # needs sage.rings.number_field sage.symbolic 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) @@ -441,9 +444,9 @@ def _element_constructor_(self, x, n=0, prec=infinity): Check that :trac:`28993` is fixed:: - sage: from sage.modular.etaproducts import qexp_eta # optional - sage.modular + sage: from sage.modular.etaproducts import qexp_eta # needs sage.modular sage: S. = LaurentSeriesRing(RationalField()) - sage: qexp_eta(S, prec=30) # optional - sage.modular + sage: qexp_eta(S, prec=30) # needs sage.modular 1 - t - t^2 + t^5 + t^7 - t^12 - t^15 + t^22 + t^26 + O(t^30) When converting from `R((z))` to `R((z))((w))`, the variable @@ -459,23 +462,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')) # optional - sage.libs.pari + sage: L(pari('1/x')) # needs sage.libs.pari q^-1 - sage: L(pari('polchebyshev(5)')) # optional - sage.libs.pari + sage: L(pari('polchebyshev(5)')) # needs sage.libs.pari 5*q - 20*q^3 + 16*q^5 - sage: L(pari('polchebyshev(5) - 1/x^4')) # optional - sage.libs.pari + sage: L(pari('polchebyshev(5) - 1/x^4')) # needs sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 - sage: L(pari('1/polchebyshev(5)')) # optional - sage.libs.pari + sage: L(pari('1/polchebyshev(5)')) # needs 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)')) # optional - sage.libs.pari + sage: L(pari('polchebyshev(5) + O(x^40)')) # needs 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)')) # optional - sage.libs.pari + sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) # needs 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)')) # optional - sage.libs.pari + sage: L(pari('1/polchebyshev(5) + O(x^10)')) # needs 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 # optional - sage.libs.pari + sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 # needs 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)')) # optional - sage.libs.pari + sage: L(pari('O(x^-10)')) # needs sage.libs.pari O(q^-10) Check that :trac:`30073` is fixed:: @@ -540,8 +543,8 @@ def random_element(self, algorithm='default'): EXAMPLES:: - sage: S. = LaurentSeriesRing(GF(3)) # optional - sage.rings.finite_rings - sage: S.random_element() # random # optional - sage.rings.finite_rings + sage: S. = LaurentSeriesRing(GF(3)) + sage: S.random_element() # random 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) """ @@ -577,9 +580,9 @@ def construction(self): sage: parent(1/2 * t) Laurent Series Ring in t over Rational Field - sage: QQbar.gen() * t # optional - sage.rings.number_field + sage: QQbar.gen() * t # needs sage.rings.number_field I*t - sage: parent(QQbar.gen() * t) # optional - sage.rings.number_field + sage: parent(QQbar.gen() * t) # needs sage.rings.number_field Laurent Series Ring in t over Algebraic Field """ from sage.categories.pushout import CompletionFunctor @@ -655,15 +658,16 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = LaurentSeriesRing(GF(17)) + sage: S. = LaurentSeriesRing(GF(19)) + sage: R.hom([y], S) # indirect doctest 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) # optional - sage.rings.finite_rings - sage: f(x^2) # optional - sage.rings.finite_rings + sage: f = R.hom(x + x^3, R) + sage: f(x^2) x^2 + 2*x^4 + x^6 The image of the generator needs to be a unit:: @@ -690,8 +694,8 @@ def characteristic(self): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings - sage: R.characteristic() # optional - sage.rings.finite_rings + sage: R. = LaurentSeriesRing(GF(17)) + sage: R.characteristic() 17 """ return self.base_ring().characteristic() @@ -705,8 +709,8 @@ def residue_field(self): EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings - sage: R.residue_field() # optional - sage.rings.finite_rings + sage: R. = LaurentSeriesRing(GF(17)) + sage: R.residue_field() 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 63cac5bce7a..9b8ad96eb09 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 # optional - sage.rings.finite_rings + sage: R. = LaurentSeriesRing(GF(7), 't'); R Laurent Series Ring in t over Finite Field of size 7 - sage: f = 1/(1-t+O(t^10)); f # optional - sage.rings.finite_rings + sage: f = 1/(1-t+O(t^10)); f 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] # optional - sage.rings.finite_rings + sage: f[2] 1 - sage: f[2] = 5 # optional - sage.rings.finite_rings + sage: f[2] = 5 Traceback (most recent call last): ... IndexError: Laurent series are immutable @@ -21,18 +21,18 @@ We compute with a Laurent series over the complex mpfr numbers. :: - sage: K. = Frac(CC[['q']]); K # optional - sage.rings.real_mpfr + sage: K. = Frac(CC[['q']]); K # needs sage.rings.real_mpfr Laurent Series Ring in q over Complex Field with 53 bits of precision - sage: q # optional - sage.rings.real_mpfr + sage: q # needs sage.rings.real_mpfr 1.00000000000000*q Saving and loading. :: - sage: loads(q.dumps()) == q # optional - sage.rings.real_mpfr + sage: loads(q.dumps()) == q # needs sage.rings.real_mpfr True - sage: loads(K.dumps()) == K # optional - sage.rings.real_mpfr + sage: loads(K.dumps()) == K # needs sage.rings.real_mpfr True IMPLEMENTATION: Laurent series in Sage are represented internally @@ -113,13 +113,14 @@ cdef class LaurentSeries(AlgebraElement): :: - 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 + sage: # needs sage.rings.finite_rings sage.rings.padics + sage: S. = LaurentSeriesRing(GF(5)) + sage: T. = PowerSeriesRing(pAdicRing(5)) + sage: S(t) s - sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics + sage: parent(S(t)) Laurent Series Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics + sage: parent(S(t)[1]) Finite Field of size 5 """ AlgebraElement.__init__(self, parent) @@ -181,7 +182,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)) # optional - sage.rings.finite_rings + sage: p.change_ring(GF(2)) 1 + q^2 """ return self._parent.change_ring(R)(self) @@ -284,16 +285,16 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: Zx. = ZZ[] - 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 + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field + sage: R. = LaurentSeriesRing(K) # needs sage.rings.number_field + sage: z = t^-1 + i*t # needs sage.rings.number_field + sage: z._im_gens_(R, [t^2]) # needs 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]) # optional - sage.rings.number_field - sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field + sage: cc = K.hom([i]) # needs sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # needs sage.rings.number_field Traceback (most recent call last): ... NotImplementedError @@ -667,11 +668,12 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: A. = LaurentSeriesRing(GF(5)) + sage: x = t^(-1) + t^2 + O(t^5) + sage: x.lift_to_precision(10) t^-1 + t^2 + O(t^10) - sage: x.lift_to_precision() # optional - sage.rings.finite_rings + sage: x.lift_to_precision() t^-1 + t^2 """ if absprec is not None and absprec <= self.precision_absolute(): @@ -1597,8 +1599,8 @@ cdef class LaurentSeries(AlgebraElement): TESTS:: - sage: y = var('y') # optional - sage.symbolic - sage: f.derivative(y) # optional - sage.symbolic + sage: y = var('y') # needs sage.symbolic + sage: f.derivative(y) # needs sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -1700,11 +1702,12 @@ cdef class LaurentSeries(AlgebraElement): sage: (x^-2 + 1 + x).nth_root(2)**2 x^-2 + 1 + x + O(x^18) - sage: j = j_invariant_qexp() # optional - sage.modular - sage: q = j.parent().gen() # optional - sage.modular - sage: j(q^3).nth_root(3) # optional - sage.modular + sage: # needs sage.modular + sage: j = j_invariant_qexp() + sage: q = j.parent().gen() + sage: j(q^3).nth_root(3) q^-1 + 248*q^2 + 4124*q^5 + ... + O(q^29) - sage: (j(q^2) - 1728).nth_root(2) # optional - sage.modular + sage: (j(q^2) - 1728).nth_root(2) q^-1 - 492*q - 22590*q^3 - ... + O(q^19) """ if prec is None: @@ -1751,10 +1754,11 @@ 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)) # 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 + sage: # needs sage.rings.finite_rings + sage: L. = LaurentSeriesRing(GF(2)) + sage: R. = PolynomialRing(L) + sage: S. = PolynomialRing(L._power_series_ring) + sage: t**(-1)*x*y in S False There used to be an issue with non-canonical representations of zero, @@ -1774,8 +1778,8 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`32440`:: - sage: L. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari - sage: (x + O(x^3)).power_series() # optional - sage.libs.pari + sage: L. = LaurentSeriesRing(QQ, implementation='pari') # needs sage.libs.pari + sage: (x + O(x^3)).power_series() # needs sage.libs.pari x + O(x^3) """ if self.__n < 0: @@ -1836,9 +1840,9 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`23928`:: - 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 + sage: R. = LaurentSeriesRing(QQ, implementation='pari') # needs sage.libs.pari + sage: f = x.add_bigoh(7) # needs sage.libs.pari + sage: f(x) # needs sage.libs.pari x + O(x^7) """ if len(kwds) >= 1: @@ -1878,16 +1882,17 @@ 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__() # optional - sage.libs.pari + sage: f.__pari__() # needs sage.libs.pari x^-1 + x + O(x^2) Check that :trac:`32437` is fixed:: - 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 + sage: # needs sage.rings.finite_rings + 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 # needs sage.libs.pari u*t + O(t^99) """ f = self.__u diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index cf9c4f9cb20..78fbbf67afc 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -83,9 +83,9 @@ A similar statement is true for lazy symmetric functions:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat - sage: L = LazySymmetricFunctions(h) # optional - sage.combinat - sage: 1 / (1-L(h[1])) # optional - sage.combinat + sage: h = SymmetricFunctions(QQ).h() # needs sage.combinat + sage: L = LazySymmetricFunctions(h) # needs sage.combinat + sage: 1 / (1-L(h[1])) # needs sage.combinat h[] + h[1] + (h[1,1]) + (h[1,1,1]) + (h[1,1,1,1]) + (h[1,1,1,1,1]) + (h[1,1,1,1,1,1]) + O^7 We can change the base ring:: @@ -145,9 +145,9 @@ sage: check(L, z) sage: L. = LazyPowerSeriesRing(QQ) sage: check(L, z) - sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat - sage: L = LazySymmetricFunctions(p) # optional - sage.combinat - sage: check(L, L(p[1])) # optional - sage.combinat + sage: p = SymmetricFunctions(QQ).p() # needs sage.combinat + sage: L = LazySymmetricFunctions(p) # needs sage.combinat + sage: check(L, L(p[1])) # needs sage.combinat We check that the elements in the cache of the stream of homogeneous components are in the correct ring:: @@ -171,30 +171,30 @@ ....: yield n ....: n += 1 - sage: L. = LazyLaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: check(L, lambda n: n, valuation=-5) # optional - sage.rings.finite_rings - sage: check(L, gen(), valuation=-5) # optional - sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2)) # needs sage.rings.finite_rings + sage: check(L, lambda n: n, valuation=-5) # needs sage.rings.finite_rings + sage: check(L, gen(), valuation=-5) # needs sage.rings.finite_rings - sage: L = LazyDirichletSeriesRing(QQbar, "s") # optional - sage.rings.number_field - sage: check(L, lambda n: n, valuation=2) # optional - sage.rings.number_field - sage: check(L, gen(), valuation=2) # optional - sage.rings.number_field + sage: L = LazyDirichletSeriesRing(QQbar, "s") # needs sage.rings.number_field + sage: check(L, lambda n: n, valuation=2) # needs sage.rings.number_field + sage: check(L, gen(), valuation=2) # needs sage.rings.number_field - sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: check(L, lambda n: n, valuation=0) # optional - sage.rings.finite_rings - sage: check(L, gen(), valuation=0) # optional - sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) # needs sage.rings.finite_rings + sage: check(L, lambda n: n, valuation=0) # needs sage.rings.finite_rings + sage: check(L, gen(), valuation=0) # needs sage.rings.finite_rings - sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: check(L, lambda n: (x + y)^n, valuation=None) # optional - sage.rings.finite_rings - sage: def gen(): # optional - sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) # needs sage.rings.finite_rings + sage: check(L, lambda n: (x + y)^n, valuation=None) # needs sage.rings.finite_rings + sage: def gen(): # needs sage.rings.finite_rings ....: n = 0 ....: while True: ....: yield (x+y)^n ....: n += 1 - sage: check(L, gen(), valuation=None) # optional - sage.rings.finite_rings + sage: check(L, gen(), valuation=None) # needs sage.rings.finite_rings - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.combinat sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.combinat sage.rings.finite_rings - sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), # optional - sage.combinat sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.combinat sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # needs sage.combinat sage.rings.finite_rings + sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), # needs sage.combinat sage.rings.finite_rings ....: valuation=0) """ @@ -296,9 +296,9 @@ def __init__(self, parent, coeff_stream): sage: L. = LazyLaurentSeriesRing(ZZ) sage: TestSuite(L.an_element()).run() - sage: L = LazyDirichletSeriesRing(QQbar, 'z') # optional - sage.rings.number_field - sage: g = L(constant=1) # optional - sage.rings.number_field - sage: TestSuite(g).run() # optional - sage.rings.number_field + sage: L = LazyDirichletSeriesRing(QQbar, 'z') # needs sage.rings.number_field + sage: g = L(constant=1) # needs sage.rings.number_field + sage: TestSuite(g).run() # needs sage.rings.number_field """ Element.__init__(self, parent) self._coeff_stream = coeff_stream @@ -436,9 +436,9 @@ def coefficients(self, n=None): sage: f.coefficients() lazy list [1, 1, -1/6, ...] - sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: f = L(lambda n: n) # optional - sage.rings.finite_rings - sage: f.coefficients(5) # optional - sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) # needs sage.rings.finite_rings + sage: f = L(lambda n: n) # needs sage.rings.finite_rings + sage: f.coefficients(5) # needs sage.rings.finite_rings [1, 1, 1, 1, 1] """ coeff_stream = self._coeff_stream @@ -496,10 +496,10 @@ def map_coefficients(self, f): sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: s = L(lambda n: n-1) - sage: s # optional - sage.symbolic + sage: s # needs sage.symbolic 1/(2^z) + 2/3^z + 3/4^z + 4/5^z + 5/6^z + 6/7^z + O(1/(8^z)) sage: ms = s.map_coefficients(lambda c: c + 1) - sage: ms # optional - sage.symbolic + sage: ms # needs sage.symbolic 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + 8/8^z + O(1/(9^z)) Similarly for multivariate power series:: @@ -520,12 +520,13 @@ def map_coefficients(self, f): Similarly for lazy symmetric functions:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat - sage: L = LazySymmetricFunctions(p) # optional - sage.combinat - sage: f = 1/(1-2*L(p[1])); f # optional - sage.combinat + sage: # needs sage.combinat + sage: p = SymmetricFunctions(QQ).p() + sage: L = LazySymmetricFunctions(p) + sage: f = 1/(1-2*L(p[1])); f p[] + 2*p[1] + (4*p[1,1]) + (8*p[1,1,1]) + (16*p[1,1,1,1]) + (32*p[1,1,1,1,1]) + (64*p[1,1,1,1,1,1]) + O^7 - sage: f.map_coefficients(lambda c: log(c, 2)) # optional - sage.combinat + sage: f.map_coefficients(lambda c: log(c, 2)) p[1] + (2*p[1,1]) + (3*p[1,1,1]) + (4*p[1,1,1,1]) + (5*p[1,1,1,1,1]) + (6*p[1,1,1,1,1,1]) + O^7 @@ -663,10 +664,10 @@ def shift(self, n): sage: D = LazyDirichletSeriesRing(QQ, 't') sage: f = D([0,1,2]) - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic 1/(2^t) + 2/3^t sage: sf = f.shift(3) - sage: sf # optional - sage.symbolic + sage: sf # needs sage.symbolic 1/(5^t) + 2/6^t Examples with power series (where the minimal valuation is `0`):: @@ -1010,60 +1011,65 @@ def __bool__(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: bool(z - z) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2)) + sage: bool(z - z) False - sage: f = 1/(1 - z) # optional - sage.rings.finite_rings - sage: bool(f) # optional - sage.rings.finite_rings + sage: f = 1/(1 - z) + sage: bool(f) True - sage: M = L(lambda n: n, valuation=0); M # optional - sage.rings.finite_rings + sage: M = L(lambda n: n, valuation=0); M z + z^3 + z^5 + O(z^7) - sage: M.is_zero() # optional - sage.rings.finite_rings + sage: M.is_zero() False - sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M # optional - sage.rings.finite_rings + sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M O(z^7) - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) Traceback (most recent call last): ... ValueError: undecidable as lazy Laurent series - sage: M[15] # optional - sage.rings.finite_rings + sage: M[15] 1 - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) True - sage: L. = LazyLaurentSeriesRing(GF(2), sparse=True) # optional - sage.rings.finite_rings - sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2), sparse=True) + sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M O(z^7) - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) Traceback (most recent call last): ... ValueError: undecidable as lazy Laurent series - sage: M[15] # optional - sage.rings.finite_rings + sage: M[15] 1 - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) True Uninitialized series:: - sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: g = L.undefined(valuation=0) + sage: bool(g) True - sage: g.define(0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g.define(0) + sage: bool(g) False - sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: g = L.undefined(valuation=0) + sage: bool(g) True - sage: g.define(1 + z) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g.define(1 + z) + sage: bool(g) True - sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: g = L.undefined(valuation=0) + sage: bool(g) True - sage: g.define(1 + z*g) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g.define(1 + z*g) + sage: bool(g) True """ if isinstance(self._coeff_stream, Stream_zero): @@ -1202,14 +1208,15 @@ def define(self, s): We can compute the Frobenius character of unlabeled trees:: - sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat - sage: L = LazySymmetricFunctions(m) # optional - sage.combinat - sage: E = L(lambda n: s[n], valuation=0) # optional - sage.combinat - sage: X = L(s[1]) # optional - sage.combinat - sage: A = L.undefined() # optional - sage.combinat - sage: A.define(X*E(A, check=False)) # optional - sage.combinat - sage: A[:6] # optional - sage.combinat + sage: # needs sage.combinat + sage: m = SymmetricFunctions(QQ).m() + sage: s = SymmetricFunctions(QQ).s() + sage: L = LazySymmetricFunctions(m) + sage: E = L(lambda n: s[n], valuation=0) + sage: X = L(s[1]) + sage: A = L.undefined() + sage: A.define(X*E(A, check=False)) + sage: A[:6] [m[1], 2*m[1, 1] + m[2], 9*m[1, 1, 1] + 5*m[2, 1] + 2*m[3], @@ -1251,7 +1258,7 @@ def define(self, s): sage: g = D.undefined(valuation=2) sage: o = D(constant=1, valuation=2) sage: g.define(o * e(g)) - sage: g # optional - sage.symbolic + sage: g # needs sage.symbolic 1/(2^s) + 1/(3^s) + 2/4^s + 1/(5^s) + 3/6^s + 1/(7^s) + 9/2/8^s + O(1/(9^s)) For Laurent series there is no minimal valuation, so it has @@ -1276,7 +1283,7 @@ def define(self, s): sage: g = D([0, 1]) sage: f = D.undefined() sage: f.define(1 + ~f*g) - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic 1 + 1/(2^s) - 1/(4^s) + O(1/(8^s)) sage: oeis(f[:30]) # optional - internet @@ -1324,11 +1331,12 @@ def define(self, s): sage: f 1 + 2*t + 12*t^3 + 32*t^4 + 368*t^5 + 2192*t^6 + O(t^7) - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat - sage: L = LazySymmetricFunctions(s) # optional - sage.combinat - sage: f = L.undefined() # optional - sage.combinat - sage: f.define(1+(s[1]*f).revert()) # optional - sage.combinat - sage: f # optional - sage.combinat + sage: # needs sage.combinat + sage: s = SymmetricFunctions(QQ).s() + sage: L = LazySymmetricFunctions(s) + sage: f = L.undefined() + sage: f.define(1+(s[1]*f).revert()) + sage: f s[] + s[1] + (-s[1,1]-s[2]) + (3*s[1,1,1]+6*s[2,1]+3*s[3]) + (-13*s[1,1,1,1]-39*s[2,1,1]-26*s[2,2]-39*s[3,1]-13*s[4]) @@ -1336,7 +1344,7 @@ def define(self, s): + (-419*s[1,1,1,1,1,1]-2095*s[2,1,1,1,1]-3771*s[2,2,1,1]-2095*s[2,2,2]-4190*s[3,1,1,1]-6704*s[3,2,1]-2095*s[3,3]-4190*s[4,1,1]-3771*s[4,2]-2095*s[5,1]-419*s[6]) + O^7 - sage: (f*s[1]).revert() + 1 - f # optional - sage.combinat + sage: (f*s[1]).revert() + 1 - f # needs sage.combinat O^7 """ @@ -1459,12 +1467,13 @@ def _ascii_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat sage.modules - sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat sage.modules - sage: L.options.display_length = 3 # optional - sage.combinat sage.modules - sage: ascii_art(1 / (1 - e[1]*z)) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: e = SymmetricFunctions(QQ).e() + sage: L. = LazyLaurentSeriesRing(e) + sage: L.options.display_length = 3 + sage: ascii_art(1 / (1 - e[1]*z)) e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() # optional - sage.combinat sage.modules + sage: L.options._reset() """ from sage.typeset.ascii_art import ascii_art, AsciiArt if isinstance(self._coeff_stream, Stream_zero): @@ -1479,12 +1488,13 @@ def _unicode_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat sage.modules - sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat sage.modules - sage: L.options.display_length = 3 # optional - sage.combinat sage.modules - sage: unicode_art(1 / (1 - e[1]*z)) # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: e = SymmetricFunctions(QQ).e() + sage: L. = LazyLaurentSeriesRing(e) + sage: L.options.display_length = 3 + sage: unicode_art(1 / (1 - e[1]*z)) e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() # optional - sage.combinat sage.modules + sage: L.options._reset() """ from sage.typeset.unicode_art import unicode_art, UnicodeArt if isinstance(self._coeff_stream, Stream_zero): @@ -1539,7 +1549,7 @@ def change_ring(self, ring): sage: t.parent() Lazy Dirichlet Series Ring in z over Rational Field sage: it = t^-1 - sage: it # optional - sage.symbolic + sage: it # needs sage.symbolic 1/2 - 1/2/2^z - 1/2/3^z - 1/2/5^z + 1/2/6^z - 1/2/7^z + O(1/(8^z)) A Taylor series example:: @@ -1607,28 +1617,28 @@ def _add_(self, other): sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: s = L(lambda n: n) - sage: s # optional - sage.symbolic + sage: s # needs sage.symbolic 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + O(1/(8^z)) sage: t = L(constant=1) - sage: t # optional - sage.symbolic + sage: t # needs sage.symbolic 1 + 1/(2^z) + 1/(3^z) + O(1/(4^z)) sage: st = s + t - sage: st # optional - sage.symbolic + sage: st # needs sage.symbolic 2 + 3/2^z + 4/3^z + 5/4^z + 6/5^z + 7/6^z + 8/7^z + O(1/(8^z)) sage: r = L(constant=-1) sage: rt = r + t - sage: rt # optional - sage.symbolic + sage: rt # needs sage.symbolic 0 sage: r = L([1,2,3]) sage: rt = r + t - sage: rt # optional - sage.symbolic + sage: rt # needs sage.symbolic 2 + 3/2^z + 4/3^z + 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)) sage: r = L([1,2,3], constant=-1) sage: rt = r + t - sage: rt # optional - sage.symbolic + sage: rt # needs sage.symbolic 2 + 3/2^z + 4/3^z """ P = self.parent() @@ -1823,16 +1833,16 @@ def _acted_upon_(self, scalar, self_on_left): sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: g = L([0,1]) - sage: 2 * g # optional - sage.symbolic + sage: 2 * g # needs sage.symbolic 2/2^z - sage: -1 * g # optional - sage.symbolic + sage: -1 * g # needs sage.symbolic -1/(2^z) - sage: 0*g # optional - sage.symbolic + sage: 0*g # needs sage.symbolic 0 sage: M = L(lambda n: n) - sage: M # optional - sage.symbolic + sage: M # needs sage.symbolic 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + O(1/(8^z)) - sage: 3 * M # optional - sage.symbolic + sage: 3 * M # needs sage.symbolic 3 + 6/2^z + 9/3^z + 12/4^z + 15/5^z + 18/6^z + 21/7^z + O(1/(8^z)) sage: 1 * M is M @@ -1955,7 +1965,7 @@ def exp(self): sage: L = LazyDirichletSeriesRing(QQ, "s") sage: Z = L(constant=1, valuation=2) - sage: exp(Z) # optional - sage.symbolic + sage: exp(Z) # needs sage.symbolic 1 + 1/(2^s) + 1/(3^s) + 3/2/4^s + 1/(5^s) + 2/6^s + 1/(7^s) + O(1/(8^s)) """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -1971,7 +1981,7 @@ def log(self): sage: L = LazyDirichletSeriesRing(QQ, "s") sage: Z = L(constant=1) - sage: log(Z) # optional - sage.symbolic + sage: log(Z) # needs sage.symbolic 1/(2^s) + 1/(3^s) + 1/2/4^s + 1/(5^s) + 1/(7^s) + O(1/(8^s)) """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2028,8 +2038,8 @@ def cos(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: cos(z)[0:6] == cos(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: cos(z)[0:6] == cos(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2054,8 +2064,8 @@ def tan(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: tan(z)[0:6] == tan(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: tan(z)[0:6] == tan(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ return self.sin() / self.cos() @@ -2076,8 +2086,8 @@ def cot(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: cot(z)[0:6] == cot(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: cot(z)[0:6] == cot(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ return ~self.tan() @@ -2098,8 +2108,8 @@ def csc(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: (z*csc(z))[0:6] == (x*csc(x)).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: (z*csc(z))[0:6] == (x*csc(x)).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ return ~self.sin() @@ -2120,8 +2130,8 @@ def sec(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: sec(z)[0:6] == sec(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: sec(z)[0:6] == sec(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ return ~self.cos() @@ -2146,8 +2156,8 @@ def arcsin(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: asin(z)[0:6] == asin(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: asin(z)[0:6] == asin(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2183,8 +2193,8 @@ def arccos(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: acos(z)[0:6] == acos(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: acos(z)[0:6] == acos(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from sage.symbolic.constants import pi @@ -2207,8 +2217,8 @@ def arctan(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: atan(z)[0:6] == atan(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: atan(z)[0:6] == atan(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2246,8 +2256,8 @@ def arccot(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: acot(z)[0:6] == acot(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: acot(z)[0:6] == acot(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from sage.symbolic.constants import pi @@ -2273,8 +2283,8 @@ def sinh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: sinh(z)[0:6] == sinh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: sinh(z)[0:6] == sinh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2300,8 +2310,8 @@ def cosh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: cosh(z)[0:6] == cosh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: cosh(z)[0:6] == cosh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2327,8 +2337,8 @@ def tanh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: tanh(z)[0:6] == tanh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: tanh(z)[0:6] == tanh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from sage.arith.misc import bernoulli @@ -2358,8 +2368,8 @@ def coth(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: coth(z)[0:6] == coth(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: coth(z)[0:6] == coth(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from sage.arith.misc import bernoulli @@ -2390,8 +2400,8 @@ def sech(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: sech(z)[0:6] == sech(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: sech(z)[0:6] == sech(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from sage.combinat.combinat import euler_number @@ -2421,8 +2431,8 @@ def csch(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: csch(z)[0:6] == csch(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: csch(z)[0:6] == csch(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ from sage.arith.misc import bernoulli @@ -2460,8 +2470,8 @@ def arcsinh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: asinh(z)[0:6] == asinh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: asinh(z)[0:6] == asinh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ @@ -2498,8 +2508,8 @@ def arctanh(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: atanh(z)[0:6] == atanh(x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: atanh(z)[0:6] == atanh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ @@ -2533,8 +2543,8 @@ def hypergeometric(self, a, b): TESTS:: - sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # optional - sage.symbolic - sage: z.hypergeometric([1,1],[1])[0:6] == hypergeometric([1,1],[1], x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR); x = var("x") # needs sage.symbolic + sage: z.hypergeometric([1,1],[1])[0:6] == hypergeometric([1,1],[1], x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ @@ -2624,14 +2634,14 @@ def __pow__(self, n): sage: D = LazyDirichletSeriesRing(QQ, 's') sage: Z = D(constant=1) - sage: Z^2 # optional - sage.symbolic + sage: Z^2 # needs sage.symbolic 1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)) sage: f = Z^(1/3) - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic 1 + 1/3/2^s + 1/3/3^s + 2/9/4^s + 1/3/5^s + 1/9/6^s + 1/3/7^s + O(1/(8^s)) - sage: f^2 # optional - sage.symbolic + sage: f^2 # needs sage.symbolic 1 + 2/3/2^s + 2/3/3^s + 5/9/4^s + 2/3/5^s + 4/9/6^s + 2/3/7^s + O(1/(8^s)) - sage: f^3 - Z # optional - sage.symbolic + sage: f^3 - Z # needs sage.symbolic O(1/(8^s)) sage: L. = LazyLaurentSeriesRing(QQ) @@ -2685,11 +2695,12 @@ def sqrt(self): This also works for Dirichlet series:: - sage: D = LazyDirichletSeriesRing(SR, "s") # optional - sage.symbolic - sage: Z = D(constant=1) # optional - sage.symbolic - sage: f = sqrt(Z); f # optional - sage.symbolic + sage: # needs sage.symbolic + sage: D = LazyDirichletSeriesRing(SR, "s") + sage: Z = D(constant=1) + sage: f = sqrt(Z); f 1 + 1/2/2^s + 1/2/3^s + 3/8/4^s + 1/2/5^s + 1/4/6^s + 1/2/7^s + O(1/(8^s)) - sage: f*f - Z # optional - sage.symbolic + sage: f*f - Z O(1/(8^s)) """ return self ** QQ((1, 2)) # == 1/2 @@ -2798,22 +2809,23 @@ def _mul_(self, other): Multiplication of series with eventually constant coefficients may yield another such series:: - sage: L. = LazyLaurentSeriesRing(SR) # optional - sage.symbolic - sage: var("a b c d e u v w") # optional - sage.symbolic + sage: # needs sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR) + sage: var("a b c d e u v w") (a, b, c, d, e, u, v, w) - sage: s = a/z^2 + b*z + c*z^2 + d*z^3 + e*z^4 # optional - sage.symbolic - sage: t = L([u, v], constant=w, valuation=-1) # optional - sage.symbolic - sage: s1 = s.approximate_series(44) # optional - sage.symbolic - sage: t1 = t.approximate_series(44) # optional - sage.symbolic - sage: s1 * t1 - (s * t).approximate_series(42) # optional - sage.symbolic + sage: s = a/z^2 + b*z + c*z^2 + d*z^3 + e*z^4 + sage: t = L([u, v], constant=w, valuation=-1) + sage: s1 = s.approximate_series(44) + sage: t1 = t.approximate_series(44) + sage: s1 * t1 - (s * t).approximate_series(42) O(z^42) Check products with exact series:: - sage: L([1], constant=3)^2 # optional - sage.symbolic + sage: L([1], constant=3)^2 # needs sage.symbolic 1 + 6*z + 15*z^2 + 24*z^3 + 33*z^4 + 42*z^5 + 51*z^6 + O(z^7) - sage: (1+z) * L([1,0,1], constant=1) # optional - sage.symbolic + sage: (1+z) * L([1,0,1], constant=1) # needs sage.symbolic 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6) """ P = self.parent() @@ -2934,8 +2946,8 @@ def __pow__(self, n): We also support the general case:: - sage: L. = LazyLaurentSeriesRing(SR) # optional - sage.symbolic - sage: (1 + z)^(1 + z) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(SR) # needs sage.symbolic + sage: (1 + z)^(1 + z) # needs sage.symbolic 1 + z + z^2 + 1/2*z^3 + 1/3*z^4 + 1/12*z^5 + 3/40*z^6 + O(z^7) """ @@ -2995,14 +3007,15 @@ def __invert__(self): We can also compute the multiplicative inverse of a symmetric function:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: L = LazySymmetricFunctions(p) # optional - sage.modules - sage: E = L(lambda n: h[n]) # optional - sage.modules - sage: (~E)[:4] # optional - sage.modules + sage: # needs sage.modules + sage: h = SymmetricFunctions(QQ).h() + sage: p = SymmetricFunctions(QQ).p() + sage: L = LazySymmetricFunctions(p) + sage: E = L(lambda n: h[n]) + sage: (~E)[:4] [p[], -p[1], 1/2*p[1, 1] - 1/2*p[2], -1/6*p[1, 1, 1] + 1/2*p[2, 1] - 1/3*p[3]] - sage: (E * ~E)[:6] # optional - sage.modules + sage: (E * ~E)[:6] # needs sage.modules [p[], 0, 0, 0, 0, 0] TESTS:: @@ -3113,9 +3126,9 @@ def _div_(self, other): An example over the ring of symmetric functions:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.modules - sage: R. = LazyLaurentSeriesRing(e) # optional - sage.modules - sage: 1 / (1 - e[1]*z) # optional - sage.modules + sage: e = SymmetricFunctions(QQ).e() # needs sage.modules + sage: R. = LazyLaurentSeriesRing(e) # needs sage.modules + sage: 1 / (1 - e[1]*z) # needs sage.modules e[] + e[1]*z + e[1, 1]*z^2 + e[1, 1, 1]*z^3 + e[1, 1, 1, 1]*z^4 + e[1, 1, 1, 1, 1]*z^5 + e[1, 1, 1, 1, 1, 1]*z^6 + O(e[]*z^7) @@ -3368,11 +3381,11 @@ def log(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # optional - sage.symbolic - sage: log(1+z)[0:6] == log(1+x).series(x, 6).coefficients(sparse=False) # optional - sage.symbolic + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic + sage: log(1+z)[0:6] == log(1+x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True - sage: log(z) # optional - sage.symbolic + sage: log(z) # needs sage.symbolic Traceback (most recent call last): ... ValueError: can only compose with a positive valuation series @@ -3501,16 +3514,16 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: Z. = ZZ[] - sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field - sage: R. = LazyLaurentSeriesRing(K) # optional - sage.rings.number_field - sage: f = R(lambda n: i^n, valuation=-2); f # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field + sage: R. = LazyLaurentSeriesRing(K) # needs sage.rings.number_field + sage: f = R(lambda n: i^n, valuation=-2); f # needs sage.rings.number_field -t^-2 - i*t^-1 + 1 + i*t - t^2 - i*t^3 + t^4 + O(t^5) - sage: f._im_gens_(R, [t + t^2]) # optional - sage.rings.number_field + sage: f._im_gens_(R, [t + t^2]) # needs sage.rings.number_field -t^-2 + (-i + 2)*t^-1 + (i - 2) + 4*t + (2*i - 6)*t^2 + (-2*i + 4)*t^3 + (-2*i - 7)*t^4 + O(t^5) - sage: cc = K.hom([-i]) # optional - sage.rings.number_field - sage: f._im_gens_(R, [t + t^2], base_map=cc) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # needs sage.rings.number_field + sage: f._im_gens_(R, [t + t^2], base_map=cc) # needs sage.rings.number_field -t^-2 + (i + 2)*t^-1 + (-i - 2) + 4*t + (-2*i - 6)*t^2 + (2*i + 4)*t^3 + (2*i - 7)*t^4 + O(t^5) """ @@ -3747,7 +3760,7 @@ def __call__(self, g, *, check=True): sage: e = L(lambda n: 1/factorial(n), 0) sage: D = LazyDirichletSeriesRing(QQ, "s") sage: g = D(constant=1)-1 - sage: g # optional - sage.symbolic + sage: g # needs sage.symbolic 1/(2^s) + 1/(3^s) + 1/(4^s) + O(1/(5^s)) sage: e(g)[0:10] @@ -3757,7 +3770,7 @@ def __call__(self, g, *, check=True): [0, 1, 1, 1, 3/2, 1, 2, 1, 13/6, 3/2] sage: g = D([0,1,0,1,1,2]) - sage: g # optional - sage.symbolic + sage: g # needs sage.symbolic 1/(2^s) + 1/(4^s) + 1/(5^s) + 2/6^s sage: e(g)[0:10] [0, 1, 1, 0, 3/2, 1, 2, 0, 7/6, 0] @@ -3770,11 +3783,11 @@ def __call__(self, g, *, check=True): ValueError: can only compose with a positive valuation series sage: e5 = L(e, degree=5) - sage: e5 # optional - sage.symbolic + sage: e5 # needs sage.symbolic 1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4 - sage: e5(g) # optional - sage.symbolic + sage: e5(g) # needs sage.symbolic 1 + 1/(2^s) + 3/2/4^s + 1/(5^s) + 2/6^s + O(1/(8^s)) - sage: sum(e5[k] * g^k for k in range(5)) # optional - sage.symbolic + sage: sum(e5[k] * g^k for k in range(5)) # needs sage.symbolic 1 + 1/(2^s) + 3/2/4^s + 1/(5^s) + 2/6^s + O(1/(8^s)) The output parent is always the common parent between the base ring @@ -4546,7 +4559,7 @@ def __call__(self, *g, check=True): sage: D = LazyDirichletSeriesRing(QQ, "s") sage: g = D(constant=1)-1 - sage: g # optional - sage.symbolic + sage: g # needs sage.symbolic 1/(2^s) + 1/(3^s) + 1/(4^s) + O(1/(5^s)) sage: f = 1 / (1 - x - y*z); f 1 + x + (x^2+y*z) + (x^3+2*x*y*z) + (x^4+3*x^2*y*z+y^2*z^2) @@ -4554,18 +4567,18 @@ def __call__(self, *g, check=True): + (x^6+5*x^4*y*z+6*x^2*y^2*z^2+y^3*z^3) + O(x,y,z)^7 sage: fog = f(g, g, g) - sage: fog # optional - sage.symbolic + sage: fog # needs sage.symbolic 1 + 1/(2^s) + 1/(3^s) + 3/4^s + 1/(5^s) + 5/6^s + O(1/(7^s)) sage: fg = 1 / (1 - g - g*g) - sage: fg # optional - sage.symbolic + sage: fg # needs sage.symbolic 1 + 1/(2^s) + 1/(3^s) + 3/4^s + 1/(5^s) + 5/6^s + 1/(7^s) + O(1/(8^s)) - sage: fog - fg # optional - sage.symbolic + sage: fog - fg # needs sage.symbolic O(1/(8^s)) sage: f = 1 / (1 - 2*a) - sage: f(g) # optional - sage.symbolic + sage: f(g) # needs sage.symbolic 1 + 2/2^s + 2/3^s + 6/4^s + 2/5^s + 10/6^s + 2/7^s + O(1/(8^s)) - sage: 1 / (1 - 2*g) # optional - sage.symbolic + sage: 1 / (1 - 2*g) # needs sage.symbolic 1 + 2/2^s + 2/3^s + 6/4^s + 2/5^s + 10/6^s + 2/7^s + O(1/(8^s)) The output parent is always the common parent between the base ring @@ -5313,19 +5326,20 @@ def xgcd(self, f): sage: g == s * a + t * b True - sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: a = L(lambda n: n % 2, valuation=3); a # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) + sage: a = L(lambda n: n % 2, valuation=3); a x^3 + x^5 + x^7 + x^9 + O(x^10) - sage: b = L(lambda n: binomial(n,2) % 2, valuation=3); b # optional - sage.rings.finite_rings + sage: b = L(lambda n: binomial(n,2) % 2, valuation=3); b x^3 + x^6 + x^7 + O(x^10) - sage: g, s, t = a.xgcd(b) # optional - sage.rings.finite_rings - sage: g # optional - sage.rings.finite_rings + sage: g, s, t = a.xgcd(b) + sage: g x^3 - sage: s # optional - sage.rings.finite_rings + sage: s 1 + x + x^3 + x^4 + x^5 + O(x^7) - sage: t # optional - sage.rings.finite_rings + sage: t x + x^2 + x^4 + x^5 + x^6 + O(x^8) - sage: g == s * a + t * b # optional - sage.rings.finite_rings + sage: g == s * a + t * b True sage: LazyPowerSeriesRing.options._reset() # reset the options @@ -5367,11 +5381,12 @@ def _format_series(self, formatter, format_strings=False): TESTS:: - sage: h = SymmetricFunctions(ZZ).h() # optional - sage.modules - sage: e = SymmetricFunctions(ZZ).e() # optional - sage.modules - sage: L = LazySymmetricFunctions(tensor([h, e])) # optional - sage.modules - sage: f = L(lambda n: sum(tensor([h[k], e[n-k]]) for k in range(n+1))) # optional - sage.modules - sage: f._format_series(repr) # optional - sage.modules + sage: # needs sage.modules + sage: h = SymmetricFunctions(ZZ).h() + sage: e = SymmetricFunctions(ZZ).e() + sage: L = LazySymmetricFunctions(tensor([h, e])) + sage: f = L(lambda n: sum(tensor([h[k], e[n-k]]) for k in range(n+1))) + sage: f._format_series(repr) '(h[]#e[]) + (h[]#e[1]+h[1]#e[]) + (h[]#e[2]+h[1]#e[1]+h[2]#e[]) @@ -5442,8 +5457,8 @@ class LazySymmetricFunction(LazyCompletionGradedAlgebraElement): EXAMPLES:: - sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules + sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules """ def is_unit(self): """ @@ -5451,22 +5466,22 @@ def is_unit(self): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules - sage: L(2*m[1]).is_unit() # optional - sage.modules + sage: L(2*m[1]).is_unit() # needs sage.modules False - sage: L(-1 + 2*m[1]).is_unit() # optional - sage.modules + sage: L(-1 + 2*m[1]).is_unit() # needs sage.modules True - sage: L(2 + m[1]).is_unit() # optional - sage.modules + sage: L(2 + m[1]).is_unit() # needs sage.modules False - sage: m = SymmetricFunctions(QQ).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules + sage: m = SymmetricFunctions(QQ).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules - sage: L(2 + 3*m[1]).is_unit() # optional - sage.modules + sage: L(2 + 3*m[1]).is_unit() # needs sage.modules True """ if self.is_zero(): # now 0 != 1 @@ -5510,54 +5525,56 @@ def __call__(self, *args, check=True): EXAMPLES:: sage: P. = QQ[] - sage: s = SymmetricFunctions(P).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: f = s[2] # optional - sage.modules - sage: g = s[3] # optional - sage.modules - sage: L(f)(L(g)) - L(f(g)) # optional - sage.modules + sage: s = SymmetricFunctions(P).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: f = s[2] # needs sage.modules + sage: g = s[3] # needs sage.modules + sage: L(f)(L(g)) - L(f(g)) # needs sage.modules 0 - sage: f = s[2] + s[2,1] # optional - sage.modules - sage: g = s[1] + s[2,2] # optional - sage.modules - sage: L(f)(L(g)) - L(f(g)) # optional - sage.modules + sage: f = s[2] + s[2,1] # needs sage.modules + sage: g = s[1] + s[2,2] # needs sage.modules + sage: L(f)(L(g)) - L(f(g)) # needs sage.modules 0 - sage: L(f)(g) - L(f(g)) # optional - sage.modules + sage: L(f)(g) - L(f(g)) # needs sage.modules 0 - sage: f = s[2] + s[2,1] # optional - sage.modules - sage: g = s[1] + s[2,2] # optional - sage.modules - sage: L(f)(L(q*g)) - L(f(q*g)) # optional - sage.modules + sage: f = s[2] + s[2,1] # needs sage.modules + sage: g = s[1] + s[2,2] # needs sage.modules + sage: L(f)(L(q*g)) - L(f(q*g)) # needs sage.modules 0 The Frobenius character of the permutation action on set partitions is a plethysm:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: S = LazySymmetricFunctions(s) # optional - sage.modules - sage: E1 = S(lambda n: s[n], valuation=1) # optional - sage.modules - sage: E = 1 + E1 # optional - sage.modules - sage: P = E(E1) # optional - sage.modules - sage: P[:5] # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: S = LazySymmetricFunctions(s) + sage: E1 = S(lambda n: s[n], valuation=1) + sage: E = 1 + E1 + sage: P = E(E1) + sage: P[:5] [s[], s[1], 2*s[2], s[2, 1] + 3*s[3], 2*s[2, 2] + 2*s[3, 1] + 5*s[4]] The plethysm with a tensor product is also implemented:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: X = tensor([s[1],s[[]]]) # optional - sage.modules - sage: Y = tensor([s[[]],s[1]]) # optional - sage.modules - sage: S = LazySymmetricFunctions(s) # optional - sage.modules - sage: S2 = LazySymmetricFunctions(tensor([s, s])) # optional - sage.modules - sage: A = S(s[1,1,1]) # optional - sage.modules - sage: B = S2(X+Y) # optional - sage.modules - sage: A(B) # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: X = tensor([s[1],s[[]]]) + sage: Y = tensor([s[[]],s[1]]) + sage: S = LazySymmetricFunctions(s) + sage: S2 = LazySymmetricFunctions(tensor([s, s])) + sage: A = S(s[1,1,1]) + sage: B = S2(X+Y) + sage: A(B) (s[]#s[1,1,1]+s[1]#s[1,1]+s[1,1]#s[1]+s[1,1,1]#s[]) - sage: H = S(lambda n: s[n]) # optional - sage.modules - sage: H(S2(X*Y)) # optional - sage.modules + sage: H = S(lambda n: s[n]) # needs sage.modules + sage: H(S2(X*Y)) # needs sage.modules (s[]#s[]) + (s[1]#s[1]) + (s[1,1]#s[1,1]+s[2]#s[2]) + (s[1,1,1]#s[1,1,1]+s[2,1]#s[2,1]+s[3]#s[3]) + O^7 - sage: H(S2(X+Y)) # optional - sage.modules + sage: H(S2(X+Y)) # needs sage.modules (s[]#s[]) + (s[]#s[1]+s[1]#s[]) + (s[]#s[2]+s[1]#s[1]+s[2]#s[]) + (s[]#s[3]+s[1]#s[2]+s[2]#s[1]+s[3]#s[]) + (s[]#s[4]+s[1]#s[3]+s[2]#s[2]+s[3]#s[1]+s[4]#s[]) @@ -5567,24 +5584,25 @@ def __call__(self, *args, check=True): TESTS:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: S = LazySymmetricFunctions(s) # optional - sage.modules - sage: f = 1 / (1 - S(s[2])) # optional - sage.modules - sage: g = f(s[2]); g # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: S = LazySymmetricFunctions(s) + sage: f = 1 / (1 - S(s[2])) + sage: g = f(s[2]); g s[] + (s[2,2]+s[4]) + O^7 - sage: S(sum(f[i](s[2]) for i in range(5))).truncate(10) == g.truncate(10) # optional - sage.modules + sage: S(sum(f[i](s[2]) for i in range(5))).truncate(10) == g.truncate(10) True - sage: f = 1 / (1 - S(s[2])) # optional - sage.modules - sage: g = S(s[1]) / (1 - S(s[1])) # optional - sage.modules - sage: f(g) # optional - sage.modules + sage: f = 1 / (1 - S(s[2])) + sage: g = S(s[1]) / (1 - S(s[1])) + sage: f(g) s[] + s[2] + (s[1,1,1]+2*s[2,1]+s[3]) + (2*s[1,1,1,1]+4*s[2,1,1]+5*s[2,2]+5*s[3,1]+3*s[4]) + (2*s[1,1,1,1,1]+10*s[2,1,1,1]+14*s[2,2,1]+18*s[3,1,1]+16*s[3,2]+14*s[4,1]+4*s[5]) + (3*s[1,1,1,1,1,1]+22*s[2,1,1,1,1]+38*s[2,2,1,1]+28*s[2,2,2]+48*s[3,1,1,1]+82*s[3,2,1]+25*s[3,3]+51*s[4,1,1]+56*s[4,2]+31*s[5,1]+9*s[6]) + O^7 - sage: f(0) # optional - sage.modules + sage: f(0) 1 - sage: f(s(1)) # optional - sage.modules + sage: f(s(1)) Traceback (most recent call last): ... ValueError: can only compose with a positive valuation series @@ -5592,22 +5610,23 @@ def __call__(self, *args, check=True): Check that composing the zero series with anything yields zero in the correct parent:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.modules - sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: L = LazySymmetricFunctions(tensor([e, h])) # optional - sage.modules - sage: r = (L(0)(s[1], p[1])); r # optional - sage.modules + sage: # needs sage.modules + sage: e = SymmetricFunctions(QQ).e() + sage: h = SymmetricFunctions(QQ).h() + sage: s = SymmetricFunctions(QQ).s() + sage: p = SymmetricFunctions(QQ).p() + sage: L = LazySymmetricFunctions(tensor([e, h])) + sage: r = (L(0)(s[1], p[1])); r 0 - sage: r.parent() # optional - sage.modules + sage: r.parent() Symmetric Functions over Rational Field in the Schur basis Check that composing `f` with zero series yields the constant term of `f`:: - sage: f = 3*L(tensor([s[1], s[1]])) # optional - sage.modules - sage: f(0, 0) # optional - sage.modules + sage: f = 3*L(tensor([s[1], s[1]])) # needs sage.modules + sage: f(0, 0) # needs sage.modules 0 - sage: (3+f)(0, 0) # optional - sage.modules + sage: (3+f)(0, 0) # needs sage.modules 3 """ fP = parent(self) @@ -5694,39 +5713,41 @@ def revert(self): EXAMPLES:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules - sage: L = LazySymmetricFunctions(h) # optional - sage.modules - sage: f = L(lambda n: h[n]) - 1 # optional - sage.modules - sage: f(f.revert()) # optional - sage.modules + sage: # needs sage.modules + sage: h = SymmetricFunctions(QQ).h() + sage: L = LazySymmetricFunctions(h) + sage: f = L(lambda n: h[n]) - 1 + sage: f(f.revert()) h[1] + O^8 TESTS:: - sage: f = L(lambda n: h[n]) - 1 - h[1] # optional - sage.modules - sage: g = f.revert() # optional - sage.modules - sage: g[1] # optional - sage.modules + sage: f = L(lambda n: h[n]) - 1 - h[1] # needs sage.modules + sage: g = f.revert() # needs sage.modules + sage: g[1] # needs sage.modules Traceback (most recent call last): ... ValueError: compositional inverse does not exist - sage: R. = QQ[] # optional - sage.modules - sage: p = SymmetricFunctions(R.fraction_field()).p() # optional - sage.modules - sage: L = LazySymmetricFunctions(p) # optional - sage.modules - sage: f = L(a + b*p[1]) # optional - sage.modules - sage: f.revert() # optional - sage.modules + sage: # needs sage.modules + sage: R. = QQ[] + sage: p = SymmetricFunctions(R.fraction_field()).p() + sage: L = LazySymmetricFunctions(p) + sage: f = L(a + b*p[1]) + sage: f.revert() (((-a)/b)*p[]) + 1/b*p[1] - sage: f = L(2*p[1]) # optional - sage.modules - sage: f.revert() # optional - sage.modules + sage: f = L(2*p[1]) # needs sage.modules + sage: f.revert() # needs sage.modules 1/2*p[1] - sage: f = L(2*p[1] + p[1,1]) # optional - sage.modules - sage: f.revert() # optional - sage.modules + sage: f = L(2*p[1] + p[1,1]) # needs sage.modules + sage: f.revert() # needs sage.modules 1/2*p[1] + (-1/8*p[1,1]) + (1/16*p[1,1,1]) + (-5/128*p[1,1,1,1]) + (7/256*p[1,1,1,1,1]) + (-21/1024*p[1,1,1,1,1,1]) + (33/2048*p[1,1,1,1,1,1,1]) + O^8 - sage: f.revert()(f) # optional - sage.modules + sage: f.revert()(f) # needs sage.modules p[1] + O^8 ALGORITHM: @@ -5819,33 +5840,36 @@ def derivative_with_respect_to_p1(self, n=1): The species `E` of sets satisfies the relationship `E' = E`:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules - sage: T = LazySymmetricFunctions(h) # optional - sage.modules - sage: E = T(lambda n: h[n]) # optional - sage.modules - sage: E - E.derivative_with_respect_to_p1() # optional - sage.modules + sage: # needs sage.modules + sage: h = SymmetricFunctions(QQ).h() + sage: T = LazySymmetricFunctions(h) + sage: E = T(lambda n: h[n]) + sage: E - E.derivative_with_respect_to_p1() O^6 The species `C` of cyclic orderings and the species `L` of linear orderings satisfy the relationship `C' = L`:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) # optional - sage.modules + sage: # needs sage.modules + sage: p = SymmetricFunctions(QQ).p() + sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) ....: for k in divisors(n))/n if n > 0 else 0)) - sage: L = T(lambda n: p([1]*n)) # optional - sage.modules - sage: L - C.derivative_with_respect_to_p1() # optional - sage.modules + sage: L = T(lambda n: p([1]*n)) + sage: L - C.derivative_with_respect_to_p1() O^6 TESTS:: - sage: T = LazySymmetricFunctions(p) # optional - sage.modules - sage: a = T(p([1,1,1])) # optional - sage.modules - sage: a.derivative_with_respect_to_p1() # optional - sage.modules + sage: # needs sage.modules + sage: T = LazySymmetricFunctions(p) + sage: a = T(p([1,1,1])) + sage: a.derivative_with_respect_to_p1() (3*p[1,1]) + O^9 - sage: a.derivative_with_respect_to_p1(1) # optional - sage.modules + sage: a.derivative_with_respect_to_p1(1) (3*p[1,1]) + O^9 - sage: a.derivative_with_respect_to_p1(2) # optional - sage.modules + sage: a.derivative_with_respect_to_p1(2) 6*p[1] + O^8 - sage: a.derivative_with_respect_to_p1(3) # optional - sage.modules + sage: a.derivative_with_respect_to_p1(3) 6*p[] + O^7 """ P = self.parent() @@ -5900,12 +5924,12 @@ def functorial_composition(self, *args): :class:`~sage.combinat.species.subset_species.SubsetSpecies`.:: sage: R. = QQ[] - sage: h = SymmetricFunctions(R).h() # optional - sage.modules - sage: m = SymmetricFunctions(R).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: P = L(lambda n: sum(q^k*h[n-k]*h[k] for k in range(n+1))) # optional - sage.modules - sage: P2 = L(lambda n: h[2]*h[n-2], valuation=2) # optional - sage.modules - sage: P.functorial_composition(P2)[:4] # optional - sage.modules + sage: h = SymmetricFunctions(R).h() # needs sage.modules + sage: m = SymmetricFunctions(R).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules + sage: P = L(lambda n: sum(q^k*h[n-k]*h[k] for k in range(n+1))) # needs sage.modules + sage: P2 = L(lambda n: h[2]*h[n-2], valuation=2) # needs sage.modules + sage: P.functorial_composition(P2)[:4] # needs sage.modules [m[], m[1], (q+1)*m[1, 1] + (q+1)*m[2], @@ -5913,12 +5937,12 @@ def functorial_composition(self, *args): For example, there are:: - sage: P.functorial_composition(P2)[4].coefficient([4])[3] # optional - sage.modules + sage: P.functorial_composition(P2)[4].coefficient([4])[3] # needs sage.modules 3 unlabelled graphs on 4 vertices and 3 edges, and:: - sage: P.functorial_composition(P2)[4].coefficient([2,2])[3] # optional - sage.modules + sage: P.functorial_composition(P2)[4].coefficient([2,2])[3] # needs sage.modules 8 labellings of their vertices with two 1's and two 2's. @@ -5926,43 +5950,46 @@ def functorial_composition(self, *args): The symmetric function `h_1 \sum_n h_n` is the neutral element with respect to functorial composition:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules - sage: e = SymmetricFunctions(QQ).e() # optional - sage.modules - sage: L = LazySymmetricFunctions(h) # optional - sage.modules - sage: E = L(lambda n: h[n]) # optional - sage.modules - sage: Ep = p[1]*E.derivative_with_respect_to_p1(); Ep # optional - sage.modules + sage: # needs sage.modules + sage: p = SymmetricFunctions(QQ).p() + sage: h = SymmetricFunctions(QQ).h() + sage: e = SymmetricFunctions(QQ).e() + sage: L = LazySymmetricFunctions(h) + sage: E = L(lambda n: h[n]) + sage: Ep = p[1]*E.derivative_with_respect_to_p1(); Ep h[1] + (h[1,1]) + (h[2,1]) + (h[3,1]) + (h[4,1]) + (h[5,1]) + O^7 - sage: f = L(lambda n: h[n-n//2, n//2]) # optional - sage.modules - sage: f - Ep.functorial_composition(f) # optional - sage.modules + sage: f = L(lambda n: h[n-n//2, n//2]) + sage: f - Ep.functorial_composition(f) O^7 The functorial composition distributes over the sum:: - sage: F1 = L(lambda n: h[n]) # optional - sage.modules - sage: F2 = L(lambda n: e[n]) # optional - sage.modules - sage: f1 = F1.functorial_composition(f) # optional - sage.modules - sage: f2 = F2.functorial_composition(f) # optional - sage.modules - sage: (F1 + F2).functorial_composition(f) - f1 - f2 # long time # optional - sage.modules + sage: # needs sage.modules + sage: F1 = L(lambda n: h[n]) + sage: F2 = L(lambda n: e[n]) + sage: f1 = F1.functorial_composition(f) + sage: f2 = F2.functorial_composition(f) + sage: (F1 + F2).functorial_composition(f) - f1 - f2 # long time O^7 TESTS: Check a corner case:: - sage: h = SymmetricFunctions(QQ).h() # optional - sage.modules - sage: L = LazySymmetricFunctions(h) # optional - sage.modules - sage: L(h[2,1]).functorial_composition(3*h[0]) # optional - sage.modules + sage: h = SymmetricFunctions(QQ).h() # needs sage.modules + sage: L = LazySymmetricFunctions(h) # needs sage.modules + sage: L(h[2,1]).functorial_composition(3*h[0]) # needs sage.modules 3*h[] + O^7 Check an instance of a non-group action:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: L = LazySymmetricFunctions(p) # optional - sage.modules - sage: f = L(lambda n: s[n]) # optional - sage.modules - sage: g = 2*s[2, 1, 1] + s[2, 2] + 3*s[4] # optional - sage.modules - sage: r = f.functorial_composition(g); r[4] # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: p = SymmetricFunctions(QQ).p() + sage: L = LazySymmetricFunctions(p) + sage: f = L(lambda n: s[n]) + sage: g = 2*s[2, 1, 1] + s[2, 2] + 3*s[4] + sage: r = f.functorial_composition(g); r[4] Traceback (most recent call last): ... ValueError: the argument is not the Frobenius character of a permutation representation @@ -6111,14 +6138,15 @@ def arithmetic_product(self, *args, check=True): consistent for all the lists in the structure. :: sage: R. = QQ[] - sage: p = SymmetricFunctions(R).p() # optional - sage.modules - sage: m = SymmetricFunctions(R).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - - sage: C = species.CycleSpecies().cycle_index_series() # optional - sage.modules - sage: c = L(lambda n: C[n]) # optional - sage.modules - sage: Lplus = L(lambda n: p([1]*n), valuation=1) # optional - sage.modules - sage: r = c.arithmetic_product(Lplus); r # optional - sage.modules + sage: p = SymmetricFunctions(R).p() # needs sage.modules + sage: m = SymmetricFunctions(R).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules + + sage: # needs sage.modules + sage: C = species.CycleSpecies().cycle_index_series() + sage: c = L(lambda n: C[n]) + sage: Lplus = L(lambda n: p([1]*n), valuation=1) + sage: r = c.arithmetic_product(Lplus); r m[1] + (3*m[1,1]+2*m[2]) + (8*m[1,1,1]+4*m[2,1]+2*m[3]) + (42*m[1,1,1,1]+21*m[2,1,1]+12*m[2,2]+7*m[3,1]+3*m[4]) @@ -6128,7 +6156,7 @@ def arithmetic_product(self, *args, check=True): In particular, the number of regular octopuses is:: - sage: [r[n].coefficient([1]*n) for n in range(8)] # optional - sage.modules + sage: [r[n].coefficient([1]*n) for n in range(8)] # needs sage.modules [0, 1, 3, 8, 42, 144, 1440, 5760] It is shown in [MM2008]_ that the exponential generating @@ -6136,7 +6164,7 @@ def arithmetic_product(self, *args, check=True): (x) = \sum_{n \geq 1} \sigma (n) (n - 1)! \frac{x^{n}}{n!}` (where `\sigma (n)` is the sum of the divisors of `n`). :: - sage: [sum(divisors(i))*factorial(i-1) for i in range(1,8)] # optional - sage.modules + sage: [sum(divisors(i))*factorial(i-1) for i in range(1,8)] # needs sage.modules [1, 3, 8, 42, 144, 1440, 5760] AUTHORS: @@ -6151,37 +6179,38 @@ def arithmetic_product(self, *args, check=True): Check that the product with zero works:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: L(0).arithmetic_product(s[2]) # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: L = LazySymmetricFunctions(s) + sage: L(0).arithmetic_product(s[2]) 0 - sage: L(s[2]).arithmetic_product(0) # optional - sage.modules + sage: L(s[2]).arithmetic_product(0) 0 Check that the arithmetic product of symmetric functions of finite support works:: - sage: L(s([2])).arithmetic_product(s([1,1,1])) # optional - sage.modules + sage: L(s([2])).arithmetic_product(s([1,1,1])) # needs sage.modules s[2, 2, 1, 1] + s[3, 1, 1, 1] + s[3, 2, 1] + s[3, 3] + 2*s[4, 1, 1] - sage: f = 1/(1-L(s[1])) # optional - sage.modules - sage: f.arithmetic_product(s[1]) - f # optional - sage.modules + sage: f = 1/(1-L(s[1])) # needs sage.modules + sage: f.arithmetic_product(s[1]) - f # needs sage.modules O^7 Check that the arithmetic product of symmetric functions with constant a term works as advertised:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: L = LazySymmetricFunctions(p) # optional - sage.modules - sage: L(5).arithmetic_product(3*p[2,1]) # optional - sage.modules + sage: p = SymmetricFunctions(QQ).p() # needs sage.modules + sage: L = LazySymmetricFunctions(p) # needs sage.modules + sage: L(5).arithmetic_product(3*p[2,1]) # needs sage.modules 15*p[] Check the arithmetic product of symmetric functions over a finite field works:: - sage: s = SymmetricFunctions(FiniteField(2)).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: L(s([2])).arithmetic_product(s([1,1,1])) # optional - sage.modules + sage: s = SymmetricFunctions(FiniteField(2)).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: L(s([2])).arithmetic_product(s([1,1,1])) # needs sage.modules s[2, 2, 1, 1] + s[3, 1, 1, 1] + s[3, 2, 1] + s[3, 3] """ @@ -6278,36 +6307,39 @@ def symmetric_function(self, degree=None): EXAMPLES:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: S = LazySymmetricFunctions(s) # optional - sage.modules - sage: elt = S(s[2]) # optional - sage.modules - sage: elt.symmetric_function() # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: S = LazySymmetricFunctions(s) + sage: elt = S(s[2]) + sage: elt.symmetric_function() s[2] TESTS:: - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: S = LazySymmetricFunctions(s) # optional - sage.modules - sage: elt = S(s[2]) # optional - sage.modules - sage: elt.symmetric_function() # optional - sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: S = LazySymmetricFunctions(s) + sage: elt = S(s[2]) + sage: elt.symmetric_function() s[2] - sage: f = 1 / (1 - elt) # optional - sage.modules - sage: f # optional - sage.modules + sage: f = 1 / (1 - elt) + sage: f s[] + s[2] + (s[2,2]+s[3,1]+s[4]) + (s[2,2,2]+2*s[3,2,1]+s[3,3]+s[4,1,1]+3*s[4,2]+2*s[5,1]+s[6]) + O^7 - sage: f.symmetric_function() # optional - sage.modules + sage: f.symmetric_function() Traceback (most recent call last): ... ValueError: not a symmetric function - sage: f4 = f.truncate(5); f4 # optional - sage.modules + sage: # needs sage.modules + sage: f4 = f.truncate(5); f4 s[] + s[2] + (s[2,2]+s[3,1]+s[4]) - sage: f4.symmetric_function() # optional - sage.modules + sage: f4.symmetric_function() s[] + s[2] + s[2, 2] + s[3, 1] + s[4] - sage: f4.symmetric_function() == f.symmetric_function(4) # optional - sage.modules + sage: f4.symmetric_function() == f.symmetric_function(4) True - sage: S.zero().symmetric_function() # optional - sage.modules + sage: S.zero().symmetric_function() 0 - sage: f4.symmetric_function(0) # optional - sage.modules + sage: f4.symmetric_function(0) s[] """ @@ -6337,15 +6369,15 @@ class LazyDirichletSeries(LazyModuleElement): sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: f = L(constant=1)^2 - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic 1 + 2/2^z + 2/3^z + 3/4^z + 2/5^z + 4/6^z + 2/7^z + O(1/(8^z)) - sage: f.coefficient(100) == number_of_divisors(100) # optional - sage.libs.pari + sage: f.coefficient(100) == number_of_divisors(100) # needs sage.libs.pari True Lazy Dirichlet series is picklable:: sage: g = loads(dumps(f)) - sage: g # optional - sage.symbolic + sage: g # needs sage.symbolic 1 + 2/2^z + 2/3^z + 3/4^z + 2/5^z + 4/6^z + 2/7^z + O(1/(8^z)) sage: g == f True @@ -6385,9 +6417,9 @@ def valuation(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, "z") - sage: mu = L(moebius); mu.valuation() # optional - sage.libs.pari + sage: mu = L(moebius); mu.valuation() # needs sage.libs.pari 0 - sage: (mu - mu).valuation() # optional - sage.libs.pari + sage: (mu - mu).valuation() # needs sage.libs.pari +Infinity sage: g = L(constant=1, valuation=2) sage: g.valuation() @@ -6412,36 +6444,36 @@ def _mul_(self, other): sage: D = LazyDirichletSeriesRing(QQ, "s") sage: zeta = D(constant=1) - sage: zeta # optional - sage.symbolic + sage: zeta # needs sage.symbolic 1 + 1/(2^s) + 1/(3^s) + O(1/(4^s)) - sage: zeta * zeta # optional - sage.symbolic + sage: zeta * zeta # needs sage.symbolic 1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)) sage: [number_of_divisors(n) for n in range(1, 8)] [1, 2, 2, 3, 2, 4, 2] sage: mu = D(moebius) - sage: mu # optional - sage.symbolic + sage: mu # needs sage.symbolic 1 - 1/(2^s) - 1/(3^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(8^s)) - sage: zeta * mu # optional - sage.symbolic + sage: zeta * mu # needs sage.symbolic 1 + O(1/(8^s)) sage: D.one() * mu is mu True sage: mu * D.one() is mu True - sage: zeta*(2-zeta) # optional - sage.symbolic + sage: zeta*(2-zeta) # needs sage.symbolic 1 - 1/(4^s) - 2/6^s + O(1/(8^s)) sage: d1 = D([0,0,1,2,3]) sage: d2 = D([0,1,2,3]) - sage: d1 * d2 # optional - sage.symbolic + sage: d1 * d2 # needs sage.symbolic 1/(6^s) + 2/8^s + 2/9^s + 3/10^s + 7/12^s + O(1/(13^s)) - sage: d1 * d2 # not tested - exact result # optional - sage.symbolic + sage: d1 * d2 # not tested # needs sage.symbolic 1/(6^s) + 2/8^s + 2/9^s + 3/10^s + 7/12^s + 6/15^s + 6/16^s + 9/20^s sage: L. = LazyLaurentSeriesRing(D) - sage: 1/(1-t*zeta) # optional - sage.symbolic + sage: 1/(1-t*zeta) # needs sage.symbolic (1 + O(1/(8^s))) + (1 + 1/(2^s) + 1/(3^s) + 1/(4^s) + 1/(5^s) + 1/(6^s) + 1/(7^s) + O(1/(8^s)))*t + (1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)))*t^2 @@ -6555,7 +6587,7 @@ def __call__(self, p, *, check=True): Infinity sage: f = D([1,2,-3,-4], valuation=2) - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic 1/(2^s) + 2/3^s - 3/4^s - 4/5^s sage: f(2) 449/3600 @@ -6625,22 +6657,22 @@ def _format_series(self, formatter, format_strings=False): sage: L = LazyDirichletSeriesRing(QQ, "s") sage: f = L(constant=1) - sage: f._format_series(repr) # optional - sage.symbolic + sage: f._format_series(repr) # needs sage.symbolic '1 + 1/(2^s) + 1/(3^s) + O(1/(4^s))' - sage: f._format_series(unicode_art) # optional - sage.symbolic + sage: f._format_series(unicode_art) # needs sage.symbolic -s -s 1 + 2 + 3 + O(1/(4^s)) - sage: L([1,-1,1])._format_series(repr) # optional - sage.symbolic + sage: L([1,-1,1])._format_series(repr) # needs sage.symbolic '1 - 1/(2^s) + 1/(3^s)' - sage: L([1,-1,1])._format_series(ascii_art) # optional - sage.symbolic + sage: L([1,-1,1])._format_series(ascii_art) # needs sage.symbolic -s -s 1 + -2 + 3 sage: R. = QQ[] sage: L = LazyDirichletSeriesRing(R, "s") - sage: L([1,-1 + x,1/3])._format_series(ascii_art) # optional - sage.symbolic + sage: L([1,-1 + x,1/3])._format_series(ascii_art) # needs sage.symbolic ( -s) (3 ) ( -s ) (---) @@ -6649,9 +6681,9 @@ def _format_series(self, formatter, format_strings=False): sage: L. = LazyLaurentSeriesRing(QQ) sage: D = LazyDirichletSeriesRing(L, "s") sage: f = D([2, 0, 1/(1-z), 3]) - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic (2)/1^s + ((1+z+z^2+O(z^3))/3^s) + (3)/4^s - sage: f._format_series(ascii_art) # optional - sage.symbolic + sage: f._format_series(ascii_art) # needs sage.symbolic ((2)/1^s) + ((1 + z + z^2 + O(z^3))/3^s) + ((3)/4^s) """ P = self.parent() diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index e105188d7fe..07ea18fafa0 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -155,10 +155,10 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No If ``x`` can be converted into an element of the underlying Laurent polynomial ring, we do this:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L(2) # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: L(2) # needs sage.rings.finite_rings 0 - sage: L(3) # optional - sage.rings.finite_rings + sage: L(3) # needs sage.rings.finite_rings 1 In particular, ``x`` can be a Laurent polynomial:: @@ -287,21 +287,22 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No Converting various series from a univariate power series:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: R = LazyPowerSeriesRing(ZZ, 'z') # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(R) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: R = LazyPowerSeriesRing(ZZ, 'z') + sage: L.has_coerce_map_from(R) True - sage: L(R(lambda n: n)) # optional - sage.rings.finite_rings + sage: L(R(lambda n: n)) z + z^3 + z^5 + z^7 + O(z^8) - sage: L(R([2,4,6])) == L.zero() # optional - sage.rings.finite_rings + sage: L(R([2,4,6])) == L.zero() True - sage: L(R([2,4,6], valuation=2, constant=4)) == L.zero() # optional - sage.rings.finite_rings + sage: L(R([2,4,6], valuation=2, constant=4)) == L.zero() True - sage: L(R([2,4,6], valuation=2, constant=5)) # optional - sage.rings.finite_rings + sage: L(R([2,4,6], valuation=2, constant=5)) z^5 + z^6 + z^7 + O(z^8) - sage: L(R([2,3,4], valuation=2, constant=4)) # optional - sage.rings.finite_rings + sage: L(R([2,3,4], valuation=2, constant=4)) z^3 - sage: L(R([2,3,4], valuation=2, constant=5)) # optional - sage.rings.finite_rings + sage: L(R([2,3,4], valuation=2, constant=5)) z^3 + z^5 + z^6 + z^7 + O(z^8) Can only convert from known to be constant multivariate power series:: @@ -712,9 +713,9 @@ def one(self): sage: L.one() 1 - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: L.one() # optional - sage.modules + sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules + sage: L.one() # needs sage.modules m[] """ @@ -733,9 +734,9 @@ def zero(self): sage: L.zero() 0 - sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: L.zero() # optional - sage.modules + sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: L.zero() # needs sage.modules 0 sage: L = LazyDirichletSeriesRing(ZZ, 'z') @@ -759,14 +760,14 @@ def characteristic(self): sage: L.characteristic() 0 - sage: R. = LazyLaurentSeriesRing(GF(11)); R # optional - sage.rings.finite_rings + sage: R. = LazyLaurentSeriesRing(GF(11)); R # needs sage.rings.finite_rings Lazy Laurent Series Ring in w over Finite Field of size 11 - sage: R.characteristic() # optional - sage.rings.finite_rings + sage: R.characteristic() # needs sage.rings.finite_rings 11 - sage: R. = LazyPowerSeriesRing(GF(7)); R # optional - sage.rings.finite_rings + sage: R. = LazyPowerSeriesRing(GF(7)); R # needs sage.rings.finite_rings Multivariate Lazy Taylor Series Ring in x, y over Finite Field of size 7 - sage: R.characteristic() # optional - sage.rings.finite_rings + sage: R.characteristic() # needs sage.rings.finite_rings 7 sage: L = LazyDirichletSeriesRing(ZZ, "s") @@ -781,13 +782,13 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: L.has_coerce_map_from(ZZ) # needs sage.rings.finite_rings True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) # needs sage.rings.finite_rings True sage: R = LazyPowerSeriesRing(ZZ, 'z') - sage: L.has_coerce_map_from(R) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(R) # needs sage.rings.finite_rings True sage: L = LazyLaurentSeriesRing(QQ, 'z') @@ -801,17 +802,18 @@ def _coerce_map_from_(self, S): sage: L.has_coerce_map_from(R) False - sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: L.has_coerce_map_from(ZZ) # needs sage.rings.finite_rings True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) # needs sage.rings.finite_rings True - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.modules sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() + sage: L = LazySymmetricFunctions(s) + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.modules sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) True """ if self.base_ring().has_coerce_map_from(S): @@ -845,13 +847,13 @@ def _coerce_map_from_base_ring(self): sage: L = LazyDirichletSeriesRing(QQ, 'z') sage: phi = L._coerce_map_from_base_ring() sage: m = phi(2) - sage: m # optional - sage.symbolic + sage: m # needs sage.symbolic 2 sage: m = phi(2, valuation=2) - sage: m # optional - sage.symbolic + sage: m # needs sage.symbolic 2/2^z sage: m = phi(2, valuation=2, constant=4) - sage: m # optional - sage.symbolic + sage: m # needs sage.symbolic 2/2^z + 4/3^z + 4/4^z + 4/5^z + O(1/(6^z)) """ # Return a DefaultConvertMap_unique; this can pass additional @@ -1050,12 +1052,13 @@ class LazyLaurentSeriesRing(LazySeriesRing): Lazy Laurent series ring over a finite field:: - sage: L. = LazyLaurentSeriesRing(GF(3)); L # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(3)); L Lazy Laurent Series Ring in z over Finite Field of size 3 - sage: e = 1 / (1 + z) # optional - sage.rings.finite_rings - sage: e.coefficient(100) # optional - sage.rings.finite_rings + sage: e = 1 / (1 + z) + sage: e.coefficient(100) 1 - sage: e.coefficient(100).parent() # optional - sage.rings.finite_rings + sage: e.coefficient(100).parent() Finite Field of size 3 Series can be defined by specifying a coefficient function @@ -1197,21 +1200,21 @@ def __init__(self, base_ring, names, sparse=True, category=None): and Category of infinite sets sage: L = LazyLaurentSeriesRing(ZZ['x, y'], 't') - sage: TestSuite(L).run() # optional - sage.libs.singular + sage: TestSuite(L).run() # needs sage.libs.singular sage: L.category() Category of infinite commutative no zero divisors algebras over (unique factorization domains and commutative algebras over (euclidean domains and infinite enumerated sets and metric spaces) and infinite sets) - sage: L = LazyLaurentSeriesRing(GF(5), 't') # optional - sage.rings.finite_rings - sage: TestSuite(L).run() # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(5), 't') # needs sage.rings.finite_rings + sage: TestSuite(L).run() # needs sage.rings.finite_rings - sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't') # optional - sage.rings.finite_rings - sage: TestSuite(L).run() # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't') # needs sage.rings.finite_rings + sage: TestSuite(L).run() # needs sage.rings.finite_rings - sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') # optional - sage.rings.finite_rings - sage: TestSuite(L).run() # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') # needs sage.rings.finite_rings + sage: TestSuite(L).run() # needs sage.rings.finite_rings sage: L = LazyLaurentSeriesRing(Zmod(6), 't') sage: TestSuite(L).run(skip=['_test_revert']) @@ -1220,8 +1223,8 @@ def __init__(self, base_ring, names, sparse=True, category=None): (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) - sage: E. = ExteriorAlgebra(QQ) # optional - sage.modules - sage: L = LazyLaurentSeriesRing(E, 't') # not tested # optional - sage.modules + sage: E. = ExteriorAlgebra(QQ) # needs sage.modules + sage: L = LazyLaurentSeriesRing(E, 't') # not tested # needs sage.modules sage: LazyLaurentSeriesRing.options._reset() # reset the options """ @@ -1254,7 +1257,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings Lazy Laurent Series Ring in z over Finite Field of size 2 """ return "Lazy Laurent Series Ring in {} over {}".format(self.variable_name(), self.base_ring()) @@ -1265,8 +1268,8 @@ def _latex_(self): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: latex(L) # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: latex(L) # needs sage.rings.finite_rings \Bold{F}_{2} (\!(z)\!) """ from sage.misc.latex import latex @@ -1351,16 +1354,16 @@ def some_elements(self): -2*z^-3 - 2*z^-2 + 4*z^-1 + 11 - z - 34*z^2 - 31*z^3 + O(z^4), 4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + O(z^5)] - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L.some_elements()[:7] # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: L.some_elements()[:7] # needs sage.rings.finite_rings [0, 1, z, z^-4 + z^-3 + z^2 + z^3, z^-2, 1 + z + z^3 + z^4 + z^6 + O(z^7), z^-1 + z + z^3 + O(z^5)] - sage: L = LazyLaurentSeriesRing(GF(3), 'z') # optional - sage.rings.finite_rings - sage: L.some_elements()[:7] # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(3), 'z') # needs sage.rings.finite_rings + sage: L.some_elements()[:7] # needs sage.rings.finite_rings [0, 1, z, z^-3 + z^-1 + 2 + z + z^2 + z^3, z^-2, @@ -1603,7 +1606,7 @@ def euler(self): sage: P = 1 / phi; P 1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + O(q^7) - sage: P[:20] == [Partitions(n).cardinality() for n in range(20)] # optional - sage.libs.flint + sage: P[:20] == [Partitions(n).cardinality() for n in range(20)] # needs sage.libs.flint True TESTS:: @@ -1668,11 +1671,11 @@ def __init__(self, base_ring, names, sparse=True, category=None): sage: L = LazyPowerSeriesRing(QQ, 's, t') sage: TestSuite(L).run(skip="_test_fraction_field") - sage: L = LazyPowerSeriesRing(GF(5), 't') # optional - sage.rings.finite_rings - sage: TestSuite(L).run() # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(5), 't') # needs sage.rings.finite_rings + sage: TestSuite(L).run() # needs sage.rings.finite_rings - sage: L = LazyPowerSeriesRing(GF(5), 's, t') # optional - sage.rings.finite_rings - sage: TestSuite(L).run(skip=['_test_fraction_field']) # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(5), 's, t') # needs sage.rings.finite_rings + sage: TestSuite(L).run(skip=['_test_fraction_field']) # needs sage.rings.finite_rings sage: L = LazyPowerSeriesRing(Zmod(6), 't') sage: TestSuite(L).run(skip=['_test_revert']) @@ -1754,7 +1757,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings Lazy Taylor Series Ring in z over Finite Field of size 2 """ BR = self.base_ring() @@ -1769,8 +1772,8 @@ def _latex_(self): EXAMPLES:: - sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: latex(L) # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: latex(L) # needs sage.rings.finite_rings \Bold{F}_{2} [\![z]\!] """ from sage.misc.latex import latex @@ -1868,10 +1871,10 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No EXAMPLES:: - sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L(2) # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: L(2) # needs sage.rings.finite_rings 0 - sage: L(3) # optional - sage.rings.finite_rings + sage: L(3) # needs sage.rings.finite_rings 1 sage: L = LazyPowerSeriesRing(ZZ, 'z') @@ -1937,11 +1940,11 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No (a + b + 1)/(c^3 + a*b + 1) sage: f.parent() Fraction Field of Multivariate Polynomial Ring in a, b, c over Integer Ring - sage: L(f) # optional - sage.libs.singular + sage: L(f) # needs sage.libs.singular 1 + (a+b) + (-a*b) + (-a^2*b-a*b^2-c^3) + (a^2*b^2-a*c^3-b*c^3) + (a^3*b^2+a^2*b^3+2*a*b*c^3) + (-a^3*b^3+2*a^2*b*c^3+2*a*b^2*c^3+c^6) + O(a,b,c)^7 - sage: L(f) == (1 + aa + bb) / (1 + aa*bb + cc^3) # optional - sage.libs.singular + sage: L(f) == (1 + aa + bb) / (1 + aa*bb + cc^3) # needs sage.libs.singular True TESTS:: @@ -2190,15 +2193,15 @@ def some_elements(self): 1 + z - 2*z^2 - 7*z^3 - z^4 + 20*z^5 + 23*z^6 + O(z^7), z + 4*z^2 + 9*z^3 + 16*z^4 + 25*z^5 + 36*z^6 + O(z^7)] - sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z') # optional - sage.rings.finite_rings - sage: L.some_elements()[:6] # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z') # needs sage.rings.finite_rings + sage: L.some_elements()[:6] # needs sage.rings.finite_rings [0, 1, z + q*z^2 + q*z^3 + q*z^4 + O(z^5), z + z^2 + z^3, 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6), z + z^2 + z^4 + z^5 + O(z^7)] - sage: L = LazyPowerSeriesRing(GF(3), 'q, t') # optional - sage.rings.finite_rings - sage: L.some_elements()[:6] # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(3), 'q, t') # needs sage.rings.finite_rings + sage: L.some_elements()[:6] # needs sage.rings.finite_rings [0, 1, q, q + q^2 + q^3, 1 + q + q^2 + (-q^3) + (-q^4) + (-q^5) + (-q^6) + O(q,t)^7, @@ -2237,26 +2240,27 @@ class LazyCompletionGradedAlgebra(LazySeriesRing): EXAMPLES:: - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # optional - sage.modules - sage: S = NCSF.Complete() # optional - sage.modules - sage: L = S.formal_series_ring(); L # optional - sage.modules + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # needs sage.modules + sage: S = NCSF.Complete() # needs sage.modules + sage: L = S.formal_series_ring(); L # needs sage.modules Lazy completion of Non-Commutative Symmetric Functions over the Rational Field in the Complete basis - sage: f = 1 / (1 - L(S[1])); f # optional - sage.modules + sage: # needs sage.modules + sage: f = 1 / (1 - L(S[1])); f S[] + S[1] + (S[1,1]) + (S[1,1,1]) + (S[1,1,1,1]) + (S[1,1,1,1,1]) + (S[1,1,1,1,1,1]) + O^7 - sage: g = 1 / (1 - L(S[2])); g # optional - sage.modules + sage: g = 1 / (1 - L(S[2])); g S[] + S[2] + (S[2,2]) + (S[2,2,2]) + O^7 - sage: f * g # optional - sage.modules + sage: f * g S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[1,2]) + (S[1,1,1,1]+S[1,1,2]+S[2,2]) + (S[1,1,1,1,1]+S[1,1,1,2]+S[1,2,2]) + (S[1,1,1,1,1,1]+S[1,1,1,1,2]+S[1,1,2,2]+S[2,2,2]) + O^7 - sage: g * f # optional - sage.modules + sage: g * f S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[2,1]) + (S[1,1,1,1]+S[2,1,1]+S[2,2]) + (S[1,1,1,1,1]+S[2,1,1,1]+S[2,2,1]) + (S[1,1,1,1,1,1]+S[2,1,1,1,1]+S[2,2,1,1]+S[2,2,2]) + O^7 - sage: f * g - g * f # optional - sage.modules + sage: f * g - g * f (S[1,2]-S[2,1]) + (S[1,1,2]-S[2,1,1]) + (S[1,1,1,2]+S[1,2,2]-S[2,1,1,1]-S[2,2,1]) + (S[1,1,1,1,2]+S[1,1,2,2]-S[2,1,1,1,1]-S[2,2,1,1]) + O^7 @@ -2271,23 +2275,23 @@ def __init__(self, basis, sparse=True, category=None): sage: LazySymmetricFunctions.options.halting_precision(6) - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: TestSuite(L).run() # optional - sage.modules + sage: s = SymmetricFunctions(QQ).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: TestSuite(L).run() # needs sage.modules - sage: p = SymmetricFunctions(GF(5)).p() # optional - sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(p) # optional - sage.modules sage.rings.finite_rings - sage: TestSuite(L).run() # optional - sage.modules sage.rings.finite_rings + sage: p = SymmetricFunctions(GF(5)).p() # needs sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(p) # needs sage.modules sage.rings.finite_rings + sage: TestSuite(L).run() # needs sage.modules sage.rings.finite_rings Reversion will only work when the base ring is a field:: - sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: TestSuite(L).run(skip=['_test_revert']) # optional - sage.modules + sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: TestSuite(L).run(skip=['_test_revert']) # needs sage.modules - sage: s = SymmetricFunctions(QQ["q"]).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: TestSuite(L).run(skip=['_test_revert']) # optional - sage.modules + sage: s = SymmetricFunctions(QQ["q"]).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: TestSuite(L).run(skip=['_test_revert']) # needs sage.modules Options are remembered across doctests:: @@ -2296,15 +2300,15 @@ def __init__(self, basis, sparse=True, category=None): Check that :trac:`34470` is fixed. The ideal generated by `p[1]` and `p[2]` is not principal:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.modules - sage: L = LazySymmetricFunctions(s) # optional - sage.modules - sage: L in PrincipalIdealDomains # optional - sage.modules + sage: p = SymmetricFunctions(QQ).p() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: L in PrincipalIdealDomains # needs sage.modules False Check that a basis which is not graded is not enough:: - sage: ht = SymmetricFunctions(ZZ).ht() # optional - sage.modules - sage: L = LazySymmetricFunctions(ht) # optional - sage.modules + sage: ht = SymmetricFunctions(ZZ).ht() # needs sage.modules + sage: L = LazySymmetricFunctions(ht) # needs sage.modules Traceback (most recent call last): ... ValueError: basis should be in GradedAlgebrasWithBasis @@ -2343,8 +2347,8 @@ def _repr_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.modules sage.rings.finite_rings - sage: LazySymmetricFunctions(s) # optional - sage.modules sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.modules sage.rings.finite_rings + sage: LazySymmetricFunctions(s) # needs sage.modules sage.rings.finite_rings Lazy completion of Symmetric Functions over Finite Field of size 2 in the Schur basis """ return "Lazy completion of {}".format(self._laurent_poly_ring) @@ -2355,9 +2359,9 @@ def _latex_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.modules sage.rings.finite_rings - sage: latex(L) # optional - sage.modules sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # needs sage.modules sage.rings.finite_rings + sage: latex(L) # needs sage.modules sage.rings.finite_rings \text{\texttt{Symmetric{ }Functions{ }over{ }Finite{ }Field{ }of{ }size{ }2{ }in{ }the{ }Schur{ }basis}} """ from sage.misc.latex import latex @@ -2369,10 +2373,11 @@ def _monomial(self, c, n): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: L._monomial(s[2,1], 3) # optional - sage.modules + sage: # needs sage.modules + sage: m = SymmetricFunctions(ZZ).m() + sage: s = SymmetricFunctions(ZZ).s() + sage: L = LazySymmetricFunctions(m) + sage: L._monomial(s[2,1], 3) 2*m[1, 1, 1] + m[2, 1] """ L = self._laurent_poly_ring @@ -2394,62 +2399,65 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No EXAMPLES:: - sage: m = SymmetricFunctions(GF(2)).m() # optional - sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(m) # optional - sage.modules sage.rings.finite_rings - sage: L(2) # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings + sage: m = SymmetricFunctions(GF(2)).m() + sage: L = LazySymmetricFunctions(m) + sage: L(2) 0 - sage: L(3) # optional - sage.modules sage.rings.finite_rings + sage: L(3) m[] - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: f = L(lambda i: m([i]), valuation=5, degree=10); f # optional - sage.modules + sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules + sage: f = L(lambda i: m([i]), valuation=5, degree=10); f # needs sage.modules m[5] + m[6] + m[7] + m[8] + m[9] - sage: f.coefficient(6) # optional - sage.modules + sage: f.coefficient(6) # needs sage.modules m[6] - sage: f[20] # optional - sage.modules + sage: f[20] # needs sage.modules 0 Alternatively, ``x`` can be a list of elements of the base ring. Then these elements are read as coefficients of the terms of degrees starting from the ``valuation``:: - sage: f = L([m[1],m[2],m[3]], valuation=1); f # optional - sage.modules + sage: f = L([m[1],m[2],m[3]], valuation=1); f # needs sage.modules m[1] + m[2] + m[3] Finally, ``x`` can be a symmetric function:: - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: L(s.an_element()) # optional - sage.modules + sage: # needs sage.modules + sage: m = SymmetricFunctions(ZZ).m() + sage: s = SymmetricFunctions(ZZ).s() + sage: L = LazySymmetricFunctions(m) + sage: L(s.an_element()) 2*m[] + 2*m[1] + (3*m[1,1]+3*m[2]) TESTS:: - sage: e = SymmetricFunctions(ZZ).e() # optional - sage.modules - sage: h = SymmetricFunctions(ZZ).h() # optional - sage.modules - sage: L = LazySymmetricFunctions(tensor([h, e])) # optional - sage.modules - sage: L(lambda n: 0) # optional - sage.modules + sage: # needs sage.modules + sage: e = SymmetricFunctions(ZZ).e() + sage: h = SymmetricFunctions(ZZ).h() + sage: L = LazySymmetricFunctions(tensor([h, e])) + sage: L(lambda n: 0) O^7 - sage: L(lambda n: tensor([h[n], e([])]) + tensor([h([]), e[n]]), degree=3) # optional - sage.modules + sage: L(lambda n: tensor([h[n], e([])]) + tensor([h([]), e[n]]), degree=3) # needs sage.modules (2*h[]#e[]) + (h[]#e[1]+h[1]#e[]) + (h[]#e[2]+h[2]#e[]) - sage: L(lambda n: n)[3]; # optional - sage.modules + sage: L(lambda n: n)[3]; # needs sage.modules Traceback (most recent call last): ... ValueError: coefficient 3*h[] # e[] should be an element of homogeneous degree 3 but has degree 0 - sage: L([1, 2, 3]); # optional - sage.modules + sage: L([1, 2, 3]); # needs sage.modules Traceback (most recent call last): ... ValueError: coefficient 2*h[] # e[] should be an element of homogeneous degree 1 but has degree 0 - sage: L(lambda n: n, degree=3); # optional - sage.modules + sage: L(lambda n: n, degree=3); # needs sage.modules Traceback (most recent call last): ... ValueError: coefficient h[] # e[] should be an element @@ -2568,9 +2576,9 @@ def _an_element_(self): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: L = LazySymmetricFunctions(m) # optional - sage.modules - sage: L.an_element() # optional - sage.modules + sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules + sage: L.an_element() # needs sage.modules 2*m[] + 2*m[1] + 3*m[2] """ return self(self._laurent_poly_ring.an_element()) @@ -2581,9 +2589,9 @@ def some_elements(self): EXAMPLES:: - sage: m = SymmetricFunctions(GF(5)).m() # optional - sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(m) # optional - sage.modules sage.rings.finite_rings - sage: L.some_elements()[:5] # optional - sage.modules sage.rings.finite_rings + sage: m = SymmetricFunctions(GF(5)).m() # needs sage.modules sage.rings.finite_rings + sage: L = LazySymmetricFunctions(m) # needs sage.modules sage.rings.finite_rings + sage: L.some_elements()[:5] # needs sage.modules sage.rings.finite_rings [0, m[], 2*m[] + 2*m[1] + 3*m[2], 2*m[1] + 3*m[2], 3*m[] + 2*m[1] + (m[1,1]+m[2]) + (2*m[1,1,1]+m[3]) @@ -2592,10 +2600,11 @@ def some_elements(self): + (2*m[2,2,1,1]+m[2,2,2]+2*m[3,2,1]+2*m[3,3]+m[4,1,1]+3*m[4,2]+4*m[5,1]+4*m[6]) + O^7] - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # optional - sage.modules - sage: S = NCSF.Complete() # optional - sage.modules - sage: L = S.formal_series_ring() # optional - sage.modules - sage: L.some_elements()[:4] # optional - sage.modules + sage: # needs sage.modules + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) + sage: S = NCSF.Complete() + sage: L = S.formal_series_ring() + sage: L.some_elements()[:4] [0, S[], 2*S[] + 2*S[1] + (3*S[1,1]), 2*S[1] + (3*S[1,1])] """ @@ -2634,12 +2643,12 @@ class LazySymmetricFunctions(LazyCompletionGradedAlgebra): EXAMPLES:: - sage: s = SymmetricFunctions(ZZ).s() # optional - sage.modules - sage: LazySymmetricFunctions(s) # optional - sage.modules + sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules + sage: LazySymmetricFunctions(s) # needs sage.modules Lazy completion of Symmetric Functions over Integer Ring in the Schur basis - sage: m = SymmetricFunctions(ZZ).m() # optional - sage.modules - sage: LazySymmetricFunctions(tensor([s, m])) # optional - sage.modules + sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules + sage: LazySymmetricFunctions(tensor([s, m])) # needs sage.modules Lazy completion of Symmetric Functions over Integer Ring in the Schur basis # Symmetric Functions over Integer Ring in the monomial basis @@ -2728,7 +2737,7 @@ def _laurent_poly_ring(self): TESTS:: sage: L = LazyDirichletSeriesRing(ZZ, 't') - sage: L._laurent_poly_ring is SR # optional - sage.symbolic + sage: L._laurent_poly_ring is SR # needs sage.symbolic True """ from sage.symbolic.ring import SR @@ -2743,10 +2752,10 @@ def __init__(self, base_ring, names, sparse=True, category=None): sage: LazyDirichletSeriesRing.options.halting_precision(12) sage: L = LazyDirichletSeriesRing(ZZ, 't') - sage: TestSuite(L).run() # optional - sage.symbolic + sage: TestSuite(L).run() # needs sage.symbolic sage: L = LazyDirichletSeriesRing(QQ, 't') - sage: TestSuite(L).run() # optional - sage.symbolic + sage: TestSuite(L).run() # needs sage.symbolic sage: LazyDirichletSeriesRing.options._reset() # reset the options @@ -2774,7 +2783,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyDirichletSeriesRing(QQbar, 'z') # optional - sage.rings.number_field + sage: LazyDirichletSeriesRing(QQbar, 'z') # needs sage.rings.number_field Lazy Dirichlet Series Ring in z over Algebraic Field """ return "Lazy Dirichlet Series Ring in {} over {}".format(self.variable_name(), self.base_ring()) @@ -2787,9 +2796,9 @@ def one(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: L.one() # optional - sage.symbolic + sage: L.one() # needs sage.symbolic 1 - sage: ~L.one() # optional - sage.symbolic + sage: ~L.one() # needs sage.symbolic 1 + O(1/(8^z)) """ R = self.base_ring() @@ -2828,31 +2837,31 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: L = LazyDirichletSeriesRing(ZZ, 'z') sage: R = L(3) - sage: R # optional - sage.symbolic + sage: R # needs sage.symbolic 3 sage: S = L(lambda i: i, constant=1, degree=6) - sage: S # optional - sage.symbolic + sage: S # needs sage.symbolic 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 1/(6^z) + 1/(7^z) + 1/(8^z) + O(1/(9^z)) sage: X = L(constant=5, degree=3) - sage: X # optional - sage.symbolic + sage: X # needs sage.symbolic 5/3^z + 5/4^z + 5/5^z + O(1/(6^z)) sage: X.valuation() log(3) sage: e = L(moebius) - sage: e # optional - sage.symbolic + sage: e # needs sage.symbolic 1 - 1/(2^z) - 1/(3^z) - 1/(5^z) + 1/(6^z) - 1/(7^z) + O(1/(8^z)) sage: T = L([0], constant=1) - sage: T # optional - sage.symbolic + sage: T # needs sage.symbolic 1/(2^z) + 1/(3^z) + 1/(4^z) + O(1/(5^z)) sage: U = L(constant=1) - sage: U # optional - sage.symbolic + sage: U # needs sage.symbolic 1 + 1/(2^z) + 1/(3^z) + O(1/(4^z)) sage: V = L(lambda i: i, valuation=3) - sage: V # optional - sage.symbolic + sage: V # needs sage.symbolic 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + 8/8^z + 9/9^z + O(1/(10^z)) Alternatively, ``x`` can be a list of elements of the base ring. @@ -2862,16 +2871,16 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No simply omitted if it is zero:: sage: f = L([1,2,3,4], 4) - sage: f # optional - sage.symbolic + sage: f # needs sage.symbolic 1/(4^z) + 2/5^z + 3/6^z + 4/7^z sage: g = L([1,3,5,7,9], 6, constant=-1) - sage: g # optional - sage.symbolic + sage: g # needs sage.symbolic 1/(6^z) + 3/7^z + 5/8^z + 7/9^z + 9/10^z - 1/(11^z) - 1/(12^z) - 1/(13^z) + O(1/(14^z)) TESTS:: - sage: L = LazyDirichletSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: L = LazyDirichletSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: positive characteristic not allowed for Dirichlet series @@ -2879,27 +2888,27 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: L. = LazyLaurentSeriesRing(QQ) sage: D = LazyDirichletSeriesRing(QQ, 't') sage: d = D(L.one()) - sage: d # optional - sage.symbolic + sage: d # needs sage.symbolic 1 + 1/(2^t) + 1/(3^t) + 1/(4^t) + 1/(5^t) + 1/(6^t) + 1/(7^t) + O(1/(8^t)) sage: R. = LaurentPolynomialRing(QQ) sage: D = LazyDirichletSeriesRing(QQ, 't') sage: dd = D(coefficients=z + z^2) - sage: dd # optional - sage.symbolic + sage: dd # needs sage.symbolic 2 + 6/2^t + 12/3^t + 20/4^t + 30/5^t + 42/6^t + 56/7^t + O(1/(8^t)) sage: s = D(lambda n: n) sage: d2 = D(s, valuation=2) - sage: d2 # optional - sage.symbolic + sage: d2 # needs sage.symbolic 1/(2^t) + 2/3^t + 3/4^t + 4/5^t + 5/6^t + 6/7^t + 7/8^t + O(1/(9^t)) sage: Ds = LazyDirichletSeriesRing(ZZ, 's') sage: m = Ds(moebius, valuation=2) - sage: m # optional - sage.symbolic + sage: m # needs sage.symbolic -1/(2^s) - 1/(3^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(9^s)) sage: D = LazyDirichletSeriesRing(QQ, 't') sage: dm = D(m) - sage: dm # optional - sage.symbolic + sage: dm # needs sage.symbolic -1/(2^t) - 1/(3^t) - 1/(5^t) + 1/(6^t) - 1/(7^t) + O(1/(9^t)) """ if isinstance(x, (list, tuple)): @@ -2945,7 +2954,7 @@ def _an_element_(self): sage: L = LazyDirichletSeriesRing(ZZ, 'z') sage: m = L.an_element() - sage: m # optional - sage.symbolic + sage: m # needs sage.symbolic 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)) """ c = self.base_ring().an_element() @@ -2959,7 +2968,7 @@ def some_elements(self): sage: L = LazyDirichletSeriesRing(ZZ, 'z') sage: l = L.some_elements() - sage: l # optional - sage.symbolic + sage: l # needs sage.symbolic [0, 1, 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)), 1/(2^z) - 1/(3^z) + 2/4^z - 2/5^z + 3/6^z - 3/7^z + 4/8^z - 4/9^z, @@ -2968,7 +2977,7 @@ def some_elements(self): sage: L = LazyDirichletSeriesRing(QQ, 'z') sage: l = L.some_elements() - sage: l # optional - sage.symbolic + sage: l # needs sage.symbolic [0, 1, 1/2/4^z + 1/2/5^z + 1/2/6^z + O(1/(7^z)), 1/2 - 1/2/2^z + 2/3^z - 2/4^z + 1/(6^z) - 1/(7^z) + 42/8^z + 2/3/9^z, @@ -2990,7 +2999,7 @@ def _monomial(self, c, n): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: m = L._monomial(5, 3); m # optional - sage.symbolic + sage: m = L._monomial(5, 3); m # needs sage.symbolic 5/3^z """ try: @@ -3010,11 +3019,12 @@ def _skip_leading_zeros(iterator): sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] - sage: it = map(GF(3), NN) # optional - sage.rings.finite_rings - sage: [x for x, _ in zip(it, range(10))] # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: it = map(GF(3), NN) + sage: [x for x, _ in zip(it, range(10))] [0, 1, 2, 0, 1, 2, 0, 1, 2, 0] - sage: it = map(GF(3), NN) # optional - sage.rings.finite_rings - sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] # optional - sage.rings.finite_rings + sage: it = map(GF(3), NN) + sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] [1, 2, 0, 1, 2, 0, 1, 2, 0, 1] """ while True: diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index bda24010204..b43fc573102 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]]) # needs sage.modules + sage: m.parent() # needs 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__ # needs sage.modules [ 1/5 -7/55] [ 0 1/11] - sage: _.parent() # optional - sage.modules + sage: _.parent() # needs 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) # needs sage.modules + sage: mi.parent() # needs 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 # needs sage.modules True The next example defines the most general ring containing the coefficients of the irreducible @@ -34,48 +34,51 @@ 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 # optional - sage.libs.pari + sage: L = R.localization(tuple(add_units)); L # needs 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) 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: # needs sage.libs.pari sage.modules + sage: m1 = matrix(L, [[u1, 0, 0], [0, u0, 0], [0, 0, u0]]) + sage: m2 = matrix(L, [[(u0*q - u0)/(u0 - u1), (u0*q - u1)/(u0 - u1), 0], ....: [(-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], ....: [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 True Check relations of the Ariki-Koike algebra:: - sage: m1*m2*m1*m2 == m2*m1*m2*m1 # optional - sage.modules + sage: # needs sage.libs.pari sage.modules + sage: m1*m2*m1*m2 == m2*m1*m2*m1 True - sage: m2*m3*m2 == m3*m2*m3 # optional - sage.modules + sage: m2*m3*m2 == m3*m2*m3 True - sage: m1*m3 == m3*m1 # optional - sage.modules + sage: m1*m3 == m3*m1 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 True - sage: m2**2 - (q-1)*m2 - q == 0 # optional - sage.modules + sage: m2**2 - (q-1)*m2 - q == 0 True - sage: m3**2 - (q-1)*m3 - q == 0 # optional - sage.modules + sage: m3**2 - (q-1)*m3 - q == 0 True - sage: ~m1 in m1.parent() # optional - sage.modules + sage: ~m1 in m1.parent() True - sage: ~m2 in m2.parent() # optional - sage.modules + sage: ~m2 in m2.parent() True - sage: ~m3 in m3.parent() # optional - sage.modules + sage: ~m3 in m3.parent() True Obtain specializations in positive characteristic:: - 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 + sage: # needs sage.rings.finite_rings + sage: Fp = GF(17) + sage: f = L.hom((3,5,7,11), codomain=Fp); f # needs sage.libs.pari 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, @@ -85,24 +88,25 @@ u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 # optional - sage.modules sage.rings.finite_rings + sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 # needs sage.libs.pari sage.modules [5 0 0] [0 3 0] [0 0 3] - sage: mFp1.base_ring() # optional - sage.modules sage.rings.finite_rings + sage: mFp1.base_ring() # needs sage.libs.pari sage.modules Finite Field of size 17 - sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 # optional - sage.modules sage.rings.finite_rings + sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 # needs sage.libs.pari sage.modules [ 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.modules sage.rings.finite_rings + sage: mFp3 = matrix({k: f(v) for k, v in m3.dict().items()}); mFp3 # needs sage.libs.pari sage.modules [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.rings.finite_rings + sage: # needs sage.libs.pari + sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ 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, @@ -112,25 +116,25 @@ u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 # optional - sage.modules sage.rings.finite_rings + sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 # needs sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mQ1.base_ring() # optional - sage.modules sage.rings.finite_rings + sage: mQ1.base_ring() # needs sage.modules sage.rings.finite_rings Rational Field - sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 # optional - sage.modules sage.rings.finite_rings + sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 # needs 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.modules sage.rings.finite_rings + sage: mQ3 = matrix({k: fQ(v) for k, v in m3.dict().items()}); mQ3 # needs 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() # optional - sage.libs.singular - sage: fF = L.hom((x, y, z, t), codomain=F); fF # optional - sage.libs.singular + sage: F = T.fraction_field() # needs sage.libs.pari sage.libs.singular + sage: fF = L.hom((x, y, z, t), codomain=F); fF # needs sage.libs.pari 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, @@ -141,16 +145,16 @@ u1 |--> ybar u2 |--> zbar q |--> tbar - sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # optional - sage.libs.singular sage.modules + sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # needs sage.libs.pari sage.libs.singular sage.modules [ ybar 0 0] [ 0 -ybar - zbar 0] [ 0 0 -ybar - zbar] - sage: mF1.base_ring() == F # optional - sage.libs.singular sage.modules + sage: mF1.base_ring() == F # needs sage.libs.pari sage.libs.singular sage.modules True TESTS:: - sage: TestSuite(L).run() # optional - sage.libs.singular sage.modules + sage: TestSuite(L).run() # needs sage.libs.pari sage.libs.singular sage.modules AUTHORS: @@ -199,21 +203,23 @@ def normalize_extra_units(base_ring, add_units, warning=True): sage: normalize_extra_units(ZZ, [3, -15, 45, 9, 2, 50]) [2, 3, 5] sage: P. = ZZ[] - sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) # optional - sage.libs.pari + sage: normalize_extra_units(P, # needs sage.libs.pari + ....: [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) [2, 3, 5, z, y, x] sage: P. = QQ[] - sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) # optional - sage.libs.pari + sage: normalize_extra_units(P, # needs sage.libs.pari + ....: [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) [z, y, x] sage: R. = ZZ[] - 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 + sage: Q. = R.quo(x**2 - 5) # needs sage.libs.singular + sage: p = b**2 - 5 # needs sage.libs.singular + sage: p == (b-a)*(b+a) # needs sage.libs.singular True - sage: normalize_extra_units(Q, [p]) # optional - sage.libs.pari + sage: normalize_extra_units(Q, [p]) # needs sage.libs.pari sage.libs.singular doctest:...: UserWarning: Localization may not be represented uniquely [b^2 - 5] - sage: normalize_extra_units(Q, [p], warning=False) # optional - sage.libs.pari + sage: normalize_extra_units(Q, [p], warning=False) # needs sage.libs.pari sage.libs.singular [b^2 - 5] """ # convert to base ring @@ -250,13 +256,15 @@ class LocalizationElement(IntegralDomainElement): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: from sage.rings.localization import LocalizationElement - sage: P. = GF(5)[] # optional - sage.rings.finite_rings - sage: L = P.localization((x, y*z-x)) # optional - sage.rings.finite_rings - sage: LocalizationElement(L, 4/(y*z-x)**2) # optional - sage.rings.finite_rings + sage: P. = GF(5)[] + sage: L = P.localization((x, y*z - x)) + sage: LocalizationElement(L, 4/(y*z-x)**2) (-1)/(y^2*z^2 - 2*x*y*z + x^2) - sage: _.parent() # optional - sage.rings.finite_rings - Multivariate Polynomial Ring in x, y, z over Finite Field of size 5 localized at (x, y*z - x) + sage: _.parent() + Multivariate Polynomial Ring in x, y, z over Finite Field of size 5 + localized at (x, y*z - x) """ def __init__(self, parent, x): @@ -267,9 +275,9 @@ def __init__(self, parent, x): sage: from sage.rings.localization import LocalizationElement sage: P. = RR[] - sage: L = Localization(P, x**2 + x + 1) # optional - sage.libs.pari - sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) # optional - sage.libs.pari - sage: l._value == (x**2+1)/(x**2+x+1) # optional - sage.libs.pari + sage: L = Localization(P, x**2 + x + 1) # needs sage.libs.pari + sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) # needs sage.libs.pari + sage: l._value == (x**2+1)/(x**2+x+1) # needs sage.libs.pari True """ IntegralDomainElement.__init__(self, parent) @@ -281,11 +289,12 @@ def _repr_(self): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: from sage.rings.localization import LocalizationElement - sage: P. = CC[] # optional - sage.rings.real_mpfr - sage: L = Localization(P, x**2 + x + 1) # optional - sage.rings.real_mpfr - sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) # optional - sage.rings.real_mpfr - sage: l._repr_() == str(l) # optional - sage.rings.real_mpfr + sage: P. = CC[] + sage: L = Localization(P, x**2 + x + 1) + sage: l = LocalizationElement(L, (x**2+1)/(x**2+x+1)) + sage: l._repr_() == str(l) True sage: R. = ZZ[] @@ -391,8 +400,8 @@ def factor(self, proof=None): sage: P. = QQ['x, y'] sage: L = P.localization(X - Y) sage: x, y = L.gens() - sage: p = (x^2 - y^2)/(x-y)^2 # optional - sage.libs.singular - sage: p.factor() # optional - sage.libs.singular + sage: p = (x^2 - y^2)/(x-y)^2 # needs sage.libs.singular + sage: p.factor() # needs sage.libs.singular (1/(x - y)) * (x + y) """ num = self._value.numerator() @@ -411,9 +420,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - 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 + sage: L = Localization(R, x**2 + 1) # needs sage.libs.pari + sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # needs sage.libs.pari + sage: f(x/(x**2+1)) # needs sage.libs.pari 5/26 """ return self._value._im_gens_(codomain, im_gens, base_map=base_map) @@ -449,12 +458,12 @@ def is_unit(self): EXAMPLES:: sage: P. = QQ[] - sage: L = P.localization((x, y*z)) # optional - sage.libs.pari - sage: L(y*z).is_unit() # optional - sage.libs.pari + sage: L = P.localization((x, y*z)) # needs sage.libs.pari + sage: L(y*z).is_unit() # needs sage.libs.pari True - sage: L(z).is_unit() # optional - sage.libs.pari + sage: L(z).is_unit() # needs sage.libs.pari True - sage: L(x*y*z).is_unit() # optional - sage.libs.pari + sage: L(x*y*z).is_unit() # needs sage.libs.pari True """ return self.parent()._cut_off_extra_units_from_base_ring_element(self._value.numerator()).is_unit() @@ -467,9 +476,9 @@ def inverse_of_unit(self): sage: P. = ZZ[] sage: L = Localization(P, x*y*z) - sage: L(x*y*z).inverse_of_unit() # optional - sage.libs.singular + sage: L(x*y*z).inverse_of_unit() # needs sage.libs.singular 1/(x*y*z) - sage: L(z).inverse_of_unit() # optional - sage.libs.singular + sage: L(z).inverse_of_unit() # needs sage.libs.singular 1/z """ parent = self.parent() @@ -481,11 +490,12 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: P. = GF(7)[] + sage: L = Localization(P, (x, y, z)) + sage: L(1/x) < L(3/(x*y*z)**3) False - sage: ~L(y*z/x) == L(x/(y*z)) # optional - sage.rings.finite_rings + sage: ~L(y*z/x) == L(x/(y*z)) True """ sval = self._value @@ -518,8 +528,8 @@ def _rational_(self): TESTS:: sage: L = ZZ.localization(5) - 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 + sage: cp3 = cyclotomic_polynomial(3).change_ring(L) + sage: cp3.splitting_field('t') # indirect doctest # needs sage.libs.pari sage.rings.number_field Number Field in t with defining polynomial x^2 + x + 1 """ from sage.rings.rational_field import QQ @@ -601,42 +611,42 @@ class Localization(IntegralDomain, UniqueRepresentation): ... ValueError: factor 7 of denominator is not a unit - sage: Localization(Zp(7), (3, 5)) # optional - sage.rings.padics + sage: Localization(Zp(7), (3, 5)) # needs sage.rings.padics Traceback (most recent call last): ... 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) # optional - sage.libs.pari + sage: L = R.localization(x**2 + 1) # needs sage.libs.pari sage: s = (x+5)/(x**2+1) - sage: s in L # optional - sage.libs.pari + sage: s in L # needs sage.libs.pari True sage: t = (x+5)/(x**2+2) - sage: t in L # optional - sage.libs.pari + sage: t in L False - sage: L(t) # optional - sage.libs.pari + sage: L(t) # needs sage.libs.pari Traceback (most recent call last): ... TypeError: fraction must have unit denominator - sage: L(s) in R # optional - sage.libs.pari + sage: L(s) in R # needs sage.libs.pari False - sage: y = L(x) # optional - sage.libs.pari - sage: g = L(s) # optional - sage.libs.pari - sage: g.parent() # optional - sage.libs.pari + sage: y = L(x) # needs sage.libs.pari + sage: g = L(s) # needs sage.libs.pari + sage: g.parent() # needs sage.libs.pari Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) - sage: f = (y+5)/(y**2+1); f # optional - sage.libs.pari + sage: f = (y+5)/(y**2+1); f # needs sage.libs.pari (x + 5)/(x^2 + 1) - sage: f == g # optional - sage.libs.pari + sage: f == g # needs sage.libs.pari True - sage: (y+5)/(y**2+2) # optional - sage.libs.pari + sage: (y+5)/(y**2+2) # needs 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(~u).parent() + sage: Lau. = LaurentPolynomialRing(ZZ) # needs sage.modules + sage: LauL = Lau.localization(u + 1) # needs sage.modules + sage: LauL(~u).parent() # needs sage.modules Multivariate Polynomial Ring in u, v over Integer Ring localized at (v, u, u + 1) More examples will be shown typing ``sage.rings.localization?`` @@ -662,8 +672,8 @@ def __init__(self, base_ring, extra_units, names=None, normalize=True, category= sage: TestSuite(L).run() sage: R. = ZZ[] - sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari - sage: TestSuite(L).run() # optional - sage.libs.pari + sage: L = R.localization(x**2 + 1) # needs sage.libs.pari + sage: TestSuite(L).run() """ if type(extra_units) is tuple: extra_units = list(extra_units) @@ -703,8 +713,8 @@ def _repr_(self): EXAMPLES:: - sage: R. = GF(3)[] # optional - sage.rings.finite_rings - sage: Localization(R, a**2 - 1) # optional - sage.rings.finite_rings + sage: R. = GF(3)[] + sage: Localization(R, a**2 - 1) # needs sage.rings.finite_rings Univariate Polynomial Ring in a over Finite Field of size 3 localized at (a + 1, a + 2) """ @@ -735,13 +745,13 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari - sage: L.hom([5]) # indirect doctest # optional - sage.libs.pari + sage: L = Localization(R, x**2 + 1) # needs sage.libs.pari + sage: L.hom([5]) # indirect doctest # needs 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 # optional - sage.libs.pari + sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # needs sage.libs.pari Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) @@ -751,22 +761,22 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): TESTS:: sage: phi = R.hom([5]) - sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) # optional - sage.libs.pari + sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) # needs 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) # optional - sage.libs.pari + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # needs 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) # optional - sage.libs.pari + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # needs 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) # optional - sage.libs.pari + sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) # needs sage.libs.pari True """ B = self.base_ring() @@ -798,7 +808,7 @@ def ngens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2 + 1, y - 1)).ngens() # optional - sage.libs.pari + sage: Localization(R, (x**2 + 1, y - 1)).ngens() # needs sage.libs.pari 2 sage: Localization(ZZ, 2).ngens() @@ -814,7 +824,7 @@ def gen(self, i): EXAMPLES:: sage: R. = ZZ[] - sage: R.localization((x**2 + 1, y - 1)).gen(0) # optional - sage.libs.pari + sage: R.localization((x**2 + 1, y - 1)).gen(0) # needs sage.libs.pari x sage: ZZ.localization(2).gen(0) @@ -830,7 +840,7 @@ def gens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2 + 1, y - 1)).gens() # optional - sage.libs.pari + sage: Localization(R, (x**2 + 1, y - 1)).gens() # needs sage.libs.pari (x, y) sage: Localization(ZZ, 2).gens() @@ -854,10 +864,10 @@ def _cut_off_extra_units_from_base_ring_element(self, x): EXAMPLES:: sage: P. = QQ[] - 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 + sage: L = Localization(P, (x, y*z)) # needs sage.libs.pari + sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) # needs sage.libs.pari 1 - sage: L._cut_off_extra_units_from_base_ring_element(x*z) # optional - sage.libs.pari + sage: L._cut_off_extra_units_from_base_ring_element(x*z) # needs sage.libs.pari 1 TESTS: @@ -898,15 +908,15 @@ def _fraction_to_element(self, x): sage: P. = QQ[] 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 + sage: L = Localization(P, d) # needs sage.libs.pari + sage: L._fraction_to_element((x+y+z)/d) # needs sage.libs.pari (x + y + z)/(x^2 + y^2 + z^2) - sage: _ in L # optional - sage.libs.pari + sage: _ in L # needs sage.libs.pari True TESTS:: - sage: TestSuite(L).run() # optional - sage.libs.pari + sage: TestSuite(L).run() # needs 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(): @@ -924,21 +934,21 @@ def _coerce_map_from_(self, S): sage: P. = QQ[] sage: L = Localization(P, y*z) - sage: M = Localization(P, (x, y, z)) - sage: M._coerce_map_from_(L) + sage: M = Localization(P, (x, y, z)) # needs sage.libs.pari + sage: M._coerce_map_from_(L) # needs sage.libs.pari True - sage: L._coerce_map_from_(M) + sage: L._coerce_map_from_(M) # needs sage.libs.pari False sage: Q. = ZZ[] sage: N = Localization(Q, v*w) sage: L._coerce_map_from_(N) True - sage: N._coerce_map_from_(M) + sage: N._coerce_map_from_(M) # needs sage.libs.pari False - sage: O = Localization(L, x**2 + 1) - sage: O._coerce_map_from_(M) + sage: O = Localization(L, x**2 + 1) # needs sage.libs.pari + sage: O._coerce_map_from_(M) # needs sage.libs.pari False - sage: O._coerce_map_from_(L) + sage: O._coerce_map_from_(L) # needs sage.libs.pari True """ if S is self.base_ring(): @@ -954,11 +964,12 @@ def fraction_field(self): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: L = Localization(R, (a**2 - 3, a)) + sage: L.fraction_field() Fraction Field of Univariate Polynomial Ring in a over Finite Field of size 5 - sage: L.is_subring(_) # optional - sage.rings.finite_rings + sage: L.is_subring(_) True """ return self._fraction_field @@ -969,9 +980,9 @@ def characteristic(self): EXAMPLES:: - 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 + sage: R. = GF(5)[] + sage: L = R.localization((a**2 - 3, a)) # needs sage.rings.finite_rings + sage: L.characteristic() # needs sage.rings.finite_rings 5 """ return self.base_ring().characteristic() diff --git a/src/sage/rings/monomials.py b/src/sage/rings/monomials.py index 0beb25a1044..9a96157c153 100644 --- a/src/sage/rings/monomials.py +++ b/src/sage/rings/monomials.py @@ -9,7 +9,7 @@ def _monomials(gens, R, n, i): EXAMPLES:: - sage: monomials([x], [3]) # indirect doctest + sage: monomials([x], [3]) # indirect doctest # needs sage.symbolic [1, x, x^2] """ # each power of the ith generator times all products @@ -51,7 +51,7 @@ def monomials(v, n): EXAMPLES:: - sage: monomials([x], [3]) + sage: monomials([x], [3]) # needs sage.symbolic [1, x, x^2] sage: R. = QQ[] sage: monomials([x,y], [5,5]) diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 9e5b1b0f551..565d1b69316 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -33,24 +33,25 @@ EXAMPLES: Reduction to finite field:: - 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 + sage: # needs sage.rings.finite_rings + sage: H = Hom(ZZ, GF(9, 'a')) + sage: phi = H([1]) + sage: phi(5) 2 - sage: psi = H([4]) # optional - sage.rings.finite_rings - sage: psi(5) # optional - sage.rings.finite_rings + sage: psi = H([4]) + sage: psi(5) 2 Map from single variable polynomial ring:: sage: R. = ZZ[] - sage: phi = R.hom([2], GF(5)) # optional - sage.rings.finite_rings - sage: phi # optional - sage.rings.finite_rings + sage: phi = R.hom([2], GF(5)) + sage: phi Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 5 Defn: x |--> 2 - sage: phi(x + 12) # optional - sage.rings.finite_rings + sage: phi(x + 12) 4 Identity map on the real numbers:: @@ -70,8 +71,8 @@ Homomorphism from one precision of field to another. From smaller to bigger doesn't make sense:: - sage: R200 = RealField(200) - sage: f = RR.hom( R200 ) + sage: R200 = RealField(200) # needs sage.rings.real_mpfr + sage: f = RR.hom( R200 ) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: natural coercion morphism from Real Field with 53 bits of precision @@ -79,7 +80,7 @@ From smaller to bigger doesn't make sense:: From bigger to small does:: - sage: f = RR.hom( RealField(15) ) + sage: f = RR.hom( RealField(15) ) # needs sage.rings.real_mpfr sage: f(2.5) 2.500 sage: f(RR.pi()) @@ -109,16 +110,16 @@ A map from a multivariate polynomial ring to itself:: An endomorphism of a quotient of a multi-variate polynomial ring:: sage: R. = PolynomialRing(QQ) - sage: S. = quo(R, ideal(1 + y^2)) # optional - sage.libs.singular - sage: phi = S.hom([a^2, -b]) # optional - sage.libs.singular - sage: phi # optional - sage.libs.singular + sage: S. = quo(R, ideal(1 + y^2)) # needs sage.libs.singular + sage: phi = S.hom([a^2, -b]) # needs sage.libs.singular + sage: phi # needs sage.libs.singular 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) # optional - sage.libs.singular + sage: phi(b) # needs sage.libs.singular -b - sage: phi(a^2 + b^2) # optional - sage.libs.singular + sage: phi(a^2 + b^2) # needs sage.libs.singular a^4 - 1 The reduction map from the integers to the integers modulo 8, viewed as @@ -147,28 +148,30 @@ a quotient ring:: Inclusion of ``GF(2)`` into ``GF(4,'a')``:: - 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 + sage: # needs sage.rings.finite_rings + sage: k = GF(2) + sage: i = k.hom(GF(4, 'a')) + sage: i Ring morphism: From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: i(0) # optional - sage.rings.finite_rings + sage: i(0) 0 - sage: a = i(1); a.parent() # optional - sage.rings.finite_rings + sage: a = i(1); a.parent() 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) # optional - sage.rings.finite_rings - sage: pi # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: pi = ZZ.hom(k) + sage: pi Natural morphism: From: Integer Ring To: Finite Field of size 2 - sage: f = i * pi # optional - sage.rings.finite_rings - sage: f # optional - sage.rings.finite_rings + sage: f = i * pi + sage: f Composite map: From: Integer Ring To: Finite Field in a of size 2^2 @@ -180,40 +183,41 @@ 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 # optional - sage.rings.finite_rings + sage: a = f(5); a 1 - sage: a.parent() # optional - sage.rings.finite_rings + sage: a.parent() 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: # needs sage.rings.padics + sage: phi = QQ.hom(Qp(3, print_mode='series')) + sage: phi Ring morphism: From: Rational Field To: 3-adic Field with capped relative precision 20 - sage: phi.codomain() # optional - sage.rings.padics + sage: phi.codomain() 3-adic Field with capped relative precision 20 - sage: phi(394) # optional - sage.rings.padics + sage: phi(394) 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) # optional - sage.libs.pari - sage: sqrt2^2 # optional - sage.libs.pari + sage: S. = R.quo(x^2 - 2) # needs sage.libs.pari + sage: sqrt2^2 # needs sage.libs.pari 2 - sage: (3+sqrt2)^10 # optional - sage.libs.pari + sage: (3+sqrt2)^10 # needs sage.libs.pari 993054*sqrt2 + 1404491 - sage: c = S.hom([-sqrt2]) # optional - sage.libs.pari - sage: c(1+sqrt2) # optional - sage.libs.pari + sage: c = S.hom([-sqrt2]) # needs sage.libs.pari + sage: c(1+sqrt2) # needs sage.libs.pari -sqrt2 + 1 Note that Sage verifies that the morphism is valid:: - sage: (1 - sqrt2)^2 # optional - sage.libs.pari + sage: (1 - sqrt2)^2 # needs sage.libs.pari -2*sqrt2 + 3 - sage: c = S.hom([1 - sqrt2]) # this is not valid # optional - sage.libs.pari + sage: c = S.hom([1 - sqrt2]) # this is not valid # needs sage.libs.pari Traceback (most recent call last): ... ValueError: relations do not all (canonically) map to 0 @@ -233,19 +237,20 @@ Endomorphism of power series ring:: Frobenius on a power series ring over a finite field:: - sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: f = R.hom([t^5]); f # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(5)) + sage: f = R.hom([t^5]); f 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) # 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 + 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) 2 + t^5 + 3*t^10 + 4*t^15 + O(t^20) - sage: f(b) # optional - sage.rings.finite_rings + sage: f(b) 1 + t^5 + 2*t^10 + t^15 + O(t^25) - sage: f(a*b) # optional - sage.rings.finite_rings + sage: f(a*b) 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) - sage: f(a)*f(b) # optional - sage.rings.finite_rings + sage: f(a)*f(b) 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) Homomorphism of Laurent series ring:: @@ -279,35 +284,36 @@ positive:: Complex conjugation on cyclotomic fields:: - sage: K. = CyclotomicField(7) # optional - sage.rings.number_field - sage: c = K.hom([1/zeta7]); c # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = CyclotomicField(7) + sage: c = K.hom([1/zeta7]); c Ring endomorphism of Cyclotomic Field of order 7 and degree 6 Defn: zeta7 |--> -zeta7^5 - zeta7^4 - zeta7^3 - zeta7^2 - zeta7 - 1 - sage: a = (1+zeta7)^5; a # optional - sage.rings.number_field + sage: a = (1+zeta7)^5; a zeta7^5 + 5*zeta7^4 + 10*zeta7^3 + 10*zeta7^2 + 5*zeta7 + 1 - sage: c(a) # optional - sage.rings.number_field + sage: c(a) 5*zeta7^5 + 5*zeta7^4 - 4*zeta7^2 - 5*zeta7 - 4 - sage: c(zeta7 + 1/zeta7) # this element is obviously fixed by inversion # optional - sage.rings.number_field + sage: c(zeta7 + 1/zeta7) # this element is obviously fixed by inversion -zeta7^5 - zeta7^4 - zeta7^3 - zeta7^2 - 1 - sage: zeta7 + 1/zeta7 # optional - sage.rings.number_field + sage: zeta7 + 1/zeta7 -zeta7^5 - zeta7^4 - zeta7^3 - zeta7^2 - 1 Embedding a number field into the reals:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field - sage: alpha = RR(2)^(1/3); alpha # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 2) # needs sage.rings.number_field + sage: alpha = RR(2)^(1/3); alpha # needs sage.rings.number_field 1.25992104989487 - sage: i = K.hom([alpha],check=False); i # optional - sage.rings.number_field + sage: i = K.hom([alpha],check=False); i # needs sage.rings.number_field Ring morphism: From: Number Field in beta with defining polynomial x^3 - 2 To: Real Field with 53 bits of precision Defn: beta |--> 1.25992104989487 - sage: i(beta) # optional - sage.rings.number_field + sage: i(beta) # needs sage.rings.number_field 1.25992104989487 - sage: i(beta^3) # optional - sage.rings.number_field + sage: i(beta^3) # needs sage.rings.number_field 2.00000000000000 - sage: i(beta^2 + 1) # optional - sage.rings.number_field + sage: i(beta^2 + 1) # needs sage.rings.number_field 2.58740105196820 An example from Jim Carlson:: @@ -338,51 +344,53 @@ TESTS:: :: - 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 + sage: K. = CyclotomicField(7) # needs sage.rings.number_field + sage: c = K.hom([1/zeta7]) # needs sage.rings.number_field + sage: c == loads(dumps(c)) True :: - 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 + sage: R. = PowerSeriesRing(GF(5)) + sage: f = R.hom([t^5]) + sage: f == loads(dumps(f)) True We define the identity map in many possible ways. These should all compare equal:: - 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: # needs sage.rings.finite_rings + sage: k = GF(2) + sage: R. = k[] + sage: F4. = R.quo(x^2+x+1) + sage: H = End(F4) + sage: # needs sage.rings.finite_rings sage: from sage.rings.morphism import * - sage: phi1 = H.identity(); phi1 # optional - sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + 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 Defn: a |--> a - sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 # optional - sage.rings.finite_rings + sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 # needs sage.libs.ntl 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) Defn: x |--> x - sage: phi4 = RingHomomorphism_cover(H); phi4 # optional - sage.rings.finite_rings + 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 Defn: Natural quotient map - sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 # optional - sage.rings.finite_rings + 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] # optional - sage.rings.finite_rings - sage: for f in maps: # optional - sage.rings.finite_rings + sage: maps = [phi1, phi2, phi3, phi4, phi5] # needs sage.libs.ntl + sage: for f in maps: # needs sage.libs.ntl ....: for g in maps: ....: if f != g: ....: print("{} != {}".format(f, g)) @@ -468,14 +476,14 @@ cdef class RingMap_lift(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: S. = R.quo( (x^2 + y^2, y) ) # optional - sage.libs.singular - sage: S.lift() # optional - sage.libs.singular + sage: S. = R.quo( (x^2 + y^2, y) ) # needs sage.libs.singular + sage: S.lift() # needs 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) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift() == 0 # optional - sage.libs.singular + sage: S.lift() == 0 # needs sage.libs.singular False Since :trac:`11068`, it is possible to create @@ -485,10 +493,11 @@ cdef class RingMap_lift(RingMap): of :class:`sage.rings.ring.Ring`, as in the following example:: - 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 + sage: # needs sage.modules sage.rings.finite_rings + 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 [0 1] [0 0] """ @@ -508,9 +517,9 @@ 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) # needs sage.rings.number_field + sage: from sage.rings.morphism import RingMap_lift + sage: RingMap_lift(GF9, ZZ) # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: no canonical coercion from Number Field in I @@ -653,14 +662,14 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: f = ZZ.hom(Zp(3)); f # optional - sage.rings.padics + sage: f = ZZ.hom(Zp(3)); f # needs 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) # needs sage.rings.padics True """ @@ -675,7 +684,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(3))._repr_type() # optional - sage.rings.padics + sage: ZZ.hom(Zp(3))._repr_type() # needs sage.rings.padics 'Ring' """ @@ -788,17 +797,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) # needs sage.rings.number_field + sage: f = End(C)[1] # needs sage.rings.number_field + sage: type(f*f) == type(f) # needs 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]) # needs sage.rings.number_field + sage: e, u, v, w = End(K) # needs sage.rings.number_field + sage: u*v # needs 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 @@ -824,20 +833,20 @@ cdef class RingHomomorphism(RingMap): We check that composition works when there is a base map:: sage: R. = ZZ[] - 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 + sage: K. = GF(7^2) # needs sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # needs sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # needs sage.rings.finite_rings + sage: phi # needs 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 # optional - sage.rings.finite_rings + sage: psi = phi^3; psi # needs 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))) # optional - sage.rings.finite_rings + sage: psi(a) == phi(phi(phi(a))) # needs 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:: @@ -906,8 +915,8 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - 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 + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.cover() # needs sage.libs.singular + sage: f.pushforward(R.ideal([x, 3*x + x*y + y^2])) # needs 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) """ @@ -940,18 +949,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 # optional - sage.libs.singular + sage: J = f.inverse_image(I); J # needs 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 # optional - sage.libs.singular + sage: f(J) == I # needs 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]] # optional - sage.libs.singular + sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] # needs sage.libs.singular [x, x^2, x*y*z + y] - sage: f.inverse_image(u*v^2) # optional - sage.libs.singular + sage: f.inverse_image(u*v^2) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: element u*v^2 does not have preimage @@ -959,27 +968,29 @@ 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') # 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 + sage: # needs sage.libs.singular + sage: S. = QQ['u,v'].quotient('v^2 - 2') + sage: f = QuadraticField(2).hom([v], S) # needs sage.rings.number_field + sage: I = S.ideal(u + v) # needs sage.rings.number_field + sage: J = f.inverse_image(I) # needs sage.rings.number_field + sage: J.is_zero() # needs sage.rings.number_field True - sage: f(J) < I # optional - sage.libs.singular sage.rings.number_field + sage: f(J) < I # needs sage.rings.number_field True Fractional ideals are not yet fully supported:: - 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 + sage: # needs sage.rings.number_field + 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) Traceback (most recent call last): ... NotImplementedError: inverse image not implemented... - sage: f.inverse_image(K.ideal(0)).is_zero() # optional - sage.rings.number_field + sage: f.inverse_image(K.ideal(0)).is_zero() True - sage: f.inverse()(I) # optional - sage.rings.number_field + sage: f.inverse()(I) Fractional ideal (-a + 1) ALGORITHM: @@ -993,7 +1004,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)) # needs sage.rings.padics Traceback (most recent call last): ... ValueError: not an ideal or element in codomain 2-adic Ring @@ -1001,7 +1012,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)) # needs sage.rings.padics Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1021,13 +1032,14 @@ 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: # needs sage.rings.number_field + sage: R. = QQbar[] + sage: f = R.hom([x, QQbar(i) * x + y^2], R) + sage: I = R.ideal(y^3) + sage: J = f._inverse_image_ideal(I); J 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 + sage: f(J) <= I True TESTS: @@ -1035,17 +1047,17 @@ cdef class RingHomomorphism(RingMap): Check that :trac:`31367` is fixed:: sage: A. = QQ[] - 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 + sage: B. = QQ['x,y'].quotient('y') # needs sage.libs.singular + sage: f = A.hom([x], B) # needs sage.libs.singular + sage: f.kernel() # needs 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') # optional - sage.libs.singular - sage: f = A.hom([x, y], B) # optional - sage.libs.singular - sage: f.kernel() # optional - sage.libs.singular + sage: B. = QQ['x,y,z'].quotient('z') # needs sage.libs.singular + sage: f = A.hom([x, y], B) # needs sage.libs.singular + sage: f.kernel() # needs sage.libs.singular Ideal (0) of Multivariate Polynomial Ring in t, u over Rational Field """ from .polynomial.polynomial_quotient_ring import is_PolynomialQuotientRing @@ -1087,36 +1099,37 @@ cdef class RingHomomorphism(RingMap): A degenerate case:: - 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 + sage: R. = QQ['x,y'].quotient(1) # needs sage.libs.singular + sage: f = R.hom([y, x], R) # needs sage.libs.singular + sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest # needs 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)) # 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 + sage: B. = R.quotient(R.ideal(x)) # needs sage.libs.singular + sage: g = R.hom([d^2, d^3], B) # needs sage.libs.singular + sage: g.inverse_image(d) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: element d does not have preimage - sage: g.inverse_image(d^2) # optional - sage.libs.singular + sage: g.inverse_image(d^2) # needs sage.libs.singular x - sage: g.inverse_image(d^3) # optional - sage.libs.singular + sage: g.inverse_image(d^3) # needs sage.libs.singular y - 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 + sage: A. = R.quotient(R.ideal(y^2 - x^3)) # needs sage.libs.singular + sage: h = A.hom([d^2, d^3], B) # needs sage.libs.singular + sage: h.inverse_image(d^2) # needs 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') # 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 + sage: # needs sage.libs.singular + 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 True """ graph, from_B, to_A = self._graph_ideal() @@ -1136,7 +1149,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() # optional - sage.libs.singular + sage: f.kernel() # needs 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 @@ -1145,18 +1158,18 @@ 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)) # optional - sage.libs.singular + sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) # needs sage.libs.singular True - sage: Q = A.quotient(f.kernel()) # optional - sage.libs.singular - sage: Q.hom(f.im_gens(), B).is_injective() # optional - sage.libs.singular + sage: Q = A.quotient(f.kernel()) # needs sage.libs.singular + sage: Q.hom(f.im_gens(), B).is_injective() # needs sage.libs.singular True The Steiner-Roman surface:: sage: R. = QQ[] - 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 + sage: S = R.quotient(x^2 + y^2 + z^2 - 1) + sage: f = R.hom([x*y, x*z, y*z], S) # needs sage.libs.singular + sage: f.kernel() # needs 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 @@ -1164,30 +1177,31 @@ cdef class RingHomomorphism(RingMap): The results are cached:: - sage: f.kernel() is f.kernel() # optional - sage.libs.singular + sage: f.kernel() is f.kernel() # needs sage.libs.singular True A degenerate case:: sage: R. = QQ[] - sage: f = R.hom([0, 0], R.quotient(1)) # optional - sage.libs.singular - sage: f.kernel().is_one() # optional - sage.libs.singular + sage: f = R.hom([0, 0], R.quotient(1)) # needs sage.libs.singular + sage: f.kernel().is_one() # needs sage.libs.singular True :: - sage: K. = QuadraticField(2) # optional - sage.rings.number_field - sage: K.hom([-sqrt2], K).kernel().is_zero() # optional - sage.rings.number_field + sage: K. = QuadraticField(2) # needs sage.rings.number_field + sage: K.hom([-sqrt2], K).kernel().is_zero() # needs sage.rings.number_field True :: - 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 + sage: # needs sage.rings.number_field + 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() True - sage: A.hom([a], B).kernel() # optional - sage.rings.number_field + sage: A.hom([a], B).kernel() Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1262,32 +1276,34 @@ cdef class RingHomomorphism(RingMap): Ideals in quotient rings over ``QQbar`` do not support reduction yet, so the graph is constructed in the ambient ring instead:: - sage: A. = QQbar['z,w'].quotient('z*w - 1') # optional - sage.rings.number_field - sage: B. = QQbar['x,y'].quotient('2*x^2 + y^2 - 1') # optional - sage.rings.number_field - sage: f = A.hom([QQbar(2).sqrt()*x + QQbar(I)*y, # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: A. = QQbar['z,w'].quotient('z*w - 1') + sage: B. = QQbar['x,y'].quotient('2*x^2 + y^2 - 1') + sage: f = A.hom([QQbar(2).sqrt()*x + QQbar(I)*y, ....: QQbar(2).sqrt()*x - QQbar(I)*y], B) - sage: f._graph_ideal()[0] # optional - sage.rings.number_field + sage: f._graph_ideal()[0] Ideal (z*w - 1, 2*x^2 + y^2 - 1, 1.414213562373095?*x + I*y - z, 1.414213562373095?*x + (-I)*y - w) of Multivariate Polynomial Ring in x, y, z, w over Algebraic Field - sage: f.inverse()(f(z)), f.inverse()(f(w)) # optional - sage.rings.number_field + sage: f.inverse()(f(z)), f.inverse()(f(w)) (z, w) Non-trivial base maps are not supported:: - sage: K. = QuadraticField(2) # optional - sage.rings.number_field - sage: R. = K[] # optional - sage.rings.number_field - sage: f = R.hom([x, a*x + y], R, base_map=K.hom([-a], K)) # optional - sage.rings.number_field - sage: f._graph_ideal() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = QuadraticField(2) + sage: R. = K[] + sage: f = R.hom([x, a*x + y], R, base_map=K.hom([-a], K)) + sage: f._graph_ideal() Traceback (most recent call last): ... NotImplementedError: base map must be trivial Non-commutative rings are not supported (:trac:`32824`):: - sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') # optional - sage.combinat sage.modules - sage: A.hom(A.gens(), A).kernel() # optional - sage.combinat sage.modules + sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') # needs sage.combinat sage.modules + sage: A.hom(A.gens(), A).kernel() # needs sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: rings are not commutative @@ -1344,7 +1360,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([2*t - 1], R) - sage: f.inverse() # optional - sage.libs.singular + sage: f.inverse() # needs sage.libs.singular Ring endomorphism of Univariate Polynomial Ring in t over Rational Field Defn: t |--> 1/2*t + 1/2 @@ -1353,15 +1369,15 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([y*z, x*z, x*y], R) - sage: f.inverse() # optional - sage.libs.singular + sage: f.inverse() # needs sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: f.is_injective() # optional - sage.libs.singular + sage: f.is_injective() # needs sage.libs.singular True - 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 + sage: Q. = R.quotient(x*y*z - 1) # needs sage.libs.singular + sage: g = Q.hom([y*z, x*z, x*y], Q) # needs sage.libs.singular + sage: g.inverse() # needs 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 @@ -1372,24 +1388,24 @@ cdef class RingHomomorphism(RingMap): sage: S. = ZZ[] sage: f = S.hom([x + 2*y, x + 3*y], S) - sage: f.inverse() # optional - sage.libs.singular + sage: f.inverse() # needs 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() # optional - sage.libs.singular + sage: (f.inverse() * f).is_identity() # needs 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() # optional - sage.libs.singular + sage: g.inverse() # needs 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() # optional - sage.libs.singular + sage: (h.inverse() * h).is_identity() # needs sage.libs.singular True This example by M. Nagata is a wild automorphism:: @@ -1397,13 +1413,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 # optional - sage.libs.singular + sage: tau = sigma.inverse(); tau # needs 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() # optional - sage.libs.singular + sage: (tau * sigma).is_identity() # needs sage.libs.singular True We compute the triangular automorphism that converts moments to @@ -1427,37 +1443,38 @@ 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] # optional - sage.libs.singular + sage: phi.inverse().im_gens()[:5] # needs 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() # optional - sage.libs.singular + sage: (phi.inverse() * phi).is_identity() # needs sage.libs.singular True Automorphisms of number fields as well as Galois fields are supported:: - 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 + sage: K. = CyclotomicField(7) # needs sage.rings.number_field + sage: c = K.hom([1/zeta7]) # needs sage.rings.number_field + sage: (c.inverse() * c).is_identity() # needs sage.rings.number_field True - 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 + sage: F. = GF(7^3) # needs sage.rings.finite_rings + sage: f = F.hom(t^7, F) # needs sage.rings.finite_rings + sage: (f.inverse() * f).is_identity() # needs sage.rings.finite_rings True An isomorphism between the algebraic torus and the circle over a number field:: - 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 + sage: # needs sage.rings.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() [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()) # optional - sage.rings.number_field + sage: all(g(f(z)) == z for z in A.gens()) True TESTS: @@ -1465,43 +1482,45 @@ cdef class RingHomomorphism(RingMap): Morphisms involving quotient rings:: sage: R. = QQ[] - 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 + sage: S. = QQ['s,u,t'].quotient('u-t^2') # needs sage.libs.singular + sage: f = R.hom([s, -t], S) # needs sage.libs.singular + sage: (f.inverse() * f).is_identity() # needs sage.libs.singular True - 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 + sage: Q. = R.quotient(x - y^2) # needs sage.libs.singular + sage: g = Q.hom([v, -w], Q) # needs sage.libs.singular + sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w # needs sage.libs.singular True sage: S. = QQ[] - 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 + sage: h = Q.hom([z^2, -z], S) # needs sage.libs.singular + sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w # needs sage.libs.singular True Morphisms between number fields and quotient rings:: - 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 + sage: # needs sage.rings.number_field + sage: K. = QuadraticField(2) + sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) + sage: (f.inverse() * f).is_identity() True - 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 + sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) + sage: (g.inverse() * g).is_identity() True Morphisms involving Galois fields:: - 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 + sage: # needs sage.rings.finite_rings + 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() True - sage: B., f = A.extension(3, map=True) # optional - sage.rings.finite_rings - sage: f.inverse() # optional - sage.rings.finite_rings + sage: B., f = A.extension(3, map=True) + sage: f.inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: B., f = A.extension(1, map=True) # optional - sage.rings.finite_rings - sage: f.inverse() # optional - sage.rings.finite_rings + sage: B., f = A.extension(1, map=True) + sage: f.inverse() Ring morphism: From: Finite Field in T of size 7^3 To: Finite Field in t of size 7^3 @@ -1511,51 +1530,51 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: S. = QQ[] - sage: S.hom([x, y, 0], R).inverse() # optional - sage.libs.singular + sage: S.hom([x, y, 0], R).inverse() # needs sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective sage: T. = QQ[] - sage: R.hom([2*z, 3*z], T).inverse() + sage: R.hom([2*z, 3*z], T).inverse() # needs sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q. = R.quotient([x^5, y^4]) # optional - sage.libs.singular - sage: R.hom([u, v], Q).inverse() # optional - sage.libs.singular + sage: Q. = R.quotient([x^5, y^4]) # needs sage.libs.singular + sage: R.hom([u, v], Q).inverse() # needs sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q.cover().inverse() # optional - sage.libs.singular + sage: Q.cover().inverse() # needs sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective Univariate quotient rings:: - sage: R. = QQ['t'].quotient('t^5') + sage: R. = QQ['t'].quotient('t^5') # needs sage.libs.pari sage: f = R.hom([2*t], R) - sage: (f.inverse() * f).is_identity() + sage: (f.inverse() * f).is_identity() # needs sage.libs.singular True A homomorphism over ``QQbar``:: - 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 + sage: R. = QQbar[] # needs sage.rings.number_field + sage: f = R.hom([x + QQbar(I)*y^2, -y], R) # needs sage.rings.number_field + sage: (f.inverse() * f).is_identity() # needs sage.rings.number_field True Check that results are cached:: - 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 + sage: R. = GF(823)[] + sage: f = R.hom([x, y+x^2], R) + sage: f.inverse() is f.inverse() # needs 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)) # optional - sage.rings.finite_rings - sage: FrobeniusEndomorphism_generic(K).inverse() # optional - sage.rings.finite_rings + sage: K. = PowerSeriesRing(GF(5)) + sage: FrobeniusEndomorphism_generic(K).inverse() Traceback (most recent call last): ... NotImplementedError @@ -1563,7 +1582,7 @@ cdef class RingHomomorphism(RingMap): :: sage: R. = LaurentPolynomialRing(QQ) - sage: R.hom([y, x], R).inverse() + sage: R.hom([y, x], R).inverse() # needs sage.libs.singular Traceback (most recent call last): ... NotImplementedError @@ -1582,11 +1601,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() # optional - sage.libs.singular + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() False - sage: f.is_injective() # optional - sage.libs.singular + sage: f.is_injective() # needs sage.libs.singular True - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # needs sage.libs.singular True """ if not self.is_injective(): @@ -1606,9 +1625,9 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - 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 + sage: R. = GF(17)[] + sage: f = R.hom([3*x, y + x^2 + x^3], R) + sage: (f * ~f).is_identity() # needs sage.rings.finite_rings True """ return self.inverse() @@ -1620,10 +1639,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_surjective() # optional - sage.libs.singular + sage: R.hom([y*z, x*z, x*y], R).is_surjective() # needs sage.libs.singular False - 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 + sage: Q. = R.quotient(x*y*z - 1) # needs sage.libs.singular + sage: R.hom([y*z, x*z, x*y], Q).is_surjective() # needs sage.libs.singular True ALGORITHM: @@ -1644,10 +1663,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_invertible() # optional - sage.libs.singular + sage: R.hom([y*z, x*z, x*y], R).is_invertible() # needs sage.libs.singular False - 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 + sage: Q. = R.quotient(x*y*z - 1) # needs sage.libs.singular + sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() # needs sage.libs.singular True ALGORITHM: @@ -1789,12 +1808,12 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): Here's another example where the domain isn't free:: - sage: S. = R.quotient(x - y) # optional - sage.libs.singular - sage: phi = S.hom([xx + 1, xx + 1]) # optional - sage.libs.singular + sage: S. = R.quotient(x - y) # needs sage.libs.singular + sage: phi = S.hom([xx + 1, xx + 1]) # needs sage.libs.singular Note that one has to specify valid images:: - sage: phi = S.hom([xx + 1, xx - 1]) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx - 1]) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: relations do not all (canonically) map to 0 @@ -1803,11 +1822,11 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): You can give a map of the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field - sage: cc = K.hom([-i]) # optional - sage.rings.number_field - sage: 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 + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field + sage: cc = K.hom([-i]) # needs sage.rings.number_field + sage: R. = K[] # needs sage.rings.number_field + sage: z = 1 + i*t + (3+4*i)*t^2 # needs sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # needs sage.rings.number_field (-4*i + 3)*t^4 - i*t^2 + 1 The base map's codomain is extended to the whole codomain:: @@ -1827,8 +1846,8 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): speed up creation of a homomorphism:: sage: R. = QQ[] - sage: S. = R.quotient(x - y) # optional - sage.libs.singular - sage: phi = S.hom([xx + 1, xx - 1], check=False) # optional - sage.libs.singular + sage: S. = R.quotient(x - y) # needs sage.libs.singular + sage: phi = S.hom([xx + 1, xx - 1], check=False) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: relations do not all (canonically) map to 0 @@ -1891,20 +1910,20 @@ 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) # needs sage.rings.number_field + sage: cc = K.hom([-i]) # needs sage.rings.number_field + sage: S. = K[] # needs sage.rings.number_field + sage: phi = S.hom([y^2], base_map=cc) # needs sage.rings.number_field + sage: phi # needs 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) # needs sage.rings.number_field y^2 - sage: phi(i*y) # optional - sage.rings.number_field + sage: phi(i*y) # needs sage.rings.number_field -i*y^2 - sage: phi.base_map() # optional - sage.rings.number_field + sage: phi.base_map() # needs 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 @@ -1967,51 +1986,52 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A single variate quotient over `\QQ`:: sage: R. = QQ[] - 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 + sage: Q. = R.quotient(x^2 + x + 1) # needs sage.libs.pari + sage: f1 = R.hom([a]) # needs sage.libs.pari + sage: f2 = R.hom([a + a^2 + a + 1]) # needs sage.libs.pari + sage: f1 == f2 # needs sage.libs.pari True - sage: f1 == R.hom([a^2]) # optional - sage.libs.pari + sage: f1 == R.hom([a^2]) # needs sage.libs.pari False - sage: f1(x^3 + x) # optional - sage.libs.pari + sage: f1(x^3 + x) # needs sage.libs.pari a + 1 - sage: f2(x^3 + x) # optional - sage.libs.pari + sage: f2(x^3 + x) # needs sage.libs.pari a + 1 TESTS:: - sage: loads(dumps(f2)) == f2 # optional - sage.libs.pari + sage: loads(dumps(f2)) == f2 # needs sage.libs.pari True :: - 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 + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) + sage: f == g # indirect doctest False EXAMPLES: A multivariate quotient over a finite field:: - 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 + sage: # needs sage.rings.finite_rings + 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 True - sage: f1 == R.hom([b, a]) # optional - sage.rings.finite_rings + sage: f1 == R.hom([b, a]) False - sage: x^3 + x + y^2 # optional - sage.rings.finite_rings + sage: x^3 + x + y^2 x^3 + y^2 + x - sage: f1(x^3 + x + y^2) # optional - sage.rings.finite_rings + sage: f1(x^3 + x + y^2) a - b - sage: f2(x^3 + x + y^2) # optional - sage.rings.finite_rings + sage: f2(x^3 + x + y^2) a - b TESTS:: - sage: loads(dumps(f2)) == f2 # optional - sage.rings.finite_rings + sage: loads(dumps(f2)) == f2 # needs sage.rings.finite_rings True This was fixed in :trac:`24277`:: @@ -2120,12 +2140,13 @@ 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, # optional - sage.modules + sage: # needs sage.modules + sage: MR = MatrixSpace(R, 2, 2) + sage: MS = MatrixSpace(S, 2, 2) + sage: M = MR([x^2 + 1/7*x*y - y^2, -1/2*y^2 + 2*y + 1/6, ....: 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) - sage: Mf = MR.hom(f, MS) # optional - sage.modules - sage: Mf # optional - sage.modules + sage: Mf = MR.hom(f, MS) + sage: Mf Ring morphism: From: Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field @@ -2137,19 +2158,20 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): 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) [ -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, # optional - sage.modules + sage: # needs sage.modules + sage: MPR = MatrixSpace(PR, 2) + sage: MPS = MatrixSpace(PS, 2) + sage: M = MPR([(-x + y)*t^2 + 58*t - 3*x^2 + x*y, ....: (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, ....: (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, ....: (x + 6*y + 1)*t^2]) - sage: MPf = MPR.hom(f, MPS); MPf # optional - sage.modules + sage: MPf = MPR.hom(f, MPS); MPf 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 @@ -2167,7 +2189,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): 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) [ 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] """ @@ -2180,9 +2202,9 @@ 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)) # optional - sage.modules - sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules - sage: g # optional - sage.modules + sage: P = MatrixSpace(R, 2).Hom(MatrixSpace(R, 2)) # needs sage.modules + sage: g = RingHomomorphism_from_base(P, f) # needs sage.modules + sage: g # needs 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 @@ -2193,8 +2215,8 @@ 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']) # optional - sage.modules - sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules + sage: P = MatrixSpace(R, 2).Hom(R['t']) # needs sage.modules + sage: g = RingHomomorphism_from_base(P, f) # needs 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) @@ -2219,10 +2241,10 @@ 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) # 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 + sage: MR = MatrixSpace(R, 2) # needs sage.modules + sage: MS = MatrixSpace(S, 2) # needs sage.modules + sage: g = MR.hom(f, MS) # needs sage.modules + sage: g.underlying_map() == f # needs sage.modules True """ return self._underlying @@ -2296,19 +2318,19 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): `\QQ`:: sage: R. = QQ[] - 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 + sage: Q. = R.quotient(x^2 + x + 1) # needs sage.libs.pari sage.modules + sage: f1 = R.hom([a]) # needs sage.libs.pari sage.libs.singular sage.modules + sage: f2 = R.hom([a + a^2 + a + 1]) # needs sage.libs.pari sage.libs.singular sage.modules + sage: PR. = R[] + sage: PQ = Q['s','t'] # needs sage.libs.pari sage.libs.singular sage.modules + sage: f1P = PR.hom(f1,PQ) # needs sage.libs.pari sage.libs.singular sage.modules + sage: f2P = PR.hom(f2,PQ) # needs sage.libs.pari sage.libs.singular sage.modules + sage: f1P == f2P # needs sage.libs.pari sage.libs.singular sage.modules True TESTS:: - sage: f1P == loads(dumps(f1P)) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P == loads(dumps(f1P)) # needs sage.libs.pari sage.libs.singular sage.modules True sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) @@ -2321,20 +2343,21 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A matrix ring over a multivariate quotient over a finite field:: - 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 + sage: # needs sage.rings.finite_rings + 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) # needs sage.modules + sage: MQ = MatrixSpace(Q, 2) # needs sage.modules + sage: f1M = MR.hom(f1, MQ) # needs sage.modules + sage: f2M = MR.hom(f2, MQ) # needs sage.modules + sage: f1M == f2M # needs sage.modules True TESTS:: - sage: f1M == loads(dumps(f1M)) # optional - sage.rings.finite_rings sage.modules + sage: f1M == loads(dumps(f1M)) # needs sage.modules sage.rings.finite_rings True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2355,9 +2378,9 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): 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: R2 = MatrixSpace(FractionField(R1)['t'], 2) # needs sage.modules + sage: g = R2.hom(f, R2) # needs sage.modules + sage: g #indirect doctest # needs 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 @@ -2405,11 +2428,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([a + b, a - b], S) # optional - sage.libs.singular + sage: f = R.hom([a + b, a - b], S) sage: PR. = R[] sage: PS = S['t'] - sage: Pf = PR.hom(f, PS) # optional - sage.libs.singular - sage: Pf.inverse() # optional - sage.libs.singular + sage: Pf = PR.hom(f, PS) + sage: Pf.inverse() # needs sage.libs.singular Ring morphism: From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field @@ -2421,7 +2444,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)) # optional - sage.libs.singular + sage: Pf.inverse()(Pf(x*t^2 + y*t)) # needs sage.libs.singular x*t^2 + y*t """ return self.parent().reversed()(self._underlying.inverse()) @@ -2435,8 +2458,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([x^2]) - sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular - sage: type(g) # optional - sage.libs.singular + sage: g = f.extend_to_fraction_field() # needs sage.libs.singular + sage: type(g) # needs sage.libs.singular """ def __init__(self, parent, morphism): @@ -2446,10 +2469,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: f = A.coerce_map_from(ZZ) # optional - sage.rings.number_field - sage: g = f.extend_to_fraction_field() # indirect doctest # optional - sage.rings.number_field - sage: g # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: f = A.coerce_map_from(ZZ) # needs sage.rings.number_field + sage: g = f.extend_to_fraction_field() # indirect doctest # needs sage.rings.number_field + sage: g # needs sage.rings.number_field Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^2 - 2 @@ -2464,11 +2487,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x^2]).extend_to_fraction_field() # optional - sage.libs.singular - sage: f # optional - sage.libs.singular + sage: f = S.hom([x^2]).extend_to_fraction_field() # needs sage.libs.singular + sage: f # needs 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() # optional - sage.libs.singular + sage: f._repr_defn() # needs sage.libs.singular 'x |--> x^2' """ return self._morphism._repr_defn() @@ -2484,10 +2507,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular - sage: f(1/x) # optional - sage.libs.singular + sage: f = S.hom([x + 1]).extend_to_fraction_field() # needs sage.libs.singular + sage: f(1/x) # needs sage.libs.singular 1/(x + 1) - sage: f(1/(x-1)) # optional - sage.libs.singular + sage: f(1/(x-1)) # needs sage.libs.singular 1/x """ return self._morphism(x.numerator()) / self._morphism(x.denominator()) @@ -2499,12 +2522,12 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f = S.hom([x + 1]).extend_to_fraction_field() # needs sage.libs.singular - sage: g = copy(f) # indirect doctest # optional - sage.libs.singular - sage: f == g # optional - sage.libs.singular + sage: g = copy(f) # indirect doctest # needs sage.libs.singular + sage: f == g # needs sage.libs.singular True - sage: f is g # optional - sage.libs.singular + sage: f is g # needs sage.libs.singular False """ self._morphism = _slots['_morphism'] @@ -2517,8 +2540,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular - sage: loads(dumps(f)) == f # optional - sage.libs.singular + sage: f = S.hom([x + 1]).extend_to_fraction_field() # needs sage.libs.singular + sage: loads(dumps(f)) == f # needs sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2534,8 +2557,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([2*x - 1]) - sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular - sage: g.inverse() # optional - sage.libs.singular + sage: g = f.extend_to_fraction_field() # needs sage.libs.singular + sage: g.inverse() # needs sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> 1/2*x + 1/2 @@ -2550,14 +2573,14 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular - sage: phi = S.cover(); phi # optional - sage.libs.singular + sage: S. = R.quo(x^2 + y^2) # needs sage.libs.singular + sage: phi = S.cover(); phi # needs 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: phi(x + y) # optional - sage.libs.singular + sage: phi(x + y) # needs sage.libs.singular a + b """ def __init__(self, parent): @@ -2643,11 +2666,11 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - 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 + sage: S. = R.quo(x^2 + y^2) # needs sage.libs.singular + sage: phi = S.cover() # needs sage.libs.singular + sage: phi == loads(dumps(phi)) # needs sage.libs.singular True - sage: phi == R.quo(x^2 + y^3).cover() # optional - sage.libs.singular + sage: phi == R.quo(x^2 + y^3).cover() # needs sage.libs.singular False """ if not isinstance(other, RingHomomorphism_cover): @@ -2663,13 +2686,13 @@ cdef class RingHomomorphism_cover(RingHomomorphism): TESTS:: sage: R. = PolynomialRing(QQ, 2) - 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: S. = R.quo(x^2 + y^2) # needs sage.libs.singular + sage: phi = S.cover() # needs sage.libs.singular + sage: type(phi) # needs sage.libs.singular - sage: hash(phi) == hash(phi) # optional - sage.libs.singular + sage: hash(phi) == hash(phi) # needs sage.libs.singular True - sage: {phi: 1}[phi] # optional - sage.libs.singular + sage: {phi: 1}[phi] # needs sage.libs.singular 1 """ return hash((self.domain(), self.codomain())) @@ -2684,12 +2707,13 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - 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 + sage: # needs sage.libs.singular + sage: R. = QQ['x,y'].quotient('x^2 * y^2') + sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) 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') # optional - sage.libs.singular - sage: S.cover().inverse_image(S.ideal(u^2 - 1)) # optional - sage.libs.singular + sage: S. = QQbar['u,v'].quotient('u^4 - 1') + sage: S.cover().inverse_image(S.ideal(u^2 - 1)) Ideal (u^4 - 1, u^2 - 1) of Multivariate Polynomial Ring in u, v over Algebraic Field """ @@ -2704,8 +2728,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: Q. = QQ['x,y'].quotient('x + y') # optional - sage.libs.singular - sage: Q.cover().inverse_image(u) # optional - sage.libs.singular + sage: Q. = QQ['x,y'].quotient('x + y') # needs sage.libs.singular + sage: Q.cover().inverse_image(u) # needs sage.libs.singular -y """ return b.lift() @@ -2734,23 +2758,23 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 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 + sage: S. = R.quo(x^3 + y^3 + z^3) # needs sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # needs 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) # optional - sage.libs.singular + sage: phi(a + b + c) # needs sage.libs.singular a + b + c - sage: loads(dumps(phi)) == phi # optional - sage.libs.singular + sage: loads(dumps(phi)) == phi # needs 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]) # optional - sage.libs.singular + sage: S.hom([b^2, c^2, a^2]) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: relations do not all (canonically) map to 0 @@ -2762,7 +2786,7 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) # needs 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 @@ -2790,21 +2814,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 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 + sage: S. = R.quo(x^3 + y^3 + z^3) # needs sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # needs 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) # optional - sage.libs.singular + sage: phi(a + b + c) # needs sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular - sage: psi == phi # optional - sage.libs.singular + sage: psi = copy(phi) # indirect doctest # needs sage.libs.singular + sage: psi == phi # needs sage.libs.singular True - sage: psi is phi # optional - sage.libs.singular + sage: psi is phi # needs sage.libs.singular False - sage: psi(a) == phi(a) # optional - sage.libs.singular + sage: psi(a) == phi(a) # needs sage.libs.singular True """ @@ -2818,21 +2842,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 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 + sage: S. = R.quo(x^3 + y^3 + z^3) # needs sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # needs 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) # optional - sage.libs.singular + sage: phi(a + b + c) # needs sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular - sage: psi == phi # optional - sage.libs.singular + sage: psi = copy(phi) # indirect doctest # needs sage.libs.singular + sage: psi == phi # needs sage.libs.singular True - sage: psi is phi # optional - sage.libs.singular + sage: psi is phi # needs sage.libs.singular False - sage: psi(a) == phi(a) # optional - sage.libs.singular + sage: psi(a) == phi(a) # needs sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2846,8 +2870,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - 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 + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy,xx]) # needs sage.libs.singular + sage: f._phi() # needs 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) @@ -2863,8 +2887,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - 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 + sage: R. = QQ[]; S. = R.quo([x^2, y^2]) # needs sage.libs.singular + sage: S.hom([yy,xx]).morphism_from_cover() # needs sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Quotient of Multivariate Polynomial Ring in x, y @@ -2880,14 +2904,15 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + 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 False - sage: phi == f # optional - sage.rings.finite_rings + sage: phi == f True """ if not isinstance(other, RingHomomorphism_from_quotient): @@ -2904,14 +2929,15 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - 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: # needs sage.rings.finite_rings + 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: hash(phi) == hash(phi) # optional - sage.rings.finite_rings + sage: hash(phi) == hash(phi) True - sage: {phi: 1}[phi] # optional - sage.rings.finite_rings + sage: {phi: 1}[phi] 1 """ return hash(self.phi) @@ -2922,9 +2948,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - 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 + sage: R. = QQ[]; S. = R.quo([x^2,y^2]) # needs sage.libs.singular + sage: f = S.hom([yy, xx]) # needs sage.libs.singular + sage: print(f._repr_defn()) # needs sage.libs.singular xx |--> yy yy |--> xx """ @@ -2939,8 +2965,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - 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 + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy, xx]) # needs sage.libs.singular + sage: f(3*x + (1/2)*y) # indirect doctest # needs sage.libs.singular 1/2*xx + 3*yy """ return self.phi(self.lift(x)) @@ -2967,11 +2993,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): TESTS:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: FrobeniusEndomorphism_generic(K) # optional - sage.rings.finite_rings + 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) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K, 2) Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 """ @@ -3000,10 +3026,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: K = Frac(GF(5)['T']) + sage: phi = K.frobenius_endomorphism() + sage: psi = copy(phi) + sage: phi == psi True """ self._p = _slots['_domain'].characteristic() @@ -3020,16 +3047,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - 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 + sage: K = Frac(GF(25)['T']) # needs sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism(2) # needs sage.rings.finite_rings + sage: phi # needs 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 # optional - sage.rings.finite_rings + sage: psi = loads(dumps(phi)); psi # needs 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 + sage: phi == psi # needs sage.rings.finite_rings True """ slots = RingHomomorphism._extra_slots(self) @@ -3042,12 +3069,12 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + 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._repr_() # optional - sage.rings.finite_rings + sage: Frob._repr_() 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5' """ @@ -3066,11 +3093,12 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: K. = PowerSeriesRing(GF(5)) + sage: Frob = K.frobenius_endomorphism() + sage: Frob._repr_short() 'Frob' - sage: (Frob^2)._repr_short() # optional - sage.rings.finite_rings + sage: (Frob^2)._repr_short() 'Frob^2' """ if self._power == 0: @@ -3087,9 +3115,9 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - 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 + sage: K. = PowerSeriesRing(GF(5)) + sage: Frob = K.frobenius_endomorphism(2) + sage: Frob._latex_() '\\verb"Frob"^{2}' """ if self._power == 0: @@ -3104,11 +3132,12 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): """ TESTS:: - 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 + sage: # needs sage.rings.finite_rings + sage: K. = PowerSeriesRing(GF(5)) + sage: Frob = K.frobenius_endomorphism() + sage: Frob(u) u^5 - sage: (Frob^2)(1 + u) # optional - sage.rings.finite_rings + sage: (Frob^2)(1 + u) 1 + u^25 """ return x ** self._q @@ -3121,11 +3150,12 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - 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 + sage: # needs sage.rings.finite_rings + sage: K. = PowerSeriesRing(GF(5)) + sage: Frob = K.frobenius_endomorphism() + sage: Frob.power() 1 - sage: (Frob^9).power() # optional - sage.rings.finite_rings + sage: (Frob^9).power() 9 """ return self._power @@ -3136,11 +3166,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + sage: Frob^2 Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 """ @@ -3152,14 +3182,15 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: f = K.frobenius_endomorphism(); f # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + sage: f * g Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u over Finite Field of size 5 """ @@ -3201,15 +3232,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) # optional - sage.libs.singular - sage: Q = _tensor_product_ring(S, R); Q # optional - sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) # needs sage.libs.singular + sage: Q = _tensor_product_ring(S, R); Q # needs 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() # optional - sage.libs.singular + sage: Q.term_order() # needs 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) # optional - sage.libs.singular + sage: _tensor_product_ring(R, R) 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 e8b58284316..3e65e05f6af 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -75,21 +75,22 @@ - Use angle-bracket notation:: - sage: S. = PowerSeriesRing(GF(65537)); S # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: S. = PowerSeriesRing(GF(65537)); S 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 # optional - sage.rings.finite_rings + sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + O(x, y)^5 - sage: s in S # optional - sage.rings.finite_rings + sage: s in S True - sage: TestSuite(S).run() # optional - sage.rings.finite_rings - sage: loads(dumps(S)) is S # optional - sage.rings.finite_rings + sage: TestSuite(S).run() + sage: loads(dumps(S)) is S 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']] # optional - sage.rings.finite_rings + sage: GF(127931)[['x,y']] # needs sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 127931 Variable ordering determines how series are displayed. @@ -117,16 +118,16 @@ sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field - sage: R.base_extend(RR) # optional - sage.rings.real_mpfr + sage: R.base_extend(RR) # needs sage.rings.real_mpfr 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 - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # needs sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings + sage: S.change_ring(GF(5)) # needs sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 Coercion from polynomial ring:: @@ -159,19 +160,19 @@ Coercion from symbolic ring:: - sage: x,y = var('x,y') # optional - sage.symbolic - sage: S = PowerSeriesRing(GF(11),2,'x,y'); S # optional - sage.rings.finite_rings + sage: x,y = var('x,y') # needs sage.symbolic + sage: S = PowerSeriesRing(GF(11),2,'x,y'); S Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: type(x) # optional - sage.symbolic + sage: type(x) # needs sage.symbolic - sage: type(S(x)) # optional - sage.rings.finite_rings sage.symbolic + sage: type(S(x)) # needs sage.rings.finite_rings sage.symbolic - sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f # optional - sage.rings.finite_rings sage.symbolic + sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f # needs sage.rings.finite_rings sage.symbolic 5 - x^2 + 4*x*y + y^2 + O(x, y)^3 - sage: f.parent() # optional - sage.rings.finite_rings sage.symbolic + sage: f.parent() # needs sage.rings.finite_rings sage.symbolic Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: f.parent() == S # optional - sage.rings.finite_rings sage.symbolic + sage: f.parent() == S # needs sage.rings.finite_rings sage.symbolic True The implementation of the multivariate power series ring uses a combination @@ -390,11 +391,12 @@ def _repr_(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings - sage: R #indirect doctest # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(17)) + sage: R #indirect doctest Multivariate Power Series Ring in x, y over Finite Field of size 17 - sage: R.rename('my multivariate power series ring') # optional - sage.rings.finite_rings - sage: R # optional - sage.rings.finite_rings + sage: R.rename('my multivariate power series ring') + sage: R my multivariate power series ring """ if self.ngens() == 0: @@ -479,10 +481,10 @@ def characteristic(self): EXAMPLES:: - sage: H = PowerSeriesRing(GF(65537),4,'f'); H # optional - sage.rings.finite_rings + sage: H = PowerSeriesRing(GF(65537),4,'f'); H # needs sage.rings.finite_rings Multivariate Power Series Ring in f0, f1, f2, f3 over Finite Field of size 65537 - sage: H.characteristic() # optional - sage.rings.finite_rings + sage: H.characteristic() # needs sage.rings.finite_rings 65537 """ return self.base_ring().characteristic() @@ -543,7 +545,7 @@ def change_ring(self, R): sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field - sage: R.base_extend(RR) # optional - sage.rings.real_mpfr + sage: R.base_extend(RR) # needs sage.rings.real_mpfr Multivariate Power Series Ring in t, u, v over Real Field with 53 bits of precision sage: R.change_ring(IntegerModRing(10)) @@ -555,10 +557,10 @@ def change_ring(self, R): TypeError: no base extension defined - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # needs sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings + sage: S.change_ring(GF(5)) # needs sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 """ return PowerSeriesRing(R, names=self.variable_names(), default_prec=self.default_prec()) @@ -576,16 +578,16 @@ def remove_var(self, *var): Power Series Ring in u over Integer Ring - sage: M = PowerSeriesRing(GF(5),5,'t'); M # optional - sage.rings.finite_rings + 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]) # optional - sage.rings.finite_rings + sage: M.remove_var(M.gens()[3]) 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()) # optional - sage.rings.finite_rings + sage: M.remove_var(*M.gens()) Finite Field of size 5 """ @@ -634,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)) # optional - sage.rings.finite_rings - sage: R2(f1) # optional - sage.rings.finite_rings + sage: R2 = R.change_ring(GF(2)) + sage: R2(f1) v + t*v - sage: R2(f2) # optional - sage.rings.finite_rings + sage: R2(f2) u*v^2 + O(t, u, v)^6 TESTS:: @@ -709,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) # 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 + sage: K. = NumberField(t^2 + 1) # needs sage.rings.number_field + sage: Q8. = CyclotomicField(8) # needs sage.rings.number_field + sage: X. = PowerSeriesRing(Q8) # needs sage.rings.number_field + sage: M. = PowerSeriesRing(K) # needs sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion # needs sage.rings.number_field False - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) # optional - sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) # needs sage.rings.number_field True """ try: @@ -757,22 +759,23 @@ def _coerce_map_from_(self, P): EXAMPLES:: - sage: A = GF(17)[['x','y']] # optional - sage.rings.finite_rings - sage: A.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A = GF(17)[['x','y']] + sage: A.has_coerce_map_from(ZZ) True - sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ['x']) True - sage: A.has_coerce_map_from(ZZ['y','x']) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ['y','x']) True - sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ[['x']]) True - sage: A.has_coerce_map_from(ZZ[['y','x']]) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ[['y','x']]) True - sage: A.has_coerce_map_from(ZZ['x','z']) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ['x','z']) False - sage: A.has_coerce_map_from(GF(3)['x','y']) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(GF(3)['x','y']) False - sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) False TESTS:: @@ -780,9 +783,9 @@ def _coerce_map_from_(self, P): sage: M = PowerSeriesRing(ZZ, 3, 'x,y,z') sage: M._coerce_map_from_(M) True - sage: M._coerce_map_from_(M.remove_var(x)) # optional - sage.symbolic + sage: M._coerce_map_from_(M.remove_var(x)) # needs sage.symbolic True - sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) # optional - sage.symbolic + sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) # needs sage.symbolic True sage: M._coerce_map_from_(PolynomialRing(ZZ,'x,z')) True diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index eeca8245b90..3ce76fdabf9 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -253,19 +253,20 @@ class MPowerSeries(PowerSeries): 1 + s + t - s*t + O(s, t)^5 - sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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() # optional - sage.rings.finite_rings - sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w # optional - sage.rings.finite_rings + sage: t = T.gens() + sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w t0 + t1*t3 - t4^3 - t0^3*t2^2 - sage: w = w.add_bigoh(5); w # optional - sage.rings.finite_rings + sage: w = w.add_bigoh(5); w t0 + t1*t3 - t4^3 + O(t0, t1, t2, t3, t4)^5 - sage: w in T # optional - sage.rings.finite_rings + sage: w in T True - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.rings.finite_rings - sage: w # optional - sage.rings.finite_rings + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # needs sage.rings.finite_rings + sage: w # needs sage.rings.finite_rings t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 @@ -274,20 +275,21 @@ class MPowerSeries(PowerSeries): sage: S.random_element(4) # random -2*t + t^2 - 12*s^3 + O(s, t)^4 - sage: T.random_element(10) # random # optional - sage.rings.finite_rings + sage: T.random_element(10) # random # needs sage.rings.finite_rings -t1^2*t3^2*t4^2 + t1^5*t3^3*t4 + O(t0, t1, t2, t3, t4)^10 Convert elements from polynomial rings:: - sage: R = PolynomialRing(ZZ, 5, T.variable_names()) # 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 + sage: # needs sage.rings.finite_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) -t2*t3 + t3^2 + t4^2 - sage: r.parent() # optional - sage.libs.pari + sage: r.parent() Multivariate Polynomial Ring in t0, t1, t2, t3, t4 over Integer Ring - sage: r in T # optional - sage.libs.pari + sage: r in T True """ @@ -314,9 +316,9 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False): Multivariate Power Series Ring in s, t over Rational Field sage: x = polygen(ZZ, 'x') - 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 + sage: K = NumberField(x - 3,'a') # needs sage.rings.number_field + sage: g = K.random_element()*f # needs sage.rings.number_field + sage: g.parent() # needs sage.rings.number_field Multivariate Power Series Ring in s, t over Number Field in a with defining polynomial x - 3 @@ -451,20 +453,20 @@ def __call__(self, *x, **kwds): Checking that :trac:`15059` is fixed:: - sage: M. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: s = M.hom([u, u+v]) # optional - sage.rings.finite_rings - sage: s(M.one()) # optional - sage.rings.finite_rings + sage: M. = PowerSeriesRing(GF(5)) + sage: s = M.hom([u, u+v]) + sage: s(M.one()) 1 Since :trac:`26105` you can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field - sage: cc = K.hom([-i]) # optional - sage.rings.number_field - sage: 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 + sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field + sage: cc = K.hom([-i]) # needs sage.rings.number_field + sage: R. = PowerSeriesRing(K) # needs sage.rings.number_field + sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f # needs 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) # optional - sage.rings.number_field + sage: f(t, s, base_map=cc) # needs sage.rings.number_field (-i)*s*t + t^2 + (-4*i + 3)*t^3 + O(s, t)^4 """ if len(x) != self.parent().ngens(): @@ -516,25 +518,25 @@ def _subs_formal(self, *x, **kwds): -2/33*z^3 - 1/5*z^5 sage: f(z,1) #indirect doctest -1/5 - 2/33*z + z^2 - z^5 - sage: RF = RealField(10) # optional - sage.rings.real_mpfr - sage: f(z, RF(1)) # indirect doctest # optional - sage.rings.real_mpfr + sage: RF = RealField(10) # needs sage.rings.real_mpfr + sage: f(z, RF(1)) # indirect doctest # needs sage.rings.real_mpfr -0.20 - 0.061*z + 1.0*z^2 - 0.00*z^3 - 0.00*z^4 - 1.0*z^5 - sage: m = matrix(QQ,[[1,0,1],[0,2,1],[-1,0,0]]); m # optional - sage.modules + sage: m = matrix(QQ,[[1,0,1],[0,2,1],[-1,0,0]]); m # needs sage.modules [ 1 0 1] [ 0 2 1] [-1 0 0] - sage: f(m,m) # indirect doctest # optional - sage.modules + sage: f(m,m) # indirect doctest # needs sage.modules [ 2/33 0 1/5] [ 131/55 -1136/165 -24/11] [ -1/5 0 -23/165] - sage: f(m,m) == -2/33*m^3 - 1/5*m^5 # indirect doctest # optional - sage.modules + sage: f(m,m) == -2/33*m^3 - 1/5*m^5 # indirect doctest # needs sage.modules True sage: f = f.add_bigoh(10) sage: f(z,z) -2/33*z^3 - 1/5*z^5 + O(z^10) - sage: f(m,m) # optional - sage.modules + sage: f(m,m) # needs sage.modules Traceback (most recent call last): ... AttributeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' object has no attribute 'add_bigoh' @@ -566,14 +568,15 @@ def _value(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(5)); R Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = 1 + a + b - a*b + R.O(3); f # optional - sage.rings.finite_rings + sage: f = 1 + a + b - a*b + R.O(3); f 1 + a + b - a*b + O(a, b, c)^3 - sage: f._value() # optional - sage.rings.finite_rings + sage: f._value() 1 + a + b - a*b - sage: f._value().parent() # optional - sage.rings.finite_rings + sage: f._value().parent() Multivariate Polynomial Ring in a, b, c over Finite Field of size 5 """ return self._go_to_fg(self._bg_value) @@ -602,15 +605,16 @@ def _latex_(self): EXAMPLES:: - sage: M = PowerSeriesRing(GF(5),3,'t'); M # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: M = PowerSeriesRing(GF(5),3,'t'); M Multivariate Power Series Ring in t0, t1, t2 over Finite Field of size 5 - sage: t = M.gens() # optional - sage.rings.finite_rings - sage: f = (-t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 # optional - sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + sage: f -t0^4*t1^3*t2^4 - 2*t0*t1^4*t2^7 + 2*t1*t2^12 + 2*t0^7*t1^5*t2^2 + O(t0, t1, t2)^15 - sage: f._latex_() # optional - sage.rings.finite_rings + sage: f._latex_() '-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}' @@ -708,30 +712,32 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(5)); R Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = a + b + c + a^2*c # optional - sage.rings.finite_rings - sage: f == f^2 # optional - sage.rings.finite_rings + sage: f = a + b + c + a^2*c + sage: f == f^2 False - sage: f = f.truncate() # optional - sage.rings.finite_rings - sage: f == f.O(4) # optional - sage.rings.finite_rings + sage: f = f.truncate() + sage: f == f.O(4) True Ordering is determined by underlying polynomial ring:: - sage: a > b # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: a > b True - sage: a > a^2 # optional - sage.rings.finite_rings + sage: a > a^2 True - sage: b > a^2 # optional - sage.rings.finite_rings + sage: b > a^2 True - sage: (f^2).O(3) # optional - sage.rings.finite_rings + sage: (f^2).O(3) a^2 + 2*a*b + 2*a*c + b^2 + 2*b*c + c^2 + O(a, b, c)^3 - sage: f < f^2 # optional - sage.rings.finite_rings + sage: f < f^2 False - sage: f > f^2 # optional - sage.rings.finite_rings + sage: f > f^2 True - sage: f < 2*f # optional - sage.rings.finite_rings + sage: f < 2*f True """ return richcmp(self._bg_value, other._bg_value, op) @@ -893,24 +899,24 @@ def quo_rem(self, other, precision=None): sage: R. = PowerSeriesRing(ZZ) sage: f = 1 + a + b - a*b + R.O(3) sage: g = 1 + 2*a - 3*a*b + R.O(3) - sage: q, r = f.quo_rem(g); q, r # optional - sage.libs.singular + sage: q, r = f.quo_rem(g); q, r # needs sage.libs.singular (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^3) - sage: f == q*g + r # optional - sage.libs.singular + sage: f == q*g + r # needs sage.libs.singular True - sage: q, r = (a*f).quo_rem(g); q, r # optional - sage.libs.singular + sage: q, r = (a*f).quo_rem(g); q, r # needs sage.libs.singular (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 # optional - sage.libs.singular + sage: a*f == q*g + r # needs sage.libs.singular True - sage: q, r = (a*f).quo_rem(a*g); q, r # optional - sage.libs.singular + sage: q, r = (a*f).quo_rem(a*g); q, r # needs 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 # optional - sage.libs.singular + sage: a*f == q*(a*g) + r # needs sage.libs.singular True - sage: q, r = (a*f).quo_rem(b*g); q, r # optional - sage.libs.singular + sage: q, r = (a*f).quo_rem(b*g); q, r # needs 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 # optional - sage.libs.singular + sage: a*f == q*(b*g) + r # needs sage.libs.singular True Trying to divide two polynomials, we run into the issue that @@ -919,61 +925,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) # optional - sage.libs.singular + sage: (1 + a^3).quo_rem(a + a^2) # needs 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) # optional - sage.libs.singular + sage: (1 + a^3 + a*b).quo_rem(b + c) # needs 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) # optional - sage.libs.singular + sage: (1 + a^3 + a*b).quo_rem(b + c, precision=17) # needs 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) # optional - sage.libs.singular + sage: (a^2 + b^2 + c^2).quo_rem(a + b + c) # needs 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)) # optional - sage.libs.singular + sage: (a^2 + b^2 + c^2).quo_rem(1/(1+a+b+c)) # needs 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)) # optional - sage.libs.singular + sage: (a^2 + b^2 + c^2).quo_rem(a/(1+a+b+c)) # needs 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) # optional - sage.libs.singular + sage: (1 + a + a^15).quo_rem(a^2) # needs 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) # optional - sage.libs.singular + sage: (1 + a + a^15).quo_rem(a^2, precision=15) # needs 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) # optional - sage.libs.singular + sage: (1 + a + a^15).quo_rem(a^2, precision=16) # needs 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) # optional - sage.libs.singular + sage: (1 + a + b).quo_rem(b + c) # needs 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) # optional - sage.libs.singular + sage: (1 + b + c).quo_rem(c + a) # needs 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) # optional - sage.libs.singular + sage: (1 + c + a).quo_rem(a + b) # needs sage.libs.singular (1 + O(a, b, c)^11, 1 - b + c + O(a, b, c)^12) TESTS:: - sage: (f).quo_rem(R.zero()) # optional - sage.libs.singular + sage: (f).quo_rem(R.zero()) Traceback (most recent call last): ... ZeroDivisionError - sage: (f).quo_rem(R.zero().add_bigoh(2)) # optional - sage.libs.singular + sage: (f).quo_rem(R.zero().add_bigoh(2)) Traceback (most recent call last): ... ZeroDivisionError Coercion is applied on ``other``:: - sage: (a + b).quo_rem(1) # optional - sage.libs.singular + sage: (a + b).quo_rem(1) (a + b + O(a, b, c)^12, 0 + O(a, b, c)^12) sage: R. = PowerSeriesRing(QQ) - sage: R(3).quo_rem(2) # optional - sage.libs.singular + sage: R(3).quo_rem(2) (3/2 + O(a, b, c)^12, 0 + O(a, b, c)^12) """ parent = self.parent() @@ -1037,30 +1043,30 @@ def _div_(self, denom_r): When possible, division by non-units also works:: - sage: a/(a*f) # optional - sage.libs.singular + sage: a/(a*f) # needs sage.libs.singular 1 - a - b + a^2 + 3*a*b + b^2 + O(a, b, c)^3 - sage: a/(R.zero()) # optional - sage.libs.singular + sage: a/(R.zero()) Traceback (most recent call last): ZeroDivisionError - sage: (a*f)/f # optional - sage.libs.singular + sage: (a*f)/f a + O(a, b, c)^4 - sage: f/(a*f) # optional - sage.libs.singular + sage: f/(a*f) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: not divisible An example where one loses precision:: - sage: ((1+a)*f - f) / a*f # optional - sage.libs.singular + sage: ((1+a)*f - f) / a*f # needs sage.libs.singular 1 + 2*a + 2*b + O(a, b, c)^2 TESTS:: - sage: ((a+b)*f) / f == (a+b) # optional - sage.libs.singular + sage: ((a+b)*f) / f == (a+b) True - sage: ((a+b)*f) / (a+b) == f # optional - sage.libs.singular + sage: ((a+b)*f) / (a+b) == f # needs sage.libs.singular True """ if denom_r.is_unit(): # faster if denom_r is a unit @@ -1083,7 +1089,7 @@ def __mod__(self, other): False sage: g in R.base_extend(Zmod(2)) True - sage: g.polynomial() == f.polynomial() % 2 # optional - sage.libs.singular + sage: g.polynomial() == f.polynomial() % 2 # needs sage.libs.singular True """ if isinstance(other, (int, Integer)): @@ -1158,14 +1164,15 @@ def variables(self): EXAMPLES:: - sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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() # optional - sage.rings.finite_rings - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.rings.finite_rings - sage: w # optional - sage.rings.finite_rings + 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 t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 - sage: w.variables() # optional - sage.rings.finite_rings + sage: w.variables() (t0, t2, t4) """ return tuple(self.parent(v) for v in self._value().variables()) @@ -1395,16 +1402,17 @@ def valuation(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(4949717)); R # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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) # optional - sage.rings.finite_rings - sage: f.valuation() # optional - sage.rings.finite_rings + sage: f = a^2 + a*b + a^3 + R.O(9) + sage: f.valuation() 2 - sage: g = 1 + a + a^3 # optional - sage.rings.finite_rings - sage: g.valuation() # optional - sage.rings.finite_rings + sage: g = 1 + a + a^3 + sage: g.valuation() 0 - sage: R.zero().valuation() # optional - sage.rings.finite_rings + sage: R.zero().valuation() +Infinity """ try: @@ -1897,13 +1905,13 @@ def exp(self, prec=infinity): sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(3) - sage: exp(f) # optional - sage.symbolic + sage: exp(f) # needs sage.symbolic 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 - sage: f.exp() # optional - sage.symbolic + sage: f.exp() # needs sage.symbolic 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 - sage: f.exp(prec=2) # optional - sage.symbolic + sage: f.exp(prec=2) # needs sage.symbolic 1 + a + b + O(a, b)^2 - sage: log(exp(f)) - f # optional - sage.symbolic + sage: log(exp(f)) - f # needs sage.symbolic 0 + O(a, b)^3 If the power series has a constant coefficient `c` and @@ -1912,7 +1920,7 @@ def exp(self, prec=infinity): are not yet implemented and therefore such cases raise an error:: sage: g = 2 + f - sage: exp(g) # optional - sage.symbolic + sage: exp(g) # needs sage.symbolic Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and @@ -1922,7 +1930,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)) # optional - sage.symbolic + sage: exp(g.change_ring(RDF)) # needs 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 @@ -1930,17 +1938,17 @@ def exp(self, prec=infinity): sage: T.default_prec() 12 - sage: exp(a) # optional - sage.symbolic + sage: exp(a) # needs 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)) # optional - sage.symbolic + sage: exp(a + T.O(5)) # needs 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)) # optional - sage.symbolic + sage: exp(a^2 + T.O(5)) # needs sage.symbolic 1 + a^2 + 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1989,11 +1997,11 @@ def log(self, prec=infinity): sage: T. = PowerSeriesRing(ZZ, 2) sage: f = 1 + a + b + a*b + T.O(5) - sage: f.log() # optional - sage.symbolic + sage: f.log() # needs sage.symbolic 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 - sage: log(f) # optional - sage.symbolic + sage: log(f) # needs sage.symbolic 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 - sage: exp(log(f)) - f # optional - sage.symbolic + sage: exp(log(f)) - f # needs sage.symbolic 0 + O(a, b)^5 If the power series has a constant coefficient `c` and @@ -2001,8 +2009,8 @@ 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 # optional - sage.symbolic - sage: log(g) # optional - sage.symbolic + sage: g = 2 + f + sage: log(g) # needs sage.symbolic Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for -: 'Symbolic Ring' and 'Power @@ -2011,7 +2019,7 @@ def log(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: log(g.change_ring(RDF)) # optional - sage.symbolic + sage: log(g.change_ring(RDF)) # needs sage.symbolic 1.09861228... + 0.333333333...*a + 0.333333333...*b - 0.0555555555...*a^2 + 0.222222222...*a*b - 0.0555555555...*b^2 + 0.0123456790...*a^3 - 0.0740740740...*a^2*b - 0.0740740740...*a*b^2 + 0.0123456790...*b^3 @@ -2020,17 +2028,17 @@ def log(self, prec=infinity): TESTS:: - sage: (1+a).log(prec=10).exp() # optional - sage.symbolic + sage: (1+a).log(prec=10).exp() # needs sage.symbolic 1 + a + O(a, b)^10 - sage: a.exp(prec=10).log() # optional - sage.symbolic + sage: a.exp(prec=10).log() # needs sage.symbolic a + O(a, b)^10 - sage: log(1+a) # optional - sage.symbolic + sage: log(1+a) # needs sage.symbolic a - 1/2*a^2 + 1/3*a^3 - 1/4*a^4 + 1/5*a^5 - 1/6*a^6 + 1/7*a^7 - 1/8*a^8 + 1/9*a^9 - 1/10*a^10 + 1/11*a^11 + O(a, b)^12 - sage: -log(1-a+T.O(5)) # optional - sage.symbolic + sage: -log(1-a+T.O(5)) # needs sage.symbolic a + 1/2*a^2 + 1/3*a^3 + 1/4*a^4 + O(a, b)^5 - sage: a.log(prec=10) # optional - sage.symbolic + sage: a.log(prec=10) Traceback (most recent call last): ... ValueError: Can only take formal power series for non-zero constant term. diff --git a/src/sage/rings/numbers_abc.py b/src/sage/rings/numbers_abc.py index 6bbcddccf40..a28021dd7db 100644 --- a/src/sage/rings/numbers_abc.py +++ b/src/sage/rings/numbers_abc.py @@ -41,26 +41,26 @@ def register_sage_classes(): True sage: isinstance(CDF(1.3, 4), numbers.Complex) True - sage: isinstance(AA(sqrt(2)), numbers.Real) + sage: isinstance(AA(sqrt(2)), numbers.Real) # needs sage.rings.number_field sage.symbolic True - sage: isinstance(QQbar(I), numbers.Complex) + sage: isinstance(QQbar(I), numbers.Complex) # needs sage.rings.number_field True This doesn't work with symbolic expressions at all:: - sage: isinstance(pi, numbers.Real) + sage: isinstance(pi, numbers.Real) # needs sage.symbolic False - sage: isinstance(I, numbers.Complex) + sage: isinstance(I, numbers.Complex) # needs sage.rings.number_field False - sage: isinstance(sqrt(2), numbers.Real) + sage: isinstance(sqrt(2), numbers.Real) # needs sage.rings.number_field sage.symbolic False Because we do this, NumPy's ``isscalar()`` recognizes Sage types:: - sage: from numpy import isscalar # optional - numpy - sage: isscalar(3.141) # optional - numpy + sage: from numpy import isscalar # needs numpy + sage: isscalar(3.141) # needs numpy True - sage: isscalar(4/17) # optional - numpy + sage: isscalar(4/17) # needs numpy True """ from sage.misc.superseded import deprecation diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 63d26c53757..e3c4305c823 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -16,9 +16,9 @@ cdef class PowerSeries_poly(PowerSeries): """ EXAMPLES:: - sage: R. = PowerSeriesRing(CC); R # optional - sage.rings.real_mpfr + sage: R. = PowerSeriesRing(CC); R # needs sage.rings.real_mpfr Power Series Ring in q over Complex Field with 53 bits of precision - sage: loads(q.dumps()) == q # optional - sage.rings.real_mpfr + sage: loads(q.dumps()) == q # needs sage.rings.real_mpfr True sage: R. = QQ[[]] @@ -33,9 +33,9 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`22216` is fixed:: sage: R. = PowerSeriesRing(QQ) - sage: R(pari('1 + O(T)')) # optional - sage.libs.pari + sage: R(pari('1 + O(T)')) # needs sage.libs.pari 1 + O(T) - sage: R(pari('1/T + O(T)')) # optional - sage.libs.pari + sage: R(pari('1/T + O(T)')) # needs sage.libs.pari Traceback (most recent call last): ... ValueError: series has negative valuation @@ -104,9 +104,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings - sage: f = 3 - t^3 + O(t^5) # optional - sage.rings.finite_rings - sage: f.polynomial() # optional - sage.rings.finite_rings + sage: R. = GF(7)[[]] + sage: f = 3 - t^3 + O(t^5) + sage: f.polynomial() 6*t^3 + 3 """ return self.__f @@ -158,12 +158,13 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] # optional - sage.rings.finite_rings - sage: bool(1 + t + O(t^18)) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = GF(11)[[]] + sage: bool(1 + t + O(t^18)) True - sage: bool(R(0)) # optional - sage.rings.finite_rings + sage: bool(R(0)) False - sage: bool(O(t^18)) # optional - sage.rings.finite_rings + sage: bool(O(t^18)) False """ return not not self.__f @@ -224,17 +225,17 @@ cdef class PowerSeries_poly(PowerSeries): A series defined over another ring can be substituted:: - sage: S. = GF(7)[[]] # optional - sage.rings.finite_rings - sage: f(2*u + u^3 + O(u^5)) # optional - sage.rings.finite_rings + sage: S. = GF(7)[[]] + sage: f(2*u + u^3 + O(u^5)) 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)) # optional - sage.rings.padics + sage: f(100 + O(5^7)) # needs 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)) # optional - sage.rings.padics + sage: f.change_ring(Zp(5))(100 + O(5^7)) # needs 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)) # optional - sage.rings.padics + sage: f.change_ring(Zp(5))(100 + O(2^7)) # needs sage.rings.padics Traceback (most recent call last): ... ValueError: Cannot substitute this value @@ -247,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)) # optional - sage.rings.padics + sage: f(2 + O(5^3)) # needs sage.rings.padics Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation @@ -267,18 +268,19 @@ cdef class PowerSeries_poly(PowerSeries): Arguments beyond the first can refer to the base ring:: - sage: P. = GF(5)[] # optional - sage.rings.finite_rings - sage: Q. = P[[]] # optional - sage.rings.finite_rings - sage: h = (1 - x*y)^-1 + O(y^7); h # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: P. = GF(5)[] + sage: Q. = P[[]] + sage: h = (1 - x*y)^-1 + O(y^7); h 1 + x*y + x^2*y^2 + x^3*y^3 + x^4*y^4 + x^5*y^5 + x^6*y^6 + O(y^7) - sage: h(y^2, 3) # optional - sage.rings.finite_rings + sage: h(y^2, 3) 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) These secondary values can also be specified using keywords:: - sage: h(y=y^2, x=3) # optional - sage.rings.finite_rings + sage: h(y=y^2, x=3) # needs sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) - sage: h(y^2, x=3) # optional - sage.rings.finite_rings + sage: h(y^2, x=3) # needs sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) """ P = self.parent() @@ -374,27 +376,29 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings - sage: f = 3 + 6*t^3 + O(t^5) # optional - sage.rings.finite_rings - sage: f._unsafe_mutate(0, 5) # optional - sage.rings.finite_rings - sage: f # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = GF(7)[[]] + sage: f = 3 + 6*t^3 + O(t^5) + sage: f._unsafe_mutate(0, 5) + sage: f 5 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(2, 1) ; f # optional - sage.rings.finite_rings + sage: f._unsafe_mutate(2, 1) ; f 5 + t^2 + 6*t^3 + O(t^5) - Mutating can even bump up the precision:: - sage: f._unsafe_mutate(6, 1) ; f # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: f._unsafe_mutate(6, 1) ; f 5 + t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(0, 0) ; f # optional - sage.rings.finite_rings + sage: f._unsafe_mutate(0, 0) ; f t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(1, 0) ; f # optional - sage.rings.finite_rings + sage: f._unsafe_mutate(1, 0) ; f t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(11,0) ; f # optional - sage.rings.finite_rings + sage: f._unsafe_mutate(11,0) ; f t^2 + 6*t^3 + t^6 + O(t^12) - sage: g = t + O(t^7) # optional - sage.rings.finite_rings - sage: g._unsafe_mutate(1,0) ; g # optional - sage.rings.finite_rings + sage: g = t + O(t^7) # needs sage.rings.finite_rings + sage: g._unsafe_mutate(1,0) ; g # needs sage.rings.finite_rings O(t^7) """ self.__f._unsafe_mutate(i, value) @@ -553,9 +557,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings - sage: f = t + 3*t^4 + O(t^11) # optional - sage.rings.finite_rings - sage: f * GF(7)(3) # optional - sage.rings.finite_rings + sage: R. = GF(7)[[]] + sage: f = t + 3*t^4 + O(t^11) + sage: f * GF(7)(3) 3*t + 2*t^4 + O(t^11) """ return PowerSeries_poly(self._parent, self.__f * c, self._prec, check=False) @@ -566,9 +570,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] # optional - sage.rings.finite_rings - sage: f = 1 + 3*t^4 + O(t^120) # optional - sage.rings.finite_rings - sage: 2 * f # optional - sage.rings.finite_rings + sage: R. = GF(11)[[]] + sage: f = 1 + 3*t^4 + O(t^120) + sage: 2 * f 2 + 6*t^4 + O(t^120) """ return PowerSeries_poly(self._parent, c * self.__f, self._prec, check=False) @@ -596,11 +600,12 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings - sage: f = t + t^4 + O(t^7) # optional - sage.rings.finite_rings - sage: f >> 1 # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = GF(2)[[]] + sage: f = t + t^4 + O(t^7) + sage: f >> 1 1 + t^3 + O(t^6) - sage: f >> 10 # optional - sage.rings.finite_rings + sage: f >> 10 O(t^0) """ if n: @@ -732,10 +737,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings - sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings + sage: R. = GF(2)[[]] + sage: f = 1/(1+I+O(I^8)); f 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) # optional - sage.rings.finite_rings + sage: f.truncate(5) I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -763,10 +768,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings - sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings + sage: R. = GF(2)[[]] + sage: f = 1/(1+I+O(I^8)); f 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate_powerseries(5) # optional - sage.rings.finite_rings + sage: f.truncate_powerseries(5) 1 + I + I^2 + I^3 + I^4 + O(I^5) """ return PowerSeries_poly(self._parent, self.__f.truncate(prec), @@ -844,8 +849,8 @@ cdef class PowerSeries_poly(PowerSeries): TESTS:: sage: R. = PowerSeriesRing(QQ, sparse=True) - sage: x = var('x') # optional - sage.symbolic - sage: t.derivative(x) # optional - sage.symbolic + sage: x = var('x') # needs sage.symbolic + sage: t.derivative(x) Traceback (most recent call last): ... ValueError: cannot differentiate with respect to x @@ -1034,10 +1039,10 @@ cdef class PowerSeries_poly(PowerSeries): ... ValueError: Series must have valuation one for reversion. - sage: Series = PowerSeriesRing(SR, 'x') # optional - sage.symbolic - sage: ser = Series([0, pi]); ser # optional - sage.symbolic + sage: Series = PowerSeriesRing(SR, 'x') # needs sage.symbolic + sage: ser = Series([0, pi]); ser # needs sage.symbolic pi*x - sage: ser.reverse() # optional - sage.symbolic + sage: ser.reverse() # needs sage.symbolic 1/pi*x + O(x^20) """ if self.valuation() != 1: @@ -1193,17 +1198,17 @@ cdef class PowerSeries_poly(PowerSeries): sage: R. = PowerSeriesRing(QQ) 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) # optional - sage.symbolic + sage: SR(s) # needs sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + Order(x^10) - sage: SR(s).is_terminating_series() # optional - sage.symbolic + sage: SR(s).is_terminating_series() # needs sage.symbolic False - sage: SR(s).variables() # optional - sage.symbolic + sage: SR(s).variables() # needs 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) # optional - sage.symbolic + sage: SR(s) # needs sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: _.is_terminating_series() # optional - sage.symbolic + sage: _.is_terminating_series() # needs sage.symbolic True TESTS: @@ -1211,7 +1216,7 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`18094` is fixed:: sage: R. = PolynomialRing(ZZ) - sage: SR(R(0).add_bigoh(20)) # optional - sage.symbolic + sage: SR(R(0).add_bigoh(20)) # needs 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 e023867b67e..e687681827d 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -59,13 +59,14 @@ :: - sage: K. = PowerSeriesRing(SR, default_prec=5) # optional - sage.symbolic - sage: a, b, c = var('a,b,c') # optional - sage.symbolic - sage: f = a + b*t + c*t^2 + O(t^3) # optional - sage.symbolic - sage: f*f # optional - sage.symbolic + sage: # needs sage.symbolic + sage: K. = PowerSeriesRing(SR, default_prec=5) + sage: a, b, c = var('a,b,c') + sage: f = a + b*t + c*t^2 + O(t^3) + sage: f*f a^2 + 2*a*b*t + (b^2 + 2*a*c)*t^2 + O(t^3) - sage: f = sqrt(2) + sqrt(3)*t + O(t^3) # optional - sage.symbolic - sage: f^2 # optional - sage.symbolic + sage: f = sqrt(2) + sqrt(3)*t + O(t^3) + sage: f^2 2 + 2*sqrt(3)*sqrt(2)*t + 3*t^2 + O(t^3) Elements are first coerced to constants in ``base_ring``, then coerced @@ -258,13 +259,13 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, Power series ring over finite field:: - sage: S = PowerSeriesRing(GF(65537),'x,y'); S # optional - sage.rings.finite_rings + sage: S = PowerSeriesRing(GF(65537),'x,y'); S # needs sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 Power series ring with many variables:: - sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R # optional - sage.libs.pari + sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R # needs 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 +275,12 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, :: - sage: R.inject_variables() # optional - sage.libs.pari + sage: R.inject_variables() # needs 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) # optional - sage.libs.pari - sage: f in R # optional - sage.libs.pari + sage: f = x47 + 3*x11*x29 - x19 + R.O(3) # needs sage.libs.pari + sage: f in R # needs sage.libs.pari True @@ -519,11 +520,12 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, commutative ring, but also a complete discrete valuation ring (CDVR). The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) # optional - sage.rings.finite_rings - sage: R. = k[[]] # optional - sage.rings.finite_rings - sage: R.category() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: k = GF(11) + sage: R. = k[[]] + sage: R.category() Category of complete discrete valuation rings - sage: TestSuite(R).run() # optional - sage.rings.finite_rings + sage: TestSuite(R).run() It is checked that the default precision is non-negative (see :trac:`19409`):: @@ -615,13 +617,14 @@ def _repr_(self): EXAMPLES:: - sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings - sage: R # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R = GF(17)[['y']] + sage: R Power Series Ring in y over Finite Field of size 17 - sage: R.__repr__() # optional - sage.rings.finite_rings + sage: R.__repr__() 'Power Series Ring in y over Finite Field of size 17' - sage: R.rename('my power series ring') # optional - sage.rings.finite_rings - sage: R # optional - sage.rings.finite_rings + sage: R.rename('my power series ring') + sage: R my power series ring """ s = "Power Series Ring in %s over %s"%(self.variable_name(), self.base_ring()) @@ -661,11 +664,12 @@ def _latex_(self): EXAMPLES:: - sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings - sage: latex(R) # indirect doctest # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R = GF(17)[['y']] + sage: latex(R) # indirect doctest \Bold{F}_{17}[[y]] - sage: R = GF(17)[['y12']] # optional - sage.rings.finite_rings - sage: latex(R) # optional - sage.rings.finite_rings + sage: R = GF(17)[['y12']] + sage: latex(R) \Bold{F}_{17}[[y_{12}]] """ return "%s[[%s]]"%(latex.latex(self.base_ring()), self.latex_variable_names()[0]) @@ -679,14 +683,15 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: A = GF(17)[['x']] # optional - sage.rings.finite_rings - sage: A.has_coerce_map_from(ZZ) # indirect doctest # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A = GF(17)[['x']] + sage: A.has_coerce_map_from(ZZ) # indirect doctest True - sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ['x']) True - sage: A.has_coerce_map_from(ZZ['y']) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ['y']) False - sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ[['x']]) True """ @@ -759,15 +764,16 @@ def _element_constructor_(self, f, prec=infinity, check=True): Conversion from symbolic series:: - sage: x,y = var('x,y') # optional - sage.symbolic - sage: s = (1/(1-x)).series(x,3); s # optional - sage.symbolic + sage: # needs sage.symbolic + sage: x,y = var('x,y') + sage: s = (1/(1-x)).series(x,3); s 1 + 1*x + 1*x^2 + Order(x^3) - sage: R. = PowerSeriesRing(QQ) # optional - sage.symbolic - sage: R(s) # optional - sage.symbolic + sage: R. = PowerSeriesRing(QQ) + sage: R(s) 1 + x + x^2 + O(x^3) - sage: ex = (gamma(1-y)).series(y,3) # optional - sage.symbolic - sage: R. = PowerSeriesRing(SR) # optional - sage.symbolic - sage: R(ex) # optional - sage.symbolic + sage: ex = (gamma(1-y)).series(y,3) + sage: R. = PowerSeriesRing(SR) + sage: R(ex) 1 + euler_gamma*y + (1/2*euler_gamma^2 + 1/12*pi^2)*y^2 + O(y^3) Laurent series with non-negative valuation are accepted (see @@ -891,16 +897,16 @@ def _coerce_impl(self, x): We illustrate canonical coercion between power series rings with compatible base rings:: - sage: R. = PowerSeriesRing(GF(7)['w']) # optional - sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(7)['w']) sage: S = PowerSeriesRing(ZZ, 't') sage: f = S([1,2,3,4]); f 1 + 2*t + 3*t^2 + 4*t^3 - sage: g = R.coerce(f); g # optional - sage.rings.finite_rings + sage: g = R.coerce(f); g 1 + 2*t + 3*t^2 + 4*t^3 - sage: parent(g) # optional - sage.rings.finite_rings + sage: parent(g) Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 - sage: S.coerce(g) # optional - sage.rings.finite_rings + sage: S.coerce(g) Traceback (most recent call last): ... TypeError: no canonical coercion @@ -981,11 +987,11 @@ def base_extend(self, R): EXAMPLES:: - sage: R. = GF(7)[[]]; R # optional - sage.rings.finite_rings + sage: R. = GF(7)[[]]; R Power Series Ring in T over Finite Field of size 7 - sage: R.change_ring(ZZ) # optional - sage.rings.finite_rings + sage: R.change_ring(ZZ) Power Series Ring in T over Integer Ring - sage: R.base_extend(ZZ) # optional - sage.rings.finite_rings + sage: R.base_extend(ZZ) Traceback (most recent call last): ... TypeError: no base extension defined @@ -1003,13 +1009,13 @@ def change_ring(self, R): sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field - sage: R.change_ring(GF(7)) # optional - sage.rings.finite_rings + sage: R.change_ring(GF(7)) Power Series Ring in T over Finite Field of size 7 - sage: R.base_extend(GF(7)) # optional - sage.rings.finite_rings + sage: R.base_extend(GF(7)) Traceback (most recent call last): ... TypeError: no base extension defined - sage: R.base_extend(QuadraticField(3,'a')) # optional - sage.rings.number_field + sage: R.base_extend(QuadraticField(3,'a')) # needs sage.rings.number_field Power Series Ring in T over Number Field in a with defining polynomial x^2 - 3 with a = 1.732050807568878? """ @@ -1234,11 +1240,11 @@ def residue_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings - sage: R.residue_field() # optional - sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(17)) + sage: R.residue_field() Finite Field of size 17 - sage: R. = PowerSeriesRing(Zp(5)) # optional - sage.rings.padics - sage: R.residue_field() # optional - sage.rings.padics + sage: R. = PowerSeriesRing(Zp(5)) # needs sage.rings.padics + sage: R.residue_field() # needs sage.rings.padics Finite Field of size 5 """ if self.base_ring().is_field(): @@ -1331,10 +1337,10 @@ def fraction_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(7)) # optional - sage.rings.finite_rings - sage: R.fraction_field() # optional - sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(7)) + sage: R.fraction_field() Laurent Series Ring in t over Finite Field of size 7 - sage: Frac(R) # optional - sage.rings.finite_rings + sage: Frac(R) Laurent Series Ring in t over Finite Field of size 7 """ return self.laurent_series_ring() diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index c9a73a18665..3579ac38953 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -130,9 +130,9 @@ def is_PowerSeries(x): True sage: is_PowerSeries(0) False - sage: var('x') # optional - sage.symbolic + sage: var('x') # needs sage.symbolic x - sage: is_PowerSeries(1 + x^2) # optional - sage.symbolic + sage: is_PowerSeries(1 + x^2) # needs sage.symbolic False """ return isinstance(x, PowerSeries) @@ -152,9 +152,9 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: PowerSeriesRing(CC, 'q') # optional - sage.rings.real_mpfr + sage: PowerSeriesRing(CC, 'q') # needs sage.rings.real_mpfr Power Series Ring in q over Complex Field with 53 bits of precision - sage: T = PowerSeriesRing(GF(3), 5, 't'); T # optional - sage.rings.finite_rings + sage: T = PowerSeriesRing(GF(3), 5, 't'); T Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite Field of size 3 """ @@ -276,13 +276,13 @@ cdef class PowerSeries(AlgebraElement): sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field sage: f = 1 - 1/2*T + 1/3*T^2 + O(T^3) - sage: f.base_extend(GF(5)) # optional - sage.rings.finite_rings + sage: f.base_extend(GF(5)) Traceback (most recent call last): ... TypeError: no base extension defined - sage: f.change_ring(GF(5)) # optional - sage.rings.finite_rings + sage: f.change_ring(GF(5)) 1 + 2*T + 2*T^2 + O(T^3) - sage: f.change_ring(GF(3)) # optional - sage.rings.finite_rings + sage: f.change_ring(GF(3)) Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(0, 3) does not exist @@ -292,18 +292,18 @@ cdef class PowerSeries(AlgebraElement): :: - sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # optional - sage.rings.number_field - sage: R. = K[['t']] # optional - sage.rings.number_field - sage: (4*t).change_ring(ZZ) # optional - sage.rings.number_field + sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # needs sage.rings.number_field + sage: R. = K[['t']] # needs sage.rings.number_field + sage: (4*t).change_ring(ZZ) # needs sage.rings.number_field 4*t This does not succeed because ``ZZ(K(a+1))`` is not defined. :: - sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # optional - sage.rings.number_field - sage: R. = K[['t']] # optional - sage.rings.number_field - sage: ((a+1)*t).change_ring(ZZ) # optional - sage.rings.number_field + sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # needs sage.rings.number_field + sage: R. = K[['t']] # needs sage.rings.number_field + sage: ((a+1)*t).change_ring(ZZ) # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce a + 1 to an integer @@ -483,11 +483,12 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: A. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: x = t + t^2 + O(t^5) # optional - sage.rings.finite_rings - sage: x.lift_to_precision(10) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A. = PowerSeriesRing(GF(5)) + sage: x = t + t^2 + O(t^5) + sage: x.lift_to_precision(10) t + t^2 + O(t^10) - sage: x.lift_to_precision() # optional - sage.rings.finite_rings + sage: x.lift_to_precision() t + t^2 """ @@ -521,8 +522,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = GF(49,'alpha')[[]] # optional - sage.rings.finite_rings - sage: (t^2 + O(t^3)).base_ring() # optional - sage.rings.finite_rings + sage: R. = GF(49,'alpha')[[]] # needs sage.rings.finite_rings + sage: (t^2 + O(t^3)).base_ring() # needs sage.rings.finite_rings Finite Field in alpha of size 7^2 """ return self._parent.base_ring() @@ -799,10 +800,10 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings - sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings + sage: R. = GF(2)[[]] + sage: f = 1/(1+I+O(I^8)); f 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) # optional - sage.rings.finite_rings + sage: f.truncate(5) I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -845,22 +846,23 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: + sage: # needs sage.rings.complex_double sage: R. = CDF[[]] - sage: f = CDF(pi)^2 + m^3 + CDF(e)*m^4 + O(m^10); f # abs tol 5e-16 + sage: f = CDF(pi)^2 + m^3 + CDF(e)*m^4 + O(m^10); f # abs tol 5e-16 # needs sage.symbolic 9.869604401089358 + 0.0*m + 0.0*m^2 + 1.0*m^3 + 2.718281828459045*m^4 + O(m^10) - sage: f[-5] + sage: f[-5] # needs sage.symbolic 0.0 - sage: f[0] + sage: f[0] # needs sage.symbolic 9.869604401089358 - sage: f[4] # abs tol 5e-16 + sage: f[4] # abs tol 5e-16 # needs sage.symbolic 2.718281828459045 - sage: f[9] + sage: f[9] # needs sage.symbolic 0.0 - sage: f[10] + sage: f[10] # needs sage.symbolic Traceback (most recent call last): ... IndexError: coefficient not known - sage: f[1000] + sage: f[1000] # needs sage.symbolic Traceback (most recent call last): ... IndexError: coefficient not known @@ -1104,9 +1106,9 @@ cdef class PowerSeries(AlgebraElement): """ EXAMPLES:: - sage: R. = Qp(7)[[]] # optional - sage.rings.padics - sage: f = (48*67 + 46*67^2)*T + (1 + 42*67 + 5*67^3)*T^2 + O(T^3) # optional - sage.rings.padics - sage: f % 67 # optional - sage.rings.padics + sage: R. = Qp(7)[[]] # needs sage.rings.padics + sage: f = (48*67 + 46*67^2)*T + (1 + 42*67 + 5*67^3)*T^2 + O(T^3) # needs sage.rings.padics + sage: f % 67 # needs sage.rings.padics T^2 + O(T^3) """ from sage.rings.power_series_ring import PowerSeriesRing @@ -1194,12 +1196,13 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari - sage: f = exp(x) + O(x^7); f # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: R. = PowerSeriesRing(QQ, implementation='pari') + sage: f = exp(x) + O(x^7); f # needs sage.symbolic 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) - sage: f << 2 # optional - sage.libs.pari + sage: f << 2 # needs sage.symbolic x^2 + x^3 + 1/2*x^4 + 1/6*x^5 + 1/24*x^6 + 1/120*x^7 + 1/720*x^8 + O(x^9) - sage: (f << 99) >> 99 # optional - sage.libs.pari + sage: (f << 99) >> 99 # needs sage.symbolic 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) """ return self.shift(n) @@ -1212,15 +1215,16 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari - sage: f = exp(x) + O(x^7) # optional - sage.libs.pari - sage: f >> 3 # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: R. = PowerSeriesRing(QQ, implementation='pari') + sage: f = exp(x) + O(x^7) # needs sage.symbolic + sage: f >> 3 # needs sage.symbolic 1/6 + 1/24*x + 1/120*x^2 + 1/720*x^3 + O(x^4) - sage: f >> 7 # optional - sage.libs.pari + sage: f >> 7 # needs sage.symbolic O(x^0) - sage: f >> 99 # optional - sage.libs.pari + sage: f >> 99 # needs sage.symbolic O(x^0) - sage: (f >> 99) << 99 # optional - sage.libs.pari + sage: (f >> 99) << 99 # needs sage.symbolic O(x^99) """ return self.shift(-n) @@ -1266,9 +1270,9 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = SR[[]] # optional - sage.symbolic - sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic - sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic + sage: R. = SR[[]] # needs sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # needs sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # needs sage.symbolic I + 3*x + (-I + 1)*x^2 sage: R. = ZZ[[]] sage: f = x^2 + 2 @@ -1278,28 +1282,28 @@ cdef class PowerSeries(AlgebraElement): Examples with different base ring:: sage: R. = ZZ[[]] - sage: k = GF(2) # optional - sage.rings.finite_rings - sage: residue = lambda x: k(x) # optional - sage.rings.finite_rings - sage: f = 4*x^2+x+3 # optional - sage.rings.finite_rings - sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings + sage: k = GF(2) + sage: residue = lambda x: k(x) + sage: f = 4*x^2+x+3 + sage: g = f.map_coefficients(residue); g 1 + x - sage: g.parent() # optional - sage.rings.finite_rings + sage: g.parent() Power Series Ring in x over Integer Ring - sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue, new_base_ring=k); g 1 + x - sage: g.parent() # optional - sage.rings.finite_rings + sage: g.parent() Power Series Ring in x over Finite Field of size 2 - sage: residue = k.coerce_map_from(ZZ) # optional - sage.rings.finite_rings - sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings + sage: residue = k.coerce_map_from(ZZ) + sage: g = f.map_coefficients(residue); g 1 + x - sage: g.parent() # optional - sage.rings.finite_rings + sage: g.parent() Power Series Ring in x over Finite Field of size 2 Tests other implementations:: - sage: R. = PowerSeriesRing(GF(11), implementation='pari') # optional - sage.rings.finite_rings - sage: f = q - q^3 + O(q^10) # optional - sage.rings.finite_rings - sage: f.map_coefficients(lambda c: c - 2) # optional - sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(11), implementation='pari') # needs sage.rings.finite_rings + sage: f = q - q^3 + O(q^10) # needs sage.rings.finite_rings + sage: f.map_coefficients(lambda c: c - 2) # needs sage.rings.finite_rings 10*q + 8*q^3 + O(q^10) """ pol = self.polynomial() @@ -1336,13 +1340,13 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: t = PowerSeriesRing(QQ, 't').gen() - sage: s = sum(factorial(k) * t**k for k in range(12)).O(12) - sage: s.jacobi_continued_fraction() + sage: s = sum(factorial(k) * t**k for k in range(12)).O(12) # needs sage.rings.complex_double + sage: s.jacobi_continued_fraction() # needs sage.rings.complex_double ((-1, -1), (-3, -4), (-5, -9), (-7, -16), (-9, -25)) Another example:: - sage: (log(1+t)/t).jacobi_continued_fraction() # optional - sage.symbolic + sage: (log(1+t)/t).jacobi_continued_fraction() ((1/2, -1/12), (1/2, -1/15), (1/2, -9/140), @@ -1401,13 +1405,13 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: t = PowerSeriesRing(QQ, 't').gen() - sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) # optional - sage.combinat - sage: s.stieltjes_continued_fraction() # optional - sage.combinat + sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) + sage: s.stieltjes_continued_fraction() (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) Another example:: - sage: (exp(t)).stieltjes_continued_fraction() # optional - sage.symbolic + sage: (exp(t)).stieltjes_continued_fraction() (1, -1/2, 1/6, @@ -1557,7 +1561,7 @@ cdef class PowerSeries(AlgebraElement): :: - sage: K. = PowerSeriesRing(CDF, 5) + sage: K. = PowerSeriesRing(CDF, 5) # needs sage.rings.complex_double sage: v = sqrt(-1 + t + t^3, all=True); v [1.0*I - 0.5*I*t - 0.125*I*t^2 - 0.5625*I*t^3 - 0.2890625*I*t^4 + O(t^5), -1.0*I + 0.5*I*t + 0.125*I*t^2 + 0.5625*I*t^3 + 0.2890625*I*t^4 + O(t^5)] @@ -1764,11 +1768,12 @@ cdef class PowerSeries(AlgebraElement): Positive characteristic:: - sage: R. = GF(3)[[]] # optional - sage.rings.finite_rings - sage: p = 1 + 2 * u^2 # optional - sage.rings.finite_rings - sage: p.nth_root(4) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = GF(3)[[]] + sage: p = 1 + 2 * u^2 + sage: p.nth_root(4) 1 + 2*u^2 + u^6 + 2*u^8 + u^12 + 2*u^14 + O(u^20) - sage: p.nth_root(4)**4 # optional - sage.rings.finite_rings + sage: p.nth_root(4)**4 1 + 2*u^2 + O(u^20) TESTS: @@ -1839,14 +1844,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cos(f) # optional - sage.symbolic + sage: cos(f) 1 - 1/2*t^2 - t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cos(f) # optional - sage.symbolic + sage: cos(f) 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 @@ -1857,7 +1862,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2+f - sage: cos(g) # optional - sage.symbolic + sage: cos(g) Traceback (most recent call last): ... ValueError: can only apply cos to formal power series with zero constant term @@ -1866,16 +1871,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cos(a) # optional - sage.symbolic + sage: cos(a) 1 - 1/2*a^2 + 1/24*a^4 - 1/720*a^6 + 1/40320*a^8 - 1/3628800*a^10 + O(a, b)^12 sage: a.cos(prec=5) 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cos(a + T.O(5)) # optional - sage.symbolic + sage: cos(a + T.O(5)) 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cos(a^2 + T.O(5)) # optional - sage.symbolic + sage: cos(a^2 + T.O(5)) 1 - 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1924,14 +1929,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sin(f) # optional - sage.symbolic + sage: sin(f) t + t^2 - 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) # optional - sage.symbolic + sage: sin(f) a + b + a*b + O(a, b)^3 sage: f.sin() a + b + a*b + O(a, b)^3 @@ -1942,7 +1947,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2+f - sage: sin(g) # optional - sage.symbolic + sage: sin(g) Traceback (most recent call last): ... ValueError: can only apply sin to formal power series with zero constant term @@ -1951,16 +1956,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sin(a) # optional - sage.symbolic + sage: sin(a) a - 1/6*a^3 + 1/120*a^5 - 1/5040*a^7 + 1/362880*a^9 - 1/39916800*a^11 + O(a, b)^12 sage: a.sin(prec=5) a - 1/6*a^3 + O(a, b)^5 - sage: sin(a + T.O(5)) # optional - sage.symbolic + sage: sin(a + T.O(5)) a - 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sin(a^2 + T.O(5)) # optional - sage.symbolic + sage: sin(a^2 + T.O(5)) a^2 + O(a, b)^5 """ R = self.parent() @@ -2010,14 +2015,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tan(f) # optional - sage.symbolic + sage: tan(f) t + t^2 + 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tan(f) # optional - sage.symbolic + sage: tan(f) a + b + a*b + O(a, b)^3 sage: f.tan() a + b + a*b + O(a, b)^3 @@ -2028,7 +2033,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: tan(g) # optional - sage.symbolic + sage: tan(g) Traceback (most recent call last): ... ValueError: can only apply tan to formal power series with zero constant term @@ -2037,16 +2042,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tan(a) # optional - sage.symbolic + sage: tan(a) a + 1/3*a^3 + 2/15*a^5 + 17/315*a^7 + 62/2835*a^9 + 1382/155925*a^11 + O(a, b)^12 sage: a.tan(prec=5) a + 1/3*a^3 + O(a, b)^5 - sage: tan(a + T.O(5)) # optional - sage.symbolic + sage: tan(a + T.O(5)) a + 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tan(a^2 + T.O(5)) # optional - sage.symbolic + sage: tan(a^2 + T.O(5)) a^2 + O(a, b)^5 """ if not self[0].is_zero(): @@ -2074,14 +2079,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sinh(f) # optional - sage.symbolic + sage: sinh(f) t + t^2 + 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sinh(f) # optional - sage.symbolic + sage: sinh(f) a + b + a*b + O(a, b)^3 sage: f.sinh() a + b + a*b + O(a, b)^3 @@ -2092,7 +2097,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: sinh(g) # optional - sage.symbolic + sage: sinh(g) Traceback (most recent call last): ... ValueError: can only apply sinh to formal power series with zero @@ -2102,17 +2107,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sinh(a) # optional - sage.symbolic + sage: sinh(a) a + 1/6*a^3 + 1/120*a^5 + 1/5040*a^7 + 1/362880*a^9 + 1/39916800*a^11 + O(a, b)^12 sage: a.sinh(prec=5) a + 1/6*a^3 + O(a, b)^5 - sage: sinh(a + T.O(5)) # optional - sage.symbolic + sage: sinh(a + T.O(5)) a + 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sinh(a^2 + T.O(5)) # optional - sage.symbolic + sage: sinh(a^2 + T.O(5)) a^2 + O(a, b)^5 """ @@ -2163,14 +2168,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cosh(f) # optional - sage.symbolic + sage: cosh(f) 1 + 1/2*t^2 + t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cosh(f) # optional - sage.symbolic + sage: cosh(f) 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 @@ -2181,7 +2186,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: cosh(g) # optional - sage.symbolic + sage: cosh(g) Traceback (most recent call last): ... ValueError: can only apply cosh to formal power series with zero @@ -2191,17 +2196,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cosh(a) # optional - sage.symbolic + sage: cosh(a) 1 + 1/2*a^2 + 1/24*a^4 + 1/720*a^6 + 1/40320*a^8 + 1/3628800*a^10 + O(a, b)^12 sage: a.cosh(prec=5) 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cosh(a + T.O(5)) # optional - sage.symbolic + sage: cosh(a + T.O(5)) 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cosh(a^2 + T.O(5)) # optional - sage.symbolic + sage: cosh(a^2 + T.O(5)) 1 + 1/2*a^4 + O(a, b)^5 """ @@ -2251,14 +2256,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tanh(f) # optional - sage.symbolic + sage: tanh(f) t + t^2 - 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tanh(f) # optional - sage.symbolic + sage: tanh(f) a + b + a*b + O(a, b)^3 sage: f.tanh() a + b + a*b + O(a, b)^3 @@ -2269,7 +2274,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2 + f - sage: tanh(g) # optional - sage.symbolic + sage: tanh(g) Traceback (most recent call last): ... ValueError: can only apply tanh to formal power series with zero @@ -2279,17 +2284,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tanh(a) # optional - sage.symbolic + sage: tanh(a) a - 1/3*a^3 + 2/15*a^5 - 17/315*a^7 + 62/2835*a^9 - 1382/155925*a^11 + O(a, b)^12 sage: a.tanh(prec=5) a - 1/3*a^3 + O(a, b)^5 - sage: tanh(a + T.O(5)) # optional - sage.symbolic + sage: tanh(a + T.O(5)) a - 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tanh(a^2 + T.O(5)) # optional - sage.symbolic + sage: tanh(a^2 + T.O(5)) a^2 + O(a, b)^5 """ @@ -2511,15 +2516,15 @@ cdef class PowerSeries(AlgebraElement): :: sage: R. = PowerSeriesRing(ZZ) - sage: (1 + x + O(x^2)).exp() + sage: (1 + x + O(x^2)).exp() # needs sage.symbolic Traceback (most recent call last): ... ArithmeticError: exponential of constant term does not belong to coefficient ring (consider working in a larger ring) :: - sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: (1 + x + O(x^2)).exp() # optional - sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(5)) + sage: (1 + x + O(x^2)).exp() Traceback (most recent call last): ... ArithmeticError: constant term of power series does not support exponentiation @@ -2787,21 +2792,21 @@ cdef class PowerSeries(AlgebraElement): sage: k. = QQ[[]] sage: f = 1 + 17*w + 15*w^3 + O(w^5) - sage: pari(f) # indirect doctest # optional - sage.libs.pari + sage: pari(f) # indirect doctest # needs sage.libs.pari 1 + 17*w + 15*w^3 + O(w^5) - sage: pari(1 - 19*w + w^5) # indirect doctest # optional - sage.libs.pari + sage: pari(1 - 19*w + w^5) # indirect doctest # needs sage.libs.pari w^5 - 19*w + 1 sage: R. = Zmod(6)[[]] - sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest # optional - sage.libs.pari + sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest # needs sage.libs.pari Mod(1, 6) + Mod(1, 6)*x + Mod(2, 6)*x^3 + O(x^8) TESTS:: - sage: pari(1 + O(x^1)) # optional - sage.libs.pari + sage: pari(1 + O(x^1)) # needs sage.libs.pari Mod(1, 6) + O(x) - sage: pari(O(x^1)) # optional - sage.libs.pari + sage: pari(O(x^1)) # needs sage.libs.pari O(x) - sage: pari(O(x^0)) # optional - sage.libs.pari + sage: pari(O(x^0)) # needs sage.libs.pari O(x^0) """ n = self.prec() diff --git a/src/sage/rings/puiseux_series_ring.py b/src/sage/rings/puiseux_series_ring.py index fdad0caef39..2f761c51925 100644 --- a/src/sage/rings/puiseux_series_ring.py +++ b/src/sage/rings/puiseux_series_ring.py @@ -111,7 +111,7 @@ def _repr_(self): EXAMPLES:: - sage: PuiseuxSeriesRing(AA, 'y') + sage: PuiseuxSeriesRing(AA, 'y') # needs sage.rings.number_field Puiseux Series Ring in y over Algebraic Real Field """ s = "Puiseux Series Ring in {} over {}".format(self.variable_name(), @@ -302,8 +302,8 @@ def _element_constructor_(self, x, e=1, prec=infinity): sage: P(z) + y**(1/2) 3 + y^(1/2) + 2*y + y^2 + 2*y^3 + O(y^5) - sage: from sage.modular.etaproducts import qexp_eta # optional - sage.modular - sage: y^(1/24)*qexp_eta(P, prec=30) # optional - sage.modular + sage: from sage.modular.etaproducts import qexp_eta # needs sage.modular + sage: y^(1/24)*qexp_eta(P, prec=30) # needs sage.modular y^(1/24) - y^(25/24) - y^(49/24) + y^(121/24) + y^(169/24) - y^(289/24) - y^(361/24) + y^(529/24) + y^(625/24) + O(y^(721/24)) """ P = parent(x) @@ -395,8 +395,8 @@ def gen(self, n=0): EXAMPLES:: - sage: A = PuiseuxSeriesRing(AA, 'z') - sage: A.gen() + sage: A = PuiseuxSeriesRing(AA, 'z') # needs sage.rings.number_field + sage: A.gen() # needs sage.rings.number_field z """ if n != 0: @@ -409,8 +409,8 @@ def ngens(self): EXAMPLES:: - sage: A = PuiseuxSeriesRing(AA, 'z') - sage: A.ngens() + sage: A = PuiseuxSeriesRing(AA, 'z') # needs sage.rings.number_field + sage: A.ngens() # needs sage.rings.number_field 1 """ return 1 @@ -421,8 +421,8 @@ def laurent_series_ring(self): EXAMPLES:: - sage: A = PuiseuxSeriesRing(AA, 'z') - sage: A.laurent_series_ring() + sage: A = PuiseuxSeriesRing(AA, 'z') # needs sage.rings.number_field + sage: A.laurent_series_ring() # needs sage.rings.number_field Laurent Series Ring in z over Algebraic Real Field """ return self._laurent_series_ring @@ -433,8 +433,8 @@ def default_prec(self): EXAMPLES:: - sage: A = PuiseuxSeriesRing(AA, 'z') - sage: A.default_prec() + sage: A = PuiseuxSeriesRing(AA, 'z') # needs sage.rings.number_field + sage: A.default_prec() # needs sage.rings.number_field 20 """ return self.laurent_series_ring().default_prec() diff --git a/src/sage/rings/puiseux_series_ring_element.pyx b/src/sage/rings/puiseux_series_ring_element.pyx index 9543ce5a24a..9465e20ba1b 100644 --- a/src/sage/rings/puiseux_series_ring_element.pyx +++ b/src/sage/rings/puiseux_series_ring_element.pyx @@ -46,7 +46,7 @@ Other arithmetic can be performed with Puiseux Series:: Mind the base ring. However, the base ring can be changed:: - sage: I*q + sage: I*q # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Number Field in I with defining polynomial x^2 + 1 with I = 1*I' and 'Puiseux Series Ring in x over Rational Field' @@ -220,11 +220,11 @@ cdef class PuiseuxSeries(AlgebraElement): sage: R. = PuiseuxSeriesRing(ZZ) sage: p = x^(1/3) + x**3 - sage: t = p._im_gens_(QQbar, [2]) - sage: t in QQbar + sage: t = p._im_gens_(QQbar, [2]) # needs sage.rings.number_field + sage: t in QQbar # needs sage.rings.number_field True - sage: f = R.hom([QQbar(2)], check=False) - sage: t == f(p) + sage: f = R.hom([QQbar(2)], check=False) # needs sage.rings.number_field + sage: t == f(p) # needs sage.rings.number_field True """ return self(codomain(im_gens[0])) @@ -241,8 +241,8 @@ cdef class PuiseuxSeries(AlgebraElement): sage: R.zero() 0 - sage: S. = PuiseuxSeriesRing(Zp(5)) - sage: t**(1/2) + 5 * t^(1/3) + sage: S. = PuiseuxSeriesRing(Zp(5)) # needs sage.rings.padics + sage: t**(1/2) + 5 * t^(1/3) # needs sage.rings.padics (5 + O(5^21))*t^(1/3) + (1 + O(5^20))*t^(1/2) """ laurent = self.laurent_part() @@ -300,7 +300,7 @@ cdef class PuiseuxSeries(AlgebraElement): sage: p = x^(1/2) + x**3-x**(-1/4) sage: p(16) 8199/2 - sage: p(pi.n()) + sage: p(pi.n()) # needs sage.symbolic 32.0276049867404 """ # use x.nth_root since x**(1/self._e) returns oo when x = 0 @@ -438,9 +438,9 @@ cdef class PuiseuxSeries(AlgebraElement): EXAMPLES:: - sage: P. = PuiseuxSeriesRing(Zp(3)) - sage: t = y^(2/5) + O(y) - sage: 5*t # indirect doctest + sage: P. = PuiseuxSeriesRing(Zp(3)) # needs sage.rings.padics + sage: t = y^(2/5) + O(y) # needs sage.rings.padics + sage: 5*t # indirect doctest # needs sage.rings.padics (2 + 3 + O(3^20))*y^(2/5) + O(y) """ return type(self)(self._parent, self._l._lmul_(c), self._e) @@ -871,6 +871,7 @@ cdef class PuiseuxSeries(AlgebraElement): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: P. = PolynomialRing(GF(5)) sage: R. = PuiseuxSeriesRing(P) sage: p = 3*y*x**(-2/3) + 2*y**2*x**(1/5); p @@ -944,6 +945,7 @@ cdef class PuiseuxSeries(AlgebraElement): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: R. = PuiseuxSeriesRing(GF(3)) sage: p = (x**(-1/3) + 2*x**3)**2; p x^(-2/3) + x^(8/3) + x^6 @@ -1018,6 +1020,7 @@ cdef class PuiseuxSeries(AlgebraElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: R. = PuiseuxSeriesRing(QQbar) sage: p = x**(3/2) - QQbar(I)*x**(1/2) sage: p.power_series() diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 4ffa5704e83..7c3e6262448 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -68,7 +68,7 @@ True sage: (sqrt(5 + 2*sqrt(QQbar(6))) - sqrt(QQbar(3)))^2 == 2 True - sage: AA((sqrt(5 + 2*sqrt(6)) - sqrt(3))^2) == 2 + sage: AA((sqrt(5 + 2*sqrt(6)) - sqrt(3))^2) == 2 # needs sage.symbolic True For a monic cubic polynomial `x^3 + bx^2 + cx + d` with roots `s1`, @@ -109,23 +109,23 @@ We can convert from symbolic expressions:: - sage: QQbar(sqrt(-5)) + sage: QQbar(sqrt(-5)) # needs sage.symbolic 2.236067977499790?*I - sage: AA(sqrt(2) + sqrt(3)) + sage: AA(sqrt(2) + sqrt(3)) # needs sage.symbolic 3.146264369941973? sage: QQbar(I) I - sage: QQbar(I * golden_ratio) + sage: QQbar(I * golden_ratio) # needs sage.symbolic 1.618033988749895?*I - sage: AA(golden_ratio)^2 - AA(golden_ratio) + sage: AA(golden_ratio)^2 - AA(golden_ratio) # needs sage.symbolic 1 - sage: QQbar((-8)^(1/3)) + sage: QQbar((-8)^(1/3)) # needs sage.symbolic 1.000000000000000? + 1.732050807568878?*I - sage: AA((-8)^(1/3)) + sage: AA((-8)^(1/3)) # needs sage.symbolic -2 - sage: QQbar((-4)^(1/4)) + sage: QQbar((-4)^(1/4)) # needs sage.symbolic 1 + 1*I - sage: AA((-4)^(1/4)) + sage: AA((-4)^(1/4)) # needs sage.symbolic Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real @@ -133,9 +133,9 @@ The coercion, however, goes in the other direction, since not all symbolic expressions are algebraic numbers:: - sage: QQbar(sqrt(2)) + sqrt(3) + sage: QQbar(sqrt(2)) + sqrt(3) # needs sage.symbolic sqrt(3) + 1.414213562373095? - sage: QQbar(sqrt(2) + QQbar(sqrt(3))) + sage: QQbar(sqrt(2) + QQbar(sqrt(3))) # needs sage.symbolic 3.146264369941973? Note the different behavior in taking roots: for ``AA`` we prefer real @@ -202,10 +202,11 @@ The Sage rings ``AA`` and ``QQbar`` can decide equalities between radical expressions (over the reals and complex numbers respectively):: - sage: a = AA((2/(3*sqrt(3)) + 10/27)^(1/3) - 2/(9*(2/(3*sqrt(3)) + 10/27)^(1/3)) + 1/3) - sage: a + sage: a = AA((2/(3*sqrt(3)) + 10/27)^(1/3) # needs sage.symbolic + ....: - 2/(9*(2/(3*sqrt(3)) + 10/27)^(1/3)) + 1/3) + sage: a # needs sage.symbolic 1.000000000000000? - sage: a == 1 + sage: a == 1 # needs sage.symbolic True Algebraic numbers which are known to be rational print as rationals; @@ -261,9 +262,9 @@ We can compute the multiplicative order of an algebraic number:: - sage: QQbar(-1/2 + I*sqrt(3)/2).multiplicative_order() + sage: QQbar(-1/2 + I*sqrt(3)/2).multiplicative_order() # needs sage.symbolic 3 - sage: QQbar(-sqrt(3)/2 + I/2).multiplicative_order() + sage: QQbar(-sqrt(3)/2 + I/2).multiplicative_order() # needs sage.symbolic 12 sage: (QQbar.zeta(23)**5).multiplicative_order() 23 @@ -332,6 +333,7 @@ on ``n`` will also trigger exact computation on ``rt2``, as you can see by the fact that the third output is different than the first:: + sage: # needs sage.symbolic sage: rt2 = AA(sqrt(2)) sage: n = rt2^2 sage: sage_input(n, verify=True) @@ -383,24 +385,24 @@ sage: loads(dumps(QQbar.zeta(5))) == QQbar.zeta(5) True - sage: t = QQbar(sqrt(2)); type(t._descr) + sage: t = QQbar(sqrt(2)); type(t._descr) # needs sage.symbolic - sage: loads(dumps(t)) == QQbar(sqrt(2)) + sage: loads(dumps(t)) == QQbar(sqrt(2)) # needs sage.symbolic True - sage: t.exactify(); type(t._descr) + sage: t.exactify(); type(t._descr) # needs sage.symbolic - sage: loads(dumps(t)) == QQbar(sqrt(2)) + sage: loads(dumps(t)) == QQbar(sqrt(2)) # needs sage.symbolic True - sage: t = ~QQbar(sqrt(2)); type(t._descr) + sage: t = ~QQbar(sqrt(2)); type(t._descr) # needs sage.symbolic - sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) + sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) # needs sage.symbolic True - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # needs sage.symbolic - sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) + sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) # needs sage.symbolic True We can convert elements of ``QQbar`` and ``AA`` into the following @@ -418,7 +420,9 @@ Here are examples of all of these conversions:: - sage: all_vals = [AA(42), AA(22/7), AA(golden_ratio), QQbar(-13), QQbar(89/55), QQbar(-sqrt(7)), QQbar.zeta(5)] + sage: # needs sage.symbolic + sage: all_vals = [AA(42), AA(22/7), AA(golden_ratio), + ....: QQbar(-13), QQbar(89/55), QQbar(-sqrt(7)), QQbar.zeta(5)] sage: def convert_test_all(ty): ....: def convert_test(v): ....: try: @@ -666,13 +670,14 @@ def common_polynomial(self, poly): sage: phi * tau == -1 True - sage: x = polygen(SR) # optional - sage.symbolic - sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p # optional - sage.symbolic + sage: # needs sage.symbolic + sage: x = polygen(SR) + sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p x^2 + (-sqrt(3) - sqrt(-5))*x + sqrt(3)*sqrt(-5) - sage: p = QQbar.common_polynomial(p) # optional - sage.symbolic - sage: a = QQbar.polynomial_root(p, CIF(RIF(-0.1, 0.1), RIF(2, 3))); a # optional - sage.symbolic + sage: p = QQbar.common_polynomial(p) + sage: a = QQbar.polynomial_root(p, CIF(RIF(-0.1, 0.1), RIF(2, 3))); a 0.?e-18 + 2.236067977499790?*I - sage: b = QQbar.polynomial_root(p, RIF(1, 2)); b # optional - sage.symbolic + sage: b = QQbar.polynomial_root(p, RIF(1, 2)); b 1.732050807568878? These "common polynomials" can be shared between real and @@ -785,6 +790,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test requiring us to further extend a number field that was used to specify the polynomial:: + sage: # needs sage.symbolic sage: p = x^2 + QQbar(sqrt(2))*y^2 sage: F = QQbar._factor_multivariate_polynomial(p) sage: F @@ -792,6 +798,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): sage: F.value() == p True + sage: # needs sage.symbolic sage: p = u^2 + AA(sqrt(2))*v^2 sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -802,6 +809,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test requiring a number field different from the number field used to specify the polynomial:: + sage: # needs sage.symbolic sage: p = QQbar(sqrt(2))*(x^2+y^2) sage: F = QQbar._factor_multivariate_polynomial(p) sage: F @@ -809,6 +817,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): sage: F.value() == p True + sage: # needs sage.symbolic sage: p = AA(sqrt(2))*(u^2+v^2) sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -819,6 +828,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test where a factor introduces a number field that was already used to specify the polynomial:: + sage: # needs sage.symbolic sage: p = QQbar(sqrt(2))*(x^2-2*y^2)^2 sage: F = QQbar._factor_multivariate_polynomial(p) sage: F @@ -827,6 +837,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): sage: F.value() == p True + sage: # needs sage.symbolic sage: p = AA(sqrt(2))*(u^2-2*v^2)^2 sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -837,6 +848,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test where two factors produce the same factor in the norm:: + sage: # needs sage.symbolic sage: p = (x^2+QQbar(sqrt(2))*y^2)*(x^4-2*y^4) sage: F = QQbar._factor_multivariate_polynomial(p) sage: F @@ -845,6 +857,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): sage: F.value() == p True + sage: # needs sage.symbolic sage: p = (u^2+AA(sqrt(2))*v^2)*(u^4-2*v^4) sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -868,9 +881,9 @@ def _factor_multivariate_polynomial(self, f, proof=True): number field generator:: sage: S. = QQbar[] - sage: p = a^2 + QQbar(sqrt(2))*b^2 - sage: F = QQbar._factor_multivariate_polynomial(p) - sage: F + sage: p = a^2 + QQbar(sqrt(2))*b^2 # needs sage.symbolic + sage: F = QQbar._factor_multivariate_polynomial(p) # needs sage.symbolic + sage: F # needs sage.symbolic (a + (-1.189207115002722?*I)*b) * (a + 1.189207115002722?*I*b) A test that led to :trac:`26898`:: @@ -1088,7 +1101,7 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: QQbar(sqrt(2)) in AA # indirect doctest + sage: QQbar(sqrt(2)) in AA # indirect doctest # needs sage.symbolic True sage: QQbar(I) in AA False @@ -1097,7 +1110,7 @@ def _element_constructor_(self, x): The following should both return ``True`` (this is a bug). :: - sage: sqrt(2) in AA # known bug + sage: sqrt(2) in AA # known bug # needs sage.symbolic False sage: K. = CyclotomicField(5); z + 1/z in AA # known bug False @@ -1178,7 +1191,7 @@ def _coerce_map_from_(self, from_par): True sage: a + AA(3) 5.645751311064590? - sage: AA.has_coerce_map_from(SR) # optional - sage.symbolic + sage: AA.has_coerce_map_from(SR) # needs sage.symbolic False sage: x = polygen(ZZ, 'x') @@ -1623,11 +1636,11 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: sqrt(2) in QQbar # indirect doctest + sage: sqrt(2) in QQbar # indirect doctest # needs sage.symbolic True sage: 22/7 in QQbar True - sage: pi in QQbar + sage: pi in QQbar # needs sage.symbolic False """ if isinstance(x, AlgebraicNumber): @@ -1685,7 +1698,7 @@ def _coerce_map_from_(self, from_par): True sage: QQbar.has_coerce_map_from(CC) False - sage: QQbar.has_coerce_map_from(SR) # optional - sage.symbolic + sage: QQbar.has_coerce_map_from(SR) # needs sage.symbolic False sage: i + QQbar(2) @@ -2567,30 +2580,34 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal sage: splitting = number_field_elements_from_algebraics(rts)[0]; splitting Number Field in a with defining polynomial y^6 - 40*y^4 - 22*y^3 + 873*y^2 + 1386*y + 594 sage: p.roots(ring=splitting) - [(361/29286*a^5 - 19/3254*a^4 - 14359/29286*a^3 + 401/29286*a^2 + 18183/1627*a + 15930/1627, 1), (49/117144*a^5 - 179/39048*a^4 - 3247/117144*a^3 + 22553/117144*a^2 + 1744/4881*a - 17195/6508, 1), (-1493/117144*a^5 + 407/39048*a^4 + 60683/117144*a^3 - 24157/117144*a^2 - 56293/4881*a - 53033/6508, 1)] - sage: rt2 = AA(sqrt(2)); rt2 + [(361/29286*a^5 - 19/3254*a^4 - 14359/29286*a^3 + 401/29286*a^2 + 18183/1627*a + 15930/1627, 1), + (49/117144*a^5 - 179/39048*a^4 - 3247/117144*a^3 + 22553/117144*a^2 + 1744/4881*a - 17195/6508, 1), + (-1493/117144*a^5 + 407/39048*a^4 + 60683/117144*a^3 - 24157/117144*a^2 - 56293/4881*a - 53033/6508, 1)] + sage: rt2 = AA(sqrt(2)); rt2 # needs sage.symbolic 1.414213562373095? - sage: rt3 = AA(sqrt(3)); rt3 + sage: rt3 = AA(sqrt(3)); rt3 # needs sage.symbolic 1.732050807568878? - sage: rt3a = QQbar(sqrt(3)); rt3a + sage: rt3a = QQbar(sqrt(3)); rt3a # needs sage.symbolic 1.732050807568878? sage: qqI = QQbar.zeta(4); qqI I sage: z3 = QQbar.zeta(3); z3 -0.500000000000000? + 0.866025403784439?*I - sage: rt2b = rt3 + rt2 - rt3; rt2b + sage: rt2b = rt3 + rt2 - rt3; rt2b # needs sage.symbolic 1.414213562373095? - sage: rt2c = z3 + rt2 - z3; rt2c + sage: rt2c = z3 + rt2 - z3; rt2c # needs sage.symbolic 1.414213562373095? + 0.?e-19*I - sage: number_field_elements_from_algebraics(rt2) - (Number Field in a with defining polynomial y^2 - 2, a, Ring morphism: + sage: number_field_elements_from_algebraics(rt2) # needs sage.symbolic + (Number Field in a with defining polynomial y^2 - 2, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 2 To: Algebraic Real Field Defn: a |--> 1.414213562373095?) - sage: number_field_elements_from_algebraics((rt2,rt3)) - (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, [-a^3 + 3*a, a^2 - 2], Ring morphism: + sage: number_field_elements_from_algebraics((rt2,rt3)) # needs sage.symbolic + (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, [-a^3 + 3*a, a^2 - 2], + Ring morphism: From: Number Field in a with defining polynomial y^4 - 4*y^2 + 1 To: Algebraic Real Field Defn: a |--> -1.931851652578137?) @@ -2599,14 +2616,16 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal to ``AA`` (because all elements are real), but if we specify ``same_field=True``, we'll get a homomorphism back to ``QQbar``:: - sage: number_field_elements_from_algebraics(rt3a) - (Number Field in a with defining polynomial y^2 - 3, a, Ring morphism: + sage: number_field_elements_from_algebraics(rt3a) # needs sage.symbolic + (Number Field in a with defining polynomial y^2 - 3, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 3 To: Algebraic Real Field Defn: a |--> 1.732050807568878?) - sage: number_field_elements_from_algebraics(rt3a, same_field=True) - (Number Field in a with defining polynomial y^2 - 3, a, Ring morphism: + sage: number_field_elements_from_algebraics(rt3a, same_field=True) # needs sage.symbolic + (Number Field in a with defining polynomial y^2 - 3, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 3 To: Algebraic Field Defn: a |--> 1.732050807568878?) @@ -2614,15 +2633,16 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal We've created ``rt2b`` in such a way that \sage does not initially know that it's in a degree-2 extension of `\QQ`:: - sage: number_field_elements_from_algebraics(rt2b) - (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, -a^3 + 3*a, Ring morphism: + sage: number_field_elements_from_algebraics(rt2b) # needs sage.symbolic + (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, -a^3 + 3*a, + Ring morphism: From: Number Field in a with defining polynomial y^4 - 4*y^2 + 1 To: Algebraic Real Field Defn: a |--> -1.931851652578137?) We can specify ``minimal=True`` if we want the smallest number field:: - sage: number_field_elements_from_algebraics(rt2b, minimal=True) + sage: number_field_elements_from_algebraics(rt2b, minimal=True) # needs sage.symbolic (Number Field in a with defining polynomial y^2 - 2, a, Ring morphism: From: Number Field in a with defining polynomial y^2 - 2 To: Algebraic Real Field @@ -2639,8 +2659,10 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal Or we can just pass in symbolic expressions, as long as they can be coerced into ``QQbar``:: - sage: number_field_elements_from_algebraics((sqrt(7), sqrt(9), sqrt(11))) - (Number Field in a with defining polynomial y^4 - 9*y^2 + 1, [-a^3 + 8*a, 3, -a^3 + 10*a], Ring morphism: + sage: number_field_elements_from_algebraics((sqrt(7), sqrt(9), sqrt(11))) # needs sage.symbolic + (Number Field in a with defining polynomial y^4 - 9*y^2 + 1, + [-a^3 + 8*a, 3, -a^3 + 10*a], + Ring morphism: From: Number Field in a with defining polynomial y^4 - 9*y^2 + 1 To: Algebraic Real Field Defn: a |--> 0.3354367396454047?) @@ -2648,12 +2670,16 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal Here we see an example of doing some computations with number field elements, and then mapping them back into ``QQbar``:: - sage: (fld,nums,hom) = number_field_elements_from_algebraics((rt2, rt3, qqI, z3)) + sage: # needs sage.symbolic + sage: algebraics = (rt2, rt3, qqI, z3) + sage: fld,nums,hom = number_field_elements_from_algebraics(algebraics) sage: fld,nums,hom # random - (Number Field in a with defining polynomial y^8 - y^4 + 1, [-a^5 + a^3 + a, a^6 - 2*a^2, a^6, -a^4], Ring morphism: - From: Number Field in a with defining polynomial y^8 - y^4 + 1 - To: Algebraic Field - Defn: a |--> -0.2588190451025208? - 0.9659258262890683?*I) + (Number Field in a with defining polynomial y^8 - y^4 + 1, + [-a^5 + a^3 + a, a^6 - 2*a^2, a^6, -a^4], + Ring morphism: + From: Number Field in a with defining polynomial y^8 - y^4 + 1 + To: Algebraic Field + Defn: a |--> -0.2588190451025208? - 0.9659258262890683?*I) sage: (nfrt2, nfrt3, nfI, nfz3) = nums sage: hom(nfrt2) 1.414213562373095? + 0.?e-18*I @@ -2689,9 +2715,13 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal :: - sage: nf,nums,hom = number_field_elements_from_algebraics([2^(1/3),3^(1/5)],embedded=True) + sage: # needs sage.symbolic + sage: elems = [2^(1/3), 3^(1/5)] + sage: nf, nums, hom = number_field_elements_from_algebraics(elems, + ....: embedded=True) sage: nf - Number Field in a with defining polynomial y^15 - 9*y^10 + 21*y^5 - 3 with a = 0.6866813218928813? + Number Field in a with defining polynomial y^15 - 9*y^10 + 21*y^5 - 3 + with a = 0.6866813218928813? sage: nums [a^10 - 5*a^5 + 2, -a^8 + 4*a^3] sage: hom @@ -2702,25 +2732,32 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal Complex embeddings are possible as well:: + sage: # needs sage.symbolic sage: elems = [sqrt(5), 2^(1/3)+sqrt(3)*I, 3/4] - sage: nf, nums, hom = number_field_elements_from_algebraics(elems, embedded=True) - sage: nf # random (polynomial and root not unique) + sage: nf, nums, hom = number_field_elements_from_algebraics(elems, + ....: embedded=True) + sage: nf # random (polynomial and root not unique) Number Field in a with defining polynomial y^24 - 6*y^23 ...- 9*y^2 + 1 with a = 0.2598679? + 0.0572892?*I - sage: nf.is_isomorphic(NumberField(x^24 - 9*x^22 + 135*x^20 - 720*x^18 + 1821*x^16 - 3015*x^14 + 3974*x^12 - 3015*x^10 + 1821*x^8 - 720*x^6 + 135*x^4 - 9*x^2 + 1, 'a')) + sage: nf.is_isomorphic(NumberField( + ....: x^24 - 9*x^22 + 135*x^20 - 720*x^18 + 1821*x^16 + ....: - 3015*x^14 + 3974*x^12 - 3015*x^10 + 1821*x^8 + ....: - 720*x^6 + 135*x^4 - 9*x^2 + 1, 'a')) True sage: list(map(QQbar, nums)) == elems == list(map(hom, nums)) True TESTS:: - sage: number_field_elements_from_algebraics(rt3) - (Number Field in a with defining polynomial y^2 - 3, a, Ring morphism: + sage: number_field_elements_from_algebraics(rt3) # needs sage.symbolic + (Number Field in a with defining polynomial y^2 - 3, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 3 To: Algebraic Real Field Defn: a |--> 1.732050807568878?) - sage: number_field_elements_from_algebraics((rt2,qqI)) - (Number Field in a with defining polynomial y^4 + 1, [-a^3 + a, a^2], Ring morphism: + sage: number_field_elements_from_algebraics((rt2,qqI)) # needs sage.symbolic + (Number Field in a with defining polynomial y^4 + 1, [-a^3 + a, a^2], + Ring morphism: From: Number Field in a with defining polynomial y^4 + 1 To: Algebraic Field Defn: a |--> 0.7071067811865475? + 0.7071067811865475?*I) @@ -2728,16 +2765,18 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal Note that for the first example, where \sage does not realize that the number is real, we get a homomorphism to ``QQbar``:: - sage: number_field_elements_from_algebraics(rt2c) # random - (Number Field in a with defining polynomial y^4 + 2*y^2 + 4, 1/2*a^3, Ring morphism: + sage: number_field_elements_from_algebraics(rt2c) # random # needs sage.symbolic + (Number Field in a with defining polynomial y^4 + 2*y^2 + 4, 1/2*a^3, + Ring morphism: From: Number Field in a with defining polynomial y^4 + 2*y^2 + 4 To: Algebraic Field Defn: a |--> -0.7071067811865475? - 1.224744871391589?*I) But with ``minimal=True``, we get a homomorphism to ``AA``:: - sage: number_field_elements_from_algebraics(rt2c, minimal=True) - (Number Field in a with defining polynomial y^2 - 2, a, Ring morphism: + sage: number_field_elements_from_algebraics(rt2c, minimal=True) # needs sage.symbolic + (Number Field in a with defining polynomial y^2 - 2, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 2 To: Algebraic Real Field Defn: a |--> 1.414213562373095?) @@ -2745,8 +2784,10 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal If we specify both ``minimal=True`` and ``same_field=True``, we get a second degree extension (minimal) that maps back to ``QQbar``:: - sage: number_field_elements_from_algebraics(rt2c, minimal=True, same_field=True) - (Number Field in a with defining polynomial y^2 - 2, a, Ring morphism: + sage: number_field_elements_from_algebraics(rt2c, minimal=True, # needs sage.symbolic + ....: same_field=True) + (Number Field in a with defining polynomial y^2 - 2, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 2 To: Algebraic Field Defn: a |--> 1.414213562373095?) @@ -2770,12 +2811,13 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal sage: E = UCF.gen(5) sage: L. = NumberField(x^2-189*x+16, embedding=200) sage: x = polygen(ZZ) - sage: my_nums = [-52*E - 136*E^2 - 136*E^3 - 52*E^4, \ - L.gen()._algebraic_(AA), \ - sqrt(2), AA.polynomial_root(x^3-3, RIF(0,3)), 11/9, 1] - sage: res = number_field_elements_from_algebraics(my_nums, embedded=True) - sage: res[0] - Number Field in a with defining polynomial y^24 - 107010*y^22 - 24*y^21 + ... + 250678447193040618624307096815048024318853254384 with a = 93.32530798172420? + sage: my_nums = [-52*E - 136*E^2 - 136*E^3 - 52*E^4, # needs sage.symbolic + ....: L.gen()._algebraic_(AA), + ....: sqrt(2), AA.polynomial_root(x^3 - 3, RIF(0,3)), 11/9, 1] + sage: res = number_field_elements_from_algebraics(my_nums, embedded=True) # needs sage.symbolic + sage: res[0] # needs sage.symbolic + Number Field in a with defining polynomial y^24 - 107010*y^22 - 24*y^21 + ... + + 250678447193040618624307096815048024318853254384 with a = 93.32530798172420? """ gen = qq_generator @@ -3030,6 +3072,7 @@ def __reduce__(self): EXAMPLES:: + sage: # needs sage.symbolic sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)) sage: t.exactify() sage: type(t._descr._generator) @@ -3456,17 +3499,17 @@ def is_simple(self): sage: from sage.rings.qqbar import ANRational sage: ANRational(1/2).is_simple() True - sage: rt2 = AA(sqrt(2)) - sage: rt3 = AA(sqrt(3)) - sage: rt2b = rt3 + rt2 - rt3 - sage: rt2.exactify() - sage: rt2._descr.is_simple() + sage: rt2 = AA(sqrt(2)) # needs sage.symbolic + sage: rt3 = AA(sqrt(3)) # needs sage.symbolic + sage: rt2b = rt3 + rt2 - rt3 # needs sage.symbolic + sage: rt2.exactify() # needs sage.symbolic + sage: rt2._descr.is_simple() # needs sage.symbolic True - sage: rt2b.exactify() - sage: rt2b._descr.is_simple() + sage: rt2b.exactify() # needs sage.symbolic + sage: rt2b._descr.is_simple() # needs sage.symbolic False - sage: rt2b.simplify() - sage: rt2b._descr.is_simple() + sage: rt2b.simplify() # needs sage.symbolic + sage: rt2b._descr.is_simple() # needs sage.symbolic True """ return False @@ -3480,9 +3523,9 @@ def neg(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(2)) - sage: b = a._descr - sage: b.neg(a) + sage: a = QQbar(sqrt(2)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.neg(a) # needs sage.symbolic """ return ANUnaryExpr(n, '-') @@ -3493,9 +3536,9 @@ def invert(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(2)) - sage: b = a._descr - sage: b.invert(a) + sage: a = QQbar(sqrt(2)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.invert(a) # needs sage.symbolic """ return ANUnaryExpr(n, '~') @@ -3506,9 +3549,9 @@ def abs(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(2)) - sage: b = a._descr - sage: b.abs(a) + sage: a = QQbar(sqrt(2)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.abs(a) # needs sage.symbolic """ return ANUnaryExpr(n, 'abs') @@ -3519,9 +3562,9 @@ def real(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-7)) - sage: b = a._descr - sage: b.real(a) + sage: a = QQbar(sqrt(-7)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.real(a) # needs sage.symbolic """ if self.is_complex(): @@ -3535,9 +3578,9 @@ def imag(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-7)) - sage: b = a._descr - sage: b.imag(a) + sage: a = QQbar(sqrt(-7)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.imag(a) # needs sage.symbolic """ if self.is_complex(): @@ -3551,9 +3594,9 @@ def conjugate(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-7)) - sage: b = a._descr - sage: b.conjugate(a) + sage: a = QQbar(sqrt(-7)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.conjugate(a) # needs sage.symbolic """ if self.is_complex(): @@ -3568,9 +3611,9 @@ def norm(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-7)) - sage: b = a._descr - sage: b.norm(a) + sage: a = QQbar(sqrt(-7)) # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: b.norm(a) # needs sage.symbolic """ if self.is_complex(): @@ -3635,7 +3678,7 @@ class AlgebraicNumber_base(sage.structure.element.FieldElement): 1.618033988749895? sage: phi^2 == phi+1 True - sage: AA(sqrt(65537)) + sage: AA(sqrt(65537)) # needs sage.symbolic 256.0019531175495? """ @@ -3695,9 +3738,9 @@ def _repr_(self): sage: AA(19).sqrt() 4.358898943540674? sage: AA.options.display_format = 'radical' - sage: AA(19).sqrt() + sage: AA(19).sqrt() # needs sage.symbolic sqrt(19) - sage: QQbar.zeta(6) + sage: QQbar.zeta(6) # needs sage.symbolic 1/2*I*sqrt(3) + 1/2 sage: QQbar.zeta(17) 0.9324722294043558? + 0.3612416661871530?*I @@ -3813,7 +3856,7 @@ def _mul_(self, other): """ TESTS:: - sage: AA(sqrt(2)) * AA(sqrt(8)) # indirect doctest + sage: AA(sqrt(2)) * AA(sqrt(8)) # indirect doctest # needs sage.symbolic 4.000000000000000? """ sk = type(self._descr) @@ -3824,7 +3867,7 @@ def _div_(self, other): """ TESTS:: - sage: AA(sqrt(2)) / AA(sqrt(8)) # indirect doctest + sage: AA(sqrt(2)) / AA(sqrt(8)) # indirect doctest # needs sage.symbolic 0.500000000000000? sage: z = QQbar(I).real() @@ -3843,7 +3886,7 @@ def __invert__(self): """ TESTS:: - sage: ~AA(sqrt(~2)) + sage: ~AA(sqrt(~2)) # needs sage.symbolic 1.414213562373095? sage: z = QQbar(I).real() @@ -3873,7 +3916,7 @@ def _sub_(self, other): """ TESTS:: - sage: AA(golden_ratio) * 2 - AA(5).sqrt() # indirect doctest + sage: AA(golden_ratio) * 2 - AA(5).sqrt() # indirect doctest # needs sage.symbolic 1.000000000000000? """ sk = type(self._descr) @@ -3893,7 +3936,7 @@ def __abs__(self): """ TESTS:: - sage: abs(AA(sqrt(2) - sqrt(3))) + sage: abs(AA(sqrt(2) - sqrt(3))) # needs sage.symbolic 0.3178372451957823? sage: abs(QQbar(3+4*I)) 5 @@ -3929,8 +3972,8 @@ def __hash__(self): True sage: h1 = hash(QQbar.zeta(6)) - sage: h2 = hash(QQbar(1/2 + I*sqrt(3)/2)) - sage: h1 == h2 + sage: h2 = hash(QQbar(1/2 + I*sqrt(3)/2)) # needs sage.symbolic + sage: h1 == h2 # needs sage.symbolic True Unfortunately, the hash code for algebraic numbers which are close @@ -4003,11 +4046,11 @@ def __bool__(self): sage: a = QQbar(2).sqrt() - 16616132878186749607/11749380235262596085 sage: b = QQbar(2).sqrt() - 6882627592338442563/4866752642924153522 sage: c = QQbar(3).sqrt() - 142437039878091970439/82236063316189858921 - sage: d = (59/2)**(1000/7) - sage: e = (a + b + c) * (a + b - c) * (a - b) * (a - b - c) / d - sage: bool(e) + sage: d = (59/2)**(1000/7) # needs sage.symbolic + sage: e = (a + b + c) * (a + b - c) * (a - b) * (a - b - c) / d # needs sage.symbolic + sage: bool(e) # needs sage.symbolic True - sage: bool(e.abs() < 2**-500) + sage: bool(e.abs() < 2**-500) # needs sage.symbolic True An identity between roots of unity:: @@ -4315,8 +4358,9 @@ def as_number_field_element(self, minimal=False, embedded=False, prec=53): EXAMPLES:: - sage: QQbar(sqrt(8)).as_number_field_element() - (Number Field in a with defining polynomial y^2 - 2, 2*a, Ring morphism: + sage: QQbar(sqrt(8)).as_number_field_element() # needs sage.symbolic + (Number Field in a with defining polynomial y^2 - 2, 2*a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 2 To: Algebraic Real Field Defn: a |--> 1.414213562373095?) @@ -4368,6 +4412,7 @@ def as_number_field_element(self, minimal=False, embedded=False, prec=53): A complex algebraic number as an element of an embedded number field:: + sage: # needs sage.symbolic sage: num = QQbar(sqrt(2) + 3^(1/3)*I) sage: nf, elt, hom = num.as_number_field_element(embedded=True) sage: hom(elt).parent() is QQbar @@ -4380,16 +4425,19 @@ def as_number_field_element(self, minimal=False, embedded=False, prec=53): We see an example where we do not get the minimal number field unless we specify ``minimal=True``:: + sage: # needs sage.symbolic sage: rt2 = AA(sqrt(2)) sage: rt3 = AA(sqrt(3)) sage: rt3b = rt2 + rt3 - rt2 sage: rt3b.as_number_field_element() - (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, a^2 - 2, Ring morphism: + (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, a^2 - 2, + Ring morphism: From: Number Field in a with defining polynomial y^4 - 4*y^2 + 1 To: Algebraic Real Field Defn: a |--> -1.931851652578137?) sage: rt3b.as_number_field_element(minimal=True) - (Number Field in a with defining polynomial y^2 - 3, a, Ring morphism: + (Number Field in a with defining polynomial y^2 - 3, a, + Ring morphism: From: Number Field in a with defining polynomial y^2 - 3 To: Algebraic Real Field Defn: a |--> 1.732050807568878?) @@ -4444,6 +4492,7 @@ def simplify(self): EXAMPLES:: + sage: # needs sage.symbolic sage: rt2 = AA(sqrt(2)) sage: rt3 = AA(sqrt(3)) sage: rt2b = rt3 + rt2 - rt3 @@ -4697,28 +4746,28 @@ def radical_expression(self): EXAMPLES:: - sage: AA(1/sqrt(5)).radical_expression() # optional - sage.symbolic + sage: AA(1/sqrt(5)).radical_expression() # needs sage.symbolic sqrt(1/5) - sage: AA(sqrt(5 + sqrt(5))).radical_expression() # optional - sage.symbolic + sage: AA(sqrt(5 + sqrt(5))).radical_expression() # needs sage.symbolic sqrt(sqrt(5) + 5) - sage: QQbar.zeta(5).radical_expression() # optional - sage.symbolic + sage: QQbar.zeta(5).radical_expression() # needs sage.symbolic 1/4*sqrt(5) + 1/2*sqrt(-1/2*sqrt(5) - 5/2) - 1/4 sage: x = polygen(QQ, 'x') sage: a = (x^7 - x - 1).roots(AA, False)[0] - sage: a.radical_expression() # optional - sage.symbolic + sage: a.radical_expression() # needs sage.symbolic 1.112775684278706? - sage: a.radical_expression().parent() == SR # optional - sage.symbolic + sage: a.radical_expression().parent() == SR # needs sage.symbolic False sage: a = sorted((x^7-x-1).roots(QQbar, False), key=imag)[0] - sage: a.radical_expression() # optional - sage.symbolic + sage: a.radical_expression() # needs sage.symbolic -0.3636235193291805? - 0.9525611952610331?*I - sage: QQbar.zeta(5).imag().radical_expression() # optional - sage.symbolic + sage: QQbar.zeta(5).imag().radical_expression() # needs sage.symbolic 1/2*sqrt(1/2*sqrt(5) + 5/2) - sage: AA(5/3).radical_expression() # optional - sage.symbolic + sage: AA(5/3).radical_expression() # needs sage.symbolic 5/3 - sage: AA(5/3).radical_expression().parent() == SR # optional - sage.symbolic + sage: AA(5/3).radical_expression().parent() == SR # needs sage.symbolic True - sage: QQbar(0).radical_expression() # optional - sage.symbolic + sage: QQbar(0).radical_expression() # needs sage.symbolic 0 TESTS: @@ -4729,15 +4778,16 @@ def radical_expression(self): :: - sage: a = AA(sqrt(2) + 10^25) # optional - sage.symbolic - sage: p = a.minpoly() # optional - sage.symbolic - sage: v = a._value # optional - sage.symbolic - sage: f = ComplexIntervalField(v.prec()) # optional - sage.symbolic - sage: var('x') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = AA(sqrt(2) + 10^25) + sage: p = a.minpoly() + sage: v = a._value + sage: f = ComplexIntervalField(v.prec()) + sage: var('x') x - sage: [f(b.rhs()).overlaps(f(v)) for b in SR(p).solve(x)] # optional - sage.symbolic + sage: [f(b.rhs()).overlaps(f(v)) for b in SR(p).solve(x)] [True, True] - sage: a.radical_expression() # optional - sage.symbolic + sage: a.radical_expression() sqrt(2) + 10000000000000000000000000 """ from sage.symbolic.ring import SR # Lazy to avoid cyclic dependency @@ -4765,17 +4815,18 @@ def _maxima_init_(self, I=None): r""" EXAMPLES:: + sage: # needs sage.symbolic sage: maxima(AA(7)) 7 - sage: maxima(QQbar(sqrt(5/2))) # optional - sage.symbolic + sage: maxima(QQbar(sqrt(5/2))) sqrt(10)/2 - sage: maxima(AA(-sqrt(5))) # optional - sage.symbolic + sage: maxima(AA(-sqrt(5))) -sqrt(5) - sage: maxima(QQbar(sqrt(-2))) # optional - sage.symbolic + sage: maxima(QQbar(sqrt(-2))) sqrt(2)*%i - sage: maxima(AA(2+sqrt(5))) # optional - sage.symbolic + sage: maxima(AA(2+sqrt(5))) sqrt(5)+2 - sage: maxima(QQ[x](x^7 - x - 1).roots(AA, False)[0]) # optional - sage.symbolic + sage: maxima(QQ[x](x^7 - x - 1).roots(AA, False)[0]) Traceback (most recent call last): ... NotImplementedError: cannot find radical expression @@ -4889,24 +4940,24 @@ def _richcmp_(self, other, op): TESTS:: - sage: QQbar.zeta(6) == QQbar(1/2 + I*sqrt(3)/2) # optional - sage.symbolic + sage: QQbar.zeta(6) == QQbar(1/2 + I*sqrt(3)/2) # needs sage.symbolic True sage: QQbar(I) == QQbar(I * (2^100+1)/(2^100)) False sage: QQbar(2) == 2 True - sage: QQbar(2) == GF(7)(2) # optional - sage.rings.finite_rings + sage: QQbar(2) == GF(7)(2) # needs sage.rings.finite_rings False - sage: GF(7)(2) in QQbar # optional - sage.rings.finite_rings + sage: GF(7)(2) in QQbar # needs sage.rings.finite_rings False - sage: QQbar.zeta(6) != QQbar(1/2 + I*sqrt(3)/2) # optional - sage.symbolic + sage: QQbar.zeta(6) != QQbar(1/2 + I*sqrt(3)/2) # needs sage.symbolic False sage: QQbar(I) != QQbar(I * (2^100+1)/(2^100)) True sage: QQbar(2) != 2 False - sage: QQbar(2) != GF(7)(2) # optional - sage.rings.finite_rings + sage: QQbar(2) != GF(7)(2) # needs sage.rings.finite_rings True sage: QQbar.zeta(3).real() == -1/2 @@ -4926,22 +4977,22 @@ def _richcmp_(self, other, op): Check that :trac:`29220` is fixed:: - sage: a = AA(2**(1/2) - 2**(1/3)) + sage: a = AA(2**(1/2) - 2**(1/3)) # needs sage.symbolic sage: b = 808620184/5240825825 - sage: a < b + sage: a < b # needs sage.symbolic True - sage: a < b + sage: a < b # needs sage.symbolic True - sage: a = AA(2^(1/3)) + sage: a = AA(2^(1/3)) # needs sage.symbolic sage: r = 3085094589/2448641198 - sage: a < r + sage: a < r # needs sage.symbolic False - sage: a > r + sage: a > r # needs sage.symbolic True - sage: a < r + sage: a < r # needs sage.symbolic False - sage: a > r + sage: a > r # needs sage.symbolic True """ if self is other: @@ -5000,7 +5051,7 @@ def _mpfr_(self, field): EXAMPLES:: - sage: QQbar(sqrt(2))._mpfr_(RR) + sage: QQbar(sqrt(2))._mpfr_(RR) # needs sage.symbolic 1.41421356237309 sage: QQbar(-22/7)._mpfr_(RR) -3.14285714285714 @@ -5019,7 +5070,7 @@ def __float__(self): EXAMPLES:: - sage: QQbar(sqrt(2)).__float__() + sage: QQbar(sqrt(2)).__float__() # needs sage.symbolic 1.414213562373095 sage: float(QQbar(-22/7)) -3.1428571428571432 @@ -5036,7 +5087,7 @@ def __complex__(self): EXAMPLES:: - sage: QQbar(sqrt(2)).__complex__() + sage: QQbar(sqrt(2)).__complex__() # needs sage.symbolic (1.414213562373095+0j) sage: complex(QQbar.zeta(3)) (-0.5+0.8660254037844386j) @@ -5049,7 +5100,7 @@ def _complex_double_(self, cdf): EXAMPLES:: - sage: QQbar(sqrt(-5))._complex_double_(CDF) + sage: QQbar(sqrt(-5))._complex_double_(CDF) # needs sage.symbolic 2.23606797749979*I sage: CDF(QQbar.zeta(12)) 0.8660254037844386 + 0.5*I @@ -5062,7 +5113,7 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: QQbar(sqrt(-5))._interval_fast(100) + sage: QQbar(sqrt(-5))._interval_fast(100) # needs sage.symbolic 2.236067977499789696409173...?*I """ return self.interval_fast(ComplexIntervalField(prec)) @@ -5081,15 +5132,15 @@ def _integer_(self, ZZ=None): Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real - sage: QQbar(sqrt(17))._integer_() + sage: QQbar(sqrt(17))._integer_() # needs sage.symbolic Traceback (most recent call last): ... ValueError: Cannot coerce non-integral Algebraic Real 4.123105625617660? to Integer - sage: QQbar(sqrt(16))._integer_() + sage: QQbar(sqrt(16))._integer_() # needs sage.symbolic 4 - sage: v = QQbar(1 + I*sqrt(3))^5 + QQbar(16*sqrt(3)*I); v + sage: v = QQbar(1 + I*sqrt(3))^5 + QQbar(16*sqrt(3)*I); v # needs sage.symbolic 16.00000000000000? + 0.?e-17*I - sage: v._integer_() + sage: v._integer_() # needs sage.symbolic 16 """ return AA(self)._integer_(ZZ) @@ -5108,15 +5159,15 @@ def _rational_(self): Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real - sage: QQbar(sqrt(2))._rational_() + sage: QQbar(sqrt(2))._rational_() # needs sage.symbolic Traceback (most recent call last): ... ValueError: Cannot coerce irrational Algebraic Real 1.414213562373095? to Rational - sage: v1 = QQbar(1/3 + I*sqrt(5))^7 - sage: v2 = QQbar((100336/729*golden_ratio - 50168/729)*I) - sage: v = v1 + v2; v + sage: v1 = QQbar(1/3 + I*sqrt(5))^7 # needs sage.symbolic + sage: v2 = QQbar((100336/729*golden_ratio - 50168/729)*I) # needs sage.symbolic + sage: v = v1 + v2; v # needs sage.symbolic -259.6909007773206? + 0.?e-15*I - sage: v._rational_() + sage: v._rational_() # needs sage.symbolic -567944/2187 """ return AA(self)._rational_() @@ -5191,10 +5242,10 @@ def interval_exact(self, field): 0.7071067811865475? + 0.7071067811865475?*I sage: a.interval_exact(CIF) 0.7071067811865475? + 0.7071067811865475?*I - sage: b = QQbar((1+I)*sqrt(2)/2) # optional - sage.symbolic - sage: (a - b).interval(CIF) # optional - sage.symbolic + sage: b = QQbar((1+I)*sqrt(2)/2) # needs sage.symbolic + sage: (a - b).interval(CIF) # needs sage.symbolic 0.?e-19 + 0.?e-18*I - sage: (a - b).interval_exact(CIF) # optional - sage.symbolic + sage: (a - b).interval_exact(CIF) # needs sage.symbolic 0 """ if not isinstance(field, sage.rings.abc.ComplexIntervalField): @@ -5274,7 +5325,7 @@ def multiplicative_order(self): EXAMPLES:: - sage: QQbar(-sqrt(3)/2 - I/2).multiplicative_order() # optional - sage.symbolic + sage: QQbar(-sqrt(3)/2 - I/2).multiplicative_order() # needs sage.symbolic 12 sage: QQbar(1).multiplicative_order() 1 @@ -5300,11 +5351,11 @@ def rational_argument(self): EXAMPLES:: - sage: QQbar((1+I)*(sqrt(2)+sqrt(5))).rational_argument() # optional - sage.symbolic + sage: QQbar((1+I)*(sqrt(2)+sqrt(5))).rational_argument() # needs sage.symbolic 1/8 - sage: QQbar(-1 + I*sqrt(3)).rational_argument() # optional - sage.symbolic + sage: QQbar(-1 + I*sqrt(3)).rational_argument() # needs sage.symbolic 1/3 - sage: QQbar(-1 - I*sqrt(3)).rational_argument() # optional - sage.symbolic + sage: QQbar(-1 - I*sqrt(3)).rational_argument() # needs sage.symbolic -1/3 sage: QQbar(3+4*I).rational_argument() is None True @@ -5334,9 +5385,9 @@ def _pow_(self, other): EXAMPLES:: - sage: QQbar(1) ^ QQbar(sqrt(2)) # optional - sage.symbolic + sage: QQbar(1) ^ QQbar(sqrt(2)) # needs sage.symbolic 1 - sage: 1 ^ QQbar(sqrt(2)) # optional - sage.symbolic + sage: 1 ^ QQbar(sqrt(2)) # needs sage.symbolic 1 sage: QQbar(2) ^ QQbar(2) Traceback (most recent call last): @@ -5371,8 +5422,9 @@ def __init__(self, x): sometimes a very small (e.g., 1e-17) complex part appears in a complex interval used to create an AlgebraicReal.:: - sage: a = QQbar((-1)^(1/4)); b = AA(a^3-a); t = b.as_number_field_element() - sage: b*1 + sage: a = QQbar((-1)^(1/4)); b = AA(a^3-a) # needs sage.symbolic + sage: t = b.as_number_field_element() # needs sage.symbolic + sage: b*1 # needs sage.symbolic -1.414213562373095? """ AlgebraicNumber_base.__init__(self, AA, x) @@ -5386,6 +5438,7 @@ def _ensure_real(self): EXAMPLES:: + sage: # needs sage.symbolic sage: a = QQbar((-1)^(1/4)); b = AA(a^3-a); b._value -1.4142135623730950488? sage: b._value = a._value; b._value @@ -5406,8 +5459,8 @@ def _more_precision(self): EXAMPLES:: - sage: a = QQbar(sqrt(2)) # optional - sage.symbolic - sage: a._more_precision() # optional - sage.symbolic + sage: a = QQbar(sqrt(2)) # needs sage.symbolic + sage: a._more_precision() # needs sage.symbolic TESTS: @@ -5432,8 +5485,8 @@ def __reduce__(self): EXAMPLES:: - sage: t = AA(sqrt(2)) # optional - sage.symbolic - sage: loads(dumps(t)) == t # optional - sage.symbolic + sage: t = AA(sqrt(2)) # needs sage.symbolic + sage: loads(dumps(t)) == t # needs sage.symbolic True """ return (AlgebraicReal, (self._descr, )) @@ -5453,32 +5506,33 @@ def _richcmp_(self, other, op): TESTS:: - sage: AA(golden_ratio) < AA(sqrt(5)) # optional - sage.symbolic + sage: AA(golden_ratio) < AA(sqrt(5)) # needs sage.symbolic True - sage: AA(golden_ratio) == AA((sqrt(5)+1)/2) # optional - sage.symbolic + sage: AA(golden_ratio) == AA((sqrt(5)+1)/2) # needs sage.symbolic True sage: AA(7) >= AA(50/7) False Check for trivial equality with identical elements:: - sage: x1 = AA(2^(1/50)) # optional - sage.symbolic - sage: x2 = AA(2^(1/50)) # optional - sage.symbolic - sage: y = x1 - x2 # optional - sage.symbolic - sage: y == y # optional - sage.symbolic + sage: # needs sage.symbolic + sage: x1 = AA(2^(1/50)) + sage: x2 = AA(2^(1/50)) + sage: y = x1 - x2 + sage: y == y True - sage: y >= y # optional - sage.symbolic + sage: y >= y True - sage: y < y # optional - sage.symbolic + sage: y < y False - sage: z = x1 - x2 # optional - sage.symbolic - sage: z == 0 # optional - sage.symbolic + sage: z = x1 - x2 # needs sage.symbolic + sage: z == 0 # needs sage.symbolic True - sage: a = x1 - x2 # optional - sage.symbolic - sage: b = x1 - x2 # optional - sage.symbolic - sage: a == b # optional - sage.symbolic + sage: a = x1 - x2 # needs sage.symbolic + sage: b = x1 - x2 # needs sage.symbolic + sage: a == b # needs sage.symbolic True """ if self is other: @@ -5552,11 +5606,11 @@ def _integer_(self, Z=None): 42 sage: AA(42)._integer_().parent() Integer Ring - sage: AA(golden_ratio)._integer_() + sage: AA(golden_ratio)._integer_() # needs sage.symbolic Traceback (most recent call last): ... ValueError: Cannot coerce non-integral Algebraic Real 1.618033988749895? to Integer - sage: (AA(golden_ratio)^10 + AA(1-golden_ratio)^10)._integer_() + sage: (AA(golden_ratio)^10 + AA(1-golden_ratio)^10)._integer_() # needs sage.symbolic 123 sage: AA(-22/7)._integer_() Traceback (most recent call last): @@ -5614,9 +5668,9 @@ def floor(self): EXAMPLES:: - sage: AA(sqrt(2)).floor() # optional - sage.symbolic + sage: AA(sqrt(2)).floor() # needs sage.symbolic 1 - sage: AA(-sqrt(2)).floor() # optional - sage.symbolic + sage: AA(-sqrt(2)).floor() # needs sage.symbolic -2 sage: AA(42).floor() 42 @@ -5625,8 +5679,8 @@ def floor(self): Check that :trac:`15501` is fixed:: - sage: a = QQbar((-1)^(1/4)).real() # optional - sage.symbolic - sage: (floor(a-a) + a).parent() # optional - sage.symbolic + sage: a = QQbar((-1)^(1/4)).real() # needs sage.symbolic + sage: (floor(a-a) + a).parent() # needs sage.symbolic Algebraic Real Field """ return self._floor_ceil(lambda x: x.floor()) @@ -5637,9 +5691,9 @@ def ceil(self): EXAMPLES:: - sage: AA(sqrt(2)).ceil() # optional - sage.symbolic + sage: AA(sqrt(2)).ceil() # needs sage.symbolic 2 - sage: AA(-sqrt(2)).ceil() # optional - sage.symbolic + sage: AA(-sqrt(2)).ceil() # needs sage.symbolic -1 sage: AA(42).ceil() 42 @@ -5652,7 +5706,7 @@ def round(self): EXAMPLES:: - sage: AA(sqrt(2)).round() # optional - sage.symbolic + sage: AA(sqrt(2)).round() # needs sage.symbolic 1 sage: AA(1/2).round() 1 @@ -5667,9 +5721,9 @@ def trunc(self): EXAMPLES:: - sage: AA(sqrt(2)).trunc() # optional - sage.symbolic + sage: AA(sqrt(2)).trunc() # needs sage.symbolic 1 - sage: AA(-sqrt(2)).trunc() # optional - sage.symbolic + sage: AA(-sqrt(2)).trunc() # needs sage.symbolic -1 sage: AA(1).trunc() 1 @@ -5688,13 +5742,13 @@ def _rational_(self): Rational Field sage: AA(-22/7)._rational_() -22/7 - sage: AA(sqrt(7))._rational_() # optional - sage.symbolic + sage: AA(sqrt(7))._rational_() # needs sage.symbolic Traceback (most recent call last): ... ValueError: Cannot coerce irrational Algebraic Real 2.645751311064591? to Rational - sage: v = AA(1/2 + sqrt(2))^3 - AA(11/4*sqrt(2)); v # optional - sage.symbolic + sage: v = AA(1/2 + sqrt(2))^3 - AA(11/4*sqrt(2)); v # needs sage.symbolic 3.125000000000000? - sage: v._rational_() + sage: v._rational_() # needs sage.symbolic 25/8 """ self.exactify() @@ -5711,10 +5765,10 @@ def real(self): EXAMPLES:: - sage: a = AA(sqrt(2) + sqrt(3)) # optional - sage.symbolic - sage: a.real() # optional - sage.symbolic + sage: a = AA(sqrt(2) + sqrt(3)) # needs sage.symbolic + sage: a.real() # needs sage.symbolic 3.146264369941973? - sage: a.real() is a # optional - sage.symbolic + sage: a.real() is a # needs sage.symbolic True """ return self @@ -5727,10 +5781,10 @@ def imag(self): EXAMPLES:: - sage: a = AA(sqrt(2) + sqrt(3)) # optional - sage.symbolic - sage: a.imag() # optional - sage.symbolic + sage: a = AA(sqrt(2) + sqrt(3)) # needs sage.symbolic + sage: a.imag() # needs sage.symbolic 0 - sage: parent(a.imag()) # optional - sage.symbolic + sage: parent(a.imag()) # needs sage.symbolic Algebraic Real Field """ return AA_0 @@ -5741,10 +5795,10 @@ def conjugate(self): EXAMPLES:: - sage: a = AA(sqrt(2) + sqrt(3)) # optional - sage.symbolic - sage: a.conjugate() # optional - sage.symbolic + sage: a = AA(sqrt(2) + sqrt(3)) # needs sage.symbolic + sage: a.conjugate() # needs sage.symbolic 3.146264369941973? - sage: a.conjugate() is a # optional - sage.symbolic + sage: a.conjugate() is a # needs sage.symbolic True """ return self @@ -5817,9 +5871,9 @@ def sign(self): sage: (a*b - b*a).sign() 0 - sage: a = AA(sqrt(1/2)) # optional - sage.symbolic - sage: b = AA(-sqrt(1/2)) # optional - sage.symbolic - sage: (a + b).sign() # optional - sage.symbolic + sage: a = AA(sqrt(1/2)) # needs sage.symbolic + sage: b = AA(-sqrt(1/2)) # needs sage.symbolic + sage: (a + b).sign() # needs sage.symbolic 0 TESTS: @@ -5828,17 +5882,18 @@ def sign(self): following example will take a long time (more than 5 seconds) when calling ``y.exactify()``:: - sage: x1 = AA(2^(1/50)) # optional - sage.symbolic - sage: x2 = AA(2^(1/50)) # optional - sage.symbolic - sage: y = x1 - x2 # optional - sage.symbolic - sage: y.sign() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: x1 = AA(2^(1/50)) + sage: x2 = AA(2^(1/50)) + sage: y = x1 - x2 + sage: y.sign() 0 Simplify to rationals for binary operations when computing the sign:: - sage: a = AA(2^(1/60)) # optional - sage.symbolic - sage: b = a - (a + 1) # optional - sage.symbolic - sage: (b + 1).sign() # optional - sage.symbolic + sage: a = AA(2^(1/60)) # needs sage.symbolic + sage: b = a - (a + 1) # needs sage.symbolic + sage: (b + 1).sign() # needs sage.symbolic 0 """ if not self._value.contains_zero(): @@ -5934,8 +5989,8 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: t = AA(sqrt(7)) # optional - sage.symbolic - sage: t._interval_fast(100) # optional - sage.symbolic + sage: t = AA(sqrt(7)) # needs sage.symbolic + sage: t._interval_fast(100) # needs sage.symbolic 2.64575131106459059050161575364? """ return self.interval_fast(RealIntervalField(prec)) @@ -6071,9 +6126,9 @@ def __float__(self): EXAMPLES:: - sage: AA(golden_ratio).__float__() + sage: AA(golden_ratio).__float__() # needs sage.symbolic 1.618033988749895 - sage: float(AA(sqrt(11))) + sage: float(AA(sqrt(11))) # needs sage.symbolic 3.3166247903554 """ return float(RR(self)) @@ -6090,9 +6145,9 @@ def _complex_mpfr_field_(self, field): EXAMPLES:: - sage: AA(golden_ratio)._complex_mpfr_field_(ComplexIntervalField(100)) + sage: AA(golden_ratio)._complex_mpfr_field_(ComplexIntervalField(100)) # needs sage.symbolic 1.618033988749894848204586834365? - sage: AA(golden_ratio)._complex_mpfr_field_(ComplexField(100)) + sage: AA(golden_ratio)._complex_mpfr_field_(ComplexField(100)) # needs sage.symbolic 1.6180339887498948482045868344 """ if isinstance(field, sage.rings.abc.ComplexIntervalField): @@ -6660,9 +6715,9 @@ def is_AlgebraicReal(x): EXAMPLES:: sage: from sage.rings.qqbar import is_AlgebraicReal - sage: is_AlgebraicReal(AA(sqrt(2))) + sage: is_AlgebraicReal(AA(sqrt(2))) # needs sage.symbolic True - sage: is_AlgebraicReal(QQbar(sqrt(2))) + sage: is_AlgebraicReal(QQbar(sqrt(2))) # needs sage.symbolic False sage: is_AlgebraicReal("spam") False @@ -6677,9 +6732,9 @@ def is_AlgebraicNumber(x): EXAMPLES:: sage: from sage.rings.qqbar import is_AlgebraicNumber - sage: is_AlgebraicNumber(AA(sqrt(2))) + sage: is_AlgebraicNumber(AA(sqrt(2))) # needs sage.symbolic False - sage: is_AlgebraicNumber(QQbar(sqrt(2))) + sage: is_AlgebraicNumber(QQbar(sqrt(2))) # needs sage.symbolic True sage: is_AlgebraicNumber("spam") False @@ -7085,13 +7140,14 @@ def conjugate(self, n): EXAMPLES:: - sage: a = (x^2 + 23).roots(ring=QQbar, multiplicities=False)[0] # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = (x^2 + 23).roots(ring=QQbar, multiplicities=False)[0] + sage: b = a._descr + sage: type(b) - sage: c = b.conjugate(a); c # optional - sage.symbolic + sage: c = b.conjugate(a); c - sage: c.exactify() # optional - sage.symbolic + sage: c.exactify() -2*a + 1 where a^2 - a + 6 = 0 and a in 0.50000000000000000? - 2.397915761656360?*I """ if not self._complex: @@ -7486,10 +7542,10 @@ def exactify(self): Verify that :trac:`12727` is fixed:: - sage: m = sqrt(sin(pi/5)); a = QQbar(m); b = AA(m) # optional - sage.symbolic - sage: a.minpoly() # optional - sage.symbolic + sage: m = sqrt(sin(pi/5)); a = QQbar(m); b = AA(m) # needs sage.symbolic + sage: a.minpoly() # needs sage.symbolic x^8 - 5/4*x^4 + 5/16 - sage: b.minpoly() # optional - sage.symbolic + sage: b.minpoly() # needs sage.symbolic x^8 - 5/4*x^4 + 5/16 """ gen = self._poly.generator() @@ -7751,16 +7807,17 @@ def is_complex(self): EXAMPLES:: - sage: rt2 = QQbar(sqrt(2)) # optional - sage.symbolic - sage: rtm3 = QQbar(sqrt(-3)) # optional - sage.symbolic - sage: x = rtm3 + rt2 - rtm3 # optional - sage.symbolic - sage: x.exactify() # optional - sage.symbolic - sage: y = x._descr # optional - sage.symbolic - sage: type(y) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: rt2 = QQbar(sqrt(2)) + sage: rtm3 = QQbar(sqrt(-3)) + sage: x = rtm3 + rt2 - rtm3 + sage: x.exactify() + sage: y = x._descr + sage: type(y) - sage: y.is_complex() # optional - sage.symbolic + sage: y.is_complex() True - sage: x.imag() == 0 # optional - sage.symbolic + sage: x.imag() == 0 True """ return not self._exactly_real @@ -7776,19 +7833,20 @@ def is_simple(self): EXAMPLES:: - sage: rt2 = AA(sqrt(2)) # optional - sage.symbolic - sage: rt3 = AA(sqrt(3)) # optional - sage.symbolic - sage: rt2b = rt3 + rt2 - rt3 # optional - sage.symbolic - sage: rt2.exactify() # optional - sage.symbolic - sage: rt2._descr # optional - sage.symbolic + sage: # needs sage.symbolic + sage: rt2 = AA(sqrt(2)) + sage: rt3 = AA(sqrt(3)) + sage: rt2b = rt3 + rt2 - rt3 + sage: rt2.exactify() + sage: rt2._descr a where a^2 - 2 = 0 and a in 1.414213562373095? - sage: rt2._descr.is_simple() # optional - sage.symbolic + sage: rt2._descr.is_simple() True - sage: rt2b.exactify() # optional - sage.symbolic - sage: rt2b._descr # optional - sage.symbolic + sage: rt2b.exactify() # needs sage.symbolic + sage: rt2b._descr # needs sage.symbolic a^3 - 3*a where a^4 - 4*a^2 + 1 = 0 and a in -0.5176380902050415? - sage: rt2b._descr.is_simple() # optional - sage.symbolic + sage: rt2b._descr.is_simple() # needs sage.symbolic False """ try: @@ -7871,13 +7929,14 @@ def simplify(self, n): EXAMPLES:: - sage: rt2 = AA(sqrt(2)) # optional - sage.symbolic - sage: rt3 = AA(sqrt(3)) # optional - sage.symbolic - sage: rt2b = rt3 + rt2 - rt3 # optional - sage.symbolic - sage: rt2b.exactify() # optional - sage.symbolic - sage: rt2b._descr # optional - sage.symbolic + sage: # needs sage.symbolic + sage: rt2 = AA(sqrt(2)) + sage: rt3 = AA(sqrt(3)) + sage: rt2b = rt3 + rt2 - rt3 + sage: rt2b.exactify() + sage: rt2b._descr a^3 - 3*a where a^4 - 4*a^2 + 1 = 0 and a in -0.5176380902050415? - sage: rt2b._descr.simplify(rt2b) # optional - sage.symbolic + sage: rt2b._descr.simplify(rt2b) a where a^2 - 2 = 0 and a in 1.414213562373095? """ @@ -7909,21 +7968,22 @@ def neg(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) # optional - sage.symbolic - sage: a.exactify() # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) + sage: a.exactify() + sage: b = a._descr + sage: type(b) - sage: c = b.neg(None); c # random (not uniquely represented) # optional - sage.symbolic + sage: c = b.neg(None); c # random (not uniquely represented) -1/3*a^3 + 1/3*a^2 - a - 1 where a^4 - 2*a^3 + a^2 + 6*a + 3 = 0 and a in 1.724744871391589? + 1.573132184970987?*I - sage: (c.generator() == b.generator() # optional - sage.symbolic + sage: (c.generator() == b.generator() ....: and c.field_element_value() + b.field_element_value() == 0) True The parameter is ignored:: - sage: (b.neg("random").generator() == c.generator() # optional - sage.symbolic + sage: (b.neg("random").generator() == c.generator() # needs sage.symbolic ....: and b.neg("random").field_element_value() == c.field_element_value()) True """ @@ -7935,21 +7995,22 @@ def invert(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) # optional - sage.symbolic - sage: a.exactify() # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) + sage: a.exactify() + sage: b = a._descr + sage: type(b) - sage: c = b.invert(None); c # random (not uniquely represented) # optional - sage.symbolic + sage: c = b.invert(None); c # random (not uniquely represented) -7/3*a^3 + 19/3*a^2 - 7*a - 9 where a^4 - 2*a^3 + a^2 + 6*a + 3 = 0 and a in 1.724744871391589? + 1.573132184970987?*I - sage: (c.generator() == b.generator() # optional - sage.symbolic + sage: (c.generator() == b.generator() ....: and c.field_element_value() * b.field_element_value() == 1) True The parameter is ignored:: - sage: (b.invert("random").generator() == c.generator() # optional - sage.symbolic + sage: (b.invert("random").generator() == c.generator() # needs sage.symbolic ....: and b.invert("random").field_element_value() == c.field_element_value()) True """ @@ -7961,12 +8022,13 @@ def conjugate(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) # optional - sage.symbolic - sage: a.exactify() # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) + sage: a.exactify() + sage: b = a._descr + sage: type(b) - sage: c = b.conjugate(None); c # random (not uniquely represented) # optional - sage.symbolic + sage: c = b.conjugate(None); c # random (not uniquely represented) 1/3*a^3 - 1/3*a^2 + a + 1 where a^4 - 2*a^3 + a^2 + 6*a + 3 = 0 and a in 1.724744871391589? - 1.573132184970987?*I @@ -7974,14 +8036,14 @@ def conjugate(self, n): same abstract field element but conjugating the complex embedding of the field:: - sage: c.generator() == b.generator().conjugate() # optional - sage.symbolic + sage: c.generator() == b.generator().conjugate() # needs sage.symbolic True - sage: c.field_element_value() == b.field_element_value() # optional - sage.symbolic + sage: c.field_element_value() == b.field_element_value() # needs sage.symbolic True The parameter is ignored:: - sage: (b.conjugate("random").generator() == c.generator() # optional - sage.symbolic + sage: (b.conjugate("random").generator() == c.generator() # needs sage.symbolic ....: and b.conjugate("random").field_element_value() == c.field_element_value()) True @@ -8000,12 +8062,13 @@ def norm(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) # optional - sage.symbolic - sage: a.exactify() # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) + sage: a.exactify() + sage: b = a._descr + sage: type(b) - sage: b.norm(a) # optional - sage.symbolic + sage: b.norm(a) """ if self._exactly_real: @@ -8021,12 +8084,13 @@ def abs(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) # optional - sage.symbolic - sage: a.exactify() # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) + sage: a.exactify() + sage: b = a._descr + sage: type(b) - sage: b.abs(a) # optional - sage.symbolic + sage: b.abs(a) Root 3.146264369941972342? of x^2 - 9.89897948556636? """ return AlgebraicReal(self.norm(n)).sqrt()._descr @@ -8038,12 +8102,12 @@ def rational_argument(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(3)) # optional - sage.symbolic - sage: a.exactify() # optional - sage.symbolic - sage: b = a._descr # optional - sage.symbolic - sage: type(b) # optional - sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(3)) # needs sage.symbolic + sage: a.exactify() # needs sage.symbolic + sage: b = a._descr # needs sage.symbolic + sage: type(b) # needs sage.symbolic - sage: b.rational_argument(a) is None # optional - sage.symbolic + sage: b.rational_argument(a) is None # needs sage.symbolic True sage: x = polygen(QQ) sage: a = (x^4 + 1).roots(QQbar, multiplicities=False)[0] @@ -8094,7 +8158,7 @@ def __init__(self, arg, op): EXAMPLES:: - sage: t = ~QQbar(sqrt(2)); type(t._descr) # indirect doctest # optional - sage.symbolic + sage: t = ~QQbar(sqrt(2)); type(t._descr) # indirect doctest # needs sage.symbolic """ self._arg = arg @@ -8107,9 +8171,9 @@ def __reduce__(self): EXAMPLES:: - sage: t = ~QQbar(sqrt(2)); type(t._descr) # optional - sage.symbolic + sage: t = ~QQbar(sqrt(2)); type(t._descr) # needs sage.symbolic - sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) # optional - sage.symbolic + sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) # needs sage.symbolic True """ return (ANUnaryExpr, (self._arg, self._op)) @@ -8208,13 +8272,14 @@ def is_complex(self): EXAMPLES:: - sage: t = AA(sqrt(2)) # optional - sage.symbolic - sage: s = (-t)._descr # optional - sage.symbolic - sage: s # optional - sage.symbolic + sage: # needs sage.symbolic + sage: t = AA(sqrt(2)) + sage: s = (-t)._descr + sage: s - sage: s.is_complex() # optional - sage.symbolic + sage: s.is_complex() False - sage: QQbar(-sqrt(2))._descr.is_complex() # optional - sage.symbolic + sage: QQbar(-sqrt(2))._descr.is_complex() True """ return self._complex @@ -8225,11 +8290,12 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: t = AA(sqrt(2)) # optional - sage.symbolic - sage: s = (-t)._descr # optional - sage.symbolic - sage: s # optional - sage.symbolic + sage: # needs sage.symbolic + sage: t = AA(sqrt(2)) + sage: s = (-t)._descr + sage: s - sage: s._interval_fast(150) # optional - sage.symbolic + sage: s._interval_fast(150) -1.414213562373095048801688724209698078569671876? """ op = self._op @@ -8282,10 +8348,10 @@ def exactify(self): EXAMPLES:: - sage: v = (-QQbar(sqrt(2)))._descr # optional - sage.symbolic - sage: type(v) # optional - sage.symbolic + sage: v = (-QQbar(sqrt(2)))._descr # needs sage.symbolic + sage: type(v) # needs sage.symbolic - sage: v.exactify() # optional - sage.symbolic + sage: v.exactify() # needs sage.symbolic -a where a^2 - 2 = 0 and a in 1.414213562373095? """ op = self._op @@ -8349,7 +8415,7 @@ def __init__(self, left, right, op): EXAMPLES:: - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # indirect doctest # optional - sage.symbolic + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # indirect doctest # needs sage.symbolic """ self._left = left @@ -8363,9 +8429,9 @@ def __reduce__(self): EXAMPLES:: - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # optional - sage.symbolic + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # needs sage.symbolic - sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) # optional - sage.symbolic + sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) # needs sage.symbolic True """ return (ANBinaryExpr, (self._left, self._right, self._op)) @@ -8413,10 +8479,10 @@ def handle_sage_input(self, sib, coerce, is_qqbar): True sage: sage_input(n) 1 + AA(3) - sage: rt3 = QQbar(sqrt(3)) # optional - sage.symbolic - sage: one = rt3/rt3 # optional - sage.symbolic + sage: rt3 = QQbar(sqrt(3)) # needs sage.symbolic + sage: one = rt3/rt3 # needs sage.symbolic sage: n = sqrt(AA(2)) + one - sage: one == 1 # optional - sage.symbolic + sage: one == 1 # needs sage.symbolic True sage: sage_input(n) R. = AA[] @@ -8487,8 +8553,8 @@ def is_complex(self): EXAMPLES:: - sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr # optional - sage.symbolic - sage: x.is_complex() # optional - sage.symbolic + sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr # needs sage.symbolic + sage: x.is_complex() # needs sage.symbolic True """ return self._complex @@ -8499,10 +8565,10 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr # optional - sage.symbolic - sage: y= x._interval_fast(64); y # optional - sage.symbolic + sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr # needs sage.symbolic + sage: y= x._interval_fast(64); y # needs sage.symbolic 0.632455532033675867? - sage: y.parent() # optional - sage.symbolic + sage: y.parent() # needs sage.symbolic Complex Interval Field with 64 bits of precision """ op = self._op @@ -8519,8 +8585,8 @@ def exactify(self): """ TESTS:: - sage: rt2c = QQbar.zeta(3) + AA(sqrt(2)) - QQbar.zeta(3) # optional - sage.symbolic - sage: rt2c.exactify() # optional - sage.symbolic + sage: rt2c = QQbar.zeta(3) + AA(sqrt(2)) - QQbar.zeta(3) # needs sage.symbolic + sage: rt2c.exactify() # needs sage.symbolic We check to make sure that this method still works even. We do this by increasing the recursion level at each step and @@ -8605,25 +8671,27 @@ def an_binop_expr(a, b, op): EXAMPLES:: - sage: a = QQbar(sqrt(2)) + QQbar(sqrt(3)) # optional - sage.symbolic - sage: b = QQbar(sqrt(3)) + QQbar(sqrt(5)) # optional - sage.symbolic - sage: type(a._descr); type(b._descr) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(2)) + QQbar(sqrt(3)) + sage: b = QQbar(sqrt(3)) + QQbar(sqrt(5)) + sage: type(a._descr); type(b._descr) sage: from sage.rings.qqbar import an_binop_expr - sage: x = an_binop_expr(a, b, operator.add); x # optional - sage.symbolic + sage: x = an_binop_expr(a, b, operator.add); x - sage: x.exactify() # optional - sage.symbolic + sage: x.exactify() 6/7*a^7 - 2/7*a^6 - 71/7*a^5 + 26/7*a^4 + 125/7*a^3 - 72/7*a^2 - 43/7*a + 47/7 where a^8 - 12*a^6 + 23*a^4 - 12*a^2 + 1 = 0 and a in -0.3199179336182997? - sage: a = QQbar(sqrt(2)) + QQbar(sqrt(3)) # optional - sage.symbolic - sage: b = QQbar(sqrt(3)) + QQbar(sqrt(5)) # optional - sage.symbolic - sage: type(a._descr) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(2)) + QQbar(sqrt(3)) + sage: b = QQbar(sqrt(3)) + QQbar(sqrt(5)) + sage: type(a._descr) - sage: x = an_binop_expr(a, b, operator.mul); x # optional - sage.symbolic + sage: x = an_binop_expr(a, b, operator.mul); x - sage: x.exactify() # optional - sage.symbolic + sage: x.exactify() 2*a^7 - a^6 - 24*a^5 + 12*a^4 + 46*a^3 - 22*a^2 - 22*a + 9 where a^8 - 12*a^6 + 23*a^4 - 12*a^2 + 1 = 0 and a in -0.3199179336182997? """ @@ -8757,7 +8825,7 @@ def get_AA_golden_ratio(): EXAMPLES:: - sage: AA(golden_ratio) # indirect doctest # optional - sage.symbolic + sage: AA(golden_ratio) # indirect doctest # needs sage.symbolic 1.618033988749895? """ global AA_golden_ratio diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index f90dcc6c9aa..b00b253b40f 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -38,8 +38,8 @@ ....: def reduce(self,x): ....: R = self.ring() ....: return add([c*R(m) for m,c in x if len(m) = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules - sage: I3 = PowerIdeal(F,3); I3 # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(QQ, 3) # needs sage.combinat sage.modules + sage: I3 = PowerIdeal(F,3); I3 # needs sage.combinat sage.modules Twosided Ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) of @@ -49,33 +49,35 @@ finite dimensional quotients defined by multiplication matrices. We are bypassing it, so that we obtain the default quotient:: - sage: Q3. = F.quotient(I3) # optional - sage.combinat sage.modules - sage: Q3 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: Q3. = F.quotient(I3) + sage: Q3 Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) - sage: (a+b+2)^4 # optional - sage.combinat sage.modules + sage: (a+b+2)^4 16 + 32*a + 32*b + 24*a^2 + 24*a*b + 24*b*a + 24*b^2 - sage: Q3.is_commutative() # optional - sage.combinat sage.modules + sage: Q3.is_commutative() False Even though `Q_3` is not commutative, there is commutativity for products of degree three:: - sage: a*(b*c)-(b*c)*a==F.zero() # optional - sage.combinat sage.modules + sage: a*(b*c)-(b*c)*a==F.zero() # needs sage.combinat sage.modules True If we quotient out all terms of degree two then of course the resulting quotient ring is commutative:: - sage: I2 = PowerIdeal(F,2); I2 # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: I2 = PowerIdeal(F,2); I2 Twosided Ideal (x^2, x*y, x*z, y*x, y^2, y*z, z*x, z*y, z^2) of Free Algebra on 3 generators (x, y, z) over Rational Field - sage: Q2. = F.quotient(I2) # optional - sage.combinat sage.modules - sage: Q2.is_commutative() # optional - sage.combinat sage.modules + sage: Q2. = F.quotient(I2) + sage: Q2.is_commutative() True - sage: (a+b+2)^4 # optional - sage.combinat sage.modules + sage: (a+b+2)^4 16 + 32*a + 32*b Since :trac:`7797`, there is an implementation of free algebras @@ -83,20 +85,21 @@ letterplace wrapper allows to provide the above toy example more easily:: + sage: # needs sage.combinat sage.libs.singular sage.modules sage: from itertools import product - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) # optional - sage.combinat sage.libs.singular sage.modules - sage: Q3 # optional - sage.combinat sage.libs.singular sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') + sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) + sage: Q3 Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) - sage: Q3.0*Q3.1 - Q3.1*Q3.0 # optional - sage.combinat sage.libs.singular sage.modules + sage: Q3.0*Q3.1 - Q3.1*Q3.0 xbar*ybar - ybar*xbar - sage: Q3.0*(Q3.1*Q3.2) - (Q3.1*Q3.2)*Q3.0 # optional - sage.combinat sage.libs.singular sage.modules + sage: Q3.0*(Q3.1*Q3.2) - (Q3.1*Q3.2)*Q3.0 0 - sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) # optional - sage.combinat sage.libs.singular sage.modules - sage: Q2.is_commutative() # optional - sage.combinat sage.libs.singular sage.modules + sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) + sage: Q2.is_commutative() True """ @@ -180,14 +183,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)) # optional - sage.libs.pari - sage: R # optional - sage.libs.pari + sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) # needs sage.libs.pari + sage: R # needs 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 + sage: R.gens(); R.gen() # needs sage.libs.pari (xx,) xx - sage: for n in range(4): xx^n # optional - sage.libs.pari + sage: for n in range(4): xx^n # needs sage.libs.pari 1 xx -1 @@ -196,13 +199,13 @@ def QuotientRing(R, I, names=None, **kwds): :: sage: P. = QQ[] - sage: S = QuotientRing(P, P.ideal(x^2 - 2)) # optional - sage.libs.pari - sage: S # optional - sage.libs.pari + sage: S = QuotientRing(P, P.ideal(x^2 - 2)) # needs sage.libs.pari + sage: S # needs sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 2 - sage: xbar = S.gen(); S.gen() # optional - sage.libs.pari + sage: xbar = S.gen(); S.gen() # needs sage.libs.pari xbar - sage: for n in range(3): xbar^n # optional - sage.libs.pari + sage: for n in range(3): xbar^n # needs sage.libs.pari 1 xbar 2 @@ -210,7 +213,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 # optional - sage.libs.pari + sage: R = QuotientRing(P, x^2 + 1); R # needs sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 @@ -220,16 +223,16 @@ def QuotientRing(R, I, names=None, **kwds): `\QQ[x,y]`:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.pari - sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.pari - sage: T # optional - sage.libs.pari + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.pari + sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.pari + sage: T # needs sage.libs.pari Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.pari + sage: R.gens(); S.gens(); T.gens() # needs sage.libs.pari (x, y) (a, b) (0, d) - sage: for n in range(4): d^n # optional - sage.libs.pari + sage: for n in range(4): d^n # needs sage.libs.pari 1 d -1 @@ -248,23 +251,24 @@ 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') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q. = F.quo(I); Q # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + 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 # optional - sage.combinat sage.libs.singular sage.modules + sage: a*b -b*c - sage: a^3 # optional - sage.combinat sage.libs.singular sage.modules + sage: a^3 -b*c*a - b*c*b - b*c*c - sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.libs.singular sage.modules - sage: R. = Q.quo(J); R # optional - sage.combinat sage.libs.singular sage.modules + 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 # optional - sage.combinat sage.libs.singular sage.modules + sage: i^3 -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat sage.libs.singular sage.modules + sage: j^3 -j*k*i - j*k*j - j*k*k Check that :trac:`5978` is fixed by if we quotient by the zero ideal `(0)` @@ -350,12 +354,13 @@ def is_QuotientRing(x): :: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules - sage: is_QuotientRing(Q) # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F + sage: Q = F.quo(I) + sage: is_QuotientRing(Q) True - sage: is_QuotientRing(F) # optional - sage.combinat sage.libs.singular sage.modules + sage: is_QuotientRing(F) False """ return isinstance(x, QuotientRing_nc) @@ -378,27 +383,29 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): Here is a quotient of a free algebra by a twosided homogeneous ideal:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2]*F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q. = F.quo(I); Q # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + 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 # optional - sage.combinat sage.libs.singular sage.modules + sage: a*b -b*c - sage: a^3 # optional - sage.combinat sage.libs.singular sage.modules + sage: a^3 -b*c*a - b*c*b - b*c*c A quotient of a quotient is just the quotient of the original top ring by the sum of two ideals:: - sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.libs.singular sage.modules - sage: R. = Q.quo(J); R # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + 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 # optional - sage.combinat sage.libs.singular sage.modules + sage: i^3 -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat sage.libs.singular sage.modules + sage: j^3 -j*k*i - j*k*j - j*k*k For rings that *do* inherit from :class:`~sage.rings.ring.CommutativeRing`, @@ -416,10 +423,10 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular - sage: a^2 + b^2 == 0 # optional - sage.libs.singular + sage: S. = R.quo(x^2 + y^2) # needs sage.libs.singular + sage: a^2 + b^2 == 0 # needs sage.libs.singular True - sage: S(0) == a^2 + b^2 # optional - sage.libs.singular + sage: S(0) == a^2 + b^2 # needs sage.libs.singular True Again, a quotient of a quotient is just the quotient of the original top @@ -428,12 +435,12 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(1 + y^2) # optional - sage.libs.singular - sage: T. = S.quo(a) # optional - sage.libs.singular - sage: T # optional - sage.libs.singular + sage: S. = R.quo(1 + y^2) # needs sage.libs.singular + sage: T. = S.quo(a) # needs sage.libs.singular + sage: T # needs sage.libs.singular Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: T.gens() # optional - sage.libs.singular + sage: T.gens() # needs sage.libs.singular (0, d) """ Element = quotient_ring_element.QuotientRingElement @@ -452,15 +459,16 @@ def __init__(self, R, I, names, category=None): EXAMPLES:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q. = F.quo(I); Q # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + 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 # optional - sage.combinat sage.libs.singular sage.modules + sage: a*b -b*c - sage: a^3 # optional - sage.combinat sage.libs.singular sage.modules + sage: a^3 -b*c*a - b*c*b - b*c*c """ @@ -507,10 +515,10 @@ def construction(self): sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: R.quotient_ring(I).construction() (QuotientFunctor, Univariate Polynomial Ring in x over Integer Ring) - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules - sage: Q.construction() # optional - sage.combinat sage.libs.singular sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # needs sage.combinat sage.libs.singular sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # needs sage.combinat sage.libs.singular sage.modules + sage: Q = F.quo(I) # needs sage.combinat sage.libs.singular sage.modules + sage: Q.construction() # needs sage.combinat sage.libs.singular sage.modules (QuotientFunctor, Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) @@ -519,8 +527,8 @@ def construction(self): sage: F, R = Integers(5).construction() sage: F(R) Ring of integers modulo 5 - sage: F, R = GF(5).construction() # optional - sage.rings.finite_rings - sage: F(R) # optional - sage.rings.finite_rings + sage: F, R = GF(5).construction() + sage: F(R) Finite Field of size 5 """ from sage.categories.pushout import QuotientFunctor @@ -592,19 +600,20 @@ def is_commutative(self): The non-commutative case is more interesting:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules - sage: Q.is_commutative() # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F + sage: Q = F.quo(I) + sage: Q.is_commutative() False - sage: Q.1*Q.2 == Q.2*Q.1 # optional - sage.combinat sage.libs.singular sage.modules + sage: Q.1*Q.2 == Q.2*Q.1 False In the next example, the generators apparently commute:: - sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: R = F.quo(J) # optional - sage.combinat sage.libs.singular sage.modules - sage: R.is_commutative() # optional - sage.combinat sage.libs.singular sage.modules + sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # needs sage.combinat sage.libs.singular sage.modules + sage: R = F.quo(J) # needs sage.combinat sage.libs.singular sage.modules + sage: R.is_commutative() # needs sage.combinat sage.libs.singular sage.modules True """ @@ -646,19 +655,19 @@ def cover(self): sage: R. = PolynomialRing(QQ) sage: Q = R.quo((x^2, y^2)) - sage: pi = Q.cover() # optional - sage.libs.singular - sage: pi(x^3 + y) # optional - sage.libs.singular + sage: pi = Q.cover() # needs sage.libs.singular + sage: pi(x^3 + y) # needs sage.libs.singular ybar - sage: l = pi.lift(x + y^3) # optional - sage.libs.singular - sage: l # optional - sage.libs.singular + sage: l = pi.lift(x + y^3) # needs sage.libs.singular + sage: l # needs sage.libs.singular x - sage: l = pi.lift(); l # optional - sage.libs.singular + sage: l = pi.lift(); l # needs 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) # optional - sage.libs.singular + sage: l(x + y^3) # needs sage.libs.singular x """ try: @@ -680,40 +689,41 @@ def lifting_map(self): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: pi = S.cover(); pi # optional - sage.libs.singular + sage: pi = S.cover(); pi # needs 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 # optional - sage.libs.singular + sage: L = S.lifting_map(); L # needs 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) # optional - sage.libs.singular + sage: L(S.0) # needs sage.libs.singular x - sage: L(S.1) # optional - sage.libs.singular + sage: L(S.1) # needs sage.libs.singular y Note that some reduction may be applied so that the lift of a reduction need not equal the original element:: - sage: z = pi(x^3 + 2*y^2); z # optional - sage.libs.singular + sage: z = pi(x^3 + 2*y^2); z # needs sage.libs.singular -xbar*ybar^2 + 2*ybar^2 - sage: L(z) # optional - sage.libs.singular + sage: L(z) # needs sage.libs.singular -x*y^2 + 2*y^2 - sage: L(z) == x^3 + 2*y^2 # optional - sage.libs.singular + sage: L(z) == x^3 + 2*y^2 # needs sage.libs.singular False Test that there also is a lift for rings that are no instances of :class:`~sage.rings.ring.Ring` (see :trac:`11068`):: - sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.modules sage.rings.finite_rings - sage: I = MS * [MS.0*MS.1, MS.2 + MS.3] * MS # optional - sage.modules sage.rings.finite_rings - sage: Q = MS.quo(I) # optional - sage.modules sage.rings.finite_rings - sage: Q.lift() # optional - sage.modules sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings + 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() Set-theoretic ring morphism: From: Quotient of Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 5 by the ideal @@ -755,13 +765,13 @@ def lift(self, x=None): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.lift() # optional - sage.libs.singular + sage: S.lift() # needs 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 # optional - sage.libs.singular + sage: S.lift(S.0) == x # needs sage.libs.singular True """ @@ -785,7 +795,7 @@ def retract(self,x): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.retract((x+y)^2) # optional - sage.libs.singular + sage: S.retract((x+y)^2) # needs sage.libs.singular 2*xbar*ybar """ @@ -826,11 +836,11 @@ def defining_ideal(self): ideals:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular - sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular - sage: S.defining_ideal() # optional - sage.libs.singular + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular + sage: S.defining_ideal() # needs sage.libs.singular Ideal (y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: T.defining_ideal() # optional - sage.libs.singular + sage: T.defining_ideal() # needs sage.libs.singular Ideal (x, y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field """ return self.__I @@ -844,14 +854,14 @@ def is_field(self, proof=True): TESTS:: sage: Q = QuotientRing(ZZ, 7*ZZ) - sage: Q.is_field() # optional - sage.libs.pari + sage: Q.is_field() True Requires the ``is_maximal`` method of the defining ideal to be implemented:: sage: R. = ZZ[] - sage: R.quotient_ring(R.ideal([2, 4 + x])).is_field() # optional - sage.libs.pari + sage: R.quotient_ring(R.ideal([2, 4 + x])).is_field() Traceback (most recent call last): ... NotImplementedError @@ -878,19 +888,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = QQ[] - sage: R.quo(x^2 - y).is_integral_domain() # optional - sage.singular + sage: R.quo(x^2 - y).is_integral_domain() # needs sage.singular True - sage: R.quo(x^2 - y^2).is_integral_domain() # optional - sage.singular + sage: R.quo(x^2 - y^2).is_integral_domain() # needs sage.singular False - sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # optional - sage.singular + sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # needs sage.singular False - sage: R. = ZZ[] # optional - sage.singular - sage: Q = R.quotient_ring([a, b]) # optional - sage.singular - sage: Q.is_integral_domain() # optional - sage.singular + sage: R. = ZZ[] + sage: Q = R.quotient_ring([a, b]) + sage: Q.is_integral_domain() Traceback (most recent call last): ... NotImplementedError - sage: Q.is_integral_domain(proof=False) # optional - sage.singular + sage: Q.is_integral_domain(proof=False) False """ if proof: @@ -912,8 +922,8 @@ def is_noetherian(self): True sage: P. = QQ[] - sage: R = QuotientRing(P, x^2 + 1) # optional - sage.libs.pari - sage: R.is_noetherian() # optional - sage.libs.pari + sage: R = QuotientRing(P, x^2 + 1) # needs sage.libs.pari + sage: R.is_noetherian() True If the cover ring of ``self`` is not Noetherian, we currently @@ -924,8 +934,8 @@ def is_noetherian(self): sage: R.is_noetherian() False sage: I = R.ideal([x[1]^2, x[2]]) - sage: S = R.quotient(I) # optional - sage.libs.pari - sage: S.is_noetherian() # optional - sage.libs.pari + sage: S = R.quotient(I) + sage: S.is_noetherian() Traceback (most recent call last): ... NotImplementedError @@ -951,8 +961,8 @@ def cover_ring(self): :: sage: P. = QQ[] - sage: Q = QuotientRing(P, x^2 + 1) # optional - sage.libs.pari - sage: Q.cover_ring() # optional - sage.libs.pari + sage: Q = QuotientRing(P, x^2 + 1) # needs sage.libs.pari + sage: Q.cover_ring() # needs sage.libs.pari Univariate Polynomial Ring in x over Rational Field """ return self.__R @@ -968,10 +978,10 @@ def ideal(self, *gens, **kwds): sage: R. = PolynomialRing(QQ) sage: S = R.quotient_ring(x^2 + y^2) - sage: S.ideal() # optional - sage.libs.pari + sage: S.ideal() # needs 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 + sage: S.ideal(x + y + 1) # needs 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) @@ -1010,9 +1020,9 @@ def _element_constructor_(self, x, coerce=True): sage: R. = PolynomialRing(QQ) sage: S = R.quotient_ring(x^2 + y^2) - sage: S(x) # indirect doctest # optional - sage.libs.singular + sage: S(x) # indirect doctest # needs sage.libs.singular xbar - sage: S(x^2 + y^2) # optional - sage.libs.singular + sage: S(x^2 + y^2) # needs sage.libs.singular 0 The rings that coerce into the quotient ring canonically, are: @@ -1025,14 +1035,14 @@ def _element_constructor_(self, x, coerce=True): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular - sage: S.coerce(0) # optional - sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) # needs sage.libs.singular + sage: S.coerce(0) # needs sage.libs.singular 0 - sage: S.coerce(2/3) # optional - sage.libs.singular + sage: S.coerce(2/3) # needs sage.libs.singular 2/3 - sage: S.coerce(a^2 - b) # optional - sage.libs.singular + sage: S.coerce(a^2 - b) # needs sage.libs.singular -b^2 - b - sage: S.coerce(GF(7)(3)) # optional - sage.rings.finite_rings sage.libs.singular + sage: S.coerce(GF(7)(3)) Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field of size 7 @@ -1040,7 +1050,7 @@ def _element_constructor_(self, x, coerce=True): TESTS:: - sage: S(x, coerce=False) # optional - sage.libs.singular + sage: S(x, coerce=False) # needs sage.libs.singular a """ if isinstance(x, quotient_ring_element.QuotientRingElement): @@ -1068,10 +1078,10 @@ def _coerce_map_from_(self, R): True sage: S.has_coerce_map_from(QQ) True - sage: T = S.quotient_ring(x^3 - y) # optional - sage.libs.singular - sage: S.has_coerce_map_from(T) # optional - sage.libs.singular + sage: T = S.quotient_ring(x^3 - y) # needs sage.libs.singular + sage: S.has_coerce_map_from(T) # needs sage.libs.singular False - sage: T.has_coerce_map_from(R) # optional - sage.libs.singular + sage: T.has_coerce_map_from(R) # needs sage.libs.singular True TESTS: @@ -1081,15 +1091,15 @@ def _coerce_map_from_(self, R): 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 # optional - sage.libs.singular + sage: I < J # needs sage.libs.singular True - 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 + sage: S = R.quotient(I) + sage: T = R.quotient(J) + sage: T.has_coerce_map_from(S) # needs sage.libs.singular True - sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) # optional - sage.libs.singular + sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) # needs sage.libs.singular True - sage: S.has_coerce_map_from(T) # optional - sage.libs.singular + sage: S.has_coerce_map_from(T) # needs sage.libs.singular False We also allow coercions with the cover rings:: @@ -1097,15 +1107,15 @@ def _coerce_map_from_(self, R): 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) # optional - sage.libs.singular - sage: Tp = Rp.quotient(Jp) # optional - sage.libs.singular - sage: R.has_coerce_map_from(Rp) # optional - sage.libs.singular + sage: Sp = Rp.quotient(Ip) + sage: Tp = Rp.quotient(Jp) + sage: R.has_coerce_map_from(Rp) True - sage: Sp.has_coerce_map_from(Sp) # optional - sage.libs.singular + sage: Sp.has_coerce_map_from(Sp) True - sage: T.has_coerce_map_from(Sp) # optional - sage.libs.singular + sage: T.has_coerce_map_from(Sp) # needs sage.libs.singular True - sage: Sp.has_coerce_map_from(T) # optional - sage.libs.singular + sage: Sp.has_coerce_map_from(T) # needs sage.libs.singular False """ C = self.cover_ring() @@ -1137,9 +1147,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) # optional - sage.libs.singular + sage: R.ideal(x^2 + y^2) == R.ideal(-x^2 - y^2) # needs sage.libs.singular True - sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) # optional - sage.libs.singular + sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) False """ if not isinstance(other, QuotientRing_nc): @@ -1169,16 +1179,16 @@ def ngens(self): :: 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: T # optional - sage.libs.singular + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular + sage: T # needs 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 + sage: R.gens(); S.gens(); T.gens() # needs sage.libs.singular (x, y) (a, b) (0, d) - sage: R.ngens(); S.ngens(); T.ngens() # optional - sage.libs.singular + sage: R.ngens(); S.ngens(); T.ngens() # needs sage.libs.singular 2 2 2 @@ -1198,18 +1208,18 @@ def gen(self, i=0): :: 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: T # optional - sage.libs.singular + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular + sage: T # needs 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 + sage: R.gen(0); R.gen(1) x y - sage: S.gen(0); S.gen(1) # optional - sage.libs.singular + sage: S.gen(0); S.gen(1) # needs sage.libs.singular a b - sage: T.gen(0); T.gen(1) # optional - sage.libs.singular + sage: T.gen(0); T.gen(1) # needs sage.libs.singular 0 d """ @@ -1236,7 +1246,7 @@ def _singular_(self, singular=None): sage: R. = PolynomialRing(QQ) sage: S = R.quotient_ring(x^2 + y^2) - sage: S._singular_() # optional - sage.libs.singular + sage: S._singular_() # needs sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 @@ -1270,10 +1280,10 @@ def _singular_init_(self, singular=None): sage: R. = PolynomialRing(QQ) 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: T = S._singular_init_() # needs sage.libs.singular + sage: parent(S) - sage: parent(T) # optional - sage.libs.singular + sage: parent(T) # needs sage.libs.singular Singular """ if singular is None: @@ -1293,9 +1303,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings - sage: magma(Q) # optional - magma # indirect doctest # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(GF(2)) + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) + sage: magma(Q) # optional - magma # needs sage.rings.finite_rings Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y @@ -1388,12 +1398,13 @@ def _macaulay2_init_(self, macaulay2=None): 2 2 2 (x*y - z , y - w ) - sage: R. = PolynomialRing(GF(101), 2) # optional - sage.rings.finite_rings - sage: I = R.ideal([x^2 + x, y^2 + y]) # optional - sage.rings.finite_rings - sage: Q = R.quotient_ring(I); Q # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + sage: Q._macaulay2_init_() # optional - macaulay2 ZZ ---[x...y] 101 @@ -1467,12 +1478,12 @@ def _contains_(self, other): :: sage: R. = QQ[] - sage: S. = R.quotient(T^3 - 1) # optional - sage.libs.pari - sage: 1 in S.ideal(t^2 - 1) # optional - sage.libs.pari + sage: S. = R.quotient(T^3 - 1) # needs sage.libs.pari + sage: 1 in S.ideal(t^2 - 1) # needs sage.libs.pari False - sage: 7 in S.ideal(t^2 + 1) # optional - sage.libs.pari + sage: 7 in S.ideal(t^2 + 1) # needs sage.libs.pari True - sage: 5-5*t in S.ideal(t^2 - 1) # optional - sage.libs.pari + sage: 5-5*t in S.ideal(t^2 - 1) # needs sage.libs.pari True """ R = self.ring() diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 8ef6d665a29..dc1fec51fad 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -61,23 +61,24 @@ class QuotientRingElement(RingElement): 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() # optional - sage.libs.singular + sage: S.gens() # needs sage.libs.singular (xbar, ybar) We name each of the generators. :: - sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular - sage: a # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) + sage: a a - sage: b # optional - sage.libs.singular + sage: b b - sage: a^2 + b^2 == 0 # optional - sage.libs.singular + sage: a^2 + b^2 == 0 True - sage: b.lift() # optional - sage.libs.singular + sage: b.lift() y - sage: (a^3 + b^2).lift() # optional - sage.libs.singular + sage: (a^3 + b^2).lift() -x*y^2 + y^2 """ def __init__(self, parent, rep, reduce=True): @@ -109,10 +110,10 @@ def _reduce_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a._reduce_() # optional - sage.libs.singular - sage: a._QuotientRingElement__rep # optional - sage.libs.singular + sage: a._reduce_() # needs sage.libs.singular + sage: a._QuotientRingElement__rep # needs sage.libs.singular x """ I = self.parent().defining_ideal() @@ -125,11 +126,11 @@ def lift(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a.lift() # optional - sage.libs.singular + sage: a.lift() # needs sage.libs.singular x - sage: (3/5*(a + a^2 + b^2)).lift() # optional - sage.libs.singular + sage: (3/5*(a + a^2 + b^2)).lift() # needs sage.libs.singular 3/5*x """ return self.__rep @@ -142,16 +143,16 @@ def __bool__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: bool(a) # indirect doctest # optional - sage.libs.singular + sage: bool(a) # indirect doctest # needs sage.libs.singular True - sage: bool(S(0)) # optional - sage.libs.singular + sage: bool(S(0)) # needs sage.libs.singular False TESTS:: - sage: bool(a - a) # optional - sage.libs.singular + sage: bool(a - a) # needs sage.libs.singular False """ return self.__rep not in self.parent().defining_ideal() @@ -162,18 +163,18 @@ def is_unit(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) # needs sage.libs.singular - sage: a*b # optional - sage.libs.singular + sage: a*b # needs sage.libs.singular 1 - sage: S(2).is_unit() # optional - sage.libs.singular + sage: S(2).is_unit() # needs sage.libs.singular True Check that :trac:`29469` is fixed:: - sage: a.is_unit() # optional - sage.libs.singular + sage: a.is_unit() # needs sage.libs.singular True - sage: (a+b).is_unit() # optional - sage.libs.singular + sage: (a+b).is_unit() # needs sage.libs.singular False """ if self.__rep.is_unit(): @@ -194,18 +195,19 @@ def _repr_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a-2*a*b # indirect doctest # optional - sage.libs.singular + sage: a-2*a*b # indirect doctest # needs 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) # 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 + sage: # needs sage.libs.singular + sage: S = SteenrodAlgebra(2) + sage: I = S * [S.0 + S.1] * S + sage: Q = S.quo(I) + sage: Q.0 Sq(1) """ @@ -235,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) # optional - sage.libs.singular - sage: latex(a) # optional - sage.libs.singular + sage: a = S.gen(0) # needs sage.libs.singular + sage: latex(a) a """ from sage.structure.parent_gens import localvars @@ -261,8 +263,8 @@ def __pari__(self): sage: R. = QQ[] 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 + sage: S. = R.quo(I) # needs sage.libs.singular + sage: pari(xb) # needs sage.libs.pari sage.libs.singular Traceback (most recent call last): ... ValueError: Pari does not support quotients by non-principal ideals @@ -270,10 +272,10 @@ def __pari__(self): 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) # optional - sage.libs.singular - sage: pari(xb)^4 # optional - sage.libs.pari sage.libs.singular + sage: S. = R.quo(I) # needs sage.libs.singular + sage: pari(xb)^4 # needs sage.libs.pari sage.libs.singular Mod(-y^3*x, x^3 + y^3) - sage: pari(yb)^4 # optional - sage.libs.pari sage.libs.singular + sage: pari(yb)^4 # needs sage.libs.pari sage.libs.singular Mod(y^4, x^3 + y^3) """ gens = self.parent().defining_ideal().gens() @@ -289,14 +291,14 @@ def _add_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a + b # optional - sage.libs.singular + sage: a + b # needs sage.libs.singular a + b TESTS:: - sage: a._add_(b) # optional - sage.libs.singular + sage: a._add_(b) # needs sage.libs.singular a + b """ return self.__class__(self.parent(), self.__rep + right.__rep) @@ -309,14 +311,14 @@ def _sub_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a - b # optional - sage.libs.singular + sage: a - b # needs sage.libs.singular a - b TESTS:: - sage: a._sub_(b) # optional - sage.libs.singular + sage: a._sub_(b) # needs sage.libs.singular a - b """ return self.__class__(self.parent(), self.__rep - right.__rep) @@ -329,16 +331,16 @@ def _mul_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a * b # optional - sage.libs.singular + sage: a * b # needs sage.libs.singular a*b TESTS:: - sage: a._mul_(b) # optional - sage.libs.singular + sage: a._mul_(b) # needs sage.libs.singular a*b - sage: a._mul_(a) # optional - sage.libs.singular + sage: a._mul_(a) # needs sage.libs.singular -b^2 """ return self.__class__(self.parent(), self.__rep * right.__rep) @@ -353,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) # optional - sage.libs.singular - sage: 1/(1+i) # optional - sage.libs.singular + sage: S. = R.quotient(I) # needs sage.libs.singular + sage: 1/(1+i) # needs sage.libs.singular -1/2*i + 1/2 Confirm via symbolic computation:: - sage: 1/(1+sqrt(-1)) # optional - sage.symbolic + sage: 1/(1+sqrt(-1)) # needs sage.symbolic -1/2*I + 1/2 Another more complicated quotient:: - sage: b = 1/(i+cuberoot); b # optional - sage.libs.singular + sage: b = 1/(i+cuberoot); b # needs 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) # optional - sage.libs.singular + sage: b*(i+cuberoot) # needs sage.libs.singular 1 Another really easy example:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: a / S(2) # optional - sage.libs.singular + sage: a / S(2) # needs sage.libs.singular 1/2*a - sage: (a*b)._div_(b) # optional - sage.libs.singular + sage: (a*b)._div_(b) # needs sage.libs.singular a An example in which we try to divide in a ring that is not a @@ -384,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) # optional - sage.libs.singular - sage: 1/cuberoot # optional - sage.libs.singular + sage: S. = R.quotient(I) # needs sage.libs.singular + sage: 1/cuberoot # needs sage.libs.singular 1/2*cuberoot^2 - sage: 1/a # optional - sage.libs.singular + sage: 1/a # needs 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) ) # optional - sage.libs.singular - sage: 1 / S(x1 + x2) # optional - sage.libs.singular + sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) + sage: 1 / S(x1 + x2) # needs sage.libs.singular Traceback (most recent call last): ... ArithmeticError: Division failed. The numerator is not a multiple of the denominator. @@ -407,7 +409,7 @@ def _div_(self, right): sage: R. = QQ[] sage: S. = R[] - sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) # optional - sage.libs.singular + sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) # needs sage.libs.singular Traceback (most recent call last): ... TypeError: Can only reduce polynomials over fields. @@ -475,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() # optional - sage.libs.singular + sage: K = R.quotient(x^2 - y^3).fraction_field() # needs sage.libs.singular sage: L. = FunctionField(QQ) - sage: f = K.hom((t^3, t^2)) # optional - sage.libs.singular - sage: list(map(f, K.gens())) # optional - sage.libs.singular + sage: f = K.hom((t^3, t^2)) # needs sage.libs.singular + sage: list(map(f, K.gens())) # needs sage.libs.singular [t^3, t^2] - sage: xbar, ybar = K.gens() # optional - sage.libs.singular - sage: f(1/ybar) # optional - sage.libs.singular + sage: xbar, ybar = K.gens() # needs sage.libs.singular + sage: f(1/ybar) # needs sage.libs.singular 1/t^2 - sage: f(xbar/ybar) # optional - sage.libs.singular + sage: f(xbar/ybar) # needs sage.libs.singular t """ return self.lift()._im_gens_(codomain, im_gens, base_map=base_map) @@ -496,13 +498,14 @@ def __int__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) - sage: int(S(-3)) # indirect doctest # optional - sage.libs.singular + sage: int(S(-3)) # indirect doctest -3 - sage: type(int(S(-3))) # optional - sage.libs.singular + sage: type(int(S(-3))) <... 'int'> - sage: int(a) # optional - sage.libs.singular + sage: int(a) Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -513,14 +516,14 @@ def _integer_(self, Z): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: ZZ(S(-3)) # optional - sage.libs.singular + sage: ZZ(S(-3)) # needs sage.libs.singular -3 TESTS:: - sage: type(ZZ(S(-3))) # optional - sage.libs.singular + sage: type(ZZ(S(-3))) # needs sage.libs.singular """ return Z(self.lift()) @@ -529,14 +532,14 @@ def _rational_(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: QQ(S(-2/3)) # optional - sage.libs.singular + sage: QQ(S(-2/3)) # needs sage.libs.singular -2/3 TESTS:: - sage: type(S(-2/3)._rational_()) # optional - sage.libs.singular + sage: type(S(-2/3)._rational_()) # needs sage.libs.singular """ from sage.rings.rational_field import QQ @@ -546,11 +549,11 @@ def __neg__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: -a # indirect doctest # optional - sage.libs.singular + sage: -a # indirect doctest # needs sage.libs.singular -a - sage: -(a+b) # optional - sage.libs.singular + sage: -(a+b) # needs sage.libs.singular -a - b """ return self.__class__(self.parent(), -self.__rep) @@ -559,11 +562,11 @@ def __pos__(self): """ TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: (a+b).__pos__() # optional - sage.libs.singular + sage: (a+b).__pos__() # needs sage.libs.singular a + b - sage: c = a+b; c.__pos__() is c # optional - sage.libs.singular + sage: c = a+b; c.__pos__() is c # needs sage.libs.singular True """ return self @@ -572,19 +575,19 @@ def __invert__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: ~S(2/3) # optional - sage.libs.singular + sage: ~S(2/3) # needs sage.libs.singular 3/2 TESTS:: - sage: S(2/3).__invert__() # optional - sage.libs.singular + sage: S(2/3).__invert__() # needs sage.libs.singular 3/2 Note that a is not invertible as an element of R:: - sage: a.__invert__() # optional - sage.libs.singular + sage: a.__invert__() # needs sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -599,11 +602,11 @@ def __float__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: float(S(2/3)) # optional - sage.libs.singular + sage: float(S(2/3)) # needs sage.libs.singular 0.6666666666666666 - sage: float(a) # optional - sage.libs.singular + sage: float(a) # needs sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -614,10 +617,11 @@ def __hash__(self): r""" TESTS:: - 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 + sage: # needs sage.libs.singular + sage: R. = QQ[] + sage: S. = R.quo(x^2 + y^2) + sage: c = a*a + b + sage: hash(a) != hash(b) True """ return hash(self.__rep) @@ -626,38 +630,41 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) - sage: a > b # indirect doctest # optional - sage.libs.singular + sage: a > b # indirect doctest True - sage: b > a # optional - sage.libs.singular + sage: b > a False - sage: a == loads(dumps(a)) # optional - sage.libs.singular + sage: a == loads(dumps(a)) True TESTS:: - sage: a == (a+1-1) # optional - sage.libs.singular + sage: a == (a+1-1) # needs sage.libs.singular True - sage: a > b # optional - sage.libs.singular + sage: a > b # needs sage.libs.singular True See :trac:`7797`:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.libs.singular sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular sage.modules - sage: Q.0^4 # indirect doctest # optional - sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + 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 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) # optional - sage.rings.finite_rings - sage: R. = F[] # optional - sage.rings.finite_rings - sage: I = Ideal(R, [x, y]) # optional - sage.rings.finite_rings - sage: S. = QuotientRing(R, I) # optional - sage.rings.finite_rings - sage: x1^4 # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5) + sage: R. = F[] + sage: I = Ideal(R, [x, y]) + sage: S. = QuotientRing(R, I) + sage: x1^4 0 """ # A containment test is not implemented for univariate polynomial @@ -680,18 +687,19 @@ def lt(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings - sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings - sage: Q = R.quo(I) # optional - sage.rings.finite_rings - sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings - sage: f.lt() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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() 2*xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: (a + 3*a*b + b).lt() # optional - sage.libs.singular + sage: (a + 3*a*b + b).lt() # needs sage.libs.singular 3*a*b """ return self.__class__(self.parent(), self.__rep.lt()) @@ -702,18 +710,19 @@ def lm(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings - sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings - sage: Q = R.quo(I) # optional - sage.rings.finite_rings - sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings - sage: f.lm() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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() xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: (a+3*a*b+b).lm() # optional - sage.libs.singular + sage: (a+3*a*b+b).lm() # needs sage.libs.singular a*b """ @@ -725,18 +734,19 @@ def lc(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings - sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings - sage: Q = R.quo(I) # optional - sage.rings.finite_rings - sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings - sage: f.lc() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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() 2 TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: (a + 3*a*b + b).lc() # optional - sage.libs.singular + sage: (a + 3*a*b + b).lc() # needs sage.libs.singular 3 """ return self.__rep.lc() @@ -752,17 +762,18 @@ def variables(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) - sage: a.variables() # optional - sage.libs.singular + sage: a.variables() (a,) - sage: b.variables() # optional - sage.libs.singular + sage: b.variables() (b,) - sage: s = a^2 + b^2 + 1; s # optional - sage.libs.singular + sage: s = a^2 + b^2 + 1; s 1 - sage: s.variables() # optional - sage.libs.singular + sage: s.variables() () - sage: (a + b).variables() # optional - sage.libs.singular + sage: (a + b).variables() (a, b) """ return tuple(self.__class__(self.parent(), v) for v in self.__rep.variables()) @@ -777,13 +788,14 @@ def monomials(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) - sage: a.monomials() # optional - sage.libs.singular + sage: a.monomials() [a] - sage: (a + a*b).monomials() # optional - sage.libs.singular + sage: (a + a*b).monomials() [a*b, a] - sage: R.zero().monomials() # optional - sage.libs.singular + sage: R.zero().monomials() [] """ return [self.__class__(self.parent(), m) for m in self.__rep.monomials()] @@ -799,10 +811,11 @@ def _singular_(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings - sage: I = sage.rings.ideal.FieldIdeal(P) # optional - sage.rings.finite_rings - sage: Q = P.quo(I) # optional - sage.rings.finite_rings - sage: Q._singular_() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: P. = PolynomialRing(GF(2), 2) + sage: I = sage.rings.ideal.FieldIdeal(P) + sage: Q = P.quo(I) + sage: Q._singular_() polynomial ring, over a field, global ordering // coefficients: ZZ/2 // number of vars : 2 @@ -812,20 +825,20 @@ def _singular_(self, singular=singular_default): // quotient ring from ideal _[1]=x2+x _[2]=y2+y - sage: xbar = Q(x); xbar # optional - sage.rings.finite_rings + sage: xbar = Q(x); xbar xbar - sage: xbar._singular_() # optional - sage.rings.finite_rings + sage: xbar._singular_() x - sage: Q(xbar._singular_()) # a round-trip # optional - sage.rings.finite_rings + sage: Q(xbar._singular_()) # a round-trip xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular - sage: (a - 2/3*b)._singular_() # optional - sage.libs.singular + sage: (a - 2/3*b)._singular_() # needs sage.libs.singular x-2/3*y - sage: S((a - 2/3*b)._singular_()) # optional - sage.libs.singular + sage: S((a - 2/3*b)._singular_()) # needs sage.libs.singular a - 2/3*b """ if singular is None: @@ -838,12 +851,13 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings - sage: xbar, ybar = Q.gens() # optional - sage.rings.finite_rings - sage: magma(xbar) # optional - magma # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: P. = PolynomialRing(GF(2)) + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) + sage: xbar, ybar = Q.gens() + sage: magma(xbar) # optional - magma x - sage: xbar._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings + sage: xbar._magma_init_(magma) # optional - magma '_sage_[...]!_sage_ref...' """ g = magma(self.__rep) @@ -856,19 +870,20 @@ def _macaulay2_(self, macaulay2=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings - sage: Q = R.quotient([x^2 - y]) # optional - sage.rings.finite_rings - sage: x, y = Q.gens() # optional - sage.rings.finite_rings - sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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 2*xbar*ybar^17 + xbar*ybar^10 - sage: mf = macaulay2(f); mf # optional - macaulay2 # optional - sage.rings.finite_rings + sage: mf = macaulay2(f); mf # optional - macaulay2 17 10 2x*y + x*y - sage: mf.sage() # optional - macaulay2 # optional - sage.rings.finite_rings + sage: mf.sage() # optional - macaulay2 2*x*y^17 + x*y^10 - sage: mf.sage() == f # optional - macaulay2 # optional - sage.rings.finite_rings + sage: mf.sage() == f # optional - macaulay2 True - sage: Q(mf) # optional - macaulay2 # optional - sage.rings.finite_rings + sage: Q(mf) # optional - macaulay2 2*xbar*ybar^17 + xbar*ybar^10 In Macaulay2, the variable names for a quotient ring are inherited from @@ -880,15 +895,16 @@ def _macaulay2_(self, macaulay2=None): :: - sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings - sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.rings.finite_rings - sage: x, y = Q.gens() # optional - sage.rings.finite_rings - sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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 2*x*y^17 + x*y^10 - sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings + sage: macaulay2(f) # optional - macaulay2 17 10 2x*y + x*y - sage: _.sage() # optional - macaulay2 # optional - sage.rings.finite_rings + sage: _.sage() # optional - macaulay2 2*x*y^17 + x*y^10 TESTS: @@ -896,15 +912,16 @@ def _macaulay2_(self, macaulay2=None): Check that changing the currently defined global variables (`x`, `y`, ...) in Macaulay2 does not affect the result of this conversion:: - sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings - sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.rings.finite_rings - sage: x, y = Q.gens() # optional - sage.rings.finite_rings - sage: f = (x^3 + 2*y^2*x)^7 # optional - sage.rings.finite_rings - sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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 17 10 2x*y + x*y - sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 # optional - sage.rings.finite_rings - sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings + sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 + sage: macaulay2(f) # optional - macaulay2 17 10 2x*y + x*y """ @@ -933,18 +950,19 @@ def reduce(self, G): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 5, order='lex') # optional - sage.rings.finite_rings - sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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)) # optional - sage.rings.finite_rings - sage: I2 = ideal([Q(f) for f in I1.gens()]) # optional - sage.rings.finite_rings - sage: f = Q((a*b + c*d + 1)^2 + e) # optional - sage.rings.finite_rings - sage: f.reduce(I2.gens()) # optional - sage.rings.finite_rings + 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()) ebar Notice that the result above is not minimal:: - sage: I2.reduce(f) # optional - sage.rings.finite_rings + sage: I2.reduce(f) # needs sage.rings.finite_rings 0 """ try: diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index f08b37d6d45..90b07c7914b 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -293,30 +293,30 @@ 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 # optional - sage.symbolic + sage: t = (3/4)^(-1/2); t # needs sage.symbolic 2/3*sqrt(3) - sage: t^2 # optional - sage.symbolic + sage: t^2 # needs sage.symbolic 4/3 Check if :trac:`15605` is fixed:: sage: rational_power_parts(-1, -1/3) (1, -1) - sage: (-1)^(-1/3) # optional - sage.symbolic + sage: (-1)^(-1/3) # needs sage.symbolic -(-1)^(2/3) - sage: 1 / ((-1)^(1/3)) # optional - sage.symbolic + sage: 1 / ((-1)^(1/3)) # needs sage.symbolic -(-1)^(2/3) sage: rational_power_parts(-1, 2/3) (1, -1) - sage: (-1)^(2/3) # optional - sage.symbolic + sage: (-1)^(2/3) # needs 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) # optional - sage.symbolic + sage: (-1)^(1/3)*(-1)^(1/5) # needs sage.symbolic (-1)^(8/15) - sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) # optional - sage.symbolic + sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) # needs sage.symbolic True - sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) # optional - sage.symbolic + sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) # needs sage.symbolic ....: for p in srange(1, 6) for q in srange(1, 6)) True @@ -416,9 +416,9 @@ cdef class Rational(sage.structure.element.FieldElement): 1/2 sage: Rational(("2", "10"), 16) 1/8 - sage: Rational(QQbar(125/8).nth_root(3)) # optional - sage.rings.number_field + sage: Rational(QQbar(125/8).nth_root(3)) # needs sage.rings.number_field 5/2 - sage: Rational(AA(209735/343 - 17910/49*golden_ratio).nth_root(3) # optional - sage.rings.number_field + sage: Rational(AA(209735/343 - 17910/49*golden_ratio).nth_root(3) # needs sage.rings.number_field sage.symbolic ....: + 3*AA(golden_ratio)) 53/7 sage: QQ(float(1.5)) @@ -435,24 +435,25 @@ cdef class Rational(sage.structure.element.FieldElement): Conversion from PARI:: - sage: Rational(pari('-939082/3992923')) # optional - sage.libs.pari + sage: Rational(pari('-939082/3992923')) # needs sage.libs.pari -939082/3992923 - sage: Rational(pari('Pol([-1/2])')) #9595 # optional - sage.libs.pari + sage: Rational(pari('Pol([-1/2])')) #9595 # needs sage.libs.pari -1/2 Conversions from numpy:: - sage: import numpy as np # optional - numpy - sage: QQ(np.int8('-15')) # optional - numpy + sage: # needs numpy + sage: import numpy as np + sage: QQ(np.int8('-15')) -15 - sage: QQ(np.int16('-32')) # optional - numpy + sage: QQ(np.int16('-32')) -32 - sage: QQ(np.int32('-19')) # optional - numpy + sage: QQ(np.int32('-19')) -19 - sage: QQ(np.uint32('1412')) # optional - numpy + sage: QQ(np.uint32('1412')) 1412 - sage: QQ(np.float16('12')) # optional - numpy + sage: QQ(np.float16('12')) # needs numpy 12 Conversions from gmpy2:: @@ -507,7 +508,7 @@ cdef class Rational(sage.structure.element.FieldElement): 7 sage: a.__init__('70', base=8); a 56 - sage: a.__init__(pari('2/3')); a # optional - sage.libs.pari + sage: a.__init__(pari('2/3')); a # needs sage.libs.pari 2/3 sage: a.__init__('-h/3ki', 32); a -17/3730 @@ -718,7 +719,7 @@ cdef class Rational(sage.structure.element.FieldElement): sage: 1 + 1/(2 + 1/(3 + 1/(4 + 1/5))) 225/157 - sage: (fibonacci(20)/fibonacci(19)).continued_fraction_list() + sage: (fibonacci(20)/fibonacci(19)).continued_fraction_list() # needs sage.libs.pari [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2] sage: (-1/3).continued_fraction_list() @@ -805,9 +806,9 @@ cdef class Rational(sage.structure.element.FieldElement): sage: a = (355/113).continued_fraction(); a [3; 7, 16] - sage: a.n(digits=10) # optional - sage.rings.real_mpfr + sage: a.n(digits=10) # needs sage.rings.real_mpfr 3.141592920 - sage: pi.n(digits=10) # optional - sage.rings.real_mpfr sage.symbolic + sage: pi.n(digits=10) # needs sage.rings.real_mpfr sage.symbolic 3.141592654 It's almost pi! @@ -958,9 +959,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: ex = SR(QQ(7)/3); ex # optional - sage.symbolic + sage: ex = SR(QQ(7)/3); ex # needs sage.symbolic 7/3 - sage: parent(ex) # optional - sage.symbolic + sage: parent(ex) # needs sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -971,12 +972,12 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: n = 1/2; n._sympy_() # optional - sympy + sage: n = 1/2; n._sympy_() # needs sympy 1/2 - sage: n = -1/5; n._sympy_() # optional - sympy + sage: n = -1/5; n._sympy_() # needs sympy -1/5 - sage: from sympy import Symbol # optional - sympy - sage: QQ(1) + Symbol('x')*QQ(2) # optional - sympy + sage: from sympy import Symbol # needs sympy + sage: QQ(1) + Symbol('x')*QQ(2) # needs sympy 2*x + 1 """ import sympy @@ -1044,16 +1045,16 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.array([1, 2, 3/1]) # optional - numpy + sage: import numpy # needs numpy + sage: numpy.array([1, 2, 3/1]) # needs numpy array([1, 2, 3]) - sage: numpy.array(QQ(2**40)).dtype # optional - numpy + sage: numpy.array(QQ(2**40)).dtype # needs numpy dtype('int64') - sage: numpy.array(QQ(2**400)).dtype # optional - numpy + sage: numpy.array(QQ(2**400)).dtype # needs numpy dtype('O') - sage: numpy.array([1, 1/2, 3/4]) # optional - numpy + sage: numpy.array([1, 1/2, 3/4]) # needs numpy array([1. , 0.5 , 0.75]) """ if mpz_cmp_ui(mpq_denref(self.value), 1) == 0: @@ -1196,11 +1197,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(25/6) - sage: a.local_height(2) # optional - sage.rings.real_mpfr + sage: a.local_height(2) # needs sage.rings.real_mpfr 0.693147180559945 - sage: a.local_height(3) # optional - sage.rings.real_mpfr + sage: a.local_height(3) # needs sage.rings.real_mpfr 1.09861228866811 - sage: a.local_height(5) # optional - sage.rings.real_mpfr + sage: a.local_height(5) # needs sage.rings.real_mpfr 0.000000000000000 """ from sage.rings.real_mpfr import RealField @@ -1234,11 +1235,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.local_height_arch() # optional - sage.rings.real_mpfr + sage: a.local_height_arch() # needs sage.rings.real_mpfr 0.000000000000000 - sage: (1/a).local_height_arch() # optional - sage.rings.real_mpfr + sage: (1/a).local_height_arch() # needs sage.rings.real_mpfr 1.42711635564015 - sage: (1/a).local_height_arch(100) # optional - sage.rings.real_mpfr + sage: (1/a).local_height_arch(100) # needs sage.rings.real_mpfr 1.4271163556401457483890413081 """ from sage.rings.real_mpfr import RealField @@ -1277,11 +1278,11 @@ cdef class Rational(sage.structure.element.FieldElement): sage: a = QQ(5/6) sage: a.support() [2, 3, 5] - sage: a.global_height_non_arch() # optional - sage.rings.real_mpfr + sage: a.global_height_non_arch() # needs sage.rings.real_mpfr 1.79175946922805 - sage: [a.local_height(p) for p in a.support()] # optional - sage.rings.real_mpfr + sage: [a.local_height(p) for p in a.support()] # needs sage.rings.real_mpfr [0.693147180559945, 1.09861228866811, 0.000000000000000] - sage: sum([a.local_height(p) for p in a.support()]) # optional - sage.rings.real_mpfr + sage: sum([a.local_height(p) for p in a.support()]) # needs sage.rings.real_mpfr 1.79175946922805 """ from sage.rings.real_mpfr import RealField @@ -1318,11 +1319,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.global_height_arch() # optional - sage.rings.real_mpfr + sage: a.global_height_arch() # needs sage.rings.real_mpfr 0.000000000000000 - sage: (1/a).global_height_arch() # optional - sage.rings.real_mpfr + sage: (1/a).global_height_arch() # needs sage.rings.real_mpfr 1.42711635564015 - sage: (1/a).global_height_arch(100) # optional - sage.rings.real_mpfr + sage: (1/a).global_height_arch(100) # needs sage.rings.real_mpfr 1.4271163556401457483890413081 """ return self.local_height_arch(prec) @@ -1350,15 +1351,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.global_height_arch() + a.global_height_non_arch() # optional - sage.rings.real_mpfr + sage: a.global_height_arch() + a.global_height_non_arch() # needs sage.rings.real_mpfr 3.21887582486820 - sage: a.global_height() # optional - sage.rings.real_mpfr + sage: a.global_height() # needs sage.rings.real_mpfr 3.21887582486820 - sage: (1/a).global_height() # optional - sage.rings.real_mpfr + sage: (1/a).global_height() # needs sage.rings.real_mpfr 3.21887582486820 - sage: QQ(0).global_height() # optional - sage.rings.real_mpfr + sage: QQ(0).global_height() # needs sage.rings.real_mpfr 0.000000000000000 - sage: QQ(1).global_height() # optional - sage.rings.real_mpfr + sage: QQ(1).global_height() # needs sage.rings.real_mpfr 0.000000000000000 """ from sage.rings.real_mpfr import RealField @@ -1418,43 +1419,43 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field - sage: (1/7).is_norm(K) # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') # needs sage.rings.number_field + sage: (1/7).is_norm(K) # needs sage.rings.number_field True - sage: (1/10).is_norm(K) # optional - sage.rings.number_field + sage: (1/10).is_norm(K) # needs sage.rings.number_field False - sage: 0.is_norm(K) # optional - sage.rings.number_field + sage: 0.is_norm(K) # needs sage.rings.number_field True - sage: (1/7).is_norm(K, element=True) # optional - sage.rings.number_field + sage: (1/7).is_norm(K, element=True) # needs sage.rings.number_field (True, 1/7*beta + 3/7) - sage: (1/10).is_norm(K, element=True) # optional - sage.rings.number_field + sage: (1/10).is_norm(K, element=True) # needs sage.rings.number_field (False, None) - sage: (1/691).is_norm(QQ, element=True) # optional - sage.rings.number_field + sage: (1/691).is_norm(QQ, element=True) (True, 1/691) The number field doesn't have to be defined by an integral polynomial:: - sage: B, e = (1/5).is_norm(QuadraticField(5/4, 'a'), element=True) # optional - sage.rings.number_field - sage: B # optional - sage.rings.number_field + sage: B, e = (1/5).is_norm(QuadraticField(5/4, 'a'), element=True) # needs sage.rings.number_field + sage: B # needs sage.rings.number_field True - sage: e.norm() # optional - sage.rings.number_field + sage: e.norm() # needs sage.rings.number_field 1/5 A non-Galois number field:: - sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field - sage: B, e = (3/5).is_norm(K, element=True); B # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - 2) # needs sage.rings.number_field + sage: B, e = (3/5).is_norm(K, element=True); B # needs sage.rings.number_field True - sage: e.norm() # optional - sage.rings.number_field + sage: e.norm() # needs sage.rings.number_field 3/5 - sage: 7.is_norm(K) # optional - sage.rings.number_field + sage: 7.is_norm(K) # needs sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: is_norm is not implemented unconditionally for norms from non-Galois number fields - sage: 7.is_norm(K, proof=False) # optional - sage.rings.number_field + sage: 7.is_norm(K, proof=False) # needs sage.rings.number_field False AUTHORS: @@ -1537,10 +1538,10 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field + sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) # needs sage.rings.number_field (i + 1, 1) sage: x = polygen(QQ, 'x') - sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # optional - sage.rings.number_field + sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # needs sage.rings.number_field (1, 7) AUTHORS: @@ -1899,34 +1900,34 @@ cdef class Rational(sage.structure.element.FieldElement): sage: x.sqrt(all=True) [10, -10] sage: x = 81/5 - sage: x.sqrt() # optional - sage.symbolic + sage: x.sqrt() # needs sage.symbolic 9*sqrt(1/5) sage: x = -81/3 - sage: x.sqrt() # optional - sage.symbolic + sage: x.sqrt() # needs sage.symbolic 3*sqrt(-3) :: sage: n = 2/3 - sage: n.sqrt() # optional - sage.symbolic + sage: n.sqrt() # needs sage.symbolic sqrt(2/3) - sage: n.sqrt(prec=10) # optional - sage.rings.real_mpfr + sage: n.sqrt(prec=10) # needs sage.rings.real_mpfr 0.82 - sage: n.sqrt(prec=100) # optional - sage.rings.real_mpfr + sage: n.sqrt(prec=100) # needs sage.rings.real_mpfr 0.81649658092772603273242802490 - sage: n.sqrt(prec=100)^2 # optional - sage.rings.real_mpfr + sage: n.sqrt(prec=100)^2 # needs sage.rings.real_mpfr 0.66666666666666666666666666667 - sage: n.sqrt(prec=53, all=True) # optional - sage.rings.real_mpfr + sage: n.sqrt(prec=53, all=True) # needs sage.rings.real_mpfr [0.816496580927726, -0.816496580927726] sage: n.sqrt(extend=False, all=True) Traceback (most recent call last): ... ValueError: square root of 2/3 not a rational number - sage: sqrt(-2/3, all=True) # optional - sage.symbolic + sage: sqrt(-2/3, all=True) # needs sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] - sage: sqrt(-2/3, prec=53) # optional - sage.rings.real_mpfr + sage: sqrt(-2/3, prec=53) # needs sage.rings.real_mpfr 0.816496580927726*I - sage: sqrt(-2/3, prec=53, all=True) # optional - sage.rings.real_mpfr + sage: sqrt(-2/3, prec=53, all=True) # needs sage.rings.real_mpfr [0.816496580927726*I, -0.816496580927726*I] AUTHORS: @@ -1988,22 +1989,22 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1/7).period() # optional - sage.libs.pari + sage: (1/7).period() # needs sage.libs.pari 6 - sage: RR(1/7) # optional - sage.rings.real_mpfr + sage: RR(1/7) # needs sage.rings.real_mpfr 0.142857142857143 - sage: (1/8).period() # optional - sage.libs.pari + sage: (1/8).period() # needs sage.libs.pari 1 - sage: RR(1/8) # optional - sage.rings.real_mpfr + sage: RR(1/8) # needs sage.rings.real_mpfr 0.125000000000000 - sage: RR(1/6) # optional - sage.rings.real_mpfr + sage: RR(1/6) # needs sage.rings.real_mpfr 0.166666666666667 - sage: (1/6).period() # optional - sage.libs.pari + sage: (1/6).period() # needs sage.libs.pari 1 sage: x = 333/106 - sage: x.period() # optional - sage.libs.pari + sage: x.period() # needs sage.libs.pari 13 - sage: RealField(200)(x) # optional - sage.rings.real_mpfr + sage: RealField(200)(x) # needs sage.rings.real_mpfr 3.1415094339622641509433962264150943396226415094339622641509 """ cdef unsigned int alpha, beta @@ -2193,27 +2194,27 @@ cdef class Rational(sage.structure.element.FieldElement): Test that conversion agrees with `RR`:: sage: Q = [a/b for a in [-99..99] for b in [1..99]] - sage: all(RDF(q) == RR(q) for q in Q) # optional - sage.rings.real_mpfr + sage: all(RDF(q) == RR(q) for q in Q) True Test that the conversion has correct rounding on simple rationals:: - sage: for p in [-100..100]: # optional - sage.rings.real_mpfr + sage: for p in [-100..100]: # needs sage.rings.real_mpfr ....: for q in [1..100]: ....: r = RDF(p/q) ....: assert (RR(r).exact_rational() - p/q) <= r.ulp()/2 Test larger rationals:: - sage: Q = continued_fraction(pi).convergents()[:100] + sage: Q = continued_fraction(pi).convergents()[:100] # needs sage.symbolic sage: all(RDF(q) == RR(q) for q in Q) True At some point, the continued fraction and direct conversion to ``RDF`` should agree:: - sage: RDFpi = RDF(pi) - sage: all(RDF(q) == RDFpi for q in Q[20:]) + sage: RDFpi = RDF(pi) # needs sage.symbolic + sage: all(RDF(q) == RDFpi for q in Q[20:]) # needs sage.symbolic True """ return mpq_get_d_nearest(self.value) @@ -2513,9 +2514,9 @@ cdef class Rational(sage.structure.element.FieldElement): sage: (2/3)^5 32/243 - sage: (-1/1)^(1/3) # optional - sage.symbolic + sage: (-1/1)^(1/3) # needs sage.symbolic (-1)^(1/3) - sage: (2/3)^(3/4) # optional - sage.symbolic + sage: (2/3)^(3/4) # needs sage.symbolic (2/3)^(3/4) sage: (-1/3)^0 1 @@ -2530,18 +2531,18 @@ cdef class Rational(sage.structure.element.FieldElement): 2/3 sage: parent(a) Rational Field - sage: (-27/125)^(1/3) # optional - sage.symbolic + sage: (-27/125)^(1/3) # needs sage.symbolic 3/5*(-1)^(1/3) - sage: (-27/125)^(1/2) # optional - sage.symbolic + sage: (-27/125)^(1/2) # needs sage.symbolic 3/5*sqrt(-3/5) The result is normalized to have the rational power in the numerator:: - sage: 2^(-1/2) # optional - sage.symbolic + sage: 2^(-1/2) # needs sage.symbolic 1/2*sqrt(2) - sage: 8^(-1/5) # optional - sage.symbolic + sage: 8^(-1/5) # needs sage.symbolic 1/8*8^(4/5) - sage: 3^(-3/2) # optional - sage.symbolic + sage: 3^(-3/2) # needs sage.symbolic 1/9*sqrt(3) TESTS:: @@ -2553,7 +2554,7 @@ cdef class Rational(sage.structure.element.FieldElement): This works even if the base is a Python integer:: - sage: int(2)^(1/2) # optional - sage.symbolic + sage: int(2)^(1/2) # needs sage.symbolic sqrt(2) sage: a = int(2)^(3/1); a 8 @@ -2572,7 +2573,7 @@ cdef class Rational(sage.structure.element.FieldElement): ... OverflowError: exponent must be at most 2147483647 # 32-bit OverflowError: exponent must be at most 9223372036854775807 # 64-bit - sage: QQ(-1)^(2^100) # optional - sage.symbolic + sage: QQ(-1)^(2^100) # needs sage.symbolic 1 """ n = other @@ -3119,42 +3120,42 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (124/345).log(5) # optional - sage.symbolic + sage: (124/345).log(5) # needs sage.symbolic log(124/345)/log(5) - sage: (124/345).log(5, 100) # optional - sage.rings.real_mpfr + sage: (124/345).log(5, 100) # needs sage.rings.real_mpfr -0.63578895682825611710391773754 - sage: log(QQ(125)) # optional - sage.symbolic + sage: log(QQ(125)) # needs sage.symbolic 3*log(5) sage: log(QQ(125), 5) 3 - sage: log(QQ(125), 3) # optional - sage.symbolic + sage: log(QQ(125), 3) # needs sage.symbolic 3*log(5)/log(3) sage: QQ(8).log(1/2) -3 - sage: (1/8).log(1/2) # optional - sage.libs.pari + sage: (1/8).log(1/2) 3 - sage: (1/2).log(1/8) # optional - sage.libs.pari + sage: (1/2).log(1/8) 1/3 - sage: (1/2).log(8) # optional - sage.libs.pari + sage: (1/2).log(8) -1/3 - sage: (16/81).log(8/27) # optional - sage.libs.pari + sage: (16/81).log(8/27) # needs sage.libs.pari 4/3 - sage: (8/27).log(16/81) # optional - sage.libs.pari + sage: (8/27).log(16/81) # needs sage.libs.pari 3/4 - sage: log(27/8, 16/81) # optional - sage.libs.pari + sage: log(27/8, 16/81) # needs sage.libs.pari -3/4 - sage: log(16/81, 27/8) # optional - sage.libs.pari + sage: log(16/81, 27/8) # needs sage.libs.pari -4/3 - sage: (125/8).log(5/2) # optional - sage.libs.pari + sage: (125/8).log(5/2) # needs sage.libs.pari 3 - sage: (125/8).log(5/2, prec=53) # optional - sage.rings.real_mpfr + sage: (125/8).log(5/2, prec=53) # needs sage.rings.real_mpfr 3.00000000000000 TESTS:: - sage: (25/2).log(5/2) # optional - sage.symbolic + sage: (25/2).log(5/2) # needs sage.symbolic log(25/2)/log(5/2) - sage: (-1/2).log(3) # optional - sage.symbolic + sage: (-1/2).log(3) # needs sage.symbolic (I*pi + log(1/2))/log(3) """ cdef int self_sgn @@ -3223,22 +3224,23 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: gamma(1/2) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: gamma(1/2) sqrt(pi) - sage: gamma(7/2) # optional - sage.symbolic + sage: gamma(7/2) 15/8*sqrt(pi) - sage: gamma(-3/2) # optional - sage.symbolic + sage: gamma(-3/2) 4/3*sqrt(pi) - sage: gamma(6/1) # optional - sage.symbolic + sage: gamma(6/1) 120 - sage: gamma(1/3) # optional - sage.symbolic + sage: gamma(1/3) gamma(1/3) This function accepts an optional precision argument:: - sage: (1/3).gamma(prec=100) # optional - sage.rings.real_mpfr + sage: (1/3).gamma(prec=100) # needs sage.rings.real_mpfr 2.6789385347077476336556929410 - sage: (1/2).gamma(prec=100) # optional - sage.rings.real_mpfr + sage: (1/2).gamma(prec=100) # needs sage.rings.real_mpfr 1.7724538509055160272981674833 TESTS: @@ -3774,11 +3776,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: n = 9390823/17 - sage: m = n.__pari__(); m # optional - sage.libs.pari + sage: m = n.__pari__(); m # needs sage.libs.pari 9390823/17 - sage: type(m) # optional - sage.libs.pari + sage: type(m) # needs sage.libs.pari - sage: m.type() # optional - sage.libs.pari + sage: m.type() # needs sage.libs.pari 't_FRAC' """ global new_gen_from_rational diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index ee665002556..8efdc093636 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -16,17 +16,17 @@ :: - sage: RealField(9).pi() # optional - sage.rings.real_mpfr + sage: RealField(9).pi() # needs sage.rings.real_mpfr 3.1 - sage: QQ(RealField(9).pi()) # optional - sage.rings.real_mpfr + sage: QQ(RealField(9).pi()) # needs sage.rings.real_mpfr 22/7 - sage: QQ(RealField().pi()) # optional - sage.rings.real_mpfr + sage: QQ(RealField().pi()) # needs sage.rings.real_mpfr 245850922/78256779 sage: QQ(35) 35 sage: QQ('12/347') 12/347 - sage: QQ(exp(pi*I)) + sage: QQ(exp(pi*I)) # needs sage.symbolic -1 sage: x = polygen(ZZ) sage: QQ((3*x)/(4*x)) @@ -86,7 +86,7 @@ class RationalField(Singleton, number_field_base.NumberField): -930482/9320842317 sage: QQ([9320842317]) 9320842317 - sage: QQ(pari(39029384023840928309482842098430284398243982394)) # optional - sage.libs.pari + sage: QQ(pari(39029384023840928309482842098430284398243982394)) # needs sage.libs.pari 39029384023840928309482842098430284398243982394 sage: QQ('sage') Traceback (most recent call last): @@ -98,11 +98,11 @@ class RationalField(Singleton, number_field_base.NumberField): :: - sage: QQ(RR(3929329/32)) # optional - sage.rings.real_mpfr + sage: QQ(RR(3929329/32)) 3929329/32 - sage: QQ(-RR(3929329/32)) # optional - sage.rings.real_mpfr + sage: QQ(-RR(3929329/32)) -3929329/32 - sage: QQ(RR(1/7)) - 1/7 # optional - sage.rings.real_mpfr + sage: QQ(RR(1/7)) - 1/7 # needs sage.rings.real_mpfr 0 If you specify the optional second argument ``base``, then the string @@ -110,26 +110,27 @@ class RationalField(Singleton, number_field_base.NumberField): :: - sage: QQ(23.2, 2) # optional - sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: QQ(23.2, 2) 6530219459687219/281474976710656 - sage: 6530219459687219.0/281474976710656 # optional - sage.rings.real_mpfr + sage: 6530219459687219.0/281474976710656 23.20000000000000 - sage: a = 23.2; a # optional - sage.rings.real_mpfr + sage: a = 23.2; a 23.2000000000000 - sage: QQ(a, 10) # optional - sage.rings.real_mpfr + sage: QQ(a, 10) 116/5 Here's a nice example involving elliptic curves:: - sage: # optional - sage.rings.real_mpfr sage.schemes - sage: E = EllipticCurve('11a') # optional - sage.schemes - sage: L = E.lseries().at1(300)[0]; L # optional - sage.schemes + sage: # needs sage.rings.real_mpfr sage.schemes + sage: E = EllipticCurve('11a') + sage: L = E.lseries().at1(300)[0]; L 0.2538418608559106843377589233... - sage: O = E.period_lattice().omega(); O # optional - sage.schemes + sage: O = E.period_lattice().omega(); O 1.26920930427955 - sage: t = L/O; t # optional - sage.schemes + sage: t = L/O; t 0.200000000000000 - sage: QQ(RealField(45)(t)) # optional - sage.rings.real_mpfr sage.schemes + sage: QQ(RealField(45)(t)) 1/5 """ def __new__(cls): @@ -325,9 +326,9 @@ def completion(self, p, prec, extras={}): EXAMPLES:: - sage: QQ.completion(infinity, 53) # optional - sage.rings.real_mpfr + sage: QQ.completion(infinity, 53) # needs sage.rings.real_mpfr Real Field with 53 bits of precision - sage: QQ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics + sage: QQ.completion(5, 15, {'print_mode': 'bars'}) # needs sage.rings.padics 5-adic Field with capped relative precision 15 """ from sage.rings.infinity import Infinity @@ -442,7 +443,7 @@ def __truediv__(self, I): EXAMPLES:: - sage: QQ / ZZ # optional - sage.groups + sage: QQ / ZZ # needs sage.groups Q/Z """ from sage.rings.ideal import Ideal_generic @@ -527,9 +528,9 @@ def primes_of_bounded_norm_iter(self, B): EXAMPLES:: sage: it = QQ.primes_of_bounded_norm_iter(10) - sage: list(it) # optional - sage.libs.pari + sage: list(it) # needs sage.libs.pari [2, 3, 5, 7] - sage: list(QQ.primes_of_bounded_norm_iter(1)) # optional - sage.libs.pari + sage: list(QQ.primes_of_bounded_norm_iter(1)) [] """ try: @@ -607,14 +608,14 @@ def embeddings(self, K): sage: QQ.embeddings(QQ) [Identity endomorphism of Rational Field] - sage: QQ.embeddings(CyclotomicField(5)) # optional - sage.rings.number_field + sage: QQ.embeddings(CyclotomicField(5)) # needs sage.rings.number_field [Coercion map: From: Rational Field To: Cyclotomic Field of order 5 and degree 4] `K` must have characteristic 0:: - sage: QQ.embeddings(GF(3)) # optional - sage.rings.finite_rings + sage: QQ.embeddings(GF(3)) Traceback (most recent call last): ... ValueError: no embeddings of the rational field into K. @@ -658,7 +659,7 @@ def places(self, all_complex=False, prec=None): EXAMPLES:: - sage: QQ.places() # optional - sage.rings.real_mpfr + sage: QQ.places() # needs sage.rings.real_mpfr [Ring morphism: From: Rational Field To: Real Field with 53 bits of precision @@ -668,7 +669,7 @@ def places(self, all_complex=False, prec=None): From: Rational Field To: Real Double Field Defn: 1 |--> 1.0] - sage: QQ.places(prec=200, all_complex=True) # optional - sage.rings.real_mpfr + sage: QQ.places(prec=200, all_complex=True) # needs sage.rings.real_mpfr [Ring morphism: From: Rational Field To: Complex Field with 200 bits of precision @@ -705,12 +706,12 @@ def complex_embedding(self, prec=53): EXAMPLES:: - sage: QQ.complex_embedding() # optional - sage.rings.real_mpfr + sage: QQ.complex_embedding() # needs sage.rings.real_mpfr Ring morphism: From: Rational Field To: Complex Field with 53 bits of precision Defn: 1 |--> 1.00000000000000 - sage: QQ.complex_embedding(20) # optional - sage.rings.real_mpfr + sage: QQ.complex_embedding(20) # needs sage.rings.real_mpfr Ring morphism: From: Rational Field To: Complex Field with 20 bits of precision @@ -736,9 +737,9 @@ def residue_field(self, p, check=True): EXAMPLES:: - sage: QQ.residue_field(5) + sage: QQ.residue_field(5) # needs sage.rings.finite_rings Residue field of Integers modulo 5 - sage: QQ.residue_field(next_prime(10^9)) + sage: QQ.residue_field(next_prime(10^9)) # needs sage.rings.finite_rings Residue field of Integers modulo 1000000007 """ from sage.rings.finite_rings.residue_field import ResidueField @@ -769,37 +770,37 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): EXAMPLES:: - sage: QQ.hilbert_symbol_negative_at_S([-1,5,3,2,7,11,13,23], -10/7) # optional - sage.rings.padics + sage: QQ.hilbert_symbol_negative_at_S([-1,5,3,2,7,11,13,23], -10/7) # needs sage.rings.padics -9867 - sage: QQ.hilbert_symbol_negative_at_S([3, 5, QQ.places()[0], 11], -15) # optional - sage.rings.padics + sage: QQ.hilbert_symbol_negative_at_S([3, 5, QQ.places()[0], 11], -15) # needs sage.rings.padics -33 - sage: QQ.hilbert_symbol_negative_at_S([3, 5], 2) # optional - sage.rings.padics + sage: QQ.hilbert_symbol_negative_at_S([3, 5], 2) # needs sage.rings.padics 15 TESTS:: - sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # needs sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: first argument must be a list or integer :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) # needs sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be nonzero :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # needs sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: list should be of even cardinality :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # needs sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: all entries in list must be prime or -1 for @@ -807,7 +808,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # needs sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be a nonsquare with @@ -815,14 +816,14 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) # needs sage.libs.pari sage.modules sage.symbolic Traceback (most recent call last): ... TypeError: second argument must be a rational number :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # optional - sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # needs sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: if the infinite place is in the list, the second @@ -1063,16 +1064,16 @@ def extension(self, poly, names, **kwds): We make a single absolute extension:: sage: x = polygen(QQ, 'x') - sage: K. = QQ.extension(x^3 + 5); K # optional - sage.rings.number_field + sage: K. = QQ.extension(x^3 + 5); K # needs 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 # optional - sage.rings.number_field + sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K # needs 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 + sage: b^2 # needs sage.rings.number_field -3 - sage: a^3 # optional - sage.rings.number_field + sage: a^3 # needs sage.rings.number_field -5 """ from sage.rings.number_field.number_field import NumberField @@ -1084,7 +1085,7 @@ def algebraic_closure(self): EXAMPLES:: - sage: QQ.algebraic_closure() # optional - sage.rings.number_field + sage: QQ.algebraic_closure() # needs sage.rings.number_field Algebraic Field """ from sage.rings.qqbar import QQbar @@ -1417,43 +1418,44 @@ def selmer_space(self, S, p, proof=None): When `S` is empty, `\QQ(S,p)` is only nontrivial for `p=2`:: - sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([], 2) # optional - sage.rings.number_field - sage: QS2 # optional - sage.rings.number_field + sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([], 2) # needs sage.rings.number_field + sage: QS2 # needs sage.rings.number_field Vector space of dimension 1 over Finite Field of size 2 - sage: QS2gens # optional - sage.rings.number_field + sage: QS2gens # needs sage.rings.number_field [-1] - sage: all(QQ.selmer_space([], p)[0].dimension() == 0 # optional - sage.libs.pari + sage: all(QQ.selmer_space([], p)[0].dimension() == 0 # needs sage.libs.pari ....: for p in primes(3, 10)) True In general there is one generator for each `p\in S`, and an additional generator of `-1` when `p=2`:: - sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([5,7], 2) # optional - sage.modules - sage: QS2 # optional - sage.modules + sage: # needs sage.modules sage.rings.number_field + sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([5,7], 2) + sage: QS2 Vector space of dimension 3 over Finite Field of size 2 - sage: QS2gens # optional - sage.modules + sage: QS2gens [5, 7, -1] - sage: toQS2(-7) # optional - sage.modules + sage: toQS2(-7) (0, 1, 1) - sage: fromQS2((0,1,1)) # optional - sage.modules + sage: fromQS2((0,1,1)) -7 The map ``fromQS2`` is only well-defined modulo `p`'th powers (in this case, modulo squares):: - sage: toQS2(-5/7) # optional - sage.modules + sage: toQS2(-5/7) # needs sage.modules sage.rings.number_field (1, 1, 1) - sage: fromQS2((1,1,1)) # optional - sage.modules + sage: fromQS2((1,1,1)) # needs sage.modules sage.rings.number_field -35 - sage: ((-5/7)/(-35)).is_square() # optional - sage.modules + sage: ((-5/7)/(-35)).is_square() True The map ``toQS2`` is not defined on all of `\QQ^*`, only on those numbers which are squares away from `5` and `7`:: - sage: toQS2(210) # optional - sage.modules + sage: toQS2(210) # needs sage.modules sage.rings.number_field Traceback (most recent call last): ... ValueError: argument 210 should have valuations divisible by 2 @@ -1523,7 +1525,7 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(QQ) # indirect doctest # optional - sage.libs.gap + sage: gap(QQ) # indirect doctest # needs sage.libs.gap Rationals """ return 'Rationals' @@ -1591,7 +1593,7 @@ def _sympy_(self): EXAMPLES:: - sage: QQ._sympy_() # optional - sympy + sage: QQ._sympy_() # needs sympy Rationals """ from sympy import Rationals @@ -1637,20 +1639,20 @@ def _factor_univariate_polynomial(self, f): TESTS:: sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(x) # needs sage.libs.pari x - sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(2*x) # needs sage.libs.pari (2) * x - sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # needs sage.libs.pari (x - 1/2)^4 * (x + 1/2)^4 - sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) # needs sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari - sage: QQ._factor_univariate_polynomial(f) # optional - sage.libs.pari + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial(f) # needs sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: QQ._factor_univariate_polynomial(10*x^5 - 1) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(10*x^5 - 1) # needs sage.libs.pari (10) * (x^5 - 1/10) - sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # needs sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ @@ -1668,9 +1670,9 @@ def valuation(self, p): EXAMPLES:: - sage: v = QQ.valuation(3); v # optional - sage.rings.padics + sage: v = QQ.valuation(3); v # needs sage.rings.padics 3-adic valuation - sage: v(1/3) # optional - sage.rings.padics + sage: v(1/3) # needs sage.rings.padics -1 .. SEEALSO:: diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index 9eec35e882e..3a93dc4645b 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -28,9 +28,9 @@ Sage :class:`RealBall` objects wrap Arb objects of type ``arb_t``. A real ball represents a ball over the real numbers, that is, an interval `[m-r,m+r]` where the midpoint `m` and the radius `r` are (extended) real numbers:: - sage: RBF(pi) + sage: RBF(pi) # needs sage.symbolic [3.141592653589793 +/- ...e-16] - sage: RBF(pi).mid(), RBF(pi).rad() + sage: RBF(pi).mid(), RBF(pi).rad() # needs sage.symbolic (3.14159265358979, ...e-16) The midpoint is represented as an arbitrary-precision floating-point number @@ -147,7 +147,7 @@ Comparisons with Sage symbolic infinities work with some limitations:: True sage: RBF(infinity) < infinity False - sage: RBF(NaN) < infinity + sage: RBF(NaN) < infinity # needs sage.symbolic Traceback (most recent call last): ... ValueError: infinite but not with +/- phase @@ -159,14 +159,14 @@ Comparisons with Sage symbolic infinities work with some limitations:: Comparisons between elements of real ball fields, however, support special values and should be preferred:: - sage: RBF(NaN) < RBF(infinity) + sage: RBF(NaN) < RBF(infinity) # needs sage.symbolic False sage: RBF(0).add_error(infinity) <= RBF(infinity) True TESTS:: - sage: (RBF(pi) * identity_matrix(QQ, 3)).parent() + sage: (RBF(pi) * identity_matrix(QQ, 3)).parent() # needs sage.symbolic Full MatrixSpace of 3 by 3 dense matrices over Real ball field with 53 bits of precision @@ -175,11 +175,11 @@ TESTS:: :: - sage: SR.coerce(RBF(0.42)) # optional - sage.symbolic + sage: SR.coerce(RBF(0.42)) # needs sage.symbolic [0.4200000000000000 +/- ...e-17] - sage: RBF(0.42) + SR(1) # optional - sage.symbolic + sage: RBF(0.42) + SR(1) # needs sage.symbolic [1.420000000000000 +/- ...e-16] - sage: _.parent() # optional - sage.symbolic + sage: _.parent() # needs sage.symbolic Symbolic Ring Classes and Methods @@ -338,7 +338,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): :: - sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, 'x') # optional - sage.symbolic + sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, 'x') # needs sage.symbolic x + [0.914213562373095 +/- ...e-16] TESTS:: @@ -362,9 +362,9 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): sage: RBF.zero() 0 - sage: NF. = QuadraticField(2, embedding=AA(2).sqrt()) - sage: a = (sqrt2 - 1)^1000 - sage: RBF(a) + sage: NF. = QuadraticField(2, embedding=AA(2).sqrt()) # needs sage.rings.number_field + sage: a = (sqrt2 - 1)^1000 # needs sage.rings.number_field + sage: RBF(a) # needs sage.rings.number_field [1.676156872756536e-383 +/- ...e-399] sage: RealBallField().is_finite() @@ -456,7 +456,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): False sage: RealBallField().has_coerce_map_from(RIF) False - sage: RealBallField().has_coerce_map_from(SR) # optional - sage.symbolic + sage: RealBallField().has_coerce_map_from(SR) # needs sage.symbolic False sage: RealBallField().has_coerce_map_from(RR) False @@ -509,34 +509,34 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): [+/- 1.01] sage: RBF(1) 1.000000000000000 - sage: RBF(x) + sage: RBF(x) # needs sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert x to a RealBall Various symbolic constants are supported:: - sage: RBF(e) + sage: RBF(e) # needs sage.symbolic [2.718281828459045 +/- ...e-16] - sage: RBF(pi) + sage: RBF(pi) # needs sage.symbolic [3.141592653589793 +/- ...e-16] Symbolic expressions are parsed :: - sage: RBF(4*zeta(3)) + sage: RBF(4*zeta(3)) # needs sage.symbolic [4.8082276126383...] - sage: RBF(exp(1), 0.01) + sage: RBF(exp(1), 0.01) # needs sage.symbolic [2.7 +/- ...] TESTS: The following conversions used to yield incorrect results:: - sage: RBF(airy_ai(1)) + sage: RBF(airy_ai(1)) # needs sage.symbolic [0.135292416312881...] - sage: v = RBF(zetaderiv(1, 3/2)); v + sage: v = RBF(zetaderiv(1, 3/2)); v # needs sage.symbolic [-3.932239737431101 +/- 5.58e-16] - sage: v.overlaps(RealBallField(100)(3/2).zetaderiv(1)) + sage: v.overlaps(RealBallField(100)(3/2).zetaderiv(1)) # needs sage.symbolic True """ @@ -816,7 +816,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): TESTS:: - sage: RBF.sinpi(RLF(sqrt(2))) + sage: RBF.sinpi(RLF(sqrt(2))) # needs sage.symbolic [-0.963902532849877 +/- ...e-16] """ cdef RealBall res, x_as_ball @@ -860,7 +860,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): TESTS:: - sage: RBF.cospi(RLF(sqrt(2))) + sage: RBF.cospi(RLF(sqrt(2))) # needs sage.symbolic [-0.26625534204142 +/- ...e-15] """ cdef RealBall res, x_as_ball @@ -908,7 +908,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): TESTS:: - sage: RBF.gamma(RLF(pi)) # abs tol 1e-13 + sage: RBF.gamma(RLF(pi)) # abs tol 1e-13 # needs sage.symbolic [2.28803779534003 +/- 4.12e-15] """ cdef RealBall res @@ -1258,7 +1258,7 @@ cdef class RealBall(RingElement): sage: RBF(3, 0.125) [3e+0 +/- 0.126] - sage: RBF(pi, 0.125r) + sage: RBF(pi, 0.125r) # needs sage.symbolic [3e+0 +/- 0.267] sage: RBF(3, 1/8) [3e+0 +/- 0.126] @@ -1267,8 +1267,8 @@ cdef class RealBall(RingElement): :: - sage: NF. = QuadraticField(2) - sage: RBF(1/5 + sqrt2/2) + sage: NF. = QuadraticField(2) # needs sage.rings.number_field + sage: RBF(1/5 + sqrt2/2) # needs sage.rings.number_field [0.907106781186547 +/- ...e-16] Note that integers and floating-point numbers are ''not'' rounded to @@ -1535,9 +1535,11 @@ cdef class RealBall(RingElement): TESTS:: - sage: [loads(dumps(b)).identical(b) for b in - ....: [RealBallField(60).pi(), RBF(infinity), RBF(NaN)]] - [True, True, True] + sage: [loads(dumps(b)).identical(b) + ....: for b in [RealBallField(60).pi(), RBF(infinity)]] + [True, True] + sage: b = RBF(NaN); loads(dumps(b)).identical(b) # needs sage.symbolic + True """ cdef bytes py_val sig_on() @@ -1582,7 +1584,7 @@ cdef class RealBall(RingElement): Traceback (most recent call last): ... ValueError: [+/- 2.01] does not contain a unique integer - sage: ZZ(RBF(pi)) + sage: ZZ(RBF(pi)) # needs sage.symbolic Traceback (most recent call last): ... ValueError: [3.141592653589793 +/- ...e-16] does not contain a unique integer @@ -1629,6 +1631,7 @@ cdef class RealBall(RingElement): EXAMPLES:: + sage: # needs sage.symbolic sage: mypi = RBF(pi) sage: RR(mypi) 3.14159265358979 @@ -2069,13 +2072,13 @@ cdef class RealBall(RingElement): their parent's nominal precision (see :mod:`~sage.rings.real_arb` for more information):: - sage: b = RBF(pi.n(100)) - sage: b.mid() + sage: b = RBF(pi.n(100)) # needs sage.symbolic + sage: b.mid() # needs sage.symbolic 3.141592653589793238462643383 The ``round()`` method rounds such a ball to its parent's precision:: - sage: b.round().mid() + sage: b.round().mid() # needs sage.symbolic 3.14159265358979 .. SEEALSO:: :meth:`trim` @@ -2097,11 +2100,11 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(pi).accuracy() + sage: RBF(pi).accuracy() # needs sage.symbolic 52 sage: RBF(1).accuracy() == RBF.maximal_accuracy() True - sage: RBF(NaN).accuracy() == -RBF.maximal_accuracy() + sage: RBF(NaN).accuracy() == -RBF.maximal_accuracy() # needs sage.symbolic True .. SEEALSO:: :meth:`~RealBallField.maximal_accuracy` @@ -2204,7 +2207,7 @@ cdef class RealBall(RingElement): EXAMPLES:: sage: RBF = RealBallField() - sage: RBF(pi).is_nonzero() + sage: RBF(pi).is_nonzero() # needs sage.symbolic True sage: RBF(RIF(-0.5, 0.5)).is_nonzero() False @@ -2563,9 +2566,9 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(pi).overlaps(RBF(pi) + 2**(-100)) + sage: RBF(pi).overlaps(RBF(pi) + 2**(-100)) # needs sage.symbolic True - sage: RBF(pi).overlaps(RBF(3)) + sage: RBF(pi).overlaps(RBF(3)) # needs sage.symbolic False """ return arb_overlaps(self.value, other.value) @@ -2599,7 +2602,7 @@ cdef class RealBall(RingElement): sage: RBF(1/3).contains_exact(1/3) True - sage: RBF(sqrt(2)).contains_exact(sqrt(2)) + sage: RBF(sqrt(2)).contains_exact(sqrt(2)) # needs sage.symbolic Traceback (most recent call last): ... TypeError: unsupported type: @@ -2645,12 +2648,12 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: sqrt(2) in RBF(sqrt(2)) + sage: sqrt(2) in RBF(sqrt(2)) # needs sage.symbolic True A false negative:: - sage: sqrt(2) in RBF(RealBallField(100)(sqrt(2))) + sage: sqrt(2) in RBF(RealBallField(100)(sqrt(2))) # needs sage.symbolic False .. SEEALSO:: :meth:`contains_exact` @@ -2730,7 +2733,7 @@ cdef class RealBall(RingElement): True sage: RBF(-infinity).is_infinity() True - sage: RBF(NaN).is_infinity() + sage: RBF(NaN).is_infinity() # needs sage.symbolic True sage: (~RBF(0)).is_infinity() True @@ -2745,7 +2748,7 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(NaN).is_NaN() + sage: RBF(NaN).is_NaN() # needs sage.symbolic True sage: RBF(-5).gamma().is_NaN() True @@ -2860,7 +2863,7 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(pi)/RBF(e) + sage: RBF(pi)/RBF(e) # needs sage.symbolic [1.155727349790922 +/- ...e-16] sage: RBF(2)/RBF(0) nan @@ -2875,6 +2878,7 @@ cdef class RealBall(RingElement): """ EXAMPLES:: + sage: # needs sage.symbolic sage: RBF(e)^17 [24154952.7535753 +/- ...e-8] sage: RBF(e)^(-1) @@ -2890,14 +2894,14 @@ cdef class RealBall(RingElement): nan sage: RBF(0)^(-1) nan - sage: RBF(-e)**RBF(pi) + sage: RBF(-e)**RBF(pi) # needs sage.symbolic nan TESTS:: - sage: RBF(e)**(2r) + sage: RBF(e)**(2r) # needs sage.symbolic [7.38905609893065 +/- ...e-15] - sage: RBF(e)**(-1r) + sage: RBF(e)**(-1r) # needs sage.symbolic [0.367879441171442 +/- ...e-16] """ cdef fmpz_t tmpz @@ -3216,7 +3220,7 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(pi).sin() + sage: RBF(pi).sin() # needs sage.symbolic [+/- ...e-16] .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBallField.sinpi` @@ -3233,7 +3237,7 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(pi).cos() + sage: RBF(pi).cos() # needs sage.symbolic [-1.00000000000000 +/- ...e-16] .. SEEALSO:: :meth:`~sage.rings.real_arb.RealBallField.cospi` @@ -3252,7 +3256,7 @@ cdef class RealBall(RingElement): sage: RBF(1).tan() [1.557407724654902 +/- ...e-16] - sage: RBF(pi/2).tan() + sage: RBF(pi/2).tan() # needs sage.symbolic nan """ cdef RealBall res = self._new() @@ -3269,7 +3273,7 @@ cdef class RealBall(RingElement): sage: RBF(1).cot() [0.642092615934331 +/- ...e-16] - sage: RBF(pi).cot() + sage: RBF(pi).cot() # needs sage.symbolic nan """ cdef RealBall res = self._new() @@ -3547,7 +3551,7 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(Ei(1)) # abs tol 5e-16 + sage: RBF(Ei(1)) # abs tol 5e-16 # needs sage.symbolic [1.89511781635594 +/- 4.94e-15] """ cdef RealBall res = self._new() @@ -3567,7 +3571,7 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(Si(1)) # abs tol 1e-15 + sage: RBF(Si(1)) # abs tol 1e-15 # needs sage.symbolic [0.946083070367183 +/- 9.22e-16] """ cdef RealBall res = self._new() @@ -3589,7 +3593,7 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(Ci(1)) # abs tol 5e-16 + sage: RBF(Ci(1)) # abs tol 5e-16 # needs sage.symbolic [0.337403922900968 +/- 3.25e-16] """ cdef RealBall res = self._new() @@ -3611,7 +3615,7 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(Shi(1)) + sage: RBF(Shi(1)) # needs sage.symbolic [1.05725087537573 +/- 2.77e-15] """ cdef RealBall res = self._new() @@ -3633,7 +3637,7 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(Chi(1)) # abs tol 1e-17 + sage: RBF(Chi(1)) # abs tol 1e-17 # needs sage.symbolic [0.837866940980208 +/- 4.72e-16] """ cdef RealBall res = self._new() @@ -3655,9 +3659,9 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(li(0)) + sage: RBF(li(0)) # needs sage.symbolic 0 - sage: RBF(Li(0)) + sage: RBF(Li(0)) # needs sage.symbolic [-1.04516378011749 +/- 4.23e-15] """ cdef RealBall res = self._new() @@ -3701,7 +3705,7 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: RBF(sin(3)).beta(RBF(2/3).sqrt()) # abs tol 1e-13 + sage: RBF(sin(3)).beta(RBF(2/3).sqrt()) # abs tol 1e-13 # needs sage.symbolic [7.407661629415 +/- 1.07e-13] sage: RealBallField(100)(7/2).beta(1) # abs tol 1e-30 [0.28571428571428571428571428571 +/- 5.23e-30] @@ -3936,11 +3940,11 @@ cdef class RealBall(RingElement): EXAMPLES:: - sage: polylog(0, -1) + sage: polylog(0, -1) # needs sage.symbolic -1/2 sage: RBF(-1).polylog(0) [-0.50000000000000 +/- ...e-16] - sage: polylog(1, 1/2) + sage: polylog(1, 1/2) # needs sage.symbolic -log(1/2) sage: RBF(1/2).polylog(1) [0.69314718055995 +/- ...e-15] @@ -3979,6 +3983,7 @@ cdef class RealBall(RingElement): EXAMPLES:: + sage: # needs sage.symbolic sage: RBF(pi).chebyshev_T(0) 1.000000000000000 sage: RBF(pi).chebyshev_T(1) @@ -4011,6 +4016,7 @@ cdef class RealBall(RingElement): EXAMPLES:: + sage: # needs sage.symbolic sage: RBF(pi).chebyshev_U(0) 1.000000000000000 sage: RBF(pi).chebyshev_U(1) @@ -4044,7 +4050,7 @@ cdef class RealBall(RingElement): sage: RBF(1).agm(1) 1.000000000000000 - sage: RBF(sqrt(2)).agm(1)^(-1) + sage: RBF(sqrt(2)).agm(1)^(-1) # needs sage.symbolic [0.8346268416740...] """ cdef RealBall other_as_ball diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index ffa28ed5866..7fa6e4c6847 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -128,15 +128,16 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: - sage: a = RealField(200)(2).sqrt(); a # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: a = RealField(200)(2).sqrt(); a 1.4142135623730950488016887242096980785696718753769480731767 - sage: b = RDF(a); b # needs sage.rings.real_mpfr + sage: b = RDF(a); b 1.4142135623730951 - sage: a.parent()(b) # needs sage.rings.real_mpfr + sage: a.parent()(b) 1.4142135623730951454746218587388284504413604736328125000000 - sage: a.parent()(b) == b # needs sage.rings.real_mpfr + sage: a.parent()(b) == b True - sage: b == RR(a) # needs sage.rings.real_mpfr + sage: b == RR(a) True TESTS:: @@ -797,13 +798,14 @@ cdef class RealDoubleElement(FieldElement): Adding or subtracting an ulp always gives a different number:: - sage: a + a.ulp() == a # needs sage.symbolic + sage: # needs sage.symbolic + sage: a + a.ulp() == a False - sage: a - a.ulp() == a # needs sage.symbolic + sage: a - a.ulp() == a False - sage: b + b.ulp() == b # needs sage.symbolic + sage: b + b.ulp() == b False - sage: b - b.ulp() == b # needs sage.symbolic + sage: b - b.ulp() == b False Since the default rounding mode is round-to-nearest, adding or @@ -1265,24 +1267,25 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(exp(1.0)); a # needs sage.symbolic + sage: # needs sage.symbolic + sage: a = RDF(exp(1.0)); a 2.718281828459045 - sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() # needs sage.symbolic - sage: sign,mantissa,exponent # needs sage.symbolic + sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() + sage: sign,mantissa,exponent (1, 6121026514868073, -51) - sage: sign*mantissa*(2**exponent) == a # needs sage.symbolic + sage: sign*mantissa*(2**exponent) == a True The mantissa is always a nonnegative number:: - sage: RDF(-1).sign_mantissa_exponent() + sage: RDF(-1).sign_mantissa_exponent() # needs sage.rings.real_mpfr (-1, 4503599627370496, -52) TESTS:: - sage: RDF('+0').sign_mantissa_exponent() + sage: RDF('+0').sign_mantissa_exponent() # needs sage.rings.real_mpfr (1, 0, 0) - sage: RDF('-0').sign_mantissa_exponent() + sage: RDF('-0').sign_mantissa_exponent() # needs sage.rings.real_mpfr (-1, 0, 0) """ from sage.rings.real_mpfr import RR @@ -1672,7 +1675,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(RDF(1/3)) # indirect doctest + sage: CDF(RDF(1/3)) # indirect doctest # needs sage.rings.complex_double 0.3333333333333333 """ return CDF(self._value) @@ -1846,7 +1849,7 @@ cdef class RealDoubleElement(FieldElement): :: sage: r = RDF(-2.0) - sage: r.sqrt() + sage: r.sqrt() # needs sage.rings.complex_double 1.4142135623730951*I :: @@ -1855,7 +1858,7 @@ cdef class RealDoubleElement(FieldElement): [1.4142135623730951, -1.4142135623730951] sage: RDF(0).sqrt(all=True) [0.0] - sage: RDF(-2).sqrt(all=True) + sage: RDF(-2).sqrt(all=True) # needs sage.rings.complex_double [1.4142135623730951*I, -1.4142135623730951*I] """ if self._value >= 0: diff --git a/src/sage/rings/real_double_element_gsl.pyx b/src/sage/rings/real_double_element_gsl.pyx index d03c0271d1a..8b6b3671605 100644 --- a/src/sage/rings/real_double_element_gsl.pyx +++ b/src/sage/rings/real_double_element_gsl.pyx @@ -249,7 +249,7 @@ cdef class RealDoubleElement_gsl(RealDoubleElement): 0.6931471805599453 sage: RDF(2).log(2) 1.0 - sage: RDF(2).log(pi) + sage: RDF(2).log(pi) # needs sage.symbolic 0.6055115613982801 sage: RDF(2).log(10) 0.30102999566398114 @@ -334,7 +334,7 @@ cdef class RealDoubleElement_gsl(RealDoubleElement): sage: r = RDF('16.0'); r.log10() 1.2041199826559248 - sage: r.log() / RDF(log(10)) + sage: r.log() / RDF(log(10)) # needs sage.symbolic 1.2041199826559246 sage: r = RDF('39.9'); r.log10() 1.6009728956867482 @@ -355,7 +355,7 @@ cdef class RealDoubleElement_gsl(RealDoubleElement): sage: r = RDF(16); r.logpi() 2.4220462455931204 - sage: r.log() / RDF(log(pi)) + sage: r.log() / RDF(log(pi)) # needs sage.symbolic 2.4220462455931204 sage: r = RDF('39.9'); r.logpi() 3.2203023346075152 @@ -508,11 +508,11 @@ cdef class RealDoubleElement_gsl(RealDoubleElement): EXAMPLES:: - sage: RDF(pi).restrict_angle() + sage: RDF(pi).restrict_angle() # needs sage.symbolic 3.141592653589793 - sage: RDF(pi + 1e-10).restrict_angle() + sage: RDF(pi + 1e-10).restrict_angle() # needs sage.symbolic -3.1415926534897936 - sage: RDF(1+10^10*pi).restrict_angle() + sage: RDF(1+10^10*pi).restrict_angle() # needs sage.symbolic 0.9999977606... """ return self._new_c(gsl_sf_angle_restrict_symm(self._value)) diff --git a/src/sage/rings/real_lazy.pyx b/src/sage/rings/real_lazy.pyx index 9fd6d547625..6dbfce3d494 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -15,9 +15,9 @@ TESTS: Bug :trac:`21991`:: - sage: a = QuadraticField(5).gen() - sage: u = -573147844013817084101/2*a + 1281597540372340914251/2 - sage: RealIntervalField(128)(RLF(u)).is_exact() + sage: a = QuadraticField(5).gen() # needs sage.rings.number_field + sage: u = -573147844013817084101/2*a + 1281597540372340914251/2 # needs sage.rings.number_field + sage: RealIntervalField(128)(RLF(u)).is_exact() # needs sage.rings.number_field False """ @@ -747,6 +747,7 @@ cdef class LazyFieldElement(FieldElement): When the absolute value is involved, the result might be real:: + sage: # needs sage.symbolic sage: z = exp(CLF(1 + I/2)); z 2.38551673095914? + 1.303213729686996?*I sage: r = z.abs(); r @@ -854,7 +855,7 @@ cdef class LazyFieldElement(FieldElement): TESTS:: - sage: "log" in RLF(sqrt(8)).__dir__() + sage: "log" in RLF(sqrt(8)).__dir__() # needs sage.symbolic True """ @@ -869,9 +870,9 @@ cdef class LazyFieldElement(FieldElement): sage: a = RLF(3) sage: a.sqrt() 1.732050807568878? - sage: sin(a) + sage: sin(a) # needs sage.symbolic 0.1411200080598673? - sage: RealField(160)(tanh(RLF(3))) + sage: RealField(160)(tanh(RLF(3))) # needs sage.symbolic 0.99505475368673045133188018525548847509781385470 """ if name in named_unops: @@ -885,6 +886,7 @@ cdef class LazyFieldElement(FieldElement): EXAMPLES:: + sage: # needs sage.symbolic sage: a = RLF(sqrt(2)) + RLF(sqrt(3)) sage: cf = a.continued_fraction() sage: cf @@ -902,8 +904,8 @@ def make_element(parent, *args): EXAMPLES:: - sage: a = RLF(pi) + RLF(sqrt(1/2)) # indirect doctest - sage: bool(loads(dumps(a)) == a) + sage: a = RLF(pi) + RLF(sqrt(1/2)) # indirect doctest # needs sage.symbolic + sage: bool(loads(dumps(a)) == a) # needs sage.symbolic True """ return parent(*args) @@ -1042,8 +1044,8 @@ cdef class LazyWrapper(LazyFieldElement): EXAMPLES:: - sage: a = RLF(sqrt(2)) - sage: a.continued_fraction() + sage: a = RLF(sqrt(2)) # needs sage.symbolic + sage: a.continued_fraction() # needs sage.symbolic [1; 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...] """ from sage.rings.continued_fraction import ContinuedFraction_real, ContinuedFraction_infinite @@ -1231,8 +1233,8 @@ cdef class LazyUnop(LazyFieldElement): sage: a = LazyUnop(RLF, 3, sqrt) sage: a.depth() 1 - sage: b = LazyUnop(RLF, a, sin) - sage: b.depth() + sage: b = LazyUnop(RLF, a, sin) # needs sage.symbolic + sage: b.depth() # needs sage.symbolic 2 """ return 1 + self._arg.depth() @@ -1245,7 +1247,7 @@ cdef class LazyUnop(LazyFieldElement): sage: from sage.rings.real_lazy import LazyUnop sage: a = LazyUnop(RLF, 3, sqrt) - sage: a.eval(ZZ) + sage: a.eval(ZZ) # needs sage.symbolic sqrt(3) """ arg = self._arg.eval(R) @@ -1261,7 +1263,7 @@ cdef class LazyUnop(LazyFieldElement): EXAMPLES:: - sage: hash(RLF(sin(1))) == hash(RLF(sin(1))) + sage: hash(RLF(sin(1))) == hash(RLF(sin(1))) # needs sage.symbolic True """ return hash(self._op(hash(self._arg))) diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 1193a14baff..6577ec8e733 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -47,7 +47,7 @@ preceding digit is possibly wrong by `\pm 1`. :: - sage: RIF(sqrt(2)) + sage: RIF(sqrt(2)) # needs sage.symbolic 1.414213562373095? However, if the interval is precise (its lower bound is equal to @@ -81,11 +81,11 @@ it is taken to be 1. '125.?2' sage: RIF(123, 127).str(error_digits=1) '125.?2' - sage: v = RIF(-e, pi); v + sage: v = RIF(-e, pi); v # needs sage.symbolic 0.?e1 - sage: v.str(error_digits=1) + sage: v.str(error_digits=1) # needs sage.symbolic '1.?4' - sage: v.str(error_digits=5) + sage: v.str(error_digits=5) # needs sage.symbolic '0.2117?29300' Error digits also sometimes let us indicate that the interval is @@ -230,10 +230,10 @@ specified if given a non-interval and an interval:: TESTS:: - sage: import numpy # optional - numpy - sage: RIF(2) == numpy.int8('2') # optional - numpy + sage: import numpy # needs numpy + sage: RIF(2) == numpy.int8('2') # needs numpy True - sage: numpy.int8('2') == RIF(2) # optional - numpy + sage: numpy.int8('2') == RIF(2) # needs numpy True sage: RIF(0,1) < float('2') Traceback (most recent call last): @@ -389,7 +389,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): 3 sage: RIF(RIF(3)) 3 - sage: RIF(pi) + sage: RIF(pi) # needs sage.symbolic 3.141592653589794? sage: RIF(RealField(53)('1.5')) 1.5000000000000000? @@ -452,9 +452,9 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: def check(x): ....: return (x, x.lower() == x.upper()) - sage: check(RIF(pi)) + sage: check(RIF(pi)) # needs sage.symbolic (3.141592653589794?, False) - sage: check(RIF(RR(pi))) + sage: check(RIF(RR(pi))) # needs sage.symbolic (3.1415926535897932?, True) sage: check(RIF(1.5)) (1.5000000000000000?, True) @@ -486,11 +486,11 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): 3 sage: R(R(3)) 3 - sage: R(pi) + sage: R(pi) # needs sage.symbolic 3.14159265358979323846264338328? sage: R(-2/19) -0.1052631578947368421052631578948? - sage: R(e,pi).str(style='brackets') + sage: R(e,pi).str(style='brackets') # needs sage.symbolic '[2.7182818284590452353602874713512 .. 3.1415926535897932384626433832825]' TESTS:: @@ -1050,7 +1050,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: magma(RealIntervalField(80)) # optional - magma # indirect doctest Real field of precision 24 - sage: floor(RR(log(2**80, 10))) + sage: floor(RR(log(2**80, 10))) # needs sage.symbolic 24 """ return "RealField(%s : Bits := true)" % self.prec() @@ -1356,7 +1356,7 @@ cdef class RealIntervalFieldElement(RingElement): error:: sage: a = RealInterval('2.3') - sage: maxima(a) + sage: maxima(a) # needs sage.symbolic Traceback (most recent call last): ... TypeError @@ -1370,10 +1370,11 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: sage_input(RIF(e, pi), verify=True) + sage: sage_input(RIF(e, pi), verify=True) # needs sage.symbolic # Verified RIF(RR(2.7182818284590451), RR(3.1415926535897936)) - sage: sage_input(RealIntervalField(64)(sqrt(2)), preparse=False, verify=True) + sage: sage_input(RealIntervalField(64)(sqrt(2)), # needs sage.symbolic + ....: preparse=False, verify=True) # Verified RR64 = RealField(64) RealIntervalField(64)(RR64('1.41421356237309504876'), RR64('1.41421356237309504887')) @@ -1386,8 +1387,9 @@ cdef class RealIntervalFieldElement(RingElement): RealIntervalField(2)(RR2(12.), RR2(16.)) sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() - sage: RIF(-sqrt(3), -sqrt(2))._sage_input_(sib, False) - {call: {atomic:RIF}({unop:- {call: {atomic:RR}({atomic:1.7320508075688774})}}, {unop:- {call: {atomic:RR}({atomic:1.4142135623730949})}})} + sage: RIF(-sqrt(3), -sqrt(2))._sage_input_(sib, False) # needs sage.symbolic + {call: {atomic:RIF}({unop:- {call: {atomic:RR}({atomic:1.7320508075688774})}}, + {unop:- {call: {atomic:RR}({atomic:1.4142135623730949})}})} """ # Interval printing could often be much prettier, # but I'm feeling lazy :) @@ -1406,7 +1408,7 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: hash(RIF(e)) == hash(RIF(e)) # indirect doctest + sage: hash(RIF(e)) == hash(RIF(e)) # indirect doctest # needs sage.symbolic True """ return hash(self.str(16)) @@ -1491,11 +1493,11 @@ cdef class RealIntervalFieldElement(RingElement): ``'brackets'`` style. In question style (the default), we print the "known correct" part of the number, followed by a question mark:: - sage: RIF(pi).str() + sage: RIF(pi).str() # needs sage.symbolic '3.141592653589794?' - sage: RIF(pi, 22/7).str() + sage: RIF(pi, 22/7).str() # needs sage.symbolic '3.142?' - sage: RIF(pi, 22/7).str(style='question') + sage: RIF(pi, 22/7).str(style='question') # needs sage.symbolic '3.142?' However, if the interval is precisely equal to some integer that's @@ -1545,9 +1547,9 @@ cdef class RealIntervalFieldElement(RingElement): We always use brackets style for ``NaN`` and infinities:: - sage: RIF(pi, infinity) + sage: RIF(pi, infinity) # needs sage.symbolic [3.1415926535897931 .. +infinity] - sage: RIF(NaN) + sage: RIF(NaN) # needs sage.symbolic [.. NaN ..] Let's take a closer, formal look at the question style. In its full @@ -1620,11 +1622,11 @@ cdef class RealIntervalFieldElement(RingElement): '3.14223?64' sage: pi_appr.str(base=36) '3.6?' - sage: RIF(NaN) + sage: RIF(NaN) # needs sage.symbolic [.. NaN ..] - sage: RIF(pi, infinity) + sage: RIF(pi, infinity) # needs sage.symbolic [3.1415926535897931 .. +infinity] - sage: RIF(-infinity, pi) + sage: RIF(-infinity, pi) # needs sage.symbolic [-infinity .. 3.1415926535897936] sage: RealIntervalField(210)(3).sqrt() 1.732050807568877293527446341505872366942805253810380628055806980? @@ -1632,7 +1634,7 @@ cdef class RealIntervalFieldElement(RingElement): 1.732050807568878? sage: RIF(3).sqrt() 1.732050807568878? - sage: RIF(0, 3^-150) + sage: RIF(0, 3^-150) # needs sage.symbolic 1.?e-71 TESTS: @@ -2311,7 +2313,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: RIF(1,2).endpoints() (1.00000000000000, 2.00000000000000) - sage: RIF(pi).endpoints() + sage: RIF(pi).endpoints() # needs sage.symbolic (3.14159265358979, 3.14159265358980) sage: a = CIF(RIF(1,2), RIF(3,4)) sage: a.real().endpoints() @@ -2342,7 +2344,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: RIF(1,2).edges() (1, 2) - sage: RIF(pi).edges() + sage: RIF(pi).edges() # needs sage.symbolic (3.1415926535897932?, 3.1415926535897936?) """ left = self._new() @@ -2363,7 +2365,7 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(1, pi).absolute_diameter() + sage: RIF(1, pi).absolute_diameter() # needs sage.symbolic 2.14159265358979 """ cdef RealNumber x @@ -2378,7 +2380,7 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(1, pi).relative_diameter() + sage: RIF(1, pi).relative_diameter() # needs sage.symbolic 1.03418797197910 """ cdef RealNumber x @@ -2399,17 +2401,17 @@ cdef class RealIntervalFieldElement(RingElement): 1.00000000000000 sage: RIF(1, 2).relative_diameter() 0.666666666666667 - sage: RIF(pi).diameter() + sage: RIF(pi).diameter() # needs sage.symbolic 1.41357985842823e-16 - sage: RIF(pi).absolute_diameter() + sage: RIF(pi).absolute_diameter() # needs sage.symbolic 4.44089209850063e-16 - sage: RIF(pi).relative_diameter() + sage: RIF(pi).relative_diameter() # needs sage.symbolic 1.41357985842823e-16 - sage: (RIF(pi) - RIF(3, 22/7)).diameter() + sage: (RIF(pi) - RIF(3, 22/7)).diameter() # needs sage.symbolic 0.142857142857144 - sage: (RIF(pi) - RIF(3, 22/7)).absolute_diameter() + sage: (RIF(pi) - RIF(3, 22/7)).absolute_diameter() # needs sage.symbolic 0.142857142857144 - sage: (RIF(pi) - RIF(3, 22/7)).relative_diameter() + sage: (RIF(pi) - RIF(3, 22/7)).relative_diameter() # needs sage.symbolic 2.03604377705518 """ cdef RealNumber x @@ -2431,31 +2433,31 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).fp_rank_diameter() + sage: RIF(pi).fp_rank_diameter() # needs sage.symbolic 1 sage: RIF(12345).fp_rank_diameter() 0 - sage: RIF(-sqrt(2)).fp_rank_diameter() + sage: RIF(-sqrt(2)).fp_rank_diameter() # needs sage.symbolic 1 sage: RIF(5/8).fp_rank_diameter() 0 sage: RIF(5/7).fp_rank_diameter() 1 - sage: a = RIF(pi)^12345; a + sage: a = RIF(pi)^12345; a # needs sage.symbolic 2.06622879260?e6137 - sage: a.fp_rank_diameter() + sage: a.fp_rank_diameter() # needs sage.symbolic 30524 - sage: (RIF(sqrt(2)) - RIF(sqrt(2))).fp_rank_diameter() + sage: (RIF(sqrt(2)) - RIF(sqrt(2))).fp_rank_diameter() # needs sage.symbolic 9671406088542672151117826 # 32-bit 41538374868278620559869609387229186 # 64-bit Just because we have the best possible interval, doesn't mean the interval is actually small:: - sage: a = RIF(pi)^12345678901234567890; a + sage: a = RIF(pi)^12345678901234567890; a # needs sage.symbolic [2.0985787164673874e323228496 .. +infinity] # 32-bit [5.8756537891115869e1388255822130839282 .. +infinity] # 64-bit - sage: a.fp_rank_diameter() + sage: a.fp_rank_diameter() # needs sage.symbolic 1 """ return self.lower().fp_rank_delta(self.upper()) @@ -2469,7 +2471,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: RIF(3).is_exact() True - sage: RIF(2*pi).is_exact() + sage: RIF(2*pi).is_exact() # needs sage.symbolic False """ return mpfr_equal_p(&self.value.left, &self.value.right) @@ -2543,6 +2545,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: b.lower(), b.upper() (1.50000000000000, 2.00000000000000) + sage: # needs sage.symbolic sage: I = RIF(e, pi) sage: a, b = I.bisection() sage: a.intersection(b) == RIF(I.center()) @@ -3372,9 +3375,9 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).unique_floor() + sage: RIF(pi).unique_floor() # needs sage.symbolic 3 - sage: RIF(100*pi).unique_floor() + sage: RIF(100*pi).unique_floor() # needs sage.symbolic 314 sage: RIF(100, 200).unique_floor() Traceback (most recent call last): @@ -3403,9 +3406,9 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).unique_ceil() + sage: RIF(pi).unique_ceil() # needs sage.symbolic 4 - sage: RIF(100*pi).unique_ceil() + sage: RIF(100*pi).unique_ceil() # needs sage.symbolic 315 sage: RIF(100, 200).unique_ceil() Traceback (most recent call last): @@ -3434,9 +3437,9 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).unique_round() + sage: RIF(pi).unique_round() # needs sage.symbolic 3 - sage: RIF(1000*pi).unique_round() + sage: RIF(1000*pi).unique_round() # needs sage.symbolic 3142 sage: RIF(100, 200).unique_round() Traceback (most recent call last): @@ -3448,7 +3451,7 @@ cdef class RealIntervalFieldElement(RingElement): ValueError: interval does not have a unique round (nearest integer) sage: RIF(0.7, 1.2).unique_round() 1 - sage: RIF(-pi).unique_round() + sage: RIF(-pi).unique_round() # needs sage.symbolic -3 sage: (RIF(4.5).unique_round(), RIF(-4.5).unique_round()) (5, -5) @@ -3521,13 +3524,13 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).unique_integer() + sage: RIF(pi).unique_integer() # needs sage.symbolic Traceback (most recent call last): ... ValueError: interval contains no integer - sage: RIF(pi, pi+1).unique_integer() + sage: RIF(pi, pi+1).unique_integer() # needs sage.symbolic 4 - sage: RIF(pi, pi+2).unique_integer() + sage: RIF(pi, pi+2).unique_integer() # needs sage.symbolic Traceback (most recent call last): ... ValueError: interval contains more than one integer @@ -3577,9 +3580,9 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RealIntervalField(10)(pi).simplest_rational() + sage: RealIntervalField(10)(pi).simplest_rational() # needs sage.symbolic 22/7 - sage: RealIntervalField(20)(pi).simplest_rational() + sage: RealIntervalField(20)(pi).simplest_rational() # needs sage.symbolic 355/113 sage: RIF(0.123, 0.567).simplest_rational() 1/2 @@ -3828,7 +3831,7 @@ cdef class RealIntervalFieldElement(RingElement): True sage: RIF(0) == RIF(0) True - sage: RIF(pi) == RIF(pi) + sage: RIF(pi) == RIF(pi) # needs sage.symbolic False sage: RIF(0, 1) == RIF(1, 2) False @@ -3852,7 +3855,7 @@ cdef class RealIntervalFieldElement(RingElement): False sage: RIF(0) != RIF(0) False - sage: RIF(pi) != RIF(pi) + sage: RIF(pi) != RIF(pi) # needs sage.symbolic False sage: RIF(0, 1) != RIF(1, 2) False @@ -3983,7 +3986,7 @@ cdef class RealIntervalFieldElement(RingElement): True sage: 1.0 in RIF(0, 2) True - sage: pi in RIF(3.1415, 3.1416) + sage: pi in RIF(3.1415, 3.1416) # needs sage.symbolic True sage: 22/7 in RIF(3.1415, 3.1416) False @@ -4115,7 +4118,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: a = RIF(-1, 1).min(0).endpoints() sage: a[0] == -1.0 and a[1].abs() == 0.0 # in MPFI, the sign of 0.0 is not specified True - sage: RIF(-1, 1).min(pi).endpoints() + sage: RIF(-1, 1).min(pi).endpoints() # needs sage.symbolic (-1.00000000000000, 1.00000000000000) sage: RIF(-1, 1).min(RIF(-100, 100)).endpoints() (-100.000000000000, 1.00000000000000) @@ -4400,10 +4403,10 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: sage: R = RealIntervalField(17) - sage: x = R((-e,pi)) - sage: x2 = x^2; x2.lower(), x2.upper() + sage: x = R((-e, pi)) # needs sage.symbolic + sage: x2 = x^2; x2.lower(), x2.upper() # needs sage.symbolic (0.0000, 9.870) - sage: x3 = x^3; x3.lower(), x3.upper() + sage: x3 = x^3; x3.lower(), x3.upper() # needs sage.symbolic (-26.83, 31.01) """ if exponent == 2: @@ -4616,7 +4619,8 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: t=RIF(pi)/2 + sage: # needs sage.symbolic + sage: t = RIF(pi)/2 sage: t.cos() 0.?e-15 sage: t.cos().str(style='brackets') @@ -5070,7 +5074,7 @@ cdef class RealIntervalFieldElement(RingElement): (2.00000000000000, 6.00000000000000) sage: RIF(-1/2).gamma() -3.54490770181104? - sage: gamma(-1/2).n(100) in RIF(-1/2).gamma() + sage: gamma(-1/2).n(100) in RIF(-1/2).gamma() # needs sage.symbolic True sage: RIF1000 = RealIntervalField(1000) sage: 0 in (RIF1000(RealField(2000)(-19/3).gamma()) - RIF1000(-19/3).gamma()) diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 15fa8bdffe9..ac3a41ce5ef 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -3329,22 +3329,23 @@ cdef class RealNumber(sage.structure.element.RingElement): Pari does maintain the same 250-bit number on both 32-bit and 64-bit platforms:: - sage: RealField(250).pi().__pari__() # needs sage.libs.pari + sage: # needs sage.libs.pari + sage: RealField(250).pi().__pari__() 3.14159265358979 - sage: RR(0.0).__pari__() # needs sage.libs.pari + sage: RR(0.0).__pari__() 0.E-19 - sage: RR(-1.234567).__pari__() # needs sage.libs.pari + sage: RR(-1.234567).__pari__() -1.23456700000000 - sage: RR(2.0).sqrt().__pari__() # needs sage.libs.pari + sage: RR(2.0).sqrt().__pari__() 1.41421356237310 - sage: RR(2.0).sqrt().__pari__().sage() # needs sage.libs.pari + sage: RR(2.0).sqrt().__pari__().sage() 1.41421356237309515 - sage: RR(2.0).sqrt().__pari__().sage().prec() # needs sage.libs.pari + sage: RR(2.0).sqrt().__pari__().sage().prec() 64 - sage: RealField(70)(pi).__pari__().sage().prec() # needs sage.libs.pari sage.symbolic + sage: RealField(70)(pi).__pari__().sage().prec() # needs sage.symbolic 96 # 32-bit 128 # 64-bit - sage: for i in range(100, 200): # needs sage.libs.pari + sage: for i in range(100, 200): ....: assert(RR(i).sqrt() == RR(i).sqrt().__pari__().sage()) TESTS: @@ -3359,11 +3360,12 @@ cdef class RealNumber(sage.structure.element.RingElement): Check that the largest and smallest exponents representable by PARI convert correctly:: - sage: a = pari(0.5) << (sys.maxsize+1)/4 # needs sage.libs.pari - sage: RR(a) >> (sys.maxsize+1)/4 # needs sage.libs.pari + sage: # needs sage.libs.pari + sage: a = pari(0.5) << (sys.maxsize+1)/4 + sage: RR(a) >> (sys.maxsize+1)/4 0.500000000000000 - sage: a = pari(0.5) >> (sys.maxsize-3)/4 # needs sage.libs.pari - sage: RR(a) << (sys.maxsize-3)/4 # needs sage.libs.pari + sage: a = pari(0.5) >> (sys.maxsize-3)/4 + sage: RR(a) << (sys.maxsize-3)/4 0.500000000000000 """ # This uses interfaces of MPFR and PARI which are documented diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 48f7e967326..8f2c55db2de 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -132,9 +132,9 @@ cdef class Ring(ParentWithGens): running ._test_some_elements() . . . pass running ._test_zero() . . . pass running ._test_zero_divisors() . . . pass - sage: TestSuite(QQ['x','y']).run(skip='_test_elements') - sage: TestSuite(ZZ['x','y']).run(skip='_test_elements') - sage: TestSuite(ZZ['x','y']['t']).run() + sage: TestSuite(QQ['x','y']).run(skip='_test_elements') # needs sage.libs.singular + sage: TestSuite(ZZ['x','y']).run(skip='_test_elements') # needs sage.libs.singular + sage: TestSuite(ZZ['x','y']['t']).run() # needs sage.libs.singular Test against another bug fixed in :trac:`9944`:: @@ -142,36 +142,38 @@ cdef class Ring(ParentWithGens): Join of Category of euclidean domains and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets sage: QQ['x','y'].category() - Join of Category of unique factorization domains and Category of commutative algebras over - (number fields and quotient fields and metric spaces) and Category of infinite sets - sage: PolynomialRing(MatrixSpace(QQ,2),'x').category() + Join of Category of unique factorization domains + and Category of commutative algebras + over (number fields and quotient fields and metric spaces) + and Category of infinite sets + sage: PolynomialRing(MatrixSpace(QQ, 2),'x').category() # needs sage.modules Category of infinite algebras over (finite dimensional algebras with basis over (number fields and quotient fields and metric spaces) and infinite sets) - sage: PolynomialRing(SteenrodAlgebra(2),'x').category() + sage: PolynomialRing(SteenrodAlgebra(2),'x').category() # needs sage.combinat sage.modules Category of infinite algebras over (super hopf algebras with basis over Finite Field of size 2 and supercocommutative super coalgebras over Finite Field of size 2) TESTS:: - sage: Zp(7)._repr_option('element_is_atomic') + sage: Zp(7)._repr_option('element_is_atomic') # needs sage.rings.padics False sage: QQ._repr_option('element_is_atomic') True - sage: CDF._repr_option('element_is_atomic') # optional - sage.rings.complex_double + sage: CDF._repr_option('element_is_atomic') # needs sage.rings.complex_double False Check that categories correctly implement `is_finite` and `cardinality`:: sage: QQ.is_finite() False - sage: GF(2^10, 'a').is_finite() # optional - sage.rings.finite_rings + sage: GF(2^10, 'a').is_finite() # needs sage.rings.finite_rings True sage: R. = GF(7)[] sage: R.is_finite() False - sage: S. = R.quo(x^2 + 1) # optional - sage.rings.finite_rings - sage: S.is_finite() # optional - sage.rings.finite_rings + sage: S. = R.quo(x^2 + 1) # needs sage.rings.finite_rings + sage: S.is_finite() # needs sage.rings.finite_rings True sage: Integers(7).cardinality() @@ -255,11 +257,11 @@ cdef class Ring(ParentWithGens): """ EXAMPLES:: - sage: QQ.base_extend(GF(7)) # optional - sage.rings.finite_rings + sage: QQ.base_extend(GF(7)) Traceback (most recent call last): ... TypeError: no base extension defined - sage: ZZ.base_extend(GF(7)) # optional - sage.rings.finite_rings + sage: ZZ.base_extend(GF(7)) Finite Field of size 7 """ if R.has_coerce_map_from(self): @@ -280,7 +282,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! # optional - sage.combinat sage.modules + sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! # needs sage.combinat sage.modules Category of algebras with basis over Rational Field Since a quotient of the integers is its own base ring, and during @@ -310,16 +312,17 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: F. = FreeAlgebra(ZZ, 3) # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q = F.quotient(I) # optional - sage.combinat sage.modules - sage: Q.ideal_monoid() # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: F. = FreeAlgebra(ZZ, 3) + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F + sage: Q = F.quotient(I) + sage: Q.ideal_monoid() Monoid of ideals of Quotient of Free Algebra on 3 generators (x, y, z) over Integer Ring by the ideal (x*y + y*z, x^2 + x*y - y*x - y^2) - sage: F. = FreeAlgebra(ZZ, implementation='letterplace') # optional - sage.combinat sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules - sage: Q = F.quo(I) # optional - sage.combinat sage.modules - sage: Q.ideal_monoid() # optional - sage.combinat sage.modules + sage: F. = FreeAlgebra(ZZ, implementation='letterplace') + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F + sage: Q = F.quo(I) + sage: Q.ideal_monoid() Monoid of ideals of Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Integer Ring by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) @@ -366,10 +369,10 @@ cdef class Ring(ParentWithGens): Here is an example over a non-commutative ring:: - sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules - sage: A.ideal(A.1, A.2^2) # optional - sage.combinat sage.modules + sage: A = SteenrodAlgebra(2) # needs sage.combinat sage.modules + sage: A.ideal(A.1, A.2^2) # needs sage.combinat sage.modules Twosided Ideal (Sq(2), Sq(2,2)) of mod 2 Steenrod algebra, milnor basis - sage: A.ideal(A.1, A.2^2, side='left') # optional - sage.combinat sage.modules + sage: A.ideal(A.1, A.2^2, side='left') # needs sage.combinat sage.modules Left Ideal (Sq(2), Sq(2,2)) of mod 2 Steenrod algebra, milnor basis TESTS: @@ -448,22 +451,23 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: R. = GF(7)[] # optional - sage.rings.finite_rings - sage: (x + y) * R # optional - sage.rings.finite_rings + 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 # optional - sage.rings.finite_rings + 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 The following was implemented in :trac:`7797`:: - sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules - sage: A * [A.1 + A.2, A.1^2] # optional - sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: A = SteenrodAlgebra(2) + sage: A * [A.1 + A.2, A.1^2] Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: [A.1 + A.2, A.1^2] * A # optional - sage.combinat sage.modules + sage: [A.1 + A.2, A.1^2] * A Right Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: A * [A.1 + A.2, A.1^2] * A # optional - sage.combinat sage.modules + sage: A * [A.1 + A.2, A.1^2] * A Twosided Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis """ @@ -521,24 +525,24 @@ cdef class Ring(ParentWithGens): sage: RR._ideal_class_() - sage: R. = GF(5)[] # optional - sage.rings.finite_rings - sage: R._ideal_class_(1) # optional - sage.rings.finite_rings + sage: R. = GF(5)[] + sage: R._ideal_class_(1) - sage: S = R.quo(x^3 - y^2) # optional - sage.rings.finite_rings - sage: S._ideal_class_(1) # optional - sage.rings.finite_rings + sage: S = R.quo(x^3 - y^2) + sage: S._ideal_class_(1) - sage: S._ideal_class_(2) # optional - sage.rings.finite_rings + sage: S._ideal_class_(2) - sage: T. = S[] # optional - sage.rings.finite_rings - sage: T._ideal_class_(5) # optional - sage.rings.finite_rings + sage: T. = S[] # needs sage.rings.finite_rings + sage: T._ideal_class_(5) # needs sage.rings.finite_rings - sage: T._ideal_class_(1) # optional - sage.rings.finite_rings + sage: T._ideal_class_(1) # needs sage.rings.finite_rings Since :trac:`7797`, non-commutative rings have ideals as well:: - sage: A = SteenrodAlgebra(2) - sage: A._ideal_class_() + sage: A = SteenrodAlgebra(2) # needs sage.combinat sage.modules + sage: A._ideal_class_() # needs sage.combinat sage.modules """ @@ -576,7 +580,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: Zp(7).unit_ideal() # optional - sage.rings.padics + sage: Zp(7).unit_ideal() # needs sage.rings.padics Principal ideal (1 + O(7^20)) of 7-adic Ring with capped relative precision 20 """ if self._unit_ideal is None: @@ -607,10 +611,11 @@ cdef class Ring(ParentWithGens): Make sure that :trac:`13644` is fixed:: - sage: K = Qp(3) # optional - sage.rings.padics - sage: R. = K[] # optional - sage.rings.padics - sage: L. = K.extension(a^2-3) # optional - sage.rings.padics - sage: L.ideal(a) # optional - sage.rings.padics + sage: # needs sage.rings.padics + sage: K = Qp(3) + sage: R. = K[] + sage: L. = K.extension(a^2-3) + sage: L.ideal(a) Principal ideal (1 + O(a^40)) of 3-adic Eisenstein Extension Field in a defined by a^2 - 3 """ @@ -678,8 +683,8 @@ cdef class Ring(ParentWithGens): True sage: QQ['x,y,z'].is_commutative() True - sage: Q. = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules - sage: Q.is_commutative() # optional - sage.combinat sage.modules + sage: Q. = QuaternionAlgebra(QQ, -1, -1) # needs sage.combinat sage.modules + sage: Q.is_commutative() # needs sage.combinat sage.modules False """ if self.is_zero(): @@ -706,7 +711,7 @@ cdef class Ring(ParentWithGens): sage: QQ.is_field() True - sage: GF(9, 'a').is_field() # optional - sage.rings.finite_rings + sage: GF(9, 'a').is_field() # needs sage.rings.finite_rings True sage: ZZ.is_field() False @@ -718,12 +723,12 @@ cdef class Ring(ParentWithGens): This illustrates the use of the ``proof`` parameter:: sage: R. = QQ[] - sage: S. = R.quo((b^3)) # optional - sage.libs.singular - sage: S.is_field(proof=True) # optional - sage.libs.singular + sage: S. = R.quo((b^3)) # needs sage.libs.singular + sage: S.is_field(proof=True) # needs sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_field(proof=False) # optional - sage.libs.singular + sage: S.is_field(proof=False) # needs sage.libs.singular False """ if self.is_zero(): @@ -750,9 +755,9 @@ cdef class Ring(ParentWithGens): True sage: ZZ.is_exact() True - sage: Qp(7).is_exact() # optional - sage.rings.padics + sage: Qp(7).is_exact() # needs sage.rings.padics False - sage: Zp(7, type='capped-abs').is_exact() # optional - sage.rings.padics + sage: Zp(7, type='capped-abs').is_exact() # needs sage.rings.padics False """ return True @@ -768,34 +773,34 @@ cdef class Ring(ParentWithGens): sage: ZZ.is_subring(QQ) True - sage: ZZ.is_subring(GF(19)) # optional - sage.rings.finite_rings + sage: ZZ.is_subring(GF(19)) False TESTS:: sage: QQ.is_subring(QQ['x']) True - sage: QQ.is_subring(GF(7)) # optional - sage.rings.finite_rings + sage: QQ.is_subring(GF(7)) False - sage: QQ.is_subring(CyclotomicField(7)) # optional - sage.rings.number_field + sage: QQ.is_subring(CyclotomicField(7)) # needs sage.rings.number_field True sage: QQ.is_subring(ZZ) False Every ring is a subring of itself, :trac:`17287`:: - sage: QQbar.is_subring(QQbar) # optional - sage.rings.number_field + sage: QQbar.is_subring(QQbar) # needs sage.rings.number_field True - sage: RR.is_subring(RR) # optional - sage.rings.real_mpfr + sage: RR.is_subring(RR) True - sage: CC.is_subring(CC) # optional - sage.rings.real_mpfr + sage: CC.is_subring(CC) # needs sage.rings.real_mpfr True sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^3 - x + 1/10) # optional - sage.rings.number_field - sage: K.is_subring(K) # optional - sage.rings.number_field + sage: K. = NumberField(x^3 - x + 1/10) # needs sage.rings.number_field + sage: K.is_subring(K) # needs sage.rings.number_field True - sage: R. = RR[] # optional - sage.rings.real_mpfr - sage: R.is_subring(R) # optional - sage.rings.real_mpfr + sage: R. = RR[] + sage: R.is_subring(R) True """ if self is other: @@ -814,15 +819,15 @@ cdef class Ring(ParentWithGens): sage: QQ.is_prime_field() True - sage: GF(3).is_prime_field() # optional - sage.rings.finite_rings + sage: GF(3).is_prime_field() True - sage: GF(9, 'a').is_prime_field() # optional - sage.rings.finite_rings + sage: GF(9, 'a').is_prime_field() # needs sage.rings.finite_rings False sage: ZZ.is_prime_field() False sage: QQ['x'].is_prime_field() False - sage: Qp(19).is_prime_field() # optional - sage.rings.padics + sage: Qp(19).is_prime_field() # needs sage.rings.padics False """ return False @@ -853,24 +858,24 @@ cdef class Ring(ParentWithGens): True sage: Integers(8).is_integral_domain() False - sage: Zp(7).is_integral_domain() # optional - sage.rings.padics + sage: Zp(7).is_integral_domain() # needs sage.rings.padics True - sage: Qp(7).is_integral_domain() # optional - sage.rings.padics + sage: Qp(7).is_integral_domain() # needs sage.rings.padics True sage: R. = QQ[] - sage: S. = R.quo((b^3)) # optional - sage.libs.singular - sage: S.is_integral_domain() # optional - sage.libs.singular + sage: S. = R.quo((b^3)) # needs sage.libs.singular + sage: S.is_integral_domain() # needs sage.libs.singular False This illustrates the use of the ``proof`` parameter:: sage: R. = ZZ[] - sage: S. = R.quo((b^3)) # optional - sage.libs.singular - sage: S.is_integral_domain(proof=True) # optional - sage.libs.singular + sage: S. = R.quo((b^3)) # needs sage.libs.singular + sage: S.is_integral_domain(proof=True) # needs sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof=False) # optional - sage.libs.singular + sage: S.is_integral_domain(proof=False) # needs sage.libs.singular False TESTS: @@ -878,21 +883,22 @@ cdef class Ring(ParentWithGens): Make sure :trac:`10481` is fixed:: sage: x = polygen(ZZ, 'x') - sage: R. = ZZ['x'].quo(x^2) # optional - sage.libs.pari - sage: R.fraction_field() # optional - sage.libs.pari + sage: R. = ZZ['x'].quo(x^2) # needs sage.libs.pari + sage: R.fraction_field() # needs sage.libs.pari Traceback (most recent call last): ... TypeError: self must be an integral domain. - sage: R.is_integral_domain() # optional - sage.libs.pari + sage: R.is_integral_domain() # needs sage.libs.pari False Forward the proof flag to ``is_field``, see :trac:`22910`:: - sage: R1. = GF(5)[] # optional - sage.rings.finite_rings - sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.rings.finite_rings - sage: R2. = F1[] # optional - sage.rings.finite_rings - sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.rings.finite_rings - sage: F2.is_integral_domain(False) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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) False """ if self.is_field(proof): @@ -925,7 +931,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: GF(19).order() # optional - sage.rings.finite_rings + sage: GF(19).order() 19 sage: QQ.order() +Infinity @@ -957,29 +963,29 @@ cdef class Ring(ParentWithGens): -1 sage: QQ.zeta(1) 1 - sage: CyclotomicField(6).zeta(6) # optional - sage.rings.number_field + sage: CyclotomicField(6).zeta(6) # needs sage.rings.number_field zeta6 - sage: CyclotomicField(3).zeta(3) # optional - sage.rings.number_field + sage: CyclotomicField(3).zeta(3) # needs sage.rings.number_field zeta3 - sage: CyclotomicField(3).zeta(3).multiplicative_order() # optional - sage.rings.number_field + sage: CyclotomicField(3).zeta(3).multiplicative_order() # needs sage.rings.number_field 3 - sage: a = GF(7).zeta(); a # optional - sage.rings.finite_rings + sage: a = GF(7).zeta(); a # needs sage.rings.finite_rings 3 - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: a.multiplicative_order() # needs sage.rings.finite_rings 6 - sage: a = GF(49,'z').zeta(); a # optional - sage.rings.finite_rings + sage: a = GF(49,'z').zeta(); a # needs sage.rings.finite_rings z - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: a.multiplicative_order() # needs sage.rings.finite_rings 48 - sage: a = GF(49,'z').zeta(2); a # optional - sage.rings.finite_rings + sage: a = GF(49,'z').zeta(2); a # needs sage.rings.finite_rings 6 - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: a.multiplicative_order() # needs sage.rings.finite_rings 2 sage: QQ.zeta(3) Traceback (most recent call last): ... ValueError: no n-th root of unity in rational field - sage: Zp(7, prec=8).zeta() # optional - sage.rings.padics + sage: Zp(7, prec=8).zeta() # needs sage.rings.padics 3 + 4*7 + 6*7^2 + 3*7^3 + 2*7^5 + 6*7^6 + 2*7^7 + O(7^8) TESTS:: @@ -989,7 +995,7 @@ cdef class Ring(ParentWithGens): 1 sage: Ring.zeta(QQ, 2) -1 - sage: Ring.zeta(QQ, 3) # optional - sage.libs.pari + sage: Ring.zeta(QQ, 3) # needs sage.libs.pari Traceback (most recent call last): ... ValueError: no 3rd root of unity in Rational Field @@ -1026,13 +1032,13 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: CyclotomicField(19).zeta_order() # optional - sage.rings.number_field + sage: CyclotomicField(19).zeta_order() # needs sage.rings.number_field 38 - sage: GF(19).zeta_order() # optional - sage.rings.finite_rings + sage: GF(19).zeta_order() 18 - sage: GF(5^3,'a').zeta_order() # optional - sage.rings.finite_rings + sage: GF(5^3,'a').zeta_order() # needs sage.rings.finite_rings 124 - sage: Zp(7, prec=8).zeta_order() # optional - sage.rings.padics + sage: Zp(7, prec=8).zeta_order() # needs sage.rings.padics 6 """ return self.zeta().multiplicative_order() @@ -1123,9 +1129,9 @@ cdef class Ring(ParentWithGens): sage: RDF.epsilon() 2.220446049250313e-16 - sage: ComplexField(53).epsilon() # optional - sage.rings.real_mpfr + sage: ComplexField(53).epsilon() # needs sage.rings.real_mpfr 2.22044604925031e-16 - sage: RealField(10).epsilon() # optional - sage.rings.real_mpfr + sage: RealField(10).epsilon() # needs sage.rings.real_mpfr 0.0020 For exact rings, zero is returned:: @@ -1135,14 +1141,14 @@ cdef class Ring(ParentWithGens): This also works over derived rings:: - sage: RR['x'].epsilon() # optional - sage.rings.real_mpfr + sage: RR['x'].epsilon() # needs sage.rings.real_mpfr 2.22044604925031e-16 sage: QQ['x'].epsilon() 0 For the symbolic ring, there is no reasonable answer:: - sage: SR.epsilon() # optional - sage.symbolic + sage: SR.epsilon() # needs sage.symbolic Traceback (most recent call last): ... NotImplementedError @@ -1200,11 +1206,11 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: R. = GF(3)[] # optional - sage.rings.finite_rings - sage: R.localization((x*y, x**2 + y**2)) # optional - sage.rings.finite_rings + sage: R. = GF(3)[] + sage: R.localization((x*y, x**2 + y**2)) # needs sage.rings.finite_rings Multivariate Polynomial Ring in x, y over Finite Field of size 3 localized at (y, x, x^2 + y^2) - sage: ~y in _ # optional - sage.rings.finite_rings + sage: ~y in _ # needs sage.rings.finite_rings True """ if not self.is_integral_domain(): @@ -1278,11 +1284,11 @@ cdef class CommutativeRing(Ring): sage: QQ.is_commutative() True - sage: ZpCA(7).is_commutative() # optional - sage.rings.padics + sage: ZpCA(7).is_commutative() # needs sage.rings.padics True - sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # optional - sage.combinat sage.modules + sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # needs sage.combinat sage.modules Quaternion Algebra (-1, -3) with base ring Rational Field - sage: A.is_commutative() # optional - sage.combinat sage.modules + sage: A.is_commutative() # needs sage.combinat sage.modules False """ return True @@ -1318,18 +1324,19 @@ cdef class CommutativeRing(Ring): All orders in number fields have Krull dimension 1, including non-maximal orders:: - sage: K. = QuadraticField(-1) # optional - sage.rings.number_field - sage: R = K.maximal_order(); R # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = QuadraticField(-1) + sage: R = K.maximal_order(); R Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.krull_dimension() # optional - sage.rings.number_field + sage: R.krull_dimension() 1 - sage: R = K.order(2*i); R # optional - sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: R.is_maximal() False - sage: R.krull_dimension() # optional - sage.rings.number_field + sage: R.krull_dimension() 1 """ raise NotImplementedError @@ -1374,16 +1381,17 @@ cdef class CommutativeRing(Ring): sage: R = QQ['x'] sage: y = polygen(R) - sage: R.extension(y^2 - 5, 'a') # optional - sage.libs.pari + sage: R.extension(y^2 - 5, 'a') # needs sage.libs.pari Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 :: - sage: P. = PolynomialRing(GF(5)) # optional - sage.rings.finite_rings - sage: F. = GF(5).extension(x^2 - 2) # optional - sage.rings.finite_rings - sage: P. = F[] # optional - sage.rings.finite_rings - sage: R. = F.extension(t^2 - a); R # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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 """ @@ -1421,19 +1429,19 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings - sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + 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) # optional - sage.rings.finite_rings + sage: Frob(u) u^5 We can specify a power:: - sage: f = K.frobenius_endomorphism(2); f # optional - sage.rings.finite_rings + 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) # optional - sage.rings.finite_rings + sage: f(1+u) 1 + u^25 """ from .morphism import FrobeniusEndomorphism_generic @@ -1468,21 +1476,21 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: M = R.derivation_module(); M # optional - sage.modules + sage: M = R.derivation_module(); M # needs sage.modules Module of derivations over Multivariate Polynomial Ring in x, y, z over Rational Field - sage: M.gens() # optional - sage.modules + sage: M.gens() # needs sage.modules (d/dx, d/dy, d/dz) We can specify a different codomain:: sage: K = R.fraction_field() - sage: M = R.derivation_module(K); M # optional - sage.modules + sage: M = R.derivation_module(K); M # needs sage.modules Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field - sage: M.gen() / x # optional - sage.modules + sage: M.gen() / x # needs sage.modules 1/x*d/dx Here is an example with a non-canonical defining morphism:: @@ -1495,32 +1503,32 @@ cdef class CommutativeRing(Ring): Defn: x |--> 0 y |--> 1 z |--> 2 - sage: M = R.derivation_module(ev) # optional - sage.modules - sage: M # optional - sage.modules + sage: M = R.derivation_module(ev) # needs sage.modules + sage: M # needs sage.modules Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field Elements in `M` acts as derivations at `(0,1,2)`:: - sage: Dx = M.gen(0); Dx # optional - sage.modules + sage: Dx = M.gen(0); Dx # needs sage.modules d/dx - sage: Dy = M.gen(1); Dy # optional - sage.modules + sage: Dy = M.gen(1); Dy # needs sage.modules d/dy - sage: Dz = M.gen(2); Dz # optional - sage.modules + sage: Dz = M.gen(2); Dz # needs sage.modules d/dz sage: f = x^2 + y^2 + z^2 - sage: Dx(f) # = 2*x evaluated at (0,1,2) # optional - sage.modules + sage: Dx(f) # = 2*x evaluated at (0,1,2) # needs sage.modules 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules + sage: Dy(f) # = 2*y evaluated at (0,1,2) # needs sage.modules 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) # optional - sage.modules + sage: Dz(f) # = 2*z evaluated at (0,1,2) # needs sage.modules 4 An example with a twisting homomorphism:: sage: theta = R.hom([x^2, y^2, z^2]) - sage: M = R.derivation_module(twist=theta); M # optional - sage.modules + sage: M = R.derivation_module(twist=theta); M # needs 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) @@ -1559,23 +1567,23 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: R.derivation() # optional - sage.modules + sage: R.derivation() # needs sage.modules d/dx In that case, ``arg`` could be a generator:: - sage: R.derivation(y) # optional - sage.modules + sage: R.derivation(y) # needs sage.modules d/dy or a list of coefficients:: - sage: R.derivation([1,2,3]) # optional - sage.modules + sage: R.derivation([1,2,3]) # needs sage.modules d/dx + 2*d/dy + 3*d/dz It is not possible to define derivations with respect to a polynomial which is not a variable:: - sage: R.derivation(x^2) # optional - sage.modules + sage: R.derivation(x^2) # needs sage.modules Traceback (most recent call last): ... ValueError: unable to create the derivation @@ -1584,18 +1592,18 @@ cdef class CommutativeRing(Ring): sage: R. = QQ[] sage: theta = R.hom([x^2, y^2, z^2]) - sage: f = R.derivation(twist=theta); f # optional - sage.modules + sage: f = R.derivation(twist=theta); f # needs sage.modules 0 - sage: f.parent() # optional - sage.modules + sage: f.parent() # needs sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) Specifying a scalar, the returned twisted derivation is the corresponding multiple of `\theta - id`:: - sage: R.derivation(1, twist=theta) # optional - sage.modules + sage: R.derivation(1, twist=theta) # needs sage.modules [x |--> x^2, y |--> y^2, z |--> z^2] - id - sage: R.derivation(x, twist=theta) # optional - sage.modules + sage: R.derivation(x, twist=theta) # needs sage.modules x*([x |--> x^2, y |--> y^2, z |--> z^2] - id) """ @@ -1713,9 +1721,9 @@ cdef class IntegralDomain(CommutativeRing): True sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field + sage: QQbar.is_integrally_closed() # needs sage.rings.number_field True - sage: GF(5).is_integrally_closed() # optional - sage.rings.finite_rings + sage: GF(5).is_integrally_closed() True sage: Z5 = Integers(5); Z5 Ring of integers modulo 5 @@ -1732,7 +1740,7 @@ cdef class IntegralDomain(CommutativeRing): EXAMPLES:: - sage: GF(7).is_field() # optional - sage.rings.finite_rings + sage: GF(7).is_field() True The following examples have their own ``is_field`` implementations:: @@ -1803,9 +1811,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.krull_dimension() 1 sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field - sage: OK = K.ring_of_integers() # optional - sage.rings.number_field - sage: OK.krull_dimension() # optional - sage.rings.number_field + sage: K = NumberField(x^2 + 1, 's') # needs sage.rings.number_field + sage: OK = K.ring_of_integers() # needs sage.rings.number_field + sage: OK.krull_dimension() # needs sage.rings.number_field 1 The following are not Dedekind domains but have @@ -1822,13 +1830,14 @@ cdef class DedekindDomain(IntegralDomain): sage: U.krull_dimension() 4 - sage: K. = QuadraticField(-1) # optional - sage.rings.number_field - sage: R = K.order(2*i); R # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + 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() # optional - sage.rings.number_field + sage: R.is_maximal() False - sage: R.krull_dimension() # optional - sage.rings.number_field + sage: R.krull_dimension() 1 """ return 1 @@ -1848,16 +1857,16 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_integrally_closed() True sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field - sage: OK = K.ring_of_integers() # optional - sage.rings.number_field - sage: OK.is_integrally_closed() # optional - sage.rings.number_field + sage: K = NumberField(x^2 + 1, 's') # needs sage.rings.number_field + sage: OK = K.ring_of_integers() # needs sage.rings.number_field + sage: OK.is_integrally_closed() # needs sage.rings.number_field True These, however, are not Dedekind domains:: sage: QQ.is_integrally_closed() True - sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() # optional - sage.rings.number_field sage.symbolic + sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() # needs sage.rings.number_field sage.symbolic False sage: T. = PolynomialRing(QQ, 2); T Multivariate Polynomial Ring in x, y over Rational Field @@ -1873,12 +1882,12 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field - sage: OK = K.ring_of_integers() # optional - sage.rings.number_field - sage: OK.integral_closure() # optional - sage.rings.number_field + sage: K = NumberField(x^2 + 1, 's') # needs sage.rings.number_field + sage: OK = K.ring_of_integers() # needs sage.rings.number_field + sage: OK.integral_closure() # needs sage.rings.number_field Gaussian Integers in Number Field in s with defining polynomial x^2 + 1 - sage: OK.integral_closure() == OK # optional - sage.rings.number_field + sage: OK.integral_closure() == OK # needs sage.rings.number_field True sage: QQ.integral_closure() == QQ @@ -1898,9 +1907,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_noetherian() True sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field - sage: OK = K.ring_of_integers() # optional - sage.rings.number_field - sage: OK.is_noetherian() # optional - sage.rings.number_field + sage: K = NumberField(x^2 + 1, 's') # needs sage.rings.number_field + sage: OK = K.ring_of_integers() # needs sage.rings.number_field + sage: OK.is_noetherian() # needs sage.rings.number_field True sage: QQ.is_noetherian() True @@ -1924,7 +1933,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: Zp(5).is_noetherian() # optional - sage.rings.padics + sage: Zp(5).is_noetherian() # needs sage.rings.padics True """ return True @@ -1935,7 +1944,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: QQ.class_group() # optional - sage.groups + sage: QQ.class_group() # needs sage.groups Trivial Abelian group """ from sage.groups.abelian_gps.abelian_group import AbelianGroup @@ -1981,22 +1990,22 @@ cdef class PrincipalIdealDomain(IntegralDomain): coercible:: sage: R. = PolynomialRing(QQ) - sage: S. = NumberField(x^2 - 2, 'a') # optional - sage.rings.number_field - sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) # optional - sage.rings.number_field - sage: print(f); print(g) # optional - sage.rings.number_field + sage: S. = NumberField(x^2 - 2, 'a') # needs sage.rings.number_field + sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) # needs sage.rings.number_field + sage: print(f); print(g) # needs sage.rings.number_field x^2 - 2 x^3 - a*x^2 - 2*x + 2*a - sage: f in R # optional - sage.rings.number_field + sage: f in R # needs sage.rings.number_field True - sage: g in R # optional - sage.rings.number_field + sage: g in R # needs sage.rings.number_field False - sage: R.gcd(f, g) # optional - sage.rings.number_field + sage: R.gcd(f, g) # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce 2*a to a rational - sage: R.base_extend(S).gcd(f,g) # optional - sage.rings.number_field + sage: R.base_extend(S).gcd(f,g) # needs sage.rings.number_field x^2 - 2 - sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # optional - sage.rings.number_field + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # needs sage.rings.number_field x - a """ if coerce: @@ -2089,7 +2098,7 @@ cpdef bint _is_Field(x) except -2: True sage: _is_Field(ZZ) False - sage: _is_Field(pAdicField(2)) # optional - sage.rings.padics + sage: _is_Field(pAdicField(2)) # needs sage.rings.padics True sage: _is_Field(5) False @@ -2131,14 +2140,14 @@ cdef class Field(PrincipalIdealDomain): sage: QQ.fraction_field() Rational Field - sage: RR.fraction_field() # optional - sage.rings.real_mpfr + sage: RR.fraction_field() # needs sage.rings.real_mpfr Real Field with 53 bits of precision - sage: CC.fraction_field() # optional - sage.rings.real_mpfr + sage: CC.fraction_field() # needs sage.rings.real_mpfr Complex Field with 53 bits of precision sage: x = polygen(ZZ, 'x') - sage: F = NumberField(x^2 + 1, 'i') # optional - sage.rings.number_field - sage: F.fraction_field() # optional - sage.rings.number_field + sage: F = NumberField(x^2 + 1, 'i') # needs sage.rings.number_field + sage: F.fraction_field() # needs sage.rings.number_field Number Field in i with defining polynomial x^2 + 1 """ return self @@ -2151,10 +2160,10 @@ cdef class Field(PrincipalIdealDomain): sage: QQ._pseudo_fraction_field() Rational Field - sage: K = GF(5) # optional - sage.rings.finite_rings - sage: K._pseudo_fraction_field() # optional - sage.rings.finite_rings + sage: K = GF(5) + sage: K._pseudo_fraction_field() Finite Field of size 5 - sage: K._pseudo_fraction_field() is K # optional - sage.rings.finite_rings + sage: K._pseudo_fraction_field() is K True """ return self @@ -2266,8 +2275,8 @@ cdef class Field(PrincipalIdealDomain): EXAMPLES:: - sage: k = GF(9, 'a') # optional - sage.rings.finite_rings - sage: k.prime_subfield() # optional - sage.rings.finite_rings + sage: k = GF(9, 'a') # needs sage.rings.finite_rings + sage: k.prime_subfield() # needs sage.rings.finite_rings Finite Field of size 3 """ if self.characteristic() == 0: @@ -2307,7 +2316,7 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A # optional - sage.modules + sage: A = Algebra(ZZ); A # needs sage.modules """ # This is a low-level class. For performance, we trust that the category @@ -2327,12 +2336,13 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A # optional - sage.modules + sage: # needs sage.modules + sage: A = Algebra(ZZ); A - sage: A.characteristic() # optional - sage.modules + sage: A.characteristic() 0 - sage: A = Algebra(GF(7^3, 'a')) # optional - sage.rings.finite_rings sage.modules - sage: A.characteristic() # optional - sage.rings.finite_rings sage.modules + sage: A = Algebra(GF(7^3, 'a')) # needs sage.rings.finite_rings + sage: A.characteristic() # needs sage.rings.finite_rings 7 """ return self.base_ring().characteristic() @@ -2347,16 +2357,16 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: B = QuaternionAlgebra(2) # optional - sage.combinat sage.modules - sage: B.has_standard_involution() # optional - sage.combinat sage.modules + sage: B = QuaternionAlgebra(2) # needs sage.combinat sage.modules + sage: B.has_standard_involution() # needs sage.combinat sage.modules True sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x**2 - 2) # optional - sage.rings.number_field - sage: A = QuaternionAlgebra(K, -2, 5) # optional - sage.rings.number_field sage.combinat sage.modules - sage: A.has_standard_involution() # optional - sage.rings.number_field sage.combinat sage.modules + sage: K. = NumberField(x**2 - 2) # needs sage.rings.number_field + sage: A = QuaternionAlgebra(K, -2, 5) # needs sage.combinat sage.modules sage.rings.number_field + sage: A.has_standard_involution() # needs sage.combinat sage.modules sage.rings.number_field True - sage: L. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules - sage: L.has_standard_involution() # optional - sage.combinat sage.modules + sage: L. = FreeAlgebra(QQ, 2) # needs sage.combinat sage.modules + sage: L.has_standard_involution() # needs sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: has_standard_involution is not implemented for this algebra @@ -2410,7 +2420,7 @@ cdef class CommutativeAlgebra(CommutativeRing): sage: sage.rings.ring.CommutativeAlgebra(QQ) - sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ, -1, -1)) # optional - sage.combinat sage.modules + sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ, -1, -1)) # needs sage.combinat sage.modules Traceback (most recent call last): ... TypeError: base ring must be a commutative ring @@ -2457,8 +2467,8 @@ def is_Ring(x): sage: from sage.rings.ring import is_Ring sage: is_Ring(ZZ) True - sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules - sage: is_Ring(MS) # optional - sage.modules + sage: MS = MatrixSpace(QQ, 2) # needs sage.modules + sage: is_Ring(MS) # needs sage.modules True """ return x in _Rings diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index 4b88454f611..3f4acbef798 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -11,39 +11,40 @@ that is `L`. For example, the following line constructs the extension of finite fields `\mathbf{F}_{5^4}/\mathbf{F}_{5^2}`:: - sage: GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings + sage: GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base By default, Sage reuses the canonical generator of the top ring (here `z_4 \in \mathbf{F}_{5^4}`), together with its name. However, the user can customize them by passing in appropriate arguments:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: k = GF(5^4) # optional - sage.rings.finite_rings - sage: z4 = k.gen() # optional - sage.rings.finite_rings - sage: K. = k.over(F, gen=1-z4); K # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: k = GF(5^4) + sage: z4 = k.gen() + sage: K. = k.over(F, gen=1-z4); K Field in a with defining polynomial x^2 + z2*x + 4 over its base The base of the extension is available via the method :meth:`base` (or equivalently :meth:`base_ring`):: - sage: K.base() # optional - sage.rings.finite_rings + sage: K.base() # needs sage.rings.finite_rings Finite Field in z2 of size 5^2 It is also possible to build an extension on top of another extension, obtaining this way a tower of extensions:: - sage: L. = GF(5^8).over(K); L # optional - sage.rings.finite_rings + sage: L. = GF(5^8).over(K); L # needs sage.rings.finite_rings Field in b with defining polynomial x^2 + (4*z2 + 3*a)*x + 1 - a over its base - sage: L.base() # optional - sage.rings.finite_rings + sage: L.base() # needs sage.rings.finite_rings Field in a with defining polynomial x^2 + z2*x + 4 over its base - sage: L.base().base() # optional - sage.rings.finite_rings + sage: L.base().base() # needs sage.rings.finite_rings Finite Field in z2 of size 5^2 The method :meth:`bases` gives access to the complete list of rings in a tower:: - sage: L.bases() # optional - sage.rings.finite_rings + sage: L.bases() # needs sage.rings.finite_rings [Field in b with defining polynomial x^2 + (4*z2 + 3*a)*x + 1 - a over its base, Field in a with defining polynomial x^2 + z2*x + 4 over its base, Finite Field in z2 of size 5^2] @@ -52,44 +53,44 @@ Once we have constructed an extension (or a tower of extensions), we have interesting methods attached to it. As a basic example, one can compute a basis of the top ring over any base in the tower:: - sage: L.basis_over(K) # optional - sage.rings.finite_rings + sage: L.basis_over(K) # needs sage.rings.finite_rings [1, b] - sage: L.basis_over(F) # optional - sage.rings.finite_rings + sage: L.basis_over(F) # needs sage.rings.finite_rings [1, a, b, a*b] When the base is omitted, the default is the natural base of the extension:: - sage: L.basis_over() # optional - sage.rings.finite_rings + sage: L.basis_over() # needs sage.rings.finite_rings [1, b] The method :meth:`sage.rings.ring_extension_element.RingExtensionWithBasis.vector` computes the coordinates of an element according to the above basis:: - sage: u = a + 2*b + 3*a*b # optional - sage.rings.finite_rings - sage: u.vector() # over K # optional - sage.rings.finite_rings + sage: u = a + 2*b + 3*a*b # needs sage.rings.finite_rings + sage: u.vector() # over K # needs sage.rings.finite_rings (a, 2 + 3*a) - sage: u.vector(F) # optional - sage.rings.finite_rings + sage: u.vector(F) # needs sage.rings.finite_rings (0, 1, 2, 3) One can also compute traces and norms with respect to any base of the tower:: - sage: u.trace() # over K # optional - sage.rings.finite_rings + sage: u.trace() # over K # needs sage.rings.finite_rings (2*z2 + 1) + (2*z2 + 1)*a - sage: u.trace(F) # optional - sage.rings.finite_rings + sage: u.trace(F) # needs sage.rings.finite_rings z2 + 1 - sage: u.trace().trace() # over K, then over F # optional - sage.rings.finite_rings + sage: u.trace().trace() # over K, then over F # needs sage.rings.finite_rings z2 + 1 - sage: u.norm() # over K # optional - sage.rings.finite_rings + sage: u.norm() # over K # needs sage.rings.finite_rings (z2 + 1) + (4*z2 + 2)*a - sage: u.norm(F) # optional - sage.rings.finite_rings + sage: u.norm(F) # needs sage.rings.finite_rings 2*z2 + 2 And minimal polynomials:: - sage: u.minpoly() # optional - sage.rings.finite_rings + sage: u.minpoly() # needs sage.rings.finite_rings x^2 + ((3*z2 + 4) + (3*z2 + 4)*a)*x + (z2 + 1) + (4*z2 + 2)*a - sage: u.minpoly(F) # optional - sage.rings.finite_rings + sage: u.minpoly(F) # needs sage.rings.finite_rings x^4 + (4*z2 + 4)*x^3 + x^2 + (z2 + 1)*x + 2*z2 + 2 @@ -165,9 +166,9 @@ def tower_bases(ring, degree): Univariate Polynomial Ring in x over Rational Field], [1]) - sage: K. = Qq(5^2) # optional - sage.rings.padics - sage: L. = K.extension(x^3 - 5) # optional - sage.rings.padics - sage: tower_bases(L, True) # optional - sage.rings.padics + sage: K. = Qq(5^2) # needs sage.rings.padics + sage: L. = K.extension(x^3 - 5) # needs sage.rings.padics + sage: tower_bases(L, True) # needs sage.rings.padics ([5-adic Eisenstein Extension Field in w defined by x^3 - 5 over its base field, 5-adic Unramified Extension Field in a defined by x^2 + 4*x + 2, 5-adic Field with capped relative precision 20], @@ -213,12 +214,12 @@ def common_base(K, L, degree): sage: from sage.rings.ring_extension import common_base - sage: common_base(GF(5^3), GF(5^7), False) # optional - sage.rings.finite_rings + sage: common_base(GF(5^3), GF(5^7), False) # needs sage.rings.finite_rings Finite Field of size 5 - sage: common_base(GF(5^3), GF(5^7), True) # optional - sage.rings.finite_rings + sage: common_base(GF(5^3), GF(5^7), True) # needs sage.rings.finite_rings (Finite Field of size 5, 3, 7) - sage: common_base(GF(5^3), GF(7^5), False) # optional - sage.rings.finite_rings + sage: common_base(GF(5^3), GF(7^5), False) # needs sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: unable to find a common base @@ -336,12 +337,12 @@ class RingExtensionFactory(UniqueFactory): True sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: E = K.over(QQ); E # optional - sage.rings.number_field + sage: K. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: E = K.over(QQ); E # needs sage.rings.number_field Field in a with defining polynomial x^2 - 2 over its base - sage: E2. = K.over(QQ) # optional - sage.rings.number_field - sage: E2 is E # optional - sage.rings.number_field + sage: E2. = K.over(QQ) # needs sage.rings.number_field + sage: E2 is E # needs sage.rings.number_field False """ def create_key_and_extra_args(self, ring, defining_morphism=None, gens=None, names=None, constructors=None): @@ -381,7 +382,7 @@ class RingExtensionFactory(UniqueFactory): 'print_options': {'print_elements_as': None, 'print_parent_as': None}})]}) - sage: RingExtension.create_key_and_extra_args(GF(5^4), GF(5^2), # optional - sage.rings.finite_rings + sage: RingExtension.create_key_and_extra_args(GF(5^4), GF(5^2), # needs sage.rings.finite_rings ....: names=('a',)) ((Ring morphism: From: Finite Field in z2 of size 5^2 @@ -561,8 +562,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): ... TypeError: only commutative rings are accepted - sage: K = GF(5^3) # optional - sage.rings.finite_rings - sage: K.over(K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: K = GF(5^3) # needs sage.rings.finite_rings + sage: K.over(K.frobenius_endomorphism()) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: exotic defining morphism between two rings in the tower; consider using another variable name @@ -625,12 +626,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: E = K.over() # over QQ # optional - sage.rings.number_field + sage: K. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: E = K.over() # over QQ # needs sage.rings.number_field - sage: hasattr(E, 'automorphisms') # optional - sage.rings.number_field + sage: hasattr(E, 'automorphisms') # needs sage.rings.number_field True - sage: E.automorphisms() # optional - sage.rings.number_field + sage: E.automorphisms() # needs sage.rings.number_field [Ring endomorphism of Field in a with defining polynomial x^2 - 2 over its base Defn: a |--> a, Ring endomorphism of Field in a with defining polynomial x^2 - 2 over its base @@ -662,10 +663,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: K. = A.over() # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: K. = A.over() # needs sage.rings.number_field - sage: dir(K) # optional - sage.rings.number_field + sage: dir(K) # needs sage.rings.number_field ['CartesianProduct', 'Element', 'Hom', @@ -694,8 +695,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES: - sage: E = GF(5^3).over() # optional - sage.rings.finite_rings - sage: hash(E) # random # optional - sage.rings.finite_rings + sage: E = GF(5^3).over() # needs sage.rings.finite_rings + sage: hash(E) # random # needs sage.rings.finite_rings 140257667982632 """ return hash_by_id(self) @@ -707,10 +708,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(7^3).over() # optional - sage.rings.finite_rings - sage: type(K) # optional - sage.rings.finite_rings + sage: K = GF(7^3).over() # needs sage.rings.finite_rings + sage: type(K) # needs sage.rings.finite_rings - sage: loads(dumps(K)) is K # optional - sage.rings.finite_rings + sage: loads(dumps(K)) is K # needs sage.rings.finite_rings True """ (defining_morphism, gens, names) = self._factory_data[2] @@ -723,8 +724,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: E = GF(5^3).over() # optional - sage.rings.finite_rings - sage: E.construction() # optional - sage.rings.finite_rings + sage: E = GF(5^3).over() # needs sage.rings.finite_rings + sage: E.construction() # needs sage.rings.finite_rings """ # One could define a construction functor K' -> K' otimes_K L, but we leave this to another issue @@ -765,18 +766,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: k = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^2).over(k) # optional - sage.rings.finite_rings - sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: k = GF(5) # needs sage.rings.finite_rings + sage: K. = GF(5^2).over(k) # needs sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: x = L.from_base_ring(k(2)); x # optional - sage.rings.finite_rings + sage: x = L.from_base_ring(k(2)); x # needs sage.rings.finite_rings 2 - sage: x.parent() # optional - sage.rings.finite_rings + sage: x.parent() # needs sage.rings.finite_rings Field in v with defining polynomial x^2 + (3 - u)*x + u over its base - sage: x = L.from_base_ring(u); x # optional - sage.rings.finite_rings + sage: x = L.from_base_ring(u); x # needs sage.rings.finite_rings u - sage: x.parent() # optional - sage.rings.finite_rings + sage: x.parent() # needs sage.rings.finite_rings Field in v with defining polynomial x^2 + (3 - u)*x + u over its base """ if r not in self._base: @@ -798,25 +799,26 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: B. = GF(5^4).over(A) # optional - sage.rings.finite_rings - sage: C. = GF(5^12).over(B) # optional - sage.rings.finite_rings - sage: D. = GF(5^24).over(C) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A. = GF(5^2).over() # over GF(5) + sage: B. = GF(5^4).over(A) + sage: C. = GF(5^12).over(B) + sage: D. = GF(5^24).over(C) Observe what happens when we modify the option ``over``:: - sage: D # optional - sage.rings.finite_rings + sage: D # needs sage.rings.finite_rings Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over its base - sage: D.print_options(over=2) # optional - sage.rings.finite_rings - sage: D # optional - sage.rings.finite_rings + sage: D.print_options(over=2) # needs sage.rings.finite_rings + sage: D # needs sage.rings.finite_rings Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over Field in c with defining polynomial x^3 + (1 + (2 - a)*b)*x^2 + (2 + 2*b)*x - b over Field in b with defining polynomial x^2 + (3 - a)*x + a over its base - sage: D.print_options(over=Infinity) # optional - sage.rings.finite_rings - sage: D # optional - sage.rings.finite_rings + sage: D.print_options(over=Infinity) # needs sage.rings.finite_rings + sage: D # needs sage.rings.finite_rings Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over Field in c with defining polynomial x^3 + (1 + (2 - a)*b)*x^2 + (2 + 2*b)*x - b over Field in b with defining polynomial x^2 + (3 - a)*x + a over @@ -825,19 +827,19 @@ cdef class RingExtension_generic(CommutativeAlgebra): Now the option ``base``:: - sage: d^2 # optional - sage.rings.finite_rings + sage: d^2 # needs sage.rings.finite_rings -c + ((-1 + a) + ((-1 + 3*a) + b)*c + ((3 - a) + (-1 + a)*b)*c^2)*d - sage: D.basis_over(B) # optional - sage.rings.finite_rings + sage: D.basis_over(B) # needs sage.rings.finite_rings [1, c, c^2, d, c*d, c^2*d] - sage: D.print_options(base=B) # optional - sage.rings.finite_rings - sage: d^2 # optional - sage.rings.finite_rings + sage: D.print_options(base=B) # needs sage.rings.finite_rings + sage: d^2 # needs sage.rings.finite_rings -c + (-1 + a)*d + ((-1 + 3*a) + b)*c*d + ((3 - a) + (-1 + a)*b)*c^2*d - sage: D.basis_over(A) # optional - sage.rings.finite_rings + sage: D.basis_over(A) # needs sage.rings.finite_rings [1, b, c, b*c, c^2, b*c^2, d, b*d, c*d, b*c*d, c^2*d, b*c^2*d] - sage: D.print_options(base=A) # optional - sage.rings.finite_rings - sage: d^2 # optional - sage.rings.finite_rings + sage: D.print_options(base=A) # needs sage.rings.finite_rings + sage: d^2 # needs sage.rings.finite_rings -c + (-1 + a)*d + (-1 + 3*a)*c*d + b*c*d + (3 - a)*c^2*d + (-1 + a)*b*c^2*d """ for (name, value) in options.items(): @@ -1041,21 +1043,21 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: E1 = GF(3^6).over(GF(3^3)) # optional - sage.rings.finite_rings - sage: E1.coerce_map_from(GF(3^3)) # indirect doctest # optional - sage.rings.finite_rings + sage: E1 = GF(3^6).over(GF(3^3)) # needs sage.rings.finite_rings + sage: E1.coerce_map_from(GF(3^3)) # indirect doctest # needs sage.rings.finite_rings Ring morphism: From: Finite Field in z3 of size 3^3 To: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base Defn: z3 |--> z3 - sage: E1.coerce_map_from(GF(3)) # indirect doctest # optional - sage.rings.finite_rings + sage: E1.coerce_map_from(GF(3)) # indirect doctest # needs sage.rings.finite_rings Ring morphism: From: Finite Field of size 3 To: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base Defn: 1 |--> 1 - sage: E2 = GF(3^18).over(GF(3^9)) # optional - sage.rings.finite_rings - sage: E2.coerce_map_from(E1) # indirect doctest # optional - sage.rings.finite_rings + sage: E2 = GF(3^18).over(GF(3^9)) # needs sage.rings.finite_rings + sage: E2.coerce_map_from(E1) # indirect doctest # needs sage.rings.finite_rings Ring morphism: From: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base To: Field in z18 with defining polynomial x^2 + (z9^8 + 2*z9^7 + z9^5 + 2*z9^4 + z9^2 + z9 + 1)*x + z9 over its base @@ -1063,11 +1065,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): A test with iterated extensions:: - sage: A = GF(3^18).over(GF(3^3)) # simple extension GF(3^3) -> GF(3^18) # optional - sage.rings.finite_rings - sage: B = GF(3^18).over(E1) # iterated extension GF(3^3) -> GF(3^6) -> GF(3^18) # optional - sage.rings.finite_rings - sage: A.has_coerce_map_from(B) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A = GF(3^18).over(GF(3^3)) # simple extension GF(3^3) -> GF(3^18) + sage: B = GF(3^18).over(E1) # iterated extension GF(3^3) -> GF(3^6) -> GF(3^18) + sage: A.has_coerce_map_from(B) False - sage: B.has_coerce_map_from(A) # optional - sage.rings.finite_rings + sage: B.has_coerce_map_from(A) True """ @@ -1087,17 +1090,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: K.base() # optional - sage.rings.finite_rings + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: K.base() # needs sage.rings.finite_rings Finite Field in z2 of size 5^2 In case of iterated extensions, the base is itself an extension:: - sage: L = GF(5^8).over(K) # optional - sage.rings.finite_rings - sage: L.base() # optional - sage.rings.finite_rings + sage: L = GF(5^8).over(K) # needs sage.rings.finite_rings + sage: L.base() # needs sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L.base() is K # optional - sage.rings.finite_rings + sage: L.base() is K # needs sage.rings.finite_rings True .. SEEALSO:: @@ -1113,20 +1116,20 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: F = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - sage: F.bases() # optional - sage.rings.finite_rings + sage: F.bases() # needs sage.rings.finite_rings [Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] - sage: K.bases() # optional - sage.rings.finite_rings + sage: K.bases() # needs sage.rings.finite_rings [Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] - sage: L.bases() # optional - sage.rings.finite_rings + sage: L.bases() # needs sage.rings.finite_rings [Field in z12 with defining polynomial x^3 + (1 + (2 - z2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, @@ -1153,15 +1156,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: F = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - sage: F.absolute_base() # optional - sage.rings.finite_rings + sage: F.absolute_base() # needs sage.rings.finite_rings Finite Field of size 5 - sage: K.absolute_base() # optional - sage.rings.finite_rings + sage: K.absolute_base() # needs sage.rings.finite_rings Finite Field of size 5 - sage: L.absolute_base() # optional - sage.rings.finite_rings + sage: L.absolute_base() # needs sage.rings.finite_rings Finite Field of size 5 .. SEEALSO:: @@ -1182,28 +1185,29 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: B = GF(5^12).over(A) # optional - sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: B = GF(5^12).over(A) # needs sage.rings.finite_rings - sage: A.is_defined_over(GF(5^2)) # optional - sage.rings.finite_rings + sage: A.is_defined_over(GF(5^2)) # needs sage.rings.finite_rings True - sage: A.is_defined_over(GF(5)) # optional - sage.rings.finite_rings + sage: A.is_defined_over(GF(5)) # needs sage.rings.finite_rings False - sage: B.is_defined_over(A) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: B.is_defined_over(A) True - sage: B.is_defined_over(GF(5^4)) # optional - sage.rings.finite_rings + sage: B.is_defined_over(GF(5^4)) True - sage: B.is_defined_over(GF(5^2)) # optional - sage.rings.finite_rings + sage: B.is_defined_over(GF(5^2)) True - sage: B.is_defined_over(GF(5)) # optional - sage.rings.finite_rings + sage: B.is_defined_over(GF(5)) False Note that an extension is defined over itself:: - sage: A.is_defined_over(A) # optional - sage.rings.finite_rings + sage: A.is_defined_over(A) # needs sage.rings.finite_rings True - sage: A.is_defined_over(GF(5^4)) # optional - sage.rings.finite_rings + sage: A.is_defined_over(GF(5^4)) # needs sage.rings.finite_rings True .. SEEALSO:: @@ -1234,26 +1238,27 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: L.bases() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(K) + sage: L.bases() [Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base, Finite Field in z2 of size 5^2] - sage: L._check_base(K) # optional - sage.rings.finite_rings + sage: L._check_base(K) # needs sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(GF(5^4)) # optional - sage.rings.finite_rings + sage: L._check_base(GF(5^4)) # needs sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(GF(5^4)) is K # optional - sage.rings.finite_rings + sage: L._check_base(GF(5^4)) is K # needs sage.rings.finite_rings True When ``base`` is ``None``, the base of the extension is returned:: - sage: L._check_base(None) # optional - sage.rings.finite_rings + sage: L._check_base(None) # needs sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(None) is L.base() # optional - sage.rings.finite_rings + sage: L._check_base(None) is L.base() # needs sage.rings.finite_rings True """ @@ -1279,17 +1284,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - sage: K.defining_morphism() # optional - sage.rings.finite_rings + sage: K.defining_morphism() # needs sage.rings.finite_rings Ring morphism: From: Finite Field in z2 of size 5^2 To: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base Defn: z2 |--> z2 - sage: L.defining_morphism() # optional - sage.rings.finite_rings + sage: L.defining_morphism() # needs sage.rings.finite_rings Ring morphism: From: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base To: Field in z12 with defining polynomial @@ -1299,14 +1304,14 @@ cdef class RingExtension_generic(CommutativeAlgebra): One can also pass in a base over which the extension is explicitly defined (see also :meth:`is_defined_over`):: - sage: L.defining_morphism(F) # optional - sage.rings.finite_rings + sage: L.defining_morphism(F) # needs sage.rings.finite_rings Ring morphism: From: Finite Field in z2 of size 5^2 To: Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base Defn: z2 |--> z2 - sage: L.defining_morphism(GF(5)) # optional - sage.rings.finite_rings + sage: L.defining_morphism(GF(5)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1343,13 +1348,14 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.gens() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) + sage: K.gens() (a,) - sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: L.gens() # optional - sage.rings.finite_rings + sage: L. = GF(5^4).over(K) + sage: L.gens() (b,) - sage: L.gens(GF(5)) # optional - sage.rings.finite_rings + sage: L.gens(GF(5)) (b, a) sage: S. = QQ[] @@ -1373,16 +1379,16 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.gens() # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.gens() # needs sage.rings.finite_rings (z2,) - sage: K.ngens() # optional - sage.rings.finite_rings + sage: K.ngens() # needs sage.rings.finite_rings 1 - sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: L.gens(GF(5)) # optional - sage.rings.finite_rings + sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings + sage: L.gens(GF(5)) # needs sage.rings.finite_rings (z4, z2) - sage: L.ngens(GF(5)) # optional - sage.rings.finite_rings + sage: L.ngens(GF(5)) # needs sage.rings.finite_rings 2 """ return len(self.gens(base)) @@ -1393,15 +1399,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: x =K.gen(); x # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: x =K.gen(); x # needs sage.rings.finite_rings z2 Observe that the generator lives in the extension:: - sage: x.parent() # optional - sage.rings.finite_rings + sage: x.parent() # needs sage.rings.finite_rings Field in z2 with defining polynomial x^2 + 4*x + 2 over its base - sage: x.parent() is K # optional - sage.rings.finite_rings + sage: x.parent() is K # needs sage.rings.finite_rings True """ return self.gens()[0] @@ -1412,13 +1418,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: x = K.random_element(); x # random # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: x = K.random_element(); x # random # needs sage.rings.finite_rings 3 + z2 - sage: x.parent() # optional - sage.rings.finite_rings + sage: x.parent() # needs sage.rings.finite_rings Field in z2 with defining polynomial x^2 + 4*x + 2 over its base - sage: x.parent() is K # optional - sage.rings.finite_rings + sage: x.parent() is K # needs sage.rings.finite_rings True """ elt = self._backend.random_element() @@ -1435,29 +1441,29 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - sage: K.degree_over(F) # optional - sage.rings.finite_rings + sage: K.degree_over(F) # needs sage.rings.finite_rings 2 - sage: L.degree_over(K) # optional - sage.rings.finite_rings + sage: L.degree_over(K) # needs sage.rings.finite_rings 3 - sage: L.degree_over(F) # optional - sage.rings.finite_rings + sage: L.degree_over(F) # needs sage.rings.finite_rings 6 If ``base`` is omitted, the degree is computed over the base of the extension:: - sage: K.degree_over() # optional - sage.rings.finite_rings + sage: K.degree_over() # needs sage.rings.finite_rings 2 - sage: L.degree_over() # optional - sage.rings.finite_rings + sage: L.degree_over() # needs sage.rings.finite_rings 3 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: K.degree_over(GF(5)) # optional - sage.rings.finite_rings + sage: K.degree_over(GF(5)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1479,11 +1485,11 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: B. = QQ.extension(x^6 - 2) # optional - sage.rings.number_field - sage: f = A.hom([b^3]) # optional - sage.rings.number_field - sage: E = B.over(f) # optional - sage.rings.number_field - sage: E.degree_over() # indirect doctest # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: B. = QQ.extension(x^6 - 2) # needs sage.rings.number_field + sage: f = A.hom([b^3]) # needs sage.rings.number_field + sage: E = B.over(f) # needs sage.rings.number_field + sage: E.degree_over() # indirect doctest # needs sage.rings.number_field 3 """ if base is self: @@ -1501,20 +1507,20 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: B = GF(5^12).over(A) # optional - sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: B = GF(5^12).over(A) # needs sage.rings.finite_rings - sage: A.degree(GF(5^2)) # optional - sage.rings.finite_rings + sage: A.degree(GF(5^2)) # needs sage.rings.finite_rings 2 - sage: B.degree(A) # optional - sage.rings.finite_rings + sage: B.degree(A) # needs sage.rings.finite_rings 3 - sage: B.degree(GF(5^2)) # optional - sage.rings.finite_rings + sage: B.degree(GF(5^2)) # needs sage.rings.finite_rings 6 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: A.degree(GF(5)) # optional - sage.rings.finite_rings + sage: A.degree(GF(5)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1531,8 +1537,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: A.relative_degree() # optional - sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: A.relative_degree() # needs sage.rings.finite_rings 2 .. SEEALSO:: @@ -1547,12 +1553,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: B = GF(5^12).over(A) # optional - sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: B = GF(5^12).over(A) # needs sage.rings.finite_rings - sage: A.absolute_degree() # optional - sage.rings.finite_rings + sage: A.absolute_degree() # needs sage.rings.finite_rings 2 - sage: B.absolute_degree() # optional - sage.rings.finite_rings + sage: B.absolute_degree() # needs sage.rings.finite_rings 6 .. SEEALSO:: @@ -1572,18 +1578,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L.is_finite_over(K) # optional - sage.rings.finite_rings + sage: L.is_finite_over(K) # needs sage.rings.finite_rings True - sage: L.is_finite_over(GF(5)) # optional - sage.rings.finite_rings + sage: L.is_finite_over(GF(5)) # needs sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: L.is_finite_over() # optional - sage.rings.finite_rings + sage: L.is_finite_over() # needs sage.rings.finite_rings True """ cdef CommutativeRing b @@ -1617,8 +1623,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.is_finite_over() # indirect doctest # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.is_finite_over() # indirect doctest # needs sage.rings.finite_rings True """ raise NotImplementedError @@ -1635,18 +1641,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L.is_free_over(K) # optional - sage.rings.finite_rings + sage: L.is_free_over(K) # needs sage.rings.finite_rings True - sage: L.is_free_over(GF(5)) # optional - sage.rings.finite_rings + sage: L.is_free_over(GF(5)) # needs sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: L.is_free_over() # optional - sage.rings.finite_rings + sage: L.is_free_over() # needs sage.rings.finite_rings True """ cdef CommutativeRing b @@ -1680,8 +1686,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.is_free_over() # indirect doctest # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.is_free_over() # indirect doctest # needs sage.rings.finite_rings True """ raise NotImplementedError @@ -1696,17 +1702,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^5).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.is_field() # optional - sage.rings.finite_rings + sage: K = GF(5^5).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.is_field() # needs sage.rings.finite_rings True - sage: S. = QQ[] # optional - sage.rings.finite_rings - sage: A = S.over(QQ) # optional - sage.rings.finite_rings - sage: A.is_field() # optional - sage.rings.finite_rings + sage: S. = QQ[] # needs sage.rings.finite_rings + sage: A = S.over(QQ) # needs sage.rings.finite_rings + sage: A.is_field() # needs sage.rings.finite_rings False - sage: B = A.fraction_field() # optional - sage.rings.finite_rings - sage: B.is_field() # optional - sage.rings.finite_rings + sage: B = A.fraction_field() # needs sage.rings.finite_rings + sage: B.is_field() # needs sage.rings.finite_rings True """ return self._backend.is_field(proof=proof) @@ -1733,46 +1739,46 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) # optional - sage.rings.number_field - sage: OK = A.over() # over ZZ # optional - sage.rings.number_field - sage: OK # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 5) # needs sage.rings.number_field + sage: OK = A.over() # over ZZ # needs sage.rings.number_field + sage: OK # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1 = OK.fraction_field(); K1 # optional - sage.rings.number_field + sage: K1 = OK.fraction_field(); K1 # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() # optional - sage.rings.number_field + sage: K1.bases() # needs sage.rings.number_field [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - sage: K2 = OK.fraction_field(extend_base=True); K2 # optional - sage.rings.number_field + sage: K2 = OK.fraction_field(extend_base=True); K2 # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() # optional - sage.rings.number_field + sage: K2.bases() # needs sage.rings.number_field [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Rational Field] Note that there is no coercion between `K_1` and `K_2`:: - sage: K1.has_coerce_map_from(K2) # optional - sage.rings.number_field + sage: K1.has_coerce_map_from(K2) # needs sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) # optional - sage.rings.number_field + sage: K2.has_coerce_map_from(K1) # needs sage.rings.number_field False We check that when the extension is a field, its fraction field does not change:: - sage: K1.fraction_field() is K1 # optional - sage.rings.number_field + sage: K1.fraction_field() is K1 # needs sage.rings.number_field True - sage: K2.fraction_field() is K2 # optional - sage.rings.number_field + sage: K2.fraction_field() is K2 # needs sage.rings.number_field True TESTS:: - sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) # optional - sage.rings.finite_rings + sage: A = GF(5).over(ZZ) # needs sage.rings.finite_rings + sage: A.fraction_field(extend_base=True) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -1797,8 +1803,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(5^2).over() # optional - sage.rings.finite_rings - sage: K.fraction_field() # indirect doctest # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # needs sage.rings.finite_rings + sage: K.fraction_field() # indirect doctest # needs sage.rings.finite_rings Field in z2 with defining polynomial x^2 + 4*x + 2 over its base sage: K = QQ.over(ZZ) @@ -1832,17 +1838,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(F) # optional - sage.rings.finite_rings + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L = GF(5^12).over(F) # needs sage.rings.finite_rings - sage: K.Hom(L) # indirect doctest # optional - sage.rings.finite_rings + sage: K.Hom(L) # indirect doctest # needs sage.rings.finite_rings Set of Homomorphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base - sage: K.Hom(L, category=Sets()) # optional - sage.rings.finite_rings + sage: K.Hom(L, category=Sets()) # needs sage.rings.finite_rings Set of Morphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 @@ -1880,12 +1886,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings We define (by hand) the relative Frobenius endomorphism of the extension `L/K`:: - sage: L.hom([b^25]) # optional - sage.rings.finite_rings + sage: L.hom([b^25]) # needs sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> 2 + 2*a*b + (2 - a)*b^2 @@ -1894,15 +1900,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): because it is not a homomorphism of `K`-algebras. For this reason, the construction ``L.hom([b^5])`` fails:: - sage: L.hom([b^5]) # optional - sage.rings.finite_rings + sage: L.hom([b^5]) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: images do not define a valid homomorphism What we need is to specify a base map:: - sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings - sage: FrobL = L.hom([b^5], base_map=FrobK); FrobL # optional - sage.rings.finite_rings + sage: FrobK = K.hom([a^5]) # needs sage.rings.finite_rings + sage: FrobL = L.hom([b^5], base_map=FrobK); FrobL # needs sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 @@ -1911,13 +1917,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): As a shortcut, we may use the following construction:: - sage: phi = L.hom([b^5, a^5]); phi # optional - sage.rings.finite_rings + sage: phi = L.hom([b^5, a^5]); phi # needs sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a - sage: phi == FrobL # optional - sage.rings.finite_rings + sage: phi == FrobL # needs sage.rings.finite_rings True """ if codomain is None: @@ -1936,14 +1942,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: F.characteristic() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2).over() # over GF(5) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(K) + sage: F.characteristic() 5 - sage: K.characteristic() # optional - sage.rings.finite_rings + sage: K.characteristic() 5 - sage: L.characteristic() # optional - sage.rings.finite_rings + sage: L.characteristic() 5 :: @@ -1954,27 +1961,29 @@ cdef class RingExtension_generic(CommutativeAlgebra): :: - sage: F = GF(11) # optional - sage.rings.finite_rings - sage: A. = F[] # optional - sage.rings.finite_rings - sage: K = Frac(F).over(F) # optional - sage.rings.finite_rings - sage: K.characteristic() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(11) + sage: A. = F[] + sage: K = Frac(F).over(F) + sage: K.characteristic() 11 :: - sage: E = GF(7).over(ZZ) # optional - sage.rings.finite_rings - sage: E.characteristic() # optional - sage.rings.finite_rings + sage: E = GF(7).over(ZZ) # needs sage.rings.finite_rings + sage: E.characteristic() # needs sage.rings.finite_rings 7 TESTS: Ensure issue :trac:`34692` is fixed:: - sage: Fq = GF(11) # optional - sage.rings.finite_rings - sage: FqX. = Fq[] # optional - sage.rings.finite_rings - sage: k = Frac(FqX) # optional - sage.rings.finite_rings - sage: K = k.over(FqX) # optional - sage.rings.finite_rings - sage: K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: Fq = GF(11) + sage: FqX. = Fq[] + sage: k = Frac(FqX) + sage: K = k.over(FqX) + sage: K.frobenius_endomorphism() Frobenius endomorphism x |--> x^11 of Fraction Field of Univariate Polynomial Ring in X over Finite Field of size 11 over its base @@ -2018,13 +2027,13 @@ cdef class RingExtensionFractionField(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: OK = A.over() # optional - sage.rings.number_field - sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: OK = A.over() # needs sage.rings.number_field + sage: K = OK.fraction_field(); K # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: TestSuite(K).run() # optional - sage.rings.number_field + sage: TestSuite(K).run() # needs sage.rings.number_field """ RingExtension_generic.__init__(self, defining_morphism, **kwargs) @@ -2040,15 +2049,15 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: OK = A.over() # optional - sage.rings.number_field - sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: OK = A.over() # needs sage.rings.number_field + sage: K = OK.fraction_field(); K # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: K.ring() # optional - sage.rings.number_field + sage: K.ring() # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: K.ring() is OK # optional - sage.rings.number_field + sage: K.ring() is OK # needs sage.rings.number_field True """ return self._ring @@ -2060,11 +2069,11 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: OK = A.over() # optional - sage.rings.number_field - sage: K = OK.fraction_field() # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: OK = A.over() # needs sage.rings.number_field + sage: K = OK.fraction_field() # needs sage.rings.number_field - sage: K._repr_topring() # optional - sage.rings.number_field + sage: K._repr_topring() # needs sage.rings.number_field 'Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2' """ if isinstance(self._ring, RingExtension_generic): @@ -2104,10 +2113,10 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: E = GF(5^4).over(GF(5^2)); E # optional - sage.rings.finite_rings + sage: E = GF(5^4).over(GF(5^2)); E # needs sage.rings.finite_rings Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: TestSuite(E).run() # optional - sage.rings.finite_rings + sage: TestSuite(E).run() # needs sage.rings.finite_rings """ Element = RingExtensionWithBasisElement @@ -2130,11 +2139,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^3 - 2) # optional - sage.rings.number_field - sage: E = K.over(); E # optional - sage.rings.number_field + sage: K. = QQ.extension(x^3 - 2) # needs sage.rings.number_field + sage: E = K.over(); E # needs sage.rings.number_field Field in a with defining polynomial x^3 - 2 over its base - sage: TestSuite(E).run() # optional - sage.rings.number_field + sage: TestSuite(E).run() # needs sage.rings.number_field """ RingExtension_generic.__init__(self, defining_morphism, **kwargs) self._basis = [ self(b) for b in basis ] @@ -2174,26 +2183,26 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K = GF(5^2).over(F) # optional - sage.rings.finite_rings - sage: L = GF(5^4).over(K) # optional - sage.rings.finite_rings + sage: F = GF(5) # needs sage.rings.finite_rings + sage: K = GF(5^2).over(F) # needs sage.rings.finite_rings + sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L._print_option_base(F) is F # optional - sage.rings.finite_rings + sage: L._print_option_base(F) is F # needs sage.rings.finite_rings True - sage: L._print_option_base(K) is K # optional - sage.rings.finite_rings + sage: L._print_option_base(K) is K # needs sage.rings.finite_rings True - sage: L._print_option_base(GF(5^2)) is K # optional - sage.rings.finite_rings + sage: L._print_option_base(GF(5^2)) is K # needs sage.rings.finite_rings True - sage: L._print_option_base(None) is K # optional - sage.rings.finite_rings + sage: L._print_option_base(None) is K # needs sage.rings.finite_rings True - sage: L._print_option_base(L) # optional - sage.rings.finite_rings + sage: L._print_option_base(L) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: base must be strict - sage: K._print_option_base(L) # optional - sage.rings.finite_rings + sage: K._print_option_base(L) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base @@ -2223,11 +2232,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: B. = QQ.extension(x^6 - 2) # optional - sage.rings.number_field - sage: f = A.hom([b^3]) # optional - sage.rings.number_field - sage: E = B.over(f) # optional - sage.rings.number_field - sage: E.degree_over() # indirect doctest # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: B. = QQ.extension(x^6 - 2) # needs sage.rings.number_field + sage: f = A.hom([b^3]) # needs sage.rings.number_field + sage: E = B.over(f) # needs sage.rings.number_field + sage: E.degree_over() # indirect doctest # needs sage.rings.number_field 3 """ if base is self: @@ -2248,8 +2257,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.is_finite_over() # indirect doctest # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.is_finite_over() # indirect doctest # needs sage.rings.finite_rings True """ if base is self or base is self._base: @@ -2267,8 +2276,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: K = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.is_free_over() # indirect doctest # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.is_free_over() # indirect doctest # needs sage.rings.finite_rings True """ if base is self or base is self._base: @@ -2286,32 +2295,32 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: - sage: F. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^12).over(K) # optional - sage.rings.finite_rings + sage: F. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L. = GF(5^12).over(K) # needs sage.rings.finite_rings - sage: L.basis_over(K) # optional - sage.rings.finite_rings + sage: L.basis_over(K) # needs sage.rings.finite_rings [1, c, c^2] - sage: L.basis_over(F) # optional - sage.rings.finite_rings + sage: L.basis_over(F) # needs sage.rings.finite_rings [1, b, c, b*c, c^2, b*c^2] - sage: L.basis_over(GF(5)) # optional - sage.rings.finite_rings + sage: L.basis_over(GF(5)) # needs sage.rings.finite_rings [1, a, b, a*b, c, a*c, b*c, a*b*c, c^2, a*c^2, b*c^2, a*b*c^2] If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: L.basis_over() # optional - sage.rings.finite_rings + sage: L.basis_over() # needs sage.rings.finite_rings [1, c, c^2] - sage: K.basis_over() # optional - sage.rings.finite_rings + sage: K.basis_over() # needs sage.rings.finite_rings [1, b] Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: L.degree_over(GF(5^6)) # optional - sage.rings.finite_rings + sage: L.degree_over(GF(5^6)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z6 of size 5^6 @@ -2331,9 +2340,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^3 - 2) # optional - sage.rings.number_field - sage: K. = A.over() # optional - sage.rings.number_field - sage: K.basis_over() # optional - sage.rings.number_field + sage: A. = QQ.extension(x^3 - 2) # needs sage.rings.number_field + sage: K. = A.over() # needs sage.rings.number_field + sage: K.basis_over() # needs sage.rings.number_field [1, u, u^2] """ if base is self: @@ -2370,60 +2379,61 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: - sage: F = GF(11) # optional - sage.rings.finite_rings - sage: K. = GF(11^2).over() # optional - sage.rings.finite_rings - sage: L. = GF(11^6).over(K) # optional - sage.rings.finite_rings + sage: F = GF(11) # needs sage.rings.finite_rings + sage: K. = GF(11^2).over() # needs sage.rings.finite_rings + sage: L. = GF(11^6).over(K) # needs sage.rings.finite_rings Forgetting a part of the multiplicative structure, the field L can be viewed as a vector space of dimension 3 over K, equipped with a distinguished basis, namely `(1, b, b^2)`:: - sage: V, i, j = L.free_module(K) # optional - sage.rings.finite_rings - sage: V # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: V, i, j = L.free_module(K) + sage: V Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base - sage: i # optional - sage.rings.finite_rings + sage: i Generic map: From: Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base To: Field in b with defining polynomial x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base - sage: j # optional - sage.rings.finite_rings + sage: j Generic map: From: Field in b with defining polynomial x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base To: Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base - sage: j(b) # optional - sage.rings.finite_rings + sage: j(b) # needs sage.rings.finite_rings (0, 1, 0) - sage: i((1, a, a+1)) # optional - sage.rings.finite_rings + sage: i((1, a, a+1)) # needs sage.rings.finite_rings 1 + a*b + (1 + a)*b^2 Similarly, one can view L as a F-vector space of dimension 6:: - sage: V, i, j, = L.free_module(F) # optional - sage.rings.finite_rings - sage: V # optional - sage.rings.finite_rings + sage: V, i, j, = L.free_module(F) # needs sage.rings.finite_rings + sage: V # needs sage.rings.finite_rings Vector space of dimension 6 over Finite Field of size 11 In this case, the isomorphisms between `V` and `L` are given by the basis `(1, a, b, ab, b^2, ab^2)`: - sage: j(a*b) # optional - sage.rings.finite_rings + sage: j(a*b) # needs sage.rings.finite_rings (0, 0, 0, 1, 0, 0) - sage: i((1,2,3,4,5,6)) # optional - sage.rings.finite_rings + sage: i((1,2,3,4,5,6)) # needs sage.rings.finite_rings (1 + 2*a) + (3 + 4*a)*b + (5 + 6*a)*b^2 When ``base`` is omitted, the default is the base of this extension:: - sage: L.free_module(map=False) # optional - sage.rings.finite_rings + sage: L.free_module(map=False) # needs sage.rings.finite_rings Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: L.degree(GF(11^3)) # optional - sage.rings.finite_rings + sage: L.degree(GF(11^3)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z3 of size 11^3 @@ -2459,9 +2469,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: K = GF(7^5).over() # optional - sage.rings.finite_rings - sage: L = GF(7^15).over(K) # optional - sage.rings.finite_rings - sage: for base in L.bases(): # optional - sage.rings.finite_rings + sage: K = GF(7^5).over() # needs sage.rings.finite_rings + sage: L = GF(7^15).over(K) # needs sage.rings.finite_rings + sage: for base in L.bases(): # needs sage.rings.finite_rings ....: V, i, j = L.free_module(base) ....: assert([ i(v) for v in V.basis() ] == L.basis_over(base)) ....: assert([ j(x) for x in L.basis_over(base) ] == V.basis()) @@ -2495,46 +2505,46 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) # optional - sage.rings.number_field - sage: OK = A.over() # over ZZ # optional - sage.rings.number_field - sage: OK # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 5) # needs sage.rings.number_field + sage: OK = A.over() # over ZZ # needs sage.rings.number_field + sage: OK # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1 = OK.fraction_field(); K1 # optional - sage.rings.number_field + sage: K1 = OK.fraction_field(); K1 # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() # optional - sage.rings.number_field + sage: K1.bases() # needs sage.rings.number_field [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - sage: K2 = OK.fraction_field(extend_base=True); K2 # optional - sage.rings.number_field + sage: K2 = OK.fraction_field(extend_base=True); K2 # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() # optional - sage.rings.number_field + sage: K2.bases() # needs sage.rings.number_field [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Rational Field] Note that there is no coercion map between `K_1` and `K_2`:: - sage: K1.has_coerce_map_from(K2) # optional - sage.rings.number_field + sage: K1.has_coerce_map_from(K2) # needs sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) # optional - sage.rings.number_field + sage: K2.has_coerce_map_from(K1) # needs sage.rings.number_field False We check that when the extension is a field, its fraction field does not change:: - sage: K1.fraction_field() is K1 # optional - sage.rings.number_field + sage: K1.fraction_field() is K1 # needs sage.rings.number_field True - sage: K2.fraction_field() is K2 # optional - sage.rings.number_field + sage: K2.fraction_field() is K2 # needs sage.rings.number_field True TESTS:: - sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) # optional - sage.rings.finite_rings + sage: A = GF(5).over(ZZ) # needs sage.rings.finite_rings + sage: A.fraction_field(extend_base=True) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -2564,13 +2574,13 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^3 - 7) # optional - sage.rings.number_field - sage: K = A.over() # optional - sage.rings.number_field + sage: A. = QQ.extension(x^3 - 7) # needs sage.rings.number_field + sage: K = A.over() # needs sage.rings.number_field - sage: type(K) # optional - sage.rings.number_field + sage: type(K) # needs sage.rings.number_field - sage: TestSuite(K).run() # optional - sage.rings.number_field + sage: TestSuite(K).run() # needs sage.rings.number_field """ def __init__(self, defining_morphism, gen, names, check=True, **kwargs): @@ -2592,11 +2602,11 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^3 + 3*x + 1) # optional - sage.rings.number_field - sage: E = K.over(); E # optional - sage.rings.number_field + sage: K. = QQ.extension(x^3 + 3*x + 1) # needs sage.rings.number_field + sage: E = K.over(); E # needs sage.rings.number_field Field in a with defining polynomial x^3 + 3*x + 1 over its base - sage: TestSuite(E).run() # optional - sage.rings.number_field + sage: TestSuite(E).run() # needs sage.rings.number_field """ self._name = names[0] backend_base = backend_parent(defining_morphism.domain()) @@ -2623,12 +2633,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: K._repr_topring() # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over() # needs sage.rings.finite_rings + sage: K._repr_topring() # needs sage.rings.finite_rings 'Field in a with defining polynomial x^3 + 3*x + 3' - sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings - sage: L._repr_topring() # optional - sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings + sage: L._repr_topring() # needs sage.rings.finite_rings 'Field in b with defining polynomial x^3 + (1 + 3*a^2)*x^2 + (3 + 2*a + 2*a^2)*x - a' """ if self._name is None: @@ -2641,12 +2651,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: K._latex_topring() # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over() # needs sage.rings.finite_rings + sage: K._latex_topring() # needs sage.rings.finite_rings '\\Bold{F}_{5}[a]' - sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings - sage: L._latex_topring() # optional - sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings + sage: L._latex_topring() # needs sage.rings.finite_rings '\\Bold{F}_{5}[a][b]' """ if self._name is None: @@ -2667,18 +2677,18 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(7^10).over(GF(7^2)); K # optional - sage.rings.finite_rings + sage: K. = GF(7^10).over(GF(7^2)); K # needs sage.rings.finite_rings Field in u with defining polynomial x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 over its base - sage: P = K.modulus(); P # optional - sage.rings.finite_rings + sage: P = K.modulus(); P # needs sage.rings.finite_rings x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 - sage: P(u) # optional - sage.rings.finite_rings + sage: P(u) # needs sage.rings.finite_rings 0 We can use a different variable name:: - sage: K.modulus('y') # optional - sage.rings.finite_rings + sage: K.modulus('y') # needs sage.rings.finite_rings y^5 + (6*z2 + 4)*y^4 + (3*z2 + 5)*y^3 + (2*z2 + 2)*y^2 + 4*y + 6*z2 """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -2699,14 +2709,14 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K.gens() # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: K.gens() # needs sage.rings.finite_rings (a,) - sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: L.gens() # optional - sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings + sage: L.gens() # needs sage.rings.finite_rings (b,) - sage: L.gens(GF(5)) # optional - sage.rings.finite_rings + sage: L.gens(GF(5)) # needs sage.rings.finite_rings (b, a) """ if base is None: @@ -2741,46 +2751,46 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) # optional - sage.rings.number_field - sage: OK = A.over() # over ZZ # optional - sage.rings.number_field - sage: OK # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 5) # needs sage.rings.number_field + sage: OK = A.over() # over ZZ # needs sage.rings.number_field + sage: OK # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1 = OK.fraction_field(); K1 # optional - sage.rings.number_field + sage: K1 = OK.fraction_field(); K1 # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() # optional - sage.rings.number_field + sage: K1.bases() # needs sage.rings.number_field [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - sage: K2 = OK.fraction_field(extend_base=True); K2 # optional - sage.rings.number_field + sage: K2 = OK.fraction_field(extend_base=True); K2 # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() # optional - sage.rings.number_field + sage: K2.bases() # needs sage.rings.number_field [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Rational Field] Note that there is no coercion map between `K_1` and `K_2`:: - sage: K1.has_coerce_map_from(K2) # optional - sage.rings.number_field + sage: K1.has_coerce_map_from(K2) # needs sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) # optional - sage.rings.number_field + sage: K2.has_coerce_map_from(K1) # needs sage.rings.number_field False We check that when the extension is a field, its fraction field does not change:: - sage: K1.fraction_field() is K1 # optional - sage.rings.number_field + sage: K1.fraction_field() is K1 # needs sage.rings.number_field True - sage: K2.fraction_field() is K2 # optional - sage.rings.number_field + sage: K2.fraction_field() is K2 # needs sage.rings.number_field True TESTS:: - sage: A = GF(5).over(ZZ) # optional - sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) # optional - sage.rings.finite_rings + sage: A = GF(5).over(ZZ) # needs sage.rings.finite_rings + sage: A.fraction_field(extend_base=True) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 98539da208f..316bf64ae1e 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -43,9 +43,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over() # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: TestSuite(x).run() # optional - sage.rings.finite_rings + sage: K = GF(5^4).over() # needs sage.rings.finite_rings + sage: x = K.random_element() # needs sage.rings.finite_rings + sage: TestSuite(x).run() # needs sage.rings.finite_rings """ def __init__(self, RingExtension_generic parent, x, *args, **kwds): @@ -86,11 +86,12 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^3).over() # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: type(x) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^3).over() + sage: x = K.random_element() + sage: type(x) - sage: loads(dumps(x)) == x # optional - sage.rings.finite_rings + sage: loads(dumps(x)) == x True """ return self._parent, (self._backend,) @@ -104,12 +105,12 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: K. = A.over() # over QQ # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: K. = A.over() # over QQ # needs sage.rings.number_field - sage: hasattr(a, 'continued_fraction') # optional - sage.rings.number_field + sage: hasattr(a, 'continued_fraction') # needs sage.rings.number_field True - sage: a.continued_fraction() # optional - sage.rings.number_field + sage: a.continued_fraction() # needs sage.rings.number_field [1; (2)*] """ try: @@ -138,10 +139,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: K. = A.over() # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: K. = A.over() # needs sage.rings.number_field - sage: dir(a) # optional - sage.rings.number_field + sage: dir(a) # needs sage.rings.number_field ['__abs__', '__add__', ... @@ -173,8 +174,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES: - sage: E. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: hash(a) # optional - sage.rings.finite_rings + sage: E. = GF(5^3).over() # needs sage.rings.finite_rings + sage: hash(a) # needs sage.rings.finite_rings 5 """ return hash(self._backend) @@ -188,9 +189,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings - sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: b._repr_() # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # needs sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings + sage: b._repr_() # needs sage.rings.finite_rings 'b' """ cdef RingExtension_generic parent = self._parent @@ -232,9 +233,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings - sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: b._latex_() # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # needs sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings + sage: b._latex_() # needs sage.rings.finite_rings 'b' """ cdef RingExtension_generic parent = self._parent @@ -370,13 +371,14 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: x == x # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() + sage: x = K.random_element() + sage: x == x True - sage: x == x + 1 # optional - sage.rings.finite_rings + sage: x == x + 1 False - sage: x == x^25 # optional - sage.rings.finite_rings + sage: x == x^25 True """ return left._backend._richcmp_(backend_element(right), op) @@ -387,13 +389,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: y = K.random_element() # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: x = K.random_element() # needs sage.rings.finite_rings + sage: y = K.random_element() # needs sage.rings.finite_rings - sage: (x+y).parent() is K # optional - sage.rings.finite_rings + sage: (x+y).parent() is K # needs sage.rings.finite_rings True - sage: x + y == y + x # optional - sage.rings.finite_rings + sage: x + y == y + x # needs sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -407,13 +409,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: x = K.random_element() # needs sage.rings.finite_rings - sage: y = -x # optional - sage.rings.finite_rings - sage: y.parent() is K # optional - sage.rings.finite_rings + sage: y = -x # needs sage.rings.finite_rings + sage: y.parent() is K # needs sage.rings.finite_rings True - sage: x + y == 0 # optional - sage.rings.finite_rings + sage: x + y == 0 # needs sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -427,13 +429,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: y = K.random_element() # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: x = K.random_element() # needs sage.rings.finite_rings + sage: y = K.random_element() # needs sage.rings.finite_rings - sage: (x-y).parent() is K # optional - sage.rings.finite_rings + sage: (x-y).parent() is K # needs sage.rings.finite_rings True - sage: x - y == x + (-y) # optional - sage.rings.finite_rings + sage: x - y == x + (-y) # needs sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -447,13 +449,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: y = K.random_element() # optional - sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: x = K.random_element() # needs sage.rings.finite_rings + sage: y = K.random_element() # needs sage.rings.finite_rings - sage: (x*y).parent() is K # optional - sage.rings.finite_rings + sage: (x*y).parent() is K # needs sage.rings.finite_rings True - sage: x * y == y * x # optional - sage.rings.finite_rings + sage: x * y == y * x # needs sage.rings.finite_rings True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -469,16 +471,16 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: OK = A.over() # optional - sage.rings.number_field - sage: a = OK(a) # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: OK = A.over() # needs sage.rings.number_field + sage: a = OK(a) # needs sage.rings.number_field - sage: b = 1/a; b # optional - sage.rings.number_field + sage: b = 1/a; b # needs sage.rings.number_field a/2 - sage: b.parent() # optional - sage.rings.number_field + sage: b.parent() # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: a*b # optional - sage.rings.number_field + sage: a*b # needs sage.rings.number_field 1 """ cdef RingExtensionElement ans @@ -497,8 +499,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: a.additive_order() # optional - sage.rings.finite_rings + sage: K. = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: a.additive_order() # needs sage.rings.finite_rings 5 """ return self._backend.additive_order() @@ -509,8 +511,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^4).over(GF(5^2)) # optional - sage.rings.finite_rings - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: K. = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings + sage: a.multiplicative_order() # needs sage.rings.finite_rings 624 """ return self._backend.multiplicative_order() @@ -553,9 +555,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): sage: A. = PolynomialRing(QQ) sage: E = A.over(QQ) - sage: E(x^2 + 1).is_prime() # optional - sage.libs.pari + sage: E(x^2 + 1).is_prime() # needs sage.libs.pari True - sage: E(x^2 - 1).is_prime() # optional - sage.libs.pari + sage: E(x^2 - 1).is_prime() # needs sage.libs.pari False """ return self._backend.is_prime() @@ -571,16 +573,16 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: a.is_square() # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over() # needs sage.rings.finite_rings + sage: a.is_square() # needs sage.rings.finite_rings False - sage: a.is_square(root=True) # optional - sage.rings.finite_rings + sage: a.is_square(root=True) # needs sage.rings.finite_rings (False, None) - sage: b = a + 1 # optional - sage.rings.finite_rings - sage: b.is_square() # optional - sage.rings.finite_rings + sage: b = a + 1 # needs sage.rings.finite_rings + sage: b.is_square() # needs sage.rings.finite_rings True - sage: b.is_square(root=True) # optional - sage.rings.finite_rings + sage: b.is_square(root=True) # needs sage.rings.finite_rings (True, 2 + 3*a + a^2) """ is_sq = self._backend.is_square() @@ -615,11 +617,12 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: b = a + 1 # optional - sage.rings.finite_rings - sage: b.sqrt() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: b = a + 1 + sage: b.sqrt() 2 + 3*a + a^2 - sage: b.sqrt(all=True) # optional - sage.rings.finite_rings + sage: b.sqrt(all=True) [2 + 3*a + a^2, 3 + 2*a - a^2] """ sq = self._backend.sqrt(extend=extend, all=all) @@ -665,8 +668,8 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES: - sage: E. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: hash(a) # optional - sage.rings.finite_rings + sage: E. = GF(5^3).over() # needs sage.rings.finite_rings + sage: hash(a) # needs sage.rings.finite_rings 5 """ return hash(self._backend) @@ -746,29 +749,29 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: OK = A.over() # over ZZ # optional - sage.rings.number_field - sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: OK = A.over() # over ZZ # needs sage.rings.number_field + sage: K = OK.fraction_field(); K # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: x = K(1/a); x # optional - sage.rings.number_field + sage: x = K(1/a); x # needs sage.rings.number_field a/2 - sage: num = x.numerator(); num # optional - sage.rings.number_field + sage: num = x.numerator(); num # needs sage.rings.number_field a The numerator is an element of the ring which was used to construct the fraction field:: - sage: num.parent() # optional - sage.rings.number_field + sage: num.parent() # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: num.parent() is OK # optional - sage.rings.number_field + sage: num.parent() is OK # needs sage.rings.number_field True TESTS:: - sage: x = K.random_element() # optional - sage.rings.number_field - sage: x == x.numerator() / x.denominator() # optional - sage.rings.number_field + sage: x = K.random_element() # needs sage.rings.number_field + sage: x == x.numerator() / x.denominator() # needs sage.rings.number_field True """ ring = (self._parent)._ring @@ -782,29 +785,29 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: sage: R. = ZZ[] - sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: OK = A.over() # over ZZ # optional - sage.rings.number_field - sage: K = OK.fraction_field(); K # optional - sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field + sage: OK = A.over() # over ZZ # needs sage.rings.number_field + sage: K = OK.fraction_field(); K # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: x = K(1/a); x # optional - sage.rings.number_field + sage: x = K(1/a); x # needs sage.rings.number_field a/2 - sage: denom = x.denominator(); denom # optional - sage.rings.number_field + sage: denom = x.denominator(); denom # needs sage.rings.number_field 2 The denominator is an element of the ring which was used to construct the fraction field:: - sage: denom.parent() # optional - sage.rings.number_field + sage: denom.parent() # needs sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: denom.parent() is OK # optional - sage.rings.number_field + sage: denom.parent() is OK # needs sage.rings.number_field True TESTS:: - sage: x = K.random_element() # optional - sage.rings.number_field - sage: x == x.numerator() / x.denominator() # optional - sage.rings.number_field + sage: x = K.random_element() # needs sage.rings.number_field + sage: x == x.numerator() / x.denominator() # needs sage.rings.number_field True """ ring = (self._parent)._ring @@ -821,11 +824,12 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings - sage: type(b) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: L. = GF(5^9).over(K) + sage: type(b) - sage: TestSuite(b).run() # optional - sage.rings.finite_rings + sage: TestSuite(b).run() """ def __hash__(self): """ @@ -833,8 +837,8 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES: - sage: E. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: hash(a) # optional - sage.rings.finite_rings + sage: E. = GF(5^3).over() # needs sage.rings.finite_rings + sage: hash(a) # needs sage.rings.finite_rings 5 """ return hash(self._backend) @@ -852,13 +856,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings - sage: u = 1/(a+b) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over() # needs sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings + sage: u = 1/(a+b) # needs sage.rings.finite_rings - sage: u._repr_extension(base=K) # optional - sage.rings.finite_rings + sage: u._repr_extension(base=K) # needs sage.rings.finite_rings '(2 + 2*a) + (-1 + a - a^2)*b + (2 + 3*a + 3*a^2)*b^2' - sage: u._repr_extension(base=GF(5)) # optional - sage.rings.finite_rings + sage: u._repr_extension(base=GF(5)) # needs sage.rings.finite_rings '2 + 2*a - b + a*b - a^2*b + 2*b^2 + 3*a*b^2 + 3*a^2*b^2' """ cdef RingExtensionWithBasis parent = self._parent @@ -930,13 +934,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # optional - sage.rings.finite_rings - sage: L. = GF(5^9).over(K) # optional - sage.rings.finite_rings - sage: u = 1/(a+b) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over() # needs sage.rings.finite_rings + sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings + sage: u = 1/(a+b) # needs sage.rings.finite_rings - sage: u._latex_extension(base=K) # optional - sage.rings.finite_rings + sage: u._latex_extension(base=K) # needs sage.rings.finite_rings \left( 2 + 2 a \right) + \left( -1 + a - a^{2} \right) b + \left( 2 + 3 a + 3 a^{2} \right) b^{2} - sage: u._latex_extension(base=GF(5)) # optional - sage.rings.finite_rings + sage: u._latex_extension(base=GF(5)) # needs sage.rings.finite_rings 2 + 2 a - b + ab - a^{2}b + 2 b^{2} + 3 ab^{2} + 3 a^{2}b^{2} """ cdef RingExtensionWithBasis parent = self._parent @@ -996,28 +1000,29 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^2).over() # over F # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: x = (a+b)^4; x # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5) + sage: K. = GF(5^2).over() # over F + sage: L. = GF(5^6).over(K) + sage: x = (a+b)^4; x (-1 + a) + (3 + a)*b + (1 - a)*b^2 - sage: x.vector(K) # basis is (1, b, b^2) # optional - sage.rings.finite_rings + sage: x.vector(K) # basis is (1, b, b^2) # needs sage.rings.finite_rings (-1 + a, 3 + a, 1 - a) - sage: x.vector(F) # basis is (1, a, b, a*b, b^2, a*b^2) # optional - sage.rings.finite_rings + sage: x.vector(F) # basis is (1, a, b, a*b, b^2, a*b^2) # needs sage.rings.finite_rings (4, 1, 3, 1, 1, 4) If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: x.vector() # optional - sage.rings.finite_rings + sage: x.vector() # needs sage.rings.finite_rings (-1 + a, 3 + a, 1 - a) Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: x.vector(GF(5^3)) # optional - sage.rings.finite_rings + sage: x.vector(GF(5^3)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3 @@ -1037,11 +1042,12 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: K = GF(11^10).over(GF(11^2)) # optional - sage.rings.finite_rings - sage: x = K.random_element() # optional - sage.rings.finite_rings - sage: coeffs = x.vector() # optional - sage.rings.finite_rings - sage: basis = K.basis_over() # optional - sage.rings.finite_rings - sage: x == sum(coeffs[i]*basis[i] for i in range(5)) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(11^10).over(GF(11^2)) + sage: x = K.random_element() + sage: coeffs = x.vector() + sage: basis = K.basis_over() + sage: x == sum(coeffs[i]*basis[i] for i in range(5)) True """ _, _, j = (self._parent)._free_module(base, map=True) @@ -1060,55 +1066,56 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^4).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^12).over(K) # optional - sage.rings.finite_rings - sage: u = 1/(a + b + c); u # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F. = GF(5^2).over() # over GF(5) + sage: K. = GF(5^4).over(F) + sage: L. = GF(5^12).over(K) + sage: u = 1/(a + b + c); u (2 + (-1 - a)*b) + ((2 + 3*a) + (1 - a)*b)*c + ((-1 - a) - a*b)*c^2 - sage: P = u.polynomial(K); P # optional - sage.rings.finite_rings + sage: P = u.polynomial(K); P # needs sage.rings.finite_rings ((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b - sage: P.base_ring() is K # optional - sage.rings.finite_rings + sage: P.base_ring() is K # needs sage.rings.finite_rings True - sage: P(c) == u # optional - sage.rings.finite_rings + sage: P(c) == u # needs sage.rings.finite_rings True When the base is `F`, we obtain a bivariate polynomial:: - sage: P = u.polynomial(F); P # optional - sage.rings.finite_rings + sage: P = u.polynomial(F); P # needs sage.rings.finite_rings (-a)*x0^2*x1 + (-1 - a)*x0^2 + (1 - a)*x0*x1 + (2 + 3*a)*x0 + (-1 - a)*x1 + 2 We check that its value at the generators is the element we started with:: - sage: L.gens(F) # optional - sage.rings.finite_rings + sage: L.gens(F) # needs sage.rings.finite_rings (c, b) - sage: P(c, b) == u # optional - sage.rings.finite_rings + sage: P(c, b) == u # needs sage.rings.finite_rings True Similarly, when the base is ``GF(5)``, we get a trivariate polynomial: - sage: P = u.polynomial(GF(5)); P # optional - sage.rings.finite_rings + sage: P = u.polynomial(GF(5)); P # needs sage.rings.finite_rings -x0^2*x1*x2 - x0^2*x2 - x0*x1*x2 - x0^2 + x0*x1 - 2*x0*x2 - x1*x2 + 2*x0 - x1 + 2 - sage: P(c, b, a) == u # optional - sage.rings.finite_rings + sage: P(c, b, a) == u # needs sage.rings.finite_rings True Different variable names can be specified:: - sage: u.polynomial(GF(5), var='y') # optional - sage.rings.finite_rings + sage: u.polynomial(GF(5), var='y') # needs sage.rings.finite_rings -y0^2*y1*y2 - y0^2*y2 - y0*y1*y2 - y0^2 + y0*y1 - 2*y0*y2 - y1*y2 + 2*y0 - y1 + 2 - sage: u.polynomial(GF(5), var=['x','y','z']) # optional - sage.rings.finite_rings + sage: u.polynomial(GF(5), var=['x','y','z']) # needs sage.rings.finite_rings -x^2*y*z - x^2*z - x*y*z - x^2 + x*y - 2*x*z - y*z + 2*x - y + 2 If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.polynomial() # optional - sage.rings.finite_rings + sage: u.polynomial() # needs sage.rings.finite_rings ((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.polynomial(GF(5^3)) # optional - sage.rings.finite_rings + sage: u.polynomial(GF(5^3)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3 @@ -1149,19 +1156,19 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # over GF(5) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: u = a/(1+b) # optional - sage.rings.finite_rings + sage: K. = GF(5^3).over() # over GF(5) # needs sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings + sage: u = a/(1+b) # needs sage.rings.finite_rings - sage: u # optional - sage.rings.finite_rings + sage: u # needs sage.rings.finite_rings (2 + a + 3*a^2) + (3 + 3*a + a^2)*b - sage: b*u # optional - sage.rings.finite_rings + sage: b*u # needs sage.rings.finite_rings (3 + 2*a^2) + (2 + 2*a - a^2)*b - sage: u.matrix(K) # optional - sage.rings.finite_rings + sage: u.matrix(K) # needs sage.rings.finite_rings [2 + a + 3*a^2 3 + 3*a + a^2] [ 3 + 2*a^2 2 + 2*a - a^2] - sage: u.matrix(GF(5)) # optional - sage.rings.finite_rings + sage: u.matrix(GF(5)) # needs sage.rings.finite_rings [2 1 3 3 3 1] [1 3 1 2 0 3] [2 3 3 1 3 0] @@ -1172,14 +1179,14 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.matrix() # optional - sage.rings.finite_rings + sage: u.matrix() # needs sage.rings.finite_rings [2 + a + 3*a^2 3 + 3*a + a^2] [ 3 + 2*a^2 2 + 2*a - a^2] Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.matrix(GF(5^2)) # optional - sage.rings.finite_rings + sage: u.matrix(GF(5^2)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1205,11 +1212,11 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) # optional - sage.rings.finite_rings - sage: K = GF(11^6).over(F) # optional - sage.rings.finite_rings - sage: L = GF(11^18).over(K) # optional - sage.rings.finite_rings + sage: F = GF(11^2) # needs sage.rings.finite_rings + sage: K = GF(11^6).over(F) # needs sage.rings.finite_rings + sage: L = GF(11^18).over(K) # needs sage.rings.finite_rings - sage: for base in L.bases(): # optional - sage.rings.finite_rings + sage: for base in L.bases(): # needs sage.rings.finite_rings ....: x = L.random_element() ....: y = L.random_element() ....: assert((x+y).matrix(base) == x.matrix(base) + y.matrix(base)) @@ -1233,41 +1240,42 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: u = a/(1+b) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5) + sage: K. = GF(5^3).over(F) + sage: L. = GF(5^6).over(K) + sage: u = a/(1+b) - sage: tr = u.trace(K); tr # optional - sage.rings.finite_rings + sage: tr = u.trace(K); tr # needs sage.rings.finite_rings -1 + 3*a + 2*a^2 We check that the trace lives in the base ring:: - sage: tr.parent() # optional - sage.rings.finite_rings + sage: tr.parent() # needs sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: tr.parent() is K # optional - sage.rings.finite_rings + sage: tr.parent() is K # needs sage.rings.finite_rings True Similarly, one can compute the trace over F:: - sage: u.trace(F) # optional - sage.rings.finite_rings + sage: u.trace(F) # needs sage.rings.finite_rings 0 We check the transitivity of the trace:: - sage: u.trace(F) == tr.trace(F) # optional - sage.rings.finite_rings + sage: u.trace(F) == tr.trace(F) # needs sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.trace() # optional - sage.rings.finite_rings + sage: u.trace() # needs sage.rings.finite_rings -1 + 3*a + 2*a^2 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.trace(GF(5^2)) # optional - sage.rings.finite_rings + sage: u.trace(GF(5^2)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1292,15 +1300,15 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) # optional - sage.rings.finite_rings - sage: K = GF(11^6).over(F) # optional - sage.rings.finite_rings - sage: L = GF(11^18).over(K) # optional - sage.rings.finite_rings + sage: F = GF(11^2) # needs sage.rings.finite_rings + sage: K = GF(11^6).over(F) # needs sage.rings.finite_rings + sage: L = GF(11^18).over(K) # needs sage.rings.finite_rings - sage: x = L.random_element() # optional - sage.rings.finite_rings - sage: x.trace(F) == x.trace().trace() # optional - sage.rings.finite_rings + sage: x = L.random_element() # needs sage.rings.finite_rings + sage: x.trace(F) == x.trace().trace() # needs sage.rings.finite_rings True - sage: for base in L.bases(): # optional - sage.rings.finite_rings + sage: for base in L.bases(): # needs sage.rings.finite_rings ....: x = L.random_element() ....: y = L.random_element() ....: assert(x.trace(base) == x.matrix(base).trace()) @@ -1327,41 +1335,42 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: u = a/(1+b) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5) + sage: K. = GF(5^3).over(F) + sage: L. = GF(5^6).over(K) + sage: u = a/(1+b) - sage: nr = u.norm(K); nr # optional - sage.rings.finite_rings + sage: nr = u.norm(K); nr # needs sage.rings.finite_rings 3 + 2*a^2 We check that the norm lives in the base ring:: - sage: nr.parent() # optional - sage.rings.finite_rings + sage: nr.parent() # needs sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: nr.parent() is K # optional - sage.rings.finite_rings + sage: nr.parent() is K # needs sage.rings.finite_rings True Similarly, one can compute the norm over F:: - sage: u.norm(F) # optional - sage.rings.finite_rings + sage: u.norm(F) # needs sage.rings.finite_rings 4 We check the transitivity of the norm:: - sage: u.norm(F) == nr.norm(F) # optional - sage.rings.finite_rings + sage: u.norm(F) == nr.norm(F) # needs sage.rings.finite_rings True If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.norm() # optional - sage.rings.finite_rings + sage: u.norm() # needs sage.rings.finite_rings 3 + 2*a^2 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.norm(GF(5^2)) # optional - sage.rings.finite_rings + sage: u.norm(GF(5^2)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1386,15 +1395,15 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) # optional - sage.rings.finite_rings - sage: K = GF(11^6).over(F) # optional - sage.rings.finite_rings - sage: L = GF(11^18).over(K) # optional - sage.rings.finite_rings + sage: F = GF(11^2) # needs sage.rings.finite_rings + sage: K = GF(11^6).over(F) # needs sage.rings.finite_rings + sage: L = GF(11^18).over(K) # needs sage.rings.finite_rings - sage: x = L.random_element() # optional - sage.rings.finite_rings - sage: x.norm(F) == x.norm().norm() # optional - sage.rings.finite_rings + sage: x = L.random_element() # needs sage.rings.finite_rings + sage: x.norm(F) == x.norm().norm() # needs sage.rings.finite_rings True - sage: for base in L.bases(): # optional - sage.rings.finite_rings + sage: for base in L.bases(): # needs sage.rings.finite_rings ....: x = L.random_element() ....: y = L.random_element() ....: assert(x.norm(base) == x.matrix(base).determinant()) @@ -1421,46 +1430,47 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: u = a/(1+b) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5) + sage: K. = GF(5^3).over(F) + sage: L. = GF(5^6).over(K) + sage: u = a/(1+b) - sage: chi = u.charpoly(K); chi # optional - sage.rings.finite_rings + sage: chi = u.charpoly(K); chi # needs sage.rings.finite_rings x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2 We check that the charpoly has coefficients in the base ring:: - sage: chi.base_ring() # optional - sage.rings.finite_rings + sage: chi.base_ring() # needs sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: chi.base_ring() is K # optional - sage.rings.finite_rings + sage: chi.base_ring() is K # needs sage.rings.finite_rings True and that it annihilates u:: - sage: chi(u) # optional - sage.rings.finite_rings + sage: chi(u) # needs sage.rings.finite_rings 0 Similarly, one can compute the characteristic polynomial over F:: - sage: u.charpoly(F) # optional - sage.rings.finite_rings + sage: u.charpoly(F) # needs sage.rings.finite_rings x^6 + x^4 + 2*x^3 + 3*x + 4 A different variable name can be specified:: - sage: u.charpoly(F, var='t') # optional - sage.rings.finite_rings + sage: u.charpoly(F, var='t') # needs sage.rings.finite_rings t^6 + t^4 + 2*t^3 + 3*t + 4 If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.charpoly() # optional - sage.rings.finite_rings + sage: u.charpoly() # needs sage.rings.finite_rings x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2 Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.charpoly(GF(5^2)) # optional - sage.rings.finite_rings + sage: u.charpoly(GF(5^2)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1470,9 +1480,9 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): We check that the characteristic polynomial of an element in the base ring is a power of a polynomial of degree 1:: - sage: S. = K[] # optional - sage.rings.finite_rings - sage: u = K.random_element() # optional - sage.rings.finite_rings - sage: L(u).charpoly() == (x - u)^2 # optional - sage.rings.finite_rings + sage: S. = K[] # needs sage.rings.finite_rings + sage: u = K.random_element() # needs sage.rings.finite_rings + sage: L(u).charpoly() == (x - u)^2 # needs sage.rings.finite_rings True """ return self.matrix(base).charpoly(var) @@ -1488,46 +1498,47 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^3).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: u = 1 / (a+b) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5) + sage: K. = GF(5^3).over(F) + sage: L. = GF(5^6).over(K) + sage: u = 1 / (a+b) - sage: chi = u.minpoly(K); chi # optional - sage.rings.finite_rings + sage: chi = u.minpoly(K); chi # needs sage.rings.finite_rings x^2 + (2*a + a^2)*x - 1 + a We check that the minimal polynomial has coefficients in the base ring:: - sage: chi.base_ring() # optional - sage.rings.finite_rings + sage: chi.base_ring() # needs sage.rings.finite_rings Field in a with defining polynomial x^3 + 3*x + 3 over its base - sage: chi.base_ring() is K # optional - sage.rings.finite_rings + sage: chi.base_ring() is K # needs sage.rings.finite_rings True and that it annihilates u:: - sage: chi(u) # optional - sage.rings.finite_rings + sage: chi(u) # needs sage.rings.finite_rings 0 Similarly, one can compute the minimal polynomial over F:: - sage: u.minpoly(F) # optional - sage.rings.finite_rings + sage: u.minpoly(F) # needs sage.rings.finite_rings x^6 + 4*x^5 + x^4 + 2*x^2 + 3 A different variable name can be specified:: - sage: u.minpoly(F, var='t') # optional - sage.rings.finite_rings + sage: u.minpoly(F, var='t') # needs sage.rings.finite_rings t^6 + 4*t^5 + t^4 + 2*t^2 + 3 If ``base`` is omitted, it is set to its default which is the base of the extension:: - sage: u.minpoly() # optional - sage.rings.finite_rings + sage: u.minpoly() # needs sage.rings.finite_rings x^2 + (2*a + a^2)*x - 1 + a Note that ``base`` must be an explicit base over which the extension has been defined (as listed by the method :meth:`bases`):: - sage: u.minpoly(GF(5^2)) # optional - sage.rings.finite_rings + sage: u.minpoly(GF(5^2)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2 @@ -1537,15 +1548,15 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): We check that the minimal polynomial of an element in the base ring has degree 1:: - sage: S. = K[] # optional - sage.rings.finite_rings - sage: u = K.random_element() # optional - sage.rings.finite_rings - sage: L(u).minpoly() == x - u # optional - sage.rings.finite_rings + sage: S. = K[] # needs sage.rings.finite_rings + sage: u = K.random_element() # needs sage.rings.finite_rings + sage: L(u).minpoly() == x - u # needs sage.rings.finite_rings True In a similar fashion, the minimal polynomial over `F` of an element of `K` should have degree 1 or 3:: - sage: L(u).minpoly(F).degree() in [ 1, 3 ] # optional - sage.rings.finite_rings + sage: L(u).minpoly(F).degree() in [ 1, 3 ] # needs sage.rings.finite_rings True """ cdef RingExtensionWithBasis parent = self._parent diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index bd5b012cfaa..fca3eca6f09 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -83,19 +83,19 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # optional - sage.rings.finite_rings - sage: L. = GF(5^4).over(K) # optional - sage.rings.finite_rings - sage: phi = L.hom([b^5, a^5]); phi # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # needs sage.rings.finite_rings + sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings + sage: phi = L.hom([b^5, a^5]); phi # needs sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^2 + (3 - a)*x + a over its base Defn: b |--> (2 + a) + 2*b with map on base ring: a |--> 1 - a - sage: type(phi) # optional - sage.rings.finite_rings + sage: type(phi) # needs sage.rings.finite_rings - sage: TestSuite(phi).run() # optional - sage.rings.finite_rings + sage: TestSuite(phi).run() # needs sage.rings.finite_rings """ def __init__(self, parent, defn, base_map=None, check=True): @@ -219,12 +219,12 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = K.hom([a^5]); f # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = K.hom([a^5]); f # needs sage.rings.finite_rings Ring endomorphism of Field in a with defining polynomial x^2 + 4*x + 2 over its base Defn: a |--> 1 - a - sage: f._repr_type() # optional - sage.rings.finite_rings + sage: f._repr_type() # needs sage.rings.finite_rings 'Ring' """ return "Ring" @@ -240,19 +240,19 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: sage: x = polygen(QQ, 'x') - sage: A. = QQ.extension(x^2 - 2) # optional - sage.rings.number_field - sage: K. = A.over() # optional - sage.rings.number_field - sage: f = K.hom([-sqrt2]); f # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field + sage: K. = A.over() # needs sage.rings.number_field + sage: f = K.hom([-sqrt2]); f # needs sage.rings.number_field Ring endomorphism of Field in sqrt2 with defining polynomial x^2 - 2 over its base Defn: sqrt2 |--> -sqrt2 - sage: f(sqrt2) # optional - sage.rings.number_field + sage: f(sqrt2) # needs sage.rings.number_field -sqrt2 TESTS:: sage: a = QQ.random_element() sage: b = QQ.random_element() - sage: f(a + b*sqrt2) == a - b*sqrt2 # optional - sage.rings.number_field + sage: f(a + b*sqrt2) == a - b*sqrt2 # needs sage.rings.number_field True """ y = self._backend(backend_element(x)) @@ -268,19 +268,19 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: F = GF(5) # optional - sage.rings.finite_rings - sage: K. = GF(5^2).over(F) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: F = GF(5) # needs sage.rings.finite_rings + sage: K. = GF(5^2).over(F) # needs sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings We define the absolute Frobenius of L:: - sage: FrobL = L.hom([b^5, a^5]); FrobL # optional - sage.rings.finite_rings + sage: FrobL = L.hom([b^5, a^5]); FrobL # needs sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a - sage: FrobL.base_map() # optional - sage.rings.finite_rings + sage: FrobL.base_map() # needs sage.rings.finite_rings Ring morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base @@ -289,11 +289,11 @@ cdef class RingExtensionHomomorphism(RingMap): The square of ``FrobL`` acts trivially on K; in other words, it has a trivial base map:: - sage: phi = FrobL^2; phi # optional - sage.rings.finite_rings + sage: phi = FrobL^2; phi # needs sage.rings.finite_rings Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: b |--> 2 + 2*a*b + (2 - a)*b^2 - sage: phi.base_map() # optional - sage.rings.finite_rings + sage: phi.base_map() # needs sage.rings.finite_rings """ domain = self.domain() @@ -332,15 +332,15 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings - sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings - sage: FrobL = L.hom([b^5], base_map=FrobK) # optional - sage.rings.finite_rings + sage: FrobK = K.hom([a^5]) # needs sage.rings.finite_rings + sage: FrobL = L.hom([b^5], base_map=FrobK) # needs sage.rings.finite_rings - sage: FrobK^2 == End(K).identity() # optional - sage.rings.finite_rings + sage: FrobK^2 == End(K).identity() # needs sage.rings.finite_rings True - sage: FrobL^6 == End(L).identity() # optional - sage.rings.finite_rings + sage: FrobL^6 == End(L).identity() # needs sage.rings.finite_rings True """ eq = are_equal_morphisms(self._backend, backend_morphism(other)) @@ -356,22 +356,23 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: FrobK = K.hom([a^5]) # optional - sage.rings.finite_rings - sage: FrobK.is_identity() # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) + sage: FrobK = K.hom([a^5]) + sage: FrobK.is_identity() False - sage: (FrobK^2).is_identity() # optional - sage.rings.finite_rings + sage: (FrobK^2).is_identity() True Coercion maps are not considered as identity morphisms:: - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: iota = L.defining_morphism(); iota # optional - sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings + sage: iota = L.defining_morphism(); iota # needs sage.rings.finite_rings Ring morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: a |--> a - sage: iota.is_identity() # optional - sage.rings.finite_rings + sage: iota.is_identity() # needs sage.rings.finite_rings False """ if self.domain() is not self.codomain(): @@ -384,23 +385,23 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K = GF(5^10).over(GF(5^5)) # optional - sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings + sage: K = GF(5^10).over(GF(5^5)) # needs sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings Ring morphism: From: Finite Field in z5 of size 5^5 To: Field in z10 with defining polynomial x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base Defn: z5 |--> z5 - sage: iota.is_injective() # optional - sage.rings.finite_rings + sage: iota.is_injective() # needs sage.rings.finite_rings True - sage: K = GF(7).over(ZZ) # optional - sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings + sage: K = GF(7).over(ZZ) # needs sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base Defn: 1 |--> 1 - sage: iota.is_injective() # optional - sage.rings.finite_rings + sage: iota.is_injective() # needs sage.rings.finite_rings False """ return self._backend.is_injective() @@ -411,23 +412,23 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K = GF(5^10).over(GF(5^5)) # optional - sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings + sage: K = GF(5^10).over(GF(5^5)) # needs sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings Ring morphism: From: Finite Field in z5 of size 5^5 To: Field in z10 with defining polynomial x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base Defn: z5 |--> z5 - sage: iota.is_surjective() # optional - sage.rings.finite_rings + sage: iota.is_surjective() # needs sage.rings.finite_rings False - sage: K = GF(7).over(ZZ) # optional - sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # optional - sage.rings.finite_rings + sage: K = GF(7).over(ZZ) # needs sage.rings.finite_rings + sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base Defn: 1 |--> 1 - sage: iota.is_surjective() # optional - sage.rings.finite_rings + sage: iota.is_surjective() # needs sage.rings.finite_rings True """ return self._backend.is_surjective() @@ -441,11 +442,11 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # optional - sage.rings.finite_rings - sage: FrobL = L.hom([b^5, a^5]) # absolute Frobenius # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings + sage: FrobL = L.hom([b^5, a^5]) # absolute Frobenius # needs sage.rings.finite_rings - sage: print(FrobL._repr_defn()) # optional - sage.rings.finite_rings + sage: print(FrobL._repr_defn()) # needs sage.rings.finite_rings b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a @@ -473,13 +474,13 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) # optional - sage.rings.number_field - sage: K. = A.over() # optional - sage.rings.number_field - sage: f = K.hom([-sqrt5]); f # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 5) # needs sage.rings.number_field + sage: K. = A.over() # needs sage.rings.number_field + sage: f = K.hom([-sqrt5]); f # needs sage.rings.number_field Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> -sqrt5 - sage: f^2 # indirect doctest # optional - sage.rings.number_field + sage: f^2 # indirect doctest # needs sage.rings.number_field Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> sqrt5 """ @@ -498,13 +499,13 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = K.hom([a^5]) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = K.hom([a^5]) # needs sage.rings.finite_rings - sage: g = copy(f) # indirect doctest # optional - sage.rings.finite_rings - sage: f == g # optional - sage.rings.finite_rings + sage: g = copy(f) # indirect doctest # needs sage.rings.finite_rings + sage: f == g # needs sage.rings.finite_rings True - sage: f is g # optional - sage.rings.finite_rings + sage: f is g # needs sage.rings.finite_rings False """ self._backend = _slots['_backend'] @@ -516,9 +517,9 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = K.hom([a^5]) # optional - sage.rings.finite_rings - sage: loads(dumps(f)) == f # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = K.hom([a^5]) # needs sage.rings.finite_rings + sage: loads(dumps(f)) == f # needs sage.rings.finite_rings True """ slots = RingMap._extra_slots(self) @@ -533,17 +534,17 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: - sage: K = GF(11^9).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: f = K.coerce_map_from(GF(11^9)); f # optional - sage.rings.finite_rings + sage: K = GF(11^9).over(GF(11^3)) # needs sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(11^9)); f # needs sage.rings.finite_rings Coercion morphism: From: Finite Field in z9 of size 11^9 To: Field in z9 with defining polynomial x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base - sage: type(f) # optional - sage.rings.finite_rings + sage: type(f) # needs sage.rings.finite_rings - sage: TestSuite(f).run() # optional - sage.rings.finite_rings + sage: TestSuite(f).run() # needs sage.rings.finite_rings """ def __init__(self, parent): r""" @@ -552,9 +553,9 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) # optional - sage.rings.number_field - sage: K = A.over() # optional - sage.rings.number_field - sage: K.coerce_map_from(A) # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 5) # needs sage.rings.number_field + sage: K = A.over() # needs sage.rings.number_field + sage: K.coerce_map_from(A) # needs sage.rings.number_field Coercion morphism: From: Number Field in a with defining polynomial x^2 - 5 To: Field in a with defining polynomial x^2 - 5 over its base @@ -569,13 +570,13 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = K.coerce_map_from(GF(5^2)); f # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(5^2)); f # needs sage.rings.finite_rings Coercion morphism: From: Finite Field in z2 of size 5^2 To: Field in a with defining polynomial x^2 + 4*x + 2 over its base - sage: f._repr_type() # optional - sage.rings.finite_rings + sage: f._repr_type() # needs sage.rings.finite_rings 'Coercion' """ return "Coercion" @@ -586,13 +587,13 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = K.coerce_map_from(GF(5^2)); f # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(5^2)); f # needs sage.rings.finite_rings Coercion morphism: From: Finite Field in z2 of size 5^2 To: Field in a with defining polynomial x^2 + 4*x + 2 over its base - sage: f._repr_defn() # optional - sage.rings.finite_rings + sage: f._repr_defn() # needs sage.rings.finite_rings '' """ return "" @@ -607,9 +608,9 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = K.coerce_map_from(GF(5^2)) # optional - sage.rings.finite_rings - sage: f(GF(5^2).gen()) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = K.coerce_map_from(GF(5^2)) # needs sage.rings.finite_rings + sage: f(GF(5^2).gen()) # needs sage.rings.finite_rings a """ codomain = self.codomain() @@ -623,17 +624,17 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: - sage: K = GF(11^9).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: f = GF(11^9).convert_map_from(K); f # optional - sage.rings.finite_rings + sage: K = GF(11^9).over(GF(11^3)) # needs sage.rings.finite_rings + sage: f = GF(11^9).convert_map_from(K); f # needs sage.rings.finite_rings Canonical morphism: From: Field in z9 with defining polynomial x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base To: Finite Field in z9 of size 11^9 - sage: type(f) # optional - sage.rings.finite_rings + sage: type(f) # needs sage.rings.finite_rings - sage: TestSuite(f).run() # optional - sage.rings.finite_rings + sage: TestSuite(f).run() # needs sage.rings.finite_rings """ def __init__(self, parent): @@ -643,9 +644,9 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) # optional - sage.rings.number_field - sage: K = A.over() # optional - sage.rings.number_field - sage: A.convert_map_from(K) # optional - sage.rings.number_field + sage: A. = QQ.extension(x^2 - 5) # needs sage.rings.number_field + sage: K = A.over() # needs sage.rings.number_field + sage: A.convert_map_from(K) # needs sage.rings.number_field Canonical morphism: From: Field in a with defining polynomial x^2 - 5 over its base To: Number Field in a with defining polynomial x^2 - 5 @@ -660,13 +661,13 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = GF(5^2).convert_map_from(K); f # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = GF(5^2).convert_map_from(K); f # needs sage.rings.finite_rings Canonical morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Finite Field in z2 of size 5^2 - sage: f._repr_type() # optional - sage.rings.finite_rings + sage: f._repr_type() # needs sage.rings.finite_rings 'Canonical' """ return "Canonical" @@ -677,13 +678,13 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = GF(5^2).convert_map_from(K); f # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = GF(5^2).convert_map_from(K); f # needs sage.rings.finite_rings Canonical morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Finite Field in z2 of size 5^2 - sage: f._repr_defn() # optional - sage.rings.finite_rings + sage: f._repr_defn() # needs sage.rings.finite_rings '' """ return "" @@ -698,9 +699,9 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # optional - sage.rings.finite_rings - sage: f = GF(5^2).convert_map_from(K) # optional - sage.rings.finite_rings - sage: f(a) # optional - sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings + sage: f = GF(5^2).convert_map_from(K) # needs sage.rings.finite_rings + sage: f(a) # needs sage.rings.finite_rings z2 """ return (x)._backend @@ -713,9 +714,9 @@ cdef class MapFreeModuleToRelativeRing(Map): TESTS:: - sage: K = GF(5^2).over() # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: type(i) # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: type(i) # needs sage.rings.finite_rings """ @@ -731,9 +732,9 @@ cdef class MapFreeModuleToRelativeRing(Map): TESTS:: - sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: i # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: i # needs sage.rings.finite_rings Generic map: From: Vector space of dimension 2 over Finite Field in z3 of size 11^3 To: Field in z6 with defining polynomial x^2 + (10*z3^2 + z3 + 6)*x + z3 over its base @@ -751,9 +752,9 @@ cdef class MapFreeModuleToRelativeRing(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: i.is_injective() # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: i.is_injective() # needs sage.rings.finite_rings True """ return True @@ -764,9 +765,9 @@ cdef class MapFreeModuleToRelativeRing(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: i.is_surjective() # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: i.is_surjective() # needs sage.rings.finite_rings True """ return True @@ -781,9 +782,9 @@ cdef class MapFreeModuleToRelativeRing(Map): EXAMPLES:: - sage: K. = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: i((0,1)) # optional - sage.rings.finite_rings + sage: K. = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: i((0,1)) # needs sage.rings.finite_rings a """ cdef Element elt @@ -800,9 +801,9 @@ cdef class MapRelativeRingToFreeModule(Map): TESTS:: - sage: K = GF(5^2).over() # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: type(j) # optional - sage.rings.finite_rings + sage: K = GF(5^2).over() # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: type(j) # needs sage.rings.finite_rings """ @@ -818,9 +819,9 @@ cdef class MapRelativeRingToFreeModule(Map): TESTS:: - sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: j # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: j # needs sage.rings.finite_rings Generic map: From: Field in z6 with defining polynomial x^2 + (10*z3^2 + z3 + 6)*x + z3 over its base To: Vector space of dimension 2 over Finite Field in z3 of size 11^3 @@ -860,9 +861,9 @@ cdef class MapRelativeRingToFreeModule(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: j.is_injective() # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: j.is_injective() # needs sage.rings.finite_rings True """ return True @@ -873,9 +874,9 @@ cdef class MapRelativeRingToFreeModule(Map): EXAMPLES:: - sage: K = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: j.is_surjective() # optional - sage.rings.finite_rings + sage: K = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: j.is_surjective() # needs sage.rings.finite_rings True """ return True @@ -890,9 +891,9 @@ cdef class MapRelativeRingToFreeModule(Map): EXAMPLES:: - sage: K. = GF(11^6).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: j(a) # optional - sage.rings.finite_rings + sage: K. = GF(11^6).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: j(a) # needs sage.rings.finite_rings (0, 1) """ coeffs = self.backend_coefficients(x) @@ -909,9 +910,9 @@ cdef class MapRelativeRingToFreeModule(Map): TESTS:: - sage: K. = GF(11^9).over(GF(11^3)) # optional - sage.rings.finite_rings - sage: V, i, j = K.free_module() # optional - sage.rings.finite_rings - sage: j(a + 2*a^2) # indirect doctest # optional - sage.rings.finite_rings + sage: K. = GF(11^9).over(GF(11^3)) # needs sage.rings.finite_rings + sage: V, i, j = K.free_module() # needs sage.rings.finite_rings + sage: j(a + 2*a^2) # indirect doctest # needs sage.rings.finite_rings (0, 1, 2) """ cdef list coeffs = [ ] diff --git a/src/sage/rings/tate_algebra_ideal.pyx b/src/sage/rings/tate_algebra_ideal.pyx index e9b45049897..e230a411397 100644 --- a/src/sage/rings/tate_algebra_ideal.pyx +++ b/src/sage/rings/tate_algebra_ideal.pyx @@ -623,7 +623,7 @@ cdef TateAlgebraElement regular_reduce(sgb, TateAlgebraTerm s, TateAlgebraElemen TESTS:: - sage: cython( # optional - sage.misc.cython + sage: cython( # needs sage.misc.cython ....: ''' ....: from sage.rings.tate_algebra_ideal cimport regular_reduce ....: def python_regular_reduce(gb, s, v, stopval): @@ -638,11 +638,12 @@ cdef TateAlgebraElement regular_reduce(sgb, TateAlgebraTerm s, TateAlgebraElemen sage: p1 = (tx, x^3 + 9*x*y) sage: p2 = (ty, x*y + 3*x^2*y) - sage: python_regular_reduce([p1,p2], tx*ty, v, 8) # indirect doctest + sage: python_regular_reduce([p1,p2], tx*ty, v, 8) # indirect doctest # needs sage.misc.cython (2 + O(3^8))*x^2*y + (1 + O(3^8))*x + (1 + O(3^8))*y + O(3^8 * ) - sage: python_regular_reduce([p1,p2], tx, v, 8) # indirect doctest - (2 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7 + O(3^8))*x^3 + (2 + O(3^8))*x^2*y + (1 + O(3^8))*x + (1 + O(3^8))*y + O(3^8 * ) + sage: python_regular_reduce([p1,p2], tx, v, 8) # indirect doctest # needs sage.misc.cython + (2 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7 + O(3^8))*x^3 + + (2 + O(3^8))*x^2*y + (1 + O(3^8))*x + (1 + O(3^8))*y + O(3^8 * ) """ # We assume that the elements of the sgb are such that lt(g) = p^v lm(g) to # avoid performing divisions @@ -713,11 +714,12 @@ cdef TateAlgebraElement reduce(gb, TateAlgebraElement v, stopval): sage: v = (x + y + 2*x^2*y - x^3*y^2).add_bigoh(8) sage: g1 = x*y + 3*x^2*y sage: g2 = x^3 + 9*y - sage: python_reduce([g1,g2], v, 8) # indirect doctest + sage: python_reduce([g1,g2], v, 8) # indirect doctest # needs sage.misc.cython (1 + O(3^8))*x + (1 + O(3^8))*y + O(3^8 * ) - sage: python_reduce([g1,g2], v, 5) # indirect doctest - (1 + O(3^8))*x + (1 + O(3^8))*y + (3^5 + O(3^8))*x^8*y^2 + (3^5 + 2*3^6 + 2*3^7 + O(3^8))*x^7*y + O(3^8 * ) + sage: python_reduce([g1,g2], v, 5) # indirect doctest # needs sage.misc.cython + (1 + O(3^8))*x + (1 + O(3^8))*y + (3^5 + O(3^8))*x^8*y^2 + + (3^5 + 2*3^6 + 2*3^7 + O(3^8))*x^7*y + O(3^8 * ) """ cdef dict coeffs = { } cdef TateAlgebraElement f diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 85977bf587b..1f9d195a048 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -23,9 +23,9 @@ def prime_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.prime_finite_field(); K # optional - sage.rings.finite_rings + sage: K = sage.rings.tests.prime_finite_field(); K # needs sage.rings.finite_rings Finite Field of size ... - sage: K.cardinality().is_prime() # optional - sage.rings.finite_rings + sage: K.cardinality().is_prime() # needs sage.rings.finite_rings True """ from sage.rings.integer_ring import ZZ @@ -42,11 +42,11 @@ def finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.finite_field(); K # optional - sage.rings.finite_rings + sage: K = sage.rings.tests.finite_field(); K # needs sage.rings.finite_rings Finite Field...of size ... - sage: K.cardinality().is_prime_power() # optional - sage.rings.finite_rings + sage: K.cardinality().is_prime_power() # needs sage.rings.finite_rings True - sage: while K.cardinality().is_prime(): # optional - sage.rings.finite_rings + sage: while K.cardinality().is_prime(): # needs sage.rings.finite_rings ....: K = sage.rings.tests.finite_field() """ from sage.rings.integer_ring import ZZ @@ -64,13 +64,14 @@ def small_finite_field(): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: import sage.rings.tests - sage: K = sage.rings.tests.small_finite_field(); K # optional - sage.rings.finite_rings + sage: K = sage.rings.tests.small_finite_field(); K Finite Field...of size ... - sage: q = K.cardinality() # optional - sage.rings.finite_rings - sage: q.is_prime_power() # optional - sage.rings.finite_rings + sage: q = K.cardinality() + sage: q.is_prime_power() True - sage: q <= 2^16 # optional - sage.rings.finite_rings + sage: q <= 2^16 True """ from sage.rings.integer_ring import ZZ @@ -107,7 +108,7 @@ def padic_field(): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.padic_field() # optional - sage.rings.padics + sage: sage.rings.tests.padic_field() # needs sage.rings.padics ...-adic Field with capped relative precision ... """ from sage.rings.integer_ring import ZZ @@ -124,7 +125,7 @@ def quadratic_number_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.quadratic_number_field(); K # optional - sage.rings.number_field + sage: K = sage.rings.tests.quadratic_number_field(); K # needs sage.rings.number_field Number Field in a with defining polynomial x^2 ... with a = ... """ from sage.rings.integer_ring import ZZ @@ -142,9 +143,9 @@ def absolute_number_field(maxdeg=10): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.absolute_number_field(); K # optional - sage.rings.number_field + sage: K = sage.rings.tests.absolute_number_field(); K # needs sage.rings.number_field Number Field in a with defining polynomial ... - sage: K.degree() <= 10 # optional - sage.rings.number_field + sage: K.degree() <= 10 # needs sage.rings.number_field True """ from sage.rings.integer_ring import ZZ @@ -166,27 +167,28 @@ def relative_number_field(n=2, maxdeg=2): EXAMPLES:: + sage: # needs sage.rings.number_field sage: import sage.rings.tests - sage: K = sage.rings.tests.relative_number_field(3); K # optional - sage.rings.number_field + sage: K = sage.rings.tests.relative_number_field(3); K Number Field in aaa with defining polynomial x^2 ... over its base field - sage: K.relative_degree() # optional - sage.rings.number_field + sage: K.relative_degree() 2 - sage: L = K.base_ring() # optional - sage.rings.number_field - sage: L.relative_degree() # optional - sage.rings.number_field + sage: L = K.base_ring() + sage: L.relative_degree() 2 - sage: M = L.base_ring() # optional - sage.rings.number_field - sage: M.relative_degree() # optional - sage.rings.number_field + sage: M = L.base_ring() + sage: M.relative_degree() 2 - sage: M.base_ring() is QQ # optional - sage.rings.number_field + sage: M.base_ring() is QQ True TESTS: Check that :trac:`32117` is fixed:: - 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 + sage: set_random_seed(3030) + sage: from sage.rings.tests import relative_number_field + sage: _ = relative_number_field(3) # needs sage.rings.number_field """ from sage.rings.integer_ring import ZZ K = absolute_number_field(maxdeg) @@ -333,7 +335,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) # optional - sage.rings.number_field + sage: sage.rings.tests.test_random_elements(trials=2, seed=0) # needs sage.rings.number_field survived 0 tests Rational Field -1/2 @@ -382,7 +384,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) # optional - sage.rings.number_field + sage: sage.rings.tests.test_random_arith(trials=2, seed=0) # needs sage.rings.number_field survived 0 tests Rational Field -1/2 -1/95 @@ -392,9 +394,9 @@ def test_random_arith(level=MAX_LEVEL, trials=1): a -2*a - 1 2*a - 30164 - sage: sage.rings.tests.test_random_arith(trials=10) # optional - sage.rings.finite_rings + sage: sage.rings.tests.test_random_arith(trials=10) # needs sage.rings.finite_rings survived 0 tests... - sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?), optional - sage.rings.finite_rings + sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?), needs sage.rings.finite_rings survived 0 tests... """ i = 0 @@ -438,15 +440,15 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, Test Karatsuba multiplication of polynomials of small degree over some common rings:: sage: rings = [QQ] - sage: rings += [ZZ[I], ZZ[I, sqrt(2)]] # optional - sage.rings.number_field - sage: rings += [GF(49, 'a')] # optional - sage.rings.finite_rings - sage: rings += [MatrixSpace(GF(17), 3)] # optional - sage.rings.finite_rings sage.modules + sage: rings += [ZZ[I], ZZ[I, sqrt(2)]] # needs sage.rings.number_field sage.symbolic + sage: rings += [GF(49, 'a')] # needs sage.rings.finite_rings + sage: rings += [MatrixSpace(GF(17), 3)] # needs sage.modules sage.rings.finite_rings sage: for C in rings: ....: test_karatsuba_multiplication(C, 10, 10) Zero-tests over ``QQbar`` are currently very slow, so we test only very small examples:: - sage: test_karatsuba_multiplication(QQbar, 3, 3, numtests=2) # long time # optional - sage.rings.number_field + sage: test_karatsuba_multiplication(QQbar, 3, 3, numtests=2) # long time, needs sage.rings.number_field Larger degrees (over ``ZZ``, using FLINT):: diff --git a/src/sage/rings/universal_cyclotomic_field.py b/src/sage/rings/universal_cyclotomic_field.py index 173224323ce..0c77ff11fb6 100644 --- a/src/sage/rings/universal_cyclotomic_field.py +++ b/src/sage/rings/universal_cyclotomic_field.py @@ -523,14 +523,14 @@ def _symbolic_(self, R): r""" TESTS:: - sage: SR(E(7)) # optional - sage.symbolic + sage: SR(E(7)) # needs sage.symbolic e^(2/7*I*pi) - sage: SR(E(5) + 2*E(5,2) + 3*E(5,3)) # optional - sage.symbolic + sage: SR(E(5) + 2*E(5,2) + 3*E(5,3)) # needs sage.symbolic -sqrt(5) + 1/4*I*sqrt(2*sqrt(5) + 10) - 1/4*I*sqrt(-2*sqrt(5) + 10) - 3/2 Test that the bug reported in :trac:`19912` has been fixed:: - sage: SR(1+E(4)) # optional - sage.symbolic + sage: SR(1+E(4)) # needs sage.symbolic I + 1 """ from sage.symbolic.constants import pi, I @@ -582,7 +582,8 @@ def to_cyclotomic_field(self, R=None): Using a non-standard embedding:: - sage: CF = CyclotomicField(5,embedding=CC(exp(4*pi*i/5))) + sage: # needs sage.symbolic + sage: CF = CyclotomicField(5, embedding=CC(exp(4*pi*i/5))) sage: x = E(5) sage: CC(x) 0.309016994374947 + 0.951056516295154*I @@ -723,7 +724,7 @@ def _eval_real_(self, R): sage: RR(E(7) + E(7,6)) 1.24697960371747 - sage: 2*cos(2*pi/7).n() + sage: 2*cos(2*pi/7).n() # needs sage.symbolic 1.24697960371747 Check that units are evaluated correctly (:trac:`23775`):: @@ -1485,7 +1486,7 @@ def _element_constructor_(self, elt): Some conversions from symbolic functions are possible:: sage: UCF = UniversalCyclotomicField() - sage: [UCF(sin(pi/k, hold=True)) for k in range(1,10)] + sage: [UCF(sin(pi/k, hold=True)) for k in range(1,10)] # needs sage.symbolic [0, 1, -1/2*E(12)^7 + 1/2*E(12)^11, @@ -1495,7 +1496,7 @@ def _element_constructor_(self, elt): -1/2*E(28)^19 + 1/2*E(28)^23, 1/2*E(16)^3 - 1/2*E(16)^5, -1/2*E(36)^25 + 1/2*E(36)^29] - sage: [UCF(cos(pi/k, hold=True)) for k in range(1,10)] + sage: [UCF(cos(pi/k, hold=True)) for k in range(1,10)] # needs sage.symbolic [-1, 0, 1/2, @@ -1506,8 +1507,9 @@ def _element_constructor_(self, elt): 1/2*E(16) - 1/2*E(16)^7, -1/2*E(9)^4 - 1/2*E(9)^5] - sage: UCF(1 + sqrt(-3/5)) - 4/5*E(15) + 4/5*E(15)^2 + 4/5*E(15)^4 + 6/5*E(15)^7 + 4/5*E(15)^8 + 6/5*E(15)^11 + 6/5*E(15)^13 + 6/5*E(15)^14 + sage: UCF(1 + sqrt(-3/5)) # needs sage.symbolic + 4/5*E(15) + 4/5*E(15)^2 + 4/5*E(15)^4 + 6/5*E(15)^7 + 4/5*E(15)^8 + + 6/5*E(15)^11 + 6/5*E(15)^13 + 6/5*E(15)^14 .. TODO:: From ffb797f52c6909aa68040b97eaa8046924088f12 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 13 Jul 2023 22:27:33 -0700 Subject: [PATCH 27/50] sage.rings: Update # needs --- src/sage/rings/continued_fraction.py | 59 ++++++++++++----------- src/sage/rings/fraction_field_element.pyx | 5 +- src/sage/rings/infinity.py | 4 +- src/sage/rings/integer.pyx | 5 +- src/sage/rings/power_series_ring.py | 6 +-- src/sage/rings/real_double.pyx | 3 +- 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index c25a89cfd90..fa5ce286f6d 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -624,24 +624,25 @@ def _mpfr_(self, R): sage: cf.n(digits=8) 0.63459101 + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^3 - 2, 'a', embedding=1.25) # needs sage.rings.number_field - sage: b = 504/253*a^2 + 635/253*a + 661/253 # needs sage.rings.number_field - sage: cf = continued_fraction(b); cf # needs sage.rings.number_field + sage: K. = NumberField(x^3 - 2, 'a', embedding=1.25) + sage: b = 504/253*a^2 + 635/253*a + 661/253 + sage: cf = continued_fraction(b); cf [8; 1, 14, 1, 10, 2, 1, 4, 12, 2, 3, 2, 1, 3, 4, 1, 1, 2, 14, 3, ...] - sage: cf.n(digits=3) # needs sage.rings.number_field + sage: cf.n(digits=3) 8.94 - sage: cf.n(digits=6) # needs sage.rings.number_field + sage: cf.n(digits=6) 8.93715 - sage: cf.n(digits=7) # needs sage.rings.number_field + sage: cf.n(digits=7) 8.937154 - sage: cf.n(digits=8) # needs sage.rings.number_field + sage: cf.n(digits=8) 8.9371541 - sage: cf.n(digits=9) # needs sage.rings.number_field + sage: cf.n(digits=9) 8.93715414 - sage: cf.n(digits=10) # needs sage.rings.number_field + sage: cf.n(digits=10) 8.937154138 - sage: cf.n(digits=11) # needs sage.rings.number_field + sage: cf.n(digits=11) 8.9371541378 TESTS: @@ -1919,19 +1920,20 @@ def quotient(self, n): The same computation with an element of a number field instead of ``pi`` gives a very satisfactory answer:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^3 - 2, embedding=1.25) # needs sage.rings.number_field - sage: c2 = continued_fraction(a2) # needs sage.rings.number_field - sage: p0 = c2.numerator(111); q0 = c2.denominator(111) # needs sage.rings.number_field - sage: p1 = c2.numerator(112); q1 = c2.denominator(112) # needs sage.rings.number_field - sage: num = (q0*a2 - p0); num.n() # needs sage.rings.number_field + sage: K. = NumberField(x^3 - 2, embedding=1.25) + sage: c2 = continued_fraction(a2) + sage: p0 = c2.numerator(111); q0 = c2.denominator(111) + sage: p1 = c2.numerator(112); q1 = c2.denominator(112) + sage: num = (q0*a2 - p0); num.n() -4.56719261665907e46 - sage: den = (q1*a2 - p1); den.n() # needs sage.rings.number_field + sage: den = (q1*a2 - p1); den.n() -3.65375409332726e47 - sage: a2 = -num/den # needs sage.rings.number_field - sage: b2 = RIF(a2); b2 # needs sage.rings.number_field + sage: a2 = -num/den + sage: b2 = RIF(a2); b2 1.002685823312715? - sage: b2.absolute_diameter() # needs sage.rings.number_field + sage: b2.absolute_diameter() 8.88178419700125e-16 The consequence is that the precision needed with ``c1`` grows when we @@ -2442,7 +2444,7 @@ def continued_fraction_list(x, type="std", partial_convergents=False, Fixed :trac:`18901`:: sage: a = 1.575709393346379 - sage: type(a) + sage: type(a) # needs sage.rings.real_mpfr sage: continued_fraction_list(a) [1, 1, 1, 2, 1, 4, 18, 1, 5, 2, 25037802, 7, 1, 3, 1, 28, 1, 8, 2] @@ -2575,20 +2577,21 @@ def continued_fraction(x, value=None): ``sqrt(2)`` above), it is much more convenient to use number fields as follows since preperiods and periods are computed:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 - 5, embedding=2.23) # needs sage.rings.number_field - sage: my_golden_ratio = (1 + sqrt5)/2 # needs sage.rings.number_field - sage: cf = continued_fraction((1+sqrt5)/2); cf # needs sage.rings.number_field + sage: K. = NumberField(x^2 - 5, embedding=2.23) + sage: my_golden_ratio = (1 + sqrt5)/2 + sage: cf = continued_fraction((1+sqrt5)/2); cf [(1)*] - sage: cf.convergent(12) # needs sage.rings.number_field + sage: cf.convergent(12) 377/233 - sage: cf.period() # needs sage.rings.number_field + sage: cf.period() (1,) - sage: cf = continued_fraction(2/3+sqrt5/5); cf # needs sage.rings.number_field + sage: cf = continued_fraction(2/3+sqrt5/5); cf [1; 8, (1, 3, 1, 1, 3, 9)*] - sage: cf.preperiod() # needs sage.rings.number_field + sage: cf.preperiod() (1, 8) - sage: cf.period() # needs sage.rings.number_field + sage: cf.period() (1, 3, 1, 1, 3, 9) sage: # needs sage.rings.number_field diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index d8517147070..ff79aa0c53b 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -145,6 +145,7 @@ cdef class FractionFieldElement(FieldElement): :: + sage: # needs sage.rings.number_field sage: Zx. = ZZ[] sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field sage: cc = K.hom([-i]) # needs sage.rings.number_field @@ -765,8 +766,8 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(I.parent()['x,y']) - sage: complex(x/(I*x) + (I*y)/y) + sage: K. = Frac(I.parent()['x,y']) # needs sage.symbolic + sage: complex(x/(I*x) + (I*y)/y) # needs sage.symbolic 0j """ return complex(self.__numerator) / complex(self.__denominator) diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index 19b52f7b242..eddcc8ccb57 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -379,7 +379,7 @@ def _add_(self, other): Traceback (most recent call last): ... SignError: cannot add unsigned infinities - sage: unsigned_infinity + oo*i + sage: unsigned_infinity + oo*i # needs sage.symbolic Traceback (most recent call last): ... SignError: cannot add unsigned infinities @@ -416,7 +416,7 @@ def _sub_(self, other): Traceback (most recent call last): ... SignError: cannot subtract unsigned infinities - sage: unsigned_infinity - oo*i + sage: unsigned_infinity - oo*i # needs sage.symbolic Traceback (most recent call last): ... SignError: cannot subtract unsigned infinities diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 3e9fe6ce885..c64b0fb1156 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -4878,9 +4878,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: ZZ(5).global_height() # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: ZZ(5).global_height() 1.60943791243410 - sage: ZZ(-2).global_height(prec=100) # needs sage.rings.real_mpfr + sage: ZZ(-2).global_height(prec=100) 0.69314718055994530941723212146 sage: exp(_) 2.0000000000000000000000000000 diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index e687681827d..034adde8f32 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -98,10 +98,10 @@ Choose another implementation of the attached polynomial ring:: sage: R. = PowerSeriesRing(ZZ) - sage: type(t.polynomial()) + sage: type(t.polynomial()) # needs sage.libs.flint <... 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'> - sage: S. = PowerSeriesRing(ZZ, implementation='NTL') - sage: type(s.polynomial()) + sage: S. = PowerSeriesRing(ZZ, implementation='NTL') # needs sage.libs.ntl + sage: type(s.polynomial()) # needs sage.libs.ntl <... 'sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl'> AUTHORS: diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 7fa6e4c6847..6be5c1211b9 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -676,7 +676,8 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): sage: f.factor() # abs tol 2e-5 # needs numpy (x - 1.0000065719436413) * (x^2 - 1.9999934280563585*x + 0.9999934280995487) """ - roots = f.roots(sage.rings.complex_double.CDF) + from sage.rings.complex_double import CDF + roots = f.roots(CDF) # collect real roots and conjugate pairs of non-real roots real_roots = [(r, e) for r, e in roots if r.imag().is_zero()] From 975b18106d03c6899eb2f08001e0d796914fefe2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 14 Jul 2023 00:18:52 -0700 Subject: [PATCH 28/50] sage.rings: Update # needs --- src/sage/rings/complex_double.pyx | 37 ++++++++++++++++--------------- src/sage/rings/complex_mpfr.pyx | 24 ++++++++++---------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 1cabe39fedf..4b7fb798a67 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -315,13 +315,13 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): 2.0 - 3.0*I sage: CDF(4.5) # indirect doctest 4.5 - sage: CDF(1+I) # indirect doctest + sage: CDF(1+I) # indirect doctest # needs sage.symbolic 1.0 + 1.0*I - sage: CDF(pari(1)) + sage: CDF(pari(1)) # needs sage.libs.pari 1.0 - sage: CDF(pari("I")) + sage: CDF(pari("I")) # needs sage.libs.pari 1.0*I - sage: CDF(pari("x^2 + x + 1").polroots()[0]) + sage: CDF(pari("x^2 + x + 1").polroots()[0]) # needs sage.libs.pari -0.5 - 0.8660254037844386*I sage: from gmpy2 import mpc sage: CDF(mpc('2.0+1.0j')) @@ -338,22 +338,22 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: - sage: a = ComplexField(200)(-2).sqrt(); a + sage: a = ComplexField(200)(-2).sqrt(); a # needs sage.rings.real_mpfr 1.4142135623730950488016887242096980785696718753769480731767*I - sage: b = CDF(a); b + sage: b = CDF(a); b # needs sage.rings.real_mpfr 1.4142135623730951*I - sage: a.parent()(b) + sage: a.parent()(b) # needs sage.rings.real_mpfr 1.4142135623730951454746218587388284504413604736328125000000*I - sage: a.parent()(b) == b + sage: a.parent()(b) == b # needs sage.rings.real_mpfr True - sage: b == CC(a) + sage: b == CC(a) # needs sage.rings.real_mpfr True TESTS: Check that :trac:`31836` is fixed:: - sage: a = CDF() ; a + sage: a = CDF(); a 0.0 sage: a.parent() Complex Double Field @@ -428,7 +428,8 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): TESTS:: - sage: CDF(1) + RR(1) + sage: # needs sage.rings.real_mpfr + sage: CDF(1) + RR(1) # needs sage.rings.real_mpfr 2.0 sage: CDF.0 - CC(1) - int(1) - RR(1) - QQbar(1) # needs sage.rings.number_field -4.0 + 1.0*I @@ -1014,7 +1015,7 @@ cdef class ComplexDoubleElement(FieldElement): sage: CDF.0._maxima_init_() '1.0000000000000000*%i' - sage: CDF(.5 + I)._maxima_init_() + sage: CDF(.5 + I)._maxima_init_() # needs sage.symbolic '0.50000000000000000 + 1.0000000000000000*%i' """ from .complex_mpfr import ComplexField @@ -1356,11 +1357,11 @@ cdef class ComplexDoubleElement(FieldElement): sage: CDF(6).argument() 0.0 - sage: CDF(i).argument() + sage: CDF(i).argument() # needs sage.symbolic 1.5707963267948966 sage: CDF(-1).argument() 3.141592653589793 - sage: CDF(-1 - 0.000001*i).argument() + sage: CDF(-1 - 0.000001*i).argument() # needs sage.symbolic -3.1415916535897934 """ return RealDoubleElement(gsl_complex_arg(self._complex)) @@ -1572,7 +1573,7 @@ cdef class ComplexDoubleElement(FieldElement): sage: CDF(0.5).is_integer() False - sage: CDF(I).is_integer() + sage: CDF(I).is_integer() # needs sage.symbolic False sage: CDF(2).is_integer() True @@ -2298,8 +2299,8 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: i = CDF(I) - sage: (1+i).agm(2-i) # rel tol 1e-15 + sage: i = CDF(I) # needs sage.symbolic + sage: (1+i).agm(2-i) # rel tol 1e-15 # needs sage.symbolic 1.6278054848727064 + 0.1368275483973686*I An example to show that the returned value depends on the algorithm @@ -2547,7 +2548,7 @@ cdef class FloatToCDF(Morphism): 1.0 + 2.0*I sage: CDF('i') # indirect doctest 1.0*I - sage: CDF(2+i) # indirect doctest + sage: CDF(2+i) # indirect doctest # needs sage.symbolic 2.0 + 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 8ab4706ff1a..93ff6c213d8 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -146,11 +146,11 @@ def is_ComplexNumber(x): while elements of the class :class:`ComplexField_class` are of type :class:`ComplexNumber`:: - sage: c = 1 + 2*I - sage: is_ComplexNumber(c) + sage: c = 1 + 2*I # needs sage.symbolic + sage: is_ComplexNumber(c) # needs sage.symbolic False - sage: d = CC(1 + 2*I) - sage: is_ComplexNumber(d) + sage: d = CC(1 + 2*I) # needs sage.symbolic + sage: is_ComplexNumber(d) # needs sage.symbolic True """ return isinstance(x, ComplexNumber) @@ -457,12 +457,12 @@ class ComplexField_class(sage.rings.abc.ComplexField): 1.00000000000000 + 1.00000000000000*I sage: CC(2,3) 2.00000000000000 + 3.00000000000000*I - sage: CC(QQ[I].gen()) + sage: CC(QQ[I].gen()) # needs sage.symbolic 1.00000000000000*I - sage: CC.gen() + QQ[I].gen() + sage: CC.gen() + QQ[I].gen() # needs sage.symbolic 2.00000000000000*I sage: x = polygen(ZZ, 'x') - sage: CC.gen() + QQ.extension(x^2 + 1, 'I', embedding=None).gen() + sage: CC.gen() + QQ.extension(x^2 + 1, 'I', embedding=None).gen() # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for +: 'Complex Field with 53 bits of precision' and 'Number Field in I with defining polynomial x^2 + 1' @@ -982,7 +982,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): Check that :trac:`12038` is resolved:: sage: from sage.rings.complex_mpfr import ComplexNumber as CN - sage: coerce(CN, 1+I) + sage: coerce(CN, 1+I) # needs sage.symbolic Traceback (most recent call last): ... TypeError: ...__init__() takes at least 2 positional arguments (1 given) @@ -999,11 +999,11 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: s1 = CC(exp(I)); s1 + sage: s1 = CC(exp(I)); s1 # needs sage.symbolic 0.540302305868140 + 0.841470984807897*I - sage: s1._interface_init_() + sage: s1._interface_init_() # needs sage.symbolic '0.54030230586813977 + 0.84147098480789650*I' - sage: s1 == CC(gp(s1)) + sage: s1 == CC(gp(s1)) # needs sage.libs.pari sage.symbolic True """ return self.str() @@ -1026,7 +1026,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: CC.0._maxima_init_() '1.0000000000000000*%i' - sage: CC(.5 + I)._maxima_init_() + sage: CC(.5 + I)._maxima_init_() # needs sage.symbolic '0.50000000000000000 + 1.0000000000000000*%i' """ return self.str(istr='%i') From 35f4d526cac6ef1441c04d2b47a4ca089e28085a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 15 Jul 2023 23:55:19 -0700 Subject: [PATCH 29/50] sage.rings: Update # needs --- src/sage/rings/complex_double.pyx | 13 +-- src/sage/rings/complex_mpfr.pyx | 9 +- src/sage/rings/fraction_field_element.pyx | 12 +-- src/sage/rings/ideal.py | 13 +-- src/sage/rings/integer_fake.pxd | 2 +- src/sage/rings/invariants/invariant_theory.py | 9 +- src/sage/rings/morphism.pyx | 83 ++++++++++--------- src/sage/rings/ring.pyx | 9 +- src/sage/rings/ring_extension.pyx | 22 ++--- src/sage/rings/ring_extension_morphism.pyx | 9 +- .../non_negative_integer_semiring.py | 8 +- .../rings/semirings/tropical_semiring.pyx | 24 +++--- 12 files changed, 114 insertions(+), 99 deletions(-) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 4b7fb798a67..7f3b7f63327 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -338,15 +338,16 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: - sage: a = ComplexField(200)(-2).sqrt(); a # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: a = ComplexField(200)(-2).sqrt(); a 1.4142135623730950488016887242096980785696718753769480731767*I - sage: b = CDF(a); b # needs sage.rings.real_mpfr + sage: b = CDF(a); b 1.4142135623730951*I - sage: a.parent()(b) # needs sage.rings.real_mpfr + sage: a.parent()(b) 1.4142135623730951454746218587388284504413604736328125000000*I - sage: a.parent()(b) == b # needs sage.rings.real_mpfr + sage: a.parent()(b) == b True - sage: b == CC(a) # needs sage.rings.real_mpfr + sage: b == CC(a) True TESTS: @@ -429,7 +430,7 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): TESTS:: sage: # needs sage.rings.real_mpfr - sage: CDF(1) + RR(1) # needs sage.rings.real_mpfr + sage: CDF(1) + RR(1) 2.0 sage: CDF.0 - CC(1) - int(1) - RR(1) - QQbar(1) # needs sage.rings.number_field -4.0 + 1.0*I diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 93ff6c213d8..1b865147962 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -146,11 +146,12 @@ def is_ComplexNumber(x): while elements of the class :class:`ComplexField_class` are of type :class:`ComplexNumber`:: - sage: c = 1 + 2*I # needs sage.symbolic - sage: is_ComplexNumber(c) # needs sage.symbolic + sage: # needs sage.symbolic + sage: c = 1 + 2*I + sage: is_ComplexNumber(c) False - sage: d = CC(1 + 2*I) # needs sage.symbolic - sage: is_ComplexNumber(d) # needs sage.symbolic + sage: d = CC(1 + 2*I) + sage: is_ComplexNumber(d) True """ return isinstance(x, ComplexNumber) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index ff79aa0c53b..ca130dfb0df 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -147,12 +147,12 @@ cdef class FractionFieldElement(FieldElement): sage: # needs sage.rings.number_field sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: cc = K.hom([-i]) # needs sage.rings.number_field - sage: R. = K[] # needs sage.rings.number_field - sage: F = R.fraction_field() # needs sage.rings.number_field - sage: phi = F.hom([F(b), F(a)], base_map=cc) # needs sage.rings.number_field - sage: phi(i/a) # needs sage.rings.number_field + 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) ((-i))/b """ nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 97694acde35..1e6ff303384 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -510,15 +510,16 @@ def apply_morphism(self, phi): TESTS:: + sage: # needs sage.rings.number_fields sage: x = polygen(ZZ) - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_fields - sage: A = K.ideal(a) # needs sage.rings.number_fields - sage: taus = K.embeddings(K) # needs sage.rings.number_fields - sage: A.apply_morphism(taus[0]) # identity # needs sage.rings.number_fields + sage: K. = NumberField(x^2 + 1) + sage: A = K.ideal(a) + sage: taus = K.embeddings(K) + sage: A.apply_morphism(taus[0]) # identity Fractional ideal (a) - sage: A.apply_morphism(taus[1]) # complex conjugation # needs sage.rings.number_fields + sage: A.apply_morphism(taus[1]) # complex conjugation Fractional ideal (-a) - sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1]) # needs sage.rings.number_fields + sage: A.apply_morphism(taus[0]) == A.apply_morphism(taus[1]) True :: diff --git a/src/sage/rings/integer_fake.pxd b/src/sage/rings/integer_fake.pxd index d900190f74d..4a02062c64b 100644 --- a/src/sage/rings/integer_fake.pxd +++ b/src/sage/rings/integer_fake.pxd @@ -17,7 +17,7 @@ This provides two functions: TESTS:: - sage: cython( # optional - sage.misc.cython + sage: cython( # needs sage.misc.cython ....: ''' ....: from sage.rings.integer_fake cimport Integer_AS_MPZ, is_Integer ....: from sage.rings.integer cimport Integer diff --git a/src/sage/rings/invariants/invariant_theory.py b/src/sage/rings/invariants/invariant_theory.py index f9b7f6a561b..5db39fd3b9d 100644 --- a/src/sage/rings/invariants/invariant_theory.py +++ b/src/sage/rings/invariants/invariant_theory.py @@ -214,14 +214,15 @@ def transvectant(f, g, h=1, scale='default'): factor will not be invertible in that case. The scale argument ``'none'`` can be used to compute the transvectant in this case:: - sage: R. = GF(5)[] # optional - sage.rings.finite_rings - sage: f = AlgebraicForm(2, 5, a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: f = AlgebraicForm(2, 5, a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 ....: + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5, x0, x1) - sage: transvectant(f, f, 4) # optional - sage.rings.finite_rings + sage: transvectant(f, f, 4) Traceback (most recent call last): ... ZeroDivisionError - sage: transvectant(f, f, 4, scale='none') # optional - sage.rings.finite_rings + sage: transvectant(f, f, 4, scale='none') Binary quadratic given by -a3^2*x0^2 + a2*a4*x0^2 + a2*a3*x0*x1 - a1*a4*x0*x1 - a2^2*x1^2 + a1*a3*x1^2 diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 565d1b69316..af08b480dea 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -2468,11 +2468,12 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: f = A.coerce_map_from(ZZ) # needs sage.rings.number_field - sage: g = f.extend_to_fraction_field() # indirect doctest # needs sage.rings.number_field - sage: g # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: f = A.coerce_map_from(ZZ) + sage: g = f.extend_to_fraction_field() # indirect doctest + sage: g Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^2 - 2 @@ -2521,8 +2522,9 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.singular sage: S. = QQ[] - sage: f = S.hom([x + 1]).extend_to_fraction_field() # needs sage.libs.singular + sage: f = S.hom([x + 1]).extend_to_fraction_field() sage: g = copy(f) # indirect doctest # needs sage.libs.singular sage: f == g # needs sage.libs.singular @@ -2665,12 +2667,13 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) # needs sage.libs.singular - sage: phi = S.cover() # needs sage.libs.singular - sage: phi == loads(dumps(phi)) # needs sage.libs.singular + sage: S. = R.quo(x^2 + y^2) + sage: phi = S.cover() + sage: phi == loads(dumps(phi)) True - sage: phi == R.quo(x^2 + y^3).cover() # needs sage.libs.singular + sage: phi == R.quo(x^2 + y^3).cover() False """ if not isinstance(other, RingHomomorphism_cover): @@ -2685,14 +2688,15 @@ cdef class RingHomomorphism_cover(RingHomomorphism): TESTS:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) # needs sage.libs.singular - sage: phi = S.cover() # needs sage.libs.singular - sage: type(phi) # needs sage.libs.singular + sage: S. = R.quo(x^2 + y^2) + sage: phi = S.cover() + sage: type(phi) - sage: hash(phi) == hash(phi) # needs sage.libs.singular + sage: hash(phi) == hash(phi) True - sage: {phi: 1}[phi] # needs sage.libs.singular + sage: {phi: 1}[phi] 1 """ return hash((self.domain(), self.codomain())) @@ -2757,17 +2761,18 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) # needs sage.libs.singular - sage: phi = S.hom([b, c, a]); phi # needs sage.libs.singular + 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) Defn: a |--> b b |--> c c |--> a - sage: phi(a + b + c) # needs sage.libs.singular + sage: phi(a + b + c) a + b + c - sage: loads(dumps(phi)) == phi # needs sage.libs.singular + sage: loads(dumps(phi)) == phi True Validity of the homomorphism is determined, when possible, and a @@ -2813,22 +2818,23 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) # needs sage.libs.singular - sage: phi = S.hom([b, c, a]); phi # needs sage.libs.singular + 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) Defn: a |--> b b |--> c c |--> a - sage: phi(a + b + c) # needs sage.libs.singular + sage: phi(a + b + c) a + b + c - sage: psi = copy(phi) # indirect doctest # needs sage.libs.singular - sage: psi == phi # needs sage.libs.singular + sage: psi = copy(phi) # indirect doctest + sage: psi == phi True - sage: psi is phi # needs sage.libs.singular + sage: psi is phi False - sage: psi(a) == phi(a) # needs sage.libs.singular + sage: psi(a) == phi(a) True """ @@ -2841,22 +2847,23 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) # needs sage.libs.singular - sage: phi = S.hom([b, c, a]); phi # needs sage.libs.singular + 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) Defn: a |--> b b |--> c c |--> a - sage: phi(a + b + c) # needs sage.libs.singular + sage: phi(a + b + c) a + b + c - sage: psi = copy(phi) # indirect doctest # needs sage.libs.singular - sage: psi == phi # needs sage.libs.singular + sage: psi = copy(phi) # indirect doctest + sage: psi == phi True - sage: psi is phi # needs sage.libs.singular + sage: psi is phi False - sage: psi(a) == phi(a) # needs sage.libs.singular + sage: psi(a) == phi(a) True """ slots = RingHomomorphism._extra_slots(self) @@ -3047,16 +3054,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(25)['T']) # needs sage.rings.finite_rings - sage: phi = K.frobenius_endomorphism(2) # needs sage.rings.finite_rings - sage: phi # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + 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: psi = loads(dumps(phi)); psi # needs sage.rings.finite_rings + 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 # needs sage.rings.finite_rings + sage: phi == psi True """ slots = RingHomomorphism._extra_slots(self) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 8f2c55db2de..5c875dc33ba 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -1881,13 +1881,14 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 + 1, 's') # needs sage.rings.number_field - sage: OK = K.ring_of_integers() # needs sage.rings.number_field - sage: OK.integral_closure() # needs sage.rings.number_field + 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 # needs sage.rings.number_field + sage: OK.integral_closure() == OK True sage: QQ.integral_closure() == QQ diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index 3f4acbef798..29fc330ce9e 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -1484,12 +1484,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field - sage: B. = QQ.extension(x^6 - 2) # needs sage.rings.number_field - sage: f = A.hom([b^3]) # needs sage.rings.number_field - sage: E = B.over(f) # needs sage.rings.number_field - sage: E.degree_over() # indirect doctest # needs sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) + sage: B. = QQ.extension(x^6 - 2) + sage: f = A.hom([b^3]) + sage: E = B.over(f) + sage: E.degree_over() # indirect doctest 3 """ if base is self: @@ -2231,12 +2232,13 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field - sage: B. = QQ.extension(x^6 - 2) # needs sage.rings.number_field - sage: f = A.hom([b^3]) # needs sage.rings.number_field - sage: E = B.over(f) # needs sage.rings.number_field - sage: E.degree_over() # indirect doctest # needs sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) + sage: B. = QQ.extension(x^6 - 2) + sage: f = A.hom([b^3]) + sage: E = B.over(f) + sage: E.degree_over() # indirect doctest 3 """ if base is self: diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index fca3eca6f09..596a36b8c96 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -239,13 +239,14 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(QQ, 'x') - sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field - sage: K. = A.over() # needs sage.rings.number_field - sage: f = K.hom([-sqrt2]); f # needs sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) + sage: K. = A.over() + sage: f = K.hom([-sqrt2]); f Ring endomorphism of Field in sqrt2 with defining polynomial x^2 - 2 over its base Defn: sqrt2 |--> -sqrt2 - sage: f(sqrt2) # needs sage.rings.number_field + sage: f(sqrt2) -sqrt2 TESTS:: diff --git a/src/sage/rings/semirings/non_negative_integer_semiring.py b/src/sage/rings/semirings/non_negative_integer_semiring.py index c041f18f99f..e56d7eb9bae 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]) # optional - sage.graphs - sage: G # optional - sage.graphs + sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) # needs sage.graphs + sage: G # needs sage.graphs Looped multi-digraph on 9 vertices - sage: G.plot() # optional - sage.graphs + sage: G.plot() # needs sage.graphs sage.plot 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() # optional - sage.combinat sage.graphs + sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() # needs sage.combinat sage.graphs sage.plot Note: as for :class:`NonNegativeIntegers `, ``NN`` is diff --git a/src/sage/rings/semirings/tropical_semiring.pyx b/src/sage/rings/semirings/tropical_semiring.pyx index 519f3213bd6..d9ddcd324fd 100644 --- a/src/sage/rings/semirings/tropical_semiring.pyx +++ b/src/sage/rings/semirings/tropical_semiring.pyx @@ -555,32 +555,32 @@ class TropicalSemiring(Parent, UniqueRepresentation): EXAMPLES:: - sage: TR = TropicalSemiring(RR) # optional - sage.rings.real_mpfr - sage: T60 = TropicalSemiring(RealField(60)) # optional - sage.rings.real_mpfr - sage: TR.has_coerce_map_from(T60) # optional - sage.rings.real_mpfr + sage: TR = TropicalSemiring(RR) # needs sage.rings.real_mpfr + sage: T60 = TropicalSemiring(RealField(60)) # needs sage.rings.real_mpfr + sage: TR.has_coerce_map_from(T60) # needs sage.rings.real_mpfr True sage: TQ = TropicalSemiring(QQ) sage: TQ.has_coerce_map_from(TropicalSemiring(ZZ)) True - sage: TR.has_coerce_map_from(TR) # optional - sage.rings.real_mpfr + sage: TR.has_coerce_map_from(TR) # needs sage.rings.real_mpfr True sage: TQ.has_coerce_map_from(TQ) True - sage: TR.has_coerce_map_from(TQ) # optional - sage.rings.real_mpfr + sage: TR.has_coerce_map_from(TQ) # needs sage.rings.real_mpfr True - sage: TR.has_coerce_map_from(float) # optional - sage.rings.real_mpfr + sage: TR.has_coerce_map_from(float) # needs sage.rings.real_mpfr False - sage: TR.has_coerce_map_from(RR) # optional - sage.rings.real_mpfr + sage: TR.has_coerce_map_from(RR) # needs sage.rings.real_mpfr False - sage: TR.has_coerce_map_from(QQ) # optional - sage.rings.real_mpfr + sage: TR.has_coerce_map_from(QQ) # needs sage.rings.real_mpfr False - sage: TR.coerce_map_from(T60)(T60(2)) # optional - sage.rings.real_mpfr + sage: TR.coerce_map_from(T60)(T60(2)) # needs sage.rings.real_mpfr 2.00000000000000 - sage: TR.coerce(T60(3.4)) # optional - sage.rings.real_mpfr + sage: TR.coerce(T60(3.4)) # needs sage.rings.real_mpfr 3.40000000000000 - sage: TR.coerce(T60.infinity()) # optional - sage.rings.real_mpfr + sage: TR.coerce(T60.infinity()) # needs sage.rings.real_mpfr +infinity - sage: TQ.coerce(TR(3.4)) # optional - sage.rings.real_mpfr + sage: TQ.coerce(TR(3.4)) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: no canonical coercion from Tropical semiring over From 54725e22bde8ff306f056c6f9537c2043d4b5a04 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 21 Jul 2023 19:43:59 -0700 Subject: [PATCH 30/50] More # needs --- src/sage/rings/function_field/place.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/function_field/place.py b/src/sage/rings/function_field/place.py index 48ea2a2c32f..89df586ce5b 100644 --- a/src/sage/rings/function_field/place.py +++ b/src/sage/rings/function_field/place.py @@ -25,16 +25,16 @@ sage: O = F.maximal_order() sage: p = O.ideal(x^2 + x + 1).place() # needs sage.libs.pari sage: k, fr_k, to_k = p.residue_field() # needs sage.rings.function_field - sage: k + sage: k # needs sage.rings.function_field Finite Field in z2 of size 2^2 The homomorphisms are between the valuation ring and the residue field:: - sage: fr_k + sage: fr_k # needs sage.rings.function_field Ring morphism: From: Finite Field in z2 of size 2^2 To: Valuation ring at Place (x^2 + x + 1) - sage: to_k + sage: to_k # needs sage.rings.function_field Ring morphism: From: Valuation ring at Place (x^2 + x + 1) To: Finite Field in z2 of size 2^2 From a86d13e2f6ce83871c1d3d0159f332bf4f2ead77 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 21 Jul 2023 20:42:38 -0700 Subject: [PATCH 31/50] src/sage/rings/derivation.py: Update # needs --- src/sage/rings/derivation.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/sage/rings/derivation.py b/src/sage/rings/derivation.py index 136c8c40307..26b6f2d5905 100644 --- a/src/sage/rings/derivation.py +++ b/src/sage/rings/derivation.py @@ -231,15 +231,15 @@ def __init__(self, domain, codomain, twist=None): sage: TestSuite(M).run() sage: from sage.rings.derivation import RingDerivationModule - sage: R5. = GF(5)[] # needs sage.rings.finite_rings + sage: R5. = GF(5)[] sage: R25. = GF(25)[] # needs sage.rings.finite_rings - sage: R7. = GF(7)[] # needs sage.rings.finite_rings + sage: R7. = GF(7)[] sage: RingDerivationModule(R5, R25) # needs 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) # needs sage.rings.finite_rings + sage: RingDerivationModule(R5, R5^2) Traceback (most recent call last): ... TypeError: the codomain must be an algebra over the domain @@ -250,7 +250,7 @@ def __init__(self, domain, codomain, twist=None): TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - sage: theta = R5.hom([R5.gen()^2]) # needs sage.rings.finite_rings + sage: theta = R5.hom([R5.gen()^2]) sage: RingDerivationModule(R5, R25, twist=theta) # needs sage.rings.finite_rings Module of twisted derivations from Univariate Polynomial Ring in x over Finite Field of size 5 @@ -1074,10 +1074,10 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = GF(5)[] # needs sage.rings.finite_rings - sage: D = sum(v*R.derivation(v) for v in R.gens()); D # needs sage.rings.finite_rings + sage: R. = GF(5)[] + sage: D = sum(v*R.derivation(v) for v in R.gens()); D x*d/dx + y*d/dy + z*d/dz - sage: D.pth_power() == D # needs sage.rings.finite_rings + sage: D.pth_power() == D True """ @@ -1915,19 +1915,19 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[[]] # needs sage.rings.finite_rings - sage: M = R.derivation_module() # needs sage.rings.finite_rings - sage: M.basis() # needs sage.rings.finite_rings + sage: R. = GF(5)[[]] + sage: M = R.derivation_module() + sage: M.basis() Family (d/dx, d/dy) - sage: R.derivation(x).list() # needs sage.rings.finite_rings + sage: R.derivation(x).list() [1, 0] - sage: R.derivation(y).list() # needs sage.rings.finite_rings + sage: R.derivation(y).list() [0, 1] - sage: f = x*R.derivation(x) + y*R.derivation(y); f # needs sage.rings.finite_rings + sage: f = x*R.derivation(x) + y*R.derivation(y); f x*d/dx + y*d/dy - sage: f.list() # needs sage.rings.finite_rings + sage: f.list() [x, y] """ From 96220860491fe20614a1b9691022a004499eae73 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 22 Jul 2023 02:54:35 -0700 Subject: [PATCH 32/50] sage.rings: Update # needs --- src/sage/rings/fraction_field.py | 7 +-- src/sage/rings/homset.py | 18 ++++--- src/sage/rings/integer.pyx | 7 +-- src/sage/rings/localization.py | 9 ++-- src/sage/rings/morphism.pyx | 6 +-- .../rings/multi_power_series_ring_element.py | 6 +-- src/sage/rings/quotient_ring.py | 2 +- src/sage/rings/rational_field.py | 12 ++--- src/sage/rings/real_lazy.pyx | 22 ++++----- src/sage/rings/ring_extension.pyx | 49 ++++++++++--------- src/sage/rings/ring_extension_element.pyx | 26 +++++----- src/sage/rings/ring_extension_morphism.pyx | 14 +++--- src/sage/rings/tests.py | 2 +- 13 files changed, 94 insertions(+), 86 deletions(-) diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 5d7e4cfab4d..3a434ad5498 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -315,14 +315,15 @@ def _coerce_map_from_(self, S): Coercion from a localization:: + sage: # needs sage.libs.pari sage: R. = ZZ[] - sage: L = Localization(R, (x**2 + 1,7)) # needs sage.libs.pari + sage: L = Localization(R, (x**2 + 1,7)) sage: F = L.fraction_field() - sage: f = F.coerce_map_from(L); f # needs sage.libs.pari + sage: f = F.coerce_map_from(L); f Coercion map: From: Univariate Polynomial Ring in x over Integer Ring localized at (7, x^2 + 1) To: Fraction Field of Univariate Polynomial Ring in x over Integer Ring - sage: f(L(1/7)) == 1/7 # needs sage.libs.pari + sage: f(L(1/7)) == 1/7 True """ from sage.rings.rational_field import QQ diff --git a/src/sage/rings/homset.py b/src/sage/rings/homset.py index 6013a6ca28b..8eb523d4f69 100644 --- a/src/sage/rings/homset.py +++ b/src/sage/rings/homset.py @@ -266,10 +266,11 @@ class RingHomset_quo_ring(RingHomset_generic): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) # needs sage.libs.singular - sage: H = S.Hom(R) # needs sage.libs.singular - sage: H == loads(dumps(H)) # needs sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) + sage: H = S.Hom(R) + sage: H == loads(dumps(H)) True We test pickling of actual homomorphisms in a quotient:: @@ -287,18 +288,19 @@ def _element_constructor_(self, x, base_map=None, check=True): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) # needs sage.libs.singular - sage: H = S.Hom(R) # needs sage.libs.singular - sage: phi = H([b, a]); phi # needs sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) + sage: H = S.Hom(R) + sage: phi = H([b, a]); phi 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) # needs sage.libs.singular - sage: H2(phi) # needs sage.libs.singular + sage: H2 = Hom(R2, S) + sage: H2(phi) 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/integer.pyx b/src/sage/rings/integer.pyx index c64b0fb1156..762c8fb6318 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -2651,10 +2651,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: + sage: # needs sage.rings.real_mpfr sage: x = 3^100000 - sage: RR(log(RR(x), 3)) # needs sage.symbolic + sage: RR(log(RR(x), 3)) 100000.000000000 - sage: RR(log(RR(x + 100000), 3)) # needs sage.symbolic + sage: RR(log(RR(x + 100000), 3)) 100000.000000000 :: @@ -2812,7 +2813,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): The logarithm of zero is done likewise:: - sage: log(0) + sage: log(0) # needs sage.symbolic -Infinity Some rational bases yield integer logarithms (:trac:`21517`):: diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index b43fc573102..7b88eac1802 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -906,17 +906,18 @@ def _fraction_to_element(self, x): EXAMPLES:: + sage: # needs sage.libs.pari sage: P. = QQ[] sage: d = x**2 + y**2 + z**2 - sage: L = Localization(P, d) # needs sage.libs.pari - sage: L._fraction_to_element((x+y+z)/d) # needs sage.libs.pari + sage: L = Localization(P, d) + sage: L._fraction_to_element((x+y+z)/d) (x + y + z)/(x^2 + y^2 + z^2) - sage: _ in L # needs sage.libs.pari + sage: _ in L True TESTS:: - sage: TestSuite(L).run() # needs sage.libs.pari + sage: TestSuite(L).run() """ potential_non_unit_denom = self._cut_off_extra_units_from_base_ring_element(x.denominator()) if potential_non_unit_denom.is_unit(): diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index af08b480dea..eff6af6e04d 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -302,7 +302,7 @@ Embedding a number field into the reals:: sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^3 - 2) # needs sage.rings.number_field - sage: alpha = RR(2)^(1/3); alpha # needs sage.rings.number_field + sage: alpha = RR(2)^(1/3); alpha 1.25992104989487 sage: i = K.hom([alpha],check=False); i # needs sage.rings.number_field Ring morphism: @@ -971,7 +971,7 @@ cdef class RingHomomorphism(RingMap): sage: # needs sage.libs.singular sage: S. = QQ['u,v'].quotient('v^2 - 2') sage: f = QuadraticField(2).hom([v], S) # needs sage.rings.number_field - sage: I = S.ideal(u + v) # needs sage.rings.number_field + sage: I = S.ideal(u + v) sage: J = f.inverse_image(I) # needs sage.rings.number_field sage: J.is_zero() # needs sage.rings.number_field True @@ -1582,7 +1582,7 @@ cdef class RingHomomorphism(RingMap): :: sage: R. = LaurentPolynomialRing(QQ) - sage: R.hom([y, x], R).inverse() # needs sage.libs.singular + sage: R.hom([y, x], R).inverse() Traceback (most recent call last): ... NotImplementedError diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 3ce76fdabf9..f1122ae27eb 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -1930,7 +1930,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)) # needs sage.symbolic + sage: exp(g.change_ring(RDF)) 7.38905609... + 7.38905609...*a + 7.38905609...*b + 3.69452804...*a^2 + 14.7781121...*a*b + 3.69452804...*b^2 + O(a, b)^3 @@ -1941,7 +1941,7 @@ def exp(self, prec=infinity): sage: exp(a) # needs 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) + sage: a.exp(prec=5) # needs sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 sage: exp(a + T.O(5)) # needs sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 @@ -2019,7 +2019,7 @@ def log(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: log(g.change_ring(RDF)) # needs sage.symbolic + sage: log(g.change_ring(RDF)) 1.09861228... + 0.333333333...*a + 0.333333333...*b - 0.0555555555...*a^2 + 0.222222222...*a*b - 0.0555555555...*b^2 + 0.0123456790...*a^3 - 0.0740740740...*a^2*b - 0.0740740740...*a*b^2 + 0.0123456790...*b^3 diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index b00b253b40f..f6b9eea69d6 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -838,7 +838,7 @@ def defining_ideal(self): sage: R. = PolynomialRing(QQ, 2) sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular - sage: S.defining_ideal() # needs sage.libs.singular + sage: S.defining_ideal() Ideal (y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field sage: T.defining_ideal() # needs sage.libs.singular Ideal (x, y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 8efdc093636..d62dfee9ff3 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -443,7 +443,7 @@ def __truediv__(self, I): EXAMPLES:: - sage: QQ / ZZ # needs sage.groups + sage: QQ / ZZ Q/Z """ from sage.rings.ideal import Ideal_generic @@ -779,28 +779,28 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): TESTS:: - sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # needs sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # needs 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) # needs sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) # needs sage.modules Traceback (most recent call last): ... ValueError: second argument must be nonzero :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # needs sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # needs sage.modules Traceback (most recent call last): ... ValueError: list should be of even cardinality :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # needs sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # needs sage.modules Traceback (most recent call last): ... ValueError: all entries in list must be prime or -1 for @@ -823,7 +823,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # needs sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # needs sage.modules Traceback (most recent call last): ... ValueError: if the infinite place is in the list, the second diff --git a/src/sage/rings/real_lazy.pyx b/src/sage/rings/real_lazy.pyx index 6dbfce3d494..d969a9a4385 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -150,16 +150,16 @@ cdef class LazyField(Field): True sage: RLF.has_coerce_map_from(QQ) True - sage: RLF.has_coerce_map_from(AA) + sage: RLF.has_coerce_map_from(AA) # needs sage.rings.number_field True - sage: CLF.has_coerce_map_from(QQbar) + sage: CLF.has_coerce_map_from(QQbar) # needs sage.rings.number_field True sage: RLF.has_coerce_map_from(RDF) False sage: CLF.has_coerce_map_from(QQ) True - sage: CLF.has_coerce_map_from(QQbar) + sage: CLF.has_coerce_map_from(QQbar) # needs sage.rings.number_field True sage: CLF.has_coerce_map_from(CC) False @@ -407,7 +407,7 @@ class ComplexLazyField_class(LazyField): sage: CLF.interval_field() Complex Interval Field with 53 bits of precision - sage: CLF.interval_field(333) + sage: CLF.interval_field(333) # needs sage.rings.complex_interval_field Complex Interval Field with 333 bits of precision sage: CLF.interval_field() is CIF True @@ -427,7 +427,7 @@ class ComplexLazyField_class(LazyField): sage: CLF.gen() 1*I - sage: ComplexField(100)(CLF.gen()) + sage: ComplexField(100)(CLF.gen()) # needs sage.rings.number_field 1.0000000000000000000000000000*I """ if i == 0: @@ -872,7 +872,7 @@ cdef class LazyFieldElement(FieldElement): 1.732050807568878? sage: sin(a) # needs sage.symbolic 0.1411200080598673? - sage: RealField(160)(tanh(RLF(3))) # needs sage.symbolic + sage: RealField(160)(tanh(RLF(3))) 0.99505475368673045133188018525548847509781385470 """ if name in named_unops: @@ -1233,8 +1233,8 @@ cdef class LazyUnop(LazyFieldElement): sage: a = LazyUnop(RLF, 3, sqrt) sage: a.depth() 1 - sage: b = LazyUnop(RLF, a, sin) # needs sage.symbolic - sage: b.depth() # needs sage.symbolic + sage: b = LazyUnop(RLF, a, sin) + sage: b.depth() 2 """ return 1 + self._arg.depth() @@ -1626,13 +1626,13 @@ cdef class LazyAlgebraic(LazyFieldElement): sage: a = LazyAlgebraic(CLF, QQ['x'].cyclotomic_polynomial(7), 0.6+0.8*CC.0) sage: a 0.6234898018587335? + 0.7818314824680299?*I - sage: ComplexField(150)(a) # indirect doctest + sage: ComplexField(150)(a) # indirect doctest # needs sage.rings.number_field 0.62348980185873353052500488400423981063227473 + 0.78183148246802980870844452667405775023233452*I sage: a = LazyAlgebraic(CLF, QQ['x'].0^2-7, -2.0) - sage: RR(a) + sage: RR(a) # needs sage.rings.number_field -2.64575131106459 - sage: RR(a)^2 + sage: RR(a)^2 # needs sage.rings.number_field 7.00000000000000 """ if isinstance(R, type): diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index 29fc330ce9e..83a4bd1ea27 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -742,14 +742,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^3) - sage: E = K.over() - sage: E - Field in z3 with defining polynomial x^3 + 3*x + 3 over its base - sage: E.backend() - Finite Field in z3 of size 5^3 - sage: E.backend() is K - True + sage: # needs sage.rings.finite_rings + sage: K = GF(5^3) + sage: E = K.over() + sage: E + Field in z3 with defining polynomial x^3 + 3*x + 3 over its base + sage: E.backend() + Finite Field in z3 of size 5^3 + sage: E.backend() is K + True """ if force or self._is_backend_exposed: @@ -766,7 +767,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: k = GF(5) # needs sage.rings.finite_rings + sage: k = GF(5) sage: K. = GF(5^2).over(k) # needs sage.rings.finite_rings sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings @@ -1707,13 +1708,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): sage: K.is_field() # needs sage.rings.finite_rings True - sage: S. = QQ[] # needs sage.rings.finite_rings - sage: A = S.over(QQ) # needs sage.rings.finite_rings - sage: A.is_field() # needs sage.rings.finite_rings + sage: S. = QQ[] + sage: A = S.over(QQ) + sage: A.is_field() False - sage: B = A.fraction_field() # needs sage.rings.finite_rings - sage: B.is_field() # needs sage.rings.finite_rings + sage: B = A.fraction_field() + sage: B.is_field() True """ return self._backend.is_field(proof=proof) @@ -1778,8 +1779,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: A = GF(5).over(ZZ) # needs sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) # needs sage.rings.finite_rings + sage: A = GF(5).over(ZZ) + sage: A.fraction_field(extend_base=True) Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -1971,8 +1972,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): :: - sage: E = GF(7).over(ZZ) # needs sage.rings.finite_rings - sage: E.characteristic() # needs sage.rings.finite_rings + sage: E = GF(7).over(ZZ) + sage: E.characteristic() 7 TESTS: @@ -2184,7 +2185,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: F = GF(5) # needs sage.rings.finite_rings + sage: F = GF(5) sage: K = GF(5^2).over(F) # needs sage.rings.finite_rings sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings @@ -2381,7 +2382,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: - sage: F = GF(11) # needs sage.rings.finite_rings + sage: F = GF(11) sage: K. = GF(11^2).over() # needs sage.rings.finite_rings sage: L. = GF(11^6).over(K) # needs sage.rings.finite_rings @@ -2545,8 +2546,8 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: - sage: A = GF(5).over(ZZ) # needs sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) # needs sage.rings.finite_rings + sage: A = GF(5).over(ZZ) + sage: A.fraction_field(extend_base=True) Traceback (most recent call last): ... ValueError: the morphism is not injective @@ -2791,8 +2792,8 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: - sage: A = GF(5).over(ZZ) # needs sage.rings.finite_rings - sage: A.fraction_field(extend_base=True) # needs sage.rings.finite_rings + sage: A = GF(5).over(ZZ) + sage: A.fraction_field(extend_base=True) Traceback (most recent call last): ... ValueError: the morphism is not injective diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 316bf64ae1e..2cc370ab059 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -279,8 +279,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: F = GF(5^2) - sage: K. = GF(5^4).over(F) + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings sage: x = z^10 sage: x (z2 + 2) + (3*z2 + 1)*z @@ -301,8 +301,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: F = GF(5^2) - sage: K. = GF(5^4).over(F) + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings sage: x = z^3 + z^2 + z + 4 sage: y = x.in_base() sage: y @@ -321,7 +321,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): sage: S. = F[] sage: E = S.over(F) - sage: f = E(1) + sage: f = E(1) # needs sage.rings.number_field sage: g = f.in_base() sage: g 1 @@ -332,9 +332,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): We check the case of a tower of extensions:: - sage: F = GF(5^2) - sage: K. = GF(5^4).over(F) - sage: L. = GF(5^8).over(K) + sage: F = GF(5^2) # needs sage.rings.finite_rings + sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: L. = GF(5^8).over(K) # needs sage.rings.finite_rings sage: x = 4*v^7 + v^6 + 3*v^4 + v^3 + v^2 + 4 sage: x.in_base() u @@ -770,8 +770,9 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): TESTS:: - sage: x = K.random_element() # needs sage.rings.number_field - sage: x == x.numerator() / x.denominator() # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: x = K.random_element() + sage: x == x.numerator() / x.denominator() True """ ring = (self._parent)._ring @@ -806,8 +807,9 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): TESTS:: - sage: x = K.random_element() # needs sage.rings.number_field - sage: x == x.numerator() / x.denominator() # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: x = K.random_element() + sage: x == x.numerator() / x.denominator() True """ ring = (self._parent)._ring diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index 596a36b8c96..fe6797159ee 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -269,7 +269,7 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: F = GF(5) # needs sage.rings.finite_rings + sage: F = GF(5) sage: K. = GF(5^2).over(F) # needs sage.rings.finite_rings sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings @@ -396,13 +396,13 @@ cdef class RingExtensionHomomorphism(RingMap): sage: iota.is_injective() # needs sage.rings.finite_rings True - sage: K = GF(7).over(ZZ) # needs sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings + sage: K = GF(7).over(ZZ) + sage: iota = K.defining_morphism(); iota Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base Defn: 1 |--> 1 - sage: iota.is_injective() # needs sage.rings.finite_rings + sage: iota.is_injective() False """ return self._backend.is_injective() @@ -423,13 +423,13 @@ cdef class RingExtensionHomomorphism(RingMap): sage: iota.is_surjective() # needs sage.rings.finite_rings False - sage: K = GF(7).over(ZZ) # needs sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings + sage: K = GF(7).over(ZZ) + sage: iota = K.defining_morphism(); iota Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base Defn: 1 |--> 1 - sage: iota.is_surjective() # needs sage.rings.finite_rings + sage: iota.is_surjective() True """ return self._backend.is_surjective() diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 1f9d195a048..5a648096f84 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -442,7 +442,7 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, sage: rings = [QQ] sage: rings += [ZZ[I], ZZ[I, sqrt(2)]] # needs sage.rings.number_field sage.symbolic sage: rings += [GF(49, 'a')] # needs sage.rings.finite_rings - sage: rings += [MatrixSpace(GF(17), 3)] # needs sage.modules sage.rings.finite_rings + sage: rings += [MatrixSpace(GF(17), 3)] # needs sage.modules sage: for C in rings: ....: test_karatsuba_multiplication(C, 10, 10) From 17495b7ef8c85e56bad781cb104c3cbf43294dea Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 30 Jul 2023 12:49:37 -0700 Subject: [PATCH 33/50] Update # needs --- src/sage/rings/ring_extension_element.pyx | 25 +++++++++++++---------- src/sage/rings/tests.py | 1 + 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 2cc370ab059..a902857d9f8 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -279,8 +279,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: F = GF(5^2) # needs sage.rings.finite_rings - sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K. = GF(5^4).over(F) sage: x = z^10 sage: x (z2 + 2) + (3*z2 + 1)*z @@ -301,8 +302,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: F = GF(5^2) # needs sage.rings.finite_rings - sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K. = GF(5^4).over(F) sage: x = z^3 + z^2 + z + 4 sage: y = x.in_base() sage: y @@ -312,29 +314,30 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): When the element is not in the base, an error is raised:: - sage: z.in_base() + sage: z.in_base() # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: z is not in the base :: + sage: # needs sage.rings.finite_rings sage: S. = F[] sage: E = S.over(F) sage: f = E(1) # needs sage.rings.number_field - sage: g = f.in_base() - sage: g + sage: g = f.in_base(); g # needs sage.rings.number_field 1 - sage: g.parent() + sage: g.parent() # needs sage.rings.number_field Finite Field in z2 of size 5^2 TESTS:: We check the case of a tower of extensions:: - sage: F = GF(5^2) # needs sage.rings.finite_rings - sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L. = GF(5^8).over(K) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K. = GF(5^4).over(F) + sage: L. = GF(5^8).over(K) sage: x = 4*v^7 + v^6 + 3*v^4 + v^3 + v^2 + 4 sage: x.in_base() u diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 5a648096f84..b3cd1c73a17 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -345,6 +345,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): -12 ---- + sage: # needs sage.libs.pari sage: sage.rings.tests.test_random_elements(trials=10) survived 0 tests... sage: sage.rings.tests.test_random_elements(trials=1000) # long time (5 seconds) From 56ac782053f01d0918ef2979946b6995bfa237c6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 30 Jul 2023 15:06:46 -0700 Subject: [PATCH 34/50] src/sage/rings/rational_field.py: Update # needs --- src/sage/rings/rational_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index d62dfee9ff3..24f9ff7b1ba 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -443,7 +443,7 @@ def __truediv__(self, I): EXAMPLES:: - sage: QQ / ZZ + sage: QQ / ZZ # needs sage.modules Q/Z """ from sage.rings.ideal import Ideal_generic From 6426d6ad8cd073387d853d6f748d4ce69f08c6a2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 14:49:01 -0700 Subject: [PATCH 35/50] sage.rings: Update # needs --- src/sage/rings/abc.pyx | 4 +-- .../rings/algebraic_closure_finite_field.py | 2 +- src/sage/rings/cfinite_sequence.py | 2 +- src/sage/rings/continued_fraction.py | 2 +- src/sage/rings/factorint_flint.pyx | 2 +- src/sage/rings/factorint_pari.pyx | 2 +- src/sage/rings/fast_arith.pyx | 2 +- src/sage/rings/infinity.py | 13 ++++---- src/sage/rings/integer.pyx | 4 ++- src/sage/rings/integer_ring.pyx | 2 +- src/sage/rings/localization.py | 30 ++++++++++--------- src/sage/rings/power_series_pari.pyx | 11 ++----- src/sage/rings/qqbar_decorators.py | 2 +- src/sage/rings/quotient_ring.py | 22 +++++++------- src/sage/rings/quotient_ring_element.py | 29 +++++++++--------- src/sage/rings/rational_field.py | 6 ++-- src/sage/rings/real_double.pyx | 2 +- src/sage/rings/real_interval_absolute.pyx | 1 + src/sage/rings/real_lazy.pyx | 2 +- src/sage/rings/ring_extension_conversion.pyx | 2 +- src/sage/rings/ring_extension_homset.py | 2 +- 21 files changed, 75 insertions(+), 69 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 860827b5ca5..8acbb4a6e5a 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -227,7 +227,7 @@ cdef class RealIntervalField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(RIF, sage.rings.abc.RealIntervalField) + sage: isinstance(RIF, sage.rings.abc.RealIntervalField) # needs sage.rings.real_interval_field True By design, there is a unique direct subclass:: @@ -327,7 +327,7 @@ class ComplexIntervalField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CIF, sage.rings.abc.ComplexIntervalField) + sage: isinstance(CIF, sage.rings.abc.ComplexIntervalField) # needs sage.rings.complex_interval_field True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/algebraic_closure_finite_field.py b/src/sage/rings/algebraic_closure_finite_field.py index b8dff4c3903..d7ad457f88c 100644 --- a/src/sage/rings/algebraic_closure_finite_field.py +++ b/src/sage/rings/algebraic_closure_finite_field.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.finite_rings +# sage.doctest: needs sage.rings.finite_rings r""" Algebraic closures of finite fields diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index 733fbcbd6a7..7229dab646a 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.symbolic r""" C-Finite Sequences diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index fa5ce286f6d..b4d3ec2b518 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -265,7 +265,7 @@ def rat_interval_cf_list(r1, r2): sage: from sage.rings.continued_fraction import rat_interval_cf_list sage: rat_interval_cf_list(257/113, 5224/2297) [2, 3, 1, 1, 1, 4] - sage: for prec in range(10,54): + sage: for prec in range(10,54): # needs sage.rings.real_interval_field ....: R = RealIntervalField(prec) ....: for _ in range(100): ....: x = R.random_element() * R.random_element() + R.random_element() / 100 diff --git a/src/sage/rings/factorint_flint.pyx b/src/sage/rings/factorint_flint.pyx index 44d8c3ebd4a..7e08edafa97 100644 --- a/src/sage/rings/factorint_flint.pyx +++ b/src/sage/rings/factorint_flint.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.flint +# sage.doctest: needs sage.libs.flint r""" Integer factorization using FLINT diff --git a/src/sage/rings/factorint_pari.pyx b/src/sage/rings/factorint_pari.pyx index b94682d0deb..8e5ed7c619e 100644 --- a/src/sage/rings/factorint_pari.pyx +++ b/src/sage/rings/factorint_pari.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari +# sage.doctest: needs sage.libs.pari r""" Integer factorization using PARI diff --git a/src/sage/rings/fast_arith.pyx b/src/sage/rings/fast_arith.pyx index 06ef980c8be..bdb5884668e 100644 --- a/src/sage/rings/fast_arith.pyx +++ b/src/sage/rings/fast_arith.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.pari +# sage.doctest: needs sage.libs.pari """ Basic arithmetic with C integers """ diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index eddcc8ccb57..552f2245c89 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -697,7 +697,7 @@ def _element_constructor_(self, x): (Infinity, Infinity) sage: UnsignedInfinityRing(CC(oo)), UnsignedInfinityRing(CC(-oo)) # needs sage.rings.real_mpfr (Infinity, Infinity) - sage: UnsignedInfinityRing(RIF(oo)), UnsignedInfinityRing(RIF(-oo)) + sage: UnsignedInfinityRing(RIF(oo)), UnsignedInfinityRing(RIF(-oo)) # needs sage.rings.real_interval_field (Infinity, Infinity) sage: UnsignedInfinityRing(float('+inf')), UnsignedInfinityRing(float('-inf')) (Infinity, Infinity) @@ -1139,7 +1139,7 @@ def _element_constructor_(self, x): (+Infinity, -Infinity) sage: InfinityRing(RR(oo)), InfinityRing(RR(-oo)) (+Infinity, -Infinity) - sage: InfinityRing(RIF(oo)), InfinityRing(RIF(-oo)) + sage: InfinityRing(RIF(oo)), InfinityRing(RIF(-oo)) # needs sage.rings.real_interval_field (+Infinity, -Infinity) sage: InfinityRing(float('+inf')), InfinityRing(float('-inf')) (+Infinity, -Infinity) @@ -1231,7 +1231,7 @@ def _coerce_map_from_(self, R): True sage: InfinityRing.has_coerce_map_from(RDF) True - sage: InfinityRing.has_coerce_map_from(RIF) + sage: InfinityRing.has_coerce_map_from(RIF) # needs sage.rings.real_interval_field True As explained above, comparison works by coercing to the @@ -1851,8 +1851,11 @@ def test_signed_infinity(pos_inf): EXAMPLES:: sage: from sage.rings.infinity import test_signed_infinity - sage: for pos_inf in [oo, float('+inf'), RLF(oo), RIF(oo), SR(oo)]: - ....: test_signed_infinity(pos_inf) + sage: test_signed_infinity(oo) + sage: test_signed_infinity(float('+inf')) + sage: test_signed_infinity(RLF(oo)) + sage: test_signed_infinity(RIF(oo)) # needs sage.rings.real_interval_field + sage: test_signed_infinity(SR(oo)) # needs sage.symbolic """ msg = 'testing {} ({})'.format(pos_inf, type(pos_inf)) assert InfinityRing(pos_inf) is infinity, msg diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 762c8fb6318..f0f16784381 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -2660,6 +2660,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: + sage: # needs sage.rings.real_mpfr sage: x.exact_log(3) 100000 sage: (x + 1).exact_log(3) @@ -2669,6 +2670,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: + sage: # needs sage.rings.real_mpfr sage: x.exact_log(2.5) Traceback (most recent call last): ... @@ -3912,7 +3914,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: p = next_prime(10^20) sage: q = next_prime(10^21) sage: n = p * q - sage: n.factor(algorithm='qsieve') + sage: n.factor(algorithm='qsieve') # needs sage.libs.flint doctest:... RuntimeWarning: the factorization returned by qsieve may be incomplete (the factors may not be prime) or even wrong; see qsieve? for details diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 15375a7b1df..aa6d56981d2 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -1006,7 +1006,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Construction can be from a prime ideal instead of a prime:: - sage: ZZ.residue_field(ZZ.ideal(97)) # needs sage.libs.pari + sage: ZZ.residue_field(ZZ.ideal(97)) Residue field of Integers modulo 97 TESTS:: diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 7b88eac1802..03e269fe27b 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -457,13 +457,14 @@ def is_unit(self): EXAMPLES:: + sage: # needs sage.libs.pari sage.singular sage: P. = QQ[] - sage: L = P.localization((x, y*z)) # needs sage.libs.pari - sage: L(y*z).is_unit() # needs sage.libs.pari + sage: L = P.localization((x, y*z)) + sage: L(y*z).is_unit() True - sage: L(z).is_unit() # needs sage.libs.pari + sage: L(z).is_unit() True - sage: L(x*y*z).is_unit() # needs sage.libs.pari + sage: L(x*y*z).is_unit() True """ return self.parent()._cut_off_extra_units_from_base_ring_element(self._value.numerator()).is_unit() @@ -490,7 +491,7 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: P. = GF(7)[] sage: L = Localization(P, (x, y, z)) sage: L(1/x) < L(3/(x*y*z)**3) @@ -906,7 +907,7 @@ def _fraction_to_element(self, x): EXAMPLES:: - sage: # needs sage.libs.pari + sage: # needs sage.libs.pari sage.libs.singular sage: P. = QQ[] sage: d = x**2 + y**2 + z**2 sage: L = Localization(P, d) @@ -917,7 +918,7 @@ def _fraction_to_element(self, x): TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # needs sage.libs.pari sage.libs.singular """ potential_non_unit_denom = self._cut_off_extra_units_from_base_ring_element(x.denominator()) if potential_non_unit_denom.is_unit(): @@ -933,23 +934,24 @@ def _coerce_map_from_(self, S): EXAMPLES:: + sage: # needs sage.libs.pari sage.libs.singular sage: P. = QQ[] sage: L = Localization(P, y*z) - sage: M = Localization(P, (x, y, z)) # needs sage.libs.pari - sage: M._coerce_map_from_(L) # needs sage.libs.pari + sage: M = Localization(P, (x, y, z)) + sage: M._coerce_map_from_(L) True - sage: L._coerce_map_from_(M) # needs sage.libs.pari + sage: L._coerce_map_from_(M) False sage: Q. = ZZ[] sage: N = Localization(Q, v*w) sage: L._coerce_map_from_(N) True - sage: N._coerce_map_from_(M) # needs sage.libs.pari + sage: N._coerce_map_from_(M) False - sage: O = Localization(L, x**2 + 1) # needs sage.libs.pari - sage: O._coerce_map_from_(M) # needs sage.libs.pari + sage: O = Localization(L, x**2 + 1) + sage: O._coerce_map_from_(M) False - sage: O._coerce_map_from_(L) # needs sage.libs.pari + sage: O._coerce_map_from_(L) True """ if S is self.base_ring(): diff --git a/src/sage/rings/power_series_pari.pyx b/src/sage/rings/power_series_pari.pyx index 24f4fde5be3..94a6d1baacb 100644 --- a/src/sage/rings/power_series_pari.pyx +++ b/src/sage/rings/power_series_pari.pyx @@ -347,16 +347,14 @@ cdef class PowerSeries_pari(PowerSeries): Substituting `p`-adic numbers:: + sage: # needs sage.rings.padics sage: f(100 + O(5^7)) 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: ff = PowerSeriesRing(pAdicRing(5), 't', implementation='pari')(f) sage: ff (1 + O(5^20))*t^2 + (1 + O(5^20))*t^3 + O(t^6) - sage: ff(100 + O(5^7)) 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: ff(100 + O(2^7)) Traceback (most recent call last): ... @@ -373,17 +371,14 @@ cdef class PowerSeries_pari(PowerSeries): Traceback (most recent call last): ... ValueError: can only substitute elements of positive valuation - sage: f(t^-2) 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)) # needs sage.rings.padics Traceback (most recent call last): ... ValueError: can only substitute elements of positive valuation - sage: g = t^2 + t^3 sage: g(1 + t + O(t^2)) 2 + 5*t + O(t^2) @@ -492,7 +487,7 @@ cdef class PowerSeries_pari(PowerSeries): sage: f[:4] 32 - 80*t + 80*t^2 - 40*t^3 - sage: f = 1 + t^3 - 4*t^4 + O(t^7) ; f + sage: f = 1 + t^3 - 4*t^4 + O(t^7); f 1 + t^3 - 4*t^4 + O(t^7) sage: f[:4] 1 + t^3 + O(t^7) diff --git a/src/sage/rings/qqbar_decorators.py b/src/sage/rings/qqbar_decorators.py index 27448c2def6..c0505b11e8b 100644 --- a/src/sage/rings/qqbar_decorators.py +++ b/src/sage/rings/qqbar_decorators.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.number_field +# sage.doctest: needs sage.rings.number_field """ QQbar decorators diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index f6b9eea69d6..c796b24961b 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -222,17 +222,18 @@ def QuotientRing(R, I, names=None, **kwds): example, we end up modding out the ideal `(x)` from the ring `\QQ[x,y]`:: + sage: # needs sage.libs.pari sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.pari - sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.pari - sage: T # needs sage.libs.pari + 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() # needs sage.libs.pari + sage: R.gens(); S.gens(); T.gens() (x, y) (a, b) (0, d) - sage: for n in range(4): d^n # needs sage.libs.pari + sage: for n in range(4): d^n 1 d -1 @@ -835,12 +836,13 @@ def defining_ideal(self): homomorphism theorems, this is actually a quotient by a sum of two ideals:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular - sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) + sage: T. = QuotientRing(S, S.ideal(a)) sage: S.defining_ideal() Ideal (y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: T.defining_ideal() # needs sage.libs.singular + sage: T.defining_ideal() Ideal (x, y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field """ return self.__I @@ -978,10 +980,10 @@ def ideal(self, *gens, **kwds): sage: R. = PolynomialRing(QQ) sage: S = R.quotient_ring(x^2 + y^2) - sage: S.ideal() # needs sage.libs.pari + sage: S.ideal() # needs sage.libs.singular 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) # needs sage.libs.pari + sage: S.ideal(x + y + 1) # needs sage.libs.singular Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index dc1fec51fad..752e03e8123 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -659,7 +659,7 @@ def _richcmp_(self, other, op): The issue from :trac:`8005` was most likely fixed as part of :trac:`9138`:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: F = GF(5) sage: R. = F[] sage: I = Ideal(R, [x, y]) @@ -687,7 +687,7 @@ def lt(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7), 3, order='lex') sage: I = sage.rings.ideal.FieldIdeal(R) sage: Q = R.quo(I) @@ -710,7 +710,7 @@ def lm(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7), 3, order='lex') sage: I = sage.rings.ideal.FieldIdeal(R) sage: Q = R.quo(I) @@ -734,7 +734,7 @@ def lc(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7), 3, order='lex') sage: I = sage.rings.ideal.FieldIdeal(R) sage: Q = R.quo(I) @@ -811,7 +811,7 @@ def _singular_(self, singular=singular_default): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: P. = PolynomialRing(GF(2), 2) sage: I = sage.rings.ideal.FieldIdeal(P) sage: Q = P.quo(I) @@ -834,11 +834,12 @@ def _singular_(self, singular=singular_default): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # needs sage.libs.singular + sage: # needs sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) - sage: (a - 2/3*b)._singular_() # needs sage.libs.singular + sage: (a - 2/3*b)._singular_() x-2/3*y - sage: S((a - 2/3*b)._singular_()) # needs sage.libs.singular + sage: S((a - 2/3*b)._singular_()) a - 2/3*b """ if singular is None: @@ -851,7 +852,7 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: P. = PolynomialRing(GF(2)) sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) sage: xbar, ybar = Q.gens() @@ -870,7 +871,7 @@ def _macaulay2_(self, macaulay2=None): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7), 2) sage: Q = R.quotient([x^2 - y]) sage: x, y = Q.gens() @@ -895,7 +896,7 @@ def _macaulay2_(self, macaulay2=None): :: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7), 2) sage: Q = R.quotient([x^2 - y], names=R.gens()) sage: x, y = Q.gens() @@ -912,7 +913,7 @@ 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: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7), 2) sage: Q = R.quotient([x^2 - y], names=R.gens()) sage: x, y = Q.gens() @@ -950,7 +951,7 @@ def reduce(self, G): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular 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]) @@ -962,7 +963,7 @@ def reduce(self, G): Notice that the result above is not minimal:: - sage: I2.reduce(f) # needs sage.rings.finite_rings + sage: I2.reduce(f) # needs sage.libs.singular 0 """ try: diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 24f9ff7b1ba..6b47fdeab0a 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -728,16 +728,16 @@ def residue_field(self, p, check=True): INPUT: - - ``p`` - a prime integer. + - ``p`` -- a prime integer. - - ``check`` (default ``True``) - if ``True``, check the primality of + - ``check`` (default ``True``) -- if ``True``, check the primality of `p`, else do not. OUTPUT: The residue field at this prime. EXAMPLES:: - sage: QQ.residue_field(5) # needs sage.rings.finite_rings + sage: QQ.residue_field(5) Residue field of Integers modulo 5 sage: QQ.residue_field(next_prime(10^9)) # needs sage.rings.finite_rings Residue field of Integers modulo 1000000007 diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 6be5c1211b9..5b1fe40d684 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -2075,7 +2075,7 @@ def is_RealDoubleElement(x): sage: from sage.rings.real_double import is_RealDoubleElement sage: is_RealDoubleElement(RDF(3)) True - sage: is_RealDoubleElement(RIF(3)) + sage: is_RealDoubleElement(RIF(3)) # needs sage.rings.real_interval_field False """ return isinstance(x, RealDoubleElement) diff --git a/src/sage/rings/real_interval_absolute.pyx b/src/sage/rings/real_interval_absolute.pyx index 3d0dabaaa5f..5caf4ac40f1 100644 --- a/src/sage/rings/real_interval_absolute.pyx +++ b/src/sage/rings/real_interval_absolute.pyx @@ -1,3 +1,4 @@ +# sage.doctest: # needs sage.symbolic """ Real intervals with a fixed absolute precision """ diff --git a/src/sage/rings/real_lazy.pyx b/src/sage/rings/real_lazy.pyx index d969a9a4385..0f797b039f5 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.real_mpfr +# sage.doctest: needs sage.rings.real_mpfr """ Lazy real and complex numbers diff --git a/src/sage/rings/ring_extension_conversion.pyx b/src/sage/rings/ring_extension_conversion.pyx index 6ea90ddbdb5..eeb6077cd0a 100644 --- a/src/sage/rings/ring_extension_conversion.pyx +++ b/src/sage/rings/ring_extension_conversion.pyx @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.finite_rings +# sage.doctest: needs sage.rings.finite_rings ############################################################################# # Copyright (C) 2019 Xavier Caruso diff --git a/src/sage/rings/ring_extension_homset.py b/src/sage/rings/ring_extension_homset.py index 65c39803caa..d2c13a11f0e 100644 --- a/src/sage/rings/ring_extension_homset.py +++ b/src/sage/rings/ring_extension_homset.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.finite_rings +# sage.doctest: needs sage.rings.finite_rings r""" Homset between extensions of rings From 252fe206c96b8dac84db7e5607bf0dc3198e09d5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Aug 2023 18:29:45 -0700 Subject: [PATCH 36/50] sage.rings: Update # needs --- src/sage/rings/ring.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 5c875dc33ba..62f1d362b54 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -893,7 +893,7 @@ cdef class Ring(ParentWithGens): Forward the proof flag to ``is_field``, see :trac:`22910`:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R1. = GF(5)[] sage: F1 = R1.quotient_ring(x^2 + x + 1) sage: R2. = F1[] From 33bf7beb545b4e2645db23dc0ee93a1d4305e31a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 12 Aug 2023 18:54:20 -0700 Subject: [PATCH 37/50] Update # needs --- src/sage/rings/tests.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index b3cd1c73a17..809c3878c10 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -345,7 +345,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): -12 ---- - sage: # needs sage.libs.pari + sage: # needs sage.rings.number_field sage.rings.finite_rings sage.rings.padics sage: sage.rings.tests.test_random_elements(trials=10) survived 0 tests... sage: sage.rings.tests.test_random_elements(trials=1000) # long time (5 seconds) @@ -366,8 +366,9 @@ def test_random_elements(level=MAX_LEVEL, trials=1): @random_testing def test_random_arith(level=MAX_LEVEL, trials=1): """ - Create random elements of random rings and does some arithmetic - with them, until a crash occurs, in which case an exception is + Create random elements of random rings and do some arithmetic with them. + + Repeats until a crash occurs, in which case an exception is raised. Defaults to running a single trial, but more can be specified. To run tests in an infinite loop, you could use:: @@ -375,17 +376,18 @@ def test_random_arith(level=MAX_LEVEL, trials=1): INPUT: - - level -- (default: MAX_LEVEL); controls the types of rings to use - - trials -- A positive integer (default 1); the number of trials + - ``level`` -- (default: ``MAX_LEVEL``); controls the types of rings to use + - ``trials`` -- A positive integer (default: 1); the number of trials to run. - - seed -- the random seed to use; if not specified, uses a truly + - ``seed`` -- the random seed to use; if not specified, uses a truly random seed. - - print_seed -- If True (default False), prints the random seed chosen. + - ``print_seed`` -- If ``True`` (default: ``False``), prints the random seed chosen. EXAMPLES:: + sage: # needs sage.rings.number_field sage.rings.finite_rings sage.rings.padics sage: import sage.rings.tests - sage: sage.rings.tests.test_random_arith(trials=2, seed=0) # needs sage.rings.number_field + sage: sage.rings.tests.test_random_arith(trials=2, seed=0) survived 0 tests Rational Field -1/2 -1/95 @@ -394,10 +396,9 @@ def test_random_arith(level=MAX_LEVEL, trials=1): Number Field in a with defining polynomial x^2 - 15083 with a = 122.81286577553673? a -2*a - 1 2*a - 30164 - - sage: sage.rings.tests.test_random_arith(trials=10) # needs sage.rings.finite_rings + sage: sage.rings.tests.test_random_arith(trials=10) survived 0 tests... - sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?), needs sage.rings.finite_rings + sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?) survived 0 tests... """ i = 0 From 5c1e20a44dcfa9e7353271348a193d22ce7814ea Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 13 Aug 2023 12:07:18 -0700 Subject: [PATCH 38/50] sage --fixdoctests --no-test src/sage/rings --- src/sage/rings/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 809c3878c10..13a205195d5 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -345,7 +345,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): -12 ---- - sage: # needs sage.rings.number_field sage.rings.finite_rings sage.rings.padics + sage: # needs sage.rings.finite_rings sage.rings.number_field sage.rings.padics sage: sage.rings.tests.test_random_elements(trials=10) survived 0 tests... sage: sage.rings.tests.test_random_elements(trials=1000) # long time (5 seconds) @@ -385,7 +385,7 @@ def test_random_arith(level=MAX_LEVEL, trials=1): EXAMPLES:: - sage: # needs sage.rings.number_field sage.rings.finite_rings sage.rings.padics + sage: # needs sage.rings.finite_rings sage.rings.number_field sage.rings.padics sage: import sage.rings.tests sage: sage.rings.tests.test_random_arith(trials=2, seed=0) survived 0 tests From 27a85b6500c5bfa6fd47ba8fb84a2fa12bd000df Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 19 Aug 2023 20:47:41 -0700 Subject: [PATCH 39/50] src/sage/rings/number_field/number_field_ideal.py: Remove abuse of symbolic x in doctests --- .../rings/number_field/number_field_ideal.py | 96 ++++++++++++++++--- 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py index b5e724a0ab4..aac441463ca 100644 --- a/src/sage/rings/number_field/number_field_ideal.py +++ b/src/sage/rings/number_field/number_field_ideal.py @@ -18,6 +18,7 @@ We test that pickling works:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 - 5) sage: I = K.ideal(2/(5+a)) sage: I == loads(dumps(I)) @@ -78,6 +79,7 @@ def __init__(self, field, gens, coerce=True): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: K.ideal(7) Fractional ideal (7) @@ -154,6 +156,7 @@ def _magma_init_(self, magma): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 2) # optional - magma sage: I = K.ideal(5) # optional - magma sage: I._magma_init_(magma) # optional - magma @@ -171,6 +174,7 @@ def __hash__(self): """ EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^2 + 1, 'a').ideal(7).__hash__() # random 7806919040325273549 """ @@ -186,6 +190,7 @@ def _latex_(self): r""" EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 23) sage: K.ideal([2, 1/2*a - 1/2])._latex_() '\\left(2, \\frac{1}{2} a - \\frac{1}{2}\\right)' @@ -232,6 +237,7 @@ def _richcmp_(self, other, op): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 3); K Number Field in a with defining polynomial x^2 + 3 sage: f = K.factor(15); f @@ -354,6 +360,7 @@ def _contains_(self, x): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 23); K Number Field in a with defining polynomial x^2 + 23 sage: I = K.factor(13)[0][0]; I @@ -406,6 +413,7 @@ def __elements_from_hnf(self, hnf): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 389); K Number Field in a with defining polynomial x^3 + 389 sage: I = K.factor(17)[0][0] @@ -433,7 +441,8 @@ def __repr__(self): EXAMPLES:: - sage: K. = NumberField(x^3-2) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^3 - 2) sage: I = K.ideal(0); I Ideal (0) of Number Field in a with defining polynomial x^3 - 2 sage: type(I) @@ -466,6 +475,7 @@ def _repr_short(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^4 + 389); K Number Field in a with defining polynomial x^4 + 389 sage: I = K.factor(17)[0][0]; I @@ -502,6 +512,7 @@ def _gens_repr(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: sage.rings.number_field.number_field_ideal.SMALL_DISC 1000000 sage: K. = NumberField(x^4 + 3*x^2 - 17) @@ -536,6 +547,7 @@ def __pari__(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 23) sage: I = K.class_group().0.ideal(); I Fractional ideal (2, 1/2*w - 1/2) @@ -550,6 +562,7 @@ def _pari_init_(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 23) sage: I = K.class_group().0.ideal() sage: I._pari_init_() @@ -563,6 +576,7 @@ def pari_hnf(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^3 - 2) sage: I = K.ideal(2/(5+a)) @@ -610,6 +624,7 @@ def basis(self): Number fields defined by non-monic and non-integral polynomials are supported (:trac:`252`):: + sage: x = polygen(ZZ) sage: K. = NumberField(2*x^2 - 1/3) sage: K.ideal(a).basis() [1, a] @@ -665,6 +680,7 @@ def free_module(self): This also works for relative extensions:: + sage: x = polygen(ZZ) sage: K. = NumberField([x^2 + 1, x^2 + 2]) sage: I = K.fractional_ideal(4) sage: I.free_module() @@ -721,6 +737,7 @@ def reduce_equiv(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 23) sage: I = ideal(w*23^5); I Fractional ideal (6436343*w) @@ -748,6 +765,7 @@ def gens_reduced(self, proof=None): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 + 5) sage: K.ideal(0).gens_reduced() @@ -810,6 +828,7 @@ def gens_two(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 + 5) sage: J = K.ideal([a + 2, 9]) @@ -861,6 +880,7 @@ def integral_basis(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 + 1) sage: J = K.ideal(i + 1) @@ -877,6 +897,7 @@ def integral_split(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 - 5) sage: I = K.ideal(2/(5+a)) @@ -923,6 +944,7 @@ def intersection(self, other): An example with non-principal ideals:: + sage: x = polygen(ZZ) sage: L. = NumberField(x^3 - 7) sage: p = L.ideal(a^2 + a + 1, 2) sage: q = L.ideal(a + 1) @@ -1152,7 +1174,7 @@ def is_principal(self, proof=None): sage: I = P^5 sage: I.is_principal() True - sage: I # random + sage: I # random Fractional ideal (-1/2*a + 3/2) sage: P = K.ideal([2]).factor()[1][0] sage: I = P^5 @@ -1197,6 +1219,7 @@ def ideal_class_log(self, proof=None): An example with a more complicated class group:: + sage: x = polygen(ZZ) sage: K. = NumberField([x^3 - x + 1, x^2 + 26]) sage: K.class_group() Class group of order 18 with structure C6 x C3 of @@ -1254,6 +1277,7 @@ def is_zero(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 2); K Number Field in a with defining polynomial x^2 + 2 sage: K.ideal(3).is_zero() @@ -1271,6 +1295,7 @@ def norm(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^4 + 23); K Number Field in a with defining polynomial x^4 + 23 sage: I = K.ideal(19); I @@ -1296,6 +1321,7 @@ def absolute_norm(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: K.ideal(1 + 2*i).absolute_norm() 5 @@ -1308,6 +1334,7 @@ def relative_norm(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: K.ideal(1 + 2*i).relative_norm() 5 @@ -1320,6 +1347,7 @@ def absolute_ramification_index(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: K.ideal(1 + i).absolute_ramification_index() 2 @@ -1332,6 +1360,7 @@ def relative_ramification_index(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: K.ideal(1 + i).relative_ramification_index() 2 @@ -1344,6 +1373,7 @@ def number_field(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 2); K Number Field in a with defining polynomial x^2 + 2 sage: K.ideal(3).number_field() @@ -1426,6 +1456,7 @@ def valuation(self, p): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^5 + 2); K Number Field in a with defining polynomial x^5 + 2 sage: i = K.ideal(38); i @@ -1520,6 +1551,7 @@ def random_element(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 2) sage: I = K.ideal(1 - a) sage: I.random_element() # random output @@ -1599,6 +1631,7 @@ def residue_symbol(self, e, m, check=True): Quadratic Residue (7 is not a square modulo 11):: + sage: x = polygen(ZZ) sage: K. = NumberField(x - 1) sage: K.ideal(11).residue_symbol(7,2) -1 @@ -1693,8 +1726,8 @@ def _quadratic_form(self): This is not defined for higher-degree extensions:: - sage: x = var('x') - sage: K. = NumberField(x**3-x-1) + sage: x = polygen(ZZ) + sage: K. = NumberField(x**3 - x - 1) sage: K.ideal(a)._quadratic_form() Traceback (most recent call last): ... @@ -1732,6 +1765,7 @@ def basis_to_module(B, K): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^4 + 1) sage: from sage.rings.number_field.number_field_ideal import basis_to_module sage: basis_to_module([K.0, K.0^2 + 3], K) @@ -1756,6 +1790,8 @@ def is_NumberFieldIdeal(x): False sage: is_NumberFieldIdeal(ideal(5)) False + + sage: x = polygen(ZZ) sage: k. = NumberField(x^2 + 2) sage: I = k.ideal([a + 1]); I Fractional ideal (a + 1) @@ -1775,6 +1811,7 @@ class NumberFieldFractionalIdeal(MultiplicativeGroupElement, NumberFieldIdeal, I EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^3 - 2) sage: I = K.ideal(2/(5+a)) @@ -1799,6 +1836,7 @@ def __init__(self, field, gens, coerce=True): EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^2 + 1, 'a').ideal(7) Fractional ideal (7) """ @@ -1826,6 +1864,7 @@ def __repr__(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 5) sage: I = K.ideal([2,1+a]); I Fractional ideal (2, a + 1) @@ -1861,6 +1900,7 @@ def factor(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^4 + 23); K Number Field in a with defining polynomial x^4 + 23 sage: I = K.ideal(19); I @@ -1916,6 +1956,7 @@ def prime_factors(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 23) sage: I = ideal(w+1) sage: I.prime_factors() @@ -1933,6 +1974,7 @@ def _div_(self, other): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 - 5) sage: I = K.ideal(2/(5+a)) @@ -1953,6 +1995,7 @@ def __invert__(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^3 - 2) sage: I = K.ideal(2/(5+a)) @@ -1977,6 +2020,7 @@ def is_maximal(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 3); K Number Field in a with defining polynomial x^3 + 3 sage: K.ideal(5).is_maximal() @@ -1999,7 +2043,7 @@ def is_trivial(self, proof=None): sage: J = F.ideal(5) sage: J.is_trivial() False - sage: (I+J).is_trivial() + sage: (I + J).is_trivial() True """ return self == self.number_field().ideal(1) @@ -2015,6 +2059,7 @@ def ramification_index(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 2); K Number Field in a with defining polynomial x^2 + 2 sage: f = K.factor(2); f @@ -2061,6 +2106,7 @@ def reduce(self, f): EXAMPLES:: + sage: x = polygen(ZZ) sage: k. = NumberField(x^3 + 11) sage: I = k.ideal(5, a^2 - a + 1) sage: c = 4*a + 9 @@ -2152,7 +2198,8 @@ def residues(self): EXAMPLES:: - sage: K.=NumberField(x^2 + 1) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^2 + 1) sage: res = K.ideal(2).residues(); res xmrange_iter([[0, 1], [0, 1]], at 0x...>) sage: list(res) @@ -2216,6 +2263,7 @@ def invertible_residues(self, reduce=True): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: ires = K.ideal(2).invertible_residues(); ires xmrange_iter([[0, 1]], at 0x...>) @@ -2286,6 +2334,7 @@ def invertible_residues_mod(self, subgp_gens=[], reduce=True): :: + sage: x = polygen(ZZ) sage: k. = NumberField(x^2 + 23) sage: I = k.ideal(a) sage: list(I.invertible_residues_mod([-1])) @@ -2356,7 +2405,8 @@ def denominator(self): EXAMPLES:: - sage: K.=NumberField(x^2 + 1) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^2 + 1) sage: I = K.ideal((3+4*i)/5); I Fractional ideal (4/5*i + 3/5) sage: I.denominator() @@ -2386,7 +2436,8 @@ def numerator(self): EXAMPLES:: - sage: K.=NumberField(x^2 + 1) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^2 + 1) sage: I = K.ideal((3+4*i)/5); I Fractional ideal (4/5*i + 3/5) sage: I.denominator() @@ -2429,6 +2480,7 @@ def is_coprime(self, other): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: I = K.ideal(2 + i) sage: J = K.ideal(2 - i) @@ -2492,6 +2544,7 @@ def idealcoprime(self, J): EXAMPLES:: + sage: x = polygen(ZZ) sage: k. = NumberField(x^2 + 23) sage: A = k.ideal(a + 1) sage: B = k.ideal(3) @@ -2542,6 +2595,7 @@ def small_residue(self, f): :: + sage: x = polygen(ZZ) sage: k. = NumberField(x^2 + 5) sage: I = k.ideal(a) sage: I.small_residue(14) @@ -2576,6 +2630,7 @@ def _pari_bid_(self, flag=1): EXAMPLES:: + sage: x = polygen(ZZ) sage: k. = NumberField(x^4 + 13) sage: I = k.ideal(2, a^2 + 1) sage: hasattr(I, '_bid') @@ -2627,6 +2682,7 @@ def idealstar(self, flag=1): EXAMPLES:: + sage: x = polygen(ZZ) sage: k. = NumberField(x^3 - 11) sage: A = k.ideal(5) sage: G = A.idealstar(); G @@ -2699,6 +2755,7 @@ def ideallog(self, x, gens=None, check=True): EXAMPLES:: + sage: x = polygen(ZZ) sage: k. = NumberField(x^3 - 11) sage: A = k.ideal(5) sage: G = A.idealstar(2) @@ -2810,6 +2867,7 @@ def element_1_mod(self, other): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 - 2) sage: A = K.ideal(a + 1); A; A.norm() Fractional ideal (a + 1) @@ -2870,6 +2928,7 @@ def euler_phi(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: I = K.ideal(2 + i) sage: [r for r in I.residues() if I.is_coprime(r)] @@ -2918,6 +2977,7 @@ def prime_to_S_part(self, S): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 - 23) sage: I = K.ideal(24) sage: S = [K.ideal(-a + 5), K.ideal(5)] @@ -2963,7 +3023,8 @@ def is_S_unit(self, S): EXAMPLES:: - sage: K. = NumberField(x^2+23) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^2 + 23) sage: I = K.ideal(2) sage: P = I.factor()[0][0] sage: I.is_S_unit([P]) @@ -2994,9 +3055,10 @@ def is_S_integral(self, S): EXAMPLES:: - sage: K. = NumberField(x^2+23) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^2 + 23) sage: I = K.ideal(1/2) - sage: P = K.ideal(2,1/2*a - 1/2) + sage: P = K.ideal(2, 1/2*a - 1/2) sage: I.is_S_integral([P]) False @@ -3025,6 +3087,7 @@ def prime_to_idealM_part(self, M): EXAMPLES:: + sage: x = polygen(ZZ) sage: k. = NumberField(x^2 + 23) sage: I = k.ideal(a + 1) sage: M = k.ideal(2, 1/2*a - 1/2) @@ -3072,6 +3135,7 @@ def _p_quotient(self, p): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1); O = K.maximal_order() sage: I = K.factor(3)[0][0] sage: Q, quo, lift = I._p_quotient(3); Q @@ -3120,6 +3184,7 @@ def residue_field(self, names=None): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 - 7) sage: P = K.ideal(29).factor()[0][0] sage: P.residue_field() @@ -3208,6 +3273,7 @@ def residue_class_degree(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^5 + 2); K Number Field in a with defining polynomial x^5 + 2 sage: f = K.factor(19); f @@ -3252,6 +3318,7 @@ def is_NumberFieldFractionalIdeal(x): False sage: is_NumberFieldFractionalIdeal(ideal(5)) False + sage: x = polygen(ZZ) sage: k. = NumberField(x^2 + 2) sage: I = k.ideal([a + 1]); I Fractional ideal (a + 1) @@ -3278,6 +3345,7 @@ def __init__(self, K, M_OK_change, Q, I): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 4) sage: f = K.ideal(1 + a^2/2).residue_field().reduction_map(); f # indirect doctest Partially defined reduction map: @@ -3302,6 +3370,7 @@ def __call__(self, x): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 4) sage: f = K.ideal(1 + a^2/2).residue_field().reduction_map() sage: f(a) @@ -3317,6 +3386,7 @@ def __repr__(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 4) sage: f = K.ideal(1 + a^2/2).residue_field().reduction_map() sage: repr(f) @@ -3336,6 +3406,7 @@ def __init__(self, OK, M_OK_map, Q, I): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 4) sage: I = K.ideal(1 + a^2/2) sage: f = I.residue_field().lift_map() @@ -3354,6 +3425,7 @@ def __call__(self, x): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 4) sage: R = K.ideal(1 + a^2/2).residue_field() sage: f = R.lift_map() @@ -3382,6 +3454,7 @@ def __repr__(self): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 + 4) sage: R = K.ideal(1 + a^2/2).residue_field() sage: repr(R.lift_map()) @@ -3400,6 +3473,7 @@ def quotient_char_p(I, p): sage: from sage.rings.number_field.number_field_ideal import quotient_char_p + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15) sage: quotient_char_p(I, 5)[0] Vector space quotient V/W of dimension 2 over Finite Field of size 5 where From f5a24bef1e8aaecd5aa70ad5b8410748bdf2728f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 26 Aug 2023 22:31:24 -0700 Subject: [PATCH 40/50] sage.rings: Update # needs --- src/sage/rings/abc.pyx | 4 ++-- src/sage/rings/polynomial/polynomial_ring_constructor.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 8acbb4a6e5a..6ad9dd8d6f0 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -232,7 +232,7 @@ cdef class RealIntervalField(Field): By design, there is a unique direct subclass:: - sage: sage.rings.abc.RealIntervalField.__subclasses__() + sage: sage.rings.abc.RealIntervalField.__subclasses__() # needs sage.rings.real_interval_field [] sage: len(sage.rings.abc.RealIntervalField.__subclasses__()) <= 1 @@ -332,7 +332,7 @@ class ComplexIntervalField(Field): By design, there is a unique direct subclass:: - sage: sage.rings.abc.ComplexIntervalField.__subclasses__() + sage: sage.rings.abc.ComplexIntervalField.__subclasses__() # needs sage.rings.complex_interval_field [] sage: len(sage.rings.abc.ComplexIntervalField.__subclasses__()) <= 1 diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index acaea2e3a16..2d1d04a9e73 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -578,7 +578,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 - sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL + sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL # needs sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); TestSuite(ZxFLINT).run(); ZxFLINT Univariate Polynomial Ring in x over Integer Ring From 00713face1ca6816a9da5899da8b8502b07cd4b7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 27 Aug 2023 13:40:33 -0700 Subject: [PATCH 41/50] sage.rings: Update # needs --- src/sage/rings/polynomial/infinite_polynomial_ring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 32f62258a7c..117dee3faf4 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -1364,7 +1364,7 @@ def key_basis(self): EXAMPLES:: sage: R. = InfinitePolynomialRing(GF(2)) - sage: R.key_basis() # needs sage.combinat + sage: R.key_basis() # needs sage.combinat sage.modules Key polynomial basis over Finite Field of size 2 """ from sage.combinat.key_polynomial import KeyPolynomialBasis From 0a3d56709c9273047e363359c500ebfdd76997fc Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 28 Aug 2023 20:48:10 -0700 Subject: [PATCH 42/50] sage.rings: Use more block tags --- src/sage/rings/complex_double.pyx | 8 +- src/sage/rings/complex_interval.pyx | 14 +- src/sage/rings/complex_mpfr.pyx | 55 +-- src/sage/rings/continued_fraction.py | 38 +- .../rings/finite_rings/integer_mod_ring.py | 2 +- src/sage/rings/fraction_field.py | 22 +- src/sage/rings/fraction_field_element.pyx | 8 +- src/sage/rings/function_field/constructor.py | 6 +- src/sage/rings/function_field/differential.py | 4 +- .../rings/function_field/function_field.py | 4 +- src/sage/rings/function_field/maps.py | 2 +- src/sage/rings/function_field/place.py | 8 +- .../rings/function_field/place_rational.py | 10 +- src/sage/rings/function_field/valuation.py | 4 +- src/sage/rings/ideal.py | 17 +- src/sage/rings/ideal_monoid.py | 2 +- src/sage/rings/infinity.py | 2 +- src/sage/rings/integer.pyx | 75 ++-- src/sage/rings/integer_ring.pyx | 37 +- src/sage/rings/laurent_series_ring.py | 19 +- .../rings/laurent_series_ring_element.pyx | 13 +- src/sage/rings/lazy_series.py | 315 +++++++------- src/sage/rings/lazy_series_ring.py | 134 +++--- src/sage/rings/morphism.pyx | 196 +++++---- src/sage/rings/multi_power_series_ring.py | 28 +- .../rings/multi_power_series_ring_element.py | 109 +++-- .../number_field/number_field_element.pyx | 12 +- .../polynomial/multi_polynomial_element.py | 2 +- .../polynomial/multi_polynomial_sequence.py | 30 +- .../rings/polynomial/polynomial_element.pyx | 8 +- .../polynomial/polynomial_modn_dense_ntl.pyx | 2 +- .../polynomial/polynomial_quotient_ring.py | 2 +- .../polynomial/polynomial_ring_constructor.py | 2 +- src/sage/rings/polynomial/symmetric_ideal.py | 2 +- src/sage/rings/polynomial/term_order.py | 48 +-- src/sage/rings/power_series_poly.pyx | 37 +- src/sage/rings/power_series_ring.py | 4 - src/sage/rings/power_series_ring_element.pyx | 46 +- .../rings/puiseux_series_ring_element.pyx | 11 +- src/sage/rings/qqbar.py | 162 +++---- src/sage/rings/quotient_ring.py | 113 ++--- src/sage/rings/quotient_ring_element.py | 13 +- src/sage/rings/rational.pyx | 78 ++-- src/sage/rings/rational_field.py | 19 +- src/sage/rings/real_arb.pyx | 4 +- src/sage/rings/real_double.pyx | 29 +- src/sage/rings/real_lazy.pyx | 2 +- src/sage/rings/real_mpfi.pyx | 32 +- src/sage/rings/real_mpfr.pyx | 9 +- src/sage/rings/ring.pyx | 60 +-- src/sage/rings/ring_extension.pyx | 395 +++++++++--------- src/sage/rings/ring_extension_element.pyx | 219 +++++----- src/sage/rings/ring_extension_morphism.pyx | 104 +++-- .../rings/semirings/tropical_semiring.pyx | 30 +- src/sage/rings/sum_of_squares.pyx | 4 +- 55 files changed, 1311 insertions(+), 1300 deletions(-) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 7f3b7f63327..f2080959a54 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -315,7 +315,7 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): 2.0 - 3.0*I sage: CDF(4.5) # indirect doctest 4.5 - sage: CDF(1+I) # indirect doctest # needs sage.symbolic + sage: CDF(1+I) # indirect doctest # needs sage.symbolic 1.0 + 1.0*I sage: CDF(pari(1)) # needs sage.libs.pari 1.0 @@ -895,9 +895,9 @@ cdef class ComplexDoubleElement(FieldElement): sage: # optional - magma sage: CDF((1.2, 0.3))._magma_init_(magma) 'ComplexField(53 : Bits := true)![1.2, 0.3]' - sage: magma(CDF(1.2, 0.3)) + sage: magma(CDF(1.2, 0.3)) # indirect doctest 1.20000000000000 + 0.300000000000000*$.1 - sage: s = magma(CDF(1.2, 0.3)).sage(); s + sage: s = magma(CDF(1.2, 0.3)).sage(); s # indirect doctest 1.20000000000000 + 0.300000000000000*I sage: s.parent() Complex Field with 53 bits of precision @@ -2549,7 +2549,7 @@ cdef class FloatToCDF(Morphism): 1.0 + 2.0*I sage: CDF('i') # indirect doctest 1.0*I - sage: CDF(2+i) # indirect doctest # needs sage.symbolic + sage: CDF(2+i) # indirect doctest # needs sage.symbolic 2.0 + 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) diff --git a/src/sage/rings/complex_interval.pyx b/src/sage/rings/complex_interval.pyx index 05c77675c53..fdc3af338db 100644 --- a/src/sage/rings/complex_interval.pyx +++ b/src/sage/rings/complex_interval.pyx @@ -352,15 +352,15 @@ cdef class ComplexIntervalFieldElement(FieldElement): (2.50000000000000, 3.00000000000000) (-4.50000000000000, -4.00000000000000) - sage: z = CIF(RIF(sqrt(2), sqrt(3)), RIF(e, pi)) # needs sage.symbolic - sage: a, b, c, d = z.bisection() # needs sage.symbolic - sage: a.intersection(b).intersection(c).intersection(d) == CIF(z.center()) # needs sage.symbolic + sage: # needs sage.symbolic + sage: z = CIF(RIF(sqrt(2), sqrt(3)), RIF(e, pi)) + sage: a, b, c, d = z.bisection() + sage: a.intersection(b).intersection(c).intersection(d) == CIF(z.center()) True - - sage: zz = a.union(b).union(c).union(c) # needs sage.symbolic - sage: zz.real().endpoints() == z.real().endpoints() # needs sage.symbolic + sage: zz = a.union(b).union(c).union(c) + sage: zz.real().endpoints() == z.real().endpoints() True - sage: zz.imag().endpoints() == z.imag().endpoints() # needs sage.symbolic + sage: zz.imag().endpoints() == z.imag().endpoints() True """ a00 = self._new() diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 1b865147962..8929faa9ae1 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -848,19 +848,20 @@ class ComplexField_class(sage.rings.abc.ComplexField): TESTS:: + sage: # needs sage.libs.pari sage: k = ComplexField(100) sage: R. = k[] - sage: k._factor_univariate_polynomial( x ) # needs sage.libs.pari + sage: k._factor_univariate_polynomial(x) x - sage: k._factor_univariate_polynomial( 2*x ) # needs sage.libs.pari + sage: k._factor_univariate_polynomial(2*x) (2.0000000000000000000000000000) * x - sage: k._factor_univariate_polynomial( x^2 ) # needs sage.libs.pari + sage: k._factor_univariate_polynomial(x^2) x^2 - sage: k._factor_univariate_polynomial( x^2 + 3 ) # needs sage.libs.pari + sage: k._factor_univariate_polynomial(x^2 + 3) (x - 1.7320508075688772935274463415*I) * (x + 1.7320508075688772935274463415*I) - sage: k._factor_univariate_polynomial( x^2 + 1 ) # needs sage.libs.pari + sage: k._factor_univariate_polynomial(x^2 + 1) (x - I) * (x + I) - sage: k._factor_univariate_polynomial( k(I) * (x^2 + 1) ) # needs sage.libs.pari + sage: k._factor_univariate_polynomial(k(I) * (x^2 + 1)) (1.0000000000000000000000000000*I) * (x - I) * (x + I) """ @@ -1266,20 +1267,22 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: a = CC(pi + I*e); a # needs sage.symbolic + sage: # needs sage.symbolic + sage: a = CC(pi + I*e); a 3.14159265358979 + 2.71828182845905*I - sage: a.str(truncate=True) # needs sage.symbolic + sage: a.str(truncate=True) '3.14159265358979 + 2.71828182845905*I' - sage: a.str() # needs sage.symbolic + sage: a.str() '3.1415926535897931 + 2.7182818284590451*I' - sage: a.str(base=2) # needs sage.symbolic + sage: a.str(base=2) '11.001001000011111101101010100010001000010110100011000 + 10.101101111110000101010001011000101000101011101101001*I' - sage: CC(0.5 + 0.625*I).str(base=2) # needs sage.symbolic + sage: CC(0.5 + 0.625*I).str(base=2) '0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I' - sage: a.str(base=16) # needs sage.symbolic + sage: a.str(base=16) '3.243f6a8885a30 + 2.b7e151628aed2*I' - sage: a.str(base=36) # needs sage.symbolic + sage: a.str(base=36) '3.53i5ab8p5fc + 2.puw5nggjf8f*I' + sage: CC(0) 0.000000000000000 sage: CC.0.str(istr='%i') @@ -1390,24 +1393,25 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): Coerce the object using the ``pari`` function:: + sage: # needs sage.libs.pari sage: a = ComplexNumber(2,1) - sage: pari(a) # needs sage.libs.pari + sage: pari(a) 2.00000000000000 + 1.00000000000000*I - sage: pari(a).type() # needs sage.libs.pari + sage: pari(a).type() 't_COMPLEX' - sage: type(pari(a)) # needs sage.libs.pari + sage: type(pari(a)) - sage: a.__pari__() # needs sage.libs.pari + sage: a.__pari__() 2.00000000000000 + 1.00000000000000*I - sage: type(a.__pari__()) # needs sage.libs.pari + sage: type(a.__pari__()) sage: a = CC(pi) # needs sage.symbolic - sage: pari(a) # needs sage.libs.pari sage.symbolic + sage: pari(a) # needs sage.symbolic 3.14159265358979 - sage: pari(a).type() # needs sage.libs.pari sage.symbolic + sage: pari(a).type() # needs sage.symbolic 't_REAL' sage: a = CC(-2).sqrt() - sage: pari(a) # needs sage.libs.pari + sage: pari(a) 1.41421356237310*I """ if self.is_real(): @@ -2897,14 +2901,15 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: + sage: # needs sage.libs.pari sage: C, i = ComplexField(30).objgen() - sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 # needs sage.libs.pari + sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 0.0020969149 - 0.059981914*I - sage: (1+i).gamma_inc(5) # needs sage.libs.pari + sage: (1+i).gamma_inc(5) -0.0013781309 + 0.0065198200*I - sage: C(2).gamma_inc(1 + i) # needs sage.libs.pari + sage: C(2).gamma_inc(1 + i) 0.70709210 - 0.42035364*I - sage: CC(2).gamma_inc(5) # needs sage.libs.pari + sage: CC(2).gamma_inc(5) 0.0404276819945128 TESTS: diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index b4d3ec2b518..a3f877e423d 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -1330,13 +1330,13 @@ def period(self): EXAMPLES:: - sage: K. = QuadraticField(3) # needs sage.rings.number_field - sage: cf = continued_fraction(sqrt3); cf # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = QuadraticField(3) + sage: cf = continued_fraction(sqrt3); cf [1; (1, 2)*] - sage: cf.period() # needs sage.rings.number_field + sage: cf.period() (1, 2) - - sage: for k in xsrange(2,40): # needs sage.rings.number_field + sage: for k in xsrange(2,40): ....: if not k.is_square(): ....: s = QuadraticField(k).gen() ....: cf = continued_fraction(s) @@ -1368,15 +1368,15 @@ def preperiod(self): EXAMPLES:: - sage: K. = QuadraticField(3) # needs sage.rings.number_field - sage: cf = continued_fraction(sqrt3); cf # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = QuadraticField(3) + sage: cf = continued_fraction(sqrt3); cf [1; (1, 2)*] - sage: cf.preperiod() # needs sage.rings.number_field + sage: cf.preperiod() (1,) - - sage: cf = continued_fraction(sqrt3/7); cf # needs sage.rings.number_field + sage: cf = continued_fraction(sqrt3/7); cf [0; 4, (24, 8)*] - sage: cf.preperiod() # needs sage.rings.number_field + sage: cf.preperiod() (0, 4) """ return self._x1 @@ -1878,7 +1878,7 @@ def _repr_(self): EXAMPLES:: - sage: continued_fraction(pi) # indirect doctest # needs sage.symbolic + sage: continued_fraction(pi) # indirect doctest # needs sage.symbolic [3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, ...] """ return '[%d; ' % self.quotient(0) + ', '.join(str(self.quotient(i)) for i in range(1, 20)) + ", ...]" @@ -2379,23 +2379,23 @@ def continued_fraction_list(x, type="std", partial_convergents=False, sage: 2 + 1/(2 + 1/(1 + 1/(2 + 1/2))) 45/19 - sage: continued_fraction_list(45/19,type="hj") + sage: continued_fraction_list(45/19, type="hj") [3, 2, 3, 2, 3] sage: 3 - 1/(2 - 1/(3 - 1/(2 - 1/3))) 45/19 Specifying ``bits`` or ``nterms`` modify the length of the output:: - sage: continued_fraction_list(e, bits=20) # needs sage.symbolic + sage: # needs sage.symbolic + sage: continued_fraction_list(e, bits=20) [2, 1, 2, 1, 1, 4, 2] - sage: continued_fraction_list(sqrt(2)+sqrt(3), bits=30) # needs sage.symbolic + sage: continued_fraction_list(sqrt(2) + sqrt(3), bits=30) [3, 6, 1, 5, 7, 2] - sage: continued_fraction_list(pi, bits=53) # needs sage.symbolic + sage: continued_fraction_list(pi, bits=53) [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14] - - sage: continued_fraction_list(log(3/2), nterms=15) # needs sage.symbolic + sage: continued_fraction_list(log(3/2), nterms=15) [0, 2, 2, 6, 1, 11, 2, 1, 2, 2, 1, 4, 3, 1, 1] - sage: continued_fraction_list(tan(sqrt(pi)), nterms=20) # needs sage.symbolic + sage: continued_fraction_list(tan(sqrt(pi)), nterms=20) [-5, 9, 4, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 2, 4, 3, 1, 63] When the continued fraction is infinite (ie ``x`` is an irrational number) diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index 20a876f4192..b615d3a8c1a 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -1600,7 +1600,7 @@ def _gap_init_(self): sage: R = Integers(12345678900) sage: R Ring of integers modulo 12345678900 - sage: gap(R) # indirect doctest # needs sage.libs.gap + sage: gap(R) # indirect doctest # needs sage.libs.gap (Integers mod 12345678900) """ return 'ZmodnZ({})'.format(self.order()) diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 3a434ad5498..5d298720a90 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -264,12 +264,13 @@ def _coerce_map_from_(self, S): We demonstrate that :trac:`7958` is resolved in the case of number fields:: + sage: # needs sage.rings.number_field sage: _. = ZZ[] - sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # needs sage.rings.number_field - sage: R = K.ring_of_integers() # needs sage.rings.number_field - sage: S. = R[] # needs sage.rings.number_field - sage: F = FractionField(S) # needs sage.rings.number_field - sage: F(1/a) # needs sage.rings.number_field + 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) (a^4 - 3*a^3 + 2424*a^2 + 2)/232 Some corner cases have been known to fail in the past (:trac:`5917`):: @@ -396,12 +397,13 @@ def _number_field_to_frac_of_ring_of_integers(self, x): We demonstrate that :trac:`7958` is resolved in the case of number fields:: + sage: # needs sage.rings.number_field sage: _. = ZZ[] - sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # needs sage.rings.number_field - sage: R = K.ring_of_integers() # needs sage.rings.number_field - sage: S. = R[] # needs sage.rings.number_field - sage: F = FractionField(S) # indirect doctest # needs sage.rings.number_field - sage: F(1/a) # needs sage.rings.number_field + 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) (a^4 - 3*a^3 + 2424*a^2 + 2)/232 """ f = x.polynomial() # Polynomial over QQ diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index ca130dfb0df..00bad2188ac 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -860,15 +860,15 @@ cdef class FractionFieldElement(FieldElement): sage: x,y = FR.gens() sage: a = x^2; a x^2 - sage: type(a.numerator()) # needs sage.lings.singular + sage: type(a.numerator()) # needs sage.libs.singular - sage: type(a.denominator()) # needs sage.lings.singular + sage: type(a.denominator()) # needs sage.libs.singular sage: a = x^(-2); a 1/x^2 - sage: type(a.numerator()) # needs sage.lings.singular + sage: type(a.numerator()) # needs sage.libs.singular - sage: type(a.denominator()) # needs sage.lings.singular + sage: type(a.denominator()) # needs sage.libs.singular sage: x^0 1 diff --git a/src/sage/rings/function_field/constructor.py b/src/sage/rings/function_field/constructor.py index 8e5ecd281ee..d1c63011d3c 100644 --- a/src/sage/rings/function_field/constructor.py +++ b/src/sage/rings/function_field/constructor.py @@ -150,7 +150,7 @@ def create_key(self,polynomial,names): sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(x - y^2) # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(x - y^2) # indirect doctest # needs sage.rings.function_field TESTS: @@ -182,9 +182,9 @@ def create_object(self,version,key,**extra_args): sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(x - y^2) # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(x - y^2) # indirect doctest # needs sage.rings.function_field sage: y2 = y*1 - sage: M. = K.extension(x - y2^2) # indirect doctest # needs sage.rings.function_field + sage: M. = K.extension(x - y2^2) # indirect doctest # needs sage.rings.function_field sage: L is M # needs sage.rings.function_field True """ diff --git a/src/sage/rings/function_field/differential.py b/src/sage/rings/function_field/differential.py index 03b327b1abf..9b6fec9a72d 100644 --- a/src/sage/rings/function_field/differential.py +++ b/src/sage/rings/function_field/differential.py @@ -152,8 +152,8 @@ def _latex_(self): sage: # needs sage.rings.finite_rings sage: K. = FunctionField(GF(4)); _. = K[] sage: L. = K.extension(Y^3 + x + x^3*Y) # needs sage.rings.function_field - sage: w = y.differential() - sage: latex(w) + sage: w = y.differential() # needs sage.rings.function_field + sage: latex(w) # needs sage.rings.function_field \left( x y^{2} + \frac{1}{x} y \right)\, dx """ if self._f.is_zero(): # zero differential diff --git a/src/sage/rings/function_field/function_field.py b/src/sage/rings/function_field/function_field.py index 973d9a8f505..26975773a88 100644 --- a/src/sage/rings/function_field/function_field.py +++ b/src/sage/rings/function_field/function_field.py @@ -129,7 +129,7 @@ sage: TestSuite(L).run(max_runs=8) # long time (25s) # needs sage.rings.function_field sage.rings.number_field sage: TestSuite(M).run(max_runs=8) # long time (35s) # needs sage.rings.finite_rings sage.rings.function_field sage: TestSuite(N).run(max_runs=8, skip='_test_derivation') # long time (15s), needs sage.rings.finite_rings - sage: TestSuite(O).run() + sage: TestSuite(O).run() # needs sage.rings.function_field sage: TestSuite(R).run() # needs sage.rings.finite_rings sage.rings.function_field sage: TestSuite(S).run() # long time (4s) # needs sage.rings.finite_rings sage.rings.function_field @@ -781,7 +781,7 @@ def _convert_map_from_(self, R): sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^3 + x^3 + 4*x + 1) # needs sage.rings.function_field - sage: K(L(x)) # indirect doctest # needs sage.rings.function_field + sage: K(L(x)) # indirect doctest # needs sage.rings.function_field x """ try: diff --git a/src/sage/rings/function_field/maps.py b/src/sage/rings/function_field/maps.py index ead3310d054..223112c9ae8 100644 --- a/src/sage/rings/function_field/maps.py +++ b/src/sage/rings/function_field/maps.py @@ -221,7 +221,7 @@ def _call_(self, v): sage: R. = K[] sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f(x*V.0 + (1/x^3)*V.1) # indirect doctest # needs sage.modules sage.rings.function_field + sage: f(x*V.0 + (1/x^3)*V.1) # indirect doctest # needs sage.modules sage.rings.function_field 1/x^3*y + x TESTS: diff --git a/src/sage/rings/function_field/place.py b/src/sage/rings/function_field/place.py index 89df586ce5b..dbc3ab0e767 100644 --- a/src/sage/rings/function_field/place.py +++ b/src/sage/rings/function_field/place.py @@ -24,17 +24,17 @@ sage: F. = FunctionField(GF(2)) sage: O = F.maximal_order() sage: p = O.ideal(x^2 + x + 1).place() # needs sage.libs.pari - sage: k, fr_k, to_k = p.residue_field() # needs sage.rings.function_field - sage: k # needs sage.rings.function_field + sage: k, fr_k, to_k = p.residue_field() # needs sage.libs.pari sage.rings.function_field + sage: k # needs sage.libs.pari sage.rings.function_field Finite Field in z2 of size 2^2 The homomorphisms are between the valuation ring and the residue field:: - sage: fr_k # needs sage.rings.function_field + sage: fr_k # needs sage.libs.pari sage.rings.function_field Ring morphism: From: Finite Field in z2 of size 2^2 To: Valuation ring at Place (x^2 + x + 1) - sage: to_k # needs sage.rings.function_field + sage: to_k # needs sage.libs.pari sage.rings.function_field Ring morphism: From: Valuation ring at Place (x^2 + x + 1) To: Finite Field in z2 of size 2^2 diff --git a/src/sage/rings/function_field/place_rational.py b/src/sage/rings/function_field/place_rational.py index b6fd87f4fc2..05511a65f4b 100644 --- a/src/sage/rings/function_field/place_rational.py +++ b/src/sage/rings/function_field/place_rational.py @@ -78,13 +78,13 @@ def residue_field(self, name=None): sage: O = F.maximal_order() sage: p = O.ideal(x^2 + x + 1).place() sage: k, fr_k, to_k = p.residue_field() # needs sage.rings.function_field - sage: k + sage: k # needs sage.rings.function_field Finite Field in z2 of size 2^2 - sage: fr_k + sage: fr_k # needs sage.rings.function_field Ring morphism: From: Finite Field in z2 of size 2^2 To: Valuation ring at Place (x^2 + x + 1) - sage: to_k + sage: to_k # needs sage.rings.function_field Ring morphism: From: Valuation ring at Place (x^2 + x + 1) To: Finite Field in z2 of size 2^2 @@ -170,8 +170,8 @@ def valuation_ring(self): sage: K. = FunctionField(GF(2)); _. = K[] sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] - sage: p.valuation_ring() + sage: p = L.places_finite()[0] # needs sage.rings.function_field + sage: p.valuation_ring() # needs sage.rings.function_field Valuation ring at Place (x, x*y) """ from .valuation_ring import FunctionFieldValuationRing diff --git a/src/sage/rings/function_field/valuation.py b/src/sage/rings/function_field/valuation.py index 5567c4db1ce..80d81cb53de 100644 --- a/src/sage/rings/function_field/valuation.py +++ b/src/sage/rings/function_field/valuation.py @@ -358,7 +358,7 @@ def create_key_and_extra_args_from_valuation_on_isomorphic_field(self, domain, v sage: R. = K[] sage: L. = K.extension(y^2 + y + x^3) # needs sage.rings.function_field sage: v = K.valuation(1/x) # needs sage.rings.function_field - sage: w = v.extension(L) # indirect doctest # needs sage.rings.function_field + sage: w = v.extension(L) # indirect doctest # needs sage.rings.function_field """ from sage.categories.function_fields import FunctionFields @@ -1117,7 +1117,7 @@ class FunctionFieldFromLimitValuation(FiniteExtensionFromLimitValuation, Discret sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - (x^2 + x + 1)) # needs sage.rings.function_field - sage: v = K.valuation(x - 1) # indirect doctest # needs sage.rings.function_field + sage: v = K.valuation(x - 1) # indirect doctest # needs sage.rings.function_field sage: w = v.extension(L); w # needs sage.rings.function_field (x - 1)-adic valuation diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 1e6ff303384..e7aeaa24cde 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -534,7 +534,7 @@ def apply_morphism(self, phi): Since 2 is totally ramified, complex conjugation fixes it:: - sage: B.apply_morphism(taus[1]) # complex conjugation # needs sage.rings.number_fields + sage: B.apply_morphism(taus[1]) # complex conjugation # needs sage.rings.number_fields Fractional ideal (2, a + 1) sage: taus[1](B) # needs sage.rings.number_fields Fractional ideal (2, a + 1) @@ -1650,25 +1650,26 @@ def residue_field(self): EXAMPLES:: + sage: # needs sage.libs.pari sage: P = ZZ.ideal(61); P Principal ideal (61) of Integer Ring - sage: F = P.residue_field(); F # needs sage.libs.pari + sage: F = P.residue_field(); F Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi # needs sage.libs.pari + sage: pi = F.reduction_map(); pi Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) # needs sage.libs.pari + sage: pi(123/234) 6 - sage: pi(1/61) # needs sage.libs.pari + sage: pi(1/61) Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift # needs sage.libs.pari + sage: lift = F.lift_map(); lift Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) # needs sage.libs.pari + sage: lift(F(12345/67890)) 33 sage: (12345/67890) % 61 33 @@ -1713,7 +1714,7 @@ def __repr__(self): sage: from sage.rings.ideal import Ideal_fractional sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: Ideal_fractional(K, [a]) # indirect doctest # needs sage.rings.number_field + sage: Ideal_fractional(K, [a]) # indirect doctest # needs sage.rings.number_field Fractional ideal (a) of Number Field in a with defining polynomial x^2 + 1 """ return "Fractional ideal %s of %s"%(self._repr_short(), self.ring()) diff --git a/src/sage/rings/ideal_monoid.py b/src/sage/rings/ideal_monoid.py index ee3ac892b8f..0988ffc72e5 100644 --- a/src/sage/rings/ideal_monoid.py +++ b/src/sage/rings/ideal_monoid.py @@ -55,7 +55,7 @@ def __init__(self, R): sage: R = QuadraticField(-23, 'a') # needs sage.rings.number_field sage: from sage.rings.ideal_monoid import IdealMonoid - sage: M = IdealMonoid(R); M # indirect doctest # needs sage.rings.number_field + sage: M = IdealMonoid(R); M # indirect doctest # needs sage.rings.number_field Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index 552f2245c89..e945fcfe455 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -1725,7 +1725,7 @@ def _sympy_(self): EXAMPLES:: sage: import sympy # needs sympy - sage: bool(oo == sympy.oo) # indirect doctest # needs sympy + sage: bool(oo == sympy.oo) # indirect doctest # needs sympy True sage: bool(SR(oo) == sympy.oo) # needs sympy sage.symbolic True diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index f0f16784381..478babb559f 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -531,33 +531,34 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Test conversion from PARI (:trac:`11685`):: - sage: ZZ(pari(-3)) # needs sage.libs.pari + sage: # needs sage.libs.pari + sage: ZZ(pari(-3)) -3 - sage: ZZ(pari("-3.0")) # needs sage.libs.pari + sage: ZZ(pari("-3.0")) -3 - sage: ZZ(pari("-3.5")) # needs sage.libs.pari + sage: ZZ(pari("-3.5")) Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral real number to an Integer - sage: ZZ(pari("1e100")) # needs sage.libs.pari + sage: ZZ(pari("1e100")) Traceback (most recent call last): ... PariError: precision too low in truncr (precision loss in truncation) - sage: ZZ(pari("10^50")) # needs sage.libs.pari + sage: ZZ(pari("10^50")) 100000000000000000000000000000000000000000000000000 - sage: ZZ(pari("Pol(3)")) # needs sage.libs.pari + sage: ZZ(pari("Pol(3)")) 3 sage: ZZ(GF(3^20,'t')(1)) # needs sage.rings.finite_rings 1 - sage: ZZ(pari(GF(3^20,'t')(1))) # needs sage.libs.pari sage.rings.finite_rings + sage: ZZ(pari(GF(3^20,'t')(1))) # needs sage.rings.finite_rings 1 sage: x = polygen(QQ) sage: K. = NumberField(x^2 + 3) # needs sage.rings.number_field sage: ZZ(a^2) # needs sage.rings.number_field -3 - sage: ZZ(pari(a)^2) # needs sage.libs.pari sage.rings.number_field + sage: ZZ(pari(a)^2) # needs sage.rings.number_field -3 - sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # needs sage.libs.pari + sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element Traceback (most recent call last): ... TypeError: Unable to coerce PARI x to an Integer @@ -2901,7 +2902,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: y = Integer(145^145) sage: y.exp() # needs sage.symbolic e^25024207011349079210459585279553675697932183658421565260323592409432707306554163224876110094014450895759296242775250476115682350821522931225499163750010280453185147546962559031653355159703678703793369785727108337766011928747055351280379806937944746847277089168867282654496776717056860661614337004721164703369140625 - sage: y.exp(prec=53) # default RealField precision # needs sage.symbolic + sage: y.exp(prec=53) # default RealField precision # needs sage.symbolic +infinity """ from sage.functions.all import exp @@ -3444,6 +3445,7 @@ 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 # needs mpmath sage: mpmath.mp.prec = 1000 # needs mpmath sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # needs mpmath @@ -5454,18 +5456,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: + sage: # needs sage.libs.pari sage: x = 10^200 + 357 - sage: x.is_pseudoprime() # needs sage.libs.pari + sage: x.is_pseudoprime() True - sage: (x^12).is_pseudoprime_power() # needs sage.libs.pari + sage: (x^12).is_pseudoprime_power() True - sage: (x^12).is_pseudoprime_power(get_data=True) # needs sage.libs.pari + sage: (x^12).is_pseudoprime_power(get_data=True) (1000...000357, 12) - sage: (997^100).is_pseudoprime_power() # needs sage.libs.pari + sage: (997^100).is_pseudoprime_power() True - sage: (998^100).is_pseudoprime_power() # needs sage.libs.pari + sage: (998^100).is_pseudoprime_power() False - sage: ((10^1000 + 453)^2).is_pseudoprime_power() # needs sage.libs.pari + sage: ((10^1000 + 453)^2).is_pseudoprime_power() True TESTS:: @@ -5541,26 +5544,27 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: + sage: n = 7 + sage: n.is_norm(QQ) + True + sage: n.is_norm(QQ, element=True) + (True, 7) + + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K = NumberField(x^2 - 2, 'beta') # needs sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') sage: n = 4 - sage: n.is_norm(K) # needs sage.rings.number_field + sage: n.is_norm(K) True - sage: 5.is_norm(K) # needs sage.rings.number_field + sage: 5.is_norm(K) False - sage: 7.is_norm(QQ) - True - sage: n.is_norm(K, element=True) # needs sage.rings.number_field + sage: n.is_norm(K, element=True) (True, -4*beta + 6) - sage: n.is_norm(K, element=True)[1].norm() # needs sage.rings.number_field + sage: n.is_norm(K, element=True)[1].norm() 4 sage: n = 5 - sage: n.is_norm(K, element=True) # needs sage.rings.number_field + sage: n.is_norm(K, element=True) (False, None) - sage: n = 7 - sage: n.is_norm(QQ, element=True) - (True, 7) - """ from sage.rings.rational_field import QQ return QQ(self).is_norm(K, element=element, proof=proof) @@ -6217,19 +6221,18 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: import numpy # needs numpy - sage: numpy.array([1, 2, 3]) # needs numpy + sage: # needs numpy + sage: import numpy + sage: numpy.array([1, 2, 3]) array([1, 2, 3]) - sage: numpy.array([1, 2, 3]).dtype # needs numpy + sage: numpy.array([1, 2, 3]).dtype dtype('int32') # 32-bit dtype('int64') # 64-bit - - sage: numpy.array(2**40).dtype # needs numpy + sage: numpy.array(2**40).dtype dtype('int64') - sage: numpy.array(2**400).dtype # needs numpy + sage: numpy.array(2**400).dtype dtype('O') - - sage: numpy.array([1,2,3,0.1]).dtype # needs numpy + sage: numpy.array([1,2,3,0.1]).dtype dtype('float64') """ if mpz_fits_slong_p(self.value): diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index aa6d56981d2..cb97fec967f 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -394,19 +394,21 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ[sqrt(2), sqrt(3)] # needs sage.rings.number_field sage.symbolic - Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field sage: ZZ['x'] Univariate Polynomial Ring in x over Integer Ring sage: ZZ['x,y'] Multivariate Polynomial Ring in x, y over Integer Ring - sage: R = ZZ[sqrt(5) + 1]; R # needs sage.rings.number_field sage.symbolic + + sage: # needs sage.rings.number_field sage.symbolic + sage: ZZ[sqrt(2), sqrt(3)] + Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field + sage: R = ZZ[sqrt(5) + 1]; R Order in Number Field in a with defining polynomial x^2 - 2*x - 4 with a = 3.236067977499790? - sage: R.is_maximal() # needs sage.rings.number_field sage.symbolic + sage: R.is_maximal() False - sage: R = ZZ[(1 + sqrt(5))/2]; R # needs sage.rings.number_field sage.symbolic + sage: R = ZZ[(1 + sqrt(5))/2]; R Order in Number Field in a with defining polynomial x^2 - x - 1 with a = 1.618033988749895? - sage: R.is_maximal() # needs sage.rings.number_field sage.symbolic + sage: R.is_maximal() True """ if x in self: @@ -1279,40 +1281,41 @@ cdef class IntegerRing_class(PrincipalIdealDomain): TESTS:: + sage: # needs sage.libs.pari 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) # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) [(100, 1), (-5445, 5), (1, 23), (-1, 23)] sage: p *= (1 + x^3458645 - 76*x^3435423343 + x^45346567867756556) - sage: ZZ._roots_univariate_polynomial(p) # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) [(1, 23), (-1, 23), (100, 1), (-5445, 5)] sage: p *= x^156468451540687043504386074354036574634735074 - sage: ZZ._roots_univariate_polynomial(p) # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) [(0, 156468451540687043504386074354036574634735074), (1, 23), (-1, 23), (100, 1), (-5445, 5)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) [0, 1, -1, 100, -5445] + sage: # needs sage.libs.pari 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) # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p) [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) [100, -5445, 1, -1] - - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # needs sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") [(100, 1), (-5445, 5), (1, 23), (-1, 23)] sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") Traceback (most recent call last): ... ValueError: unknown algorithm 'foobar' - sage: p = x^20 * p + sage: p = x^20 * p # needs sage.libs.pari sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # needs sage.libs.pari [(0, 20), (100, 1), (-5445, 5), (1, 23), (-1, 23)] sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # needs sage.libs.pari @@ -1468,7 +1471,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: gap(ZZ) # indirect doctest # needs sage.libs.gap + sage: gap(ZZ) # indirect doctest # needs sage.libs.gap Integers """ return 'Integers' diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index a5fc28597eb..565e5d12f4c 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -461,24 +461,25 @@ def _element_constructor_(self, x, n=0, prec=infinity): Various conversions from PARI (see also :trac:`2508`):: + sage: # needs sage.libs.pari sage: L. = LaurentSeriesRing(QQ, default_prec=10) - sage: L(pari('1/x')) # needs sage.libs.pari + sage: L(pari('1/x')) q^-1 - sage: L(pari('polchebyshev(5)')) # needs sage.libs.pari + sage: L(pari('polchebyshev(5)')) 5*q - 20*q^3 + 16*q^5 - sage: L(pari('polchebyshev(5) - 1/x^4')) # needs sage.libs.pari + sage: L(pari('polchebyshev(5) - 1/x^4')) -q^-4 + 5*q - 20*q^3 + 16*q^5 - sage: L(pari('1/polchebyshev(5)')) # needs sage.libs.pari + sage: L(pari('1/polchebyshev(5)')) 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)')) # needs sage.libs.pari + sage: L(pari('polchebyshev(5) + O(x^40)')) 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) # needs sage.libs.pari + sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) -q^-4 + 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('1/polchebyshev(5) + O(x^10)')) # needs sage.libs.pari + sage: L(pari('1/polchebyshev(5) + O(x^10)')) 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 # needs sage.libs.pari + sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 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)')) # needs sage.libs.pari + sage: L(pari('O(x^-10)')) O(q^-10) Check that :trac:`30073` is fixed:: diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index 9b8ad96eb09..52d84e8edb2 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -280,18 +280,19 @@ cdef class LaurentSeries(AlgebraElement): def _im_gens_(self, codomain, im_gens, base_map=None): """ Return the image of this series under the map that sends the generators of - the parent to im_gens. + the parent to ``im_gens``. EXAMPLES:: + sage: # needs sage.rings.number_field sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: R. = LaurentSeriesRing(K) # needs sage.rings.number_field - sage: z = t^-1 + i*t # needs sage.rings.number_field - sage: z._im_gens_(R, [t^2]) # needs sage.rings.number_field + sage: K. = NumberField(x^2 + 1) + sage: R. = LaurentSeriesRing(K) + sage: z = t^-1 + i*t + sage: z._im_gens_(R, [t^2]) t^-2 + i*t^2 - The argument base_map is not yet supported, because it isn't over power series:: + The argument ``base_map`` is not yet supported, because it isn't over power series:: sage: cc = K.hom([i]) # needs sage.rings.number_field sage: z._im_gens_(R, [t^2], base_map=cc) # needs sage.rings.number_field diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index 78fbbf67afc..aef134a609d 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -91,13 +91,13 @@ We can change the base ring:: sage: h = g.change_ring(QQ) - sage: h.parent() + sage: h.parent() # needs sage.combinat Lazy Laurent Series Ring in z over Rational Field - sage: h + sage: h # needs sage.combinat 4*z + 6*z^2 + 8*z^3 + 19*z^4 + 38*z^5 + 71*z^6 + 130*z^7 + O(z^8) - sage: hinv = h^-1; hinv + sage: hinv = h^-1; hinv # needs sage.combinat 1/4*z^-1 - 3/8 + 1/16*z - 17/32*z^2 + 5/64*z^3 - 29/128*z^4 + 165/256*z^5 + O(z^6) - sage: hinv.valuation() + sage: hinv.valuation() # needs sage.combinat -1 TESTS: @@ -171,30 +171,30 @@ ....: yield n ....: n += 1 - sage: L. = LazyLaurentSeriesRing(GF(2)) # needs sage.rings.finite_rings - sage: check(L, lambda n: n, valuation=-5) # needs sage.rings.finite_rings - sage: check(L, gen(), valuation=-5) # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2)) + sage: check(L, lambda n: n, valuation=-5) + sage: check(L, gen(), valuation=-5) sage: L = LazyDirichletSeriesRing(QQbar, "s") # needs sage.rings.number_field sage: check(L, lambda n: n, valuation=2) # needs sage.rings.number_field - sage: check(L, gen(), valuation=2) # needs sage.rings.number_field + sage: check(L, gen(), valuation=2) - sage: L. = LazyPowerSeriesRing(GF(2)) # needs sage.rings.finite_rings - sage: check(L, lambda n: n, valuation=0) # needs sage.rings.finite_rings - sage: check(L, gen(), valuation=0) # needs sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) + sage: check(L, lambda n: n, valuation=0) + sage: check(L, gen(), valuation=0) - sage: L. = LazyPowerSeriesRing(GF(2)) # needs sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) sage: check(L, lambda n: (x + y)^n, valuation=None) # needs sage.rings.finite_rings - sage: def gen(): # needs sage.rings.finite_rings + sage: def gen(): ....: n = 0 ....: while True: ....: yield (x+y)^n ....: n += 1 sage: check(L, gen(), valuation=None) # needs sage.rings.finite_rings - sage: s = SymmetricFunctions(GF(2)).s() # needs sage.combinat sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # needs sage.combinat sage.rings.finite_rings - sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), # needs sage.combinat sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.combinat + sage: L = LazySymmetricFunctions(s) # needs sage.combinat + sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), # needs sage.combinat ....: valuation=0) """ @@ -436,9 +436,9 @@ def coefficients(self, n=None): sage: f.coefficients() lazy list [1, 1, -1/6, ...] - sage: L. = LazyPowerSeriesRing(GF(2)) # needs sage.rings.finite_rings - sage: f = L(lambda n: n) # needs sage.rings.finite_rings - sage: f.coefficients(5) # needs sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) + sage: f = L(lambda n: n) + sage: f.coefficients(5) [1, 1, 1, 1, 1] """ coeff_stream = self._coeff_stream @@ -498,7 +498,7 @@ def map_coefficients(self, f): sage: s = L(lambda n: n-1) sage: s # needs sage.symbolic 1/(2^z) + 2/3^z + 3/4^z + 4/5^z + 5/6^z + 6/7^z + O(1/(8^z)) - sage: ms = s.map_coefficients(lambda c: c + 1) + sage: ms = s.map_coefficients(lambda c: c + 1) # needs sage.symbolic sage: ms # needs sage.symbolic 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + 8/8^z + O(1/(9^z)) @@ -1117,7 +1117,7 @@ def define(self, s): sage: C.define(1 + z*C^2) sage: C 1 + z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + 132*z^6 + O(z^7) - sage: binomial(2000, 1000) / C[1000] + sage: binomial(2000, 1000) / C[1000] # needs sage.symbolic 1001 The Catalan numbers but with a valuation 1:: @@ -1336,7 +1336,7 @@ def define(self, s): sage: L = LazySymmetricFunctions(s) sage: f = L.undefined() sage: f.define(1+(s[1]*f).revert()) - sage: f + sage: f # needs lrcalc_python s[] + s[1] + (-s[1,1]-s[2]) + (3*s[1,1,1]+6*s[2,1]+3*s[3]) + (-13*s[1,1,1,1]-39*s[2,1,1]-26*s[2,2]-39*s[3,1]-13*s[4]) @@ -1344,7 +1344,7 @@ def define(self, s): + (-419*s[1,1,1,1,1,1]-2095*s[2,1,1,1,1]-3771*s[2,2,1,1]-2095*s[2,2,2]-4190*s[3,1,1,1]-6704*s[3,2,1]-2095*s[3,3]-4190*s[4,1,1]-3771*s[4,2]-2095*s[5,1]-419*s[6]) + O^7 - sage: (f*s[1]).revert() + 1 - f # needs sage.combinat + sage: (f*s[1]).revert() + 1 - f # needs lrcalc_python sage.combinat O^7 """ @@ -1615,30 +1615,28 @@ def _add_(self, other): Similarly for Dirichlet series:: + sage: # needs sage.symbolic sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: s = L(lambda n: n) - sage: s # needs sage.symbolic + sage: s 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + O(1/(8^z)) sage: t = L(constant=1) - sage: t # needs sage.symbolic + sage: t 1 + 1/(2^z) + 1/(3^z) + O(1/(4^z)) sage: st = s + t - sage: st # needs sage.symbolic + sage: st 2 + 3/2^z + 4/3^z + 5/4^z + 6/5^z + 7/6^z + 8/7^z + O(1/(8^z)) - sage: r = L(constant=-1) sage: rt = r + t - sage: rt # needs sage.symbolic + sage: rt 0 - sage: r = L([1,2,3]) sage: rt = r + t - sage: rt # needs sage.symbolic + sage: rt 2 + 3/2^z + 4/3^z + 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)) - sage: r = L([1,2,3], constant=-1) sage: rt = r + t - sage: rt # needs sage.symbolic + sage: rt 2 + 3/2^z + 4/3^z """ P = self.parent() @@ -1831,20 +1829,20 @@ def _acted_upon_(self, scalar, self_on_left): Similarly for Dirichlet series:: + sage: # needs sage.symbolic sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: g = L([0,1]) - sage: 2 * g # needs sage.symbolic + sage: 2 * g 2/2^z - sage: -1 * g # needs sage.symbolic + sage: -1 * g -1/(2^z) - sage: 0*g # needs sage.symbolic + sage: 0*g 0 sage: M = L(lambda n: n) - sage: M # needs sage.symbolic + sage: M 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + O(1/(8^z)) - sage: 3 * M # needs sage.symbolic + sage: 3 * M 3 + 6/2^z + 9/3^z + 12/4^z + 15/5^z + 18/6^z + 21/7^z + O(1/(8^z)) - sage: 1 * M is M True @@ -2012,7 +2010,7 @@ def sin(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic sage: sin(z)[0:6] == sin(x).series(x, 6).coefficients(sparse=False) True """ @@ -2177,17 +2175,17 @@ def arccos(self): EXAMPLES:: sage: L. = LazyLaurentSeriesRing(RR) - sage: arccos(z) + sage: arccos(z) # needs sage.symbolic 1.57079632679490 - 1.00000000000000*z + 0.000000000000000*z^2 - 0.166666666666667*z^3 + 0.000000000000000*z^4 - 0.0750000000000000*z^5 + O(1.00000000000000*z^7) - sage: L. = LazyLaurentSeriesRing(SR) - sage: arccos(z/(1-z)) + sage: L. = LazyLaurentSeriesRing(SR) # needs sage.symbolic + sage: arccos(z/(1-z)) # needs sage.symbolic 1/2*pi - z - z^2 - 7/6*z^3 - 3/2*z^4 - 83/40*z^5 - 73/24*z^6 + O(z^7) - sage: L. = LazyPowerSeriesRing(SR) - sage: arccos(x/(1-y)) + sage: L. = LazyPowerSeriesRing(SR) # needs sage.symbolic + sage: arccos(x/(1-y)) # needs sage.symbolic 1/2*pi + (-x) + (-x*y) + ((-1/6)*x^3-x*y^2) + ((-1/2)*x^3*y-x*y^3) + ((-3/40)*x^5-x^3*y^2-x*y^4) + ((-3/8)*x^5*y+(-5/3)*x^3*y^3-x*y^5) + O(x,y)^7 @@ -2240,17 +2238,17 @@ def arccot(self): EXAMPLES:: sage: L. = LazyLaurentSeriesRing(RR) - sage: arccot(z) + sage: arccot(z) # needs sage.symbolic 1.57079632679490 - 1.00000000000000*z + 0.000000000000000*z^2 + 0.333333333333333*z^3 + 0.000000000000000*z^4 - 0.200000000000000*z^5 + O(1.00000000000000*z^7) - sage: L. = LazyLaurentSeriesRing(SR) - sage: arccot(z/(1-z)) + sage: L. = LazyLaurentSeriesRing(SR) # needs sage.symbolic + sage: arccot(z/(1-z)) # needs sage.symbolic 1/2*pi - z - z^2 - 2/3*z^3 + 4/5*z^5 + 4/3*z^6 + O(z^7) - sage: L. = LazyPowerSeriesRing(SR) - sage: acot(x/(1-y)) + sage: L. = LazyPowerSeriesRing(SR) # needs sage.symbolic + sage: acot(x/(1-y)) # needs sage.symbolic 1/2*pi + (-x) + (-x*y) + (1/3*x^3-x*y^2) + (x^3*y-x*y^3) + ((-1/5)*x^5+2*x^3*y^2-x*y^4) + (-x^5*y+10/3*x^3*y^3-x*y^5) + O(x,y)^7 @@ -2327,11 +2325,11 @@ def tanh(self): EXAMPLES:: sage: L. = LazyLaurentSeriesRing(QQ) - sage: tanh(z) + sage: tanh(z) # needs sage.libs.flint z - 1/3*z^3 + 2/15*z^5 - 17/315*z^7 + O(z^8) sage: L. = LazyPowerSeriesRing(QQ) - sage: tanh(x/(1-y)) + sage: tanh(x/(1-y)) # needs sage.libs.flint x + x*y + (-1/3*x^3+x*y^2) + (-x^3*y+x*y^3) + (2/15*x^5-2*x^3*y^2+x*y^4) + (2/3*x^5*y-10/3*x^3*y^3+x*y^5) + (-17/315*x^7+2*x^5*y^2-5*x^3*y^4+x*y^6) + O(x,y)^8 @@ -2360,10 +2358,10 @@ def coth(self): EXAMPLES:: sage: L. = LazyLaurentSeriesRing(QQ) - sage: coth(z) + sage: coth(z) # needs sage.libs.flint z^-1 + 1/3*z - 1/45*z^3 + 2/945*z^5 + O(z^6) - sage: coth(z + z^2) + sage: coth(z + z^2) # needs sage.libs.flint z^-1 - 1 + 4/3*z - 2/3*z^2 + 44/45*z^3 - 16/15*z^4 + 884/945*z^5 + O(z^6) TESTS:: @@ -2390,11 +2388,11 @@ def sech(self): EXAMPLES:: sage: L. = LazyLaurentSeriesRing(QQ) - sage: sech(z) + sage: sech(z) # needs sage.libs.flint 1 - 1/2*z^2 + 5/24*z^4 - 61/720*z^6 + O(z^7) sage: L. = LazyPowerSeriesRing(QQ) - sage: sech(x/(1-y)) + sage: sech(x/(1-y)) # needs sage.libs.flint 1 + (-1/2*x^2) + (-x^2*y) + (5/24*x^4-3/2*x^2*y^2) + (5/6*x^4*y-2*x^2*y^3) + (-61/720*x^6+25/12*x^4*y^2-5/2*x^2*y^4) + O(x,y)^7 @@ -2422,11 +2420,11 @@ def csch(self): EXAMPLES:: sage: L. = LazyLaurentSeriesRing(QQ) - sage: csch(z) + sage: csch(z) # needs sage.libs.flint z^-1 - 1/6*z + 7/360*z^3 - 31/15120*z^5 + O(z^6) sage: L. = LazyLaurentSeriesRing(QQ) - sage: csch(z/(1-z)) + sage: csch(z/(1-z)) # needs sage.libs.flint z^-1 - 1 - 1/6*z - 1/6*z^2 - 53/360*z^3 - 13/120*z^4 - 787/15120*z^5 + O(z^6) TESTS:: @@ -2632,16 +2630,17 @@ def __pow__(self, n): EXAMPLES:: + sage: # needs sage.symbolic sage: D = LazyDirichletSeriesRing(QQ, 's') sage: Z = D(constant=1) - sage: Z^2 # needs sage.symbolic + sage: Z^2 1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)) sage: f = Z^(1/3) - sage: f # needs sage.symbolic + sage: f 1 + 1/3/2^s + 1/3/3^s + 2/9/4^s + 1/3/5^s + 1/9/6^s + 1/3/7^s + O(1/(8^s)) - sage: f^2 # needs sage.symbolic + sage: f^2 1 + 2/3/2^s + 2/3/3^s + 5/9/4^s + 2/3/5^s + 4/9/6^s + 2/3/7^s + O(1/(8^s)) - sage: f^3 - Z # needs sage.symbolic + sage: f^3 - Z O(1/(8^s)) sage: L. = LazyLaurentSeriesRing(QQ) @@ -2822,10 +2821,10 @@ def _mul_(self, other): Check products with exact series:: - sage: L([1], constant=3)^2 # needs sage.symbolic + sage: L([1], constant=3)^2 1 + 6*z + 15*z^2 + 24*z^3 + 33*z^4 + 42*z^5 + 51*z^6 + O(z^7) - sage: (1+z) * L([1,0,1], constant=1) # needs sage.symbolic + sage: (1+z) * L([1,0,1], constant=1) 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6) """ P = self.parent() @@ -3138,7 +3137,7 @@ def _div_(self, other): sage: 1 / (1 - y) 1 + y + y^2 + y^3 + y^4 + y^5 + y^6 + O(x,y)^7 - sage: (x + y) / (1 - y) + sage: (x + y) / (1 - y) # needs sage.libs.singular (x+y) + (x*y+y^2) + (x*y^2+y^3) + (x*y^3+y^4) + (x*y^4+y^5) + (x*y^5+y^6) + (x*y^6+y^7) + O(x,y)^8 TESTS:: @@ -3314,7 +3313,7 @@ def exp(self): 1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4 + 1/120*z^5 + 1/720*z^6 + O(z^7) sage: exp(z + z^2) 1 + z + 3/2*z^2 + 7/6*z^3 + 25/24*z^4 + 27/40*z^5 + 331/720*z^6 + O(z^7) - sage: exp(0) + sage: exp(0) # needs sage.symbolic 1 sage: exp(1 + z) Traceback (most recent call last): @@ -3329,7 +3328,7 @@ def exp(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") + sage: L. = LazyLaurentSeriesRing(QQ); x = var("x") # needs sage.symbolic sage: exp(z)[0:6] == exp(x).series(x, 6).coefficients(sparse=False) True @@ -3385,7 +3384,7 @@ def log(self): sage: log(1+z)[0:6] == log(1+x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True - sage: log(z) # needs sage.symbolic + sage: log(z) Traceback (most recent call last): ... ValueError: can only compose with a positive valuation series @@ -3513,17 +3512,17 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: + sage: # needs sage.rings.number_field sage: Z. = ZZ[] - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: R. = LazyLaurentSeriesRing(K) # needs sage.rings.number_field - sage: f = R(lambda n: i^n, valuation=-2); f # needs sage.rings.number_field + sage: K. = NumberField(x^2 + 1) + sage: R. = LazyLaurentSeriesRing(K) + sage: f = R(lambda n: i^n, valuation=-2); f -t^-2 - i*t^-1 + 1 + i*t - t^2 - i*t^3 + t^4 + O(t^5) - sage: f._im_gens_(R, [t + t^2]) # needs sage.rings.number_field + sage: f._im_gens_(R, [t + t^2]) -t^-2 + (-i + 2)*t^-1 + (i - 2) + 4*t + (2*i - 6)*t^2 + (-2*i + 4)*t^3 + (-2*i - 7)*t^4 + O(t^5) - - sage: cc = K.hom([-i]) # needs sage.rings.number_field - sage: f._im_gens_(R, [t + t^2], base_map=cc) # needs sage.rings.number_field + sage: cc = K.hom([-i]) + sage: f._im_gens_(R, [t + t^2], base_map=cc) -t^-2 + (i + 2)*t^-1 + (-i - 2) + 4*t + (-2*i - 6)*t^2 + (2*i + 4)*t^3 + (2*i - 7)*t^4 + O(t^5) """ @@ -3783,7 +3782,7 @@ def __call__(self, g, *, check=True): ValueError: can only compose with a positive valuation series sage: e5 = L(e, degree=5) - sage: e5 # needs sage.symbolic + sage: e5 1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4 sage: e5(g) # needs sage.symbolic 1 + 1/(2^s) + 3/2/4^s + 1/(5^s) + 2/6^s + O(1/(8^s)) @@ -4557,9 +4556,10 @@ def __call__(self, *g, check=True): We perform the composition with a lazy Dirichlet series:: + sage: # needs sage.symbolic sage: D = LazyDirichletSeriesRing(QQ, "s") sage: g = D(constant=1)-1 - sage: g # needs sage.symbolic + sage: g 1/(2^s) + 1/(3^s) + 1/(4^s) + O(1/(5^s)) sage: f = 1 / (1 - x - y*z); f 1 + x + (x^2+y*z) + (x^3+2*x*y*z) + (x^4+3*x^2*y*z+y^2*z^2) @@ -4567,12 +4567,12 @@ def __call__(self, *g, check=True): + (x^6+5*x^4*y*z+6*x^2*y^2*z^2+y^3*z^3) + O(x,y,z)^7 sage: fog = f(g, g, g) - sage: fog # needs sage.symbolic + sage: fog 1 + 1/(2^s) + 1/(3^s) + 3/4^s + 1/(5^s) + 5/6^s + O(1/(7^s)) sage: fg = 1 / (1 - g - g*g) - sage: fg # needs sage.symbolic + sage: fg 1 + 1/(2^s) + 1/(3^s) + 3/4^s + 1/(5^s) + 5/6^s + 1/(7^s) + O(1/(8^s)) - sage: fog - fg # needs sage.symbolic + sage: fog - fg O(1/(8^s)) sage: f = 1 / (1 - 2*a) @@ -5217,11 +5217,11 @@ def _floordiv_(self, other): sage: g = x^2 + y*x sage: x // g 0 - sage: g = (x^2 + y*x) / (1 - x + x*y) + sage: g = (x^2 + y*x) / (1 - x + x*y) # needs sage.libs.singular sage: x // g 0 - sage: f = (x + y) / (1 - x - y + x*y) - sage: f // g + sage: f = (x + y) / (1 - x - y + x*y) # needs sage.libs.singular + sage: f // g # needs sage.libs.singular 0 sage: L. = LazyPowerSeriesRing(QQ) @@ -5466,22 +5466,18 @@ def is_unit(self): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules - sage: L = LazySymmetricFunctions(m) # needs sage.modules - - sage: L(2*m[1]).is_unit() # needs sage.modules + sage: # needs sage.modules + sage: m = SymmetricFunctions(ZZ).m() + sage: L = LazySymmetricFunctions(m) + sage: L(2*m[1]).is_unit() False - - sage: L(-1 + 2*m[1]).is_unit() # needs sage.modules + sage: L(-1 + 2*m[1]).is_unit() True - - sage: L(2 + m[1]).is_unit() # needs sage.modules + sage: L(2 + m[1]).is_unit() False - - sage: m = SymmetricFunctions(QQ).m() # needs sage.modules - sage: L = LazySymmetricFunctions(m) # needs sage.modules - - sage: L(2 + 3*m[1]).is_unit() # needs sage.modules + sage: m = SymmetricFunctions(QQ).m() + sage: L = LazySymmetricFunctions(m) + sage: L(2 + 3*m[1]).is_unit() True """ if self.is_zero(): # now 0 != 1 @@ -5524,25 +5520,23 @@ def __call__(self, *args, check=True): EXAMPLES:: + sage: # needs sage.modules sage: P. = QQ[] - sage: s = SymmetricFunctions(P).s() # needs sage.modules - sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: f = s[2] # needs sage.modules - sage: g = s[3] # needs sage.modules - sage: L(f)(L(g)) - L(f(g)) # needs sage.modules + sage: s = SymmetricFunctions(P).s() + sage: L = LazySymmetricFunctions(s) + sage: f = s[2] + sage: g = s[3] + sage: L(f)(L(g)) - L(f(g)) 0 - - sage: f = s[2] + s[2,1] # needs sage.modules - sage: g = s[1] + s[2,2] # needs sage.modules - sage: L(f)(L(g)) - L(f(g)) # needs sage.modules + sage: f = s[2] + s[2,1] + sage: g = s[1] + s[2,2] + sage: L(f)(L(g)) - L(f(g)) 0 - - sage: L(f)(g) - L(f(g)) # needs sage.modules + sage: L(f)(g) - L(f(g)) 0 - - sage: f = s[2] + s[2,1] # needs sage.modules - sage: g = s[1] + s[2,2] # needs sage.modules - sage: L(f)(L(q*g)) - L(f(q*g)) # needs sage.modules + sage: f = s[2] + s[2,1] + sage: g = s[1] + s[2,2] + sage: L(f)(L(q*g)) - L(f(q*g)) 0 The Frobenius character of the permutation action on set @@ -5567,11 +5561,11 @@ def __call__(self, *args, check=True): sage: S2 = LazySymmetricFunctions(tensor([s, s])) sage: A = S(s[1,1,1]) sage: B = S2(X+Y) - sage: A(B) + sage: A(B) # needs lrcalc_python (s[]#s[1,1,1]+s[1]#s[1,1]+s[1,1]#s[1]+s[1,1,1]#s[]) sage: H = S(lambda n: s[n]) # needs sage.modules - sage: H(S2(X*Y)) # needs sage.modules + sage: H(S2(X*Y)) # needs lrcalc_python sage.modules (s[]#s[]) + (s[1]#s[1]) + (s[1,1]#s[1,1]+s[2]#s[2]) + (s[1,1,1]#s[1,1,1]+s[2,1]#s[2,1]+s[3]#s[3]) + O^7 sage: H(S2(X+Y)) # needs sage.modules @@ -5588,19 +5582,19 @@ def __call__(self, *args, check=True): sage: s = SymmetricFunctions(QQ).s() sage: S = LazySymmetricFunctions(s) sage: f = 1 / (1 - S(s[2])) - sage: g = f(s[2]); g + sage: g = f(s[2]); g # needs lrcalc_python s[] + (s[2,2]+s[4]) + O^7 - sage: S(sum(f[i](s[2]) for i in range(5))).truncate(10) == g.truncate(10) + sage: S(sum(f[i](s[2]) for i in range(5))).truncate(10) == g.truncate(10) # needs lrcalc_python True sage: f = 1 / (1 - S(s[2])) sage: g = S(s[1]) / (1 - S(s[1])) - sage: f(g) + sage: f(g) # needs lrcalc_python s[] + s[2] + (s[1,1,1]+2*s[2,1]+s[3]) + (2*s[1,1,1,1]+4*s[2,1,1]+5*s[2,2]+5*s[3,1]+3*s[4]) + (2*s[1,1,1,1,1]+10*s[2,1,1,1]+14*s[2,2,1]+18*s[3,1,1]+16*s[3,2]+14*s[4,1]+4*s[5]) + (3*s[1,1,1,1,1,1]+22*s[2,1,1,1,1]+38*s[2,2,1,1]+28*s[2,2,2]+48*s[3,1,1,1]+82*s[3,2,1]+25*s[3,3]+51*s[4,1,1]+56*s[4,2]+31*s[5,1]+9*s[6]) + O^7 - sage: f(0) + sage: f(0) # needs lrcalc_python 1 sage: f(s(1)) Traceback (most recent call last): @@ -5736,18 +5730,15 @@ def revert(self): sage: f = L(a + b*p[1]) sage: f.revert() (((-a)/b)*p[]) + 1/b*p[1] - - sage: f = L(2*p[1]) # needs sage.modules - sage: f.revert() # needs sage.modules + sage: f = L(2*p[1]) + sage: f.revert() 1/2*p[1] - - sage: f = L(2*p[1] + p[1,1]) # needs sage.modules - sage: f.revert() # needs sage.modules + sage: f = L(2*p[1] + p[1,1]) + sage: f.revert() 1/2*p[1] + (-1/8*p[1,1]) + (1/16*p[1,1,1]) + (-5/128*p[1,1,1,1]) + (7/256*p[1,1,1,1,1]) + (-21/1024*p[1,1,1,1,1,1]) + (33/2048*p[1,1,1,1,1,1,1]) + O^8 - - sage: f.revert()(f) # needs sage.modules + sage: f.revert()(f) p[1] + O^8 ALGORITHM: @@ -5855,7 +5846,7 @@ def derivative_with_respect_to_p1(self, n=1): sage: C = T(lambda n: (sum(euler_phi(k)*p([k])**(n//k) ....: for k in divisors(n))/n if n > 0 else 0)) sage: L = T(lambda n: p([1]*n)) - sage: L - C.derivative_with_respect_to_p1() + sage: L - C.derivative_with_respect_to_p1() # needs sage.libs.pari O^6 TESTS:: @@ -5923,13 +5914,14 @@ def functorial_composition(self, *args): \mathfrak{p}_{2}`, where `\mathfrak{p}` is the :class:`~sage.combinat.species.subset_species.SubsetSpecies`.:: + sage: # needs sage.modules sage: R. = QQ[] - sage: h = SymmetricFunctions(R).h() # needs sage.modules - sage: m = SymmetricFunctions(R).m() # needs sage.modules - sage: L = LazySymmetricFunctions(m) # needs sage.modules - sage: P = L(lambda n: sum(q^k*h[n-k]*h[k] for k in range(n+1))) # needs sage.modules - sage: P2 = L(lambda n: h[2]*h[n-2], valuation=2) # needs sage.modules - sage: P.functorial_composition(P2)[:4] # needs sage.modules + sage: h = SymmetricFunctions(R).h() + sage: m = SymmetricFunctions(R).m() + sage: L = LazySymmetricFunctions(m) + sage: P = L(lambda n: sum(q^k*h[n-k]*h[k] for k in range(n+1))) + sage: P2 = L(lambda n: h[2]*h[n-2], valuation=2) + sage: P.functorial_composition(P2)[:4] # needs sage.libs.pari [m[], m[1], (q+1)*m[1, 1] + (q+1)*m[2], @@ -5937,12 +5929,12 @@ def functorial_composition(self, *args): For example, there are:: - sage: P.functorial_composition(P2)[4].coefficient([4])[3] # needs sage.modules + sage: P.functorial_composition(P2)[4].coefficient([4])[3] # needs sage.libs.pari sage.modules 3 unlabelled graphs on 4 vertices and 3 edges, and:: - sage: P.functorial_composition(P2)[4].coefficient([2,2])[3] # needs sage.modules + sage: P.functorial_composition(P2)[4].coefficient([2,2])[3] # needs sage.libs.pari sage.modules 8 labellings of their vertices with two 1's and two 2's. @@ -5959,7 +5951,7 @@ def functorial_composition(self, *args): sage: Ep = p[1]*E.derivative_with_respect_to_p1(); Ep h[1] + (h[1,1]) + (h[2,1]) + (h[3,1]) + (h[4,1]) + (h[5,1]) + O^7 sage: f = L(lambda n: h[n-n//2, n//2]) - sage: f - Ep.functorial_composition(f) + sage: f - Ep.functorial_composition(f) # needs sage.libs.pari O^7 The functorial composition distributes over the sum:: @@ -5978,7 +5970,7 @@ def functorial_composition(self, *args): sage: h = SymmetricFunctions(QQ).h() # needs sage.modules sage: L = LazySymmetricFunctions(h) # needs sage.modules - sage: L(h[2,1]).functorial_composition(3*h[0]) # needs sage.modules + sage: L(h[2,1]).functorial_composition(3*h[0]) # needs sage.libs.pari sage.modules 3*h[] + O^7 Check an instance of a non-group action:: @@ -5989,7 +5981,7 @@ def functorial_composition(self, *args): sage: L = LazySymmetricFunctions(p) sage: f = L(lambda n: s[n]) sage: g = 2*s[2, 1, 1] + s[2, 2] + 3*s[4] - sage: r = f.functorial_composition(g); r[4] + sage: r = f.functorial_composition(g); r[4] # needs sage.libs.pari Traceback (most recent call last): ... ValueError: the argument is not the Frobenius character of a permutation representation @@ -6146,7 +6138,7 @@ def arithmetic_product(self, *args, check=True): sage: C = species.CycleSpecies().cycle_index_series() sage: c = L(lambda n: C[n]) sage: Lplus = L(lambda n: p([1]*n), valuation=1) - sage: r = c.arithmetic_product(Lplus); r + sage: r = c.arithmetic_product(Lplus); r # needs sage.libs.pari m[1] + (3*m[1,1]+2*m[2]) + (8*m[1,1,1]+4*m[2,1]+2*m[3]) + (42*m[1,1,1,1]+21*m[2,1,1]+12*m[2,2]+7*m[3,1]+3*m[4]) @@ -6156,7 +6148,7 @@ def arithmetic_product(self, *args, check=True): In particular, the number of regular octopuses is:: - sage: [r[n].coefficient([1]*n) for n in range(8)] # needs sage.modules + sage: [r[n].coefficient([1]*n) for n in range(8)] # needs sage.libs.pari sage.modules [0, 1, 3, 8, 42, 144, 1440, 5760] It is shown in [MM2008]_ that the exponential generating @@ -6194,7 +6186,7 @@ def arithmetic_product(self, *args, check=True): s[2, 2, 1, 1] + s[3, 1, 1, 1] + s[3, 2, 1] + s[3, 3] + 2*s[4, 1, 1] sage: f = 1/(1-L(s[1])) # needs sage.modules - sage: f.arithmetic_product(s[1]) - f # needs sage.modules + sage: f.arithmetic_product(s[1]) - f # needs lrcalc_python sage.modules O^7 Check that the arithmetic product of symmetric functions with @@ -6323,7 +6315,7 @@ def symmetric_function(self, degree=None): sage: elt.symmetric_function() s[2] sage: f = 1 / (1 - elt) - sage: f + sage: f # needs lrcalc_python s[] + s[2] + (s[2,2]+s[3,1]+s[4]) + (s[2,2,2]+2*s[3,2,1]+s[3,3]+s[4,1,1]+3*s[4,2]+2*s[5,1]+s[6]) + O^7 sage: f.symmetric_function() Traceback (most recent call last): @@ -6331,15 +6323,15 @@ def symmetric_function(self, degree=None): ValueError: not a symmetric function sage: # needs sage.modules - sage: f4 = f.truncate(5); f4 + sage: f4 = f.truncate(5); f4 # needs lrcalc_python s[] + s[2] + (s[2,2]+s[3,1]+s[4]) - sage: f4.symmetric_function() + sage: f4.symmetric_function() # needs lrcalc_python s[] + s[2] + s[2, 2] + s[3, 1] + s[4] - sage: f4.symmetric_function() == f.symmetric_function(4) + sage: f4.symmetric_function() == f.symmetric_function(4) # needs lrcalc_python True sage: S.zero().symmetric_function() 0 - sage: f4.symmetric_function(0) + sage: f4.symmetric_function(0) # needs lrcalc_python s[] """ @@ -6422,9 +6414,9 @@ def valuation(self): sage: (mu - mu).valuation() # needs sage.libs.pari +Infinity sage: g = L(constant=1, valuation=2) - sage: g.valuation() + sage: g.valuation() # needs sage.symbolic log(2) - sage: (g*g).valuation() + sage: (g*g).valuation() # needs sage.symbolic 2*log(2) """ if isinstance(self._coeff_stream, Stream_zero): @@ -6448,7 +6440,7 @@ def _mul_(self, other): 1 + 1/(2^s) + 1/(3^s) + O(1/(4^s)) sage: zeta * zeta # needs sage.symbolic 1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)) - sage: [number_of_divisors(n) for n in range(1, 8)] + sage: [number_of_divisors(n) for n in range(1, 8)] # needs sage.libs.pari [1, 2, 2, 3, 2, 4, 2] sage: mu = D(moebius) @@ -6521,10 +6513,10 @@ def __invert__(self): TESTS:: sage: L = LazyDirichletSeriesRing(ZZ, "z", sparse=False) - sage: ~L(constant=1) - L(moebius) + sage: ~L(constant=1) - L(moebius) # needs sage.libs.pari O(1/(8^z)) sage: L = LazyDirichletSeriesRing(ZZ, "z", sparse=True) - sage: ~L(constant=1) - L(moebius) + sage: ~L(constant=1) - L(moebius) # needs sage.libs.pari O(1/(8^z)) Trying to invert a non-invertible 'exact' series raises a @@ -6571,12 +6563,13 @@ def __call__(self, p, *, check=True): sage: Z = D(constant=1) sage: from sage.arith.misc import dedekind_psi sage: Psi = D(dedekind_psi) - sage: Z(s)*Z(s-1)/Z(2*s) - Psi + sage: Z(s)*Z(s-1)/Z(2*s) - Psi # needs sage.symbolic O(1/(8^s)) - sage: Z(s)*Z(s-1)/Z(2*s-2) - (1/Psi).map_coefficients(abs) + sage: Z(s)*Z(s-1)/Z(2*s-2) - (1/Psi).map_coefficients(abs) # needs sage.symbolic O(1/(8^s)) + sage: # needs sage.symbolic sage: Z(5) zeta(5) sage: Z(1+I) @@ -6605,11 +6598,11 @@ def __call__(self, p, *, check=True): 5 sage: f = D([1,2,-3,-4], constant=2) - sage: bool(f(2) == -1 + -5/3^2 + -6/4^2 + 2*zeta(2)) + sage: bool(f(2) == -1 + -5/3^2 + -6/4^2 + 2*zeta(2)) # needs sage.symbolic True - sage: f(0) + sage: f(0) # needs sage.symbolic -13 - sage: f(1) + sage: f(1) # needs sage.symbolic Infinity """ P = self.parent() @@ -6655,24 +6648,22 @@ def _format_series(self, formatter, format_strings=False): TESTS:: + sage: # needs sage.symbolic sage: L = LazyDirichletSeriesRing(QQ, "s") sage: f = L(constant=1) - sage: f._format_series(repr) # needs sage.symbolic + sage: f._format_series(repr) '1 + 1/(2^s) + 1/(3^s) + O(1/(4^s))' - sage: f._format_series(unicode_art) # needs sage.symbolic + sage: f._format_series(unicode_art) -s -s 1 + 2 + 3 + O(1/(4^s)) - - sage: L([1,-1,1])._format_series(repr) # needs sage.symbolic + sage: L([1,-1,1])._format_series(repr) '1 - 1/(2^s) + 1/(3^s)' - - sage: L([1,-1,1])._format_series(ascii_art) # needs sage.symbolic + sage: L([1,-1,1])._format_series(ascii_art) -s -s 1 + -2 + 3 - sage: R. = QQ[] sage: L = LazyDirichletSeriesRing(R, "s") - sage: L([1,-1 + x,1/3])._format_series(ascii_art) # needs sage.symbolic + sage: L([1,-1 + x,1/3])._format_series(ascii_art) ( -s) (3 ) ( -s ) (---) diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index 07ea18fafa0..f1dbbe5f5ce 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -155,10 +155,10 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No If ``x`` can be converted into an element of the underlying Laurent polynomial ring, we do this:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: L(2) # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: L(2) 0 - sage: L(3) # needs sage.rings.finite_rings + sage: L(3) 1 In particular, ``x`` can be a Laurent polynomial:: @@ -256,13 +256,13 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: D = LazyDirichletSeriesRing(QQ, "s") sage: L. = LazyLaurentSeriesRing(D) - sage: L(lambda n: 1/factorial(n), valuation=0) + sage: L(lambda n: 1/factorial(n), valuation=0) # needs sage.symbolic (1 + 1/2/2^s + 1/6/3^s + 1/24/4^s + 1/120/5^s + 1/720/6^s + 1/5040/7^s + O(1/(8^s))) We can also specify that the given function should be interpreted as the coefficients of the Laurent series:: - sage: L(coefficients=lambda n: 1/factorial(n), valuation=0) + sage: L(coefficients=lambda n: 1/factorial(n), valuation=0) # needs sage.symbolic 1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4 + 1/120*z^5 + 1/720*z^6 + O(z^7) When the argument ``x`` is callable and not convertible into @@ -272,14 +272,14 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: R. = QQ[] sage: D = LazyDirichletSeriesRing(ZZ, 't') - sage: D(1+2*q) + sage: D(1+2*q) # needs sage.symbolic 3 + 5/2^t + 7/3^t + 9/4^t + 11/5^t + 13/6^t + 15/7^t + O(1/(8^t)) In this example, the Dirichlet series ``m`` is considered as an element in the base ring:: sage: m = D(moebius) - sage: s = L(m, valuation=0) + sage: s = L(m, valuation=0) # needs sage.symbolic sage: s[0] 1 - 1/(2^s) - 1/(3^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(8^s)) sage: s[1] @@ -401,7 +401,7 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: D = LazyDirichletSeriesRing(ZZ, "s") sage: E = LazyDirichletSeriesRing(QQ, "t") - sage: D(E([1,2,3])) + sage: D(E([1,2,3])) # needs sage.symbolic 1 + 2/2^s + 3/3^s This gives zero:: @@ -760,14 +760,14 @@ def characteristic(self): sage: L.characteristic() 0 - sage: R. = LazyLaurentSeriesRing(GF(11)); R # needs sage.rings.finite_rings + sage: R. = LazyLaurentSeriesRing(GF(11)); R Lazy Laurent Series Ring in w over Finite Field of size 11 - sage: R.characteristic() # needs sage.rings.finite_rings + sage: R.characteristic() 11 - sage: R. = LazyPowerSeriesRing(GF(7)); R # needs sage.rings.finite_rings + sage: R. = LazyPowerSeriesRing(GF(7)); R Multivariate Lazy Taylor Series Ring in x, y over Finite Field of size 7 - sage: R.characteristic() # needs sage.rings.finite_rings + sage: R.characteristic() 7 sage: L = LazyDirichletSeriesRing(ZZ, "s") @@ -782,13 +782,13 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # needs sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) True sage: R = LazyPowerSeriesRing(ZZ, 'z') - sage: L.has_coerce_map_from(R) # needs sage.rings.finite_rings + sage: L.has_coerce_map_from(R) True sage: L = LazyLaurentSeriesRing(QQ, 'z') @@ -802,10 +802,10 @@ def _coerce_map_from_(self, S): sage: L.has_coerce_map_from(R) False - sage: L = LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # needs sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) True sage: # needs sage.modules sage.rings.finite_rings @@ -1207,13 +1207,13 @@ def __init__(self, base_ring, names, sparse=True, category=None): (euclidean domains and infinite enumerated sets and metric spaces) and infinite sets) - sage: L = LazyLaurentSeriesRing(GF(5), 't') # needs sage.rings.finite_rings - sage: TestSuite(L).run() # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(5), 't') + sage: TestSuite(L).run() - sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't') # needs sage.rings.finite_rings - sage: TestSuite(L).run() # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't') + sage: TestSuite(L).run() - sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') sage: TestSuite(L).run() # needs sage.rings.finite_rings sage: L = LazyLaurentSeriesRing(Zmod(6), 't') @@ -1257,7 +1257,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: LazyLaurentSeriesRing(GF(2), 'z') Lazy Laurent Series Ring in z over Finite Field of size 2 """ return "Lazy Laurent Series Ring in {} over {}".format(self.variable_name(), self.base_ring()) @@ -1268,8 +1268,8 @@ def _latex_(self): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: latex(L) # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: latex(L) \Bold{F}_{2} (\!(z)\!) """ from sage.misc.latex import latex @@ -1354,16 +1354,16 @@ def some_elements(self): -2*z^-3 - 2*z^-2 + 4*z^-1 + 11 - z - 34*z^2 - 31*z^3 + O(z^4), 4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + O(z^5)] - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: L.some_elements()[:7] # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: L.some_elements()[:7] [0, 1, z, z^-4 + z^-3 + z^2 + z^3, z^-2, 1 + z + z^3 + z^4 + z^6 + O(z^7), z^-1 + z + z^3 + O(z^5)] - sage: L = LazyLaurentSeriesRing(GF(3), 'z') # needs sage.rings.finite_rings - sage: L.some_elements()[:7] # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(3), 'z') + sage: L.some_elements()[:7] [0, 1, z, z^-3 + z^-1 + 2 + z + z^2 + z^3, z^-2, @@ -1562,7 +1562,7 @@ def q_pochhammer(self, q=None): sage: R = ZZ['q'].fraction_field() sage: q = R.gen() sage: L. = LazyLaurentSeriesRing(LazyDirichletSeriesRing(R, "s")) - sage: z.q_pochhammer(q) + sage: z.q_pochhammer(q) # needs sage.symbolic 1 + ((1/(q-1)))*z + ((q/(q^3-q^2-q+1)))*z^2 + ... + O(z^7) REFERENCES: @@ -1612,7 +1612,7 @@ def euler(self): TESTS:: sage: L. = LazyLaurentSeriesRing(LazyDirichletSeriesRing(QQ, "s")) - sage: q.euler() + sage: q.euler() # needs sage.symbolic 1 - q - q^2 + q^5 + O(q^7) REFERENCES: @@ -1671,11 +1671,11 @@ def __init__(self, base_ring, names, sparse=True, category=None): sage: L = LazyPowerSeriesRing(QQ, 's, t') sage: TestSuite(L).run(skip="_test_fraction_field") - sage: L = LazyPowerSeriesRing(GF(5), 't') # needs sage.rings.finite_rings - sage: TestSuite(L).run() # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(5), 't') + sage: TestSuite(L).run() - sage: L = LazyPowerSeriesRing(GF(5), 's, t') # needs sage.rings.finite_rings - sage: TestSuite(L).run(skip=['_test_fraction_field']) # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(5), 's, t') + sage: TestSuite(L).run(skip=['_test_fraction_field']) sage: L = LazyPowerSeriesRing(Zmod(6), 't') sage: TestSuite(L).run(skip=['_test_revert']) @@ -1757,7 +1757,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: LazyPowerSeriesRing(GF(2), 'z') Lazy Taylor Series Ring in z over Finite Field of size 2 """ BR = self.base_ring() @@ -1772,8 +1772,8 @@ def _latex_(self): EXAMPLES:: - sage: L = LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: latex(L) # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') + sage: latex(L) \Bold{F}_{2} [\![z]\!] """ from sage.misc.latex import latex @@ -1871,10 +1871,10 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No EXAMPLES:: - sage: L = LazyPowerSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings - sage: L(2) # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') + sage: L(2) 0 - sage: L(3) # needs sage.rings.finite_rings + sage: L(3) 1 sage: L = LazyPowerSeriesRing(ZZ, 'z') @@ -2193,15 +2193,15 @@ def some_elements(self): 1 + z - 2*z^2 - 7*z^3 - z^4 + 20*z^5 + 23*z^6 + O(z^7), z + 4*z^2 + 9*z^3 + 16*z^4 + 25*z^5 + 36*z^6 + O(z^7)] - sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z') # needs sage.rings.finite_rings - sage: L.some_elements()[:6] # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z') + sage: L.some_elements()[:6] [0, 1, z + q*z^2 + q*z^3 + q*z^4 + O(z^5), z + z^2 + z^3, 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6), z + z^2 + z^4 + z^5 + O(z^7)] - sage: L = LazyPowerSeriesRing(GF(3), 'q, t') # needs sage.rings.finite_rings - sage: L.some_elements()[:6] # needs sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(3), 'q, t') + sage: L.some_elements()[:6] [0, 1, q, q + q^2 + q^3, 1 + q + q^2 + (-q^3) + (-q^4) + (-q^5) + (-q^6) + O(q,t)^7, @@ -2277,21 +2277,21 @@ def __init__(self, basis, sparse=True, category=None): sage: s = SymmetricFunctions(QQ).s() # needs sage.modules sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: TestSuite(L).run() # needs sage.modules + sage: TestSuite(L).run() # needs lrcalc_python sage.modules - sage: p = SymmetricFunctions(GF(5)).p() # needs sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(p) # needs sage.modules sage.rings.finite_rings - sage: TestSuite(L).run() # needs sage.modules sage.rings.finite_rings + sage: p = SymmetricFunctions(GF(5)).p() # needs sage.modules + sage: L = LazySymmetricFunctions(p) # needs sage.modules + sage: TestSuite(L).run() # needs sage.modules Reversion will only work when the base ring is a field:: sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: TestSuite(L).run(skip=['_test_revert']) # needs sage.modules + sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python sage.modules sage: s = SymmetricFunctions(QQ["q"]).s() # needs sage.modules sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: TestSuite(L).run(skip=['_test_revert']) # needs sage.modules + sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python sage.modules Options are remembered across doctests:: @@ -2347,8 +2347,8 @@ def _repr_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() # needs sage.modules sage.rings.finite_rings - sage: LazySymmetricFunctions(s) # needs sage.modules sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.modules + sage: LazySymmetricFunctions(s) # needs sage.modules Lazy completion of Symmetric Functions over Finite Field of size 2 in the Schur basis """ return "Lazy completion of {}".format(self._laurent_poly_ring) @@ -2359,9 +2359,9 @@ def _latex_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() # needs sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # needs sage.modules sage.rings.finite_rings - sage: latex(L) # needs sage.modules sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules + sage: latex(L) # needs sage.modules \text{\texttt{Symmetric{ }Functions{ }over{ }Finite{ }Field{ }of{ }size{ }2{ }in{ }the{ }Schur{ }basis}} """ from sage.misc.latex import latex @@ -2589,9 +2589,9 @@ def some_elements(self): EXAMPLES:: - sage: m = SymmetricFunctions(GF(5)).m() # needs sage.modules sage.rings.finite_rings - sage: L = LazySymmetricFunctions(m) # needs sage.modules sage.rings.finite_rings - sage: L.some_elements()[:5] # needs sage.modules sage.rings.finite_rings + sage: m = SymmetricFunctions(GF(5)).m() # needs sage.modules + sage: L = LazySymmetricFunctions(m) # needs sage.modules + sage: L.some_elements()[:5] # needs sage.modules [0, m[], 2*m[] + 2*m[1] + 3*m[2], 2*m[1] + 3*m[2], 3*m[] + 2*m[1] + (m[1,1]+m[2]) + (2*m[1,1,1]+m[3]) @@ -2846,7 +2846,7 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: X = L(constant=5, degree=3) sage: X # needs sage.symbolic 5/3^z + 5/4^z + 5/5^z + O(1/(6^z)) - sage: X.valuation() + sage: X.valuation() # needs sage.symbolic log(3) sage: e = L(moebius) sage: e # needs sage.symbolic @@ -2880,14 +2880,14 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No TESTS:: - sage: L = LazyDirichletSeriesRing(GF(2), 'z') # needs sage.rings.finite_rings + sage: L = LazyDirichletSeriesRing(GF(2), 'z') Traceback (most recent call last): ... ValueError: positive characteristic not allowed for Dirichlet series sage: L. = LazyLaurentSeriesRing(QQ) sage: D = LazyDirichletSeriesRing(QQ, 't') - sage: d = D(L.one()) + sage: d = D(L.one()) # needs sage.symbolic sage: d # needs sage.symbolic 1 + 1/(2^t) + 1/(3^t) + 1/(4^t) + 1/(5^t) + 1/(6^t) + 1/(7^t) + O(1/(8^t)) @@ -2898,7 +2898,7 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No 2 + 6/2^t + 12/3^t + 20/4^t + 30/5^t + 42/6^t + 56/7^t + O(1/(8^t)) sage: s = D(lambda n: n) - sage: d2 = D(s, valuation=2) + sage: d2 = D(s, valuation=2) # needs sage.symbolic sage: d2 # needs sage.symbolic 1/(2^t) + 2/3^t + 3/4^t + 4/5^t + 5/6^t + 6/7^t + 7/8^t + O(1/(9^t)) @@ -2907,8 +2907,8 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: m # needs sage.symbolic -1/(2^s) - 1/(3^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(9^s)) sage: D = LazyDirichletSeriesRing(QQ, 't') - sage: dm = D(m) - sage: dm # needs sage.symbolic + sage: dm = D(m) # needs sage.libs.pari + sage: dm # needs sage.libs.pari sage.symbolic -1/(2^t) - 1/(3^t) - 1/(5^t) + 1/(6^t) - 1/(7^t) + O(1/(9^t)) """ if isinstance(x, (list, tuple)): diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index eff6af6e04d..8f7c0176ccb 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -99,16 +99,17 @@ Inclusion map from the reals to the complexes:: A map from a multivariate polynomial ring to itself:: sage: R. = PolynomialRing(QQ,3) - sage: phi = R.hom([y,z,x^2]); phi + sage: phi = R.hom([y, z, x^2]); phi Ring endomorphism of Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> y y |--> z z |--> x^2 - sage: phi(x+y+z) + sage: phi(x + y + z) x^2 + y + z An endomorphism of a quotient of a multi-variate polynomial ring:: + sage; # needs sage.libs.singular sage: R. = PolynomialRing(QQ) sage: S. = quo(R, ideal(1 + y^2)) # needs sage.libs.singular sage: phi = S.hom([a^2, -b]) # needs sage.libs.singular @@ -203,14 +204,15 @@ Inclusion from `\QQ` to the 3-adic field:: An automorphism of a quotient of a univariate polynomial ring:: + sage: # needs sage.libs.pari sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2 - 2) # needs sage.libs.pari - sage: sqrt2^2 # needs sage.libs.pari + sage: S. = R.quo(x^2 - 2) + sage: sqrt2^2 2 - sage: (3+sqrt2)^10 # needs sage.libs.pari + sage: (3+sqrt2)^10 993054*sqrt2 + 1404491 - sage: c = S.hom([-sqrt2]) # needs sage.libs.pari - sage: c(1+sqrt2) # needs sage.libs.pari + sage: c = S.hom([-sqrt2]) + sage: c(1+sqrt2) -sqrt2 + 1 Note that Sage verifies that the morphism is valid:: @@ -276,11 +278,13 @@ positive:: sage: R.hom([1/t]) Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators sage: R.hom([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 Complex conjugation on cyclotomic fields:: @@ -300,20 +304,21 @@ Complex conjugation on cyclotomic fields:: Embedding a number field into the reals:: + sage: # needs sage.rings.number_field sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^3 - 2) # needs sage.rings.number_field + sage: K. = NumberField(x^3 - 2) sage: alpha = RR(2)^(1/3); alpha 1.25992104989487 - sage: i = K.hom([alpha],check=False); i # needs sage.rings.number_field + sage: i = K.hom([alpha],check=False); i Ring morphism: From: Number Field in beta with defining polynomial x^3 - 2 To: Real Field with 53 bits of precision Defn: beta |--> 1.25992104989487 - sage: i(beta) # needs sage.rings.number_field + sage: i(beta) 1.25992104989487 - sage: i(beta^3) # needs sage.rings.number_field + sage: i(beta^3) 2.00000000000000 - sage: i(beta^2 + 1) # needs sage.rings.number_field + sage: i(beta^2 + 1) 2.58740105196820 An example from Jim Carlson:: @@ -832,21 +837,22 @@ cdef class RingHomomorphism(RingMap): We check that composition works when there is a base map:: + sage: # needs sage.rings.finite_rings sage: R. = ZZ[] - sage: K. = GF(7^2) # needs sage.rings.finite_rings - sage: L. = K.extension(x^3 - 3) # needs sage.rings.finite_rings - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # needs sage.rings.finite_rings - sage: phi # needs sage.rings.finite_rings + 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 Defn: u |--> 2*u with map of base ring - sage: psi = phi^3; psi # needs sage.rings.finite_rings + 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 Defn: u |--> u with map of base ring - sage: psi(a) == phi(phi(phi(a))) # needs sage.rings.finite_rings + sage: psi(a) == phi(phi(phi(a))) True It also works when the image of the base map is not contained within the base ring of the codomain:: @@ -968,14 +974,14 @@ cdef class RingHomomorphism(RingMap): The image of the inverse image ideal can be strictly smaller than the original ideal:: - sage: # needs sage.libs.singular + sage: # needs sage.libs.singular sage.rings.number_field sage: S. = QQ['u,v'].quotient('v^2 - 2') - sage: f = QuadraticField(2).hom([v], S) # needs sage.rings.number_field + sage: f = QuadraticField(2).hom([v], S) sage: I = S.ideal(u + v) - sage: J = f.inverse_image(I) # needs sage.rings.number_field - sage: J.is_zero() # needs sage.rings.number_field + sage: J = f.inverse_image(I) + sage: J.is_zero() True - sage: f(J) < I # needs sage.rings.number_field + sage: f(J) < I True Fractional ideals are not yet fully supported:: @@ -1107,20 +1113,21 @@ cdef class RingHomomorphism(RingMap): Check cases involving quotient rings in which a generator is constant (:trac:`31178`):: + sage: # needs sage.libs.singular sage: R. = QQ[] - sage: B. = R.quotient(R.ideal(x)) # needs sage.libs.singular - sage: g = R.hom([d^2, d^3], B) # needs sage.libs.singular - sage: g.inverse_image(d) # needs sage.libs.singular + sage: B. = R.quotient(R.ideal(x)) + sage: g = R.hom([d^2, d^3], B) + sage: g.inverse_image(d) Traceback (most recent call last): ... ValueError: element d does not have preimage - sage: g.inverse_image(d^2) # needs sage.libs.singular + sage: g.inverse_image(d^2) x - sage: g.inverse_image(d^3) # needs sage.libs.singular + sage: g.inverse_image(d^3) y - sage: A. = R.quotient(R.ideal(y^2 - x^3)) # needs sage.libs.singular - sage: h = A.hom([d^2, d^3], B) # needs sage.libs.singular - sage: h.inverse_image(d^2) # needs sage.libs.singular + 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) a Check that quotient rings are handled correctly (:trac:`33217`):: @@ -1367,17 +1374,18 @@ cdef class RingHomomorphism(RingMap): The following non-linear homomorphism is not invertible, but it induces an isomorphism on a quotient ring:: + sage: # needs sage.libs.singular sage: R. = QQ[] sage: f = R.hom([y*z, x*z, x*y], R) - sage: f.inverse() # needs sage.libs.singular + sage: f.inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: f.is_injective() # needs sage.libs.singular + sage: f.is_injective() True - sage: Q. = R.quotient(x*y*z - 1) # needs sage.libs.singular - sage: g = Q.hom([y*z, x*z, x*y], Q) # needs sage.libs.singular - sage: g.inverse() # needs sage.libs.singular + sage: Q. = R.quotient(x*y*z - 1) + sage: g = Q.hom([y*z, x*z, x*y], Q) + sage: g.inverse() 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 @@ -1481,18 +1489,19 @@ cdef class RingHomomorphism(RingMap): Morphisms involving quotient rings:: + sage: # needs sage.libs.singular sage: R. = QQ[] - sage: S. = QQ['s,u,t'].quotient('u-t^2') # needs sage.libs.singular - sage: f = R.hom([s, -t], S) # needs sage.libs.singular - sage: (f.inverse() * f).is_identity() # needs sage.libs.singular + sage: S. = QQ['s,u,t'].quotient('u-t^2') + sage: f = R.hom([s, -t], S) + sage: (f.inverse() * f).is_identity() True - sage: Q. = R.quotient(x - y^2) # needs sage.libs.singular - sage: g = Q.hom([v, -w], Q) # needs sage.libs.singular - sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w # needs sage.libs.singular + 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 True sage: S. = QQ[] - sage: h = Q.hom([z^2, -z], S) # needs sage.libs.singular - sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w # needs sage.libs.singular + sage: h = Q.hom([z^2, -z], S) + sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w True Morphisms between number fields and quotient rings:: @@ -1528,23 +1537,24 @@ cdef class RingHomomorphism(RingMap): Non-injective homomorphisms:: + sage: # needs sage.libs.singular sage: R. = QQ[] sage: S. = QQ[] - sage: S.hom([x, y, 0], R).inverse() # needs sage.libs.singular + sage: S.hom([x, y, 0], R).inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective sage: T. = QQ[] - sage: R.hom([2*z, 3*z], T).inverse() # needs sage.libs.singular + sage: R.hom([2*z, 3*z], T).inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q. = R.quotient([x^5, y^4]) # needs sage.libs.singular - sage: R.hom([u, v], Q).inverse() # needs sage.libs.singular + sage: Q. = R.quotient([x^5, y^4]) + sage: R.hom([u, v], Q).inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q.cover().inverse() # needs sage.libs.singular + sage: Q.cover().inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1821,12 +1831,13 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): You can give a map of the base ring:: + sage: # needs sage.rings.number_field sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: cc = K.hom([-i]) # needs sage.rings.number_field - sage: R. = K[] # needs sage.rings.number_field - sage: z = 1 + i*t + (3+4*i)*t^2 # needs sage.rings.number_field - sage: z._im_gens_(R, [t^2], base_map=cc) # needs sage.rings.number_field + 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) (-4*i + 3)*t^4 - i*t^2 + 1 The base map's codomain is extended to the whole codomain:: @@ -1909,21 +1920,22 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: + sage: # needs sage.rings.number_field sage: R. = ZZ[] - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: cc = K.hom([-i]) # needs sage.rings.number_field - sage: S. = K[] # needs sage.rings.number_field - sage: phi = S.hom([y^2], base_map=cc) # needs sage.rings.number_field - sage: phi # needs sage.rings.number_field + sage: K. = NumberField(x^2 + 1) + sage: cc = K.hom([-i]) + sage: S. = K[] + sage: phi = S.hom([y^2], base_map=cc) + sage: phi Ring endomorphism of Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 Defn: y |--> y^2 with map of base ring - sage: phi(y) # needs sage.rings.number_field + sage: phi(y) y^2 - sage: phi(i*y) # needs sage.rings.number_field + sage: phi(i*y) -i*y^2 - sage: phi.base_map() # needs sage.rings.number_field + sage: phi.base_map() Composite map: From: Number Field in i with defining polynomial x^2 + 1 To: Univariate Polynomial Ring in y over Number Field in i @@ -1985,17 +1997,18 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A single variate quotient over `\QQ`:: + sage: # needs sage.libs.pari sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) # needs sage.libs.pari - sage: f1 = R.hom([a]) # needs sage.libs.pari - sage: f2 = R.hom([a + a^2 + a + 1]) # needs sage.libs.pari - sage: f1 == f2 # needs sage.libs.pari + 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 True - sage: f1 == R.hom([a^2]) # needs sage.libs.pari + sage: f1 == R.hom([a^2]) False - sage: f1(x^3 + x) # needs sage.libs.pari + sage: f1(x^3 + x) a + 1 - sage: f2(x^3 + x) # needs sage.libs.pari + sage: f2(x^3 + x) a + 1 TESTS:: @@ -2013,7 +2026,6 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A multivariate quotient over a finite field:: - sage: # needs sage.rings.finite_rings sage: R. = GF(7)[] sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) sage: f1 = R.hom([a, b]) @@ -2238,13 +2250,14 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): EXAMPLES:: + sage: # needs sage.modules sage: R. = QQ[] sage: S. = QQ[] sage: f = R.hom([2*z, 3*z], S) - sage: MR = MatrixSpace(R, 2) # needs sage.modules - sage: MS = MatrixSpace(S, 2) # needs sage.modules - sage: g = MR.hom(f, MS) # needs sage.modules - sage: g.underlying_map() == f # needs sage.modules + sage: MR = MatrixSpace(R, 2) + sage: MS = MatrixSpace(S, 2) + sage: g = MR.hom(f, MS) + sage: g.underlying_map() == f True """ return self._underlying @@ -2317,15 +2330,16 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A multivariate polynomial ring over a single variate quotient over `\QQ`:: + sage: # needs sage.libs.pari sage.libs.singular sage.modules sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) # needs sage.libs.pari sage.modules - sage: f1 = R.hom([a]) # needs sage.libs.pari sage.libs.singular sage.modules - sage: f2 = R.hom([a + a^2 + a + 1]) # needs sage.libs.pari sage.libs.singular sage.modules + 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'] # needs sage.libs.pari sage.libs.singular sage.modules - sage: f1P = PR.hom(f1,PQ) # needs sage.libs.pari sage.libs.singular sage.modules - sage: f2P = PR.hom(f2,PQ) # needs sage.libs.pari sage.libs.singular sage.modules - sage: f1P == f2P # needs sage.libs.pari sage.libs.singular sage.modules + sage: PQ = Q['s','t'] + sage: f1P = PR.hom(f1,PQ) + sage: f2P = PR.hom(f2,PQ) + sage: f1P == f2P True TESTS:: @@ -2343,21 +2357,21 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A matrix ring over a multivariate quotient over a finite field:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.modules 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) # needs sage.modules - sage: MQ = MatrixSpace(Q, 2) # needs sage.modules - sage: f1M = MR.hom(f1, MQ) # needs sage.modules - sage: f2M = MR.hom(f2, MQ) # needs sage.modules - sage: f1M == f2M # needs sage.modules + 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 True TESTS:: - sage: f1M == loads(dumps(f1M)) # needs sage.modules sage.rings.finite_rings + sage: f1M == loads(dumps(f1M)) # needs sage.modules True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2380,7 +2394,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: f = R1.hom([x + y, x - y]) sage: R2 = MatrixSpace(FractionField(R1)['t'], 2) # needs sage.modules sage: g = R2.hom(f, R2) # needs sage.modules - sage: g #indirect doctest # needs sage.modules + sage: g # indirect doctest # needs 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 diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 3e65e05f6af..fe7ca905fc7 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -160,19 +160,19 @@ Coercion from symbolic ring:: - sage: x,y = var('x,y') # needs sage.symbolic + sage: # needs sage.symbolic + sage: x,y = var('x,y') sage: S = PowerSeriesRing(GF(11),2,'x,y'); S Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: type(x) # needs sage.symbolic + sage: type(x) - sage: type(S(x)) # needs sage.rings.finite_rings sage.symbolic + sage: type(S(x)) - - sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f # needs sage.rings.finite_rings sage.symbolic + sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f 5 - x^2 + 4*x*y + y^2 + O(x, y)^3 - sage: f.parent() # needs sage.rings.finite_rings sage.symbolic + sage: f.parent() Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: f.parent() == S # needs sage.rings.finite_rings sage.symbolic + sage: f.parent() == S True The implementation of the multivariate power series ring uses a combination @@ -391,7 +391,6 @@ def _repr_(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R. = PowerSeriesRing(GF(17)) sage: R #indirect doctest Multivariate Power Series Ring in x, y over Finite Field of size 17 @@ -710,14 +709,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): You must either give a base map or there must be a coercion from the base ring to the codomain:: + sage: # needs sage.rings.number_field sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) # needs sage.rings.number_field - sage: Q8. = CyclotomicField(8) # needs sage.rings.number_field - sage: X. = PowerSeriesRing(Q8) # needs sage.rings.number_field - sage: M. = PowerSeriesRing(K) # needs sage.rings.number_field - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion # needs sage.rings.number_field + 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 False - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) # needs sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) True """ try: diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index f1122ae27eb..8be86e21b89 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -275,7 +275,7 @@ class MPowerSeries(PowerSeries): sage: S.random_element(4) # random -2*t + t^2 - 12*s^3 + O(s, t)^4 - sage: T.random_element(10) # random # needs sage.rings.finite_rings + sage: T.random_element(10) # random # needs sage.rings.finite_rings -t1^2*t3^2*t4^2 + t1^5*t3^3*t4 + O(t0, t1, t2, t3, t4)^10 @@ -460,13 +460,14 @@ def __call__(self, *x, **kwds): Since :trac:`26105` you can specify a map on the base ring:: + sage: # needs sage.rings.number_field sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field - sage: cc = K.hom([-i]) # needs sage.rings.number_field - sage: R. = PowerSeriesRing(K) # needs sage.rings.number_field - sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f # needs sage.rings.number_field + 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 s^2 + i*s*t + (4*i + 3)*s^3 + O(s, t)^4 - sage: f(t, s, base_map=cc) # needs sage.rings.number_field + sage: f(t, s, base_map=cc) (-i)*s*t + t^2 + (-4*i + 3)*t^3 + O(s, t)^4 """ if len(x) != self.parent().ngens(): @@ -568,7 +569,6 @@ def _value(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R. = PowerSeriesRing(GF(5)); R Multivariate Power Series Ring in a, b, c over Finite Field of size 5 @@ -605,7 +605,6 @@ def _latex_(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: M = PowerSeriesRing(GF(5),3,'t'); M Multivariate Power Series Ring in t0, t1, t2 over Finite Field of size 5 sage: t = M.gens() @@ -712,7 +711,6 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R. = PowerSeriesRing(GF(5)); R Multivariate Power Series Ring in a, b, c over Finite Field of size 5 sage: f = a + b + c + a^2*c @@ -724,7 +722,6 @@ def _richcmp_(self, other, op): Ordering is determined by underlying polynomial ring:: - sage: # needs sage.rings.finite_rings sage: a > b True sage: a > a^2 @@ -896,27 +893,25 @@ def quo_rem(self, other, precision=None): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PowerSeriesRing(ZZ) sage: f = 1 + a + b - a*b + R.O(3) sage: g = 1 + 2*a - 3*a*b + R.O(3) - sage: q, r = f.quo_rem(g); q, r # needs sage.libs.singular + 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 # needs sage.libs.singular + sage: f == q*g + r True - - sage: q, r = (a*f).quo_rem(g); q, r # needs sage.libs.singular + 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 # needs sage.libs.singular + sage: a*f == q*g + r True - - sage: q, r = (a*f).quo_rem(a*g); q, r # needs sage.libs.singular + sage: q, r = (a*f).quo_rem(a*g); q, r (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^4) - sage: a*f == q*(a*g) + r # needs sage.libs.singular + sage: a*f == q*(a*g) + r True - - sage: q, r = (a*f).quo_rem(b*g); q, r # needs sage.libs.singular + sage: q, r = (a*f).quo_rem(b*g); q, r (a - 3*a^2 + O(a, b, c)^3, a + a^2 + O(a, b, c)^4) - sage: a*f == q*(b*g) + r # needs sage.libs.singular + sage: a*f == q*(b*g) + r True Trying to divide two polynomials, we run into the issue that @@ -925,57 +920,54 @@ 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) # needs sage.libs.singular + sage: # needs sage.libs.singular + 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 + a*b).quo_rem(b + c) # needs sage.libs.singular + sage: (1 + a^3 + a*b).quo_rem(b + c) (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) # needs sage.libs.singular + sage: (1 + a^3 + a*b).quo_rem(b + c, precision=17) (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) # needs sage.libs.singular + sage: (a^2 + b^2 + c^2).quo_rem(a + b + c) (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)) # needs sage.libs.singular + 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, 0) - - sage: (a^2 + b^2 + c^2).quo_rem(a/(1+a+b+c)) # needs sage.libs.singular + sage: (a^2 + b^2 + c^2).quo_rem(a/(1+a+b+c)) (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) # needs sage.libs.singular + sage: (1 + a + a^15).quo_rem(a^2) (0 + O(a, b, c)^10, 1 + a + O(a, b, c)^12) - sage: (1 + a + a^15).quo_rem(a^2, precision=15) # needs sage.libs.singular + sage: (1 + a + a^15).quo_rem(a^2, precision=15) (0 + O(a, b, c)^13, 1 + a + O(a, b, c)^15) - sage: (1 + a + a^15).quo_rem(a^2, precision=16) # needs sage.libs.singular + sage: (1 + a + a^15).quo_rem(a^2, precision=16) (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) # needs sage.libs.singular + sage: # needs sage.libs.singular + sage: (1 + a + b).quo_rem(b + c) (1 + O(a, b, c)^11, 1 + a - c + O(a, b, c)^12) - sage: (1 + b + c).quo_rem(c + a) # needs sage.libs.singular + sage: (1 + b + c).quo_rem(c + a) (0 + O(a, b, c)^11, 1 + b + c + O(a, b, c)^12) - sage: (1 + c + a).quo_rem(a + b) # needs sage.libs.singular + sage: (1 + c + a).quo_rem(a + b) (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()) # needs 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)) # needs 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) # needs sage.libs.singular (a + b + O(a, b, c)^12, 0 + O(a, b, c)^12) sage: R. = PowerSeriesRing(QQ) @@ -1164,7 +1156,6 @@ def variables(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: T = PowerSeriesRing(GF(3),5,'t'); T Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite Field of size 3 @@ -1905,13 +1896,13 @@ def exp(self, prec=infinity): sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(3) - sage: exp(f) # needs sage.symbolic + sage: exp(f) 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 - sage: f.exp() # needs sage.symbolic + 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) # needs sage.symbolic + sage: f.exp(prec=2) 1 + a + b + O(a, b)^2 - sage: log(exp(f)) - f # needs sage.symbolic + sage: log(exp(f)) - f 0 + O(a, b)^3 If the power series has a constant coefficient `c` and @@ -1920,7 +1911,7 @@ def exp(self, prec=infinity): are not yet implemented and therefore such cases raise an error:: sage: g = 2 + f - sage: exp(g) # needs sage.symbolic + sage: exp(g) Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and @@ -1938,17 +1929,17 @@ def exp(self, prec=infinity): sage: T.default_prec() 12 - sage: exp(a) # needs sage.symbolic + sage: exp(a) 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) # needs sage.symbolic + 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)) # needs sage.symbolic + sage: exp(a + T.O(5)) 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)) # needs sage.symbolic + sage: exp(a^2 + T.O(5)) 1 + a^2 + 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1997,11 +1988,11 @@ def log(self, prec=infinity): sage: T. = PowerSeriesRing(ZZ, 2) sage: f = 1 + a + b + a*b + T.O(5) - sage: f.log() # needs sage.symbolic + 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 - sage: log(f) # needs sage.symbolic + sage: log(f) 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 - sage: exp(log(f)) - f # needs sage.symbolic + sage: exp(log(f)) - f 0 + O(a, b)^5 If the power series has a constant coefficient `c` and @@ -2010,7 +2001,7 @@ def log(self, prec=infinity): are not yet implemented and therefore such cases raise an error:: sage: g = 2 + f - sage: log(g) # needs sage.symbolic + sage: log(g) Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for -: 'Symbolic Ring' and 'Power @@ -2028,15 +2019,15 @@ def log(self, prec=infinity): TESTS:: - sage: (1+a).log(prec=10).exp() # needs sage.symbolic + sage: (1+a).log(prec=10).exp() 1 + a + O(a, b)^10 - sage: a.exp(prec=10).log() # needs sage.symbolic + sage: a.exp(prec=10).log() a + O(a, b)^10 - sage: log(1+a) # needs sage.symbolic + sage: log(1+a) a - 1/2*a^2 + 1/3*a^3 - 1/4*a^4 + 1/5*a^5 - 1/6*a^6 + 1/7*a^7 - 1/8*a^8 + 1/9*a^9 - 1/10*a^10 + 1/11*a^11 + O(a, b)^12 - sage: -log(1-a+T.O(5)) # needs sage.symbolic + sage: -log(1-a+T.O(5)) a + 1/2*a^2 + 1/3*a^3 + 1/4*a^4 + O(a, b)^5 sage: a.log(prec=10) Traceback (most recent call last): diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 27e33ad5be0..a5c56f7f39d 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -2942,16 +2942,16 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: K. = QuadraticField(2) - sage: SR(a) # indirect doctest # needs sage.symbolic + sage: SR(a) # indirect doctest # needs sage.symbolic sqrt(2) - sage: SR(3*a-5) # indirect doctest # needs sage.symbolic + sage: SR(3*a-5) # indirect doctest # needs sage.symbolic 3*sqrt(2) - 5 sage: K. = QuadraticField(2, embedding=-1.4) - sage: SR(a) # indirect doctest # needs sage.symbolic + sage: SR(a) # indirect doctest # needs sage.symbolic -sqrt(2) sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) - sage: SR(a) # indirect doctest # needs sage.symbolic + sage: SR(a) # indirect doctest # needs sage.symbolic Traceback (most recent call last): ... TypeError: an embedding into RR or CC must be specified @@ -2959,7 +2959,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Now a more complicated example:: sage: K. = NumberField(x^3 + x - 1, embedding=0.68) - sage: b = SR(a); b # indirect doctest # needs sage.symbolic + sage: b = SR(a); b # indirect doctest # needs sage.symbolic (1/18*sqrt(31)*sqrt(3) + 1/2)^(1/3) - 1/3/(1/18*sqrt(31)*sqrt(3) + 1/2)^(1/3) sage: (b^3 + b - 1).canonicalize_radical() # needs sage.symbolic 0 @@ -2974,7 +2974,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Special case for cyclotomic fields:: sage: K. = CyclotomicField(19) - sage: SR(zeta) # indirect doctest # needs sage.symbolic + sage: SR(zeta) # indirect doctest # needs sage.symbolic e^(2/19*I*pi) sage: CC(zeta) 0.945817241700635 + 0.324699469204683*I diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index 27b6f577f16..f4f631e2b46 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -220,7 +220,7 @@ def _im_gens_(self, codomain, im_gens, base_map=None): sage: R. = PolynomialRing(QQbar, 2) # needs sage.rings.number_field sage: f = R.hom([y, x], R) # needs sage.rings.number_field - sage: f(x^2 + 3*y^5) # indirect doctest # needs sage.rings.number_field + sage: f(x^2 + 3*y^5) # indirect doctest # needs sage.rings.number_field 3*x^5 + y^2 You can specify a map on the base ring:: diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 22c92ba44d6..7a4519bf823 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -229,7 +229,7 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): If a list of tuples is provided, those form the parts:: - sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest # needs sage.libs.singular + sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest # needs sage.libs.singular [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -396,7 +396,7 @@ def __init__(self, parts, ring, immutable=False, cr=False, cr_str=None): sage: P. = PolynomialRing(GF(127), 4) sage: I = sage.rings.ideal.Katsura(P) # needs sage.rings.finite_rings - sage: Sequence([I.gens()], I.ring()) # indirect doctest # needs sage.rings.finite_rings + sage: Sequence([I.gens()], I.ring()) # indirect doctest # needs sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] @@ -1276,13 +1276,14 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc If the input system is detected to be inconsistent then ``[1]`` is returned, and the list of reductors is empty:: - sage: R. = BooleanPolynomialRing() # needs sage.rings.polynomial.pbori - sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # needs sage.rings.polynomial.pbori - sage: S.eliminate_linear_variables() # needs sage.rings.polynomial.pbori + sage: # needs sage.rings.polynomial.pbori + sage: R. = BooleanPolynomialRing() + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) + sage: S.eliminate_linear_variables() [1] - sage: R. = BooleanPolynomialRing() # needs sage.rings.polynomial.pbori - sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # needs sage.rings.polynomial.pbori - sage: S.eliminate_linear_variables(return_reductors=True) # needs sage.rings.polynomial.pbori + sage: R. = BooleanPolynomialRing() + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) + sage: S.eliminate_linear_variables(return_reductors=True) ([1], []) @@ -1306,13 +1307,14 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc We test a case which would increase the degree with ``polybori=True``:: - sage: B. = BooleanPolynomialRing() # needs sage.rings.polynomial.pbori - sage: f = a*d + a + b*d + c*d + 1 # needs sage.rings.polynomial.pbori - sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables() # needs sage.rings.polynomial.pbori + sage: # needs sage.rings.polynomial.pbori + sage: B. = BooleanPolynomialRing() + sage: f = a*d + a + b*d + c*d + 1 + sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables() [a*d + a + b*d + c*d + 1, a + b*c + c + d + 1] - sage: B. = BooleanPolynomialRing() # needs sage.rings.polynomial.pbori - sage: f = a*d + a + b*d + c*d + 1 # needs sage.rings.polynomial.pbori - sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables(use_polybori=True) # needs sage.rings.polynomial.pbori + sage: B. = BooleanPolynomialRing() + sage: f = a*d + a + b*d + c*d + 1 + sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables(use_polybori=True) [b*c*d + b*c + b*d + c + d] .. NOTE:: diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 4d4b9dd10f5..7f9f8dff42e 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -9833,13 +9833,13 @@ cdef class Polynomial(CommutativePolynomial): sage: # needs sage.libs.pari sage: R. = ZZ[] - sage: (2*x).is_squarefree() # needs sage.libs.pari + sage: (2*x).is_squarefree() True - sage: (4*x).is_squarefree() # needs sage.libs.pari + sage: (4*x).is_squarefree() False - sage: (2*x^2).is_squarefree() # needs sage.libs.pari + sage: (2*x^2).is_squarefree() False - sage: R(0).is_squarefree() # needs sage.libs.pari + sage: R(0).is_squarefree() False sage: S. = QQ[] diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx index 57468e3510f..add6792f99c 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx @@ -553,7 +553,7 @@ def small_roots(self, X=None, beta=1.0, epsilon=None, **kwds): sage: from sage.misc.verbose import set_verbose sage: set_verbose(2) - sage: d = f.small_roots(X=2^hidden-1, beta=0.5)[0] # time random # needs sage.symbolic + sage: d = f.small_roots(X=2^hidden-1, beta=0.5)[0] # time random # needs sage.symbolic verbose 2 () m = 4 verbose 2 () t = 4 verbose 2 () X = 1298074214633706907132624082305023 diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index 07d5e0cb837..9d31364e7e9 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -1458,7 +1458,7 @@ def S_class_group(self, S, proof=True): `x^2 + 31` from 12 to 2, i.e. we lose a generator of order 6 (this was fixed in :trac:`14489`):: - sage: S.S_class_group([K.ideal(a)]) # representation varies # not tested, needs sage.rings.number_field + sage: S.S_class_group([K.ideal(a)]) # representation varies # not tested, needs sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index 2d1d04a9e73..ecccc51519e 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -578,7 +578,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 - sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL # needs sage.libs.ntl + sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL # needs sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); TestSuite(ZxFLINT).run(); ZxFLINT Univariate Polynomial Ring in x over Integer Ring diff --git a/src/sage/rings/polynomial/symmetric_ideal.py b/src/sage/rings/polynomial/symmetric_ideal.py index 84138cd8975..e13abffd50c 100644 --- a/src/sage/rings/polynomial/symmetric_ideal.py +++ b/src/sage/rings/polynomial/symmetric_ideal.py @@ -242,7 +242,7 @@ def _contains_(self, p): sage: I # needs sage.combinat Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of Infinite polynomial ring in x over Rational Field - sage: x[2]^2 + x[3] in I # indirect doctest # needs sage.combinat + sage: x[2]^2 + x[3] in I # indirect doctest # needs sage.combinat True """ try: diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index a3321cf1bb2..dc306c2ee39 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -932,7 +932,7 @@ def sortkey_matrix(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') # needs sage.rings.number_field - sage: y > x^2 # indirect doctest # needs sage.rings.number_field + sage: y > x^2 # indirect doctest # needs sage.rings.number_field True sage: y > x^3 # needs sage.rings.number_field False @@ -952,7 +952,7 @@ def sortkey_lex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='lex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field True sage: x > 1 # needs sage.rings.number_field True @@ -971,7 +971,7 @@ def sortkey_invlex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='invlex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field False sage: x > 1 # needs sage.rings.number_field True @@ -990,7 +990,7 @@ def sortkey_deglex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='deglex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field False sage: x > 1 # needs sage.rings.number_field True @@ -1010,7 +1010,7 @@ def sortkey_degrevlex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='degrevlex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field False sage: x > 1 # needs sage.rings.number_field True @@ -1032,7 +1032,7 @@ def sortkey_neglex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='neglex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field False sage: x > 1 # needs sage.rings.number_field False @@ -1051,7 +1051,7 @@ def sortkey_negdegrevlex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='negdegrevlex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field True sage: x > 1 # needs sage.rings.number_field False @@ -1071,7 +1071,7 @@ def sortkey_negdeglex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='negdeglex') # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field True sage: x > 1 # needs sage.rings.number_field False @@ -1090,7 +1090,7 @@ def sortkey_degneglex(self, f): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 3, order='degneglex') # needs sage.rings.number_field - sage: x*y > y*z # indirect doctest # needs sage.rings.number_field + sage: x*y > y*z # indirect doctest # needs sage.rings.number_field False sage: x*y > x # needs sage.rings.number_field True @@ -1110,7 +1110,7 @@ def sortkey_wdegrevlex(self, f): sage: t = TermOrder('wdegrevlex',(3,2)) sage: P. = PolynomialRing(QQbar, 2, order=t) # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field False sage: x^2 > y^3 # needs sage.rings.number_field True @@ -1131,7 +1131,7 @@ def sortkey_wdeglex(self, f): sage: t = TermOrder('wdeglex',(3,2)) sage: P. = PolynomialRing(QQbar, 2, order=t) # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field False sage: x > y # needs sage.rings.number_field True @@ -1151,7 +1151,7 @@ def sortkey_negwdeglex(self, f): sage: t = TermOrder('negwdeglex',(3,2)) sage: P. = PolynomialRing(QQbar, 2, order=t) # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field True sage: x^2 > y^3 # needs sage.rings.number_field True @@ -1171,7 +1171,7 @@ def sortkey_negwdegrevlex(self, f): sage: t = TermOrder('negwdegrevlex',(3,2)) sage: P. = PolynomialRing(QQbar, 2, order=t) # needs sage.rings.number_field - sage: x > y^2 # indirect doctest # needs sage.rings.number_field + sage: x > y^2 # indirect doctest # needs sage.rings.number_field True sage: x^2 > y^3 # needs sage.rings.number_field True @@ -1192,7 +1192,7 @@ def sortkey_block(self, f): sage: P. = PolynomialRing(QQbar, 6, # needs sage.rings.number_field ....: order='degrevlex(3),degrevlex(3)') - sage: a > c^4 # indirect doctest # needs sage.rings.number_field + sage: a > c^4 # indirect doctest # needs sage.rings.number_field False sage: a > e^4 # needs sage.rings.number_field True @@ -1227,7 +1227,7 @@ def greater_tuple_matrix(self,f,g): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') # needs sage.rings.number_field - sage: y > x^2 # indirect doctest # needs sage.rings.number_field + sage: y > x^2 # indirect doctest # needs sage.rings.number_field True sage: y > x^3 # needs sage.rings.number_field False @@ -1256,7 +1256,7 @@ def greater_tuple_lex(self,f,g): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 3, order='lex') # needs sage.rings.number_field - sage: f = x + y^2; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y^2; f.lm() # indirect doctest # needs sage.rings.number_field x This method is called by the lm/lc/lt methods of @@ -1278,7 +1278,7 @@ def greater_tuple_invlex(self,f,g): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 3, order='invlex') # needs sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field y sage: f = y + x^2; f.lm() # needs sage.rings.number_field y @@ -1302,7 +1302,7 @@ def greater_tuple_deglex(self,f,g): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 3, order='deglex') # needs sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field x sage: f = x + y^2*z; f.lm() # needs sage.rings.number_field y^2*z @@ -1328,7 +1328,7 @@ def greater_tuple_degrevlex(self,f,g): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 3, order='degrevlex') # needs sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field x sage: f = x + y^2*z; f.lm() # needs sage.rings.number_field y^2*z @@ -1412,7 +1412,7 @@ def greater_tuple_degneglex(self,f,g): EXAMPLES:: sage: P. = PolynomialRing(QQbar, 3, order='degneglex') # needs sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field y sage: f = x + y^2*z; f.lm() # needs sage.rings.number_field y^2*z @@ -1442,7 +1442,7 @@ def greater_tuple_neglex(self,f,g): sage: P. = PolynomialRing(QQbar, 6, # needs sage.rings.number_field ....: order='degrevlex(3),degrevlex(3)') - sage: f = a + c^4; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = a + c^4; f.lm() # indirect doctest # needs sage.rings.number_field c^4 sage: g = a + e^4; g.lm() # needs sage.rings.number_field a @@ -1464,7 +1464,7 @@ def greater_tuple_wdeglex(self,f,g): sage: t = TermOrder('wdeglex',(1,2,3)) sage: P. = PolynomialRing(QQbar, 3, order=t) # needs sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field y sage: f = x*y + z; f.lm() # needs sage.rings.number_field x*y @@ -1491,7 +1491,7 @@ def greater_tuple_wdegrevlex(self,f,g): sage: t = TermOrder('wdegrevlex',(1,2,3)) sage: P. = PolynomialRing(QQbar, 3, order=t) # needs sage.rings.number_field - sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # needs sage.rings.number_field y sage: f = x + y^2*z; f.lm() # needs sage.rings.number_field y^2*z @@ -1581,7 +1581,7 @@ def greater_tuple_block(self, f,g): sage: P. = PolynomialRing(QQbar, 6, # needs sage.rings.number_field ....: order='degrevlex(3),degrevlex(3)') - sage: f = a + c^4; f.lm() # indirect doctest # needs sage.rings.number_field + sage: f = a + c^4; f.lm() # indirect doctest # needs sage.rings.number_field c^4 sage: g = a + e^4; g.lm() # needs sage.rings.number_field a diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index e3c4305c823..c2c1436d388 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -158,7 +158,6 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R. = GF(11)[[]] sage: bool(1 + t + O(t^18)) True @@ -268,7 +267,6 @@ cdef class PowerSeries_poly(PowerSeries): Arguments beyond the first can refer to the base ring:: - sage: # needs sage.rings.finite_rings sage: P. = GF(5)[] sage: Q. = P[[]] sage: h = (1 - x*y)^-1 + O(y^7); h @@ -278,9 +276,9 @@ cdef class PowerSeries_poly(PowerSeries): These secondary values can also be specified using keywords:: - sage: h(y=y^2, x=3) # needs sage.rings.finite_rings + sage: h(y=y^2, x=3) 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) # needs sage.rings.finite_rings + sage: h(y^2, x=3) 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) """ P = self.parent() @@ -376,29 +374,27 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R. = GF(7)[[]] sage: f = 3 + 6*t^3 + O(t^5) sage: f._unsafe_mutate(0, 5) sage: f 5 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(2, 1) ; f + sage: f._unsafe_mutate(2, 1); f 5 + t^2 + 6*t^3 + O(t^5) - Mutating can even bump up the precision:: - sage: # needs sage.rings.finite_rings - sage: f._unsafe_mutate(6, 1) ; f + sage: f._unsafe_mutate(6, 1); f 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 t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(1, 0) ; f + sage: f._unsafe_mutate(1, 0); f t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(11,0) ; f + sage: f._unsafe_mutate(11,0); f t^2 + 6*t^3 + t^6 + O(t^12) - sage: g = t + O(t^7) # needs sage.rings.finite_rings - sage: g._unsafe_mutate(1,0) ; g # needs sage.rings.finite_rings + sage: g = t + O(t^7) + sage: g._unsafe_mutate(1,0); g O(t^7) """ self.__f._unsafe_mutate(i, value) @@ -438,7 +434,7 @@ cdef class PowerSeries_poly(PowerSeries): 32 - 80*t + 80*t^2 - 40*t^3 + 10*t^4 - t^5 sage: f[:4] 32 - 80*t + 80*t^2 - 40*t^3 - sage: f = 1 + t^3 - 4*t^4 + O(t^7) ; f + sage: f = 1 + t^3 - 4*t^4 + O(t^7); f 1 + t^3 - 4*t^4 + O(t^7) sage: f[:4] 1 + t^3 + O(t^7) @@ -895,7 +891,7 @@ cdef class PowerSeries_poly(PowerSeries): sage: t = PowerSeriesRing(QQ,'t').gen() sage: f = t + 5*t^2 + 21*t^3 - sage: g = f.integral() ; g + sage: g = f.integral(); g 1/2*t^2 + 5/3*t^3 + 21/4*t^4 sage: g.parent() Power Series Ring in t over Rational Field @@ -1195,20 +1191,21 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: + sage: # needs sage.symbolic sage: R. = PowerSeriesRing(QQ) 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) # needs sage.symbolic + sage: SR(s) 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + Order(x^10) - sage: SR(s).is_terminating_series() # needs sage.symbolic + sage: SR(s).is_terminating_series() False - sage: SR(s).variables() # needs sage.symbolic + sage: SR(s).variables() (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) # needs sage.symbolic + sage: SR(s) 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: _.is_terminating_series() # needs sage.symbolic + sage: _.is_terminating_series() True TESTS: diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index 034adde8f32..8bf2d900f45 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -520,7 +520,6 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, commutative ring, but also a complete discrete valuation ring (CDVR). The appropriate (sub)category is automatically set in this case:: - sage: # needs sage.rings.finite_rings sage: k = GF(11) sage: R. = k[[]] sage: R.category() @@ -617,7 +616,6 @@ def _repr_(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R = GF(17)[['y']] sage: R Power Series Ring in y over Finite Field of size 17 @@ -664,7 +662,6 @@ def _latex_(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R = GF(17)[['y']] sage: latex(R) # indirect doctest \Bold{F}_{17}[[y]] @@ -683,7 +680,6 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: A = GF(17)[['x']] sage: A.has_coerce_map_from(ZZ) # indirect doctest True diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 3579ac38953..52c4cf782d8 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -483,7 +483,6 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: A. = PowerSeriesRing(GF(5)) sage: x = t + t^2 + O(t^5) sage: x.lift_to_precision(10) @@ -846,23 +845,23 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: # needs sage.rings.complex_double + sage: # needs sage.rings.complex_double sage.symbolic sage: R. = CDF[[]] - sage: f = CDF(pi)^2 + m^3 + CDF(e)*m^4 + O(m^10); f # abs tol 5e-16 # needs sage.symbolic + sage: f = CDF(pi)^2 + m^3 + CDF(e)*m^4 + O(m^10); f # abs tol 5e-16 9.869604401089358 + 0.0*m + 0.0*m^2 + 1.0*m^3 + 2.718281828459045*m^4 + O(m^10) - sage: f[-5] # needs sage.symbolic + sage: f[-5] 0.0 - sage: f[0] # needs sage.symbolic + sage: f[0] 9.869604401089358 - sage: f[4] # abs tol 5e-16 # needs sage.symbolic + sage: f[4] # abs tol 5e-16 2.718281828459045 - sage: f[9] # needs sage.symbolic + sage: f[9] 0.0 - sage: f[10] # needs sage.symbolic + sage: f[10] Traceback (most recent call last): ... IndexError: coefficient not known - sage: f[1000] # needs sage.symbolic + sage: f[1000] Traceback (most recent call last): ... IndexError: coefficient not known @@ -1198,11 +1197,11 @@ cdef class PowerSeries(AlgebraElement): sage: # needs sage.libs.pari sage: R. = PowerSeriesRing(QQ, implementation='pari') - sage: f = exp(x) + O(x^7); f # needs sage.symbolic + sage: f = exp(x) + O(x^7); f 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) - sage: f << 2 # needs sage.symbolic + sage: f << 2 x^2 + x^3 + 1/2*x^4 + 1/6*x^5 + 1/24*x^6 + 1/120*x^7 + 1/720*x^8 + O(x^9) - sage: (f << 99) >> 99 # needs sage.symbolic + sage: (f << 99) >> 99 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) """ return self.shift(n) @@ -1217,14 +1216,14 @@ cdef class PowerSeries(AlgebraElement): sage: # needs sage.libs.pari sage: R. = PowerSeriesRing(QQ, implementation='pari') - sage: f = exp(x) + O(x^7) # needs sage.symbolic - sage: f >> 3 # needs sage.symbolic + sage: f = exp(x) + O(x^7) + sage: f >> 3 1/6 + 1/24*x + 1/120*x^2 + 1/720*x^3 + O(x^4) - sage: f >> 7 # needs sage.symbolic + sage: f >> 7 O(x^0) - sage: f >> 99 # needs sage.symbolic + sage: f >> 99 O(x^0) - sage: (f >> 99) << 99 # needs sage.symbolic + sage: (f >> 99) << 99 O(x^99) """ return self.shift(-n) @@ -1301,9 +1300,9 @@ cdef class PowerSeries(AlgebraElement): Tests other implementations:: - sage: R. = PowerSeriesRing(GF(11), implementation='pari') # needs sage.rings.finite_rings - sage: f = q - q^3 + O(q^10) # needs sage.rings.finite_rings - sage: f.map_coefficients(lambda c: c - 2) # needs sage.rings.finite_rings + sage: R. = PowerSeriesRing(GF(11), implementation='pari') + sage: f = q - q^3 + O(q^10) + sage: f.map_coefficients(lambda c: c - 2) 10*q + 8*q^3 + O(q^10) """ pol = self.polynomial() @@ -1768,7 +1767,6 @@ cdef class PowerSeries(AlgebraElement): Positive characteristic:: - sage: # needs sage.rings.finite_rings sage: R. = GF(3)[[]] sage: p = 1 + 2 * u^2 sage: p.nth_root(4) @@ -2792,12 +2790,12 @@ cdef class PowerSeries(AlgebraElement): sage: k. = QQ[[]] sage: f = 1 + 17*w + 15*w^3 + O(w^5) - sage: pari(f) # indirect doctest # needs sage.libs.pari + sage: pari(f) # indirect doctest # needs sage.libs.pari 1 + 17*w + 15*w^3 + O(w^5) - sage: pari(1 - 19*w + w^5) # indirect doctest # needs sage.libs.pari + sage: pari(1 - 19*w + w^5) # indirect doctest # needs sage.libs.pari w^5 - 19*w + 1 sage: R. = Zmod(6)[[]] - sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest # needs sage.libs.pari + sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest # needs sage.libs.pari Mod(1, 6) + Mod(1, 6)*x + Mod(2, 6)*x^3 + O(x^8) TESTS:: diff --git a/src/sage/rings/puiseux_series_ring_element.pyx b/src/sage/rings/puiseux_series_ring_element.pyx index 9465e20ba1b..503d11ee975 100644 --- a/src/sage/rings/puiseux_series_ring_element.pyx +++ b/src/sage/rings/puiseux_series_ring_element.pyx @@ -218,13 +218,14 @@ cdef class PuiseuxSeries(AlgebraElement): """ EXAMPLES:: + sage: # needs sage.rings.number_field sage: R. = PuiseuxSeriesRing(ZZ) sage: p = x^(1/3) + x**3 - sage: t = p._im_gens_(QQbar, [2]) # needs sage.rings.number_field - sage: t in QQbar # needs sage.rings.number_field + sage: t = p._im_gens_(QQbar, [2]) + sage: t in QQbar True - sage: f = R.hom([QQbar(2)], check=False) # needs sage.rings.number_field - sage: t == f(p) # needs sage.rings.number_field + sage: f = R.hom([QQbar(2)], check=False) + sage: t == f(p) True """ return self(codomain(im_gens[0])) @@ -871,7 +872,6 @@ cdef class PuiseuxSeries(AlgebraElement): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: P. = PolynomialRing(GF(5)) sage: R. = PuiseuxSeriesRing(P) sage: p = 3*y*x**(-2/3) + 2*y**2*x**(1/5); p @@ -945,7 +945,6 @@ cdef class PuiseuxSeries(AlgebraElement): EXAMPLES:: - sage: # needs sage.rings.finite_rings sage: R. = PuiseuxSeriesRing(GF(3)) sage: p = (x**(-1/3) + 2*x**3)**2; p x^(-2/3) + x^(8/3) + x^6 diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 7c3e6262448..4be1f45c1e2 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -109,23 +109,24 @@ We can convert from symbolic expressions:: - sage: QQbar(sqrt(-5)) # needs sage.symbolic + sage: # needs sage.symbolic + sage: QQbar(sqrt(-5)) 2.236067977499790?*I - sage: AA(sqrt(2) + sqrt(3)) # needs sage.symbolic + sage: AA(sqrt(2) + sqrt(3)) 3.146264369941973? sage: QQbar(I) I - sage: QQbar(I * golden_ratio) # needs sage.symbolic + sage: QQbar(I * golden_ratio) 1.618033988749895?*I - sage: AA(golden_ratio)^2 - AA(golden_ratio) # needs sage.symbolic + sage: AA(golden_ratio)^2 - AA(golden_ratio) 1 - sage: QQbar((-8)^(1/3)) # needs sage.symbolic + sage: QQbar((-8)^(1/3)) 1.000000000000000? + 1.732050807568878?*I - sage: AA((-8)^(1/3)) # needs sage.symbolic + sage: AA((-8)^(1/3)) -2 - sage: QQbar((-4)^(1/4)) # needs sage.symbolic + sage: QQbar((-4)^(1/4)) 1 + 1*I - sage: AA((-4)^(1/4)) # needs sage.symbolic + sage: AA((-4)^(1/4)) Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real @@ -385,24 +386,22 @@ sage: loads(dumps(QQbar.zeta(5))) == QQbar.zeta(5) True - sage: t = QQbar(sqrt(2)); type(t._descr) # needs sage.symbolic + sage: # needs sage.symbolic + sage: t = QQbar(sqrt(2)); type(t._descr) - sage: loads(dumps(t)) == QQbar(sqrt(2)) # needs sage.symbolic + sage: loads(dumps(t)) == QQbar(sqrt(2)) True - - sage: t.exactify(); type(t._descr) # needs sage.symbolic + sage: t.exactify(); type(t._descr) - sage: loads(dumps(t)) == QQbar(sqrt(2)) # needs sage.symbolic + sage: loads(dumps(t)) == QQbar(sqrt(2)) True - - sage: t = ~QQbar(sqrt(2)); type(t._descr) # needs sage.symbolic + sage: t = ~QQbar(sqrt(2)); type(t._descr) - sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) # needs sage.symbolic + sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) True - - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # needs sage.symbolic + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) - sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) # needs sage.symbolic + sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) True We can convert elements of ``QQbar`` and ``AA`` into the following @@ -1636,7 +1635,7 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: sqrt(2) in QQbar # indirect doctest # needs sage.symbolic + sage: sqrt(2) in QQbar # indirect doctest # needs sage.symbolic True sage: 22/7 in QQbar True @@ -3499,17 +3498,19 @@ def is_simple(self): sage: from sage.rings.qqbar import ANRational sage: ANRational(1/2).is_simple() True - sage: rt2 = AA(sqrt(2)) # needs sage.symbolic - sage: rt3 = AA(sqrt(3)) # needs sage.symbolic - sage: rt2b = rt3 + rt2 - rt3 # needs sage.symbolic - sage: rt2.exactify() # needs sage.symbolic - sage: rt2._descr.is_simple() # needs sage.symbolic + + sage: # needs sage.symbolic + sage: rt2 = AA(sqrt(2)) + sage: rt3 = AA(sqrt(3)) + sage: rt2b = rt3 + rt2 - rt3 + sage: rt2.exactify() + sage: rt2._descr.is_simple() True - sage: rt2b.exactify() # needs sage.symbolic - sage: rt2b._descr.is_simple() # needs sage.symbolic + sage: rt2b.exactify() + sage: rt2b._descr.is_simple() False - sage: rt2b.simplify() # needs sage.symbolic - sage: rt2b._descr.is_simple() # needs sage.symbolic + sage: rt2b.simplify() + sage: rt2b._descr.is_simple() True """ return False @@ -4046,11 +4047,13 @@ def __bool__(self): sage: a = QQbar(2).sqrt() - 16616132878186749607/11749380235262596085 sage: b = QQbar(2).sqrt() - 6882627592338442563/4866752642924153522 sage: c = QQbar(3).sqrt() - 142437039878091970439/82236063316189858921 - sage: d = (59/2)**(1000/7) # needs sage.symbolic - sage: e = (a + b + c) * (a + b - c) * (a - b) * (a - b - c) / d # needs sage.symbolic - sage: bool(e) # needs sage.symbolic + + sage: # needs sage.symbolic + sage: d = (59/2)**(1000/7) + sage: e = (a + b + c) * (a + b - c) * (a - b) * (a - b - c) / d + sage: bool(e) True - sage: bool(e.abs() < 2**-500) # needs sage.symbolic + sage: bool(e.abs() < 2**-500) True An identity between roots of unity:: @@ -4746,28 +4749,29 @@ def radical_expression(self): EXAMPLES:: - sage: AA(1/sqrt(5)).radical_expression() # needs sage.symbolic + sage: # needs sage.symbolic + sage: AA(1/sqrt(5)).radical_expression() sqrt(1/5) - sage: AA(sqrt(5 + sqrt(5))).radical_expression() # needs sage.symbolic + sage: AA(sqrt(5 + sqrt(5))).radical_expression() sqrt(sqrt(5) + 5) - sage: QQbar.zeta(5).radical_expression() # needs sage.symbolic + sage: QQbar.zeta(5).radical_expression() 1/4*sqrt(5) + 1/2*sqrt(-1/2*sqrt(5) - 5/2) - 1/4 sage: x = polygen(QQ, 'x') sage: a = (x^7 - x - 1).roots(AA, False)[0] - sage: a.radical_expression() # needs sage.symbolic + sage: a.radical_expression() 1.112775684278706? - sage: a.radical_expression().parent() == SR # needs sage.symbolic + sage: a.radical_expression().parent() == SR False sage: a = sorted((x^7-x-1).roots(QQbar, False), key=imag)[0] - sage: a.radical_expression() # needs sage.symbolic + sage: a.radical_expression() -0.3636235193291805? - 0.9525611952610331?*I - sage: QQbar.zeta(5).imag().radical_expression() # needs sage.symbolic + sage: QQbar.zeta(5).imag().radical_expression() 1/2*sqrt(1/2*sqrt(5) + 5/2) - sage: AA(5/3).radical_expression() # needs sage.symbolic + sage: AA(5/3).radical_expression() 5/3 - sage: AA(5/3).radical_expression().parent() == SR # needs sage.symbolic + sage: AA(5/3).radical_expression().parent() == SR True - sage: QQbar(0).radical_expression() # needs sage.symbolic + sage: QQbar(0).radical_expression() 0 TESTS: @@ -4946,9 +4950,9 @@ def _richcmp_(self, other, op): False sage: QQbar(2) == 2 True - sage: QQbar(2) == GF(7)(2) # needs sage.rings.finite_rings + sage: QQbar(2) == GF(7)(2) False - sage: GF(7)(2) in QQbar # needs sage.rings.finite_rings + sage: GF(7)(2) in QQbar False sage: QQbar.zeta(6) != QQbar(1/2 + I*sqrt(3)/2) # needs sage.symbolic @@ -4957,7 +4961,7 @@ def _richcmp_(self, other, op): True sage: QQbar(2) != 2 False - sage: QQbar(2) != GF(7)(2) # needs sage.rings.finite_rings + sage: QQbar(2) != GF(7)(2) True sage: QQbar.zeta(3).real() == -1/2 @@ -4977,22 +4981,22 @@ def _richcmp_(self, other, op): Check that :trac:`29220` is fixed:: - sage: a = AA(2**(1/2) - 2**(1/3)) # needs sage.symbolic + sage: # needs sage.symbolic + sage: a = AA(2**(1/2) - 2**(1/3)) sage: b = 808620184/5240825825 - sage: a < b # needs sage.symbolic + sage: a < b True - sage: a < b # needs sage.symbolic + sage: a < b True - - sage: a = AA(2^(1/3)) # needs sage.symbolic + sage: a = AA(2^(1/3)) sage: r = 3085094589/2448641198 - sage: a < r # needs sage.symbolic + sage: a < r False - sage: a > r # needs sage.symbolic + sage: a > r True - sage: a < r # needs sage.symbolic + sage: a < r False - sage: a > r # needs sage.symbolic + sage: a > r True """ if self is other: @@ -5132,15 +5136,17 @@ def _integer_(self, ZZ=None): Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real - sage: QQbar(sqrt(17))._integer_() # needs sage.symbolic + + sage: # needs sage.symbolic + sage: QQbar(sqrt(17))._integer_() Traceback (most recent call last): ... ValueError: Cannot coerce non-integral Algebraic Real 4.123105625617660? to Integer - sage: QQbar(sqrt(16))._integer_() # needs sage.symbolic + sage: QQbar(sqrt(16))._integer_() 4 - sage: v = QQbar(1 + I*sqrt(3))^5 + QQbar(16*sqrt(3)*I); v # needs sage.symbolic + sage: v = QQbar(1 + I*sqrt(3))^5 + QQbar(16*sqrt(3)*I); v 16.00000000000000? + 0.?e-17*I - sage: v._integer_() # needs sage.symbolic + sage: v._integer_() 16 """ return AA(self)._integer_(ZZ) @@ -5159,15 +5165,17 @@ def _rational_(self): Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real - sage: QQbar(sqrt(2))._rational_() # needs sage.symbolic + + sage: # needs sage.symbolic + sage: QQbar(sqrt(2))._rational_() Traceback (most recent call last): ... ValueError: Cannot coerce irrational Algebraic Real 1.414213562373095? to Rational - sage: v1 = QQbar(1/3 + I*sqrt(5))^7 # needs sage.symbolic - sage: v2 = QQbar((100336/729*golden_ratio - 50168/729)*I) # needs sage.symbolic - sage: v = v1 + v2; v # needs sage.symbolic + sage: v1 = QQbar(1/3 + I*sqrt(5))^7 + sage: v2 = QQbar((100336/729*golden_ratio - 50168/729)*I) + sage: v = v1 + v2; v -259.6909007773206? + 0.?e-15*I - sage: v._rational_() # needs sage.symbolic + sage: v._rational_() -567944/2187 """ return AA(self)._rational_() @@ -5525,14 +5533,12 @@ def _richcmp_(self, other, op): True sage: y < y False - - sage: z = x1 - x2 # needs sage.symbolic - sage: z == 0 # needs sage.symbolic + sage: z = x1 - x2 + sage: z == 0 True - - sage: a = x1 - x2 # needs sage.symbolic - sage: b = x1 - x2 # needs sage.symbolic - sage: a == b # needs sage.symbolic + sage: a = x1 - x2 + sage: b = x1 - x2 + sage: a == b True """ if self is other: @@ -8102,13 +8108,15 @@ def rational_argument(self, n): EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(3)) # needs sage.symbolic - sage: a.exactify() # needs sage.symbolic - sage: b = a._descr # needs sage.symbolic - sage: type(b) # needs sage.symbolic + sage: # needs sage.symbolic + sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(3)) + sage: a.exactify() + sage: b = a._descr + sage: type(b) - sage: b.rational_argument(a) is None # needs sage.symbolic + sage: b.rational_argument(a) is None True + sage: x = polygen(QQ) sage: a = (x^4 + 1).roots(QQbar, multiplicities=False)[0] sage: a.exactify() @@ -8415,7 +8423,7 @@ def __init__(self, left, right, op): EXAMPLES:: - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # indirect doctest # needs sage.symbolic + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # indirect doctest # needs sage.symbolic """ self._left = left diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index c796b24961b..d2c3d160518 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -182,15 +182,16 @@ def QuotientRing(R, I, names=None, **kwds): With polynomial rings (note that the variable name of the quotient ring can be specified as shown below):: + sage: # needs sage.libs.pari sage: P. = QQ[] - sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) # needs sage.libs.pari - sage: R # needs sage.libs.pari + 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() # needs sage.libs.pari + sage: R.gens(); R.gen() (xx,) xx - sage: for n in range(4): xx^n # needs sage.libs.pari + sage: for n in range(4): xx^n 1 xx -1 @@ -198,14 +199,15 @@ def QuotientRing(R, I, names=None, **kwds): :: + sage: # needs sage.libs.pari sage: P. = QQ[] - sage: S = QuotientRing(P, P.ideal(x^2 - 2)) # needs sage.libs.pari - sage: S # needs sage.libs.pari + sage: S = QuotientRing(P, P.ideal(x^2 - 2)) + sage: S Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 2 - sage: xbar = S.gen(); S.gen() # needs sage.libs.pari + sage: xbar = S.gen(); S.gen() xbar - sage: for n in range(3): xbar^n # needs sage.libs.pari + sage: for n in range(3): xbar^n 1 xbar 2 @@ -435,13 +437,14 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(1 + y^2) # needs sage.libs.singular - sage: T. = S.quo(a) # needs sage.libs.singular - sage: T # needs sage.libs.singular + sage: S. = R.quo(1 + y^2) + sage: T. = S.quo(a) + sage: T Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: T.gens() # needs sage.libs.singular + sage: T.gens() (0, d) """ Element = quotient_ring_element.QuotientRingElement @@ -516,10 +519,12 @@ def construction(self): sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: R.quotient_ring(I).construction() (QuotientFunctor, Univariate Polynomial Ring in x over Integer Ring) - sage: F. = FreeAlgebra(QQ, implementation='letterplace') # needs sage.combinat sage.libs.singular sage.modules - sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # needs sage.combinat sage.libs.singular sage.modules - sage: Q = F.quo(I) # needs sage.combinat sage.libs.singular sage.modules - sage: Q.construction() # needs sage.combinat sage.libs.singular sage.modules + + sage: # needs sage.combinat sage.libs.singular sage.modules + sage: F. = FreeAlgebra(QQ, implementation='letterplace') + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F + sage: Q = F.quo(I) + sage: Q.construction() (QuotientFunctor, Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) @@ -612,9 +617,10 @@ def is_commutative(self): In the next example, the generators apparently commute:: - sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # needs sage.combinat sage.libs.singular sage.modules - sage: R = F.quo(J) # needs sage.combinat sage.libs.singular sage.modules - sage: R.is_commutative() # needs sage.combinat sage.libs.singular sage.modules + sage: # needs sage.combinat sage.libs.singular sage.modules + sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F + sage: R = F.quo(J) + sage: R.is_commutative() True """ @@ -654,21 +660,22 @@ def cover(self): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ) sage: Q = R.quo((x^2, y^2)) - sage: pi = Q.cover() # needs sage.libs.singular - sage: pi(x^3 + y) # needs sage.libs.singular + sage: pi = Q.cover() + sage: pi(x^3 + y) ybar - sage: l = pi.lift(x + y^3) # needs sage.libs.singular - sage: l # needs sage.libs.singular + sage: l = pi.lift(x + y^3) + sage: l x - sage: l = pi.lift(); l # needs sage.libs.singular + sage: l = pi.lift(); l 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) # needs sage.libs.singular + sage: l(x + y^3) x """ try: @@ -688,23 +695,24 @@ def lifting_map(self): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: pi = S.cover(); pi # needs sage.libs.singular + sage: pi = S.cover(); pi 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 # needs sage.libs.singular + sage: L = S.lifting_map(); L 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) # needs sage.libs.singular + sage: L(S.0) x - sage: L(S.1) # needs sage.libs.singular + sage: L(S.1) y Note that some reduction may be applied so that the lift of a @@ -1036,13 +1044,14 @@ def _element_constructor_(self, x, coerce=True): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) # needs sage.libs.singular - sage: S.coerce(0) # needs sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) + sage: S.coerce(0) 0 - sage: S.coerce(2/3) # needs sage.libs.singular + sage: S.coerce(2/3) 2/3 - sage: S.coerce(a^2 - b) # needs sage.libs.singular + sage: S.coerce(a^2 - b) -b^2 - b sage: S.coerce(GF(7)(3)) Traceback (most recent call last): @@ -1180,17 +1189,18 @@ def ngens(self): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular - sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular - sage: T # needs sage.libs.singular + 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() # needs sage.libs.singular + sage: R.gens(); S.gens(); T.gens() (x, y) (a, b) (0, d) - sage: R.ngens(); S.ngens(); T.ngens() # needs sage.libs.singular + sage: R.ngens(); S.ngens(); T.ngens() 2 2 2 @@ -1209,19 +1219,20 @@ def gen(self, i=0): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # needs sage.libs.singular - sage: T. = QuotientRing(S, S.ideal(a)) # needs sage.libs.singular - sage: T # needs sage.libs.singular + 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) x y - sage: S.gen(0); S.gen(1) # needs sage.libs.singular + sage: S.gen(0); S.gen(1) a b - sage: T.gen(0); T.gen(1) # needs sage.libs.singular + sage: T.gen(0); T.gen(1) 0 d """ @@ -1307,7 +1318,7 @@ def _magma_init_(self, magma): sage: P. = PolynomialRing(GF(2)) sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: magma(Q) # optional - magma # needs sage.rings.finite_rings + sage: magma(Q) # optional - magma Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y @@ -1391,7 +1402,7 @@ def _macaulay2_init_(self, macaulay2=None): x - y sage: R. = PolynomialRing(ZZ, 4) - sage: I = R.ideal([x*y-z^2, y^2-w^2]) + sage: I = R.ideal([x*y - z^2, y^2 - w^2]) sage: Q = R.quotient(I); Q Quotient of Multivariate Polynomial Ring in x, y, z, w over Integer Ring by the ideal (x*y - z^2, y^2 - w^2) sage: Q._macaulay2_init_() # optional - macaulay2 @@ -1400,13 +1411,12 @@ def _macaulay2_init_(self, macaulay2=None): 2 2 2 (x*y - z , y - w ) - sage: # needs sage.rings.finite_rings 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: Q._macaulay2_init_() # optional - macaulay2 ZZ ---[x...y] 101 @@ -1479,13 +1489,14 @@ def _contains_(self, other): :: + sage: # needs sage.libs.pari sage: R. = QQ[] - sage: S. = R.quotient(T^3 - 1) # needs sage.libs.pari - sage: 1 in S.ideal(t^2 - 1) # needs sage.libs.pari + sage: S. = R.quotient(T^3 - 1) + sage: 1 in S.ideal(t^2 - 1) False - sage: 7 in S.ideal(t^2 + 1) # needs sage.libs.pari + sage: 7 in S.ideal(t^2 + 1) True - sage: 5-5*t in S.ideal(t^2 - 1) # needs sage.libs.pari + sage: 5-5*t in S.ideal(t^2 - 1) True """ R = self.ring() diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 752e03e8123..f67c7192f11 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -476,16 +476,17 @@ def _im_gens_(self, codomain, im_gens, base_map=None): Ring homomorphisms whose domain is the fraction field of a quotient ring work correctly (see :trac:`16135`):: + sage: # needs sage.libs.singular sage: R. = QQ[] - sage: K = R.quotient(x^2 - y^3).fraction_field() # needs sage.libs.singular + sage: K = R.quotient(x^2 - y^3).fraction_field() sage: L. = FunctionField(QQ) - sage: f = K.hom((t^3, t^2)) # needs sage.libs.singular - sage: list(map(f, K.gens())) # needs sage.libs.singular + sage: f = K.hom((t^3, t^2)) + sage: list(map(f, K.gens())) [t^3, t^2] - sage: xbar, ybar = K.gens() # needs sage.libs.singular - sage: f(1/ybar) # needs sage.libs.singular + sage: xbar, ybar = K.gens() + sage: f(1/ybar) 1/t^2 - sage: f(xbar/ybar) # needs sage.libs.singular + sage: f(xbar/ybar) t """ return self.lift()._im_gens_(codomain, im_gens, base_map=base_map) diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 90b07c7914b..39d69e76d33 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -302,21 +302,23 @@ cpdef rational_power_parts(a, Rational b, factor_limit=10**5): sage: rational_power_parts(-1, -1/3) (1, -1) - sage: (-1)^(-1/3) # needs sage.symbolic - -(-1)^(2/3) - sage: 1 / ((-1)^(1/3)) # needs sage.symbolic - -(-1)^(2/3) sage: rational_power_parts(-1, 2/3) (1, -1) - sage: (-1)^(2/3) # needs 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) # needs sage.symbolic + + sage: # needs sage.symbolic + sage: (-1)^(-1/3) + -(-1)^(2/3) + sage: 1 / ((-1)^(1/3)) + -(-1)^(2/3) + sage: (-1)^(2/3) + (-1)^(2/3) + sage: (-1)^(1/3)*(-1)^(1/5) (-1)^(8/15) - sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) # needs sage.symbolic + sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) True - sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) # needs sage.symbolic + 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)) True @@ -972,12 +974,13 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: n = 1/2; n._sympy_() # needs sympy + sage: # needs sympy + sage: n = 1/2; n._sympy_() 1/2 - sage: n = -1/5; n._sympy_() # needs sympy + sage: n = -1/5; n._sympy_() -1/5 - sage: from sympy import Symbol # needs sympy - sage: QQ(1) + Symbol('x')*QQ(2) # needs sympy + sage: from sympy import Symbol + sage: QQ(1) + Symbol('x')*QQ(2) 2*x + 1 """ import sympy @@ -1045,16 +1048,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy # needs numpy - sage: numpy.array([1, 2, 3/1]) # needs numpy + sage: # needs numpy + sage: import numpy + sage: numpy.array([1, 2, 3/1]) array([1, 2, 3]) - - sage: numpy.array(QQ(2**40)).dtype # needs numpy + sage: numpy.array(QQ(2**40)).dtype dtype('int64') - sage: numpy.array(QQ(2**400)).dtype # needs numpy + sage: numpy.array(QQ(2**400)).dtype dtype('O') - - sage: numpy.array([1, 1/2, 3/4]) # needs numpy + sage: numpy.array([1, 1/2, 3/4]) array([1. , 0.5 , 0.75]) """ if mpz_cmp_ui(mpq_denref(self.value), 1) == 0: @@ -1350,16 +1352,17 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: a = QQ(6/25) - sage: a.global_height_arch() + a.global_height_non_arch() # needs sage.rings.real_mpfr + sage: a.global_height_arch() + a.global_height_non_arch() 3.21887582486820 - sage: a.global_height() # needs sage.rings.real_mpfr + sage: a.global_height() 3.21887582486820 - sage: (1/a).global_height() # needs sage.rings.real_mpfr + sage: (1/a).global_height() 3.21887582486820 - sage: QQ(0).global_height() # needs sage.rings.real_mpfr + sage: QQ(0).global_height() 0.000000000000000 - sage: QQ(1).global_height() # needs sage.rings.real_mpfr + sage: QQ(1).global_height() 0.000000000000000 """ from sage.rings.real_mpfr import RealField @@ -1418,17 +1421,18 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(QQ, 'x') - sage: K = NumberField(x^2 - 2, 'beta') # needs sage.rings.number_field - sage: (1/7).is_norm(K) # needs sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') + sage: (1/7).is_norm(K) True - sage: (1/10).is_norm(K) # needs sage.rings.number_field + sage: (1/10).is_norm(K) False - sage: 0.is_norm(K) # needs sage.rings.number_field + sage: 0.is_norm(K) True - sage: (1/7).is_norm(K, element=True) # needs sage.rings.number_field + sage: (1/7).is_norm(K, element=True) (True, 1/7*beta + 3/7) - sage: (1/10).is_norm(K, element=True) # needs sage.rings.number_field + sage: (1/10).is_norm(K, element=True) (False, None) sage: (1/691).is_norm(QQ, element=True) (True, 1/691) @@ -1444,18 +1448,18 @@ cdef class Rational(sage.structure.element.FieldElement): A non-Galois number field:: - sage: K. = NumberField(x^3 - 2) # needs sage.rings.number_field - sage: B, e = (3/5).is_norm(K, element=True); B # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = NumberField(x^3 - 2) + sage: B, e = (3/5).is_norm(K, element=True); B True - sage: e.norm() # needs sage.rings.number_field + sage: e.norm() 3/5 - - sage: 7.is_norm(K) # needs sage.rings.number_field + sage: 7.is_norm(K) Traceback (most recent call last): ... NotImplementedError: is_norm is not implemented unconditionally for norms from non-Galois number fields - sage: 7.is_norm(K, proof=False) # needs sage.rings.number_field + sage: 7.is_norm(K, proof=False) False AUTHORS: diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 6b47fdeab0a..eb8f087691f 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -1525,7 +1525,7 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(QQ) # indirect doctest # needs sage.libs.gap + sage: gap(QQ) # indirect doctest # needs sage.libs.gap Rationals """ return 'Rationals' @@ -1638,21 +1638,22 @@ def _factor_univariate_polynomial(self, f): TESTS:: + sage: # needs sage.libs.pari sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial(x) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial(x) x - sage: QQ._factor_univariate_polynomial(2*x) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial(2*x) (2) * x - sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) (x - 1/2)^4 * (x + 1/2)^4 - sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # needs sage.libs.pari - sage: QQ._factor_univariate_polynomial(f) # needs sage.libs.pari + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) + sage: QQ._factor_univariate_polynomial(f) (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) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial(10*x^5 - 1) (10) * (x^5 - 1/10) - sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # needs sage.libs.pari + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index 3a93dc4645b..802e4567fc3 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -908,7 +908,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): TESTS:: - sage: RBF.gamma(RLF(pi)) # abs tol 1e-13 # needs sage.symbolic + sage: RBF.gamma(RLF(pi)) # abs tol 1e-13 # needs sage.symbolic [2.28803779534003 +/- 4.12e-15] """ cdef RealBall res @@ -3571,7 +3571,7 @@ cdef class RealBall(RingElement): TESTS:: - sage: RBF(Si(1)) # abs tol 1e-15 # needs sage.symbolic + sage: RBF(Si(1)) # abs tol 1e-15 # needs sage.symbolic [0.946083070367183 +/- 9.22e-16] """ cdef RealBall res = self._new() diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 5b1fe40d684..f3183dcb050 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -650,22 +650,23 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): TESTS:: + sage: # needs numpy sage: R. = RDF[] - sage: RDF._factor_univariate_polynomial(x) # needs numpy + sage: RDF._factor_univariate_polynomial(x) x - sage: RDF._factor_univariate_polynomial(2*x) # needs numpy + sage: RDF._factor_univariate_polynomial(2*x) (2.0) * x - sage: RDF._factor_univariate_polynomial(x^2) # needs numpy + sage: RDF._factor_univariate_polynomial(x^2) x^2 - sage: RDF._factor_univariate_polynomial(x^2 + 1) # needs numpy + sage: RDF._factor_univariate_polynomial(x^2 + 1) x^2 + 1.0 - sage: RDF._factor_univariate_polynomial(x^2 - 1) # needs numpy + sage: RDF._factor_univariate_polynomial(x^2 - 1) (x - 1.0) * (x + 1.0) The implementation relies on the ``roots()`` method which often reports roots not to be real even though they are:: - sage: f = (x-1)^3 + sage: f = (x-1)^3 # needs numpy sage: f.roots(ring=CDF) # abs tol 2e-5 # needs numpy [(1.0000065719436413, 1), (0.9999967140281792 - 5.691454546815028e-06*I, 1), @@ -815,14 +816,16 @@ 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 # needs sage.symbolic + sage: # needs sage.symbolic + sage: a - a.ulp()/3 == a True - sage: a + a.ulp()/3 == a # needs sage.symbolic + sage: a + a.ulp()/3 == a True - sage: b - b.ulp()/3 == b # needs sage.symbolic + sage: b - b.ulp()/3 == b True - sage: b + b.ulp()/3 == b # needs sage.symbolic + sage: b + b.ulp()/3 == b True + sage: c = RDF(1) sage: c - c.ulp()/3 == c False @@ -1271,8 +1274,8 @@ cdef class RealDoubleElement(FieldElement): sage: # needs sage.symbolic sage: a = RDF(exp(1.0)); a 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() + sage: sign, mantissa, exponent (1, 6121026514868073, -51) sage: sign*mantissa*(2**exponent) == a True @@ -1676,7 +1679,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(RDF(1/3)) # indirect doctest # needs sage.rings.complex_double + sage: CDF(RDF(1/3)) # indirect doctest # needs sage.rings.complex_double 0.3333333333333333 """ return CDF(self._value) diff --git a/src/sage/rings/real_lazy.pyx b/src/sage/rings/real_lazy.pyx index 0f797b039f5..fb96ae89407 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -1626,7 +1626,7 @@ cdef class LazyAlgebraic(LazyFieldElement): sage: a = LazyAlgebraic(CLF, QQ['x'].cyclotomic_polynomial(7), 0.6+0.8*CC.0) sage: a 0.6234898018587335? + 0.7818314824680299?*I - sage: ComplexField(150)(a) # indirect doctest # needs sage.rings.number_field + sage: ComplexField(150)(a) # indirect doctest # needs sage.rings.number_field 0.62348980185873353052500488400423981063227473 + 0.78183148246802980870844452667405775023233452*I sage: a = LazyAlgebraic(CLF, QQ['x'].0^2-7, -2.0) diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 6577ec8e733..b11fba1ac59 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -1408,7 +1408,7 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: hash(RIF(e)) == hash(RIF(e)) # indirect doctest # needs sage.symbolic + sage: hash(RIF(e)) == hash(RIF(e)) # indirect doctest # needs sage.symbolic True """ return hash(self.str(16)) @@ -2401,17 +2401,19 @@ cdef class RealIntervalFieldElement(RingElement): 1.00000000000000 sage: RIF(1, 2).relative_diameter() 0.666666666666667 - sage: RIF(pi).diameter() # needs sage.symbolic + + sage: # needs sage.symbolic + sage: RIF(pi).diameter() 1.41357985842823e-16 - sage: RIF(pi).absolute_diameter() # needs sage.symbolic + sage: RIF(pi).absolute_diameter() 4.44089209850063e-16 - sage: RIF(pi).relative_diameter() # needs sage.symbolic + sage: RIF(pi).relative_diameter() 1.41357985842823e-16 - sage: (RIF(pi) - RIF(3, 22/7)).diameter() # needs sage.symbolic + sage: (RIF(pi) - RIF(3, 22/7)).diameter() 0.142857142857144 - sage: (RIF(pi) - RIF(3, 22/7)).absolute_diameter() # needs sage.symbolic + sage: (RIF(pi) - RIF(3, 22/7)).absolute_diameter() 0.142857142857144 - sage: (RIF(pi) - RIF(3, 22/7)).relative_diameter() # needs sage.symbolic + sage: (RIF(pi) - RIF(3, 22/7)).relative_diameter() 2.03604377705518 """ cdef RealNumber x @@ -2433,21 +2435,23 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).fp_rank_diameter() # needs sage.symbolic - 1 sage: RIF(12345).fp_rank_diameter() 0 - sage: RIF(-sqrt(2)).fp_rank_diameter() # needs sage.symbolic - 1 sage: RIF(5/8).fp_rank_diameter() 0 sage: RIF(5/7).fp_rank_diameter() 1 - sage: a = RIF(pi)^12345; a # needs sage.symbolic + + sage: # needs sage.symbolic + sage: RIF(pi).fp_rank_diameter() + 1 + sage: RIF(-sqrt(2)).fp_rank_diameter() + 1 + sage: a = RIF(pi)^12345; a 2.06622879260?e6137 - sage: a.fp_rank_diameter() # needs sage.symbolic + sage: a.fp_rank_diameter() 30524 - sage: (RIF(sqrt(2)) - RIF(sqrt(2))).fp_rank_diameter() # needs sage.symbolic + sage: (RIF(sqrt(2)) - RIF(sqrt(2))).fp_rank_diameter() 9671406088542672151117826 # 32-bit 41538374868278620559869609387229186 # 64-bit diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index ac3a41ce5ef..1d1143c5548 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -1438,12 +1438,13 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: import numpy # needs numpy - sage: numpy.arange(10.0) # needs numpy + sage: # needs numpy + sage: import numpy + sage: numpy.arange(10.0) array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) - sage: numpy.array([1.0, 1.1, 1.2]).dtype # needs numpy + sage: numpy.array([1.0, 1.1, 1.2]).dtype dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype # needs numpy + sage: numpy.array([1.000000000000000000000000000000000000]).dtype dtype('O') """ if (self._parent).__prec <= 53: diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 62f1d362b54..54c8053062b 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -282,7 +282,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! # needs sage.combinat sage.modules + sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! # needs sage.combinat sage.modules Category of algebras with basis over Rational Field Since a quotient of the integers is its own base ring, and during @@ -969,18 +969,21 @@ cdef class Ring(ParentWithGens): zeta3 sage: CyclotomicField(3).zeta(3).multiplicative_order() # needs sage.rings.number_field 3 - sage: a = GF(7).zeta(); a # needs sage.rings.finite_rings + + sage: # needs sage.rings.finite_rings + sage: a = GF(7).zeta(); a 3 - sage: a.multiplicative_order() # needs sage.rings.finite_rings + sage: a.multiplicative_order() 6 - sage: a = GF(49,'z').zeta(); a # needs sage.rings.finite_rings + sage: a = GF(49,'z').zeta(); a z - sage: a.multiplicative_order() # needs sage.rings.finite_rings + sage: a.multiplicative_order() 48 - sage: a = GF(49,'z').zeta(2); a # needs sage.rings.finite_rings + sage: a = GF(49,'z').zeta(2); a 6 - sage: a.multiplicative_order() # needs sage.rings.finite_rings + sage: a.multiplicative_order() 2 + sage: QQ.zeta(3) Traceback (most recent call last): ... @@ -1511,18 +1514,19 @@ cdef class CommutativeRing(Ring): Elements in `M` acts as derivations at `(0,1,2)`:: - sage: Dx = M.gen(0); Dx # needs sage.modules + sage: # needs sage.modules + sage: Dx = M.gen(0); Dx d/dx - sage: Dy = M.gen(1); Dy # needs sage.modules + sage: Dy = M.gen(1); Dy d/dy - sage: Dz = M.gen(2); Dz # needs sage.modules + sage: Dz = M.gen(2); Dz d/dz sage: f = x^2 + y^2 + z^2 - sage: Dx(f) # = 2*x evaluated at (0,1,2) # needs sage.modules + sage: Dx(f) # = 2*x evaluated at (0,1,2) 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) # needs sage.modules + sage: Dy(f) # = 2*y evaluated at (0,1,2) 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) # needs sage.modules + sage: Dz(f) # = 2*z evaluated at (0,1,2) 4 An example with a twisting homomorphism:: @@ -1990,23 +1994,24 @@ cdef class PrincipalIdealDomain(IntegralDomain): over an extension ring. Note that ``gcd`` requires x and y to be coercible:: + sage: # needs sage.rings.number_field sage: R. = PolynomialRing(QQ) - sage: S. = NumberField(x^2 - 2, 'a') # needs sage.rings.number_field - sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) # needs sage.rings.number_field - sage: print(f); print(g) # needs sage.rings.number_field + sage: S. = NumberField(x^2 - 2, 'a') + sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) + sage: print(f); print(g) x^2 - 2 x^3 - a*x^2 - 2*x + 2*a - sage: f in R # needs sage.rings.number_field + sage: f in R True - sage: g in R # needs sage.rings.number_field + sage: g in R False - sage: R.gcd(f, g) # needs sage.rings.number_field + sage: R.gcd(f, g) Traceback (most recent call last): ... TypeError: Unable to coerce 2*a to a rational - sage: R.base_extend(S).gcd(f,g) # needs sage.rings.number_field + sage: R.base_extend(S).gcd(f,g) x^2 - 2 - sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # needs sage.rings.number_field + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) x - a """ if coerce: @@ -2358,16 +2363,17 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: B = QuaternionAlgebra(2) # needs sage.combinat sage.modules - sage: B.has_standard_involution() # needs sage.combinat sage.modules + sage: # needs sage.combinat sage.modules + sage: B = QuaternionAlgebra(2) + sage: B.has_standard_involution() True sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x**2 - 2) # needs sage.rings.number_field - sage: A = QuaternionAlgebra(K, -2, 5) # needs sage.combinat sage.modules sage.rings.number_field - sage: A.has_standard_involution() # needs sage.combinat sage.modules sage.rings.number_field + sage: A = QuaternionAlgebra(K, -2, 5) # needs sage.rings.number_field + sage: A.has_standard_involution() # needs sage.rings.number_field True - sage: L. = FreeAlgebra(QQ, 2) # needs sage.combinat sage.modules - sage: L.has_standard_involution() # needs sage.combinat sage.modules + sage: L. = FreeAlgebra(QQ, 2) + sage: L.has_standard_involution() Traceback (most recent call last): ... NotImplementedError: has_standard_involution is not implemented for this algebra diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index 83a4bd1ea27..a1e785aaefc 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -74,16 +74,16 @@ computes the coordinates of an element according to the above basis:: One can also compute traces and norms with respect to any base of the tower:: - sage: u.trace() # over K # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: u.trace() # over K (2*z2 + 1) + (2*z2 + 1)*a - sage: u.trace(F) # needs sage.rings.finite_rings + sage: u.trace(F) z2 + 1 - sage: u.trace().trace() # over K, then over F # needs sage.rings.finite_rings + sage: u.trace().trace() # over K, then over F z2 + 1 - - sage: u.norm() # over K # needs sage.rings.finite_rings + sage: u.norm() # over K (z2 + 1) + (4*z2 + 2)*a - sage: u.norm(F) # needs sage.rings.finite_rings + sage: u.norm(F) 2*z2 + 2 And minimal polynomials:: @@ -625,13 +625,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^2 - 2) # needs sage.rings.number_field - sage: E = K.over() # over QQ # needs sage.rings.number_field - - sage: hasattr(E, 'automorphisms') # needs sage.rings.number_field + sage: K. = QQ.extension(x^2 - 2) + sage: E = K.over() # over QQ + sage: hasattr(E, 'automorphisms') True - sage: E.automorphisms() # needs sage.rings.number_field + sage: E.automorphisms() [Ring endomorphism of Field in a with defining polynomial x^2 - 2 over its base Defn: a |--> a, Ring endomorphism of Field in a with defining polynomial x^2 - 2 over its base @@ -767,18 +767,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: k = GF(5) - sage: K. = GF(5^2).over(k) # needs sage.rings.finite_rings - sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings - - sage: x = L.from_base_ring(k(2)); x # needs sage.rings.finite_rings + sage: K. = GF(5^2).over(k) + sage: L. = GF(5^4).over(K) + sage: x = L.from_base_ring(k(2)); x 2 - sage: x.parent() # needs sage.rings.finite_rings + sage: x.parent() Field in v with defining polynomial x^2 + (3 - u)*x + u over its base - - sage: x = L.from_base_ring(u); x # needs sage.rings.finite_rings + sage: x = L.from_base_ring(u); x u - sage: x.parent() # needs sage.rings.finite_rings + sage: x.parent() Field in v with defining polynomial x^2 + (3 - u)*x + u over its base """ if r not in self._base: @@ -808,18 +807,17 @@ cdef class RingExtension_generic(CommutativeAlgebra): Observe what happens when we modify the option ``over``:: - sage: D # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: D Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over its base - - sage: D.print_options(over=2) # needs sage.rings.finite_rings - sage: D # needs sage.rings.finite_rings + sage: D.print_options(over=2) + sage: D Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over Field in c with defining polynomial x^3 + (1 + (2 - a)*b)*x^2 + (2 + 2*b)*x - b over Field in b with defining polynomial x^2 + (3 - a)*x + a over its base - - sage: D.print_options(over=Infinity) # needs sage.rings.finite_rings - sage: D # needs sage.rings.finite_rings + sage: D.print_options(over=Infinity) + sage: D Field in d with defining polynomial x^2 + ((1 - a) + ((1 + 2*a) - b)*c + ((2 + a) + (1 - a)*b)*c^2)*x + c over Field in c with defining polynomial x^3 + (1 + (2 - a)*b)*x^2 + (2 + 2*b)*x - b over Field in b with defining polynomial x^2 + (3 - a)*x + a over @@ -828,19 +826,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): Now the option ``base``:: - sage: d^2 # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: d^2 -c + ((-1 + a) + ((-1 + 3*a) + b)*c + ((3 - a) + (-1 + a)*b)*c^2)*d - - sage: D.basis_over(B) # needs sage.rings.finite_rings + sage: D.basis_over(B) [1, c, c^2, d, c*d, c^2*d] - sage: D.print_options(base=B) # needs sage.rings.finite_rings - sage: d^2 # needs sage.rings.finite_rings + sage: D.print_options(base=B) + sage: d^2 -c + (-1 + a)*d + ((-1 + 3*a) + b)*c*d + ((3 - a) + (-1 + a)*b)*c^2*d - - sage: D.basis_over(A) # needs sage.rings.finite_rings + sage: D.basis_over(A) [1, b, c, b*c, c^2, b*c^2, d, b*d, c*d, b*c*d, c^2*d, b*c^2*d] - sage: D.print_options(base=A) # needs sage.rings.finite_rings - sage: d^2 # needs sage.rings.finite_rings + sage: D.print_options(base=A) + sage: d^2 -c + (-1 + a)*d + (-1 + 3*a)*c*d + b*c*d + (3 - a)*c^2*d + (-1 + a)*b*c^2*d """ for (name, value) in options.items(): @@ -1044,21 +1041,20 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: E1 = GF(3^6).over(GF(3^3)) # needs sage.rings.finite_rings - sage: E1.coerce_map_from(GF(3^3)) # indirect doctest # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: E1 = GF(3^6).over(GF(3^3)) + sage: E1.coerce_map_from(GF(3^3)) # indirect doctest Ring morphism: From: Finite Field in z3 of size 3^3 To: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base Defn: z3 |--> z3 - - sage: E1.coerce_map_from(GF(3)) # indirect doctest # needs sage.rings.finite_rings + sage: E1.coerce_map_from(GF(3)) # indirect doctest Ring morphism: From: Finite Field of size 3 To: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base Defn: 1 |--> 1 - - sage: E2 = GF(3^18).over(GF(3^9)) # needs sage.rings.finite_rings - sage: E2.coerce_map_from(E1) # indirect doctest # needs sage.rings.finite_rings + sage: E2 = GF(3^18).over(GF(3^9)) + sage: E2.coerce_map_from(E1) # indirect doctest Ring morphism: From: Field in z6 with defining polynomial x^2 + (2*z3 + 1)*x + z3 over its base To: Field in z18 with defining polynomial x^2 + (z9^8 + 2*z9^7 + z9^5 + 2*z9^4 + z9^2 + z9 + 1)*x + z9 over its base @@ -1117,20 +1113,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - - sage: F.bases() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2).over() # over GF(5) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(K) + sage: F.bases() [Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] - - sage: K.bases() # needs sage.rings.finite_rings + sage: K.bases() [Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, Field in z2 with defining polynomial x^2 + 4*x + 2 over its base, Finite Field of size 5] - - sage: L.bases() # needs sage.rings.finite_rings + sage: L.bases() [Field in z12 with defining polynomial x^3 + (1 + (2 - z2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base, @@ -1157,15 +1151,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - - sage: F.absolute_base() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2).over() # over GF(5) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(K) + sage: F.absolute_base() Finite Field of size 5 - sage: K.absolute_base() # needs sage.rings.finite_rings + sage: K.absolute_base() Finite Field of size 5 - sage: L.absolute_base() # needs sage.rings.finite_rings + sage: L.absolute_base() Finite Field of size 5 .. SEEALSO:: @@ -1186,12 +1180,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: B = GF(5^12).over(A) # needs sage.rings.finite_rings - - sage: A.is_defined_over(GF(5^2)) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) + sage: B = GF(5^12).over(A) + sage: A.is_defined_over(GF(5^2)) True - sage: A.is_defined_over(GF(5)) # needs sage.rings.finite_rings + sage: A.is_defined_over(GF(5)) False sage: # needs sage.rings.finite_rings @@ -1247,12 +1241,11 @@ cdef class RingExtension_generic(CommutativeAlgebra): [Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base, Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base, Finite Field in z2 of size 5^2] - - sage: L._check_base(K) # needs sage.rings.finite_rings + sage: L._check_base(K) Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(GF(5^4)) # needs sage.rings.finite_rings + sage: L._check_base(GF(5^4)) Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base - sage: L._check_base(GF(5^4)) is K # needs sage.rings.finite_rings + sage: L._check_base(GF(5^4)) is K True When ``base`` is ``None``, the base of the extension is returned:: @@ -1285,17 +1278,16 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # needs sage.rings.finite_rings - sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - - sage: K.defining_morphism() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(K) + sage: K.defining_morphism() Ring morphism: From: Finite Field in z2 of size 5^2 To: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base Defn: z2 |--> z2 - - sage: L.defining_morphism() # needs sage.rings.finite_rings + sage: L.defining_morphism() Ring morphism: From: Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base To: Field in z12 with defining polynomial @@ -1311,7 +1303,6 @@ cdef class RingExtension_generic(CommutativeAlgebra): To: Field in z12 with defining polynomial x^3 + (1 + (4*z2 + 2)*z4)*x^2 + (2 + 2*z4)*x - z4 over its base Defn: z2 |--> z2 - sage: L.defining_morphism(GF(5)) # needs sage.rings.finite_rings Traceback (most recent call last): ... @@ -1380,16 +1371,16 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: K.gens() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) + sage: K.gens() (z2,) - sage: K.ngens() # needs sage.rings.finite_rings + sage: K.ngens() 1 - - sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L.gens(GF(5)) # needs sage.rings.finite_rings + sage: L = GF(5^4).over(K) + sage: L.gens(GF(5)) (z4, z2) - sage: L.ngens(GF(5)) # needs sage.rings.finite_rings + sage: L.ngens(GF(5)) 2 """ return len(self.gens(base)) @@ -1401,7 +1392,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: x =K.gen(); x # needs sage.rings.finite_rings + sage: x = K.gen(); x # needs sage.rings.finite_rings z2 Observe that the generator lives in the extension:: @@ -1419,13 +1410,13 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: x = K.random_element(); x # random # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) + sage: x = K.random_element(); x # random 3 + z2 - - sage: x.parent() # needs sage.rings.finite_rings + sage: x.parent() Field in z2 with defining polynomial x^2 + 4*x + 2 over its base - sage: x.parent() is K # needs sage.rings.finite_rings + sage: x.parent() is K True """ elt = self._backend.random_element() @@ -1442,15 +1433,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # needs sage.rings.finite_rings - sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L = GF(5^12).over(K) # needs sage.rings.finite_rings - - sage: K.degree_over(F) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(K) + sage: K.degree_over(F) 2 - sage: L.degree_over(K) # needs sage.rings.finite_rings + sage: L.degree_over(K) 3 - sage: L.degree_over(F) # needs sage.rings.finite_rings + sage: L.degree_over(F) 6 If ``base`` is omitted, the degree is computed over the base @@ -1509,14 +1500,14 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: B = GF(5^12).over(A) # needs sage.rings.finite_rings - - sage: A.degree(GF(5^2)) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) + sage: B = GF(5^12).over(A) + sage: A.degree(GF(5^2)) 2 - sage: B.degree(A) # needs sage.rings.finite_rings + sage: B.degree(A) 3 - sage: B.degree(GF(5^2)) # needs sage.rings.finite_rings + sage: B.degree(GF(5^2)) 6 Note that ``base`` must be an explicit base over which the @@ -1555,12 +1546,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: A = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: B = GF(5^12).over(A) # needs sage.rings.finite_rings - - sage: A.absolute_degree() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: A = GF(5^4).over(GF(5^2)) + sage: B = GF(5^12).over(A) + sage: A.absolute_degree() 2 - sage: B.absolute_degree() # needs sage.rings.finite_rings + sage: B.absolute_degree() 6 .. SEEALSO:: @@ -1580,12 +1571,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - - sage: L.is_finite_over(K) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) + sage: L = GF(5^4).over(K) + sage: L.is_finite_over(K) True - sage: L.is_finite_over(GF(5)) # needs sage.rings.finite_rings + sage: L.is_finite_over(GF(5)) True If ``base`` is omitted, it is set to its default which is the @@ -1643,12 +1634,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: K = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - - sage: L.is_free_over(K) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^2).over() # over GF(5) + sage: L = GF(5^4).over(K) + sage: L.is_free_over(K) True - sage: L.is_free_over(GF(5)) # needs sage.rings.finite_rings + sage: L.is_free_over(GF(5)) True If ``base`` is omitted, it is set to its default which is the @@ -1740,25 +1731,24 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) # needs sage.rings.number_field - sage: OK = A.over() # over ZZ # needs sage.rings.number_field - sage: OK # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 5) + sage: OK = A.over() # over ZZ + sage: OK Order in Number Field in a with defining polynomial x^2 - 5 over its base - - sage: K1 = OK.fraction_field(); K1 # needs sage.rings.number_field + sage: K1 = OK.fraction_field(); K1 Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() # needs sage.rings.number_field + sage: K1.bases() [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - - sage: K2 = OK.fraction_field(extend_base=True); K2 # needs sage.rings.number_field + sage: K2 = OK.fraction_field(extend_base=True); K2 Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() # needs sage.rings.number_field + sage: K2.bases() [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Rational Field] @@ -1840,17 +1830,16 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: F = GF(5^2) # needs sage.rings.finite_rings - sage: K = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L = GF(5^12).over(F) # needs sage.rings.finite_rings - - sage: K.Hom(L) # indirect doctest # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(5^2) + sage: K = GF(5^4).over(F) + sage: L = GF(5^12).over(F) + sage: K.Hom(L) # indirect doctest Set of Homomorphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 + (3*z2 + 1)*x^3 + x^2 + (4*z2 + 1)*x + z2 over its base - - sage: K.Hom(L, category=Sets()) # needs sage.rings.finite_rings + sage: K.Hom(L, category=Sets()) Set of Morphisms from Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base to Field in z12 with defining polynomial x^6 + (4*z2 + 3)*x^5 + x^4 @@ -2028,14 +2017,14 @@ cdef class RingExtensionFractionField(RingExtension_generic): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: OK = A.over() # needs sage.rings.number_field - sage: K = OK.fraction_field(); K # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: OK = A.over() + sage: K = OK.fraction_field(); K Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - - sage: TestSuite(K).run() # needs sage.rings.number_field + sage: TestSuite(K).run() """ RingExtension_generic.__init__(self, defining_morphism, **kwargs) @@ -2050,16 +2039,16 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: OK = A.over() # needs sage.rings.number_field - sage: K = OK.fraction_field(); K # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: OK = A.over() + sage: K = OK.fraction_field(); K Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - - sage: K.ring() # needs sage.rings.number_field + sage: K.ring() Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: K.ring() is OK # needs sage.rings.number_field + sage: K.ring() is OK True """ return self._ring @@ -2070,12 +2059,12 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: OK = A.over() # needs sage.rings.number_field - sage: K = OK.fraction_field() # needs sage.rings.number_field - - sage: K._repr_topring() # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: OK = A.over() + sage: K = OK.fraction_field() + sage: K._repr_topring() 'Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2' """ if isinstance(self._ring, RingExtension_generic): @@ -2188,22 +2177,18 @@ cdef class RingExtensionWithBasis(RingExtension_generic): sage: F = GF(5) sage: K = GF(5^2).over(F) # needs sage.rings.finite_rings sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L._print_option_base(F) is F # needs sage.rings.finite_rings True sage: L._print_option_base(K) is K # needs sage.rings.finite_rings True sage: L._print_option_base(GF(5^2)) is K # needs sage.rings.finite_rings True - sage: L._print_option_base(None) is K # needs sage.rings.finite_rings True - sage: L._print_option_base(L) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: base must be strict - sage: K._print_option_base(L) # needs sage.rings.finite_rings Traceback (most recent call last): ... @@ -2298,17 +2283,15 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: - sage: F. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: K. = GF(5^4).over(F) # needs sage.rings.finite_rings - sage: L. = GF(5^12).over(K) # needs sage.rings.finite_rings - - sage: L.basis_over(K) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F. = GF(5^2).over() # over GF(5) + sage: K. = GF(5^4).over(F) + sage: L. = GF(5^12).over(K) + sage: L.basis_over(K) [1, c, c^2] - - sage: L.basis_over(F) # needs sage.rings.finite_rings + sage: L.basis_over(F) [1, b, c, b*c, c^2, b*c^2] - - sage: L.basis_over(GF(5)) # needs sage.rings.finite_rings + sage: L.basis_over(GF(5)) [1, a, b, a*b, c, a*c, b*c, a*b*c, c^2, a*c^2, b*c^2, a*b*c^2] If ``base`` is omitted, it is set to its default which is the @@ -2407,10 +2390,9 @@ cdef class RingExtensionWithBasis(RingExtension_generic): x^3 + (7 + 2*a)*x^2 + (2 - a)*x - a over its base To: Vector space of dimension 3 over Field in a with defining polynomial x^2 + 7*x + 2 over its base - - sage: j(b) # needs sage.rings.finite_rings + sage: j(b) (0, 1, 0) - sage: i((1, a, a+1)) # needs sage.rings.finite_rings + sage: i((1, a, a+1)) 1 + a*b + (1 + a)*b^2 Similarly, one can view L as a F-vector space of dimension 6:: @@ -2507,25 +2489,24 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) # needs sage.rings.number_field - sage: OK = A.over() # over ZZ # needs sage.rings.number_field - sage: OK # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 5) + sage: OK = A.over() # over ZZ + sage: OK Order in Number Field in a with defining polynomial x^2 - 5 over its base - - sage: K1 = OK.fraction_field(); K1 # needs sage.rings.number_field + sage: K1 = OK.fraction_field(); K1 Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() # needs sage.rings.number_field + sage: K1.bases() [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - - sage: K2 = OK.fraction_field(extend_base=True); K2 # needs sage.rings.number_field + sage: K2 = OK.fraction_field(extend_base=True); K2 Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() # needs sage.rings.number_field + sage: K2.bases() [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Rational Field] @@ -2576,14 +2557,13 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^3 - 7) # needs sage.rings.number_field - sage: K = A.over() # needs sage.rings.number_field - - sage: type(K) # needs sage.rings.number_field + sage: A. = QQ.extension(x^3 - 7) + sage: K = A.over() + sage: type(K) - - sage: TestSuite(K).run() # needs sage.rings.number_field + sage: TestSuite(K).run() """ def __init__(self, defining_morphism, gen, names, check=True, **kwargs): @@ -2636,12 +2616,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^3).over() # needs sage.rings.finite_rings - sage: K._repr_topring() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: K._repr_topring() 'Field in a with defining polynomial x^3 + 3*x + 3' - - sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings - sage: L._repr_topring() # needs sage.rings.finite_rings + sage: L. = GF(5^9).over(K) + sage: L._repr_topring() 'Field in b with defining polynomial x^3 + (1 + 3*a^2)*x^2 + (3 + 2*a + 2*a^2)*x - a' """ if self._name is None: @@ -2654,12 +2634,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^3).over() # needs sage.rings.finite_rings - sage: K._latex_topring() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: K._latex_topring() '\\Bold{F}_{5}[a]' - - sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings - sage: L._latex_topring() # needs sage.rings.finite_rings + sage: L. = GF(5^9).over(K) + sage: L._latex_topring() '\\Bold{F}_{5}[a][b]' """ if self._name is None: @@ -2680,13 +2660,13 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(7^10).over(GF(7^2)); K # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(7^10).over(GF(7^2)); K Field in u with defining polynomial x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 over its base - - sage: P = K.modulus(); P # needs sage.rings.finite_rings + sage: P = K.modulus(); P x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 - sage: P(u) # needs sage.rings.finite_rings + sage: P(u) 0 We can use a different variable name:: @@ -2712,14 +2692,14 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: K.gens() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) + sage: K.gens() (a,) - - sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L.gens() # needs sage.rings.finite_rings + sage: L. = GF(5^4).over(K) + sage: L.gens() (b,) - sage: L.gens(GF(5)) # needs sage.rings.finite_rings + sage: L.gens(GF(5)) (b, a) """ if base is None: @@ -2753,25 +2733,24 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 5) # needs sage.rings.number_field - sage: OK = A.over() # over ZZ # needs sage.rings.number_field - sage: OK # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 5) + sage: OK = A.over() # over ZZ + sage: OK Order in Number Field in a with defining polynomial x^2 - 5 over its base - - sage: K1 = OK.fraction_field(); K1 # needs sage.rings.number_field + sage: K1 = OK.fraction_field(); K1 Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K1.bases() # needs sage.rings.number_field + sage: K1.bases() [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Order in Number Field in a with defining polynomial x^2 - 5 over its base, Integer Ring] - - sage: K2 = OK.fraction_field(extend_base=True); K2 # needs sage.rings.number_field + sage: K2 = OK.fraction_field(extend_base=True); K2 Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base - sage: K2.bases() # needs sage.rings.number_field + sage: K2.bases() [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, Rational Field] diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index a902857d9f8..694ab2a05fc 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -104,13 +104,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field - sage: K. = A.over() # over QQ # needs sage.rings.number_field - - sage: hasattr(a, 'continued_fraction') # needs sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) + sage: K. = A.over() # over QQ + sage: hasattr(a, 'continued_fraction') True - sage: a.continued_fraction() # needs sage.rings.number_field + sage: a.continued_fraction() [1; (2)*] """ try: @@ -138,11 +138,11 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 2) # needs sage.rings.number_field - sage: K. = A.over() # needs sage.rings.number_field - - sage: dir(a) # needs sage.rings.number_field + sage: A. = QQ.extension(x^2 - 2) + sage: K. = A.over() + sage: dir(a) ['__abs__', '__add__', ... @@ -324,10 +324,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): sage: # needs sage.rings.finite_rings sage: S. = F[] sage: E = S.over(F) - sage: f = E(1) # needs sage.rings.number_field - sage: g = f.in_base(); g # needs sage.rings.number_field + sage: f = E(1) + sage: g = f.in_base(); g 1 - sage: g.parent() # needs sage.rings.number_field + sage: g.parent() Finite Field in z2 of size 5^2 TESTS:: @@ -392,13 +392,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: x = K.random_element() # needs sage.rings.finite_rings - sage: y = K.random_element() # needs sage.rings.finite_rings - - sage: (x+y).parent() is K # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) + sage: x = K.random_element() + sage: y = K.random_element() + sage: (x+y).parent() is K True - sage: x + y == y + x # needs sage.rings.finite_rings + sage: x + y == y + x True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -412,13 +412,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: x = K.random_element() # needs sage.rings.finite_rings - - sage: y = -x # needs sage.rings.finite_rings - sage: y.parent() is K # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) + sage: x = K.random_element() + sage: y = -x + sage: y.parent() is K True - sage: x + y == 0 # needs sage.rings.finite_rings + sage: x + y == 0 True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -432,13 +432,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: x = K.random_element() # needs sage.rings.finite_rings - sage: y = K.random_element() # needs sage.rings.finite_rings - - sage: (x-y).parent() is K # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) + sage: x = K.random_element() + sage: y = K.random_element() + sage: (x - y).parent() is K True - sage: x - y == x + (-y) # needs sage.rings.finite_rings + sage: x - y == x + (-y) True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -452,13 +452,13 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: - sage: K = GF(5^4).over(GF(5^2)) # needs sage.rings.finite_rings - sage: x = K.random_element() # needs sage.rings.finite_rings - sage: y = K.random_element() # needs sage.rings.finite_rings - - sage: (x*y).parent() is K # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^4).over(GF(5^2)) + sage: x = K.random_element() + sage: y = K.random_element() + sage: (x*y).parent() is K True - sage: x * y == y * x # needs sage.rings.finite_rings + sage: x * y == y * x True """ cdef RingExtensionElement ans = PY_NEW(type(self)) @@ -473,17 +473,17 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: OK = A.over() # needs sage.rings.number_field - sage: a = OK(a) # needs sage.rings.number_field - - sage: b = 1/a; b # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: OK = A.over() + sage: a = OK(a) + sage: b = 1/a; b a/2 - sage: b.parent() # needs sage.rings.number_field + sage: b.parent() Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: a*b # needs sage.rings.number_field + sage: a*b 1 """ cdef RingExtensionElement ans @@ -576,16 +576,16 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: - sage: K. = GF(5^3).over() # needs sage.rings.finite_rings - sage: a.is_square() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: a.is_square() False - sage: a.is_square(root=True) # needs sage.rings.finite_rings + sage: a.is_square(root=True) (False, None) - - sage: b = a + 1 # needs sage.rings.finite_rings - sage: b.is_square() # needs sage.rings.finite_rings + sage: b = a + 1 + sage: b.is_square() True - sage: b.is_square(root=True) # needs sage.rings.finite_rings + sage: b.is_square(root=True) (True, 2 + 3*a + a^2) """ is_sq = self._backend.is_square() @@ -751,16 +751,16 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: OK = A.over() # over ZZ # needs sage.rings.number_field - sage: K = OK.fraction_field(); K # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: OK = A.over() # over ZZ + sage: K = OK.fraction_field(); K Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - - sage: x = K(1/a); x # needs sage.rings.number_field + sage: x = K(1/a); x a/2 - sage: num = x.numerator(); num # needs sage.rings.number_field + sage: num = x.numerator(); num a The numerator is an element of the ring which was used @@ -794,7 +794,6 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): sage: K = OK.fraction_field(); K # needs sage.rings.number_field Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: x = K(1/a); x # needs sage.rings.number_field a/2 sage: denom = x.denominator(); denom # needs sage.rings.number_field @@ -861,13 +860,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # needs sage.rings.finite_rings - sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings - sage: u = 1/(a+b) # needs sage.rings.finite_rings - - sage: u._repr_extension(base=K) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: L. = GF(5^9).over(K) + sage: u = 1/(a+b) + sage: u._repr_extension(base=K) '(2 + 2*a) + (-1 + a - a^2)*b + (2 + 3*a + 3*a^2)*b^2' - sage: u._repr_extension(base=GF(5)) # needs sage.rings.finite_rings + sage: u._repr_extension(base=GF(5)) '2 + 2*a - b + a*b - a^2*b + 2*b^2 + 3*a*b^2 + 3*a^2*b^2' """ cdef RingExtensionWithBasis parent = self._parent @@ -939,13 +938,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # needs sage.rings.finite_rings - sage: L. = GF(5^9).over(K) # needs sage.rings.finite_rings - sage: u = 1/(a+b) # needs sage.rings.finite_rings - - sage: u._latex_extension(base=K) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() + sage: L. = GF(5^9).over(K) + sage: u = 1/(a+b) + sage: u._latex_extension(base=K) \left( 2 + 2 a \right) + \left( -1 + a - a^{2} \right) b + \left( 2 + 3 a + 3 a^{2} \right) b^{2} - sage: u._latex_extension(base=GF(5)) # needs sage.rings.finite_rings + sage: u._latex_extension(base=GF(5)) 2 + 2 a - b + ab - a^{2}b + 2 b^{2} + 3 ab^{2} + 3 a^{2}b^{2} """ cdef RingExtensionWithBasis parent = self._parent @@ -1011,11 +1010,9 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): sage: L. = GF(5^6).over(K) sage: x = (a+b)^4; x (-1 + a) + (3 + a)*b + (1 - a)*b^2 - - sage: x.vector(K) # basis is (1, b, b^2) # needs sage.rings.finite_rings + sage: x.vector(K) # basis is (1, b, b^2) (-1 + a, 3 + a, 1 - a) - - sage: x.vector(F) # basis is (1, a, b, a*b, b^2, a*b^2) # needs sage.rings.finite_rings + sage: x.vector(F) # basis is (1, a, b, a*b, b^2, a*b^2) (4, 1, 3, 1, 1, 4) If ``base`` is omitted, it is set to its default which is the @@ -1077,12 +1074,11 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): sage: L. = GF(5^12).over(K) sage: u = 1/(a + b + c); u (2 + (-1 - a)*b) + ((2 + 3*a) + (1 - a)*b)*c + ((-1 - a) - a*b)*c^2 - - sage: P = u.polynomial(K); P # needs sage.rings.finite_rings + sage: P = u.polynomial(K); P ((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b - sage: P.base_ring() is K # needs sage.rings.finite_rings + sage: P.base_ring() is K True - sage: P(c) == u # needs sage.rings.finite_rings + sage: P(c) == u True When the base is `F`, we obtain a bivariate polynomial:: @@ -1161,19 +1157,18 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: - sage: K. = GF(5^3).over() # over GF(5) # needs sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings - sage: u = a/(1+b) # needs sage.rings.finite_rings - - sage: u # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^3).over() # over GF(5) + sage: L. = GF(5^6).over(K) + sage: u = a/(1+b) + sage: u (2 + a + 3*a^2) + (3 + 3*a + a^2)*b - sage: b*u # needs sage.rings.finite_rings + sage: b*u (3 + 2*a^2) + (2 + 2*a - a^2)*b - sage: u.matrix(K) # needs sage.rings.finite_rings + sage: u.matrix(K) [2 + a + 3*a^2 3 + 3*a + a^2] [ 3 + 2*a^2 2 + 2*a - a^2] - - sage: u.matrix(GF(5)) # needs sage.rings.finite_rings + sage: u.matrix(GF(5)) [2 1 3 3 3 1] [1 3 1 2 0 3] [2 3 3 1 3 0] @@ -1217,11 +1212,11 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) # needs sage.rings.finite_rings - sage: K = GF(11^6).over(F) # needs sage.rings.finite_rings - sage: L = GF(11^18).over(K) # needs sage.rings.finite_rings - - sage: for base in L.bases(): # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(11^2) + sage: K = GF(11^6).over(F) + sage: L = GF(11^18).over(K) + sage: for base in L.bases(): ....: x = L.random_element() ....: y = L.random_element() ....: assert((x+y).matrix(base) == x.matrix(base) + y.matrix(base)) @@ -1250,8 +1245,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): sage: K. = GF(5^3).over(F) sage: L. = GF(5^6).over(K) sage: u = a/(1+b) - - sage: tr = u.trace(K); tr # needs sage.rings.finite_rings + sage: tr = u.trace(K); tr -1 + 3*a + 2*a^2 We check that the trace lives in the base ring:: @@ -1305,15 +1299,14 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) # needs sage.rings.finite_rings - sage: K = GF(11^6).over(F) # needs sage.rings.finite_rings - sage: L = GF(11^18).over(K) # needs sage.rings.finite_rings - - sage: x = L.random_element() # needs sage.rings.finite_rings - sage: x.trace(F) == x.trace().trace() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(11^2) + sage: K = GF(11^6).over(F) + sage: L = GF(11^18).over(K) + sage: x = L.random_element() + sage: x.trace(F) == x.trace().trace() True - - sage: for base in L.bases(): # needs sage.rings.finite_rings + sage: for base in L.bases(): ....: x = L.random_element() ....: y = L.random_element() ....: assert(x.trace(base) == x.matrix(base).trace()) @@ -1345,8 +1338,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): sage: K. = GF(5^3).over(F) sage: L. = GF(5^6).over(K) sage: u = a/(1+b) - - sage: nr = u.norm(K); nr # needs sage.rings.finite_rings + sage: nr = u.norm(K); nr 3 + 2*a^2 We check that the norm lives in the base ring:: @@ -1400,15 +1392,14 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: - sage: F = GF(11^2) # needs sage.rings.finite_rings - sage: K = GF(11^6).over(F) # needs sage.rings.finite_rings - sage: L = GF(11^18).over(K) # needs sage.rings.finite_rings - - sage: x = L.random_element() # needs sage.rings.finite_rings - sage: x.norm(F) == x.norm().norm() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: F = GF(11^2) + sage: K = GF(11^6).over(F) + sage: L = GF(11^18).over(K) + sage: x = L.random_element() + sage: x.norm(F) == x.norm().norm() True - - sage: for base in L.bases(): # needs sage.rings.finite_rings + sage: for base in L.bases(): ....: x = L.random_element() ....: y = L.random_element() ....: assert(x.norm(base) == x.matrix(base).determinant()) @@ -1440,8 +1431,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): sage: K. = GF(5^3).over(F) sage: L. = GF(5^6).over(K) sage: u = a/(1+b) - - sage: chi = u.charpoly(K); chi # needs sage.rings.finite_rings + sage: chi = u.charpoly(K); chi x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2 We check that the charpoly has coefficients in the base ring:: @@ -1508,8 +1498,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): sage: K. = GF(5^3).over(F) sage: L. = GF(5^6).over(K) sage: u = 1 / (a+b) - - sage: chi = u.minpoly(K); chi # needs sage.rings.finite_rings + sage: chi = u.minpoly(K); chi x^2 + (2*a + a^2)*x - 1 + a We check that the minimal polynomial has coefficients in the base ring:: diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index fe6797159ee..f861d015a35 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -83,20 +83,18 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # needs sage.rings.finite_rings - sage: L. = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: phi = L.hom([b^5, a^5]); phi # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() + sage: L. = GF(5^4).over(K) + sage: phi = L.hom([b^5, a^5]); phi Ring endomorphism of Field in b with defining polynomial x^2 + (3 - a)*x + a over its base Defn: b |--> (2 + a) + 2*b with map on base ring: a |--> 1 - a - - sage: type(phi) # needs sage.rings.finite_rings + sage: type(phi) - - sage: TestSuite(phi).run() # needs sage.rings.finite_rings - + sage: TestSuite(phi).run() """ def __init__(self, parent, defn, base_map=None, check=True): r""" @@ -333,15 +331,14 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings - - sage: FrobK = K.hom([a^5]) # needs sage.rings.finite_rings - sage: FrobL = L.hom([b^5], base_map=FrobK) # needs sage.rings.finite_rings - - sage: FrobK^2 == End(K).identity() # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) + sage: L. = GF(5^6).over(K) + sage: FrobK = K.hom([a^5]) + sage: FrobL = L.hom([b^5], base_map=FrobK) + sage: FrobK^2 == End(K).identity() True - sage: FrobL^6 == End(L).identity() # needs sage.rings.finite_rings + sage: FrobL^6 == End(L).identity() True """ eq = are_equal_morphisms(self._backend, backend_morphism(other)) @@ -367,13 +364,14 @@ cdef class RingExtensionHomomorphism(RingMap): Coercion maps are not considered as identity morphisms:: - sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings - sage: iota = L.defining_morphism(); iota # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = GF(5^6).over(K) + sage: iota = L.defining_morphism(); iota Ring morphism: From: Field in a with defining polynomial x^2 + 4*x + 2 over its base To: Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base Defn: a |--> a - sage: iota.is_identity() # needs sage.rings.finite_rings + sage: iota.is_identity() False """ if self.domain() is not self.codomain(): @@ -386,14 +384,15 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K = GF(5^10).over(GF(5^5)) # needs sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^10).over(GF(5^5)) + sage: iota = K.defining_morphism(); iota Ring morphism: From: Finite Field in z5 of size 5^5 To: Field in z10 with defining polynomial x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base Defn: z5 |--> z5 - sage: iota.is_injective() # needs sage.rings.finite_rings + sage: iota.is_injective() True sage: K = GF(7).over(ZZ) @@ -413,14 +412,15 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K = GF(5^10).over(GF(5^5)) # needs sage.rings.finite_rings - sage: iota = K.defining_morphism(); iota # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(5^10).over(GF(5^5)) + sage: iota = K.defining_morphism(); iota Ring morphism: From: Finite Field in z5 of size 5^5 To: Field in z10 with defining polynomial x^2 + (2*z5^3 + 2*z5^2 + 4*z5 + 4)*x + z5 over its base Defn: z5 |--> z5 - sage: iota.is_surjective() # needs sage.rings.finite_rings + sage: iota.is_surjective() False sage: K = GF(7).over(ZZ) @@ -443,11 +443,11 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: - sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: L. = GF(5^6).over(K) # needs sage.rings.finite_rings - sage: FrobL = L.hom([b^5, a^5]) # absolute Frobenius # needs sage.rings.finite_rings - - sage: print(FrobL._repr_defn()) # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) + sage: L. = GF(5^6).over(K) + sage: FrobL = L.hom([b^5, a^5]) # absolute Frobenius + sage: print(FrobL._repr_defn()) b |--> (-1 + a) + (1 + 2*a)*b + a*b^2 with map on base ring: a |--> 1 - a @@ -474,14 +474,14 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: A. = QQ.extension(x^2 - 5) # needs sage.rings.number_field - sage: K. = A.over() # needs sage.rings.number_field - sage: f = K.hom([-sqrt5]); f # needs sage.rings.number_field + sage: A. = QQ.extension(x^2 - 5) + sage: K. = A.over() + sage: f = K.hom([-sqrt5]); f Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> -sqrt5 - - sage: f^2 # indirect doctest # needs sage.rings.number_field + sage: f^2 # indirect doctest Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> sqrt5 """ @@ -500,13 +500,13 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: - sage: K. = GF(5^2).over() # over GF(5) # needs sage.rings.finite_rings - sage: f = K.hom([a^5]) # needs sage.rings.finite_rings - - sage: g = copy(f) # indirect doctest # needs sage.rings.finite_rings - sage: f == g # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K. = GF(5^2).over() # over GF(5) + sage: f = K.hom([a^5]) + sage: g = copy(f) # indirect doctest + sage: f == g True - sage: f is g # needs sage.rings.finite_rings + sage: f is g False """ self._backend = _slots['_backend'] @@ -535,17 +535,16 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: - sage: K = GF(11^9).over(GF(11^3)) # needs sage.rings.finite_rings - sage: f = K.coerce_map_from(GF(11^9)); f # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(11^9).over(GF(11^3)) + sage: f = K.coerce_map_from(GF(11^9)); f Coercion morphism: From: Finite Field in z9 of size 11^9 To: Field in z9 with defining polynomial x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base - - sage: type(f) # needs sage.rings.finite_rings + sage: type(f) - - sage: TestSuite(f).run() # needs sage.rings.finite_rings + sage: TestSuite(f).run() """ def __init__(self, parent): r""" @@ -625,17 +624,16 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: - sage: K = GF(11^9).over(GF(11^3)) # needs sage.rings.finite_rings - sage: f = GF(11^9).convert_map_from(K); f # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: K = GF(11^9).over(GF(11^3)) + sage: f = GF(11^9).convert_map_from(K); f Canonical morphism: From: Field in z9 with defining polynomial x^3 + (9*z3^2 + 5*z3 + 1)*x^2 + (4*z3 + 3)*x + 10*z3 over its base To: Finite Field in z9 of size 11^9 - - sage: type(f) # needs sage.rings.finite_rings + sage: type(f) - - sage: TestSuite(f).run() # needs sage.rings.finite_rings + sage: TestSuite(f).run() """ def __init__(self, parent): diff --git a/src/sage/rings/semirings/tropical_semiring.pyx b/src/sage/rings/semirings/tropical_semiring.pyx index d9ddcd324fd..2922298e286 100644 --- a/src/sage/rings/semirings/tropical_semiring.pyx +++ b/src/sage/rings/semirings/tropical_semiring.pyx @@ -555,32 +555,34 @@ class TropicalSemiring(Parent, UniqueRepresentation): EXAMPLES:: - sage: TR = TropicalSemiring(RR) # needs sage.rings.real_mpfr - sage: T60 = TropicalSemiring(RealField(60)) # needs sage.rings.real_mpfr - sage: TR.has_coerce_map_from(T60) # needs sage.rings.real_mpfr - True sage: TQ = TropicalSemiring(QQ) + sage: TQ.has_coerce_map_from(TQ) + True sage: TQ.has_coerce_map_from(TropicalSemiring(ZZ)) True - sage: TR.has_coerce_map_from(TR) # needs sage.rings.real_mpfr + + sage: # needs sage.rings.real_mpfr + sage: TR = TropicalSemiring(RR) + sage: T60 = TropicalSemiring(RealField(60)) + sage: TR.has_coerce_map_from(T60) True - sage: TQ.has_coerce_map_from(TQ) + sage: TR.has_coerce_map_from(TR) True - sage: TR.has_coerce_map_from(TQ) # needs sage.rings.real_mpfr + sage: TR.has_coerce_map_from(TQ) True - sage: TR.has_coerce_map_from(float) # needs sage.rings.real_mpfr + sage: TR.has_coerce_map_from(float) False - sage: TR.has_coerce_map_from(RR) # needs sage.rings.real_mpfr + sage: TR.has_coerce_map_from(RR) False - sage: TR.has_coerce_map_from(QQ) # needs sage.rings.real_mpfr + sage: TR.has_coerce_map_from(QQ) False - sage: TR.coerce_map_from(T60)(T60(2)) # needs sage.rings.real_mpfr + sage: TR.coerce_map_from(T60)(T60(2)) 2.00000000000000 - sage: TR.coerce(T60(3.4)) # needs sage.rings.real_mpfr + sage: TR.coerce(T60(3.4)) 3.40000000000000 - sage: TR.coerce(T60.infinity()) # needs sage.rings.real_mpfr + sage: TR.coerce(T60.infinity()) +infinity - sage: TQ.coerce(TR(3.4)) # needs sage.rings.real_mpfr + sage: TQ.coerce(TR(3.4)) Traceback (most recent call last): ... TypeError: no canonical coercion from Tropical semiring over diff --git a/src/sage/rings/sum_of_squares.pyx b/src/sage/rings/sum_of_squares.pyx index 8c97f25b0df..b8f719d4dac 100644 --- a/src/sage/rings/sum_of_squares.pyx +++ b/src/sage/rings/sum_of_squares.pyx @@ -166,7 +166,7 @@ def two_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ij in Subsets(Subsets(45000, 15).random_element(), 2): # optional - sage.combinat + sage: for ij in Subsets(Subsets(45000, 15).random_element(), 2): # needs sage.combinat ....: if s(two_squares_pyx(s(ij))) != s(ij): ....: print("hey") @@ -254,7 +254,7 @@ def three_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): # optional - sage.combinat + sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): # needs sage.combinat ....: if s(three_squares_pyx(s(ijk))) != s(ijk): ....: print("hey") """ From 95cd4091f5215cafe3ee57524198d3d29aeb1125 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 29 Aug 2023 09:21:13 -0700 Subject: [PATCH 43/50] sage.rings: Use more block tags --- src/sage/rings/morphism.pyx | 24 ++++++++----------- .../number_field/number_field_element.pyx | 17 ++++++------- src/sage/rings/qqbar.py | 21 ++++++++-------- src/sage/rings/quotient_ring.py | 20 +++++++++------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 8f7c0176ccb..797445e78eb 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -109,26 +109,25 @@ A map from a multivariate polynomial ring to itself:: An endomorphism of a quotient of a multi-variate polynomial ring:: - sage; # needs sage.libs.singular + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ) - sage: S. = quo(R, ideal(1 + y^2)) # needs sage.libs.singular - sage: phi = S.hom([a^2, -b]) # needs sage.libs.singular - sage: phi # needs sage.libs.singular + 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) Defn: a |--> a^2 b |--> -b - sage: phi(b) # needs sage.libs.singular + sage: phi(b) -b - sage: phi(a^2 + b^2) # needs sage.libs.singular + sage: phi(a^2 + b^2) a^4 - 1 The reduction map from the integers to the integers modulo 8, viewed as a quotient ring:: sage: R = ZZ.quo(8*ZZ) - sage: pi = R.cover() - sage: pi + sage: pi = R.cover(); pi Ring morphism: From: Integer Ring To: Ring of integers modulo 8 @@ -239,7 +238,6 @@ Endomorphism of power series ring:: Frobenius on a power series ring over a finite field:: - sage: # needs sage.rings.finite_rings sage: R. = PowerSeriesRing(GF(5)) sage: f = R.hom([t^5]); f Ring endomorphism of Power Series Ring in t over Finite Field of size 5 @@ -323,7 +321,7 @@ Embedding a number field into the reals:: An example from Jim Carlson:: - sage: K = QQ # by the way :-) + sage: K = QQ # by the way :-) sage: R. = K[]; R Multivariate Polynomial Ring in a, b, c, d over Rational Field sage: S. = K[]; S @@ -336,9 +334,9 @@ An example from Jim Carlson:: b |--> 0 c |--> 0 d |--> u - sage: f(a+b+c+d) + sage: f(a + b + c + d) u - sage: f( (a+b+c+d)^2 ) + sage: f((a+b+c+d)^2) u^2 TESTS:: @@ -369,8 +367,6 @@ compare equal:: sage: R. = k[] sage: F4. = R.quo(x^2+x+1) sage: H = End(F4) - - sage: # needs sage.rings.finite_rings sage: from sage.rings.morphism import * sage: phi1 = H.identity(); phi1 Identity endomorphism of Univariate Quotient Polynomial Ring in a diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index a5c56f7f39d..1a405e705bc 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -2941,24 +2941,25 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: # needs sage.symbolic sage: K. = QuadraticField(2) - sage: SR(a) # indirect doctest # needs sage.symbolic + sage: SR(a) # indirect doctest sqrt(2) - sage: SR(3*a-5) # indirect doctest # needs sage.symbolic + sage: SR(3*a - 5) # indirect doctest 3*sqrt(2) - 5 sage: K. = QuadraticField(2, embedding=-1.4) - sage: SR(a) # indirect doctest # needs sage.symbolic + sage: SR(a) # indirect doctest -sqrt(2) sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) - sage: SR(a) # indirect doctest # needs sage.symbolic + sage: SR(a) # indirect doctest Traceback (most recent call last): ... TypeError: an embedding into RR or CC must be specified Now a more complicated example:: - sage: K. = NumberField(x^3 + x - 1, embedding=0.68) + sage: K. = NumberField(x^3 + x - 1, embedding=0.68) # needs sage.symbolic sage: b = SR(a); b # indirect doctest # needs sage.symbolic (1/18*sqrt(31)*sqrt(3) + 1/2)^(1/3) - 1/3/(1/18*sqrt(31)*sqrt(3) + 1/2)^(1/3) sage: (b^3 + b - 1).canonicalize_radical() # needs sage.symbolic @@ -2989,20 +2990,20 @@ cdef class NumberFieldElement(NumberFieldElement_base): embedded into the symbolic ring, which will usually get printed as a numerical approximation:: - sage: K. = NumberField(x^5-x+1, embedding=-1) + sage: K. = NumberField(x^5-x+1, embedding=-1) # needs sage.symbolic sage: SR(a) # needs sage.symbolic -1.167303978261419? :: - sage: K. = NumberField(x^6-x^3-1, embedding=1) + sage: K. = NumberField(x^6-x^3-1, embedding=1) # needs sage.symbolic sage: SR(a) # needs sage.symbolic (1/2*sqrt(5) + 1/2)^(1/3) In this field, general elements cannot be written in terms of radicals, but particular elements might be:: - sage: K. = NumberField(x^10 + 6*x^6 + 9*x^2 + 1, embedding=CC(0.332*I)) + sage: K. = NumberField(x^10 + 6*x^6 + 9*x^2 + 1, embedding=CC(0.332*I)) # needs sage.symbolic sage: SR(a) # needs sage.symbolic 0.3319890295845093?*I sage: SR(a^5+3*a) # needs sage.symbolic diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 4be1f45c1e2..ed3b1071b04 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -2582,29 +2582,29 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal [(361/29286*a^5 - 19/3254*a^4 - 14359/29286*a^3 + 401/29286*a^2 + 18183/1627*a + 15930/1627, 1), (49/117144*a^5 - 179/39048*a^4 - 3247/117144*a^3 + 22553/117144*a^2 + 1744/4881*a - 17195/6508, 1), (-1493/117144*a^5 + 407/39048*a^4 + 60683/117144*a^3 - 24157/117144*a^2 - 56293/4881*a - 53033/6508, 1)] - sage: rt2 = AA(sqrt(2)); rt2 # needs sage.symbolic + + sage: # needs sage.symbolic + sage: rt2 = AA(sqrt(2)); rt2 1.414213562373095? - sage: rt3 = AA(sqrt(3)); rt3 # needs sage.symbolic + sage: rt3 = AA(sqrt(3)); rt3 1.732050807568878? - sage: rt3a = QQbar(sqrt(3)); rt3a # needs sage.symbolic + sage: rt3a = QQbar(sqrt(3)); rt3a 1.732050807568878? sage: qqI = QQbar.zeta(4); qqI I sage: z3 = QQbar.zeta(3); z3 -0.500000000000000? + 0.866025403784439?*I - sage: rt2b = rt3 + rt2 - rt3; rt2b # needs sage.symbolic + sage: rt2b = rt3 + rt2 - rt3; rt2b 1.414213562373095? - sage: rt2c = z3 + rt2 - z3; rt2c # needs sage.symbolic + sage: rt2c = z3 + rt2 - z3; rt2c 1.414213562373095? + 0.?e-19*I - - sage: number_field_elements_from_algebraics(rt2) # needs sage.symbolic + sage: number_field_elements_from_algebraics(rt2) (Number Field in a with defining polynomial y^2 - 2, a, Ring morphism: From: Number Field in a with defining polynomial y^2 - 2 To: Algebraic Real Field Defn: a |--> 1.414213562373095?) - - sage: number_field_elements_from_algebraics((rt2,rt3)) # needs sage.symbolic + sage: number_field_elements_from_algebraics((rt2,rt3)) (Number Field in a with defining polynomial y^4 - 4*y^2 + 1, [-a^3 + 3*a, a^2 - 2], Ring morphism: From: Number Field in a with defining polynomial y^4 - 4*y^2 + 1 @@ -2725,7 +2725,8 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal [a^10 - 5*a^5 + 2, -a^8 + 4*a^3] sage: hom Ring morphism: - From: Number Field in a with defining polynomial y^15 - 9*y^10 + 21*y^5 - 3 with a = 0.6866813218928813? + From: Number Field in a with defining polynomial y^15 - 9*y^10 + 21*y^5 - 3 + with a = 0.6866813218928813? To: Algebraic Real Field Defn: a |--> 0.6866813218928813? diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index d2c3d160518..7bdcee92a11 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -898,11 +898,11 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = QQ[] - sage: R.quo(x^2 - y).is_integral_domain() # needs sage.singular + sage: R.quo(x^2 - y).is_integral_domain() # needs sage.libs.singular True - sage: R.quo(x^2 - y^2).is_integral_domain() # needs sage.singular + sage: R.quo(x^2 - y^2).is_integral_domain() # needs sage.libs.singular False - sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # needs sage.singular + sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # needs sage.libs.singular False sage: R. = ZZ[] sage: Q = R.quotient_ring([a, b]) @@ -1102,15 +1102,17 @@ def _coerce_map_from_(self, R): 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 # needs sage.libs.singular - True sage: S = R.quotient(I) sage: T = R.quotient(J) - sage: T.has_coerce_map_from(S) # needs sage.libs.singular + + sage: # needs sage.libs.singular + sage: I < J True - sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) # needs sage.libs.singular + sage: T.has_coerce_map_from(S) True - sage: S.has_coerce_map_from(T) # needs sage.libs.singular + sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) + True + sage: S.has_coerce_map_from(T) False We also allow coercions with the cover rings:: @@ -1318,7 +1320,7 @@ def _magma_init_(self, magma): sage: P. = PolynomialRing(GF(2)) sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: magma(Q) # optional - magma + sage: magma(Q) # indirect doctest # optional - magma Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y From e384b4751f76b6d3b2f28108ad44996a0963e093 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 29 Aug 2023 11:22:46 -0700 Subject: [PATCH 44/50] sage.rings: Use more block tags --- src/sage/rings/function_field/constructor.py | 15 +- src/sage/rings/function_field/maps.py | 294 +++++++++--------- .../number_field/number_field_element.pyx | 2 +- src/sage/rings/quotient_ring.py | 4 +- src/sage/rings/rational.pyx | 19 +- src/sage/rings/real_mpfr.pyx | 18 +- src/sage/rings/ring_extension.pyx | 20 +- src/sage/rings/ring_extension_element.pyx | 11 +- 8 files changed, 205 insertions(+), 178 deletions(-) diff --git a/src/sage/rings/function_field/constructor.py b/src/sage/rings/function_field/constructor.py index d1c63011d3c..7063eb6acff 100644 --- a/src/sage/rings/function_field/constructor.py +++ b/src/sage/rings/function_field/constructor.py @@ -132,7 +132,7 @@ class FunctionFieldExtensionFactory(UniqueFactory): EXAMPLES:: sage: K. = FunctionField(QQ) - sage: R.=K[] + sage: R. = K[] sage: y2 = y*1 sage: y2 is y False @@ -156,14 +156,15 @@ def create_key(self,polynomial,names): Verify that :trac:`16530` has been resolved:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(y^2 - x) # needs sage.rings.function_field - sage: R. = L[] # needs sage.rings.function_field - sage: M. = L.extension(z - 1) # needs sage.rings.function_field + sage: L. = K.extension(y^2 - x) + sage: R. = L[] + sage: M. = L.extension(z - 1) sage: R. = K[] - sage: N. = K.extension(z - 1) # needs sage.rings.function_field - sage: M is N # needs sage.rings.function_field + sage: N. = K.extension(z - 1) + sage: M is N False """ @@ -182,7 +183,7 @@ def create_object(self,version,key,**extra_args): sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(x - y^2) # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(x - y^2) # indirect doctest # needs sage.rings.function_field sage: y2 = y*1 sage: M. = K.extension(x - y2^2) # indirect doctest # needs sage.rings.function_field sage: L is M # needs sage.rings.function_field diff --git a/src/sage/rings/function_field/maps.py b/src/sage/rings/function_field/maps.py index 223112c9ae8..85377f1c894 100644 --- a/src/sage/rings/function_field/maps.py +++ b/src/sage/rings/function_field/maps.py @@ -9,17 +9,19 @@ sage: K.hom(1/x) Function Field endomorphism of Rational function field in x over Rational Field Defn: x |--> 1/x - sage: L. = K.extension(y^2 - x) # needs sage.rings.function_field - sage: K.hom(y) # needs sage.rings.function_field + + sage: # needs sage.rings.function_field + sage: L. = K.extension(y^2 - x) + sage: K.hom(y) Function Field morphism: From: Rational function field in x over Rational Field To: Function field in y defined by y^2 - x Defn: x |--> y - sage: L.hom([y,x]) # needs sage.rings.function_field + sage: L.hom([y,x]) Function Field endomorphism of Function field in y defined by y^2 - x Defn: y |--> y x |--> x - sage: L.hom([x,y]) # needs sage.rings.function_field + sage: L.hom([x,y]) Traceback (most recent call last): ... ValueError: invalid morphism @@ -71,10 +73,11 @@ class FunctionFieldVectorSpaceIsomorphism(Morphism): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: isinstance(f, sage.rings.function_field.maps.FunctionFieldVectorSpaceIsomorphism) # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: isinstance(f, sage.rings.function_field.maps.FunctionFieldVectorSpaceIsomorphism) True """ def _repr_(self) -> str: @@ -83,14 +86,15 @@ def _repr_(self) -> str: EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: f Isomorphism: From: Vector space of dimension 2 over Rational function field in x over Rational Field To: Function field in y defined by y^2 - x*y + 4*x^3 - sage: t # needs sage.modules sage.rings.function_field + sage: t Isomorphism: From: Function field in y defined by y^2 - x*y + 4*x^3 To: Vector space of dimension 2 over Rational function field in x over Rational Field @@ -106,10 +110,11 @@ def is_injective(self) -> bool: EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f.is_injective() # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: f.is_injective() True """ return True @@ -120,10 +125,11 @@ def is_surjective(self) -> bool: EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f.is_surjective() # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: f.is_surjective() True """ return True @@ -143,15 +149,15 @@ def _richcmp_(self, other, op): sage: K = QQ['x'].fraction_field() sage: L = K.function_field() sage: f = K.coerce_map_from(L) + sage: f == f + True - sage: K = QQbar['x'].fraction_field() # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K = QQbar['x'].fraction_field() sage: L = K.function_field() sage: g = K.coerce_map_from(L) - - sage: f == g # needs sage.rings.number_field + sage: f == g False - sage: f == f - True """ if type(self) is not type(other): @@ -186,9 +192,10 @@ class MapVectorSpaceToFunctionField(FunctionFieldVectorSpaceIsomorphism): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space(); f # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space(); f Isomorphism: From: Vector space of dimension 2 over Rational function field in x over Rational Field To: Function field in y defined by y^2 - x*y + 4*x^3 @@ -197,9 +204,10 @@ def __init__(self, V, K): """ EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space(); type(f) # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space(); type(f) """ self._V = V @@ -217,20 +225,22 @@ def _call_(self, v): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f(x*V.0 + (1/x^3)*V.1) # indirect doctest # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: f(x*V.0 + (1/x^3)*V.1) # indirect doctest 1/x^3*y + x TESTS: Test that this map is a bijection for some random inputs:: - sage: R. = L[] # needs sage.rings.function_field - sage: M. = L.extension(z^3 - y - x) # needs sage.rings.function_field - sage: for F in [K, L, M]: # needs sage.modules sage.rings.function_field + sage: # needs sage.modules sage.rings.function_field + sage: R. = L[] + sage: M. = L.extension(z^3 - y - x) + sage: for F in [K, L, M]: ....: for base in F._intermediate_fields(K): ....: V, f, t = F.vector_space(base) ....: for i in range(100): @@ -261,10 +271,11 @@ def domain(self): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f.domain() # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: f.domain() Vector space of dimension 2 over Rational function field in x over Rational Field """ return self._V @@ -275,10 +286,11 @@ def codomain(self): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: f.codomain() # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: f.codomain() Function field in y defined by y^2 - x*y + 4*x^3 """ return self._K @@ -290,9 +302,10 @@ class MapFunctionFieldToVectorSpace(FunctionFieldVectorSpaceIsomorphism): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space(); t # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space(); t Isomorphism: From: Function field in y defined by y^2 - x*y + 4*x^3 To: Vector space of dimension 2 over Rational function field in x over Rational Field @@ -309,10 +322,11 @@ def __init__(self, K, V): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: TestSuite(t).run(skip="_test_category") # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: TestSuite(t).run(skip="_test_category") """ self._V = V self._K = K @@ -326,19 +340,21 @@ def _call_(self, x): EXAMPLES:: + sage: # needs sage.modules sage.rings.function_field sage: K. = FunctionField(QQ); R. = K[] - sage: L. = K.extension(y^2 - x*y + 4*x^3) # needs sage.rings.function_field - sage: V, f, t = L.vector_space() # needs sage.modules sage.rings.function_field - sage: t(x + (1/x^3)*y) # indirect doctest # needs sage.modules sage.rings.function_field + sage: L. = K.extension(y^2 - x*y + 4*x^3) + sage: V, f, t = L.vector_space() + sage: t(x + (1/x^3)*y) # indirect doctest (x, 1/x^3) TESTS: Test that this map is a bijection for some random inputs:: - sage: R. = L[] # needs sage.rings.function_field - sage: M. = L.extension(z^3 - y - x) # needs sage.rings.function_field - sage: for F in [K, L, M]: # needs sage.modules sage.rings.function_field + sage: # needs sage.modules sage.rings.function_field + sage: R. = L[] + sage: M. = L.extension(z^3 - y - x) + sage: for F in [K, L, M]: ....: for base in F._intermediate_fields(K): ....: V, f, t = F.vector_space(base) ....: for i in range(100): @@ -391,11 +407,11 @@ def _repr_type(self) -> str: EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(7)); R. = K[] - sage: L. = K.extension(y^3 + 6*x^3 + x) # needs sage.rings.function_field - sage: f = L.hom(y*2) # needs sage.rings.function_field - sage: f._repr_type() # needs sage.rings.function_field + sage: L. = K.extension(y^3 + 6*x^3 + x) + sage: f = L.hom(y*2) + sage: f._repr_type() 'Function Field' """ return "Function Field" @@ -406,11 +422,11 @@ def _repr_defn(self) -> str: EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(7)); R. = K[] - sage: L. = K.extension(y^3 + 6*x^3 + x) # needs sage.rings.function_field - sage: f = L.hom(y*2) # needs sage.rings.function_field - sage: f._repr_defn() # needs sage.rings.function_field + sage: L. = K.extension(y^3 + 6*x^3 + x) + sage: f = L.hom(y*2) + sage: f._repr_defn() 'y |--> 2*y' """ a = '%s |--> %s' % (self.domain().variable_name(), self._im_gen) @@ -425,15 +441,15 @@ class FunctionFieldMorphism_polymod(FunctionFieldMorphism): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(7)); R. = K[] - sage: L. = K.extension(y^3 + 6*x^3 + x) # needs sage.rings.function_field - sage: f = L.hom(y*2); f # needs sage.rings.function_field + sage: L. = K.extension(y^3 + 6*x^3 + x) + sage: f = L.hom(y*2); f Function Field endomorphism of Function field in y defined by y^3 + 6*x^3 + x Defn: y |--> 2*y - sage: factor(L.polynomial()) # needs sage.rings.function_field + sage: factor(L.polynomial()) y^3 + 6*x^3 + x - sage: f(y).charpoly('y') # needs sage.rings.function_field + sage: f(y).charpoly('y') y^3 + 6*x^3 + x """ def __init__(self, parent, im_gen, base_morphism): @@ -442,11 +458,11 @@ def __init__(self, parent, im_gen, base_morphism): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(7)); R. = K[] - sage: L. = K.extension(y^3 + 6*x^3 + x) # needs sage.rings.function_field - sage: f = L.hom(y*2) # needs sage.rings.function_field - sage: TestSuite(f).run(skip="_test_category") # needs sage.rings.function_field + sage: L. = K.extension(y^3 + 6*x^3 + x) + sage: f = L.hom(y*2) + sage: TestSuite(f).run(skip="_test_category") """ FunctionFieldMorphism.__init__(self, parent, im_gen, base_morphism) # Verify that the morphism is valid: @@ -462,12 +478,12 @@ def _call_(self, x): """ EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(7)); R. = K[] - sage: L. = K.extension(y^3 + 6*x^3 + x); f = L.hom(y*2) # needs sage.rings.function_field - sage: f(y/x + x^2/(x+1)) # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(y^3 + 6*x^3 + x); f = L.hom(y*2) + sage: f(y/x + x^2/(x+1)) # indirect doctest 2/x*y + x^2/(x + 1) - sage: f(y) # needs sage.rings.function_field + sage: f(y) 2*y """ v = x.list() @@ -503,7 +519,7 @@ def _call_(self, x): sage: f = K.hom(1/x); f Function Field endomorphism of Rational function field in x over Finite Field of size 7 Defn: x |--> 1/x - sage: f(x+1) # indirect doctest + sage: f(x + 1) # indirect doctest (x + 1)/x sage: 1/x + 1 (x + 1)/x @@ -569,7 +585,7 @@ def _repr_type(self) -> str: EXAMPLES:: sage: K. = FunctionField(QQ) - sage: QQ.convert_map_from(K) # indirect doctest + sage: QQ.convert_map_from(K) # indirect doctest Conversion map: From: Rational function field in x over Rational Field To: Rational Field @@ -724,23 +740,23 @@ class FunctionFieldCompletion(Map): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m Completion map: From: Function field in y defined by y^2 + y + (x^2 + 1)/x To: Laurent Series Ring in s over Finite Field of size 2 - sage: m(x) # needs sage.rings.function_field + sage: m(x) s^2 + s^3 + s^4 + s^5 + s^7 + s^8 + s^9 + s^10 + s^12 + s^13 + s^15 + s^16 + s^17 + s^19 + O(s^22) - sage: m(y) # needs sage.rings.function_field + sage: m(y) s^-1 + 1 + s^3 + s^5 + s^7 + s^9 + s^13 + s^15 + s^17 + O(s^19) - sage: m(x*y) == m(x) * m(y) # needs sage.rings.function_field + sage: m(x*y) == m(x) * m(y) True - sage: m(x+y) == m(x) + m(y) # needs sage.rings.function_field + sage: m(x+y) == m(x) + m(y) True The variable name of the series can be supplied. If the place is not @@ -764,12 +780,12 @@ def __init__(self, field, place, name=None, prec=None, gen_name=None): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m Completion map: From: Function field in y defined by y^2 + y + (x^2 + 1)/x To: Laurent Series Ring in s over Finite Field of size 2 @@ -803,12 +819,12 @@ def _repr_type(self) -> str: EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m # indirect doctest Completion map: From: Function field in y defined by y^2 + y + (x^2 + 1)/x To: Laurent Series Ring in s over Finite Field of size 2 @@ -821,12 +837,12 @@ def _call_(self, f): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m(y) # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m(y) s^-1 + 1 + s^3 + s^5 + s^7 + s^9 + s^13 + s^15 + s^17 + O(s^19) """ if self._precision == infinity: @@ -840,12 +856,12 @@ def _call_with_args(self, f, args, kwds): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m(x+y, 10) # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m(x+y, 10) # indirect doctest s^-1 + 1 + s^2 + s^4 + s^8 + O(s^9) """ if self._precision == infinity: @@ -865,12 +881,12 @@ def _expand(self, f, prec=None): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m(x, prec=20) # indirect doctest # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m(x, prec=20) # indirect doctest s^2 + s^3 + s^4 + s^5 + s^7 + s^8 + s^9 + s^10 + s^12 + s^13 + s^15 + s^16 + s^17 + s^19 + O(s^22) """ @@ -900,16 +916,16 @@ def _expand_lazy(self, f): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p, prec=infinity) # needs sage.rings.function_field - sage: e = m(x); e # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p, prec=infinity) + sage: e = m(x); e s^2 + s^3 + s^4 + s^5 + s^7 + s^8 + ... - sage: e.coefficient(99) # indirect doctest # needs sage.rings.function_field + sage: e.coefficient(99) # indirect doctest 0 - sage: e.coefficient(100) # needs sage.rings.function_field + sage: e.coefficient(100) 1 """ place = self._place @@ -933,12 +949,12 @@ def default_precision(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: m = L.completion(p) # needs sage.rings.function_field - sage: m.default_precision() # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: m = L.completion(p) + sage: m.default_precision() 20 """ return self._precision @@ -954,15 +970,15 @@ def _repr_(self) -> str: EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(2)); _. = K[] - sage: L. = K.extension(Y^2 + Y + x + 1/x) # needs sage.rings.function_field - sage: p = L.places_finite()[0] # needs sage.rings.function_field - sage: R = p.valuation_ring() # needs sage.rings.function_field - sage: k, fr_k, to_k = R.residue_field() # needs sage.rings.function_field - sage: k # needs sage.rings.function_field + sage: L. = K.extension(Y^2 + Y + x + 1/x) + sage: p = L.places_finite()[0] + sage: R = p.valuation_ring() + sage: k, fr_k, to_k = R.residue_field() + sage: k Finite Field of size 2 - sage: fr_k # needs sage.rings.function_field + sage: fr_k Ring morphism: From: Finite Field of size 2 To: Valuation ring at Place (x, x*y) @@ -983,14 +999,14 @@ def _repr_(self) -> str: EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(5)); R. = PolynomialRing(K) - sage: F. = K.extension(t^2-x^3-1) # needs sage.rings.function_field - sage: O = F.maximal_order() # needs sage.rings.function_field - sage: I = O.ideal(x - 2) # needs sage.rings.function_field - sage: D = I.divisor() # needs sage.rings.function_field - sage: V, from_V, to_V = D.function_space() # needs sage.rings.function_field - sage: from_V # needs sage.rings.function_field + sage: F. = K.extension(t^2-x^3-1) + sage: O = F.maximal_order() + sage: I = O.ideal(x - 2) + sage: D = I.divisor() + sage: V, from_V, to_V = D.function_space() + sage: from_V Linear map: From: Vector space of dimension 2 over Finite Field of size 5 To: Function field in y defined by y^2 + 4*x^3 + 4 @@ -1011,14 +1027,14 @@ def _repr_(self) -> str: EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: K. = FunctionField(GF(5)); R. = PolynomialRing(K) - sage: F. = K.extension(t^2 - x^3 - 1) # needs sage.rings.function_field - sage: O = F.maximal_order() # needs sage.rings.function_field - sage: I = O.ideal(x - 2) # needs sage.rings.function_field - sage: D = I.divisor() # needs sage.rings.function_field - sage: V, from_V, to_V = D.function_space() # needs sage.rings.function_field - sage: to_V # needs sage.rings.function_field + sage: F. = K.extension(t^2 - x^3 - 1) + sage: O = F.maximal_order() + sage: I = O.ideal(x - 2) + sage: D = I.divisor() + sage: V, from_V, to_V = D.function_space() + sage: to_V Section of linear map: From: Function field in y defined by y^2 + 4*x^3 + 4 To: Vector space of dimension 2 over Finite Field of size 5 diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 1a405e705bc..4cf97ff4efd 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -2967,7 +2967,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Make sure we got the right one:: - sage: CC(a) + sage: CC(a) # needs sage.symbolic 0.682327803828019 sage: CC(b) # needs sage.symbolic 0.682327803828019 diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 7bdcee92a11..1b3086aaab8 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -728,7 +728,7 @@ def lifting_map(self): Test that there also is a lift for rings that are no instances of :class:`~sage.rings.ring.Ring` (see :trac:`11068`):: - sage: # needs sage.modules sage.rings.finite_rings + sage: # needs sage.modules sage: MS = MatrixSpace(GF(5), 2, 2) sage: I = MS * [MS.0*MS.1, MS.2 + MS.3] * MS sage: Q = MS.quo(I) @@ -1085,7 +1085,7 @@ def _coerce_map_from_(self, R): sage: R. = PolynomialRing(QQ) sage: S = R.quotient_ring(x^2 + y^2) - sage: S.has_coerce_map_from(R) # indirect doctest + sage: S.has_coerce_map_from(R) # indirect doctest True sage: S.has_coerce_map_from(QQ) True diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 39d69e76d33..f8843a2cee7 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -1915,24 +1915,27 @@ cdef class Rational(sage.structure.element.FieldElement): sage: n = 2/3 sage: n.sqrt() # needs sage.symbolic sqrt(2/3) - sage: n.sqrt(prec=10) # needs sage.rings.real_mpfr + + sage: # needs sage.rings.real_mpfr + sage: n.sqrt(prec=10) 0.82 - sage: n.sqrt(prec=100) # needs sage.rings.real_mpfr + sage: n.sqrt(prec=100) 0.81649658092772603273242802490 - sage: n.sqrt(prec=100)^2 # needs sage.rings.real_mpfr + sage: n.sqrt(prec=100)^2 0.66666666666666666666666666667 - sage: n.sqrt(prec=53, all=True) # needs sage.rings.real_mpfr + sage: n.sqrt(prec=53, all=True) [0.816496580927726, -0.816496580927726] + sage: sqrt(-2/3, prec=53) + 0.816496580927726*I + sage: sqrt(-2/3, prec=53, all=True) + [0.816496580927726*I, -0.816496580927726*I] + sage: n.sqrt(extend=False, all=True) Traceback (most recent call last): ... ValueError: square root of 2/3 not a rational number sage: sqrt(-2/3, all=True) # needs sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] - sage: sqrt(-2/3, prec=53) # needs sage.rings.real_mpfr - 0.816496580927726*I - sage: sqrt(-2/3, prec=53, all=True) # needs sage.rings.real_mpfr - [0.816496580927726*I, -0.816496580927726*I] AUTHORS: diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 1d1143c5548..6b00131c21c 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -3297,12 +3297,13 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: + sage: # needs sage.symbolic sage: R = RealField(100) - sage: R(pi) # needs sage.symbolic + sage: R(pi) 3.1415926535897932384626433833 - sage: axiom(R(pi)) # optional - axiom # needs sage.symbolic + sage: axiom(R(pi)) # indirect doctest # optional - axiom 3.1415926535 8979323846 26433833 - sage: fricas(R(pi)) # optional - fricas # needs sage.symbolic + sage: fricas(R(pi)) # optional - fricas 3.1415926535_8979323846_26433833 """ @@ -3791,14 +3792,17 @@ cdef class RealNumber(sage.structure.element.RingElement): -333/1000 sage: RR(3/4).nearby_rational(max_denominator=2) 1 - sage: RR(pi).nearby_rational(max_denominator=120) # needs sage.symbolic + + sage: # needs sage.symbolic + sage: RR(pi).nearby_rational(max_denominator=120) 355/113 - sage: RR(pi).nearby_rational(max_denominator=10000) # needs sage.symbolic + sage: RR(pi).nearby_rational(max_denominator=10000) 355/113 - sage: RR(pi).nearby_rational(max_denominator=100000) # needs sage.symbolic + sage: RR(pi).nearby_rational(max_denominator=100000) 312689/99532 - sage: RR(pi).nearby_rational(max_denominator=1) # needs sage.symbolic + sage: RR(pi).nearby_rational(max_denominator=1) 3 + sage: RR(-3.5).nearby_rational(max_denominator=1) -3 diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index a1e785aaefc..f6ce2b04826 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -2174,25 +2174,27 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: # needs sage.rings.finite_rings sage: F = GF(5) - sage: K = GF(5^2).over(F) # needs sage.rings.finite_rings - sage: L = GF(5^4).over(K) # needs sage.rings.finite_rings - sage: L._print_option_base(F) is F # needs sage.rings.finite_rings + sage: K = GF(5^2).over(F) + sage: L = GF(5^4).over(K) + sage: L._print_option_base(F) is F True - sage: L._print_option_base(K) is K # needs sage.rings.finite_rings + sage: L._print_option_base(K) is K True - sage: L._print_option_base(GF(5^2)) is K # needs sage.rings.finite_rings + sage: L._print_option_base(GF(5^2)) is K True - sage: L._print_option_base(None) is K # needs sage.rings.finite_rings + sage: L._print_option_base(None) is K True - sage: L._print_option_base(L) # needs sage.rings.finite_rings + sage: L._print_option_base(L) Traceback (most recent call last): ... ValueError: base must be strict - sage: K._print_option_base(L) # needs sage.rings.finite_rings + sage: K._print_option_base(L) Traceback (most recent call last): ... - ValueError: not (explicitly) defined over Field in z4 with defining polynomial x^2 + (3 - z2)*x + z2 over its base + ValueError: not (explicitly) defined over Field in z4 + with defining polynomial x^2 + (3 - z2)*x + z2 over its base """ if 'print_elements_as' in self._print_options: diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 694ab2a05fc..fb80ba84e6e 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -788,15 +788,16 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: R. = ZZ[] - sage: A. = ZZ.extension(x^2 - 2) # needs sage.rings.number_field - sage: OK = A.over() # over ZZ # needs sage.rings.number_field - sage: K = OK.fraction_field(); K # needs sage.rings.number_field + sage: A. = ZZ.extension(x^2 - 2) + sage: OK = A.over() # over ZZ + sage: K = OK.fraction_field(); K Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base - sage: x = K(1/a); x # needs sage.rings.number_field + sage: x = K(1/a); x a/2 - sage: denom = x.denominator(); denom # needs sage.rings.number_field + sage: denom = x.denominator(); denom 2 The denominator is an element of the ring which was used From 182b9bc461cbc0963176e6fbb7fad8c52d2da511 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 30 Aug 2023 18:24:31 -0700 Subject: [PATCH 45/50] sage.rings: More block tags, other tag fixes --- src/sage/rings/complex_interval.pyx | 11 +++-- src/sage/rings/lazy_series_ring.py | 2 +- src/sage/rings/localization.py | 48 +++++++++---------- .../rings/multi_power_series_ring_element.py | 2 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/sage/rings/complex_interval.pyx b/src/sage/rings/complex_interval.pyx index fdc3af338db..7fe25fd8114 100644 --- a/src/sage/rings/complex_interval.pyx +++ b/src/sage/rings/complex_interval.pyx @@ -290,19 +290,20 @@ cdef class ComplexIntervalFieldElement(FieldElement): Exact and nearly exact points are still visible:: - sage: plot(CIF(pi, 1), color='red') + plot(CIF(1, e), color='purple') + plot(CIF(-1, -1)) # needs sage.plot + sage: # needs sage.plot + sage: plot(CIF(pi, 1), color='red') + plot(CIF(1, e), color='purple') + plot(CIF(-1, -1)) Graphics object consisting of 6 graphics primitives A demonstration that `z \mapsto z^2` acts chaotically on `|z|=1`:: - sage: # needs sage.symbolic + sage: # needs sage.plot sage.symbolic sage: z = CIF(0, 2*pi/1000).exp() - sage: g = Graphics() # needs sage.plot - sage: for i in range(40): # needs sage.plot + sage: g = Graphics() + sage: for i in range(40): ....: z = z^2 ....: g += z.plot(color=(1./(40-i), 0, 1)) ... - sage: g # needs sage.plot + sage: g Graphics object consisting of 80 graphics primitives """ from sage.plot.polygon import polygon2d diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index f1dbbe5f5ce..faff4a5a52a 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -1214,7 +1214,7 @@ def __init__(self, base_ring, names, sparse=True, category=None): sage: TestSuite(L).run() sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') - sage: TestSuite(L).run() # needs sage.rings.finite_rings + sage: TestSuite(L).run() sage: L = LazyLaurentSeriesRing(Zmod(6), 't') sage: TestSuite(L).run(skip=['_test_revert']) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 03e269fe27b..9ed5586e325 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -9,19 +9,20 @@ EXAMPLES:: + sage: # needs sage.modules sage: LZ = Localization(ZZ, (5,11)) - sage: m = matrix(LZ, [[5, 7], [0,11]]) # needs sage.modules - sage: m.parent() # needs sage.modules + sage: m = matrix(LZ, [[5, 7], [0,11]]) + sage: m.parent() 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__ # needs sage.modules + sage: ~m # parent of inverse is different: see documentation of m.__invert__ [ 1/5 -7/55] [ 0 1/11] - sage: _.parent() # needs sage.modules + sage: _.parent() Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: mi = matrix(LZ, ~m) # needs sage.modules - sage: mi.parent() # needs sage.modules + sage: mi = matrix(LZ, ~m) + sage: mi.parent() Full MatrixSpace of 2 by 2 dense matrices over Integer Ring localized at (5, 11) - sage: mi == ~m # needs sage.modules + sage: mi == ~m True The next example defines the most general ring containing the coefficients of the irreducible @@ -76,7 +77,6 @@ Obtain specializations in positive characteristic:: - sage: # needs sage.rings.finite_rings sage: Fp = GF(17) sage: f = L.hom((3,5,7,11), codomain=Fp); f # needs sage.libs.pari Ring morphism: @@ -618,29 +618,30 @@ class Localization(IntegralDomain, UniqueRepresentation): ValueError: all given elements are invertible in 7-adic Ring with capped relative precision 20 + sage: # needs sage.libs.pari sage: R. = ZZ[] - sage: L = R.localization(x**2 + 1) # needs sage.libs.pari + sage: L = R.localization(x**2 + 1) sage: s = (x+5)/(x**2+1) - sage: s in L # needs sage.libs.pari + sage: s in L True sage: t = (x+5)/(x**2+2) sage: t in L False - sage: L(t) # needs sage.libs.pari + sage: L(t) Traceback (most recent call last): ... TypeError: fraction must have unit denominator - sage: L(s) in R # needs sage.libs.pari + sage: L(s) in R False - sage: y = L(x) # needs sage.libs.pari - sage: g = L(s) # needs sage.libs.pari - sage: g.parent() # needs sage.libs.pari + sage: y = L(x) + sage: g = L(s) + sage: g.parent() Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) - sage: f = (y+5)/(y**2+1); f # needs sage.libs.pari + sage: f = (y+5)/(y**2+1); f (x + 5)/(x^2 + 1) - sage: f == g # needs sage.libs.pari + sage: f == g True - sage: (y+5)/(y**2+2) # needs sage.libs.pari + sage: (y+5)/(y**2+2) Traceback (most recent call last): ... ValueError: factor x^2 + 2 of denominator is not a unit @@ -761,23 +762,22 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): TESTS:: + sage: # needs sage.libs.pari sage: phi = R.hom([5]) - sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) # needs sage.libs.pari + sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) 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) # needs sage.libs.pari + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) 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) # needs sage.libs.pari + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) Traceback (most recent call last): ... ValueError: codomain of base_map must be Integer Ring - - sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) # needs sage.libs.pari + sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) True """ B = self.base_ring() diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 8be86e21b89..56262c56cee 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -1081,7 +1081,7 @@ def __mod__(self, other): False sage: g in R.base_extend(Zmod(2)) True - sage: g.polynomial() == f.polynomial() % 2 # needs sage.libs.singular + sage: g.polynomial() == f.polynomial() % 2 # needs sage.libs.singular True """ if isinstance(other, (int, Integer)): From 59e556e6498a0516c6b4340ee546ec6b393fa9de Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 30 Aug 2023 18:56:17 -0700 Subject: [PATCH 46/50] src/sage/rings/localization.py: Change # needs sage.rings.finite_rings to more precise sage.libs.pari; use more block tags --- src/sage/rings/localization.py | 52 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/sage/rings/localization.py b/src/sage/rings/localization.py index 9ed5586e325..20c090da681 100644 --- a/src/sage/rings/localization.py +++ b/src/sage/rings/localization.py @@ -77,8 +77,9 @@ Obtain specializations in positive characteristic:: + sage: # needs sage.libs.pari sage.modules sage: Fp = GF(17) - sage: f = L.hom((3,5,7,11), codomain=Fp); f # needs sage.libs.pari + sage: f = L.hom((3,5,7,11), codomain=Fp); f 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, @@ -88,17 +89,17 @@ u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 # needs sage.libs.pari sage.modules + sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 [5 0 0] [0 3 0] [0 0 3] - sage: mFp1.base_ring() # needs sage.libs.pari sage.modules + sage: mFp1.base_ring() Finite Field of size 17 - sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 # needs sage.libs.pari sage.modules + sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 [ 2 3 0] [ 9 8 0] [ 0 0 16] - sage: mFp3 = matrix({k: f(v) for k, v in m3.dict().items()}); mFp3 # needs sage.libs.pari sage.modules + sage: mFp3 = matrix({k: f(v) for k, v in m3.dict().items()}); mFp3 [16 0 0] [ 0 4 5] [ 0 7 6] @@ -116,25 +117,28 @@ u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 # needs sage.modules sage.rings.finite_rings + + sage: # needs sage.libs.pari sage.modules sage.rings.finite_rings + sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 [5 0 0] [0 3 0] [0 0 3] - sage: mQ1.base_ring() # needs sage.modules sage.rings.finite_rings + sage: mQ1.base_ring() Rational Field - sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 # needs sage.modules sage.rings.finite_rings + sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 [-15 -14 0] [ 26 25 0] [ 0 0 -1] - sage: mQ3 = matrix({k: fQ(v) for k, v in m3.dict().items()}); mQ3 # needs sage.modules sage.rings.finite_rings + sage: mQ3 = matrix({k: fQ(v) for k, v in m3.dict().items()}); mQ3 [ -1 0 0] [ 0 -15/26 11/26] [ 0 301/26 275/26] + sage: # needs sage.libs.pari sage.libs.singular sage: S. = QQ[] sage: T = S.quo(x + y + z) - sage: F = T.fraction_field() # needs sage.libs.pari sage.libs.singular - sage: fF = L.hom((x, y, z, t), codomain=F); fF # needs sage.libs.pari sage.libs.singular + sage: F = T.fraction_field() + sage: fF = L.hom((x, y, z, t), codomain=F); fF 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, @@ -145,11 +149,11 @@ u1 |--> ybar u2 |--> zbar q |--> tbar - sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # needs sage.libs.pari sage.libs.singular sage.modules + sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # needs sage.modules [ ybar 0 0] [ 0 -ybar - zbar 0] [ 0 0 -ybar - zbar] - sage: mF1.base_ring() == F # needs sage.libs.pari sage.libs.singular sage.modules + sage: mF1.base_ring() == F # needs sage.modules True TESTS:: @@ -211,15 +215,16 @@ def normalize_extra_units(base_ring, add_units, warning=True): ....: [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) [z, y, x] + sage: # needs sage.libs.singular sage: R. = ZZ[] - sage: Q. = R.quo(x**2 - 5) # needs sage.libs.singular - sage: p = b**2 - 5 # needs sage.libs.singular - sage: p == (b-a)*(b+a) # needs sage.libs.singular + sage: Q. = R.quo(x**2 - 5) + sage: p = b**2 - 5 + sage: p == (b-a)*(b+a) True - sage: normalize_extra_units(Q, [p]) # needs sage.libs.pari sage.libs.singular + sage: normalize_extra_units(Q, [p]) # needs sage.libs.pari doctest:...: UserWarning: Localization may not be represented uniquely [b^2 - 5] - sage: normalize_extra_units(Q, [p], warning=False) # needs sage.libs.pari sage.libs.singular + sage: normalize_extra_units(Q, [p], warning=False) # needs sage.libs.pari [b^2 - 5] """ # convert to base ring @@ -256,7 +261,7 @@ class LocalizationElement(IntegralDomainElement): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.pari sage: from sage.rings.localization import LocalizationElement sage: P. = GF(5)[] sage: L = P.localization((x, y*z - x)) @@ -716,7 +721,7 @@ def _repr_(self): EXAMPLES:: sage: R. = GF(3)[] - sage: Localization(R, a**2 - 1) # needs sage.rings.finite_rings + sage: Localization(R, a**2 - 1) # needs sage.libs.pari Univariate Polynomial Ring in a over Finite Field of size 3 localized at (a + 1, a + 2) """ @@ -967,7 +972,7 @@ def fraction_field(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.pari sage: R. = GF(5)[] sage: L = Localization(R, (a**2 - 3, a)) sage: L.fraction_field() @@ -983,9 +988,10 @@ def characteristic(self): EXAMPLES:: + sage: # needs sage.libs.pari sage: R. = GF(5)[] - sage: L = R.localization((a**2 - 3, a)) # needs sage.rings.finite_rings - sage: L.characteristic() # needs sage.rings.finite_rings + sage: L = R.localization((a**2 - 3, a)) + sage: L.characteristic() 5 """ return self.base_ring().characteristic() From 733d5c2243373d31fe56c770d11696612cb1b9e7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 30 Aug 2023 19:01:55 -0700 Subject: [PATCH 47/50] src/sage/rings/multi_power_series_ring_element.py: Remove unnecessary # needs sage.rings.finite_rings --- .../rings/multi_power_series_ring_element.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 56262c56cee..eb41c15586c 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -252,8 +252,6 @@ class MPowerSeries(PowerSeries): sage: g = 1 + s + t - s*t + S.O(5); g 1 + s + t - s*t + O(s, t)^5 - - sage: # needs sage.rings.finite_rings sage: T = PowerSeriesRing(GF(3),5,'t'); T Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite Field of size 3 @@ -265,17 +263,17 @@ class MPowerSeries(PowerSeries): sage: w in T True - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # needs sage.rings.finite_rings - sage: w # needs sage.rings.finite_rings + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) + sage: w t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 Get random elements:: - sage: S.random_element(4) # random + sage: S.random_element(4) # random -2*t + t^2 - 12*s^3 + O(s, t)^4 - sage: T.random_element(10) # random # needs sage.rings.finite_rings + sage: T.random_element(10) # random -t1^2*t3^2*t4^2 + t1^5*t3^3*t4 + O(t0, t1, t2, t3, t4)^10 @@ -515,9 +513,9 @@ def _subs_formal(self, *x, **kwds): z sage: f = -2/33*s*t^2 - 1/5*t^5 - s^5*t + s^2*t^4 - sage: f(z,z) #indirect doctest + sage: f(z,z) # indirect doctest -2/33*z^3 - 1/5*z^5 - sage: f(z,1) #indirect doctest + sage: f(z,1) # indirect doctest -1/5 - 2/33*z + z^2 - z^5 sage: RF = RealField(10) # needs sage.rings.real_mpfr sage: f(z, RF(1)) # indirect doctest # needs sage.rings.real_mpfr @@ -540,7 +538,8 @@ def _subs_formal(self, *x, **kwds): sage: f(m,m) # needs sage.modules Traceback (most recent call last): ... - AttributeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' object has no attribute 'add_bigoh' + AttributeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' + object has no attribute 'add_bigoh' """ from sage.misc.misc_c import prod From 569bcc247b2a844ff411930cb7d333887c843345 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 30 Aug 2023 19:10:21 -0700 Subject: [PATCH 48/50] src/sage/rings/ring_extension.pyx: Remove unnecessary # needs sage.rings.finite_rings --- src/sage/rings/ring_extension.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index f6ce2b04826..d9438aaa648 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -1952,7 +1952,6 @@ cdef class RingExtension_generic(CommutativeAlgebra): :: - sage: # needs sage.rings.finite_rings sage: F = GF(11) sage: A. = F[] sage: K = Frac(F).over(F) @@ -1969,7 +1968,6 @@ cdef class RingExtension_generic(CommutativeAlgebra): Ensure issue :trac:`34692` is fixed:: - sage: # needs sage.rings.finite_rings sage: Fq = GF(11) sage: FqX. = Fq[] sage: k = Frac(FqX) From ad5635887b94ff7d686dfa2feae3d26301a53e90 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Aug 2023 14:51:43 -0700 Subject: [PATCH 49/50] src/sage/rings/real_double.pyx: Doctest cosmetics --- src/sage/rings/real_double.pyx | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index f3183dcb050..bfa020f14b8 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -189,7 +189,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: latex(RDF) # indirect doctest + sage: latex(RDF) # indirect doctest \Bold{R} """ return "\\Bold{R}" @@ -215,7 +215,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RealDoubleField() # indirect doctest + sage: RealDoubleField() # indirect doctest Real Double Field sage: RDF Real Double Field @@ -315,7 +315,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RDF.coerce(5) # indirect doctest + sage: RDF.coerce(5) # indirect doctest 5.0 sage: RDF.coerce(9499294r) 9499294.0 @@ -389,7 +389,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): Magma handles precision in decimal digits, so we lose a bit:: - sage: magma(RDF) # optional - magma # indirect doctest + sage: magma(RDF) # indirect doctest # optional - magma Real field of precision 15 sage: 10^15 < 2^53 < 10^16 True @@ -397,7 +397,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): When we convert back from Magma, we convert to a generic real field that has 53 bits of precision:: - sage: magma(RDF).sage() # optional - magma + sage: magma(RDF).sage() # optional - magma Real Field with 53 bits of precision """ return "RealField(%s : Bits := true)" % self.prec() @@ -408,7 +408,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: fricas(RDF) # indirect doctest, optional - fricas + sage: fricas(RDF) # indirect doctest # optional - fricas DoubleFloat """ return "DoubleFloat" @@ -419,7 +419,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: polymake(RDF) #optional - jupymake # indirect doctest + sage: polymake(RDF) # indirect doctest # optional - jupymake Float """ return '"Float"' @@ -713,7 +713,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF(2.3) # indirect doctest + sage: RDF(2.3) # indirect doctest 2.3 """ (self)._parent = _RDF @@ -747,7 +747,7 @@ cdef class RealDoubleElement(FieldElement): sage: RDF(10.5) 10.5 - sage: magma(RDF(10.5)) # optional - magma # indirect doctest + sage: magma(RDF(10.5)) # indirect doctest # optional - magma 10.5000000000000 """ return "%s!%s" % (self.parent()._magma_init_(magma), self) @@ -933,7 +933,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: ZZ(RDF(237.0)) # indirect doctest + sage: ZZ(RDF(237.0)) # indirect doctest 237 sage: ZZ(RDF(0.0/0.0)) Traceback (most recent call last): @@ -1136,9 +1136,9 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: latex(RDF(3.4)) # indirect doctest + sage: latex(RDF(3.4)) # indirect doctest 3.4 - sage: latex(RDF(2e-100)) # indirect doctest + sage: latex(RDF(2e-100)) # indirect doctest 2 \times 10^{-100} """ s = self.str() @@ -1339,7 +1339,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF('-1.5') + RDF('2.5') # indirect doctest + sage: RDF('-1.5') + RDF('2.5') # indirect doctest 1.0 """ cdef RealDoubleElement x = PY_NEW(RealDoubleElement) @@ -1352,7 +1352,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF('-1.5') - RDF('2.5') # indirect doctest + sage: RDF('-1.5') - RDF('2.5') # indirect doctest -4.0 """ cdef RealDoubleElement x = PY_NEW(RealDoubleElement) @@ -1365,7 +1365,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF('-1.5') * RDF('2.5') # indirect doctest + sage: RDF('-1.5') * RDF('2.5') # indirect doctest -3.75 """ cdef RealDoubleElement x = PY_NEW(RealDoubleElement) @@ -1378,7 +1378,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF('-1.5') / RDF('2.5') # indirect doctest + sage: RDF('-1.5') / RDF('2.5') # indirect doctest -0.6 sage: RDF(1)/RDF(0) +infinity @@ -2029,7 +2029,7 @@ cdef class ToRDF(Morphism): EXAMPLES:: sage: f = RDF.coerce_map_from(float) - sage: f(3.5) # indirect doctest + sage: f(3.5) # indirect doctest 3.5 """ cdef RealDoubleElement r = PY_NEW(RealDoubleElement) From 89e4c05f09351e7b576241d97fb79ef18474aaa8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Aug 2023 15:06:41 -0700 Subject: [PATCH 50/50] src/sage/rings/lazy_series_ring.py: More block tags --- src/sage/rings/lazy_series_ring.py | 63 ++++++++++++++---------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index faff4a5a52a..9670b391073 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -2240,13 +2240,12 @@ class LazyCompletionGradedAlgebra(LazySeriesRing): EXAMPLES:: - sage: NCSF = NonCommutativeSymmetricFunctions(QQ) # needs sage.modules - sage: S = NCSF.Complete() # needs sage.modules - sage: L = S.formal_series_ring(); L # needs sage.modules + sage: # needs sage.modules + sage: NCSF = NonCommutativeSymmetricFunctions(QQ) + sage: S = NCSF.Complete() + sage: L = S.formal_series_ring(); L Lazy completion of Non-Commutative Symmetric Functions over the Rational Field in the Complete basis - - sage: # needs sage.modules sage: f = 1 / (1 - L(S[1])); f S[] + S[1] + (S[1,1]) + (S[1,1,1]) + (S[1,1,1,1]) + (S[1,1,1,1,1]) + (S[1,1,1,1,1,1]) + O^7 @@ -2275,23 +2274,23 @@ def __init__(self, basis, sparse=True, category=None): sage: LazySymmetricFunctions.options.halting_precision(6) - sage: s = SymmetricFunctions(QQ).s() # needs sage.modules - sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: TestSuite(L).run() # needs lrcalc_python sage.modules - - sage: p = SymmetricFunctions(GF(5)).p() # needs sage.modules - sage: L = LazySymmetricFunctions(p) # needs sage.modules - sage: TestSuite(L).run() # needs sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: L = LazySymmetricFunctions(s) + sage: TestSuite(L).run() # needs lrcalc_python + sage: p = SymmetricFunctions(GF(5)).p() + sage: L = LazySymmetricFunctions(p) + sage: TestSuite(L).run() Reversion will only work when the base ring is a field:: - sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules - sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python sage.modules - - sage: s = SymmetricFunctions(QQ["q"]).s() # needs sage.modules - sage: L = LazySymmetricFunctions(s) # needs sage.modules - sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python sage.modules + sage: # needs sage.modules + sage: s = SymmetricFunctions(ZZ).s() + sage: L = LazySymmetricFunctions(s) + sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python + sage: s = SymmetricFunctions(QQ["q"]).s() + sage: L = LazySymmetricFunctions(s) + sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python Options are remembered across doctests:: @@ -2399,7 +2398,7 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No EXAMPLES:: - sage: # needs sage.modules sage.rings.finite_rings + sage: # needs sage.modules sage: m = SymmetricFunctions(GF(2)).m() sage: L = LazySymmetricFunctions(m) sage: L(2) @@ -2407,14 +2406,14 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: L(3) m[] - sage: m = SymmetricFunctions(ZZ).m() # needs sage.modules - sage: L = LazySymmetricFunctions(m) # needs sage.modules - sage: f = L(lambda i: m([i]), valuation=5, degree=10); f # needs sage.modules + sage: # needs sage.modules + sage: m = SymmetricFunctions(ZZ).m() + sage: L = LazySymmetricFunctions(m) + sage: f = L(lambda i: m([i]), valuation=5, degree=10); f m[5] + m[6] + m[7] + m[8] + m[9] - - sage: f.coefficient(6) # needs sage.modules + sage: f.coefficient(6) m[6] - sage: f[20] # needs sage.modules + sage: f[20] 0 Alternatively, ``x`` can be a list of elements of the base ring. @@ -2442,22 +2441,20 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No sage: L(lambda n: 0) O^7 - sage: L(lambda n: tensor([h[n], e([])]) + tensor([h([]), e[n]]), degree=3) # needs sage.modules + sage: # needs sage.modules + sage: L(lambda n: tensor([h[n], e([])]) + tensor([h([]), e[n]]), degree=3) (2*h[]#e[]) + (h[]#e[1]+h[1]#e[]) + (h[]#e[2]+h[2]#e[]) - - sage: L(lambda n: n)[3]; # needs sage.modules + sage: L(lambda n: n)[3]; Traceback (most recent call last): ... ValueError: coefficient 3*h[] # e[] should be an element of homogeneous degree 3 but has degree 0 - - sage: L([1, 2, 3]); # needs sage.modules + sage: L([1, 2, 3]); Traceback (most recent call last): ... ValueError: coefficient 2*h[] # e[] should be an element of homogeneous degree 1 but has degree 0 - - sage: L(lambda n: n, degree=3); # needs sage.modules + sage: L(lambda n: n, degree=3); Traceback (most recent call last): ... ValueError: coefficient h[] # e[] should be an element