diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index d967cfbb95c..6ad9dd8d6f0 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) + 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__() + 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) + 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__() + sage: sage.rings.abc.RealBallField.__subclasses__() # needs sage.libs.flint [] sage: len(sage.rings.abc.RealBallField.__subclasses__()) <= 1 @@ -227,12 +227,12 @@ 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:: - 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 @@ -277,12 +277,12 @@ cdef class ComplexField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(CC, sage.rings.abc.ComplexField) + 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__() + 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) + 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__() + sage: sage.rings.abc.ComplexBallField.__subclasses__() # needs sage.libs.flint [] sage: len(sage.rings.abc.ComplexBallField.__subclasses__()) <= 1 @@ -327,12 +327,12 @@ 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:: - 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 @@ -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) # needs 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__() # 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/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/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/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/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 132ae733eb9..f2080959a54 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 @@ -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,6 +338,7 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: + sage: # needs sage.rings.real_mpfr sage: a = ComplexField(200)(-2).sqrt(); a 1.4142135623730950488016887242096980785696718753769480731767*I sage: b = CDF(a); b @@ -353,7 +354,7 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): Check that :trac:`31836` is fixed:: - sage: a = CDF() ; a + sage: a = CDF(); a 0.0 sage: a.parent() Complex Double Field @@ -421,16 +422,17 @@ 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: # needs sage.rings.real_mpfr 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 +478,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 +892,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)) # indirect doctest 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 # indirect doctest 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 +984,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? @@ -1013,7 +1016,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 @@ -1025,11 +1028,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,6 +1148,7 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: + sage: # needs sage.libs.pari sage: CDF(1,2).__pari__() 1.00000000000000 + 2.00000000000000*I sage: pari(CDF(1,2)) @@ -1354,11 +1358,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)) @@ -1570,7 +1574,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 @@ -1628,7 +1632,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 +1667,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 +1743,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 +2198,42 @@ cdef class ComplexDoubleElement(FieldElement): We compute a few values of :meth:`eta()`:: - sage: CDF(0,1).eta() + sage: CDF(0,1).eta() # needs sage.libs.pari 0.7682254223260566 - sage: CDF(1,1).eta() + sage: CDF(1,1).eta() # needs sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I - sage: CDF(25,1).eta() + 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 + 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) + 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() + 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) + 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 +2247,7 @@ cdef class ComplexDoubleElement(FieldElement): You can also use functional notation:: sage: z = CDF(1,1) - sage: eta(z) + sage: eta(z) # needs sage.libs.pari 0.7420487758365647 + 0.1988313702299107*I """ if GSL_IMAG(self._complex) <= 0: @@ -2295,8 +2300,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 @@ -2372,9 +2377,9 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,2).dilog() + sage: CDF(1,2).dilog() # needs sage.libs.pari -0.059474798673809476 + 2.0726479717747566*I - sage: CDF(10000000,10000000).dilog() + sage: CDF(10000000,10000000).dilog() # needs sage.libs.pari -134.411774490731 + 38.79396299904504*I """ global complex_double_element_dilog @@ -2389,6 +2394,7 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: + sage: # needs sage.libs.pari sage: CDF(5,0).gamma() 24.0 sage: CDF(1,1).gamma() @@ -2420,11 +2426,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1,1).gamma_inc(CDF(2,3)) + 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) + 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)) + 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 +2445,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: sage: z = CDF(1, 1) - sage: z.zeta() + sage: z.zeta() # needs sage.libs.pari 0.5821580597520036 - 0.9268485643308071*I - sage: zeta(z) + sage: zeta(z) # needs sage.libs.pari 0.5821580597520036 - 0.9268485643308071*I - sage: zeta(CDF(1)) + sage: zeta(CDF(1)) # needs sage.libs.pari Infinity """ if GSL_REAL(self._complex) == 1 and GSL_IMAG(self._complex) == 0: @@ -2467,18 +2473,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 + 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) + sage: CDF(0,2).algdep(10) # needs sage.libs.pari x^2 + 4 - sage: CDF(1,5).algdep(2) + sage: CDF(1,5).algdep(2) # needs sage.libs.pari x^2 - 2*x + 26 """ from sage.arith.misc import algdep @@ -2543,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 + sage: CDF(2+i) # indirect doctest # needs sage.symbolic 2.0 + 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) @@ -2569,11 +2575,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 +2595,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 +2609,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..7fe25fd8114 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,16 +285,18 @@ 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: # 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.plot sage.symbolic sage: z = CIF(0, 2*pi/1000).exp() sage: g = Graphics() sage: for i in range(40): @@ -351,11 +353,11 @@ cdef class ComplexIntervalFieldElement(FieldElement): (2.50000000000000, 3.00000000000000) (-4.50000000000000, -4.00000000000000) + 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) sage: zz.real().endpoints() == z.real().endpoints() True @@ -399,9 +401,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 +987,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 +1001,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 +1999,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 +2021,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 +2063,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 33d73d81b12..8929faa9ae1 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -146,6 +146,7 @@ def is_ComplexNumber(x): while elements of the class :class:`ComplexField_class` are of type :class:`ComplexNumber`:: + sage: # needs sage.symbolic sage: c = 1 + 2*I sage: is_ComplexNumber(c) False @@ -457,12 +458,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' @@ -493,9 +494,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)) # 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 +716,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:: @@ -847,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 ) + sage: k._factor_univariate_polynomial(x) x - sage: k._factor_univariate_polynomial( 2*x ) + sage: k._factor_univariate_polynomial(2*x) (2.0000000000000000000000000000) * x - sage: k._factor_univariate_polynomial( x^2 ) + sage: k._factor_univariate_polynomial(x^2) x^2 - sage: k._factor_univariate_polynomial( x^2 + 3 ) + sage: k._factor_univariate_polynomial(x^2 + 3) (x - 1.7320508075688772935274463415*I) * (x + 1.7320508075688772935274463415*I) - sage: k._factor_univariate_polynomial( x^2 + 1 ) + sage: k._factor_univariate_polynomial(x^2 + 1) (x - I) * (x + I) - sage: k._factor_univariate_polynomial( k(I) * (x^2 + 1) ) + sage: k._factor_univariate_polynomial(k(I) * (x^2 + 1)) (1.0000000000000000000000000000*I) * (x - I) * (x + I) """ @@ -982,7 +984,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 +1001,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 +1028,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') @@ -1038,10 +1040,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,20 +1267,22 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: a = CC(pi + I*e); a # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a = CC(pi + I*e); a 3.14159265358979 + 2.71828182845905*I - sage: a.str(truncate=True) # optional - sage.symbolic + sage: a.str(truncate=True) '3.14159265358979 + 2.71828182845905*I' - sage: a.str() # optional - sage.symbolic + sage: a.str() '3.1415926535897931 + 2.7182818284590451*I' - sage: a.str(base=2) # optional - sage.symbolic + sage: a.str(base=2) '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) '0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I' - sage: a.str(base=16) # optional - sage.symbolic + sage: a.str(base=16) '3.243f6a8885a30 + 2.b7e151628aed2*I' - sage: a.str(base=36) # optional - sage.symbolic + sage: a.str(base=36) '3.53i5ab8p5fc + 2.puw5nggjf8f*I' + sage: CC(0) 0.000000000000000 sage: CC.0.str(istr='%i') @@ -1389,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) # optional - sage.libs.pari + sage: pari(a) 2.00000000000000 + 1.00000000000000*I - sage: pari(a).type() # optional - sage.libs.pari + sage: pari(a).type() 't_COMPLEX' - sage: type(pari(a)) # optional - sage.libs.pari + sage: type(pari(a)) - sage: a.__pari__() # optional - sage.libs.pari + sage: a.__pari__() 2.00000000000000 + 1.00000000000000*I - sage: type(a.__pari__()) # optional - sage.libs.pari + sage: type(a.__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.symbolic 3.14159265358979 - sage: pari(a).type() # optional - sage.libs.pari sage.symbolic + sage: pari(a).type() # needs sage.symbolic 't_REAL' sage: a = CC(-2).sqrt() - sage: pari(a) # optional - sage.libs.pari + sage: pari(a) 1.41421356237310*I """ if self.is_real(): @@ -1473,11 +1478,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 +1884,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 +2094,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 +2116,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arccos() + sage: (1+CC(I)).arccos() # needs sage.libs.pari 0.904556894302381 - 1.06127506190504*I """ return self._parent(self.__pari__().acos()) @@ -2122,7 +2127,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arccosh() + sage: (1+CC(I)).arccosh() # needs sage.libs.pari 1.06127506190504 + 0.904556894302381*I """ return self._parent(self.__pari__().acosh()) @@ -2133,7 +2138,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arcsin() + sage: (1+CC(I)).arcsin() # needs sage.libs.pari 0.666239432492515 + 1.06127506190504*I """ return self._parent(self.__pari__().asin()) @@ -2144,7 +2149,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arcsinh() + sage: (1+CC(I)).arcsinh() # needs sage.libs.pari 1.06127506190504 + 0.666239432492515*I """ return self._parent(self.__pari__().asinh()) @@ -2155,7 +2160,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arctan() + sage: (1+CC(I)).arctan() # needs sage.libs.pari 1.01722196789785 + 0.402359478108525*I """ return self._parent(self.__pari__().atan()) @@ -2166,7 +2171,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1+CC(I)).arctanh() + sage: (1+CC(I)).arctanh() # needs sage.libs.pari 0.402359478108525 + 1.01722196789785*I """ return self._parent(self.__pari__().atanh()) @@ -2177,7 +2182,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).coth() + sage: ComplexField(100)(1,1).coth() # needs sage.libs.pari 0.86801414289592494863584920892 - 0.21762156185440268136513424361*I """ return ~(self.tanh()) @@ -2188,7 +2193,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arccoth() + sage: ComplexField(100)(1,1).arccoth() # needs sage.libs.pari 0.40235947810852509365018983331 - 0.55357435889704525150853273009*I """ return (~self).arctanh() @@ -2199,7 +2204,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).csc() + sage: ComplexField(100)(1,1).csc() # needs sage.libs.pari 0.62151801717042842123490780586 - 0.30393100162842645033448560451*I """ return ~(self.sin()) @@ -2210,7 +2215,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).csch() + sage: ComplexField(100)(1,1).csch() # needs sage.libs.pari 0.30393100162842645033448560451 - 0.62151801717042842123490780586*I """ return ~(self.sinh()) @@ -2221,7 +2226,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arccsch() + sage: ComplexField(100)(1,1).arccsch() # needs sage.libs.pari 0.53063753095251782601650945811 - 0.45227844715119068206365839783*I """ return (~self).arcsinh() @@ -2232,7 +2237,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).sec() + sage: ComplexField(100)(1,1).sec() # needs sage.libs.pari 0.49833703055518678521380589177 + 0.59108384172104504805039169297*I """ return ~(self.cos()) @@ -2243,7 +2248,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).sech() + sage: ComplexField(100)(1,1).sech() # needs sage.libs.pari 0.49833703055518678521380589177 - 0.59108384172104504805039169297*I """ return ~(self.cosh()) @@ -2254,7 +2259,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: ComplexField(100)(1,1).arcsech() + sage: ComplexField(100)(1,1).arcsech() # needs sage.libs.pari 0.53063753095251782601650945811 - 1.1185178796437059371676632938*I """ return (~self).arccosh() @@ -2265,6 +2270,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: + sage: # needs sage.libs.pari sage: (1+CC(I)).cot() 0.217621561854403 - 0.868014142895925*I sage: i = ComplexField(200).0 @@ -2371,37 +2377,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() # needs 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. # 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 = 1 + i - sage: z.eta(omit_frac=True) + 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)]) + 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() + 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)) + sage: eta(1 + CC(I)) # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I """ try: @@ -2586,7 +2590,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") # needs sage.libs.pari 1.62780548487271 + 0.136827548397369*I An example to show that the returned value depends on the algorithm @@ -2598,13 +2602,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") + 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() + sage: a.agm(b, algorithm="pari").abs() # needs sage.libs.pari 0.490319232466314 TESTS: @@ -2821,21 +2825,21 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: a = ComplexNumber(1,0) - sage: a.dilog() + 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() + sage: b.dilog() # needs sage.libs.pari -0.205616758356028 + 0.915965594177219*I :: sage: c = ComplexNumber(0,0) - sage: c.dilog() + sage: c.dilog() # needs sage.libs.pari 0.000000000000000 """ return self._parent(self.__pari__().dilog()) @@ -2871,17 +2875,17 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: sage: i = ComplexField(30).0 - sage: (1+i).gamma() + sage: (1 + i).gamma() # needs sage.libs.pari 0.49801567 - 0.15494983*I TESTS:: - sage: CC(0).gamma() + sage: CC(0).gamma() # needs sage.libs.pari Infinity :: - sage: CC(-1).gamma() + sage: CC(-1).gamma() # needs sage.libs.pari Infinity """ try: @@ -2897,6 +2901,7 @@ 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 0.0020969149 - 0.059981914*I @@ -2912,7 +2917,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 # needs sage.libs.pari 0.121515644664508695525971545977439666159749344176962379708992904126499444842886620664991650378432544392118359044438541515 + 0.101533909079826033296475736021224621546966200987295663190553587086145836461236284668967411665020429964946098113930918850*I """ @@ -3246,9 +3251,9 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: i = ComplexField(30).gen() sage: z = 1 + i - sage: z.zeta() + sage: z.zeta() # needs sage.libs.pari 0.58215806 - 0.92684856*I - sage: zeta(z) + 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 c5298a34ae4..a3f877e423d 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]) @@ -264,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 @@ -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, ...] @@ -622,10 +624,11 @@ 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) # 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) + 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) 8.94 @@ -648,7 +651,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 +748,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 +762,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 +797,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 +820,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 +888,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 +904,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 +931,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 +970,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 +1038,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 +1055,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 +1104,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 +1134,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 +1179,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 +1214,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 +1265,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 +1278,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,12 +1330,12 @@ def period(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K. = QuadraticField(3) sage: cf = continued_fraction(sqrt3); cf [1; (1, 2)*] sage: cf.period() (1, 2) - sage: for k in xsrange(2,40): ....: if not k.is_square(): ....: s = QuadraticField(k).gen() @@ -1365,12 +1368,12 @@ def preperiod(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K. = QuadraticField(3) sage: cf = continued_fraction(sqrt3); cf [1; (1, 2)*] sage: cf.preperiod() (1,) - sage: cf = continued_fraction(sqrt3/7); cf [0; 4, (24, 8)*] sage: cf.preperiod() @@ -1448,6 +1451,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 +1496,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 +1548,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 +1579,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 +1660,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 +1705,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 +1715,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 +1749,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: # needs sage.rings.number_field ....: cf = continued_fraction(q) ....: ncf = -cf ....: nncf = -ncf @@ -1795,16 +1800,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 +1818,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 +1836,7 @@ def length(self): EXAMPLES:: - sage: continued_fraction(pi).length() + sage: continued_fraction(pi).length() # needs sage.symbolic +Infinity """ return Infinity @@ -1842,7 +1845,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 +1858,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 +1878,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 +1889,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 +1904,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) @@ -1915,12 +1920,13 @@ 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) # 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) + 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() -3.65375409332726e47 @@ -1933,6 +1939,7 @@ def quotient(self, n): 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 +1953,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 +2003,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 +2016,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 +2033,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 +2062,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 +2124,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 +2136,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 +2153,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 +2171,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 +2188,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 +2212,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 +2239,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 @@ -2374,20 +2379,20 @@ 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: # 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) + sage: continued_fraction_list(sqrt(2) + sqrt(3), bits=30) [3, 6, 1, 5, 7, 2] 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) [0, 2, 2, 6, 1, 11, 2, 1, 2, 2, 1, 4, 3, 1, 1] sage: continued_fraction_list(tan(sqrt(pi)), nterms=20) @@ -2397,16 +2402,18 @@ def continued_fraction_list(x, type="std", partial_convergents=False, 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,24 +2434,24 @@ 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`:: 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] 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,41 +2544,44 @@ 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 ``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) # 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) + sage: my_golden_ratio = (1 + sqrt5)/2 + sage: cf = continued_fraction((1+sqrt5)/2); cf [(1)*] sage: cf.convergent(12) 377/233 @@ -2584,6 +2594,7 @@ def continued_fraction(x, value=None): sage: cf.period() (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 +2611,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 +2646,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..26b6f2d5905 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)[] + sage: R25. = GF(25)[] # needs sage.rings.finite_rings + sage: R7. = GF(7)[] - 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) 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]) + 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)[] + 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 # optional - sage.rings.finite_rings + sage: D.pth_power() == D 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)[[]] + sage: M = R.derivation_module() + sage: M.basis() Family (d/dx, d/dy) - sage: R.derivation(x).list() # optional - sage.rings.finite_rings + sage: R.derivation(x).list() [1, 0] - sage: R.derivation(y).list() # optional - sage.rings.finite_rings + sage: R.derivation(y).list() [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 x*d/dx + y*d/dy - sage: f.list() # optional - sage.rings.finite_rings + sage: f.list() [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/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/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 1aff655bed8..5d298720a90 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -25,6 +25,7 @@ The GCD is not taken (since it doesn't converge sometimes) in the inexact case:: + sage: # needs sage.rings.real_mpfr sage: Z. = CC[] sage: I = CC.gen() sage: (1+I+z)/(z+0.1*I) @@ -263,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) # 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) + 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`):: @@ -296,6 +298,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,13 +309,14 @@ 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') # 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: # needs sage.libs.pari sage: R. = ZZ[] sage: L = Localization(R, (x**2 + 1,7)) sage: F = L.fraction_field() @@ -393,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) # 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) + 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 @@ -459,7 +464,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 +486,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 +499,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 +543,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 +576,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 +612,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 +736,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 +991,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 +1003,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 +1015,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 +1027,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 +1047,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 +1066,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 +1173,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 +1243,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 +1306,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 11a2b646d35..00bad2188ac 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,32 @@ 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: # needs sage.rings.number_field 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) + 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)) @@ -173,10 +174,10 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - sage: R. = RealField(10)[] - sage: f = (x^2+2*x+1)/(x+1); f + 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 + sage: f.reduce(); f # needs sage.rings.real_mpfr x + 1.0 TESTS: @@ -393,10 +394,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 +569,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 +647,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 @@ -764,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) @@ -775,7 +777,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 +813,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 +860,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()) # needs sage.libs.singular - sage: type(a.denominator()) + sage: type(a.denominator()) # needs sage.libs.singular sage: a = x^(-2); a 1/x^2 - sage: type(a.numerator()) + sage: type(a.numerator()) # needs sage.libs.singular - sage: type(a.denominator()) + sage: type(a.denominator()) # needs sage.libs.singular sage: x^0 1 @@ -897,10 +900,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 +924,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 +938,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 +1043,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 +1102,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 +1209,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/function_field/constructor.py b/src/sage/rings/function_field/constructor.py index 8e5ecd281ee..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 @@ -150,20 +150,21 @@ 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: 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,9 +183,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..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/function_field/place.py b/src/sage/rings/function_field/place.py index 48ea2a2c32f..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 + 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 + 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 + 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/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/ideal.py b/src/sage/rings/ideal.py index 2bb3a47e4d3..e7aeaa24cde 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,6 +486,7 @@ def apply_morphism(self, phi): EXAMPLES:: + 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 @@ -509,6 +510,7 @@ def apply_morphism(self, phi): TESTS:: + sage: # needs sage.rings.number_fields sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: A = K.ideal(a) @@ -522,6 +524,7 @@ def apply_morphism(self, phi): :: + 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) @@ -531,9 +534,9 @@ def apply_morphism(self, phi): 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 # needs sage.rings.number_fields Fractional ideal (2, a + 1) - sage: taus[1](B) + sage: taus[1](B) # needs sage.rings.number_fields Fractional ideal (2, a + 1) """ from sage.categories.morphism import is_Morphism @@ -589,12 +592,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 +702,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 +747,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 +808,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 +896,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 +964,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) - sage: I.is_trivial() + 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 +1122,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 +1146,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 +1182,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 +1233,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 +1252,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 +1579,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 +1620,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(): @@ -1645,32 +1650,33 @@ 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 # optional - sage.libs.pari + sage: F = P.residue_field(); 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 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 +1685,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 +1713,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 +1750,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 +1808,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 +1855,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..0988ffc72e5 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 d4cbe9372bb..e945fcfe455 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 @@ -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 @@ -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)) (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)) + 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) - 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) + 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 @@ -1130,20 +1130,20 @@ 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)) (+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) - 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`` / @@ -1151,22 +1151,22 @@ def _element_constructor_(self, x): 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) - sage: InfinityRing(CC(oo)), InfinityRing(CC(-oo)) + 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) + 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,18 +1227,18 @@ 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 - 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 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) + 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 + 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] - sage: for R in rings: + 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 = ... @@ -1850,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 d5e87626d31..478babb559f 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,41 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Test conversion from PARI (:trac:`11685`):: - sage: ZZ(pari(-3)) # optional - sage.libs.pari + sage: # needs sage.libs.pari + sage: ZZ(pari(-3)) -3 - sage: ZZ(pari("-3.0")) # optional - sage.libs.pari + sage: ZZ(pari("-3.0")) -3 - sage: ZZ(pari("-3.5")) # optional - 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")) # optional - 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")) # optional - sage.libs.pari + sage: ZZ(pari("10^50")) 100000000000000000000000000000000000000000000000000 - sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari + sage: ZZ(pari("Pol(3)")) 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.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.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 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 +581,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 +766,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 +1004,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 +1017,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 +2005,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 +2110,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 +2137,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:: @@ -2650,6 +2652,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: + sage: # needs sage.rings.real_mpfr sage: x = 3^100000 sage: RR(log(RR(x), 3)) 100000.000000000 @@ -2658,6 +2661,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) @@ -2667,6 +2671,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): ... @@ -2764,15 +2769,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) + 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) + 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,33 +2790,33 @@ 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 + sage: x.log(3, 53) # default precision for RealField # needs sage.rings.real_mpfr 100000.000000000 - sage: (x + 1).log(3, 53) + sage: (x + 1).log(3, 53) # needs sage.rings.real_mpfr 100000.000000000 - sage: (x + 1).log(3, 1000) + 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) + 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:: - sage: log(0) + sage: log(0) # needs sage.symbolic -Infinity Some rational bases yield integer logarithms (:trac:`21517`):: @@ -2826,7 +2831,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 +2888,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 +2900,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 +2982,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 +3029,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 +3064,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 +3347,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 +3445,11 @@ 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 +3702,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 +3867,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 +3894,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 +3907,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') # 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 @@ -3915,10 +3924,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 +4624,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 +4821,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 +4829,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,6 +4883,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: ZZ(5).global_height() 1.60943791243410 sage: ZZ(-2).global_height(prec=100) @@ -5135,55 +5147,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 +5291,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 +5319,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 +5341,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 +5404,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 +5433,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() @@ -5442,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() # optional - sage.libs.pari + sage: x.is_pseudoprime() True - sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power() True - sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power(get_data=True) (1000...000357, 12) - sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (997^100).is_pseudoprime_power() True - sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (998^100).is_pseudoprime_power() False - sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari + sage: ((10^1000 + 453)^2).is_pseudoprime_power() True TESTS:: @@ -5462,7 +5477,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) @@ -5529,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') # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') sage: n = 4 - sage: n.is_norm(K) # optional - sage.rings.number_field + sage: n.is_norm(K) True - sage: 5.is_norm(K) # optional - sage.rings.number_field + sage: 5.is_norm(K) 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) (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() 4 sage: n = 5 - sage: n.is_norm(K, element=True) # optional - 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) @@ -5559,9 +5575,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 +5678,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 +5764,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 +5812,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 +5842,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 +5887,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 +5902,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 +5943,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 +6007,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 +6024,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 +6098,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 +6147,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 +6160,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 +6182,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 +6221,18 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.array([1, 2, 3]) # optional - numpy + sage: # needs numpy + sage: import numpy + sage: numpy.array([1, 2, 3]) array([1, 2, 3]) - sage: numpy.array([1, 2, 3]).dtype # optional - numpy + sage: numpy.array([1, 2, 3]).dtype dtype('int32') # 32-bit dtype('int64') # 64-bit - - sage: numpy.array(2**40).dtype # optional - numpy + sage: numpy.array(2**40).dtype dtype('int64') - sage: numpy.array(2**400).dtype # optional - numpy + sage: numpy.array(2**400).dtype dtype('O') - - sage: numpy.array([1,2,3,0.1]).dtype # optional - numpy + sage: numpy.array([1,2,3,0.1]).dtype dtype('float64') """ if mpz_fits_slong_p(self.value): @@ -6241,11 +6259,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 +6396,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 +6425,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 +7049,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 +7091,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_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/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index b4046098436..cb97fec967f 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,21 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ[sqrt(2), sqrt(3)] # optional - sage.rings.number_field sage.symbolic - Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field sage: ZZ['x'] Univariate Polynomial Ring in x over Integer Ring sage: ZZ['x,y'] Multivariate Polynomial Ring in x, y over Integer Ring - sage: R = ZZ[sqrt(5) + 1]; R # optional - sage.rings.number_field sage.symbolic + + sage: # 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() # optional - sage.rings.number_field sage.symbolic + sage: R.is_maximal() False - sage: R = ZZ[(1 + sqrt(5))/2]; R # optional - 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() # optional - sage.rings.number_field sage.symbolic + sage: R.is_maximal() True """ if x in self: @@ -531,7 +533,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 +555,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:: @@ -600,10 +603,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: @@ -718,7 +722,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 # needs sage.modules True TESTS: @@ -727,7 +731,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 # needs sage.modules True sage: ZZ.random_element(5, -5, distribution="mpz_rrandomb").parent() is ZZ True @@ -923,9 +927,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 """ @@ -979,40 +983,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)) 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 @@ -1163,7 +1168,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: @@ -1276,43 +1281,44 @@ 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) # optional - 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) # optional - 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) # optional - 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) # optional - 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) # optional - 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) # optional - sage.libs.pari + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) [100, -5445, 1, -1] - - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - 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") # optional - 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") # 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: 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") # 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() @@ -1465,7 +1471,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' @@ -1521,7 +1527,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ._sympy_() # optional - sympy + sage: ZZ._sympy_() # needs sympy Integers """ from sympy import Integers @@ -1551,9 +1557,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/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/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index e2a5c524cfe..565e5d12f4c 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,23 +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') - sage: K + 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 + sage: loads(K.dumps()) == K # needs sage.rings.real_mpfr True sage: P = QQ[['x']] sage: F = Frac(P) @@ -127,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 @@ -405,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) @@ -442,8 +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 - sage: qexp_eta(S, prec=30) + sage: from sage.modular.etaproducts import qexp_eta # needs sage.modular + sage: S. = LaurentSeriesRing(RationalField()) + 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 @@ -458,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')) # optional - sage.libs.pari + sage: L(pari('1/x')) q^-1 - sage: L(pari('polchebyshev(5)')) # optional - sage.libs.pari + sage: L(pari('polchebyshev(5)')) 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')) -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)')) 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)')) 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)')) -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)')) 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 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)')) O(q^-10) Check that :trac:`30073` is fixed:: @@ -540,8 +544,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 +581,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 +659,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 +695,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 +710,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 8e950478045..52d84e8edb2 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,19 +21,18 @@ We compute with a Laurent series over the complex mpfr numbers. :: - sage: K. = Frac(CC[['q']]) - sage: K + 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 + sage: q # needs sage.rings.real_mpfr 1.00000000000000*q Saving and loading. :: - sage: loads(q.dumps()) == q + sage: loads(q.dumps()) == q # needs sage.rings.real_mpfr True - sage: loads(K.dumps()) == K + sage: loads(K.dumps()) == K # needs sage.rings.real_mpfr True IMPLEMENTATION: Laurent series in Sage are represented internally @@ -114,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) @@ -182,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) @@ -280,21 +280,22 @@ 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) # 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) + 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]) # 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 @@ -668,11 +669,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(): @@ -1598,8 +1600,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 @@ -1701,6 +1703,7 @@ cdef class LaurentSeries(AlgebraElement): sage: (x^-2 + 1 + x).nth_root(2)**2 x^-2 + 1 + x + O(x^18) + sage: # needs sage.modular sage: j = j_invariant_qexp() sage: q = j.parent().gen() sage: j(q^3).nth_root(3) @@ -1752,10 +1755,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, @@ -1775,8 +1779,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: @@ -1837,9 +1841,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: @@ -1879,16 +1883,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 b58e21e655c..aef134a609d 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -83,21 +83,21 @@ 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:: 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: @@ -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)) + sage: check(L, lambda n: n, valuation=-5) + sage: check(L, gen(), valuation=-5) - 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) - 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)) + sage: check(L, lambda n: n, valuation=0) + sage: check(L, gen(), valuation=0) - 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)) + sage: check(L, lambda n: (x + y)^n, valuation=None) # needs sage.rings.finite_rings + sage: def gen(): ....: 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: 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) """ @@ -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)) + sage: f = L(lambda n: n) + sage: f.coefficients(5) [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 = 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)) 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): @@ -1111,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:: @@ -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 # 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]) @@ -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 lrcalc_python sage.combinat O^7 """ @@ -1459,12 +1467,13 @@ 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: # 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: 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: 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: # 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: 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:: @@ -1605,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 # optional - 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 # optional - sage.symbolic + sage: t 1 + 1/(2^z) + 1/(3^z) + O(1/(4^z)) sage: st = s + t - sage: st # optional - 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 # optional - sage.symbolic + sage: rt 0 - sage: r = L([1,2,3]) sage: rt = r + t - sage: rt # optional - 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 # optional - sage.symbolic + sage: rt 2 + 3/2^z + 4/3^z """ P = self.parent() @@ -1821,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 # optional - sage.symbolic + sage: 2 * g 2/2^z - sage: -1 * g # optional - sage.symbolic + sage: -1 * g -1/(2^z) - sage: 0*g # optional - sage.symbolic + sage: 0*g 0 sage: M = L(lambda n: n) - sage: M # optional - 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 # optional - 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 @@ -1955,7 +1963,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 +1979,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 @@ -2002,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 """ @@ -2028,8 +2036,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") # 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 +2062,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") # 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 +2084,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") # 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 +2106,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") # 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 +2128,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") # 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 +2154,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") # 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 @@ -2167,24 +2175,24 @@ 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 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") # 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 +2215,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") # 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 @@ -2230,24 +2238,24 @@ 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 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") # 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 +2281,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") # 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 +2308,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") # 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 @@ -2317,18 +2325,18 @@ 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 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") # 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 @@ -2350,16 +2358,16 @@ 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:: - 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") # 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 @@ -2380,18 +2388,18 @@ 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 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") # 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 @@ -2412,17 +2420,17 @@ 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:: - 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") # 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 +2468,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") # needs sage.symbolic + sage: asinh(z)[0:6] == asinh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ @@ -2498,8 +2506,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") # needs sage.symbolic + sage: atanh(z)[0:6] == atanh(x).series(x, 6).coefficients(sparse=False) # needs sage.symbolic True """ @@ -2533,8 +2541,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") # 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 """ @@ -2622,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 # optional - 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 # optional - 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 # optional - 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 # optional - sage.symbolic + sage: f^3 - Z O(1/(8^s)) sage: L. = LazyLaurentSeriesRing(QQ) @@ -2685,12 +2694,12 @@ def sqrt(self): This also works for Dirichlet series:: + sage: # needs sage.symbolic sage: D = LazyDirichletSeriesRing(SR, "s") sage: Z = D(constant=1) - sage: f = sqrt(Z) - sage: f # optional - sage.symbolic + 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 @@ -2799,6 +2808,7 @@ def _mul_(self, other): Multiplication of series with eventually constant coefficients may yield another such series:: + 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) @@ -2935,8 +2945,8 @@ def __pow__(self, n): We also support the general case:: - sage: L. = LazyLaurentSeriesRing(SR) - sage: (1 + z)^(1 + z) + 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) """ @@ -2996,6 +3006,7 @@ def __invert__(self): We can also compute the multiplicative inverse of a symmetric function:: + sage: # needs sage.modules sage: h = SymmetricFunctions(QQ).h() sage: p = SymmetricFunctions(QQ).p() sage: L = LazySymmetricFunctions(p) @@ -3003,7 +3014,7 @@ def __invert__(self): 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] + sage: (E * ~E)[:6] # needs sage.modules [p[], 0, 0, 0, 0, 0] TESTS:: @@ -3114,9 +3125,9 @@ 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: 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) @@ -3126,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:: @@ -3302,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): @@ -3317,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 @@ -3369,8 +3380,8 @@ 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") # 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) @@ -3501,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) # 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) + 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]) # optional - 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]) # 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]) + 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) """ @@ -3748,7 +3759,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] @@ -3758,7 +3769,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] @@ -3771,11 +3782,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 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 @@ -4545,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 # optional - 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) @@ -4555,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 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 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 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 @@ -5205,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) @@ -5314,6 +5326,7 @@ def xgcd(self, f): sage: g == s * a + t * b True + 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) @@ -5368,6 +5381,7 @@ def _format_series(self, formatter, format_strings=False): TESTS:: + sage: # needs sage.modules sage: h = SymmetricFunctions(ZZ).h() sage: e = SymmetricFunctions(ZZ).e() sage: L = LazySymmetricFunctions(tensor([h, e])) @@ -5443,8 +5457,8 @@ class LazySymmetricFunction(LazyCompletionGradedAlgebraElement): EXAMPLES:: - sage: s = SymmetricFunctions(ZZ).s() - sage: L = LazySymmetricFunctions(s) + sage: s = SymmetricFunctions(ZZ).s() # needs sage.modules + sage: L = LazySymmetricFunctions(s) # needs sage.modules """ def is_unit(self): """ @@ -5452,21 +5466,17 @@ def is_unit(self): EXAMPLES:: + 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() True - sage: L(2 + m[1]).is_unit() False - sage: m = SymmetricFunctions(QQ).m() sage: L = LazySymmetricFunctions(m) - sage: L(2 + 3*m[1]).is_unit() True """ @@ -5510,6 +5520,7 @@ def __call__(self, *args, check=True): EXAMPLES:: + sage: # needs sage.modules sage: P. = QQ[] sage: s = SymmetricFunctions(P).s() sage: L = LazySymmetricFunctions(s) @@ -5517,15 +5528,12 @@ def __call__(self, *args, check=True): sage: g = s[3] sage: L(f)(L(g)) - L(f(g)) 0 - 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)) 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)) @@ -5534,6 +5542,7 @@ def __call__(self, *args, check=True): The Frobenius character of the permutation action on set partitions is a plethysm:: + sage: # needs sage.modules sage: s = SymmetricFunctions(QQ).s() sage: S = LazySymmetricFunctions(s) sage: E1 = S(lambda n: s[n], valuation=1) @@ -5544,6 +5553,7 @@ def __call__(self, *args, check=True): The plethysm with a tensor product is also implemented:: + sage: # needs sage.modules sage: s = SymmetricFunctions(QQ).s() sage: X = tensor([s[1],s[[]]]) sage: Y = tensor([s[[]],s[1]]) @@ -5551,14 +5561,14 @@ 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]) - sage: H(S2(X*Y)) + sage: H = S(lambda n: s[n]) # 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)) + 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[]) @@ -5568,22 +5578,23 @@ def __call__(self, *args, check=True): TESTS:: + 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 + 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): @@ -5593,6 +5604,7 @@ def __call__(self, *args, check=True): Check that composing the zero series with anything yields zero in the correct parent:: + sage: # needs sage.modules sage: e = SymmetricFunctions(QQ).e() sage: h = SymmetricFunctions(QQ).h() sage: s = SymmetricFunctions(QQ).s() @@ -5605,10 +5617,10 @@ def __call__(self, *args, check=True): 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]])) # needs sage.modules + sage: f(0, 0) # needs sage.modules 0 - sage: (3+f)(0, 0) + sage: (3+f)(0, 0) # needs sage.modules 3 """ fP = parent(self) @@ -5695,6 +5707,7 @@ def revert(self): EXAMPLES:: + sage: # needs sage.modules sage: h = SymmetricFunctions(QQ).h() sage: L = LazySymmetricFunctions(h) sage: f = L(lambda n: h[n]) - 1 @@ -5703,30 +5716,28 @@ def revert(self): 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] # 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: # 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]) sage: f.revert() 1/2*p[1] - 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) p[1] + O^8 @@ -5820,6 +5831,7 @@ def derivative_with_respect_to_p1(self, n=1): The species `E` of sets satisfies the relationship `E' = E`:: + sage: # needs sage.modules sage: h = SymmetricFunctions(QQ).h() sage: T = LazySymmetricFunctions(h) sage: E = T(lambda n: h[n]) @@ -5829,14 +5841,17 @@ def derivative_with_respect_to_p1(self, n=1): The species `C` of cyclic orderings and the species `L` of linear orderings satisfy the relationship `C' = L`:: + 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: 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:: + sage: # needs sage.modules sage: T = LazySymmetricFunctions(p) sage: a = T(p([1,1,1])) sage: a.derivative_with_respect_to_p1() @@ -5899,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() 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: P.functorial_composition(P2)[:4] # needs sage.libs.pari [m[], m[1], (q+1)*m[1, 1] + (q+1)*m[2], @@ -5913,12 +5929,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] # 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] + 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. @@ -5926,6 +5942,7 @@ def functorial_composition(self, *args): The symmetric function `h_1 \sum_n h_n` is the neutral element with respect to functorial composition:: + sage: # needs sage.modules sage: p = SymmetricFunctions(QQ).p() sage: h = SymmetricFunctions(QQ).h() sage: e = SymmetricFunctions(QQ).e() @@ -5934,35 +5951,37 @@ 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:: + 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 + sage: (F1 + F2).functorial_composition(f) - f1 - f2 # long time 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() # needs sage.modules + sage: L = LazySymmetricFunctions(h) # 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:: + 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] + 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 @@ -6111,14 +6130,15 @@ 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: 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 + 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]) @@ -6128,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)] + 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 @@ -6136,7 +6156,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)] # needs sage.modules [1, 3, 8, 42, 144, 1440, 5760] AUTHORS: @@ -6151,6 +6171,7 @@ def arithmetic_product(self, *args, check=True): Check that the product with zero works:: + sage: # needs sage.modules sage: s = SymmetricFunctions(QQ).s() sage: L = LazySymmetricFunctions(s) sage: L(0).arithmetic_product(s[2]) @@ -6161,27 +6182,27 @@ def arithmetic_product(self, *args, check=True): 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])) # 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])) - sage: f.arithmetic_product(s[1]) - f + sage: f = 1/(1-L(s[1])) # 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 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() # 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() - sage: L = LazySymmetricFunctions(s) - sage: L(s([2])).arithmetic_product(s([1,1,1])) + 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,6 +6299,7 @@ def symmetric_function(self, degree=None): EXAMPLES:: + sage: # needs sage.modules sage: s = SymmetricFunctions(QQ).s() sage: S = LazySymmetricFunctions(s) sage: elt = S(s[2]) @@ -6286,28 +6308,30 @@ def symmetric_function(self, degree=None): TESTS:: + 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) - 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): ... ValueError: not a symmetric function - sage: f4 = f.truncate(5); f4 + sage: # needs sage.modules + 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[] """ @@ -6337,15 +6361,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) + 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,14 +6409,14 @@ def valuation(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, "z") - sage: mu = L(moebius); mu.valuation() + sage: mu = L(moebius); mu.valuation() # needs sage.libs.pari 0 - sage: (mu - mu).valuation() + 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): @@ -6412,36 +6436,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)] + 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) - 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 @@ -6489,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 @@ -6539,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) @@ -6555,7 +6580,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 @@ -6573,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() @@ -6623,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) # optional - sage.symbolic + sage: f._format_series(repr) '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) -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) '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) -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) ( -s) (3 ) ( -s ) (---) @@ -6649,9 +6672,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 32545f65574..9670b391073 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') + sage: L(2) 0 - sage: L(3) # optional - 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] @@ -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:: @@ -400,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:: @@ -712,9 +713,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() # 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() - sage: L = LazySymmetricFunctions(s) - sage: L.zero() + 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 Lazy Laurent Series Ring in w over Finite Field of size 11 - sage: R.characteristic() # optional - sage.rings.finite_rings + sage: R.characteristic() 11 - sage: R. = LazyPowerSeriesRing(GF(7)); R # optional - 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() # optional - sage.rings.finite_rings + sage: R.characteristic() 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') + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # optional - 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) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(R) 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') + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) 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: # 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.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() + 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') + sage: TestSuite(L).run() - 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') + sage: TestSuite(L).run() - 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') + sage: TestSuite(L).run() 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) - sage: L = LazyLaurentSeriesRing(E, 't') # not tested + 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') 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') + sage: latex(L) \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') + 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') # optional - sage.rings.finite_rings - sage: L.some_elements()[:7] # optional - 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, @@ -1559,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: @@ -1603,13 +1606,13 @@ 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)] # needs sage.libs.flint True 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: @@ -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') + sage: TestSuite(L).run() - 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') + sage: TestSuite(L).run(skip=['_test_fraction_field']) 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') 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') + sage: latex(L) \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') + sage: L(2) 0 - sage: L(3) # optional - sage.rings.finite_rings + sage: L(3) 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) + 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) + 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') + 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') # optional - sage.rings.finite_rings - sage: L.some_elements()[:6] # optional - 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, @@ -2237,17 +2240,16 @@ class LazyCompletionGradedAlgebra(LazySeriesRing): EXAMPLES:: + sage: # needs sage.modules 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: 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: L = S.formal_series_ring(); L + Lazy completion of Non-Commutative Symmetric Functions + over the Rational Field in the Complete basis + 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 S[] + S[2] + (S[2,2]) + (S[2,2,2]) + O^7 sage: f * g S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[1,2]) @@ -2272,23 +2274,23 @@ def __init__(self, basis, sparse=True, category=None): sage: LazySymmetricFunctions.options.halting_precision(6) + 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() - 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 - Reversion will only work when the base ring is a field:: + sage: # needs sage.modules sage: s = SymmetricFunctions(ZZ).s() sage: L = LazySymmetricFunctions(s) - sage: TestSuite(L).run(skip=['_test_revert']) - + 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']) + sage: TestSuite(L).run(skip=['_test_revert']) # needs lrcalc_python Options are remembered across doctests:: @@ -2297,15 +2299,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() # 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() - sage: L = LazySymmetricFunctions(ht) + 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 @@ -2344,8 +2346,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() # 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) @@ -2356,9 +2358,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() # 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 @@ -2370,6 +2372,7 @@ def _monomial(self, c, n): EXAMPLES:: + sage: # needs sage.modules sage: m = SymmetricFunctions(ZZ).m() sage: s = SymmetricFunctions(ZZ).s() sage: L = LazySymmetricFunctions(m) @@ -2395,18 +2398,19 @@ 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: # needs sage.modules + sage: m = SymmetricFunctions(GF(2)).m() + sage: L = LazySymmetricFunctions(m) + sage: L(2) 0 - sage: L(3) # optional - sage.rings.finite_rings + sage: L(3) m[] + 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) m[6] sage: f[20] @@ -2416,11 +2420,12 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No 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 # needs sage.modules m[1] + m[2] + m[3] Finally, ``x`` can be a symmetric function:: + sage: # needs sage.modules sage: m = SymmetricFunctions(ZZ).m() sage: s = SymmetricFunctions(ZZ).s() sage: L = LazySymmetricFunctions(m) @@ -2429,29 +2434,31 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No TESTS:: + 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: # 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]; 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]); 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); 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 +2573,9 @@ def _an_element_(self): EXAMPLES:: - sage: m = SymmetricFunctions(ZZ).m() - sage: L = LazySymmetricFunctions(m) - sage: L.an_element() + 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()) @@ -2579,9 +2586,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() # 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]) @@ -2590,6 +2597,7 @@ 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: # needs sage.modules sage: NCSF = NonCommutativeSymmetricFunctions(QQ) sage: S = NCSF.Complete() sage: L = S.formal_series_ring() @@ -2632,13 +2640,15 @@ class LazySymmetricFunctions(LazyCompletionGradedAlgebra): EXAMPLES:: - sage: s = SymmetricFunctions(ZZ).s() - sage: LazySymmetricFunctions(s) + 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() - 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() # 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 """ Element = LazySymmetricFunction @@ -2724,7 +2734,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 @@ -2739,10 +2749,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() # needs sage.symbolic sage: L = LazyDirichletSeriesRing(QQ, 't') - sage: TestSuite(L).run() + sage: TestSuite(L).run() # needs sage.symbolic sage: LazyDirichletSeriesRing.options._reset() # reset the options @@ -2770,7 +2780,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()) @@ -2783,9 +2793,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() @@ -2824,31 +2834,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() + sage: X.valuation() # needs sage.symbolic 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. @@ -2858,44 +2868,44 @@ 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') 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 # optional - sage.symbolic + 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)) 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 = 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)) 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 = 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)): @@ -2941,7 +2951,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() @@ -2955,7 +2965,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, @@ -2964,7 +2974,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, @@ -2986,8 +2996,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 # needs sage.symbolic 5/3^z """ try: @@ -3007,11 +3016,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 3062c9439d8..20c090da681 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]]) # optional - sage.modules - sage: m.parent() # optional - 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__ # optional - sage.modules + sage: ~m # parent of inverse is different: see documentation of m.__invert__ [ 1/5 -7/55] [ 0 1/11] - sage: _.parent() # optional - sage.modules + sage: _.parent() 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) + sage: mi.parent() Full MatrixSpace of 2 by 2 dense matrices over Integer Ring localized at (5, 11) - sage: mi == ~m # optional - sage.modules + sage: mi == ~m True The next example defines the most general ring containing the coefficients of the irreducible @@ -34,48 +35,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.libs.pari sage.modules + sage: Fp = GF(17) + 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, @@ -85,24 +89,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 [5 0 0] [0 3 0] [0 0 3] - sage: mFp1.base_ring() # optional - sage.modules sage.rings.finite_rings + sage: mFp1.base_ring() 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 [ 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 [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 +117,28 @@ 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: # 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() # optional - 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 # optional - 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 # optional - 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() # optional - sage.libs.singular - sage: fF = L.hom((x, y, z, t), codomain=F); fF # optional - 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, @@ -141,16 +149,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.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.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 +207,24 @@ 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: # needs sage.libs.singular 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) + sage: p = b**2 - 5 + sage: p == (b-a)*(b+a) True - sage: normalize_extra_units(Q, [p]) # optional - sage.libs.pari + 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) # optional - sage.libs.pari + sage: normalize_extra_units(Q, [p], warning=False) # needs sage.libs.pari [b^2 - 5] """ # convert to base ring @@ -250,13 +261,15 @@ class LocalizationElement(IntegralDomainElement): EXAMPLES:: + sage: # needs sage.libs.pari 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 +280,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) # 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,15 +294,16 @@ def _repr_(self): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: from sage.rings.localization import LocalizationElement sage: P. = CC[] - sage: L = Localization(P, x**2+x+1) + 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[] - sage: L. = R.localization(X-Y) + sage: L. = R.localization(X - Y) sage: x*y/(x-y) x*y/(x - y) """ @@ -391,8 +405,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 +425,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) @@ -448,13 +462,14 @@ def is_unit(self): EXAMPLES:: + sage: # needs sage.libs.pari sage.singular 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)) + sage: L(y*z).is_unit() True - sage: L(z).is_unit() # optional - sage.libs.pari + sage: L(z).is_unit() True - sage: L(x*y*z).is_unit() # optional - 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() @@ -467,9 +482,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 +496,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.libs.singular + 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 +534,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 +617,43 @@ 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: # needs sage.libs.pari sage: R. = ZZ[] - sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari + sage: L = R.localization(x**2 + 1) sage: s = (x+5)/(x**2+1) - sage: s in L # optional - sage.libs.pari + sage: s in L 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) 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 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) + 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 # optional - sage.libs.pari + sage: f = (y+5)/(y**2+1); f (x + 5)/(x^2 + 1) - sage: f == g # optional - sage.libs.pari + sage: f == g True - sage: (y+5)/(y**2+2) # optional - 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 - 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 +679,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 +720,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.libs.pari Univariate Polynomial Ring in a over Finite Field of size 3 localized at (a + 1, a + 2) """ @@ -735,13 +752,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,) @@ -750,23 +767,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) # optional - 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) # optional - 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) # optional - 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) # optional - sage.libs.pari + sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) True """ B = self.base_ring() @@ -798,7 +814,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 +830,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 +846,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 +870,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: @@ -896,17 +912,18 @@ def _fraction_to_element(self, x): EXAMPLES:: + sage: # needs sage.libs.pari sage.libs.singular 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) + sage: L._fraction_to_element((x+y+z)/d) (x + y + z)/(x^2 + y^2 + z^2) - sage: _ in L # optional - sage.libs.pari + sage: _ in L True TESTS:: - sage: TestSuite(L).run() # optional - sage.libs.pari + 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(): @@ -922,6 +939,7 @@ 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)) @@ -954,11 +972,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.libs.pari + 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 +988,10 @@ 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: # needs sage.libs.pari + sage: R. = GF(5)[] + sage: L = R.localization((a**2 - 3, a)) + sage: L.characteristic() 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 ba341f7f93a..797445e78eb 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()) @@ -98,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)) sage: phi = S.hom([a^2, -b]) @@ -125,8 +127,7 @@ 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 @@ -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,25 +183,27 @@ We next compose the inclusion with reduction from the integers to From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: a = f(5); a # 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: # needs sage.libs.pari sage: R. = PolynomialRing(QQ) sage: S. = R.quo(x^2 - 2) sage: sqrt2^2 @@ -211,12 +216,13 @@ An automorphism of a quotient of a univariate polynomial ring:: Note that Sage verifies that the morphism is valid:: - sage: (1 - sqrt2)^2 + sage: (1 - sqrt2)^2 # needs 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 # needs 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:: @@ -232,19 +238,19 @@ 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: 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:: @@ -270,14 +276,17 @@ 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:: + 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 @@ -293,6 +302,7 @@ 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) sage: alpha = RR(2)^(1/3); alpha @@ -311,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 @@ -324,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:: @@ -337,51 +347,51 @@ 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: 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)) @@ -467,14 +477,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 @@ -484,10 +494,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] """ @@ -507,9 +518,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 @@ -652,14 +663,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 """ @@ -674,7 +685,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' """ @@ -787,17 +798,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 @@ -822,21 +833,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) # 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) + 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 # optional - 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))) # optional - 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:: @@ -905,8 +917,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) """ @@ -939,18 +951,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 @@ -958,27 +970,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.rings.number_field + sage: S. = QQ['u,v'].quotient('v^2 - 2') + sage: f = QuadraticField(2).hom([v], S) + sage: I = S.ideal(u + v) + sage: J = f.inverse_image(I) + sage: J.is_zero() True - sage: f(J) < I # optional - sage.libs.singular sage.rings.number_field + sage: f(J) < I 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: @@ -992,7 +1006,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 @@ -1000,7 +1014,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 @@ -1020,13 +1034,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: @@ -1034,17 +1049,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 @@ -1086,36 +1101,38 @@ 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: # needs sage.libs.singular 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)) + 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) # optional - sage.libs.singular + sage: g.inverse_image(d^2) x - sage: g.inverse_image(d^3) # optional - sage.libs.singular + sage: g.inverse_image(d^3) 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)) + 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`):: - 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() @@ -1135,7 +1152,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 @@ -1144,18 +1161,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 @@ -1163,30 +1180,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 @@ -1261,32 +1279,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 @@ -1343,24 +1363,25 @@ 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 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() # optional - sage.libs.singular + sage: f.inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: f.is_injective() # optional - sage.libs.singular + sage: f.is_injective() 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) + 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 @@ -1371,24 +1392,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:: @@ -1396,13 +1417,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 @@ -1426,81 +1447,85 @@ 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: Morphisms involving quotient rings:: + sage: # needs sage.libs.singular 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') + sage: f = R.hom([s, -t], S) + sage: (f.inverse() * f).is_identity() 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) + 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) # 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) + sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w 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 @@ -1508,9 +1533,10 @@ 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() # optional - sage.libs.singular + sage: S.hom([x, y, 0], R).inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1519,42 +1545,42 @@ cdef class RingHomomorphism(RingMap): 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]) + sage: R.hom([u, v], Q).inverse() Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q.cover().inverse() # optional - sage.libs.singular + sage: Q.cover().inverse() 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 @@ -1581,11 +1607,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(): @@ -1605,9 +1631,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() @@ -1619,10 +1645,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: @@ -1643,10 +1669,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: @@ -1788,12 +1814,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 @@ -1801,12 +1827,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) # 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) + 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:: @@ -1826,8 +1853,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 @@ -1889,21 +1916,22 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: + sage: # needs sage.rings.number_field 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) + 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) # optional - sage.rings.number_field + sage: phi(y) y^2 - sage: phi(i*y) # optional - sage.rings.number_field + sage: phi(i*y) -i*y^2 - sage: phi.base_map() # optional - 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 @@ -1965,52 +1993,53 @@ 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) # 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) + sage: f1 = R.hom([a]) + sage: f2 = R.hom([a + a^2 + a + 1]) + sage: f1 == f2 True - sage: f1 == R.hom([a^2]) # optional - sage.libs.pari + sage: f1 == R.hom([a^2]) False - sage: f1(x^3 + x) # optional - sage.libs.pari + sage: f1(x^3 + x) a + 1 - sage: f2(x^3 + x) # optional - sage.libs.pari + sage: f2(x^3 + x) 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: 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`:: @@ -2119,12 +2148,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 @@ -2136,19 +2166,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 @@ -2166,7 +2197,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] """ @@ -2179,9 +2210,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 @@ -2192,8 +2223,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) @@ -2215,13 +2246,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) # 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) + sage: MS = MatrixSpace(S, 2) + sage: g = MR.hom(f, MS) + sage: g.underlying_map() == f True """ return self._underlying @@ -2294,20 +2326,21 @@ 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) # 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) + sage: f1 = R.hom([a]) + sage: f2 = R.hom([a + a^2 + a + 1]) + sage: PR. = R[] + sage: PQ = Q['s','t'] + sage: f1P = PR.hom(f1,PQ) + sage: f2P = PR.hom(f2,PQ) + sage: f1P == f2P 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]) @@ -2320,20 +2353,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.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) + 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)) # optional - sage.rings.finite_rings sage.modules + sage: f1M == loads(dumps(f1M)) # needs sage.modules True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2354,9 +2388,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 @@ -2404,11 +2438,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 @@ -2420,7 +2454,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()) @@ -2434,8 +2468,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): @@ -2444,11 +2478,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) # 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) + 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 @@ -2463,11 +2498,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() @@ -2483,10 +2518,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()) @@ -2497,13 +2532,14 @@ 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() # optional - sage.libs.singular + sage: f = S.hom([x + 1]).extend_to_fraction_field() - 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'] @@ -2516,8 +2552,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) @@ -2533,8 +2569,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 @@ -2549,14 +2585,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): @@ -2641,12 +2677,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) # 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) + sage: phi = S.cover() + sage: phi == loads(dumps(phi)) True - sage: phi == R.quo(x^2 + y^3).cover() # optional - sage.libs.singular + sage: phi == R.quo(x^2 + y^3).cover() False """ if not isinstance(other, RingHomomorphism_cover): @@ -2661,14 +2698,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) # 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) + sage: phi = S.cover() + sage: type(phi) - sage: hash(phi) == hash(phi) # optional - sage.libs.singular + sage: hash(phi) == hash(phi) True - sage: {phi: 1}[phi] # optional - sage.libs.singular + sage: {phi: 1}[phi] 1 """ return hash((self.domain(), self.codomain())) @@ -2683,12 +2721,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 """ @@ -2703,8 +2742,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() @@ -2732,24 +2771,25 @@ 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) # 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) + 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) # optional - sage.libs.singular + sage: phi(a + b + c) a + b + c - sage: loads(dumps(phi)) == phi # optional - sage.libs.singular + sage: loads(dumps(phi)) == phi 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 @@ -2761,7 +2801,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 @@ -2788,22 +2828,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) # 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) + 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) # optional - sage.libs.singular + sage: phi(a + b + c) 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 + sage: psi == phi True - sage: psi is phi # optional - sage.libs.singular + sage: psi is phi False - sage: psi(a) == phi(a) # optional - sage.libs.singular + sage: psi(a) == phi(a) True """ @@ -2816,22 +2857,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) # 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) + 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) # optional - sage.libs.singular + sage: phi(a + b + c) 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 + sage: psi == phi True - sage: psi is phi # optional - sage.libs.singular + sage: psi is phi False - sage: psi(a) == phi(a) # optional - sage.libs.singular + sage: psi(a) == phi(a) True """ slots = RingHomomorphism._extra_slots(self) @@ -2845,8 +2887,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) @@ -2862,8 +2904,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 @@ -2879,14 +2921,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): @@ -2903,14 +2946,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) @@ -2921,9 +2965,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 """ @@ -2938,8 +2982,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)) @@ -2966,11 +3010,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 """ @@ -2999,10 +3043,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() @@ -3019,16 +3064,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: # 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 # optional - 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 # optional - sage.rings.finite_rings + sage: phi == psi True """ slots = RingHomomorphism._extra_slots(self) @@ -3041,12 +3086,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' """ @@ -3065,11 +3110,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: @@ -3086,9 +3132,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: @@ -3103,11 +3149,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 @@ -3120,11 +3167,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 @@ -3135,11 +3183,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 """ @@ -3151,14 +3199,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 """ @@ -3200,15 +3249,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 410de0bbff0..fe7ca905fc7 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) + 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: # 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) # optional - sage.symbolic + sage: type(x) - sage: type(S(x)) # optional - 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 # optional - 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() # optional - 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 # optional - sage.rings.finite_rings sage.symbolic + sage: f.parent() == S True The implementation of the multivariate power series ring uses a combination @@ -390,11 +391,11 @@ def _repr_(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings - sage: R #indirect doctest # optional - 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 +480,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 +544,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) # 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 +556,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 +577,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 +635,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:: @@ -708,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) # 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) + 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])) # optional - sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) 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 9aa3f6ea5a4..eb41c15586c 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -252,42 +252,42 @@ class MPowerSeries(PowerSeries): sage: g = 1 + s + t - s*t + S.O(5); g 1 + s + t - s*t + O(s, t)^5 - - 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 - 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) + 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 # optional - 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 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 +314,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 +451,21 @@ 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: # needs sage.rings.number_field 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) + 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) # optional - 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(): @@ -512,33 +513,33 @@ 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) - sage: f(z,RF(1)) #indirect doctest + 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]]) - sage: m + 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 + 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 + 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) + 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 @@ -567,14 +568,14 @@ def _value(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R # optional - 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) @@ -603,15 +604,15 @@ def _latex_(self): EXAMPLES:: - sage: M = PowerSeriesRing(GF(5),3,'t'); M # optional - 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}' @@ -709,30 +710,30 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R # optional - 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: 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) @@ -891,27 +892,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 # optional - 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 # optional - sage.libs.singular + sage: f == q*g + r 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 (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 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 (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 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 (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 True Trying to divide two polynomials, we run into the issue that @@ -920,61 +919,58 @@ 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: # 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) # optional - 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) # optional - 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) # optional - 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)) # optional - 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)) # optional - 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) # optional - 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) # optional - 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) # optional - 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) # optional - 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) # optional - 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) # optional - 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()) # optional - sage.libs.singular + 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)) # optional - sage.libs.singular + 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) # optional - sage.libs.singular + 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) - 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() @@ -1038,30 +1034,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 @@ -1084,7 +1080,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)): @@ -1159,14 +1155,14 @@ def variables(self): EXAMPLES:: - 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 - 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()) @@ -1396,16 +1392,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: @@ -1898,13 +1895,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) 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() 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) 1 + a + b + O(a, b)^2 - sage: log(exp(f)) - f # optional - sage.symbolic + sage: log(exp(f)) - f 0 + O(a, b)^3 If the power series has a constant coefficient `c` and @@ -1913,7 +1910,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) Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and @@ -1923,7 +1920,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)) 7.38905609... + 7.38905609...*a + 7.38905609...*b + 3.69452804...*a^2 + 14.7781121...*a*b + 3.69452804...*b^2 + O(a, b)^3 @@ -1931,17 +1928,17 @@ def exp(self, prec=infinity): sage: T.default_prec() 12 - sage: exp(a) # optional - 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) 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)) 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)) 1 + a^2 + 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1990,11 +1987,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() 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) 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 0 + O(a, b)^5 If the power series has a constant coefficient `c` and @@ -2002,8 +1999,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) Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for -: 'Symbolic Ring' and 'Power @@ -2012,7 +2009,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)) 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 @@ -2021,17 +2018,17 @@ def log(self, prec=infinity): TESTS:: - sage: (1+a).log(prec=10).exp() # optional - sage.symbolic + sage: (1+a).log(prec=10).exp() 1 + a + O(a, b)^10 - sage: a.exp(prec=10).log() # optional - sage.symbolic + sage: a.exp(prec=10).log() a + O(a, b)^10 - sage: log(1+a) # optional - 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)) # optional - 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) # 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/noncommutative_ideals.pyx b/src/sage/rings/noncommutative_ideals.pyx index af27882313d..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 @@ -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/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 27e33ad5be0..4cf97ff4efd 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -2941,32 +2941,33 @@ 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: b = SR(a); b # indirect doctest # needs sage.symbolic + 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 0 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 @@ -2974,7 +2975,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 @@ -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/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 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/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 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 acaea2e3a16..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 + 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_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/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 7c93168d4b1..c2c1436d388 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 # needs 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 # needs sage.rings.real_mpfr True sage: R. = QQ[[]] @@ -34,9 +33,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)')) # needs sage.libs.pari 1 + O(T) - sage: R(pari('1/T + O(T)')) + sage: R(pari('1/T + O(T)')) # needs sage.libs.pari Traceback (most recent call last): ... ValueError: series has negative valuation @@ -105,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 @@ -159,12 +158,12 @@ 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: 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 @@ -225,17 +224,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 @@ -248,7 +247,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 @@ -268,18 +267,18 @@ 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: 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) 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) 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) """ P = self.parent() @@ -375,27 +374,27 @@ 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: 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: 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) + sage: g._unsafe_mutate(1,0); g O(t^7) """ self.__f._unsafe_mutate(i, value) @@ -435,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) @@ -554,9 +553,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) @@ -567,9 +566,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) @@ -597,11 +596,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: @@ -733,10 +733,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: @@ -764,10 +764,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), @@ -845,8 +845,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 @@ -891,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 @@ -1035,10 +1035,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: @@ -1191,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) # optional - 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() # optional - sage.symbolic + sage: SR(s).is_terminating_series() False - sage: SR(s).variables() # optional - 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) # optional - sage.symbolic + sage: SR(s) 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: _.is_terminating_series() # optional - sage.symbolic + sage: _.is_terminating_series() True TESTS: @@ -1212,7 +1213,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..8bf2d900f45 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 @@ -97,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: @@ -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,11 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, commutative ring, but also a complete discrete valuation ring (CDVR). The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) # optional - sage.rings.finite_rings - sage: R. = k[[]] # optional - sage.rings.finite_rings - sage: R.category() # optional - 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 +616,13 @@ def _repr_(self): EXAMPLES:: - sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings - sage: R # optional - 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 +662,11 @@ 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: 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 +680,14 @@ 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: 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 +760,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 +893,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 +983,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 +1005,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 +1236,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 +1333,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 54314d538ed..52c4cf782d8 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') + 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,11 @@ 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: 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 +521,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 +799,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,6 +845,7 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: + 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 9.869604401089358 + 0.0*m + 0.0*m^2 + 1.0*m^3 + 2.718281828459045*m^4 + O(m^10) @@ -1104,9 +1105,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 +1195,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 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 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 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 +1214,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) + sage: f >> 3 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 O(x^0) - sage: f >> 99 # optional - sage.libs.pari + sage: f >> 99 O(x^0) - sage: (f >> 99) << 99 # optional - sage.libs.pari + sage: (f >> 99) << 99 O(x^99) """ return self.shift(-n) @@ -1266,9 +1269,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 +1281,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') + 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() @@ -1336,13 +1339,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 +1404,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 +1560,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 +1767,11 @@ 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: 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 +1842,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 +1860,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 +1869,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 +1927,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 +1945,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 +1954,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 +2013,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 +2031,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 +2040,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 +2077,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 +2095,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 +2105,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 +2166,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 +2184,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 +2194,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 +2254,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 +2272,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 +2282,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 +2514,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 +2790,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 27a91d6a187..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 - sage: y^(1/24)*qexp_eta(P, prec=30) + 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..503d11ee975 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' @@ -218,10 +218,11 @@ 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]) - sage: t in QQbar + sage: t in QQbar True sage: f = R.hom([QQbar(2)], check=False) sage: t == f(p) @@ -241,8 +242,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 +301,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 +439,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) @@ -1018,6 +1019,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..ed3b1071b04 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,6 +109,7 @@ We can convert from symbolic expressions:: + sage: # needs sage.symbolic sage: QQbar(sqrt(-5)) 2.236067977499790?*I sage: AA(sqrt(2) + sqrt(3)) @@ -133,9 +134,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 +203,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 +263,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 +334,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,21 +386,19 @@ sage: loads(dumps(QQbar.zeta(5))) == QQbar.zeta(5) True + sage: # needs sage.symbolic sage: t = QQbar(sqrt(2)); type(t._descr) sage: loads(dumps(t)) == QQbar(sqrt(2)) True - sage: t.exactify(); type(t._descr) sage: loads(dumps(t)) == QQbar(sqrt(2)) True - sage: t = ~QQbar(sqrt(2)); type(t._descr) sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) True - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) @@ -418,7 +419,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 +669,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 +789,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 +797,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 +808,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 +816,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 +827,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 +836,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 +847,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 +856,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 +880,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 +1100,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 +1109,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 +1190,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 +1635,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 +1697,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,7 +2579,11 @@ 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)] + [(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: # needs sage.symbolic sage: rt2 = AA(sqrt(2)); rt2 1.414213562373095? sage: rt3 = AA(sqrt(3)); rt3 @@ -2582,15 +2598,15 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal 1.414213562373095? sage: rt2c = z3 + rt2 - z3; rt2c 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: + (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: + (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 +2615,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 +2632,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 +2658,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 +2669,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,38 +2714,50 @@ 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 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? 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,6 +3499,8 @@ def is_simple(self): sage: from sage.rings.qqbar import ANRational sage: ANRational(1/2).is_simple() True + + sage: # needs sage.symbolic sage: rt2 = AA(sqrt(2)) sage: rt3 = AA(sqrt(3)) sage: rt2b = rt3 + rt2 - rt3 @@ -3480,9 +3525,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 +3538,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 +3551,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 +3564,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 +3580,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 +3596,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 +3613,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 +3680,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 +3740,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 +3858,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 +3869,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 +3888,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 +3918,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 +3938,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 +3974,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,6 +4048,8 @@ 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: # 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) @@ -4315,8 +4362,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 +4416,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 +4429,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 +4496,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 +4750,29 @@ def radical_expression(self): EXAMPLES:: - sage: AA(1/sqrt(5)).radical_expression() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: AA(1/sqrt(5)).radical_expression() sqrt(1/5) - sage: AA(sqrt(5 + sqrt(5))).radical_expression() # optional - sage.symbolic + sage: AA(sqrt(5 + sqrt(5))).radical_expression() sqrt(sqrt(5) + 5) - sage: QQbar.zeta(5).radical_expression() # optional - 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() # optional - sage.symbolic + sage: a.radical_expression() 1.112775684278706? - sage: a.radical_expression().parent() == SR # optional - 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() # optional - sage.symbolic + sage: a.radical_expression() -0.3636235193291805? - 0.9525611952610331?*I - sage: QQbar.zeta(5).imag().radical_expression() # optional - sage.symbolic + sage: QQbar.zeta(5).imag().radical_expression() 1/2*sqrt(1/2*sqrt(5) + 5/2) - sage: AA(5/3).radical_expression() # optional - sage.symbolic + sage: AA(5/3).radical_expression() 5/3 - sage: AA(5/3).radical_expression().parent() == SR # optional - sage.symbolic + sage: AA(5/3).radical_expression().parent() == SR True - sage: QQbar(0).radical_expression() # optional - sage.symbolic + sage: QQbar(0).radical_expression() 0 TESTS: @@ -4729,15 +4783,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 +4820,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 +4945,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) False - sage: GF(7)(2) in QQbar # optional - sage.rings.finite_rings + sage: GF(7)(2) in QQbar 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) True sage: QQbar.zeta(3).real() == -1/2 @@ -4926,13 +4982,13 @@ def _richcmp_(self, other, op): Check that :trac:`29220` is fixed:: + sage: # needs sage.symbolic sage: a = AA(2**(1/2) - 2**(1/3)) sage: b = 808620184/5240825825 sage: a < b True sage: a < b True - sage: a = AA(2^(1/3)) sage: r = 3085094589/2448641198 sage: a < r @@ -5000,7 +5056,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 +5075,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 +5092,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 +5105,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 +5118,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,6 +5137,8 @@ def _integer_(self, ZZ=None): Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real + + sage: # needs sage.symbolic sage: QQbar(sqrt(17))._integer_() Traceback (most recent call last): ... @@ -5108,6 +5166,8 @@ def _rational_(self): Traceback (most recent call last): ... ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real + + sage: # needs sage.symbolic sage: QQbar(sqrt(2))._rational_() Traceback (most recent call last): ... @@ -5191,10 +5251,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 +5334,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 +5360,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 +5394,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 +5431,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 +5447,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 +5468,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 +5494,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 +5515,31 @@ 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 + sage: z == 0 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 + sage: b = x1 - x2 + sage: a == b True """ if self is other: @@ -5552,11 +5613,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 +5675,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 +5686,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 +5698,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 +5713,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 +5728,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 +5749,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 +5772,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 +5788,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 +5802,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 +5878,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 +5889,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 +5996,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 +6133,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 +6152,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 +6722,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 +6739,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 +7147,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 +7549,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 +7814,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 +7840,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 +7936,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 +7975,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 +8002,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 +8029,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 +8043,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 +8069,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 +8091,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,13 +8109,15 @@ 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: # 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 # optional - 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() @@ -8094,7 +8167,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 +8180,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 +8281,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 +8299,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 +8357,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 +8424,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 +8438,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 +8488,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 +8562,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 +8574,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 +8594,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 +8680,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 +8834,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/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 178cae67a22..1b3086aaab8 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,18 +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.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') + 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.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 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 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) + sage: Q2.is_commutative() True """ @@ -177,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)) # optional - sage.libs.pari - sage: R # optional - 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() # optional - sage.libs.pari + sage: R.gens(); R.gen() (xx,) xx - sage: for n in range(4): xx^n # optional - sage.libs.pari + sage: for n in range(4): xx^n 1 xx -1 @@ -193,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)) # optional - sage.libs.pari - sage: S # optional - 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() # optional - sage.libs.pari + sage: xbar = S.gen(); S.gen() xbar - sage: for n in range(3): xbar^n # optional - sage.libs.pari + sage: for n in range(3): xbar^n 1 xbar 2 @@ -208,7 +215,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 @@ -217,17 +224,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)) # 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)) + 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() # optional - sage.libs.pari + sage: R.gens(); S.gens(); T.gens() (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 1 d -1 @@ -246,23 +254,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.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: # 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.modules + sage: a*b -b*c - sage: a^3 # optional - sage.combinat 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.modules - sage: R. = Q.quo(J); R # optional - sage.combinat 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.modules + sage: i^3 -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat 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)` @@ -348,12 +357,13 @@ 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: # 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.modules + sage: is_QuotientRing(F) False """ return isinstance(x, QuotientRing_nc) @@ -376,26 +386,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.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: # 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.modules + sage: a*b -b*c - sage: a^3 # optional - sage.combinat 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.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: # 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.modules + sage: i^3 -j*k*i - j*k*j - j*k*k - sage: j^3 # optional - sage.combinat 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`, @@ -413,10 +426,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 @@ -424,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) # 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) + 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() # optional - sage.libs.singular + sage: T.gens() (0, d) """ Element = quotient_ring_element.QuotientRingElement @@ -449,15 +463,16 @@ 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: # 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.modules + sage: a*b -b*c - sage: a^3 # optional - sage.combinat sage.modules + sage: a^3 -b*c*a - b*c*b - b*c*c """ @@ -504,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') # 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: # 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) @@ -516,8 +533,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 @@ -589,19 +606,21 @@ 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: # 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.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.modules - sage: R = F.quo(J) # optional - sage.combinat sage.modules - sage: R.is_commutative() # optional - sage.combinat 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 """ @@ -641,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() # optional - sage.libs.singular - sage: pi(x^3 + y) # optional - sage.libs.singular + sage: pi = Q.cover() + sage: pi(x^3 + y) 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) + sage: l x - sage: l = pi.lift(); l # optional - 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) # optional - sage.libs.singular + sage: l(x + y^3) x """ try: @@ -675,42 +695,44 @@ 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 # optional - 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 # optional - 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) # optional - sage.libs.singular + sage: L(S.0) x - sage: L(S.1) # optional - sage.libs.singular + sage: L(S.1) 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: 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 @@ -752,13 +774,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 """ @@ -782,7 +804,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 """ @@ -822,12 +844,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)) # 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)) + 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() # optional - 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 @@ -841,14 +864,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 @@ -875,19 +898,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.libs.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.libs.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.libs.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: @@ -909,8 +932,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 @@ -921,8 +944,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 @@ -948,8 +971,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 @@ -965,10 +988,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.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) # optional - 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) @@ -1007,9 +1030,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: @@ -1021,15 +1044,16 @@ 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) # optional - sage.libs.singular - sage: S.coerce(0) # optional - sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) + sage: S.coerce(0) 0 - sage: S.coerce(2/3) # optional - sage.libs.singular + sage: S.coerce(2/3) 2/3 - sage: S.coerce(a^2 - b) # optional - sage.libs.singular + sage: S.coerce(a^2 - b) -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 @@ -1037,7 +1061,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): @@ -1061,14 +1085,14 @@ 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 - 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: @@ -1078,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 # optional - sage.libs.singular + sage: S = R.quotient(I) + sage: T = R.quotient(J) + + sage: # needs sage.libs.singular + sage: I < J 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: T.has_coerce_map_from(S) 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) True - sage: S.has_coerce_map_from(T) # optional - sage.libs.singular + sage: S.has_coerce_map_from(T) False We also allow coercions with the cover rings:: @@ -1094,15 +1120,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() @@ -1134,9 +1160,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): @@ -1165,17 +1191,18 @@ def ngens(self): :: + sage: # needs sage.libs.singular 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)) + 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() # optional - sage.libs.singular + sage: R.gens(); S.gens(); T.gens() (x, y) (a, b) (0, d) - sage: R.ngens(); S.ngens(); T.ngens() # optional - sage.libs.singular + sage: R.ngens(); S.ngens(); T.ngens() 2 2 2 @@ -1194,19 +1221,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)) # 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)) + 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) # 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) a b - sage: T.gen(0); T.gen(1) # optional - sage.libs.singular + sage: T.gen(0); T.gen(1) 0 d """ @@ -1233,7 +1261,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 @@ -1267,10 +1295,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: @@ -1290,9 +1318,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) # indirect doctest # optional - magma Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y @@ -1376,7 +1404,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 @@ -1385,12 +1413,12 @@ 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: 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 @@ -1463,13 +1491,14 @@ def _contains_(self, other): :: + sage: # needs sage.libs.pari 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) + sage: 1 in S.ideal(t^2 - 1) False - sage: 7 in S.ideal(t^2 + 1) # optional - sage.libs.pari + sage: 7 in S.ideal(t^2 + 1) 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) True """ R = self.ring() diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 27ceb3ceaf9..f67c7192f11 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. @@ -474,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() # optional - 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)) # optional - sage.libs.singular - sage: list(map(f, K.gens())) # optional - 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() # optional - sage.libs.singular - sage: f(1/ybar) # optional - sage.libs.singular + sage: xbar, ybar = K.gens() + sage: f(1/ybar) 1/t^2 - sage: f(xbar/ybar) # optional - sage.libs.singular + sage: f(xbar/ybar) t """ return self.lift()._im_gens_(codomain, im_gens, base_map=base_map) @@ -496,13 +499,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 +517,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 +533,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 +550,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 +563,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 +576,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 +603,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 +618,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 +631,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: 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: # 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.libs.singular + 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 +688,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.libs.singular + 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 +711,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.libs.singular + 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 +735,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.libs.singular + 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 +763,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 +789,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 +812,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.libs.singular + 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 +826,21 @@ 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: # needs sage.libs.singular + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) - sage: (a - 2/3*b)._singular_() # optional - sage.libs.singular + sage: (a - 2/3*b)._singular_() x-2/3*y - sage: S((a - 2/3*b)._singular_()) # optional - sage.libs.singular + sage: S((a - 2/3*b)._singular_()) a - 2/3*b """ if singular is None: @@ -838,12 +853,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.libs.singular + 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 +872,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.libs.singular + 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 +897,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.libs.singular + 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 +914,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.libs.singular + 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 +952,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.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]) - 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.libs.singular 0 """ try: diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 313ace10d98..f8843a2cee7 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -293,30 +293,32 @@ 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 - -(-1)^(2/3) - sage: 1 / ((-1)^(1/3)) # optional - sage.symbolic - -(-1)^(2/3) sage: rational_power_parts(-1, 2/3) (1, -1) - sage: (-1)^(2/3) # optional - sage.symbolic - (-1)^(2/3) sage: all(rational_power_parts(-1, i/77) == (1,-1) for i in range(1,9)) True - sage: (-1)^(1/3)*(-1)^(1/5) # optional - 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) # optional - 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) # optional - 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 @@ -416,9 +418,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 +437,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 +510,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 +721,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 +808,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) # needs sage.rings.real_mpfr 3.141592920 - sage: pi.n(digits=10) + sage: pi.n(digits=10) # needs sage.rings.real_mpfr sage.symbolic 3.141592654 It's almost pi! @@ -958,9 +961,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 +974,13 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: n = 1/2; n._sympy_() # optional - sympy + sage: # needs sympy + sage: n = 1/2; n._sympy_() 1/2 - sage: n = -1/5; n._sympy_() # optional - sympy + sage: n = -1/5; n._sympy_() -1/5 - sage: from sympy import Symbol # optional - sympy - sage: QQ(1) + Symbol('x')*QQ(2) # optional - sympy + sage: from sympy import Symbol + sage: QQ(1) + Symbol('x')*QQ(2) 2*x + 1 """ import sympy @@ -1044,16 +1048,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.array([1, 2, 3/1]) # optional - 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 # optional - numpy + sage: numpy.array(QQ(2**40)).dtype dtype('int64') - sage: numpy.array(QQ(2**400)).dtype # optional - numpy + sage: numpy.array(QQ(2**400)).dtype dtype('O') - - sage: numpy.array([1, 1/2, 3/4]) # optional - 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: @@ -1196,11 +1199,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(25/6) - sage: a.local_height(2) + sage: a.local_height(2) # needs sage.rings.real_mpfr 0.693147180559945 - sage: a.local_height(3) + sage: a.local_height(3) # needs sage.rings.real_mpfr 1.09861228866811 - sage: a.local_height(5) + sage: a.local_height(5) # needs sage.rings.real_mpfr 0.000000000000000 """ from sage.rings.real_mpfr import RealField @@ -1234,11 +1237,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.local_height_arch() + sage: a.local_height_arch() # needs sage.rings.real_mpfr 0.000000000000000 - sage: (1/a).local_height_arch() + sage: (1/a).local_height_arch() # needs sage.rings.real_mpfr 1.42711635564015 - sage: (1/a).local_height_arch(100) + sage: (1/a).local_height_arch(100) # needs sage.rings.real_mpfr 1.4271163556401457483890413081 """ from sage.rings.real_mpfr import RealField @@ -1277,11 +1280,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() # needs 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()] # needs 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()]) # needs sage.rings.real_mpfr 1.79175946922805 """ from sage.rings.real_mpfr import RealField @@ -1318,11 +1321,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: a = QQ(6/25) - sage: a.global_height_arch() + sage: a.global_height_arch() # needs sage.rings.real_mpfr 0.000000000000000 - sage: (1/a).global_height_arch() + sage: (1/a).global_height_arch() # needs sage.rings.real_mpfr 1.42711635564015 - sage: (1/a).global_height_arch(100) + sage: (1/a).global_height_arch(100) # needs sage.rings.real_mpfr 1.4271163556401457483890413081 """ return self.local_height_arch(prec) @@ -1349,6 +1352,7 @@ 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() 3.21887582486820 @@ -1417,44 +1421,45 @@ 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') # optional - sage.rings.number_field - sage: (1/7).is_norm(K) # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') + sage: (1/7).is_norm(K) True - sage: (1/10).is_norm(K) # optional - sage.rings.number_field + sage: (1/10).is_norm(K) False - sage: 0.is_norm(K) # optional - sage.rings.number_field + sage: 0.is_norm(K) True - sage: (1/7).is_norm(K, element=True) # optional - 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) # optional - sage.rings.number_field + sage: (1/10).is_norm(K, element=True) (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: # 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() # optional - sage.rings.number_field + sage: e.norm() 3/5 - - sage: 7.is_norm(K) # optional - 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) # optional - sage.rings.number_field + sage: 7.is_norm(K, proof=False) False AUTHORS: @@ -1537,10 +1542,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,17 +1904,19 @@ 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: # needs sage.rings.real_mpfr sage: n.sqrt(prec=10) 0.82 sage: n.sqrt(prec=100) @@ -1918,16 +1925,17 @@ cdef class Rational(sage.structure.element.FieldElement): 0.66666666666666666666666666667 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) # optional - sage.symbolic + sage: sqrt(-2/3, all=True) # needs sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] - sage: sqrt(-2/3, prec=53) - 0.816496580927726*I - sage: sqrt(-2/3, prec=53, all=True) - [0.816496580927726*I, -0.816496580927726*I] AUTHORS: @@ -1988,22 +1996,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) + 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) + sage: RR(1/8) # needs sage.rings.real_mpfr 0.125000000000000 - sage: RR(1/6) + 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) + sage: RealField(200)(x) # needs sage.rings.real_mpfr 3.1415094339622641509433962264150943396226415094339622641509 """ cdef unsigned int alpha, beta @@ -2198,22 +2206,22 @@ cdef class Rational(sage.structure.element.FieldElement): Test that the conversion has correct rounding on simple rationals:: - sage: for p in [-100..100]: + 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 +2521,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 +2538,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 +2561,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 +2580,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,15 +3127,15 @@ 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) + 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 @@ -3137,24 +3145,24 @@ cdef class Rational(sage.structure.element.FieldElement): 1/3 sage: (1/2).log(8) -1/3 - sage: (16/81).log(8/27) + sage: (16/81).log(8/27) # needs sage.libs.pari 4/3 - sage: (8/27).log(16/81) + sage: (8/27).log(16/81) # needs sage.libs.pari 3/4 - sage: log(27/8, 16/81) + sage: log(27/8, 16/81) # needs sage.libs.pari -3/4 - sage: log(16/81, 27/8) + sage: log(16/81, 27/8) # needs sage.libs.pari -4/3 - sage: (125/8).log(5/2) + sage: (125/8).log(5/2) # needs sage.libs.pari 3 - sage: (125/8).log(5/2, prec=53) + 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 +3231,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) + sage: (1/3).gamma(prec=100) # needs sage.rings.real_mpfr 2.6789385347077476336556929410 - sage: (1/2).gamma(prec=100) + sage: (1/2).gamma(prec=100) # needs sage.rings.real_mpfr 1.7724538509055160272981674833 TESTS: @@ -3774,11 +3783,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 cbd5a4ba483..eb8f087691f 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -16,17 +16,17 @@ :: - sage: RealField(9).pi() + sage: RealField(9).pi() # needs sage.rings.real_mpfr 3.1 - sage: QQ(RealField(9).pi()) + sage: QQ(RealField(9).pi()) # needs sage.rings.real_mpfr 22/7 - sage: QQ(RealField().pi()) + 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): @@ -102,7 +102,7 @@ class RationalField(Singleton, number_field_base.NumberField): 3929329/32 sage: QQ(-RR(3929329/32)) -3929329/32 - sage: QQ(RR(1/7)) - 1/7 + 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,6 +110,7 @@ class RationalField(Singleton, number_field_base.NumberField): :: + sage: # needs sage.rings.real_mpfr sage: QQ(23.2, 2) 6530219459687219/281474976710656 sage: 6530219459687219.0/281474976710656 @@ -121,6 +122,7 @@ class RationalField(Singleton, number_field_base.NumberField): Here's a nice example involving elliptic curves:: + sage: # needs sage.rings.real_mpfr sage.schemes sage: E = EllipticCurve('11a') sage: L = E.lseries().at1(300)[0]; L 0.2538418608559106843377589233... @@ -324,9 +326,9 @@ def completion(self, p, prec, extras={}): EXAMPLES:: - sage: QQ.completion(infinity, 53) + 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'}) + 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 @@ -441,7 +443,7 @@ def __truediv__(self, I): EXAMPLES:: - sage: QQ / ZZ # optional - sage.groups + sage: QQ / ZZ # needs sage.modules Q/Z """ from sage.rings.ideal import Ideal_generic @@ -526,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: @@ -606,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. @@ -657,7 +659,7 @@ def places(self, all_complex=False, prec=None): EXAMPLES:: - sage: QQ.places() + sage: QQ.places() # needs sage.rings.real_mpfr [Ring morphism: From: Rational Field To: Real Field with 53 bits of precision @@ -667,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) + 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 @@ -675,19 +677,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): @@ -696,12 +706,12 @@ def complex_embedding(self, prec=53): EXAMPLES:: - sage: QQ.complex_embedding() + 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) + sage: QQ.complex_embedding(20) # needs sage.rings.real_mpfr Ring morphism: From: Rational Field To: Complex Field with 20 bits of precision @@ -718,9 +728,9 @@ 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. @@ -729,7 +739,7 @@ def residue_field(self, p, check=True): sage: QQ.residue_field(5) 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 @@ -760,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.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.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.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.modules Traceback (most recent call last): ... ValueError: all entries in list must be prime or -1 for @@ -798,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 @@ -806,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.modules Traceback (most recent call last): ... ValueError: if the infinite place is in the list, the second @@ -1054,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 @@ -1075,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 @@ -1408,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 @@ -1514,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' @@ -1582,7 +1593,7 @@ def _sympy_(self): EXAMPLES:: - sage: QQ._sympy_() # optional - sympy + sage: QQ._sympy_() # needs sympy Rationals """ from sympy import Rationals @@ -1627,21 +1638,22 @@ def _factor_univariate_polynomial(self, f): TESTS:: + sage: # needs sage.libs.pari sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(x) x - sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(2*x) (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) (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) (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)) + 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) # optional - 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) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ @@ -1659,9 +1671,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..802e4567fc3 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 ec4af251254..bfa020f14b8 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)) + sage: is_RealDoubleField(RealField(53)) # needs sage.rings.real_mpfr False """ from sage.misc.superseded import deprecation @@ -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 @@ -128,6 +128,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): numbers and higher-precision ones, though of course there may be loss of precision:: + sage: # needs sage.rings.real_mpfr sage: a = RealField(200)(2).sqrt(); a 1.4142135623730950488016887242096980785696718753769480731767 sage: b = RDF(a); b @@ -188,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}" @@ -214,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 @@ -281,7 +282,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 +295,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 @@ -314,37 +315,37 @@ 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 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 - 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: @@ -388,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 @@ -396,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() @@ -407,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" @@ -418,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"' @@ -446,7 +447,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): EXAMPLES:: - sage: RDF.to_prec(52) + 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 @@ -649,6 +650,7 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): TESTS:: + sage: # needs numpy sage: R. = RDF[] sage: RDF._factor_univariate_polynomial(x) x @@ -664,18 +666,19 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): 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 = (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), (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 # 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()] @@ -710,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 @@ -744,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) @@ -790,20 +793,21 @@ 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: # needs sage.symbolic + sage: a + a.ulp() == a False - sage: a - a.ulp() == a # optional - sage.symbolic + sage: a - a.ulp() == a False - sage: b + b.ulp() == b # optional - sage.symbolic + sage: b + b.ulp() == b False - sage: b - b.ulp() == b # optional - sage.symbolic + sage: b - b.ulp() == b False Since the default rounding mode is round-to-nearest, adding or @@ -812,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 # optional - sage.symbolic + sage: # needs sage.symbolic + sage: a - a.ulp()/3 == a True - sage: a + a.ulp()/3 == a # optional - sage.symbolic + sage: a + a.ulp()/3 == a True - sage: b - b.ulp()/3 == b # optional - sage.symbolic + sage: b - b.ulp()/3 == b True - sage: b + b.ulp()/3 == b # optional - sage.symbolic + sage: b + b.ulp()/3 == b True + sage: c = RDF(1) sage: c - c.ulp()/3 == c False @@ -927,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): @@ -977,11 +983,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 +1012,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,22 +1020,22 @@ 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() 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) @@ -1130,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() @@ -1167,8 +1173,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) # 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,24 +1271,25 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(exp(1.0)); a # optional - 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() # optional - sage.symbolic - sage: sign,mantissa,exponent # optional - 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 # optional - 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 @@ -1332,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) @@ -1345,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) @@ -1358,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) @@ -1371,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 @@ -1649,9 +1656,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 +1666,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) @@ -1672,7 +1679,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) @@ -1683,7 +1690,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 @@ -1846,7 +1853,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 +1862,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: @@ -1969,7 +1976,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) @@ -2022,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) @@ -2071,7 +2078,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_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_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 b6ff3f64015..fb96ae89407 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.rings.real_mpfr """ Lazy real and complex numbers @@ -14,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 """ @@ -149,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 @@ -406,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 @@ -426,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: @@ -746,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 @@ -853,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 """ @@ -868,7 +870,7 @@ 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))) 0.99505475368673045133188018525548847509781385470 @@ -884,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 @@ -901,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) @@ -1041,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 @@ -1244,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) @@ -1260,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))) @@ -1623,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/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 1193a14baff..b11fba1ac59 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,6 +2401,8 @@ cdef class RealIntervalFieldElement(RingElement): 1.00000000000000 sage: RIF(1, 2).relative_diameter() 0.666666666666667 + + sage: # needs sage.symbolic sage: RIF(pi).diameter() 1.41357985842823e-16 sage: RIF(pi).absolute_diameter() @@ -2431,16 +2435,18 @@ cdef class RealIntervalFieldElement(RingElement): EXAMPLES:: - sage: RIF(pi).fp_rank_diameter() - 1 sage: RIF(12345).fp_rank_diameter() 0 - sage: RIF(-sqrt(2)).fp_rank_diameter() - 1 sage: RIF(5/8).fp_rank_diameter() 0 sage: RIF(5/7).fp_rank_diameter() 1 + + 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() @@ -2452,10 +2458,10 @@ cdef class RealIntervalFieldElement(RingElement): 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 +2475,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 +2549,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 +3379,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 +3410,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 +3441,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 +3455,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 +3528,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 +3584,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 +3835,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 +3859,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 +3990,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 +4122,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 +4407,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 +4623,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 +5078,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 ea7ff07a216..6b00131c21c 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) + 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) @@ -1438,12 +1438,13 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: import numpy # optional - numpy - sage: numpy.arange(10.0) # optional - 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 # optional - numpy + sage: numpy.array([1.0, 1.1, 1.2]).dtype dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype # optional - numpy + sage: numpy.array([1.000000000000000000000000000000000000]).dtype dtype('O') """ if (self._parent).__prec <= 53: @@ -1604,7 +1605,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 +1653,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 +1681,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 +1697,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 +1715,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 +2339,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] @@ -2385,7 +2388,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 +2412,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 +2436,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 +2460,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): @@ -2505,22 +2520,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 @@ -3126,11 +3141,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 @@ -3160,9 +3175,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' """ @@ -3186,9 +3201,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' """ @@ -3208,9 +3223,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) @@ -3236,9 +3251,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__int__() + 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): @@ -3254,9 +3269,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi).__complex__() + sage: RR(pi).__complex__() # needs sage.symbolic (3.141592653589793+0j) - sage: type(RR(pi).__complex__()) + sage: type(RR(pi).__complex__()) # needs sage.symbolic <... 'complex'> """ @@ -3268,9 +3283,9 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: RR(pi)._complex_number_() + 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 @@ -3282,12 +3297,13 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: + sage: # needs sage.symbolic sage: R = RealField(100) sage: R(pi) 3.1415926535897932384626433833 - sage: axiom(R(pi)) # optional - axiom # indirect doctest + sage: axiom(R(pi)) # indirect doctest # optional - axiom 3.1415926535 8979323846 26433833 - sage: fricas(R(pi)) # optional - fricas + sage: fricas(R(pi)) # optional - fricas 3.1415926535_8979323846_26433833 """ @@ -3308,13 +3324,14 @@ 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: # needs sage.libs.pari sage: RealField(250).pi().__pari__() 3.14159265358979 sage: RR(0.0).__pari__() @@ -3327,7 +3344,7 @@ cdef class RealNumber(sage.structure.element.RingElement): 1.41421356237309515 sage: RR(2.0).sqrt().__pari__().sage().prec() 64 - sage: RealField(70)(pi).__pari__().sage().prec() + sage: RealField(70)(pi).__pari__().sage().prec() # needs sage.symbolic 96 # 32-bit 128 # 64-bit sage: for i in range(100, 200): @@ -3337,14 +3354,15 @@ cdef class RealNumber(sage.structure.element.RingElement): 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: # needs sage.libs.pari sage: a = pari(0.5) << (sys.maxsize+1)/4 sage: RR(a) >> (sys.maxsize+1)/4 0.500000000000000 @@ -3504,7 +3522,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:: @@ -3608,9 +3626,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 @@ -3774,6 +3792,8 @@ cdef class RealNumber(sage.structure.element.RingElement): -333/1000 sage: RR(3/4).nearby_rational(max_denominator=2) 1 + + sage: # needs sage.symbolic sage: RR(pi).nearby_rational(max_denominator=120) 355/113 sage: RR(pi).nearby_rational(max_denominator=10000) @@ -3782,6 +3802,7 @@ cdef class RealNumber(sage.structure.element.RingElement): 312689/99532 sage: RR(pi).nearby_rational(max_denominator=1) 3 + sage: RR(-3.5).nearby_rational(max_denominator=1) -3 @@ -4084,7 +4105,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) @@ -4229,7 +4250,7 @@ cdef class RealNumber(sage.structure.element.RingElement): :: sage: r = 4344 - sage: r.sqrt() + sage: r.sqrt() # needs sage.symbolic 2*sqrt(1086) :: @@ -4345,10 +4366,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: @@ -4406,21 +4427,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 """ @@ -5109,8 +5130,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:: @@ -5340,11 +5361,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 # needs sage.libs.pari 1.64493406684823 - sage: pari(2).zeta(precision=128).sage().prec() + sage: pari(2).zeta(precision=128).sage().prec() # needs sage.libs.pari 128 - sage: pari(2).zeta(precision=65).sage().prec() + sage: pari(2).zeta(precision=65).sage().prec() # needs sage.libs.pari 128 # 64-bit 96 # 32-bit @@ -5356,9 +5377,9 @@ cdef class RealNumber(sage.structure.element.RingElement): :: - sage: type(z) + sage: type(z) # needs sage.libs.pari - sage: R(z) + sage: R(z) # needs sage.libs.pari 1.64493406684823 """ cdef RealNumber x = self._new() @@ -5511,8 +5532,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:: @@ -5925,7 +5949,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) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 4cba2c9ba7f..54c8053062b 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') + 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)[] # 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 + 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,31 +773,31 @@ 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) True - sage: CC.is_subring(CC) + 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[] sage: R.is_subring(R) @@ -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() + 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() + 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.libs.singular + 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,32 @@ 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: # needs sage.rings.finite_rings + sage: a = GF(7).zeta(); a 3 - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: a.multiplicative_order() 6 - sage: a = GF(49,'z').zeta(); a # optional - sage.rings.finite_rings + sage: a = GF(49,'z').zeta(); a z - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: a.multiplicative_order() 48 - sage: a = GF(49,'z').zeta(2); a # optional - sage.rings.finite_rings + sage: a = GF(49,'z').zeta(2); a 6 - sage: a.multiplicative_order() # optional - sage.rings.finite_rings + sage: a.multiplicative_order() 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 +998,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 +1035,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 +1132,9 @@ cdef class Ring(ParentWithGens): sage: RDF.epsilon() 2.220446049250313e-16 - sage: ComplexField(53).epsilon() + sage: ComplexField(53).epsilon() # needs sage.rings.real_mpfr 2.22044604925031e-16 - sage: RealField(10).epsilon() + sage: RealField(10).epsilon() # needs sage.rings.real_mpfr 0.0020 For exact rings, zero is returned:: @@ -1135,14 +1144,14 @@ cdef class Ring(ParentWithGens): This also works over derived rings:: - sage: RR['x'].epsilon() + 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.symbolics + sage: SR.epsilon() # needs sage.symbolic Traceback (most recent call last): ... NotImplementedError @@ -1200,11 +1209,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 +1287,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 +1327,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 +1384,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 +1432,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 +1479,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 +1506,33 @@ 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: # needs sage.modules + sage: Dx = M.gen(0); Dx d/dx - sage: Dy = M.gen(1); Dy # optional - sage.modules + sage: Dy = M.gen(1); Dy d/dy - sage: Dz = M.gen(2); Dz # optional - 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) # optional - sage.modules + sage: Dx(f) # = 2*x evaluated at (0,1,2) 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules + sage: Dy(f) # = 2*y evaluated at (0,1,2) 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) # optional - sage.modules + sage: Dz(f) # = 2*z evaluated at (0,1,2) 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 +1571,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 +1596,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 +1725,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 +1744,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 +1815,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 +1834,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 +1861,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 @@ -1872,13 +1885,14 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: + sage: # needs sage.rings.number_field 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') + 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 # optional - sage.rings.number_field + sage: OK.integral_closure() == OK True sage: QQ.integral_closure() == QQ @@ -1898,9 +1912,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 +1938,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 +1949,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 @@ -1980,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') # 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') + 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 # optional - sage.rings.number_field + sage: f in R True - sage: g in R # optional - sage.rings.number_field + sage: g in R False - sage: R.gcd(f, g) # optional - 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) # optional - 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)) # optional - sage.rings.number_field + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) x - a """ if coerce: @@ -2089,7 +2104,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 +2146,14 @@ cdef class Field(PrincipalIdealDomain): sage: QQ.fraction_field() Rational Field - sage: RR.fraction_field() + sage: RR.fraction_field() # needs sage.rings.real_mpfr Real Field with 53 bits of precision - sage: CC.fraction_field() + 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 +2166,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 +2281,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 +2322,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 +2342,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 +2363,17 @@ 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: # 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) # 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.rings.number_field + sage: A.has_standard_involution() # needs 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) + sage: L.has_standard_involution() Traceback (most recent call last): ... NotImplementedError: has_standard_involution is not implemented for this algebra @@ -2410,7 +2427,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 +2474,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 ddd675e8a3e..d9438aaa648 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)) # 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: # 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) - sage: K + 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() + 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) - sage: L + 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() + 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() + 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() + 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] @@ -54,34 +53,34 @@ 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) # needs sage.rings.finite_rings [1, b] - sage: L.basis_over(F) + 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() + 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 - sage: u.vector() # over K + 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) + 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: # needs sage.rings.finite_rings sage: u.trace() # over K (2*z2 + 1) + (2*z2 + 1)*a sage: u.trace(F) z2 + 1 sage: u.trace().trace() # over K, then over F z2 + 1 - sage: u.norm() # over K (z2 + 1) + (4*z2 + 2)*a sage: u.norm(F) @@ -89,9 +88,9 @@ One can also compute traces and norms with respect to any base of the tower:: And minimal polynomials:: - sage: u.minpoly() + 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) + sage: u.minpoly(F) # needs sage.rings.finite_rings x^4 + (4*z2 + 4)*x^3 + x^2 + (z2 + 1)*x + 2*z2 + 2 @@ -157,17 +156,19 @@ 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) - sage: L. = K.extension(x^3 - 5) - sage: tower_bases(L, True) + 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) + 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) + 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) + 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,13 +337,12 @@ class RingExtensionFactory(UniqueFactory): True sage: x = polygen(ZZ, 'x') - sage: K. = QQ.extension(x^2 - 2) - sage: E = K.over(QQ) - sage: E + 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) - sage: E2 is E + 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): @@ -378,16 +378,18 @@ 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), names=('a',)) + 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 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 @@ -536,9 +538,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: @@ -560,8 +562,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) # 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 @@ -623,10 +625,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension(x^2 - 2) sage: E = K.over() # over QQ - sage: hasattr(E, 'automorphisms') True sage: E.automorphisms() @@ -661,10 +663,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) # needs sage.rings.number_field + sage: K. = A.over() # needs sage.rings.number_field - sage: dir(K) + sage: dir(K) # needs sage.rings.number_field ['CartesianProduct', 'Element', 'Hom', @@ -693,8 +695,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES: - sage: E = GF(5^3).over() - sage: hash(E) # random + 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) @@ -706,10 +708,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: - sage: K = GF(7^3).over() - sage: type(K) + 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 + sage: loads(dumps(K)) is K # needs sage.rings.finite_rings True """ (defining_morphism, gens, names) = self._factory_data[2] @@ -722,8 +724,8 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: - sage: E = GF(5^3).over() - sage: E.construction() + 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 @@ -740,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: @@ -764,15 +767,14 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: k = GF(5) 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() Field in v with defining polynomial x^2 + (3 - u)*x + u over its base - sage: x = L.from_base_ring(u); x u sage: x.parent() @@ -797,6 +799,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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) @@ -804,15 +807,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): Observe what happens when we modify the option ``over``:: + 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 - + 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 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 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 @@ -823,15 +826,14 @@ cdef class RingExtension_generic(CommutativeAlgebra): Now the option ``base``:: + 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) [1, c, c^2, d, c*d, c^2*d] 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) [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) @@ -1039,19 +1041,18 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: + 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 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 Ring morphism: @@ -1061,6 +1062,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): A test with iterated extensions:: + 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) @@ -1085,17 +1087,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) # 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) - sage: L.base() + 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 + sage: L.base() is K # needs sage.rings.finite_rings True .. SEEALSO:: @@ -1111,21 +1113,20 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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() [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() - [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] @@ -1150,10 +1151,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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() @@ -1179,14 +1180,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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)) False + sage: # needs sage.rings.finite_rings sage: B.is_defined_over(A) True sage: B.is_defined_over(GF(5^4)) @@ -1198,9 +1200,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): Note that an extension is defined over itself:: - sage: A.is_defined_over(A) + sage: A.is_defined_over(A) # needs sage.rings.finite_rings True - sage: A.is_defined_over(GF(5^4)) + sage: A.is_defined_over(GF(5^4)) # needs sage.rings.finite_rings True .. SEEALSO:: @@ -1231,6 +1233,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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) @@ -1238,7 +1241,6 @@ 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) Field in z4 with defining polynomial x^2 + (4*z2 + 3)*x + z2 over its base sage: L._check_base(GF(5^4)) @@ -1248,9 +1250,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): When ``base`` is ``None``, the base of the extension is returned:: - sage: L._check_base(None) + 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() + sage: L._check_base(None) is L.base() # needs sage.rings.finite_rings True """ @@ -1276,32 +1278,32 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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() 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 defined (see also :meth:`is_defined_over`):: - sage: L.defining_morphism(F) + 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 + 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)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1338,6 +1340,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K. = GF(5^2).over() # over GF(5) sage: K.gens() (a,) @@ -1368,12 +1371,12 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K = GF(5^2).over() # over GF(5) sage: K.gens() (z2,) sage: K.ngens() 1 - sage: L = GF(5^4).over(K) sage: L.gens(GF(5)) (z4, z2) @@ -1388,15 +1391,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) # 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() + 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 + sage: x.parent() is K # needs sage.rings.finite_rings True """ return self.gens()[0] @@ -1407,10 +1410,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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() Field in z2 with defining polynomial x^2 + 4*x + 2 over its base sage: x.parent() is K @@ -1430,10 +1433,10 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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) @@ -1444,15 +1447,15 @@ cdef class RingExtension_generic(CommutativeAlgebra): If ``base`` is omitted, the degree is computed over the base of the extension:: - sage: K.degree_over() + sage: K.degree_over() # needs sage.rings.finite_rings 2 - sage: L.degree_over() + 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)) + 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 @@ -1473,6 +1476,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: B. = QQ.extension(x^6 - 2) @@ -1496,9 +1500,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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) @@ -1509,7 +1513,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): 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)) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not (explicitly) defined over Finite Field of size 5 @@ -1526,8 +1530,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)) # needs sage.rings.finite_rings + sage: A.relative_degree() # needs sage.rings.finite_rings 2 .. SEEALSO:: @@ -1542,9 +1546,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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() @@ -1567,9 +1571,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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)) @@ -1578,7 +1582,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): 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() # needs sage.rings.finite_rings True """ cdef CommutativeRing b @@ -1612,8 +1616,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) # needs sage.rings.finite_rings + sage: K.is_finite_over() # indirect doctest # needs sage.rings.finite_rings True """ raise NotImplementedError @@ -1630,9 +1634,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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)) @@ -1641,7 +1645,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): 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() # needs sage.rings.finite_rings True """ cdef CommutativeRing b @@ -1675,8 +1679,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) # needs sage.rings.finite_rings + sage: K.is_free_over() # indirect doctest # needs sage.rings.finite_rings True """ raise NotImplementedError @@ -1691,8 +1695,8 @@ 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) # needs sage.rings.finite_rings + sage: K.is_field() # needs sage.rings.finite_rings True sage: S. = QQ[] @@ -1727,39 +1731,40 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') 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() - sage: K1 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base + 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() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + [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 = 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() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + [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) # needs sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) + 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 + sage: K1.fraction_field() is K1 # needs sage.rings.number_field True - sage: K2.fraction_field() is K2 + sage: K2.fraction_field() is K2 # needs sage.rings.number_field True TESTS:: @@ -1790,8 +1795,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() # 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) @@ -1825,18 +1830,21 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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 - + 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()) - 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 @@ -1869,43 +1877,44 @@ 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) # 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]) - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + 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 Defining the absolute Frobenius of `L` is a bit more complicated 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]) # 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]) - sage: FrobL = L.hom([b^5], base_map=FrobK) - sage: FrobL - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + 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 with map on base ring: a |--> 1 - a As a shortcut, we may use the following construction:: - sage: phi = L.hom([b^5, a^5]) - sage: phi - Ring endomorphism of Field in b with defining polynomial x^3 + (2 + 2*a)*x - a over its base + 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 + sage: phi == FrobL # needs sage.rings.finite_rings True """ if codomain is None: @@ -1924,6 +1933,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + 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) @@ -1963,7 +1973,9 @@ cdef class RingExtension_generic(CommutativeAlgebra): 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 + 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() @@ -2003,13 +2015,13 @@ cdef class RingExtensionFractionField(RingExtension_generic): TESTS:: + sage: # needs sage.rings.number_field 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: 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() """ @@ -2025,13 +2037,13 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: + sage: # needs sage.rings.number_field 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: 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() Order in Number Field in a with defining polynomial x^2 - 2 over its base sage: K.ring() is OK @@ -2045,11 +2057,11 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') 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' """ @@ -2090,11 +2102,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 # 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() + sage: TestSuite(E).run() # needs sage.rings.finite_rings """ Element = RingExtensionWithBasisElement @@ -2117,12 +2128,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) # 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() + sage: TestSuite(E).run() # needs sage.rings.number_field """ RingExtension_generic.__init__(self, defining_morphism, **kwargs) self._basis = [ self(b) for b in basis ] @@ -2162,29 +2172,27 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: # needs sage.rings.finite_rings sage: F = GF(5) 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 True sage: L._print_option_base(GF(5^2)) is K True - sage: L._print_option_base(None) is K True - sage: L._print_option_base(L) Traceback (most recent call last): ... ValueError: base must be strict - 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: @@ -2210,6 +2218,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: B. = QQ.extension(x^6 - 2) @@ -2236,8 +2245,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) # 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: @@ -2255,8 +2264,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) # 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: @@ -2274,32 +2283,30 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: + 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) [1, b, c, b*c, c^2, b*c^2] - 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 base of the extension:: - sage: L.basis_over() + sage: L.basis_over() # needs sage.rings.finite_rings [1, c, c^2] - sage: K.basis_over() + 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)) + 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 @@ -2319,9 +2326,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) # 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: @@ -2359,25 +2366,30 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: sage: F = GF(11) - sage: K. = GF(11^2).over() - sage: L. = GF(11^6).over(K) + 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: # 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 + Vector space of dimension 3 over + Field in a with defining polynomial x^2 + 7*x + 2 over its base 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 + 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 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) (0, 1, 0) sage: i((1, a, a+1)) @@ -2385,27 +2397,28 @@ cdef class RingExtensionWithBasis(RingExtension_generic): 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) # 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) + sage: j(a*b) # needs 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)) # 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) - 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) # 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)) + 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 @@ -2441,9 +2454,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() # 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()) @@ -2476,39 +2489,40 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') 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() - sage: K1 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base + 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() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + [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 = 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() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + [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) # needs sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) + 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 + sage: K1.fraction_field() is K1 # needs sage.rings.number_field True - sage: K2.fraction_field() is K2 + sage: K2.fraction_field() is K2 # needs sage.rings.number_field True TESTS:: @@ -2543,13 +2557,12 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^3 - 7) sage: K = A.over() - sage: type(K) - sage: TestSuite(K).run() """ @@ -2572,12 +2585,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) # 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() + sage: TestSuite(E).run() # needs sage.rings.number_field """ self._name = names[0] backend_base = backend_parent(defining_morphism.domain()) @@ -2604,10 +2616,10 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: + 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) 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' @@ -2622,10 +2634,10 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: + 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) sage: L._latex_topring() '\\Bold{F}_{5}[a][b]' @@ -2648,10 +2660,10 @@ 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: # 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 x^5 + (6*z2 + 4)*x^4 + (3*z2 + 5)*x^3 + (2*z2 + 2)*x^2 + 4*x + 6*z2 sage: P(u) @@ -2659,7 +2671,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): We can use a different variable name:: - sage: K.modulus('y') + 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 @@ -2680,10 +2692,10 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: + 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) sage: L.gens() (b,) @@ -2721,39 +2733,40 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') 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() - sage: K1 - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base + 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() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + [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 = 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() - [Fraction Field of Order in Number Field in a with defining polynomial x^2 - 5 over its base, + [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) # needs sage.rings.number_field False - sage: K2.has_coerce_map_from(K1) + 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 + sage: K1.fraction_field() is K1 # needs sage.rings.number_field True - sage: K2.fraction_field() is K2 + sage: K2.fraction_field() is K2 # needs sage.rings.number_field True TESTS:: diff --git a/src/sage/rings/ring_extension_conversion.pyx b/src/sage/rings/ring_extension_conversion.pyx index 9d94fb7567d..eeb6077cd0a 100644 --- a/src/sage/rings/ring_extension_conversion.pyx +++ b/src/sage/rings/ring_extension_conversion.pyx @@ -1,3 +1,5 @@ +# sage.doctest: needs 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..fb80ba84e6e 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() # 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,6 +86,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + sage: # needs sage.rings.finite_rings sage: K = GF(5^3).over() sage: x = K.random_element() sage: type(x) @@ -103,10 +104,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() # over QQ - sage: hasattr(a, 'continued_fraction') True sage: a.continued_fraction() @@ -137,10 +138,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() - sage: dir(a) ['__abs__', '__add__', @@ -173,8 +174,8 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES: - sage: E. = GF(5^3).over() - sage: hash(a) + 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() - sage: L. = GF(5^4).over(K) - sage: b._repr_() + 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() - sage: L. = GF(5^4).over(K) - sage: b._latex_() + 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 @@ -278,6 +279,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: F = GF(5^2) sage: K. = GF(5^4).over(F) sage: x = z^10 @@ -300,6 +302,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + 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 @@ -311,18 +314,18 @@ 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) - sage: g = f.in_base() - sage: g + sage: g = f.in_base(); g 1 sage: g.parent() Finite Field in z2 of size 5^2 @@ -331,6 +334,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): We check the case of a tower of extensions:: + 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) @@ -370,6 +374,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K. = GF(5^2).over() sage: x = K.random_element() sage: x == x @@ -387,10 +392,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + 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 @@ -407,9 +412,9 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + 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 @@ -427,11 +432,11 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + 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 + sage: (x - y).parent() is K True sage: x - y == x + (-y) True @@ -447,10 +452,10 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + 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 @@ -468,15 +473,16 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') 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() - Fraction Field of Order in Number Field in a with defining polynomial x^2 - 2 over its base + Fraction Field of + Order in Number Field in a with defining polynomial x^2 - 2 over its base sage: a*b 1 """ @@ -496,8 +502,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)) # needs sage.rings.finite_rings + sage: a.additive_order() # needs sage.rings.finite_rings 5 """ return self._backend.additive_order() @@ -508,8 +514,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)) # needs sage.rings.finite_rings + sage: a.multiplicative_order() # needs sage.rings.finite_rings 624 """ return self._backend.multiplicative_order() @@ -552,9 +558,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() # needs sage.libs.pari True - sage: E(x^2-1).is_prime() + sage: E(x^2 - 1).is_prime() # needs sage.libs.pari False """ return self._backend.is_prime() @@ -570,12 +576,12 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K. = GF(5^3).over() sage: a.is_square() False sage: a.is_square(root=True) (False, None) - sage: b = a + 1 sage: b.is_square() True @@ -599,7 +605,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,10 +616,11 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): .. NOTE:: - The option `extend=True` is often not implemented. + The option ``extend=True`` is often not implemented. EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K. = GF(5^3).over() sage: b = a + 1 sage: b.sqrt() @@ -664,8 +671,8 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES: - sage: E. = GF(5^3).over() - sage: hash(a) + sage: E. = GF(5^3).over() # needs sage.rings.finite_rings + sage: hash(a) # needs sage.rings.finite_rings 5 """ return hash(self._backend) @@ -744,13 +751,13 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: + sage: # needs sage.rings.number_field 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: 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 a/2 sage: num = x.numerator(); num @@ -759,13 +766,14 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): The numerator is an element of the ring which was used to construct the fraction field:: - sage: num.parent() + 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 + sage: num.parent() is OK # needs sage.rings.number_field True TESTS:: + sage: # needs sage.rings.number_field sage: x = K.random_element() sage: x == x.numerator() / x.denominator() True @@ -780,13 +788,13 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: + sage: # needs sage.rings.number_field 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: 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 a/2 sage: denom = x.denominator(); denom @@ -795,13 +803,14 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): The denominator is an element of the ring which was used to construct the fraction field:: - sage: denom.parent() + 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 + sage: denom.parent() is OK # needs sage.rings.number_field True TESTS:: + sage: # needs sage.rings.number_field sage: x = K.random_element() sage: x == x.numerator() / x.denominator() True @@ -820,6 +829,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: + sage: # needs sage.rings.finite_rings sage: K. = GF(5^3).over() sage: L. = GF(5^9).over(K) sage: type(b) @@ -832,8 +842,8 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES: - sage: E. = GF(5^3).over() - sage: hash(a) + sage: E. = GF(5^3).over() # needs sage.rings.finite_rings + sage: hash(a) # needs sage.rings.finite_rings 5 """ return hash(self._backend) @@ -851,10 +861,10 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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)) @@ -929,10 +939,10 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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)) @@ -995,28 +1005,27 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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) + 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) + 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 base of the extension:: - sage: x.vector() + 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)) + 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 @@ -1036,6 +1045,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: + sage: # needs sage.rings.finite_rings sage: K = GF(11^10).over(GF(11^2)) sage: x = K.random_element() sage: coeffs = x.vector() @@ -1059,12 +1069,12 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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 ((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b sage: P.base_ring() is K @@ -1074,40 +1084,40 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): When the base is `F`, we obtain a bivariate polynomial:: - sage: P = u.polynomial(F); P + 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) + sage: L.gens(F) # needs sage.rings.finite_rings (c, b) - sage: P(c, b) == u + 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 + 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 + 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') + 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']) + 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() + 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)) + 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 @@ -1148,10 +1158,10 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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 @@ -1159,7 +1169,6 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): 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)) [2 1 3 3 3 1] [1 3 1 2 0 3] @@ -1171,14 +1180,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() # 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)) + 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 @@ -1204,10 +1213,10 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: + 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() @@ -1232,41 +1241,41 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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 -1 + 3*a + 2*a^2 We check that the trace lives in the base ring:: - sage: tr.parent() + 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 + sage: tr.parent() is K # needs sage.rings.finite_rings True Similarly, one can compute the trace over F:: - sage: u.trace(F) + sage: u.trace(F) # needs 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) # 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() + 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)) + 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 @@ -1291,14 +1300,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: + 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(): ....: x = L.random_element() ....: y = L.random_element() @@ -1326,41 +1334,41 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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 3 + 2*a^2 We check that the norm lives in the base ring:: - sage: nr.parent() + 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 + sage: nr.parent() is K # needs sage.rings.finite_rings True Similarly, one can compute the norm over F:: - sage: u.norm(F) + sage: u.norm(F) # needs 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) # 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() + 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)) + 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 @@ -1385,14 +1393,13 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): TESTS:: + 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(): ....: x = L.random_element() ....: y = L.random_element() @@ -1420,46 +1427,46 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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 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() # 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 + sage: chi.base_ring() is K # needs sage.rings.finite_rings True and that it annihilates u:: - sage: chi(u) + sage: chi(u) # needs sage.rings.finite_rings 0 Similarly, one can compute the characteristic polynomial over F:: - sage: u.charpoly(F) + 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') + 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() + 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)) + 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 @@ -1469,9 +1476,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[] # 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) @@ -1487,46 +1494,46 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): EXAMPLES:: + 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 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() # 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 + sage: chi.base_ring() is K # needs sage.rings.finite_rings True and that it annihilates u:: - sage: chi(u) + sage: chi(u) # needs sage.rings.finite_rings 0 Similarly, one can compute the minimal polynomial over F:: - sage: u.minpoly(F) + 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') + 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() + 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)) + 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 @@ -1536,15 +1543,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[] # 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 ] + 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_homset.py b/src/sage/rings/ring_extension_homset.py index 28b2b736dd8..d2c13a11f0e 100644 --- a/src/sage/rings/ring_extension_homset.py +++ b/src/sage/rings/ring_extension_homset.py @@ -1,3 +1,4 @@ +# sage.doctest: needs 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..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: # 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]) - sage: phi - Ring endomorphism of Field in b with defining polynomial x^2 + (3 - a)*x + a over its base + 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) - sage: TestSuite(phi).run() - """ def __init__(self, parent, defn, base_map=None, check=True): r""" @@ -117,8 +115,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 +217,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) # 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() + sage: f._repr_type() # needs sage.rings.finite_rings 'Ring' """ return "Ring" @@ -241,11 +237,11 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + sage: # needs sage.rings.number_field sage: x = polygen(QQ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() - sage: f = K.hom([-sqrt2]) - sage: f + 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) @@ -255,7 +251,7 @@ cdef class RingExtensionHomomorphism(RingMap): 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 # needs sage.rings.number_field True """ y = self._backend(backend_element(x)) @@ -272,18 +268,18 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: sage: F = GF(5) - sage: K. = GF(5^2).over(F) - sage: L. = GF(5^6).over(K) + 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]) - 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 # 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() + 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 @@ -292,11 +288,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 # 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() + sage: phi.base_map() # needs sage.rings.finite_rings """ domain = self.domain() @@ -335,12 +331,11 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: + 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() @@ -359,6 +354,7 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + 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() @@ -368,9 +364,9 @@ cdef class RingExtensionHomomorphism(RingMap): Coercion maps are not considered as identity morphisms:: + sage: # needs sage.rings.finite_rings sage: L. = GF(5^6).over(K) - sage: iota = L.defining_morphism() - sage: iota + 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 @@ -388,19 +384,19 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K = GF(5^10).over(GF(5^5)) - sage: iota = K.defining_morphism() - sage: iota + 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 + 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() True sage: K = GF(7).over(ZZ) - sage: iota = K.defining_morphism() - sage: iota + sage: iota = K.defining_morphism(); iota Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base @@ -416,19 +412,19 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: K = GF(5^10).over(GF(5^5)) - sage: iota = K.defining_morphism() - sage: iota + 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 + 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() False sage: K = GF(7).over(ZZ) - sage: iota = K.defining_morphism() - sage: iota + sage: iota = K.defining_morphism(); iota Ring morphism: From: Integer Ring To: Finite Field of size 7 over its base @@ -447,10 +443,10 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + 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: @@ -478,14 +474,13 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 5) sage: K. = A.over() - sage: f = K.hom([-sqrt5]) - sage: f + 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 Ring endomorphism of Field in sqrt5 with defining polynomial x^2 - 5 over its base Defn: sqrt5 |--> sqrt5 @@ -505,9 +500,9 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: + 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 @@ -523,9 +518,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) # 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) @@ -540,16 +535,15 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: + sage: # needs sage.rings.finite_rings sage: K = GF(11^9).over(GF(11^3)) - sage: f = K.coerce_map_from(GF(11^9)) - sage: f + 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 - + 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: TestSuite(f).run() """ def __init__(self, parent): @@ -559,9 +553,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) # 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 @@ -576,14 +570,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) # 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() + sage: f._repr_type() # needs sage.rings.finite_rings 'Coercion' """ return "Coercion" @@ -594,14 +587,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) # 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() + sage: f._repr_defn() # needs sage.rings.finite_rings '' """ return "" @@ -616,9 +608,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) # 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() @@ -632,16 +624,15 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: + sage: # needs sage.rings.finite_rings sage: K = GF(11^9).over(GF(11^3)) - sage: f = GF(11^9).convert_map_from(K) - sage: f + 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 + 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: TestSuite(f).run() """ @@ -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) # 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 @@ -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) # 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() + sage: f._repr_type() # needs 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) # 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() + sage: f._repr_defn() # needs 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) # 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 @@ -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() # 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 """ @@ -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)) # 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 @@ -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)) # 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 @@ -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)) # 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 @@ -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)) # 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 @@ -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() # 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 """ @@ -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)) # 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 @@ -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)) # 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 @@ -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)) # 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 @@ -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)) # 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) @@ -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)) # 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/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 5beff3cff55..2922298e286 100644 --- a/src/sage/rings/semirings/tropical_semiring.pyx +++ b/src/sage/rings/semirings/tropical_semiring.pyx @@ -555,17 +555,19 @@ class TropicalSemiring(Parent, UniqueRepresentation): EXAMPLES:: + sage: TQ = TropicalSemiring(QQ) + sage: TQ.has_coerce_map_from(TQ) + True + sage: TQ.has_coerce_map_from(TropicalSemiring(ZZ)) + True + + 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 = TropicalSemiring(QQ) - sage: TQ.has_coerce_map_from(TropicalSemiring(ZZ)) - True sage: TR.has_coerce_map_from(TR) True - sage: TQ.has_coerce_map_from(TQ) - True sage: TR.has_coerce_map_from(TQ) True sage: TR.has_coerce_map_from(float) 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") """ 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 d7d14aa4e0a..13a205195d5 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 @@ -343,6 +345,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): -12 ---- + 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) @@ -363,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:: @@ -372,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.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) # optional - sage.rings.number_field + sage: sage.rings.tests.test_random_arith(trials=2, seed=0) survived 0 tests Rational Field -1/2 -1/95 @@ -391,7 +396,6 @@ 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) survived 0 tests... sage: sage.rings.tests.test_random_arith(trials=1000) # long time (5 seconds?) @@ -438,15 +442,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: 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::